@kenkaiiii/gg-agent 5.23.2 → 5.24.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 +32 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +31 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
isAbortError: () => isAbortError,
|
|
27
27
|
isBillingError: () => isBillingError,
|
|
28
28
|
isContextOverflow: () => isContextOverflow,
|
|
29
|
+
isLocalBackendUrl: () => isLocalBackendUrl,
|
|
29
30
|
isUsageLimitError: () => isUsageLimitError,
|
|
30
31
|
setStreamDiagnostic: () => setStreamDiagnostic
|
|
31
32
|
});
|
|
@@ -37,6 +38,30 @@ var import_gg_ai2 = require("@kenkaiiii/gg-ai");
|
|
|
37
38
|
// src/agent-loop.ts
|
|
38
39
|
var import_zod = require("zod");
|
|
39
40
|
var import_gg_ai = require("@kenkaiiii/gg-ai");
|
|
41
|
+
|
|
42
|
+
// src/local-backend.ts
|
|
43
|
+
function isLocalBackendUrl(baseUrl) {
|
|
44
|
+
if (!baseUrl) return false;
|
|
45
|
+
let host;
|
|
46
|
+
try {
|
|
47
|
+
host = new URL(baseUrl).hostname.toLowerCase();
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (host === "[::1]" || host === "::1") return true;
|
|
52
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
53
|
+
if (host === "0.0.0.0") return true;
|
|
54
|
+
if (host.endsWith(".local")) return true;
|
|
55
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
56
|
+
if (ipv4) {
|
|
57
|
+
const octets = ipv4.slice(1).map(Number);
|
|
58
|
+
if (octets.some((n) => n > 255)) return false;
|
|
59
|
+
return octets[0] === 127;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/agent-loop.ts
|
|
40
65
|
var DEFAULT_MAX_TURNS = 300;
|
|
41
66
|
var _diagFn = null;
|
|
42
67
|
function setStreamDiagnostic(fn) {
|
|
@@ -256,8 +281,9 @@ async function* agentLoop(messages, options) {
|
|
|
256
281
|
const STREAM_THINKING_HARD_TIMEOUT_MS = 6e5;
|
|
257
282
|
const NON_STREAMING_HARD_TIMEOUT_MS = 3e5;
|
|
258
283
|
const usesSilentReasoningBudget = options.provider === "sakana" || options.provider === "openai" && options.thinking != null;
|
|
259
|
-
const
|
|
260
|
-
const
|
|
284
|
+
const localBackend = isLocalBackendUrl(options.baseUrl);
|
|
285
|
+
const firstEventTimeoutMs = localBackend ? Number.POSITIVE_INFINITY : usesSilentReasoningBudget ? STREAM_THINKING_IDLE_TIMEOUT_MS : STREAM_FIRST_EVENT_TIMEOUT_MS;
|
|
286
|
+
const initialHardTimeoutMs = localBackend || usesSilentReasoningBudget ? STREAM_THINKING_HARD_TIMEOUT_MS : STREAM_HARD_TIMEOUT_MS;
|
|
261
287
|
const MAX_TOOLCALL_DELTA_CHARS = 1e6;
|
|
262
288
|
const MAX_TOOLCALL_DELTA_EVENTS = 2e4;
|
|
263
289
|
let logicalTurnStartedAt = 0;
|
|
@@ -288,7 +314,8 @@ async function* agentLoop(messages, options) {
|
|
|
288
314
|
model: options.model,
|
|
289
315
|
thinking: options.thinking ?? "off",
|
|
290
316
|
firstEventTimeoutMs,
|
|
291
|
-
initialHardTimeoutMs
|
|
317
|
+
initialHardTimeoutMs,
|
|
318
|
+
localBackend
|
|
292
319
|
});
|
|
293
320
|
}
|
|
294
321
|
if (firstTurn && options.getSteeringMessages) {
|
|
@@ -346,6 +373,7 @@ async function* agentLoop(messages, options) {
|
|
|
346
373
|
if (useNonStreamingFallback) return;
|
|
347
374
|
if (idleTimer) clearTimeout(idleTimer);
|
|
348
375
|
const timeoutMs = hasReceivedEvent ? STREAM_IDLE_TIMEOUT_MS : hasReceivedThinking ? STREAM_THINKING_IDLE_TIMEOUT_MS : firstEventTimeoutMs;
|
|
376
|
+
if (!Number.isFinite(timeoutMs)) return;
|
|
349
377
|
idleTimer = setTimeout(() => {
|
|
350
378
|
diag("idle_timeout_fired", {
|
|
351
379
|
events: streamEventCount,
|
|
@@ -1563,6 +1591,7 @@ var Agent = class {
|
|
|
1563
1591
|
isAbortError,
|
|
1564
1592
|
isBillingError,
|
|
1565
1593
|
isContextOverflow,
|
|
1594
|
+
isLocalBackendUrl,
|
|
1566
1595
|
isUsageLimitError,
|
|
1567
1596
|
setStreamDiagnostic
|
|
1568
1597
|
});
|