experimental-agent 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-workflow.d.mts +3 -2
- package/dist/agent-workflow.d.ts +3 -2
- package/dist/agent-workflow.js +29 -29
- package/dist/agent-workflow.mjs +1 -2
- package/dist/{chunk-GJETDXOU.mjs → chunk-2SPAJ777.mjs} +5 -1
- package/dist/chunk-6J462JGP.mjs +1267 -0
- package/dist/{chunk-T2UUL6VC.mjs → chunk-E7TOPGHY.mjs} +3 -3
- package/dist/chunk-ILPVXRI5.mjs +2026 -0
- package/dist/chunk-ORE6LK2L.mjs +344 -0
- package/dist/chunk-W4SSZPDX.mjs +106 -0
- package/dist/{types-DuTc4UQW.d.mts → client-CKLwB-ES.d.mts} +730 -3
- package/dist/{types-DuTc4UQW.d.ts → client-CKLwB-ES.d.ts} +730 -3
- package/dist/{client-66JIQLSA.mjs → client-YUU54ZZH.mjs} +1 -1
- package/dist/{handler-BQY5SOI2.mjs → handler-LDFBSCRA.mjs} +1 -1
- package/dist/index.d.mts +4 -18
- package/dist/index.d.ts +4 -18
- package/dist/index.js +67 -40
- package/dist/index.mjs +21 -16
- package/dist/lifecycle-workflow.d.mts +2 -3
- package/dist/lifecycle-workflow.d.ts +2 -3
- package/dist/lifecycle-workflow.js +19 -15
- package/dist/lifecycle-workflow.mjs +1 -2
- package/dist/local-fs-handlers-SY2RDXZE.mjs +314 -0
- package/dist/next/loader.js +3 -3
- package/dist/next/loader.mjs +1 -1
- package/dist/next.js +3 -5
- package/dist/next.mjs +2 -4
- package/dist/{sandbox-27X2DSE3.mjs → sandbox-GPCA35PJ.mjs} +2 -3
- package/dist/{storage-KQYV42J4.mjs → storage-LL6IA24R.mjs} +2 -2
- package/package.json +2 -2
- package/dist/chunk-2IIWVPZB.mjs +0 -334
- package/dist/chunk-A63YU65A.mjs +0 -20
- package/dist/chunk-RDKDLHXM.mjs +0 -2031
- package/dist/chunk-VGJISV6O.mjs +0 -108
- package/dist/chunk-VS7U6SXN.mjs +0 -1261
- package/dist/client-DjcE0ATp.d.mts +0 -710
- package/dist/client-DwrDzn4_.d.ts +0 -710
- package/dist/local-fs-handlers-Q5W52DKV.mjs +0 -290
|
@@ -1,710 +0,0 @@
|
|
|
1
|
-
import { g as SandboxRecord, e as SandboxError, m as Storage, N as NetworkPolicy, f as SandboxNotFoundError, l as StorageError, k as StorageConfig, h as Session, U as UsageSummary, d as SandboxConfig, n as SessionError, i as SessionNotFoundError, T as TypedStorage, S as StorageMethods } from './types-DuTc4UQW.mjs';
|
|
2
|
-
import * as ai from 'ai';
|
|
3
|
-
import { JSONSchema7, ToolSet, InferToolInput, ModelMessage, GatewayModelId, UIMessageChunk, UIMessage, InferUITools } from 'ai';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Summary of a discovered skill, used in the system prompt
|
|
8
|
-
* to inform the LLM about available skills.
|
|
9
|
-
*/
|
|
10
|
-
type SkillSummary = {
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
/** Full path to the SKILL.md file inside the sandbox */
|
|
14
|
-
skillMdPath: string;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* A file ready to be uploaded to the sandbox.
|
|
18
|
-
* Content can be text (string) or binary (Buffer).
|
|
19
|
-
*/
|
|
20
|
-
type UploadableFile = {
|
|
21
|
-
/** Relative path within the upload destination */
|
|
22
|
-
path: string;
|
|
23
|
-
content: string | Buffer;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Path or paths to skills directories inside the sandbox.
|
|
27
|
-
*/
|
|
28
|
-
type SkillsDir = string | string[];
|
|
29
|
-
|
|
30
|
-
type SandboxSetup = {
|
|
31
|
-
/** Explicit key the developer controls. Bump to invalidate and re-run setup. */
|
|
32
|
-
key: string;
|
|
33
|
-
/** Async function that receives a bare Sandbox and does setup work. */
|
|
34
|
-
run: (sandbox: Sandbox) => Promise<void>;
|
|
35
|
-
};
|
|
36
|
-
type OnRestart = (sandbox: Sandbox) => Promise<void>;
|
|
37
|
-
type SandboxLifecycleInput = {
|
|
38
|
-
id: string;
|
|
39
|
-
vercelSandboxId: string;
|
|
40
|
-
storageConfig: StorageConfig;
|
|
41
|
-
};
|
|
42
|
-
type LogEntry = {
|
|
43
|
-
stream: "stdout" | "stderr";
|
|
44
|
-
data: string;
|
|
45
|
-
};
|
|
46
|
-
type ExecResult = {
|
|
47
|
-
commandId: string;
|
|
48
|
-
logs: () => AsyncIterable<LogEntry>;
|
|
49
|
-
result: Promise<{
|
|
50
|
-
stdout: string;
|
|
51
|
-
stderr: string;
|
|
52
|
-
exitCode: number;
|
|
53
|
-
}>;
|
|
54
|
-
};
|
|
55
|
-
type SandboxStatus = "pending" | "running" | "stopping" | "stopped" | "failed";
|
|
56
|
-
interface SandboxLifecycle {
|
|
57
|
-
start: () => Promise<SandboxError | SandboxStatus>;
|
|
58
|
-
snapshot: () => Promise<SandboxError | {
|
|
59
|
-
snapshotId: string;
|
|
60
|
-
}>;
|
|
61
|
-
stop: () => Promise<SandboxError | undefined>;
|
|
62
|
-
getStatus: () => Promise<SandboxError | SandboxStatus>;
|
|
63
|
-
getCreatedAt: () => Promise<SandboxError | Date>;
|
|
64
|
-
getRemainingTimeout: () => Promise<SandboxError | number>;
|
|
65
|
-
}
|
|
66
|
-
interface Sandbox<TTags extends TagsSchema = TagsSchema> {
|
|
67
|
-
id: SandboxRecord["id"];
|
|
68
|
-
config: SandboxRecord["config"];
|
|
69
|
-
exec: (opts: {
|
|
70
|
-
command: string;
|
|
71
|
-
args?: string[];
|
|
72
|
-
signal?: AbortSignal;
|
|
73
|
-
}) => Promise<SandboxError | ExecResult>;
|
|
74
|
-
/**
|
|
75
|
-
* Get the public domain URL for an exposed port.
|
|
76
|
-
* Only available for Vercel sandboxes with exposed ports.
|
|
77
|
-
*/
|
|
78
|
-
getDomain: (port: number) => Promise<SandboxError | string>;
|
|
79
|
-
kill: (opts: {
|
|
80
|
-
commandId: string;
|
|
81
|
-
storage: Storage;
|
|
82
|
-
}) => Promise<SandboxError | undefined>;
|
|
83
|
-
readFile: (opts: {
|
|
84
|
-
path: string;
|
|
85
|
-
}) => Promise<SandboxError | Buffer | null>;
|
|
86
|
-
writeFiles: (opts: {
|
|
87
|
-
files: UploadableFile[];
|
|
88
|
-
destPath: string;
|
|
89
|
-
}) => Promise<void>;
|
|
90
|
-
lifecycle?: SandboxLifecycle;
|
|
91
|
-
/**
|
|
92
|
-
* Dynamically update the network policy on a running sandbox.
|
|
93
|
-
* Only available for Vercel sandboxes.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* // Lock down to specific domains
|
|
98
|
-
* await sandbox.updateNetworkPolicy({ allow: ["github.com", "*.github.com"] });
|
|
99
|
-
*
|
|
100
|
-
* // Deny all network access
|
|
101
|
-
* await sandbox.updateNetworkPolicy("deny-all");
|
|
102
|
-
*
|
|
103
|
-
* // Restore full access
|
|
104
|
-
* await sandbox.updateNetworkPolicy("allow-all");
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
updateNetworkPolicy: (policy: NonNullable<NetworkPolicy>) => Promise<SandboxError | NonNullable<NetworkPolicy>>;
|
|
108
|
-
tag: {
|
|
109
|
-
list: () => Promise<SandboxNotFoundError | StorageError | TTags>;
|
|
110
|
-
get: (key: string) => Promise<SandboxNotFoundError | StorageError | TTags[typeof key] | undefined>;
|
|
111
|
-
set: (key: string, value: unknown) => Promise<StorageError | undefined>;
|
|
112
|
-
setMany: (tags: Record<string, unknown>) => Promise<StorageError | undefined>;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Metadata about how the sandbox was set up.
|
|
118
|
-
* Used by the workflow to emit the correct status indicator.
|
|
119
|
-
* Returned as a promise because the metadata is determined asynchronously
|
|
120
|
-
* during sandbox creation, before _onReady runs setup.
|
|
121
|
-
*/
|
|
122
|
-
type SandboxSetupMeta = {
|
|
123
|
-
/** Whether setup.run() needs to execute (cold start, no snapshot). */
|
|
124
|
-
needsSetupRun: boolean;
|
|
125
|
-
/** Whether the sandbox was created from a snapshot. */
|
|
126
|
-
createdFromSnapshot: boolean;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
type GenerationOptions = {
|
|
130
|
-
/** Max tool-use steps per assistant response. Default: unlimited. */
|
|
131
|
-
maxSteps?: number;
|
|
132
|
-
temperature?: number;
|
|
133
|
-
topK?: number;
|
|
134
|
-
topP?: number;
|
|
135
|
-
frequencyPenalty?: number;
|
|
136
|
-
presencePenalty?: number;
|
|
137
|
-
maxOutputTokens?: number;
|
|
138
|
-
/** Provider-specific HTTP headers. */
|
|
139
|
-
headers?: Record<string, string>;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
type ToolContext<TContext = Record<string, unknown>> = {
|
|
143
|
-
session: Session;
|
|
144
|
-
sandbox: Sandbox;
|
|
145
|
-
storage: Storage;
|
|
146
|
-
context: TContext;
|
|
147
|
-
};
|
|
148
|
-
declare const builtInTools: {
|
|
149
|
-
Read: ai.Tool<{
|
|
150
|
-
path: string;
|
|
151
|
-
startLine?: number | undefined;
|
|
152
|
-
endLine?: number | undefined;
|
|
153
|
-
}, {
|
|
154
|
-
content: string;
|
|
155
|
-
metadata: {
|
|
156
|
-
totalLines: number;
|
|
157
|
-
linesShown: number;
|
|
158
|
-
startLine: number;
|
|
159
|
-
endLine: number;
|
|
160
|
-
isPaginated: boolean;
|
|
161
|
-
fileSize: string;
|
|
162
|
-
path: string;
|
|
163
|
-
};
|
|
164
|
-
}>;
|
|
165
|
-
Grep: ai.Tool<{
|
|
166
|
-
pattern: string;
|
|
167
|
-
caseSensitive: boolean;
|
|
168
|
-
filesWithMatches: boolean;
|
|
169
|
-
path?: string | undefined;
|
|
170
|
-
fileType?: string | undefined;
|
|
171
|
-
glob?: string | undefined;
|
|
172
|
-
contextLines?: number | undefined;
|
|
173
|
-
maxCount?: number | undefined;
|
|
174
|
-
}, {
|
|
175
|
-
matches: string;
|
|
176
|
-
summary: {
|
|
177
|
-
matchCount: number;
|
|
178
|
-
fileCount: number;
|
|
179
|
-
searchPath: string;
|
|
180
|
-
pattern: string;
|
|
181
|
-
};
|
|
182
|
-
}>;
|
|
183
|
-
List: ai.Tool<{
|
|
184
|
-
includeHidden: boolean;
|
|
185
|
-
filesOnly: boolean;
|
|
186
|
-
path?: string | undefined;
|
|
187
|
-
depth?: number | undefined;
|
|
188
|
-
pattern?: string | undefined;
|
|
189
|
-
}, {
|
|
190
|
-
listing: string;
|
|
191
|
-
summary: {
|
|
192
|
-
totalItems: number;
|
|
193
|
-
totalFiles: number;
|
|
194
|
-
totalDirs: number;
|
|
195
|
-
searchPath: string;
|
|
196
|
-
depth?: number | undefined;
|
|
197
|
-
};
|
|
198
|
-
}>;
|
|
199
|
-
Write: ai.Tool<{
|
|
200
|
-
path: string;
|
|
201
|
-
content: string;
|
|
202
|
-
}, {
|
|
203
|
-
success: boolean;
|
|
204
|
-
path: string;
|
|
205
|
-
bytesWritten: number;
|
|
206
|
-
error?: string | undefined;
|
|
207
|
-
}>;
|
|
208
|
-
Edit: ai.Tool<{
|
|
209
|
-
path: string;
|
|
210
|
-
old_string: string;
|
|
211
|
-
new_string: string;
|
|
212
|
-
}, {
|
|
213
|
-
success: boolean;
|
|
214
|
-
path: string;
|
|
215
|
-
error?: string | undefined;
|
|
216
|
-
}>;
|
|
217
|
-
Bash: ai.Tool<{
|
|
218
|
-
command: string;
|
|
219
|
-
waitUntil?: number | undefined;
|
|
220
|
-
}, {
|
|
221
|
-
pid: number;
|
|
222
|
-
output: string;
|
|
223
|
-
exitCode: number;
|
|
224
|
-
status: "running" | "completed" | "failed";
|
|
225
|
-
cwd: string;
|
|
226
|
-
outputFile: string;
|
|
227
|
-
}>;
|
|
228
|
-
JavaScript: ai.Tool<{
|
|
229
|
-
code: string;
|
|
230
|
-
}, any>;
|
|
231
|
-
};
|
|
232
|
-
type BuiltInToolName = keyof typeof builtInTools;
|
|
233
|
-
declare const builtinToolNames: { [K in BuiltInToolName]: K; };
|
|
234
|
-
|
|
235
|
-
type ToolMetadata = {
|
|
236
|
-
name: string;
|
|
237
|
-
description?: string;
|
|
238
|
-
inputSchema?: JSONSchema7;
|
|
239
|
-
};
|
|
240
|
-
type ToolsExecuteParams = {
|
|
241
|
-
name: string;
|
|
242
|
-
input: unknown;
|
|
243
|
-
session: Session;
|
|
244
|
-
sandboxRecord: SandboxRecord;
|
|
245
|
-
context: Record<string, unknown>;
|
|
246
|
-
};
|
|
247
|
-
type HookToolBeforeParams = {
|
|
248
|
-
name: string;
|
|
249
|
-
input: unknown;
|
|
250
|
-
context: ToolContext;
|
|
251
|
-
};
|
|
252
|
-
type HookToolBeforeResult = {
|
|
253
|
-
input?: unknown;
|
|
254
|
-
stop?: boolean;
|
|
255
|
-
};
|
|
256
|
-
type HookToolAfterParams = {
|
|
257
|
-
name: string;
|
|
258
|
-
input: unknown;
|
|
259
|
-
result: unknown;
|
|
260
|
-
context: ToolContext;
|
|
261
|
-
};
|
|
262
|
-
type HookToolAfterResult = {
|
|
263
|
-
result?: unknown;
|
|
264
|
-
stop?: boolean;
|
|
265
|
-
};
|
|
266
|
-
type ToolsNeedsApprovalParams = {
|
|
267
|
-
toolName: string;
|
|
268
|
-
input: unknown;
|
|
269
|
-
toolCallId: string;
|
|
270
|
-
messages: unknown[];
|
|
271
|
-
};
|
|
272
|
-
type ToolsNeedsApprovalResult = boolean;
|
|
273
|
-
type HookStatusParams = {
|
|
274
|
-
status: AgentStatus;
|
|
275
|
-
};
|
|
276
|
-
type HookStatusResult = Record<string, never>;
|
|
277
|
-
|
|
278
|
-
type SessionUsage = {
|
|
279
|
-
total: UsageSummary & {
|
|
280
|
-
messageCount: number;
|
|
281
|
-
};
|
|
282
|
-
byMessageId: Record<string, UsageSummary | null>;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
type SendInput = string | {
|
|
286
|
-
role?: UIMessage["role"];
|
|
287
|
-
parts: UIMessage["parts"];
|
|
288
|
-
id?: string;
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Transient status indicators emitted over the stream during long-running phases.
|
|
292
|
-
* Delivered to the client as `data-status` chunks with `transient: true` — not persisted.
|
|
293
|
-
*/
|
|
294
|
-
type AgentStatus = {
|
|
295
|
-
type: "sandbox-setup";
|
|
296
|
-
} | {
|
|
297
|
-
type: "sandbox-setup-cold";
|
|
298
|
-
} | {
|
|
299
|
-
type: "loading-skills";
|
|
300
|
-
} | {
|
|
301
|
-
type: "processing-approvals";
|
|
302
|
-
} | {
|
|
303
|
-
type: "needs-approval";
|
|
304
|
-
} | {
|
|
305
|
-
type: "thinking";
|
|
306
|
-
} | {
|
|
307
|
-
type: "custom";
|
|
308
|
-
status: string;
|
|
309
|
-
};
|
|
310
|
-
/**
|
|
311
|
-
* Augmented `ReadableStream` returned by `session.stream()`.
|
|
312
|
-
* Passes `instanceof ReadableStream` and works with `createUIMessageStreamResponse({ stream })`.
|
|
313
|
-
*/
|
|
314
|
-
type AgentStream = ReadableStream<UIMessageChunk> & {
|
|
315
|
-
/** Write a typed status update to the stream (transient, not persisted). */
|
|
316
|
-
writeStatus: (status: AgentStatus) => void;
|
|
317
|
-
};
|
|
318
|
-
/**
|
|
319
|
-
* Data part types emitted by every agent over the stream.
|
|
320
|
-
* Used as the `DATA_PARTS` generic for `UIMessage`.
|
|
321
|
-
*/
|
|
322
|
-
type AgentDataTypes = {
|
|
323
|
-
status: AgentStatus;
|
|
324
|
-
};
|
|
325
|
-
/**
|
|
326
|
-
* Infer a typed UIMessage from an agent instance.
|
|
327
|
-
* Tool parts are discriminated by `type: "tool-${name}"` with typed input/output.
|
|
328
|
-
* Data parts include `data-status` with typed `AgentStatus`.
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* ```ts
|
|
332
|
-
* const myAgent = agent({ tools: { myTool: tool({...}) } });
|
|
333
|
-
* type MyMessage = typeof myAgent.$UIMessage;
|
|
334
|
-
* // MyMessage.parts includes { type: "tool-myTool"; input: MyInput; output: MyOutput; ... }
|
|
335
|
-
* // onData callback receives { type: "data-status"; data: AgentStatus }
|
|
336
|
-
* ```
|
|
337
|
-
*/
|
|
338
|
-
type InferUIMessage<A> = A extends {
|
|
339
|
-
tools: infer T extends ToolSet;
|
|
340
|
-
} ? UIMessage<unknown, AgentDataTypes, InferUITools<T>> : UIMessage<unknown, AgentDataTypes>;
|
|
341
|
-
type ToolName<Tools> = Extract<keyof Tools, string> | BuiltInToolName;
|
|
342
|
-
type ToolInput<Tools, K> = K extends BuiltInToolName ? InferToolInput<(typeof builtInTools)[K]> : K extends keyof Tools ? Tools[K] extends ai.Tool ? InferToolInput<Tools[K]> : unknown : unknown;
|
|
343
|
-
type NeedsApprovalMap<Tools> = {
|
|
344
|
-
[K in ToolName<Tools>]?: boolean | ((input: ToolInput<Tools, K>, options: {
|
|
345
|
-
toolCallId: string;
|
|
346
|
-
messages: ModelMessage[];
|
|
347
|
-
experimental_context: unknown;
|
|
348
|
-
}) => boolean | Promise<boolean>);
|
|
349
|
-
};
|
|
350
|
-
/**
|
|
351
|
-
* Options that can be set per-session, overriding agent-level defaults.
|
|
352
|
-
*/
|
|
353
|
-
type SessionOptions<Tools extends ToolSet, TTags extends Record<string, unknown> = Record<string, never>> = {
|
|
354
|
-
/** The AI model to use. */
|
|
355
|
-
model?: GatewayModelId;
|
|
356
|
-
/** System prompt for the AI model. */
|
|
357
|
-
system?: string;
|
|
358
|
-
/** Sandbox configuration or ID. If string, uses as sandbox ID with its config. */
|
|
359
|
-
sandbox?: (SandboxConfig & {
|
|
360
|
-
setup?: SandboxSetup;
|
|
361
|
-
onRestart?: OnRestart;
|
|
362
|
-
}) | string;
|
|
363
|
-
/** Key-value metadata tags for the session. */
|
|
364
|
-
tags?: TTags;
|
|
365
|
-
/** Directory containing skill definitions for the agent. */
|
|
366
|
-
skillsDir?: SkillsDir;
|
|
367
|
-
/**
|
|
368
|
-
* Names of tools to activate for this session.
|
|
369
|
-
* If not specified, all agent-level tools are active.
|
|
370
|
-
* Use this to restrict which tools are available per-session.
|
|
371
|
-
*/
|
|
372
|
-
activeTools?: (Extract<keyof Tools, string> | BuiltInToolName)[];
|
|
373
|
-
/** Generation options (temperature, maxSteps, etc.). Overrides agent-level defaults. */
|
|
374
|
-
generation?: GenerationOptions;
|
|
375
|
-
};
|
|
376
|
-
type SessionUpdateOptions<Tools extends ToolSet> = Pick<SessionOptions<Tools>, "model" | "system" | "skillsDir" | "activeTools" | "generation">;
|
|
377
|
-
/**
|
|
378
|
-
* Configuration options for creating an agent instance.
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* ```ts
|
|
382
|
-
* const myAgent = agent({
|
|
383
|
-
* model: "anthropic/claude-opus-4.5",
|
|
384
|
-
* system: "You are a helpful assistant...",
|
|
385
|
-
* tagsSchema: z.object({ userId: z.string() }),
|
|
386
|
-
* contextSchema: z.object({ authToken: z.string() }),
|
|
387
|
-
* });
|
|
388
|
-
* ```
|
|
389
|
-
*/
|
|
390
|
-
type AgentOptions<Tools extends ToolSet, TTags extends Record<string, unknown> = Record<string, never>, TContext extends Record<string, unknown> = Record<string, never>> = {
|
|
391
|
-
/**
|
|
392
|
-
* Agent name. Used to isolate storage data - different names have separate data.
|
|
393
|
-
* @default "default"
|
|
394
|
-
*/
|
|
395
|
-
name?: string;
|
|
396
|
-
/**
|
|
397
|
-
* Storage backend configuration.
|
|
398
|
-
* - `{ type: "local" }` - filesystem storage (dev)
|
|
399
|
-
* - `{ type: "vercel" }` - Vercel managed storage (prod)
|
|
400
|
-
* - `{ type: "custom", url: "..." }` - custom HTTP backend
|
|
401
|
-
* @default Inferred from environment: `{ type: "vercel" }` when `VERCEL_OIDC_TOKEN` is set, `{ type: "local" }` otherwise.
|
|
402
|
-
*/
|
|
403
|
-
storage?: StorageConfig;
|
|
404
|
-
/**
|
|
405
|
-
* Custom tools available to the agent.
|
|
406
|
-
* These are exposed via the RPC handler and called over HTTP.
|
|
407
|
-
*/
|
|
408
|
-
tools?: Tools;
|
|
409
|
-
/**
|
|
410
|
-
* Hooks for intercepting agent operations.
|
|
411
|
-
*/
|
|
412
|
-
hooks?: AgentHooks;
|
|
413
|
-
/**
|
|
414
|
-
* Schema for session tags. All sessions share this schema.
|
|
415
|
-
* Tags are persisted in storage and survive across requests.
|
|
416
|
-
*/
|
|
417
|
-
tagsSchema?: z.ZodType<TTags>;
|
|
418
|
-
/**
|
|
419
|
-
* Schema for transient tool context. Passed per-request via send().
|
|
420
|
-
* NOT persisted - use for secrets like auth tokens.
|
|
421
|
-
*/
|
|
422
|
-
contextSchema?: z.ZodType<TContext>;
|
|
423
|
-
/**
|
|
424
|
-
* Approval rules for tools you don't own (built-in or third-party).
|
|
425
|
-
* Maps tool names to a boolean or a function that decides whether to ask.
|
|
426
|
-
*
|
|
427
|
-
* @example
|
|
428
|
-
* ```ts
|
|
429
|
-
* needsApproval: {
|
|
430
|
-
* Bash: (input) => input.command.startsWith("rm"),
|
|
431
|
-
* Write: true,
|
|
432
|
-
* }
|
|
433
|
-
* ```
|
|
434
|
-
*/
|
|
435
|
-
needsApproval?: NeedsApprovalMap<Tools>;
|
|
436
|
-
/**
|
|
437
|
-
* Sandbox configuration with optional setup and restart hooks.
|
|
438
|
-
*
|
|
439
|
-
* - `setup.key`: explicit string to control snapshot invalidation (bump to re-run)
|
|
440
|
-
* - `setup.run`: async function that runs once to initialize the sandbox, then gets snapshotted
|
|
441
|
-
* - `onRestart`: async function that runs every time a sandbox resumes from a snapshot
|
|
442
|
-
*
|
|
443
|
-
* @example
|
|
444
|
-
* ```ts
|
|
445
|
-
* sandbox: {
|
|
446
|
-
* type: "vercel",
|
|
447
|
-
* setup: {
|
|
448
|
-
* key: "dev-env-v3",
|
|
449
|
-
* run: async (sandbox) => {
|
|
450
|
-
* await sandbox.exec({ command: "npm", args: ["i", "-g", "vercel"] })
|
|
451
|
-
* },
|
|
452
|
-
* },
|
|
453
|
-
* onRestart: async (sandbox) => {
|
|
454
|
-
* await sandbox.exec({ command: "bash", args: ["-c", "npm run dev &"] })
|
|
455
|
-
* },
|
|
456
|
-
* }
|
|
457
|
-
* ```
|
|
458
|
-
*/
|
|
459
|
-
sandbox?: (SandboxConfig & {
|
|
460
|
-
setup?: SandboxSetup;
|
|
461
|
-
onRestart?: OnRestart;
|
|
462
|
-
}) | string;
|
|
463
|
-
} & Omit<SessionOptions<Tools, TTags>, "tags" | "sandbox">;
|
|
464
|
-
/**
|
|
465
|
-
* Base type for session/sandbox tags. Used for generic constraints.
|
|
466
|
-
* For agent-level tag validation, use `tagsSchema` option with a zod schema.
|
|
467
|
-
*/
|
|
468
|
-
type TagsSchema = Record<string, unknown>;
|
|
469
|
-
/**
|
|
470
|
-
* Hooks for intercepting agent operations.
|
|
471
|
-
*/
|
|
472
|
-
type AgentHooks = {
|
|
473
|
-
/** Called before a tool is executed. Can modify input or throw to block. */
|
|
474
|
-
"tool.before"?: (opts: {
|
|
475
|
-
name: string;
|
|
476
|
-
input: unknown;
|
|
477
|
-
context: ToolContext;
|
|
478
|
-
}) => Promise<undefined | {
|
|
479
|
-
input: unknown;
|
|
480
|
-
}>;
|
|
481
|
-
/** Called after a tool is executed. Can modify result. */
|
|
482
|
-
"tool.after"?: (opts: {
|
|
483
|
-
name: string;
|
|
484
|
-
input: unknown;
|
|
485
|
-
result: unknown;
|
|
486
|
-
context: ToolContext;
|
|
487
|
-
}) => Promise<undefined | {
|
|
488
|
-
result: unknown;
|
|
489
|
-
}>;
|
|
490
|
-
/** Called when the agent emits a transient status indicator. */
|
|
491
|
-
status?: (status: AgentStatus) => void | Promise<void>;
|
|
492
|
-
};
|
|
493
|
-
/**
|
|
494
|
-
* RPC response type for dispatch.
|
|
495
|
-
*/
|
|
496
|
-
type RpcResult<T = unknown> = {
|
|
497
|
-
result: T;
|
|
498
|
-
} | {
|
|
499
|
-
error: {
|
|
500
|
-
code: string;
|
|
501
|
-
message: string;
|
|
502
|
-
};
|
|
503
|
-
status?: number;
|
|
504
|
-
};
|
|
505
|
-
/**
|
|
506
|
-
* Direct RPC payload for step function calls (no HTTP).
|
|
507
|
-
*/
|
|
508
|
-
type RpcPayload = {
|
|
509
|
-
name?: string;
|
|
510
|
-
method: string;
|
|
511
|
-
params: unknown;
|
|
512
|
-
};
|
|
513
|
-
/**
|
|
514
|
-
* All RPC methods available on the agent handler.
|
|
515
|
-
* Combines tools methods, hooks, and storage methods.
|
|
516
|
-
*/
|
|
517
|
-
type AgentRpcMethods = {
|
|
518
|
-
"tools.list": {
|
|
519
|
-
params: Record<string, never>;
|
|
520
|
-
result: ToolMetadata[];
|
|
521
|
-
};
|
|
522
|
-
"tools.execute": {
|
|
523
|
-
params: ToolsExecuteParams;
|
|
524
|
-
result: unknown;
|
|
525
|
-
};
|
|
526
|
-
"tools.needsApproval": {
|
|
527
|
-
params: ToolsNeedsApprovalParams;
|
|
528
|
-
result: ToolsNeedsApprovalResult;
|
|
529
|
-
};
|
|
530
|
-
"hook.tool.before": {
|
|
531
|
-
params: HookToolBeforeParams;
|
|
532
|
-
result: HookToolBeforeResult;
|
|
533
|
-
};
|
|
534
|
-
"hook.tool.after": {
|
|
535
|
-
params: HookToolAfterParams;
|
|
536
|
-
result: HookToolAfterResult;
|
|
537
|
-
};
|
|
538
|
-
"hook.status": {
|
|
539
|
-
params: HookStatusParams;
|
|
540
|
-
result: HookStatusResult;
|
|
541
|
-
};
|
|
542
|
-
} & StorageMethods;
|
|
543
|
-
type AgentRpcMethodName = keyof AgentRpcMethods;
|
|
544
|
-
/**
|
|
545
|
-
* Result type for RPC override handlers.
|
|
546
|
-
* - `{ ok: true; result: T }` - return this result
|
|
547
|
-
* - `{ ok: false; error: string }` - return this error
|
|
548
|
-
* - `null` - use default handler
|
|
549
|
-
*/
|
|
550
|
-
type AgentRpcResult<T> = {
|
|
551
|
-
ok: true;
|
|
552
|
-
result: T;
|
|
553
|
-
} | {
|
|
554
|
-
ok: false;
|
|
555
|
-
error: string;
|
|
556
|
-
} | null;
|
|
557
|
-
/**
|
|
558
|
-
* Override handlers for agent RPC methods.
|
|
559
|
-
* Each method can be individually overridden.
|
|
560
|
-
* Return `null` to fall back to the default handler.
|
|
561
|
-
*/
|
|
562
|
-
type AgentRpcOverrides = {
|
|
563
|
-
[K in AgentRpcMethodName]?: (params: AgentRpcMethods[K]["params"]) => Promise<AgentRpcResult<AgentRpcMethods[K]["result"]>>;
|
|
564
|
-
};
|
|
565
|
-
declare const agent: <Tools extends {}, TTags extends Record<string, unknown> = Record<string, never>, TContext extends Record<string, unknown> = Record<string, never>>(options: AgentOptions<Tools, TTags, TContext>) => {
|
|
566
|
-
session: (sessionId: string, sessionOptions?: SessionOptions<Tools, TTags>) => Promise<{
|
|
567
|
-
send: ({ input, interruptIfStreaming, context, }: {
|
|
568
|
-
input: SendInput | SendInput[];
|
|
569
|
-
interruptIfStreaming?: boolean;
|
|
570
|
-
context?: TContext;
|
|
571
|
-
}) => Promise<void | SessionError | StorageError>;
|
|
572
|
-
stream: (opts?: {
|
|
573
|
-
messageId?: string;
|
|
574
|
-
}) => Promise<AgentStream | Error>;
|
|
575
|
-
ui: () => Promise<StorageError | {
|
|
576
|
-
messages: UIMessage<unknown, AgentDataTypes, InferUITools<{
|
|
577
|
-
Read: ai.Tool<{
|
|
578
|
-
path: string;
|
|
579
|
-
startLine?: number | undefined;
|
|
580
|
-
endLine?: number | undefined;
|
|
581
|
-
}, {
|
|
582
|
-
content: string;
|
|
583
|
-
metadata: {
|
|
584
|
-
totalLines: number;
|
|
585
|
-
linesShown: number;
|
|
586
|
-
startLine: number;
|
|
587
|
-
endLine: number;
|
|
588
|
-
isPaginated: boolean;
|
|
589
|
-
fileSize: string;
|
|
590
|
-
path: string;
|
|
591
|
-
};
|
|
592
|
-
}>;
|
|
593
|
-
Grep: ai.Tool<{
|
|
594
|
-
pattern: string;
|
|
595
|
-
caseSensitive: boolean;
|
|
596
|
-
filesWithMatches: boolean;
|
|
597
|
-
path?: string | undefined;
|
|
598
|
-
fileType?: string | undefined;
|
|
599
|
-
glob?: string | undefined;
|
|
600
|
-
contextLines?: number | undefined;
|
|
601
|
-
maxCount?: number | undefined;
|
|
602
|
-
}, {
|
|
603
|
-
matches: string;
|
|
604
|
-
summary: {
|
|
605
|
-
matchCount: number;
|
|
606
|
-
fileCount: number;
|
|
607
|
-
searchPath: string;
|
|
608
|
-
pattern: string;
|
|
609
|
-
};
|
|
610
|
-
}>;
|
|
611
|
-
List: ai.Tool<{
|
|
612
|
-
includeHidden: boolean;
|
|
613
|
-
filesOnly: boolean;
|
|
614
|
-
path?: string | undefined;
|
|
615
|
-
depth?: number | undefined;
|
|
616
|
-
pattern?: string | undefined;
|
|
617
|
-
}, {
|
|
618
|
-
listing: string;
|
|
619
|
-
summary: {
|
|
620
|
-
totalItems: number;
|
|
621
|
-
totalFiles: number;
|
|
622
|
-
totalDirs: number;
|
|
623
|
-
searchPath: string;
|
|
624
|
-
depth?: number | undefined;
|
|
625
|
-
};
|
|
626
|
-
}>;
|
|
627
|
-
Write: ai.Tool<{
|
|
628
|
-
path: string;
|
|
629
|
-
content: string;
|
|
630
|
-
}, {
|
|
631
|
-
success: boolean;
|
|
632
|
-
path: string;
|
|
633
|
-
bytesWritten: number;
|
|
634
|
-
error?: string | undefined;
|
|
635
|
-
}>;
|
|
636
|
-
Edit: ai.Tool<{
|
|
637
|
-
path: string;
|
|
638
|
-
old_string: string;
|
|
639
|
-
new_string: string;
|
|
640
|
-
}, {
|
|
641
|
-
success: boolean;
|
|
642
|
-
path: string;
|
|
643
|
-
error?: string | undefined;
|
|
644
|
-
}>;
|
|
645
|
-
Bash: ai.Tool<{
|
|
646
|
-
command: string;
|
|
647
|
-
waitUntil?: number | undefined;
|
|
648
|
-
}, {
|
|
649
|
-
pid: number;
|
|
650
|
-
output: string;
|
|
651
|
-
exitCode: number;
|
|
652
|
-
status: "running" | "completed" | "failed";
|
|
653
|
-
cwd: string;
|
|
654
|
-
outputFile: string;
|
|
655
|
-
}>;
|
|
656
|
-
JavaScript: ai.Tool<{
|
|
657
|
-
code: string;
|
|
658
|
-
}, any>;
|
|
659
|
-
} & Tools>>[];
|
|
660
|
-
streamingMessageId: string | null;
|
|
661
|
-
usage: SessionUsage;
|
|
662
|
-
}>;
|
|
663
|
-
tag: {
|
|
664
|
-
list: () => Promise<SessionNotFoundError | StorageError | TTags>;
|
|
665
|
-
get: <K extends keyof TTags & string>(key: K) => Promise<TTags[K] | undefined | Error>;
|
|
666
|
-
set: <K extends keyof TTags & string>(key: K, value: TTags[K]) => Promise<undefined | Error>;
|
|
667
|
-
setMany: (tags: Partial<TTags>) => Promise<undefined | Error>;
|
|
668
|
-
};
|
|
669
|
-
sandbox: Sandbox<TTags> & {
|
|
670
|
-
_onReady?: Promise<void>;
|
|
671
|
-
_setupMeta?: Promise<SandboxSetupMeta>;
|
|
672
|
-
};
|
|
673
|
-
interrupt: () => Promise<StorageError | undefined>;
|
|
674
|
-
resolveApproval: ({ approvalId, approved, reason, }: {
|
|
675
|
-
approvalId: string;
|
|
676
|
-
approved: boolean;
|
|
677
|
-
reason?: string;
|
|
678
|
-
}) => Promise<undefined | Error>;
|
|
679
|
-
usage: () => Promise<SessionUsage | Error>;
|
|
680
|
-
update: (updateOptions: SessionUpdateOptions<Tools> & {
|
|
681
|
-
tags?: TTags;
|
|
682
|
-
}) => Promise<undefined | Error>;
|
|
683
|
-
}>;
|
|
684
|
-
sandbox: (sandboxId: string, opts?: {
|
|
685
|
-
config?: SandboxConfig;
|
|
686
|
-
tags?: TTags;
|
|
687
|
-
setup?: SandboxSetup;
|
|
688
|
-
onRestart?: OnRestart;
|
|
689
|
-
}) => Promise<Sandbox<TTags> & {
|
|
690
|
-
_onReady?: Promise<void>;
|
|
691
|
-
_setupMeta?: Promise<SandboxSetupMeta>;
|
|
692
|
-
}>;
|
|
693
|
-
readonly storage: TypedStorage<TTags>;
|
|
694
|
-
/**
|
|
695
|
-
* RPC handler for agent operations.
|
|
696
|
-
* Handles tools.list, tools.execute, storage RPC, and hooks.
|
|
697
|
-
*
|
|
698
|
-
* Called internally by the `rpc` step function during workflow execution.
|
|
699
|
-
* Can also be exposed via HTTP for external access if needed.
|
|
700
|
-
*/
|
|
701
|
-
handler: (input: Request | RpcPayload, overrides?: AgentRpcOverrides) => Promise<Response | RpcResult>;
|
|
702
|
-
tools: typeof builtInTools & Tools;
|
|
703
|
-
/** Phantom property for type inference. Use `typeof myAgent.$UIMessage` to get the typed UIMessage. */
|
|
704
|
-
$UIMessage: UIMessage<unknown, AgentDataTypes, InferUITools<typeof builtInTools & Tools>>;
|
|
705
|
-
/** Agent name used as key for the RPC registry. Set by the loader init. */
|
|
706
|
-
_agentName: string;
|
|
707
|
-
rpc: (params: RpcPayload) => Promise<RpcResult>;
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
export { type AgentDataTypes as A, type BuiltInToolName as B, type ExecResult as E, type GenerationOptions as G, type InferUIMessage as I, type OnRestart as O, type RpcPayload as R, type Sandbox as S, type TagsSchema as T, type UploadableFile as U, type RpcResult as a, type AgentOptions as b, type AgentStatus as c, type AgentStream as d, type SandboxSetup as e, type SendInput as f, type SessionOptions as g, type SkillSummary as h, type ToolContext as i, agent as j, builtinToolNames as k, type SandboxLifecycleInput as l };
|