From 627f260cee108476e5335584e81f5e36f3e248cb Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Tue, 18 Jul 2023 16:31:39 -0700
Subject: CONTRIBUTING.md

---
 extension/react-app/src/App.tsx                    |  8 +-
 .../src/hooks/AbstractContinueGUIClientProtocol.ts | 35 ++++++++
 .../src/hooks/ContinueGUIClientProtocol.ts         | 93 +++++++++++++++++----
 .../react-app/src/hooks/useContinueGUIProtocol.ts  | 95 ----------------------
 extension/react-app/src/hooks/useWebsocket.ts      |  2 +-
 5 files changed, 113 insertions(+), 120 deletions(-)
 create mode 100644 extension/react-app/src/hooks/AbstractContinueGUIClientProtocol.ts
 delete mode 100644 extension/react-app/src/hooks/useContinueGUIProtocol.ts

(limited to 'extension/react-app')

diff --git a/extension/react-app/src/App.tsx b/extension/react-app/src/App.tsx
index c9bd42e0..aa462171 100644
--- a/extension/react-app/src/App.tsx
+++ b/extension/react-app/src/App.tsx
@@ -2,7 +2,7 @@ import DebugPanel from "./components/DebugPanel";
 import GUI from "./pages/gui";
 import { createContext } from "react";
 import useContinueGUIProtocol from "./hooks/useWebsocket";
-import ContinueGUIClientProtocol from "./hooks/useContinueGUIProtocol";
+import ContinueGUIClientProtocol from "./hooks/ContinueGUIClientProtocol";
 
 export const GUIClientContext = createContext<
   ContinueGUIClientProtocol | undefined
@@ -13,11 +13,7 @@ function App() {
 
   return (
     <GUIClientContext.Provider value={client}>
-      <DebugPanel
-        tabs={[
-          { element: <GUI />, title: "GUI" }
-        ]}
-      />
+      <DebugPanel tabs={[{ element: <GUI />, title: "GUI" }]} />
     </GUIClientContext.Provider>
   );
 }
diff --git a/extension/react-app/src/hooks/AbstractContinueGUIClientProtocol.ts b/extension/react-app/src/hooks/AbstractContinueGUIClientProtocol.ts
new file mode 100644
index 00000000..6c0df8fc
--- /dev/null
+++ b/extension/react-app/src/hooks/AbstractContinueGUIClientProtocol.ts
@@ -0,0 +1,35 @@
+abstract class AbstractContinueGUIClientProtocol {
+  abstract sendMainInput(input: string): void;
+
+  abstract reverseToIndex(index: number): void;
+
+  abstract sendRefinementInput(input: string, index: number): void;
+
+  abstract sendStepUserInput(input: string, index: number): void;
+
+  abstract onStateUpdate(state: any): void;
+
+  abstract onAvailableSlashCommands(
+    callback: (commands: { name: string; description: string }[]) => void
+  ): void;
+
+  abstract changeDefaultModel(model: string): void;
+
+  abstract sendClear(): void;
+
+  abstract retryAtIndex(index: number): void;
+
+  abstract deleteAtIndex(index: number): void;
+
+  abstract deleteContextAtIndices(indices: number[]): void;
+
+  abstract setEditingAtIndices(indices: number[]): void;
+
+  abstract setPinnedAtIndices(indices: number[]): void;
+
+  abstract toggleAddingHighlightedCode(): void;
+
+  abstract showLogsAtIndex(index: number): void;
+}
+
+export default AbstractContinueGUIClientProtocol;
diff --git a/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts b/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
index 6c0df8fc..7d6c2a71 100644
--- a/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
+++ b/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
@@ -1,35 +1,92 @@
-abstract class AbstractContinueGUIClientProtocol {
-  abstract sendMainInput(input: string): void;
+import AbstractContinueGUIClientProtocol from "./AbstractContinueGUIClientProtocol";
+import { Messenger, WebsocketMessenger } from "./messenger";
+import { VscodeMessenger } from "./vscodeMessenger";
 
-  abstract reverseToIndex(index: number): void;
+class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
+  messenger: Messenger;
+  // Server URL must contain the session ID param
+  serverUrlWithSessionId: string;
 
-  abstract sendRefinementInput(input: string, index: number): void;
+  constructor(
+    serverUrlWithSessionId: string,
+    useVscodeMessagePassing: boolean
+  ) {
+    super();
+    this.serverUrlWithSessionId = serverUrlWithSessionId;
+    this.messenger = useVscodeMessagePassing
+      ? new VscodeMessenger(serverUrlWithSessionId)
+      : new WebsocketMessenger(serverUrlWithSessionId);
+  }
 
-  abstract sendStepUserInput(input: string, index: number): void;
+  sendMainInput(input: string) {
+    this.messenger.send("main_input", { input });
+  }
 
-  abstract onStateUpdate(state: any): void;
+  reverseToIndex(index: number) {
+    this.messenger.send("reverse_to_index", { index });
+  }
 
-  abstract onAvailableSlashCommands(
+  sendRefinementInput(input: string, index: number) {
+    this.messenger.send("refinement_input", { input, index });
+  }
+
+  sendStepUserInput(input: string, index: number) {
+    this.messenger.send("step_user_input", { input, index });
+  }
+
+  onStateUpdate(callback: (state: any) => void) {
+    this.messenger.onMessageType("state_update", (data: any) => {
+      if (data.state) {
+        callback(data.state);
+      }
+    });
+  }
+
+  onAvailableSlashCommands(
     callback: (commands: { name: string; description: string }[]) => void
-  ): void;
+  ) {
+    this.messenger.onMessageType("available_slash_commands", (data: any) => {
+      if (data.commands) {
+        callback(data.commands);
+      }
+    });
+  }
 
-  abstract changeDefaultModel(model: string): void;
+  changeDefaultModel(model: string) {
+    this.messenger.send("change_default_model", { model });
+  }
 
-  abstract sendClear(): void;
+  sendClear() {
+    this.messenger.send("clear_history", {});
+  }
 
-  abstract retryAtIndex(index: number): void;
+  retryAtIndex(index: number) {
+    this.messenger.send("retry_at_index", { index });
+  }
 
-  abstract deleteAtIndex(index: number): void;
+  deleteAtIndex(index: number) {
+    this.messenger.send("delete_at_index", { index });
+  }
 
-  abstract deleteContextAtIndices(indices: number[]): void;
+  deleteContextAtIndices(indices: number[]) {
+    this.messenger.send("delete_context_at_indices", { indices });
+  }
 
-  abstract setEditingAtIndices(indices: number[]): void;
+  setEditingAtIndices(indices: number[]) {
+    this.messenger.send("set_editing_at_indices", { indices });
+  }
 
-  abstract setPinnedAtIndices(indices: number[]): void;
+  setPinnedAtIndices(indices: number[]) {
+    this.messenger.send("set_pinned_at_indices", { indices });
+  }
 
-  abstract toggleAddingHighlightedCode(): void;
+  toggleAddingHighlightedCode(): void {
+    this.messenger.send("toggle_adding_highlighted_code", {});
+  }
 
-  abstract showLogsAtIndex(index: number): void;
+  showLogsAtIndex(index: number): void {
+    this.messenger.send("show_logs_at_index", { index });
+  }
 }
 
