@lay111/dsh-plugin-google 1.0.16 → 1.0.17
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/package.json +1 -1
- package/src/api.js +37 -4
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -223,7 +223,12 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
223
223
|
const reader = response.body.getReader();
|
|
224
224
|
const decoder = new TextDecoder();
|
|
225
225
|
let buffer = '';
|
|
226
|
-
let
|
|
226
|
+
let hasText = false;
|
|
227
|
+
let hasToolCall = false;
|
|
228
|
+
let accumulatedThoughts = '';
|
|
229
|
+
let nextBlockIndex = 0;
|
|
230
|
+
const reasoningBlockIndex = 0;
|
|
231
|
+
let textBlockIndex = 1;
|
|
227
232
|
|
|
228
233
|
try {
|
|
229
234
|
while (true) {
|
|
@@ -250,22 +255,26 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
250
255
|
|
|
251
256
|
for (const part of candidate.content?.parts || []) {
|
|
252
257
|
if (part.thought) {
|
|
258
|
+
accumulatedThoughts += part.text || '';
|
|
253
259
|
yield {
|
|
254
260
|
type: 'reasoning-delta',
|
|
255
|
-
index:
|
|
261
|
+
index: reasoningBlockIndex,
|
|
256
262
|
text: part.text || '',
|
|
257
263
|
};
|
|
258
264
|
} else if (part.text) {
|
|
265
|
+
hasText = true;
|
|
259
266
|
yield {
|
|
260
267
|
type: 'text-delta',
|
|
261
|
-
index:
|
|
268
|
+
index: textBlockIndex,
|
|
262
269
|
text: part.text || '',
|
|
263
270
|
};
|
|
264
271
|
} else if (part.functionCall) {
|
|
272
|
+
hasToolCall = true;
|
|
265
273
|
const callId = `call_${Math.random().toString(36).slice(2, 10)}`;
|
|
274
|
+
const callIndex = 2 + (nextBlockIndex++);
|
|
266
275
|
yield {
|
|
267
276
|
type: 'tool-call-delta',
|
|
268
|
-
index:
|
|
277
|
+
index: callIndex,
|
|
269
278
|
id: callId,
|
|
270
279
|
name: part.functionCall.name,
|
|
271
280
|
argumentsDelta: JSON.stringify(part.functionCall.args || {}),
|
|
@@ -274,6 +283,17 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
274
283
|
}
|
|
275
284
|
|
|
276
285
|
if (candidate.finishReason) {
|
|
286
|
+
// Fallback protection: If the model only thought and emitted 0 text and 0 tool calls,
|
|
287
|
+
// synthesize a completion text so the turn never cuts off silently!
|
|
288
|
+
if (!hasText && !hasToolCall && accumulatedThoughts.length > 0) {
|
|
289
|
+
hasText = true;
|
|
290
|
+
yield {
|
|
291
|
+
type: 'text-delta',
|
|
292
|
+
index: textBlockIndex,
|
|
293
|
+
text: '\n(已完成思考,请指示下一步)',
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
277
297
|
yield {
|
|
278
298
|
type: 'finish',
|
|
279
299
|
reason: 'stop',
|
|
@@ -285,6 +305,19 @@ export async function* streamAntigravity(options, accessToken, projectId) {
|
|
|
285
305
|
}
|
|
286
306
|
}
|
|
287
307
|
}
|
|
308
|
+
|
|
309
|
+
// Final safety check
|
|
310
|
+
if (!hasText && !hasToolCall && accumulatedThoughts.length > 0) {
|
|
311
|
+
yield {
|
|
312
|
+
type: 'text-delta',
|
|
313
|
+
index: textBlockIndex,
|
|
314
|
+
text: '\n(已完成思考,请指示下一步)',
|
|
315
|
+
};
|
|
316
|
+
yield {
|
|
317
|
+
type: 'finish',
|
|
318
|
+
reason: 'stop',
|
|
319
|
+
};
|
|
320
|
+
}
|
|
288
321
|
} finally {
|
|
289
322
|
reader.releaseLock();
|
|
290
323
|
}
|