@jackle.dev/zalox-plugin 1.0.7 → 1.0.8
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/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/tools-scenario.ts +48 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { zaloxPlugin, zaloxDock } from './channel.js';
|
|
|
10
10
|
import { setPluginRuntime } from './listener.js';
|
|
11
11
|
import { zaloxGroupTool } from './tools.js';
|
|
12
12
|
import { zaloxTemplateTool } from './tools-template.js';
|
|
13
|
+
import { zaloxScenarioTool } from './tools-scenario.js';
|
|
13
14
|
|
|
14
15
|
const plugin = {
|
|
15
16
|
id: 'zalox',
|
|
@@ -26,6 +27,7 @@ const plugin = {
|
|
|
26
27
|
// Register admin tool
|
|
27
28
|
api.registerTool(zaloxGroupTool);
|
|
28
29
|
api.registerTool(zaloxTemplateTool);
|
|
30
|
+
api.registerTool(zaloxScenarioTool);
|
|
29
31
|
},
|
|
30
32
|
};
|
|
31
33
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createTemplate } from './core/templates.js';
|
|
3
|
+
|
|
4
|
+
export const zaloxScenarioTool = {
|
|
5
|
+
name: 'zalox_scenario',
|
|
6
|
+
description: 'Import scenario templates from a URL or Registry ID.',
|
|
7
|
+
parameters: z.object({
|
|
8
|
+
action: z.enum(['import']),
|
|
9
|
+
url: z.string().optional().describe('Direct URL to scenario JSON'),
|
|
10
|
+
registryId: z.string().optional().describe('Registry ID (e.g., "appointment-booking")'),
|
|
11
|
+
}),
|
|
12
|
+
execute: async (args: any) => {
|
|
13
|
+
const { action, url, registryId } = args;
|
|
14
|
+
if (action !== 'import') return 'Only import action supported';
|
|
15
|
+
|
|
16
|
+
let targetUrl = url;
|
|
17
|
+
if (!targetUrl && registryId) {
|
|
18
|
+
// Default to jackle.dev registry
|
|
19
|
+
targetUrl = `https://zalox.jackle.dev/registry/${registryId}.json`;
|
|
20
|
+
}
|
|
21
|
+
if (!targetUrl) throw new Error('url or registryId required');
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(targetUrl);
|
|
25
|
+
if (!res.ok) throw new Error(`Fetch failed: ${res.statusText}`);
|
|
26
|
+
const data = await res.json();
|
|
27
|
+
|
|
28
|
+
const results = [];
|
|
29
|
+
if (Array.isArray(data.templates)) {
|
|
30
|
+
for (const t of data.templates) {
|
|
31
|
+
try {
|
|
32
|
+
createTemplate(t.name, t.content);
|
|
33
|
+
results.push(`✅ Created "${t.name}"`);
|
|
34
|
+
} catch (e: any) {
|
|
35
|
+
if (e.message.includes('exists')) {
|
|
36
|
+
results.push(`⚠️ Skipped "${t.name}" (already exists)`);
|
|
37
|
+
} else {
|
|
38
|
+
results.push(`❌ Failed "${t.name}": ${e.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return `Imported scenario "${data.name || 'Unknown'}":\n${results.join('\n')}`;
|
|
44
|
+
} catch (e: any) {
|
|
45
|
+
return `Scenario import failed: ${e.message}`;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|