@hailer/mcp 0.0.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/.claude/commands/tool-builder.md +37 -0
- package/.claude/commands/ws-pull.md +44 -0
- package/.claude/settings.json +8 -0
- package/.claude/settings.local.json +49 -0
- package/.claude/skills/activity-api/SKILL.md +96 -0
- package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
- package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
- package/.claude/skills/agent-building/SKILL.md +243 -0
- package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
- package/.claude/skills/agent-building/references/code-examples.md +587 -0
- package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
- package/.claude/skills/app-api/SKILL.md +219 -0
- package/.claude/skills/app-api/references/app-endpoints.md +759 -0
- package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
- package/.claude/skills/create-app-skill/SKILL.md +1101 -0
- package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
- package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
- package/.claude/skills/hailer-api/SKILL.md +283 -0
- package/.claude/skills/hailer-api/references/activities.md +620 -0
- package/.claude/skills/hailer-api/references/authentication.md +216 -0
- package/.claude/skills/hailer-api/references/datasets.md +437 -0
- package/.claude/skills/hailer-api/references/files.md +301 -0
- package/.claude/skills/hailer-api/references/insights.md +469 -0
- package/.claude/skills/hailer-api/references/workflows.md +720 -0
- package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
- package/.claude/skills/insight-api/SKILL.md +185 -0
- package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
- package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
- package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
- package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
- package/.claude/skills/local-first-skill/SKILL.md +570 -0
- package/.claude/skills/mcp-tools/SKILL.md +419 -0
- package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
- package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
- package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
- package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
- package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
- package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
- package/.claude/skills/remove-app-skill/SKILL.md +985 -0
- package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
- package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
- package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
- package/.claude/skills/skill-testing/README.md +137 -0
- package/.claude/skills/skill-testing/SKILL.md +348 -0
- package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
- package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
- package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
- package/.claude/skills/tool-builder/SKILL.md +328 -0
- package/.claude/skills/update-app-skill/SKILL.md +970 -0
- package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
- package/.env.example +81 -0
- package/.mcp.json +13 -0
- package/README.md +297 -0
- package/dist/app.d.ts +4 -0
- package/dist/app.js +74 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +5 -0
- package/dist/client/adaptive-documentation-bot.d.ts +108 -0
- package/dist/client/adaptive-documentation-bot.js +475 -0
- package/dist/client/adaptive-documentation-types.d.ts +66 -0
- package/dist/client/adaptive-documentation-types.js +9 -0
- package/dist/client/agent-activity-bot.d.ts +51 -0
- package/dist/client/agent-activity-bot.js +166 -0
- package/dist/client/agent-tracker.d.ts +499 -0
- package/dist/client/agent-tracker.js +659 -0
- package/dist/client/description-updater.d.ts +56 -0
- package/dist/client/description-updater.js +259 -0
- package/dist/client/log-parser.d.ts +72 -0
- package/dist/client/log-parser.js +387 -0
- package/dist/client/mcp-client.d.ts +50 -0
- package/dist/client/mcp-client.js +532 -0
- package/dist/client/message-processor.d.ts +35 -0
- package/dist/client/message-processor.js +352 -0
- package/dist/client/multi-bot-manager.d.ts +24 -0
- package/dist/client/multi-bot-manager.js +74 -0
- package/dist/client/providers/anthropic-provider.d.ts +19 -0
- package/dist/client/providers/anthropic-provider.js +631 -0
- package/dist/client/providers/llm-provider.d.ts +47 -0
- package/dist/client/providers/llm-provider.js +367 -0
- package/dist/client/providers/openai-provider.d.ts +23 -0
- package/dist/client/providers/openai-provider.js +621 -0
- package/dist/client/simple-llm-caller.d.ts +19 -0
- package/dist/client/simple-llm-caller.js +100 -0
- package/dist/client/skill-generator.d.ts +81 -0
- package/dist/client/skill-generator.js +386 -0
- package/dist/client/test-adaptive-bot.d.ts +9 -0
- package/dist/client/test-adaptive-bot.js +82 -0
- package/dist/client/token-pricing.d.ts +38 -0
- package/dist/client/token-pricing.js +127 -0
- package/dist/client/token-tracker.d.ts +232 -0
- package/dist/client/token-tracker.js +457 -0
- package/dist/client/token-usage-bot.d.ts +53 -0
- package/dist/client/token-usage-bot.js +153 -0
- package/dist/client/tool-executor.d.ts +69 -0
- package/dist/client/tool-executor.js +159 -0
- package/dist/client/tool-schema-loader.d.ts +60 -0
- package/dist/client/tool-schema-loader.js +178 -0
- package/dist/client/types.d.ts +69 -0
- package/dist/client/types.js +7 -0
- package/dist/config.d.ts +162 -0
- package/dist/config.js +296 -0
- package/dist/core.d.ts +26 -0
- package/dist/core.js +147 -0
- package/dist/lib/context-manager.d.ts +111 -0
- package/dist/lib/context-manager.js +431 -0
- package/dist/lib/logger.d.ts +74 -0
- package/dist/lib/logger.js +277 -0
- package/dist/lib/materialize.d.ts +3 -0
- package/dist/lib/materialize.js +101 -0
- package/dist/lib/normalizedName.d.ts +7 -0
- package/dist/lib/normalizedName.js +48 -0
- package/dist/lib/prompt-length-manager.d.ts +81 -0
- package/dist/lib/prompt-length-manager.js +457 -0
- package/dist/lib/terminal-prompt.d.ts +9 -0
- package/dist/lib/terminal-prompt.js +108 -0
- package/dist/mcp/UserContextCache.d.ts +56 -0
- package/dist/mcp/UserContextCache.js +163 -0
- package/dist/mcp/auth.d.ts +2 -0
- package/dist/mcp/auth.js +29 -0
- package/dist/mcp/hailer-clients.d.ts +42 -0
- package/dist/mcp/hailer-clients.js +246 -0
- package/dist/mcp/signal-handler.d.ts +45 -0
- package/dist/mcp/signal-handler.js +317 -0
- package/dist/mcp/tool-registry.d.ts +100 -0
- package/dist/mcp/tool-registry.js +306 -0
- package/dist/mcp/tools/activity.d.ts +15 -0
- package/dist/mcp/tools/activity.js +955 -0
- package/dist/mcp/tools/app.d.ts +20 -0
- package/dist/mcp/tools/app.js +1488 -0
- package/dist/mcp/tools/discussion.d.ts +19 -0
- package/dist/mcp/tools/discussion.js +950 -0
- package/dist/mcp/tools/file.d.ts +15 -0
- package/dist/mcp/tools/file.js +119 -0
- package/dist/mcp/tools/insight.d.ts +17 -0
- package/dist/mcp/tools/insight.js +806 -0
- package/dist/mcp/tools/skill.d.ts +10 -0
- package/dist/mcp/tools/skill.js +279 -0
- package/dist/mcp/tools/user.d.ts +10 -0
- package/dist/mcp/tools/user.js +108 -0
- package/dist/mcp/tools/workflow-template.d.ts +19 -0
- package/dist/mcp/tools/workflow-template.js +822 -0
- package/dist/mcp/tools/workflow.d.ts +18 -0
- package/dist/mcp/tools/workflow.js +1362 -0
- package/dist/mcp/utils/api-errors.d.ts +45 -0
- package/dist/mcp/utils/api-errors.js +160 -0
- package/dist/mcp/utils/data-transformers.d.ts +102 -0
- package/dist/mcp/utils/data-transformers.js +194 -0
- package/dist/mcp/utils/file-upload.d.ts +33 -0
- package/dist/mcp/utils/file-upload.js +148 -0
- package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
- package/dist/mcp/utils/hailer-api-client.js +323 -0
- package/dist/mcp/utils/index.d.ts +13 -0
- package/dist/mcp/utils/index.js +39 -0
- package/dist/mcp/utils/logger.d.ts +42 -0
- package/dist/mcp/utils/logger.js +103 -0
- package/dist/mcp/utils/types.d.ts +286 -0
- package/dist/mcp/utils/types.js +7 -0
- package/dist/mcp/workspace-cache.d.ts +42 -0
- package/dist/mcp/workspace-cache.js +97 -0
- package/dist/mcp-server.d.ts +42 -0
- package/dist/mcp-server.js +280 -0
- package/package.json +56 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Workflow Template Tools - Clean Architecture Implementation
|
|
4
|
+
*
|
|
5
|
+
* Document template management for Hailer workflows:
|
|
6
|
+
* - Templates define how to convert activity data into documents (PDF, etc.)
|
|
7
|
+
* - Templates can be workflow-specific or global
|
|
8
|
+
* - Preview and install capabilities for testing and deployment
|
|
9
|
+
*
|
|
10
|
+
* All 7 template management tools in one file for cohesion.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.installTemplateTool = exports.previewTemplateTool = exports.deleteTemplateTool = exports.updateTemplateTool = exports.createTemplateTool = exports.getTemplateTool = exports.listTemplatesTool = void 0;
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const tool_registry_1 = require("../tool-registry");
|
|
16
|
+
const logger_1 = require("../../lib/logger");
|
|
17
|
+
const logger = (0, logger_1.createLogger)({ component: 'template-tools' });
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// LIST TEMPLATES TOOL
|
|
20
|
+
// ============================================================================
|
|
21
|
+
const listTemplatesDescription = `๐งช [PLAYGROUND] List Templates - View all document templates in a workflow
|
|
22
|
+
|
|
23
|
+
**What are Templates?**
|
|
24
|
+
Templates are document generation templates in Hailer workflows. They define how to convert activity data into documents (PDF, etc.).
|
|
25
|
+
|
|
26
|
+
**Purpose**: List all templates for a specific workflow.
|
|
27
|
+
|
|
28
|
+
**Example**:
|
|
29
|
+
\`\`\`javascript
|
|
30
|
+
list_templates({
|
|
31
|
+
processId: "68446dc05b30685f67c6fcd4"
|
|
32
|
+
})
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
35
|
+
**Response includes**:
|
|
36
|
+
- Template ID and name
|
|
37
|
+
- File type (pdf, etc.)
|
|
38
|
+
- Description
|
|
39
|
+
- Configuration details
|
|
40
|
+
- Owner information`;
|
|
41
|
+
exports.listTemplatesTool = {
|
|
42
|
+
name: 'list_templates',
|
|
43
|
+
group: tool_registry_1.ToolGroup.PLAYGROUND,
|
|
44
|
+
description: listTemplatesDescription,
|
|
45
|
+
schema: zod_1.z.object({
|
|
46
|
+
processId: zod_1.z
|
|
47
|
+
.string()
|
|
48
|
+
.length(24)
|
|
49
|
+
.describe("Workflow/process ID to list templates from"),
|
|
50
|
+
}),
|
|
51
|
+
async execute(args, context) {
|
|
52
|
+
logger.debug('Listing templates', {
|
|
53
|
+
processId: args.processId,
|
|
54
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
logger.debug('Calling v3.template.list', {
|
|
58
|
+
processId: args.processId
|
|
59
|
+
});
|
|
60
|
+
const response = await context.hailer.request('v3.template.list', [args.processId]);
|
|
61
|
+
logger.debug('Templates list successful', {
|
|
62
|
+
count: Array.isArray(response) ? response.length : 0
|
|
63
|
+
});
|
|
64
|
+
const templates = Array.isArray(response) ? response : [];
|
|
65
|
+
let responseText = `๐ **Document Templates**\n\n`;
|
|
66
|
+
responseText += `**Workflow ID:** \`${args.processId}\`\n`;
|
|
67
|
+
responseText += `**Total Templates:** ${templates.length}\n\n`;
|
|
68
|
+
if (templates.length === 0) {
|
|
69
|
+
responseText += `No templates found for this workflow.\n\n`;
|
|
70
|
+
responseText += `๐ก Use \`create_template\` to create a new template.`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
templates.forEach((template, index) => {
|
|
74
|
+
responseText += `**${index + 1}. ${template.description || 'Unnamed Template'}**\n`;
|
|
75
|
+
responseText += ` ID: \`${template._id}\`\n`;
|
|
76
|
+
responseText += ` Type: ${template.fileType || 'Unknown'}\n`;
|
|
77
|
+
if (template.global)
|
|
78
|
+
responseText += ` Global: Yes\n`;
|
|
79
|
+
responseText += `\n`;
|
|
80
|
+
});
|
|
81
|
+
responseText += `๐ก **Next Steps:**\n`;
|
|
82
|
+
responseText += `- Use \`get_template\` to view template details\n`;
|
|
83
|
+
responseText += `- Use \`preview_template\` to test with activity data\n`;
|
|
84
|
+
responseText += `- Use \`update_template\` to modify templates\n`;
|
|
85
|
+
responseText += `- Use \`delete_template\` to remove templates`;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
content: [{
|
|
89
|
+
type: "text",
|
|
90
|
+
text: responseText,
|
|
91
|
+
}],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
logger.error("Error listing templates", error);
|
|
96
|
+
let errorMessage = 'Unknown error occurred';
|
|
97
|
+
if (error instanceof Error) {
|
|
98
|
+
errorMessage = error.message;
|
|
99
|
+
}
|
|
100
|
+
else if (typeof error === 'object' && error !== null) {
|
|
101
|
+
try {
|
|
102
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
errorMessage = String(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
errorMessage = String(error);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
content: [{
|
|
113
|
+
type: "text",
|
|
114
|
+
text: `โ **Error listing templates**\n\n**Error:** ${errorMessage}\n\n**Workflow ID:** \`${args.processId}\``,
|
|
115
|
+
}],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// GET TEMPLATE TOOL
|
|
122
|
+
// ============================================================================
|
|
123
|
+
const getTemplateDescription = `๐งช [PLAYGROUND] Get Template - View document template details
|
|
124
|
+
|
|
125
|
+
**Purpose**: Retrieve full details of a specific document template.
|
|
126
|
+
|
|
127
|
+
**Example**:
|
|
128
|
+
\`\`\`javascript
|
|
129
|
+
get_template({
|
|
130
|
+
templateId: "68446dc05b30685f67c6fcd4"
|
|
131
|
+
})
|
|
132
|
+
\`\`\`
|
|
133
|
+
|
|
134
|
+
**Response includes**:
|
|
135
|
+
- Template ID and description
|
|
136
|
+
- File type (pdf, etc.)
|
|
137
|
+
- Template content/structure
|
|
138
|
+
- Configuration
|
|
139
|
+
- Owner and workflow information`;
|
|
140
|
+
exports.getTemplateTool = {
|
|
141
|
+
name: 'get_template',
|
|
142
|
+
group: tool_registry_1.ToolGroup.PLAYGROUND,
|
|
143
|
+
description: getTemplateDescription,
|
|
144
|
+
schema: zod_1.z.object({
|
|
145
|
+
templateId: zod_1.z
|
|
146
|
+
.string()
|
|
147
|
+
.length(24)
|
|
148
|
+
.describe("Template ID to retrieve"),
|
|
149
|
+
}),
|
|
150
|
+
async execute(args, context) {
|
|
151
|
+
logger.debug('Getting template', {
|
|
152
|
+
templateId: args.templateId,
|
|
153
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
154
|
+
});
|
|
155
|
+
try {
|
|
156
|
+
logger.debug('Calling v3.template.get', {
|
|
157
|
+
templateId: args.templateId
|
|
158
|
+
});
|
|
159
|
+
const template = await context.hailer.request('v3.template.get', [args.templateId]);
|
|
160
|
+
logger.debug('Template retrieval successful');
|
|
161
|
+
let responseText = `๐ **Document Template Details**\n\n`;
|
|
162
|
+
responseText += `**Description:** ${template.description || 'Unnamed'}\n`;
|
|
163
|
+
responseText += `**ID:** \`${template._id}\`\n`;
|
|
164
|
+
responseText += `**Type:** ${template.fileType || 'Unknown'}\n`;
|
|
165
|
+
responseText += `**Global:** ${template.global ? 'Yes' : 'No'}\n`;
|
|
166
|
+
if (template.processId)
|
|
167
|
+
responseText += `**Workflow ID:** \`${template.processId}\`\n`;
|
|
168
|
+
if (template.cid)
|
|
169
|
+
responseText += `**Company ID:** \`${template.cid}\`\n`;
|
|
170
|
+
responseText += `\n`;
|
|
171
|
+
if (template.configuration) {
|
|
172
|
+
responseText += `**Configuration:**\n\`\`\`json\n${JSON.stringify(template.configuration, null, 2)}\n\`\`\`\n\n`;
|
|
173
|
+
}
|
|
174
|
+
if (template.content) {
|
|
175
|
+
responseText += `**Content Preview:**\n\`\`\`\n${template.content.substring(0, 500)}${template.content.length > 500 ? '...' : ''}\n\`\`\`\n\n`;
|
|
176
|
+
}
|
|
177
|
+
responseText += `๐ก **Next Steps:**\n`;
|
|
178
|
+
responseText += `- Use \`preview_template\` to test with activity data\n`;
|
|
179
|
+
responseText += `- Use \`update_template\` to modify this template\n`;
|
|
180
|
+
responseText += `- Use \`delete_template\` to remove this template`;
|
|
181
|
+
return {
|
|
182
|
+
content: [{
|
|
183
|
+
type: "text",
|
|
184
|
+
text: responseText,
|
|
185
|
+
}],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
logger.error("Error getting template", error);
|
|
190
|
+
let errorMessage = 'Unknown error occurred';
|
|
191
|
+
if (error instanceof Error) {
|
|
192
|
+
errorMessage = error.message;
|
|
193
|
+
}
|
|
194
|
+
else if (typeof error === 'object' && error !== null) {
|
|
195
|
+
try {
|
|
196
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
errorMessage = String(error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
errorMessage = String(error);
|
|
204
|
+
}
|
|
205
|
+
if (errorMessage.toLowerCase().includes('not found')) {
|
|
206
|
+
return {
|
|
207
|
+
content: [{
|
|
208
|
+
type: "text",
|
|
209
|
+
text: `โ **Template Not Found**\n\nThe specified template doesn't exist.\n\n**Template ID:** \`${args.templateId}\`\n\n๐ก Use \`list_templates\` to see available templates.`,
|
|
210
|
+
}],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
content: [{
|
|
215
|
+
type: "text",
|
|
216
|
+
text: `โ **Error getting template**\n\n**Error:** ${errorMessage}\n\n**Template ID:** \`${args.templateId}\``,
|
|
217
|
+
}],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
// ============================================================================
|
|
223
|
+
// CREATE TEMPLATE TOOL
|
|
224
|
+
// ============================================================================
|
|
225
|
+
const createTemplateDescription = `๐งช [PLAYGROUND] Create Template - Create new document template
|
|
226
|
+
|
|
227
|
+
**Purpose**: Create a new document generation template for a workflow.
|
|
228
|
+
|
|
229
|
+
**Example**:
|
|
230
|
+
\`\`\`javascript
|
|
231
|
+
create_template({
|
|
232
|
+
processId: "68446dc05b30685f67c6fcd4",
|
|
233
|
+
description: "Invoice Template",
|
|
234
|
+
fileType: "pdf",
|
|
235
|
+
content: "<template content here>",
|
|
236
|
+
global: false,
|
|
237
|
+
configuration: {
|
|
238
|
+
// Optional configuration
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
\`\`\`
|
|
242
|
+
|
|
243
|
+
**Parameters**:
|
|
244
|
+
- \`processId\` (required) - Workflow ID to attach template to
|
|
245
|
+
- \`description\` (optional) - Template description/name
|
|
246
|
+
- \`fileType\` (required) - File type (e.g., "pdf")
|
|
247
|
+
- \`content\` (required) - Template content/structure
|
|
248
|
+
- \`global\` (optional) - Whether template is globally accessible
|
|
249
|
+
- \`configuration\` (optional) - Additional configuration
|
|
250
|
+
- \`ownerCids\` (optional) - Owner company IDs
|
|
251
|
+
- \`cid\` (optional) - Company ID`;
|
|
252
|
+
exports.createTemplateTool = {
|
|
253
|
+
name: 'create_template',
|
|
254
|
+
group: tool_registry_1.ToolGroup.PLAYGROUND,
|
|
255
|
+
description: createTemplateDescription,
|
|
256
|
+
schema: zod_1.z.object({
|
|
257
|
+
processId: zod_1.z
|
|
258
|
+
.string()
|
|
259
|
+
.length(24)
|
|
260
|
+
.describe("Workflow/process ID to attach template to"),
|
|
261
|
+
description: zod_1.z
|
|
262
|
+
.string()
|
|
263
|
+
.optional()
|
|
264
|
+
.describe("Template description/name"),
|
|
265
|
+
fileType: zod_1.z
|
|
266
|
+
.string()
|
|
267
|
+
.describe("File type (e.g., 'pdf')"),
|
|
268
|
+
content: zod_1.z
|
|
269
|
+
.string()
|
|
270
|
+
.describe("Template content/structure"),
|
|
271
|
+
global: zod_1.z
|
|
272
|
+
.coerce.boolean()
|
|
273
|
+
.optional()
|
|
274
|
+
.describe("Whether template is globally accessible"),
|
|
275
|
+
configuration: zod_1.z.preprocess((val) => {
|
|
276
|
+
if (typeof val === 'string') {
|
|
277
|
+
try {
|
|
278
|
+
return JSON.parse(val);
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
return val;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return val;
|
|
285
|
+
}, zod_1.z.record(zod_1.z.any()).optional()).describe("Additional template configuration"),
|
|
286
|
+
ownerCids: zod_1.z.preprocess((val) => {
|
|
287
|
+
if (typeof val === 'string') {
|
|
288
|
+
try {
|
|
289
|
+
return JSON.parse(val);
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return val;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return val;
|
|
296
|
+
}, zod_1.z.array(zod_1.z.string()).optional()).describe("Owner company IDs"),
|
|
297
|
+
cid: zod_1.z
|
|
298
|
+
.string()
|
|
299
|
+
.length(24)
|
|
300
|
+
.optional()
|
|
301
|
+
.describe("Company ID"),
|
|
302
|
+
}),
|
|
303
|
+
async execute(args, context) {
|
|
304
|
+
logger.debug('Creating template', {
|
|
305
|
+
processId: args.processId,
|
|
306
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
307
|
+
});
|
|
308
|
+
try {
|
|
309
|
+
const templateData = {
|
|
310
|
+
processId: args.processId,
|
|
311
|
+
fileType: args.fileType,
|
|
312
|
+
content: args.content,
|
|
313
|
+
};
|
|
314
|
+
if (args.description)
|
|
315
|
+
templateData.description = args.description;
|
|
316
|
+
if (args.global !== undefined)
|
|
317
|
+
templateData.global = args.global;
|
|
318
|
+
if (args.configuration)
|
|
319
|
+
templateData.configuration = args.configuration;
|
|
320
|
+
if (args.ownerCids)
|
|
321
|
+
templateData.ownerCids = args.ownerCids;
|
|
322
|
+
if (args.cid)
|
|
323
|
+
templateData.cid = args.cid;
|
|
324
|
+
logger.debug('Calling v3.template.create', templateData);
|
|
325
|
+
const template = await context.hailer.request('v3.template.create', [templateData]);
|
|
326
|
+
logger.debug('Template creation successful', {
|
|
327
|
+
templateId: template._id
|
|
328
|
+
});
|
|
329
|
+
let responseText = `โ
**Template Created Successfully**\n\n`;
|
|
330
|
+
responseText += `**Template ID:** \`${template._id}\`\n`;
|
|
331
|
+
responseText += `**Description:** ${template.description || 'Unnamed'}\n`;
|
|
332
|
+
responseText += `**Type:** ${template.fileType}\n`;
|
|
333
|
+
responseText += `**Workflow ID:** \`${template.processId}\`\n\n`;
|
|
334
|
+
responseText += `๐ก **Next Steps:**\n`;
|
|
335
|
+
responseText += `- Use \`preview_template\` to test with activity data\n`;
|
|
336
|
+
responseText += `- Use \`get_template\` to view full details\n`;
|
|
337
|
+
responseText += `- Use \`update_template\` to modify if needed`;
|
|
338
|
+
return {
|
|
339
|
+
content: [{
|
|
340
|
+
type: "text",
|
|
341
|
+
text: responseText,
|
|
342
|
+
}],
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
logger.error("Error creating template", error);
|
|
347
|
+
let errorMessage = 'Unknown error occurred';
|
|
348
|
+
if (error instanceof Error) {
|
|
349
|
+
errorMessage = error.message;
|
|
350
|
+
}
|
|
351
|
+
else if (typeof error === 'object' && error !== null) {
|
|
352
|
+
try {
|
|
353
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
errorMessage = String(error);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
errorMessage = String(error);
|
|
361
|
+
}
|
|
362
|
+
if (errorMessage.toLowerCase().includes('permission')) {
|
|
363
|
+
return {
|
|
364
|
+
content: [{
|
|
365
|
+
type: "text",
|
|
366
|
+
text: `โ **Permission Denied**\n\nYou don't have permission to create templates in this workflow.\n\n**Error:** ${errorMessage}`,
|
|
367
|
+
}],
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
content: [{
|
|
372
|
+
type: "text",
|
|
373
|
+
text: `โ **Error creating template**\n\n**Error:** ${errorMessage}\n\n**Common Issues:**\n- Invalid workflow ID\n- Missing required fields\n- Permission denied`,
|
|
374
|
+
}],
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
// ============================================================================
|
|
380
|
+
// UPDATE TEMPLATE TOOL
|
|
381
|
+
// ============================================================================
|
|
382
|
+
const updateTemplateDescription = `๐งช [PLAYGROUND] Update Template - Modify document template
|
|
383
|
+
|
|
384
|
+
**Purpose**: Update an existing document template's properties.
|
|
385
|
+
|
|
386
|
+
**Example**:
|
|
387
|
+
\`\`\`javascript
|
|
388
|
+
update_template({
|
|
389
|
+
templateId: "68446dc05b30685f67c6fcd4",
|
|
390
|
+
description: "Updated Invoice Template",
|
|
391
|
+
content: "<updated template content>",
|
|
392
|
+
fileType: "pdf"
|
|
393
|
+
})
|
|
394
|
+
\`\`\`
|
|
395
|
+
|
|
396
|
+
**Updatable Properties**:
|
|
397
|
+
- \`description\` - Template description/name
|
|
398
|
+
- \`content\` - Template content/structure
|
|
399
|
+
- \`fileType\` - File type
|
|
400
|
+
- \`global\` - Global accessibility
|
|
401
|
+
- \`configuration\` - Configuration object
|
|
402
|
+
- \`ownerCids\` - Owner company IDs
|
|
403
|
+
- \`processId\` - Workflow ID
|
|
404
|
+
- \`cid\` - Company ID
|
|
405
|
+
|
|
406
|
+
**Note**: Only specified properties are updated.`;
|
|
407
|
+
exports.updateTemplateTool = {
|
|
408
|
+
name: 'update_template',
|
|
409
|
+
group: tool_registry_1.ToolGroup.PLAYGROUND,
|
|
410
|
+
description: updateTemplateDescription,
|
|
411
|
+
schema: zod_1.z.object({
|
|
412
|
+
templateId: zod_1.z
|
|
413
|
+
.string()
|
|
414
|
+
.length(24)
|
|
415
|
+
.describe("Template ID to update"),
|
|
416
|
+
description: zod_1.z
|
|
417
|
+
.string()
|
|
418
|
+
.optional()
|
|
419
|
+
.describe("New template description"),
|
|
420
|
+
fileType: zod_1.z
|
|
421
|
+
.string()
|
|
422
|
+
.optional()
|
|
423
|
+
.describe("New file type"),
|
|
424
|
+
content: zod_1.z
|
|
425
|
+
.string()
|
|
426
|
+
.optional()
|
|
427
|
+
.describe("New template content"),
|
|
428
|
+
global: zod_1.z
|
|
429
|
+
.boolean()
|
|
430
|
+
.optional()
|
|
431
|
+
.describe("New global accessibility setting"),
|
|
432
|
+
configuration: zod_1.z
|
|
433
|
+
.record(zod_1.z.any())
|
|
434
|
+
.optional()
|
|
435
|
+
.describe("New configuration"),
|
|
436
|
+
ownerCids: zod_1.z
|
|
437
|
+
.array(zod_1.z.string())
|
|
438
|
+
.optional()
|
|
439
|
+
.describe("New owner company IDs"),
|
|
440
|
+
processId: zod_1.z
|
|
441
|
+
.string()
|
|
442
|
+
.length(24)
|
|
443
|
+
.optional()
|
|
444
|
+
.describe("New workflow/process ID"),
|
|
445
|
+
cid: zod_1.z
|
|
446
|
+
.string()
|
|
447
|
+
.length(24)
|
|
448
|
+
.optional()
|
|
449
|
+
.describe("New company ID"),
|
|
450
|
+
}),
|
|
451
|
+
async execute(args, context) {
|
|
452
|
+
logger.debug('Updating template', {
|
|
453
|
+
templateId: args.templateId,
|
|
454
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
455
|
+
});
|
|
456
|
+
try {
|
|
457
|
+
const updateData = {
|
|
458
|
+
templateId: args.templateId,
|
|
459
|
+
};
|
|
460
|
+
if (args.description !== undefined)
|
|
461
|
+
updateData.description = args.description;
|
|
462
|
+
if (args.fileType !== undefined)
|
|
463
|
+
updateData.fileType = args.fileType;
|
|
464
|
+
if (args.content !== undefined)
|
|
465
|
+
updateData.content = args.content;
|
|
466
|
+
if (args.global !== undefined)
|
|
467
|
+
updateData.global = args.global;
|
|
468
|
+
if (args.configuration !== undefined)
|
|
469
|
+
updateData.configuration = args.configuration;
|
|
470
|
+
if (args.ownerCids !== undefined)
|
|
471
|
+
updateData.ownerCids = args.ownerCids;
|
|
472
|
+
if (args.processId !== undefined)
|
|
473
|
+
updateData.processId = args.processId;
|
|
474
|
+
if (args.cid !== undefined)
|
|
475
|
+
updateData.cid = args.cid;
|
|
476
|
+
logger.debug('Calling v3.template.update', updateData);
|
|
477
|
+
const template = await context.hailer.request('v3.template.update', [updateData]);
|
|
478
|
+
logger.debug('Template update successful');
|
|
479
|
+
let responseText = `โ
**Template Updated Successfully**\n\n`;
|
|
480
|
+
responseText += `**Template ID:** \`${template._id}\`\n`;
|
|
481
|
+
responseText += `**Description:** ${template.description || 'Unnamed'}\n`;
|
|
482
|
+
responseText += `**Type:** ${template.fileType}\n`;
|
|
483
|
+
if (template.processId)
|
|
484
|
+
responseText += `**Workflow ID:** \`${template.processId}\`\n`;
|
|
485
|
+
responseText += `\n๐ก Use \`get_template\` to view updated details or \`preview_template\` to test.`;
|
|
486
|
+
return {
|
|
487
|
+
content: [{
|
|
488
|
+
type: "text",
|
|
489
|
+
text: responseText,
|
|
490
|
+
}],
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
logger.error("Error updating template", error);
|
|
495
|
+
let errorMessage = 'Unknown error occurred';
|
|
496
|
+
if (error instanceof Error) {
|
|
497
|
+
errorMessage = error.message;
|
|
498
|
+
}
|
|
499
|
+
else if (typeof error === 'object' && error !== null) {
|
|
500
|
+
try {
|
|
501
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
errorMessage = String(error);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
errorMessage = String(error);
|
|
509
|
+
}
|
|
510
|
+
if (errorMessage.toLowerCase().includes('not found')) {
|
|
511
|
+
return {
|
|
512
|
+
content: [{
|
|
513
|
+
type: "text",
|
|
514
|
+
text: `โ **Template Not Found**\n\nThe specified template doesn't exist.\n\n**Template ID:** \`${args.templateId}\`\n\n๐ก Use \`list_templates\` to see available templates.`,
|
|
515
|
+
}],
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
if (errorMessage.toLowerCase().includes('permission')) {
|
|
519
|
+
return {
|
|
520
|
+
content: [{
|
|
521
|
+
type: "text",
|
|
522
|
+
text: `โ **Permission Denied**\n\nYou don't have permission to update this template.\n\n**Error:** ${errorMessage}`,
|
|
523
|
+
}],
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
content: [{
|
|
528
|
+
type: "text",
|
|
529
|
+
text: `โ **Error updating template**\n\n**Error:** ${errorMessage}`,
|
|
530
|
+
}],
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
// ============================================================================
|
|
536
|
+
// DELETE TEMPLATE TOOL
|
|
537
|
+
// ============================================================================
|
|
538
|
+
const deleteTemplateDescription = `๐งช [PLAYGROUND] Delete Template - Remove document template permanently
|
|
539
|
+
|
|
540
|
+
โ ๏ธ **MANDATORY: GATHER COMPLETE CONTEXT BEFORE CALLING THIS TOOL**
|
|
541
|
+
**BEFORE calling this tool, you are REQUIRED to:**
|
|
542
|
+
1. Fetch template details with \`get_template\` or \`list_templates\` to get:
|
|
543
|
+
- Template name/description and ID
|
|
544
|
+
- Workflow ID and name
|
|
545
|
+
- Template type (pdf, etc.)
|
|
546
|
+
- Whether template is global
|
|
547
|
+
2. Show comprehensive confirmation message including:
|
|
548
|
+
- Template ID and name/description
|
|
549
|
+
- Workflow ID and name
|
|
550
|
+
- What will be deleted (definition, content, configuration)
|
|
551
|
+
- Clear irreversibility warning
|
|
552
|
+
3. Wait for explicit user confirmation
|
|
553
|
+
**FAILURE TO GATHER AND SHOW THIS CONTEXT IS AN ERROR**
|
|
554
|
+
|
|
555
|
+
**Example**:
|
|
556
|
+
\`\`\`javascript
|
|
557
|
+
delete_template({
|
|
558
|
+
templateId: "68446dc05b30685f67c6fcd4"
|
|
559
|
+
})
|
|
560
|
+
\`\`\`
|
|
561
|
+
|
|
562
|
+
**What gets deleted**:
|
|
563
|
+
- Template definition
|
|
564
|
+
- Template content
|
|
565
|
+
- Template configuration
|
|
566
|
+
|
|
567
|
+
**Note**: This operation cannot be undone.`;
|
|
568
|
+
exports.deleteTemplateTool = {
|
|
569
|
+
name: 'delete_template',
|
|
570
|
+
group: tool_registry_1.ToolGroup.NUCLEAR,
|
|
571
|
+
description: deleteTemplateDescription,
|
|
572
|
+
schema: zod_1.z.object({
|
|
573
|
+
templateId: zod_1.z
|
|
574
|
+
.string()
|
|
575
|
+
.length(24)
|
|
576
|
+
.describe("Template ID to delete"),
|
|
577
|
+
}),
|
|
578
|
+
async execute(args, context) {
|
|
579
|
+
logger.debug('Deleting template', {
|
|
580
|
+
templateId: args.templateId,
|
|
581
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
582
|
+
});
|
|
583
|
+
try {
|
|
584
|
+
logger.debug('Calling v3.template.delete', {
|
|
585
|
+
templateId: args.templateId
|
|
586
|
+
});
|
|
587
|
+
await context.hailer.request('v3.template.delete', [args.templateId]);
|
|
588
|
+
logger.debug('Template deletion successful');
|
|
589
|
+
let responseText = `โ
**Template Deleted Successfully**\n\n`;
|
|
590
|
+
responseText += `**Template ID:** \`${args.templateId}\`\n\n`;
|
|
591
|
+
responseText += `โ ๏ธ **The template has been permanently deleted.**\n\n`;
|
|
592
|
+
responseText += `๐ก Use \`list_templates\` to see remaining templates.`;
|
|
593
|
+
return {
|
|
594
|
+
content: [{
|
|
595
|
+
type: "text",
|
|
596
|
+
text: responseText,
|
|
597
|
+
}],
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
logger.error("Error deleting template", error);
|
|
602
|
+
let errorMessage = 'Unknown error occurred';
|
|
603
|
+
if (error instanceof Error) {
|
|
604
|
+
errorMessage = error.message;
|
|
605
|
+
}
|
|
606
|
+
else if (typeof error === 'object' && error !== null) {
|
|
607
|
+
try {
|
|
608
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
609
|
+
}
|
|
610
|
+
catch {
|
|
611
|
+
errorMessage = String(error);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
errorMessage = String(error);
|
|
616
|
+
}
|
|
617
|
+
if (errorMessage.toLowerCase().includes('not found')) {
|
|
618
|
+
return {
|
|
619
|
+
content: [{
|
|
620
|
+
type: "text",
|
|
621
|
+
text: `โ **Template Not Found**\n\nThe specified template doesn't exist or has already been deleted.\n\n**Template ID:** \`${args.templateId}\``,
|
|
622
|
+
}],
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
if (errorMessage.toLowerCase().includes('permission')) {
|
|
626
|
+
return {
|
|
627
|
+
content: [{
|
|
628
|
+
type: "text",
|
|
629
|
+
text: `โ **Permission Denied**\n\nYou don't have permission to delete this template.\n\n**Error:** ${errorMessage}`,
|
|
630
|
+
}],
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
content: [{
|
|
635
|
+
type: "text",
|
|
636
|
+
text: `โ **Error deleting template**\n\n**Error:** ${errorMessage}`,
|
|
637
|
+
}],
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
// ============================================================================
|
|
643
|
+
// PREVIEW TEMPLATE TOOL
|
|
644
|
+
// ============================================================================
|
|
645
|
+
const previewTemplateDescription = `๐งช [PLAYGROUND] Preview Template - Test template with activity data
|
|
646
|
+
|
|
647
|
+
**Purpose**: Generate a preview of a template using actual activity data.
|
|
648
|
+
|
|
649
|
+
**Example**:
|
|
650
|
+
\`\`\`javascript
|
|
651
|
+
preview_template({
|
|
652
|
+
templateId: "68446dc05b30685f67c6fcd4",
|
|
653
|
+
activityId: "68446dc05b30685f67c6fce1"
|
|
654
|
+
})
|
|
655
|
+
\`\`\`
|
|
656
|
+
|
|
657
|
+
**Use Cases**:
|
|
658
|
+
- Test template before deploying
|
|
659
|
+
- Verify template logic with real data
|
|
660
|
+
- Debug template issues
|
|
661
|
+
- Preview document output
|
|
662
|
+
|
|
663
|
+
**Response**: Preview data showing how the template renders with the activity's data.`;
|
|
664
|
+
exports.previewTemplateTool = {
|
|
665
|
+
name: 'preview_template',
|
|
666
|
+
group: tool_registry_1.ToolGroup.PLAYGROUND,
|
|
667
|
+
description: previewTemplateDescription,
|
|
668
|
+
schema: zod_1.z.object({
|
|
669
|
+
templateId: zod_1.z
|
|
670
|
+
.string()
|
|
671
|
+
.length(24)
|
|
672
|
+
.describe("Template ID to preview"),
|
|
673
|
+
activityId: zod_1.z
|
|
674
|
+
.string()
|
|
675
|
+
.length(24)
|
|
676
|
+
.describe("Activity ID to use for preview data"),
|
|
677
|
+
}),
|
|
678
|
+
async execute(args, context) {
|
|
679
|
+
logger.debug('Previewing template', {
|
|
680
|
+
templateId: args.templateId,
|
|
681
|
+
activityId: args.activityId,
|
|
682
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
683
|
+
});
|
|
684
|
+
try {
|
|
685
|
+
logger.debug('Calling v3.template.preview', {
|
|
686
|
+
templateId: args.templateId,
|
|
687
|
+
activityId: args.activityId
|
|
688
|
+
});
|
|
689
|
+
const previewData = await context.hailer.request('v3.template.preview', [{
|
|
690
|
+
templateId: args.templateId,
|
|
691
|
+
activityId: args.activityId
|
|
692
|
+
}]);
|
|
693
|
+
logger.debug('Template preview successful');
|
|
694
|
+
let responseText = `๐ **Template Preview**\n\n`;
|
|
695
|
+
responseText += `**Template ID:** \`${args.templateId}\`\n`;
|
|
696
|
+
responseText += `**Activity ID:** \`${args.activityId}\`\n\n`;
|
|
697
|
+
responseText += `**Preview Data:**\n\`\`\`json\n${JSON.stringify(previewData, null, 2)}\n\`\`\`\n\n`;
|
|
698
|
+
responseText += `๐ก **Next Steps:**\n`;
|
|
699
|
+
responseText += `- Use \`update_template\` to modify template if needed\n`;
|
|
700
|
+
responseText += `- Test with different activities to verify template logic`;
|
|
701
|
+
return {
|
|
702
|
+
content: [{
|
|
703
|
+
type: "text",
|
|
704
|
+
text: responseText,
|
|
705
|
+
}],
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
catch (error) {
|
|
709
|
+
logger.error("Error previewing template", error);
|
|
710
|
+
let errorMessage = 'Unknown error occurred';
|
|
711
|
+
if (error instanceof Error) {
|
|
712
|
+
errorMessage = error.message;
|
|
713
|
+
}
|
|
714
|
+
else if (typeof error === 'object' && error !== null) {
|
|
715
|
+
try {
|
|
716
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
717
|
+
}
|
|
718
|
+
catch {
|
|
719
|
+
errorMessage = String(error);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
errorMessage = String(error);
|
|
724
|
+
}
|
|
725
|
+
if (errorMessage.toLowerCase().includes('not found')) {
|
|
726
|
+
return {
|
|
727
|
+
content: [{
|
|
728
|
+
type: "text",
|
|
729
|
+
text: `โ **Template or Activity Not Found**\n\nThe specified template or activity doesn't exist.\n\n**Template ID:** \`${args.templateId}\`\n**Activity ID:** \`${args.activityId}\`\n\n๐ก Verify both IDs are correct.`,
|
|
730
|
+
}],
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
return {
|
|
734
|
+
content: [{
|
|
735
|
+
type: "text",
|
|
736
|
+
text: `โ **Error previewing template**\n\n**Error:** ${errorMessage}\n\n**Template ID:** \`${args.templateId}\`\n**Activity ID:** \`${args.activityId}\``,
|
|
737
|
+
}],
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
// ============================================================================
|
|
743
|
+
// INSTALL TEMPLATE TOOL
|
|
744
|
+
// ============================================================================
|
|
745
|
+
const installTemplateDescription = `๐งช [PLAYGROUND] Install Template - Register template in workflow
|
|
746
|
+
|
|
747
|
+
**Purpose**: Install/register a template to make it available in the workflow UI.
|
|
748
|
+
|
|
749
|
+
**Example**:
|
|
750
|
+
\`\`\`javascript
|
|
751
|
+
install_template({
|
|
752
|
+
templateId: "6915a49e43a99588c70b38f0"
|
|
753
|
+
})
|
|
754
|
+
\`\`\`
|
|
755
|
+
|
|
756
|
+
**When to use:**
|
|
757
|
+
- After creating a template with \`create_template\`
|
|
758
|
+
- To make a template appear in the workflow settings UI
|
|
759
|
+
- To activate a template for use in the workflow
|
|
760
|
+
|
|
761
|
+
**โ ๏ธ IMPORTANT**: Templates must be installed to appear in the workflow UI dropdown.`;
|
|
762
|
+
exports.installTemplateTool = {
|
|
763
|
+
name: 'install_template',
|
|
764
|
+
group: tool_registry_1.ToolGroup.PLAYGROUND,
|
|
765
|
+
description: installTemplateDescription,
|
|
766
|
+
schema: zod_1.z.object({
|
|
767
|
+
templateId: zod_1.z
|
|
768
|
+
.string()
|
|
769
|
+
.length(24)
|
|
770
|
+
.describe("Template ID to install"),
|
|
771
|
+
}),
|
|
772
|
+
async execute(args, context) {
|
|
773
|
+
logger.debug('Installing template', {
|
|
774
|
+
templateId: args.templateId,
|
|
775
|
+
apiKey: context.apiKey.substring(0, 8) + '...'
|
|
776
|
+
});
|
|
777
|
+
try {
|
|
778
|
+
logger.debug('Calling process.install_template', {
|
|
779
|
+
templateId: args.templateId
|
|
780
|
+
});
|
|
781
|
+
await context.hailer.request('process.install_template', [args.templateId]);
|
|
782
|
+
logger.debug('Template installation successful');
|
|
783
|
+
let responseText = `โ
**Template Installed Successfully**\n\n`;
|
|
784
|
+
responseText += `**Template ID:** \`${args.templateId}\`\n\n`;
|
|
785
|
+
responseText += `๐ก **Next Steps:**\n`;
|
|
786
|
+
responseText += `- Refresh your browser to see the template in the workflow UI\n`;
|
|
787
|
+
responseText += `- Use the template dropdown in workflow settings to configure it\n`;
|
|
788
|
+
responseText += `- Generate PDFs from activities using this template`;
|
|
789
|
+
return {
|
|
790
|
+
content: [{
|
|
791
|
+
type: "text",
|
|
792
|
+
text: responseText,
|
|
793
|
+
}],
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
logger.error("Error installing template", error);
|
|
798
|
+
let errorMessage = 'Unknown error occurred';
|
|
799
|
+
if (error instanceof Error) {
|
|
800
|
+
errorMessage = error.message;
|
|
801
|
+
}
|
|
802
|
+
else if (typeof error === 'object' && error !== null) {
|
|
803
|
+
try {
|
|
804
|
+
errorMessage = JSON.stringify(error, null, 2);
|
|
805
|
+
}
|
|
806
|
+
catch {
|
|
807
|
+
errorMessage = String(error);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
errorMessage = String(error);
|
|
812
|
+
}
|
|
813
|
+
return {
|
|
814
|
+
content: [{
|
|
815
|
+
type: "text",
|
|
816
|
+
text: `โ **Error installing template**\n\n**Error:** ${errorMessage}\n\n**Template ID:** \`${args.templateId}\`\n\n**Debug:** Check if the template exists and is accessible in the current workspace.`,
|
|
817
|
+
}],
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
//# sourceMappingURL=workflow-template.js.map
|