1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
import { ContextItemId } from "../../../schema/FullState";
import AbstractContinueGUIClientProtocol from "./AbstractContinueGUIClientProtocol";
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;
useVscodeMessagePassing: boolean;
private connectMessenger(
serverUrlWithSessionId: string,
useVscodeMessagePassing: boolean
) {
if (this.messenger) {
// this.messenger.close(); TODO
}
this.serverUrlWithSessionId = serverUrlWithSessionId;
this.messenger = useVscodeMessagePassing
? new VscodeMessenger(serverUrlWithSessionId)
: new WebsocketMessenger(serverUrlWithSessionId);
this.messenger.onClose(() => {
console.log("GUI -> IDE websocket closed");
});
this.messenger.onError((error) => {
console.log("GUI -> IDE websocket error", error);
});
this.messenger.onMessageType("reconnect_at_session", (data: any) => {
if (data.session_id) {
this.onReconnectAtSession(data.session_id);
}
});
}
constructor(
serverUrlWithSessionId: string,
useVscodeMessagePassing: boolean
) {
super();
this.serverUrlWithSessionId = serverUrlWithSessionId;
this.useVscodeMessagePassing = useVscodeMessagePassing;
this.connectMessenger(serverUrlWithSessionId, useVscodeMessagePassing);
}
onReconnectAtSession(session_id: string): void {
this.connectMessenger(
this.serverUrlWithSessionId.replace(
/\/session\/[a-zA-Z0-9-]+/,
`/session/${session_id}`
),
this.useVscodeMessagePassing
);
}
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);
}
});
}
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 });
}
deleteContextWithIds(ids: ContextItemId[]) {
this.messenger?.send("delete_context_with_ids", {
ids: ids.map((id) => `${id.provider_title}-${id.item_id}`),
});
}
setEditingAtIds(ids: string[]) {
this.messenger?.send("set_editing_at_ids", { ids });
}
toggleAddingHighlightedCode(): void {
this.messenger?.send("toggle_adding_highlighted_code", {});
}
showLogsAtIndex(index: number): void {
this.messenger?.send("show_logs_at_index", { index });
}
selectContextItem(id: string, query: string): void {
this.messenger?.send("select_context_item", { id, query });
}
}
export default ContinueGUIClientProtocol;
|