@codeany/open-agent-sdk 0.2.1 → 0.2.3

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.
Files changed (57) hide show
  1. package/dist/engine.d.ts.map +1 -1
  2. package/dist/engine.js +2 -0
  3. package/dist/engine.js.map +1 -1
  4. package/package.json +5 -6
  5. package/src/agent.ts +0 -516
  6. package/src/engine.ts +0 -630
  7. package/src/hooks.ts +0 -261
  8. package/src/index.ts +0 -426
  9. package/src/mcp/client.ts +0 -150
  10. package/src/providers/anthropic.ts +0 -60
  11. package/src/providers/index.ts +0 -34
  12. package/src/providers/openai.ts +0 -315
  13. package/src/providers/types.ts +0 -85
  14. package/src/sdk-mcp-server.ts +0 -78
  15. package/src/session.ts +0 -227
  16. package/src/skills/bundled/commit.ts +0 -38
  17. package/src/skills/bundled/debug.ts +0 -48
  18. package/src/skills/bundled/index.ts +0 -28
  19. package/src/skills/bundled/review.ts +0 -41
  20. package/src/skills/bundled/simplify.ts +0 -51
  21. package/src/skills/bundled/test.ts +0 -43
  22. package/src/skills/index.ts +0 -25
  23. package/src/skills/registry.ts +0 -133
  24. package/src/skills/types.ts +0 -99
  25. package/src/tool-helper.ts +0 -127
  26. package/src/tools/agent-tool.ts +0 -164
  27. package/src/tools/ask-user.ts +0 -79
  28. package/src/tools/bash.ts +0 -75
  29. package/src/tools/config-tool.ts +0 -89
  30. package/src/tools/cron-tools.ts +0 -153
  31. package/src/tools/edit.ts +0 -74
  32. package/src/tools/glob.ts +0 -77
  33. package/src/tools/grep.ts +0 -168
  34. package/src/tools/index.ts +0 -240
  35. package/src/tools/lsp-tool.ts +0 -163
  36. package/src/tools/mcp-resource-tools.ts +0 -125
  37. package/src/tools/notebook-edit.ts +0 -93
  38. package/src/tools/plan-tools.ts +0 -88
  39. package/src/tools/read.ts +0 -73
  40. package/src/tools/send-message.ts +0 -96
  41. package/src/tools/skill-tool.ts +0 -133
  42. package/src/tools/task-tools.ts +0 -290
  43. package/src/tools/team-tools.ts +0 -128
  44. package/src/tools/todo-tool.ts +0 -112
  45. package/src/tools/tool-search.ts +0 -87
  46. package/src/tools/types.ts +0 -66
  47. package/src/tools/web-fetch.ts +0 -66
  48. package/src/tools/web-search.ts +0 -86
  49. package/src/tools/worktree-tools.ts +0 -140
  50. package/src/tools/write.ts +0 -42
  51. package/src/types.ts +0 -486
  52. package/src/utils/compact.ts +0 -207
  53. package/src/utils/context.ts +0 -191
  54. package/src/utils/fileCache.ts +0 -148
  55. package/src/utils/messages.ts +0 -195
  56. package/src/utils/retry.ts +0 -140
  57. package/src/utils/tokens.ts +0 -145
