@agent-native/core 0.24.10 → 0.26.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/agent/engine/ai-sdk-engine.d.ts.map +1 -1
- package/dist/agent/engine/ai-sdk-engine.js +2 -1
- package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
- package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
- package/dist/agent/engine/anthropic-engine.js +2 -1
- package/dist/agent/engine/anthropic-engine.js.map +1 -1
- package/dist/agent/engine/builder-engine.d.ts.map +1 -1
- package/dist/agent/engine/builder-engine.js +31 -12
- package/dist/agent/engine/builder-engine.js.map +1 -1
- package/dist/agent/engine/output-tokens.d.ts +8 -0
- package/dist/agent/engine/output-tokens.d.ts.map +1 -0
- package/dist/agent/engine/output-tokens.js +60 -0
- package/dist/agent/engine/output-tokens.js.map +1 -0
- package/dist/agent/production-agent.d.ts +2 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +66 -25
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +3 -1
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.d.ts.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.js +138 -5
- package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
- package/dist/client/index.d.ts +3 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +124 -8
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/use-external-value.d.ts +17 -0
- package/dist/client/use-external-value.d.ts.map +1 -0
- package/dist/client/use-external-value.js +29 -0
- package/dist/client/use-external-value.js.map +1 -0
- package/dist/collab/client.d.ts +18 -0
- package/dist/collab/client.d.ts.map +1 -1
- package/dist/collab/client.js +81 -2
- package/dist/collab/client.js.map +1 -1
- package/dist/scripts/docs/search.d.ts.map +1 -1
- package/dist/scripts/docs/search.js +52 -6
- package/dist/scripts/docs/search.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +87 -79
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +6 -6
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/create-server.d.ts.map +1 -1
- package/dist/server/create-server.js +5 -1
- package/dist/server/create-server.js.map +1 -1
- package/dist/server/onboarding-html.js +1 -1
- package/dist/server/onboarding-html.js.map +1 -1
- package/package.json +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-tokens.d.ts","sourceRoot":"","sources":["../../../src/agent/engine/output-tokens.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oCAAoC,OAAO,CAAC;AACzD,eAAO,MAAM,gCAAgC,OAAO,CAAC;AACrD,eAAO,MAAM,mCAAmC,OAAO,CAAC;AACxD,eAAO,MAAM,iCAAiC,OAAO,CAAC;AAetD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAOtE;AAgBD,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAe1E;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,OAAO,GACjB,MAAM,CAKR"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const MIN_MAX_OUTPUT_TOKENS = 256;
|
|
2
|
+
const MAX_MAX_OUTPUT_TOKENS = 32_768;
|
|
3
|
+
export const DEFAULT_OPENROUTER_MAX_OUTPUT_TOKENS = 1024;
|
|
4
|
+
export const DEFAULT_AI_SDK_MAX_OUTPUT_TOKENS = 4096;
|
|
5
|
+
export const DEFAULT_ANTHROPIC_MAX_OUTPUT_TOKENS = 8192;
|
|
6
|
+
export const DEFAULT_BUILDER_MAX_OUTPUT_TOKENS = 8192;
|
|
7
|
+
function parsePositiveInteger(value) {
|
|
8
|
+
if (typeof value === "string" && value.trim() === "")
|
|
9
|
+
return null;
|
|
10
|
+
const n = typeof value === "number"
|
|
11
|
+
? value
|
|
12
|
+
: typeof value === "string"
|
|
13
|
+
? Number(value)
|
|
14
|
+
: null;
|
|
15
|
+
if (n == null || !Number.isFinite(n) || !Number.isInteger(n))
|
|
16
|
+
return null;
|
|
17
|
+
if (n <= 0)
|
|
18
|
+
return null;
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
export function normalizeMaxOutputTokens(value) {
|
|
22
|
+
const parsed = parsePositiveInteger(value);
|
|
23
|
+
if (parsed == null)
|
|
24
|
+
return null;
|
|
25
|
+
return Math.min(MAX_MAX_OUTPUT_TOKENS, Math.max(MIN_MAX_OUTPUT_TOKENS, parsed));
|
|
26
|
+
}
|
|
27
|
+
function envOverrideForEngine(engineName) {
|
|
28
|
+
const provider = engineName.startsWith("ai-sdk:")
|
|
29
|
+
? engineName.slice("ai-sdk:".length)
|
|
30
|
+
: engineName;
|
|
31
|
+
const providerEnvKey = `AGENT_${provider
|
|
32
|
+
.replace(/[^a-z0-9]+/gi, "_")
|
|
33
|
+
.toUpperCase()}_MAX_OUTPUT_TOKENS`;
|
|
34
|
+
return (
|
|
35
|
+
// guard:allow-env-credential — output-token cap config, not a credential
|
|
36
|
+
normalizeMaxOutputTokens(process.env[providerEnvKey]) ??
|
|
37
|
+
normalizeMaxOutputTokens(process.env.AGENT_MAX_OUTPUT_TOKENS));
|
|
38
|
+
}
|
|
39
|
+
export function defaultMaxOutputTokensForEngine(engineName) {
|
|
40
|
+
const override = envOverrideForEngine(engineName);
|
|
41
|
+
if (override != null)
|
|
42
|
+
return override;
|
|
43
|
+
if (engineName === "builder")
|
|
44
|
+
return DEFAULT_BUILDER_MAX_OUTPUT_TOKENS;
|
|
45
|
+
if (engineName === "anthropic" || engineName === "ai-sdk:anthropic") {
|
|
46
|
+
return DEFAULT_ANTHROPIC_MAX_OUTPUT_TOKENS;
|
|
47
|
+
}
|
|
48
|
+
if (engineName === "ai-sdk:openrouter") {
|
|
49
|
+
return DEFAULT_OPENROUTER_MAX_OUTPUT_TOKENS;
|
|
50
|
+
}
|
|
51
|
+
if (engineName.startsWith("ai-sdk:")) {
|
|
52
|
+
return DEFAULT_AI_SDK_MAX_OUTPUT_TOKENS;
|
|
53
|
+
}
|
|
54
|
+
return DEFAULT_AI_SDK_MAX_OUTPUT_TOKENS;
|
|
55
|
+
}
|
|
56
|
+
export function resolveMaxOutputTokensForEngine(engineName, explicit) {
|
|
57
|
+
return (normalizeMaxOutputTokens(explicit) ??
|
|
58
|
+
defaultMaxOutputTokensForEngine(engineName));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=output-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-tokens.js","sourceRoot":"","sources":["../../../src/agent/engine/output-tokens.ts"],"names":[],"mappings":"AAAA,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC,MAAM,CAAC,MAAM,oCAAoC,GAAG,IAAI,CAAC;AACzD,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,CAAC;AACrD,MAAM,CAAC,MAAM,mCAAmC,GAAG,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAC;AAEtD,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAClE,MAAM,CAAC,GACL,OAAO,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,OAAO,KAAK,KAAK,QA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UAAU,KAAK,SAAS;QAAE,OAAO,iCAAiC,CAAC;IACvE,IAAI,UAAU,KAAK,WAAW,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;QACpE,OAAO,mCAAmC,CAAC;IAC7C,CAAC;IACD,IAAI,UAAU,KAAK,mBAAmB,EAAE,CAAC;QACvC,OAAO,oCAAoC,CAAC;IAC9C,CAAC;IACD,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACrC,OAAO,gCAAgC,CAAC;IAC1C,CAAC;IACD,OAAO,gCAAgC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,UAAkB,EAClB,QAAkB;IAElB,OAAO,CACL,wBAAwB,CAAC,QAAQ,CAAC;QAClC,+BAA+B,CAAC,UAAU,CAAC,CAC5C,CAAC;AACJ,CAAC","sourcesContent":["const MIN_MAX_OUTPUT_TOKENS = 256;\nconst MAX_MAX_OUTPUT_TOKENS = 32_768;\n\nexport const DEFAULT_OPENROUTER_MAX_OUTPUT_TOKENS = 1024;\nexport const DEFAULT_AI_SDK_MAX_OUTPUT_TOKENS = 4096;\nexport const DEFAULT_ANTHROPIC_MAX_OUTPUT_TOKENS = 8192;\nexport const DEFAULT_BUILDER_MAX_OUTPUT_TOKENS = 8192;\n\nfunction parsePositiveInteger(value: unknown): number | null {\n if (typeof value === \"string\" && value.trim() === \"\") return null;\n const n =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\"\n ? Number(value)\n : null;\n if (n == null || !Number.isFinite(n) || !Number.isInteger(n)) return null;\n if (n <= 0) return null;\n return n;\n}\n\nexport function normalizeMaxOutputTokens(value: unknown): number | null {\n const parsed = parsePositiveInteger(value);\n if (parsed == null) return null;\n return Math.min(\n MAX_MAX_OUTPUT_TOKENS,\n Math.max(MIN_MAX_OUTPUT_TOKENS, parsed),\n );\n}\n\nfunction envOverrideForEngine(engineName: string): number | null {\n const provider = engineName.startsWith(\"ai-sdk:\")\n ? engineName.slice(\"ai-sdk:\".length)\n : engineName;\n const providerEnvKey = `AGENT_${provider\n .replace(/[^a-z0-9]+/gi, \"_\")\n .toUpperCase()}_MAX_OUTPUT_TOKENS`;\n return (\n // guard:allow-env-credential — output-token cap config, not a credential\n normalizeMaxOutputTokens(process.env[providerEnvKey]) ??\n normalizeMaxOutputTokens(process.env.AGENT_MAX_OUTPUT_TOKENS)\n );\n}\n\nexport function defaultMaxOutputTokensForEngine(engineName: string): number {\n const override = envOverrideForEngine(engineName);\n if (override != null) return override;\n\n if (engineName === \"builder\") return DEFAULT_BUILDER_MAX_OUTPUT_TOKENS;\n if (engineName === \"anthropic\" || engineName === \"ai-sdk:anthropic\") {\n return DEFAULT_ANTHROPIC_MAX_OUTPUT_TOKENS;\n }\n if (engineName === \"ai-sdk:openrouter\") {\n return DEFAULT_OPENROUTER_MAX_OUTPUT_TOKENS;\n }\n if (engineName.startsWith(\"ai-sdk:\")) {\n return DEFAULT_AI_SDK_MAX_OUTPUT_TOKENS;\n }\n return DEFAULT_AI_SDK_MAX_OUTPUT_TOKENS;\n}\n\nexport function resolveMaxOutputTokensForEngine(\n engineName: string,\n explicit?: unknown,\n): number {\n return (\n normalizeMaxOutputTokens(explicit) ??\n defaultMaxOutputTokensForEngine(engineName)\n );\n}\n"]}
|
|
@@ -204,7 +204,7 @@ export type AgentLoopFinalResponseGuardResult = string | {
|
|
|
204
204
|
};
|
|
205
205
|
export type AgentLoopFinalResponseGuard = (context: AgentLoopFinalResponseGuardContext) => AgentLoopFinalResponseGuardResult | null | undefined | Promise<AgentLoopFinalResponseGuardResult | null | undefined>;
|
|
206
206
|
export declare const AGENT_INTERNAL_CONTINUE_PROMPT = "Continue from where you left off and finish the user's original request. Do not repeat completed work, do not mention internal reconnects, time limits, or step limits, and continue as if this is the same uninterrupted run.";
|
|
207
|
-
export type AgentLoopContinuationReason = "run_timeout" | "loop_limit" | "stream_ended" | "gateway_timeout" | "network_interrupted";
|
|
207
|
+
export type AgentLoopContinuationReason = "run_timeout" | "loop_limit" | "max_tokens" | "stream_ended" | "gateway_timeout" | "network_interrupted";
|
|
208
208
|
export declare function appendAgentLoopContinuation(messages: EngineMessage[], reason: AgentLoopContinuationReason): void;
|
|
209
209
|
/**
|
|
210
210
|
* True when an error thrown by `runAgentLoop` is a recoverable transport- or
|
|
@@ -249,6 +249,7 @@ export declare function runAgentLoop(opts: {
|
|
|
249
249
|
orgId?: string | null;
|
|
250
250
|
reasoningEffort?: ReasoningEffort;
|
|
251
251
|
providerOptions?: any;
|
|
252
|
+
maxOutputTokens?: number;
|
|
252
253
|
executionMode?: AgentExecutionMode;
|
|
253
254
|
maxIterations?: number;
|
|
254
255
|
finalResponseGuard?: AgentLoopFinalResponseGuard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEnB,cAAc,EACd,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,iBAAiB,
|
|
1
|
+
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEnB,cAAc,EACd,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAc3B,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAIhE,OAAO,EAEL,cAAc,EACd,qBAAqB,EAC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AM,CAAC,MAAM,EAAE,WAAW,CAAC,GACnC,UAAU,EAAE,CAiBd;AAmED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,2BAA2B,CAAC;CAClD,GAAG,OAAO,CAAC,cAAc,CAAC,CA4iB1B;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAi6BhB;AAED,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EACR,cAAc,GACf,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, setResponseHeader, setResponseStatus, getMethod, } from "h3";
|
|
2
2
|
import { isDeployCredentialFallbackAllowed, readDeployCredentialEnv, } from "../server/credential-provider.js";
|
|
3
3
|
import { EngineError } from "./engine/types.js";
|
|
4
|
+
import { resolveMaxOutputTokensForEngine } from "./engine/output-tokens.js";
|
|
4
5
|
import { backfillEngineMessagesToolResults, stringifyToolUseInputForGateway, unmatchedToolResultReplayText, } from "./engine/translate-anthropic.js";
|
|
5
6
|
import { resolveEngine, registerBuiltinEngines, getStoredModelForEngine, } from "./engine/index.js";
|
|
6
7
|
import { userFacingLlmCredentialError } from "./engine/credential-errors.js";
|
|
@@ -395,6 +396,9 @@ function maxRetriesForError(err) {
|
|
|
395
396
|
}
|
|
396
397
|
const TOOL_INPUT_ACTIVITY_INTERVAL_MS = 1500;
|
|
397
398
|
const MAX_TEXT_ATTACHMENT_CHARS = 60_000;
|
|
399
|
+
const MAX_SELECTION_CONTEXT_CHARS = 8_000;
|
|
400
|
+
const MAX_RESOURCE_INVENTORY_ITEMS = 40;
|
|
401
|
+
const MAX_RESOURCE_INVENTORY_DESCRIPTION_CHARS = 160;
|
|
398
402
|
/**
|
|
399
403
|
* Hard cap on the `<current-screen>` block injected into EVERY user message.
|
|
400
404
|
*
|
|
@@ -403,17 +407,37 @@ const MAX_TEXT_ATTACHMENT_CHARS = 60_000;
|
|
|
403
407
|
* every segment. Injected on every turn with no cap, that single block can blow
|
|
404
408
|
* past the model's context window and hard-error the chat with
|
|
405
409
|
* `context_length_exceeded` (observed: a brand-new "hi" message failing because
|
|
406
|
-
* an open recording's transcript shipped in `<current-screen>`).
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* like `get-recording-player-data`) for the full detail on demand.
|
|
410
|
+
* an open recording's transcript shipped in `<current-screen>`). Keep this to a
|
|
411
|
+
* compact page summary; the agent can call `view-screen` (or a data action like
|
|
412
|
+
* `get-recording-player-data`) for full detail on demand.
|
|
410
413
|
*/
|
|
411
|
-
const MAX_SCREEN_CONTEXT_CHARS =
|
|
414
|
+
const MAX_SCREEN_CONTEXT_CHARS = 10_000;
|
|
412
415
|
function capScreenContext(text) {
|
|
413
416
|
if (text.length <= MAX_SCREEN_CONTEXT_CHARS)
|
|
414
417
|
return text;
|
|
415
418
|
return `${text.slice(0, MAX_SCREEN_CONTEXT_CHARS)}\n\n…[current-screen snapshot truncated after ${MAX_SCREEN_CONTEXT_CHARS.toLocaleString()} chars to protect the context window. Call the view-screen action for the full snapshot, or a data action (e.g. get-recording-player-data) for full transcripts.]`;
|
|
416
419
|
}
|
|
420
|
+
function capSelectionContext(text) {
|
|
421
|
+
if (text.length <= MAX_SELECTION_CONTEXT_CHARS)
|
|
422
|
+
return text;
|
|
423
|
+
return `${text.slice(0, MAX_SELECTION_CONTEXT_CHARS)}\n\n…[selection truncated after ${MAX_SELECTION_CONTEXT_CHARS.toLocaleString()} chars. Ask the user or use an app data action if the omitted text is required.]`;
|
|
424
|
+
}
|
|
425
|
+
function compactInventoryDescription(description) {
|
|
426
|
+
const oneLine = description.replace(/\s+/g, " ").trim();
|
|
427
|
+
if (oneLine.length <= MAX_RESOURCE_INVENTORY_DESCRIPTION_CHARS) {
|
|
428
|
+
return oneLine;
|
|
429
|
+
}
|
|
430
|
+
return `${oneLine.slice(0, MAX_RESOURCE_INVENTORY_DESCRIPTION_CHARS - 1)}…`;
|
|
431
|
+
}
|
|
432
|
+
function limitInventoryLines(lines, label) {
|
|
433
|
+
if (lines.length <= MAX_RESOURCE_INVENTORY_ITEMS)
|
|
434
|
+
return lines;
|
|
435
|
+
const omitted = lines.length - MAX_RESOURCE_INVENTORY_ITEMS;
|
|
436
|
+
return [
|
|
437
|
+
...lines.slice(0, MAX_RESOURCE_INVENTORY_ITEMS),
|
|
438
|
+
` … ${omitted} more ${label} omitted; use resource-list/resource-read for the full inventory.`,
|
|
439
|
+
];
|
|
440
|
+
}
|
|
417
441
|
function generateRunId() {
|
|
418
442
|
return `run-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
419
443
|
}
|
|
@@ -727,13 +751,15 @@ export const AGENT_INTERNAL_CONTINUE_PROMPT = "Continue from where you left off
|
|
|
727
751
|
export function appendAgentLoopContinuation(messages, reason) {
|
|
728
752
|
const note = reason === "loop_limit"
|
|
729
753
|
? "The previous run reached an internal step budget."
|
|
730
|
-
: reason === "
|
|
731
|
-
? "The previous
|
|
732
|
-
: reason === "
|
|
733
|
-
? "The previous
|
|
734
|
-
: reason === "
|
|
735
|
-
? "The previous LLM call
|
|
736
|
-
:
|
|
754
|
+
: reason === "max_tokens"
|
|
755
|
+
? "The previous LLM call reached the model output-token cap before the response finished."
|
|
756
|
+
: reason === "stream_ended"
|
|
757
|
+
? "The previous stream ended before the agent sent a final completion signal."
|
|
758
|
+
: reason === "gateway_timeout"
|
|
759
|
+
? "The previous LLM call hit an upstream gateway timeout before the response finished streaming."
|
|
760
|
+
: reason === "network_interrupted"
|
|
761
|
+
? "The previous LLM call was cut off by a transport-level interruption (socket dropped, connection reset, or stream closed unexpectedly)."
|
|
762
|
+
: "The previous run reached an internal execution budget.";
|
|
737
763
|
messages.push({
|
|
738
764
|
role: "user",
|
|
739
765
|
content: [
|
|
@@ -974,10 +1000,12 @@ export async function runAgentLoop(opts) {
|
|
|
974
1000
|
}
|
|
975
1001
|
let assistantContent;
|
|
976
1002
|
let bufferedAssistantText = "";
|
|
1003
|
+
let terminalStopReason;
|
|
977
1004
|
const toolCallErrors = new Map();
|
|
978
1005
|
for (let retry = 0;; retry++) {
|
|
979
1006
|
assistantContent = undefined;
|
|
980
1007
|
bufferedAssistantText = "";
|
|
1008
|
+
terminalStopReason = undefined;
|
|
981
1009
|
toolCallErrors.clear();
|
|
982
1010
|
try {
|
|
983
1011
|
const streamOpts = {
|
|
@@ -986,6 +1014,7 @@ export async function runAgentLoop(opts) {
|
|
|
986
1014
|
messages,
|
|
987
1015
|
tools,
|
|
988
1016
|
abortSignal: signal,
|
|
1017
|
+
maxOutputTokens: resolveMaxOutputTokensForEngine(engine.name, opts.maxOutputTokens),
|
|
989
1018
|
reasoningEffort: opts.reasoningEffort,
|
|
990
1019
|
providerOptions: opts.providerOptions,
|
|
991
1020
|
};
|
|
@@ -1051,11 +1080,14 @@ export async function runAgentLoop(opts) {
|
|
|
1051
1080
|
usage.cacheReadTokens += event.cacheReadTokens ?? 0;
|
|
1052
1081
|
usage.cacheWriteTokens += event.cacheWriteTokens ?? 0;
|
|
1053
1082
|
}
|
|
1054
|
-
else if (event.type === "stop"
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1083
|
+
else if (event.type === "stop") {
|
|
1084
|
+
terminalStopReason = event.reason;
|
|
1085
|
+
if (event.reason === "error") {
|
|
1086
|
+
throw new EngineError(event.error ?? "Engine stream error", {
|
|
1087
|
+
errorCode: event.errorCode,
|
|
1088
|
+
upgradeUrl: event.upgradeUrl,
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1059
1091
|
}
|
|
1060
1092
|
}
|
|
1061
1093
|
break;
|
|
@@ -1116,6 +1148,11 @@ export async function runAgentLoop(opts) {
|
|
|
1116
1148
|
send({ type: "text", text });
|
|
1117
1149
|
};
|
|
1118
1150
|
if (toolCallParts.length === 0) {
|
|
1151
|
+
if (terminalStopReason === "max_tokens") {
|
|
1152
|
+
flushBufferedAssistantText();
|
|
1153
|
+
appendAgentLoopContinuation(messages, "max_tokens");
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1119
1156
|
const guard = opts.finalResponseGuard
|
|
1120
1157
|
? await opts.finalResponseGuard({
|
|
1121
1158
|
messages,
|
|
@@ -1680,7 +1717,7 @@ export function createProductionAgentHandler(options) {
|
|
|
1680
1717
|
return "";
|
|
1681
1718
|
return (`\n\nThe user has selected the following text and pressed Cmd+I to focus the agent. ` +
|
|
1682
1719
|
`Treat this as the immediate context to act on:\n` +
|
|
1683
|
-
`<selection>\n${sel.text}\n</selection>`);
|
|
1720
|
+
`<selection>\n${capSelectionContext(sel.text)}\n</selection>`);
|
|
1684
1721
|
}
|
|
1685
1722
|
catch {
|
|
1686
1723
|
// DB not ready — skip silently
|
|
@@ -1735,30 +1772,34 @@ export function createProductionAgentHandler(options) {
|
|
|
1735
1772
|
continue;
|
|
1736
1773
|
if (kind === "skill") {
|
|
1737
1774
|
const skill = parseSkillMetadata(full.content, r.path);
|
|
1738
|
-
skillLines.push(` ${skill?.name || r.path} — ${skill?.description || r.path} (${scope}, ${r.path})`);
|
|
1775
|
+
skillLines.push(` ${skill?.name || r.path} — ${compactInventoryDescription(skill?.description || r.path)} (${scope}, ${r.path})`);
|
|
1739
1776
|
}
|
|
1740
1777
|
else if (kind === "agent") {
|
|
1741
1778
|
const agent = parseCustomAgentProfile(full.content, r.path);
|
|
1742
|
-
agentLines.push(` ${agent?.name || r.path} — ${agent?.description || "Custom workspace agent"} (${scope}, ${r.path}${agent?.model ? `, model: ${agent.model}` : ""})`);
|
|
1779
|
+
agentLines.push(` ${agent?.name || r.path} — ${compactInventoryDescription(agent?.description || "Custom workspace agent")} (${scope}, ${r.path}${agent?.model ? `, model: ${agent.model}` : ""})`);
|
|
1743
1780
|
}
|
|
1744
1781
|
else {
|
|
1745
1782
|
const agent = parseRemoteAgentManifest(full.content, r.path);
|
|
1746
|
-
agentLines.push(` ${agent?.name || r.path} — ${agent?.description || "Connected A2A agent"} (${scope}, remote via ${r.path})`);
|
|
1783
|
+
agentLines.push(` ${agent?.name || r.path} — ${compactInventoryDescription(agent?.description || "Connected A2A agent")} (${scope}, remote via ${r.path})`);
|
|
1747
1784
|
}
|
|
1748
1785
|
}
|
|
1749
1786
|
}
|
|
1750
1787
|
const blocks = [];
|
|
1751
1788
|
if (fileLines.length > 0) {
|
|
1752
|
-
|
|
1789
|
+
const lines = limitInventoryLines(fileLines, "files");
|
|
1790
|
+
blocks.push(`<available-files>\nFiles in the workspace:\n${lines.join("\n")}\n\nTo read a file's contents, use the resource-read action with the file path.\n</available-files>`);
|
|
1753
1791
|
}
|
|
1754
1792
|
if (skillLines.length > 0) {
|
|
1755
|
-
|
|
1793
|
+
const lines = limitInventoryLines(skillLines, "skills");
|
|
1794
|
+
blocks.push(`<available-skills>\nSkills in the workspace:\n${lines.join("\n")}\n</available-skills>`);
|
|
1756
1795
|
}
|
|
1757
1796
|
if (agentLines.length > 0) {
|
|
1758
|
-
|
|
1797
|
+
const lines = limitInventoryLines(agentLines, "agents");
|
|
1798
|
+
blocks.push(`<available-agents>\nCustom and connected agents in the workspace:\n${lines.join("\n")}\n\nCustom agents under agents/*.md can be mentioned or used via agent-teams (action: "spawn") with the agent parameter.\n</available-agents>`);
|
|
1759
1799
|
}
|
|
1760
1800
|
if (jobLines.length > 0) {
|
|
1761
|
-
|
|
1801
|
+
const lines = limitInventoryLines(jobLines, "jobs");
|
|
1802
|
+
blocks.push(`<available-jobs>\nScheduled tasks in the workspace:\n${lines.join("\n")}\n</available-jobs>`);
|
|
1762
1803
|
}
|
|
1763
1804
|
filesContext =
|
|
1764
1805
|
blocks.length > 0 ? `\n\n${blocks.join("\n\n")}` : "";
|