@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 CHANGED
@@ -412,11 +412,14 @@ async function* agentLoop(messages, options) {
412
412
  const OVERLOAD_BASE_DELAY_MS = 2e3;
413
413
  const OVERLOAD_MAX_DELAY_MS = 3e4;
414
414
  const STREAM_IDLE_TIMEOUT_MS = 9e4;
415
+ const STREAM_TOOL_INPUT_IDLE_TIMEOUT_MS = 3e5;
415
416
  const STREAM_HARD_TIMEOUT_MS = 9e4;
416
417
  const STREAM_OUTPUT_HARD_TIMEOUT_MS = 3e5;
417
- const STREAM_THINKING_IDLE_TIMEOUT_MS = 3e5;
418
- const STREAM_THINKING_HARD_TIMEOUT_MS = 6e5;
418
+ const STREAM_THINKING_IDLE_TIMEOUT_MS = 6e5;
419
+ const STREAM_THINKING_HARD_TIMEOUT_MS = 9e5;
419
420
  const NON_STREAMING_HARD_TIMEOUT_MS = 3e5;
421
+ const nonStreamingHardTimeoutMs = options.thinking != null ? STREAM_THINKING_HARD_TIMEOUT_MS : NON_STREAMING_HARD_TIMEOUT_MS;
422
+ const VISIBLE_STALL_AFTER_MS = 6e4;
420
423
  const usesSilentReasoningBudget = options.provider === "sakana" || options.provider === "openai" && options.thinking != null;
421
424
  const localBackend = isLocalBackendUrl(options.baseUrl);
422
425
  const baseFirstEventTimeoutMs = localBackend ? Number.POSITIVE_INFINITY : usesSilentReasoningBudget ? STREAM_THINKING_IDLE_TIMEOUT_MS : STREAM_FIRST_EVENT_TIMEOUT_MS;
@@ -517,10 +520,11 @@ async function* agentLoop(messages, options) {
517
520
  options.signal?.addEventListener("abort", forwardAbort, { once: true });
518
521
  let hasReceivedEvent = false;
519
522
  let hasReceivedThinking = false;
523
+ let toolInputOpen = false;
520
524
  const resetIdleTimer = () => {
521
525
  if (useNonStreamingFallback) return;
522
526
  if (idleTimer) clearTimeout(idleTimer);
523
- const timeoutMs = hasReceivedEvent ? STREAM_IDLE_TIMEOUT_MS : hasReceivedThinking ? STREAM_THINKING_IDLE_TIMEOUT_MS : firstEventTimeoutMs;
527
+ const timeoutMs = hasReceivedEvent ? toolInputOpen ? STREAM_TOOL_INPUT_IDLE_TIMEOUT_MS : STREAM_IDLE_TIMEOUT_MS : hasReceivedThinking ? STREAM_THINKING_IDLE_TIMEOUT_MS : firstEventTimeoutMs;
524
528
  if (!Number.isFinite(timeoutMs)) return;
525
529
  idleTimer = setTimeout(() => {
526
530
  diag("idle_timeout_fired", {
@@ -528,14 +532,14 @@ async function* agentLoop(messages, options) {
528
532
  sinceLastEventMs: Date.now() - lastEventTime,
529
533
  lastEventType,
530
534
  maxConsumerLagMs,
531
- phase: hasReceivedEvent ? "mid_stream" : hasReceivedThinking ? "post_thinking" : "first_event",
535
+ phase: hasReceivedEvent ? toolInputOpen ? "mid_tool_input" : "mid_stream" : hasReceivedThinking ? "post_thinking" : "first_event",
532
536
  eventTypes: eventTypeCounts
533
537
  });
534
538
  idleTimedOut = true;
535
539
  streamController.abort();
536
540
  }, timeoutMs);
537
541
  };
538
- let hardTimeoutMs = useNonStreamingFallback ? NON_STREAMING_HARD_TIMEOUT_MS : initialHardTimeoutMs;
542
+ let hardTimeoutMs = useNonStreamingFallback ? nonStreamingHardTimeoutMs : initialHardTimeoutMs;
539
543
  hardTimer = setTimeout(() => {
540
544
  diag("hard_timeout_fired", {
541
545
  events: typeof streamEventCount !== "undefined" ? streamEventCount : 0,
@@ -625,6 +629,8 @@ async function* agentLoop(messages, options) {
625
629
  if (firstProviderEventAt === void 0) firstProviderEventAt = pullTime;
626
630
  eventTypeCounts[event.type] = (eventTypeCounts[event.type] ?? 0) + 1;
627
631
  lastEventType = event.type;
632
+ if (event.type === "toolcall_delta") toolInputOpen = true;
633
+ else if (event.type === "toolcall_done") toolInputOpen = false;
628
634
  if ((event.type === "text_delta" || event.type === "server_toolcall" || event.type === "toolcall_delta") && !hasReceivedEvent) {
629
635
  hasReceivedEvent = true;
630
636
  if (hardTimer && hardTimeoutMs < STREAM_OUTPUT_HARD_TIMEOUT_MS) {
@@ -952,7 +958,7 @@ async function* agentLoop(messages, options) {
952
958
  attempt: stallRetries,
953
959
  maxAttempts: MAX_STALL_RETRIES,
954
960
  delayMs,
955
- silent: stallRetries <= 2,
961
+ silent: stallRetries <= 2 && Date.now() - streamCallStart < VISIBLE_STALL_AFTER_MS,
956
962
  ...preservedChars > 0 ? { preservedChars } : {}
957
963
  };
958
964
  await abortableSleep(delayMs, options.signal);