@siteboon/claude-code-ui 1.19.1 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/assets/index-Cxnz_sny.css +32 -0
- package/dist/assets/index-DN2ZJcRJ.js +1381 -0
- package/dist/assets/{vendor-codemirror-l-lAmaJ1.js → vendor-codemirror-BMLq5tLB.js} +8 -8
- package/dist/assets/{vendor-xterm-DfaPXD3y.js → vendor-xterm-CJZjLICi.js} +10 -10
- package/dist/icons/gemini-ai-icon.svg +1 -0
- package/dist/index.html +4 -4
- package/package.json +4 -3
- package/server/claude-sdk.js +3 -0
- package/server/database/db.js +18 -2
- package/server/gemini-cli.js +455 -0
- package/server/gemini-response-handler.js +140 -0
- package/server/index.js +311 -227
- package/server/load-env.js +5 -0
- package/server/projects.js +292 -275
- package/server/routes/agent.js +15 -4
- package/server/routes/auth.js +3 -3
- package/server/routes/cli-auth.js +114 -0
- package/server/routes/gemini.js +46 -0
- package/server/sessionManager.js +226 -0
- package/shared/modelConstants.js +19 -0
- package/dist/assets/index-0DqtvI36.js +0 -1413
- package/dist/assets/index-BPHfv_yU.css +0 -32
- package/server/database/auth.db +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Gemini Response Handler - JSON Stream processing
|
|
2
|
+
class GeminiResponseHandler {
|
|
3
|
+
constructor(ws, options = {}) {
|
|
4
|
+
this.ws = ws;
|
|
5
|
+
this.buffer = '';
|
|
6
|
+
this.onContentFragment = options.onContentFragment || null;
|
|
7
|
+
this.onInit = options.onInit || null;
|
|
8
|
+
this.onToolUse = options.onToolUse || null;
|
|
9
|
+
this.onToolResult = options.onToolResult || null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Process incoming raw data from Gemini stream-json
|
|
13
|
+
processData(data) {
|
|
14
|
+
this.buffer += data;
|
|
15
|
+
|
|
16
|
+
// Split by newline
|
|
17
|
+
const lines = this.buffer.split('\n');
|
|
18
|
+
|
|
19
|
+
// Keep the last incomplete line in the buffer
|
|
20
|
+
this.buffer = lines.pop() || '';
|
|
21
|
+
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
if (!line.trim()) continue;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const event = JSON.parse(line);
|
|
27
|
+
this.handleEvent(event);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
// Not a JSON line, probably debug output or CLI warnings
|
|
30
|
+
// console.error('[Gemini Handler] Non-JSON line ignored:', line);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
handleEvent(event) {
|
|
36
|
+
const socketSessionId = typeof this.ws.getSessionId === 'function' ? this.ws.getSessionId() : null;
|
|
37
|
+
|
|
38
|
+
if (event.type === 'init') {
|
|
39
|
+
if (this.onInit) {
|
|
40
|
+
this.onInit(event);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (event.type === 'message' && event.role === 'assistant') {
|
|
46
|
+
const content = event.content || '';
|
|
47
|
+
|
|
48
|
+
// Notify the parent CLI handler of accumulated text
|
|
49
|
+
if (this.onContentFragment && content) {
|
|
50
|
+
this.onContentFragment(content);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let payload = {
|
|
54
|
+
type: 'gemini-response',
|
|
55
|
+
data: {
|
|
56
|
+
type: 'message',
|
|
57
|
+
content: content,
|
|
58
|
+
isPartial: event.delta === true
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
if (socketSessionId) payload.sessionId = socketSessionId;
|
|
62
|
+
this.ws.send(payload);
|
|
63
|
+
}
|
|
64
|
+
else if (event.type === 'tool_use') {
|
|
65
|
+
if (this.onToolUse) {
|
|
66
|
+
this.onToolUse(event);
|
|
67
|
+
}
|
|
68
|
+
let payload = {
|
|
69
|
+
type: 'gemini-tool-use',
|
|
70
|
+
toolName: event.tool_name,
|
|
71
|
+
toolId: event.tool_id,
|
|
72
|
+
parameters: event.parameters || {}
|
|
73
|
+
};
|
|
74
|
+
if (socketSessionId) payload.sessionId = socketSessionId;
|
|
75
|
+
this.ws.send(payload);
|
|
76
|
+
}
|
|
77
|
+
else if (event.type === 'tool_result') {
|
|
78
|
+
if (this.onToolResult) {
|
|
79
|
+
this.onToolResult(event);
|
|
80
|
+
}
|
|
81
|
+
let payload = {
|
|
82
|
+
type: 'gemini-tool-result',
|
|
83
|
+
toolId: event.tool_id,
|
|
84
|
+
status: event.status,
|
|
85
|
+
output: event.output || ''
|
|
86
|
+
};
|
|
87
|
+
if (socketSessionId) payload.sessionId = socketSessionId;
|
|
88
|
+
this.ws.send(payload);
|
|
89
|
+
}
|
|
90
|
+
else if (event.type === 'result') {
|
|
91
|
+
// Send a finalize message string
|
|
92
|
+
let payload = {
|
|
93
|
+
type: 'gemini-response',
|
|
94
|
+
data: {
|
|
95
|
+
type: 'message',
|
|
96
|
+
content: '',
|
|
97
|
+
isPartial: false
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
if (socketSessionId) payload.sessionId = socketSessionId;
|
|
101
|
+
this.ws.send(payload);
|
|
102
|
+
|
|
103
|
+
if (event.stats && event.stats.total_tokens) {
|
|
104
|
+
let statsPayload = {
|
|
105
|
+
type: 'claude-status',
|
|
106
|
+
data: {
|
|
107
|
+
status: 'Complete',
|
|
108
|
+
tokens: event.stats.total_tokens
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
if (socketSessionId) statsPayload.sessionId = socketSessionId;
|
|
112
|
+
this.ws.send(statsPayload);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (event.type === 'error') {
|
|
116
|
+
let payload = {
|
|
117
|
+
type: 'gemini-error',
|
|
118
|
+
error: event.error || event.message || 'Unknown Gemini streaming error'
|
|
119
|
+
};
|
|
120
|
+
if (socketSessionId) payload.sessionId = socketSessionId;
|
|
121
|
+
this.ws.send(payload);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
forceFlush() {
|
|
126
|
+
// If the buffer has content, try to parse it one last time
|
|
127
|
+
if (this.buffer.trim()) {
|
|
128
|
+
try {
|
|
129
|
+
const event = JSON.parse(this.buffer);
|
|
130
|
+
this.handleEvent(event);
|
|
131
|
+
} catch (err) { }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
destroy() {
|
|
136
|
+
this.buffer = '';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export default GeminiResponseHandler;
|