lua-cli 2.2.8-alpha.2 → 2.3.0-alpha.2
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/API_REFERENCE.md +1408 -0
- package/CLI_REFERENCE.md +818 -0
- package/GETTING_STARTED.md +1040 -0
- package/README.md +738 -424
- package/TEMPLATE_GUIDE.md +1398 -0
- package/dist/api/agent.api.service.d.ts +33 -6
- package/dist/api/agent.api.service.js +27 -0
- package/dist/api/auth.api.service.d.ts +31 -2
- package/dist/api/auth.api.service.js +29 -0
- package/dist/api/basket.api.service.d.ts +53 -11
- package/dist/api/basket.api.service.js +63 -14
- package/dist/api/chat.api.service.d.ts +15 -3
- package/dist/api/chat.api.service.js +12 -0
- package/dist/api/credentials.d.ts +24 -0
- package/dist/api/credentials.js +46 -0
- package/dist/api/custom.data.api.service.d.ts +45 -9
- package/dist/api/custom.data.api.service.js +43 -9
- package/dist/api/lazy-instances.d.ts +49 -0
- package/dist/api/lazy-instances.js +95 -0
- package/dist/api/order.api.service.d.ts +34 -4
- package/dist/api/order.api.service.js +41 -3
- package/dist/api/products.api.service.d.ts +39 -9
- package/dist/api/products.api.service.js +43 -5
- package/dist/api/skills.api.service.d.ts +49 -2
- package/dist/api/skills.api.service.js +47 -1
- package/dist/api/tool.api.service.d.ts +39 -1
- package/dist/api/tool.api.service.js +38 -0
- package/dist/api/user.data.api.service.d.ts +23 -1
- package/dist/api/user.data.api.service.js +22 -0
- package/dist/api-exports.d.ts +236 -5
- package/dist/api-exports.js +264 -81
- package/dist/cli/command-definitions.d.ts +30 -0
- package/dist/cli/command-definitions.js +71 -0
- package/dist/commands/agents.d.ts +20 -0
- package/dist/commands/agents.js +24 -2
- package/dist/commands/apiKey.d.ts +23 -0
- package/dist/commands/apiKey.js +23 -0
- package/dist/commands/compile.d.ts +24 -0
- package/dist/commands/compile.js +67 -759
- package/dist/commands/configure.d.ts +24 -0
- package/dist/commands/configure.js +31 -96
- package/dist/commands/deploy.d.ts +31 -19
- package/dist/commands/deploy.js +45 -74
- package/dist/commands/destroy.d.ts +27 -0
- package/dist/commands/destroy.js +27 -1
- package/dist/commands/dev.d.ts +25 -62
- package/dist/commands/dev.js +58 -878
- package/dist/commands/init.d.ts +27 -0
- package/dist/commands/init.js +98 -260
- package/dist/commands/push.d.ts +24 -21
- package/dist/commands/push.js +39 -92
- package/dist/commands/test.d.ts +26 -0
- package/dist/commands/test.js +41 -188
- package/dist/common/basket.instance.d.ts +54 -3
- package/dist/common/basket.instance.js +56 -3
- package/dist/common/data.entry.instance.d.ts +25 -2
- package/dist/common/data.entry.instance.js +24 -0
- package/dist/common/http.client.d.ts +51 -1
- package/dist/common/http.client.js +50 -0
- package/dist/common/order.instance.d.ts +22 -0
- package/dist/common/order.instance.js +31 -4
- package/dist/common/product.instance.d.ts +22 -1
- package/dist/common/product.instance.js +24 -6
- package/dist/common/product.pagination.instance.d.ts +22 -2
- package/dist/common/product.pagination.instance.js +22 -1
- package/dist/common/product.search.instance.d.ts +13 -3
- package/dist/common/product.search.instance.js +12 -1
- package/dist/common/user.instance.d.ts +27 -3
- package/dist/common/user.instance.js +28 -7
- package/dist/config/auth.constants.d.ts +11 -0
- package/dist/config/auth.constants.js +11 -0
- package/dist/config/compile.constants.d.ts +67 -0
- package/dist/config/compile.constants.js +99 -0
- package/dist/config/constants.d.ts +5 -0
- package/dist/config/constants.js +5 -0
- package/dist/config/dev.constants.d.ts +65 -0
- package/dist/config/dev.constants.js +79 -0
- package/dist/config/init.constants.d.ts +23 -0
- package/dist/config/init.constants.js +41 -0
- package/dist/index.d.ts +19 -3
- package/dist/index.js +28 -44
- package/dist/interfaces/admin.d.ts +56 -50
- package/dist/interfaces/admin.js +4 -0
- package/dist/interfaces/agent.d.ts +21 -0
- package/dist/interfaces/agent.js +4 -0
- package/dist/interfaces/baskets.d.ts +60 -0
- package/dist/interfaces/baskets.js +12 -0
- package/dist/interfaces/chat.d.ts +48 -4
- package/dist/interfaces/chat.js +4 -0
- package/dist/interfaces/common.d.ts +62 -0
- package/dist/interfaces/common.js +8 -0
- package/dist/interfaces/compile.d.ts +11 -0
- package/dist/interfaces/compile.js +4 -0
- package/dist/interfaces/custom.data.d.ts +49 -19
- package/dist/interfaces/custom.data.js +4 -0
- package/dist/interfaces/deploy.d.ts +29 -0
- package/dist/interfaces/deploy.js +4 -0
- package/dist/interfaces/dev.d.ts +53 -0
- package/dist/interfaces/dev.js +5 -0
- package/dist/interfaces/init.d.ts +60 -0
- package/dist/interfaces/init.js +4 -0
- package/dist/interfaces/orders.d.ts +37 -0
- package/dist/interfaces/orders.js +12 -0
- package/dist/interfaces/product.d.ts +38 -10
- package/dist/interfaces/product.js +4 -0
- package/dist/interfaces/push.d.ts +26 -0
- package/dist/interfaces/push.js +4 -0
- package/dist/interfaces/test.d.ts +36 -0
- package/dist/interfaces/test.js +4 -0
- package/dist/services/auth.d.ts +54 -99
- package/dist/services/auth.js +76 -12
- package/dist/types/api-contracts.d.ts +211 -0
- package/dist/types/api-contracts.js +8 -0
- package/dist/types/compile.types.d.ts +76 -0
- package/dist/types/compile.types.js +4 -0
- package/dist/types/index.d.ts +23 -121
- package/dist/types/index.js +25 -14
- package/dist/types/skill.d.ts +142 -0
- package/dist/{skill.js → types/skill.js} +66 -17
- package/dist/types/tool-validation.d.ts +34 -0
- package/dist/types/tool-validation.js +42 -0
- package/dist/utils/auth-flows.d.ts +26 -0
- package/dist/utils/auth-flows.js +141 -0
- package/dist/utils/bundling.d.ts +36 -0
- package/dist/utils/bundling.js +137 -0
- package/dist/utils/compile.d.ts +37 -0
- package/dist/utils/compile.js +242 -0
- package/dist/utils/deploy-api.d.ts +26 -0
- package/dist/utils/deploy-api.js +53 -0
- package/dist/utils/deploy-helpers.d.ts +46 -0
- package/dist/utils/deploy-helpers.js +86 -0
- package/dist/utils/deployment.d.ts +25 -0
- package/dist/utils/deployment.js +161 -0
- package/dist/utils/dev-api.d.ts +61 -0
- package/dist/utils/dev-api.js +262 -0
- package/dist/utils/dev-helpers.d.ts +46 -0
- package/dist/utils/dev-helpers.js +83 -0
- package/dist/utils/dev-server.d.ts +24 -0
- package/dist/utils/dev-server.js +555 -0
- package/dist/utils/dev-watcher.d.ts +31 -0
- package/dist/utils/dev-watcher.js +110 -0
- package/dist/utils/files.js +0 -5
- package/dist/utils/init-agent.d.ts +34 -0
- package/dist/utils/init-agent.js +129 -0
- package/dist/utils/init-helpers.d.ts +41 -0
- package/dist/utils/init-helpers.js +73 -0
- package/dist/utils/init-prompts.d.ts +47 -0
- package/dist/utils/init-prompts.js +168 -0
- package/dist/utils/push-api.d.ts +15 -0
- package/dist/utils/push-api.js +48 -0
- package/dist/utils/push-helpers.d.ts +38 -0
- package/dist/utils/push-helpers.js +84 -0
- package/dist/utils/sandbox-storage.d.ts +27 -0
- package/dist/utils/sandbox-storage.js +71 -0
- package/dist/utils/sandbox.js +78 -114
- package/dist/utils/skill-management.d.ts +14 -0
- package/dist/utils/skill-management.js +148 -0
- package/dist/utils/test-helpers.d.ts +40 -0
- package/dist/utils/test-helpers.js +92 -0
- package/dist/utils/test-prompts.d.ts +23 -0
- package/dist/utils/test-prompts.js +186 -0
- package/dist/utils/tool-detection.d.ts +18 -0
- package/dist/utils/tool-detection.js +110 -0
- package/dist/web/app.css +941 -17
- package/dist/web/app.js +174 -22
- package/dist/web/index.html +7 -1
- package/package.json +13 -4
- package/template/QUICKSTART.md +299 -144
- package/template/README.md +928 -349
- package/template/TOOL_EXAMPLES.md +655 -0
- package/template/package-lock.json +5 -5
- package/template/package.json +1 -1
- package/template/src/index.ts +147 -207
- package/template/src/tools/BasketTool.ts +128 -0
- package/template/src/tools/CustomDataTool.ts +7 -13
- package/template/src/tools/OrderTool.ts +54 -0
- package/template/src/tools/PaymentTool.ts +1 -1
- package/template/src/tools/ProductsTool.ts +56 -118
- package/template/src/tools/UserDataTool.ts +4 -26
- package/dist/common/config.d.ts +0 -5
- package/dist/common/config.js +0 -5
- package/dist/custom-data-api.d.ts +0 -72
- package/dist/custom-data-api.js +0 -174
- package/dist/product-api.d.ts +0 -189
- package/dist/product-api.js +0 -141
- package/dist/services/api.d.ts +0 -549
- package/dist/services/api.js +0 -596
- package/dist/skill.d.ts +0 -50
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -2
- package/dist/user-data-api.d.ts +0 -39
- package/dist/user-data-api.js +0 -50
- package/template/API.md +0 -604
- package/template/DEVELOPER.md +0 -771
- package/template/lua.skill.yaml +0 -7
package/dist/commands/test.js
CHANGED
|
@@ -1,230 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Test Command
|
|
3
|
+
* Orchestrates the testing of individual tools in a local sandbox environment
|
|
4
|
+
*/
|
|
4
5
|
import { compileCommand } from "./compile.js";
|
|
5
|
-
import { gunzipSync } from "zlib";
|
|
6
|
-
import { Buffer } from "buffer";
|
|
7
6
|
import { withErrorHandling, clearPromptLines, writeProgress, writeSuccess } from "../utils/cli.js";
|
|
8
7
|
import { loadApiKey } from "../services/auth.js";
|
|
9
8
|
import { executeTool, loadEnvironmentVariables } from "../utils/sandbox.js";
|
|
10
9
|
import { readSkillConfig } from "../utils/files.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
import { decompressCode, readDeployJson, extractToolsFromDeployData, hasEnvFile, hasConfigEnvVars, } from "../utils/test-helpers.js";
|
|
11
|
+
import { promptToolSelection, generatePromptsForObject } from "../utils/test-prompts.js";
|
|
12
|
+
/**
|
|
13
|
+
* Main test command - tests a tool in a local sandbox environment.
|
|
14
|
+
*
|
|
15
|
+
* This command performs the following steps:
|
|
16
|
+
* 1. Compiles the skill to ensure latest code
|
|
17
|
+
* 2. Loads deploy.json with tool definitions
|
|
18
|
+
* 3. Extracts all available tools
|
|
19
|
+
* 4. Prompts user to select a tool
|
|
20
|
+
* 5. Collects input values based on tool's input schema
|
|
21
|
+
* 6. Executes the tool in a sandboxed environment
|
|
22
|
+
* 7. Displays the results
|
|
23
|
+
*
|
|
24
|
+
* Features:
|
|
25
|
+
* - Interactive tool selection from compiled tools
|
|
26
|
+
* - Dynamic input prompts based on tool schemas
|
|
27
|
+
* - Support for nested object inputs
|
|
28
|
+
* - Environment variable injection
|
|
29
|
+
* - Secure sandbox execution
|
|
30
|
+
* - Detailed error reporting
|
|
31
|
+
*
|
|
32
|
+
* @returns Promise that resolves when test completes
|
|
33
|
+
*/
|
|
16
34
|
export async function testCommand() {
|
|
17
35
|
return withErrorHandling(async () => {
|
|
18
36
|
writeProgress("🧪 Testing Lua skill...");
|
|
19
|
-
//
|
|
37
|
+
// Step 1: Compile the code
|
|
20
38
|
writeProgress("📦 Compiling code first...");
|
|
21
39
|
await compileCommand();
|
|
22
|
-
//
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
// Read deploy.json
|
|
28
|
-
const deployJsonPath = path.join(luaDir, "deploy.json");
|
|
29
|
-
if (!fs.existsSync(deployJsonPath)) {
|
|
30
|
-
throw new Error("deploy.json not found. Run 'lua compile' first.");
|
|
31
|
-
}
|
|
32
|
-
const deployData = JSON.parse(fs.readFileSync(deployJsonPath, "utf8"));
|
|
33
|
-
// Extract all tools from deploy.json (handle both new and legacy formats)
|
|
34
|
-
let allTools = [];
|
|
35
|
-
if (deployData.skills && Array.isArray(deployData.skills)) {
|
|
36
|
-
// New format: extract tools from skills array
|
|
37
|
-
deployData.skills.forEach((skill) => {
|
|
38
|
-
if (skill.tools && Array.isArray(skill.tools)) {
|
|
39
|
-
skill.tools.forEach((tool) => {
|
|
40
|
-
allTools.push({
|
|
41
|
-
...tool,
|
|
42
|
-
skillName: skill.name // Add skill context
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else if (deployData.tools) {
|
|
49
|
-
// Legacy format: tools as object or array
|
|
50
|
-
if (Array.isArray(deployData.tools)) {
|
|
51
|
-
allTools = deployData.tools;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
// Convert tools object to array
|
|
55
|
-
allTools = Object.entries(deployData.tools).map(([name, tool]) => ({
|
|
56
|
-
name,
|
|
57
|
-
...tool
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (allTools.length === 0) {
|
|
62
|
-
throw new Error("No tools found in deploy.json");
|
|
63
|
-
}
|
|
64
|
-
// Get API key from keystore and agent ID from YAML
|
|
40
|
+
// Step 2: Load deploy data and extract tools
|
|
41
|
+
const deployData = readDeployJson();
|
|
42
|
+
const allTools = extractToolsFromDeployData(deployData);
|
|
43
|
+
// Step 3: Load authentication and configuration
|
|
65
44
|
const apiKey = await loadApiKey();
|
|
66
45
|
if (!apiKey) {
|
|
67
46
|
throw new Error("No API key found. Please run 'lua auth configure' first.");
|
|
68
47
|
}
|
|
69
|
-
// Extract environment variables from YAML config
|
|
70
48
|
const config = readSkillConfig();
|
|
71
49
|
const agentId = config?.agent?.agentId;
|
|
72
50
|
if (!agentId) {
|
|
73
51
|
throw new Error("No agent ID found in lua.skill.yaml. Please run 'lua init' first.");
|
|
74
52
|
}
|
|
75
|
-
// Load environment variables
|
|
53
|
+
// Step 4: Load environment variables
|
|
76
54
|
const envVars = loadEnvironmentVariables();
|
|
77
|
-
if (
|
|
55
|
+
if (hasEnvFile()) {
|
|
78
56
|
writeProgress(`📄 Loaded environment variables from .env file`);
|
|
79
57
|
}
|
|
80
|
-
if (
|
|
58
|
+
if (hasConfigEnvVars(config)) {
|
|
81
59
|
writeProgress(`📄 Loaded environment variables from lua.skill.yaml`);
|
|
82
60
|
}
|
|
83
|
-
// Let user select a tool
|
|
84
|
-
const
|
|
85
|
-
name: tool.skillName ? `${tool.name} (${tool.skillName}) - ${tool.description}` : `${tool.name} - ${tool.description}`,
|
|
86
|
-
value: tool
|
|
87
|
-
}));
|
|
88
|
-
const { selectedTool } = await inquirer.prompt([
|
|
89
|
-
{
|
|
90
|
-
type: 'list',
|
|
91
|
-
name: 'selectedTool',
|
|
92
|
-
message: '🔧 Select a tool to test:',
|
|
93
|
-
choices: toolChoices,
|
|
94
|
-
pageSize: 10
|
|
95
|
-
}
|
|
96
|
-
]);
|
|
97
|
-
// Clear the tool selection prompt lines
|
|
61
|
+
// Step 5: Let user select a tool
|
|
62
|
+
const selectedTool = await promptToolSelection(allTools);
|
|
98
63
|
clearPromptLines(2);
|
|
99
64
|
writeProgress(`✅ Selected tool: ${selectedTool.name}`);
|
|
100
|
-
//
|
|
65
|
+
// Step 6: Collect input values based on schema
|
|
101
66
|
let inputValues = {};
|
|
102
67
|
const inputSchema = selectedTool.inputSchema;
|
|
103
68
|
if (inputSchema.properties) {
|
|
104
69
|
writeProgress("\n📝 Enter input values:");
|
|
105
|
-
// Recursive function to generate prompts for nested objects
|
|
106
|
-
async function generatePromptsForObject(schema, prefix = '', required = []) {
|
|
107
|
-
const prompts = [];
|
|
108
|
-
const result = {};
|
|
109
|
-
for (const [key, value] of Object.entries(schema.properties || {})) {
|
|
110
|
-
const property = value;
|
|
111
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
112
|
-
const isRequired = required.includes(key);
|
|
113
|
-
if (property.type === "object" && property.properties) {
|
|
114
|
-
// Handle nested object - use fullKey to maintain proper prompt names
|
|
115
|
-
writeProgress(`\n📋 Entering values for ${key}:`);
|
|
116
|
-
const nestedResult = await generatePromptsForObject(property, fullKey, property.required || []);
|
|
117
|
-
// Extract the nested values from the nested result
|
|
118
|
-
result[key] = nestedResult[key] || nestedResult;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// Handle primitive types
|
|
122
|
-
let promptType = 'input';
|
|
123
|
-
let validate = undefined;
|
|
124
|
-
switch (property.type) {
|
|
125
|
-
case "string":
|
|
126
|
-
if (isRequired) {
|
|
127
|
-
validate = (input) => input.trim() !== "" || `${key} is required`;
|
|
128
|
-
}
|
|
129
|
-
break;
|
|
130
|
-
case "number":
|
|
131
|
-
promptType = 'number';
|
|
132
|
-
if (isRequired) {
|
|
133
|
-
validate = (input) => !isNaN(input) || `${key} must be a valid number`;
|
|
134
|
-
}
|
|
135
|
-
break;
|
|
136
|
-
case "boolean":
|
|
137
|
-
promptType = 'confirm';
|
|
138
|
-
break;
|
|
139
|
-
default:
|
|
140
|
-
if (isRequired) {
|
|
141
|
-
validate = (input) => input.trim() !== "" || `${key} is required`;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const prompt = {
|
|
145
|
-
type: promptType,
|
|
146
|
-
name: fullKey,
|
|
147
|
-
message: `${key}${isRequired ? " (required)" : " (optional)"}:`,
|
|
148
|
-
validate: validate,
|
|
149
|
-
};
|
|
150
|
-
prompts.push(prompt);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (prompts.length > 0) {
|
|
154
|
-
const answers = await inquirer.prompt(prompts);
|
|
155
|
-
// Convert answers to proper types and structure
|
|
156
|
-
for (const [key, value] of Object.entries(answers)) {
|
|
157
|
-
const keyParts = key.split('.');
|
|
158
|
-
const propertyKey = keyParts[keyParts.length - 1];
|
|
159
|
-
// For nested properties, we need to find the property in the original schema
|
|
160
|
-
let currentSchema = inputSchema; // Use the original inputSchema
|
|
161
|
-
let currentProperty = null;
|
|
162
|
-
// Navigate through nested schemas to find the property
|
|
163
|
-
for (let i = 0; i < keyParts.length; i++) {
|
|
164
|
-
const part = keyParts[i];
|
|
165
|
-
if (currentSchema.properties && currentSchema.properties[part]) {
|
|
166
|
-
currentProperty = currentSchema.properties[part];
|
|
167
|
-
if (i < keyParts.length - 1) {
|
|
168
|
-
// Move to nested schema
|
|
169
|
-
currentSchema = currentProperty;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (currentProperty) {
|
|
174
|
-
let convertedValue = value;
|
|
175
|
-
switch (currentProperty.type) {
|
|
176
|
-
case "number":
|
|
177
|
-
convertedValue = parseFloat(value);
|
|
178
|
-
break;
|
|
179
|
-
case "boolean":
|
|
180
|
-
convertedValue = value;
|
|
181
|
-
break;
|
|
182
|
-
default:
|
|
183
|
-
convertedValue = value;
|
|
184
|
-
}
|
|
185
|
-
// Check if field is optional and value is empty - skip if so
|
|
186
|
-
// For nested properties, check the parent schema's required fields
|
|
187
|
-
const parentSchema = keyParts.length > 1 ? currentSchema : schema;
|
|
188
|
-
const isOptional = !parentSchema.required || !parentSchema.required.includes(propertyKey);
|
|
189
|
-
const isEmpty = convertedValue === '' || convertedValue === null || convertedValue === undefined;
|
|
190
|
-
if (isOptional && isEmpty) {
|
|
191
|
-
// Skip optional empty fields
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
// Build nested structure
|
|
195
|
-
if (keyParts.length === 1) {
|
|
196
|
-
// Top-level property
|
|
197
|
-
result[propertyKey] = convertedValue;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
// Nested property - build the nested structure
|
|
201
|
-
let current = result;
|
|
202
|
-
for (let i = 0; i < keyParts.length - 1; i++) {
|
|
203
|
-
const part = keyParts[i];
|
|
204
|
-
if (!current[part]) {
|
|
205
|
-
current[part] = {};
|
|
206
|
-
}
|
|
207
|
-
current = current[part];
|
|
208
|
-
}
|
|
209
|
-
current[propertyKey] = convertedValue;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
70
|
inputValues = await generatePromptsForObject(inputSchema, '', inputSchema.required || []);
|
|
217
71
|
}
|
|
72
|
+
// Step 7: Execute the tool
|
|
218
73
|
writeProgress("\n🚀 Executing tool...");
|
|
219
74
|
writeProgress(`Input: ${JSON.stringify(inputValues, null, 2)}`);
|
|
220
|
-
// Get the execute function string directly from the selected tool and decompress it
|
|
221
75
|
const toolCode = decompressCode(selectedTool.execute);
|
|
222
|
-
// Set environment variables
|
|
76
|
+
// Set environment variables for sandbox
|
|
223
77
|
const originalEnv = { ...process.env };
|
|
224
78
|
for (const [key, value] of Object.entries(envVars)) {
|
|
225
79
|
process.env[key] = value;
|
|
226
80
|
}
|
|
227
|
-
// Execute the tool
|
|
228
81
|
try {
|
|
229
82
|
const result = await executeTool({
|
|
230
83
|
toolCode,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { Basket, BasketItem, BasketStatus } from "../interfaces/baskets";
|
|
2
|
-
import { BasketAPI } from "../types";
|
|
3
|
-
import OrderInstance from "./order.instance";
|
|
1
|
+
import { Basket, BasketItem, BasketStatus } from "../interfaces/baskets.js";
|
|
2
|
+
import { BasketAPI } from "../types/index.js";
|
|
3
|
+
import OrderInstance from "./order.instance.js";
|
|
4
|
+
/**
|
|
5
|
+
* Basket instance class providing a fluent API for managing user baskets
|
|
6
|
+
* Provides methods for adding/removing items, updating metadata, and placing orders
|
|
7
|
+
*/
|
|
4
8
|
export default class BasketInstance {
|
|
5
9
|
private id;
|
|
6
10
|
private userId;
|
|
@@ -12,16 +16,63 @@ export default class BasketInstance {
|
|
|
12
16
|
itemCount: number;
|
|
13
17
|
status: BasketStatus;
|
|
14
18
|
private basketAPI;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new BasketInstance
|
|
21
|
+
* @param api - The BasketAPI instance for making API calls
|
|
22
|
+
* @param basket - The basket data from the API
|
|
23
|
+
*/
|
|
15
24
|
constructor(api: BasketAPI, basket: Basket);
|
|
16
25
|
/**
|
|
17
26
|
* Custom toJSON method to control what gets serialized when logging
|
|
27
|
+
* @returns Serialized basket data combining data and common fields
|
|
18
28
|
*/
|
|
19
29
|
toJSON(): Record<string, any>;
|
|
30
|
+
/**
|
|
31
|
+
* Updates the basket's metadata
|
|
32
|
+
* @param metadata - The metadata object to merge with existing metadata
|
|
33
|
+
* @returns Promise resolving to the updated basket data
|
|
34
|
+
* @throws Error if the metadata update fails
|
|
35
|
+
*/
|
|
20
36
|
updateMetadata(metadata: any): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Updates the basket's status
|
|
39
|
+
* @param status - The new basket status to set
|
|
40
|
+
* @returns Promise resolving to the updated basket data
|
|
41
|
+
* @throws Error if the status update fails
|
|
42
|
+
*/
|
|
21
43
|
updateStatus(status: BasketStatus): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Updates the basket instance with new data from the API
|
|
46
|
+
* @param basket - The updated basket data from the API
|
|
47
|
+
* @returns The combined basket data and common fields
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
22
50
|
private updateBasket;
|
|
51
|
+
/**
|
|
52
|
+
* Adds an item to the basket
|
|
53
|
+
* @param item - The basket item to add (must include productId and quantity)
|
|
54
|
+
* @returns Promise resolving to the updated basket data
|
|
55
|
+
* @throws Error if the item cannot be added
|
|
56
|
+
*/
|
|
23
57
|
addItem(item: BasketItem): Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Removes an item from the basket
|
|
60
|
+
* @param itemId - The unique identifier of the item to remove
|
|
61
|
+
* @returns Promise resolving to the updated basket data
|
|
62
|
+
* @throws Error if the item cannot be removed or is not found
|
|
63
|
+
*/
|
|
24
64
|
removeItem(itemId: string): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Clears all items from the basket
|
|
67
|
+
* @returns Promise resolving to the updated empty basket data
|
|
68
|
+
* @throws Error if the clear operation fails
|
|
69
|
+
*/
|
|
25
70
|
clear(): Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Places an order from the basket contents
|
|
73
|
+
* @param data - Additional order data (shipping info, payment details, etc.)
|
|
74
|
+
* @returns Promise resolving to an OrderInstance representing the created order
|
|
75
|
+
* @throws Error if the order creation fails
|
|
76
|
+
*/
|
|
26
77
|
placeOrder(data: Record<string, any>): Promise<OrderInstance>;
|
|
27
78
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { BasketStatus } from "../interfaces/baskets";
|
|
1
|
+
import { BasketStatus } from "../interfaces/baskets.js";
|
|
2
|
+
/**
|
|
3
|
+
* Basket instance class providing a fluent API for managing user baskets
|
|
4
|
+
* Provides methods for adding/removing items, updating metadata, and placing orders
|
|
5
|
+
*/
|
|
2
6
|
export default class BasketInstance {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new BasketInstance
|
|
9
|
+
* @param api - The BasketAPI instance for making API calls
|
|
10
|
+
* @param basket - The basket data from the API
|
|
11
|
+
*/
|
|
3
12
|
constructor(api, basket) {
|
|
4
13
|
this.data = basket.data;
|
|
5
14
|
this.common = basket.common;
|
|
@@ -20,32 +29,54 @@ export default class BasketInstance {
|
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
31
|
* Custom toJSON method to control what gets serialized when logging
|
|
32
|
+
* @returns Serialized basket data combining data and common fields
|
|
23
33
|
*/
|
|
24
34
|
toJSON() {
|
|
25
35
|
return {
|
|
26
36
|
...this.data,
|
|
27
|
-
...this.common
|
|
37
|
+
...this.common,
|
|
38
|
+
id: this.id
|
|
28
39
|
};
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
42
|
* Custom inspect method for Node.js console.log
|
|
43
|
+
* @returns Formatted basket data for console output
|
|
32
44
|
*/
|
|
33
45
|
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
34
46
|
return {
|
|
35
47
|
...this.data,
|
|
36
48
|
...this.common,
|
|
49
|
+
id: this.id
|
|
37
50
|
};
|
|
38
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Updates the basket's metadata
|
|
54
|
+
* @param metadata - The metadata object to merge with existing metadata
|
|
55
|
+
* @returns Promise resolving to the updated basket data
|
|
56
|
+
* @throws Error if the metadata update fails
|
|
57
|
+
*/
|
|
39
58
|
async updateMetadata(metadata) {
|
|
40
59
|
await this.basketAPI.updateMetadata(this.id, metadata);
|
|
41
60
|
this.data.metadata = { ...this.data.metadata, ...metadata };
|
|
42
61
|
return { ...this.data, ...this.common };
|
|
43
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Updates the basket's status
|
|
65
|
+
* @param status - The new basket status to set
|
|
66
|
+
* @returns Promise resolving to the updated basket data
|
|
67
|
+
* @throws Error if the status update fails
|
|
68
|
+
*/
|
|
44
69
|
async updateStatus(status) {
|
|
45
70
|
await this.basketAPI.updateStatus(this.id, status);
|
|
46
71
|
this.common.status = status;
|
|
47
72
|
return { ...this.data, ...this.common };
|
|
48
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Updates the basket instance with new data from the API
|
|
76
|
+
* @param basket - The updated basket data from the API
|
|
77
|
+
* @returns The combined basket data and common fields
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
49
80
|
updateBasket(basket) {
|
|
50
81
|
this.data = basket.data;
|
|
51
82
|
this.common = basket.common;
|
|
@@ -58,21 +89,43 @@ export default class BasketInstance {
|
|
|
58
89
|
this.status = basket.common.status;
|
|
59
90
|
return { ...this.data, ...this.common };
|
|
60
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Adds an item to the basket
|
|
94
|
+
* @param item - The basket item to add (must include productId and quantity)
|
|
95
|
+
* @returns Promise resolving to the updated basket data
|
|
96
|
+
* @throws Error if the item cannot be added
|
|
97
|
+
*/
|
|
61
98
|
async addItem(item) {
|
|
62
99
|
const basket = await this.basketAPI.addItem(this.id, item);
|
|
63
100
|
return this.updateBasket(basket);
|
|
64
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Removes an item from the basket
|
|
104
|
+
* @param itemId - The unique identifier of the item to remove
|
|
105
|
+
* @returns Promise resolving to the updated basket data
|
|
106
|
+
* @throws Error if the item cannot be removed or is not found
|
|
107
|
+
*/
|
|
65
108
|
async removeItem(itemId) {
|
|
66
109
|
const basket = await this.basketAPI.removeItem(this.id, itemId);
|
|
67
110
|
return this.updateBasket(basket);
|
|
68
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Clears all items from the basket
|
|
114
|
+
* @returns Promise resolving to the updated empty basket data
|
|
115
|
+
* @throws Error if the clear operation fails
|
|
116
|
+
*/
|
|
69
117
|
async clear() {
|
|
70
118
|
const basket = await this.basketAPI.clear(this.id);
|
|
71
119
|
return this.updateBasket(basket);
|
|
72
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Places an order from the basket contents
|
|
123
|
+
* @param data - Additional order data (shipping info, payment details, etc.)
|
|
124
|
+
* @returns Promise resolving to an OrderInstance representing the created order
|
|
125
|
+
* @throws Error if the order creation fails
|
|
126
|
+
*/
|
|
73
127
|
async placeOrder(data) {
|
|
74
128
|
const order = await this.basketAPI.placeOrder(data, this.id);
|
|
75
|
-
console.log('order', order);
|
|
76
129
|
await this.updateStatus(BasketStatus.CHECKED_OUT);
|
|
77
130
|
return order;
|
|
78
131
|
}
|
|
@@ -1,16 +1,39 @@
|
|
|
1
|
-
import { CustomDataAPI } from "../types";
|
|
2
|
-
import { CreateCustomDataResponse } from "../interfaces/custom.data";
|
|
1
|
+
import { CustomDataAPI } from "../types/index.js";
|
|
2
|
+
import { CreateCustomDataResponse } from "../interfaces/custom.data.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data entry instance class providing a fluent API for managing custom data entries
|
|
5
|
+
* Provides methods for updating and deleting individual data entries
|
|
6
|
+
*/
|
|
3
7
|
export default class DataEntryInstance {
|
|
4
8
|
data: Record<string, any>;
|
|
5
9
|
id: string;
|
|
6
10
|
collectionName: string;
|
|
7
11
|
score?: number;
|
|
8
12
|
private customDataAPI;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new DataEntryInstance
|
|
15
|
+
* @param api - The CustomDataAPI instance for making API calls
|
|
16
|
+
* @param entry - The custom data entry response from the API
|
|
17
|
+
* @param collectionName - The name of the collection this entry belongs to
|
|
18
|
+
*/
|
|
9
19
|
constructor(api: CustomDataAPI, entry: CreateCustomDataResponse, collectionName: string);
|
|
10
20
|
/**
|
|
11
21
|
* Custom toJSON method to control what gets serialized when logging
|
|
22
|
+
* @returns Serialized data entry including score if available
|
|
12
23
|
*/
|
|
13
24
|
toJSON(): Record<string, any>;
|
|
25
|
+
/**
|
|
26
|
+
* Updates the custom data entry
|
|
27
|
+
* @param data - The data fields to update (partial update supported)
|
|
28
|
+
* @param searchText - Optional new search text for semantic search indexing
|
|
29
|
+
* @returns Promise resolving to the updated data
|
|
30
|
+
* @throws Error if the update fails
|
|
31
|
+
*/
|
|
14
32
|
update(data: Record<string, any>, searchText?: string): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Deletes the custom data entry
|
|
35
|
+
* @returns Promise resolving to true if deletion was successful
|
|
36
|
+
* @throws Error if the deletion fails
|
|
37
|
+
*/
|
|
15
38
|
delete(): Promise<boolean>;
|
|
16
39
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data entry instance class providing a fluent API for managing custom data entries
|
|
3
|
+
* Provides methods for updating and deleting individual data entries
|
|
4
|
+
*/
|
|
1
5
|
export default class DataEntryInstance {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new DataEntryInstance
|
|
8
|
+
* @param api - The CustomDataAPI instance for making API calls
|
|
9
|
+
* @param entry - The custom data entry response from the API
|
|
10
|
+
* @param collectionName - The name of the collection this entry belongs to
|
|
11
|
+
*/
|
|
2
12
|
constructor(api, entry, collectionName) {
|
|
3
13
|
this.data = entry.data;
|
|
4
14
|
this.id = entry.id;
|
|
@@ -14,6 +24,7 @@ export default class DataEntryInstance {
|
|
|
14
24
|
}
|
|
15
25
|
/**
|
|
16
26
|
* Custom toJSON method to control what gets serialized when logging
|
|
27
|
+
* @returns Serialized data entry including score if available
|
|
17
28
|
*/
|
|
18
29
|
toJSON() {
|
|
19
30
|
return {
|
|
@@ -23,6 +34,7 @@ export default class DataEntryInstance {
|
|
|
23
34
|
}
|
|
24
35
|
/**
|
|
25
36
|
* Custom inspect method for Node.js console.log
|
|
37
|
+
* @returns Formatted data entry for console output
|
|
26
38
|
*/
|
|
27
39
|
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
28
40
|
return {
|
|
@@ -30,6 +42,13 @@ export default class DataEntryInstance {
|
|
|
30
42
|
score: this.score
|
|
31
43
|
};
|
|
32
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Updates the custom data entry
|
|
47
|
+
* @param data - The data fields to update (partial update supported)
|
|
48
|
+
* @param searchText - Optional new search text for semantic search indexing
|
|
49
|
+
* @returns Promise resolving to the updated data
|
|
50
|
+
* @throws Error if the update fails
|
|
51
|
+
*/
|
|
33
52
|
async update(data, searchText) {
|
|
34
53
|
try {
|
|
35
54
|
const response = await this.customDataAPI.update(this.collectionName, this.id, { data, searchText });
|
|
@@ -40,6 +59,11 @@ export default class DataEntryInstance {
|
|
|
40
59
|
throw new Error('Failed to update user data');
|
|
41
60
|
}
|
|
42
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Deletes the custom data entry
|
|
64
|
+
* @returns Promise resolving to true if deletion was successful
|
|
65
|
+
* @throws Error if the deletion fails
|
|
66
|
+
*/
|
|
43
67
|
async delete() {
|
|
44
68
|
try {
|
|
45
69
|
await this.customDataAPI.delete(this.collectionName, this.id);
|
|
@@ -1,14 +1,64 @@
|
|
|
1
|
-
import { ApiResponse } from "../interfaces/
|
|
1
|
+
import { ApiResponse } from "../interfaces/common.js";
|
|
2
2
|
/**
|
|
3
3
|
* Generic HTTP client with common error handling
|
|
4
|
+
* Provides a base class for all API service classes with standardized HTTP methods
|
|
4
5
|
*/
|
|
5
6
|
export declare abstract class HttpClient {
|
|
6
7
|
protected baseUrl: string;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an instance of HttpClient
|
|
10
|
+
* @param baseUrl - The base URL for all API requests
|
|
11
|
+
*/
|
|
7
12
|
constructor(baseUrl: string);
|
|
13
|
+
/**
|
|
14
|
+
* Makes an HTTP request with standardized error handling
|
|
15
|
+
* @param url - The full URL to request
|
|
16
|
+
* @param options - Fetch API request options
|
|
17
|
+
* @returns Promise resolving to an ApiResponse with typed data
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
8
20
|
private request;
|
|
21
|
+
/**
|
|
22
|
+
* Performs an HTTP GET request
|
|
23
|
+
* @param url - The relative URL path to request (will be appended to baseUrl)
|
|
24
|
+
* @param headers - Optional HTTP headers to include in the request
|
|
25
|
+
* @returns Promise resolving to an ApiResponse with typed data
|
|
26
|
+
* @protected
|
|
27
|
+
*/
|
|
9
28
|
protected httpGet<T>(url: string, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
29
|
+
/**
|
|
30
|
+
* Performs an HTTP POST request
|
|
31
|
+
* @param url - The relative URL path to request (will be appended to baseUrl)
|
|
32
|
+
* @param data - Optional request body data (will be JSON stringified)
|
|
33
|
+
* @param headers - Optional HTTP headers to include in the request
|
|
34
|
+
* @returns Promise resolving to an ApiResponse with typed data
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
10
37
|
protected httpPost<T>(url: string, data?: any, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
38
|
+
/**
|
|
39
|
+
* Performs an HTTP PUT request
|
|
40
|
+
* @param url - The relative URL path to request (will be appended to baseUrl)
|
|
41
|
+
* @param data - Optional request body data (will be JSON stringified)
|
|
42
|
+
* @param headers - Optional HTTP headers to include in the request
|
|
43
|
+
* @returns Promise resolving to an ApiResponse with typed data
|
|
44
|
+
* @protected
|
|
45
|
+
*/
|
|
11
46
|
protected httpPut<T>(url: string, data?: any, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
47
|
+
/**
|
|
48
|
+
* Performs an HTTP DELETE request
|
|
49
|
+
* @param url - The relative URL path to request (will be appended to baseUrl)
|
|
50
|
+
* @param headers - Optional HTTP headers to include in the request
|
|
51
|
+
* @returns Promise resolving to an ApiResponse with typed data
|
|
52
|
+
* @protected
|
|
53
|
+
*/
|
|
12
54
|
protected httpDelete<T>(url: string, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* Performs an HTTP PATCH request
|
|
57
|
+
* @param url - The relative URL path to request (will be appended to baseUrl)
|
|
58
|
+
* @param data - Optional request body data (will be JSON stringified)
|
|
59
|
+
* @param headers - Optional HTTP headers to include in the request
|
|
60
|
+
* @returns Promise resolving to an ApiResponse with typed data
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
13
63
|
protected httpPatch<T>(url: string, data?: any, headers?: Record<string, string>): Promise<ApiResponse<T>>;
|
|
14
64
|
}
|