lua-cli 2.5.7 → 3.0.0-alpha.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/dist/api/agent.api.service.d.ts +45 -0
- package/dist/api/agent.api.service.js +54 -0
- package/dist/api/job.api.service.d.ts +210 -0
- package/dist/api/job.api.service.js +200 -0
- package/dist/api/lazy-instances.d.ts +24 -0
- package/dist/api/lazy-instances.js +48 -0
- package/dist/api/postprocessor.api.service.d.ts +98 -0
- package/dist/api/postprocessor.api.service.js +76 -0
- package/dist/api/preprocessor.api.service.d.ts +98 -0
- package/dist/api/preprocessor.api.service.js +76 -0
- package/dist/api/user.data.api.service.d.ts +28 -0
- package/dist/api/user.data.api.service.js +51 -0
- package/dist/api/webhook.api.service.d.ts +151 -0
- package/dist/api/webhook.api.service.js +134 -0
- package/dist/api-exports.d.ts +156 -41
- package/dist/api-exports.js +182 -21
- package/dist/cli/command-definitions.js +149 -7
- package/dist/commands/compile.js +124 -5
- package/dist/commands/completion.d.ts +11 -0
- package/dist/commands/completion.js +209 -0
- package/dist/commands/env.d.ts +3 -2
- package/dist/commands/env.js +42 -17
- package/dist/commands/features.d.ts +16 -0
- package/dist/commands/features.js +352 -0
- package/dist/commands/index.d.ts +7 -0
- package/dist/commands/index.js +7 -0
- package/dist/commands/init.js +53 -7
- package/dist/commands/jobs.d.ts +20 -0
- package/dist/commands/jobs.js +533 -0
- package/dist/commands/logs.js +2 -5
- package/dist/commands/persona.d.ts +3 -2
- package/dist/commands/persona.js +43 -18
- package/dist/commands/postprocessors.d.ts +8 -0
- package/dist/commands/postprocessors.js +431 -0
- package/dist/commands/preprocessors.d.ts +8 -0
- package/dist/commands/preprocessors.js +431 -0
- package/dist/commands/push.d.ts +9 -13
- package/dist/commands/push.js +937 -69
- package/dist/commands/skills.d.ts +16 -0
- package/dist/commands/skills.js +438 -0
- package/dist/commands/test.d.ts +9 -18
- package/dist/commands/test.js +558 -82
- package/dist/commands/webhooks.d.ts +18 -0
- package/dist/commands/webhooks.js +424 -0
- package/dist/common/data.entry.instance.d.ts +7 -0
- package/dist/common/data.entry.instance.js +15 -0
- package/dist/common/job.instance.d.ts +77 -0
- package/dist/common/job.instance.js +108 -0
- package/dist/common/order.instance.d.ts +6 -0
- package/dist/common/order.instance.js +14 -0
- package/dist/common/product.instance.d.ts +6 -0
- package/dist/common/product.instance.js +14 -0
- package/dist/common/user.instance.d.ts +15 -0
- package/dist/common/user.instance.js +38 -0
- package/dist/config/constants.d.ts +2 -2
- package/dist/config/constants.js +4 -4
- package/dist/index.js +14 -3
- package/dist/interfaces/agent.d.ts +33 -1
- package/dist/interfaces/chat.d.ts +22 -0
- package/dist/interfaces/index.d.ts +10 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/interfaces/jobs.d.ts +172 -0
- package/dist/interfaces/jobs.js +5 -0
- package/dist/interfaces/message.d.ts +18 -0
- package/dist/interfaces/message.js +1 -0
- package/dist/interfaces/postprocessors.d.ts +35 -0
- package/dist/interfaces/postprocessors.js +4 -0
- package/dist/interfaces/preprocessors.d.ts +35 -0
- package/dist/interfaces/preprocessors.js +4 -0
- package/dist/interfaces/webhooks.d.ts +104 -0
- package/dist/interfaces/webhooks.js +5 -0
- package/dist/types/api-contracts.d.ts +14 -0
- package/dist/types/api-contracts.js +0 -7
- package/dist/types/compile.types.d.ts +49 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/skill.d.ts +502 -0
- package/dist/types/skill.js +477 -0
- package/dist/utils/agent-management.d.ts +25 -0
- package/dist/utils/agent-management.js +67 -0
- package/dist/utils/bundling.d.ts +31 -1
- package/dist/utils/bundling.js +653 -10
- package/dist/utils/compile.d.ts +63 -0
- package/dist/utils/compile.js +691 -36
- package/dist/utils/deployment.d.ts +2 -1
- package/dist/utils/deployment.js +16 -2
- package/dist/utils/init-agent.d.ts +3 -1
- package/dist/utils/init-agent.js +6 -4
- package/dist/utils/init-prompts.d.ts +2 -1
- package/dist/utils/init-prompts.js +14 -9
- package/dist/utils/job-management.d.ts +24 -0
- package/dist/utils/job-management.js +264 -0
- package/dist/utils/postprocessor-management.d.ts +9 -0
- package/dist/utils/postprocessor-management.js +118 -0
- package/dist/utils/preprocessor-management.d.ts +9 -0
- package/dist/utils/preprocessor-management.js +118 -0
- package/dist/utils/sandbox.d.ts +61 -1
- package/dist/utils/sandbox.js +283 -72
- package/dist/utils/tool-detection.d.ts +3 -2
- package/dist/utils/tool-detection.js +18 -4
- package/dist/utils/webhook-management.d.ts +24 -0
- package/dist/utils/webhook-management.js +256 -0
- package/dist/web/app.css +152 -736
- package/dist/web/app.js +45 -45
- package/package.json +2 -2
- package/template/AGENT_CONFIGURATION.md +251 -0
- package/template/COMPLEX_JOB_EXAMPLES.md +795 -0
- package/template/DYNAMIC_JOB_CREATION.md +371 -0
- package/template/README.md +30 -2
- package/template/WEBHOOKS_JOBS_QUICKSTART.md +318 -0
- package/template/WEBHOOK_JOB_EXAMPLES.md +817 -0
- package/template/package.json +1 -1
- package/template/src/index-agent-example.ts +201 -0
- package/template/src/index.ts +39 -0
- package/template/src/jobs/AbandonedBasketProcessorJob.ts +139 -0
- package/template/src/jobs/DailyCleanupJob.ts +100 -0
- package/template/src/jobs/DataMigrationJob.ts +133 -0
- package/template/src/jobs/HealthCheckJob.ts +87 -0
- package/template/src/postprocessors/ResponseFormatter.ts +151 -0
- package/template/src/preprocessors/MessageFilter.ts +91 -0
- package/template/src/tools/GameScoreTrackerTool.ts +356 -0
- package/template/src/tools/SmartBasketTool.ts +188 -0
- package/template/src/webhooks/PaymentWebhook.ts +113 -0
- package/template/src/webhooks/UserEventWebhook.ts +77 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook Management Utilities
|
|
3
|
+
* Handles webhook creation via API and YAML configuration management
|
|
4
|
+
*/
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import yaml from "js-yaml";
|
|
8
|
+
import WebhookApi from '../api/webhook.api.service.js';
|
|
9
|
+
import { BASE_URLS } from '../config/constants.js';
|
|
10
|
+
import { loadApiKey } from '../services/auth.js';
|
|
11
|
+
import { COMPILE_FILES, SKILL_DEFAULTS, YAML_FORMAT, } from '../config/compile.constants.js';
|
|
12
|
+
/**
|
|
13
|
+
* Ensures all detected webhooks exist in the YAML config with valid webhook IDs.
|
|
14
|
+
* If a webhook doesn't exist or has no ID, creates it via the API.
|
|
15
|
+
*
|
|
16
|
+
* @param webhooksArray - Array of webhooks detected from source code
|
|
17
|
+
* @param config - The skill configuration from lua.skill.yaml
|
|
18
|
+
* @returns Updated webhooks array with valid webhook IDs
|
|
19
|
+
*/
|
|
20
|
+
export async function ensureWebhooksExistInYaml(webhooksArray, config) {
|
|
21
|
+
const updatedWebhooksArray = [];
|
|
22
|
+
let yamlUpdated = false;
|
|
23
|
+
const existingWebhooks = config?.webhooks || [];
|
|
24
|
+
const existingWebhooksMap = createWebhooksMap(existingWebhooks);
|
|
25
|
+
// Process each detected webhook
|
|
26
|
+
for (const webhook of webhooksArray) {
|
|
27
|
+
const existingWebhook = existingWebhooksMap.get(webhook.name);
|
|
28
|
+
if (existingWebhook && existingWebhook.webhookId && existingWebhook.webhookId !== '') {
|
|
29
|
+
// Webhook exists with valid webhookId - reuse it
|
|
30
|
+
updatedWebhooksArray.push({
|
|
31
|
+
...webhook,
|
|
32
|
+
webhookId: existingWebhook.webhookId
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Webhook doesn't exist or missing webhookId - create via API
|
|
37
|
+
const createdWebhook = await createWebhookViaApi(webhook, config, existingWebhooks, existingWebhook);
|
|
38
|
+
updatedWebhooksArray.push(createdWebhook);
|
|
39
|
+
yamlUpdated = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Update YAML file if any changes were made
|
|
43
|
+
if (yamlUpdated) {
|
|
44
|
+
await updateYamlWithWebhooks(config);
|
|
45
|
+
}
|
|
46
|
+
return updatedWebhooksArray;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a map of existing webhooks for quick lookup by name.
|
|
50
|
+
*
|
|
51
|
+
* @param existingWebhooks - Array of webhooks from YAML config
|
|
52
|
+
* @returns Map of webhook names to webhook objects
|
|
53
|
+
*/
|
|
54
|
+
function createWebhooksMap(existingWebhooks) {
|
|
55
|
+
const map = new Map();
|
|
56
|
+
existingWebhooks.forEach((webhook) => {
|
|
57
|
+
map.set(webhook.name, webhook);
|
|
58
|
+
});
|
|
59
|
+
return map;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new webhook via the Lua API and updates the config.
|
|
63
|
+
*
|
|
64
|
+
* @param webhook - The webhook to create
|
|
65
|
+
* @param config - The skill configuration
|
|
66
|
+
* @param existingWebhooks - Array of existing webhooks (mutated)
|
|
67
|
+
* @param existingWebhook - The existing webhook entry if one exists (may be without ID)
|
|
68
|
+
* @returns The webhook with its new ID
|
|
69
|
+
*/
|
|
70
|
+
async function createWebhookViaApi(webhook, config, existingWebhooks, existingWebhook) {
|
|
71
|
+
try {
|
|
72
|
+
// Validate prerequisites
|
|
73
|
+
const apiKey = await loadApiKey();
|
|
74
|
+
if (!apiKey) {
|
|
75
|
+
throw new Error("No API key found. Run 'lua auth configure' first.");
|
|
76
|
+
}
|
|
77
|
+
const agentId = config?.agent?.agentId;
|
|
78
|
+
if (!agentId) {
|
|
79
|
+
throw new Error("No agent ID found in lua.skill.yaml. Run 'lua init' first.");
|
|
80
|
+
}
|
|
81
|
+
// Create webhook via API
|
|
82
|
+
const webhookPayload = {
|
|
83
|
+
name: webhook.name,
|
|
84
|
+
description: webhook.description || `A Lua webhook for ${webhook.name}`,
|
|
85
|
+
context: webhook.context || ''
|
|
86
|
+
};
|
|
87
|
+
const webhookApi = new WebhookApi(BASE_URLS.API, apiKey, agentId);
|
|
88
|
+
const result = await webhookApi.createWebhook(webhookPayload);
|
|
89
|
+
if (result.success && result.data && result.data.id) {
|
|
90
|
+
const newWebhookId = result.data.id;
|
|
91
|
+
// Update YAML config with new webhook ID
|
|
92
|
+
if (!existingWebhook) {
|
|
93
|
+
existingWebhooks.push({
|
|
94
|
+
name: webhook.name || '',
|
|
95
|
+
version: webhook.version || SKILL_DEFAULTS.VERSION,
|
|
96
|
+
webhookId: newWebhookId
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
existingWebhook.webhookId = newWebhookId;
|
|
101
|
+
}
|
|
102
|
+
// Add webhooks to config if not already present
|
|
103
|
+
if (!config.webhooks) {
|
|
104
|
+
config.webhooks = existingWebhooks;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
...webhook,
|
|
108
|
+
webhookId: newWebhookId
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.error(`❌ Failed to create webhook ${webhook.name}:`, result.error);
|
|
113
|
+
throw new Error(result.error?.message || 'Failed to create webhook - no ID returned from API');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error(`❌ Failed to create webhook ${webhook.name}:`, error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Updates the lua.skill.yaml file with the current webhooks array.
|
|
123
|
+
* Ensures no undefined values are written to the YAML file.
|
|
124
|
+
*
|
|
125
|
+
* @param config - Current skill configuration to merge with
|
|
126
|
+
*/
|
|
127
|
+
async function updateYamlWithWebhooks(config) {
|
|
128
|
+
const webhooks = config?.webhooks || [];
|
|
129
|
+
// Clean webhooks array to ensure no undefined values
|
|
130
|
+
const cleanedWebhooks = webhooks.map(webhook => ({
|
|
131
|
+
name: webhook.name || '',
|
|
132
|
+
version: webhook.version || SKILL_DEFAULTS.VERSION,
|
|
133
|
+
webhookId: webhook.webhookId || ''
|
|
134
|
+
}));
|
|
135
|
+
// Update config with cleaned webhooks array
|
|
136
|
+
const updatedConfig = {
|
|
137
|
+
...config,
|
|
138
|
+
webhooks: cleanedWebhooks
|
|
139
|
+
};
|
|
140
|
+
// Write updated YAML with consistent formatting
|
|
141
|
+
const yamlPath = path.join(process.cwd(), COMPILE_FILES.LUA_SKILL_YAML);
|
|
142
|
+
const yamlContent = yaml.dump(updatedConfig, {
|
|
143
|
+
indent: YAML_FORMAT.INDENT,
|
|
144
|
+
lineWidth: YAML_FORMAT.LINE_WIDTH,
|
|
145
|
+
noRefs: YAML_FORMAT.NO_REFS,
|
|
146
|
+
replacer: (key, value) => {
|
|
147
|
+
// Replace undefined values with empty strings
|
|
148
|
+
return value === undefined ? '' : value;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
fs.writeFileSync(yamlPath, yamlContent);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Syncs the server webhooks with the YAML configuration.
|
|
155
|
+
* Performs a two-way sync:
|
|
156
|
+
* 1. Deletes/deactivates webhooks from server that aren't in YAML
|
|
157
|
+
* 2. Updates YAML with active version numbers from server
|
|
158
|
+
*
|
|
159
|
+
* @param config - The skill configuration from lua.skill.yaml
|
|
160
|
+
* @returns Array of messages about sync operations
|
|
161
|
+
*/
|
|
162
|
+
export async function syncServerWebhooksWithYaml(config) {
|
|
163
|
+
const messages = [];
|
|
164
|
+
let yamlNeedsUpdate = false;
|
|
165
|
+
try {
|
|
166
|
+
// Validate prerequisites
|
|
167
|
+
const apiKey = await loadApiKey();
|
|
168
|
+
if (!apiKey) {
|
|
169
|
+
console.warn("⚠️ No API key found. Skipping server webhook sync.");
|
|
170
|
+
return messages;
|
|
171
|
+
}
|
|
172
|
+
const agentId = config?.agent?.agentId;
|
|
173
|
+
if (!agentId) {
|
|
174
|
+
console.warn("⚠️ No agent ID found in lua.skill.yaml. Skipping server webhook sync.");
|
|
175
|
+
return messages;
|
|
176
|
+
}
|
|
177
|
+
// Get webhooks from server
|
|
178
|
+
const webhookApi = new WebhookApi(BASE_URLS.API, apiKey, agentId);
|
|
179
|
+
const serverWebhooksResponse = await webhookApi.getWebhooks();
|
|
180
|
+
if (!serverWebhooksResponse.success || !serverWebhooksResponse.data?.webhooks) {
|
|
181
|
+
console.warn("⚠️ Could not retrieve server webhooks. Skipping server webhook sync.");
|
|
182
|
+
return messages;
|
|
183
|
+
}
|
|
184
|
+
const serverWebhooks = serverWebhooksResponse.data.webhooks;
|
|
185
|
+
const yamlWebhooks = config?.webhooks || [];
|
|
186
|
+
// Create maps for efficient lookup
|
|
187
|
+
const yamlWebhooksMap = new Map(yamlWebhooks
|
|
188
|
+
.filter((webhook) => webhook.webhookId)
|
|
189
|
+
.map((webhook) => [webhook.webhookId, webhook]));
|
|
190
|
+
const serverWebhooksMap = new Map(serverWebhooks.map(webhook => [webhook.id, webhook]));
|
|
191
|
+
// Part 1: Delete webhooks from server that aren't in YAML
|
|
192
|
+
const webhooksToDelete = serverWebhooks.filter(serverWebhook => !yamlWebhooksMap.has(serverWebhook.id));
|
|
193
|
+
for (const webhook of webhooksToDelete) {
|
|
194
|
+
try {
|
|
195
|
+
const deleteResponse = await webhookApi.deleteWebhook(webhook.id);
|
|
196
|
+
if (deleteResponse.success && deleteResponse.data) {
|
|
197
|
+
if (deleteResponse.data.deleted) {
|
|
198
|
+
const msg = `✅ Deleted webhook "${webhook.name}" from server`;
|
|
199
|
+
messages.push(msg);
|
|
200
|
+
console.log(msg);
|
|
201
|
+
}
|
|
202
|
+
else if (deleteResponse.data.deactivated) {
|
|
203
|
+
const msg = `⚠️ Webhook "${webhook.name}" has versions and cannot be deleted. It has been deactivated instead.`;
|
|
204
|
+
messages.push(msg);
|
|
205
|
+
console.warn(msg);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const msg = `❌ Failed to delete webhook "${webhook.name}": ${deleteResponse.error?.message || 'Unknown error'}`;
|
|
210
|
+
messages.push(msg);
|
|
211
|
+
console.error(msg);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
const msg = `❌ Error deleting webhook "${webhook.name}": ${error}`;
|
|
216
|
+
messages.push(msg);
|
|
217
|
+
console.error(msg);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Part 2: Sync version numbers from server to YAML
|
|
221
|
+
const updatedYamlWebhooks = yamlWebhooks.map((yamlWebhook) => {
|
|
222
|
+
const serverWebhook = serverWebhooksMap.get(yamlWebhook.webhookId);
|
|
223
|
+
if (serverWebhook && serverWebhook.versions && serverWebhook.versions.length > 0) {
|
|
224
|
+
// Find the active version on the server
|
|
225
|
+
const activeVersion = serverWebhook.versions.find((v) => v.isActive);
|
|
226
|
+
if (activeVersion && activeVersion.version !== yamlWebhook.version) {
|
|
227
|
+
const msg = `📝 Updated "${yamlWebhook.name}" webhook version in YAML: ${yamlWebhook.version} → ${activeVersion.version}`;
|
|
228
|
+
messages.push(msg);
|
|
229
|
+
console.log(msg);
|
|
230
|
+
yamlNeedsUpdate = true;
|
|
231
|
+
return {
|
|
232
|
+
...yamlWebhook,
|
|
233
|
+
version: activeVersion.version
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return yamlWebhook;
|
|
238
|
+
});
|
|
239
|
+
// Update YAML file if versions changed
|
|
240
|
+
if (yamlNeedsUpdate) {
|
|
241
|
+
const updatedConfig = {
|
|
242
|
+
...config,
|
|
243
|
+
webhooks: updatedYamlWebhooks
|
|
244
|
+
};
|
|
245
|
+
await updateYamlWithWebhooks(updatedConfig);
|
|
246
|
+
console.log("✅ YAML webhook versions synced with server");
|
|
247
|
+
}
|
|
248
|
+
if (webhooksToDelete.length === 0 && !yamlNeedsUpdate) {
|
|
249
|
+
console.log("✅ Server webhooks and YAML are fully in sync");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
console.error("❌ Error syncing server webhooks:", error);
|
|
254
|
+
}
|
|
255
|
+
return messages;
|
|
256
|
+
}
|