@kenkaiiii/gg-agent 5.39.3 → 5.40.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
@@ -186,6 +186,17 @@ function isMalformedStream(err) {
186
186
  const msg = err.message;
187
187
  return /\bin JSON at position \d+/i.test(msg);
188
188
  }
189
+ var TIMEOUT_NAMES = /* @__PURE__ */ new Set(["TimeoutError", "ConnectTimeoutError", "HeadersTimeoutError"]);
190
+ var TIMEOUT_MESSAGES = [
191
+ /^request timed out\.?$/i,
192
+ /\brequest to [\w .-]+ timed out\b/i,
193
+ /\b(?:connection|socket|headers|stream) timed out\b/i
194
+ ];
195
+ function isBareTimeout(e) {
196
+ if (typeof e.name === "string" && TIMEOUT_NAMES.has(e.name)) return true;
197
+ if (typeof e.message !== "string") return false;
198
+ return TIMEOUT_MESSAGES.some((re) => re.test(e.message));
199
+ }
189
200
  function isTransportFailure(err) {
190
201
  const codes = /* @__PURE__ */ new Set([
191
202
  "ECONNRESET",
@@ -222,6 +233,8 @@ function isTransportFailure(err) {
222
233
  if (typeof e.message === "string") {
223
234
  for (const re of messages) if (re.test(e.message)) return true;
224
235
  }
236
+ const clientError = typeof e.status === "number" && e.status >= 400 && e.status < 500;
237
+ if (!clientError && isBareTimeout(e)) return true;
225
238
  cur = e.cause;
226
239
  }
227
240
  return false;
@@ -413,6 +426,21 @@ async function* agentLoop(messages, options) {
413
426
  diag("stream_call", { nonStreaming: useNonStreamingFallback });
414
427
  streamCallStart = Date.now();
415
428
  providerAttemptStartedAt = streamCallStart;
429
+ let liveApiKey = options.apiKey;
430
+ let liveAccountId = options.accountId;
431
+ let liveProjectId = options.projectId;
432
+ if (options.resolveCredentials) {
433
+ try {
434
+ const fresh = await options.resolveCredentials();
435
+ liveApiKey = fresh.apiKey;
436
+ if (fresh.accountId !== void 0) liveAccountId = fresh.accountId;
437
+ if (fresh.projectId !== void 0) liveProjectId = fresh.projectId;
438
+ } catch (credErr) {
439
+ diag("credential_refresh_failed", {
440
+ error: (credErr instanceof Error ? credErr.message : String(credErr)).slice(0, 200)
441
+ });
442
+ }
443
+ }
416
444
  const result = (0, import_gg_ai.stream)({
417
445
  provider: options.provider,
418
446
  model: options.model,
@@ -424,12 +452,12 @@ async function* agentLoop(messages, options) {
424
452
  maxTokens: options.maxTokens,
425
453
  temperature: options.temperature,
426
454
  thinking: options.thinking,
427
- apiKey: options.apiKey,
455
+ apiKey: liveApiKey,
428
456
  baseUrl: options.baseUrl,
429
457
  signal: streamController.signal,
430
- accountId: options.accountId,
458
+ accountId: liveAccountId,
431
459
  transportSessionId: options.transportSessionId,
432
- projectId: options.projectId,
460
+ projectId: liveProjectId,
433
461
  cacheRetention: options.cacheRetention,
434
462
  promptCacheKey: options.promptCacheKey,
435
463
  serviceTier: options.serviceTier,