pi-gemini-app 0.1.7 → 0.1.8
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/extensions/pi/stream.js +8 -0
- package/package.json +1 -1
- package/src/native-provider.mjs +28 -5
package/extensions/pi/stream.js
CHANGED
|
@@ -447,6 +447,14 @@ export function createGeminiStreamHandler({
|
|
|
447
447
|
}
|
|
448
448
|
break;
|
|
449
449
|
} catch (turnError) {
|
|
450
|
+
if (
|
|
451
|
+
!options?.signal?.aborted &&
|
|
452
|
+
turnError?.code === 'NATIVE_TURN_TIMEOUT' &&
|
|
453
|
+
turnError?.unverifiedOutput !== true &&
|
|
454
|
+
(hasToolCalls || turnError?.postOutputIdleStall === true || publishedBytes >= PREFIX_BYTES)
|
|
455
|
+
) {
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
450
458
|
if (
|
|
451
459
|
!started &&
|
|
452
460
|
attempts === 0 &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-gemini-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "In-process Google Gemini App provider extension for Pi (direct native HTTP/2, /login gemini-app, /gemini-quota, zero runtime dependencies).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
package/src/native-provider.mjs
CHANGED
|
@@ -108,7 +108,7 @@ const validateIdleMs = (value, name) => {
|
|
|
108
108
|
const IDLE_TIMEOUT_SENTINEL = Symbol('IDLE_TIMEOUT_SENTINEL');
|
|
109
109
|
|
|
110
110
|
export class NativeDirectProvider {
|
|
111
|
-
constructor(authManager, { openTurn, uploadImages = uploadNativeImages, downloadImages = downloadRemoteImages, blobCache = createImageBlobCache(), timeoutMs = 600_000, postCompleteGraceMs =
|
|
111
|
+
constructor(authManager, { openTurn, uploadImages = uploadNativeImages, downloadImages = downloadRemoteImages, blobCache = createImageBlobCache(), timeoutMs = 600_000, postCompleteGraceMs = 2_000, postToolIdleMs = 6_000, postOutputIdleMs = 15_000, modelAlias = 'gemini-neon', continuation = false, allowTextSnapshotReplacement = false, allowAutoModel = false } = {}) {
|
|
112
112
|
if (!authManager || typeof authManager.getValidAccessToken !== 'function') throw new TypeError('authManager.getValidAccessToken required');
|
|
113
113
|
if (typeof openTurn !== 'function') throw new TypeError('openTurn required');
|
|
114
114
|
if (typeof uploadImages !== 'function') throw new TypeError('uploadImages required');
|
|
@@ -360,12 +360,31 @@ export class NativeDirectProvider {
|
|
|
360
360
|
...(context.nativeDiagnostic ? { diagnostic: context.nativeDiagnostic } : {}) });
|
|
361
361
|
iterator = turn.events[Symbol.asyncIterator]();
|
|
362
362
|
try {
|
|
363
|
+
const isCleanPostOutputIdleStall = () => {
|
|
364
|
+
if (!rawText.trim()) return false;
|
|
365
|
+
if (/^\s*I'm on it\.\s*Responses with Deep Think can take some time, so check back in a bit\.\s*https?:\/\/googleusercontent\.com\/agentic_processing_chip\/\d+\s*$/i.test(rawText)) return false;
|
|
366
|
+
try {
|
|
367
|
+
const probe = createToolCallSplitter({ policy });
|
|
368
|
+
const probeItems = [...probe.push(rawText), ...probe.flush()];
|
|
369
|
+
const probeCalls = probeItems.filter(it => it.type === 'call').map(it => it.call);
|
|
370
|
+
const probeContent = probeItems.filter(it => it.type === 'content').map(it => it.text).join('');
|
|
371
|
+
if (!outputShape.nativeStructuredOutputPresent && softErrorReason(probeContent, body, probeCalls.length)) return false;
|
|
372
|
+
if (body.parallel_tool_calls === false && probeCalls.length > 1) return false;
|
|
373
|
+
validateToolCompletion(probeCalls, policy);
|
|
374
|
+
if (!probeCalls.length && !probeContent.trim()) return false;
|
|
375
|
+
if (body.response_format && !probeCalls.length) validateStructuredOutputText(probeContent, body.response_format);
|
|
376
|
+
return true;
|
|
377
|
+
} catch {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
363
381
|
const nextEventWithIdle = async () => {
|
|
364
382
|
const verified = !downgrade && !outputShape.nativeRefusalPresent && modeMatches(observedMode) && attributionVerified();
|
|
365
|
-
|
|
366
|
-
|
|
383
|
+
// Never arm an idle timer unless we already have verified, complete, deliverable output;
|
|
384
|
+
// otherwise a slow mid-tool-call or mid-JSON pause would be falsely killed with 504 -> 422.
|
|
385
|
+
const idleKind = (modelComplete && verified && rawText.trim().length > 0) ? 'post_complete'
|
|
367
386
|
: (verified && liveCalls.length > 0 ? 'post_tool'
|
|
368
|
-
: (verified &&
|
|
387
|
+
: (verified && liveCalls.length === 0 && isCleanPostOutputIdleStall() ? 'post_output' : null));
|
|
369
388
|
const idleMs = idleKind === 'post_complete' ? postCompleteGraceMs
|
|
370
389
|
: idleKind === 'post_tool' ? postToolIdleMs
|
|
371
390
|
: idleKind === 'post_output' ? postOutputIdleMs
|
|
@@ -405,7 +424,11 @@ export class NativeDirectProvider {
|
|
|
405
424
|
textBytes: Buffer.byteLength(rawText),
|
|
406
425
|
});
|
|
407
426
|
try { turn?.cancel(); } catch {}
|
|
408
|
-
|
|
427
|
+
const idleError = protocolError('NATIVE_TURN_TIMEOUT', 504);
|
|
428
|
+
if (idleKind === 'post_output' && item.verified && isCleanPostOutputIdleStall()) {
|
|
429
|
+
idleError.postOutputIdleStall = true;
|
|
430
|
+
}
|
|
431
|
+
throw idleError;
|
|
409
432
|
}
|
|
410
433
|
if (item.done) break;
|
|
411
434
|
const event = item.value;
|