lua-cli 2.5.8 → 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.
Files changed (115) hide show
  1. package/dist/api/job.api.service.d.ts +219 -0
  2. package/dist/api/job.api.service.js +216 -0
  3. package/dist/api/lazy-instances.d.ts +24 -0
  4. package/dist/api/lazy-instances.js +48 -0
  5. package/dist/api/postprocessor.api.service.d.ts +158 -0
  6. package/dist/api/postprocessor.api.service.js +111 -0
  7. package/dist/api/preprocessor.api.service.d.ts +158 -0
  8. package/dist/api/preprocessor.api.service.js +111 -0
  9. package/dist/api/user.data.api.service.d.ts +13 -0
  10. package/dist/api/user.data.api.service.js +20 -0
  11. package/dist/api/webhook.api.service.d.ts +151 -0
  12. package/dist/api/webhook.api.service.js +134 -0
  13. package/dist/api-exports.d.ts +176 -41
  14. package/dist/api-exports.js +195 -21
  15. package/dist/cli/command-definitions.js +75 -5
  16. package/dist/commands/chat.js +32 -5
  17. package/dist/commands/compile.js +140 -7
  18. package/dist/commands/dev.js +23 -2
  19. package/dist/commands/index.d.ts +4 -0
  20. package/dist/commands/index.js +4 -0
  21. package/dist/commands/init.js +53 -7
  22. package/dist/commands/jobs.d.ts +20 -0
  23. package/dist/commands/jobs.js +533 -0
  24. package/dist/commands/logs.js +2 -5
  25. package/dist/commands/postprocessors.d.ts +8 -0
  26. package/dist/commands/postprocessors.js +431 -0
  27. package/dist/commands/preprocessors.d.ts +8 -0
  28. package/dist/commands/preprocessors.js +431 -0
  29. package/dist/commands/push.js +686 -5
  30. package/dist/commands/test.d.ts +9 -18
  31. package/dist/commands/test.js +574 -82
  32. package/dist/commands/webhooks.d.ts +18 -0
  33. package/dist/commands/webhooks.js +424 -0
  34. package/dist/common/job.instance.d.ts +80 -0
  35. package/dist/common/job.instance.js +116 -0
  36. package/dist/common/user.instance.d.ts +1 -0
  37. package/dist/common/user.instance.js +9 -0
  38. package/dist/config/constants.d.ts +4 -3
  39. package/dist/config/constants.js +10 -8
  40. package/dist/interfaces/agent.d.ts +2 -1
  41. package/dist/interfaces/chat.d.ts +52 -1
  42. package/dist/interfaces/index.d.ts +10 -0
  43. package/dist/interfaces/index.js +7 -0
  44. package/dist/interfaces/jobs.d.ts +193 -0
  45. package/dist/interfaces/jobs.js +5 -0
  46. package/dist/interfaces/postprocessors.d.ts +35 -0
  47. package/dist/interfaces/postprocessors.js +4 -0
  48. package/dist/interfaces/preprocessors.d.ts +35 -0
  49. package/dist/interfaces/preprocessors.js +4 -0
  50. package/dist/interfaces/webhooks.d.ts +104 -0
  51. package/dist/interfaces/webhooks.js +5 -0
  52. package/dist/types/api-contracts.d.ts +5 -0
  53. package/dist/types/compile.types.d.ts +49 -0
  54. package/dist/types/index.d.ts +1 -1
  55. package/dist/types/index.js +1 -1
  56. package/dist/types/skill.d.ts +521 -0
  57. package/dist/types/skill.js +471 -0
  58. package/dist/utils/agent-management.d.ts +25 -0
  59. package/dist/utils/agent-management.js +67 -0
  60. package/dist/utils/bundling.d.ts +44 -5
  61. package/dist/utils/bundling.js +723 -23
  62. package/dist/utils/compile.d.ts +63 -0
  63. package/dist/utils/compile.js +712 -36
  64. package/dist/utils/deployment.d.ts +2 -1
  65. package/dist/utils/deployment.js +16 -2
  66. package/dist/utils/dev-api.d.ts +42 -2
  67. package/dist/utils/dev-api.js +177 -4
  68. package/dist/utils/dev-server.d.ts +1 -1
  69. package/dist/utils/dev-server.js +4 -4
  70. package/dist/utils/dynamic-job-bundler.d.ts +17 -0
  71. package/dist/utils/dynamic-job-bundler.js +143 -0
  72. package/dist/utils/init-agent.d.ts +3 -1
  73. package/dist/utils/init-agent.js +6 -4
  74. package/dist/utils/init-prompts.d.ts +2 -1
  75. package/dist/utils/init-prompts.js +14 -9
  76. package/dist/utils/job-management.d.ts +24 -0
  77. package/dist/utils/job-management.js +264 -0
  78. package/dist/utils/postprocessor-management.d.ts +9 -0
  79. package/dist/utils/postprocessor-management.js +118 -0
  80. package/dist/utils/pre-bundle-jobs.d.ts +26 -0
  81. package/dist/utils/pre-bundle-jobs.js +176 -0
  82. package/dist/utils/preprocessor-management.d.ts +9 -0
  83. package/dist/utils/preprocessor-management.js +118 -0
  84. package/dist/utils/sandbox-storage.d.ts +48 -0
  85. package/dist/utils/sandbox-storage.js +114 -0
  86. package/dist/utils/sandbox.d.ts +61 -1
  87. package/dist/utils/sandbox.js +299 -72
  88. package/dist/utils/tool-detection.d.ts +3 -2
  89. package/dist/utils/tool-detection.js +18 -4
  90. package/dist/utils/webhook-management.d.ts +24 -0
  91. package/dist/utils/webhook-management.js +256 -0
  92. package/package.json +1 -1
  93. package/template/README.md +30 -2
  94. package/template/lua.skill.yaml +47 -0
  95. package/template/package-lock.json +10505 -0
  96. package/template/package.json +2 -1
  97. package/template/src/index.ts +103 -2
  98. package/template/src/jobs/AbandonedBasketProcessorJob.ts +139 -0
  99. package/template/src/jobs/DailyCleanupJob.ts +100 -0
  100. package/template/src/jobs/DataMigrationJob.ts +133 -0
  101. package/template/src/jobs/HealthCheckJob.ts +87 -0
  102. package/template/src/tools/CreateInlineJob.ts +42 -0
  103. package/template/src/tools/GameScoreTrackerTool.ts +356 -0
  104. package/template/src/tools/SmartBasketTool.ts +188 -0
  105. package/template/src/webhooks/PaymentWebhook.ts +113 -0
  106. package/template/src/webhooks/UserEventWebhook.ts +77 -0
  107. package/API_REFERENCE.md +0 -1408
  108. package/CHANGELOG.md +0 -236
  109. package/CLI_REFERENCE.md +0 -908
  110. package/GETTING_STARTED.md +0 -1040
  111. package/INSTANCE_TYPES.md +0 -1158
  112. package/README.md +0 -865
  113. package/TEMPLATE_GUIDE.md +0 -1398
  114. package/USER_DATA_INSTANCE.md +0 -621
  115. package/template/TOOL_EXAMPLES.md +0 -655
