Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/src/gotty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
25 changes: 23 additions & 2 deletions src/resources/chat-widget/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,8 +66,9 @@ renderer.code = (code, infostring, escaped) => {
// Create and append the button
const encodedcode = btoa(code);
const insertButton = `<button class="share-btn" onclick="insertcodesnippet('${encodedcode}')">Insert</button>`
const replaceButton = `<button class="share-btn" onclick="replacecodesnippet('${encodedcode}')">Replace</button>`

return parsedcode+insertButton;
return parsedcode+insertButton+replaceButton;
};

marked.setOptions({
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -516,7 +535,9 @@ declare global {
interface Window {
ChatWidget: typeof ChatWidget;
insertcodesnippet: () => void;
replacecodesnippet: () => void;
firebase: typeof import('firebase');
editor?: any;
}
}

Expand Down
21 changes: 20 additions & 1 deletion src/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
<li class="menu__item"><a id="sign-in-button" class="link link--dark"><i id = "auth-icon" class="fa fa-sign-in"></i> Login</a></li>
<li class="menu__item"><a class="link link--dark" onclick="StartTour()"><i class="fa fa-rocket" aria-hidden="true"></i> Getting started</a></li>
<li class="menu__item"><a href="/blog" class="link link--dark"><i class="fa fa-book"></i> Blogs</a></li>
<li class="menu__item"><a href="doc.html" class="link link--dark" target="_blank"><i class="fa fa-book"></i> Documentation</a></li>
<li class="menu__item"><a href="/doc.html" class="link link--dark" target="_blank"><i class="fa fa-book"></i> Documentation</a></li>
<li class="menu__item"> </li>
</ul>
</nav>
Expand Down Expand Up @@ -704,6 +704,25 @@ <h3 class="section__title">Share/Collaborate</h3>
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);
}
};
});
</script>
<button data-chat-widget-button class="share-btn floating-button opaq" style="position: fixed; right: 20px; bottom: 20px; border-radius: 10%;z-index: 9999;">
Expand Down
10 changes: 5 additions & 5 deletions src/resources/js/scribbler.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ function uploadFile() {
var http = new XMLHttpRequest();
cmd = getSelectValue();
console.log('command: ',cmd);
var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "demo?q=" + cmd;
var url = window.location.protocol + "//" + window.location.host + "/demo?q=" + cmd;
http.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
try {
Expand Down Expand Up @@ -854,7 +854,7 @@ if (document.getElementsByClassName('demo').length > 0) {

function logout () {
var xhr = new XMLHttpRequest();
var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "logout";
var url = window.location.protocol + "//" + window.location.host + "/logout";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
Expand All @@ -870,7 +870,7 @@ function logout () {

function renderProfileData () {
var xhr = new XMLHttpRequest();
var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "profile?q=json";
var url = window.location.protocol + "//" + window.location.host + "/profile?q=json";
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
Expand Down Expand Up @@ -918,7 +918,7 @@ $(function() {
if ((authResult.user) && (authResult.user.emailVerified)) {
// User is signed in and email is verified, so proceed with login
xhr = new XMLHttpRequest();
var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "login";
var url = window.location.protocol + "//" + window.location.host + "/login";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ $(function() {

// check if already logged in
xhr = new XMLHttpRequest();
var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "login";
var url = window.location.protocol + "//" + window.location.host + "/login";
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
Expand Down
2 changes: 1 addition & 1 deletion src/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (server *Server) errorHandler(w http.ResponseWriter, r *http.Request, statu
}

func (server *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
if r.URL.Path != "/" && r.URL.Path != "/practice"{
server.errorHandler(w, r, http.StatusNotFound)
return
}
Expand Down
1 change: 1 addition & 0 deletions src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (server *Server) setupHandlers(ctx context.Context, cancel context.CancelFu

var siteMux = http.NewServeMux()
siteMux.HandleFunc(pathPrefix, server.handleIndex)
//siteMux.HandleFunc(pathPrefix+"practice", server.handleIndex)
siteMux.HandleFunc(pathPrefix+"feedback", handleFeedback)
siteMux.HandleFunc(pathPrefix+"blog", handleBlog)
siteMux.HandleFunc(pathPrefix+"demo", handleDemo)
Expand Down
Loading