agent-worker 0.1.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/dist/backends-BklSbwcH.mjs +381 -0
- package/dist/backends-BqaAh6cC.mjs +4 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +867 -0
- package/dist/index.d.mts +572 -0
- package/dist/index.mjs +121 -0
- package/dist/models-FOOpWB91.mjs +182 -0
- package/dist/session-DQQAmPf-.mjs +419 -0
- package/package.json +85 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import * as ai0 from "ai";
|
|
2
|
+
import { LanguageModel } from "ai";
|
|
3
|
+
import { BashToolkit, CreateBashToolOptions, createBashTool } from "bash-tool";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Message status for streaming/response tracking
|
|
8
|
+
*/
|
|
9
|
+
type MessageStatus = 'responding' | 'complete';
|
|
10
|
+
/**
|
|
11
|
+
* Extended message with status for tracking streaming state
|
|
12
|
+
*/
|
|
13
|
+
interface AgentMessage {
|
|
14
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
15
|
+
content: string;
|
|
16
|
+
/** Message status - 'responding' while streaming, 'complete' when done */
|
|
17
|
+
status?: MessageStatus;
|
|
18
|
+
/** Timestamp when message started */
|
|
19
|
+
timestamp?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Tool definition with optional mock implementation
|
|
23
|
+
*/
|
|
24
|
+
interface ToolDefinition {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
parameters: {
|
|
28
|
+
type: 'object';
|
|
29
|
+
properties: Record<string, unknown>;
|
|
30
|
+
required?: string[];
|
|
31
|
+
};
|
|
32
|
+
/** Mock function - returns controlled response for testing */
|
|
33
|
+
execute?: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
34
|
+
/** Static mock response (JSON-serializable, used when execute is not set) */
|
|
35
|
+
mockResponse?: unknown;
|
|
36
|
+
/** Require user approval before execution (default: false) */
|
|
37
|
+
needsApproval?: boolean | ((args: Record<string, unknown>) => boolean);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A pending tool call awaiting user approval
|
|
41
|
+
*/
|
|
42
|
+
interface PendingApproval {
|
|
43
|
+
/** Unique approval ID */
|
|
44
|
+
id: string;
|
|
45
|
+
/** Tool name */
|
|
46
|
+
toolName: string;
|
|
47
|
+
/** Tool call ID from the model */
|
|
48
|
+
toolCallId: string;
|
|
49
|
+
/** Arguments passed to the tool */
|
|
50
|
+
arguments: Record<string, unknown>;
|
|
51
|
+
/** When the approval was requested */
|
|
52
|
+
requestedAt: string;
|
|
53
|
+
/** Current status */
|
|
54
|
+
status: 'pending' | 'approved' | 'denied';
|
|
55
|
+
/** Denial reason if denied */
|
|
56
|
+
denyReason?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A single tool call with its result
|
|
60
|
+
*/
|
|
61
|
+
interface ToolCall {
|
|
62
|
+
name: string;
|
|
63
|
+
arguments: Record<string, unknown>;
|
|
64
|
+
result: unknown;
|
|
65
|
+
timing: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Token usage statistics
|
|
69
|
+
*/
|
|
70
|
+
interface TokenUsage {
|
|
71
|
+
input: number;
|
|
72
|
+
output: number;
|
|
73
|
+
total: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Response from a single message exchange
|
|
77
|
+
*/
|
|
78
|
+
interface AgentResponse {
|
|
79
|
+
/** Final text content */
|
|
80
|
+
content: string;
|
|
81
|
+
/** All tool calls made during this turn */
|
|
82
|
+
toolCalls: ToolCall[];
|
|
83
|
+
/** Tool calls awaiting approval (response is incomplete until approved) */
|
|
84
|
+
pendingApprovals: PendingApproval[];
|
|
85
|
+
/** Token usage */
|
|
86
|
+
usage: TokenUsage;
|
|
87
|
+
/** Response latency in ms */
|
|
88
|
+
latency: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Session configuration
|
|
92
|
+
*/
|
|
93
|
+
interface SessionConfig {
|
|
94
|
+
/** Model identifier (e.g., 'openai/gpt-5.2' or 'anthropic:claude-sonnet-4-5') */
|
|
95
|
+
model: string;
|
|
96
|
+
/** System prompt */
|
|
97
|
+
system: string;
|
|
98
|
+
/** Tool definitions with mock implementations */
|
|
99
|
+
tools?: ToolDefinition[];
|
|
100
|
+
/** Maximum tokens for response (default: 4096) */
|
|
101
|
+
maxTokens?: number;
|
|
102
|
+
/** Maximum tool call steps per turn (default: 10) */
|
|
103
|
+
maxSteps?: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Persisted session state for restoration
|
|
107
|
+
*/
|
|
108
|
+
interface SessionState {
|
|
109
|
+
/** Session ID to restore */
|
|
110
|
+
id: string;
|
|
111
|
+
/** Creation timestamp */
|
|
112
|
+
createdAt: string;
|
|
113
|
+
/** Conversation messages with status */
|
|
114
|
+
messages: AgentMessage[];
|
|
115
|
+
/** Accumulated token usage */
|
|
116
|
+
totalUsage: TokenUsage;
|
|
117
|
+
/** Pending tool approvals */
|
|
118
|
+
pendingApprovals: PendingApproval[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Exported transcript for analysis
|
|
122
|
+
*/
|
|
123
|
+
interface Transcript {
|
|
124
|
+
sessionId: string;
|
|
125
|
+
model: string;
|
|
126
|
+
system: string;
|
|
127
|
+
messages: AgentMessage[];
|
|
128
|
+
totalUsage: TokenUsage;
|
|
129
|
+
createdAt: string;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/session.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* Step finish callback info
|
|
135
|
+
*/
|
|
136
|
+
interface StepInfo {
|
|
137
|
+
stepNumber: number;
|
|
138
|
+
toolCalls: ToolCall[];
|
|
139
|
+
usage: TokenUsage;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Options for send() method
|
|
143
|
+
*/
|
|
144
|
+
interface SendOptions {
|
|
145
|
+
/** Auto-approve all tool calls that require approval (default: true) */
|
|
146
|
+
autoApprove?: boolean;
|
|
147
|
+
/** Callback after each agent step */
|
|
148
|
+
onStepFinish?: (info: StepInfo) => void | Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* AgentSession - Stateful session for controlled agent testing
|
|
152
|
+
*
|
|
153
|
+
* Uses ToolLoopAgent internally for multi-step reasoning loops.
|
|
154
|
+
* Maintains conversation state across multiple send() calls,
|
|
155
|
+
* enabling improvisational testing where you observe responses
|
|
156
|
+
* and decide next actions.
|
|
157
|
+
*/
|
|
158
|
+
declare class AgentSession {
|
|
159
|
+
readonly id: string;
|
|
160
|
+
readonly model: string;
|
|
161
|
+
readonly system: string;
|
|
162
|
+
readonly createdAt: string;
|
|
163
|
+
private tools;
|
|
164
|
+
private maxTokens;
|
|
165
|
+
private maxSteps;
|
|
166
|
+
private messages;
|
|
167
|
+
private totalUsage;
|
|
168
|
+
private pendingApprovals;
|
|
169
|
+
private cachedAgent;
|
|
170
|
+
private toolsChanged;
|
|
171
|
+
/**
|
|
172
|
+
* Convert AgentMessage[] to ModelMessage[] for AI SDK
|
|
173
|
+
*/
|
|
174
|
+
private toModelMessages;
|
|
175
|
+
constructor(config: SessionConfig, restore?: SessionState);
|
|
176
|
+
/**
|
|
177
|
+
* Check if a tool needs approval for given arguments
|
|
178
|
+
*/
|
|
179
|
+
private toolNeedsApproval;
|
|
180
|
+
/**
|
|
181
|
+
* Build tools with approval handling
|
|
182
|
+
*/
|
|
183
|
+
private buildTools;
|
|
184
|
+
/**
|
|
185
|
+
* Get or create cached agent, rebuild if tools changed
|
|
186
|
+
*/
|
|
187
|
+
private getAgent;
|
|
188
|
+
/**
|
|
189
|
+
* Send a message and get the agent's response
|
|
190
|
+
* Conversation state is maintained across calls
|
|
191
|
+
*
|
|
192
|
+
* @param content - The message to send
|
|
193
|
+
* @param options - Send options (autoApprove, onStepFinish, etc.)
|
|
194
|
+
*/
|
|
195
|
+
send(content: string, options?: SendOptions): Promise<AgentResponse>;
|
|
196
|
+
/**
|
|
197
|
+
* Send a message and stream the response
|
|
198
|
+
* Returns an async iterable of text chunks
|
|
199
|
+
*
|
|
200
|
+
* @param content - The message to send
|
|
201
|
+
* @param options - Send options (autoApprove, onStepFinish, etc.)
|
|
202
|
+
*/
|
|
203
|
+
sendStream(content: string, options?: SendOptions): AsyncGenerator<string, AgentResponse, unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* Add a tool definition with mock implementation
|
|
206
|
+
*/
|
|
207
|
+
addTool(tool: ToolDefinition): void;
|
|
208
|
+
/**
|
|
209
|
+
* Set mock response for an existing tool
|
|
210
|
+
*/
|
|
211
|
+
mockTool(name: string, mockFn: (args: Record<string, unknown>) => unknown): void;
|
|
212
|
+
/**
|
|
213
|
+
* Get current tool definitions (without execute functions)
|
|
214
|
+
*/
|
|
215
|
+
getTools(): ToolDefinition[];
|
|
216
|
+
/**
|
|
217
|
+
* Set a static mock response for an existing tool (JSON-serializable)
|
|
218
|
+
*/
|
|
219
|
+
setMockResponse(name: string, response: unknown): void;
|
|
220
|
+
/**
|
|
221
|
+
* Get conversation history with status information
|
|
222
|
+
* Messages with status 'responding' are still being generated
|
|
223
|
+
*/
|
|
224
|
+
history(): AgentMessage[];
|
|
225
|
+
/**
|
|
226
|
+
* Get session statistics
|
|
227
|
+
*/
|
|
228
|
+
stats(): {
|
|
229
|
+
messageCount: number;
|
|
230
|
+
usage: TokenUsage;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Export full transcript for analysis
|
|
234
|
+
*/
|
|
235
|
+
export(): Transcript;
|
|
236
|
+
/**
|
|
237
|
+
* Get session state for persistence
|
|
238
|
+
*/
|
|
239
|
+
getState(): SessionState;
|
|
240
|
+
/**
|
|
241
|
+
* Get all pending approvals
|
|
242
|
+
*/
|
|
243
|
+
getPendingApprovals(): PendingApproval[];
|
|
244
|
+
/**
|
|
245
|
+
* Approve a pending tool call and execute it
|
|
246
|
+
* @returns The tool execution result
|
|
247
|
+
*/
|
|
248
|
+
approve(approvalId: string): Promise<unknown>;
|
|
249
|
+
/**
|
|
250
|
+
* Deny a pending tool call
|
|
251
|
+
* @param approvalId - The approval ID to deny
|
|
252
|
+
* @param reason - Optional reason for denial
|
|
253
|
+
*/
|
|
254
|
+
deny(approvalId: string, reason?: string): void;
|
|
255
|
+
/**
|
|
256
|
+
* Clear conversation history (keep system prompt and tools)
|
|
257
|
+
*/
|
|
258
|
+
clear(): void;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/models.d.ts
|
|
262
|
+
/**
|
|
263
|
+
* Parse model identifier and return the appropriate provider model
|
|
264
|
+
*
|
|
265
|
+
* Supports three formats:
|
|
266
|
+
*
|
|
267
|
+
* 1. Provider-only format: provider
|
|
268
|
+
* Uses first model from FRONTIER_MODELS via gateway
|
|
269
|
+
* Examples: anthropic → anthropic/claude-sonnet-4-5, openai → openai/gpt-5.2
|
|
270
|
+
*
|
|
271
|
+
* 2. Gateway format: provider/model-name
|
|
272
|
+
* Uses Vercel AI Gateway (requires AI_GATEWAY_API_KEY)
|
|
273
|
+
* Examples: anthropic/claude-sonnet-4-5, openai/gpt-5.2, deepseek/deepseek-chat
|
|
274
|
+
*
|
|
275
|
+
* 3. Direct provider format: provider:model-name
|
|
276
|
+
* Requires installing the specific @ai-sdk/provider package
|
|
277
|
+
* Examples: anthropic:claude-sonnet-4-5, openai:gpt-5.2, deepseek:deepseek-chat
|
|
278
|
+
*/
|
|
279
|
+
declare function createModel(modelId: string): LanguageModel;
|
|
280
|
+
/**
|
|
281
|
+
* Async version of createModel - supports lazy loading of direct providers
|
|
282
|
+
* Use this when you need direct provider access (provider:model format)
|
|
283
|
+
*/
|
|
284
|
+
declare function createModelAsync(modelId: string): Promise<LanguageModel>;
|
|
285
|
+
/**
|
|
286
|
+
* List of supported providers for direct access
|
|
287
|
+
* Note: minimax uses Claude-compatible API via @ai-sdk/anthropic with custom baseURL
|
|
288
|
+
*/
|
|
289
|
+
declare const SUPPORTED_PROVIDERS: readonly ["anthropic", "openai", "deepseek", "google", "groq", "mistral", "xai", "minimax"];
|
|
290
|
+
type SupportedProvider = (typeof SUPPORTED_PROVIDERS)[number];
|
|
291
|
+
/**
|
|
292
|
+
* Frontier models for each provider (as of 2026-02)
|
|
293
|
+
* Only includes the latest/best models, no legacy versions
|
|
294
|
+
*
|
|
295
|
+
* Note: Some models may be placeholders for testing or future releases.
|
|
296
|
+
* Always verify model availability with the provider before production use.
|
|
297
|
+
*/
|
|
298
|
+
declare const FRONTIER_MODELS: {
|
|
299
|
+
readonly anthropic: readonly ["claude-sonnet-4-5", "claude-haiku-4-5", "claude-opus-4-5"];
|
|
300
|
+
readonly openai: readonly ["gpt-5.2", "gpt-5.2-codex"];
|
|
301
|
+
readonly google: readonly ["gemini-3-pro-preview", "gemini-2.5-flash", "gemini-2.5-pro"];
|
|
302
|
+
readonly deepseek: readonly ["deepseek-chat", "deepseek-reasoner"];
|
|
303
|
+
readonly groq: readonly ["meta-llama/llama-4-scout-17b-16e-instruct", "deepseek-r1-distill-llama-70b"];
|
|
304
|
+
readonly mistral: readonly ["mistral-large-latest", "pixtral-large-latest", "magistral-medium-2506"];
|
|
305
|
+
readonly xai: readonly ["grok-4", "grok-4-fast-reasoning"];
|
|
306
|
+
readonly minimax: readonly ["MiniMax-M2"];
|
|
307
|
+
};
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/tools.d.ts
|
|
310
|
+
/**
|
|
311
|
+
* Convert ToolDefinition array to AI SDK tools object
|
|
312
|
+
* Uses tool() with jsonSchema() for runtime-defined mock tools
|
|
313
|
+
*/
|
|
314
|
+
declare function createTools(definitions: ToolDefinition[]): Record<string, ai0.Tool<never, never>>;
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/bash-tools.d.ts
|
|
317
|
+
/**
|
|
318
|
+
* Options for creating bash tools compatible with AgentSession
|
|
319
|
+
*/
|
|
320
|
+
interface BashToolsOptions extends CreateBashToolOptions {
|
|
321
|
+
/**
|
|
322
|
+
* Include readFile tool (default: true)
|
|
323
|
+
*/
|
|
324
|
+
includeReadFile?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Include writeFile tool (default: true)
|
|
327
|
+
*/
|
|
328
|
+
includeWriteFile?: boolean;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Create bash tools as ToolDefinition array for use with AgentSession
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const bashTools = await createBashTools({
|
|
336
|
+
* files: { 'src/index.ts': 'console.log("hello")' }
|
|
337
|
+
* })
|
|
338
|
+
*
|
|
339
|
+
* const session = new AgentSession({
|
|
340
|
+
* model: 'anthropic/claude-sonnet-4-5',
|
|
341
|
+
* system: 'You are a coding assistant.',
|
|
342
|
+
* tools: bashTools
|
|
343
|
+
* })
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
declare function createBashTools(options?: BashToolsOptions): Promise<{
|
|
347
|
+
tools: ToolDefinition[];
|
|
348
|
+
toolkit: BashToolkit;
|
|
349
|
+
}>;
|
|
350
|
+
/**
|
|
351
|
+
* Quick helper to create bash tools with a directory
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const { tools } = await createBashToolsFromDirectory('./src')
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare function createBashToolsFromDirectory(source: string, options?: Omit<BashToolsOptions, 'uploadDirectory'>): Promise<{
|
|
359
|
+
tools: ToolDefinition[];
|
|
360
|
+
toolkit: BashToolkit;
|
|
361
|
+
}>;
|
|
362
|
+
/**
|
|
363
|
+
* Quick helper to create bash tools with inline files
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const { tools } = await createBashToolsFromFiles({
|
|
368
|
+
* 'index.ts': 'console.log("hello")',
|
|
369
|
+
* 'package.json': '{"name": "test"}'
|
|
370
|
+
* })
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
declare function createBashToolsFromFiles(files: Record<string, string>, options?: Omit<BashToolsOptions, 'files'>): Promise<{
|
|
374
|
+
tools: ToolDefinition[];
|
|
375
|
+
toolkit: BashToolkit;
|
|
376
|
+
}>;
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/backends/types.d.ts
|
|
379
|
+
/**
|
|
380
|
+
* Backend types for different AI execution engines
|
|
381
|
+
*/
|
|
382
|
+
type BackendType = 'sdk' | 'claude' | 'codex' | 'cursor';
|
|
383
|
+
interface BackendConfig {
|
|
384
|
+
type: BackendType;
|
|
385
|
+
/** Model identifier (interpretation depends on backend) */
|
|
386
|
+
model?: string;
|
|
387
|
+
/** Additional CLI flags or SDK options */
|
|
388
|
+
options?: Record<string, unknown>;
|
|
389
|
+
}
|
|
390
|
+
interface BackendResponse {
|
|
391
|
+
content: string;
|
|
392
|
+
/** Tool calls made during execution (if supported) */
|
|
393
|
+
toolCalls?: Array<{
|
|
394
|
+
name: string;
|
|
395
|
+
arguments: unknown;
|
|
396
|
+
result: unknown;
|
|
397
|
+
}>;
|
|
398
|
+
/** Usage statistics (if available) */
|
|
399
|
+
usage?: {
|
|
400
|
+
input: number;
|
|
401
|
+
output: number;
|
|
402
|
+
total: number;
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
interface Backend {
|
|
406
|
+
readonly type: BackendType;
|
|
407
|
+
/** Send a message and get a response */
|
|
408
|
+
send(message: string, options?: {
|
|
409
|
+
system?: string;
|
|
410
|
+
}): Promise<BackendResponse>;
|
|
411
|
+
/** Check if the backend is available (CLI installed, API key set, etc.) */
|
|
412
|
+
isAvailable(): Promise<boolean>;
|
|
413
|
+
/** Get backend info for display */
|
|
414
|
+
getInfo(): {
|
|
415
|
+
name: string;
|
|
416
|
+
version?: string;
|
|
417
|
+
model?: string;
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/backends/claude-cli.d.ts
|
|
422
|
+
interface ClaudeCliOptions {
|
|
423
|
+
/** Model to use (e.g., 'opus', 'sonnet') */
|
|
424
|
+
model?: string;
|
|
425
|
+
/** Additional system prompt to append */
|
|
426
|
+
appendSystemPrompt?: string;
|
|
427
|
+
/** Allowed tools (permission rule syntax) */
|
|
428
|
+
allowedTools?: string[];
|
|
429
|
+
/** Output format: 'text' | 'json' | 'stream-json' */
|
|
430
|
+
outputFormat?: 'text' | 'json' | 'stream-json';
|
|
431
|
+
/** Continue most recent conversation */
|
|
432
|
+
continue?: boolean;
|
|
433
|
+
/** Resume specific session by ID */
|
|
434
|
+
resume?: string;
|
|
435
|
+
/** Working directory */
|
|
436
|
+
cwd?: string;
|
|
437
|
+
}
|
|
438
|
+
declare class ClaudeCliBackend implements Backend {
|
|
439
|
+
readonly type: "claude";
|
|
440
|
+
private options;
|
|
441
|
+
constructor(options?: ClaudeCliOptions);
|
|
442
|
+
send(message: string, options?: {
|
|
443
|
+
system?: string;
|
|
444
|
+
}): Promise<BackendResponse>;
|
|
445
|
+
isAvailable(): Promise<boolean>;
|
|
446
|
+
getInfo(): {
|
|
447
|
+
name: string;
|
|
448
|
+
version?: string;
|
|
449
|
+
model?: string;
|
|
450
|
+
};
|
|
451
|
+
private buildArgs;
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/backends/codex-cli.d.ts
|
|
455
|
+
interface CodexCliOptions {
|
|
456
|
+
/** Model to use (e.g., 'gpt-5.2-codex') */
|
|
457
|
+
model?: string;
|
|
458
|
+
/** Output as JSON events */
|
|
459
|
+
json?: boolean;
|
|
460
|
+
/** Working directory */
|
|
461
|
+
cwd?: string;
|
|
462
|
+
/** Skip git repo check */
|
|
463
|
+
skipGitRepoCheck?: boolean;
|
|
464
|
+
/** Approval mode: 'suggest' | 'auto-edit' | 'full-auto' */
|
|
465
|
+
approvalMode?: 'suggest' | 'auto-edit' | 'full-auto';
|
|
466
|
+
/** Resume a previous session */
|
|
467
|
+
resume?: string;
|
|
468
|
+
}
|
|
469
|
+
declare class CodexCliBackend implements Backend {
|
|
470
|
+
readonly type: "codex";
|
|
471
|
+
private options;
|
|
472
|
+
constructor(options?: CodexCliOptions);
|
|
473
|
+
send(message: string, _options?: {
|
|
474
|
+
system?: string;
|
|
475
|
+
}): Promise<BackendResponse>;
|
|
476
|
+
isAvailable(): Promise<boolean>;
|
|
477
|
+
getInfo(): {
|
|
478
|
+
name: string;
|
|
479
|
+
version?: string;
|
|
480
|
+
model?: string;
|
|
481
|
+
};
|
|
482
|
+
private buildArgs;
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/backends/cursor-cli.d.ts
|
|
486
|
+
interface CursorCliOptions {
|
|
487
|
+
/** Model to use */
|
|
488
|
+
model?: string;
|
|
489
|
+
/** Working directory */
|
|
490
|
+
cwd?: string;
|
|
491
|
+
/** Use 'agent' command instead of 'cursor-agent' */
|
|
492
|
+
useAgentCommand?: boolean;
|
|
493
|
+
/** Timeout in milliseconds (cursor CLI can hang) */
|
|
494
|
+
timeout?: number;
|
|
495
|
+
}
|
|
496
|
+
declare class CursorCliBackend implements Backend {
|
|
497
|
+
readonly type: "cursor";
|
|
498
|
+
private options;
|
|
499
|
+
constructor(options?: CursorCliOptions);
|
|
500
|
+
send(message: string, _options?: {
|
|
501
|
+
system?: string;
|
|
502
|
+
}): Promise<BackendResponse>;
|
|
503
|
+
isAvailable(): Promise<boolean>;
|
|
504
|
+
private checkCommand;
|
|
505
|
+
getInfo(): {
|
|
506
|
+
name: string;
|
|
507
|
+
version?: string;
|
|
508
|
+
model?: string;
|
|
509
|
+
};
|
|
510
|
+
private buildCommand;
|
|
511
|
+
}
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/backends/sdk.d.ts
|
|
514
|
+
interface SdkBackendOptions {
|
|
515
|
+
/** Model identifier (e.g., 'openai/gpt-5.2' or 'anthropic:claude-sonnet-4-5') */
|
|
516
|
+
model: string;
|
|
517
|
+
/** Maximum tokens to generate */
|
|
518
|
+
maxTokens?: number;
|
|
519
|
+
}
|
|
520
|
+
declare class SdkBackend implements Backend {
|
|
521
|
+
readonly type: "sdk";
|
|
522
|
+
private modelId;
|
|
523
|
+
private model;
|
|
524
|
+
private maxTokens;
|
|
525
|
+
constructor(options: SdkBackendOptions);
|
|
526
|
+
send(message: string, options?: {
|
|
527
|
+
system?: string;
|
|
528
|
+
}): Promise<BackendResponse>;
|
|
529
|
+
isAvailable(): Promise<boolean>;
|
|
530
|
+
getInfo(): {
|
|
531
|
+
name: string;
|
|
532
|
+
version?: string;
|
|
533
|
+
model?: string;
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/backends/index.d.ts
|
|
538
|
+
type BackendOptions = {
|
|
539
|
+
type: 'sdk';
|
|
540
|
+
model: string;
|
|
541
|
+
maxTokens?: number;
|
|
542
|
+
} | {
|
|
543
|
+
type: 'claude';
|
|
544
|
+
model?: string;
|
|
545
|
+
options?: Omit<ClaudeCliOptions, 'model'>;
|
|
546
|
+
} | {
|
|
547
|
+
type: 'codex';
|
|
548
|
+
model?: string;
|
|
549
|
+
options?: Omit<CodexCliOptions, 'model'>;
|
|
550
|
+
} | {
|
|
551
|
+
type: 'cursor';
|
|
552
|
+
model?: string;
|
|
553
|
+
options?: Omit<CursorCliOptions, 'model'>;
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* Create a backend instance
|
|
557
|
+
*/
|
|
558
|
+
declare function createBackend(config: BackendOptions): Backend;
|
|
559
|
+
/**
|
|
560
|
+
* Check which backends are available
|
|
561
|
+
*/
|
|
562
|
+
declare function checkBackends(): Promise<Record<BackendType, boolean>>;
|
|
563
|
+
/**
|
|
564
|
+
* List available backends with info
|
|
565
|
+
*/
|
|
566
|
+
declare function listBackends(): Promise<Array<{
|
|
567
|
+
type: BackendType;
|
|
568
|
+
available: boolean;
|
|
569
|
+
name: string;
|
|
570
|
+
}>>;
|
|
571
|
+
//#endregion
|
|
572
|
+
export { type AgentMessage, type AgentResponse, AgentSession, type Backend, type BackendConfig, type BackendOptions, type BackendResponse, type BackendType, type BashToolkit, type BashToolsOptions, ClaudeCliBackend, type ClaudeCliOptions, CodexCliBackend, type CodexCliOptions, type CreateBashToolOptions, CursorCliBackend, type CursorCliOptions, FRONTIER_MODELS, type MessageStatus, type PendingApproval, SUPPORTED_PROVIDERS, SdkBackend, type SdkBackendOptions, type SendOptions, type SessionConfig, type SessionState, type StepInfo, type SupportedProvider, type TokenUsage, type ToolCall, type ToolDefinition, type Transcript, checkBackends, createBackend, createBashTool, createBashTools, createBashToolsFromDirectory, createBashToolsFromFiles, createModel, createModelAsync, createTools, listBackends };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { i as createModelAsync, n as SUPPORTED_PROVIDERS, r as createModel, t as FRONTIER_MODELS } from "./models-FOOpWB91.mjs";
|
|
2
|
+
import { n as createTools, t as AgentSession } from "./session-DQQAmPf-.mjs";
|
|
3
|
+
import { a as CursorCliBackend, i as SdkBackend, n as createBackend, o as CodexCliBackend, r as listBackends, s as ClaudeCliBackend, t as checkBackends } from "./backends-BklSbwcH.mjs";
|
|
4
|
+
import { createBashTool } from "bash-tool";
|
|
5
|
+
|
|
6
|
+
//#region src/bash-tools.ts
|
|
7
|
+
/**
|
|
8
|
+
* Integration with Vercel's bash-tool for file system operations
|
|
9
|
+
*
|
|
10
|
+
* Provides bash, readFile, writeFile tools for AI agents in a sandboxed environment
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Create bash tools as ToolDefinition array for use with AgentSession
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const bashTools = await createBashTools({
|
|
18
|
+
* files: { 'src/index.ts': 'console.log("hello")' }
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* const session = new AgentSession({
|
|
22
|
+
* model: 'anthropic/claude-sonnet-4-5',
|
|
23
|
+
* system: 'You are a coding assistant.',
|
|
24
|
+
* tools: bashTools
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
async function createBashTools(options = {}) {
|
|
29
|
+
const { includeReadFile = true, includeWriteFile = true, ...bashOptions } = options;
|
|
30
|
+
const toolkit = await createBashTool(bashOptions);
|
|
31
|
+
const tools = [];
|
|
32
|
+
tools.push({
|
|
33
|
+
name: "bash",
|
|
34
|
+
description: "Execute bash commands in a sandboxed environment. Returns stdout, stderr, and exit code.",
|
|
35
|
+
parameters: {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: { command: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "The bash command to execute"
|
|
40
|
+
} },
|
|
41
|
+
required: ["command"]
|
|
42
|
+
},
|
|
43
|
+
execute: async (args) => {
|
|
44
|
+
return await toolkit.tools.bash.execute(args);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (includeReadFile) tools.push({
|
|
48
|
+
name: "readFile",
|
|
49
|
+
description: "Read the contents of a file from the sandbox filesystem.",
|
|
50
|
+
parameters: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: { path: {
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "The path to the file to read"
|
|
55
|
+
} },
|
|
56
|
+
required: ["path"]
|
|
57
|
+
},
|
|
58
|
+
execute: async (args) => {
|
|
59
|
+
return await toolkit.tools.readFile.execute(args);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (includeWriteFile) tools.push({
|
|
63
|
+
name: "writeFile",
|
|
64
|
+
description: "Write content to a file in the sandbox filesystem. Creates parent directories if needed.",
|
|
65
|
+
parameters: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
path: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "The path to the file to write"
|
|
71
|
+
},
|
|
72
|
+
content: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "The content to write to the file"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
required: ["path", "content"]
|
|
78
|
+
},
|
|
79
|
+
execute: async (args) => {
|
|
80
|
+
return await toolkit.tools.writeFile.execute(args);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
tools,
|
|
85
|
+
toolkit
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Quick helper to create bash tools with a directory
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const { tools } = await createBashToolsFromDirectory('./src')
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
async function createBashToolsFromDirectory(source, options = {}) {
|
|
97
|
+
return createBashTools({
|
|
98
|
+
...options,
|
|
99
|
+
uploadDirectory: { source }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Quick helper to create bash tools with inline files
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const { tools } = await createBashToolsFromFiles({
|
|
108
|
+
* 'index.ts': 'console.log("hello")',
|
|
109
|
+
* 'package.json': '{"name": "test"}'
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
async function createBashToolsFromFiles(files, options = {}) {
|
|
114
|
+
return createBashTools({
|
|
115
|
+
...options,
|
|
116
|
+
files
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { AgentSession, ClaudeCliBackend, CodexCliBackend, CursorCliBackend, FRONTIER_MODELS, SUPPORTED_PROVIDERS, SdkBackend, checkBackends, createBackend, createBashTool, createBashTools, createBashToolsFromDirectory, createBashToolsFromFiles, createModel, createModelAsync, createTools, listBackends };
|