diff --git a/src/js/src/gotty.ts b/src/js/src/gotty.ts index f881c053..af5477ff 100644 --- a/src/js/src/gotty.ts +++ b/src/js/src/gotty.ts @@ -192,7 +192,7 @@ export class GottyTerminal { if (option !== null) { if (this.ismaster) { const httpsEnabled = window.location.protocol == "https:"; - const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws' + '_' + option; + const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + '/ws' + '_' + option; let args = window.location.search; let args2 = ''; if ( eventname=="optionchange" && option && option2args[option] && option2args[option] !== undefined ) { diff --git a/src/resources/chat-widget/src/index.ts b/src/resources/chat-widget/src/index.ts index fe175eff..2fbdd15f 100644 --- a/src/resources/chat-widget/src/index.ts +++ b/src/resources/chat-widget/src/index.ts @@ -19,6 +19,15 @@ function generateFiveCharUUID(): string { return uuid.substring(0, 5); } +function fetchEditorContent(): string { + var editor: any = window["editor"]; + if( editor && editor.env && editor.env.editor && + editor.env.editor.getValue && (typeof(editor.env.editor.getValue) === "function")) { + return editor.env.editor.getValue(); + } + return ""; +} + let chatfirebasedbref: firebase.database.Reference | null = null; const UID = generateFiveCharUUID(); let peerchatmode: boolean = false; @@ -57,8 +66,9 @@ renderer.code = (code, infostring, escaped) => { // Create and append the button const encodedcode = btoa(code); const insertButton = `` + const replaceButton = `` - return parsedcode+insertButton; + return parsedcode+insertButton+replaceButton; }; marked.setOptions({ @@ -92,7 +102,7 @@ interface MessageType { content: string; } -const NUM_MANDATORY_ENTRIES = 3; +const NUM_MANDATORY_ENTRIES = 4; const MAX_HISTORY_SIZE = 20; // older conversation history might not be usefull // Initialize the conversationHistory array @@ -103,7 +113,15 @@ function addMessageToHistory(role: string, content: string, uid: string=UID): vo if (role=="user") { // to handle multiple peer users content = `[${role}-${uid}] ` + content; + if (conversationHistory.length >= NUM_MANDATORY_ENTRIES) { + // update editors content to msg history everytime user writes/sends message + conversationHistory[NUM_MANDATORY_ENTRIES-1] = { + role: "system", + content: "Openrepl IDE/Editor Code Content: "+ fetchEditorContent(), + } + } } + conversationHistory.push({ role: role, content: content }); if (conversationHistory.length > MAX_HISTORY_SIZE) { // Trim the oldest non-mandatory message from the beginning, preserving mandatory entries of docs @@ -210,6 +228,7 @@ async function init() { addMessageToHistory("system", "welcome to openrepl.com!! I am Genie. your OpenRepl AI assistant."); addMessageToHistory("system", "documentation: "+documentation); addMessageToHistory("system", "keywords: "+ keywords); + addMessageToHistory("system", "Openrepl IDE/EditorCodeContent: "+ fetchEditorContent()); setupFBListener(); } window.addEventListener("load", init); @@ -516,7 +535,9 @@ declare global { interface Window { ChatWidget: typeof ChatWidget; insertcodesnippet: () => void; + replacecodesnippet: () => void; firebase: typeof import('firebase'); + editor?: any; } } diff --git a/src/resources/index.html b/src/resources/index.html index 83629286..3ffea830 100755 --- a/src/resources/index.html +++ b/src/resources/index.html @@ -199,7 +199,7 @@ - + @@ -704,6 +704,25 @@

Share/Collaborate

console.error(error); } }; + window.replacecodesnippet = (encodedcode) => { + const code = atob(encodedcode); + console.log("code replace hit: ", code); + try { + if (window.location.pathname.includes("practice")) { + alert("Unable to replace code in practice mode"); + return; + } + let editor = window["editor"]; + if( editor.env && editor.env.editor) { + editor = editor.env.editor; + editor.setValue(code); + } + } + catch(error) { + alert("Unable to replace code"); + console.error(error); + } + }; });