@lleverage-ai/agent-sdk 0.0.1 → 0.0.2-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -2160
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +32 -25
- package/dist/agent.js.map +1 -1
- package/dist/backend.d.ts +90 -68
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +22 -12
- package/dist/backend.js.map +1 -1
- package/dist/backends/filesystem.d.ts +153 -5
- package/dist/backends/filesystem.d.ts.map +1 -1
- package/dist/backends/filesystem.js +274 -1
- package/dist/backends/filesystem.js.map +1 -1
- package/dist/backends/index.d.ts +1 -2
- package/dist/backends/index.d.ts.map +1 -1
- package/dist/backends/index.js +1 -2
- package/dist/backends/index.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/security/index.d.ts +20 -20
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +26 -24
- package/dist/security/index.js.map +1 -1
- package/dist/tools/execute.d.ts +15 -9
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/execute.js +19 -9
- package/dist/tools/execute.js.map +1 -1
- package/dist/tools/factory.d.ts +48 -32
- package/dist/tools/factory.d.ts.map +1 -1
- package/dist/tools/factory.js +60 -43
- package/dist/tools/factory.js.map +1 -1
- package/dist/tools/index.d.ts +3 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/task.d.ts +49 -1
- package/dist/tools/task.d.ts.map +1 -1
- package/dist/tools/task.js +130 -3
- package/dist/tools/task.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -8
- package/dist/backends/sandbox.d.ts +0 -315
- package/dist/backends/sandbox.d.ts.map +0 -1
- package/dist/backends/sandbox.js +0 -490
- package/dist/backends/sandbox.js.map +0 -1
- package/dist/tools/user-interaction.d.ts +0 -116
- package/dist/tools/user-interaction.d.ts.map +0 -1
- package/dist/tools/user-interaction.js +0 -147
- package/dist/tools/user-interaction.js.map +0 -1
|
@@ -1,147 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-interaction.js","sourceRoot":"","sources":["../../src/tools/user-interaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH,MAAM,UAAU,yBAAyB,CAAC,SAA0B;IAClE,OAAO,IAAI,CAAC;QACV,WAAW,EACT,0IAA0I;QAC5I,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6DAA6D,CAAC;YAC5F,OAAO,EAAE,CAAC;iBACP,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;gBACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mDAAmD,CAAC;gBAC/E,WAAW,EAAE,CAAC;qBACX,MAAM,EAAE;qBACR,QAAQ,EAAE;qBACV,QAAQ,CAAC,2DAA2D,CAAC;gBACxE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;aACjF,CAAC,CACH;iBACA,GAAG,CAAC,CAAC,CAAC;iBACN,GAAG,CAAC,EAAE,CAAC;iBACP,QAAQ,CAAC,yCAAyC,CAAC;YACtD,WAAW,EAAE,CAAC;iBACX,OAAO,EAAE;iBACT,QAAQ,EAAE;iBACV,OAAO,CAAC,KAAK,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