@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.d.cts
CHANGED
|
@@ -324,4 +324,13 @@ declare function isBillingError(err: unknown): boolean;
|
|
|
324
324
|
declare function isUsageLimitError(err: unknown): boolean;
|
|
325
325
|
declare function agentLoop(messages: Message[], options: AgentOptions): AsyncGenerator<AgentEvent, AgentResult>;
|
|
326
326
|
|
|
327
|
-
|
|
327
|
+
/**
|
|
328
|
+
* A local inference server (llama.cpp, vLLM, Ollama, LM Studio) can spend
|
|
329
|
+
* minutes prefilling a large prompt before it emits its first token. The
|
|
330
|
+
* first-event watchdog that protects hosted streams turns that into an abort
|
|
331
|
+
* → retry → cold-prefill loop that never converges, so it is disabled for
|
|
332
|
+
* loopback backends.
|
|
333
|
+
*/
|
|
334
|
+
declare function isLocalBackendUrl(baseUrl?: string): boolean;
|
|
335
|
+
|
|
336
|
+
export { Agent, type AgentDoneEvent, type AgentErrorEvent, type AgentEvent, type AgentFollowUpMessageEvent, type AgentOptions, type AgentResult, type AgentRetryEvent, type AgentServerToolCallEvent, type AgentServerToolResultEvent, type AgentSteeringMessageEvent, AgentStream, type AgentTextDeltaEvent, type AgentThinkingDeltaEvent, type AgentTool, type AgentToolCallDeltaEvent, type AgentToolCallEndEvent, type AgentToolCallStartEvent, type AgentToolCallUpdateEvent, type AgentTurnEndEvent, type AgentTurnTiming, type StreamDiagnosticFn, type StructuredToolResult, type ToolContext, type ToolExecuteResult, type ToolExecutionMode, type TransformContextOptions, agentLoop, isAbortError, isBillingError, isContextOverflow, isLocalBackendUrl, isUsageLimitError, setStreamDiagnostic };
|
package/dist/index.d.ts
CHANGED
|
@@ -324,4 +324,13 @@ declare function isBillingError(err: unknown): boolean;
|
|
|
324
324
|
declare function isUsageLimitError(err: unknown): boolean;
|
|
325
325
|
declare function agentLoop(messages: Message[], options: AgentOptions): AsyncGenerator<AgentEvent, AgentResult>;
|
|
326
326
|
|
|
327
|
-
|
|
327
|
+
/**
|
|
328
|
+
* A local inference server (llama.cpp, vLLM, Ollama, LM Studio) can spend
|
|
329
|
+
* minutes prefilling a large prompt before it emits its first token. The
|
|
330
|
+
* first-event watchdog that protects hosted streams turns that into an abort
|
|
331
|
+
* → retry → cold-prefill loop that never converges, so it is disabled for
|
|
332
|
+
* loopback backends.
|
|
333
|
+
*/
|
|
334
|
+
declare function isLocalBackendUrl(baseUrl?: string): boolean;
|
|
335
|
+
|
|
336
|
+
export { Agent, type AgentDoneEvent, type AgentErrorEvent, type AgentEvent, type AgentFollowUpMessageEvent, type AgentOptions, type AgentResult, type AgentRetryEvent, type AgentServerToolCallEvent, type AgentServerToolResultEvent, type AgentSteeringMessageEvent, AgentStream, type AgentTextDeltaEvent, type AgentThinkingDeltaEvent, type AgentTool, type AgentToolCallDeltaEvent, type AgentToolCallEndEvent, type AgentToolCallStartEvent, type AgentToolCallUpdateEvent, type AgentTurnEndEvent, type AgentTurnTiming, type StreamDiagnosticFn, type StructuredToolResult, type ToolContext, type ToolExecuteResult, type ToolExecutionMode, type TransformContextOptions, agentLoop, isAbortError, isBillingError, isContextOverflow, isLocalBackendUrl, isUsageLimitError, setStreamDiagnostic };
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,30 @@ import {
|
|
|
10
10
|
isHardBillingMessage,
|
|
11
11
|
redactValue
|
|
12
12
|
} from "@kenkaiiii/gg-ai";
|
|
13
|
+
|
|
14
|
+
// src/local-backend.ts
|
|
15
|
+
function isLocalBackendUrl(baseUrl) {
|
|
16
|
+
if (!baseUrl) return false;
|
|
17
|
+
let host;
|
|
18
|
+
try {
|
|
19
|
+
host = new URL(baseUrl).hostname.toLowerCase();
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (host === "[::1]" || host === "::1") return true;
|
|
24
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
25
|
+
if (host === "0.0.0.0") return true;
|
|
26
|
+
if (host.endsWith(".local")) return true;
|
|
27
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
28
|
+
if (ipv4) {
|
|
29
|
+
const octets = ipv4.slice(1).map(Number);
|
|
30
|
+
if (octets.some((n) => n > 255)) return false;
|
|
31
|
+
return octets[0] === 127;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/agent-loop.ts
|
|
13
37
|
var DEFAULT_MAX_TURNS = 300;
|
|
14
38
|
var _diagFn = null;
|
|
15
39
|
function setStreamDiagnostic(fn) {
|
|
@@ -229,8 +253,9 @@ async function* agentLoop(messages, options) {
|
|
|
229
253
|
const STREAM_THINKING_HARD_TIMEOUT_MS = 6e5;
|
|
230
254
|
const NON_STREAMING_HARD_TIMEOUT_MS = 3e5;
|
|
231
255
|
const usesSilentReasoningBudget = options.provider === "sakana" || options.provider === "openai" && options.thinking != null;
|
|
232
|
-
const
|
|
233
|
-
const
|
|
256
|
+
const localBackend = isLocalBackendUrl(options.baseUrl);
|
|
257
|
+
const firstEventTimeoutMs = localBackend ? Number.POSITIVE_INFINITY : usesSilentReasoningBudget ? STREAM_THINKING_IDLE_TIMEOUT_MS : STREAM_FIRST_EVENT_TIMEOUT_MS;
|
|
258
|
+
const initialHardTimeoutMs = localBackend || usesSilentReasoningBudget ? STREAM_THINKING_HARD_TIMEOUT_MS : STREAM_HARD_TIMEOUT_MS;
|
|
234
259
|
const MAX_TOOLCALL_DELTA_CHARS = 1e6;
|
|
235
260
|
const MAX_TOOLCALL_DELTA_EVENTS = 2e4;
|
|
236
261
|
let logicalTurnStartedAt = 0;
|
|
@@ -261,7 +286,8 @@ async function* agentLoop(messages, options) {
|
|
|
261
286
|
model: options.model,
|
|
262
287
|
thinking: options.thinking ?? "off",
|
|
263
288
|
firstEventTimeoutMs,
|
|
264
|
-
initialHardTimeoutMs
|
|
289
|
+
initialHardTimeoutMs,
|
|
290
|
+
localBackend
|
|
265
291
|
});
|
|
266
292
|
}
|
|
267
293
|
if (firstTurn && options.getSteeringMessages) {
|
|
@@ -319,6 +345,7 @@ async function* agentLoop(messages, options) {
|
|
|
319
345
|
if (useNonStreamingFallback) return;
|
|
320
346
|
if (idleTimer) clearTimeout(idleTimer);
|
|
321
347
|
const timeoutMs = hasReceivedEvent ? STREAM_IDLE_TIMEOUT_MS : hasReceivedThinking ? STREAM_THINKING_IDLE_TIMEOUT_MS : firstEventTimeoutMs;
|
|
348
|
+
if (!Number.isFinite(timeoutMs)) return;
|
|
322
349
|
idleTimer = setTimeout(() => {
|
|
323
350
|
diag("idle_timeout_fired", {
|
|
324
351
|
events: streamEventCount,
|
|
@@ -1535,6 +1562,7 @@ export {
|
|
|
1535
1562
|
isAbortError,
|
|
1536
1563
|
isBillingError,
|
|
1537
1564
|
isContextOverflow,
|
|
1565
|
+
isLocalBackendUrl,
|
|
1538
1566
|
isUsageLimitError,
|
|
1539
1567
|
setStreamDiagnostic
|
|
1540
1568
|
};
|