@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.
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +2 -0
- package/dist/engine.js.map +1 -1
- package/package.json +5 -6
- package/src/agent.ts +0 -516
- package/src/engine.ts +0 -630
- package/src/hooks.ts +0 -261
- package/src/index.ts +0 -426
- package/src/mcp/client.ts +0 -150
- package/src/providers/anthropic.ts +0 -60
- package/src/providers/index.ts +0 -34
- package/src/providers/openai.ts +0 -315
- package/src/providers/types.ts +0 -85
- package/src/sdk-mcp-server.ts +0 -78
- package/src/session.ts +0 -227
- package/src/skills/bundled/commit.ts +0 -38
- package/src/skills/bundled/debug.ts +0 -48
- package/src/skills/bundled/index.ts +0 -28
- package/src/skills/bundled/review.ts +0 -41
- package/src/skills/bundled/simplify.ts +0 -51
- package/src/skills/bundled/test.ts +0 -43
- package/src/skills/index.ts +0 -25
- package/src/skills/registry.ts +0 -133
- package/src/skills/types.ts +0 -99
- package/src/tool-helper.ts +0 -127
- package/src/tools/agent-tool.ts +0 -164
- package/src/tools/ask-user.ts +0 -79
- package/src/tools/bash.ts +0 -75
- package/src/tools/config-tool.ts +0 -89
- package/src/tools/cron-tools.ts +0 -153
- package/src/tools/edit.ts +0 -74
- package/src/tools/glob.ts +0 -77
- package/src/tools/grep.ts +0 -168
- package/src/tools/index.ts +0 -240
- package/src/tools/lsp-tool.ts +0 -163
- package/src/tools/mcp-resource-tools.ts +0 -125
- package/src/tools/notebook-edit.ts +0 -93
- package/src/tools/plan-tools.ts +0 -88
- package/src/tools/read.ts +0 -73
- package/src/tools/send-message.ts +0 -96
- package/src/tools/skill-tool.ts +0 -133
- package/src/tools/task-tools.ts +0 -290
- package/src/tools/team-tools.ts +0 -128
- package/src/tools/todo-tool.ts +0 -112
- package/src/tools/tool-search.ts +0 -87
- package/src/tools/types.ts +0 -66
- package/src/tools/web-fetch.ts +0 -66
- package/src/tools/web-search.ts +0 -86
- package/src/tools/worktree-tools.ts +0 -140
- package/src/tools/write.ts +0 -42
- package/src/types.ts +0 -486
- package/src/utils/compact.ts +0 -207
- package/src/utils/context.ts +0 -191
- package/src/utils/fileCache.ts +0 -148
- package/src/utils/messages.ts +0 -195
- package/src/utils/retry.ts +0 -140
- package/src/utils/tokens.ts +0 -145
package/src/hooks.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook System
|
|
3
|
-
*
|
|
4
|
-
* Lifecycle hooks for intercepting agent behavior.
|
|
5
|
-
* Supports pre/post tool use, session lifecycle, and custom events.
|
|
6
|
-
*
|
|
7
|
-
* Hook events:
|
|
8
|
-
* - PreToolUse: before tool execution
|
|
9
|
-
* - PostToolUse: after tool execution
|
|
10
|
-
* - PostToolUseFailure: after tool failure
|
|
11
|
-
* - SessionStart: session initialization
|
|
12
|
-
* - SessionEnd: session cleanup
|
|
13
|
-
* - Stop: when turn completes
|
|
14
|
-
* - SubagentStart: subagent spawned
|
|
15
|
-
* - SubagentStop: subagent completed
|
|
16
|
-
* - UserPromptSubmit: user sends message
|
|
17
|
-
* - PermissionRequest: permission check triggered
|
|
18
|
-
* - TaskCreated: task created
|
|
19
|
-
* - TaskCompleted: task finished
|
|
20
|
-
* - ConfigChange: settings changed
|
|
21
|
-
* - CwdChanged: working directory changed
|
|
22
|
-
* - FileChanged: file modified
|
|
23
|
-
* - Notification: system notification
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import { spawn, type ChildProcess } from 'child_process'
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* All supported hook events.
|
|
30
|
-
*/
|
|
31
|
-
export const HOOK_EVENTS = [
|
|
32
|
-
'PreToolUse',
|
|
33
|
-
'PostToolUse',
|
|
34
|
-
'PostToolUseFailure',
|
|
35
|
-
'SessionStart',
|
|
36
|
-
'SessionEnd',
|
|
37
|
-
'Stop',
|
|
38
|
-
'SubagentStart',
|
|
39
|
-
'SubagentStop',
|
|
40
|
-
'UserPromptSubmit',
|
|
41
|
-
'PermissionRequest',
|
|
42
|
-
'PermissionDenied',
|
|
43
|
-
'TaskCreated',
|
|
44
|
-
'TaskCompleted',
|
|
45
|
-
'ConfigChange',
|
|
46
|
-
'CwdChanged',
|
|
47
|
-
'FileChanged',
|
|
48
|
-
'Notification',
|
|
49
|
-
'PreCompact',
|
|
50
|
-
'PostCompact',
|
|
51
|
-
'TeammateIdle',
|
|
52
|
-
] as const
|
|
53
|
-
|
|
54
|
-
export type HookEvent = typeof HOOK_EVENTS[number]
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Hook definition.
|
|
58
|
-
*/
|
|
59
|
-
export interface HookDefinition {
|
|
60
|
-
/** Shell command or function to execute */
|
|
61
|
-
command?: string
|
|
62
|
-
/** Function handler */
|
|
63
|
-
handler?: (input: HookInput) => Promise<HookOutput | void>
|
|
64
|
-
/** Tool name matcher (regex pattern) */
|
|
65
|
-
matcher?: string
|
|
66
|
-
/** Timeout in milliseconds */
|
|
67
|
-
timeout?: number
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Hook input passed to handlers.
|
|
72
|
-
*/
|
|
73
|
-
export interface HookInput {
|
|
74
|
-
event: HookEvent
|
|
75
|
-
toolName?: string
|
|
76
|
-
toolInput?: unknown
|
|
77
|
-
toolOutput?: unknown
|
|
78
|
-
toolUseId?: string
|
|
79
|
-
sessionId?: string
|
|
80
|
-
cwd?: string
|
|
81
|
-
error?: string
|
|
82
|
-
[key: string]: unknown
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Hook output returned by handlers.
|
|
87
|
-
*/
|
|
88
|
-
export interface HookOutput {
|
|
89
|
-
/** Message to append to conversation */
|
|
90
|
-
message?: string
|
|
91
|
-
/** Permission update */
|
|
92
|
-
permissionUpdate?: {
|
|
93
|
-
tool: string
|
|
94
|
-
behavior: 'allow' | 'deny'
|
|
95
|
-
}
|
|
96
|
-
/** Whether to block the action */
|
|
97
|
-
block?: boolean
|
|
98
|
-
/** Notification */
|
|
99
|
-
notification?: {
|
|
100
|
-
title: string
|
|
101
|
-
body: string
|
|
102
|
-
level?: 'info' | 'warning' | 'error'
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Hook configuration (from settings).
|
|
108
|
-
*/
|
|
109
|
-
export type HookConfig = Record<string, HookDefinition[]>
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Hook registry for managing and executing hooks.
|
|
113
|
-
*/
|
|
114
|
-
export class HookRegistry {
|
|
115
|
-
private hooks: Map<HookEvent, HookDefinition[]> = new Map()
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Register hooks from configuration.
|
|
119
|
-
*/
|
|
120
|
-
registerFromConfig(config: HookConfig): void {
|
|
121
|
-
for (const [event, definitions] of Object.entries(config)) {
|
|
122
|
-
const hookEvent = event as HookEvent
|
|
123
|
-
if (!HOOK_EVENTS.includes(hookEvent)) continue
|
|
124
|
-
|
|
125
|
-
const existing = this.hooks.get(hookEvent) || []
|
|
126
|
-
this.hooks.set(hookEvent, [...existing, ...definitions])
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Register a single hook.
|
|
132
|
-
*/
|
|
133
|
-
register(event: HookEvent, definition: HookDefinition): void {
|
|
134
|
-
const existing = this.hooks.get(event) || []
|
|
135
|
-
existing.push(definition)
|
|
136
|
-
this.hooks.set(event, existing)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Execute hooks for an event.
|
|
141
|
-
*/
|
|
142
|
-
async execute(
|
|
143
|
-
event: HookEvent,
|
|
144
|
-
input: HookInput,
|
|
145
|
-
): Promise<HookOutput[]> {
|
|
146
|
-
const definitions = this.hooks.get(event) || []
|
|
147
|
-
const results: HookOutput[] = []
|
|
148
|
-
|
|
149
|
-
for (const def of definitions) {
|
|
150
|
-
// Check matcher for tool-specific hooks
|
|
151
|
-
if (def.matcher && input.toolName) {
|
|
152
|
-
const regex = new RegExp(def.matcher)
|
|
153
|
-
if (!regex.test(input.toolName)) continue
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
let output: HookOutput | void = undefined
|
|
158
|
-
|
|
159
|
-
if (def.handler) {
|
|
160
|
-
// Function handler
|
|
161
|
-
output = await Promise.race([
|
|
162
|
-
def.handler(input),
|
|
163
|
-
new Promise<void>((_, reject) =>
|
|
164
|
-
setTimeout(() => reject(new Error('Hook timeout')), def.timeout || 30000),
|
|
165
|
-
),
|
|
166
|
-
])
|
|
167
|
-
} else if (def.command) {
|
|
168
|
-
// Shell command handler
|
|
169
|
-
output = await executeShellHook(def.command, input, def.timeout || 30000)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (output) {
|
|
173
|
-
results.push(output)
|
|
174
|
-
}
|
|
175
|
-
} catch (err: any) {
|
|
176
|
-
// Log but don't fail on hook errors
|
|
177
|
-
console.error(`[Hook] ${event} hook failed: ${err.message}`)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return results
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Check if any hooks are registered for an event.
|
|
186
|
-
*/
|
|
187
|
-
hasHooks(event: HookEvent): boolean {
|
|
188
|
-
return (this.hooks.get(event)?.length || 0) > 0
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Clear all hooks.
|
|
193
|
-
*/
|
|
194
|
-
clear(): void {
|
|
195
|
-
this.hooks.clear()
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Execute a shell command as a hook.
|
|
201
|
-
*/
|
|
202
|
-
async function executeShellHook(
|
|
203
|
-
command: string,
|
|
204
|
-
input: HookInput,
|
|
205
|
-
timeout: number,
|
|
206
|
-
): Promise<HookOutput | void> {
|
|
207
|
-
return new Promise((resolve) => {
|
|
208
|
-
const proc = spawn('bash', ['-c', command], {
|
|
209
|
-
timeout,
|
|
210
|
-
env: {
|
|
211
|
-
...process.env,
|
|
212
|
-
HOOK_EVENT: input.event,
|
|
213
|
-
HOOK_TOOL_NAME: input.toolName || '',
|
|
214
|
-
HOOK_SESSION_ID: input.sessionId || '',
|
|
215
|
-
HOOK_CWD: input.cwd || '',
|
|
216
|
-
},
|
|
217
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
// Send input as JSON on stdin
|
|
221
|
-
proc.stdin?.write(JSON.stringify(input))
|
|
222
|
-
proc.stdin?.end()
|
|
223
|
-
|
|
224
|
-
const chunks: Buffer[] = []
|
|
225
|
-
proc.stdout?.on('data', (d: Buffer) => chunks.push(d))
|
|
226
|
-
|
|
227
|
-
proc.on('close', (code) => {
|
|
228
|
-
if (code !== 0) {
|
|
229
|
-
resolve(undefined)
|
|
230
|
-
return
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const stdout = Buffer.concat(chunks).toString('utf-8').trim()
|
|
234
|
-
if (!stdout) {
|
|
235
|
-
resolve(undefined)
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
const output = JSON.parse(stdout) as HookOutput
|
|
241
|
-
resolve(output)
|
|
242
|
-
} catch {
|
|
243
|
-
// Non-JSON output treated as message
|
|
244
|
-
resolve({ message: stdout })
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
proc.on('error', () => resolve(undefined))
|
|
249
|
-
})
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Create a default hook registry.
|
|
254
|
-
*/
|
|
255
|
-
export function createHookRegistry(config?: HookConfig): HookRegistry {
|
|
256
|
-
const registry = new HookRegistry()
|
|
257
|
-
if (config) {
|
|
258
|
-
registry.registerFromConfig(config)
|
|
259
|
-
}
|
|
260
|
-
return registry
|
|
261
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @codeany/open-agent-sdk
|
|
3
|
-
*
|
|
4
|
-
* Open-source Agent SDK by CodeAny (https://codeany.ai).
|
|
5
|
-
* Runs the full agent loop in-process without spawning subprocesses.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - 30+ built-in tools (file I/O, shell, web, agents, tasks, teams, etc.)
|
|
9
|
-
* - Skill system (reusable prompt templates with bundled skills)
|
|
10
|
-
* - MCP server integration (stdio, SSE, HTTP)
|
|
11
|
-
* - Context compression (auto-compact, micro-compact)
|
|
12
|
-
* - Retry with exponential backoff
|
|
13
|
-
* - Git status & project context injection
|
|
14
|
-
* - Multi-turn session persistence
|
|
15
|
-
* - Permission system (allow/deny/bypass modes)
|
|
16
|
-
* - Subagent spawning & team coordination
|
|
17
|
-
* - Task management & scheduling
|
|
18
|
-
* - Hook system with lifecycle integration (pre/post tool use, session, compact)
|
|
19
|
-
* - Token estimation & cost tracking
|
|
20
|
-
* - File state LRU caching
|
|
21
|
-
* - Plan mode for structured workflows
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
// --------------------------------------------------------------------------
|
|
25
|
-
// High-level Agent API
|
|
26
|
-
// --------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
export { Agent, createAgent, query } from './agent.js'
|
|
29
|
-
|
|
30
|
-
// --------------------------------------------------------------------------
|
|
31
|
-
// Tool Helper (Zod-based tool creation, compatible with official SDK)
|
|
32
|
-
// --------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
export { tool, sdkToolToToolDefinition } from './tool-helper.js'
|
|
35
|
-
export type {
|
|
36
|
-
ToolAnnotations,
|
|
37
|
-
CallToolResult,
|
|
38
|
-
SdkMcpToolDefinition,
|
|
39
|
-
} from './tool-helper.js'
|
|
40
|
-
|
|
41
|
-
// --------------------------------------------------------------------------
|
|
42
|
-
// In-Process MCP Server
|
|
43
|
-
// --------------------------------------------------------------------------
|
|
44
|
-
|
|
45
|
-
export { createSdkMcpServer, isSdkServerConfig } from './sdk-mcp-server.js'
|
|
46
|
-
export type { McpSdkServerConfig } from './sdk-mcp-server.js'
|
|
47
|
-
|
|
48
|
-
// --------------------------------------------------------------------------
|
|
49
|
-
// Core Engine
|
|
50
|
-
// --------------------------------------------------------------------------
|
|
51
|
-
|
|
52
|
-
export { QueryEngine } from './engine.js'
|
|
53
|
-
|
|
54
|
-
// --------------------------------------------------------------------------
|
|
55
|
-
// LLM Providers (Anthropic + OpenAI)
|
|
56
|
-
// --------------------------------------------------------------------------
|
|
57
|
-
|
|
58
|
-
export {
|
|
59
|
-
createProvider,
|
|
60
|
-
AnthropicProvider,
|
|
61
|
-
OpenAIProvider,
|
|
62
|
-
} from './providers/index.js'
|
|
63
|
-
export type {
|
|
64
|
-
ApiType,
|
|
65
|
-
LLMProvider,
|
|
66
|
-
CreateMessageParams,
|
|
67
|
-
CreateMessageResponse,
|
|
68
|
-
NormalizedMessageParam,
|
|
69
|
-
NormalizedContentBlock,
|
|
70
|
-
NormalizedTool,
|
|
71
|
-
NormalizedResponseBlock,
|
|
72
|
-
} from './providers/index.js'
|
|
73
|
-
|
|
74
|
-
// --------------------------------------------------------------------------
|
|
75
|
-
// Tool System (30+ tools)
|
|
76
|
-
// --------------------------------------------------------------------------
|
|
77
|
-
|
|
78
|
-
export {
|
|
79
|
-
// Registry
|
|
80
|
-
getAllBaseTools,
|
|
81
|
-
filterTools,
|
|
82
|
-
assembleToolPool,
|
|
83
|
-
|
|
84
|
-
// Helpers
|
|
85
|
-
defineTool,
|
|
86
|
-
toApiTool,
|
|
87
|
-
|
|
88
|
-
// Core file I/O & execution
|
|
89
|
-
BashTool,
|
|
90
|
-
FileReadTool,
|
|
91
|
-
FileWriteTool,
|
|
92
|
-
FileEditTool,
|
|
93
|
-
GlobTool,
|
|
94
|
-
GrepTool,
|
|
95
|
-
NotebookEditTool,
|
|
96
|
-
|
|
97
|
-
// Web
|
|
98
|
-
WebFetchTool,
|
|
99
|
-
WebSearchTool,
|
|
100
|
-
|
|
101
|
-
// Agent & Multi-agent
|
|
102
|
-
AgentTool,
|
|
103
|
-
SendMessageTool,
|
|
104
|
-
TeamCreateTool,
|
|
105
|
-
TeamDeleteTool,
|
|
106
|
-
|
|
107
|
-
// Tasks
|
|
108
|
-
TaskCreateTool,
|
|
109
|
-
TaskListTool,
|
|
110
|
-
TaskUpdateTool,
|
|
111
|
-
TaskGetTool,
|
|
112
|
-
TaskStopTool,
|
|
113
|
-
TaskOutputTool,
|
|
114
|
-
|
|
115
|
-
// Worktree
|
|
116
|
-
EnterWorktreeTool,
|
|
117
|
-
ExitWorktreeTool,
|
|
118
|
-
|
|
119
|
-
// Planning
|
|
120
|
-
EnterPlanModeTool,
|
|
121
|
-
ExitPlanModeTool,
|
|
122
|
-
|
|
123
|
-
// User interaction
|
|
124
|
-
AskUserQuestionTool,
|
|
125
|
-
|
|
126
|
-
// Discovery
|
|
127
|
-
ToolSearchTool,
|
|
128
|
-
|
|
129
|
-
// MCP Resources
|
|
130
|
-
ListMcpResourcesTool,
|
|
131
|
-
ReadMcpResourceTool,
|
|
132
|
-
|
|
133
|
-
// Scheduling
|
|
134
|
-
CronCreateTool,
|
|
135
|
-
CronDeleteTool,
|
|
136
|
-
CronListTool,
|
|
137
|
-
RemoteTriggerTool,
|
|
138
|
-
|
|
139
|
-
// LSP
|
|
140
|
-
LSPTool,
|
|
141
|
-
|
|
142
|
-
// Config
|
|
143
|
-
ConfigTool,
|
|
144
|
-
|
|
145
|
-
// Todo
|
|
146
|
-
TodoWriteTool,
|
|
147
|
-
|
|
148
|
-
// Skill
|
|
149
|
-
SkillTool,
|
|
150
|
-
} from './tools/index.js'
|
|
151
|
-
|
|
152
|
-
// --------------------------------------------------------------------------
|
|
153
|
-
// MCP Client
|
|
154
|
-
// --------------------------------------------------------------------------
|
|
155
|
-
|
|
156
|
-
export { connectMCPServer, closeAllConnections } from './mcp/client.js'
|
|
157
|
-
export type { MCPConnection } from './mcp/client.js'
|
|
158
|
-
|
|
159
|
-
// --------------------------------------------------------------------------
|
|
160
|
-
// Skill System
|
|
161
|
-
// --------------------------------------------------------------------------
|
|
162
|
-
|
|
163
|
-
export {
|
|
164
|
-
registerSkill,
|
|
165
|
-
getSkill,
|
|
166
|
-
getAllSkills,
|
|
167
|
-
getUserInvocableSkills,
|
|
168
|
-
hasSkill,
|
|
169
|
-
unregisterSkill,
|
|
170
|
-
clearSkills,
|
|
171
|
-
formatSkillsForPrompt,
|
|
172
|
-
initBundledSkills,
|
|
173
|
-
} from './skills/index.js'
|
|
174
|
-
export type {
|
|
175
|
-
SkillDefinition,
|
|
176
|
-
SkillContentBlock,
|
|
177
|
-
SkillResult,
|
|
178
|
-
} from './skills/index.js'
|
|
179
|
-
|
|
180
|
-
// --------------------------------------------------------------------------
|
|
181
|
-
// Hook System
|
|
182
|
-
// --------------------------------------------------------------------------
|
|
183
|
-
|
|
184
|
-
export {
|
|
185
|
-
HookRegistry,
|
|
186
|
-
createHookRegistry,
|
|
187
|
-
HOOK_EVENTS,
|
|
188
|
-
} from './hooks.js'
|
|
189
|
-
export type {
|
|
190
|
-
HookEvent,
|
|
191
|
-
HookDefinition,
|
|
192
|
-
HookInput,
|
|
193
|
-
HookOutput,
|
|
194
|
-
HookConfig,
|
|
195
|
-
} from './hooks.js'
|
|
196
|
-
|
|
197
|
-
// --------------------------------------------------------------------------
|
|
198
|
-
// Session Management
|
|
199
|
-
// --------------------------------------------------------------------------
|
|
200
|
-
|
|
201
|
-
export {
|
|
202
|
-
saveSession,
|
|
203
|
-
loadSession,
|
|
204
|
-
listSessions,
|
|
205
|
-
forkSession,
|
|
206
|
-
getSessionMessages,
|
|
207
|
-
getSessionInfo,
|
|
208
|
-
renameSession,
|
|
209
|
-
tagSession,
|
|
210
|
-
appendToSession,
|
|
211
|
-
deleteSession,
|
|
212
|
-
} from './session.js'
|
|
213
|
-
export type { SessionMetadata, SessionData } from './session.js'
|
|
214
|
-
|
|
215
|
-
// --------------------------------------------------------------------------
|
|
216
|
-
// Context Utilities
|
|
217
|
-
// --------------------------------------------------------------------------
|
|
218
|
-
|
|
219
|
-
export {
|
|
220
|
-
getSystemContext,
|
|
221
|
-
getUserContext,
|
|
222
|
-
getGitStatus,
|
|
223
|
-
readProjectContextContent,
|
|
224
|
-
discoverProjectContextFiles,
|
|
225
|
-
clearContextCache,
|
|
226
|
-
} from './utils/context.js'
|
|
227
|
-
|
|
228
|
-
// --------------------------------------------------------------------------
|
|
229
|
-
// Message Utilities
|
|
230
|
-
// --------------------------------------------------------------------------
|
|
231
|
-
|
|
232
|
-
export {
|
|
233
|
-
createUserMessage,
|
|
234
|
-
createAssistantMessage,
|
|
235
|
-
normalizeMessagesForAPI,
|
|
236
|
-
stripImagesFromMessages,
|
|
237
|
-
extractTextFromContent,
|
|
238
|
-
createCompactBoundaryMessage,
|
|
239
|
-
truncateText,
|
|
240
|
-
} from './utils/messages.js'
|
|
241
|
-
|
|
242
|
-
// --------------------------------------------------------------------------
|
|
243
|
-
// Token Estimation & Cost
|
|
244
|
-
// --------------------------------------------------------------------------
|
|
245
|
-
|
|
246
|
-
export {
|
|
247
|
-
estimateTokens,
|
|
248
|
-
estimateMessagesTokens,
|
|
249
|
-
estimateSystemPromptTokens,
|
|
250
|
-
getTokenCountFromUsage,
|
|
251
|
-
getContextWindowSize,
|
|
252
|
-
getAutoCompactThreshold,
|
|
253
|
-
estimateCost,
|
|
254
|
-
MODEL_PRICING,
|
|
255
|
-
AUTOCOMPACT_BUFFER_TOKENS,
|
|
256
|
-
} from './utils/tokens.js'
|
|
257
|
-
|
|
258
|
-
// --------------------------------------------------------------------------
|
|
259
|
-
// Context Compression
|
|
260
|
-
// --------------------------------------------------------------------------
|
|
261
|
-
|
|
262
|
-
export {
|
|
263
|
-
shouldAutoCompact,
|
|
264
|
-
compactConversation,
|
|
265
|
-
microCompactMessages,
|
|
266
|
-
createAutoCompactState,
|
|
267
|
-
} from './utils/compact.js'
|
|
268
|
-
export type { AutoCompactState } from './utils/compact.js'
|
|
269
|
-
|
|
270
|
-
// --------------------------------------------------------------------------
|
|
271
|
-
// Retry Logic
|
|
272
|
-
// --------------------------------------------------------------------------
|
|
273
|
-
|
|
274
|
-
export {
|
|
275
|
-
withRetry,
|
|
276
|
-
isRetryableError,
|
|
277
|
-
isPromptTooLongError,
|
|
278
|
-
isAuthError,
|
|
279
|
-
isRateLimitError,
|
|
280
|
-
formatApiError,
|
|
281
|
-
getRetryDelay,
|
|
282
|
-
DEFAULT_RETRY_CONFIG,
|
|
283
|
-
} from './utils/retry.js'
|
|
284
|
-
export type { RetryConfig } from './utils/retry.js'
|
|
285
|
-
|
|
286
|
-
// --------------------------------------------------------------------------
|
|
287
|
-
// File State Cache
|
|
288
|
-
// --------------------------------------------------------------------------
|
|
289
|
-
|
|
290
|
-
export {
|
|
291
|
-
FileStateCache,
|
|
292
|
-
createFileStateCache,
|
|
293
|
-
} from './utils/fileCache.js'
|
|
294
|
-
export type { FileState } from './utils/fileCache.js'
|
|
295
|
-
|
|
296
|
-
// --------------------------------------------------------------------------
|
|
297
|
-
// Task & Team State (for advanced usage)
|
|
298
|
-
// --------------------------------------------------------------------------
|
|
299
|
-
|
|
300
|
-
export {
|
|
301
|
-
getAllTasks,
|
|
302
|
-
getTask,
|
|
303
|
-
clearTasks,
|
|
304
|
-
} from './tools/task-tools.js'
|
|
305
|
-
export type { Task, TaskStatus } from './tools/task-tools.js'
|
|
306
|
-
|
|
307
|
-
export {
|
|
308
|
-
getAllTeams,
|
|
309
|
-
getTeam,
|
|
310
|
-
clearTeams,
|
|
311
|
-
} from './tools/team-tools.js'
|
|
312
|
-
export type { Team } from './tools/team-tools.js'
|
|
313
|
-
|
|
314
|
-
export {
|
|
315
|
-
readMailbox,
|
|
316
|
-
writeToMailbox,
|
|
317
|
-
clearMailboxes,
|
|
318
|
-
} from './tools/send-message.js'
|
|
319
|
-
export type { AgentMessage } from './tools/send-message.js'
|
|
320
|
-
|
|
321
|
-
export {
|
|
322
|
-
isPlanModeActive,
|
|
323
|
-
getCurrentPlan,
|
|
324
|
-
} from './tools/plan-tools.js'
|
|
325
|
-
|
|
326
|
-
export {
|
|
327
|
-
registerAgents,
|
|
328
|
-
clearAgents,
|
|
329
|
-
} from './tools/agent-tool.js'
|
|
330
|
-
|
|
331
|
-
export {
|
|
332
|
-
setQuestionHandler,
|
|
333
|
-
clearQuestionHandler,
|
|
334
|
-
} from './tools/ask-user.js'
|
|
335
|
-
|
|
336
|
-
export {
|
|
337
|
-
setDeferredTools,
|
|
338
|
-
} from './tools/tool-search.js'
|
|
339
|
-
|
|
340
|
-
export {
|
|
341
|
-
setMcpConnections,
|
|
342
|
-
} from './tools/mcp-resource-tools.js'
|
|
343
|
-
|
|
344
|
-
export {
|
|
345
|
-
getAllCronJobs,
|
|
346
|
-
clearCronJobs,
|
|
347
|
-
} from './tools/cron-tools.js'
|
|
348
|
-
export type { CronJob } from './tools/cron-tools.js'
|
|
349
|
-
|
|
350
|
-
export {
|
|
351
|
-
getConfig,
|
|
352
|
-
setConfig,
|
|
353
|
-
clearConfig,
|
|
354
|
-
} from './tools/config-tool.js'
|
|
355
|
-
|
|
356
|
-
export {
|
|
357
|
-
getTodos,
|
|
358
|
-
clearTodos,
|
|
359
|
-
} from './tools/todo-tool.js'
|
|
360
|
-
export type { TodoItem } from './tools/todo-tool.js'
|
|
361
|
-
|
|
362
|
-
// --------------------------------------------------------------------------
|
|
363
|
-
// Types
|
|
364
|
-
// --------------------------------------------------------------------------
|
|
365
|
-
|
|
366
|
-
export type {
|
|
367
|
-
// Message types
|
|
368
|
-
Message,
|
|
369
|
-
UserMessage,
|
|
370
|
-
AssistantMessage,
|
|
371
|
-
ConversationMessage,
|
|
372
|
-
MessageRole,
|
|
373
|
-
|
|
374
|
-
// SDK message types (streaming events)
|
|
375
|
-
SDKMessage,
|
|
376
|
-
SDKAssistantMessage,
|
|
377
|
-
SDKToolResultMessage,
|
|
378
|
-
SDKResultMessage,
|
|
379
|
-
SDKPartialMessage,
|
|
380
|
-
|
|
381
|
-
// Tool types
|
|
382
|
-
ToolDefinition,
|
|
383
|
-
ToolInputSchema,
|
|
384
|
-
ToolContext,
|
|
385
|
-
ToolResult,
|
|
386
|
-
|
|
387
|
-
// Permission types
|
|
388
|
-
PermissionMode,
|
|
389
|
-
PermissionBehavior,
|
|
390
|
-
CanUseToolFn,
|
|
391
|
-
CanUseToolResult,
|
|
392
|
-
|
|
393
|
-
// MCP types
|
|
394
|
-
McpServerConfig,
|
|
395
|
-
McpStdioConfig,
|
|
396
|
-
McpSseConfig,
|
|
397
|
-
McpHttpConfig,
|
|
398
|
-
|
|
399
|
-
// Agent types
|
|
400
|
-
AgentOptions,
|
|
401
|
-
AgentDefinition,
|
|
402
|
-
QueryResult,
|
|
403
|
-
ThinkingConfig,
|
|
404
|
-
TokenUsage,
|
|
405
|
-
|
|
406
|
-
// Engine types
|
|
407
|
-
QueryEngineConfig,
|
|
408
|
-
|
|
409
|
-
// Content block types
|
|
410
|
-
ContentBlockParam,
|
|
411
|
-
ContentBlock,
|
|
412
|
-
|
|
413
|
-
// Sandbox types
|
|
414
|
-
SandboxSettings,
|
|
415
|
-
SandboxNetworkConfig,
|
|
416
|
-
SandboxFilesystemConfig,
|
|
417
|
-
|
|
418
|
-
// Output format
|
|
419
|
-
OutputFormat,
|
|
420
|
-
|
|
421
|
-
// Setting sources
|
|
422
|
-
SettingSource,
|
|
423
|
-
|
|
424
|
-
// Model info
|
|
425
|
-
ModelInfo,
|
|
426
|
-
} from './types.js'
|