@@ -0,0 +1,118 @@
1
+ /**
2
+ * PreProcessor Management Utilities
3
+ */
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import yaml from "js-yaml";
7
+ import PreProcessorApi from '../api/preprocessor.api.service.js';
8
+ import { BASE_URLS } from '../config/constants.js';
9
+ import { loadApiKey } from '../services/auth.js';
10
+ import { SKILL_DEFAULTS, YAML_FORMAT } from '../config/compile.constants.js';
11
+ /**
12
+ * Ensures all detected preprocessors exist in the YAML config with valid IDs.
13
+ */
14
+ export async function ensurePreProcessorsExistInYaml(preprocessorsArray, config) {
15
+ const updatedPreProcessorsArray = [];
16
+ let yamlUpdated = false;
17
+ const existingPreProcessors = config?.preprocessors || [];
18
+ const existingMap = new Map(existingPreProcessors.map((p) => [p.name, p]));
19
+ for (const preprocessor of preprocessorsArray) {
20
+ const existing = existingMap.get(preprocessor.name);
21
+ if (existing && existing.preprocessorId) {
22
+ updatedPreProcessorsArray.push({
23
+ ...preprocessor,
24
+ preprocessorId: existing.preprocessorId
25
+ });
26
+ }
27
+ else {
28
+ const created = await createPreProcessorViaApi(preprocessor, config, existingPreProcessors, existing);
29
+ updatedPreProcessorsArray.push(created);
30
+ yamlUpdated = true;
31
+ }
32
+ }
33
+ if (yamlUpdated) {
34
+ await updateYamlWithPreProcessors(config);
35
+ }
36
+ return updatedPreProcessorsArray;
37
+ }
38
+ async function createPreProcessorViaApi(preprocessor, config, existingPreProcessors, existingPreProcessor) {
39
+ try {
40
+ const apiKey = await loadApiKey();
41
+ if (!apiKey)
42
+ throw new Error("No API key found. Run 'lua auth configure' first.");
43
+ const agentId = config?.agent?.agentId;
44
+ if (!agentId)
45
+ throw new Error("No agent ID found in lua.skill.yaml. Run 'lua init' first.");
46
+ const payload = {
47
+ name: preprocessor.name,
48
+ description: preprocessor.description || `A Lua preprocessor for ${preprocessor.name}`,
49
+ context: preprocessor.context || ''
50
+ };
51
+ const api = new PreProcessorApi(BASE_URLS.API, apiKey, agentId);
52
+ const result = await api.createPreProcessor(payload);
53
+ if (result.success && result.data && result.data.id) {
54
+ const newId = result.data.id;
55
+ if (!existingPreProcessor) {
56
+ existingPreProcessors.push({
57
+ name: preprocessor.name || '',
58
+ version: preprocessor.version || SKILL_DEFAULTS.VERSION,
59
+ preprocessorId: newId
60
+ });
61
+ }
62
+ else {
63
+ existingPreProcessor.preprocessorId = newId;
64
+ }
65
+ if (!config.preprocessors) {
66
+ config.preprocessors = existingPreProcessors;
67
+ }
68
+ return {
69
+ ...preprocessor,
70
+ preprocessorId: newId
71
+ };
72
+ }
73
+ else {
74
+ throw new Error(result.error?.message || "Failed to create preprocessor");
75
+ }
76
+ }
77
+ catch (error) {
78
+ console.warn(`Warning: Could not create preprocessor ${preprocessor.name}:`, error);
79
+ return preprocessor;
80
+ }
81
+ }
82
+ async function updateYamlWithPreProcessors(config) {
83
+ const yamlPath = path.join(process.cwd(), 'lua.skill.yaml');
84
+ const yamlContent = yaml.dump(config, { ...YAML_FORMAT, sortKeys: (a, b) => {
85
+ const order = ['agent', 'skills', 'webhooks', 'jobs', 'preprocessors', 'postprocessors', 'skill'];
86
+ const aIndex = order.indexOf(a);
87
+ const bIndex = order.indexOf(b);
88
+ if (aIndex !== -1 && bIndex !== -1)
89
+ return aIndex - bIndex;
90
+ if (aIndex !== -1)
91
+ return -1;
92
+ if (bIndex !== -1)
93
+ return 1;
94
+ return a.localeCompare(b);
95
+ } });
96
+ fs.writeFileSync(yamlPath, yamlContent);
97
+ }
98
+ export async function syncServerPreProcessorsWithYaml(config) {
99
+ const messages = [];
100
+ try {
101
+ const apiKey = await loadApiKey();
102
+ if (!apiKey) {
103
+ console.warn("⚠️ No API key found. Skipping server preprocessor sync.");
104
+ return messages;
105
+ }
106
+ const agentId = config?.agent?.agentId;
107
+ if (!agentId) {
108
+ console.warn("⚠️ No agent ID found. Skipping server preprocessor sync.");
109
+ return messages;
110
+ }
111
+ // Server sync will be implemented when backend is ready
112
+ return messages;
113
+ }
114
+ catch (error) {
115
+ console.warn("⚠️ Error syncing preprocessors:", error);
116
+ return messages;
117
+ }
118
+ }
@@ -25,3 +25,51 @@ export declare function setSandboxSkillId(sandboxId: string, skillName?: string)
25
25
  * @returns Array of skill overrides with skillId and sandboxId pairs
