noumen 0.1.0 → 0.2.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 +767 -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-BrkbZyOT.d.ts +1028 -0
- package/dist/cache-DVqaCX8v.d.ts +38 -0
- package/dist/chunk-2ZTGQLYK.js +356 -0
- package/dist/chunk-2ZTGQLYK.js.map +1 -0
- package/dist/chunk-42PHHZUA.js +132 -0
- package/dist/chunk-42PHHZUA.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-7ZMN7XJE.js +94 -0
- package/dist/chunk-7ZMN7XJE.js.map +1 -0
- package/dist/chunk-AMYIJSAZ.js +57 -0
- package/dist/chunk-AMYIJSAZ.js.map +1 -0
- package/dist/chunk-BGG2E6JD.js +10 -0
- package/dist/chunk-BGG2E6JD.js.map +1 -0
- package/dist/chunk-BZSFUEWM.js +43 -0
- package/dist/chunk-BZSFUEWM.js.map +1 -0
- package/dist/chunk-CPFHEPW4.js +139 -0
- package/dist/chunk-CPFHEPW4.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-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-KY6ZPWHO.js +112 -0
- package/dist/chunk-KY6ZPWHO.js.map +1 -0
- package/dist/chunk-NBDFQYUZ.js +7992 -0
- package/dist/chunk-NBDFQYUZ.js.map +1 -0
- package/dist/chunk-OGXNFXFA.js +196 -0
- package/dist/chunk-OGXNFXFA.js.map +1 -0
- package/dist/chunk-QTJ7VTJY.js +1994 -0
- package/dist/chunk-QTJ7VTJY.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 +868 -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-Q7XHHZIW.js +143 -0
- package/dist/headless-Q7XHHZIW.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 +1305 -418
- package/dist/index.js +384 -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 +104 -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/ollama-YNXAYP3R.js +18 -0
- package/dist/ollama-YNXAYP3R.js.map +1 -0
- package/dist/provider-factory-34MSWJZ3.js +20 -0
- package/dist/provider-factory-34MSWJZ3.js.map +1 -0
- package/dist/providers/anthropic.d.ts +19 -0
- package/dist/providers/anthropic.js +33 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/bedrock.d.ts +39 -0
- package/dist/providers/bedrock.js +54 -0
- package/dist/providers/bedrock.js.map +1 -0
- package/dist/providers/gemini.d.ts +16 -0
- package/dist/providers/gemini.js +224 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/openai.d.ts +18 -0
- package/dist/providers/openai.js +8 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +16 -0
- package/dist/providers/openrouter.js +23 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/vertex.d.ts +40 -0
- package/dist/providers/vertex.js +64 -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-XM52G7YE.js +14 -0
- package/dist/resolve-XM52G7YE.js.map +1 -0
- package/dist/server/index.d.ts +128 -0
- package/dist/server/index.js +626 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server-Cg1yWGaV.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-3c88cRKH.d.ts +547 -0
- package/dist/types-CwKKucOF.d.ts +620 -0
- package/dist/types-DwdzmXfs.d.ts +107 -0
- package/dist/types-NIyVwQ4h.d.ts +109 -0
- package/dist/types-QwfylltH.d.ts +71 -0
- package/package.json +134 -6
|
@@ -0,0 +1,1028 @@
|
|
|
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-3c88cRKH.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-CwKKucOF.js';
|
|
3
|
+
import { C as CacheControlConfig } from './cache-DVqaCX8v.js';
|
|
4
|
+
import { M as McpServerConfig, T as TokenStorage } from './types-2kTLUCnD.js';
|
|
5
|
+
import { c as PermissionHandler, d as PermissionConfig } from './types-DwdzmXfs.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
|
+
* Bundled sandbox: a `VirtualFs` and `VirtualComputer` paired together.
|
|
173
|
+
*
|
|
174
|
+
* Use one of the built-in factories (`LocalSandbox`, `UnsandboxedLocal`,
|
|
175
|
+
* `SpritesSandbox`) or supply any object that satisfies this shape for
|
|
176
|
+
* custom sandboxes (Docker, E2B, Daytona, in-memory, etc.).
|
|
177
|
+
*/
|
|
178
|
+
interface Sandbox {
|
|
179
|
+
fs: VirtualFs;
|
|
180
|
+
computer: VirtualComputer;
|
|
181
|
+
}
|
|
182
|
+
interface UnsandboxedLocalOptions {
|
|
183
|
+
/** Working directory for both file resolution and command execution. */
|
|
184
|
+
cwd?: string;
|
|
185
|
+
/** Default timeout (ms) for shell commands. */
|
|
186
|
+
defaultTimeout?: number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a `Sandbox` backed by the host filesystem and shell with **no
|
|
190
|
+
* OS-level isolation**. The agent can access anything the host process can.
|
|
191
|
+
*
|
|
192
|
+
* Use this for development or fully-trusted environments where sandboxing
|
|
193
|
+
* overhead is unwanted. For production use, prefer `LocalSandbox()` (which
|
|
194
|
+
* wraps commands with `@anthropic-ai/sandbox-runtime`).
|
|
195
|
+
*/
|
|
196
|
+
declare function UnsandboxedLocal(opts?: UnsandboxedLocalOptions): Sandbox;
|
|
197
|
+
interface LocalSandboxOptions {
|
|
198
|
+
/** Working directory for both file resolution and command execution. */
|
|
199
|
+
cwd?: string;
|
|
200
|
+
/** Default timeout (ms) for shell commands. */
|
|
201
|
+
defaultTimeout?: number;
|
|
202
|
+
/**
|
|
203
|
+
* Sandbox restrictions. Defaults: writes allowed only in `cwd`,
|
|
204
|
+
* reads allowed everywhere, network unrestricted.
|
|
205
|
+
*/
|
|
206
|
+
sandbox?: SandboxConfig;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a `Sandbox` with OS-level isolation via `@anthropic-ai/sandbox-runtime`.
|
|
210
|
+
*
|
|
211
|
+
* - **macOS**: Seatbelt (`sandbox-exec`) profiles restrict filesystem and network.
|
|
212
|
+
* - **Linux**: bubblewrap (`bwrap`) + socat for namespace-based isolation.
|
|
213
|
+
*
|
|
214
|
+
* Filesystem operations (`VirtualFs`) use the host `node:fs` — the sandbox
|
|
215
|
+
* boundary is enforced on shell commands (`VirtualComputer`), which is where
|
|
216
|
+
* the agent executes arbitrary code.
|
|
217
|
+
*
|
|
218
|
+
* Requires `@anthropic-ai/sandbox-runtime` as a peer dependency.
|
|
219
|
+
*/
|
|
220
|
+
declare function LocalSandbox(opts?: LocalSandboxOptions): Sandbox;
|
|
221
|
+
interface SpritesSandboxOptions {
|
|
222
|
+
/** sprites.dev API token. */
|
|
223
|
+
token: string;
|
|
224
|
+
/** Name of the sprite container. */
|
|
225
|
+
spriteName: string;
|
|
226
|
+
/** Base URL for sprites API (default: https://api.sprites.dev). */
|
|
227
|
+
baseURL?: string;
|
|
228
|
+
/** Working directory inside the sprite (default: /home/sprite). */
|
|
229
|
+
workingDir?: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Create a `Sandbox` backed by a remote sprites.dev container.
|
|
233
|
+
* Full isolation — the agent has no access to the host machine.
|
|
234
|
+
*/
|
|
235
|
+
declare function SpritesSandbox(opts: SpritesSandboxOptions): Sandbox;
|
|
236
|
+
interface DockerSandboxOptions {
|
|
237
|
+
/** A dockerode Container instance for the target container. */
|
|
238
|
+
container: DockerContainer;
|
|
239
|
+
/** Working directory inside the container. */
|
|
240
|
+
cwd?: string;
|
|
241
|
+
/** Default timeout (ms) for shell commands. */
|
|
242
|
+
defaultTimeout?: number;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create a `Sandbox` backed by a Docker container.
|
|
246
|
+
* Requires `dockerode` as an optional peer dependency.
|
|
247
|
+
*/
|
|
248
|
+
declare function DockerSandbox(opts: DockerSandboxOptions): Sandbox;
|
|
249
|
+
interface E2BSandboxOptions {
|
|
250
|
+
/** An E2B Sandbox instance created via `Sandbox.create()`. */
|
|
251
|
+
sandbox: E2BSandboxInstance;
|
|
252
|
+
/** Working directory inside the sandbox. */
|
|
253
|
+
cwd?: string;
|
|
254
|
+
/** Default timeout (ms) for shell commands. */
|
|
255
|
+
defaultTimeout?: number;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Create a `Sandbox` backed by an E2B cloud sandbox.
|
|
259
|
+
* Requires `e2b` as an optional peer dependency.
|
|
260
|
+
*/
|
|
261
|
+
declare function E2BSandbox(opts: E2BSandboxOptions): Sandbox;
|
|
262
|
+
|
|
263
|
+
interface SkillDefinition {
|
|
264
|
+
name: string;
|
|
265
|
+
/** Skill body content (after frontmatter is stripped) */
|
|
266
|
+
content: string;
|
|
267
|
+
path?: string;
|
|
268
|
+
description?: string;
|
|
269
|
+
/** Glob patterns for files this skill applies to (from frontmatter `paths`) */
|
|
270
|
+
globs?: string[];
|
|
271
|
+
/** Tool names this skill is allowed to use */
|
|
272
|
+
allowedTools?: string[];
|
|
273
|
+
/** Execution context: inline expands into conversation, fork runs as sub-agent */
|
|
274
|
+
context?: "inline" | "fork";
|
|
275
|
+
/** Hint for the $ARGUMENTS placeholder */
|
|
276
|
+
argumentHint?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface WebSearchResult {
|
|
280
|
+
title: string;
|
|
281
|
+
url: string;
|
|
282
|
+
snippet: string;
|
|
283
|
+
}
|
|
284
|
+
interface WebSearchConfig {
|
|
285
|
+
search: (query: string, domains?: string[]) => Promise<WebSearchResult[]>;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Create a WebSearch tool backed by a user-provided search implementation.
|
|
289
|
+
* This keeps noumen provider-agnostic — plug in Tavily, SerpAPI, Brave Search, etc.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const webSearch = createWebSearchTool({
|
|
294
|
+
* search: async (query) => {
|
|
295
|
+
* const res = await tavily.search({ query });
|
|
296
|
+
* return res.results.map(r => ({ title: r.title, url: r.url, snippet: r.content }));
|
|
297
|
+
* },
|
|
298
|
+
* });
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare function createWebSearchTool(config: WebSearchConfig): Tool;
|
|
302
|
+
/**
|
|
303
|
+
* Default WebSearch tool that returns a helpful error when no search provider
|
|
304
|
+
* is configured. Register this as a placeholder; consumers should replace
|
|
305
|
+
* it with `createWebSearchTool(config)`.
|
|
306
|
+
*/
|
|
307
|
+
declare const webSearchToolPlaceholder: Tool;
|
|
308
|
+
|
|
309
|
+
interface RetryConfig {
|
|
310
|
+
maxRetries?: number;
|
|
311
|
+
baseDelayMs?: number;
|
|
312
|
+
maxDelayMs?: number;
|
|
313
|
+
retryableStatuses?: number[];
|
|
314
|
+
fallbackModel?: string;
|
|
315
|
+
/** Max consecutive overloaded (529) errors before triggering model fallback. */
|
|
316
|
+
maxConsecutiveOverloaded?: number;
|
|
317
|
+
onRetry?: (attempt: number, error: Error, delayMs: number) => void;
|
|
318
|
+
}
|
|
319
|
+
declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
320
|
+
interface RetryEngineOptions extends RetryConfig {
|
|
321
|
+
model: string;
|
|
322
|
+
thinkingBudget?: number;
|
|
323
|
+
signal?: AbortSignal;
|
|
324
|
+
}
|
|
325
|
+
interface RetryContext {
|
|
326
|
+
attempt: number;
|
|
327
|
+
model: string;
|
|
328
|
+
maxTokensOverride?: number;
|
|
329
|
+
}
|
|
330
|
+
type RetryEvent = Extract<StreamEvent, {
|
|
331
|
+
type: "retry_attempt" | "retry_exhausted";
|
|
332
|
+
}>;
|
|
333
|
+
|
|
334
|
+
declare const SpanStatusCode: {
|
|
335
|
+
readonly OK: 0;
|
|
336
|
+
readonly ERROR: 1;
|
|
337
|
+
};
|
|
338
|
+
type SpanStatusCode = (typeof SpanStatusCode)[keyof typeof SpanStatusCode];
|
|
339
|
+
type SpanAttributeValue = string | number | boolean;
|
|
340
|
+
interface SpanOptions {
|
|
341
|
+
parent?: Span;
|
|
342
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
343
|
+
}
|
|
344
|
+
interface Span {
|
|
345
|
+
readonly name: string;
|
|
346
|
+
setAttribute(key: string, value: SpanAttributeValue): void;
|
|
347
|
+
addEvent(name: string, attributes?: Record<string, SpanAttributeValue>): void;
|
|
348
|
+
setStatus(code: SpanStatusCode, message?: string): void;
|
|
349
|
+
end(): void;
|
|
350
|
+
}
|
|
351
|
+
interface Tracer {
|
|
352
|
+
startSpan(name: string, options?: SpanOptions): Span;
|
|
353
|
+
}
|
|
354
|
+
interface TracingConfig {
|
|
355
|
+
tracer: Tracer;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
interface MicrocompactConfig {
|
|
359
|
+
enabled: boolean;
|
|
360
|
+
/** Keep the N most recent compactable tool results uncleared. Default: 5 */
|
|
361
|
+
keepRecent?: number;
|
|
362
|
+
}
|
|
363
|
+
interface MicrocompactResult {
|
|
364
|
+
messages: ChatMessage[];
|
|
365
|
+
tokensFreed: number;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Tools whose results can be safely cleared to free context tokens.
|
|
369
|
+
* Includes read-heavy tools (ReadFile, Grep, Glob, WebFetch, WebSearch,
|
|
370
|
+
* Bash) as well as mutation tools (EditFile, WriteFile) whose results
|
|
371
|
+
* are short confirmation strings the model can reconstruct from context.
|
|
372
|
+
*/
|
|
373
|
+
declare const COMPACTABLE_TOOLS: Set<string>;
|
|
374
|
+
declare const CLEARED_PLACEHOLDER = "[tool result cleared to save context]";
|
|
375
|
+
/**
|
|
376
|
+
* Clear the content of old tool-result messages to free context tokens
|
|
377
|
+
* without a full summarization pass.
|
|
378
|
+
*
|
|
379
|
+
* Only results from {@link COMPACTABLE_TOOLS} are eligible. The most
|
|
380
|
+
* recent `keepRecent` eligible results are preserved; older ones have
|
|
381
|
+
* their content replaced with {@link CLEARED_PLACEHOLDER}.
|
|
382
|
+
*
|
|
383
|
+
* Returns a **new** messages array (shallow-copied where unchanged).
|
|
384
|
+
*/
|
|
385
|
+
declare function microcompactMessages(messages: ChatMessage[], config: MicrocompactConfig): MicrocompactResult;
|
|
386
|
+
|
|
387
|
+
interface ToolResultBudgetConfig {
|
|
388
|
+
enabled: boolean;
|
|
389
|
+
/** Max total chars across all tool results in one group. Default: 200_000 */
|
|
390
|
+
maxCharsPerGroup?: number;
|
|
391
|
+
/** Max chars for a single tool result before individual truncation. Default: 50_000 */
|
|
392
|
+
maxCharsPerResult?: number;
|
|
393
|
+
/** Number of preview chars to keep when truncating. Default: 1_000 */
|
|
394
|
+
previewChars?: number;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Tracks which tool_call_ids have already been truncated so that
|
|
398
|
+
* decisions are deterministic across repeated calls and session resume.
|
|
399
|
+
*/
|
|
400
|
+
interface BudgetState {
|
|
401
|
+
truncatedIds: Set<string>;
|
|
402
|
+
}
|
|
403
|
+
declare function createBudgetState(): BudgetState;
|
|
404
|
+
interface ToolResultBudgetResult {
|
|
405
|
+
messages: ChatMessage[];
|
|
406
|
+
state: BudgetState;
|
|
407
|
+
tokensFreed: number;
|
|
408
|
+
truncatedEntries: Array<{
|
|
409
|
+
toolCallId: string;
|
|
410
|
+
originalChars: number;
|
|
411
|
+
truncatedChars: number;
|
|
412
|
+
}>;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Enforce per-group and per-result character budgets on tool results.
|
|
416
|
+
*
|
|
417
|
+
* For each assistant-round group: first enforce per-result caps (truncate
|
|
418
|
+
* any single result exceeding `maxCharsPerResult`), then if the group
|
|
419
|
+
* total still exceeds `maxCharsPerGroup`, truncate the largest results
|
|
420
|
+
* first until under budget.
|
|
421
|
+
*
|
|
422
|
+
* Tool results that were already truncated (tracked in `state`) are
|
|
423
|
+
* left as-is for deterministic resume.
|
|
424
|
+
*/
|
|
425
|
+
declare function enforceToolResultBudget(messages: ChatMessage[], config: ToolResultBudgetConfig, state?: BudgetState): ToolResultBudgetResult;
|
|
426
|
+
|
|
427
|
+
declare class SessionStorage {
|
|
428
|
+
private fs;
|
|
429
|
+
private sessionDir;
|
|
430
|
+
constructor(fs: VirtualFs, sessionDir: string);
|
|
431
|
+
private getTranscriptPath;
|
|
432
|
+
ensureDir(): Promise<void>;
|
|
433
|
+
appendEntry(sessionId: string, entry: Entry): Promise<void>;
|
|
434
|
+
appendMessage(sessionId: string, message: ChatMessage, parentUuid?: UUID | null): Promise<UUID>;
|
|
435
|
+
appendCompactBoundary(sessionId: string): Promise<UUID>;
|
|
436
|
+
appendSummary(sessionId: string, summaryMessage: ChatMessage, parentUuid?: UUID | null): Promise<UUID>;
|
|
437
|
+
appendToolResultOverflow(sessionId: string, toolCallId: string, originalContent: string): Promise<void>;
|
|
438
|
+
appendCheckpointEntry(sessionId: string, messageId: string, snapshot: FileCheckpointSnapshot, isSnapshotUpdate: boolean): Promise<void>;
|
|
439
|
+
appendSnipBoundary(sessionId: string, removedUuids: string[]): Promise<void>;
|
|
440
|
+
appendContentReplacement(sessionId: string, replacements: ContentReplacementRecord$1[]): Promise<void>;
|
|
441
|
+
appendMetadata(sessionId: string, key: string, value: unknown): Promise<void>;
|
|
442
|
+
loadMessages(sessionId: string): Promise<ChatMessage[]>;
|
|
443
|
+
loadAllEntries(sessionId: string): Promise<Entry[]>;
|
|
444
|
+
sessionExists(sessionId: string): Promise<boolean>;
|
|
445
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
interface ReactiveCompactConfig {
|
|
449
|
+
enabled: boolean;
|
|
450
|
+
}
|
|
451
|
+
interface ReactiveCompactResult {
|
|
452
|
+
messages: ChatMessage[];
|
|
453
|
+
strategy: "compacted" | "truncated";
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Attempt to recover from a context-overflow error by compacting the
|
|
457
|
+
* conversation. If compaction itself fails (e.g. the context is so large
|
|
458
|
+
* that even the summarizer cannot run), falls back to
|
|
459
|
+
* {@link truncateHeadForPTLRetry} which drops the oldest turn groups
|
|
460
|
+
* until the estimate fits within the target.
|
|
461
|
+
*
|
|
462
|
+
* Returns `null` if there are not enough messages to meaningfully compact
|
|
463
|
+
* or truncate (less than 2 messages).
|
|
464
|
+
*/
|
|
465
|
+
declare function tryReactiveCompact(provider: AIProvider, model: string, messages: ChatMessage[], storage: SessionStorage, sessionId: string): Promise<ReactiveCompactResult | null>;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Disk-backed tool result storage.
|
|
469
|
+
*
|
|
470
|
+
* When a tool result exceeds a size threshold, the full content is persisted
|
|
471
|
+
* to VirtualFs and replaced in-memory with a compact stub containing a
|
|
472
|
+
* preview and path. This prevents context window bloat while preserving
|
|
473
|
+
* the full data for resume.
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
interface ToolResultStorageConfig {
|
|
477
|
+
enabled: boolean;
|
|
478
|
+
/** Directory under which persisted results are stored. Default: ".noumen/tool-results" */
|
|
479
|
+
storageDir?: string;
|
|
480
|
+
/** Char threshold for a single result before spilling to disk. Default: 50_000 */
|
|
481
|
+
defaultThreshold?: number;
|
|
482
|
+
/** Per-tool overrides (tool name -> threshold). Use Infinity to never persist. */
|
|
483
|
+
perToolThresholds?: Record<string, number>;
|
|
484
|
+
/** Chars to keep as preview in the replacement stub. Default: 2_000 */
|
|
485
|
+
previewChars?: number;
|
|
486
|
+
/** Per-message aggregate budget for all tool results. Default: 200_000 */
|
|
487
|
+
perMessageBudget?: number;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Tracks which tool results have been replaced, enabling deterministic
|
|
491
|
+
* resume — previously replaced results are re-applied from the stored
|
|
492
|
+
* replacement string without re-reading from disk.
|
|
493
|
+
*/
|
|
494
|
+
interface ContentReplacementState {
|
|
495
|
+
seenIds: Set<string>;
|
|
496
|
+
replacements: Map<string, string>;
|
|
497
|
+
}
|
|
498
|
+
interface ContentReplacementRecord {
|
|
499
|
+
toolUseId: string;
|
|
500
|
+
replacement: string;
|
|
501
|
+
}
|
|
502
|
+
declare function createContentReplacementState(): ContentReplacementState;
|
|
503
|
+
/**
|
|
504
|
+
* Persist a single oversized tool result to disk and return a replacement stub.
|
|
505
|
+
* Returns null if the content is below threshold.
|
|
506
|
+
*/
|
|
507
|
+
declare function persistToolResult(fs: VirtualFs, sessionId: string, toolUseId: string, toolName: string, content: string, config: ToolResultStorageConfig): Promise<string | null>;
|
|
508
|
+
interface ToolResultSpillResult {
|
|
509
|
+
messages: ChatMessage[];
|
|
510
|
+
state: ContentReplacementState;
|
|
511
|
+
tokensFreed: number;
|
|
512
|
+
spilledEntries: ContentReplacementRecord[];
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Enforce per-message tool result budget by spilling the largest results to disk.
|
|
516
|
+
*
|
|
517
|
+
* For each assistant turn group, if the total tool result size exceeds
|
|
518
|
+
* `perMessageBudget`, the largest results are spilled first.
|
|
519
|
+
*/
|
|
520
|
+
declare function enforceToolResultStorageBudget(messages: ChatMessage[], config: ToolResultStorageConfig, fs: VirtualFs, sessionId: string, state?: ContentReplacementState): Promise<ToolResultSpillResult>;
|
|
521
|
+
/**
|
|
522
|
+
* Reconstruct ContentReplacementState from persisted records (used during session resume).
|
|
523
|
+
*/
|
|
524
|
+
declare function reconstructContentReplacementState(records: ContentReplacementRecord[], messages?: ChatMessage[]): ContentReplacementState;
|
|
525
|
+
/**
|
|
526
|
+
* Re-apply persisted replacements to loaded messages (for resume).
|
|
527
|
+
*/
|
|
528
|
+
declare function applyPersistedReplacements(messages: ChatMessage[], state: ContentReplacementState): ChatMessage[];
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* History snip: remove middle ranges of conversation history.
|
|
532
|
+
*
|
|
533
|
+
* Unlike prefix compaction (which summarizes and removes the oldest
|
|
534
|
+
* messages), history snip removes specific message ranges from the middle
|
|
535
|
+
* of the conversation. The JSONL transcript stays append-only — snipped
|
|
536
|
+
* messages remain on disk but their UUIDs are recorded on a snip-boundary
|
|
537
|
+
* entry so they're filtered out on resume.
|
|
538
|
+
*
|
|
539
|
+
* Parent pointers are relinked across gaps using path compression so the
|
|
540
|
+
* conversation chain stays intact.
|
|
541
|
+
*/
|
|
542
|
+
|
|
543
|
+
interface SnipConfig {
|
|
544
|
+
enabled: boolean;
|
|
545
|
+
}
|
|
546
|
+
interface SnipResult {
|
|
547
|
+
messages: ChatMessage[];
|
|
548
|
+
removedCount: number;
|
|
549
|
+
relinkedCount: number;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Apply snip removals to a UUID-keyed message map.
|
|
553
|
+
*
|
|
554
|
+
* Ported from claude-code's `applySnipRemovals`. Walks entries looking
|
|
555
|
+
* for snip-boundary entries with `snipMetadata.removedUuids`, deletes
|
|
556
|
+
* those messages, and relinks parentUuid across gaps with path compression.
|
|
557
|
+
*/
|
|
558
|
+
declare function applySnipRemovals(entries: Entry[]): {
|
|
559
|
+
messages: ChatMessage[];
|
|
560
|
+
removedCount: number;
|
|
561
|
+
relinkedCount: number;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Snip specific messages from an in-memory message array by UUID.
|
|
565
|
+
*
|
|
566
|
+
* This is the in-memory operation — call this during a live thread to
|
|
567
|
+
* remove messages before the next model call. The caller is responsible
|
|
568
|
+
* for persisting a snip-boundary entry to the JSONL transcript.
|
|
569
|
+
*/
|
|
570
|
+
declare function snipMessagesByUuids(entries: Array<{
|
|
571
|
+
uuid: UUID;
|
|
572
|
+
parentUuid: UUID | null;
|
|
573
|
+
message: ChatMessage;
|
|
574
|
+
}>, removedUuids: Set<UUID>): SnipResult;
|
|
575
|
+
/**
|
|
576
|
+
* Project a "snipped view" of messages for the model.
|
|
577
|
+
*
|
|
578
|
+
* Filters out messages marked as snipped. Use the `includeSnipped` option
|
|
579
|
+
* to get the full scrollback for UI display.
|
|
580
|
+
*/
|
|
581
|
+
declare function projectSnippedView(messages: ChatMessage[], snippedIndices: Set<number>, opts?: {
|
|
582
|
+
includeSnipped?: boolean;
|
|
583
|
+
}): ChatMessage[];
|
|
584
|
+
|
|
585
|
+
type ContextScope = "managed" | "user" | "project" | "local";
|
|
586
|
+
interface ContextFile {
|
|
587
|
+
path: string;
|
|
588
|
+
scope: ContextScope;
|
|
589
|
+
content: string;
|
|
590
|
+
/** Glob patterns from frontmatter `paths:` field. Undefined = unconditional. */
|
|
591
|
+
globs?: string[];
|
|
592
|
+
/** Files included via @ references. */
|
|
593
|
+
includes?: ContextFile[];
|
|
594
|
+
}
|
|
595
|
+
interface ProjectContextConfig {
|
|
596
|
+
/** Working directory (project root). Required. */
|
|
597
|
+
cwd: string;
|
|
598
|
+
/** User home directory. Pass explicitly for sandboxed environments. */
|
|
599
|
+
homeDir?: string;
|
|
600
|
+
/** Managed settings directory (enterprise/MDM). Optional. */
|
|
601
|
+
managedDir?: string;
|
|
602
|
+
/** Glob patterns to exclude context files (picomatch-style). */
|
|
603
|
+
excludes?: string[];
|
|
604
|
+
/** Maximum include depth for @ references. Default: 5. */
|
|
605
|
+
maxIncludeDepth?: number;
|
|
606
|
+
/** Whether to load .claude/ files in addition to .noumen/ files. Default: true. */
|
|
607
|
+
loadClaudeMd?: boolean;
|
|
608
|
+
/** Enable loading user-scope context from homeDir. Default: true. */
|
|
609
|
+
loadUserContext?: boolean;
|
|
610
|
+
/** Enable loading project-scope context from cwd ancestors. Default: true. */
|
|
611
|
+
loadProjectContext?: boolean;
|
|
612
|
+
/** Enable loading local-scope (.local.md) context. Default: true. */
|
|
613
|
+
loadLocalContext?: boolean;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
interface StoredCostState {
|
|
617
|
+
byModel: Record<string, ModelUsageSummary>;
|
|
618
|
+
totalApiMs: number;
|
|
619
|
+
wallStartMs: number;
|
|
620
|
+
}
|
|
621
|
+
declare class CostTracker {
|
|
622
|
+
private pricing;
|
|
623
|
+
private byModel;
|
|
624
|
+
private totalApiMs;
|
|
625
|
+
private wallStartMs;
|
|
626
|
+
constructor(pricing?: Record<string, ModelPricing>);
|
|
627
|
+
addUsage(model: string, usage: UsageRecord, apiDurationMs?: number): CostSummary;
|
|
628
|
+
getSummary(): CostSummary;
|
|
629
|
+
reset(): void;
|
|
630
|
+
getState(): StoredCostState;
|
|
631
|
+
restore(state: StoredCostState): void;
|
|
632
|
+
formatSummary(): string;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
interface AutoCompactConfig {
|
|
636
|
+
enabled: boolean;
|
|
637
|
+
/** Token threshold at which to trigger compaction. */
|
|
638
|
+
threshold: number;
|
|
639
|
+
/** Number of recent messages to keep uncompacted. */
|
|
640
|
+
tailMessagesToKeep?: number;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Tracks consecutive auto-compact failures to implement a circuit breaker.
|
|
644
|
+
* After `maxFailures` consecutive failures, auto-compact is skipped to
|
|
645
|
+
* avoid an infinite fail-retry loop.
|
|
646
|
+
*/
|
|
647
|
+
interface AutoCompactTrackingState {
|
|
648
|
+
consecutiveFailures: number;
|
|
649
|
+
maxFailures: number;
|
|
650
|
+
}
|
|
651
|
+
declare function createAutoCompactConfig(opts?: {
|
|
652
|
+
enabled?: boolean;
|
|
653
|
+
threshold?: number;
|
|
654
|
+
/** Model name — when provided, the threshold is computed from the model's
|
|
655
|
+
* context window instead of the fixed default. */
|
|
656
|
+
model?: string;
|
|
657
|
+
maxOutputTokens?: number;
|
|
658
|
+
tailMessagesToKeep?: number;
|
|
659
|
+
}): AutoCompactConfig;
|
|
660
|
+
declare function createAutoCompactTracking(maxFailures?: number): AutoCompactTrackingState;
|
|
661
|
+
/**
|
|
662
|
+
* Determine whether auto-compaction should fire. Uses usage-grounded counting
|
|
663
|
+
* when a usage anchor is available, otherwise falls back to estimation.
|
|
664
|
+
*
|
|
665
|
+
* @param tokensFreed — tokens already reclaimed by microcompact/budget in
|
|
666
|
+
* this turn; subtracted from the estimate so we don't over-eagerly compact.
|
|
667
|
+
*/
|
|
668
|
+
declare function shouldAutoCompact(messages: ChatMessage[], config: AutoCompactConfig, lastUsage?: ChatCompletionUsage, anchorMessageIndex?: number, tokensFreed?: number): boolean;
|
|
669
|
+
/**
|
|
670
|
+
* Check whether the circuit breaker allows another auto-compact attempt.
|
|
671
|
+
*/
|
|
672
|
+
declare function canAutoCompact(tracking: AutoCompactTrackingState): boolean;
|
|
673
|
+
declare function recordAutoCompactSuccess(tracking: AutoCompactTrackingState): void;
|
|
674
|
+
declare function recordAutoCompactFailure(tracking: AutoCompactTrackingState): void;
|
|
675
|
+
|
|
676
|
+
interface ThreadOptions {
|
|
677
|
+
sessionId?: string;
|
|
678
|
+
resume?: boolean;
|
|
679
|
+
cwd?: string;
|
|
680
|
+
model?: string;
|
|
681
|
+
/** Override the permission handler for this thread (takes precedence over AgentOptions). */
|
|
682
|
+
permissionHandler?: PermissionHandler;
|
|
683
|
+
/** Override the user input handler for this thread (takes precedence over AgentOptions). */
|
|
684
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
685
|
+
}
|
|
686
|
+
interface ThreadConfig {
|
|
687
|
+
provider: AIProvider;
|
|
688
|
+
fs: VirtualFs;
|
|
689
|
+
computer: VirtualComputer;
|
|
690
|
+
sessionDir: string;
|
|
691
|
+
skills?: SkillDefinition[];
|
|
692
|
+
tools?: Tool[];
|
|
693
|
+
systemPrompt?: string;
|
|
694
|
+
model?: string;
|
|
695
|
+
maxTokens?: number;
|
|
696
|
+
autoCompact?: AutoCompactConfig;
|
|
697
|
+
microcompact?: MicrocompactConfig;
|
|
698
|
+
toolResultBudget?: ToolResultBudgetConfig;
|
|
699
|
+
reactiveCompact?: ReactiveCompactConfig;
|
|
700
|
+
permissions?: PermissionConfig;
|
|
701
|
+
hooks?: HookDefinition[];
|
|
702
|
+
spawnSubagent?: (config: SubagentConfig) => SubagentRun;
|
|
703
|
+
streamingToolExecution?: boolean;
|
|
704
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
705
|
+
taskStore?: TaskStore;
|
|
706
|
+
lspManager?: LspServerManager;
|
|
707
|
+
thinking?: ThinkingConfig;
|
|
708
|
+
retry?: RetryConfig;
|
|
709
|
+
costTracker?: CostTracker;
|
|
710
|
+
tracer?: Tracer;
|
|
711
|
+
memory?: MemoryConfig;
|
|
712
|
+
toolSearchEnabled?: boolean;
|
|
713
|
+
checkpointManager?: FileCheckpointManager;
|
|
714
|
+
/** File state cache config for read-before-edit enforcement. */
|
|
715
|
+
fileStateCacheConfig?: FileStateCacheConfig;
|
|
716
|
+
/** Disk-backed tool result storage config. */
|
|
717
|
+
toolResultStorage?: ToolResultStorageConfig;
|
|
718
|
+
/** History snip: enable middle-range removal from conversation history. */
|
|
719
|
+
historySnip?: SnipConfig;
|
|
720
|
+
/** Enable deterministic tool ordering and CacheSafeParams tracking for prompt caching. */
|
|
721
|
+
promptCachingEnabled?: boolean;
|
|
722
|
+
/** When true, signal skipCacheWrite to the provider (for subagent forks). */
|
|
723
|
+
skipCacheWrite?: boolean;
|
|
724
|
+
/** Set of MCP tool names for cache-stable sorting (built-in first, then MCP). */
|
|
725
|
+
mcpToolNames?: ReadonlySet<string>;
|
|
726
|
+
/** Loaded project context files (NOUMEN.md / CLAUDE.md) for system prompt injection. */
|
|
727
|
+
projectContext?: ContextFile[];
|
|
728
|
+
/** Default structured output format for all runs on this thread. */
|
|
729
|
+
outputFormat?: OutputFormat;
|
|
730
|
+
/** Default structured output mode for all runs on this thread. */
|
|
731
|
+
structuredOutputMode?: "alongside_tools" | "final_response";
|
|
732
|
+
}
|
|
733
|
+
declare class Thread {
|
|
734
|
+
readonly sessionId: string;
|
|
735
|
+
private config;
|
|
736
|
+
private storage;
|
|
737
|
+
private toolRegistry;
|
|
738
|
+
private messages;
|
|
739
|
+
private loaded;
|
|
740
|
+
private abortController;
|
|
741
|
+
private cwd;
|
|
742
|
+
private model;
|
|
743
|
+
private activatedSkills;
|
|
744
|
+
private activatedContextRules;
|
|
745
|
+
private permissionContext;
|
|
746
|
+
private permissionHandler;
|
|
747
|
+
private hooks;
|
|
748
|
+
private lastUsage;
|
|
749
|
+
private anchorMessageIndex;
|
|
750
|
+
private prePlanMode;
|
|
751
|
+
private tracer;
|
|
752
|
+
private autoCompactTracking;
|
|
753
|
+
private budgetState;
|
|
754
|
+
private hasAttemptedReactiveCompact;
|
|
755
|
+
private microcompactTokensFreed;
|
|
756
|
+
private resumeRequested;
|
|
757
|
+
private fileStateCache;
|
|
758
|
+
private contentReplacementState;
|
|
759
|
+
private denialTracker;
|
|
760
|
+
constructor(config: ThreadConfig, opts?: ThreadOptions);
|
|
761
|
+
run(prompt: string | ContentPart[], opts?: RunOptions): AsyncGenerator<StreamEvent, void, unknown>;
|
|
762
|
+
/**
|
|
763
|
+
* If tool result storage is enabled and the content exceeds the threshold,
|
|
764
|
+
* spill to disk and return the replacement stub. Otherwise return the original.
|
|
765
|
+
*/
|
|
766
|
+
private maybeSpillToolResult;
|
|
767
|
+
private buildStreamingExecutorFn;
|
|
768
|
+
private buildPermissionOpts;
|
|
769
|
+
private buildCurrentSystemPromptAsync;
|
|
770
|
+
getMessages(): Promise<ChatMessage[]>;
|
|
771
|
+
compact(opts?: {
|
|
772
|
+
instructions?: string;
|
|
773
|
+
}): Promise<void>;
|
|
774
|
+
/**
|
|
775
|
+
* Remove specific messages from the middle of conversation history.
|
|
776
|
+
*
|
|
777
|
+
* Unlike `compact()` which summarizes a prefix, `snip()` removes
|
|
778
|
+
* specific messages by UUID. The JSONL transcript records the removed
|
|
779
|
+
* UUIDs so they're filtered on resume. Parent pointers are relinked
|
|
780
|
+
* across gaps.
|
|
781
|
+
*
|
|
782
|
+
* @param uuids - UUIDs of messages to remove
|
|
783
|
+
*/
|
|
784
|
+
snip(uuids: string[]): Promise<void>;
|
|
785
|
+
setModel(model: string): void;
|
|
786
|
+
setProvider(provider: AIProvider, model?: string): void;
|
|
787
|
+
getModel(): string;
|
|
788
|
+
abort(): void;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
interface DiagnoseCheckResult {
|
|
792
|
+
ok: boolean;
|
|
793
|
+
latencyMs: number;
|
|
794
|
+
error?: string;
|
|
795
|
+
warning?: string;
|
|
796
|
+
}
|
|
797
|
+
interface DiagnoseResult {
|
|
798
|
+
overall: boolean;
|
|
799
|
+
provider: DiagnoseCheckResult & {
|
|
800
|
+
model?: string;
|
|
801
|
+
};
|
|
802
|
+
sandbox: {
|
|
803
|
+
fs: DiagnoseCheckResult;
|
|
804
|
+
computer: DiagnoseCheckResult;
|
|
805
|
+
};
|
|
806
|
+
sandboxRuntime: DiagnoseCheckResult & {
|
|
807
|
+
platform?: string;
|
|
808
|
+
};
|
|
809
|
+
mcp: Record<string, DiagnoseCheckResult & {
|
|
810
|
+
status?: string;
|
|
811
|
+
toolCount?: number;
|
|
812
|
+
}>;
|
|
813
|
+
lsp: Record<string, DiagnoseCheckResult & {
|
|
814
|
+
state?: string;
|
|
815
|
+
}>;
|
|
816
|
+
timestamp: string;
|
|
817
|
+
}
|
|
818
|
+
interface AgentOptions {
|
|
819
|
+
/**
|
|
820
|
+
* AI provider — either an `AIProvider` instance or a provider name string.
|
|
821
|
+
* When a string is passed (e.g. `"openai"`), the provider is resolved
|
|
822
|
+
* lazily using env-var auto-detection on the first call to `run()`,
|
|
823
|
+
* `createThread()`, or `init()`.
|
|
824
|
+
*/
|
|
825
|
+
provider: AIProvider | ProviderName;
|
|
826
|
+
/**
|
|
827
|
+
* Working directory. When set without an explicit `sandbox`, an
|
|
828
|
+
* `UnsandboxedLocal({ cwd })` is created automatically.
|
|
829
|
+
*/
|
|
830
|
+
cwd?: string;
|
|
831
|
+
/**
|
|
832
|
+
* Bundled sandbox providing both filesystem and shell execution.
|
|
833
|
+
* Use `LocalSandbox()` for OS-level sandboxing (requires
|
|
834
|
+
* `@anthropic-ai/sandbox-runtime`), `UnsandboxedLocal()` for raw host
|
|
835
|
+
* access, `SpritesSandbox()` for isolated remote containers, or pass
|
|
836
|
+
* any `{ fs: VirtualFs; computer: VirtualComputer }` for custom sandboxes.
|
|
837
|
+
*
|
|
838
|
+
* Defaults to `UnsandboxedLocal({ cwd })` when omitted — the library
|
|
839
|
+
* default is non-sandboxed for backward compatibility. The CLI defaults
|
|
840
|
+
* to `LocalSandbox()` when sandbox-runtime is available.
|
|
841
|
+
*/
|
|
842
|
+
sandbox?: Sandbox;
|
|
843
|
+
options?: {
|
|
844
|
+
sessionDir?: string;
|
|
845
|
+
skills?: SkillDefinition[];
|
|
846
|
+
skillsPaths?: string[];
|
|
847
|
+
tools?: Tool[];
|
|
848
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
849
|
+
/** Token storage for MCP OAuth flows (defaults to in-memory). */
|
|
850
|
+
mcpTokenStorage?: TokenStorage;
|
|
851
|
+
/** Called when an MCP server requires OAuth and the user must visit a URL. */
|
|
852
|
+
mcpOnAuthorizationUrl?: (url: string) => void | Promise<void>;
|
|
853
|
+
systemPrompt?: string;
|
|
854
|
+
model?: string;
|
|
855
|
+
maxTokens?: number;
|
|
856
|
+
autoCompact?: boolean;
|
|
857
|
+
autoCompactThreshold?: number;
|
|
858
|
+
microcompact?: MicrocompactConfig;
|
|
859
|
+
toolResultBudget?: ToolResultBudgetConfig;
|
|
860
|
+
reactiveCompact?: ReactiveCompactConfig;
|
|
861
|
+
cwd?: string;
|
|
862
|
+
permissions?: PermissionConfig;
|
|
863
|
+
hooks?: HookDefinition[];
|
|
864
|
+
enableSubagents?: boolean;
|
|
865
|
+
enableTasks?: boolean;
|
|
866
|
+
tasksDir?: string;
|
|
867
|
+
enablePlanMode?: boolean;
|
|
868
|
+
enableWorktrees?: boolean;
|
|
869
|
+
lsp?: Record<string, LspServerConfig>;
|
|
870
|
+
streamingToolExecution?: boolean;
|
|
871
|
+
webSearch?: WebSearchConfig;
|
|
872
|
+
userInputHandler?: (question: string) => Promise<string>;
|
|
873
|
+
thinking?: ThinkingConfig;
|
|
874
|
+
retry?: RetryConfig | boolean;
|
|
875
|
+
costTracking?: {
|
|
876
|
+
enabled: boolean;
|
|
877
|
+
pricing?: Record<string, ModelPricing>;
|
|
878
|
+
};
|
|
879
|
+
tracing?: TracingConfig;
|
|
880
|
+
memory?: MemoryConfig;
|
|
881
|
+
/** Enable ToolSearch: deferred tools are hidden until the model discovers them. */
|
|
882
|
+
toolSearch?: boolean;
|
|
883
|
+
/** File checkpointing: snapshot files before edits for rollback. */
|
|
884
|
+
checkpoint?: CheckpointConfig;
|
|
885
|
+
/** Prompt caching: enable deterministic tool ordering and cache_control injection. */
|
|
886
|
+
promptCaching?: CacheControlConfig;
|
|
887
|
+
/** File state cache: track reads for read-before-edit enforcement. */
|
|
888
|
+
fileStateCache?: FileStateCacheConfig;
|
|
889
|
+
/** Disk-backed storage for oversized tool results. */
|
|
890
|
+
toolResultStorage?: ToolResultStorageConfig;
|
|
891
|
+
/** History snip: enable middle-range removal from conversation history. */
|
|
892
|
+
historySnip?: SnipConfig;
|
|
893
|
+
/** Project context loading (NOUMEN.md / CLAUDE.md). Pass true for defaults or a config object. */
|
|
894
|
+
projectContext?: ProjectContextConfig | boolean;
|
|
895
|
+
/** Default structured output format for all threads. */
|
|
896
|
+
outputFormat?: OutputFormat;
|
|
897
|
+
/** Default structured output mode for all threads. */
|
|
898
|
+
structuredOutputMode?: "alongside_tools" | "final_response";
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
interface RunCallbacks {
|
|
902
|
+
onText?: (text: string) => void;
|
|
903
|
+
onThinking?: (text: string) => void;
|
|
904
|
+
onToolUse?: (toolName: string, args: Record<string, unknown>) => void;
|
|
905
|
+
onToolResult?: (toolName: string, result: ToolResult) => void;
|
|
906
|
+
onError?: (error: Error) => void;
|
|
907
|
+
onComplete?: (result: RunResult) => void;
|
|
908
|
+
}
|
|
909
|
+
interface RunResult {
|
|
910
|
+
text: string;
|
|
911
|
+
toolCalls: number;
|
|
912
|
+
usage: ChatCompletionUsage;
|
|
913
|
+
sessionId: string;
|
|
914
|
+
}
|
|
915
|
+
declare class Agent {
|
|
916
|
+
private providerInput;
|
|
917
|
+
private resolvedProvider;
|
|
918
|
+
private fs;
|
|
919
|
+
private computer;
|
|
920
|
+
private sessionDir;
|
|
921
|
+
private skills;
|
|
922
|
+
private skillsPaths;
|
|
923
|
+
private tools;
|
|
924
|
+
private systemPrompt?;
|
|
925
|
+
private model?;
|
|
926
|
+
private maxTokens?;
|
|
927
|
+
private autoCompactEnabled;
|
|
928
|
+
private autoCompactThreshold?;
|
|
929
|
+
private cwd;
|
|
930
|
+
private storage;
|
|
931
|
+
private resolvedSkills;
|
|
932
|
+
private mcpManager;
|
|
933
|
+
private mcpServerConfigs?;
|
|
934
|
+
private mcpTokenStorage?;
|
|
935
|
+
private mcpOnAuthorizationUrl?;
|
|
936
|
+
private mcpTools;
|
|
937
|
+
private mcpToolNames;
|
|
938
|
+
private mcpAuthTools;
|
|
939
|
+
private permissions?;
|
|
940
|
+
private hooks;
|
|
941
|
+
private enableSubagents;
|
|
942
|
+
private enableTasks;
|
|
943
|
+
private taskStore;
|
|
944
|
+
private enablePlanMode;
|
|
945
|
+
private enableWorktrees;
|
|
946
|
+
private lspManager;
|
|
947
|
+
private lspConfigs?;
|
|
948
|
+
private lspToolRef;
|
|
949
|
+
private streamingToolExecution;
|
|
950
|
+
private webSearchConfig?;
|
|
951
|
+
private userInputHandler?;
|
|
952
|
+
private thinkingConfig?;
|
|
953
|
+
private retryConfig?;
|
|
954
|
+
private costTracker;
|
|
955
|
+
private tracer?;
|
|
956
|
+
private memoryProvider?;
|
|
957
|
+
private memoryConfig?;
|
|
958
|
+
private microcompactConfig?;
|
|
959
|
+
private toolResultBudgetConfig?;
|
|
960
|
+
private reactiveCompactConfig?;
|
|
961
|
+
private toolSearchEnabled;
|
|
962
|
+
private projectContextConfig?;
|
|
963
|
+
private resolvedProjectContext;
|
|
964
|
+
private checkpointManager;
|
|
965
|
+
private promptCachingConfig;
|
|
966
|
+
private fileStateCacheConfig;
|
|
967
|
+
private toolResultStorageConfig;
|
|
968
|
+
private historySnipConfig;
|
|
969
|
+
private outputFormat;
|
|
970
|
+
private structuredOutputMode;
|
|
971
|
+
constructor(opts: AgentOptions);
|
|
972
|
+
private ensureProvider;
|
|
973
|
+
private getProvider;
|
|
974
|
+
private getSkills;
|
|
975
|
+
private getAllTools;
|
|
976
|
+
private createSpawnSubagent;
|
|
977
|
+
createThread(opts?: ThreadOptions): Thread;
|
|
978
|
+
listSessions(): Promise<SessionInfo[]>;
|
|
979
|
+
getCostSummary(): CostSummary | null;
|
|
980
|
+
/**
|
|
981
|
+
* Create a thread that resumes an existing session. Automatically restores
|
|
982
|
+
* messages (respecting compact boundaries), file checkpoint state, and
|
|
983
|
+
* cost tracking state from the persisted JSONL transcript.
|
|
984
|
+
*/
|
|
985
|
+
resumeThread(sessionId: string, opts?: Omit<ThreadOptions, "sessionId" | "resume">): Thread;
|
|
986
|
+
/**
|
|
987
|
+
* One-shot streaming: creates an ephemeral thread and yields events.
|
|
988
|
+
* Auto-resolves string providers on first call (no need to call `init()`).
|
|
989
|
+
*
|
|
990
|
+
* ```ts
|
|
991
|
+
* for await (const event of agent.run("Fix the bug")) {
|
|
992
|
+
* if (event.type === "text_delta") process.stdout.write(event.text);
|
|
993
|
+
* }
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
run(prompt: string | ContentPart[], opts?: RunOptions & ThreadOptions): AsyncGenerator<StreamEvent, void, unknown>;
|
|
997
|
+
/**
|
|
998
|
+
* One-shot execution: runs the prompt to completion and returns a result
|
|
999
|
+
* summary. Optional callbacks fire as events arrive.
|
|
1000
|
+
*
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* const result = await agent.execute("Fix the bug", {
|
|
1003
|
+
* onText: (text) => process.stdout.write(text),
|
|
1004
|
+
* });
|
|
1005
|
+
* console.log(`Done — ${result.toolCalls} tool calls`);
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
execute(prompt: string | ContentPart[], opts?: RunOptions & ThreadOptions & RunCallbacks): Promise<RunResult>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Pre-resolve the provider (if string), skills, MCP servers, and LSP servers.
|
|
1011
|
+
* Call this once after construction if using a string provider, skillsPaths,
|
|
1012
|
+
* mcpServers, or lsp, so that createThread() has everything available synchronously.
|
|
1013
|
+
*/
|
|
1014
|
+
init(): Promise<void>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Run health checks on the provider, sandbox, MCP servers, and LSP servers.
|
|
1017
|
+
* Returns a structured report — useful for debugging integration issues.
|
|
1018
|
+
*
|
|
1019
|
+
* @param timeoutMs Per-check timeout in milliseconds (default 10 000).
|
|
1020
|
+
*/
|
|
1021
|
+
diagnose(timeoutMs?: number): Promise<DiagnoseResult>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Disconnect all MCP clients. Call when done with this Agent instance.
|
|
1024
|
+
*/
|
|
1025
|
+
close(): Promise<void>;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
export { type SandboxedLocalComputerOptions as $, Agent as A, type BudgetState as B, type ContextFile as C, type DockerContainer as D, type E2BSandboxInstance as E, E2BComputer as F, type E2BComputerOptions as G, E2BSandbox as H, type E2BSandboxOptions as I, type LocalSandboxOptions as J, type MicrocompactResult as K, LocalSandbox as L, type MicrocompactConfig as M, type ProviderName as N, type ReactiveCompactConfig as O, type ProjectContextConfig as P, type ReactiveCompactResult as Q, type RetryConfig as R, type Sandbox as S, type ThreadConfig as T, type ResolveProviderOptions as U, type RetryEvent as V, type RunCallbacks as W, type RunResult as X, SUPPORTED_PROVIDERS as Y, type SandboxConfig as Z, SandboxedLocalComputer as _, type SkillDefinition as a, type SnipConfig as a0, type SnipResult as a1, SpritesSandbox as a2, type SpritesSandboxOptions as a3, Thread as a4, type ThreadOptions as a5, type ToolResultBudgetConfig as a6, type ToolResultBudgetResult as a7, type ContentReplacementRecord as a8, type ToolResultSpillResult as a9, tryReactiveCompact as aA, webSearchToolPlaceholder as aB, type ToolResultStorageConfig as aa, type TracingConfig as ab, UnsandboxedLocal as ac, type UnsandboxedLocalOptions as ad, type WebSearchConfig as ae, type WebSearchResult as af, applyPersistedReplacements as ag, applySnipRemovals as ah, canAutoCompact as ai, createAutoCompactConfig as aj, createAutoCompactTracking as ak, createBudgetState as al, createContentReplacementState as am, createWebSearchTool as an, detectProvider as ao, enforceToolResultBudget as ap, enforceToolResultStorageBudget as aq, microcompactMessages as ar, persistToolResult as as, projectSnippedView as at, reconstructContentReplacementState as au, recordAutoCompactFailure as av, recordAutoCompactSuccess as aw, resolveProvider as ax, shouldAutoCompact as ay, snipMessagesByUuids 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 };
|