lua-cli 2.5.8 → 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/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 +13 -0
- package/dist/api/user.data.api.service.js +20 -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 +75 -5
- package/dist/commands/compile.js +124 -5
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.js +4 -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/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.js +684 -5
- 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/job.instance.d.ts +77 -0
- package/dist/common/job.instance.js +108 -0
- package/dist/common/user.instance.d.ts +1 -0
- package/dist/common/user.instance.js +9 -0
- package/dist/config/constants.d.ts +2 -2
- package/dist/config/constants.js +4 -4
- package/dist/interfaces/agent.d.ts +2 -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/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 +5 -0
- 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/package.json +1 -1
- 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/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,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostProcessors Command
|
|
3
|
+
* Manages agent postprocessors for production environment
|
|
4
|
+
*/
|
|
5
|
+
import { loadApiKey, checkApiKey } from '../services/auth.js';
|
|
6
|
+
import { readSkillConfig } from '../utils/files.js';
|
|
7
|
+
import { withErrorHandling, writeProgress, writeSuccess, writeInfo } from '../utils/cli.js';
|
|
8
|
+
import { BASE_URLS } from '../config/constants.js';
|
|
9
|
+
import { safePrompt } from '../utils/prompt-handler.js';
|
|
10
|
+
import { validateConfig, validateAgentConfig, } from '../utils/dev-helpers.js';
|
|
11
|
+
import PostProcessorApi from '../api/postprocessor.api.service.js';
|
|
12
|
+
/**
|
|
13
|
+
* Main postprocessors command - manages agent postprocessors
|
|
14
|
+
*/
|
|
15
|
+
export async function postprocessorsCommand() {
|
|
16
|
+
return withErrorHandling(async () => {
|
|
17
|
+
// Step 1: Load configuration
|
|
18
|
+
const config = readSkillConfig();
|
|
19
|
+
validateConfig(config);
|
|
20
|
+
validateAgentConfig(config);
|
|
21
|
+
const agentId = config.agent.agentId;
|
|
22
|
+
// Step 2: Authenticate
|
|
23
|
+
const apiKey = await loadApiKey();
|
|
24
|
+
if (!apiKey) {
|
|
25
|
+
console.error("❌ No API key found. Please run 'lua auth configure' to set up your API key.");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
await checkApiKey(apiKey);
|
|
29
|
+
writeProgress("✅ Authenticated");
|
|
30
|
+
const context = {
|
|
31
|
+
agentId,
|
|
32
|
+
apiKey,
|
|
33
|
+
};
|
|
34
|
+
// Start postprocessor management
|
|
35
|
+
await manageProductionPostProcessors(context, config);
|
|
36
|
+
}, "postprocessors");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Manage production postprocessors
|
|
40
|
+
*/
|
|
41
|
+
async function manageProductionPostProcessors(context, config) {
|
|
42
|
+
let continueManaging = true;
|
|
43
|
+
while (continueManaging) {
|
|
44
|
+
console.log("\n" + "=".repeat(60));
|
|
45
|
+
console.log("🚀 Production PostProcessors");
|
|
46
|
+
console.log("=".repeat(60) + "\n");
|
|
47
|
+
const actionAnswer = await safePrompt([
|
|
48
|
+
{
|
|
49
|
+
type: 'list',
|
|
50
|
+
name: 'action',
|
|
51
|
+
message: 'What would you like to do?',
|
|
52
|
+
choices: [
|
|
53
|
+
{ name: '👁️ View deployed postprocessors', value: 'view' },
|
|
54
|
+
{ name: '📜 View postprocessor versions', value: 'versions' },
|
|
55
|
+
{ name: '🚀 Deploy a version', value: 'deploy' },
|
|
56
|
+
{ name: '✅ Activate a postprocessor', value: 'activate' },
|
|
57
|
+
{ name: '🚫 Deactivate a postprocessor', value: 'deactivate' },
|
|
58
|
+
{ name: '🗑️ Delete a postprocessor', value: 'delete' },
|
|
59
|
+
{ name: '❌ Exit', value: 'exit' }
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
if (!actionAnswer)
|
|
64
|
+
return;
|
|
65
|
+
const { action } = actionAnswer;
|
|
66
|
+
switch (action) {
|
|
67
|
+
case 'view':
|
|
68
|
+
await viewDeployedPostProcessors(context, config);
|
|
69
|
+
break;
|
|
70
|
+
case 'versions':
|
|
71
|
+
await viewPostProcessorVersions(context, config);
|
|
72
|
+
break;
|
|
73
|
+
case 'deploy':
|
|
74
|
+
await deployPostProcessorVersion(context, config);
|
|
75
|
+
break;
|
|
76
|
+
case 'activate':
|
|
77
|
+
await activatePostProcessor(context, config);
|
|
78
|
+
break;
|
|
79
|
+
case 'deactivate':
|
|
80
|
+
await deactivatePostProcessor(context, config);
|
|
81
|
+
break;
|
|
82
|
+
case 'delete':
|
|
83
|
+
await deletePostProcessor(context, config);
|
|
84
|
+
break;
|
|
85
|
+
case 'exit':
|
|
86
|
+
continueManaging = false;
|
|
87
|
+
console.log("\n👋 Goodbye!\n");
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* View deployed postprocessors in production
|
|
94
|
+
*/
|
|
95
|
+
async function viewDeployedPostProcessors(context, config) {
|
|
96
|
+
writeProgress("🔄 Loading postprocessor information...");
|
|
97
|
+
try {
|
|
98
|
+
const postprocessors = config.postprocessors || [];
|
|
99
|
+
if (postprocessors.length === 0) {
|
|
100
|
+
console.log("\nℹ️ No postprocessors found in configuration.\n");
|
|
101
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
console.log("\n" + "=".repeat(60));
|
|
105
|
+
console.log("⚙️ Production PostProcessors");
|
|
106
|
+
console.log("=".repeat(60) + "\n");
|
|
107
|
+
const api = new PostProcessorApi(BASE_URLS.API, context.apiKey, context.agentId);
|
|
108
|
+
for (const postprocessor of postprocessors) {
|
|
109
|
+
try {
|
|
110
|
+
const response = await api.getPostProcessorVersions(postprocessor.postprocessorId);
|
|
111
|
+
if (response.success && response.data) {
|
|
112
|
+
const versions = response.data.versions || [];
|
|
113
|
+
const activeVersionId = response.data.activeVersionId;
|
|
114
|
+
const activeVersion = versions.find((v) => v.versionId === activeVersionId);
|
|
115
|
+
console.log(`📤 ${postprocessor.name}`);
|
|
116
|
+
console.log(` PostProcessor ID: ${postprocessor.postprocessorId}`);
|
|
117
|
+
if (activeVersion) {
|
|
118
|
+
console.log(` Deployed Version: ${activeVersion.version} ⭐`);
|
|
119
|
+
const date = new Date(activeVersion.createdAt);
|
|
120
|
+
console.log(` Deployed: ${date.toLocaleString()}`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
console.log(` Deployed Version: Not deployed`);
|
|
124
|
+
}
|
|
125
|
+
console.log(` Total Versions: ${versions.length}`);
|
|
126
|
+
console.log();
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.log(`📤 ${postprocessor.name}`);
|
|
130
|
+
console.log(` PostProcessor ID: ${postprocessor.postprocessorId}`);
|
|
131
|
+
console.log(` Status: Unable to fetch version info`);
|
|
132
|
+
console.log();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.log(`📤 ${postprocessor.name}`);
|
|
137
|
+
console.log(` PostProcessor ID: ${postprocessor.postprocessorId}`);
|
|
138
|
+
console.log(` Status: Error loading versions`);
|
|
139
|
+
console.log();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
console.log("=".repeat(60) + "\n");
|
|
143
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('❌ Error loading postprocessor information:', error);
|
|
147
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* View versions for a specific postprocessor
|
|
152
|
+
*/
|
|
153
|
+
async function viewPostProcessorVersions(context, config) {
|
|
154
|
+
const postprocessors = config.postprocessors || [];
|
|
155
|
+
if (postprocessors.length === 0) {
|
|
156
|
+
console.log("\nℹ️ No postprocessors found in configuration.\n");
|
|
157
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const answer = await safePrompt([
|
|
161
|
+
{
|
|
162
|
+
type: 'list',
|
|
163
|
+
name: 'selected',
|
|
164
|
+
message: 'Select a postprocessor to view versions:',
|
|
165
|
+
choices: postprocessors.map((p) => ({
|
|
166
|
+
name: `${p.name} (${p.postprocessorId})`,
|
|
167
|
+
value: p
|
|
168
|
+
}))
|
|
169
|
+
}
|
|
170
|
+
]);
|
|
171
|
+
if (!answer)
|
|
172
|
+
return;
|
|
173
|
+
const selected = answer.selected;
|
|
174
|
+
writeProgress(`🔄 Loading versions for ${selected.name}...`);
|
|
175
|
+
try {
|
|
176
|
+
const api = new PostProcessorApi(BASE_URLS.API, context.apiKey, context.agentId);
|
|
177
|
+
const response = await api.getPostProcessorVersions(selected.postprocessorId);
|
|
178
|
+
if (!response.success || !response.data) {
|
|
179
|
+
throw new Error(response.error?.message || 'Failed to fetch versions');
|
|
180
|
+
}
|
|
181
|
+
const versions = response.data.versions || [];
|
|
182
|
+
const activeVersionId = response.data.activeVersionId;
|
|
183
|
+
if (versions.length === 0) {
|
|
184
|
+
console.log(`\nℹ️ No versions found for ${selected.name}.\n`);
|
|
185
|
+
console.log("💡 Push a version first using 'lua push postprocessor'.\n");
|
|
186
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const sortedVersions = versions.sort((a, b) => {
|
|
190
|
+
const dateA = new Date(a.createdAt).getTime();
|
|
191
|
+
const dateB = new Date(b.createdAt).getTime();
|
|
192
|
+
return dateB - dateA;
|
|
193
|
+
});
|
|
194
|
+
console.log("\n" + "=".repeat(60));
|
|
195
|
+
console.log(`📜 Versions for ${selected.name}`);
|
|
196
|
+
console.log("=".repeat(60) + "\n");
|
|
197
|
+
sortedVersions.forEach((version) => {
|
|
198
|
+
const isActive = version.postprocessorId === activeVersionId;
|
|
199
|
+
const date = new Date(version.createdAt);
|
|
200
|
+
console.log(`${isActive ? '⭐' : ' '} Version ${version.version}`);
|
|
201
|
+
console.log(` Created: ${date.toLocaleString()}`);
|
|
202
|
+
console.log();
|
|
203
|
+
});
|
|
204
|
+
console.log("=".repeat(60) + "\n");
|
|
205
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.error('\n❌ Error loading versions:', error);
|
|
209
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Deploy a postprocessor version to production
|
|
214
|
+
*/
|
|
215
|
+
async function deployPostProcessorVersion(context, config) {
|
|
216
|
+
const postprocessors = config.postprocessors || [];
|
|
217
|
+
if (postprocessors.length === 0) {
|
|
218
|
+
console.log("\nℹ️ No postprocessors found in configuration.\n");
|
|
219
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const answer = await safePrompt([
|
|
223
|
+
{
|
|
224
|
+
type: 'list',
|
|
225
|
+
name: 'selected',
|
|
226
|
+
message: 'Select a postprocessor to deploy:',
|
|
227
|
+
choices: postprocessors.map((p) => ({
|
|
228
|
+
name: `${p.name} (${p.postprocessorId})`,
|
|
229
|
+
value: p
|
|
230
|
+
}))
|
|
231
|
+
}
|
|
232
|
+
]);
|
|
233
|
+
if (!answer)
|
|
234
|
+
return;
|
|
235
|
+
const selected = answer.selected;
|
|
236
|
+
writeProgress(`🔄 Loading versions for ${selected.name}...`);
|
|
237
|
+
try {
|
|
238
|
+
const api = new PostProcessorApi(BASE_URLS.API, context.apiKey, context.agentId);
|
|
239
|
+
const response = await api.getPostProcessorVersions(selected.postprocessorId);
|
|
240
|
+
if (!response.success || !response.data) {
|
|
241
|
+
throw new Error(response.error?.message || 'Failed to fetch versions');
|
|
242
|
+
}
|
|
243
|
+
const versions = response.data.versions || [];
|
|
244
|
+
const activeVersionId = response.data.activeVersionId;
|
|
245
|
+
if (versions.length === 0) {
|
|
246
|
+
console.log(`\nℹ️ No versions found for ${selected.name}.\n`);
|
|
247
|
+
console.log("💡 Push a version first using 'lua push postprocessor'.\n");
|
|
248
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const sortedVersions = versions.sort((a, b) => {
|
|
252
|
+
const dateA = new Date(a.createdAt).getTime();
|
|
253
|
+
const dateB = new Date(b.createdAt).getTime();
|
|
254
|
+
return dateB - dateA;
|
|
255
|
+
});
|
|
256
|
+
const versionAnswer = await safePrompt([
|
|
257
|
+
{
|
|
258
|
+
type: 'list',
|
|
259
|
+
name: 'selectedVersion',
|
|
260
|
+
message: 'Select a version to deploy:',
|
|
261
|
+
choices: sortedVersions.map((version) => {
|
|
262
|
+
const isActive = version.postprocessorId === activeVersionId;
|
|
263
|
+
const date = new Date(version.createdAt);
|
|
264
|
+
return {
|
|
265
|
+
name: `Version ${version.version} (${date.toLocaleDateString()})${isActive ? ' ⭐ CURRENT' : ''}`,
|
|
266
|
+
value: version
|
|
267
|
+
};
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
]);
|
|
271
|
+
if (!versionAnswer)
|
|
272
|
+
return;
|
|
273
|
+
const selectedVersion = versionAnswer.selectedVersion;
|
|
274
|
+
console.log("\n⚠️ WARNING: You are about to deploy to PRODUCTION!");
|
|
275
|
+
console.log("⚠️ This will affect ALL users immediately.\n");
|
|
276
|
+
console.log(`PostProcessor: ${selected.name}`);
|
|
277
|
+
console.log(`Version: ${selectedVersion.version}\n`);
|
|
278
|
+
const confirmAnswer = await safePrompt([
|
|
279
|
+
{
|
|
280
|
+
type: 'confirm',
|
|
281
|
+
name: 'confirm',
|
|
282
|
+
message: 'Are you absolutely sure you want to deploy this version?',
|
|
283
|
+
default: false
|
|
284
|
+
}
|
|
285
|
+
]);
|
|
286
|
+
if (!confirmAnswer || !confirmAnswer.confirm) {
|
|
287
|
+
console.log("\n❌ Deployment cancelled.\n");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
writeProgress("🔄 Deploying version...");
|
|
291
|
+
const deployResponse = await api.publishPostProcessorVersion(selected.postprocessorId, selectedVersion.version);
|
|
292
|
+
if (!deployResponse.success) {
|
|
293
|
+
console.error(`\n❌ Deploy Error: ${deployResponse.error?.message || 'Unknown error'}\n`);
|
|
294
|
+
throw new Error(deployResponse.error?.message || 'Failed to publish postprocessor version');
|
|
295
|
+
}
|
|
296
|
+
writeSuccess(`\n✅ Version ${selectedVersion.version} of "${selected.name}" deployed successfully to production\n`);
|
|
297
|
+
writeInfo("💡 The new version is now active and will process all outgoing responses.");
|
|
298
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
console.error('\n❌ Error deploying version:', error);
|
|
302
|
+
await safePrompt([{ type: 'input', name: 'continue', message: 'Press Enter to continue...' }]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Activate a postprocessor
|
|
307
|
+
*/
|
|
308
|
+
async function activatePostProcessor(context, config) {
|
|
309
|
+
const postprocessors = config.postprocessors || [];
|
|
310
|
+
if (postprocessors.length === 0) {
|
|
311
|
+
console.log("\nℹ️ No postprocessors found.\n");
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const answer = await safePrompt([
|
|
315
|
+
{
|
|
316
|
+
type: 'list',
|
|
317
|
+
name: 'selected',
|
|
318
|
+
message: 'Select a postprocessor to activate:',
|
|
319
|
+
choices: postprocessors.map((p) => ({
|
|
320
|
+
name: `${p.name} (${p.postprocessorId})`,
|
|
321
|
+
value: p
|
|
322
|
+
}))
|
|
323
|
+
}
|
|
324
|
+
]);
|
|
325
|
+
if (!answer)
|
|
326
|
+
return;
|
|
327
|
+
writeProgress(`🔄 Activating postprocessor "${answer.selected.name}"...`);
|
|
328
|
+
const api = new PostProcessorApi(BASE_URLS.API, context.apiKey, context.agentId);
|
|
329
|
+
const response = await api.activatePostProcessor(answer.selected.postprocessorId);
|
|
330
|
+
if (response.success) {
|
|
331
|
+
writeSuccess(`✅ PostProcessor "${answer.selected.name}" activated successfully`);
|
|
332
|
+
writeInfo("💡 The postprocessor is now enabled and will process all outgoing responses.");
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
console.error(`❌ Failed to activate postprocessor: ${response.error?.message || 'Unknown error'}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Deactivate a postprocessor
|
|
340
|
+
*/
|
|
341
|
+
async function deactivatePostProcessor(context, config) {
|
|
342
|
+
const postprocessors = config.postprocessors || [];
|
|
343
|
+
if (postprocessors.length === 0) {
|
|
344
|
+
console.log("\nℹ️ No postprocessors found.\n");
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const answer = await safePrompt([
|
|
348
|
+
{
|
|
349
|
+
type: 'list',
|
|
350
|
+
name: 'selected',
|
|
351
|
+
message: 'Select a postprocessor to deactivate:',
|
|
352
|
+
choices: postprocessors.map((p) => ({
|
|
353
|
+
name: `${p.name} (${p.postprocessorId})`,
|
|
354
|
+
value: p
|
|
355
|
+
}))
|
|
356
|
+
}
|
|
357
|
+
]);
|
|
358
|
+
if (!answer)
|
|
359
|
+
return;
|
|
360
|
+
const confirmAnswer = await safePrompt([
|
|
361
|
+
{
|
|
362
|
+
type: 'confirm',
|
|
363
|
+
name: 'confirm',
|
|
364
|
+
message: `Are you sure you want to deactivate "${answer.selected.name}"? Responses will not be postprocessed.`,
|
|
365
|
+
default: false
|
|
366
|
+
}
|
|
367
|
+
]);
|
|
368
|
+
if (!confirmAnswer || !confirmAnswer.confirm) {
|
|
369
|
+
console.log("\n❌ Deactivation cancelled.\n");
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
writeProgress(`🔄 Deactivating postprocessor "${answer.selected.name}"...`);
|
|
373
|
+
const api = new PostProcessorApi(BASE_URLS.API, context.apiKey, context.agentId);
|
|
374
|
+
const response = await api.deactivatePostProcessor(answer.selected.postprocessorId);
|
|
375
|
+
if (response.success) {
|
|
376
|
+
writeSuccess(`✅ PostProcessor "${answer.selected.name}" deactivated successfully`);
|
|
377
|
+
writeInfo("💡 The postprocessor is now disabled.");
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
console.error(`❌ Failed to deactivate postprocessor: ${response.error?.message || 'Unknown error'}`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Delete a postprocessor
|
|
385
|
+
*/
|
|
386
|
+
async function deletePostProcessor(context, config) {
|
|
387
|
+
const postprocessors = config.postprocessors || [];
|
|
388
|
+
if (postprocessors.length === 0) {
|
|
389
|
+
console.log("\nℹ️ No postprocessors found.\n");
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const answer = await safePrompt([
|
|
393
|
+
{
|
|
394
|
+
type: 'list',
|
|
395
|
+
name: 'selected',
|
|
396
|
+
message: 'Select a postprocessor to delete:',
|
|
397
|
+
choices: postprocessors.map((p) => ({
|
|
398
|
+
name: `${p.name} (${p.postprocessorId})`,
|
|
399
|
+
value: p
|
|
400
|
+
}))
|
|
401
|
+
}
|
|
402
|
+
]);
|
|
403
|
+
if (!answer)
|
|
404
|
+
return;
|
|
405
|
+
const confirmAnswer = await safePrompt([
|
|
406
|
+
{
|
|
407
|
+
type: 'confirm',
|
|
408
|
+
name: 'confirm',
|
|
409
|
+
message: `⚠️ Are you sure you want to DELETE "${answer.selected.name}"? This cannot be undone.`,
|
|
410
|
+
default: false
|
|
411
|
+
}
|
|
412
|
+
]);
|
|
413
|
+
if (!confirmAnswer || !confirmAnswer.confirm) {
|
|
414
|
+
console.log("\n❌ Deletion cancelled.\n");
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
writeProgress(`🔄 Deleting postprocessor "${answer.selected.name}"...`);
|
|
418
|
+
const api = new PostProcessorApi(BASE_URLS.API, context.apiKey, context.agentId);
|
|
419
|
+
const response = await api.deletePostProcessor(answer.selected.postprocessorId);
|
|
420
|
+
if (response.success) {
|
|
421
|
+
if (response.data?.deleted) {
|
|
422
|
+
writeSuccess(`✅ PostProcessor "${answer.selected.name}" deleted successfully`);
|
|
423
|
+
}
|
|
424
|
+
else if (response.data?.deactivated) {
|
|
425
|
+
writeInfo(`⚠️ PostProcessor "${answer.selected.name}" has versions and cannot be deleted. It has been deactivated instead.`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
console.error(`❌ Failed to delete postprocessor: ${response.error?.message || 'Unknown error'}`);
|
|
430
|
+
}
|
|
431
|
+
}
|