26
26
  */
27
27
  export declare function getAllSandboxSkillIds(deployData: any): Promise<SkillOverride[]>;
28
+ /**
29
+ * Retrieves sandbox preprocessor ID from secure storage.
30
+ *
31
+ * @param preprocessorName - Preprocessor name
32
+ * @returns The sandbox preprocessor ID or null if not found
33
+ */
34
+ export declare function getSandboxPreProcessorId(preprocessorName: string): Promise<string | null>;
35
+ /**
36
+ * Stores sandbox preprocessor ID in secure storage.
37
+ *
38
+ * @param sandboxId - The sandbox preprocessor ID to store
39
+ * @param preprocessorName - Preprocessor name
40
+ */
41
+ export declare function setSandboxPreProcessorId(sandboxId: string, preprocessorName: string): Promise<void>;
42
+ /**
43
+ * Retrieves sandbox postprocessor ID from secure storage.
44
+ *
45
+ * @param postprocessorName - Postprocessor name
46
+ * @returns The sandbox postprocessor ID or null if not found
47
+ */
48
+ export declare function getSandboxPostProcessorId(postprocessorName: string): Promise<string | null>;
49
+ /**
50
+ * Stores sandbox postprocessor ID in secure storage.
51
+ *
52
+ * @param sandboxId - The sandbox postprocessor ID to store
53
+ * @param postprocessorName - Postprocessor name
54
+ */
55
+ export declare function setSandboxPostProcessorId(sandboxId: string, postprocessorName: string): Promise<void>;
56
+ /**
57
+ * Gets all sandbox preprocessor overrides for the current config.
58
+ *
59
+ * @param config - Configuration with preprocessors
60
+ * @returns Array of preprocessor overrides
61
+ */
62
+ export declare function getAllSandboxPreProcessorIds(config: any): Promise<Array<{
63
+ preprocessorId: string;
64
+ sandboxId: string;
65
+ }>>;
66
+ /**
67
+ * Gets all sandbox postprocessor overrides for the current config.
68
+ *
69
+ * @param config - Configuration with postprocessors
70
+ * @returns Array of postprocessor overrides
71
+ */
72
+ export declare function getAllSandboxPostProcessorIds(config: any): Promise<Array<{
73
+ postprocessorId: string;
74
+ sandboxId: string;
75
+ }>>;
@@ -69,3 +69,117 @@ export async function getAllSandboxSkillIds(deployData) {
69
69
  }
