@opencow-ai/opencow-agent-sdk 0.4.23 → 0.4.25
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/capabilities/SdkTool.d.ts +5 -0
- package/dist/capabilities/tools/AgentTool/AgentTool.d.ts +1 -0
- package/dist/capabilities/tools/AgentTool/agentMerge.d.ts +1 -0
- package/dist/capabilities/tools/AgentTool/runAgent.d.ts +3 -3
- package/dist/cli.mjs +64022 -76785
- package/dist/client.js +31615 -93160
- package/dist/constants/envVars.d.ts +4 -0
- package/dist/controller/dispatch/permissionPreDecision.d.ts +22 -0
- package/dist/controller/loop.d.ts +5 -0
- package/dist/entrypoints/sdk/runtimeTypes.d.ts +11 -0
- package/dist/lib/toolInputNullCoercion.d.ts +1 -1
- package/dist/providers/shared/retry.d.ts +33 -1
- package/dist/sdk.js +31615 -93160
- package/dist/session/forkedAgent.d.ts +2 -1
- package/dist/session/tokens.d.ts +2 -1
- package/dist/types/replayState.d.ts +13 -0
- package/dist/types/toolRuntime.d.ts +18 -0
- package/package.json +1 -1
|
@@ -235,6 +235,10 @@ export declare const ENV_VARS: {
|
|
|
235
235
|
readonly DEBUG_INPUT: EnvVarSpec;
|
|
236
236
|
readonly DISABLE_EARLY_INPUT: EnvVarSpec;
|
|
237
237
|
readonly ENABLE_EXTENDED_KEYS: EnvVarSpec;
|
|
238
|
+
readonly ENABLE_STREAM_WATCHDOG: EnvVarSpec;
|
|
239
|
+
readonly STREAM_IDLE_TIMEOUT_MS: EnvVarSpec;
|
|
240
|
+
readonly UNBOUNDED_CONNECTION_RETRY: EnvVarSpec;
|
|
241
|
+
readonly STREAM_REPLAY_RETRIES: EnvVarSpec;
|
|
238
242
|
readonly USE_READABLE_STDIN: EnvVarSpec;
|
|
239
243
|
};
|
|
240
244
|
export type EnvVarKey = keyof typeof ENV_VARS;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CanonicalToolUseBlock as ToolUseBlock } from '../../session/canonical/index.js';
|
|
2
|
+
import { type CanUseToolFn, type ToolRuntimeContext } from '../../types/toolRuntime.js';
|
|
3
|
+
import type { AssistantMessage } from '../../types/message.js';
|
|
4
|
+
import type { PermissionResult } from '../../types/permissions.js';
|
|
5
|
+
/**
|
|
6
|
+
* 权限决策前置:runTools() 入口对同批全部 tool_use 并发预调 canUseTool,把
|
|
7
|
+
* 决策 promise 缓存到 toolUseContext.permissionPreDecisions;工具仍按原顺序
|
|
8
|
+
* 独占执行,执行时经 consumePermissionPreDecision 消费缓存,避免串行批里
|
|
9
|
+
* host 审批逐个阻塞弹出。
|
|
10
|
+
*
|
|
11
|
+
* 与执行期(checkPermissionsAndCallTool)对齐的规范化:找不到 tool runtime、
|
|
12
|
+
* zod 校验失败的块跳过(执行期走各自的内联错误路径,本就不该有预决策);
|
|
13
|
+
* backfillObservableInput 在浅克隆上调用,与执行期 backfill 后的 observable
|
|
14
|
+
* input 保持一致,保证消费时深比较有命中机会。
|
|
15
|
+
*/
|
|
16
|
+
export declare function startPermissionPreDecisions(blocks: ToolUseBlock[], assistantMessages: AssistantMessage[], canUseTool: CanUseToolFn, toolUseContext: ToolRuntimeContext): void;
|
|
17
|
+
/**
|
|
18
|
+
* 一次性消费预决策:无缓存 / input 与执行期不一致(hook 改写等)时回退
|
|
19
|
+
* fallback 内联询问;命中则返回缓存 promise。无论命中与否,条目取出即删——
|
|
20
|
+
* 后续同名 tool_use(如 forceDecision 场景)必须重新询问。
|
|
21
|
+
*/
|
|
22
|
+
export declare function consumePermissionPreDecision(toolUseContext: ToolRuntimeContext, toolUseID: string, input: Record<string, unknown>, fallback: () => Promise<PermissionResult>): Promise<PermissionResult>;
|
|
@@ -26,6 +26,11 @@ export declare function adjustParamsForNonStreaming<T extends {
|
|
|
26
26
|
* tool schemas, session identity, caching strategy, and host callbacks.
|
|
27
27
|
*/
|
|
28
28
|
export type Options = {
|
|
29
|
+
/**
|
|
30
|
+
* 内部:由 replayStreamOnTransportError 置位。为 true 时,读流阶段的可重放传输错误
|
|
31
|
+
* (且尚无完整消息送出)作为异常抛给调用方重放,而不是转成 assistant 错误消息。
|
|
32
|
+
*/
|
|
33
|
+
streamReplayEscape?: boolean;
|
|
29
34
|
getToolPermissionContext: () => Promise<ToolPermissionContext>;
|
|
30
35
|
model: string;
|
|
31
36
|
toolChoice?: BetaToolChoiceTool | BetaToolChoiceAuto | undefined;
|
|
@@ -287,6 +287,17 @@ export type Options = {
|
|
|
287
287
|
replayUserMessages?: boolean;
|
|
288
288
|
permissionMode?: string;
|
|
289
289
|
canUseTool?: SdkCanUseTool;
|
|
290
|
+
/**
|
|
291
|
+
* 权限决策前置。开启后,同一批 queued tool_use 的 canUseTool 会在工具调度
|
|
292
|
+
* 入口并发预调并缓存结果;工具仍按原顺序独占执行(串行语义、context
|
|
293
|
+
* modifier 顺序、级联取消均不变),执行时消费缓存决策,不再逐个阻塞等待
|
|
294
|
+
* host 审批。PreToolUse hook 改写 input 或给出 ask 消息时缓存自动 miss,
|
|
295
|
+
* 回退执行期内联询问。
|
|
296
|
+
*
|
|
297
|
+
* mechanism / policy 分层:SDK 只提供预决策机制,默认 false,是否开启由
|
|
298
|
+
* host 决定(host 需接受 canUseTool 被并发调用)。
|
|
299
|
+
*/
|
|
300
|
+
preDecidePermissions?: boolean;
|
|
290
301
|
mcpServers?: Record<string, McpServerConfig>;
|
|
291
302
|
/**
|
|
292
303
|
* Selects the SDK-owned built-in tool set for this query.
|
|
@@ -20,4 +20,4 @@ import type { z } from 'zod/v4';
|
|
|
20
20
|
* 习惯性回传 `null`,只剥顶层会漏掉它们、导致整个阻塞工具因校验失败被跳过(handler
|
|
21
21
|
* 不执行、不阻塞,对话直接溜到下一轮)。
|
|
22
22
|
*/
|
|
23
|
-
export declare function safeParseToolInputWithNullCoercion<T extends z.ZodType>(schema: T, input: unknown): ReturnType<T['safeParse']>;
|
|
23
|
+
export declare function safeParseToolInputWithNullCoercion<T extends z.ZodType>(schema: T, input: unknown, unknownKeys?: 'strip' | 'reject'): ReturnType<T['safeParse']>;
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
import { APIError } from '@anthropic-ai/sdk';
|
|
2
|
+
import { APIConnectionError, APIError } from '@anthropic-ai/sdk';
|
|
3
3
|
import type { QuerySource } from 'src/constants/querySource.js';
|
|
4
4
|
import type { SystemAPIErrorMessage } from 'src/types/message.js';
|
|
5
5
|
import type { ThinkingConfig } from '../../lib/thinking.js';
|
|
6
6
|
export declare const BASE_DELAY_MS = 500;
|
|
7
|
+
/**
|
|
8
|
+
* 200 头已到、读 body 时连接被切断,Anthropic SDK 抛的是原始 TypeError,
|
|
9
|
+
* 不经过它自己的连接错误包装;不补包装就会落入下方「非 APIError 不重试」。
|
|
10
|
+
* 只认传输特征(cause 带系统错误码或固定文案),普通 TypeError 仍按程序错误处理。
|
|
11
|
+
*/
|
|
12
|
+
export declare function wrapBodyTransportError(error: unknown): unknown;
|
|
13
|
+
/** 读流阶段的传输中断(对端关闭、socket 断开、空闲看门狗中止)可以整条请求重放;其余不行。 */
|
|
14
|
+
export declare function toReplayableStreamError(error: unknown): APIConnectionError | null;
|
|
15
|
+
/**
|
|
16
|
+
* 流式响应读到一半断开、且还没有任何完整消息送出时,整个流式请求重放。
|
|
17
|
+
* 只在宿主显式给出重放次数时启用(默认 0 = 关闭,行为不变)。
|
|
18
|
+
* `run(escapable)`:前 maxReplays 次尝试 escapable=true,允许 queryModel 把可重放的流错误
|
|
19
|
+
* 作为异常抛出(否则它会把错误转成一条 assistant 错误消息);最后一次 escapable=false,
|
|
20
|
+
* 错误照常转成消息,所以总尝试次数是 maxReplays + 1,最终报错文案与不开启时一致。
|
|
21
|
+
* 已有完整 assistant 消息送出(工具可能已在执行)则不重放,避免重复执行;
|
|
22
|
+
* 重放前送出的 stream_event 半截内容由新的 message_start 取代。
|
|
23
|
+
* 建立连接阶段的失败由 withRetry 处理,这里只管读流阶段。
|
|
24
|
+
*/
|
|
25
|
+
export declare function replayStreamOnTransportError<T extends {
|
|
26
|
+
type: string;
|
|
27
|
+
}>(run: (escapable: boolean) => AsyncGenerator<T, void>, options: {
|
|
28
|
+
maxReplays: number;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
delayMs?: (replay: number) => number;
|
|
31
|
+
}): AsyncGenerator<T | SystemAPIErrorMessage, void>;
|
|
32
|
+
export declare function getConnectionWaitDelay(attempt: number, backoff?: ConnectionWaitBackoff, random?: () => number): number;
|
|
7
33
|
export interface RetryContext {
|
|
8
34
|
maxTokensOverride?: number;
|
|
9
35
|
model: string;
|
|
10
36
|
thinkingConfig: ThinkingConfig;
|
|
11
37
|
fastMode?: boolean;
|
|
12
38
|
}
|
|
39
|
+
export interface ConnectionWaitBackoff {
|
|
40
|
+
initialMs: number;
|
|
41
|
+
maxMs: number;
|
|
42
|
+
}
|
|
13
43
|
interface RetryOptions {
|
|
44
|
+
/** 连接错误等待的退避节奏,默认 5s 起翻倍、上限 60s;主要供测试缩短等待。 */
|
|
45
|
+
connectionWaitBackoff?: ConnectionWaitBackoff;
|
|
14
46
|
maxRetries?: number;
|
|
15
47
|
model: string;
|
|
16
48
|
fallbackModel?: string;
|