@opencow-ai/opencow-agent-sdk 0.4.6 → 0.4.8
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/Tool.d.ts +1 -0
- package/dist/capabilities/SdkTool.d.ts +8 -0
- package/dist/capabilities/mcp/types.d.ts +1 -1
- package/dist/capabilities/tools/AgentTool/agentMerge.d.ts +8 -0
- package/dist/capabilities/tools/AgentTool/builtInAgents.d.ts +15 -0
- package/dist/capabilities/tools/AgentTool/runAgent.d.ts +13 -2
- package/dist/capabilities/tools/ToolSearchTool/ToolSearchTool.d.ts +1 -1
- package/dist/cli.mjs +914 -567
- package/dist/client.d.ts +10 -0
- package/dist/client.js +863 -399
- package/dist/constants/envVars.d.ts +1 -0
- package/dist/constants/tools.d.ts +1 -1
- package/dist/controller/compact/autoCompact.d.ts +17 -1
- package/dist/controller/compact/reactiveCompact.d.ts +52 -0
- package/dist/controller/hooks.d.ts +17 -2
- package/dist/controller/loop.d.ts +2 -5
- package/dist/controller/query/deps.d.ts +2 -1
- package/dist/controller/toolSearch.d.ts +20 -0
- package/dist/entrypoints/sdk/controlSchemas.d.ts +74 -1
- package/dist/entrypoints/sdk/coreSchemas.d.ts +19 -1
- package/dist/entrypoints/sdk/runtimeTypes.d.ts +41 -0
- package/dist/lib/envDynamic.d.ts +1 -1
- package/dist/permissions/permissions.d.ts +15 -0
- package/dist/providers/anthropic/teleport/api.d.ts +1 -1
- package/dist/providers/codex/shim.d.ts +8 -0
- package/dist/providers/openai/shim.d.ts +19 -12
- package/dist/providers/provider.d.ts +2 -5
- package/dist/providers/shared/clientFactory.d.ts +2 -5
- package/dist/providers/shared/logging.d.ts +2 -2
- package/dist/providers/shared/model/providers.d.ts +5 -0
- package/dist/providers/shared/routing.d.ts +37 -6
- package/dist/providers/shared/usage.d.ts +11 -0
- package/dist/query.d.ts +3 -0
- package/dist/sdk.js +863 -399
- package/dist/session/backgroundAbortRegistry.d.ts +23 -0
- package/dist/types/toolRuntime.d.ts +14 -5
- package/package.json +3 -3
|
@@ -106,6 +106,7 @@ export declare const ENV_VARS: {
|
|
|
106
106
|
readonly ENABLE_TASKS: EnvVarSpec;
|
|
107
107
|
readonly ENABLE_TELEMETRY: EnvVarSpec;
|
|
108
108
|
readonly ENABLE_TOKEN_USAGE_ATTACHMENT: EnvVarSpec;
|
|
109
|
+
readonly ENABLE_TOOL_SEARCH: EnvVarSpec;
|
|
109
110
|
readonly ENABLE_XAA: EnvVarSpec;
|
|
110
111
|
readonly ENHANCED_TELEMETRY_BETA: EnvVarSpec;
|
|
111
112
|
readonly ENTRYPOINT: EnvVarSpec;
|
|
@@ -6,7 +6,7 @@ export declare const ASYNC_AGENT_ALLOWED_TOOLS: Set<string>;
|
|
|
6
6
|
* These are injected by inProcessRunner.ts and allowed through filterToolsForAgent
|
|
7
7
|
* via isInProcessTeammate() check.
|
|
8
8
|
*/
|
|
9
|
-
export declare const IN_PROCESS_TEAMMATE_ALLOWED_TOOLS: Set<
|
|
9
|
+
export declare const IN_PROCESS_TEAMMATE_ALLOWED_TOOLS: Set<string>;
|
|
10
10
|
/**
|
|
11
11
|
* Tools allowed in coordinator mode - only output and agent management tools for the coordinator
|
|
12
12
|
*/
|
|
@@ -2,7 +2,8 @@ import type { QuerySource } from '../../constants/querySource.js';
|
|
|
2
2
|
import type { ToolRuntimeContext } from '../../types/toolRuntime.js';
|
|
3
3
|
import type { Message } from '../../types/message.js';
|
|
4
4
|
import type { CacheSafeParams } from '../../session/forkedAgent.js';
|
|
5
|
-
import { type CompactionResult } from './compact.js';
|
|
5
|
+
import { type CompactionResult, compactConversation } from './compact.js';
|
|
6
|
+
import { trySessionMemoryCompaction } from './sessionMemoryCompact.js';
|
|
6
7
|
export declare function getEffectiveContextWindowSize(model: string, opts?: {
|
|
7
8
|
contextWindow?: number;
|
|
8
9
|
maxOutputTokens?: number;
|
|
@@ -41,3 +42,18 @@ export declare function autoCompactIfNeeded(messages: Message[], toolUseContext:
|
|
|
41
42
|
compactionResult?: CompactionResult;
|
|
42
43
|
consecutiveFailures?: number;
|
|
43
44
|
}>;
|
|
45
|
+
/**
|
|
46
|
+
* host 主动触发的手动压缩(用户的 `/compact`)。与 autoCompactIfNeeded 不同:
|
|
47
|
+
* 不看 token 阈值——总是立即压缩;并以非自动方式运行(isAutoCompact=false),
|
|
48
|
+
* 从而尊重自定义指令。其余策略与自动压缩一致:无指令时先试 session-memory 压缩
|
|
49
|
+
* (它不支持自定义指令),不可用再退回完整摘要压缩。
|
|
50
|
+
*
|
|
51
|
+
* deps 可注入,便于在不驱动真实摘要模型的前提下测试编排逻辑(沿用本仓 QueryDeps 思路)。
|
|
52
|
+
*/
|
|
53
|
+
export declare function manualCompact(messages: Message[], toolUseContext: ToolRuntimeContext, cacheSafeParams: CacheSafeParams, instructions?: string, deps?: {
|
|
54
|
+
compactConversation: typeof compactConversation;
|
|
55
|
+
trySessionMemoryCompaction: typeof trySessionMemoryCompaction;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
wasCompacted: boolean;
|
|
58
|
+
compactionResult?: CompactionResult;
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive(撞墙后)上下文压缩 —— 413 "Prompt is too long" / 媒体过大的兜底。
|
|
3
|
+
*
|
|
4
|
+
* 主动压缩(autoCompact)在每轮开头按 token 阈值预判;但大 tool 输出能在同一 agent
|
|
5
|
+
* loop 内、两次检查之间把上下文顶爆 → 下一次 API 调用直接被上游拒(413/400
|
|
6
|
+
* "prompt is too long")。窗口估错(后端虚报 / openai 模型退回 200k 默认)时主动压缩
|
|
7
|
+
* 更是抓不住。本模块在 query loop 的流式阶段「withhold」住这类可恢复错误,turn 结束后由
|
|
8
|
+
* tryReactiveCompact 压缩 + 重试(单发防自旋:本 turn 试过一次就放弃,让错误浮现)。
|
|
9
|
+
*
|
|
10
|
+
* 复用 compactConversation(同主动压缩的摘要引擎,会 strip 图片 + 摘要旧消息),所以
|
|
11
|
+
* 媒体过大错误压缩后也能在重试时消失。query.ts 已接好 withhold/recovery/retry 状态机,
|
|
12
|
+
* 本模块只负责:判定可恢复 + 执行一次压缩。
|
|
13
|
+
*/
|
|
14
|
+
import type { AssistantMessage, Message } from '../../types/message.js';
|
|
15
|
+
import type { QuerySource } from '../../constants/querySource.js';
|
|
16
|
+
import type { CacheSafeParams } from '../../session/forkedAgent.js';
|
|
17
|
+
import { type CompactionResult, compactConversation } from './compact.js';
|
|
18
|
+
type WithholdableMessage = AssistantMessage | {
|
|
19
|
+
type?: string;
|
|
20
|
+
} | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Reactive 压缩是否启用。沿用用户的自动压缩开关:关掉自动压缩 = 连兜底也不做
|
|
23
|
+
* (尊重 DISABLE_AUTO_COMPACT / autoCompactEnabled=false 的「不要任何自动行为」语义)。
|
|
24
|
+
*/
|
|
25
|
+
export declare function isReactiveCompactEnabled(): boolean;
|
|
26
|
+
/** 流式阶段:这条消息是否是可兜底的 prompt-too-long(应 withhold 等待恢复)。 */
|
|
27
|
+
export declare function isWithheldPromptTooLong(message: WithholdableMessage): boolean;
|
|
28
|
+
/** 流式阶段:这条消息是否是可兜底的媒体过大错误(压缩 strip 图片后重试可恢复)。 */
|
|
29
|
+
export declare function isWithheldMediaSizeError(message: WithholdableMessage): boolean;
|
|
30
|
+
export interface TryReactiveCompactParams {
|
|
31
|
+
/** 本 turn 是否已经 reactive 压缩过一次(单发防自旋)。 */
|
|
32
|
+
hasAttempted: boolean;
|
|
33
|
+
querySource: QuerySource | undefined;
|
|
34
|
+
aborted: boolean;
|
|
35
|
+
messages: Message[];
|
|
36
|
+
cacheSafeParams: CacheSafeParams;
|
|
37
|
+
}
|
|
38
|
+
interface TryReactiveCompactDeps {
|
|
39
|
+
compactConversation: typeof compactConversation;
|
|
40
|
+
isReactiveCompactEnabled: typeof isReactiveCompactEnabled;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 撞墙后压缩一次并返回结果供 query loop 重试;不可恢复时返回 null(错误浮现)。
|
|
44
|
+
*
|
|
45
|
+
* 单发:hasAttempted=true(本 turn 已试过)或已 abort 直接 null,避免「压缩→仍超→
|
|
46
|
+
* 再压缩」死循环。复用 compactConversation:suppress 提问、无自定义指令、isAutoCompact
|
|
47
|
+
* 语义(它会 strip 图片 + 摘要旧消息,使 413/媒体过大在重试时消失)。
|
|
48
|
+
*
|
|
49
|
+
* deps 可注入,便于在不驱动真实摘要模型的前提下测试编排逻辑(沿用本仓 manualCompact 思路)。
|
|
50
|
+
*/
|
|
51
|
+
export declare function tryReactiveCompact(params: TryReactiveCompactParams, deps?: TryReactiveCompactDeps): Promise<CompactionResult | null>;
|
|
52
|
+
export {};
|
|
@@ -218,7 +218,10 @@ export declare function executeStopFailureHooks(lastMessage: AssistantMessage, t
|
|
|
218
218
|
* @param messages Optional conversation history for prompt/function hooks
|
|
219
219
|
* @returns Async generator that yields progress messages and blocking errors
|
|
220
220
|
*/
|
|
221
|
-
export declare function executeStopHooks(permissionMode?: string, signal?: AbortSignal, timeoutMs?: number, stopHookActive?: boolean, subagentId?: AgentId, toolUseContext?: ToolRuntimeContext, messages?: Message[], agentType?: string, requestPrompt?: (sourceName: string, toolInputSummary?: string | null) => (request: PromptRequest) => Promise<PromptResponse
|
|
221
|
+
export declare function executeStopHooks(permissionMode?: string, signal?: AbortSignal, timeoutMs?: number, stopHookActive?: boolean, subagentId?: AgentId, toolUseContext?: ToolRuntimeContext, messages?: Message[], agentType?: string, requestPrompt?: (sourceName: string, toolInputSummary?: string | null) => (request: PromptRequest) => Promise<PromptResponse>, terminal?: {
|
|
222
|
+
status: 'completed' | 'failed' | 'stopped';
|
|
223
|
+
errorMessage?: string;
|
|
224
|
+
}): AsyncGenerator<AggregatedHookResult>;
|
|
222
225
|
/**
|
|
223
226
|
* Execute TeammateIdle hooks when a teammate is about to go idle.
|
|
224
227
|
* If a hook blocks (exit code 2), the teammate should continue working instead of going idle.
|
|
@@ -296,7 +299,19 @@ export declare function executeSetupHooks(trigger: 'init' | 'maintenance', signa
|
|
|
296
299
|
* @param timeoutMs Optional timeout in milliseconds for hook execution
|
|
297
300
|
* @returns Async generator that yields progress messages and hook results
|
|
298
301
|
*/
|
|
299
|
-
export declare function executeSubagentStartHooks(agentId: string, agentType: string, signal?: AbortSignal, timeoutMs?: number): AsyncGenerator<AggregatedHookResult>;
|
|
302
|
+
export declare function executeSubagentStartHooks(agentId: string, agentType: string, signal?: AbortSignal, timeoutMs?: number, toolUseId?: string, isBackground?: boolean): AsyncGenerator<AggregatedHookResult>;
|
|
303
|
+
/**
|
|
304
|
+
* Fire a SubagentProgress hook carrying one of a background sub-agent's
|
|
305
|
+
* completed messages (its content blocks, already simplified). Lets a host
|
|
306
|
+
* stream a background sub-agent's running sub-conversation (thinking / text /
|
|
307
|
+
* tool calls) into its UI out-of-band — i.e. while the main turn is idle —
|
|
308
|
+
* reusing the same per-message reduction it uses for foreground sub-agents.
|
|
309
|
+
*
|
|
310
|
+
* Fire-and-forget by design: callers must NOT await the per-message firing in
|
|
311
|
+
* the agent's hot loop. `blocks` is intentionally loosely typed (hook inputs
|
|
312
|
+
* are `any` in coreTypes) and mirrors the host's normalized event shapes.
|
|
313
|
+
*/
|
|
314
|
+
export declare function executeSubagentProgressHooks(agentId: string, agentType: string, messageId: string, parentToolUseId: string | undefined, blocks: Array<Record<string, unknown>>, signal?: AbortSignal): Promise<void>;
|
|
300
315
|
/**
|
|
301
316
|
* Execute pre-compact hooks if configured
|
|
302
317
|
* @param compactData The compact data to pass to hooks
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderOverride } from '../providers/shared/routing.js';
|
|
1
2
|
import type { BetaJSONOutputFormat, BetaMessage, BetaMessageStreamParams, BetaToolChoiceAuto, BetaToolChoiceTool, BetaToolUnion } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
|
|
2
3
|
import { type QueryChainTracking, type ToolPermissionContext, type Tools } from '../Tool.js';
|
|
3
4
|
import type { AgentDefinition } from '../capabilities/tools/AgentTool/loadAgentsDir.js';
|
|
@@ -54,11 +55,7 @@ export type Options = {
|
|
|
54
55
|
total: number;
|
|
55
56
|
remaining?: number;
|
|
56
57
|
};
|
|
57
|
-
providerOverride?:
|
|
58
|
-
model: string;
|
|
59
|
-
baseURL: string;
|
|
60
|
-
apiKey: string;
|
|
61
|
-
};
|
|
58
|
+
providerOverride?: ProviderOverride;
|
|
62
59
|
};
|
|
63
60
|
export declare function queryModelWithoutStreaming({ messages, systemPrompt, thinkingConfig, tools, signal, options, }: {
|
|
64
61
|
messages: Message[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { queryModelWithStreaming } from '../loop.js';
|
|
2
|
-
import { autoCompactIfNeeded } from '../compact/autoCompact.js';
|
|
2
|
+
import { autoCompactIfNeeded, manualCompact } from '../compact/autoCompact.js';
|
|
3
3
|
import { microcompactMessages } from '../compact/microCompact.js';
|
|
4
4
|
export type QueryDeps = {
|
|
5
5
|
callModel: typeof queryModelWithStreaming;
|
|
6
6
|
microcompact: typeof microcompactMessages;
|
|
7
7
|
autocompact: typeof autoCompactIfNeeded;
|
|
8
|
+
manualCompact: typeof manualCompact;
|
|
8
9
|
uuid: () => string;
|
|
9
10
|
};
|
|
10
11
|
export declare function productionDeps(): QueryDeps;
|
|
@@ -46,6 +46,17 @@ export declare function getToolSearchMode(): ToolSearchMode;
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function modelSupportsToolReference(model: string): boolean;
|
|
48
48
|
export declare function isToolSearchEnabledOptimistic(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the current request may use the NATIVE tool-search wire shapes:
|
|
51
|
+
* `tool_reference` content blocks + `defer_loading: true` on tool
|
|
52
|
+
* definitions + the tool-search beta header. These are Anthropic beta
|
|
53
|
+
* shapes — only the direct first-party Anthropic endpoint reliably
|
|
54
|
+
* accepts them. Proxies (custom ANTHROPIC_BASE_URL) and the OpenAI /
|
|
55
|
+
* Gemini families get the client-side EMULATION instead: ToolSearchTool
|
|
56
|
+
* results carry plain-text `<discovered-tool name="X" />` markers and
|
|
57
|
+
* discovered tools are sent with their FULL schema (no defer_loading).
|
|
58
|
+
*/
|
|
59
|
+
export declare function isNativeToolReferenceWire(): boolean;
|
|
49
60
|
/**
|
|
50
61
|
* Check if ToolSearchTool is available in the provided tools list.
|
|
51
62
|
* If ToolSearchTool is not available (e.g., disallowed via disallowedTools),
|
|
@@ -81,6 +92,15 @@ export declare function isToolSearchEnabled(model: string, tools: Tools, getTool
|
|
|
81
92
|
* tool_reference is a beta feature not in the SDK types, so we need runtime checks.
|
|
82
93
|
*/
|
|
83
94
|
export declare function isToolReferenceBlock(obj: unknown): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Marker emitted by ToolSearchTool under the emulation wire (non-native
|
|
97
|
+
* providers). One line per discovered tool. Kept attribute-style so a
|
|
98
|
+
* model quoting it verbatim in prose is unlikely to collide.
|
|
99
|
+
* Emitter lives in ToolSearchTool.ts (mapToolResultToToolResultBlockParam)
|
|
100
|
+
* — keep the two in sync. Has the `g` flag for matchAll — do NOT call
|
|
101
|
+
* .test()/.exec() on this export (stateful lastIndex).
|
|
102
|
+
*/
|
|
103
|
+
export declare const DISCOVERED_TOOL_MARKER_RE: RegExp;
|
|
84
104
|
/**
|
|
85
105
|
* Extract tool names from tool_reference blocks in message history.
|
|
86
106
|
*
|
|
@@ -601,6 +601,8 @@ export declare const SDKHookCallbackRequestSchema: () => z.ZodObject<{
|
|
|
601
601
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
602
602
|
agent_id: z.ZodString;
|
|
603
603
|
agent_type: z.ZodString;
|
|
604
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
605
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
604
606
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
605
607
|
session_id: z.ZodString;
|
|
606
608
|
transcript_path: z.ZodString;
|
|
@@ -615,6 +617,12 @@ export declare const SDKHookCallbackRequestSchema: () => z.ZodObject<{
|
|
|
615
617
|
agent_transcript_path: z.ZodString;
|
|
616
618
|
agent_type: z.ZodString;
|
|
617
619
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
620
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
621
|
+
failed: "failed";
|
|
622
|
+
completed: "completed";
|
|
623
|
+
stopped: "stopped";
|
|
624
|
+
}>>;
|
|
625
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
618
626
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
619
627
|
session_id: z.ZodString;
|
|
620
628
|
transcript_path: z.ZodString;
|
|
@@ -1458,6 +1466,8 @@ export declare const SDKControlRequestInnerSchema: () => z.ZodUnion<readonly [z.
|
|
|
1458
1466
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
1459
1467
|
agent_id: z.ZodString;
|
|
1460
1468
|
agent_type: z.ZodString;
|
|
1469
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
1470
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
1461
1471
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
1462
1472
|
session_id: z.ZodString;
|
|
1463
1473
|
transcript_path: z.ZodString;
|
|
@@ -1472,6 +1482,12 @@ export declare const SDKControlRequestInnerSchema: () => z.ZodUnion<readonly [z.
|
|
|
1472
1482
|
agent_transcript_path: z.ZodString;
|
|
1473
1483
|
agent_type: z.ZodString;
|
|
1474
1484
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
1485
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
1486
|
+
failed: "failed";
|
|
1487
|
+
completed: "completed";
|
|
1488
|
+
stopped: "stopped";
|
|
1489
|
+
}>>;
|
|
1490
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
1475
1491
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
1476
1492
|
session_id: z.ZodString;
|
|
1477
1493
|
transcript_path: z.ZodString;
|
|
@@ -2218,6 +2234,8 @@ export declare const SDKControlRequestSchema: () => z.ZodObject<{
|
|
|
2218
2234
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
2219
2235
|
agent_id: z.ZodString;
|
|
2220
2236
|
agent_type: z.ZodString;
|
|
2237
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
2238
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
2221
2239
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
2222
2240
|
session_id: z.ZodString;
|
|
2223
2241
|
transcript_path: z.ZodString;
|
|
@@ -2232,6 +2250,12 @@ export declare const SDKControlRequestSchema: () => z.ZodObject<{
|
|
|
2232
2250
|
agent_transcript_path: z.ZodString;
|
|
2233
2251
|
agent_type: z.ZodString;
|
|
2234
2252
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
2253
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
2254
|
+
failed: "failed";
|
|
2255
|
+
completed: "completed";
|
|
2256
|
+
stopped: "stopped";
|
|
2257
|
+
}>>;
|
|
2258
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
2235
2259
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
2236
2260
|
session_id: z.ZodString;
|
|
2237
2261
|
transcript_path: z.ZodString;
|
|
@@ -2988,6 +3012,8 @@ export declare const ControlErrorResponseSchema: () => z.ZodObject<{
|
|
|
2988
3012
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
2989
3013
|
agent_id: z.ZodString;
|
|
2990
3014
|
agent_type: z.ZodString;
|
|
3015
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
3016
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
2991
3017
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
2992
3018
|
session_id: z.ZodString;
|
|
2993
3019
|
transcript_path: z.ZodString;
|
|
@@ -3002,6 +3028,12 @@ export declare const ControlErrorResponseSchema: () => z.ZodObject<{
|
|
|
3002
3028
|
agent_transcript_path: z.ZodString;
|
|
3003
3029
|
agent_type: z.ZodString;
|
|
3004
3030
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
3031
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
3032
|
+
failed: "failed";
|
|
3033
|
+
completed: "completed";
|
|
3034
|
+
stopped: "stopped";
|
|
3035
|
+
}>>;
|
|
3036
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
3005
3037
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
3006
3038
|
session_id: z.ZodString;
|
|
3007
3039
|
transcript_path: z.ZodString;
|
|
@@ -3760,6 +3792,8 @@ export declare const SDKControlResponseSchema: () => z.ZodObject<{
|
|
|
3760
3792
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
3761
3793
|
agent_id: z.ZodString;
|
|
3762
3794
|
agent_type: z.ZodString;
|
|
3795
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
3796
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
3763
3797
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
3764
3798
|
session_id: z.ZodString;
|
|
3765
3799
|
transcript_path: z.ZodString;
|
|
@@ -3774,6 +3808,12 @@ export declare const SDKControlResponseSchema: () => z.ZodObject<{
|
|
|
3774
3808
|
agent_transcript_path: z.ZodString;
|
|
3775
3809
|
agent_type: z.ZodString;
|
|
3776
3810
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
3811
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
3812
|
+
failed: "failed";
|
|
3813
|
+
completed: "completed";
|
|
3814
|
+
stopped: "stopped";
|
|
3815
|
+
}>>;
|
|
3816
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
3777
3817
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
3778
3818
|
session_id: z.ZodString;
|
|
3779
3819
|
transcript_path: z.ZodString;
|
|
@@ -4336,6 +4376,7 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
4336
4376
|
auto: "auto";
|
|
4337
4377
|
}>;
|
|
4338
4378
|
pre_tokens: z.ZodNumber;
|
|
4379
|
+
post_tokens: z.ZodOptional<z.ZodNumber>;
|
|
4339
4380
|
preserved_segment: z.ZodOptional<z.ZodObject<{
|
|
4340
4381
|
head_uuid: z.ZodString;
|
|
4341
4382
|
anchor_uuid: z.ZodString;
|
|
@@ -4579,9 +4620,9 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
4579
4620
|
summarizes_uuid: z.ZodString;
|
|
4580
4621
|
status_category: z.ZodEnum<{
|
|
4581
4622
|
failed: "failed";
|
|
4623
|
+
completed: "completed";
|
|
4582
4624
|
blocked: "blocked";
|
|
4583
4625
|
waiting: "waiting";
|
|
4584
|
-
completed: "completed";
|
|
4585
4626
|
review_ready: "review_ready";
|
|
4586
4627
|
}>;
|
|
4587
4628
|
status_detail: z.ZodString;
|
|
@@ -4974,6 +5015,8 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
4974
5015
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
4975
5016
|
agent_id: z.ZodString;
|
|
4976
5017
|
agent_type: z.ZodString;
|
|
5018
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
5019
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
4977
5020
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
4978
5021
|
session_id: z.ZodString;
|
|
4979
5022
|
transcript_path: z.ZodString;
|
|
@@ -4988,6 +5031,12 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
4988
5031
|
agent_transcript_path: z.ZodString;
|
|
4989
5032
|
agent_type: z.ZodString;
|
|
4990
5033
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
5034
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
5035
|
+
failed: "failed";
|
|
5036
|
+
completed: "completed";
|
|
5037
|
+
stopped: "stopped";
|
|
5038
|
+
}>>;
|
|
5039
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
4991
5040
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
4992
5041
|
session_id: z.ZodString;
|
|
4993
5042
|
transcript_path: z.ZodString;
|
|
@@ -5736,6 +5785,8 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
5736
5785
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
5737
5786
|
agent_id: z.ZodString;
|
|
5738
5787
|
agent_type: z.ZodString;
|
|
5788
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
5789
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
5739
5790
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
5740
5791
|
session_id: z.ZodString;
|
|
5741
5792
|
transcript_path: z.ZodString;
|
|
@@ -5750,6 +5801,12 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
5750
5801
|
agent_transcript_path: z.ZodString;
|
|
5751
5802
|
agent_type: z.ZodString;
|
|
5752
5803
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
5804
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
5805
|
+
failed: "failed";
|
|
5806
|
+
completed: "completed";
|
|
5807
|
+
stopped: "stopped";
|
|
5808
|
+
}>>;
|
|
5809
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
5753
5810
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
5754
5811
|
session_id: z.ZodString;
|
|
5755
5812
|
transcript_path: z.ZodString;
|
|
@@ -6516,6 +6573,8 @@ export declare const StdinMessageSchema: () => z.ZodUnion<readonly [z.ZodObject<
|
|
|
6516
6573
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
6517
6574
|
agent_id: z.ZodString;
|
|
6518
6575
|
agent_type: z.ZodString;
|
|
6576
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
6577
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
6519
6578
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
6520
6579
|
session_id: z.ZodString;
|
|
6521
6580
|
transcript_path: z.ZodString;
|
|
@@ -6530,6 +6589,12 @@ export declare const StdinMessageSchema: () => z.ZodUnion<readonly [z.ZodObject<
|
|
|
6530
6589
|
agent_transcript_path: z.ZodString;
|
|
6531
6590
|
agent_type: z.ZodString;
|
|
6532
6591
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
6592
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
6593
|
+
failed: "failed";
|
|
6594
|
+
completed: "completed";
|
|
6595
|
+
stopped: "stopped";
|
|
6596
|
+
}>>;
|
|
6597
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
6533
6598
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
6534
6599
|
session_id: z.ZodString;
|
|
6535
6600
|
transcript_path: z.ZodString;
|
|
@@ -7286,6 +7351,8 @@ export declare const StdinMessageSchema: () => z.ZodUnion<readonly [z.ZodObject<
|
|
|
7286
7351
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
7287
7352
|
agent_id: z.ZodString;
|
|
7288
7353
|
agent_type: z.ZodString;
|
|
7354
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
7355
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
7289
7356
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
7290
7357
|
session_id: z.ZodString;
|
|
7291
7358
|
transcript_path: z.ZodString;
|
|
@@ -7300,6 +7367,12 @@ export declare const StdinMessageSchema: () => z.ZodUnion<readonly [z.ZodObject<
|
|
|
7300
7367
|
agent_transcript_path: z.ZodString;
|
|
7301
7368
|
agent_type: z.ZodString;
|
|
7302
7369
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
7370
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
7371
|
+
failed: "failed";
|
|
7372
|
+
completed: "completed";
|
|
7373
|
+
stopped: "stopped";
|
|
7374
|
+
}>>;
|
|
7375
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
7303
7376
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
7304
7377
|
session_id: z.ZodString;
|
|
7305
7378
|
transcript_path: z.ZodString;
|
|
@@ -704,6 +704,8 @@ export declare const SubagentStartHookInputSchema: () => z.ZodIntersection<z.Zod
|
|
|
704
704
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
705
705
|
agent_id: z.ZodString;
|
|
706
706
|
agent_type: z.ZodString;
|
|
707
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
708
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
707
709
|
}, z.core.$strip>>;
|
|
708
710
|
export declare const SubagentStopHookInputSchema: () => z.ZodIntersection<z.ZodObject<{
|
|
709
711
|
session_id: z.ZodString;
|
|
@@ -719,6 +721,12 @@ export declare const SubagentStopHookInputSchema: () => z.ZodIntersection<z.ZodO
|
|
|
719
721
|
agent_transcript_path: z.ZodString;
|
|
720
722
|
agent_type: z.ZodString;
|
|
721
723
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
724
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
725
|
+
failed: "failed";
|
|
726
|
+
completed: "completed";
|
|
727
|
+
stopped: "stopped";
|
|
728
|
+
}>>;
|
|
729
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
722
730
|
}, z.core.$strip>>;
|
|
723
731
|
export declare const PreCompactHookInputSchema: () => z.ZodIntersection<z.ZodObject<{
|
|
724
732
|
session_id: z.ZodString;
|
|
@@ -1117,6 +1125,8 @@ export declare const HookInputSchema: () => z.ZodUnion<readonly [z.ZodIntersecti
|
|
|
1117
1125
|
hook_event_name: z.ZodLiteral<"SubagentStart">;
|
|
1118
1126
|
agent_id: z.ZodString;
|
|
1119
1127
|
agent_type: z.ZodString;
|
|
1128
|
+
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
1129
|
+
is_background: z.ZodOptional<z.ZodBoolean>;
|
|
1120
1130
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
1121
1131
|
session_id: z.ZodString;
|
|
1122
1132
|
transcript_path: z.ZodString;
|
|
@@ -1131,6 +1141,12 @@ export declare const HookInputSchema: () => z.ZodUnion<readonly [z.ZodIntersecti
|
|
|
1131
1141
|
agent_transcript_path: z.ZodString;
|
|
1132
1142
|
agent_type: z.ZodString;
|
|
1133
1143
|
last_assistant_message: z.ZodOptional<z.ZodString>;
|
|
1144
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
1145
|
+
failed: "failed";
|
|
1146
|
+
completed: "completed";
|
|
1147
|
+
stopped: "stopped";
|
|
1148
|
+
}>>;
|
|
1149
|
+
error_message: z.ZodOptional<z.ZodString>;
|
|
1134
1150
|
}, z.core.$strip>>, z.ZodIntersection<z.ZodObject<{
|
|
1135
1151
|
session_id: z.ZodString;
|
|
1136
1152
|
transcript_path: z.ZodString;
|
|
@@ -2486,6 +2502,7 @@ export declare const SDKCompactBoundaryMessageSchema: () => z.ZodObject<{
|
|
|
2486
2502
|
auto: "auto";
|
|
2487
2503
|
}>;
|
|
2488
2504
|
pre_tokens: z.ZodNumber;
|
|
2505
|
+
post_tokens: z.ZodOptional<z.ZodNumber>;
|
|
2489
2506
|
preserved_segment: z.ZodOptional<z.ZodObject<{
|
|
2490
2507
|
head_uuid: z.ZodString;
|
|
2491
2508
|
anchor_uuid: z.ZodString;
|
|
@@ -2515,9 +2532,9 @@ export declare const SDKPostTurnSummaryMessageSchema: () => z.ZodObject<{
|
|
|
2515
2532
|
summarizes_uuid: z.ZodString;
|
|
2516
2533
|
status_category: z.ZodEnum<{
|
|
2517
2534
|
failed: "failed";
|
|
2535
|
+
completed: "completed";
|
|
2518
2536
|
blocked: "blocked";
|
|
2519
2537
|
waiting: "waiting";
|
|
2520
|
-
completed: "completed";
|
|
2521
2538
|
review_ready: "review_ready";
|
|
2522
2539
|
}>;
|
|
2523
2540
|
status_detail: z.ZodString;
|
|
@@ -2894,6 +2911,7 @@ export declare const SDKMessageSchema: () => z.ZodUnion<readonly [z.ZodObject<{
|
|
|
2894
2911
|
auto: "auto";
|
|
2895
2912
|
}>;
|
|
2896
2913
|
pre_tokens: z.ZodNumber;
|
|
2914
|
+
post_tokens: z.ZodOptional<z.ZodNumber>;
|
|
2897
2915
|
preserved_segment: z.ZodOptional<z.ZodObject<{
|
|
2898
2916
|
head_uuid: z.ZodString;
|
|
2899
2917
|
anchor_uuid: z.ZodString;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
+
import type { ModelProviders } from '../../providers/shared/routing.js';
|
|
3
|
+
export type { ModelProviders, ModelProviderConfig } from '../../providers/shared/routing.js';
|
|
2
4
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
5
|
import type { CallToolResult, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
|
|
4
6
|
import type { z } from 'zod/v4';
|
|
@@ -15,6 +17,15 @@ export type Query = AsyncIterable<SDKMessage> & {
|
|
|
15
17
|
* cancel a long turn without ending the whole query.
|
|
16
18
|
*/
|
|
17
19
|
interrupt(): Promise<void> | void;
|
|
20
|
+
/**
|
|
21
|
+
* Abort a single in-flight run_in_background sub-agent by its agentId, without
|
|
22
|
+
* touching the main turn or other agents. The agent's AbortController is
|
|
23
|
+
* signalled (killAsyncAgent), so its in-flight tool calls unwind cleanly.
|
|
24
|
+
* No-op if the agent is unknown or already settled. Lets a host surface a
|
|
25
|
+
* per-agent "stop" affordance (desktop UI) on top of the model-facing
|
|
26
|
+
* TaskStop tool.
|
|
27
|
+
*/
|
|
28
|
+
killAgent(agentId: string): void;
|
|
18
29
|
};
|
|
19
30
|
/** @internal */
|
|
20
31
|
export type InternalQuery = Query;
|
|
@@ -149,6 +160,14 @@ export type Options = {
|
|
|
149
160
|
* Values < 10_000 or > 5_000_000 are dropped + warn-logged (table fallback).
|
|
150
161
|
*/
|
|
151
162
|
contextWindow?: number;
|
|
163
|
+
/**
|
|
164
|
+
* 本回合手动压缩上下文(对应 host 的 /compact)。设置后 SDK 复用 auto-compact
|
|
165
|
+
* 机制(isAutoCompact=false + 这些指令)压缩当前消息、发出 system/compact_boundary,
|
|
166
|
+
* 随后结束本回合而不调用模型。单次信号——仅作用于携带它的那次 query()。
|
|
167
|
+
*/
|
|
168
|
+
compact?: {
|
|
169
|
+
instructions?: string;
|
|
170
|
+
};
|
|
152
171
|
includePartialMessages?: boolean;
|
|
153
172
|
replayUserMessages?: boolean;
|
|
154
173
|
permissionMode?: string;
|
|
@@ -217,6 +236,17 @@ export type Options = {
|
|
|
217
236
|
*/
|
|
218
237
|
agents?: readonly unknown[];
|
|
219
238
|
disallowedTools?: string[];
|
|
239
|
+
/**
|
|
240
|
+
* Tool names hidden from sub-agents (Agent/Task spawns) only — the main
|
|
241
|
+
* loop keeps them. Use this for MCP tools a sub-agent must not see (e.g. an
|
|
242
|
+
* interactive form/question capability): native UI tools like AskUserQuestion
|
|
243
|
+
* and EnterPlanMode are ALREADY excluded from every sub-agent, but MCP tools
|
|
244
|
+
* are not, so list them here. Matched with the same rules as `disallowedTools`,
|
|
245
|
+
* so MCP server-prefix (`mcp__server`) and wildcard (`mcp__server__*`) work.
|
|
246
|
+
* Unlike `disallowedTools` (a session-wide deny), this does NOT affect the
|
|
247
|
+
* main conversation.
|
|
248
|
+
*/
|
|
249
|
+
subagentDisallowedTools?: string[];
|
|
220
250
|
hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
221
251
|
/**
|
|
222
252
|
* Pre-execute lifecycle hook. Invoked SYNCHRONOUSLY (the SDK awaits the
|
|
@@ -271,6 +301,17 @@ export type Options = {
|
|
|
271
301
|
* Accepted at runtime with console.warn; remove call sites by 0.3.0.
|
|
272
302
|
*/
|
|
273
303
|
transport?: ProviderTransport | DeprecatedProviderTransportName | 'auto';
|
|
304
|
+
/**
|
|
305
|
+
* Host model → provider-route catalog, keyed by model id. Consulted AFTER
|
|
306
|
+
* subagent model resolution (tier aliases / Agent tool `model` param), so
|
|
307
|
+
* a subagent whose model lives on a different wire or endpoint than the
|
|
308
|
+
* main session routes to its own baseURL/key/transport instead of
|
|
309
|
+
* inheriting the session's (which 404s for cross-protocol tier models).
|
|
310
|
+
* Models absent from the catalog use the session provider config as
|
|
311
|
+
* before. Entries may carry `providerSpecific.openaiResponses` extras
|
|
312
|
+
* applied when that model's request uses the openai_responses wire.
|
|
313
|
+
*/
|
|
314
|
+
modelProviders?: ModelProviders;
|
|
274
315
|
/**
|
|
275
316
|
* Per-protocol passthrough channel for fields the wire supports but the
|
|
276
317
|
* SDK does not surface as first-class options. The shim merges these
|
package/dist/lib/envDynamic.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare const envDynamic: {
|
|
|
23
23
|
initJetBrainsDetection: typeof initJetBrainsDetection;
|
|
24
24
|
hasInternetAccess: any;
|
|
25
25
|
isCI: boolean;
|
|
26
|
-
platform: "
|
|
26
|
+
platform: "linux" | "win32" | "darwin";
|
|
27
27
|
arch: NodeJS.Architecture;
|
|
28
28
|
nodeVersion: string;
|
|
29
29
|
isSSH: () => boolean;
|
|
@@ -19,6 +19,21 @@ export declare function getAllowRules(context: ToolPermissionContext): Permissio
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function createPermissionRequestMessage(toolName: string, decisionReason?: PermissionDecisionReason): string;
|
|
21
21
|
export declare function getDenyRules(context: ToolPermissionContext): PermissionRule[];
|
|
22
|
+
/**
|
|
23
|
+
* 把禁用工具名烘焙进权限上下文,作为 session 级 deny 规则。SDK 模式借此让
|
|
24
|
+
* Options.disallowedTools 经由共享的 deny 规则过滤,作用到每一处工具池组装——
|
|
25
|
+
* 主循环、子代理、fork。子代理会从它继承的权限上下文重建自己的工具池,所以仅在
|
|
26
|
+
* 主池上事后过滤的名字,否则会泄漏进子代理(并能通过 ToolSearch 被检索到)。
|
|
27
|
+
* 与 CLI 把 --disallowedTools 路由进 alwaysDenyRules 的做法一致。
|
|
28
|
+
*/
|
|
29
|
+
export declare function denySessionTools(context: ToolPermissionContext, toolNames: readonly string[] | undefined): ToolPermissionContext;
|
|
30
|
+
/**
|
|
31
|
+
* 过滤掉「仅对子代理隐藏」的工具(Options.subagentDisallowedTools)。复用与
|
|
32
|
+
* disallowedTools 同一套 deny 规则匹配,因此 MCP server 前缀('mcp__server')和
|
|
33
|
+
* 通配符('mcp__server__*')都能命中整组工具——不像裸 `Set.has(tool.name)` 只认精确全名。
|
|
34
|
+
* 在每个子代理工具池组装后调用(runAgent),主循环不调用,故对主循环无影响。
|
|
35
|
+
*/
|
|
36
|
+
export declare function filterSubagentDisallowedTools<T extends Pick<ToolRuntime, 'name' | 'mcpInfo'>>(tools: readonly T[], subagentDisallowedTools: readonly string[] | undefined): readonly T[];
|
|
22
37
|
export declare function getAskRules(context: ToolPermissionContext): PermissionRule[];
|
|
23
38
|
/**
|
|
24
39
|
* Check if the entire tool is listed in the always allow rules
|
|
@@ -68,9 +68,9 @@ export declare const CodeSessionSchema: () => z.ZodObject<{
|
|
|
68
68
|
title: z.ZodString;
|
|
69
69
|
description: z.ZodString;
|
|
70
70
|
status: z.ZodEnum<{
|
|
71
|
+
completed: "completed";
|
|
71
72
|
rejected: "rejected";
|
|
72
73
|
waiting: "waiting";
|
|
73
|
-
completed: "completed";
|
|
74
74
|
cancelled: "cancelled";
|
|
75
75
|
idle: "idle";
|
|
76
76
|
working: "working";
|
|
@@ -125,6 +125,14 @@ export declare function performCodexRequest(options: {
|
|
|
125
125
|
/** Host-provided Responses-protocol-specific fields (merged into body). */
|
|
126
126
|
providerSpecific?: ResponsesProviderSpecific;
|
|
127
127
|
}): Promise<Response>;
|
|
128
|
+
/**
|
|
129
|
+
* 上游 `response.failed` 的错误若是「prompt 太长 / 上下文超限」,必须用非重试态 400 抛出。
|
|
130
|
+
* 否则 shouldRetry 把它当 5xx 服务端错误重试 MAX_RETRIES 次——同样超长的 prompt 原样重发
|
|
131
|
+
* 必然再失败,纯属浪费;且要等重试耗尽才轮到 query loop 的 reactive 压缩。400 让它即时浮现,
|
|
132
|
+
* 第一次就触发一次压缩重试(formatAPIError 仍按消息归一为 PROMPT_TOO_LONG_ERROR_MESSAGE,
|
|
133
|
+
* reactive 据此识别)。其余失败保持 500(可能是真·瞬时服务端错误,该重试)。
|
|
134
|
+
*/
|
|
135
|
+
export declare function codexFailureStatus(errorMessage: string): number;
|
|
128
136
|
export declare function collectCodexCompletedResponse(response: Response): Promise<Record<string, any>>;
|
|
129
137
|
export declare function codexStreamToAnthropic(response: Response, model: string): AsyncGenerator<AnthropicStreamEvent>;
|
|
130
138
|
export declare function convertCodexResponseToAnthropicMessage(data: Record<string, any>, model: string): Record<string, unknown>;
|