70
70
  return skillOverrides;
71
71
  }
72
+ /**
73
+ * Retrieves sandbox preprocessor ID from secure storage.
74
+ *
75
+ * @param preprocessorName - Preprocessor name
76
+ * @returns The sandbox preprocessor ID or null if not found
77
+ */
78
+ export async function getSandboxPreProcessorId(preprocessorName) {
79
+ try {
80
+ const account = `${SANDBOX_STORAGE.ACCOUNT}_preprocessor_${preprocessorName}`;
81
+ return await keytar.getPassword(SANDBOX_STORAGE.SERVICE, account);
82
+ }
83
+ catch (error) {
84
+ return null;
85
+ }
86
+ }
87
+ /**
88
+ * Stores sandbox preprocessor ID in secure storage.
89
+ *
90
+ * @param sandboxId - The sandbox preprocessor ID to store
91
+ * @param preprocessorName - Preprocessor name
92
+ */
93
+ export async function setSandboxPreProcessorId(sandboxId, preprocessorName) {
94
+ try {
95
+ const account = `${SANDBOX_STORAGE.ACCOUNT}_preprocessor_${preprocessorName}`;
96
+ await keytar.setPassword(SANDBOX_STORAGE.SERVICE, account, sandboxId);
97
+ }
98
+ catch (error) {
99
+ // Ignore storage errors
100
+ }
101
+ }
102
+ /**
103
+ * Retrieves sandbox postprocessor ID from secure storage.
104
+ *
105
+ * @param postprocessorName - Postprocessor name
106
+ * @returns The sandbox postprocessor ID or null if not found
107
+ */
108
+ export async function getSandboxPostProcessorId(postprocessorName) {
109
+ try {
110
+ const account = `${SANDBOX_STORAGE.ACCOUNT}_postprocessor_${postprocessorName}`;
111
+ return await keytar.getPassword(SANDBOX_STORAGE.SERVICE, account);
112
+ }
113
+ catch (error) {
114
+ return null;
115
+ }
116
+ }
117
+ /**
118
+ * Stores sandbox postprocessor ID in secure storage.
119
+ *
120
+ * @param sandboxId - The sandbox postprocessor ID to store
121
+ * @param postprocessorName - Postprocessor name
122
+ */
123
+ export async function setSandboxPostProcessorId(sandboxId, postprocessorName) {
124
+ try {
125
+ const account = `${SANDBOX_STORAGE.ACCOUNT}_postprocessor_${postprocessorName}`;
126
+ await keytar.setPassword(SANDBOX_STORAGE.SERVICE, account, sandboxId);
127
+ }
128
+ catch (error) {
129
+ // Ignore storage errors
130
+ }
131
+ }
132
+ /**
133
+ * Gets all sandbox preprocessor overrides for the current config.
134
+ *
135
+ * @param config - Configuration with preprocessors
136
+ * @returns Array of preprocessor overrides
137
+ */
138
+ export async function getAllSandboxPreProcessorIds(config) {
139
+ const overrides = [];
140
+ try {
141
+ const preprocessors = config.preprocessors || [];
142
+ for (const preprocessor of preprocessors) {
143
+ if (preprocessor.preprocessorId && preprocessor.name) {
144
+ const sandboxId = await getSandboxPreProcessorId(preprocessor.name);
145
+ if (sandboxId) {
146
+ overrides.push({
147
+ preprocessorId: preprocessor.preprocessorId,
148
+ sandboxId: sandboxId
149
+ });
150
+ }
151
+ }
152
+ }
153
+ }
154
+ catch (error) {
155
+ console.error('Error getting sandbox preprocessor IDs:', error);
156
+ }
157
+ return overrides;
158
+ }
159
+ /**
160
+ * Gets all sandbox postprocessor overrides for the current config.
161
+ *
162
+ * @param config - Configuration with postprocessors
163
+ * @returns Array of postprocessor overrides
164
+ */
165
+ export async function getAllSandboxPostProcessorIds(config) {
166
+ const overrides = [];
167
+ try {
168
+ const postprocessors = config.postprocessors || [];
169
+ for (const postprocessor of postprocessors) {
170
+ if (postprocessor.postprocessorId && postprocessor.name) {
171
+ const sandboxId = await getSandboxPostProcessorId(postprocessor.name);
172
+ if (sandboxId) {
173
+ overrides.push({
174
+ postprocessorId: postprocessor.postprocessorId,
175
+ sandboxId: sandboxId
176
+ });
177
+ }
178
+ }
179
+ }
180
+ }
181
+ catch (error) {
182
+ console.error('Error getting sandbox postprocessor IDs:', error);
183
+ }
184
+ return overrides;
185
+ }
@@ -8,6 +8,27 @@ export interface ExecuteToolOptions extends SandboxOptions {
8
8
  toolCode: string;
9
9
  inputs: any;
10
10
  }