@@ -1,42 +0,0 @@
1
- /**
2
- * FileWriteTool - Write/create files
3
- */
4
-
5
- import { writeFile, mkdir } from 'fs/promises'
6
- import { resolve, dirname } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const FileWriteTool = defineTool({
10
- name: 'Write',
11
- description: 'Write content to a file. Creates the file if it does not exist, or overwrites if it does. Creates parent directories as needed.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- file_path: {
16
- type: 'string',
17
- description: 'The absolute path to the file to write',
18
- },
19
- content: {
20
- type: 'string',
21
- description: 'The content to write to the file',
22
- },
23
- },
24
- required: ['file_path', 'content'],
25
- },
26
- isReadOnly: false,
27
- isConcurrencySafe: false,
28
- async call(input, context) {
29
- const filePath = resolve(context.cwd, input.file_path)
30
-
31
- try {
32
- await mkdir(dirname(filePath), { recursive: true })
33
- await writeFile(filePath, input.content, 'utf-8')
34
-
35
- const lines = input.content.split('\n').length
36
- const bytes = Buffer.byteLength(input.content, 'utf-8')
37
- return `File written: ${filePath} (${lines} lines, ${bytes} bytes)`
38
- } catch (err: any) {
39
- return { data: `Error writing file: ${err.message}`, is_error: true }
40
- }
41
- },
42
- })
package/src/types.ts DELETED
@@ -1,486 +0,0 @@
1
- /**
2
- * Core type definitions for the Agent SDK
3
- */
4
-
5
- // Content block types (provider-agnostic, compatible with Anthropic format)
6
- export type ContentBlockParam =
7
- | { type: 'text'; text: string }
8
- | { type: 'image'; source: any }
9
- | { type: 'tool_use'; id: string; name: string; input: any }
10
- | { type: 'tool_result'; tool_use_id: string; content: string | any[]; is_error?: boolean }
11
-
12
- export type ContentBlock =
13
- | { type: 'text'; text: string }
14
- | { type: 'tool_use'; id: string; name: string; input: any }
15
- | { type: 'thinking'; thinking: string }
16
-
17
- // --------------------------------------------------------------------------
18
- // Message Types
19
- // --------------------------------------------------------------------------
20
-
21
- export type MessageRole = 'user' | 'assistant'
22
-
23
- export interface ConversationMessage {
24
- role: MessageRole
25
- content: string | ContentBlockParam[]
26
- }
27
-
28
- export interface UserMessage {
29
- type: 'user'
30
- message: ConversationMessage
31
- uuid: string
32
- timestamp: string
33
- }
34
-
35
- export interface AssistantMessage {
36
- type: 'assistant'
37
- message: {
38
- role: 'assistant'
39
- content: ContentBlock[]
40
- }
41
- uuid: string
42
- timestamp: string
43
- usage?: TokenUsage
44
- cost?: number
45
- }
46
-
47
- export type Message = UserMessage | AssistantMessage
48
-
49
- // --------------------------------------------------------------------------
50
- // SDK Message Types (streaming events)
51
- // --------------------------------------------------------------------------
52
-
53
- export type SDKMessage =
54
- | SDKAssistantMessage
55
- | SDKToolResultMessage
56
- | SDKResultMessage
57
- | SDKPartialMessage
58
- | SDKSystemMessage
59
- | SDKCompactBoundaryMessage
60
- | SDKStatusMessage
61
- | SDKTaskNotificationMessage
62
- | SDKRateLimitEvent
63
-
64
- export interface SDKAssistantMessage {
65
- type: 'assistant'
66
- uuid?: string
67
- session_id?: string
68
- message: {
69
- role: 'assistant'
70
- content: ContentBlock[]
71
- }
72
- parent_tool_use_id?: string | null
73
- }
74
-
75
- export interface SDKToolResultMessage {
76
- type: 'tool_result'
77
- result: {
78
- tool_use_id: string
79
- tool_name: string
80
- output: string
81
- }
82
- }
83
-
84
- export interface SDKResultMessage {
85
- type: 'result'
86
- subtype: 'success' | 'error_max_turns' | 'error_during_execution' | 'error_max_budget_usd' | string
87
- uuid?: string
88
- session_id?: string
89
- is_error?: boolean
90
- num_turns?: number
91
- result?: string
92
- stop_reason?: string | null
93
- total_cost_usd?: number
94
- duration_ms?: number
95
- duration_api_ms?: number
96
- usage?: TokenUsage
97
- model_usage?: Record<string, { input_tokens: number; output_tokens: number }>
98
- permission_denials?: Array<{ tool: string; reason: string }>
99
- structured_output?: unknown
100
- errors?: string[]
101
- /** @deprecated Use total_cost_usd */
102
- cost?: number
103
- }
104
-
105
- export interface SDKPartialMessage {
106
- type: 'partial_message'
107
- partial: {
108
- type: 'text' | 'tool_use'
109
- text?: string
110
- name?: string
111
- input?: string
112
- }
113
- }
114
-
115
- /** Emitted once at session start with initialization info. */
116
- export interface SDKSystemMessage {
117
- type: 'system'
118
- subtype: 'init'
119
- uuid?: string
120
- session_id: string
121
- tools: string[]
122
- model: string
123
- cwd: string
124
- mcp_servers: Array<{ name: string; status: string }>
125
- permission_mode: string
126
- }
127
-
128
- /** Marks a compaction boundary in the conversation. */
129
- export interface SDKCompactBoundaryMessage {
130
- type: 'system'
131
- subtype: 'compact_boundary'
132
- summary?: string
133
- }
134
-
135
- /** Status update during long operations. */
136
- export interface SDKStatusMessage {
137
- type: 'system'
138
- subtype: 'status'
139
- message: string
140
- }
141
-
142
- /** Task lifecycle notification. */
143
- export interface SDKTaskNotificationMessage {
144
- type: 'system'
145
- subtype: 'task_notification'
146
- task_id: string
147
- status: string
148
- message?: string
149
- }
150
-
151
- /** Rate limit event. */
152
- export interface SDKRateLimitEvent {
153
- type: 'system'
154
- subtype: 'rate_limit'
155
- retry_after_ms?: number
156
- message: string
157
- }
158
-
159
- // --------------------------------------------------------------------------
160
- // Token Usage
161
- // --------------------------------------------------------------------------
162
-
163
- export interface TokenUsage {
164
- input_tokens: number
165
- output_tokens: number
166
- cache_creation_input_tokens?: number
167
- cache_read_input_tokens?: number
168
- }
169
-
170
- // --------------------------------------------------------------------------
171
- // Tool Types
172
- // --------------------------------------------------------------------------
173
-
174
- export interface ToolDefinition {
175
- name: string
176
- description: string
177
- inputSchema: ToolInputSchema
178
- call: (input: any, context: ToolContext) => Promise<ToolResult>
179
- isReadOnly?: () => boolean
180
- isConcurrencySafe?: () => boolean
181
- isEnabled?: () => boolean
182
- prompt?: (context: ToolContext) => Promise<string>
183
- }
184
-
185
- export interface ToolInputSchema {
186
- type: 'object'
187
- properties: Record<string, any>
188
- required?: string[]
189
- }
190
-
191
- export interface ToolContext {
192
- cwd: string
193
- abortSignal?: AbortSignal
194
- /** Parent agent's LLM provider (inherited by subagents) */
195
- provider?: import('./providers/types.js').LLMProvider
196
- /** Parent agent's model ID */
197
- model?: string
198
- /** Parent agent's API type */
199
- apiType?: import('./providers/types.js').ApiType
200
- }
201
-
202
- export interface ToolResult {
203
- type: 'tool_result'
204
- tool_use_id: string
205
- content: string | any[]
206
- is_error?: boolean
207
- }
208
-
209
- // --------------------------------------------------------------------------
210
- // Permission Types
211
- // --------------------------------------------------------------------------
212
-
213
- export type PermissionMode =
214
- | 'default'
215
- | 'acceptEdits'
216
- | 'bypassPermissions'
217
- | 'plan'
218
- | 'dontAsk'
219
- | 'auto'
220
-
221
- export type PermissionBehavior = 'allow' | 'deny'
222
-
223
- export type CanUseToolResult = {
224
- behavior: PermissionBehavior
225
- updatedInput?: unknown
226
- message?: string
227
- }
228
-
229
- export type CanUseToolFn = (
230
- tool: ToolDefinition,
231
- input: unknown,
232
- ) => Promise<CanUseToolResult>
233
-
234
- // --------------------------------------------------------------------------
235
- // MCP Types
236
- // --------------------------------------------------------------------------
237
-
238
- export type McpServerConfig =
239
- | McpStdioConfig
240
- | McpSseConfig
241
- | McpHttpConfig
242
-
243
- export interface McpStdioConfig {
244
- type?: 'stdio'
245
- command: string
246
- args?: string[]
247
- env?: Record<string, string>
248
- }
249
-
250
- export interface McpSseConfig {
251
- type: 'sse'
252
- url: string
253
- headers?: Record<string, string>
254
- }
255
-
256
- export interface McpHttpConfig {
257
- type: 'http'
258
- url: string
259
- headers?: Record<string, string>
260
- }
261
-
262
- // --------------------------------------------------------------------------
263
- // Agent Types
264
- // --------------------------------------------------------------------------
265
-
266
- export interface AgentDefinition {
267
- description: string
268
- prompt: string
269
- tools?: string[]
270
- disallowedTools?: string[]
271
- model?: 'sonnet' | 'opus' | 'haiku' | 'inherit' | string
272
- mcpServers?: Array<string | { name: string; tools?: string[] }>
273
- skills?: string[]
274
- maxTurns?: number
275
- criticalSystemReminder_EXPERIMENTAL?: string
276
- }
277
-
278
- export interface ThinkingConfig {
279
- type: 'adaptive' | 'enabled' | 'disabled'
280
- budgetTokens?: number
281
- }
282
-
283
- // --------------------------------------------------------------------------
284
- // Sandbox Types
285
- // --------------------------------------------------------------------------
286
-
287
- export interface SandboxSettings {
288
- enabled?: boolean
289
- autoAllowBashIfSandboxed?: boolean
290
- excludedCommands?: string[]
291
- allowUnsandboxedCommands?: boolean
292
- network?: SandboxNetworkConfig
293
- filesystem?: SandboxFilesystemConfig
294
- ignoreViolations?: Record<string, string[]>
295
- enableWeakerNestedSandbox?: boolean
296
- ripgrep?: { command: string; args?: string[] }
297
- }
298
-
299
- export interface SandboxNetworkConfig {
300
- allowedDomains?: string[]
301
- allowManagedDomainsOnly?: boolean
302
- allowLocalBinding?: boolean
303
- allowUnixSockets?: string[]
304
- allowAllUnixSockets?: boolean
305
- httpProxyPort?: number
306
- socksProxyPort?: number
307
- }
308
-
309
- export interface SandboxFilesystemConfig {
310
- allowWrite?: string[]
311
- denyWrite?: string[]
312
- denyRead?: string[]
313
- }
314
-
315
- // --------------------------------------------------------------------------
316
- // Output Format
317
- // --------------------------------------------------------------------------
318
-
319
- export interface OutputFormat {
320
- type: 'json_schema'
321
- schema: Record<string, unknown>
322
- }
323
-
324
- // --------------------------------------------------------------------------
325
- // Setting Sources
326
- // --------------------------------------------------------------------------
327
-
328
- export type SettingSource = 'user' | 'project' | 'local'
329
-
330
- // --------------------------------------------------------------------------
331
- // Model Info
332
- // --------------------------------------------------------------------------
333
-
334
- export interface ModelInfo {
335
- value: string
336
- displayName: string
337
- description: string
338
- supportsEffort?: boolean
339
- supportedEffortLevels?: ('low' | 'medium' | 'high' | 'max')[]
340
- supportsAdaptiveThinking?: boolean
341
- supportsFastMode?: boolean
342
- }
343
-
344
- export interface AgentOptions {
345
- /** LLM model ID */
346
- model?: string
347
- /**
348
- * API type: 'anthropic-messages' or 'openai-completions'.
349
- * Falls back to CODEANY_API_TYPE env var. Default: 'anthropic-messages'.
350
- */
351
- apiType?: import('./providers/types.js').ApiType
352
- /** API key. Falls back to CODEANY_API_KEY env var. */
353
- apiKey?: string
354
- /** API base URL override */
355
- baseURL?: string
356
- /** Working directory for file/shell tools */
357
- cwd?: string
358
- /** System prompt override or preset */
359
- systemPrompt?: string | { type: 'preset'; preset: 'default'; append?: string }
360
- /** Append to default system prompt */
361
- appendSystemPrompt?: string
362
- /** Available tools (ToolDefinition[] or string[] preset) */
363
- tools?: ToolDefinition[] | string[] | { type: 'preset'; preset: 'default' }
364
- /** Maximum number of agentic turns per query */
365
- maxTurns?: number
366
- /** Maximum USD budget per query */
367
- maxBudgetUsd?: number
368
- /** Extended thinking configuration */
369
- thinking?: ThinkingConfig
370
- /** Maximum thinking tokens (deprecated, use thinking.budgetTokens) */
371
- maxThinkingTokens?: number
372
- /** Structured output JSON schema */
373
- jsonSchema?: Record<string, unknown>
374
- /** Structured output format */
375
- outputFormat?: OutputFormat
376
- /** Permission handler callback */
377
- canUseTool?: CanUseToolFn
378
- /** Permission mode controlling tool approval behavior */
379
- permissionMode?: PermissionMode
380
- /** Abort controller for cancellation */
381
- abortController?: AbortController
382
- /** Abort signal for cancellation */
383
- abortSignal?: AbortSignal
384
- /** Whether to include partial streaming events */
385
- includePartialMessages?: boolean
386
- /** Environment variables */
387
- env?: Record<string, string | undefined>
388
- /** Tool names to pre-approve without prompting */
389
- allowedTools?: string[]
390
- /** Tool names to deny */
391
- disallowedTools?: string[]
392
- /** MCP server configurations */
393
- mcpServers?: Record<string, McpServerConfig | any> // supports McpSdkServerConfig
394
- /** Custom subagent definitions */
395
- agents?: Record<string, AgentDefinition>
396
- /** Maximum tokens for responses */
397
- maxTokens?: number
398
- /** Effort level for reasoning */
399
- effort?: 'low' | 'medium' | 'high' | 'max'
400
- /** Fallback model if primary is unavailable */
401
- fallbackModel?: string
402
- /** Continue the most recent session in cwd */
403
- continue?: boolean
404
- /** Resume a specific session by ID */
405
- resume?: string
406
- /** Fork a session instead of continuing it */
407
- forkSession?: boolean
408
- /** Persist session to disk */
409
- persistSession?: boolean
410
- /** Explicit session ID */
411
- sessionId?: string
412
- /** Enable file checkpointing (for rewindFiles) */
413
- enableFileCheckpointing?: boolean
414
- /** Sandbox configuration */
415
- sandbox?: SandboxSettings
416
- /** Load settings from filesystem */
417
- settingSources?: SettingSource[]
418
- /** Plugin configurations */
419
- plugins?: Array<{ name: string; config?: Record<string, unknown> }>
420
- /** Additional working directories */
421
- additionalDirectories?: string[]
422
- /** Default agent to use */
423
- agent?: string
424
- /** Debug mode */
425
- debug?: boolean
426
- /** Debug log file */
427
- debugFile?: string
428
- /** Tool-specific configuration */
429
- toolConfig?: Record<string, unknown>
430
- /** Enable prompt suggestions */
431
- promptSuggestions?: boolean
432
- /** Strict MCP config validation */
433
- strictMcpConfig?: boolean
434
- /** Extra CLI arguments */
435
- extraArgs?: Record<string, string | null>
436
- /** SDK betas to enable */
437
- betas?: string[]
438
- /** Permission prompt tool name override */
439
- permissionPromptToolName?: string
440
- /** Hook configurations */
441
- hooks?: Record<string, Array<{
442
- matcher?: string
443
- hooks: Array<(input: any, toolUseId: string, context: { signal: AbortSignal }) => Promise<any>>
444
- timeout?: number
445
- }>>
446
- }
447
-
448
- export interface QueryResult {
449
- /** Final text output from the assistant */
450
- text: string
451
- /** Token usage */
452
- usage: TokenUsage
453
- /** Number of agentic turns */
454
- num_turns: number
455
- /** Duration in milliseconds */
456
- duration_ms: number
457
- /** All conversation messages */
458
- messages: Message[]
459
- }
460
-
461
- // --------------------------------------------------------------------------
462
- // Query Engine Types
463
- // --------------------------------------------------------------------------
464
-
465
- export interface QueryEngineConfig {
466
- cwd: string
467
- model: string
468
- /** LLM provider instance (created from apiType) */
469
- provider: import('./providers/types.js').LLMProvider
470
- tools: ToolDefinition[]
471
- systemPrompt?: string
472
- appendSystemPrompt?: string
473
- maxTurns: number
474
- maxBudgetUsd?: number
475
- maxTokens: number
476
- thinking?: ThinkingConfig
477
- jsonSchema?: Record<string, unknown>
478
- canUseTool: CanUseToolFn
479
- includePartialMessages: boolean
480
- abortSignal?: AbortSignal
481
- agents?: Record<string, AgentDefinition>
482
- /** Hook registry for lifecycle events */
483
- hookRegistry?: import('./hooks.js').HookRegistry
484
- /** Session ID for hook context */
485
- sessionId?: string
486
- }