-export default AbstractContinueGUIClientProtocol;
+export default ContinueGUIClientProtocol;
diff --git a/extension/react-app/src/hooks/useContinueGUIProtocol.ts b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
deleted file mode 100644
index fef5b2e1..00000000
--- a/extension/react-app/src/hooks/useContinueGUIProtocol.ts
+++ /dev/null
@@ -1,95 +0,0 @@
-import AbstractContinueGUIClientProtocol from "./ContinueGUIClientProtocol";
-// import { Messenger, WebsocketMessenger } from "../../../src/util/messenger";
-import { Messenger, WebsocketMessenger } from "./messenger";
-import { VscodeMessenger } from "./vscodeMessenger";
-
-class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
-  messenger: Messenger;
-  // Server URL must contain the session ID param
-  serverUrlWithSessionId: string;
-
-  constructor(
-    serverUrlWithSessionId: string,
-    useVscodeMessagePassing: boolean
-  ) {
-    super();
-    this.serverUrlWithSessionId = serverUrlWithSessionId;
-    if (useVscodeMessagePassing) {
-      this.messenger = new VscodeMessenger(serverUrlWithSessionId);
-    } else {
-      this.messenger = new WebsocketMessenger(serverUrlWithSessionId);
-    }
-  }
-
-  sendMainInput(input: string) {
-    this.messenger.send("main_input", { input });
-  }
-
-  reverseToIndex(index: number) {
-    this.messenger.send("reverse_to_index", { index });
-  }
-
-  sendRefinementInput(input: string, index: number) {
-    this.messenger.send("refinement_input", { input, index });
-  }
-
-  sendStepUserInput(input: string, index: number) {
-    this.messenger.send("step_user_input", { input, index });
-  }
-
-  onStateUpdate(callback: (state: any) => void) {
-    this.messenger.onMessageType("state_update", (data: any) => {
-      if (data.state) {
-        callback(data.state);
-      }
-    });
-  }
-
-  onAvailableSlashCommands(
-    callback: (commands: { name: string; description: string }[]) => void
-  ) {
-    this.messenger.onMessageType("available_slash_commands", (data: any) => {
-      if (data.commands) {
-        callback(data.commands);
-      }
-    });
-  }
-
-  changeDefaultModel(model: string) {
-    this.messenger.send("change_default_model", { model });
-  }
-
-  sendClear() {
-    this.messenger.send("clear_history", {});
-  }
-
-  retryAtIndex(index: number) {
-    this.messenger.send("retry_at_index", { index });
-  }
-
-  deleteAtIndex(index: number) {
-    this.messenger.send("delete_at_index", { index });
-  }
-
-  deleteContextAtIndices(indices: number[]) {
-    this.messenger.send("delete_context_at_indices", { indices });
-  }
-
-  setEditingAtIndices(indices: number[]) {
-    this.messenger.send("set_editing_at_indices", { indices });
-  }
-
-  setPinnedAtIndices(indices: number[]) {
-    this.messenger.send("set_pinned_at_indices", { indices });
-  }
-
-  toggleAddingHighlightedCode(): void {
-    this.messenger.send("toggle_adding_highlighted_code", {});
-  }
-
-  showLogsAtIndex(index: number): void {
-    this.messenger.send("show_logs_at_index", { index });
-  }
-}
-
-export default ContinueGUIClientProtocol;
diff --git a/extension/react-app/src/hooks/useWebsocket.ts b/extension/react-app/src/hooks/useWebsocket.ts
index e762666f..6b36be97 100644
--- a/extension/react-app/src/hooks/useWebsocket.ts
+++ b/extension/react-app/src/hooks/useWebsocket.ts
@@ -1,7 +1,7 @@
 import React, { useEffect, useState } from "react";
 import { RootStore } from "../redux/store";
 import { useSelector } from "react-redux";
-import ContinueGUIClientProtocol from "./useContinueGUIProtocol";
+import ContinueGUIClientProtocol from "./ContinueGUIClientProtocol";
 import { postVscMessage } from "../vscode";
 
 function useContinueGUIProtocol(useVscodeMessagePassing: boolean = true) {
-- 
cgit v1.2.3-70-g09d2