11
+ export interface ExecuteWebhookOptions extends SandboxOptions {
12
+ webhookCode: string;
13
+ query: any;
14
+ headers: any;
15
+ body: any;
16
+ }
17
+ export interface ExecuteJobOptions extends SandboxOptions {
18
+ jobCode: string;
19
+ jobData?: any;
20
+ }
21
+ export interface ExecutePreProcessorOptions extends SandboxOptions {
22
+ processorCode: string;
23
+ messages: any[];
24
+ channel: string;
25
+ }
26
+ export interface ExecutePostProcessorOptions extends SandboxOptions {
27
+ processorCode: string;
28
+ message: string;
29
+ response: string;
30
+ channel: string;
31
+ }
11
32
  /**
12
33
  * Loads environment variables from multiple sources in priority order:
13
34
  * 1. process.env (lowest priority)
@@ -16,13 +37,52 @@ export interface ExecuteToolOptions extends SandboxOptions {
16
37
  */
17
38
  export declare function loadEnvironmentVariables(): Record<string, string>;
18
39
  /**
19
- * Creates a VM sandbox context with all necessary globals and utilities
40
+ * Creates a VM sandbox context with all necessary globals and utilities.
41
+ *
42
+ * Available globals in the sandbox:
43
+ * - User: User data API
44
+ * - Products: Product catalog API
45
+ * - Data: Custom data collections API
46
+ * - Baskets: Shopping basket API
47
+ * - Orders: Order management API
48
+ * - Webhooks: Webhook management API (new)
49
+ * - Jobs: Job scheduling API (new)
50
+ * - env(): Environment variable access function
51
+ * - console, fetch, and other standard globals
20
52
  */
21
53
  export declare function createSandbox(options: SandboxOptions): any;
22
54
  /**
23
55
  * Executes a tool in a VM sandbox
24
56
  */
25
57
  export declare function executeTool(options: ExecuteToolOptions): Promise<any>;
58
+ /**
59
+ * Executes a webhook in a sandboxed environment.
60
+ *
61
+ * @param options - Webhook execution options including code and request data
62
+ * @returns Result from webhook execution
63
+ */
64
+ export declare function executeWebhook(options: ExecuteWebhookOptions): Promise<any>;
65
+ /**
66
+ * Executes a job in a sandboxed environment.
67
+ *
68
+ * @param options - Job execution options including code and job data
69
+ * @returns Result from job execution
70
+ */
71
+ export declare function executeJob(options: ExecuteJobOptions): Promise<any>;
72
+ /**
73
+ * Executes a preprocessor in a sandboxed environment.
74
+ *
75
+ * @param options - PreProcessor execution options
76
+ * @returns Processed message string
77
+ */
78
+ export declare function executePreProcessor(options: ExecutePreProcessorOptions): Promise<any[]>;
79
+ /**
80
+ * Executes a postprocessor in a sandboxed environment.
81
+ *
82
+ * @param options - PostProcessor execution options
83
+ * @returns Processed response string
84
+ */
85
+ export declare function executePostProcessor(options: ExecutePostProcessorOptions): Promise<string>;
26
86
  /**
27
87
  * Creates a custom console that broadcasts logs via WebSocket
28
88
  */