noumen 0.1.0 → 0.3.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/README.md +846 -51
- package/dist/a2a/index.d.ts +148 -0
- package/dist/a2a/index.js +579 -0
- package/dist/a2a/index.js.map +1 -0
- package/dist/acp/index.d.ts +129 -0
- package/dist/acp/index.js +498 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/agent-1nFVUP9E.d.ts +1332 -0
- package/dist/cache-DsRqxx6v.d.ts +38 -0
- package/dist/chunk-3HEYCV26.js +10 -0
- package/dist/chunk-3HEYCV26.js.map +1 -0
- package/dist/chunk-3SK5GCI6.js +75 -0
- package/dist/chunk-3SK5GCI6.js.map +1 -0
- package/dist/chunk-42PHHZUA.js +132 -0
- package/dist/chunk-42PHHZUA.js.map +1 -0
- package/dist/chunk-4HW6LN6D.js +10365 -0
- package/dist/chunk-4HW6LN6D.js.map +1 -0
- package/dist/chunk-4SQA2UCV.js +26 -0
- package/dist/chunk-4SQA2UCV.js.map +1 -0
- package/dist/chunk-5GEX6ZSB.js +179 -0
- package/dist/chunk-5GEX6ZSB.js.map +1 -0
- package/dist/chunk-5JN4SPI7.js +94 -0
- package/dist/chunk-5JN4SPI7.js.map +1 -0
- package/dist/chunk-AMYIJSAZ.js +57 -0
- package/dist/chunk-AMYIJSAZ.js.map +1 -0
- package/dist/chunk-BZSFUEWM.js +43 -0
- package/dist/chunk-BZSFUEWM.js.map +1 -0
- package/dist/chunk-CS6WNDCF.js +171 -0
- package/dist/chunk-CS6WNDCF.js.map +1 -0
- package/dist/chunk-D43BWEZA.js +346 -0
- package/dist/chunk-D43BWEZA.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-EKOGVTBT.js +472 -0
- package/dist/chunk-EKOGVTBT.js.map +1 -0
- package/dist/chunk-HEQQQGK5.js +131 -0
- package/dist/chunk-HEQQQGK5.js.map +1 -0
- package/dist/chunk-HL6JCRZJ.js +3112 -0
- package/dist/chunk-HL6JCRZJ.js.map +1 -0
- package/dist/chunk-JACGEMTF.js +43 -0
- package/dist/chunk-JACGEMTF.js.map +1 -0
- package/dist/chunk-JX7CLUCV.js +21 -0
- package/dist/chunk-JX7CLUCV.js.map +1 -0
- package/dist/chunk-KXDB56YW.js +39 -0
- package/dist/chunk-KXDB56YW.js.map +1 -0
- package/dist/chunk-L3L3FG5T.js +16 -0
- package/dist/chunk-L3L3FG5T.js.map +1 -0
- package/dist/chunk-OGXNFXFA.js +196 -0
- package/dist/chunk-OGXNFXFA.js.map +1 -0
- package/dist/chunk-UVSSQBDY.js +192 -0
- package/dist/chunk-UVSSQBDY.js.map +1 -0
- package/dist/chunk-Y45R3PQL.js +684 -0
- package/dist/chunk-Y45R3PQL.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +874 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/index.d.ts +64 -0
- package/dist/client/index.js +409 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client-CRRO2376.js +10 -0
- package/dist/client-CRRO2376.js.map +1 -0
- package/dist/headless-FFU2DESQ.js +142 -0
- package/dist/headless-FFU2DESQ.js.map +1 -0
- package/dist/history-snip-64GYP4ZL.js +12 -0
- package/dist/history-snip-64GYP4ZL.js.map +1 -0
- package/dist/index.d.ts +1459 -422
- package/dist/index.js +398 -1757
- package/dist/index.js.map +1 -1
- package/dist/jsonrpc/index.d.ts +54 -0
- package/dist/jsonrpc/index.js +34 -0
- package/dist/jsonrpc/index.js.map +1 -0
- package/dist/lsp/index.d.ts +36 -0
- package/dist/lsp/index.js +16 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp-PS3BWIHC.js +8 -0
- package/dist/lsp-PS3BWIHC.js.map +1 -0
- package/dist/manager-DLXK63XC.js +8 -0
- package/dist/manager-DLXK63XC.js.map +1 -0
- package/dist/mcp/index.d.ts +111 -0
- package/dist/mcp/index.js +105 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp-auth-AEI2R4ZC.js +9 -0
- package/dist/mcp-auth-AEI2R4ZC.js.map +1 -0
- package/dist/provider-factory-KCLIF34X.js +20 -0
- package/dist/provider-factory-KCLIF34X.js.map +1 -0
- package/dist/providers/anthropic.d.ts +19 -0
- package/dist/providers/anthropic.js +35 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/bedrock.d.ts +39 -0
- package/dist/providers/bedrock.js +56 -0
- package/dist/providers/bedrock.js.map +1 -0
- package/dist/providers/gemini.d.ts +17 -0
- package/dist/providers/gemini.js +262 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/ollama.d.ts +13 -0
- package/dist/providers/ollama.js +20 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +21 -0
- package/dist/providers/openai.js +9 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +16 -0
- package/dist/providers/openrouter.js +24 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/vertex.d.ts +42 -0
- package/dist/providers/vertex.js +67 -0
- package/dist/providers/vertex.js.map +1 -0
- package/dist/render-GRN4ZSSW.js +14 -0
- package/dist/render-GRN4ZSSW.js.map +1 -0
- package/dist/resolve-4JA2BBDA.js +14 -0
- package/dist/resolve-4JA2BBDA.js.map +1 -0
- package/dist/server/index.d.ts +143 -0
- package/dist/server/index.js +695 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server-CHMxuWKq.d.ts +96 -0
- package/dist/spinner-OJNR6NFO.js +8 -0
- package/dist/spinner-OJNR6NFO.js.map +1 -0
- package/dist/types-2kTLUCnD.d.ts +107 -0
- package/dist/types-CD0rUKKT.d.ts +109 -0
- package/dist/types-LrU4LRmX.d.ts +575 -0
- package/dist/types-NIyVwQ4h.d.ts +109 -0
- package/dist/types-QwfylltH.d.ts +71 -0
- package/dist/types-RPKUTu1k.d.ts +645 -0
- package/dist/uuid-RVN2T26F.js +8 -0
- package/dist/uuid-RVN2T26F.js.map +1 -0
- package/dist/zod-7YXKWYMC.js +12 -0
- package/dist/zod-7YXKWYMC.js.map +1 -0
- package/package.json +141 -7
|
@@ -0,0 +1,1332 @@
|
|
|
1
|
+
import { A as AIProvider, S as StreamEvent, b as ChatMessage, E as Entry, U as UUID, d as FileCheckpointSnapshot, f as ContentReplacementRecord$1, g as SessionInfo, M as ModelPricing, h as UsageRecord, i as CostSummary, j as ModelUsageSummary, k as ChatCompletionUsage, l as ThinkingConfig, m as MemoryConfig, O as OutputFormat, e as ContentPart, R as RunOptions, c as CheckpointConfig, n as ToolResult } from './types-LrU4LRmX.js';
|
|
2
|
+
import { j as VirtualComputer, E as ExecOptions, C as CommandResult, V as VirtualFs, T as Tool, H as HookDefinition, S as SubagentConfig, k as SubagentRun, l as TaskStore, e as LspServerManager, m as FileCheckpointManager, n as FileStateCacheConfig, L as LspServerConfig } from './types-RPKUTu1k.js';
|
|
3
|
+
import { C as CacheControlConfig } from './cache-DsRqxx6v.js';
|
|
4
|
+
import { M as McpServerConfig, T as TokenStorage } from './types-2kTLUCnD.js';
|
|
5
|
+
import { c as PermissionHandler, d as PermissionConfig } from './types-CD0rUKKT.js';
|
|
6
|
+
|
|
7
|
+
type ProviderName = "openai" | "anthropic" | "gemini" | "openrouter" | "bedrock" | "vertex" | "ollama";
|
|
8
|
+
declare const DEFAULT_MODELS: Record<string, string>;
|
|
9
|
+
declare const SUPPORTED_PROVIDERS: ProviderName[];
|
|
10
|
+
interface ResolveProviderOptions {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolve a provider from a name string or pass through an AIProvider instance.
|
|
17
|
+
* API key resolution order:
|
|
18
|
+
* 1. Explicit apiKey option
|
|
19
|
+
* 2. Provider-specific env var (OPENAI_API_KEY, etc.)
|
|
20
|
+
* 3. NOUMEN_API_KEY generic env var
|
|
21
|
+
*/
|
|
22
|
+
declare function resolveProvider(input: AIProvider | ProviderName, opts?: ResolveProviderOptions): Promise<AIProvider>;
|
|
23
|
+
/**
|
|
24
|
+
* Auto-detect provider from available environment variables.
|
|
25
|
+
*/
|
|
26
|
+
declare function detectProvider(): Promise<ProviderName | undefined>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Filesystem and network restriction config passed to `@anthropic-ai/sandbox-runtime`.
|
|
30
|
+
*/
|
|
31
|
+
interface SandboxConfig {
|
|
32
|
+
filesystem?: {
|
|
33
|
+
/** Paths the agent may write to (default: `[cwd]`). Write is denied everywhere else. */
|
|
34
|
+
allowWrite?: string[];
|
|
35
|
+
/** Paths to explicitly deny writes within allowed regions. */
|
|
36
|
+
denyWrite?: string[];
|
|
37
|
+
/** Paths to deny reading. By default everything is readable. */
|
|
38
|
+
denyRead?: string[];
|
|
39
|
+
/** Paths to re-allow reading within denyRead regions. Takes precedence over denyRead. */
|
|
40
|
+
allowRead?: string[];
|
|
41
|
+
};
|
|
42
|
+
network?: {
|
|
43
|
+
/** Domains the agent may reach via HTTP/HTTPS/SOCKS. */
|
|
44
|
+
allowedDomains?: string[];
|
|
45
|
+
/** Domains to explicitly block. */
|
|
46
|
+
deniedDomains?: string[];
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface SandboxedLocalComputerOptions {
|
|
50
|
+
defaultCwd?: string;
|
|
51
|
+
defaultTimeout?: number;
|
|
52
|
+
sandbox?: SandboxConfig;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `VirtualComputer` that wraps every command with OS-level sandboxing via
|
|
56
|
+
* `@anthropic-ai/sandbox-runtime`. Uses macOS Seatbelt (`sandbox-exec`) or
|
|
57
|
+
* Linux bubblewrap (`bwrap`) under the hood.
|
|
58
|
+
*/
|
|
59
|
+
declare class SandboxedLocalComputer implements VirtualComputer {
|
|
60
|
+
private defaultCwd;
|
|
61
|
+
private defaultTimeout;
|
|
62
|
+
private sandboxConfig;
|
|
63
|
+
private initPromise;
|
|
64
|
+
private initialized;
|
|
65
|
+
constructor(opts?: SandboxedLocalComputerOptions);
|
|
66
|
+
private buildRuntimeConfig;
|
|
67
|
+
private ensureInitialized;
|
|
68
|
+
executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Tear down the sandbox runtime. Call when the agent is done.
|
|
71
|
+
*/
|
|
72
|
+
dispose(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Minimal subset of the dockerode Container interface used by DockerComputer.
|
|
77
|
+
* Avoids a hard import of dockerode at the module level.
|
|
78
|
+
*/
|
|
79
|
+
interface DockerContainer {
|
|
80
|
+
exec(options: Record<string, unknown>): Promise<{
|
|
81
|
+
start(opts?: Record<string, unknown>): Promise<NodeJS.ReadableStream>;
|
|
82
|
+
inspect(): Promise<{
|
|
83
|
+
ExitCode: number;
|
|
84
|
+
}>;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
interface DockerComputerOptions {
|
|
88
|
+
/** A dockerode Container instance for the target container. */
|
|
89
|
+
container: DockerContainer;
|
|
90
|
+
/** Default working directory for commands (default: /). */
|
|
91
|
+
defaultCwd?: string;
|
|
92
|
+
/** Default timeout in ms for commands (default: 30000). */
|
|
93
|
+
defaultTimeout?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* VirtualComputer backed by command execution inside a Docker container.
|
|
97
|
+
*
|
|
98
|
+
* Requires `dockerode` as an optional peer dependency.
|
|
99
|
+
* The user is responsible for container lifecycle (create, start, stop).
|
|
100
|
+
*/
|
|
101
|
+
declare class DockerComputer implements VirtualComputer {
|
|
102
|
+
private container;
|
|
103
|
+
private defaultCwd;
|
|
104
|
+
private defaultTimeout;
|
|
105
|
+
constructor(opts: DockerComputerOptions);
|
|
106
|
+
executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Minimal subset of the E2B Sandbox interface used by E2BComputer and E2BFs.
|
|
111
|
+
* Avoids a hard import of `e2b` at the module level.
|
|
112
|
+
*/
|
|
113
|
+
interface E2BSandboxInstance {
|
|
114
|
+
commands: {
|
|
115
|
+
run(cmd: string, opts?: {
|
|
116
|
+
cwd?: string;
|
|
117
|
+
timeout?: number;
|
|
118
|
+
envs?: Record<string, string>;
|
|
119
|
+
}): Promise<{
|
|
120
|
+
exitCode: number;
|
|
121
|
+
stdout: string;
|
|
122
|
+
stderr: string;
|
|
123
|
+
}>;
|
|
124
|
+
};
|
|
125
|
+
files: {
|
|
126
|
+
read(path: string, opts?: {
|
|
127
|
+
format?: string;
|
|
128
|
+
}): Promise<string>;
|
|
129
|
+
write(path: string, data: string): Promise<unknown>;
|
|
130
|
+
remove(path: string): Promise<void>;
|
|
131
|
+
makeDir(path: string): Promise<unknown>;
|
|
132
|
+
list(path: string): Promise<Array<{
|
|
133
|
+
name: string;
|
|
134
|
+
path: string;
|
|
135
|
+
type?: string;
|
|
136
|
+
size?: number;
|
|
137
|
+
modifiedTime?: Date;
|
|
138
|
+
}>>;
|
|
139
|
+
exists(path: string): Promise<boolean>;
|
|
140
|
+
getInfo(path: string): Promise<{
|
|
141
|
+
name: string;
|
|
142
|
+
path: string;
|
|
143
|
+
type?: string;
|
|
144
|
+
size?: number;
|
|
145
|
+
modifiedTime?: Date;
|
|
146
|
+
}>;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
interface E2BComputerOptions {
|
|
150
|
+
/** An E2B Sandbox instance created via `Sandbox.create()`. */
|
|
151
|
+
sandbox: E2BSandboxInstance;
|
|
152
|
+
/** Default working directory for commands. */
|
|
153
|
+
defaultCwd?: string;
|
|
154
|
+
/** Default timeout in ms for commands (default: 30000). */
|
|
155
|
+
defaultTimeout?: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* VirtualComputer backed by command execution in an E2B cloud sandbox.
|
|
159
|
+
*
|
|
160
|
+
* Requires `e2b` as an optional peer dependency.
|
|
161
|
+
* The user is responsible for sandbox lifecycle (create, close).
|
|
162
|
+
*/
|
|
163
|
+
declare class E2BComputer implements VirtualComputer {
|
|
164
|
+
private sandbox;
|
|
165
|
+
private defaultCwd;
|
|
166
|
+
private defaultTimeout;
|
|
167
|
+
constructor(opts: E2BComputerOptions);
|
|
168
|
+
executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Minimal subset of the Freestyle VM interface used by FreestyleComputer and
|
|
173
|
+
* FreestyleFs. Avoids a hard import of `freestyle-sandboxes` at the module
|
|
174
|
+
* level — the real SDK is only loaded dynamically during `FreestyleSandbox`
|
|
175
|
+
* auto-creation.
|
|
176
|
+
*/
|
|
177
|
+
interface FreestyleVmInstance {
|
|
178
|
+
exec(command: string, opts?: {
|
|
179
|
+
cwd?: string;
|
|
180
|
+
timeout?: number;
|
|
181
|
+
}): Promise<{
|
|
182
|
+
stdout: string | null;
|
|
183
|
+
stderr: string | null;
|
|
184
|
+
statusCode: number | null;
|
|
185
|
+
}>;
|
|
186
|
+
fs: {
|
|
187
|
+
readTextFile(path: string): Promise<string>;
|
|
188
|
+
writeTextFile(path: string, content: string): Promise<void>;
|
|
189
|
+
readDir(path: string): Promise<Array<{
|
|
190
|
+
name: string;
|
|
191
|
+
kind: string;
|
|
192
|
+
}>>;
|
|
193
|
+
};
|
|
194
|
+
suspend(): Promise<unknown>;
|
|
195
|
+
start(): Promise<unknown>;
|
|
196
|
+
}
|
|
197
|
+
interface FreestyleComputerOptions {
|
|
198
|
+
/** A Freestyle VM instance. */
|
|
199
|
+
vm: FreestyleVmInstance;
|
|
200
|
+
/** Default working directory for commands. */
|
|
201
|
+
defaultCwd?: string;
|
|
202
|
+
/** Default timeout in ms for commands (default: 30000). */
|
|
203
|
+
defaultTimeout?: number;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* VirtualComputer backed by command execution in a Freestyle VM.
|
|
207
|
+
*
|
|
208
|
+
* Requires `freestyle-sandboxes` as an optional peer dependency.
|
|
209
|
+
* The user is responsible for VM lifecycle when using explicit mode.
|
|
210
|
+
*/
|
|
211
|
+
declare class FreestyleComputer implements VirtualComputer {
|
|
212
|
+
private vm;
|
|
213
|
+
private defaultCwd;
|
|
214
|
+
private defaultTimeout;
|
|
215
|
+
constructor(opts: FreestyleComputerOptions);
|
|
216
|
+
executeCommand(command: string, opts?: ExecOptions): Promise<CommandResult>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Bundled sandbox: a `VirtualFs` and `VirtualComputer` paired together.
|
|
221
|
+
*
|
|
222
|
+
* Use one of the built-in factories (`LocalSandbox`, `UnsandboxedLocal`,
|
|
223
|
+
* `SpritesSandbox`) or supply any object that satisfies this shape for
|
|
224
|
+
* custom sandboxes (Docker, E2B, Daytona, in-memory, etc.).
|
|
225
|
+
*/
|
|
226
|
+
interface Sandbox {
|
|
227
|
+
fs: VirtualFs;
|
|
228
|
+
computer: VirtualComputer;
|
|
229
|
+
/** Optional cleanup — called by Agent.close() to tear down OS-level sandbox state. */
|
|
230
|
+
dispose?(): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Lazily provision the underlying sandbox resource. Idempotent — repeated
|
|
233
|
+
* calls return the same single-flight promise.
|
|
234
|
+
*
|
|
235
|
+
* When `sandboxId` is provided the sandbox reconnects to an existing
|
|
236
|
+
* resource instead of creating a new one. This is used during session
|
|
237
|
+
* resume: the stored sandbox identifier is read from session metadata
|
|
238
|
+
* and passed here so the agent reattaches to its previous container.
|
|
239
|
+
*
|
|
240
|
+
* When omitted a fresh resource is provisioned (for factories that
|
|
241
|
+
* support auto-creation) or the call is a no-op (for factories that
|
|
242
|
+
* were given a pre-created resource up front).
|
|
243
|
+
*/
|
|
244
|
+
init?(sandboxId?: string): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Return the opaque identifier for this sandbox instance so it can be
|
|
247
|
+
* persisted in session metadata and used to reconnect later via `init()`.
|
|
248
|
+
* Returns `undefined` before `init()` has resolved or for sandboxes
|
|
249
|
+
* that don't support reconnection.
|
|
250
|
+
*/
|
|
251
|
+
sandboxId?(): string | undefined;
|
|
252
|
+
}
|
|
253
|
+
interface UnsandboxedLocalOptions {
|
|
254
|
+
/** Working directory for both file resolution and command execution. */
|
|
255
|
+
cwd?: string;
|
|
256
|
+
/** Default timeout (ms) for shell commands. */
|
|
257
|
+
defaultTimeout?: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create a `Sandbox` backed by the host filesystem and shell with **no
|
|
261
|
+
* OS-level isolation**. The agent can access anything the host process can.
|
|
262
|
+
*
|
|
263
|
+
* Use this for development or fully-trusted environments where sandboxing
|
|
264
|
+
* overhead is unwanted. For production use, prefer `LocalSandbox()` (which
|
|
265
|
+
* wraps commands with `@anthropic-ai/sandbox-runtime`).
|
|
266
|
+
*/
|
|
267
|
+
declare function UnsandboxedLocal(opts?: UnsandboxedLocalOptions): Sandbox;
|
|
268
|
+
interface LocalSandboxOptions {
|
|
269
|
+
/** Working directory for both file resolution and command execution. */
|
|
270
|
+
cwd?: string;
|
|
271
|
+
/** Default timeout (ms) for shell commands. */
|
|
272
|
+
defaultTimeout?: number;
|
|
273
|
+
/**
|
|
274
|
+
* Sandbox restrictions. Defaults: writes allowed only in `cwd`,
|
|
275
|
+
* reads allowed everywhere, network unrestricted.
|
|
276
|
+
*/
|
|
277
|
+
sandbox?: SandboxConfig;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Create a `Sandbox` with OS-level isolation via `@anthropic-ai/sandbox-runtime`.
|
|
281
|
+
*
|
|
282
|
+
* - **macOS**: Seatbelt (`sandbox-exec`) profiles restrict filesystem and network.
|
|
283
|
+
* - **Linux**: bubblewrap (`bwrap`) + socat for namespace-based isolation.
|
|
284
|
+
*
|
|
285
|
+
* Filesystem operations (`VirtualFs`) use the host `node:fs` — the sandbox
|
|
286
|
+
* boundary is enforced on shell commands (`VirtualComputer`), which is where
|
|
287
|
+
* the agent executes arbitrary code.
|
|
288
|
+
*
|
|
289
|
+
* Requires `@anthropic-ai/sandbox-runtime` as a peer dependency.
|
|
290
|
+
*/
|
|
291
|
+
declare function LocalSandbox(opts?: LocalSandboxOptions): Sandbox;
|
|
292
|
+
interface SpritesSandboxOptions {
|
|
293
|
+
/** sprites.dev API token. */
|
|
294
|
+
token: string;
|
|
295
|
+
/**
|
|
296
|
+
* Name of an existing sprite container. When provided the sandbox
|
|
297
|
+
* attaches to this sprite directly — no auto-creation occurs and
|
|
298
|
+
* `dispose()` will **not** delete it (lifecycle is yours to manage).
|
|
299
|
+
*
|
|
300
|
+
* When omitted a new sprite is provisioned on the first `init()` call
|
|
301
|
+
* (via `POST /v1/sprites`). The auto-created sprite is deleted when
|
|
302
|
+
* `dispose()` is called, and its name is available via `sandboxId()`
|
|
303
|
+
* for session persistence.
|
|
304
|
+
*/
|
|
305
|
+
spriteName?: string;
|
|
306
|
+
/** Base URL for sprites API (default: https://api.sprites.dev). */
|
|
307
|
+
baseURL?: string;
|
|
308
|
+
/** Working directory inside the sprite (default: /home/sprite). */
|
|
309
|
+
workingDir?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Optional prefix for auto-generated sprite names (default: "noumen-").
|
|
312
|
+
* Only used when `spriteName` is omitted.
|
|
313
|
+
*/
|
|
314
|
+
namePrefix?: string;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Create a `Sandbox` backed by a remote sprites.dev container.
|
|
318
|
+
* Full isolation — the agent has no access to the host machine.
|
|
319
|
+
*
|
|
320
|
+
* **Auto-creation:** When `spriteName` is omitted the sandbox is created
|
|
321
|
+
* lazily on the first `init()` call via the Sprites REST API. The sprite
|
|
322
|
+
* name is available through `sandboxId()` so callers can persist it in
|
|
323
|
+
* session metadata for reconnection on resume. Pass the stored name back
|
|
324
|
+
* through `init(storedId)` to reattach instead of creating a new sprite.
|
|
325
|
+
*
|
|
326
|
+
* **Explicit ID:** When `spriteName` is provided the sandbox attaches to
|
|
327
|
+
* that sprite immediately on `init()`. `dispose()` is a no-op in this
|
|
328
|
+
* case — the caller owns the sprite's lifecycle.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* // Auto-create — sprite provisioned on first init()
|
|
333
|
+
* const sandbox = SpritesSandbox({ token: process.env.SPRITES_TOKEN! });
|
|
334
|
+
*
|
|
335
|
+
* // Explicit — attach to pre-existing sprite, no auto-lifecycle
|
|
336
|
+
* const sandbox = SpritesSandbox({
|
|
337
|
+
* token: process.env.SPRITES_TOKEN!,
|
|
338
|
+
* spriteName: "my-sprite",
|
|
339
|
+
* });
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
declare function SpritesSandbox(opts: SpritesSandboxOptions): Sandbox;
|
|
343
|
+
interface DockerSandboxOptions {
|
|
344
|
+
/**
|
|
345
|
+
* A pre-existing dockerode Container instance. When provided the sandbox
|
|
346
|
+
* attaches to this container directly — no auto-creation occurs and
|
|
347
|
+
* `dispose()` will **not** stop or remove it.
|
|
348
|
+
*
|
|
349
|
+
* When omitted, a new container is created from `image` on the first
|
|
350
|
+
* `init()` call via a dynamic import of `dockerode`. The auto-created
|
|
351
|
+
* container is stopped and removed when `dispose()` is called.
|
|
352
|
+
*/
|
|
353
|
+
container?: DockerContainer;
|
|
354
|
+
/**
|
|
355
|
+
* Docker image to use for auto-creation (e.g. `"ubuntu:22.04"`).
|
|
356
|
+
* Required when `container` is omitted; ignored when `container` is provided.
|
|
357
|
+
*/
|
|
358
|
+
image?: string;
|
|
359
|
+
/** Command to run in the auto-created container (default: `["sleep", "infinity"]`). */
|
|
360
|
+
cmd?: string[];
|
|
361
|
+
/** Environment variables for the auto-created container. */
|
|
362
|
+
env?: string[];
|
|
363
|
+
/** Extra options passed to dockerode `createContainer`. */
|
|
364
|
+
dockerOptions?: Record<string, unknown>;
|
|
365
|
+
/** Working directory inside the container. */
|
|
366
|
+
cwd?: string;
|
|
367
|
+
/** Default timeout (ms) for shell commands. */
|
|
368
|
+
defaultTimeout?: number;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Create a `Sandbox` backed by a Docker container.
|
|
372
|
+
* Requires `dockerode` as an optional peer dependency.
|
|
373
|
+
*
|
|
374
|
+
* **Auto-creation:** When `container` is omitted and `image` is provided,
|
|
375
|
+
* the container is created and started lazily on the first `init()` call.
|
|
376
|
+
* The container ID is available through `sandboxId()` for session
|
|
377
|
+
* persistence. Pass the stored ID back through `init(storedId)` to
|
|
378
|
+
* reattach to an existing container on resume.
|
|
379
|
+
*
|
|
380
|
+
* **Explicit container:** When `container` is provided, `init()` binds
|
|
381
|
+
* it immediately. `dispose()` is a no-op — the caller owns the
|
|
382
|
+
* container's lifecycle.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* // Auto-create from image
|
|
387
|
+
* const sandbox = DockerSandbox({ image: "ubuntu:22.04", cwd: "/workspace" });
|
|
388
|
+
*
|
|
389
|
+
* // Explicit container (lifecycle managed externally)
|
|
390
|
+
* const sandbox = DockerSandbox({ container: myDockerodeContainer });
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
declare function DockerSandbox(opts: DockerSandboxOptions): Sandbox;
|
|
394
|
+
interface E2BSandboxOptions {
|
|
395
|
+
/**
|
|
396
|
+
* A pre-existing E2B Sandbox instance (e.g. from `Sandbox.create()`).
|
|
397
|
+
* When provided the sandbox attaches to this instance — no auto-creation
|
|
398
|
+
* occurs and `dispose()` will **not** kill it.
|
|
399
|
+
*
|
|
400
|
+
* When omitted, a new E2B sandbox is created on the first `init()` call
|
|
401
|
+
* via a dynamic import of the `e2b` package. The auto-created sandbox
|
|
402
|
+
* is killed when `dispose()` is called.
|
|
403
|
+
*/
|
|
404
|
+
sandbox?: E2BSandboxInstance;
|
|
405
|
+
/**
|
|
406
|
+
* E2B template to use for auto-creation (default: `"base"`).
|
|
407
|
+
* Only used when `sandbox` is omitted.
|
|
408
|
+
*/
|
|
409
|
+
template?: string;
|
|
410
|
+
/**
|
|
411
|
+
* E2B API key. Falls back to the `E2B_API_KEY` environment variable
|
|
412
|
+
* when omitted. Only used during auto-creation.
|
|
413
|
+
*/
|
|
414
|
+
apiKey?: string;
|
|
415
|
+
/** Timeout (ms) for the auto-created E2B sandbox (default: E2B SDK default). */
|
|
416
|
+
timeoutMs?: number;
|
|
417
|
+
/** Working directory inside the sandbox. */
|
|
418
|
+
cwd?: string;
|
|
419
|
+
/** Default timeout (ms) for shell commands. */
|
|
420
|
+
defaultTimeout?: number;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Create a `Sandbox` backed by an E2B cloud sandbox.
|
|
424
|
+
* Requires `e2b` as an optional peer dependency.
|
|
425
|
+
*
|
|
426
|
+
* **Auto-creation:** When `sandbox` is omitted the E2B sandbox is
|
|
427
|
+
* provisioned lazily on the first `init()` call via the E2B SDK.
|
|
428
|
+
* The sandbox ID is available through `sandboxId()` for session
|
|
429
|
+
* persistence. Pass the stored ID back through `init(storedId)` to
|
|
430
|
+
* reconnect to the same sandbox on resume (via `Sandbox.connect()`).
|
|
431
|
+
*
|
|
432
|
+
* **Explicit instance:** When `sandbox` is provided, `init()` binds
|
|
433
|
+
* it immediately. `dispose()` is a no-op — the caller owns the
|
|
434
|
+
* sandbox's lifecycle.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* // Auto-create — sandbox provisioned on first init()
|
|
439
|
+
* const sandbox = E2BSandbox({ template: "base" });
|
|
440
|
+
*
|
|
441
|
+
* // Explicit — attach to pre-existing instance
|
|
442
|
+
* const sandbox = E2BSandbox({ sandbox: await E2BSdk.Sandbox.create() });
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
declare function E2BSandbox(opts: E2BSandboxOptions): Sandbox;
|
|
446
|
+
interface FreestyleSandboxOptions {
|
|
447
|
+
/**
|
|
448
|
+
* A pre-existing Freestyle VM instance. When provided the sandbox
|
|
449
|
+
* attaches to this VM directly — no auto-creation occurs and
|
|
450
|
+
* `dispose()` will **not** suspend or delete it.
|
|
451
|
+
*
|
|
452
|
+
* When omitted, a new VM is created on the first `init()` call via
|
|
453
|
+
* a dynamic import of the `freestyle-sandboxes` package.
|
|
454
|
+
*/
|
|
455
|
+
vm?: FreestyleVmInstance;
|
|
456
|
+
/**
|
|
457
|
+
* Freestyle API key. Falls back to the `FREESTYLE_API_KEY` environment
|
|
458
|
+
* variable when omitted. Only used during auto-creation.
|
|
459
|
+
*/
|
|
460
|
+
apiKey?: string;
|
|
461
|
+
/** Snapshot ID to create the VM from. Only used during auto-creation. */
|
|
462
|
+
snapshotId?: string;
|
|
463
|
+
/**
|
|
464
|
+
* A `VmSpec` instance or configuration object passed through to
|
|
465
|
+
* `freestyle.vms.create()`. Only used during auto-creation.
|
|
466
|
+
*/
|
|
467
|
+
spec?: unknown;
|
|
468
|
+
/**
|
|
469
|
+
* Idle timeout in seconds for the auto-created VM (default: 600).
|
|
470
|
+
* The VM auto-suspends after this many seconds of network inactivity.
|
|
471
|
+
*/
|
|
472
|
+
idleTimeoutSeconds?: number;
|
|
473
|
+
/** Working directory inside the VM. */
|
|
474
|
+
cwd?: string;
|
|
475
|
+
/** Default timeout (ms) for shell commands. */
|
|
476
|
+
defaultTimeout?: number;
|
|
477
|
+
/** Files to provision at creation time. */
|
|
478
|
+
additionalFiles?: Record<string, {
|
|
479
|
+
content: string;
|
|
480
|
+
encoding?: string;
|
|
481
|
+
}>;
|
|
482
|
+
/** Git repos to clone at creation time. */
|
|
483
|
+
gitRepos?: Array<{
|
|
484
|
+
repo: string;
|
|
485
|
+
path: string;
|
|
486
|
+
rev?: string;
|
|
487
|
+
}>;
|
|
488
|
+
/**
|
|
489
|
+
* What to do with auto-created VMs on `dispose()`:
|
|
490
|
+
* - `"suspend"` (default) — suspends the VM, preserving full memory
|
|
491
|
+
* state for near-instant resume on reconnect.
|
|
492
|
+
* - `"delete"` — permanently deletes the VM and frees all resources.
|
|
493
|
+
*/
|
|
494
|
+
disposeStrategy?: "suspend" | "delete";
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Create a `Sandbox` backed by a Freestyle VM.
|
|
498
|
+
* Requires `freestyle-sandboxes` as an optional peer dependency.
|
|
499
|
+
*
|
|
500
|
+
* **Auto-creation:** When `vm` is omitted a new Freestyle VM is
|
|
501
|
+
* provisioned lazily on the first `init()` call. The VM ID is available
|
|
502
|
+
* through `sandboxId()` for session persistence. Pass the stored ID back
|
|
503
|
+
* through `init(storedId)` to reconnect (this also wakes suspended VMs).
|
|
504
|
+
*
|
|
505
|
+
* By default, auto-created VMs are **suspended** on `dispose()` rather
|
|
506
|
+
* than deleted. This preserves full memory state and allows near-instant
|
|
507
|
+
* resume. Set `disposeStrategy: "delete"` for full cleanup.
|
|
508
|
+
*
|
|
509
|
+
* **Explicit instance:** When `vm` is provided, `init()` binds it
|
|
510
|
+
* immediately. `dispose()` is a no-op — the caller owns the VM's
|
|
511
|
+
* lifecycle.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts
|
|
515
|
+
* // Auto-create — VM provisioned on first init()
|
|
516
|
+
* const sandbox = FreestyleSandbox({ cwd: "/workspace" });
|
|
517
|
+
*
|
|
518
|
+
* // Auto-create from a snapshot
|
|
519
|
+
* const sandbox = FreestyleSandbox({
|
|
520
|
+
* snapshotId: "abc123",
|
|
521
|
+
* cwd: "/workspace",
|
|
522
|
+
* });
|
|
523
|
+
*
|
|
524
|
+
* // Explicit — attach to pre-existing VM
|
|
525
|
+
* const sandbox = FreestyleSandbox({ vm: existingVm });
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
declare function FreestyleSandbox(opts: FreestyleSandboxOptions): Sandbox;
|
|
529
|
+
|
|
530
|
+
interface SkillDefinition {
|
|
531
|
+
name: string;
|
|
532
|
+
/** Skill body content (after frontmatter is stripped) */
|
|
533
|
+
content: string;
|
|
534
|
+
path?: string;
|
|
535
|
+
description?: string;
|
|
536
|
+
/** Glob patterns for files this skill applies to (from frontmatter `paths`) */
|
|
537
|
+
globs?: string[];
|
|
538
|
+
/** Tool names this skill is allowed to use */
|
|
539
|
+
allowedTools?: string[];
|
|
540
|
+
/** Execution context: inline expands into conversation, fork runs as sub-agent */
|
|
541
|
+
context?: "inline" | "fork";
|
|
542
|
+
/** Hint for the $ARGUMENTS placeholder */
|
|
543
|
+
argumentHint?: string;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
interface WebSearchResult {
|
|
547
|
+
title: string;
|
|
548
|
+
url: string;
|
|
549
|
+
snippet: string;
|
|
550
|
+
}
|
|
551
|
+
interface WebSearchConfig {
|
|
552
|
+
search: (query: string, domains?: string[]) => Promise<WebSearchResult[]>;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Create a WebSearch tool backed by a user-provided search implementation.
|
|
556
|
+
* This keeps noumen provider-agnostic — plug in Tavily, SerpAPI, Brave Search, etc.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```ts
|
|
560
|
+
* const webSearch = createWebSearchTool({
|
|
561
|
+
* search: async (query) => {
|
|
562
|
+
* const res = await tavily.search({ query });
|
|
563
|
+
* return res.results.map(r => ({ title: r.title, url: r.url, snippet: r.content }));
|
|
564
|
+
* },
|
|
565
|
+
* });
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
declare function createWebSearchTool(config: WebSearchConfig): Tool;
|
|
569
|
+
/**
|
|
570
|
+
* Default WebSearch tool that returns a helpful error when no search provider
|
|
571
|
+
* is configured. Register this as a placeholder; consumers should replace
|
|
572
|
+
* it with `createWebSearchTool(config)`.
|
|
573
|
+
*/
|
|
574
|
+
declare const webSearchToolPlaceholder: Tool;
|
|
575
|
+
|
|
576
|
+
interface RetryConfig {
|
|
577
|
+
maxRetries?: number;
|
|
578
|
+
baseDelayMs?: number;
|
|
579
|
+
maxDelayMs?: number;
|
|
580
|
+
retryableStatuses?: number[];
|
|
581
|
+
fallbackModel?: string;
|
|
582
|
+
/** Max consecutive overloaded (529) errors before triggering model fallback. */
|
|
583
|
+
maxConsecutiveOverloaded?: number;
|
|
584
|
+
onRetry?: (attempt: number, error: Error, delayMs: number) => void;
|
|
585
|
+
}
|
|
586
|
+
declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
587
|
+
interface RetryEngineOptions extends RetryConfig {
|
|
588
|
+
model: string;
|
|
589
|
+
thinkingBudget?: number;
|
|
590
|
+
signal?: AbortSignal;
|
|
591
|
+
}
|
|
592
|
+
interface RetryContext {
|
|
593
|
+
attempt: number;
|
|
594
|
+
model: string;
|
|
595
|
+
maxTokensOverride?: number;
|
|
596
|
+
}
|
|
597
|
+
type RetryEvent = Extract<StreamEvent, {
|
|
598
|
+
type: "retry_attempt" | "retry_exhausted";
|
|
599
|
+
}>;
|
|
600
|
+
|
|
601
|
+
declare const SpanStatusCode: {
|
|
602
|
+
readonly OK: 0;
|
|
603
|
+
readonly ERROR: 1;
|
|
604
|
+
};
|
|
605
|
+
type SpanStatusCode = (typeof SpanStatusCode)[keyof typeof SpanStatusCode];
|
|
606
|
+
type SpanAttributeValue = string | number | boolean;
|
|
607
|
+
interface SpanOptions {
|
|
608
|
+
parent?: Span;
|
|
609
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
610
|
+
}
|
|
611
|
+
interface Span {
|
|
612
|
+
readonly name: string;
|
|
613
|
+
setAttribute(key: string, value: SpanAttributeValue): void;
|
|
614
|
+
addEvent(name: string, attributes?: Record<string, SpanAttributeValue>): void;
|
|
615
|
+
setStatus(code: SpanStatusCode, message?: string): void;
|
|
616
|
+
end(): void;
|
|
617
|
+
}
|
|
618
|
+
interface Tracer {
|
|
619
|
+
startSpan(name: string, options?: SpanOptions): Span;
|
|
620
|
+
}
|
|
621
|
+
interface TracingConfig {
|
|
622
|
+
tracer: Tracer;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
interface MicrocompactConfig {
|
|
626
|
+
enabled: boolean;
|
|
627
|
+
/** Keep the N most recent compactable tool results uncleared. Default: 5 */
|
|
628
|
+
keepRecent?: number;
|
|
629
|
+
}
|
|
630
|
+
interface MicrocompactResult {
|
|
631
|
+
messages: ChatMessage[];
|
|
632
|
+
tokensFreed: number;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Tools whose results can be safely cleared to free context tokens.
|
|
636
|
+
* Includes read-heavy tools (ReadFile, Grep, Glob, WebFetch, WebSearch,
|
|
637
|
+
* Bash) as well as mutation tools (EditFile, WriteFile) whose results
|
|
638
|
+
* are short confirmation strings the model can reconstruct from context.
|
|
639
|
+
*/
|
|
640
|
+
declare const COMPACTABLE_TOOLS: Set<string>;
|
|
641
|
+
declare const CLEARED_PLACEHOLDER = "[tool result cleared to save context]";
|
|
642
|
+
/**
|
|
643
|
+
* Clear the content of old tool-result messages to free context tokens
|
|
644
|
+
* without a full summarization pass.
|
|
645
|
+
*
|
|
646
|
+
* Only results from {@link COMPACTABLE_TOOLS} are eligible. The most
|
|
647
|
+
* recent `keepRecent` eligible results are preserved; older ones have
|
|
648
|
+
* their content replaced with {@link CLEARED_PLACEHOLDER}.
|
|
649
|
+
*
|
|
650
|
+
* Returns a **new** messages array (shallow-copied where unchanged).
|
|
651
|
+
*/
|
|
652
|
+
declare function microcompactMessages(messages: ChatMessage[], config: MicrocompactConfig): MicrocompactResult;
|
|
653
|
+
|
|
654
|
+
interface ToolResultBudgetConfig {
|
|
655
|
+
enabled: boolean;
|
|
656
|
+
/** Max total chars across all tool results in one group. Default: 200_000 */
|
|
657
|
+
maxCharsPerGroup?: number;
|
|
658
|
+
/** Max chars for a single tool result before individual truncation. Default: 50_000 */
|
|
659
|
+
maxCharsPerResult?: number;
|
|
660
|
+
/** Number of preview chars to keep when truncating. Default: 1_000 */
|
|
661
|
+
previewChars?: number;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Tracks which tool_call_ids have already been truncated so that
|
|
665
|
+
* decisions are deterministic across repeated calls and session resume.
|
|
666
|
+
*/
|
|
667
|
+
interface BudgetState {
|
|
668
|
+
truncatedIds: Set<string>;
|
|
669
|
+
}
|
|
670
|
+
declare function createBudgetState(): BudgetState;
|
|
671
|
+
interface ToolResultBudgetResult {
|
|
672
|
+
messages: ChatMessage[];
|
|
673
|
+
state: BudgetState;
|
|
674
|
+
tokensFreed: number;
|
|
675
|
+
truncatedEntries: Array<{
|
|
676
|
+
toolCallId: string;
|
|
677
|
+
originalChars: number;
|
|
678
|
+
truncatedChars: number;
|
|
679
|
+
}>;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Enforce per-group and per-result character budgets on tool results.
|
|
683
|
+
*
|
|
684
|
+
* For each assistant-round group: first enforce per-result caps (truncate
|
|
685
|
+
* any single result exceeding `maxCharsPerResult`), then if the group
|
|
686
|
+
* total still exceeds `maxCharsPerGroup`, truncate the largest results
|
|
687
|
+
* first until under budget.
|
|
688
|
+
*
|
|
689
|
+
* Tool results that were already truncated (tracked in `state`) are
|
|
690
|
+
* left as-is for deterministic resume.
|
|
691
|
+
*/
|
|
692
|
+
declare function enforceToolResultBudget(messages: ChatMessage[], config: ToolResultBudgetConfig, state?: BudgetState): ToolResultBudgetResult;
|
|
693
|
+
|
|
694
|
+
declare class SessionStorage {
|
|
695
|
+
private fs;
|
|
696
|
+
private sessionDir;
|
|
697
|
+
private writeLock;
|
|
698
|
+
constructor(fs: VirtualFs, sessionDir: string);
|
|
699
|
+
/**
|
|
700
|
+
* Serialize writes through a simple promise chain so parallel
|
|
701
|
+
* appendEntry calls don't interleave large JSONL records.
|
|
702
|
+
*/
|
|
703
|
+
private serializedWrite;
|
|
704
|
+
private getTranscriptPath;
|
|
705
|
+
ensureDir(): Promise<void>;
|
|
706
|
+
appendEntry(sessionId: string, entry: Entry): Promise<void>;
|
|
707
|
+
/**
|
|
708
|
+
* Append multiple entries atomically as a single write.
|
|
709
|
+
* All entries are serialized into one string and written in one appendFile
|
|
710
|
+
* call, preventing partial writes on crash.
|
|
711
|
+
*/
|
|
712
|
+
appendEntriesBatch(sessionId: string, entries: Entry[]): Promise<void>;
|
|
713
|
+
appendMessage(sessionId: string, message: ChatMessage, parentUuid?: UUID | null): Promise<UUID>;
|
|
714
|
+
appendCompactBoundary(sessionId: string): Promise<UUID>;
|
|
715
|
+
appendSummary(sessionId: string, summaryMessage: ChatMessage, parentUuid?: UUID | null): Promise<UUID>;
|
|
716
|
+
appendToolResultOverflow(sessionId: string, toolCallId: string, originalContent: string): Promise<void>;
|
|
717
|
+
appendCheckpointEntry(sessionId: string, messageId: string, snapshot: FileCheckpointSnapshot, isSnapshotUpdate: boolean): Promise<void>;
|
|
718
|
+
appendSnipBoundary(sessionId: string, removedUuids: string[]): Promise<void>;
|
|
719
|
+
appendContentReplacement(sessionId: string, replacements: ContentReplacementRecord$1[]): Promise<void>;
|
|
720
|
+
appendMetadata(sessionId: string, key: string, value: unknown): Promise<void>;
|
|
721
|
+
/**
|
|
722
|
+
* Re-append custom-title and key metadata entries after a compact boundary
|
|
723
|
+
* so they remain discoverable in the active-entries window.
|
|
724
|
+
*/
|
|
725
|
+
reAppendMetadataAfterCompact(sessionId: string): Promise<void>;
|
|
726
|
+
loadMessages(sessionId: string): Promise<ChatMessage[]>;
|
|
727
|
+
loadAllEntries(sessionId: string): Promise<Entry[]>;
|
|
728
|
+
sessionExists(sessionId: string): Promise<boolean>;
|
|
729
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
730
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
interface ReactiveCompactConfig {
|
|
734
|
+
enabled: boolean;
|
|
735
|
+
}
|
|
736
|
+
interface ReactiveCompactResult {
|
|
737
|
+
messages: ChatMessage[];
|
|
738
|
+
strategy: "compacted" | "truncated";
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Attempt to recover from a context-overflow error by compacting the
|
|
742
|
+
* conversation. If compaction itself fails (e.g. the context is so large
|
|
743
|
+
* that even the summarizer cannot run), falls back to
|
|
744
|
+
* {@link truncateHeadForPTLRetry} which drops the oldest turn groups
|
|
745
|
+
* until the estimate fits within the target.
|
|
746
|
+
*
|
|
747
|
+
* Returns `null` if there are not enough messages to meaningfully compact
|
|
748
|
+
* or truncate (less than 2 messages).
|
|
749
|
+
*/
|
|
750
|
+
declare function tryReactiveCompact(provider: AIProvider, model: string, messages: ChatMessage[], storage: SessionStorage, sessionId: string, opts?: {
|
|
751
|
+
signal?: AbortSignal;
|
|
752
|
+
}): Promise<ReactiveCompactResult | null>;
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Disk-backed tool result storage.
|
|
756
|
+
*
|
|
757
|
+
* When a tool result exceeds a size threshold, the full content is persisted
|
|
758
|
+
* to VirtualFs and replaced in-memory with a compact stub containing a
|
|
759
|
+
* preview and path. This prevents context window bloat while preserving
|
|
760
|
+
* the full data for resume.
|
|
761
|
+
*/
|
|
762
|
+
|
|
763
|
+
interface ToolResultStorageConfig {
|
|
764
|
+
enabled: boolean;
|
|
765
|
+
/** Directory under which persisted results are stored. Default: ".noumen/tool-results" */
|
|
766
|
+
storageDir?: string;
|
|
767
|
+
/** Char threshold for a single result before spilling to disk. Default: 50_000 */
|
|
768
|
+
defaultThreshold?: number;
|
|
769
|
+
/** Per-tool overrides (tool name -> threshold). Use Infinity to never persist. */
|
|
770
|
+
perToolThresholds?: Record<string, number>;
|
|
771
|
+
/** Chars to keep as preview in the replacement stub. Default: 2_000 */
|
|
772
|
+
previewChars?: number;
|
|
773
|
+
/** Per-message aggregate budget for all tool results. Default: 200_000 */
|
|
774
|
+
perMessageBudget?: number;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Tracks which tool results have been replaced, enabling deterministic
|
|
778
|
+
* resume — previously replaced results are re-applied from the stored
|
|
779
|
+
* replacement string without re-reading from disk.
|
|
780
|
+
*/
|
|
781
|
+
interface ContentReplacementState {
|
|
782
|
+
seenIds: Set<string>;
|
|
783
|
+
replacements: Map<string, string>;
|
|
784
|
+
}
|
|
785
|
+
interface ContentReplacementRecord {
|
|
786
|
+
toolUseId: string;
|
|
787
|
+
replacement: string;
|
|
788
|
+
}
|
|
789
|
+
declare function createContentReplacementState(): ContentReplacementState;
|
|
790
|
+
/**
|
|
791
|
+
* Persist a single oversized tool result to disk and return a replacement stub.
|
|
792
|
+
* Returns null if the content is below threshold.
|
|
793
|
+
*/
|
|
794
|
+
declare function persistToolResult(fs: VirtualFs, sessionId: string, toolUseId: string, toolName: string, content: string, config: ToolResultStorageConfig): Promise<string | null>;
|
|
795
|
+
interface ToolResultSpillResult {
|
|
796
|
+
messages: ChatMessage[];
|
|
797
|
+
state: ContentReplacementState;
|
|
798
|
+
tokensFreed: number;
|
|
799
|
+
spilledEntries: ContentReplacementRecord[];
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Enforce per-message tool result budget by spilling the largest results to disk.
|
|
803
|
+
*
|
|
804
|
+
* For each assistant turn group, if the total tool result size exceeds
|
|
805
|
+
* `perMessageBudget`, the largest results are spilled first.
|
|
806
|
+
*/
|
|
807
|
+
declare function enforceToolResultStorageBudget(messages: ChatMessage[], config: ToolResultStorageConfig, fs: VirtualFs, sessionId: string, state?: ContentReplacementState): Promise<ToolResultSpillResult>;
|
|
808
|
+
/**
|
|
809
|
+
* Reconstruct ContentReplacementState from persisted records (used during session resume).
|
|
810
|
+
*/
|
|
811
|
+
declare function reconstructContentReplacementState(records: ContentReplacementRecord[], messages?: ChatMessage[]): ContentReplacementState;
|
|
812
|
+
/**
|
|
813
|
+
* Re-apply persisted replacements to loaded messages (for resume).
|
|
814
|
+
*/
|
|
815
|
+
declare function applyPersistedReplacements(messages: ChatMessage[], state: ContentReplacementState): ChatMessage[];
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* History snip: remove middle ranges of conversation history.
|
|
819
|
+
*
|
|
820
|
+
* Unlike prefix compaction (which summarizes and removes the oldest
|
|
821
|
+
* messages), history snip removes specific message ranges from the middle
|
|
822
|
+
* of the conversation. The JSONL transcript stays append-only — snipped
|
|
823
|
+
* messages remain on disk but their UUIDs are recorded on a snip-boundary
|
|
824
|
+
* entry so they're filtered out on resume.
|
|
825
|
+
*
|
|
826
|
+
* Parent pointers are relinked across gaps using path compression so the
|
|
827
|
+
* conversation chain stays intact.
|
|
828
|
+
*/
|
|
829
|
+
|
|
830
|
+
interface SnipConfig {
|
|
831
|
+
enabled: boolean;
|
|
832
|
+
}
|
|
833
|
+
interface SnipResult {
|
|
834
|
+
messages: ChatMessage[];
|
|
835
|
+
removedCount: number;
|
|
836
|
+
relinkedCount: number;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Apply snip removals to a UUID-keyed message map.
|
|
840
|
+
*
|
|
841
|
+
* Ported from claude-code's `applySnipRemovals`. Walks entries looking
|
|
842
|
+
* for snip-boundary entries with `snipMetadata.removedUuids`, deletes
|
|
843
|
+
* those messages, and relinks parentUuid across gaps with path compression.
|
|
844
|
+
*/
|
|
845
|
+
declare function applySnipRemovals(entries: Entry[]): {
|
|
846
|
+
messages: ChatMessage[];
|
|
847
|
+
removedCount: number;
|
|
848
|
+
relinkedCount: number;
|
|
849
|
+
};
|
|
850
|
+
/**
|
|
851
|
+
* Snip specific messages from an in-memory message array by UUID.
|
|
852
|
+
*
|
|
853
|
+
* This is the in-memory operation — call this during a live thread to
|
|
854
|
+
* remove messages before the next model call. The caller is responsible
|
|
855
|
+
* for persisting a snip-boundary entry to the JSONL transcript.
|
|
856
|
+
*/
|
|
857
|
+
declare function snipMessagesByUuids(entries: Array<{
|
|
858
|
+
uuid: UUID;
|
|
859
|
+
parentUuid: UUID | null;
|
|
860
|
+
message: ChatMessage;
|
|
861
|
+
}>, removedUuids: Set<UUID>): SnipResult;
|
|
862
|
+
/**
|
|
863
|
+
* Project a "snipped view" of messages for the model.
|
|
864
|
+
*
|
|
865
|
+
* Filters out messages marked as snipped. Use the `includeSnipped` option
|
|
866
|
+
* to get the full scrollback for UI display.
|
|
867
|
+
*/
|
|
868
|
+
declare function projectSnippedView(messages: ChatMessage[], snippedIndices: Set<number>, opts?: {
|
|
869
|
+
includeSnipped?: boolean;
|
|
870
|
+
}): ChatMessage[];
|
|
871
|
+
|
|
872
|
+
type ContextScope = "managed" | "user" | "project" | "local";
|
|
873
|
+
interface ContextFile {
|
|
874
|
+
path: string;
|
|
875
|
+
scope: ContextScope;
|
|
876
|
+
content: string;
|
|
877
|
+
/** Glob patterns from frontmatter `paths:` field. Undefined = unconditional. */
|
|
878
|
+
globs?: string[];
|
|
879
|
+
/** Files included via @ references. */
|
|
880
|
+
includes?: ContextFile[];
|
|
881
|
+
}
|
|
882
|
+
interface ProjectContextConfig {
|
|
883
|
+
/** Working directory (project root). Required. */
|
|
884
|
+
cwd: string;
|
|
885
|
+
/** User home directory. Pass explicitly for sandboxed environments. */
|
|
886
|
+
homeDir?: string;
|
|
887
|
+
/** Managed settings directory (enterprise/MDM). Optional. */
|
|
888
|
+
managedDir?: string;
|
|
889
|
+
/** Glob patterns to exclude context files (picomatch-style). */
|
|
890
|
+
excludes?: string[];
|
|
891
|
+
/** Maximum include depth for @ references. Default: 5. */
|
|
892
|
+
maxIncludeDepth?: number;
|
|
893
|
+
/** Whether to load .claude/ files in addition to .noumen/ files. Default: true. */
|
|
894
|
+
loadClaudeMd?: boolean;
|
|
895
|
+
/** Enable loading user-scope context from homeDir. Default: true. */
|
|
896
|
+
loadUserContext?: boolean;
|
|
897
|
+
/** Enable loading project-scope context from cwd ancestors. Default: true. */
|
|
898
|
+
loadProjectContext?: boolean;
|
|
899
|
+
/** Enable loading local-scope (.local.md) context. Default: true. */
|
|
900
|
+
loadLocalContext?: boolean;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
interface StoredCostState {
|
|
904
|
+
byModel: Record<string, ModelUsageSummary>;
|
|
905
|
+
totalApiMs: number;
|
|
906
|
+
wallStartMs: number;
|
|
907
|
+
}
|
|
908
|
+
declare class CostTracker {
|
|
909
|
+
private pricing;
|
|
910
|
+
private byModel;
|
|
911
|
+
private totalApiMs;
|
|
912
|
+
private wallStartMs;
|
|
913
|
+
constructor(pricing?: Record<string, ModelPricing>);
|
|
914
|
+
addUsage(model: string, usage: UsageRecord, apiDurationMs?: number): CostSummary;
|
|
915
|
+
getSummary(): CostSummary;
|
|
916
|
+
reset(): void;
|
|
917
|
+
getState(): StoredCostState;
|
|
918
|
+
restore(state: StoredCostState): void;
|
|
919
|
+
formatSummary(): string;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
interface AutoCompactConfig {
|
|
923
|
+
enabled: boolean;
|
|
924
|
+
/** Token threshold at which to trigger compaction. */
|
|
925
|
+
threshold: number;
|
|
926
|
+
/** Number of recent messages to keep uncompacted. */
|
|
927
|
+
tailMessagesToKeep?: number;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Tracks consecutive auto-compact failures to implement a circuit breaker.
|
|
931
|
+
* After `maxFailures` consecutive failures, auto-compact is skipped to
|
|
932
|
+
* avoid an infinite fail-retry loop.
|
|
933
|
+
*/
|
|
934
|
+
interface AutoCompactTrackingState {
|
|
935
|
+
consecutiveFailures: number;
|
|
936
|
+
maxFailures: number;
|
|
937
|
+
}
|
|
938
|
+
declare function createAutoCompactConfig(opts?: {
|
|
939
|
+
enabled?: boolean;
|
|
940
|
+
threshold?: number;
|
|
941
|
+
/** Model name — when provided, the threshold is computed from the model's
|
|
942
|
+
* context window instead of the fixed default. */
|
|
943
|
+
model?: string;
|
|
944
|
+
maxOutputTokens?: number;
|
|
945
|
+
tailMessagesToKeep?: number;
|
|
946
|
+
}): AutoCompactConfig;
|
|
947
|
+
declare function createAutoCompactTracking(maxFailures?: number): AutoCompactTrackingState;
|
|
948
|
+
/**
|
|
949
|
+
* Determine whether auto-compaction should fire. Uses usage-grounded counting
|
|
950
|
+
* when a usage anchor is available, otherwise falls back to estimation.
|
|
951
|
+
*
|
|
952
|
+
* @param tokensFreed — tokens already reclaimed by microcompact/budget in
|
|
953
|
+
* this turn; subtracted from the estimate so we don't over-eagerly compact.
|
|
954
|
+
* @param querySource — the source of the current query; prevents recursive
|
|
955
|
+
* compaction when called from a compact or session_memory context.
|
|
956
|
+
*/
|
|
957
|
+
declare function shouldAutoCompact(messages: ChatMessage[], config: AutoCompactConfig, lastUsage?: ChatCompletionUsage, anchorMessageIndex?: number, tokensFreed?: number, querySource?: string): boolean;
|
|
958
|
+
/**
|
|
959
|
+
* Check whether the circuit breaker allows another auto-compact attempt.
|
|
960
|
+
*/
|
|
961
|
+
declare function canAutoCompact(tracking: AutoCompactTrackingState): boolean;
|
|
962
|
+
declare function recordAutoCompactSuccess(tracking: AutoCompactTrackingState): void;
|
|
963
|
+
declare function recordAutoCompactFailure(tracking: AutoCompactTrackingState): void;
|
|
964
|
+
|
|
965
|
+
interface ThreadOptions {
|
|
966
|
+
sessionId?: string;
|
|
967
|
+
resume?: boolean;
|
|
968
|
+
cwd?: string;
|
|
969
|
+
model?: string;
|
|
970
|
+
/** Override the permission handler for this thread (takes precedence over AgentOptions). */
|
|
971
|
+
permissionHandler?: PermissionHandler;
|
|
972
|
+
/** Override the user input handler for this thread (takes precedence over AgentOptions). */
|
|
973
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
974
|
+
}
|
|
975
|
+
interface ThreadConfig {
|
|
976
|
+
provider: AIProvider;
|
|
977
|
+
fs: VirtualFs;
|
|
978
|
+
computer: VirtualComputer;
|
|
979
|
+
sessionDir: string;
|
|
980
|
+
skills?: SkillDefinition[];
|
|
981
|
+
tools?: Tool[];
|
|
982
|
+
systemPrompt?: string;
|
|
983
|
+
model?: string;
|
|
984
|
+
maxTokens?: number;
|
|
985
|
+
autoCompact?: AutoCompactConfig;
|
|
986
|
+
microcompact?: MicrocompactConfig;
|
|
987
|
+
toolResultBudget?: ToolResultBudgetConfig;
|
|
988
|
+
reactiveCompact?: ReactiveCompactConfig;
|
|
989
|
+
permissions?: PermissionConfig;
|
|
990
|
+
hooks?: HookDefinition[];
|
|
991
|
+
spawnSubagent?: (config: SubagentConfig) => SubagentRun;
|
|
992
|
+
streamingToolExecution?: boolean;
|
|
993
|
+
/** Truncate individual tool results exceeding this character count. Default: 100000. */
|
|
994
|
+
maxResultChars?: number;
|
|
995
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
996
|
+
taskStore?: TaskStore;
|
|
997
|
+
lspManager?: LspServerManager;
|
|
998
|
+
thinking?: ThinkingConfig;
|
|
999
|
+
retry?: RetryConfig;
|
|
1000
|
+
costTracker?: CostTracker;
|
|
1001
|
+
tracer?: Tracer;
|
|
1002
|
+
memory?: MemoryConfig;
|
|
1003
|
+
toolSearchEnabled?: boolean;
|
|
1004
|
+
checkpointManager?: FileCheckpointManager;
|
|
1005
|
+
/** File state cache config for read-before-edit enforcement. */
|
|
1006
|
+
fileStateCacheConfig?: FileStateCacheConfig;
|
|
1007
|
+
/** Disk-backed tool result storage config. */
|
|
1008
|
+
toolResultStorage?: ToolResultStorageConfig;
|
|
1009
|
+
/** History snip: enable middle-range removal from conversation history. */
|
|
1010
|
+
historySnip?: SnipConfig;
|
|
1011
|
+
/** Enable deterministic tool ordering and CacheSafeParams tracking for prompt caching. */
|
|
1012
|
+
promptCachingEnabled?: boolean;
|
|
1013
|
+
/** When true, signal skipCacheWrite to the provider (for subagent forks). */
|
|
1014
|
+
skipCacheWrite?: boolean;
|
|
1015
|
+
/** Set of MCP tool names for cache-stable sorting (built-in first, then MCP). */
|
|
1016
|
+
mcpToolNames?: ReadonlySet<string>;
|
|
1017
|
+
/** Loaded project context files (NOUMEN.md / CLAUDE.md) for system prompt injection. */
|
|
1018
|
+
projectContext?: ContextFile[];
|
|
1019
|
+
/** Default structured output format for all runs on this thread. */
|
|
1020
|
+
outputFormat?: OutputFormat;
|
|
1021
|
+
/** Default structured output mode for all runs on this thread. */
|
|
1022
|
+
structuredOutputMode?: "alongside_tools" | "final_response";
|
|
1023
|
+
/** When true, assert normalization invariants after every API message preparation. */
|
|
1024
|
+
debug?: boolean;
|
|
1025
|
+
}
|
|
1026
|
+
declare class Thread {
|
|
1027
|
+
readonly sessionId: string;
|
|
1028
|
+
private config;
|
|
1029
|
+
private storage;
|
|
1030
|
+
private toolRegistry;
|
|
1031
|
+
private messages;
|
|
1032
|
+
private loaded;
|
|
1033
|
+
private abortController;
|
|
1034
|
+
private cwd;
|
|
1035
|
+
private model;
|
|
1036
|
+
private activatedSkills;
|
|
1037
|
+
private activatedContextRules;
|
|
1038
|
+
private permissionContext;
|
|
1039
|
+
private permissionHandler;
|
|
1040
|
+
private hooks;
|
|
1041
|
+
private lastUsage;
|
|
1042
|
+
private anchorMessageIndex;
|
|
1043
|
+
private prePlanMode;
|
|
1044
|
+
private tracer;
|
|
1045
|
+
private autoCompactTracking;
|
|
1046
|
+
private budgetState;
|
|
1047
|
+
private hasAttemptedReactiveCompact;
|
|
1048
|
+
private microcompactTokensFreed;
|
|
1049
|
+
private querySource;
|
|
1050
|
+
private resumeRequested;
|
|
1051
|
+
private fileStateCache;
|
|
1052
|
+
private contentReplacementState;
|
|
1053
|
+
private denialTracker;
|
|
1054
|
+
/** Tracks file paths read by ReadFile for post-compact reinjection. */
|
|
1055
|
+
private recentlyReadFiles;
|
|
1056
|
+
constructor(config: ThreadConfig, opts?: ThreadOptions);
|
|
1057
|
+
run(prompt: string | ContentPart[], opts?: RunOptions): AsyncGenerator<StreamEvent, void, unknown>;
|
|
1058
|
+
/**
|
|
1059
|
+
* If tool result storage is enabled and the content exceeds the threshold,
|
|
1060
|
+
* spill to disk and return the replacement stub. Otherwise return the original.
|
|
1061
|
+
*/
|
|
1062
|
+
private maybeSpillToolResult;
|
|
1063
|
+
private buildStreamingExecutorFn;
|
|
1064
|
+
private buildPermissionOpts;
|
|
1065
|
+
private buildCurrentSystemPromptAsync;
|
|
1066
|
+
getMessages(): Promise<ChatMessage[]>;
|
|
1067
|
+
compact(opts?: {
|
|
1068
|
+
instructions?: string;
|
|
1069
|
+
}): Promise<void>;
|
|
1070
|
+
/**
|
|
1071
|
+
* Remove specific messages from the middle of conversation history.
|
|
1072
|
+
*
|
|
1073
|
+
* Unlike `compact()` which summarizes a prefix, `snip()` removes
|
|
1074
|
+
* specific messages by UUID. The JSONL transcript records the removed
|
|
1075
|
+
* UUIDs so they're filtered on resume. Parent pointers are relinked
|
|
1076
|
+
* across gaps.
|
|
1077
|
+
*
|
|
1078
|
+
* @param uuids - UUIDs of messages to remove
|
|
1079
|
+
*/
|
|
1080
|
+
snip(uuids: string[]): Promise<void>;
|
|
1081
|
+
setModel(model: string): void;
|
|
1082
|
+
setProvider(provider: AIProvider, model?: string): void;
|
|
1083
|
+
getModel(): string;
|
|
1084
|
+
getCwd(): string;
|
|
1085
|
+
abort(): void;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
interface DiagnoseCheckResult {
|
|
1089
|
+
ok: boolean;
|
|
1090
|
+
latencyMs: number;
|
|
1091
|
+
error?: string;
|
|
1092
|
+
warning?: string;
|
|
1093
|
+
}
|
|
1094
|
+
interface DiagnoseResult {
|
|
1095
|
+
overall: boolean;
|
|
1096
|
+
provider: DiagnoseCheckResult & {
|
|
1097
|
+
model?: string;
|
|
1098
|
+
};
|
|
1099
|
+
sandbox: {
|
|
1100
|
+
fs: DiagnoseCheckResult;
|
|
1101
|
+
computer: DiagnoseCheckResult;
|
|
1102
|
+
};
|
|
1103
|
+
sandboxRuntime: DiagnoseCheckResult & {
|
|
1104
|
+
platform?: string;
|
|
1105
|
+
};
|
|
1106
|
+
mcp: Record<string, DiagnoseCheckResult & {
|
|
1107
|
+
status?: string;
|
|
1108
|
+
toolCount?: number;
|
|
1109
|
+
}>;
|
|
1110
|
+
lsp: Record<string, DiagnoseCheckResult & {
|
|
1111
|
+
state?: string;
|
|
1112
|
+
}>;
|
|
1113
|
+
timestamp: string;
|
|
1114
|
+
}
|
|
1115
|
+
interface AgentOptions {
|
|
1116
|
+
/**
|
|
1117
|
+
* AI provider — either an `AIProvider` instance or a provider name string.
|
|
1118
|
+
* When a string is passed (e.g. `"openai"`), the provider is resolved
|
|
1119
|
+
* lazily using env-var auto-detection on the first call to `run()`,
|
|
1120
|
+
* `createThread()`, or `init()`.
|
|
1121
|
+
*/
|
|
1122
|
+
provider: AIProvider | ProviderName;
|
|
1123
|
+
/**
|
|
1124
|
+
* Working directory. When set without an explicit `sandbox`, an
|
|
1125
|
+
* `UnsandboxedLocal({ cwd })` is created automatically.
|
|
1126
|
+
*/
|
|
1127
|
+
cwd?: string;
|
|
1128
|
+
/**
|
|
1129
|
+
* Bundled sandbox providing both filesystem and shell execution.
|
|
1130
|
+
* Use `LocalSandbox()` for OS-level sandboxing (requires
|
|
1131
|
+
* `@anthropic-ai/sandbox-runtime`), `UnsandboxedLocal()` for raw host
|
|
1132
|
+
* access, `SpritesSandbox()` for isolated remote containers, or pass
|
|
1133
|
+
* any `{ fs: VirtualFs; computer: VirtualComputer }` for custom sandboxes.
|
|
1134
|
+
*
|
|
1135
|
+
* Defaults to `UnsandboxedLocal({ cwd })` when omitted — the library
|
|
1136
|
+
* default is non-sandboxed for backward compatibility. The CLI defaults
|
|
1137
|
+
* to `LocalSandbox()` when sandbox-runtime is available.
|
|
1138
|
+
*/
|
|
1139
|
+
sandbox?: Sandbox;
|
|
1140
|
+
options?: {
|
|
1141
|
+
sessionDir?: string;
|
|
1142
|
+
skills?: SkillDefinition[];
|
|
1143
|
+
skillsPaths?: string[];
|
|
1144
|
+
tools?: Tool[];
|
|
1145
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
1146
|
+
/** Token storage for MCP OAuth flows (defaults to in-memory). */
|
|
1147
|
+
mcpTokenStorage?: TokenStorage;
|
|
1148
|
+
/** Called when an MCP server requires OAuth and the user must visit a URL. */
|
|
1149
|
+
mcpOnAuthorizationUrl?: (url: string) => void | Promise<void>;
|
|
1150
|
+
systemPrompt?: string;
|
|
1151
|
+
model?: string;
|
|
1152
|
+
maxTokens?: number;
|
|
1153
|
+
autoCompact?: boolean;
|
|
1154
|
+
autoCompactThreshold?: number;
|
|
1155
|
+
microcompact?: MicrocompactConfig;
|
|
1156
|
+
toolResultBudget?: ToolResultBudgetConfig;
|
|
1157
|
+
reactiveCompact?: ReactiveCompactConfig;
|
|
1158
|
+
cwd?: string;
|
|
1159
|
+
permissions?: PermissionConfig;
|
|
1160
|
+
hooks?: HookDefinition[];
|
|
1161
|
+
enableSubagents?: boolean;
|
|
1162
|
+
enableTasks?: boolean;
|
|
1163
|
+
tasksDir?: string;
|
|
1164
|
+
enablePlanMode?: boolean;
|
|
1165
|
+
enableWorktrees?: boolean;
|
|
1166
|
+
lsp?: Record<string, LspServerConfig>;
|
|
1167
|
+
streamingToolExecution?: boolean;
|
|
1168
|
+
webSearch?: WebSearchConfig;
|
|
1169
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
1170
|
+
thinking?: ThinkingConfig;
|
|
1171
|
+
retry?: RetryConfig | boolean;
|
|
1172
|
+
costTracking?: {
|
|
1173
|
+
enabled: boolean;
|
|
1174
|
+
pricing?: Record<string, ModelPricing>;
|
|
1175
|
+
};
|
|
1176
|
+
tracing?: TracingConfig;
|
|
1177
|
+
memory?: MemoryConfig;
|
|
1178
|
+
/** Enable ToolSearch: deferred tools are hidden until the model discovers them. */
|
|
1179
|
+
toolSearch?: boolean;
|
|
1180
|
+
/** File checkpointing: snapshot files before edits for rollback. */
|
|
1181
|
+
checkpoint?: CheckpointConfig;
|
|
1182
|
+
/** Prompt caching: enable deterministic tool ordering and cache_control injection. */
|
|
1183
|
+
promptCaching?: CacheControlConfig;
|
|
1184
|
+
/** File state cache: track reads for read-before-edit enforcement. */
|
|
1185
|
+
fileStateCache?: FileStateCacheConfig;
|
|
1186
|
+
/** Disk-backed storage for oversized tool results. */
|
|
1187
|
+
toolResultStorage?: ToolResultStorageConfig;
|
|
1188
|
+
/** History snip: enable middle-range removal from conversation history. */
|
|
1189
|
+
historySnip?: SnipConfig;
|
|
1190
|
+
/** Project context loading (NOUMEN.md / CLAUDE.md). Pass true for defaults or a config object. */
|
|
1191
|
+
projectContext?: ProjectContextConfig | boolean;
|
|
1192
|
+
/** Default structured output format for all threads. */
|
|
1193
|
+
outputFormat?: OutputFormat;
|
|
1194
|
+
/** Default structured output mode for all threads. */
|
|
1195
|
+
structuredOutputMode?: "alongside_tools" | "final_response";
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
interface RunCallbacks {
|
|
1199
|
+
onText?: (text: string) => void;
|
|
1200
|
+
onThinking?: (text: string) => void;
|
|
1201
|
+
onToolUse?: (toolName: string, args: Record<string, unknown>) => void;
|
|
1202
|
+
onToolResult?: (toolName: string, result: ToolResult) => void;
|
|
1203
|
+
onError?: (error: Error) => void;
|
|
1204
|
+
onComplete?: (result: RunResult) => void;
|
|
1205
|
+
}
|
|
1206
|
+
interface RunResult {
|
|
1207
|
+
text: string;
|
|
1208
|
+
toolCalls: number;
|
|
1209
|
+
usage: ChatCompletionUsage;
|
|
1210
|
+
sessionId: string;
|
|
1211
|
+
}
|
|
1212
|
+
declare class Agent {
|
|
1213
|
+
private providerInput;
|
|
1214
|
+
private resolvedProvider;
|
|
1215
|
+
private fs;
|
|
1216
|
+
private computer;
|
|
1217
|
+
private sandbox;
|
|
1218
|
+
private sessionDir;
|
|
1219
|
+
private skills;
|
|
1220
|
+
private skillsPaths;
|
|
1221
|
+
private tools;
|
|
1222
|
+
private systemPrompt?;
|
|
1223
|
+
private model?;
|
|
1224
|
+
private maxTokens?;
|
|
1225
|
+
private autoCompactEnabled;
|
|
1226
|
+
private autoCompactThreshold?;
|
|
1227
|
+
private cwd;
|
|
1228
|
+
private storage;
|
|
1229
|
+
private resolvedSkills;
|
|
1230
|
+
private mcpManager;
|
|
1231
|
+
private mcpServerConfigs?;
|
|
1232
|
+
private mcpTokenStorage?;
|
|
1233
|
+
private mcpOnAuthorizationUrl?;
|
|
1234
|
+
private mcpTools;
|
|
1235
|
+
private mcpToolNames;
|
|
1236
|
+
private mcpAuthTools;
|
|
1237
|
+
private permissions?;
|
|
1238
|
+
private hooks;
|
|
1239
|
+
private enableSubagents;
|
|
1240
|
+
private enableTasks;
|
|
1241
|
+
private taskStore;
|
|
1242
|
+
private enablePlanMode;
|
|
1243
|
+
private enableWorktrees;
|
|
1244
|
+
private lspManager;
|
|
1245
|
+
private lspConfigs?;
|
|
1246
|
+
private lspToolRef;
|
|
1247
|
+
private streamingToolExecution;
|
|
1248
|
+
private webSearchConfig?;
|
|
1249
|
+
private userInputHandler?;
|
|
1250
|
+
private thinkingConfig?;
|
|
1251
|
+
private retryConfig?;
|
|
1252
|
+
private costTracker;
|
|
1253
|
+
private tracer?;
|
|
1254
|
+
private memoryProvider?;
|
|
1255
|
+
private memoryConfig?;
|
|
1256
|
+
private microcompactConfig?;
|
|
1257
|
+
private toolResultBudgetConfig?;
|
|
1258
|
+
private reactiveCompactConfig?;
|
|
1259
|
+
private toolSearchEnabled;
|
|
1260
|
+
private projectContextConfig?;
|
|
1261
|
+
private resolvedProjectContext;
|
|
1262
|
+
private checkpointManager;
|
|
1263
|
+
private promptCachingConfig;
|
|
1264
|
+
private fileStateCacheConfig;
|
|
1265
|
+
private toolResultStorageConfig;
|
|
1266
|
+
private historySnipConfig;
|
|
1267
|
+
private outputFormat;
|
|
1268
|
+
private structuredOutputMode;
|
|
1269
|
+
private providerPromise;
|
|
1270
|
+
private initPromise;
|
|
1271
|
+
constructor(opts: AgentOptions);
|
|
1272
|
+
private ensureProvider;
|
|
1273
|
+
private getProvider;
|
|
1274
|
+
private getSkills;
|
|
1275
|
+
private getAllTools;
|
|
1276
|
+
private createSpawnSubagent;
|
|
1277
|
+
createThread(opts?: ThreadOptions): Promise<Thread>;
|
|
1278
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
1279
|
+
getCostSummary(): CostSummary | null;
|
|
1280
|
+
/**
|
|
1281
|
+
* Create a thread that resumes an existing session. Automatically restores
|
|
1282
|
+
* messages (respecting compact boundaries), file checkpoint state, and
|
|
1283
|
+
* cost tracking state from the persisted JSONL transcript.
|
|
1284
|
+
*/
|
|
1285
|
+
resumeThread(sessionId: string, opts?: Omit<ThreadOptions, "sessionId" | "resume">): Promise<Thread>;
|
|
1286
|
+
/**
|
|
1287
|
+
* One-shot streaming: creates an ephemeral thread and yields events.
|
|
1288
|
+
* Auto-resolves string providers on first call (no need to call `init()`).
|
|
1289
|
+
*
|
|
1290
|
+
* ```ts
|
|
1291
|
+
* for await (const event of agent.run("Fix the bug")) {
|
|
1292
|
+
* if (event.type === "text_delta") process.stdout.write(event.text);
|
|
1293
|
+
* }
|
|
1294
|
+
* ```
|
|
1295
|
+
*/
|
|
1296
|
+
run(prompt: string | ContentPart[], opts?: RunOptions & ThreadOptions): AsyncGenerator<StreamEvent, void, unknown>;
|
|
1297
|
+
/**
|
|
1298
|
+
* One-shot execution: runs the prompt to completion and returns a result
|
|
1299
|
+
* summary. Optional callbacks fire as events arrive.
|
|
1300
|
+
*
|
|
1301
|
+
* ```ts
|
|
1302
|
+
* const result = await agent.execute("Fix the bug", {
|
|
1303
|
+
* onText: (text) => process.stdout.write(text),
|
|
1304
|
+
* });
|
|
1305
|
+
* console.log(`Done — ${result.toolCalls} tool calls`);
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
execute(prompt: string | ContentPart[], opts?: RunOptions & ThreadOptions & RunCallbacks): Promise<RunResult>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Pre-resolve the provider (if string), skills, MCP servers, and LSP servers.
|
|
1311
|
+
* Call this once after construction if using a string provider, skillsPaths,
|
|
1312
|
+
* mcpServers, or lsp, so that createThread() has everything available synchronously.
|
|
1313
|
+
*/
|
|
1314
|
+
init(): Promise<void>;
|
|
1315
|
+
private doInit;
|
|
1316
|
+
/**
|
|
1317
|
+
* Run health checks on the provider, sandbox, MCP servers, and LSP servers.
|
|
1318
|
+
* Returns a structured report — useful for debugging integration issues.
|
|
1319
|
+
*
|
|
1320
|
+
* @param timeoutMs Per-check timeout in milliseconds (default 10 000).
|
|
1321
|
+
*/
|
|
1322
|
+
diagnose(timeoutMs?: number): Promise<DiagnoseResult>;
|
|
1323
|
+
private get sandboxIndexPath();
|
|
1324
|
+
private loadSandboxId;
|
|
1325
|
+
private storeSandboxId;
|
|
1326
|
+
/**
|
|
1327
|
+
* Disconnect all MCP clients. Call when done with this Agent instance.
|
|
1328
|
+
*/
|
|
1329
|
+
close(): Promise<void>;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
export { type RunCallbacks as $, Agent as A, type BudgetState as B, type ContextFile as C, type DockerContainer as D, type E2BSandboxInstance as E, type FreestyleVmInstance as F, E2BComputer as G, type E2BComputerOptions as H, E2BSandbox as I, type E2BSandboxOptions as J, FreestyleComputer as K, type FreestyleComputerOptions as L, FreestyleSandbox as M, type FreestyleSandboxOptions as N, LocalSandbox as O, type ProjectContextConfig as P, type LocalSandboxOptions as Q, type RetryConfig as R, type Sandbox as S, type ThreadConfig as T, type MicrocompactConfig as U, type MicrocompactResult as V, type ProviderName as W, type ReactiveCompactConfig as X, type ReactiveCompactResult as Y, type ResolveProviderOptions as Z, type RetryEvent as _, type SkillDefinition as a, type RunResult as a0, SUPPORTED_PROVIDERS as a1, type SandboxConfig as a2, SandboxedLocalComputer as a3, type SandboxedLocalComputerOptions as a4, type SnipConfig as a5, type SnipResult as a6, SpritesSandbox as a7, type SpritesSandboxOptions as a8, Thread as a9, recordAutoCompactFailure as aA, recordAutoCompactSuccess as aB, resolveProvider as aC, shouldAutoCompact as aD, snipMessagesByUuids as aE, tryReactiveCompact as aF, webSearchToolPlaceholder as aG, type ThreadOptions as aa, type ToolResultBudgetConfig as ab, type ToolResultBudgetResult as ac, type ContentReplacementRecord as ad, type ToolResultSpillResult as ae, type ToolResultStorageConfig as af, type TracingConfig as ag, UnsandboxedLocal as ah, type UnsandboxedLocalOptions as ai, type WebSearchConfig as aj, type WebSearchResult as ak, applyPersistedReplacements as al, applySnipRemovals as am, canAutoCompact as an, createAutoCompactConfig as ao, createAutoCompactTracking as ap, createBudgetState as aq, createContentReplacementState as ar, createWebSearchTool as as, detectProvider as at, enforceToolResultBudget as au, enforceToolResultStorageBudget as av, microcompactMessages as aw, persistToolResult as ax, projectSnippedView as ay, reconstructContentReplacementState as az, SessionStorage as b, type ContextScope as c, type RetryContext as d, type RetryEngineOptions as e, type Span as f, type SpanAttributeValue as g, SpanStatusCode as h, type Tracer as i, type SpanOptions as j, type StoredCostState as k, type AgentOptions as l, type AutoCompactConfig as m, type AutoCompactTrackingState as n, CLEARED_PLACEHOLDER as o, COMPACTABLE_TOOLS as p, type ContentReplacementState as q, CostTracker as r, DEFAULT_MODELS as s, DEFAULT_RETRY_CONFIG as t, type DiagnoseCheckResult as u, type DiagnoseResult as v, DockerComputer as w, type DockerComputerOptions as x, DockerSandbox as y, type DockerSandboxOptions as z };
|