@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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User interaction tools for agent-user communication.
|
|
3
|
+
*
|
|
4
|
+
* These tools allow agents to ask clarifying questions and get user input
|
|
5
|
+
* during execution. This enables interactive workflows where the agent
|
|
6
|
+
* needs additional information from the user to proceed.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* An option for a multiple-choice question.
|
|
12
|
+
*/
|
|
13
|
+
export interface QuestionOption {
|
|
14
|
+
/** Display label for this option */
|
|
15
|
+
label: string;
|
|
16
|
+
/** Description of what this option means or what will happen if chosen */
|
|
17
|
+
description?: string;
|
|
18
|
+
/** Value to return if this option is selected */
|
|
19
|
+
value: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Callback function to prompt the user for input.
|
|
23
|
+
*
|
|
24
|
+
* @param question - The question to ask the user
|
|
25
|
+
* @param options - Available answer options
|
|
26
|
+
* @param multiSelect - Whether the user can select multiple options
|
|
27
|
+
* @returns The selected option value(s) as string or string array
|
|
28
|
+
*/
|
|
29
|
+
export type AskUserCallback = (question: string, options: QuestionOption[], multiSelect: boolean) => Promise<string | string[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a tool for asking the user clarifying questions.
|
|
32
|
+
*
|
|
33
|
+
* This tool allows agents to request additional information from users
|
|
34
|
+
* during execution. It supports both single-select and multi-select
|
|
35
|
+
* questions with multiple choice options.
|
|
36
|
+
*
|
|
37
|
+
* The tool requires a callback function that handles the actual UI
|
|
38
|
+
* interaction with the user. The callback receives the question and
|
|
39
|
+
* options, prompts the user, and returns their selection.
|
|
40
|
+
*
|
|
41
|
+
* @param onAskUser - Callback function to handle user prompts
|
|
42
|
+
* @returns An AI SDK compatible tool for asking questions
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* Single-select question
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { createAskUserQuestionTool } from "@lleverage-ai/agent-sdk";
|
|
48
|
+
*
|
|
49
|
+
* const askUserQuestion = createAskUserQuestionTool(
|
|
50
|
+
* async (question, options, multiSelect) => {
|
|
51
|
+
* console.log(question);
|
|
52
|
+
* options.forEach((opt, i) => {
|
|
53
|
+
* console.log(`${i + 1}. ${opt.label}: ${opt.description}`);
|
|
54
|
+
* });
|
|
55
|
+
* const answer = await getUserInput(); // Your UI logic
|
|
56
|
+
* return options[answer - 1].value;
|
|
57
|
+
* }
|
|
58
|
+
* );
|
|
59
|
+
*
|
|
60
|
+
* const agent = createAgent({
|
|
61
|
+
* model,
|
|
62
|
+
* tools: { askUserQuestion },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* Multi-select question
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const askUserQuestion = createAskUserQuestionTool(
|
|
70
|
+
* async (question, options, multiSelect) => {
|
|
71
|
+
* if (multiSelect) {
|
|
72
|
+
* // Show checkboxes, allow multiple selections
|
|
73
|
+
* const selected = await getUserMultipleChoices();
|
|
74
|
+
* return selected.map(i => options[i].value);
|
|
75
|
+
* }
|
|
76
|
+
* // Single select logic
|
|
77
|
+
* }
|
|
78
|
+
* );
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* Integration with UI framework
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // React example
|
|
85
|
+
* const askUserQuestion = createAskUserQuestionTool(
|
|
86
|
+
* async (question, options, multiSelect) => {
|
|
87
|
+
* return new Promise((resolve) => {
|
|
88
|
+
* setQuestion({ question, options, multiSelect, resolve });
|
|
89
|
+
* });
|
|
90
|
+
* }
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* // In your React component:
|
|
94
|
+
* function QuestionDialog({ question, options, multiSelect, resolve }) {
|
|
95
|
+
* const [selected, setSelected] = useState([]);
|
|
96
|
+
*
|
|
97
|
+
* const handleSubmit = () => {
|
|
98
|
+
* if (multiSelect) {
|
|
99
|
+
* resolve(selected);
|
|
100
|
+
* } else {
|
|
101
|
+
* resolve(selected[0]);
|
|
102
|
+
* }
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* // Render question UI...
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @category Tools
|
|
110
|
+
*/
|
|
111
|
+
export declare function createAskUserQuestionTool(onAskUser: AskUserCallback): import("ai").Tool<{
|
|
112
|
+
question: string;
|
|
113
|
+
options: QuestionOption[];
|
|
114
|
+
multiSelect?: boolean;
|
|
115
|
+
}, string>;
|
|
116
|
+
//# sourceMappingURL=user-interaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-interaction.d.ts","sourceRoot":"","sources":["../../src/tools/user-interaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,cAAc,EAAE,EACzB,WAAW,EAAE,OAAO,KACjB,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAMhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,eAAe;cA+BpD,MAAM;aACP,cAAc,EAAE;kBACX,OAAO;WAkC1B"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User interaction tools for agent-user communication.
|
|
3
|
+
*
|
|
4
|
+
* These tools allow agents to ask clarifying questions and get user input
|
|
5
|
+
* during execution. This enables interactive workflows where the agent
|
|
6
|
+
* needs additional information from the user to proceed.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { tool } from "ai";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// AskUserQuestion Tool
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Creates a tool for asking the user clarifying questions.
|
|
17
|
+
*
|
|
18
|
+
* This tool allows agents to request additional information from users
|
|
19
|
+
* during execution. It supports both single-select and multi-select
|
|
20
|
+
* questions with multiple choice options.
|
|
21
|
+
*
|
|
22
|
+
* The tool requires a callback function that handles the actual UI
|
|
23
|
+
* interaction with the user. The callback receives the question and
|
|
24
|
+
* options, prompts the user, and returns their selection.
|
|
25
|
+
*
|
|
26
|
+
* @param onAskUser - Callback function to handle user prompts
|
|
27
|
+
* @returns An AI SDK compatible tool for asking questions
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* Single-select question
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { createAskUserQuestionTool } from "@lleverage-ai/agent-sdk";
|
|
33
|
+
*
|
|
34
|
+
* const askUserQuestion = createAskUserQuestionTool(
|
|
35
|
+
* async (question, options, multiSelect) => {
|
|
36
|
+
* console.log(question);
|
|
37
|
+
* options.forEach((opt, i) => {
|
|
38
|
+
* console.log(`${i + 1}. ${opt.label}: ${opt.description}`);
|
|
39
|
+
* });
|
|
40
|
+
* const answer = await getUserInput(); // Your UI logic
|
|
41
|
+
* return options[answer - 1].value;
|
|
42
|
+
* }
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* const agent = createAgent({
|
|
46
|
+
* model,
|
|
47
|
+
* tools: { askUserQuestion },
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* Multi-select question
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const askUserQuestion = createAskUserQuestionTool(
|
|
55
|
+
* async (question, options, multiSelect) => {
|
|
56
|
+
* if (multiSelect) {
|
|
57
|
+
* // Show checkboxes, allow multiple selections
|
|
58
|
+
* const selected = await getUserMultipleChoices();
|
|
59
|
+
* return selected.map(i => options[i].value);
|
|
60
|
+
* }
|
|
61
|
+
* // Single select logic
|
|
62
|
+
* }
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* Integration with UI framework
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // React example
|
|
70
|
+
* const askUserQuestion = createAskUserQuestionTool(
|
|
71
|
+
* async (question, options, multiSelect) => {
|
|
72
|
+
* return new Promise((resolve) => {
|
|
73
|
+
* setQuestion({ question, options, multiSelect, resolve });
|
|
74
|
+
* });
|
|
75
|
+
* }
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* // In your React component:
|
|
79
|
+
* function QuestionDialog({ question, options, multiSelect, resolve }) {
|
|
80
|
+
* const [selected, setSelected] = useState([]);
|
|
81
|
+
*
|
|
82
|
+
* const handleSubmit = () => {
|
|
83
|
+
* if (multiSelect) {
|
|
84
|
+
* resolve(selected);
|
|
85
|
+
* } else {
|
|
86
|
+
* resolve(selected[0]);
|
|
87
|
+
* }
|
|
88
|
+
* };
|
|
89
|
+
*
|
|
90
|
+
* // Render question UI...
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @category Tools
|
|
95
|
+
*/
|
|
96
|
+
export function createAskUserQuestionTool(onAskUser) {
|
|
97
|
+
return tool({
|
|
98
|
+
description: "Ask the user a clarifying question with multiple choice options. Use this when you need additional information from the user to proceed.",
|
|
99
|
+
inputSchema: z.object({
|
|
100
|
+
question: z.string().describe("The question to ask the user. Should be clear and specific."),
|
|
101
|
+
options: z
|
|
102
|
+
.array(z.object({
|
|
103
|
+
label: z.string().describe("Display text for this option (concise, 1-5 words)"),
|
|
104
|
+
description: z
|
|
105
|
+
.string()
|
|
106
|
+
.optional()
|
|
107
|
+
.describe("Explanation of what this option means or what will happen"),
|
|
108
|
+
value: z.string().describe("Value to return if selected (can be same as label)"),
|
|
109
|
+
}))
|
|
110
|
+
.min(2)
|
|
111
|
+
.max(10)
|
|
112
|
+
.describe("Available answer options (2-10 options)"),
|
|
113
|
+
multiSelect: z
|
|
114
|
+
.boolean()
|
|
115
|
+
.optional()
|
|
116
|
+
.default(false)
|
|
117
|
+
.describe("Whether the user can select multiple options (default: false)"),
|
|
118
|
+
}),
|
|
119
|
+
execute: async ({ question, options, multiSelect = false, }) => {
|
|
120
|
+
// Validate options
|
|
121
|
+
if (options.length < 2) {
|
|
122
|
+
return "Error: At least 2 options are required for a question.";
|
|
123
|
+
}
|
|
124
|
+
if (options.length > 10) {
|
|
125
|
+
return "Error: Maximum 10 options allowed per question.";
|
|
126
|
+
}
|
|
127
|
+
// Call the user-provided callback to handle the interaction
|
|
128
|
+
const result = await onAskUser(question, options, multiSelect);
|
|
129
|
+
// Format the response
|
|
130
|
+
if (multiSelect && Array.isArray(result)) {
|
|
131
|
+
const selectedLabels = result
|
|
132
|
+
.map((value) => {
|
|
133
|
+
const option = options.find((opt) => opt.value === value);
|
|
134
|
+
return option?.label || value;
|
|
135
|
+
})
|
|
136
|
+
.join(", ");
|
|
137
|
+
return `User selected: ${selectedLabels}`;
|
|
138
|
+
}
|
|
139
|
+
if (typeof result === "string") {
|
|
140
|
+
const option = options.find((opt) => opt.value === result);
|
|
141
|
+
return `User selected: ${option?.label || result}`;
|
|
142
|
+
}
|
|
143
|
+
return `User selected: ${String(result)}`;
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=user-interaction.js.map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ools
|
|
5
|
+
* which have verbose prefixed names.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { Tool, ToolSet } from "ai";
|
|
10
|
+
import type { PluginOptions } from "../types.js";
|
|
11
|
+
/**
|
|
12
|
+
* A reference to a tool that can be resolved to a tool name.
|
|
13
|
+
*
|
|
14
|
+
* Can be:
|
|
15
|
+
* - A string (tool name directly)
|
|
16
|
+
* - A Tool object (name extracted from key when in a ToolSet)
|
|
17
|
+
* - A Plugin (all tool names extracted, or MCP tool names generated)
|
|
18
|
+
* - A ToolSet record (all keys extracted as tool names)
|
|
19
|
+
*
|
|
20
|
+
* @category Tools
|
|
21
|
+
*/
|
|
22
|
+
export type ToolReference = string | Tool | PluginOptions | ToolSet | ToolReference[];
|
|
23
|
+
/**
|
|
24
|
+
* Creates a helper for generating MCP tool names for a specific plugin.
|
|
25
|
+
*
|
|
26
|
+
* MCP tools are prefixed with `mcp__<plugin-name>__<tool-name>`. This helper
|
|
27
|
+
* makes it easier to reference these tools without typing the full name.
|
|
28
|
+
*
|
|
29
|
+
* @param pluginName - The MCP plugin name (e.g., "web-search")
|
|
30
|
+
* @returns A function that generates full MCP tool names
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const webSearch = mcpTools("web-search");
|
|
35
|
+
*
|
|
36
|
+
* const subagent = createSubagent(parent, {
|
|
37
|
+
* allowedTools: [webSearch("search"), webSearch("extract")],
|
|
38
|
+
* // Equivalent to: ["mcp__web-search__search", "mcp__web-search__extract"]
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category Tools
|
|
43
|
+
*/
|
|
44
|
+
export declare function mcpTools(pluginName: string): (toolName: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a helper for a specific MCP plugin with known tools.
|
|
47
|
+
*
|
|
48
|
+
* Returns an object with tool name properties for better IDE autocomplete.
|
|
49
|
+
*
|
|
50
|
+
* @param pluginName - The MCP plugin name
|
|
51
|
+
* @param toolNames - Array of tool names provided by the plugin
|
|
52
|
+
* @returns An object mapping tool names to their full MCP names
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const webSearch = mcpToolsFor("web-search", ["search", "extract"] as const);
|
|
57
|
+
*
|
|
58
|
+
* // Now you get autocomplete:
|
|
59
|
+
* webSearch.search // "mcp__web-search__search"
|
|
60
|
+
* webSearch.extract // "mcp__web-search__extract"
|
|
61
|
+
*
|
|
62
|
+
* const subagent = createSubagent(parent, {
|
|
63
|
+
* allowedTools: [webSearch.search, webSearch.extract],
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @category Tools
|
|
68
|
+
*/
|
|
69
|
+
export declare function mcpToolsFor<T extends readonly string[]>(pluginName: string, toolNames: T): {
|
|
70
|
+
[K in T[number]]: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Extracts tool names from a plugin.
|
|
74
|
+
*
|
|
75
|
+
* For regular plugins, extracts tool names from the tools property.
|
|
76
|
+
* For MCP plugins, generates tool names based on the plugin name and
|
|
77
|
+
* optionally specified tool names.
|
|
78
|
+
*
|
|
79
|
+
* @param plugin - The plugin to extract tool names from
|
|
80
|
+
* @param mcpToolNames - For MCP plugins, the specific tool names to include
|
|
81
|
+
* @returns Array of tool name strings
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Regular plugin with tools
|
|
86
|
+
* const names = toolsFromPlugin(myPlugin);
|
|
87
|
+
* // Returns: ["tool1", "tool2", ...]
|
|
88
|
+
*
|
|
89
|
+
* // MCP plugin with specific tools
|
|
90
|
+
* const names = toolsFromPlugin(webSearchPlugin, ["search", "extract"]);
|
|
91
|
+
* // Returns: ["mcp__web-search__search", "mcp__web-search__extract"]
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @category Tools
|
|
95
|
+
*/
|
|
96
|
+
export declare function toolsFromPlugin(plugin: PluginOptions, mcpToolNames?: string[]): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Extracts tool names from various sources.
|
|
99
|
+
*
|
|
100
|
+
* Accepts strings, plugins, tool sets, or arrays of these and returns
|
|
101
|
+
* a flat array of tool name strings.
|
|
102
|
+
*
|
|
103
|
+
* @param refs - Tool references to extract names from
|
|
104
|
+
* @returns Array of tool name strings
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Mix of different reference types
|
|
109
|
+
* const tools = toolsFrom(
|
|
110
|
+
* "read", // String
|
|
111
|
+
* "write",
|
|
112
|
+
* myPlugin, // Plugin (extracts tool names)
|
|
113
|
+
* { custom: customTool }, // ToolSet (extracts keys)
|
|
114
|
+
* );
|
|
115
|
+
*
|
|
116
|
+
* const subagent = createSubagent(parent, {
|
|
117
|
+
* allowedTools: tools,
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* @category Tools
|
|
122
|
+
*/
|
|
123
|
+
export declare function toolsFrom(...refs: ToolReference[]): string[];
|
|
124
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,aAAa,GAAG,OAAO,GAAG,aAAa,EAAE,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAEzE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EACrD,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,CAAC,GACX;KAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM;CAAE,CAM9B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAyBxF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,GAAG,IAAI,EAAE,aAAa,EAAE,GAAG,MAAM,EAAE,CA0B5D"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool utilities for improved developer experience.
|
|
3
|
+
*
|
|
4
|
+
* Provides helpers for working with tool names, especially for MCP tools
|
|
5
|
+
* which have verbose prefixed names.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Creates a helper for generating MCP tool names for a specific plugin.
|
|
11
|
+
*
|
|
12
|
+
* MCP tools are prefixed with `mcp__<plugin-name>__<tool-name>`. This helper
|
|
13
|
+
* makes it easier to reference these tools without typing the full name.
|
|
14
|
+
*
|
|
15
|
+
* @param pluginName - The MCP plugin name (e.g., "web-search")
|
|
16
|
+
* @returns A function that generates full MCP tool names
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const webSearch = mcpTools("web-search");
|
|
21
|
+
*
|
|
22
|
+
* const subagent = createSubagent(parent, {
|
|
23
|
+
* allowedTools: [webSearch("search"), webSearch("extract")],
|
|
24
|
+
* // Equivalent to: ["mcp__web-search__search", "mcp__web-search__extract"]
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @category Tools
|
|
29
|
+
*/
|
|
30
|
+
export function mcpTools(pluginName) {
|
|
31
|
+
return (toolName) => `mcp__${pluginName}__${toolName}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a helper for a specific MCP plugin with known tools.
|
|
35
|
+
*
|
|
36
|
+
* Returns an object with tool name properties for better IDE autocomplete.
|
|
37
|
+
*
|
|
38
|
+
* @param pluginName - The MCP plugin name
|
|
39
|
+
* @param toolNames - Array of tool names provided by the plugin
|
|
40
|
+
* @returns An object mapping tool names to their full MCP names
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const webSearch = mcpToolsFor("web-search", ["search", "extract"] as const);
|
|
45
|
+
*
|
|
46
|
+
* // Now you get autocomplete:
|
|
47
|
+
* webSearch.search // "mcp__web-search__search"
|
|
48
|
+
* webSearch.extract // "mcp__web-search__extract"
|
|
49
|
+
*
|
|
50
|
+
* const subagent = createSubagent(parent, {
|
|
51
|
+
* allowedTools: [webSearch.search, webSearch.extract],
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @category Tools
|
|
56
|
+
*/
|
|
57
|
+
export function mcpToolsFor(pluginName, toolNames) {
|
|
58
|
+
const result = {};
|
|
59
|
+
for (const name of toolNames) {
|
|
60
|
+
result[name] = `mcp__${pluginName}__${name}`;
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extracts tool names from a plugin.
|
|
66
|
+
*
|
|
67
|
+
* For regular plugins, extracts tool names from the tools property.
|
|
68
|
+
* For MCP plugins, generates tool names based on the plugin name and
|
|
69
|
+
* optionally specified tool names.
|
|
70
|
+
*
|
|
71
|
+
* @param plugin - The plugin to extract tool names from
|
|
72
|
+
* @param mcpToolNames - For MCP plugins, the specific tool names to include
|
|
73
|
+
* @returns Array of tool name strings
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Regular plugin with tools
|
|
78
|
+
* const names = toolsFromPlugin(myPlugin);
|
|
79
|
+
* // Returns: ["tool1", "tool2", ...]
|
|
80
|
+
*
|
|
81
|
+
* // MCP plugin with specific tools
|
|
82
|
+
* const names = toolsFromPlugin(webSearchPlugin, ["search", "extract"]);
|
|
83
|
+
* // Returns: ["mcp__web-search__search", "mcp__web-search__extract"]
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @category Tools
|
|
87
|
+
*/
|
|
88
|
+
export function toolsFromPlugin(plugin, mcpToolNames) {
|
|
89
|
+
// If it's an MCP plugin
|
|
90
|
+
if (plugin.mcpServer) {
|
|
91
|
+
if (!mcpToolNames || mcpToolNames.length === 0) {
|
|
92
|
+
throw new Error(`MCP plugin "${plugin.name}" requires explicit tool names. ` +
|
|
93
|
+
`Use toolsFromPlugin(plugin, ["toolName1", "toolName2"]) or mcpTools("${plugin.name}")("toolName").`);
|
|
94
|
+
}
|
|
95
|
+
const helper = mcpTools(plugin.name);
|
|
96
|
+
return mcpToolNames.map(helper);
|
|
97
|
+
}
|
|
98
|
+
// Regular plugin with tools
|
|
99
|
+
if (plugin.tools) {
|
|
100
|
+
if (typeof plugin.tools === "function") {
|
|
101
|
+
throw new Error(`Plugin "${plugin.name}" uses dynamic tools (StreamingToolsFactory). ` +
|
|
102
|
+
`Tool names cannot be extracted statically. Use string tool names instead.`);
|
|
103
|
+
}
|
|
104
|
+
return Object.keys(plugin.tools);
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Extracts tool names from various sources.
|
|
110
|
+
*
|
|
111
|
+
* Accepts strings, plugins, tool sets, or arrays of these and returns
|
|
112
|
+
* a flat array of tool name strings.
|
|
113
|
+
*
|
|
114
|
+
* @param refs - Tool references to extract names from
|
|
115
|
+
* @returns Array of tool name strings
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // Mix of different reference types
|
|
120
|
+
* const tools = toolsFrom(
|
|
121
|
+
* "read", // String
|
|
122
|
+
* "write",
|
|
123
|
+
* myPlugin, // Plugin (extracts tool names)
|
|
124
|
+
* { custom: customTool }, // ToolSet (extracts keys)
|
|
125
|
+
* );
|
|
126
|
+
*
|
|
127
|
+
* const subagent = createSubagent(parent, {
|
|
128
|
+
* allowedTools: tools,
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @category Tools
|
|
133
|
+
*/
|
|
134
|
+
export function toolsFrom(...refs) {
|
|
135
|
+
const names = [];
|
|
136
|
+
for (const ref of refs) {
|
|
137
|
+
if (typeof ref === "string") {
|
|
138
|
+
names.push(ref);
|
|
139
|
+
}
|
|
140
|
+
else if (Array.isArray(ref)) {
|
|
141
|
+
names.push(...toolsFrom(...ref));
|
|
142
|
+
}
|
|
143
|
+
else if (isPlugin(ref)) {
|
|
144
|
+
// For plugins, extract tool names (throws for MCP without explicit names)
|
|
145
|
+
try {
|
|
146
|
+
names.push(...toolsFromPlugin(ref));
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// MCP plugin without tool names - skip with warning
|
|
150
|
+
console.warn(`Skipping MCP plugin "${ref.name}" in toolsFrom(). ` +
|
|
151
|
+
`Use toolsFromPlugin(plugin, ["tool1", "tool2"]) for MCP plugins.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (isToolSet(ref)) {
|
|
155
|
+
names.push(...Object.keys(ref));
|
|
156
|
+
}
|
|
157
|
+
// Tool objects without names are skipped - they need to be in a ToolSet
|
|
158
|
+
}
|
|
159
|
+
return names;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Type guard to check if a value is a Plugin.
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
function isPlugin(value) {
|
|
166
|
+
return (typeof value === "object" &&
|
|
167
|
+
value !== null &&
|
|
168
|
+
"name" in value &&
|
|
169
|
+
typeof value.name === "string");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Type guard to check if a value is a ToolSet.
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
function isToolSet(value) {
|
|
176
|
+
if (typeof value !== "object" || value === null)
|
|
177
|
+
return false;
|
|
178
|
+
// A ToolSet is a Record<string, Tool>
|
|
179
|
+
// Check that it's not a Plugin (which also has string keys)
|
|
180
|
+
if ("name" in value && typeof value.name === "string") {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
// Check if all values look like tools (have execute function)
|
|
184
|
+
const entries = Object.entries(value);
|
|
185
|
+
if (entries.length === 0)
|
|
186
|
+
return false;
|
|
187
|
+
return entries.every(([, v]) => typeof v === "object" && v !== null && "execute" in v);
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/tools/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAkBH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAkB;IACzC,OAAO,CAAC,QAAgB,EAAE,EAAE,CAAC,QAAQ,UAAU,KAAK,QAAQ,EAAE,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,WAAW,CACzB,UAAkB,EAClB,SAAY;IAEZ,MAAM,MAAM,GAAG,EAAkC,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC5B,MAAiC,CAAC,IAAI,CAAC,GAAG,QAAQ,UAAU,KAAK,IAAI,EAAE,CAAC;IAC3E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,eAAe,CAAC,MAAqB,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,IAAI,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill definition helpers.
|
|
3
|
+
*
|
|
4
|
+
* Tools should be defined using AI SDK's `tool()` function directly.
|
|
5
|
+
* This module provides helpers for skills which provide contextual
|
|
6
|
+
* instructions and guidance for agents.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import type { SkillDefinition, SkillOptions, ToolSet } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Creates a skill definition for providing contextual instructions to agents.
|
|
13
|
+
*
|
|
14
|
+
* Skills serve multiple purposes:
|
|
15
|
+
* - **Tool guidance**: Bundle with plugin tools to explain how to use them
|
|
16
|
+
* - **Instructions only**: Load dynamic instructions without tools
|
|
17
|
+
* - **Progressive disclosure**: Include tools that load on-demand
|
|
18
|
+
*
|
|
19
|
+
* @param options - Configuration options for the skill
|
|
20
|
+
* @returns A skill definition object
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { defineSkill, definePlugin } from "@lleverage-ai/agent-sdk";
|
|
25
|
+
*
|
|
26
|
+
* // Skill that provides guidance for using plugin tools
|
|
27
|
+
* const dataSkill = defineSkill({
|
|
28
|
+
* name: "data-exploration",
|
|
29
|
+
* description: "Query and visualize data",
|
|
30
|
+
* prompt: `You have access to data exploration tools.
|
|
31
|
+
* Available tables: products, users, sales.
|
|
32
|
+
* Always use getSchema first to see column types.`,
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Bundle skill with tools in a plugin
|
|
36
|
+
* const dataPlugin = definePlugin({
|
|
37
|
+
* name: "data-explorer",
|
|
38
|
+
* tools: { getSchema, queryData },
|
|
39
|
+
* skills: [dataSkill],
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Skill with no tools - just loads instructions
|
|
43
|
+
* const guidelinesSkill = defineSkill({
|
|
44
|
+
* name: "guidelines",
|
|
45
|
+
* description: "Project coding standards",
|
|
46
|
+
* prompt: "Follow TypeScript strict mode and use named exports.",
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Skill with tools for progressive disclosure
|
|
50
|
+
* const analyzeSkill = defineSkill({
|
|
51
|
+
* name: "analyze",
|
|
52
|
+
* description: "Deep code analysis",
|
|
53
|
+
* prompt: "Perform detailed code analysis.",
|
|
54
|
+
* tools: {
|
|
55
|
+
* lint: tool({
|
|
56
|
+
* description: "Run linter",
|
|
57
|
+
* inputSchema: z.object({ path: z.string() }),
|
|
58
|
+
* execute: async ({ path }) => runLinter(path),
|
|
59
|
+
* }),
|
|
60
|
+
* },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @category Tools
|
|
65
|
+
*/
|
|
66
|
+
export declare function defineSkill(options: SkillOptions): SkillDefinition;
|
|
67
|
+
/**
|
|
68
|
+
* Helper type for tools that can be provided to skills.
|
|
69
|
+
* Re-exported from AI SDK for convenience.
|
|
70
|
+
*
|
|
71
|
+
* @category Tools
|
|
72
|
+
*/
|
|
73
|
+
export type { ToolSet };
|
|
74
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe,CAOlE;AAED;;;;;GAKG;AACH,YAAY,EAAE,OAAO,EAAE,CAAC"}
|