blits-bridge 0.1.10 → 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 -70
- 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,62 +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
|
-
console.log(` [CLI] type=${event.type} ${event.type === 'assistant' ? `content_len=${JSON.stringify(event.message?.content || []).length} stop=${event.message?.stop_reason}` : ''}`);
|
|
142
|
-
this.processStreamEvent(requestId, event, fullText);
|
|
143
|
-
// Accumulate text from assistant messages
|
|
144
|
-
if (event.type === 'assistant') {
|
|
145
|
-
const text = event.message?.content
|
|
146
|
-
?.filter((c) => c.type === 'text')
|
|
147
|
-
.map((c) => c.text)
|
|
148
|
-
.join('') || '';
|
|
149
|
-
if (text)
|
|
150
|
-
fullText = text;
|
|
151
|
-
}
|
|
152
|
-
// Final result
|
|
153
|
-
if (event.type === 'result') {
|
|
154
|
-
fullText = event.result || fullText;
|
|
155
|
-
if (event.usage) {
|
|
156
|
-
usageData = {
|
|
157
|
-
input_tokens: event.usage.input_tokens || 0,
|
|
158
|
-
output_tokens: event.usage.output_tokens || 0,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
// Not JSON, ignore
|
|
165
|
-
}
|
|
166
|
-
}
|
|
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
|
+
});
|
|
167
138
|
});
|
|
168
139
|
proc.stderr.on('data', () => { }); // ignore stderr
|
|
169
140
|
proc.stdin.write(prompt);
|
|
170
141
|
proc.stdin.end();
|
|
171
142
|
proc.on('close', (code) => {
|
|
172
|
-
// Process remaining buffer
|
|
173
|
-
if (buffer.trim()) {
|
|
174
|
-
try {
|
|
175
|
-
const event = JSON.parse(buffer);
|
|
176
|
-
if (event.type === 'result') {
|
|
177
|
-
fullText = event.result || fullText;
|
|
178
|
-
if (event.usage) {
|
|
179
|
-
usageData = { input_tokens: event.usage.input_tokens || 0, output_tokens: event.usage.output_tokens || 0 };
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
catch { }
|
|
184
|
-
}
|
|
185
143
|
// Send final result
|
|
186
144
|
this.send({
|
|
187
145
|
id: requestId,
|
|
@@ -208,23 +166,6 @@ class BlitsBridge {
|
|
|
208
166
|
});
|
|
209
167
|
});
|
|
210
168
|
}
|
|
211
|
-
processStreamEvent(requestId, event, _currentText) {
|
|
212
|
-
// Send stream chunks to server for both full and partial assistant messages
|
|
213
|
-
if (event.type === 'assistant') {
|
|
214
|
-
const text = event.message?.content
|
|
215
|
-
?.filter((c) => c.type === 'text')
|
|
216
|
-
.map((c) => c.text)
|
|
217
|
-
.join('') || '';
|
|
218
|
-
if (text) {
|
|
219
|
-
this.send({
|
|
220
|
-
id: requestId,
|
|
221
|
-
type: 'claude_api_stream',
|
|
222
|
-
text,
|
|
223
|
-
done: event.message?.stop_reason === 'end_turn',
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
169
|
scheduleReconnect() {
|
|
229
170
|
if (this.reconnecting)
|
|
230
171
|
return;
|
package/package.json
CHANGED