@anthropic-ai/claude-agent-sdk 0.2.91 → 0.2.94

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/assistant.d.ts ADDED
@@ -0,0 +1,135 @@
1
+ /**
2
+ * API surface definition for @anthropic-ai/claude-agent-sdk/assistant.
3
+ *
4
+ * Source of truth for the /assistant export's public types. Imports ONLY
5
+ * from agentSdkTypes.ts so the compiled .d.ts has exactly one import to
6
+ * rewrite (./agentSdkTypes → ./sdk) for the flat package layout.
7
+ *
8
+ * Compiled by scripts/build-ant-sdk-typings.sh; runtime in
9
+ * agentSdkAssistant.ts (bun-built to assistant.mjs).
10
+ *
11
+ * Type definitions below are copied from src/assistant/worker.ts and
12
+ * src/assistant/daemonBridge.ts. Keep in sync — those are the
13
+ * implementation source of truth.
14
+ */
15
+ import type { CanUseTool, ConnectRemoteControlOptions, InboundPrompt, Options, PermissionResult, SDKMessage, SDKUserMessage } from './agentSdkTypes.js';
16
+ export type { ConnectRemoteControlOptions, InboundPrompt };
17
+ /**
18
+ * Worker-persisted state. Checkpointed on turn boundaries, bridge
19
+ * reconnects, and teardown.
20
+ * @alpha
21
+ */
22
+ export type WorkerState = {
23
+ claudeSessionId?: string;
24
+ lastSSESequenceNum?: number;
25
+ bridgeSessionId?: string;
26
+ };
27
+ /** @alpha */
28
+ export type WorkerStateAdapter = {
29
+ load(): Promise<WorkerState | null>;
30
+ save(state: WorkerState): Promise<void>;
31
+ };
32
+ /**
33
+ * Third argument to the SDK's CanUseTool callback.
34
+ * @alpha
35
+ */
36
+ export type CanUseToolContext = Parameters<CanUseTool>[2];
37
+ /**
38
+ * Structured failure from `runAssistantWorker`. `kind` lets callers branch
39
+ * on handling — conflict UI, retry with backoff, or bail.
40
+ * @alpha
41
+ */
42
+ export type AssistantWorkerError = {
43
+ kind: 'conflict' | 'auth' | 'network' | 'unknown';
44
+ detail: string;
45
+ };
46
+ /** @alpha */
47
+ export type AssistantWorkerResult = {
48
+ ok: true;
49
+ handle: AssistantWorkerHandle;
50
+ } | {
51
+ ok: false;
52
+ error: AssistantWorkerError;
53
+ };
54
+ /** @alpha */
55
+ export type AssistantWorkerOptions = {
56
+ /**
57
+ * Bridge connection config — passed through to `connectRemoteControl`.
58
+ * `initialSSESequenceNum` is seeded from `stateAdapter.load()` if unset.
59
+ */
60
+ bridge: ConnectRemoteControlOptions;
61
+ /**
62
+ * Runs in a sandbox (VM, container) where the sandbox boundary IS the
63
+ * trust boundary. Injects `CLAUDE_CODE_SANDBOXED=1` so the CLI's
64
+ * directory trust check passes. Default false.
65
+ */
66
+ sandboxed?: boolean;
67
+ /**
68
+ * Cron-horizon polling. Worker reads `<dir>/.claude/scheduled_tasks.json`
69
+ * every 10s and spawns the child ~5s before a fire is due. Omit to
70
+ * disable cron-driven spawn.
71
+ */
72
+ scheduling?: {
73
+ dir: string;
74
+ horizonMs?: number;
75
+ leadMs?: number;
76
+ };
77
+ /**
78
+ * Called each time the worker spawns query(). `base` carries
79
+ * `assistant:true`, `cwd`, `resume`, `stderr`, and the worker's
80
+ * bridge-wired `canUseTool`. Spread over `base` to add MCP servers,
81
+ * VM spawn, env vars, system prompt, tool lists.
82
+ *
83
+ * May be async — dispatch awaits VM spawn, system prompt build, and
84
+ * OAuth token fetch before each query() spawn.
85
+ */
86
+ buildQueryOptions: (base: Options) => Options | Promise<Options>;
87
+ /**
88
+ * Called BEFORE the bridge permission prompt. Return a PermissionResult
89
+ * to short-circuit; undefined to fall through to the bridge.
90
+ */
91
+ canUseToolPreFilter?: (toolName: string, input: Record<string, unknown>, ctx: CanUseToolContext) => Promise<PermissionResult | undefined>;
92
+ /**
93
+ * Called AFTER the bridge resolves (or pre-filter short-circuits).
94
+ * Lets callers persist "always allow" to their own cache.
95
+ */
96
+ onPermissionResolved?: (toolName: string, result: PermissionResult) => void;
97
+ /**
98
+ * Applied to every SDKMessage after the worker's own filter, before
99
+ * bridge write. Return null to drop. Used for VM→host path translation.
100
+ */
101
+ transformOutbound?: (msg: SDKMessage) => SDKMessage | null;
102
+ /**
103
+ * Where to persist WorkerState. Omit to run stateless — fresh
104
+ * claudeSessionId and SSE seq on every restart.
105
+ */
106
+ stateAdapter?: WorkerStateAdapter;
107
+ /**
108
+ * Pushed into the input queue at worker start. Daemon passes install.md
109
+ * on first-run; dispatch passes seed messages or omits.
110
+ */
111
+ initialPrompt?: string;
112
+ /** Despawn child after this much quiet. Default 5 minutes. */
113
+ userIdleMs?: number;
114
+ signal: AbortSignal;
115
+ log?: (msg: string) => void;
116
+ };
117
+ /** @alpha */
118
+ export type AssistantWorkerHandle = {
119
+ readonly sessionUrl: string;
120
+ readonly bridgeSessionId: string;
121
+ readonly claudeSessionId: string | undefined;
122
+ /** Push a prompt into the input queue without going through the bridge. */
123
+ pushPrompt(content: string | SDKUserMessage['message']['content']): void;
124
+ interrupt(): Promise<void>;
125
+ /** Resolves when the fan-in loop exits and teardown completes. */
126
+ done: Promise<void>;
127
+ teardown(): Promise<void>;
128
+ };
129
+ /**
130
+ * Run a single-session assistant worker: connect to the claude.ai bridge,
131
+ * spawn query() on demand (inbound prompt or cron due), proxy permissions
132
+ * through the bridge, despawn on idle.
133
+ * @alpha
134
+ */
135
+ export declare function runAssistantWorker(opts: AssistantWorkerOptions): Promise<AssistantWorkerResult>;