@lleverage-ai/agent-sdk 0.0.1
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 +2321 -0
- package/dist/agent.d.ts +52 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +2122 -0
- package/dist/agent.js.map +1 -0
- package/dist/backend.d.ts +378 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +71 -0
- package/dist/backend.js.map +1 -0
- package/dist/backends/composite.d.ts +258 -0
- package/dist/backends/composite.d.ts.map +1 -0
- package/dist/backends/composite.js +437 -0
- package/dist/backends/composite.js.map +1 -0
- package/dist/backends/filesystem.d.ts +268 -0
- package/dist/backends/filesystem.d.ts.map +1 -0
- package/dist/backends/filesystem.js +623 -0
- package/dist/backends/filesystem.js.map +1 -0
- package/dist/backends/index.d.ts +14 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +14 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/persistent.d.ts +312 -0
- package/dist/backends/persistent.d.ts.map +1 -0
- package/dist/backends/persistent.js +519 -0
- package/dist/backends/persistent.js.map +1 -0
- package/dist/backends/sandbox.d.ts +315 -0
- package/dist/backends/sandbox.d.ts.map +1 -0
- package/dist/backends/sandbox.js +490 -0
- package/dist/backends/sandbox.js.map +1 -0
- package/dist/backends/state.d.ts +225 -0
- package/dist/backends/state.d.ts.map +1 -0
- package/dist/backends/state.js +396 -0
- package/dist/backends/state.js.map +1 -0
- package/dist/checkpointer/file-saver.d.ts +182 -0
- package/dist/checkpointer/file-saver.d.ts.map +1 -0
- package/dist/checkpointer/file-saver.js +298 -0
- package/dist/checkpointer/file-saver.js.map +1 -0
- package/dist/checkpointer/index.d.ts +40 -0
- package/dist/checkpointer/index.d.ts.map +1 -0
- package/dist/checkpointer/index.js +40 -0
- package/dist/checkpointer/index.js.map +1 -0
- package/dist/checkpointer/kv-saver.d.ts +142 -0
- package/dist/checkpointer/kv-saver.d.ts.map +1 -0
- package/dist/checkpointer/kv-saver.js +176 -0
- package/dist/checkpointer/kv-saver.js.map +1 -0
- package/dist/checkpointer/memory-saver.d.ts +158 -0
- package/dist/checkpointer/memory-saver.d.ts.map +1 -0
- package/dist/checkpointer/memory-saver.js +222 -0
- package/dist/checkpointer/memory-saver.js.map +1 -0
- package/dist/checkpointer/types.d.ts +353 -0
- package/dist/checkpointer/types.d.ts.map +1 -0
- package/dist/checkpointer/types.js +159 -0
- package/dist/checkpointer/types.js.map +1 -0
- package/dist/context-manager.d.ts +627 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +1039 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/context.d.ts +57 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +76 -0
- package/dist/context.js.map +1 -0
- package/dist/errors/index.d.ts +611 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +1023 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/generation-helpers.d.ts +126 -0
- package/dist/generation-helpers.d.ts.map +1 -0
- package/dist/generation-helpers.js +181 -0
- package/dist/generation-helpers.js.map +1 -0
- package/dist/hooks/audit.d.ts +210 -0
- package/dist/hooks/audit.d.ts.map +1 -0
- package/dist/hooks/audit.js +305 -0
- package/dist/hooks/audit.js.map +1 -0
- package/dist/hooks/cache.d.ts +180 -0
- package/dist/hooks/cache.d.ts.map +1 -0
- package/dist/hooks/cache.js +273 -0
- package/dist/hooks/cache.js.map +1 -0
- package/dist/hooks/guardrails.d.ts +145 -0
- package/dist/hooks/guardrails.d.ts.map +1 -0
- package/dist/hooks/guardrails.js +326 -0
- package/dist/hooks/guardrails.js.map +1 -0
- package/dist/hooks/index.d.ts +18 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +32 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/logging.d.ts +193 -0
- package/dist/hooks/logging.d.ts.map +1 -0
- package/dist/hooks/logging.js +345 -0
- package/dist/hooks/logging.js.map +1 -0
- package/dist/hooks/parallel-guardrails.d.ts +268 -0
- package/dist/hooks/parallel-guardrails.d.ts.map +1 -0
- package/dist/hooks/parallel-guardrails.js +416 -0
- package/dist/hooks/parallel-guardrails.js.map +1 -0
- package/dist/hooks/rate-limit.d.ts +305 -0
- package/dist/hooks/rate-limit.d.ts.map +1 -0
- package/dist/hooks/rate-limit.js +372 -0
- package/dist/hooks/rate-limit.js.map +1 -0
- package/dist/hooks/retry.d.ts +144 -0
- package/dist/hooks/retry.d.ts.map +1 -0
- package/dist/hooks/retry.js +210 -0
- package/dist/hooks/retry.js.map +1 -0
- package/dist/hooks/secrets.d.ts +174 -0
- package/dist/hooks/secrets.d.ts.map +1 -0
- package/dist/hooks/secrets.js +306 -0
- package/dist/hooks/secrets.js.map +1 -0
- package/dist/hooks.d.ts +229 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +352 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +182 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/env.d.ts +25 -0
- package/dist/mcp/env.d.ts.map +1 -0
- package/dist/mcp/env.js +18 -0
- package/dist/mcp/env.js.map +1 -0
- package/dist/mcp/index.d.ts +16 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +184 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +446 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/types.d.ts +58 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +7 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/mcp/validation.d.ts +119 -0
- package/dist/mcp/validation.d.ts.map +1 -0
- package/dist/mcp/validation.js +407 -0
- package/dist/mcp/validation.js.map +1 -0
- package/dist/mcp/virtual-server.d.ts +78 -0
- package/dist/mcp/virtual-server.d.ts.map +1 -0
- package/dist/mcp/virtual-server.js +137 -0
- package/dist/mcp/virtual-server.js.map +1 -0
- package/dist/memory/filesystem-store.d.ts +217 -0
- package/dist/memory/filesystem-store.d.ts.map +1 -0
- package/dist/memory/filesystem-store.js +343 -0
- package/dist/memory/filesystem-store.js.map +1 -0
- package/dist/memory/index.d.ts +46 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +46 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/loader.d.ts +396 -0
- package/dist/memory/loader.d.ts.map +1 -0
- package/dist/memory/loader.js +419 -0
- package/dist/memory/loader.js.map +1 -0
- package/dist/memory/permissions.d.ts +282 -0
- package/dist/memory/permissions.d.ts.map +1 -0
- package/dist/memory/permissions.js +297 -0
- package/dist/memory/permissions.js.map +1 -0
- package/dist/memory/rules.d.ts +249 -0
- package/dist/memory/rules.d.ts.map +1 -0
- package/dist/memory/rules.js +362 -0
- package/dist/memory/rules.js.map +1 -0
- package/dist/memory/store.d.ts +286 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +263 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/middleware/apply.d.ts +73 -0
- package/dist/middleware/apply.d.ts.map +1 -0
- package/dist/middleware/apply.js +219 -0
- package/dist/middleware/apply.js.map +1 -0
- package/dist/middleware/context.d.ts +33 -0
- package/dist/middleware/context.d.ts.map +1 -0
- package/dist/middleware/context.js +176 -0
- package/dist/middleware/context.js.map +1 -0
- package/dist/middleware/index.d.ts +31 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +32 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/logging.d.ts +137 -0
- package/dist/middleware/logging.d.ts.map +1 -0
- package/dist/middleware/logging.js +374 -0
- package/dist/middleware/logging.js.map +1 -0
- package/dist/middleware/types.d.ts +183 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +11 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/observability/events.d.ts +183 -0
- package/dist/observability/events.d.ts.map +1 -0
- package/dist/observability/events.js +305 -0
- package/dist/observability/events.js.map +1 -0
- package/dist/observability/index.d.ts +55 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +87 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +318 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +436 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +341 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +490 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/preset.d.ts +161 -0
- package/dist/observability/preset.d.ts.map +1 -0
- package/dist/observability/preset.js +133 -0
- package/dist/observability/preset.js.map +1 -0
- package/dist/observability/streaming.d.ts +113 -0
- package/dist/observability/streaming.d.ts.map +1 -0
- package/dist/observability/streaming.js +114 -0
- package/dist/observability/streaming.js.map +1 -0
- package/dist/observability/tracing.d.ts +378 -0
- package/dist/observability/tracing.d.ts.map +1 -0
- package/dist/observability/tracing.js +539 -0
- package/dist/observability/tracing.js.map +1 -0
- package/dist/plugins.d.ts +55 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +63 -0
- package/dist/plugins.js.map +1 -0
- package/dist/presets/index.d.ts +7 -0
- package/dist/presets/index.d.ts.map +1 -0
- package/dist/presets/index.js +7 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/production.d.ts +262 -0
- package/dist/presets/production.d.ts.map +1 -0
- package/dist/presets/production.js +295 -0
- package/dist/presets/production.js.map +1 -0
- package/dist/security/index.d.ts +179 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +323 -0
- package/dist/security/index.js.map +1 -0
- package/dist/subagents/advanced.d.ts +413 -0
- package/dist/subagents/advanced.d.ts.map +1 -0
- package/dist/subagents/advanced.js +396 -0
- package/dist/subagents/advanced.js.map +1 -0
- package/dist/subagents/index.d.ts +14 -0
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +15 -0
- package/dist/subagents/index.js.map +1 -0
- package/dist/subagents.d.ts +73 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +213 -0
- package/dist/subagents.js.map +1 -0
- package/dist/task-store/file-store.d.ts +76 -0
- package/dist/task-store/file-store.d.ts.map +1 -0
- package/dist/task-store/file-store.js +190 -0
- package/dist/task-store/file-store.js.map +1 -0
- package/dist/task-store/index.d.ts +11 -0
- package/dist/task-store/index.d.ts.map +1 -0
- package/dist/task-store/index.js +10 -0
- package/dist/task-store/index.js.map +1 -0
- package/dist/task-store/kv-store.d.ts +140 -0
- package/dist/task-store/kv-store.d.ts.map +1 -0
- package/dist/task-store/kv-store.js +169 -0
- package/dist/task-store/kv-store.js.map +1 -0
- package/dist/task-store/memory-store.d.ts +66 -0
- package/dist/task-store/memory-store.d.ts.map +1 -0
- package/dist/task-store/memory-store.js +125 -0
- package/dist/task-store/memory-store.js.map +1 -0
- package/dist/task-store/types.d.ts +235 -0
- package/dist/task-store/types.d.ts.map +1 -0
- package/dist/task-store/types.js +110 -0
- package/dist/task-store/types.js.map +1 -0
- package/dist/testing/assertions.d.ts +401 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +630 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/index.d.ts +343 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +360 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-agent.d.ts +214 -0
- package/dist/testing/mock-agent.d.ts.map +1 -0
- package/dist/testing/mock-agent.js +448 -0
- package/dist/testing/mock-agent.js.map +1 -0
- package/dist/testing/recorder.d.ts +288 -0
- package/dist/testing/recorder.d.ts.map +1 -0
- package/dist/testing/recorder.js +499 -0
- package/dist/testing/recorder.js.map +1 -0
- package/dist/tools/execute.d.ts +104 -0
- package/dist/tools/execute.d.ts.map +1 -0
- package/dist/tools/execute.js +191 -0
- package/dist/tools/execute.js.map +1 -0
- package/dist/tools/factory.d.ts +260 -0
- package/dist/tools/factory.d.ts.map +1 -0
- package/dist/tools/factory.js +241 -0
- package/dist/tools/factory.js.map +1 -0
- package/dist/tools/filesystem.d.ts +215 -0
- package/dist/tools/filesystem.d.ts.map +1 -0
- package/dist/tools/filesystem.js +311 -0
- package/dist/tools/filesystem.js.map +1 -0
- package/dist/tools/index.d.ts +33 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/search.d.ts +59 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +94 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/skills.d.ts +354 -0
- package/dist/tools/skills.d.ts.map +1 -0
- package/dist/tools/skills.js +413 -0
- package/dist/tools/skills.js.map +1 -0
- package/dist/tools/task.d.ts +272 -0
- package/dist/tools/task.d.ts.map +1 -0
- package/dist/tools/task.js +521 -0
- package/dist/tools/task.js.map +1 -0
- package/dist/tools/todos.d.ts +131 -0
- package/dist/tools/todos.d.ts.map +1 -0
- package/dist/tools/todos.js +120 -0
- package/dist/tools/todos.js.map +1 -0
- package/dist/tools/tool-registry.d.ts +424 -0
- package/dist/tools/tool-registry.d.ts.map +1 -0
- package/dist/tools/tool-registry.js +607 -0
- package/dist/tools/tool-registry.js.map +1 -0
- package/dist/tools/user-interaction.d.ts +116 -0
- package/dist/tools/user-interaction.d.ts.map +1 -0
- package/dist/tools/user-interaction.js +147 -0
- package/dist/tools/user-interaction.js.map +1 -0
- package/dist/tools/utils.d.ts +124 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +189 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools.d.ts +74 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +73 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +2421 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +55 -0
- package/dist/types.js.map +1 -0
- package/package.json +81 -0
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook system for observing agent lifecycle events.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
// =============================================================================
|
|
7
|
+
// Unified Hook System with Matchers
|
|
8
|
+
// =============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a tool name matches a HookMatcher pattern.
|
|
11
|
+
*
|
|
12
|
+
* @param toolName - The tool name to test
|
|
13
|
+
* @param matcher - The matcher pattern (undefined matches all)
|
|
14
|
+
* @returns true if the tool name matches the pattern
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function matchesToolName(toolName, matcher) {
|
|
19
|
+
if (matcher === undefined) {
|
|
20
|
+
return true; // No matcher = match all tools
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const regex = new RegExp(matcher);
|
|
24
|
+
return regex.test(toolName);
|
|
25
|
+
}
|
|
26
|
+
catch (_error) {
|
|
27
|
+
// Invalid regex - treat as literal string match
|
|
28
|
+
return toolName === matcher;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Error thrown when a hook times out.
|
|
33
|
+
*
|
|
34
|
+
* @category Hooks
|
|
35
|
+
*/
|
|
36
|
+
export class HookTimeoutError extends Error {
|
|
37
|
+
constructor(timeout) {
|
|
38
|
+
super(`Hook execution timed out after ${timeout}ms`);
|
|
39
|
+
this.name = "HookTimeoutError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Invokes hook callbacks with timeout support.
|
|
44
|
+
*
|
|
45
|
+
* This function enforces a hard timeout using `Promise.race`. If a hook does not complete
|
|
46
|
+
* within the specified timeout, it will be treated as returning an empty result `{}`.
|
|
47
|
+
* The abort signal is also set when the timeout is reached, allowing cooperative hooks
|
|
48
|
+
* to clean up resources.
|
|
49
|
+
*
|
|
50
|
+
* @param hooks - Array of hook callbacks to invoke
|
|
51
|
+
* @param input - The hook input data
|
|
52
|
+
* @param toolUseId - The tool use ID (null for non-tool hooks)
|
|
53
|
+
* @param agent - The agent instance
|
|
54
|
+
* @param timeout - Timeout in milliseconds (default: 60000). Each hook must complete within this time.
|
|
55
|
+
* @param retryAttempt - Current retry attempt number (default: 0)
|
|
56
|
+
* @returns Array of hook outputs. Timed out hooks return empty objects `{}`.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Hook that respects the abort signal for cooperative cancellation
|
|
61
|
+
* const cooperativeHook: HookCallback = async (input, toolUseId, ctx) => {
|
|
62
|
+
* for (const item of items) {
|
|
63
|
+
* if (ctx.signal.aborted) {
|
|
64
|
+
* return {}; // Early exit on abort
|
|
65
|
+
* }
|
|
66
|
+
* await processItem(item);
|
|
67
|
+
* }
|
|
68
|
+
* return { hookSpecificOutput: { ... } };
|
|
69
|
+
* };
|
|
70
|
+
*
|
|
71
|
+
* // Even if a hook doesn't check the signal, it will be timed out
|
|
72
|
+
* const results = await invokeHooksWithTimeout(
|
|
73
|
+
* [cooperativeHook, slowHook],
|
|
74
|
+
* input,
|
|
75
|
+
* toolUseId,
|
|
76
|
+
* agent,
|
|
77
|
+
* 5000 // 5 second timeout
|
|
78
|
+
* );
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export async function invokeHooksWithTimeout(hooks, input, toolUseId, agent, timeout = 60000, retryAttempt = 0) {
|
|
84
|
+
const abortController = new AbortController();
|
|
85
|
+
const timeoutId = setTimeout(() => abortController.abort(), timeout);
|
|
86
|
+
try {
|
|
87
|
+
const context = {
|
|
88
|
+
signal: abortController.signal,
|
|
89
|
+
agent,
|
|
90
|
+
retryAttempt,
|
|
91
|
+
};
|
|
92
|
+
const results = await Promise.all(hooks.map(async (hook) => {
|
|
93
|
+
try {
|
|
94
|
+
// Create a timeout promise that rejects after the specified time
|
|
95
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
96
|
+
const hookTimeoutId = setTimeout(() => {
|
|
97
|
+
reject(new HookTimeoutError(timeout));
|
|
98
|
+
}, timeout);
|
|
99
|
+
// Clean up timeout if signal is aborted (parent timeout reached)
|
|
100
|
+
abortController.signal.addEventListener("abort", () => {
|
|
101
|
+
clearTimeout(hookTimeoutId);
|
|
102
|
+
reject(new HookTimeoutError(timeout));
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
// Race between hook execution and timeout
|
|
106
|
+
const result = await Promise.race([hook(input, toolUseId, context), timeoutPromise]);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// If hook throws or times out, treat as allowing with no modifications
|
|
111
|
+
if (error instanceof HookTimeoutError) {
|
|
112
|
+
console.error(`Hook timed out after ${timeout}ms`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
console.error("Hook execution error:", error);
|
|
116
|
+
}
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
}));
|
|
120
|
+
return results;
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
clearTimeout(timeoutId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Filters and invokes matching hooks for a tool use event.
|
|
128
|
+
*
|
|
129
|
+
* @param matchers - Array of HookMatcher configurations
|
|
130
|
+
* @param toolName - The name of the tool being used
|
|
131
|
+
* @param input - The hook input data
|
|
132
|
+
* @param toolUseId - The tool use ID
|
|
133
|
+
* @param agent - The agent instance
|
|
134
|
+
* @returns Array of hook outputs from all matching hooks
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const matchers: HookMatcher[] = [
|
|
139
|
+
* { matcher: 'Write|Edit', hooks: [protectFiles], timeout: 30000 },
|
|
140
|
+
* { hooks: [auditLogger] } // Matches all tools
|
|
141
|
+
* ];
|
|
142
|
+
*
|
|
143
|
+
* const outputs = await invokeMatchingHooks(
|
|
144
|
+
* matchers,
|
|
145
|
+
* 'Write',
|
|
146
|
+
* input,
|
|
147
|
+
* toolUseId,
|
|
148
|
+
* agent
|
|
149
|
+
* );
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @category Hooks
|
|
153
|
+
*/
|
|
154
|
+
export async function invokeMatchingHooks(matchers, toolName, input, toolUseId, agent) {
|
|
155
|
+
const allOutputs = [];
|
|
156
|
+
for (const matcher of matchers) {
|
|
157
|
+
if (matchesToolName(toolName, matcher.matcher)) {
|
|
158
|
+
const timeout = matcher.timeout ?? 60000;
|
|
159
|
+
const outputs = await invokeHooksWithTimeout(matcher.hooks, input, toolUseId, agent, timeout);
|
|
160
|
+
allOutputs.push(...outputs);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return allOutputs;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Aggregates permission decisions from multiple hook outputs.
|
|
167
|
+
*
|
|
168
|
+
* Follows the hierarchy: deny > ask > allow > default
|
|
169
|
+
*
|
|
170
|
+
* @param hookOutputs - Array of hook outputs to aggregate
|
|
171
|
+
* @param defaultDecision - Default decision if no hooks provide one (default: 'allow')
|
|
172
|
+
* @returns The aggregated permission decision
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const outputs: HookOutput[] = [
|
|
177
|
+
* { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'allow' } },
|
|
178
|
+
* { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny' } },
|
|
179
|
+
* ];
|
|
180
|
+
*
|
|
181
|
+
* const decision = aggregatePermissionDecisions(outputs);
|
|
182
|
+
* // Returns 'deny' because deny wins over allow
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @category Hooks
|
|
186
|
+
*/
|
|
187
|
+
export function aggregatePermissionDecisions(hookOutputs, defaultDecision = "allow") {
|
|
188
|
+
let hasDeny = false;
|
|
189
|
+
let hasAsk = false;
|
|
190
|
+
let hasAllow = false;
|
|
191
|
+
for (const output of hookOutputs) {
|
|
192
|
+
const decision = output.hookSpecificOutput?.permissionDecision;
|
|
193
|
+
if (decision === "deny") {
|
|
194
|
+
hasDeny = true;
|
|
195
|
+
}
|
|
196
|
+
else if (decision === "ask") {
|
|
197
|
+
hasAsk = true;
|
|
198
|
+
}
|
|
199
|
+
else if (decision === "allow") {
|
|
200
|
+
hasAllow = true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Priority: deny > ask > allow > default
|
|
204
|
+
if (hasDeny)
|
|
205
|
+
return "deny";
|
|
206
|
+
if (hasAsk)
|
|
207
|
+
return "ask";
|
|
208
|
+
if (hasAllow)
|
|
209
|
+
return "allow";
|
|
210
|
+
return defaultDecision;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Extracts a cached/mock result from hook outputs for short-circuit execution.
|
|
214
|
+
*
|
|
215
|
+
* Returns the first non-undefined `respondWith` value found in the hook outputs.
|
|
216
|
+
* This enables cache hooks to return cached results without executing the actual operation.
|
|
217
|
+
*
|
|
218
|
+
* @param hookOutputs - Array of hook outputs to scan
|
|
219
|
+
* @returns The cached result if found, undefined otherwise
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const outputs: HookOutput[] = [
|
|
224
|
+
* { hookSpecificOutput: { hookEventName: 'PreGenerate' } },
|
|
225
|
+
* { hookSpecificOutput: { hookEventName: 'PreGenerate', respondWith: cachedResult } },
|
|
226
|
+
* ];
|
|
227
|
+
*
|
|
228
|
+
* const result = extractRespondWith(outputs);
|
|
229
|
+
* // Returns cachedResult
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @category Hooks
|
|
233
|
+
*/
|
|
234
|
+
export function extractRespondWith(hookOutputs) {
|
|
235
|
+
for (const output of hookOutputs) {
|
|
236
|
+
const respondWith = output.hookSpecificOutput?.respondWith;
|
|
237
|
+
if (respondWith !== undefined) {
|
|
238
|
+
return respondWith;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Extracts transformed input from hook outputs.
|
|
245
|
+
*
|
|
246
|
+
* Returns the first non-undefined `updatedInput` value found in the hook outputs.
|
|
247
|
+
* This enables hooks to modify inputs before they are used (e.g., redirect file paths,
|
|
248
|
+
* add rate limit headers, sanitize user input).
|
|
249
|
+
*
|
|
250
|
+
* @param hookOutputs - Array of hook outputs to scan
|
|
251
|
+
* @returns The transformed input if found, undefined otherwise
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const outputs: HookOutput[] = [
|
|
256
|
+
* { hookSpecificOutput: { hookEventName: 'PreToolUse' } },
|
|
257
|
+
* { hookSpecificOutput: {
|
|
258
|
+
* hookEventName: 'PreToolUse',
|
|
259
|
+
* updatedInput: { file_path: '/sandbox/file.txt' }
|
|
260
|
+
* }
|
|
261
|
+
* },
|
|
262
|
+
* ];
|
|
263
|
+
*
|
|
264
|
+
* const transformed = extractUpdatedInput(outputs);
|
|
265
|
+
* // Returns { file_path: '/sandbox/file.txt' }
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @category Hooks
|
|
269
|
+
*/
|
|
270
|
+
export function extractUpdatedInput(hookOutputs) {
|
|
271
|
+
for (const output of hookOutputs) {
|
|
272
|
+
const updatedInput = output.hookSpecificOutput?.updatedInput;
|
|
273
|
+
if (updatedInput !== undefined) {
|
|
274
|
+
return updatedInput;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Extracts transformed result from hook outputs.
|
|
281
|
+
*
|
|
282
|
+
* Returns the first non-undefined `updatedResult` value found in the hook outputs.
|
|
283
|
+
* This enables hooks to modify outputs after execution (e.g., filter sensitive data,
|
|
284
|
+
* add metadata, transform format, apply post-processing).
|
|
285
|
+
*
|
|
286
|
+
* @param hookOutputs - Array of hook outputs to scan
|
|
287
|
+
* @returns The transformed result if found, undefined otherwise
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const outputs: HookOutput[] = [
|
|
292
|
+
* { hookSpecificOutput: { hookEventName: 'PostGenerate' } },
|
|
293
|
+
* { hookSpecificOutput: {
|
|
294
|
+
* hookEventName: 'PostGenerate',
|
|
295
|
+
* updatedResult: { ...originalResult, filtered: true }
|
|
296
|
+
* }
|
|
297
|
+
* },
|
|
298
|
+
* ];
|
|
299
|
+
*
|
|
300
|
+
* const transformed = extractUpdatedResult(outputs);
|
|
301
|
+
* // Returns { ...originalResult, filtered: true }
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @category Hooks
|
|
305
|
+
*/
|
|
306
|
+
export function extractUpdatedResult(hookOutputs) {
|
|
307
|
+
for (const output of hookOutputs) {
|
|
308
|
+
const updatedResult = output.hookSpecificOutput?.updatedResult;
|
|
309
|
+
if (updatedResult !== undefined) {
|
|
310
|
+
return updatedResult;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Extracts retry decision from PostGenerateFailure or PostToolUseFailure hook outputs.
|
|
317
|
+
*
|
|
318
|
+
* Returns the first retry decision found in the hook outputs. If any hook requests a retry,
|
|
319
|
+
* the operation will be retried after the specified delay (or 0ms if no delay specified).
|
|
320
|
+
*
|
|
321
|
+
* @param hookOutputs - Array of hook outputs to scan
|
|
322
|
+
* @returns Object with retry flag and delay, or undefined if no retry requested
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const outputs: HookOutput[] = [
|
|
327
|
+
* { hookSpecificOutput: { hookEventName: 'PostGenerateFailure' } },
|
|
328
|
+
* { hookSpecificOutput: {
|
|
329
|
+
* hookEventName: 'PostGenerateFailure',
|
|
330
|
+
* retry: true,
|
|
331
|
+
* retryDelayMs: 1000 // Wait 1s before retrying
|
|
332
|
+
* }
|
|
333
|
+
* },
|
|
334
|
+
* ];
|
|
335
|
+
*
|
|
336
|
+
* const retryDecision = extractRetryDecision(outputs);
|
|
337
|
+
* // Returns { retry: true, retryDelayMs: 1000 }
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @category Hooks
|
|
341
|
+
*/
|
|
342
|
+
export function extractRetryDecision(hookOutputs) {
|
|
343
|
+
for (const output of hookOutputs) {
|
|
344
|
+
const retry = output.hookSpecificOutput?.retry;
|
|
345
|
+
if (retry === true) {
|
|
346
|
+
const retryDelayMs = output.hookSpecificOutput?.retryDelayMs ?? 0;
|
|
347
|
+
return { retry: true, retryDelayMs };
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,gFAAgF;AAChF,oCAAoC;AACpC,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,OAA2B;IAC3E,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,CAAC,+BAA+B;IAC9C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAAC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;;;;;GA0BG;AACH,MAAM,UAAU,mBAAmB,CAAc,WAAyB;IACxE,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;QACjC,MAAM,YAAY,GAAG,MAAM,CAAC,kBAAkB,EAAE,YAAY,CAAC;QAC7D,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,YAAiB,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,oBAAoB,CAAc,WAAyB;IACzE,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;QACjC,MAAM,aAAa,GAAG,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;QAC/D,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO,aAAkB,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,oBAAoB,CAClC,WAAyB;IAEzB,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,kBAAkB,EAAE,KAAK,CAAC;QAC/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,MAAM,YAAY,GAAG,MAAM,CAAC,kBAAkB,EAAE,YAAY,IAAI,CAAC,CAAC;YAClE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lleverage-ai/agent-sdk - A TypeScript framework for building AI agents.
|
|
3
|
+
*
|
|
4
|
+
* Built on top of Vercel AI SDK, this library provides a comprehensive toolkit
|
|
5
|
+
* for creating intelligent agents that can use tools, respond to hooks, and
|
|
6
|
+
* delegate tasks to specialized subagents.
|
|
7
|
+
*
|
|
8
|
+
* ## Quick Start
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createAgent } from "@lleverage-ai/agent-sdk";
|
|
12
|
+
* import { anthropic } from "@ai-sdk/anthropic";
|
|
13
|
+
* import { tool } from "ai";
|
|
14
|
+
* import { z } from "zod";
|
|
15
|
+
*
|
|
16
|
+
* // Create an agent with tools
|
|
17
|
+
* const agent = createAgent({
|
|
18
|
+
* model: anthropic("claude-sonnet-4-20250514"),
|
|
19
|
+
* systemPrompt: "You are a friendly assistant.",
|
|
20
|
+
* tools: {
|
|
21
|
+
* greet: tool({
|
|
22
|
+
* description: "Greet a person by name",
|
|
23
|
+
* inputSchema: z.object({ name: z.string() }),
|
|
24
|
+
* execute: async ({ name }) => `Hello, ${name}!`,
|
|
25
|
+
* }),
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Generate a response
|
|
30
|
+
* const result = await agent.generate({
|
|
31
|
+
* prompt: "Say hello to Alice",
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Or use with Next.js API routes and useChat
|
|
35
|
+
* export async function POST(req: Request) {
|
|
36
|
+
* const { messages } = await req.json();
|
|
37
|
+
* return agent.streamResponse({ messages });
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* ## Key Concepts
|
|
42
|
+
*
|
|
43
|
+
* - **Agents** - The main abstraction combining a model with tools and plugins
|
|
44
|
+
* - **Tools** - Use AI SDK's `tool()` function directly for full compatibility
|
|
45
|
+
* - **Plugins** - Bundles of tools, skills, and hooks for reusability
|
|
46
|
+
* - **Skills** - User-invocable slash commands
|
|
47
|
+
* - **Hooks** - Lifecycle event handlers for observing agent behavior
|
|
48
|
+
* - **Subagents** - Specialized agents for task delegation
|
|
49
|
+
*
|
|
50
|
+
* ## AI SDK Compatibility
|
|
51
|
+
*
|
|
52
|
+
* This SDK is built on Vercel AI SDK and maintains full compatibility:
|
|
53
|
+
* - Use `tool()` from 'ai' to define tools
|
|
54
|
+
* - Use `CoreMessage` and `UIMessage` types directly
|
|
55
|
+
* - `streamResponse()` returns a Response compatible with `useChat`
|
|
56
|
+
* - `streamRaw()` returns the raw AI SDK `streamText` result
|
|
57
|
+
*
|
|
58
|
+
* @packageDocumentation
|
|
59
|
+
*/
|
|
60
|
+
export { createAgent } from "./agent.js";
|
|
61
|
+
export type { BackendProtocol, EditResult, ExecuteResponse, FileData, FileInfo, FileUploadResponse, GrepMatch, SandboxBackendProtocol, WriteResult, } from "./backend.js";
|
|
62
|
+
export { isBackend, isSandboxBackend } from "./backend.js";
|
|
63
|
+
export type { AgentState, CompositeBackendOptions, FilesystemBackendOptions, KeyValueStore, LocalSandboxOptions, PersistentBackendOptions, RouteConfig, TodoItem, TodoStatus, } from "./backends/index.js";
|
|
64
|
+
export { BaseSandbox, CommandBlockedError, CommandTimeoutError, CompositeBackend, createAgentState, createCompositeBackend, createFilesystemBackend, createLocalSandbox, createPersistentBackend, createStateBackend, FileSizeLimitError, FilesystemBackend, InMemoryStore, LocalSandbox, PathTraversalError, PersistentBackend, StateBackend, SymlinkError, } from "./backends/index.js";
|
|
65
|
+
export type { ApprovalInterrupt, ApprovalRequest, ApprovalResponse, BaseCheckpointSaver, Checkpoint, CheckpointEvent, CheckpointLoadedEvent, CheckpointSavedEvent, CheckpointSaverOptions, FileSaverOptions, Interrupt, KeyValueStoreSaverOptions, MemorySaverOptions, } from "./checkpointer/index.js";
|
|
66
|
+
export { createApprovalInterrupt, createCheckpoint, createFileSaver, createInterrupt, createKeyValueStoreSaver, createMemorySaver, FileSaver, isApprovalInterrupt, isCheckpoint, isInterrupt, KeyValueStoreSaver, MemorySaver, updateCheckpoint, } from "./checkpointer/index.js";
|
|
67
|
+
export { createContext } from "./context.js";
|
|
68
|
+
export type { CompactionPolicy, CompactionResult, CompactionScheduler, CompactionSchedulerOptions, CompactionStrategy, CompactionTask, CompactionTaskStatus, CompactionTrigger, ContextManager, ContextManagerOptions, CustomTokenCounterOptions, PinnedMessageMetadata, StructuredSummary, SummarizationConfig, TokenBudget, TokenCounter, } from "./context-manager.js";
|
|
69
|
+
export type { AgentErrorCode, ErrorSeverity, FallbackOptions, WrapErrorOptions, } from "./errors/index.js";
|
|
70
|
+
export { AbortError, AgentError, AuthenticationError, AuthorizationError, BackendError, CheckpointError, ConfigurationError, ContextError, createCircuitBreaker, createErrorHandler, formatErrorForLogging, GeneratePermissionDeniedError, getUserMessage, isRetryable, MemoryError, ModelError, NetworkError, RateLimitError, SubagentError, TimeoutError, ToolExecutionError, ToolPermissionDeniedError, tryOperations, ValidationError, withFallback, withFallbackFn, wrapError, } from "./errors/index.js";
|
|
71
|
+
export type { AuditEvent, AuditEventCategory, AuditEventHandler, AuditHooksOptions, BufferedGuardrailState, CacheEntry as CacheEntryHook, CacheHooksOptions, CacheStore as CacheStoreHook, Guardrail, GuardrailCheckResult, GuardrailsHooksOptions, LoggingHooksOptions as GenerationLoggingHooksOptions, OutputGuardrailConfig, RaceGuardrailsOptions, RateLimitHooksOptions, RetryHooksOptions, SecretsFilterHooksOptions, ServerRateLimitInfo, } from "./hooks/index.js";
|
|
72
|
+
export { BufferedOutputGuardrail, COMMON_SECRET_PATTERNS, createAuditHooks, createBufferedOutputGuardrail, createCacheHooks, createComprehensiveLoggingHooks, createGuardrailsHooks, createInMemoryAuditStore, createLoggingHooks as createGenerationLoggingHooks, createManagedCacheHooks, createManagedGuardrailsHooks, createManagedRateLimitHooks, createManagedRetryHooks, createManagedSecretsFilterHooks, createRateLimitHooks, createRegexGuardrail, createRetryHooks, createSecretsFilterHooks, createToolLoggingHooks, exportAuditEventsJSONLines, extractTextFromMessages, findLastUserMessageId, InMemoryCacheStore as InMemoryCacheStoreHook, raceGuardrails, runWithGuardrails, TokenBucketRateLimiter, withTimeout, wrapStreamWithOutputGuardrail, } from "./hooks/index.js";
|
|
73
|
+
export { aggregatePermissionDecisions, extractRespondWith, extractRetryDecision, extractUpdatedInput, extractUpdatedResult, HookTimeoutError, invokeHooksWithTimeout, invokeMatchingHooks, matchesToolName, } from "./hooks.js";
|
|
74
|
+
export type { MCPManagerOptions, MCPToolLoadResult, MCPToolMetadata, MCPToolSource, } from "./mcp/index.js";
|
|
75
|
+
export { expandEnvVars, isSchemaEmpty, MCPInputValidationError, MCPInputValidator, MCPManager, VirtualMCPServer, } from "./mcp/index.js";
|
|
76
|
+
export type { AdditionalMemoryFile, BuildMemorySectionOptions, BuildPathMemoryContextOptions, FileMemoryPermissionStoreOptions, FilesystemMemoryStoreOptions, LoadAdditionalMemoryOptions, LoadAgentMemoryOptions, LoadAllMemoryOptions, LoadAllMemoryResult, MemoryApproval, MemoryAuditEvent, MemoryDocument, MemoryMetadata, MemoryPermissionStore, MemoryStore, ParsedMarkdown, PathMemoryContext, } from "./memory/index.js";
|
|
77
|
+
export { buildMemorySection, buildPathMemoryContext, computeContentHash, computeFileHash, createFilesystemMemoryStore, createInMemoryMemoryStore, createInMemoryPermissionStore, createMemoryPermissionStore, FileMemoryPermissionStore, FilesystemMemoryStore, filterAdditionalFilesByPath, filterAutoLoadAdditionalFiles, filterAutoLoadMemories, filterMemoriesByAllTags, filterMemoriesByPath, filterMemoriesByTags, findGitRoot, getProjectMemoryPath, getUserAgentDir, getUserMemoryPath, InMemoryMemoryStore, InMemoryPermissionStore, loadAdditionalMemoryFiles, loadAgentMemory, loadAllMemory, matchesAnyPathPattern, matchesPathPattern, parseMarkdownWithFrontmatter, parseSimpleYaml, serializeMarkdownWithFrontmatter, } from "./memory/index.js";
|
|
78
|
+
export type { AgentMiddleware, LoggingMiddlewareOptions, MiddlewareContext, MiddlewareContextResult, } from "./middleware/index.js";
|
|
79
|
+
export { applyMiddleware, createLoggingMiddleware, createMiddlewareContext, mergeHooks, setupMiddleware, teardownMiddleware, } from "./middleware/index.js";
|
|
80
|
+
export type { AgentMetrics, Counter, EventExporterOptions, EventSeverity, Gauge, Histogram, HistogramBucket, HistogramData, LogEntry, LogFormatter, Logger, LoggerOptions, LogLevel, LogTimer, LogTransport, MetricLabels, MetricPoint, MetricsExporter, MetricsRegistry, MetricsRegistryOptions, MetricType, ObservabilityEvent, ObservabilityEventStore, ObservabilityEventStoreOptions, ObservabilityPreset, ObservabilityPresetOptions, Span, SpanAttributes, SpanContext, SpanData, SpanEvent, SpanExporter, SpanKind, SpanLink, SpanStatus, SpanStatusCode, StartSpanOptions, StructuredEvent, Tracer, TracerOptions, } from "./observability/index.js";
|
|
81
|
+
export { createAgentMetrics, createCallbackMetricsExporter, createCallbackSpanExporter, createCallbackTransport, createConsoleMetricsExporter, createConsoleSpanExporter, createConsoleTransport, createFilteredTransport, createJsonFormatter, createLogger, createMemoryMetricsExporter, createMemorySpanExporter, createMemoryTransport, createMetricsRegistry, createObservabilityEventHooks, createObservabilityEventStore, createObservabilityPreset, createOTLPSpanExporter, createPrettyFormatter, createTracer, DEFAULT_LATENCY_BUCKETS, DEFAULT_TOKEN_BUCKETS, defaultLogger, defaultMetricsRegistry, defaultTracer, exportEventsJSONLines, exportEventsPrometheus, LOG_LEVEL_VALUES, SemanticAttributes, setDefaultLogger, setDefaultMetricsRegistry, setDefaultTracer, toStructuredEvent, } from "./observability/index.js";
|
|
82
|
+
export { definePlugin } from "./plugins.js";
|
|
83
|
+
export type { ProductionAgentOptions, ProductionAgentResult, SecureProductionAgentOptions, } from "./presets/index.js";
|
|
84
|
+
export { createProductionAgent, createSecureProductionAgent, DEFAULT_BLOCKED_INPUT_PATTERNS, DEFAULT_BLOCKED_OUTPUT_PATTERNS, } from "./presets/index.js";
|
|
85
|
+
export type { SecurityPolicy, SecurityPolicyPreset } from "./security/index.js";
|
|
86
|
+
export { applySecurityPolicy } from "./security/index.js";
|
|
87
|
+
export type { EnhancedSubagentDefinition, ParallelExecutionResult, ParallelTask, SubagentContext, SubagentContextOptions, SubagentErrorEvent, SubagentEvent, SubagentEventEmitter, SubagentExecutionOptions, SubagentExecutionResult, SubagentFinishEvent, SubagentStartEvent, SubagentStepEvent, } from "./subagents/index.js";
|
|
88
|
+
export { createSubagentContext, createSubagentEventEmitter, executeSubagent, executeSubagentsParallel, mergeSubagentContext, } from "./subagents/index.js";
|
|
89
|
+
export { createSubagent } from "./subagents.js";
|
|
90
|
+
export type { BackgroundTask, BackgroundTaskStatus, BaseTaskStore, KeyValueStore as KVStore, TaskStoreOptions, } from "./task-store/index.js";
|
|
91
|
+
export { createBackgroundTask, FileTaskStore, isBackgroundTask, KVTaskStore, MemoryTaskStore, shouldExpireTask, updateBackgroundTask, } from "./task-store/index.js";
|
|
92
|
+
export type { AskUserCallback, BashResult, BashToolOptions, CoreTools, CoreToolsOptions, FilesystemTools, FilesystemToolsOptions, LoadableSkillDefinition, OnTodosChanged, QuestionOption, SearchToolsOptions, SkillLoadResult, SkillRegistryOptions, SkillToolOptions, TaskStatus, TaskToolOptions as TaskToolOptions_Tool, TodoChangeType, TodoInput, TodosChangedData, TodoWriteToolOptions, ToolLoadResult, ToolMetadata, ToolReference, ToolRegistryOptions, ToolSearchOptions, UseToolsToolOptions, } from "./tools/index.js";
|
|
93
|
+
export { cleanupStaleTasks, clearCompletedTasks, createAskUserQuestionTool, createBashTool, createCoreTools, createEditTool, createFilesystemTools, createFilesystemToolsOnly, createGlobTool, createGrepTool, createReadTool, createSearchToolsTool, createSkillRegistry, createSkillTool, createTaskTool, createTodoWriteTool, createToolRegistry, createUseToolsTool, createWriteTool, defineLoadableSkill, getBackgroundTask, listBackgroundTasks, mcpTools, mcpToolsFor, recoverFailedTasks, recoverRunningTasks, SkillRegistry, ToolRegistry, toolsFrom, toolsFromPlugin, } from "./tools/index.js";
|
|
94
|
+
export { defineSkill } from "./tools.js";
|
|
95
|
+
export type { Agent, AgentContext, AgentDataTypes, AgentOptions, AgentPlugin, AgentUIMessage, BackendFactory, CoreToolName, ExtendedToolExecutionOptions, FinishReason, GenerateOptions, GenerateResult, GenerateResultComplete, GenerateResultInterrupted, GenerateStep, HookCallback, HookCallbackContext, HookEvent, HookInput, HookMatcher, HookOutput, HookRegistration, HookSpecificOutput, HttpMCPServerConfig, InterruptFunction, InterruptRequestedInput, InterruptResolvedInput, LanguageModel, LanguageModelUsage, MCPConnectionFailedInput, MCPConnectionRestoredInput, MCPServerConfig, ModelMessage, PartialGenerateResult, PermissionDecision, PermissionMode, PluginLoadingMode, PluginOptions, PostCompactInput, PostGenerateFailureInput, PostGenerateInput, PostToolUseFailureInput, PostToolUseInput, PreCompactInput, PreGenerateInput, PreToolUseInput, SkillDefinition, SkillOptions, SseMCPServerConfig, StdioMCPServerConfig, StreamingContext, StreamingMetadata, StreamingToolsFactory, StreamPart, SubagentCreateContext, SubagentDefinition, SubagentOptions, SubagentStartInput, SubagentStopInput, TaskToolOptions, Tool, ToolCallResult, ToolExecutionOptions, ToolLoadErrorInput, ToolRegisteredInput, ToolResultPart, ToolSet, UIMessage, } from "./types.js";
|
|
96
|
+
export { isCompleteResult, isInterruptedResult, } from "./types.js";
|
|
97
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,YAAY,EACV,eAAe,EACf,UAAU,EACV,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,kBAAkB,EAClB,SAAS,EACT,sBAAsB,EACtB,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3D,YAAY,EACV,UAAU,EACV,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EACb,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,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P,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAEL,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lleverage-ai/agent-sdk - A TypeScript framework for building AI agents.
|
|
3
|
+
*
|
|
4
|
+
* Built on top of Vercel AI SDK, this library provides a comprehensive toolkit
|
|
5
|
+
* for creating intelligent agents that can use tools, respond to hooks, and
|
|
6
|
+
* delegate tasks to specialized subagents.
|
|
7
|
+
*
|
|
8
|
+
* ## Quick Start
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createAgent } from "@lleverage-ai/agent-sdk";
|
|
12
|
+
* import { anthropic } from "@ai-sdk/anthropic";
|
|
13
|
+
* import { tool } from "ai";
|
|
14
|
+
* import { z } from "zod";
|
|
15
|
+
*
|
|
16
|
+
* // Create an agent with tools
|
|
17
|
+
* const agent = createAgent({
|
|
18
|
+
* model: anthropic("claude-sonnet-4-20250514"),
|
|
19
|
+
* systemPrompt: "You are a friendly assistant.",
|
|
20
|
+
* tools: {
|
|
21
|
+
* greet: tool({
|
|
22
|
+
* description: "Greet a person by name",
|
|
23
|
+
* inputSchema: z.object({ name: z.string() }),
|
|
24
|
+
* execute: async ({ name }) => `Hello, ${name}!`,
|
|
25
|
+
* }),
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Generate a response
|
|
30
|
+
* const result = await agent.generate({
|
|
31
|
+
* prompt: "Say hello to Alice",
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Or use with Next.js API routes and useChat
|
|
35
|
+
* export async function POST(req: Request) {
|
|
36
|
+
* const { messages } = await req.json();
|
|
37
|
+
* return agent.streamResponse({ messages });
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* ## Key Concepts
|
|
42
|
+
*
|
|
43
|
+
* - **Agents** - The main abstraction combining a model with tools and plugins
|
|
44
|
+
* - **Tools** - Use AI SDK's `tool()` function directly for full compatibility
|
|
45
|
+
* - **Plugins** - Bundles of tools, skills, and hooks for reusability
|
|
46
|
+
* - **Skills** - User-invocable slash commands
|
|
47
|
+
* - **Hooks** - Lifecycle event handlers for observing agent behavior
|
|
48
|
+
* - **Subagents** - Specialized agents for task delegation
|
|
49
|
+
*
|
|
50
|
+
* ## AI SDK Compatibility
|
|
51
|
+
*
|
|
52
|
+
* This SDK is built on Vercel AI SDK and maintains full compatibility:
|
|
53
|
+
* - Use `tool()` from 'ai' to define tools
|
|
54
|
+
* - Use `CoreMessage` and `UIMessage` types directly
|
|
55
|
+
* - `streamResponse()` returns a Response compatible with `useChat`
|
|
56
|
+
* - `streamRaw()` returns the raw AI SDK `streamText` result
|
|
57
|
+
*
|
|
58
|
+
* @packageDocumentation
|
|
59
|
+
*/
|
|
60
|
+
// Core agent
|
|
61
|
+
export { createAgent } from "./agent.js";
|
|
62
|
+
// Backend
|
|
63
|
+
export { isBackend, isSandboxBackend } from "./backend.js";
|
|
64
|
+
export { BaseSandbox, CommandBlockedError, CommandTimeoutError, CompositeBackend, createAgentState, createCompositeBackend, createFilesystemBackend, createLocalSandbox, createPersistentBackend, createStateBackend, FileSizeLimitError, FilesystemBackend, InMemoryStore, LocalSandbox, PathTraversalError, PersistentBackend, StateBackend, SymlinkError, } from "./backends/index.js";
|
|
65
|
+
// Checkpointer System
|
|
66
|
+
export { createApprovalInterrupt,
|
|
67
|
+
// Types and helpers
|
|
68
|
+
createCheckpoint, createFileSaver, createInterrupt, createKeyValueStoreSaver, createMemorySaver,
|
|
69
|
+
// File Saver
|
|
70
|
+
FileSaver, isApprovalInterrupt, isCheckpoint, isInterrupt,
|
|
71
|
+
// KeyValueStore Saver
|
|
72
|
+
KeyValueStoreSaver,
|
|
73
|
+
// Memory Saver
|
|
74
|
+
MemorySaver, updateCheckpoint, } from "./checkpointer/index.js";
|
|
75
|
+
// Context
|
|
76
|
+
export { createContext } from "./context.js";
|
|
77
|
+
// Error Handling System
|
|
78
|
+
export { AbortError,
|
|
79
|
+
// Base error class
|
|
80
|
+
AgentError, AuthenticationError, AuthorizationError, BackendError, CheckpointError,
|
|
81
|
+
// Specific error classes
|
|
82
|
+
ConfigurationError, ContextError, createCircuitBreaker, createErrorHandler, formatErrorForLogging, GeneratePermissionDeniedError, getUserMessage, isRetryable, MemoryError, ModelError, NetworkError, RateLimitError, SubagentError, TimeoutError, ToolExecutionError, ToolPermissionDeniedError, tryOperations, ValidationError,
|
|
83
|
+
// Graceful degradation
|
|
84
|
+
withFallback, withFallbackFn,
|
|
85
|
+
// Utilities
|
|
86
|
+
wrapError, } from "./errors/index.js";
|
|
87
|
+
// Hook Utilities (factories for common patterns)
|
|
88
|
+
export { BufferedOutputGuardrail, COMMON_SECRET_PATTERNS,
|
|
89
|
+
// Audit hooks
|
|
90
|
+
createAuditHooks,
|
|
91
|
+
// Buffered output guardrails
|
|
92
|
+
createBufferedOutputGuardrail,
|
|
93
|
+
// Cache hooks
|
|
94
|
+
createCacheHooks, createComprehensiveLoggingHooks,
|
|
95
|
+
// Guardrails hooks
|
|
96
|
+
createGuardrailsHooks, createInMemoryAuditStore,
|
|
97
|
+
// Logging hooks
|
|
98
|
+
createLoggingHooks as createGenerationLoggingHooks, createManagedCacheHooks, createManagedGuardrailsHooks, createManagedRateLimitHooks, createManagedRetryHooks, createManagedSecretsFilterHooks,
|
|
99
|
+
// Rate limit hooks
|
|
100
|
+
createRateLimitHooks, createRegexGuardrail,
|
|
101
|
+
// Retry hooks
|
|
102
|
+
createRetryHooks,
|
|
103
|
+
// Secrets filter hooks
|
|
104
|
+
createSecretsFilterHooks, createToolLoggingHooks, exportAuditEventsJSONLines, extractTextFromMessages, findLastUserMessageId, InMemoryCacheStore as InMemoryCacheStoreHook,
|
|
105
|
+
// Composable guardrails (race pattern)
|
|
106
|
+
raceGuardrails, runWithGuardrails, TokenBucketRateLimiter, withTimeout, wrapStreamWithOutputGuardrail, } from "./hooks/index.js";
|
|
107
|
+
// Hooks
|
|
108
|
+
export { aggregatePermissionDecisions, extractRespondWith, extractRetryDecision, extractUpdatedInput, extractUpdatedResult, HookTimeoutError, invokeHooksWithTimeout, invokeMatchingHooks, matchesToolName, } from "./hooks.js";
|
|
109
|
+
// MCP (Model Context Protocol)
|
|
110
|
+
export { expandEnvVars, isSchemaEmpty, MCPInputValidationError, MCPInputValidator, MCPManager, VirtualMCPServer, } from "./mcp/index.js";
|
|
111
|
+
// Memory System
|
|
112
|
+
export { buildMemorySection, buildPathMemoryContext, computeContentHash, computeFileHash, createFilesystemMemoryStore, createInMemoryMemoryStore, createInMemoryPermissionStore, createMemoryPermissionStore,
|
|
113
|
+
// Permission store
|
|
114
|
+
FileMemoryPermissionStore,
|
|
115
|
+
// Filesystem store
|
|
116
|
+
FilesystemMemoryStore, filterAdditionalFilesByPath, filterAutoLoadAdditionalFiles, filterAutoLoadMemories, filterMemoriesByAllTags, filterMemoriesByPath, filterMemoriesByTags, findGitRoot, getProjectMemoryPath, getUserAgentDir, getUserMemoryPath, InMemoryMemoryStore, InMemoryPermissionStore, loadAdditionalMemoryFiles,
|
|
117
|
+
// Loading functions
|
|
118
|
+
loadAgentMemory, loadAllMemory, matchesAnyPathPattern,
|
|
119
|
+
// Path-based rules
|
|
120
|
+
matchesPathPattern,
|
|
121
|
+
// Store and parsing
|
|
122
|
+
parseMarkdownWithFrontmatter, parseSimpleYaml, serializeMarkdownWithFrontmatter, } from "./memory/index.js";
|
|
123
|
+
// Middleware System
|
|
124
|
+
export {
|
|
125
|
+
// Application utilities
|
|
126
|
+
applyMiddleware,
|
|
127
|
+
// Built-in middleware
|
|
128
|
+
createLoggingMiddleware,
|
|
129
|
+
// Context creation (for custom middleware)
|
|
130
|
+
createMiddlewareContext, mergeHooks, setupMiddleware, teardownMiddleware, } from "./middleware/index.js";
|
|
131
|
+
// Observability presets
|
|
132
|
+
// Observability System
|
|
133
|
+
export { createAgentMetrics, createCallbackMetricsExporter, createCallbackSpanExporter, createCallbackTransport, createConsoleMetricsExporter, createConsoleSpanExporter, createConsoleTransport, createFilteredTransport, createJsonFormatter, createLogger, createMemoryMetricsExporter, createMemorySpanExporter, createMemoryTransport, createMetricsRegistry, createObservabilityEventHooks, createObservabilityEventStore, createObservabilityPreset, createOTLPSpanExporter, createPrettyFormatter,
|
|
134
|
+
// Tracing
|
|
135
|
+
createTracer,
|
|
136
|
+
// Metrics
|
|
137
|
+
DEFAULT_LATENCY_BUCKETS, DEFAULT_TOKEN_BUCKETS, defaultLogger, defaultMetricsRegistry, defaultTracer, exportEventsJSONLines, exportEventsPrometheus,
|
|
138
|
+
// Logger
|
|
139
|
+
LOG_LEVEL_VALUES, SemanticAttributes, setDefaultLogger, setDefaultMetricsRegistry, setDefaultTracer,
|
|
140
|
+
// Events
|
|
141
|
+
toStructuredEvent, } from "./observability/index.js";
|
|
142
|
+
// Plugins
|
|
143
|
+
export { definePlugin } from "./plugins.js";
|
|
144
|
+
// Presets (convenience bundles for quick setup)
|
|
145
|
+
export { createProductionAgent, createSecureProductionAgent, DEFAULT_BLOCKED_INPUT_PATTERNS, DEFAULT_BLOCKED_OUTPUT_PATTERNS, } from "./presets/index.js";
|
|
146
|
+
// Security (security policy presets)
|
|
147
|
+
export { applySecurityPolicy } from "./security/index.js";
|
|
148
|
+
// Advanced Subagents
|
|
149
|
+
export { createSubagentContext, createSubagentEventEmitter, executeSubagent, executeSubagentsParallel, mergeSubagentContext, } from "./subagents/index.js";
|
|
150
|
+
// Subagents
|
|
151
|
+
export { createSubagent } from "./subagents.js";
|
|
152
|
+
// Task Store (background task persistence)
|
|
153
|
+
export { createBackgroundTask, FileTaskStore, isBackgroundTask, KVTaskStore, MemoryTaskStore, shouldExpireTask, updateBackgroundTask, } from "./task-store/index.js";
|
|
154
|
+
// Core Tools
|
|
155
|
+
export { cleanupStaleTasks, clearCompletedTasks,
|
|
156
|
+
// User interaction tools
|
|
157
|
+
createAskUserQuestionTool,
|
|
158
|
+
// Bash tool
|
|
159
|
+
createBashTool,
|
|
160
|
+
// Tool factory (unified tool creation)
|
|
161
|
+
createCoreTools, createEditTool, createFilesystemTools, createFilesystemToolsOnly, createGlobTool, createGrepTool,
|
|
162
|
+
// Filesystem tools
|
|
163
|
+
createReadTool,
|
|
164
|
+
// Search tools (MCP integration)
|
|
165
|
+
createSearchToolsTool, createSkillRegistry, createSkillTool,
|
|
166
|
+
// Task tool (subagent delegation)
|
|
167
|
+
createTaskTool,
|
|
168
|
+
// Todo tool
|
|
169
|
+
createTodoWriteTool, createToolRegistry, createUseToolsTool, createWriteTool, defineLoadableSkill, getBackgroundTask, listBackgroundTasks,
|
|
170
|
+
// Tool utilities (DX helpers)
|
|
171
|
+
mcpTools, mcpToolsFor, recoverFailedTasks, recoverRunningTasks,
|
|
172
|
+
// Skill tool (progressive disclosure)
|
|
173
|
+
SkillRegistry,
|
|
174
|
+
// Tool registry (deferred tool loading)
|
|
175
|
+
ToolRegistry, toolsFrom, toolsFromPlugin, } from "./tools/index.js";
|
|
176
|
+
// Skills (tools use AI SDK's tool() directly)
|
|
177
|
+
export { defineSkill } from "./tools.js";
|
|
178
|
+
// Types - Re-export AI SDK types for convenience
|
|
179
|
+
export {
|
|
180
|
+
// Result type guards
|
|
181
|
+
isCompleteResult, isInterruptedResult, } from "./types.js";
|
|
182
|
+
//# sourceMappingURL=index.js.map
|