lua-cli 3.0.0-alpha.1 → 3.0.0-alpha.4
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/job.api.service.d.ts +16 -7
- package/dist/api/job.api.service.js +21 -5
- package/dist/api/postprocessor.api.service.d.ts +61 -1
- package/dist/api/postprocessor.api.service.js +35 -0
- package/dist/api/preprocessor.api.service.d.ts +61 -1
- package/dist/api/preprocessor.api.service.js +35 -0
- package/dist/api-exports.d.ts +26 -6
- package/dist/api-exports.js +42 -29
- package/dist/commands/chat.js +32 -5
- package/dist/commands/compile.js +16 -2
- package/dist/commands/dev.js +23 -2
- package/dist/commands/push.js +5 -3
- package/dist/commands/test.js +18 -2
- package/dist/common/job.instance.d.ts +3 -0
- package/dist/common/job.instance.js +8 -0
- package/dist/config/constants.d.ts +6 -5
- package/dist/config/constants.js +12 -10
- package/dist/interfaces/chat.d.ts +30 -1
- package/dist/interfaces/jobs.d.ts +21 -0
- package/dist/types/skill.d.ts +75 -56
- package/dist/types/skill.js +53 -59
- package/dist/utils/bundling.d.ts +13 -4
- package/dist/utils/bundling.js +83 -26
- package/dist/utils/compile.js +27 -6
- package/dist/utils/dev-api.d.ts +42 -2
- package/dist/utils/dev-api.js +177 -4
- package/dist/utils/dev-server.d.ts +1 -1
- package/dist/utils/dev-server.js +4 -4
- package/dist/utils/dynamic-job-bundler.d.ts +17 -0
- package/dist/utils/dynamic-job-bundler.js +143 -0
- package/dist/utils/pre-bundle-jobs.d.ts +26 -0
- package/dist/utils/pre-bundle-jobs.js +176 -0
- package/dist/utils/sandbox-storage.d.ts +48 -0
- package/dist/utils/sandbox-storage.js +114 -0
- package/dist/utils/sandbox.d.ts +2 -2
- package/dist/utils/sandbox.js +23 -7
- package/package.json +1 -1
- package/template/lua.skill.yaml +47 -0
- package/template/package-lock.json +10505 -0
- package/template/package.json +2 -1
- package/template/src/index.ts +65 -3
- package/template/src/tools/CreateInlineJob.ts +42 -0
- package/API_REFERENCE.md +0 -1408
- package/CHANGELOG.md +0 -236
- package/CLI_REFERENCE.md +0 -908
- package/GETTING_STARTED.md +0 -1040
- package/INSTANCE_TYPES.md +0 -1158
- package/README.md +0 -865
- package/TEMPLATE_GUIDE.md +0 -1398
- package/USER_DATA_INSTANCE.md +0 -621
- package/template/AGENT_CONFIGURATION.md +0 -251
- package/template/COMPLEX_JOB_EXAMPLES.md +0 -795
- package/template/DYNAMIC_JOB_CREATION.md +0 -371
- package/template/TOOL_EXAMPLES.md +0 -655
- package/template/WEBHOOKS_JOBS_QUICKSTART.md +0 -318
- package/template/WEBHOOK_JOB_EXAMPLES.md +0 -817
- package/template/src/index-agent-example.ts +0 -201
- package/template/src/postprocessors/ResponseFormatter.ts +0 -151
- package/template/src/preprocessors/MessageFilter.ts +0 -91
package/dist/commands/dev.js
CHANGED
|
@@ -7,7 +7,7 @@ import { compileCommand } from './compile.js';
|
|
|
7
7
|
import { checkApiKey, loadApiKey } from '../services/auth.js';
|
|
8
8
|
import { readSkillConfig } from '../utils/files.js';
|
|
9
9
|
import { withErrorHandling, writeProgress, writeSuccess } from '../utils/cli.js';
|
|
10
|
-
import { pushSkillsToSandbox } from '../utils/dev-api.js';
|
|
10
|
+
import { pushSkillsToSandbox, pushProcessorsToSandbox } from '../utils/dev-api.js';
|
|
11
11
|
import { createChatServer } from '../utils/dev-server.js';
|
|
12
12
|
import { createFileWatcher } from '../utils/dev-watcher.js';
|
|
13
13
|
import { readConfigVersion, readDeployJson, extractSkillId, validateConfig, validateDeployData, validateAgentConfig, } from '../utils/dev-helpers.js';
|
|
@@ -75,6 +75,26 @@ export async function devCommand() {
|
|
|
75
75
|
process.exit(1);
|
|
76
76
|
}
|
|
77
77
|
writeSuccess(`✅ Pushed ${Object.keys(sandboxIds).length} skills to sandbox`);
|
|
78
|
+
// Step 6b: Push preprocessors and postprocessors to sandbox
|
|
79
|
+
const fs = await import('fs');
|
|
80
|
+
const path = await import('path');
|
|
81
|
+
const preprocessorsPath = path.join(process.cwd(), 'dist', 'preprocessors.json');
|
|
82
|
+
const postprocessorsPath = path.join(process.cwd(), 'dist', 'postprocessors.json');
|
|
83
|
+
let bundledPreProcessors = [];
|
|
84
|
+
let bundledPostProcessors = [];
|
|
85
|
+
if (fs.existsSync(preprocessorsPath)) {
|
|
86
|
+
bundledPreProcessors = JSON.parse(fs.readFileSync(preprocessorsPath, 'utf8'));
|
|
87
|
+
}
|
|
88
|
+
if (fs.existsSync(postprocessorsPath)) {
|
|
89
|
+
bundledPostProcessors = JSON.parse(fs.readFileSync(postprocessorsPath, 'utf8'));
|
|
90
|
+
}
|
|
91
|
+
if (bundledPreProcessors.length > 0 || bundledPostProcessors.length > 0) {
|
|
92
|
+
writeProgress("🔄 Pushing processors to sandbox...");
|
|
93
|
+
const processorCounts = await pushProcessorsToSandbox(apiKey, agentId, updatedConfig, bundledPreProcessors, bundledPostProcessors, true);
|
|
94
|
+
if (processorCounts.preprocessors > 0 || processorCounts.postprocessors > 0) {
|
|
95
|
+
writeSuccess(`✅ Pushed ${processorCounts.preprocessors} preprocessor(s) and ${processorCounts.postprocessors} postprocessor(s) to sandbox`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
78
98
|
// Use the first skill's sandbox ID for the web interface
|
|
79
99
|
const firstSkillName = Object.keys(sandboxIds)[0];
|
|
80
100
|
const sandboxSkillId = sandboxIds[firstSkillName];
|
|
@@ -83,7 +103,8 @@ export async function devCommand() {
|
|
|
83
103
|
process.exit(1);
|
|
84
104
|
}
|
|
85
105
|
// Step 7: Start web server for chat interface
|
|
86
|
-
const { server, wss, broadcastLog } = createChatServer(apiKey, agentId, skillId, sandboxSkillId, DEV_SERVER_PORT
|
|
106
|
+
const { server, wss, broadcastLog } = createChatServer(apiKey, agentId, skillId, sandboxSkillId, DEV_SERVER_PORT, updatedConfig // Pass config for processor overrides
|
|
107
|
+
);
|
|
87
108
|
// Step 8: Open browser to chat interface
|
|
88
109
|
try {
|
|
89
110
|
await open(`http://localhost:${DEV_SERVER_PORT}`);
|
package/dist/commands/push.js
CHANGED
|
@@ -441,7 +441,7 @@ async function pushWebhookVersion() {
|
|
|
441
441
|
}
|
|
442
442
|
const result = await response.json();
|
|
443
443
|
writeSuccess(`\n✅ Successfully pushed ${selectedWebhook.name} v${versionToPush}\n`);
|
|
444
|
-
writeInfo(`📦 Webhook URL: ${BASE_URLS.
|
|
444
|
+
writeInfo(`📦 Webhook URL: ${BASE_URLS.WEBHOOK}/${config.agent.agentId}/${selectedWebhook.webhookId}`);
|
|
445
445
|
// Step 8: Ask if user wants to deploy now
|
|
446
446
|
const deployAnswer = await safePrompt([
|
|
447
447
|
{
|
|
@@ -765,7 +765,8 @@ async function pushPreProcessorVersion() {
|
|
|
765
765
|
context: bundledData.context || selected.context,
|
|
766
766
|
preprocessorId: selected.preprocessorId,
|
|
767
767
|
code: bundledData.code,
|
|
768
|
-
executeFunction: bundledData.executeFunction
|
|
768
|
+
executeFunction: bundledData.executeFunction,
|
|
769
|
+
async: Boolean(bundledData.async ?? false) // Ensure boolean type
|
|
769
770
|
};
|
|
770
771
|
writeProgress(`\n🚀 Pushing ${selected.name} v${confirmedVersion}...`);
|
|
771
772
|
const api = new PreProcessorApi(BASE_URLS.API, apiKey, config.agent.agentId);
|
|
@@ -896,7 +897,8 @@ async function pushPostProcessorVersion() {
|
|
|
896
897
|
context: bundledData.context || selected.context,
|
|
897
898
|
postprocessorId: selected.postprocessorId,
|
|
898
899
|
code: bundledData.code,
|
|
899
|
-
executeFunction: bundledData.executeFunction
|
|
900
|
+
executeFunction: bundledData.executeFunction,
|
|
901
|
+
async: Boolean(bundledData.async ?? false) // Ensure boolean type
|
|
900
902
|
};
|
|
901
903
|
writeProgress(`\n🚀 Pushing ${selected.name} v${confirmedVersion}...`);
|
|
902
904
|
const api = new PostProcessorApi(BASE_URLS.API, apiKey, config.agent.agentId);
|
package/dist/commands/test.js
CHANGED
|
@@ -434,15 +434,31 @@ async function testPreProcessor() {
|
|
|
434
434
|
process.env[key] = value;
|
|
435
435
|
}
|
|
436
436
|
try {
|
|
437
|
+
// Convert string message to ChatMessage array
|
|
438
|
+
const messages = [{ type: 'text', text: messageAnswer.message }];
|
|
437
439
|
const result = await executePreProcessor({
|
|
438
440
|
processorCode: preprocessorCode,
|
|
439
|
-
|
|
441
|
+
messages: messages, // Pass array instead of string
|
|
440
442
|
channel: channelAnswer.channel,
|
|
441
443
|
apiKey,
|
|
442
444
|
agentId
|
|
443
445
|
});
|
|
444
446
|
writeSuccess("\n✅ PreProcessor execution successful!");
|
|
445
|
-
console.log(
|
|
447
|
+
console.log(`\nProcessed messages (${result.length}):`);
|
|
448
|
+
result.forEach((msg, idx) => {
|
|
449
|
+
if (msg.type === 'text') {
|
|
450
|
+
console.log(` ${idx + 1}. [TEXT] ${msg.text}`);
|
|
451
|
+
}
|
|
452
|
+
else if (msg.type === 'image') {
|
|
453
|
+
console.log(` ${idx + 1}. [IMAGE] ${msg.mimeType}`);
|
|
454
|
+
}
|
|
455
|
+
else if (msg.type === 'file') {
|
|
456
|
+
console.log(` ${idx + 1}. [FILE] ${msg.mimeType}`);
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
console.log(` ${idx + 1}. [${msg.type}]`, msg);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
446
462
|
}
|
|
447
463
|
catch (error) {
|
|
448
464
|
console.error("\n❌ PreProcessor execution failed:");
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Provides a convenient interface for interacting with a job
|
|
4
4
|
*/
|
|
5
5
|
import JobApi from '../api/job.api.service.js';
|
|
6
|
+
import UserDataInstance from './user.instance.js';
|
|
6
7
|
/**
|
|
7
8
|
* Job Instance class.
|
|
8
9
|
* Represents a single job with helper methods for common operations.
|
|
@@ -38,6 +39,7 @@ export declare class JobInstance {
|
|
|
38
39
|
readonly jobId: string;
|
|
39
40
|
readonly schedule: any;
|
|
40
41
|
metadata: Record<string, any>;
|
|
42
|
+
private userApi;
|
|
41
43
|
constructor(jobApi: JobApi, jobData: any);
|
|
42
44
|
/**
|
|
43
45
|
* Gets the full job data.
|
|
@@ -70,6 +72,7 @@ export declare class JobInstance {
|
|
|
70
72
|
* ```
|
|
71
73
|
*/
|
|
72
74
|
delete(): Promise<void>;
|
|
75
|
+
user(): Promise<UserDataInstance>;
|
|
73
76
|
/**
|
|
74
77
|
* Converts the job instance to JSON.
|
|
75
78
|
*/
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Job Instance
|
|
3
3
|
* Provides a convenient interface for interacting with a job
|
|
4
4
|
*/
|
|
5
|
+
import UserDataInstance from './user.instance.js';
|
|
6
|
+
import UserDataApi from '../api/user.data.api.service.js';
|
|
7
|
+
import { BASE_URLS } from '../config/constants.js';
|
|
5
8
|
/**
|
|
6
9
|
* Job Instance class.
|
|
7
10
|
* Represents a single job with helper methods for common operations.
|
|
@@ -38,6 +41,7 @@ export class JobInstance {
|
|
|
38
41
|
this.name = jobData.name;
|
|
39
42
|
this.schedule = jobData.schedule;
|
|
40
43
|
this.metadata = jobData.metadata || {};
|
|
44
|
+
this.userApi = new UserDataApi(BASE_URLS.API, jobApi.apiKey, jobApi.agentId);
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* Gets the full job data.
|
|
@@ -92,6 +96,10 @@ export class JobInstance {
|
|
|
92
96
|
console.warn(`Job "${this.name}" has versions and was deactivated instead of deleted.`);
|
|
93
97
|
}
|
|
94
98
|
}
|
|
99
|
+
async user() {
|
|
100
|
+
const result = await this.userApi.get();
|
|
101
|
+
return new UserDataInstance(this.userApi, result);
|
|
102
|
+
}
|
|
95
103
|
/**
|
|
96
104
|
* Converts the job instance to JSON.
|
|
97
105
|
*/
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base URLs for the API, Auth, and Chat - Production
|
|
3
3
|
*/
|
|
4
|
-
export declare const BASE_URLS: {
|
|
5
|
-
readonly API: "http://localhost:3022";
|
|
6
|
-
readonly AUTH: "https://auth.heylua.ai";
|
|
7
|
-
readonly CHAT: "http://localhost:3001";
|
|
8
|
-
};
|
|
9
4
|
/**
|
|
10
5
|
* Base URLs for the API, Auth, and Chat - Development
|
|
11
6
|
*/
|
|
7
|
+
export declare const BASE_URLS: {
|
|
8
|
+
readonly API: "https://api.heylua.ai";
|
|
9
|
+
readonly AUTH: "https://auth.heylua.ai";
|
|
10
|
+
readonly CHAT: "https://api.heylua.ai";
|
|
11
|
+
readonly WEBHOOK: "https://webhook.heylua.ai";
|
|
12
|
+
};
|
package/dist/config/constants.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base URLs for the API, Auth, and Chat - Production
|
|
3
3
|
*/
|
|
4
|
-
export const BASE_URLS = {
|
|
5
|
-
API: 'http://localhost:3022',
|
|
6
|
-
AUTH: 'https://auth.heylua.ai',
|
|
7
|
-
CHAT: 'http://localhost:3001',
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Base URLs for the API, Auth, and Chat - Development
|
|
11
|
-
*/
|
|
12
4
|
// export const BASE_URLS = {
|
|
13
|
-
// API: '
|
|
5
|
+
// API: 'http://localhost:3022',
|
|
14
6
|
// AUTH: 'https://auth.heylua.ai',
|
|
15
|
-
// CHAT: '
|
|
7
|
+
// CHAT: 'http://localhost:3001',
|
|
8
|
+
// WEBHOOK: 'https://webhook.heylua.ai',
|
|
16
9
|
// } as const;
|
|
10
|
+
/**
|
|
11
|
+
* Base URLs for the API, Auth, and Chat - Development
|
|
12
|
+
*/
|
|
13
|
+
export const BASE_URLS = {
|
|
14
|
+
API: 'https://api.heylua.ai',
|
|
15
|
+
AUTH: 'https://auth.heylua.ai',
|
|
16
|
+
CHAT: 'https://api.heylua.ai',
|
|
17
|
+
WEBHOOK: 'https://webhook.heylua.ai',
|
|
18
|
+
};
|
|
@@ -6,10 +6,21 @@
|
|
|
6
6
|
* Chat message structure.
|
|
7
7
|
* Currently only supports text messages.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type ChatMessage = TextMessage | ImageMessage | FileMessage;
|
|
10
|
+
export interface TextMessage {
|
|
10
11
|
type: 'text';
|
|
11
12
|
text: string;
|
|
12
13
|
}
|
|
14
|
+
export interface ImageMessage {
|
|
15
|
+
type: 'image';
|
|
16
|
+
image: string;
|
|
17
|
+
mimeType: string;
|
|
18
|
+
}
|
|
19
|
+
export interface FileMessage {
|
|
20
|
+
type: 'file';
|
|
21
|
+
data: string;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
}
|
|
13
24
|
/**
|
|
14
25
|
* Skill override for testing specific skill versions.
|
|
15
26
|
* Used in dev mode to override production skills with sandbox versions.
|
|
@@ -18,6 +29,22 @@ export interface SkillOverride {
|
|
|
18
29
|
skillId: string;
|
|
19
30
|
sandboxId: string;
|
|
20
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* PreProcessor override for sandbox testing.
|
|
34
|
+
* Maps production preprocessor ID to sandbox version ID.
|
|
35
|
+
*/
|
|
36
|
+
export interface PreProcessorOverride {
|
|
37
|
+
preprocessorId: string;
|
|
38
|
+
sandboxId: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* PostProcessor override for sandbox testing.
|
|
42
|
+
* Maps production postprocessor ID to sandbox version ID.
|
|
43
|
+
*/
|
|
44
|
+
export interface PostProcessorOverride {
|
|
45
|
+
postprocessorId: string;
|
|
46
|
+
sandboxId: string;
|
|
47
|
+
}
|
|
21
48
|
/**
|
|
22
49
|
* Chat request payload.
|
|
23
50
|
* Sent to the chat API to start or continue a conversation.
|
|
@@ -26,6 +53,8 @@ export interface ChatRequest {
|
|
|
26
53
|
messages: ChatMessage[];
|
|
27
54
|
navigate: boolean;
|
|
28
55
|
skillOverride: SkillOverride[];
|
|
56
|
+
preprocessorOverride?: PreProcessorOverride[];
|
|
57
|
+
postprocessorOverride?: PostProcessorOverride[];
|
|
29
58
|
personaOverride?: string;
|
|
30
59
|
runtimeContext?: string;
|
|
31
60
|
}
|
|
@@ -13,6 +13,27 @@ export interface CreateJobDTO {
|
|
|
13
13
|
timeout?: number;
|
|
14
14
|
retry?: JobRetryConfig;
|
|
15
15
|
metadata?: Record<string, any>;
|
|
16
|
+
dynamic?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Optional initial version data.
|
|
19
|
+
* If provided, creates the first version automatically.
|
|
20
|
+
*/
|
|
21
|
+
version?: {
|
|
22
|
+
version: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
context?: string;
|
|
25
|
+
code: string;
|
|
26
|
+
executeFunction: string;
|
|
27
|
+
timeout?: number;
|
|
28
|
+
retry?: JobRetryConfig;
|
|
29
|
+
metadata?: Record<string, any>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Auto-publish and activate the job after creation.
|
|
33
|
+
* If true, the job will be immediately active and running.
|
|
34
|
+
* Default: false
|
|
35
|
+
*/
|
|
36
|
+
activate?: boolean;
|
|
16
37
|
}
|
|
17
38
|
/**
|
|
18
39
|
* DTO for pushing a job version
|
package/dist/types/skill.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ZodType } from "zod";
|
|
6
6
|
import UserDataInstance from "../common/user.instance.js";
|
|
7
|
+
import { JobInstance } from "../common/job.instance.js";
|
|
7
8
|
/**
|
|
8
9
|
* Safe environment variable access function.
|
|
9
10
|
* Gets injected at runtime with skill-specific environment variables.
|
|
@@ -171,8 +172,11 @@ export interface LuaJobConfig {
|
|
|
171
172
|
context: string;
|
|
172
173
|
/** Schedule configuration - cron, once, or interval */
|
|
173
174
|
schedule: JobSchedule;
|
|
174
|
-
/**
|
|
175
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Function that executes the job logic.
|
|
177
|
+
* Receives metadata as parameter for accessing job configuration.
|
|
178
|
+
*/
|
|
179
|
+
execute: (job: JobInstance) => Promise<any>;
|
|
176
180
|
/** Optional timeout in seconds (default: 300) */
|
|
177
181
|
timeout?: number;
|
|
178
182
|
/** Optional retry configuration */
|
|
@@ -180,7 +184,11 @@ export interface LuaJobConfig {
|
|
|
180
184
|
maxAttempts: number;
|
|
181
185
|
backoffSeconds?: number;
|
|
182
186
|
};
|
|
183
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Optional metadata for the job.
|
|
189
|
+
* Can store any custom data (tags, config, context, etc.)
|
|
190
|
+
* Sent to server and accessible during execution.
|
|
191
|
+
*/
|
|
184
192
|
metadata?: Record<string, any>;
|
|
185
193
|
}
|
|
186
194
|
/**
|
|
@@ -309,19 +317,6 @@ export declare class LuaJob {
|
|
|
309
317
|
* Gets the job metadata.
|
|
310
318
|
*/
|
|
311
319
|
getMetadata(): Record<string, any> | undefined;
|
|
312
|
-
/**
|
|
313
|
-
* Executes the job.
|
|
314
|
-
* This is called by the scheduler at the appropriate time.
|
|
315
|
-
*
|
|
316
|
-
* @returns Promise resolving to job execution result
|
|
317
|
-
*
|
|
318
|
-
* @example
|
|
319
|
-
* ```typescript
|
|
320
|
-
* const result = await job.execute();
|
|
321
|
-
* console.log('Job completed:', result);
|
|
322
|
-
* ```
|
|
323
|
-
*/
|
|
324
|
-
execute(): Promise<any>;
|
|
325
320
|
}
|
|
326
321
|
/**
|
|
327
322
|
* Lua Webhook configuration.
|
|
@@ -343,11 +338,7 @@ export interface LuaWebhookConfig {
|
|
|
343
338
|
/** Optional Zod schema for body validation */
|
|
344
339
|
bodySchema?: ZodType;
|
|
345
340
|
/** Function that executes the webhook logic */
|
|
346
|
-
execute: (
|
|
347
|
-
query?: any;
|
|
348
|
-
headers?: any;
|
|
349
|
-
body?: any;
|
|
350
|
-
}) => Promise<any>;
|
|
341
|
+
execute: (query?: any, headers?: any, body?: any) => Promise<any>;
|
|
351
342
|
}
|
|
352
343
|
/**
|
|
353
344
|
* Lua Webhook class.
|
|
@@ -380,19 +371,19 @@ export interface LuaWebhookConfig {
|
|
|
380
371
|
* email: z.string().email(),
|
|
381
372
|
* name: z.string()
|
|
382
373
|
* }),
|
|
383
|
-
* execute: async (
|
|
374
|
+
* execute: async (query, headers, body) => {
|
|
384
375
|
* // Process the webhook...
|
|
385
376
|
* console.log('New user:', body.email);
|
|
386
377
|
* return { success: true, userId: body.userId };
|
|
387
378
|
* }
|
|
388
379
|
* });
|
|
389
380
|
*
|
|
390
|
-
* // Execute the webhook with validated
|
|
391
|
-
* const result = await webhook.execute(
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
381
|
+
* // Execute the webhook with validated inputs
|
|
382
|
+
* const result = await webhook.execute(
|
|
383
|
+
* { source: 'mobile' },
|
|
384
|
+
* { 'x-api-key': 'secret-key' },
|
|
385
|
+
* { userId: '123', email: 'user@example.com', name: 'John' }
|
|
386
|
+
* );
|
|
396
387
|
* ```
|
|
397
388
|
*/
|
|
398
389
|
export declare class LuaWebhook {
|
|
@@ -439,27 +430,22 @@ export declare class LuaWebhook {
|
|
|
439
430
|
* Validates query parameters, headers, and body against their respective schemas
|
|
440
431
|
* before executing the webhook function.
|
|
441
432
|
*
|
|
442
|
-
* @param
|
|
443
|
-
* @param
|
|
444
|
-
* @param
|
|
445
|
-
* @param input.body - Request body
|
|
433
|
+
* @param query - Query parameters object
|
|
434
|
+
* @param headers - Headers object
|
|
435
|
+
* @param body - Request body
|
|
446
436
|
* @returns Promise resolving to webhook execution result
|
|
447
437
|
* @throws Error if validation fails for any input
|
|
448
438
|
*
|
|
449
439
|
* @example
|
|
450
440
|
* ```typescript
|
|
451
|
-
* const result = await webhook.execute(
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
441
|
+
* const result = await webhook.execute(
|
|
442
|
+
* { limit: '10' },
|
|
443
|
+
* { 'x-api-key': 'secret' },
|
|
444
|
+
* { data: 'value' }
|
|
445
|
+
* );
|
|
456
446
|
* ```
|
|
457
447
|
*/
|
|
458
|
-
execute(
|
|
459
|
-
query?: Record<string, any>;
|
|
460
|
-
headers?: Record<string, any>;
|
|
461
|
-
body?: any;
|
|
462
|
-
}): Promise<any>;
|
|
448
|
+
execute(query?: Record<string, any>, headers?: Record<string, any>, body?: any): Promise<any>;
|
|
463
449
|
}
|
|
464
450
|
/**
|
|
465
451
|
* PreProcessor configuration.
|
|
@@ -473,26 +459,45 @@ export interface PreProcessorConfig {
|
|
|
473
459
|
description: string;
|
|
474
460
|
/** Detailed context for what this preprocessor does */
|
|
475
461
|
context: string;
|
|
476
|
-
/**
|
|
477
|
-
|
|
462
|
+
/**
|
|
463
|
+
* Async flag - indicates if processor should run in background on server:
|
|
464
|
+
* - true: Run asynchronously (non-blocking, for slow operations like API calls)
|
|
465
|
+
* - false: Run synchronously (blocking, for fast operations like text filtering)
|
|
466
|
+
* Default: false (synchronous)
|
|
467
|
+
*/
|
|
468
|
+
async?: boolean;
|
|
469
|
+
/**
|
|
470
|
+
* Function that processes messages before sending to agent.
|
|
471
|
+
* MUST return ChatMessage[] - array of text, image, or file messages.
|
|
472
|
+
*/
|
|
473
|
+
execute: (user: UserDataInstance, messages: import("../interfaces/chat.js").ChatMessage[], channel: string) => Promise<import("../interfaces/chat.js").ChatMessage[]>;
|
|
478
474
|
}
|
|
479
475
|
/**
|
|
480
476
|
* PreProcessor class.
|
|
481
477
|
* Processes user messages before they reach the agent.
|
|
478
|
+
* Can handle rich content (text, images, files).
|
|
482
479
|
*
|
|
483
480
|
* @example
|
|
484
481
|
* ```typescript
|
|
485
|
-
* const
|
|
486
|
-
* name: '
|
|
482
|
+
* const contentFilter = new PreProcessor({
|
|
483
|
+
* name: 'content-filter',
|
|
487
484
|
* version: '1.0.0',
|
|
488
|
-
* description: '
|
|
489
|
-
* context: '
|
|
490
|
-
* execute: async (user,
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
485
|
+
* description: 'Filters and processes message content',
|
|
486
|
+
* context: 'Filters spam, validates images, and adds context',
|
|
487
|
+
* execute: async (user, messages, channel) => {
|
|
488
|
+
* // Process each message
|
|
489
|
+
* return messages.map(msg => {
|
|
490
|
+
* if (msg.type === 'text') {
|
|
491
|
+
* // Filter spam from text
|
|
492
|
+
* const filtered = msg.text.replace(/spam/gi, '[filtered]');
|
|
493
|
+
* return { type: 'text', text: filtered };
|
|
494
|
+
* }
|
|
495
|
+
* if (msg.type === 'image') {
|
|
496
|
+
* // Could validate image, add watermark, etc.
|
|
497
|
+
* return msg;
|
|
498
|
+
* }
|
|
499
|
+
* return msg;
|
|
500
|
+
* });
|
|
496
501
|
* }
|
|
497
502
|
* });
|
|
498
503
|
* ```
|
|
@@ -502,13 +507,15 @@ export declare class PreProcessor {
|
|
|
502
507
|
private readonly version;
|
|
503
508
|
private readonly description;
|
|
504
509
|
private readonly context;
|
|
510
|
+
private readonly asyncMode;
|
|
505
511
|
private readonly executeFunction;
|
|
506
512
|
constructor(config: PreProcessorConfig);
|
|
507
513
|
getName(): string;
|
|
508
514
|
getVersion(): string;
|
|
509
515
|
getDescription(): string;
|
|
510
516
|
getContext(): string;
|
|
511
|
-
|
|
517
|
+
getAsync(): boolean;
|
|
518
|
+
execute(user: UserDataInstance, messages: import("../interfaces/chat.js").ChatMessage[], channel: string): Promise<import("../interfaces/chat.js").ChatMessage[]>;
|
|
512
519
|
}
|
|
513
520
|
/**
|
|
514
521
|
* PostProcessor configuration.
|
|
@@ -522,7 +529,17 @@ export interface PostProcessorConfig {
|
|
|
522
529
|
description: string;
|
|
523
530
|
/** Detailed context for what this postprocessor does */
|
|
524
531
|
context: string;
|
|
525
|
-
/**
|
|
532
|
+
/**
|
|
533
|
+
* Async flag - indicates if processor should run in background on server:
|
|
534
|
+
* - true: Run asynchronously (non-blocking, for slow operations like API calls, translations)
|
|
535
|
+
* - false: Run synchronously (blocking, for fast operations like text formatting)
|
|
536
|
+
* Default: false (synchronous)
|
|
537
|
+
*/
|
|
538
|
+
async?: boolean;
|
|
539
|
+
/**
|
|
540
|
+
* Function that processes the agent's response before sending to user.
|
|
541
|
+
* MUST return string - the formatted response text.
|
|
542
|
+
*/
|
|
526
543
|
execute: (user: UserDataInstance, message: string, response: string, channel: string) => Promise<string>;
|
|
527
544
|
}
|
|
528
545
|
/**
|
|
@@ -547,12 +564,14 @@ export declare class PostProcessor {
|
|
|
547
564
|
private readonly version;
|
|
548
565
|
private readonly description;
|
|
549
566
|
private readonly context;
|
|
567
|
+
private readonly asyncMode;
|
|
550
568
|
private readonly executeFunction;
|
|
551
569
|
constructor(config: PostProcessorConfig);
|
|
552
570
|
getName(): string;
|
|
553
571
|
getVersion(): string;
|
|
554
572
|
getDescription(): string;
|
|
555
573
|
getContext(): string;
|
|
574
|
+
getAsync(): boolean;
|
|
556
575
|
execute(user: UserDataInstance, message: string, response: string, channel: string): Promise<string>;
|
|
557
576
|
}
|
|
558
577
|
/**
|