open-agent-sdk 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +284 -0
- package/README.zh.md +285 -0
- package/dist/agent/agent-definition.d.ts +107 -0
- package/dist/agent/agent-definition.d.ts.map +1 -0
- package/dist/agent/agent-definition.js +90 -0
- package/dist/agent/agent-definition.js.map +1 -0
- package/dist/agent/react-loop.d.ts +117 -0
- package/dist/agent/react-loop.d.ts.map +1 -0
- package/dist/agent/react-loop.js +674 -0
- package/dist/agent/react-loop.js.map +1 -0
- package/dist/agent/subagent-runner.d.ts +67 -0
- package/dist/agent/subagent-runner.d.ts.map +1 -0
- package/dist/agent/subagent-runner.js +168 -0
- package/dist/agent/subagent-runner.js.map +1 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/inputs.d.ts +56 -0
- package/dist/hooks/inputs.d.ts.map +1 -0
- package/dist/hooks/inputs.js +150 -0
- package/dist/hooks/inputs.js.map +1 -0
- package/dist/hooks/manager.d.ts +63 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +137 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +191 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +6 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/errors.d.ts +26 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +43 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +11 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +13 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +50 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +170 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/server-registry.d.ts +48 -0
- package/dist/mcp/server-registry.d.ts.map +1 -0
- package/dist/mcp/server-registry.js +121 -0
- package/dist/mcp/server-registry.js.map +1 -0
- package/dist/mcp/tool-adapter.d.ts +42 -0
- package/dist/mcp/tool-adapter.d.ts.map +1 -0
- package/dist/mcp/tool-adapter.js +89 -0
- package/dist/mcp/tool-adapter.js.map +1 -0
- package/dist/mcp/types.d.ts +74 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +21 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/permissions/index.d.ts +3 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +4 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/manager.d.ts +40 -0
- package/dist/permissions/manager.d.ts.map +1 -0
- package/dist/permissions/manager.js +115 -0
- package/dist/permissions/manager.js.map +1 -0
- package/dist/permissions/types.d.ts +124 -0
- package/dist/permissions/types.d.ts.map +1 -0
- package/dist/permissions/types.js +25 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +18 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +126 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +85 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +36 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/google.d.ts +12 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +123 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/openai.d.ts +12 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +110 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/session/factory.d.ts +156 -0
- package/dist/session/factory.d.ts.map +1 -0
- package/dist/session/factory.js +311 -0
- package/dist/session/factory.js.map +1 -0
- package/dist/session/index.d.ts +8 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +7 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/session.d.ts +144 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +319 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/storage.d.ts +105 -0
- package/dist/session/storage.d.ts.map +1 -0
- package/dist/session/storage.js +148 -0
- package/dist/session/storage.js.map +1 -0
- package/dist/tools/ask-user-question.d.ts +31 -0
- package/dist/tools/ask-user-question.d.ts.map +1 -0
- package/dist/tools/ask-user-question.js +66 -0
- package/dist/tools/ask-user-question.js.map +1 -0
- package/dist/tools/bash-output.d.ts +22 -0
- package/dist/tools/bash-output.d.ts.map +1 -0
- package/dist/tools/bash-output.js +43 -0
- package/dist/tools/bash-output.js.map +1 -0
- package/dist/tools/bash.d.ts +36 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +161 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit.d.ts +24 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +83 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +22 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +248 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +39 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +312 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/kill-bash.d.ts +19 -0
- package/dist/tools/kill-bash.d.ts.map +1 -0
- package/dist/tools/kill-bash.js +64 -0
- package/dist/tools/kill-bash.js.map +1 -0
- package/dist/tools/read.d.ts +26 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +87 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/registry.d.ts +32 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +91 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/task-create.d.ts +22 -0
- package/dist/tools/task-create.d.ts.map +1 -0
- package/dist/tools/task-create.js +42 -0
- package/dist/tools/task-create.js.map +1 -0
- package/dist/tools/task-get.d.ts +19 -0
- package/dist/tools/task-get.d.ts.map +1 -0
- package/dist/tools/task-get.js +38 -0
- package/dist/tools/task-get.js.map +1 -0
- package/dist/tools/task-list.d.ts +18 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +27 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/task-storage.d.ts +6 -0
- package/dist/tools/task-storage.d.ts.map +1 -0
- package/dist/tools/task-storage.js +83 -0
- package/dist/tools/task-storage.js.map +1 -0
- package/dist/tools/task-update.d.ts +28 -0
- package/dist/tools/task-update.d.ts.map +1 -0
- package/dist/tools/task-update.js +118 -0
- package/dist/tools/task-update.js.map +1 -0
- package/dist/tools/task.d.ts +80 -0
- package/dist/tools/task.d.ts.map +1 -0
- package/dist/tools/task.js +99 -0
- package/dist/tools/task.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +21 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +124 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +20 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +127 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +22 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +46 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types/messages.d.ts +138 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/messages.js +88 -0
- package/dist/types/messages.js.map +1 -0
- package/dist/types/task.d.ts +29 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/task.js +5 -0
- package/dist/types/task.js.map +1 -0
- package/dist/types/tools.d.ts +56 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +25 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +46 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/uuid.d.ts +3 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +5 -0
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HookManager - Manages hook registration and emission
|
|
3
|
+
* Aligned with Claude Agent SDK
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Manages hook callbacks and their execution
|
|
7
|
+
*/
|
|
8
|
+
export class HookManager {
|
|
9
|
+
hooks;
|
|
10
|
+
abortController;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new HookManager
|
|
13
|
+
* @param config - Optional initial hooks configuration
|
|
14
|
+
*/
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.hooks = new Map();
|
|
17
|
+
this.abortController = new AbortController();
|
|
18
|
+
if (config) {
|
|
19
|
+
for (const [event, matchers] of Object.entries(config)) {
|
|
20
|
+
this.register(event, matchers);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Register hook callbacks for an event
|
|
26
|
+
* @param event - The hook event type
|
|
27
|
+
* @param matchers - Array of matcher configurations
|
|
28
|
+
*/
|
|
29
|
+
register(event, matchers) {
|
|
30
|
+
const existing = this.hooks.get(event) ?? [];
|
|
31
|
+
this.hooks.set(event, [...existing, ...matchers]);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Emit a hook event to all registered callbacks
|
|
35
|
+
* @param event - The hook event type
|
|
36
|
+
* @param input - The hook input data
|
|
37
|
+
* @param toolUseID - Optional tool use ID
|
|
38
|
+
* @returns Array of results from all callbacks
|
|
39
|
+
*/
|
|
40
|
+
async emit(event, input, toolUseID) {
|
|
41
|
+
const matchers = this.hooks.get(event);
|
|
42
|
+
if (!matchers || matchers.length === 0) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const results = [];
|
|
46
|
+
const signal = this.abortController.signal;
|
|
47
|
+
for (const matcher of matchers) {
|
|
48
|
+
for (const hook of matcher.hooks) {
|
|
49
|
+
try {
|
|
50
|
+
const result = await hook(input, toolUseID, { signal });
|
|
51
|
+
results.push(result);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// Convert error to a sync output with error info
|
|
55
|
+
results.push({
|
|
56
|
+
continue: false,
|
|
57
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return results;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Emit a hook event with tool name filtering
|
|
66
|
+
* Only callbacks with matching matcher or no matcher will be called
|
|
67
|
+
* @param event - The hook event type
|
|
68
|
+
* @param input - The hook input data
|
|
69
|
+
* @param toolName - The tool name for matcher filtering
|
|
70
|
+
* @param toolUseID - Optional tool use ID
|
|
71
|
+
* @returns Array of results from matching callbacks
|
|
72
|
+
*/
|
|
73
|
+
async emitForTool(event, input, toolName, toolUseID) {
|
|
74
|
+
const matchers = this.hooks.get(event);
|
|
75
|
+
if (!matchers || matchers.length === 0) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
const results = [];
|
|
79
|
+
const signal = this.abortController.signal;
|
|
80
|
+
for (const matcher of matchers) {
|
|
81
|
+
// Skip if matcher is specified and doesn't match tool name
|
|
82
|
+
if (matcher.matcher && matcher.matcher !== toolName) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
for (const hook of matcher.hooks) {
|
|
86
|
+
try {
|
|
87
|
+
const result = await hook(input, toolUseID, { signal });
|
|
88
|
+
results.push(result);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
// Convert error to a sync output with error info
|
|
92
|
+
results.push({
|
|
93
|
+
continue: false,
|
|
94
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if there are any hooks registered for an event
|
|
103
|
+
* @param event - The hook event type
|
|
104
|
+
* @returns True if hooks are registered
|
|
105
|
+
*/
|
|
106
|
+
hasHooks(event) {
|
|
107
|
+
const matchers = this.hooks.get(event);
|
|
108
|
+
return !!matchers && matchers.length > 0;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the number of hooks registered for an event
|
|
112
|
+
* @param event - The hook event type
|
|
113
|
+
* @returns Number of registered hook callbacks
|
|
114
|
+
*/
|
|
115
|
+
hookCount(event) {
|
|
116
|
+
const matchers = this.hooks.get(event);
|
|
117
|
+
if (!matchers)
|
|
118
|
+
return 0;
|
|
119
|
+
return matchers.reduce((count, matcher) => count + matcher.hooks.length, 0);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Clear all registered hooks
|
|
123
|
+
*/
|
|
124
|
+
clear() {
|
|
125
|
+
this.hooks.clear();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Destroy the hook manager
|
|
129
|
+
* Aborts the internal abort controller
|
|
130
|
+
*/
|
|
131
|
+
destroy() {
|
|
132
|
+
this.abortController.abort();
|
|
133
|
+
// Create a new controller for potential future use
|
|
134
|
+
this.abortController = new AbortController();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/hooks/manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH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|
+
*
|
|
8
|
+
* Implementation status:
|
|
9
|
+
* - PreToolUse: ✅ Triggered in ReActLoop.executeTool() before tool execution
|
|
10
|
+
* - PostToolUse: ✅ Triggered in ReActLoop.executeTool() after successful execution
|
|
11
|
+
* - PostToolUseFailure:✅ Triggered in ReActLoop.executeTool() after failed execution
|
|
12
|
+
* - UserPromptSubmit: ✅ Triggered in ReActLoop.run()/runStream() when user prompt is received
|
|
13
|
+
* - SessionStart: ✅ Triggered in ReActLoop.runStream() at session start
|
|
14
|
+
* - SessionEnd: ✅ Triggered in ReActLoop.runStream() at session end
|
|
15
|
+
* - Stop: ✅ Triggered in ReActLoop when agent produces final answer (no tool calls)
|
|
16
|
+
* - SubagentStart: ✅ Triggered in subagent-runner when subagent starts
|
|
17
|
+
* - SubagentStop: ✅ Triggered in subagent-runner when subagent stops
|
|
18
|
+
* - PermissionRequest: ✅ Triggered in ReActLoop.executeTool() on permission denial
|
|
19
|
+
* - Notification: ⏳ Helper only. No auto trigger — requires compact feature (planned v0.4.0+)
|
|
20
|
+
* - PreCompact: ⏳ Helper only. No auto trigger — requires compact feature (planned v0.4.0+)
|
|
21
|
+
*/
|
|
22
|
+
export type HookEvent = 'PreToolUse' | 'PostToolUse' | 'PostToolUseFailure' | 'Notification' | 'UserPromptSubmit' | 'SessionStart' | 'SessionEnd' | 'Stop' | 'SubagentStart' | 'SubagentStop' | 'PreCompact' | 'PermissionRequest';
|
|
23
|
+
/** Base interface that all hook input types extend */
|
|
24
|
+
export type BaseHookInput = {
|
|
25
|
+
session_id: string;
|
|
26
|
+
transcript_path: string;
|
|
27
|
+
cwd: string;
|
|
28
|
+
permission_mode?: string;
|
|
29
|
+
};
|
|
30
|
+
/** PreToolUse hook input - triggered before tool execution */
|
|
31
|
+
export type PreToolUseHookInput = BaseHookInput & {
|
|
32
|
+
hook_event_name: 'PreToolUse';
|
|
33
|
+
tool_name: string;
|
|
34
|
+
tool_input: unknown;
|
|
35
|
+
};
|
|
36
|
+
/** PostToolUse hook input - triggered after successful tool execution */
|
|
37
|
+
export type PostToolUseHookInput = BaseHookInput & {
|
|
38
|
+
hook_event_name: 'PostToolUse';
|
|
39
|
+
tool_name: string;
|
|
40
|
+
tool_input: unknown;
|
|
41
|
+
tool_response: unknown;
|
|
42
|
+
};
|
|
43
|
+
/** PostToolUseFailure hook input - triggered after failed tool execution */
|
|
44
|
+
export type PostToolUseFailureHookInput = BaseHookInput & {
|
|
45
|
+
hook_event_name: 'PostToolUseFailure';
|
|
46
|
+
tool_name: string;
|
|
47
|
+
tool_input: unknown;
|
|
48
|
+
error: string;
|
|
49
|
+
is_interrupt?: boolean;
|
|
50
|
+
};
|
|
51
|
+
/** Notification hook input
|
|
52
|
+
* ⏳ No auto trigger point — application-level notifications, planned for v0.4.0+
|
|
53
|
+
*/
|
|
54
|
+
export type NotificationHookInput = BaseHookInput & {
|
|
55
|
+
hook_event_name: 'Notification';
|
|
56
|
+
message: string;
|
|
57
|
+
title?: string;
|
|
58
|
+
};
|
|
59
|
+
/** UserPromptSubmit hook input */
|
|
60
|
+
export type UserPromptSubmitHookInput = BaseHookInput & {
|
|
61
|
+
hook_event_name: 'UserPromptSubmit';
|
|
62
|
+
prompt: string;
|
|
63
|
+
};
|
|
64
|
+
/** SessionStart hook input */
|
|
65
|
+
export type SessionStartHookInput = BaseHookInput & {
|
|
66
|
+
hook_event_name: 'SessionStart';
|
|
67
|
+
source: 'startup' | 'resume' | 'clear' | 'compact';
|
|
68
|
+
};
|
|
69
|
+
/** Exit reason for session end */
|
|
70
|
+
export type ExitReason = 'completed' | 'error' | 'interrupted' | 'max_turns_reached' | 'abort';
|
|
71
|
+
/** SessionEnd hook input */
|
|
72
|
+
export type SessionEndHookInput = BaseHookInput & {
|
|
73
|
+
hook_event_name: 'SessionEnd';
|
|
74
|
+
reason: ExitReason;
|
|
75
|
+
};
|
|
76
|
+
/** Stop hook input */
|
|
77
|
+
export type StopHookInput = BaseHookInput & {
|
|
78
|
+
hook_event_name: 'Stop';
|
|
79
|
+
stop_hook_active: boolean;
|
|
80
|
+
};
|
|
81
|
+
/** SubagentStart hook input */
|
|
82
|
+
export type SubagentStartHookInput = BaseHookInput & {
|
|
83
|
+
hook_event_name: 'SubagentStart';
|
|
84
|
+
subagent_id: string;
|
|
85
|
+
subagent_type: string;
|
|
86
|
+
/** Optional prompt/context for the subagent (extension beyond Claude Agent SDK) */
|
|
87
|
+
prompt?: string;
|
|
88
|
+
};
|
|
89
|
+
/** SubagentStop hook input */
|
|
90
|
+
export type SubagentStopHookInput = BaseHookInput & {
|
|
91
|
+
hook_event_name: 'SubagentStop';
|
|
92
|
+
stop_hook_active: boolean;
|
|
93
|
+
};
|
|
94
|
+
/** PreCompact hook input
|
|
95
|
+
* ⏳ No auto trigger point — requires compact feature, planned for v0.4.0+
|
|
96
|
+
*/
|
|
97
|
+
export type PreCompactHookInput = BaseHookInput & {
|
|
98
|
+
hook_event_name: 'PreCompact';
|
|
99
|
+
trigger: 'manual' | 'auto';
|
|
100
|
+
custom_instructions: string | null;
|
|
101
|
+
};
|
|
102
|
+
/** PermissionRequest hook input */
|
|
103
|
+
export type PermissionRequestHookInput = BaseHookInput & {
|
|
104
|
+
hook_event_name: 'PermissionRequest';
|
|
105
|
+
tool_name: string;
|
|
106
|
+
tool_input: unknown;
|
|
107
|
+
permission_suggestions?: PermissionUpdate[];
|
|
108
|
+
};
|
|
109
|
+
/** Union type of all hook input types */
|
|
110
|
+
export type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PermissionRequestHookInput;
|
|
111
|
+
/** Async hook output for long-running operations */
|
|
112
|
+
export type AsyncHookJSONOutput = {
|
|
113
|
+
async: true;
|
|
114
|
+
asyncTimeout?: number;
|
|
115
|
+
};
|
|
116
|
+
/** Sync hook output for immediate decisions */
|
|
117
|
+
export type SyncHookJSONOutput = {
|
|
118
|
+
continue?: boolean;
|
|
119
|
+
suppressOutput?: boolean;
|
|
120
|
+
stopReason?: string;
|
|
121
|
+
decision?: 'approve' | 'block';
|
|
122
|
+
systemMessage?: string;
|
|
123
|
+
reason?: string;
|
|
124
|
+
hookSpecificOutput?: {
|
|
125
|
+
hookEventName: 'PreToolUse';
|
|
126
|
+
permissionDecision?: 'allow' | 'deny' | 'ask';
|
|
127
|
+
permissionDecisionReason?: string;
|
|
128
|
+
updatedInput?: Record<string, unknown>;
|
|
129
|
+
} | {
|
|
130
|
+
hookEventName: 'UserPromptSubmit';
|
|
131
|
+
additionalContext?: string;
|
|
132
|
+
} | {
|
|
133
|
+
hookEventName: 'SessionStart';
|
|
134
|
+
additionalContext?: string;
|
|
135
|
+
} | {
|
|
136
|
+
hookEventName: 'PostToolUse';
|
|
137
|
+
additionalContext?: string;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
/** Hook return value */
|
|
141
|
+
export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput | void;
|
|
142
|
+
/** Hook callback function type */
|
|
143
|
+
export type HookCallback = (input: HookInput, toolUseID: string | undefined, options: {
|
|
144
|
+
signal: AbortSignal;
|
|
145
|
+
}) => Promise<HookJSONOutput>;
|
|
146
|
+
/** Hook configuration with optional matcher */
|
|
147
|
+
export interface HookCallbackMatcher {
|
|
148
|
+
matcher?: string;
|
|
149
|
+
hooks: HookCallback[];
|
|
150
|
+
}
|
|
151
|
+
/** Hooks configuration type */
|
|
152
|
+
export type HooksConfig = Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
153
|
+
/** Permission behavior */
|
|
154
|
+
export type PermissionBehavior = 'allow' | 'deny' | 'ask';
|
|
155
|
+
/** Permission update destination */
|
|
156
|
+
export type PermissionUpdateDestination = 'userSettings' | 'projectSettings' | 'localSettings' | 'session';
|
|
157
|
+
/** Permission update operations */
|
|
158
|
+
export type PermissionUpdate = {
|
|
159
|
+
type: 'addRules';
|
|
160
|
+
rules: PermissionRuleValue[];
|
|
161
|
+
behavior: PermissionBehavior;
|
|
162
|
+
destination: PermissionUpdateDestination;
|
|
163
|
+
} | {
|
|
164
|
+
type: 'replaceRules';
|
|
165
|
+
rules: PermissionRuleValue[];
|
|
166
|
+
behavior: PermissionBehavior;
|
|
167
|
+
destination: PermissionUpdateDestination;
|
|
168
|
+
} | {
|
|
169
|
+
type: 'removeRules';
|
|
170
|
+
rules: PermissionRuleValue[];
|
|
171
|
+
behavior: PermissionBehavior;
|
|
172
|
+
destination: PermissionUpdateDestination;
|
|
173
|
+
} | {
|
|
174
|
+
type: 'setMode';
|
|
175
|
+
mode: string;
|
|
176
|
+
destination: PermissionUpdateDestination;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'addDirectories';
|
|
179
|
+
directories: string[];
|
|
180
|
+
destination: PermissionUpdateDestination;
|
|
181
|
+
} | {
|
|
182
|
+
type: 'removeDirectories';
|
|
183
|
+
directories: string[];
|
|
184
|
+
destination: PermissionUpdateDestination;
|
|
185
|
+
};
|
|
186
|
+
/** Permission rule value */
|
|
187
|
+
export type PermissionRuleValue = {
|
|
188
|
+
toolName: string;
|
|
189
|
+
ruleContent?: string;
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,GACjB,YAAY,GACZ,aAAa,GACb,oBAAoB,GACpB,cAAc,GACd,kBAAkB,GAClB,cAAc,GACd,YAAY,GACZ,MAAM,GACN,eAAe,GACf,cAAc,GACd,YAAY,GACZ,mBAAmB,CAAC;AAExB,sDAAsD;AACtD,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EA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AAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open Agent SDK - Core API
|
|
3
|
+
* Single-query prompt function for one-shot agent interactions
|
|
4
|
+
*/
|
|
5
|
+
import { type LogLevel } from './utils/logger';
|
|
6
|
+
import type { PermissionMode, CanUseTool } from './permissions/types';
|
|
7
|
+
import type { McpServersConfig } from './mcp/types';
|
|
8
|
+
import type { SessionStorage } from './session/storage';
|
|
9
|
+
export { PermissionManager, type PermissionMode, type PermissionOptions, type PermissionResult, type CanUseTool, type PermissionCheckResult, type PlanLogEntry, SENSITIVE_TOOLS, EDIT_TOOLS, isSensitiveTool, isEditTool, } from './permissions';
|
|
10
|
+
export interface PromptOptions {
|
|
11
|
+
/** Model identifier (e.g., 'gpt-4', 'gpt-4o', 'gemini-2.0-flash') */
|
|
12
|
+
model: string;
|
|
13
|
+
/** API key (defaults to OPENAI_API_KEY or GEMINI_API_KEY env var based on provider) */
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/** Provider to use: 'openai', 'google', or 'anthropic' (auto-detected from model name if not specified) */
|
|
16
|
+
provider?: 'openai' | 'google' | 'anthropic';
|
|
17
|
+
/** Base URL for API (OpenAI only) */
|
|
18
|
+
baseURL?: string;
|
|
19
|
+
/** Maximum conversation turns (default: 10) */
|
|
20
|
+
maxTurns?: number;
|
|
21
|
+
/** Allowed tools whitelist (default: all) */
|
|
22
|
+
allowedTools?: string[];
|
|
23
|
+
/** System prompt for the agent */
|
|
24
|
+
systemPrompt?: string;
|
|
25
|
+
/** Working directory (default: process.cwd()) */
|
|
26
|
+
cwd?: string;
|
|
27
|
+
/** Environment variables */
|
|
28
|
+
env?: Record<string, string>;
|
|
29
|
+
/** AbortController for cancellation */
|
|
30
|
+
abortController?: AbortController;
|
|
31
|
+
/** Permission mode for the session (default: 'default') */
|
|
32
|
+
permissionMode?: PermissionMode;
|
|
33
|
+
/** Required to be true when using bypassPermissions mode */
|
|
34
|
+
allowDangerouslySkipPermissions?: boolean;
|
|
35
|
+
/** MCP servers configuration */
|
|
36
|
+
mcpServers?: McpServersConfig;
|
|
37
|
+
/** Log level: 'debug' | 'info' | 'warn' | 'error' | 'silent' (default: 'info') */
|
|
38
|
+
logLevel?: LogLevel;
|
|
39
|
+
/** Custom callback for tool permission checks */
|
|
40
|
+
canUseTool?: CanUseTool;
|
|
41
|
+
/** Storage implementation for session persistence. If provided, session will be saved and can be resumed later */
|
|
42
|
+
storage?: SessionStorage;
|
|
43
|
+
/** Session ID to resume. When provided, continues the conversation from the specified session */
|
|
44
|
+
resume?: string;
|
|
45
|
+
/** Fork the session instead of resuming. When true with resume option, creates a new session with copied history */
|
|
46
|
+
forkSession?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface PromptResult {
|
|
49
|
+
/** Final result text from the agent */
|
|
50
|
+
result: string;
|
|
51
|
+
/** Total execution time in milliseconds */
|
|
52
|
+
duration_ms: number;
|
|
53
|
+
/** Token usage statistics */
|
|
54
|
+
usage: {
|
|
55
|
+
input_tokens: number;
|
|
56
|
+
output_tokens: number;
|
|
57
|
+
};
|
|
58
|
+
/** Session ID for this conversation. Can be used to resume or fork later */
|
|
59
|
+
session_id?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Execute a single prompt with the agent
|
|
63
|
+
* @param prompt - User's question or task
|
|
64
|
+
* @param options - Configuration options
|
|
65
|
+
* @returns Promise with result, duration, and usage
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const result = await prompt("What files are in the current directory?", {
|
|
70
|
+
* model: "gpt-4o",
|
|
71
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
72
|
+
* });
|
|
73
|
+
* console.log(result.result);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function prompt(prompt: string, options: PromptOptions): Promise<PromptResult>;
|
|
77
|
+
export type { SDKMessage, SDKUserMessage, SDKAssistantMessage, SDKToolResultMessage, SDKSystemMessage, SDKCompactBoundaryMessage, SDKResultMessage, ToolCall, ApiKeySource, McpServerInfo, CreateSystemMessageOptions, } from './types/messages';
|
|
78
|
+
export type { Tool, ToolDefinition, ToolContext, ToolInput, ToolOutput, ToolHandler, JSONSchema, } from './types/tools';
|
|
79
|
+
export type { ReadInput, ReadOutput } from './tools/read';
|
|
80
|
+
export type { WriteInput, WriteOutput } from './tools/write';
|
|
81
|
+
export type { EditInput, EditOutput } from './tools/edit';
|
|
82
|
+
export type { BashInput, BashOutput, BackgroundProcess } from './tools/bash';
|
|
83
|
+
export type { GlobInput, GlobOutput } from './tools/glob';
|
|
84
|
+
export type { GrepInput, GrepOutput, GrepMatch } from './tools/grep';
|
|
85
|
+
export type { TaskListInput, TaskListOutput } from './tools/task-list';
|
|
86
|
+
export type { TaskCreateInput, TaskCreateOutput } from './tools/task-create';
|
|
87
|
+
export type { TaskGetInput, TaskGetOutput } from './tools/task-get';
|
|
88
|
+
export type { TaskUpdateInput, TaskUpdateOutput } from './tools/task-update';
|
|
89
|
+
export type { WebSearchInput, WebSearchOutput } from './tools/web-search';
|
|
90
|
+
export type { WebFetchInput, WebFetchOutput } from './tools/web-fetch';
|
|
91
|
+
export type { BashOutputInput, BashOutputOutput } from './tools/bash-output';
|
|
92
|
+
export type { KillBashInput, KillBashOutput } from './tools/kill-bash';
|
|
93
|
+
export type { AskUserQuestionInput, AskUserQuestionOutput, AskUserQuestionItem, AskUserQuestionOption, } from './tools/ask-user-question';
|
|
94
|
+
export type { Task, TaskStatus, TaskStorage } from './types/task';
|
|
95
|
+
export { LLMProvider, type LLMChunk, type ProviderConfig, type ChatOptions, type TokenUsage } from './providers/base';
|
|
96
|
+
export { OpenAIProvider, type OpenAIConfig } from './providers/openai';
|
|
97
|
+
export { GoogleProvider, type GoogleConfig } from './providers/google';
|
|
98
|
+
export { AnthropicProvider, type AnthropicConfig } from './providers/anthropic';
|
|
99
|
+
export { ToolRegistry, createDefaultRegistry, ReadTool, readTool, WriteTool, writeTool, EditTool, editTool, BashTool, bashTool, GlobTool, globTool, GrepTool, grepTool, TaskListTool, taskListTool, TaskCreateTool, taskCreateTool, TaskGetTool, taskGetTool, TaskUpdateTool, taskUpdateTool, WebSearchTool, webSearchTool, WebFetchTool, webFetchTool, BashOutputTool, bashOutputTool, KillBashTool, killBashTool, AskUserQuestionTool, askUserQuestionTool, } from './tools/registry';
|
|
100
|
+
export { ReActLoop, type ReActLoopConfig, type ReActResult, type ReActStreamEvent } from './agent/react-loop';
|
|
101
|
+
export { AgentDefinitionSchema, validateAgentDefinition, safeValidateAgentDefinition, createAgentDefinition, hasCustomTools, inheritsModel, hasCustomMaxTurns, hasCustomPermissionMode, type AgentDefinition, type AgentDefinitions, type ModelIdentifier, } from './agent/agent-definition';
|
|
102
|
+
export { runSubagent, isSubagentSuccess, formatSubagentResult, type SubagentResult, type SubagentContext, } from './agent/subagent-runner';
|
|
103
|
+
export { TaskTool, createTaskTool, createTaskToolFromConfig, type TaskInput, type TaskOutput, type TaskToolConfig } from './tools/task';
|
|
104
|
+
export { createUserMessage, createSystemMessage, createAssistantMessage, createToolResultMessage, createResultMessage, createCompactBoundaryMessage, } from './types/messages';
|
|
105
|
+
export { Session, SessionState, SessionError, SessionNotIdleError, SessionNotReadyError, SessionAlreadyStreamingError, SessionClosedError, InMemoryStorage, FileStorage, createSession, resumeSession, forkSession, type SessionStorage, type SessionData, type SessionOptions as SessionStorageOptions, type FileStorageOptions, type CreateSessionOptions, type ResumeSessionOptions, type ForkSessionOptions, } from './session';
|
|
106
|
+
export { logger, type LogLevel } from './utils/logger';
|
|
107
|
+
export { HookManager, type HookEvent, type HookInput, type BaseHookInput, type PreToolUseHookInput, type PostToolUseHookInput, type NotificationHookInput, type UserPromptSubmitHookInput, type SessionStartHookInput, type SessionEndHookInput, type StopHookInput, type SubagentStartHookInput, type SubagentStopHookInput, type PreCompactHookInput, type ExitReason, type HookCallback, type HookCallbackMatcher, type HooksConfig, type HookJSONOutput, type AsyncHookJSONOutput, type SyncHookJSONOutput, createPreToolUseInput, createPostToolUseInput, createSessionStartInput, createSessionEndInput, createSubagentStartInput, createSubagentStopInput, createNotificationInput, createStopInput, createPreCompactInput, createUserPromptSubmitInput, } from './hooks';
|
|
108
|
+
export * from './mcp';
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAMxD,OAAO,EACL,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,eAAe,EACf,UAAU,EACV,eAAe,EACf,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2GAA2G;IAC3G,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC7C,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C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