@kenkaiiii/gg-agent 5.64.2 → 5.65.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/dist/index.cjs +12 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -385,11 +385,14 @@ async function* agentLoop(messages, options) {
|
|
|
385
385
|
const OVERLOAD_BASE_DELAY_MS = 2e3;
|
|
386
386
|
const OVERLOAD_MAX_DELAY_MS = 3e4;
|
|
387
387
|
const STREAM_IDLE_TIMEOUT_MS = 9e4;
|
|
388
|
+
const STREAM_TOOL_INPUT_IDLE_TIMEOUT_MS = 3e5;
|
|
388
389
|
const STREAM_HARD_TIMEOUT_MS = 9e4;
|
|
389
390
|
const STREAM_OUTPUT_HARD_TIMEOUT_MS = 3e5;
|
|
390
|
-
const STREAM_THINKING_IDLE_TIMEOUT_MS =
|
|
391
|
-
const STREAM_THINKING_HARD_TIMEOUT_MS =
|
|
391
|
+
const STREAM_THINKING_IDLE_TIMEOUT_MS = 6e5;
|
|
392
|
+
const STREAM_THINKING_HARD_TIMEOUT_MS = 9e5;
|
|
392
393
|
const NON_STREAMING_HARD_TIMEOUT_MS = 3e5;
|
|
394
|
+
const nonStreamingHardTimeoutMs = options.thinking != null ? STREAM_THINKING_HARD_TIMEOUT_MS : NON_STREAMING_HARD_TIMEOUT_MS;
|
|
395
|
+
const VISIBLE_STALL_AFTER_MS = 6e4;
|
|
393
396
|
const usesSilentReasoningBudget = options.provider === "sakana" || options.provider === "openai" && options.thinking != null;
|
|
394
397
|
const localBackend = isLocalBackendUrl(options.baseUrl);
|
|
395
398
|
const baseFirstEventTimeoutMs = localBackend ? Number.POSITIVE_INFINITY : usesSilentReasoningBudget ? STREAM_THINKING_IDLE_TIMEOUT_MS : STREAM_FIRST_EVENT_TIMEOUT_MS;
|
|
@@ -490,10 +493,11 @@ async function* agentLoop(messages, options) {
|
|
|
490
493
|
options.signal?.addEventListener("abort", forwardAbort, { once: true });
|
|
491
494
|
let hasReceivedEvent = false;
|
|
492
495
|
let hasReceivedThinking = false;
|
|
496
|
+
let toolInputOpen = false;
|
|
493
497
|
const resetIdleTimer = () => {
|
|
494
498
|
if (useNonStreamingFallback) return;
|
|
495
499
|
if (idleTimer) clearTimeout(idleTimer);
|
|
496
|
-
const timeoutMs = hasReceivedEvent ? STREAM_IDLE_TIMEOUT_MS : hasReceivedThinking ? STREAM_THINKING_IDLE_TIMEOUT_MS : firstEventTimeoutMs;
|
|
500
|
+
const timeoutMs = hasReceivedEvent ? toolInputOpen ? STREAM_TOOL_INPUT_IDLE_TIMEOUT_MS : STREAM_IDLE_TIMEOUT_MS : hasReceivedThinking ? STREAM_THINKING_IDLE_TIMEOUT_MS : firstEventTimeoutMs;
|
|
497
501
|
if (!Number.isFinite(timeoutMs)) return;
|
|
498
502
|
idleTimer = setTimeout(() => {
|
|
499
503
|
diag("idle_timeout_fired", {
|
|
@@ -501,14 +505,14 @@ async function* agentLoop(messages, options) {
|
|
|
501
505
|
sinceLastEventMs: Date.now() - lastEventTime,
|
|
502
506
|
lastEventType,
|
|
503
507
|
maxConsumerLagMs,
|
|
504
|
-
phase: hasReceivedEvent ? "mid_stream" : hasReceivedThinking ? "post_thinking" : "first_event",
|
|
508
|
+
phase: hasReceivedEvent ? toolInputOpen ? "mid_tool_input" : "mid_stream" : hasReceivedThinking ? "post_thinking" : "first_event",
|
|
505
509
|
eventTypes: eventTypeCounts
|
|
506
510
|
});
|
|
507
511
|
idleTimedOut = true;
|
|
508
512
|
streamController.abort();
|
|
509
513
|
}, timeoutMs);
|
|
510
514
|
};
|
|
511
|
-
let hardTimeoutMs = useNonStreamingFallback ?
|
|
515
|
+
let hardTimeoutMs = useNonStreamingFallback ? nonStreamingHardTimeoutMs : initialHardTimeoutMs;
|
|
512
516
|
hardTimer = setTimeout(() => {
|
|
513
517
|
diag("hard_timeout_fired", {
|
|
514
518
|
events: typeof streamEventCount !== "undefined" ? streamEventCount : 0,
|
|
@@ -598,6 +602,8 @@ async function* agentLoop(messages, options) {
|
|
|
598
602
|
if (firstProviderEventAt === void 0) firstProviderEventAt = pullTime;
|
|
599
603
|
eventTypeCounts[event.type] = (eventTypeCounts[event.type] ?? 0) + 1;
|
|
600
604
|
lastEventType = event.type;
|
|
605
|
+
if (event.type === "toolcall_delta") toolInputOpen = true;
|
|
606
|
+
else if (event.type === "toolcall_done") toolInputOpen = false;
|
|
601
607
|
if ((event.type === "text_delta" || event.type === "server_toolcall" || event.type === "toolcall_delta") && !hasReceivedEvent) {
|
|
602
608
|
hasReceivedEvent = true;
|
|
603
609
|
if (hardTimer && hardTimeoutMs < STREAM_OUTPUT_HARD_TIMEOUT_MS) {
|
|
@@ -925,7 +931,7 @@ async function* agentLoop(messages, options) {
|
|
|
925
931
|
attempt: stallRetries,
|
|
926
932
|
maxAttempts: MAX_STALL_RETRIES,
|
|
927
933
|
delayMs,
|
|
928
|
-
silent: stallRetries <= 2,
|
|
934
|
+
silent: stallRetries <= 2 && Date.now() - streamCallStart < VISIBLE_STALL_AFTER_MS,
|
|
929
935
|
...preservedChars > 0 ? { preservedChars } : {}
|
|
930
936
|
};
|
|
931
937
|
await abortableSleep(delayMs, options.signal);
|