blits-bridge 0.1.9 → 0.1.11
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/dist/bridge.d.ts +0 -1
- package/dist/bridge.js +11 -69
- package/package.json +1 -1
package/dist/bridge.d.ts
CHANGED
package/dist/bridge.js
CHANGED
|
@@ -108,9 +108,7 @@ class BlitsBridge {
|
|
|
108
108
|
: JSON.stringify(lastUserMsg?.content ?? '');
|
|
109
109
|
const args = [
|
|
110
110
|
'-p',
|
|
111
|
-
'--output-format', '
|
|
112
|
-
'--verbose',
|
|
113
|
-
'--include-partial-messages',
|
|
111
|
+
'--output-format', 'text',
|
|
114
112
|
'--model', payload.model,
|
|
115
113
|
'--no-session-persistence',
|
|
116
114
|
'--effort', payload.effort || 'low',
|
|
@@ -126,61 +124,22 @@ class BlitsBridge {
|
|
|
126
124
|
cwd: process.env.TMPDIR || process.env.TEMP || '/tmp',
|
|
127
125
|
});
|
|
128
126
|
let fullText = '';
|
|
129
|
-
|
|
130
|
-
let usageData = { input_tokens: 0, output_tokens: 0 };
|
|
127
|
+
const usageData = { input_tokens: 0, output_tokens: 0 };
|
|
131
128
|
proc.stdout.on('data', (chunk) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.processStreamEvent(requestId, event, fullText);
|
|
142
|
-
// Accumulate text from assistant messages
|
|
143
|
-
if (event.type === 'assistant') {
|
|
144
|
-
const text = event.message?.content
|
|
145
|
-
?.filter((c) => c.type === 'text')
|
|
146
|
-
.map((c) => c.text)
|
|
147
|
-
.join('') || '';
|
|
148
|
-
if (text)
|
|
149
|
-
fullText = text;
|
|
150
|
-
}
|
|
151
|
-
// Final result
|
|
152
|
-
if (event.type === 'result') {
|
|
153
|
-
fullText = event.result || fullText;
|
|
154
|
-
if (event.usage) {
|
|
155
|
-
usageData = {
|
|
156
|
-
input_tokens: event.usage.input_tokens || 0,
|
|
157
|
-
output_tokens: event.usage.output_tokens || 0,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
// Not JSON, ignore
|
|
164
|
-
}
|
|
165
|
-
}
|
|
129
|
+
const text = chunk.toString();
|
|
130
|
+
fullText += text;
|
|
131
|
+
// Send each stdout chunk as a stream event
|
|
132
|
+
this.send({
|
|
133
|
+
id: requestId,
|
|
134
|
+
type: 'claude_api_stream',
|
|
135
|
+
text: fullText,
|
|
136
|
+
done: false,
|
|
137
|
+
});
|
|
166
138
|
});
|
|
167
139
|
proc.stderr.on('data', () => { }); // ignore stderr
|
|
168
140
|
proc.stdin.write(prompt);
|
|
169
141
|
proc.stdin.end();
|
|
170
142
|
proc.on('close', (code) => {
|
|
171
|
-
// Process remaining buffer
|
|
172
|
-
if (buffer.trim()) {
|
|
173
|
-
try {
|
|
174
|
-
const event = JSON.parse(buffer);
|
|
175
|
-
if (event.type === 'result') {
|
|
176
|
-
fullText = event.result || fullText;
|
|
177
|
-
if (event.usage) {
|
|
178
|
-
usageData = { input_tokens: event.usage.input_tokens || 0, output_tokens: event.usage.output_tokens || 0 };
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch { }
|
|
183
|
-
}
|
|
184
143
|
// Send final result
|
|
185
144
|
this.send({
|
|
186
145
|
id: requestId,
|
|
@@ -207,23 +166,6 @@ class BlitsBridge {
|
|
|
207
166
|
});
|
|
208
167
|
});
|
|
209
168
|
}
|
|
210
|
-
processStreamEvent(requestId, event, _currentText) {
|
|
211
|
-
// Send stream chunks to server for both full and partial assistant messages
|
|
212
|
-
if (event.type === 'assistant') {
|
|
213
|
-
const text = event.message?.content
|
|
214
|
-
?.filter((c) => c.type === 'text')
|
|
215
|
-
.map((c) => c.text)
|
|
216
|
-
.join('') || '';
|
|
217
|
-
if (text) {
|
|
218
|
-
this.send({
|
|
219
|
-
id: requestId,
|
|
220
|
-
type: 'claude_api_stream',
|
|
221
|
-
text,
|
|
222
|
-
done: event.message?.stop_reason === 'end_turn',
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
169
|
scheduleReconnect() {
|
|
228
170
|
if (this.reconnecting)
|
|
229
171
|
return;
|