@defai.digital/mcp-server 13.0.3
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/LICENSE +214 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/bootstrap.d.ts +89 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +161 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/rate-limiter.d.ts +136 -0
- package/dist/middleware/rate-limiter.d.ts.map +1 -0
- package/dist/middleware/rate-limiter.js +262 -0
- package/dist/middleware/rate-limiter.js.map +1 -0
- package/dist/prompts/agent-guide.d.ts +16 -0
- package/dist/prompts/agent-guide.d.ts.map +1 -0
- package/dist/prompts/agent-guide.js +391 -0
- package/dist/prompts/agent-guide.js.map +1 -0
- package/dist/prompts/explain-workflow.d.ts +15 -0
- package/dist/prompts/explain-workflow.d.ts.map +1 -0
- package/dist/prompts/explain-workflow.js +157 -0
- package/dist/prompts/explain-workflow.js.map +1 -0
- package/dist/prompts/index.d.ts +39 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +83 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/review-changes.d.ts +15 -0
- package/dist/prompts/review-changes.d.ts.map +1 -0
- package/dist/prompts/review-changes.js +102 -0
- package/dist/prompts/review-changes.js.map +1 -0
- package/dist/prompts/troubleshoot-session.d.ts +15 -0
- package/dist/prompts/troubleshoot-session.d.ts.map +1 -0
- package/dist/prompts/troubleshoot-session.js +156 -0
- package/dist/prompts/troubleshoot-session.js.map +1 -0
- package/dist/registry-accessor.d.ts +83 -0
- package/dist/registry-accessor.d.ts.map +1 -0
- package/dist/registry-accessor.js +153 -0
- package/dist/registry-accessor.js.map +1 -0
- package/dist/resources/agents.d.ts +40 -0
- package/dist/resources/agents.d.ts.map +1 -0
- package/dist/resources/agents.js +123 -0
- package/dist/resources/agents.js.map +1 -0
- package/dist/resources/config.d.ts +57 -0
- package/dist/resources/config.d.ts.map +1 -0
- package/dist/resources/config.js +222 -0
- package/dist/resources/config.js.map +1 -0
- package/dist/resources/index.d.ts +38 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +132 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/policies.d.ts +40 -0
- package/dist/resources/policies.d.ts.map +1 -0
- package/dist/resources/policies.js +122 -0
- package/dist/resources/policies.js.map +1 -0
- package/dist/resources/sessions.d.ts +30 -0
- package/dist/resources/sessions.d.ts.map +1 -0
- package/dist/resources/sessions.js +64 -0
- package/dist/resources/sessions.js.map +1 -0
- package/dist/resources/workflows.d.ts +40 -0
- package/dist/resources/workflows.d.ts.map +1 -0
- package/dist/resources/workflows.js +143 -0
- package/dist/resources/workflows.js.map +1 -0
- package/dist/schema-registry.d.ts +23 -0
- package/dist/schema-registry.d.ts.map +1 -0
- package/dist/schema-registry.js +225 -0
- package/dist/schema-registry.js.map +1 -0
- package/dist/server.d.ts +63 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +393 -0
- package/dist/server.js.map +1 -0
- package/dist/session-accessor.d.ts +23 -0
- package/dist/session-accessor.d.ts.map +1 -0
- package/dist/session-accessor.js +39 -0
- package/dist/session-accessor.js.map +1 -0
- package/dist/shared-registry.d.ts +23 -0
- package/dist/shared-registry.d.ts.map +1 -0
- package/dist/shared-registry.js +235 -0
- package/dist/shared-registry.js.map +1 -0
- package/dist/stdio.d.ts +6 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +152 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tool-namespacing.d.ts +28 -0
- package/dist/tool-namespacing.d.ts.map +1 -0
- package/dist/tool-namespacing.js +80 -0
- package/dist/tool-namespacing.js.map +1 -0
- package/dist/tools/ability.d.ts +55 -0
- package/dist/tools/ability.d.ts.map +1 -0
- package/dist/tools/ability.js +560 -0
- package/dist/tools/ability.js.map +1 -0
- package/dist/tools/agent.d.ts +73 -0
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +895 -0
- package/dist/tools/agent.js.map +1 -0
- package/dist/tools/config.d.ts +36 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +265 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/design.d.ts +42 -0
- package/dist/tools/design.d.ts.map +1 -0
- package/dist/tools/design.js +736 -0
- package/dist/tools/design.js.map +1 -0
- package/dist/tools/discuss.d.ts +40 -0
- package/dist/tools/discuss.d.ts.map +1 -0
- package/dist/tools/discuss.js +331 -0
- package/dist/tools/discuss.js.map +1 -0
- package/dist/tools/file-system.d.ts +63 -0
- package/dist/tools/file-system.d.ts.map +1 -0
- package/dist/tools/file-system.js +513 -0
- package/dist/tools/file-system.js.map +1 -0
- package/dist/tools/guard.d.ts +29 -0
- package/dist/tools/guard.d.ts.map +1 -0
- package/dist/tools/guard.js +311 -0
- package/dist/tools/guard.js.map +1 -0
- package/dist/tools/index.d.ts +35 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +178 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory.d.ts +101 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +704 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/tools/orchestration.d.ts +58 -0
- package/dist/tools/orchestration.d.ts.map +1 -0
- package/dist/tools/orchestration.js +714 -0
- package/dist/tools/orchestration.js.map +1 -0
- package/dist/tools/review.d.ts +40 -0
- package/dist/tools/review.d.ts.map +1 -0
- package/dist/tools/review.js +319 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/scaffold.d.ts +27 -0
- package/dist/tools/scaffold.d.ts.map +1 -0
- package/dist/tools/scaffold.js +495 -0
- package/dist/tools/scaffold.js.map +1 -0
- package/dist/tools/session.d.ts +75 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/dist/tools/session.js +749 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/telemetry.d.ts +58 -0
- package/dist/tools/telemetry.d.ts.map +1 -0
- package/dist/tools/telemetry.js +638 -0
- package/dist/tools/telemetry.js.map +1 -0
- package/dist/tools/trace.d.ts +29 -0
- package/dist/tools/trace.d.ts.map +1 -0
- package/dist/tools/trace.js +191 -0
- package/dist/tools/trace.js.map +1 -0
- package/dist/tools/workflow.d.ts +26 -0
- package/dist/tools/workflow.d.ts.map +1 -0
- package/dist/tools/workflow.js +269 -0
- package/dist/tools/workflow.js.map +1 -0
- package/dist/trace-wrapper.d.ts +79 -0
- package/dist/trace-wrapper.d.ts.map +1 -0
- package/dist/trace-wrapper.js +151 -0
- package/dist/trace-wrapper.js.map +1 -0
- package/dist/types.d.ts +185 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/artifact-store.d.ts +49 -0
- package/dist/utils/artifact-store.d.ts.map +1 -0
- package/dist/utils/artifact-store.js +102 -0
- package/dist/utils/artifact-store.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/response.d.ts +139 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +293 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/validation.d.ts +223 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +372 -0
- package/dist/validation.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Task submit tool definition
|
|
4
|
+
*/
|
|
5
|
+
export const taskSubmitTool = {
|
|
6
|
+
name: 'task_submit',
|
|
7
|
+
description: 'Submit a new task to the orchestration queue',
|
|
8
|
+
idempotent: false,
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
queueId: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: 'Queue ID to submit to (uses default if not specified)',
|
|
15
|
+
},
|
|
16
|
+
name: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'Task name',
|
|
19
|
+
},
|
|
20
|
+
description: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Task description',
|
|
23
|
+
},
|
|
24
|
+
type: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: 'Task type',
|
|
27
|
+
enum: ['sequential', 'parallel', 'conditional', 'loop', 'retry', 'timeout', 'wait', 'callback', 'other'],
|
|
28
|
+
default: 'sequential',
|
|
29
|
+
},
|
|
30
|
+
priority: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Task priority',
|
|
33
|
+
enum: ['critical', 'high', 'medium', 'low', 'background'],
|
|
34
|
+
default: 'medium',
|
|
35
|
+
},
|
|
36
|
+
agentId: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'Agent ID to assign the task to',
|
|
39
|
+
},
|
|
40
|
+
input: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
description: 'Input data for the task',
|
|
43
|
+
},
|
|
44
|
+
dependencies: {
|
|
45
|
+
type: 'array',
|
|
46
|
+
description: 'List of task IDs that must complete first',
|
|
47
|
+
items: { type: 'string' },
|
|
48
|
+
},
|
|
49
|
+
scheduledAt: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'ISO datetime for scheduled execution',
|
|
52
|
+
},
|
|
53
|
+
tags: {
|
|
54
|
+
type: 'array',
|
|
55
|
+
description: 'Task tags for filtering',
|
|
56
|
+
items: { type: 'string' },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
required: ['name'],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Task status tool definition
|
|
64
|
+
*/
|
|
65
|
+
export const taskStatusTool = {
|
|
66
|
+
name: 'task_status',
|
|
67
|
+
description: 'Get the status of a task',
|
|
68
|
+
idempotent: true,
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
taskId: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
description: 'Task ID to check',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
required: ['taskId'],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Task list tool definition
|
|
82
|
+
*/
|
|
83
|
+
export const taskListTool = {
|
|
84
|
+
name: 'task_list',
|
|
85
|
+
description: 'List tasks with optional filters',
|
|
86
|
+
idempotent: true,
|
|
87
|
+
inputSchema: {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
queueId: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
description: 'Filter by queue ID',
|
|
93
|
+
},
|
|
94
|
+
status: {
|
|
95
|
+
type: 'array',
|
|
96
|
+
description: 'Filter by status',
|
|
97
|
+
items: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
enum: ['pending', 'queued', 'running', 'paused', 'completed', 'failed', 'cancelled', 'timeout'],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
priority: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
description: 'Filter by priority',
|
|
105
|
+
items: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
enum: ['critical', 'high', 'medium', 'low', 'background'],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
agentId: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
description: 'Filter by agent ID',
|
|
113
|
+
},
|
|
114
|
+
tags: {
|
|
115
|
+
type: 'array',
|
|
116
|
+
description: 'Filter by tags',
|
|
117
|
+
items: { type: 'string' },
|
|
118
|
+
},
|
|
119
|
+
limit: {
|
|
120
|
+
type: 'number',
|
|
121
|
+
description: 'Maximum results to return',
|
|
122
|
+
default: 50,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Task cancel tool definition
|
|
129
|
+
*/
|
|
130
|
+
export const taskCancelTool = {
|
|
131
|
+
name: 'task_cancel',
|
|
132
|
+
description: 'Cancel a running or pending task',
|
|
133
|
+
idempotent: false,
|
|
134
|
+
inputSchema: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
taskId: {
|
|
138
|
+
type: 'string',
|
|
139
|
+
description: 'Task ID to cancel',
|
|
140
|
+
},
|
|
141
|
+
reason: {
|
|
142
|
+
type: 'string',
|
|
143
|
+
description: 'Cancellation reason',
|
|
144
|
+
},
|
|
145
|
+
force: {
|
|
146
|
+
type: 'boolean',
|
|
147
|
+
description: 'Force cancel even if running',
|
|
148
|
+
default: false,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
required: ['taskId'],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Task retry tool definition
|
|
156
|
+
*/
|
|
157
|
+
export const taskRetryTool = {
|
|
158
|
+
name: 'task_retry',
|
|
159
|
+
description: 'Retry a failed task',
|
|
160
|
+
idempotent: false,
|
|
161
|
+
inputSchema: {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
taskId: {
|
|
165
|
+
type: 'string',
|
|
166
|
+
description: 'Task ID to retry',
|
|
167
|
+
},
|
|
168
|
+
resetAttempts: {
|
|
169
|
+
type: 'boolean',
|
|
170
|
+
description: 'Reset attempt counter',
|
|
171
|
+
default: false,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
required: ['taskId'],
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Queue create tool definition
|
|
179
|
+
*/
|
|
180
|
+
export const queueCreateTool = {
|
|
181
|
+
name: 'queue_create',
|
|
182
|
+
description: 'Create a new task queue',
|
|
183
|
+
idempotent: false,
|
|
184
|
+
inputSchema: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
name: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
description: 'Queue name',
|
|
190
|
+
},
|
|
191
|
+
description: {
|
|
192
|
+
type: 'string',
|
|
193
|
+
description: 'Queue description',
|
|
194
|
+
},
|
|
195
|
+
maxConcurrency: {
|
|
196
|
+
type: 'number',
|
|
197
|
+
description: 'Maximum concurrent tasks',
|
|
198
|
+
default: 5,
|
|
199
|
+
},
|
|
200
|
+
defaultPriority: {
|
|
201
|
+
type: 'string',
|
|
202
|
+
description: 'Default priority for tasks',
|
|
203
|
+
enum: ['critical', 'high', 'medium', 'low', 'background'],
|
|
204
|
+
default: 'medium',
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
required: ['name'],
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Queue list tool definition
|
|
212
|
+
*/
|
|
213
|
+
export const queueListTool = {
|
|
214
|
+
name: 'queue_list',
|
|
215
|
+
description: 'List all task queues',
|
|
216
|
+
idempotent: true,
|
|
217
|
+
inputSchema: {
|
|
218
|
+
type: 'object',
|
|
219
|
+
properties: {
|
|
220
|
+
limit: {
|
|
221
|
+
type: 'number',
|
|
222
|
+
description: 'Maximum results',
|
|
223
|
+
default: 20,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
// In-memory storage
|
|
229
|
+
const taskStore = new Map();
|
|
230
|
+
const queueStore = new Map();
|
|
231
|
+
// Create default queue
|
|
232
|
+
const defaultQueueId = randomUUID();
|
|
233
|
+
queueStore.set(defaultQueueId, {
|
|
234
|
+
queueId: defaultQueueId,
|
|
235
|
+
name: 'default',
|
|
236
|
+
description: 'Default task queue',
|
|
237
|
+
maxConcurrency: 5,
|
|
238
|
+
defaultPriority: 'medium',
|
|
239
|
+
isPaused: false,
|
|
240
|
+
createdAt: new Date().toISOString(),
|
|
241
|
+
});
|
|
242
|
+
/**
|
|
243
|
+
* Handler for task_submit tool
|
|
244
|
+
*/
|
|
245
|
+
export const handleTaskSubmit = async (args) => {
|
|
246
|
+
const queueId = args.queueId ?? defaultQueueId;
|
|
247
|
+
const name = args.name;
|
|
248
|
+
const description = args.description;
|
|
249
|
+
const type = args.type ?? 'sequential';
|
|
250
|
+
const priority = args.priority ?? 'medium';
|
|
251
|
+
const agentId = args.agentId;
|
|
252
|
+
const input = args.input;
|
|
253
|
+
const dependencies = args.dependencies ?? [];
|
|
254
|
+
const scheduledAt = args.scheduledAt;
|
|
255
|
+
const tags = args.tags ?? [];
|
|
256
|
+
try {
|
|
257
|
+
// Validate queue exists
|
|
258
|
+
const queue = queueStore.get(queueId);
|
|
259
|
+
if (queue === undefined) {
|
|
260
|
+
return {
|
|
261
|
+
content: [
|
|
262
|
+
{
|
|
263
|
+
type: 'text',
|
|
264
|
+
text: JSON.stringify({
|
|
265
|
+
error: 'QUEUE_NOT_FOUND',
|
|
266
|
+
message: `Queue with ID "${queueId}" not found`,
|
|
267
|
+
queueId,
|
|
268
|
+
}),
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
isError: true,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const taskId = randomUUID();
|
|
275
|
+
const task = {
|
|
276
|
+
taskId,
|
|
277
|
+
queueId,
|
|
278
|
+
name,
|
|
279
|
+
description,
|
|
280
|
+
type,
|
|
281
|
+
priority,
|
|
282
|
+
status: scheduledAt !== undefined ? 'pending' : 'queued',
|
|
283
|
+
agentId,
|
|
284
|
+
input,
|
|
285
|
+
output: undefined,
|
|
286
|
+
dependencies,
|
|
287
|
+
tags,
|
|
288
|
+
attempt: 1,
|
|
289
|
+
error: undefined,
|
|
290
|
+
scheduledAt,
|
|
291
|
+
startedAt: undefined,
|
|
292
|
+
completedAt: undefined,
|
|
293
|
+
createdAt: new Date().toISOString(),
|
|
294
|
+
};
|
|
295
|
+
taskStore.set(taskId, task);
|
|
296
|
+
// Calculate queue position
|
|
297
|
+
const queuedTasks = Array.from(taskStore.values()).filter((t) => t.queueId === queueId && t.status === 'queued');
|
|
298
|
+
return {
|
|
299
|
+
content: [
|
|
300
|
+
{
|
|
301
|
+
type: 'text',
|
|
302
|
+
text: JSON.stringify({
|
|
303
|
+
taskId,
|
|
304
|
+
queueId,
|
|
305
|
+
status: task.status,
|
|
306
|
+
position: queuedTasks.length,
|
|
307
|
+
submittedAt: task.createdAt,
|
|
308
|
+
}, null, 2),
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
315
|
+
return {
|
|
316
|
+
content: [
|
|
317
|
+
{
|
|
318
|
+
type: 'text',
|
|
319
|
+
text: JSON.stringify({
|
|
320
|
+
error: 'SUBMIT_FAILED',
|
|
321
|
+
message,
|
|
322
|
+
name,
|
|
323
|
+
}),
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
isError: true,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Handler for task_status tool
|
|
332
|
+
*/
|
|
333
|
+
export const handleTaskStatus = async (args) => {
|
|
334
|
+
const taskId = args.taskId;
|
|
335
|
+
try {
|
|
336
|
+
const task = taskStore.get(taskId);
|
|
337
|
+
if (task === undefined) {
|
|
338
|
+
return {
|
|
339
|
+
content: [
|
|
340
|
+
{
|
|
341
|
+
type: 'text',
|
|
342
|
+
text: JSON.stringify({
|
|
343
|
+
error: 'TASK_NOT_FOUND',
|
|
344
|
+
message: `Task with ID "${taskId}" not found`,
|
|
345
|
+
taskId,
|
|
346
|
+
}),
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
isError: true,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
content: [
|
|
354
|
+
{
|
|
355
|
+
type: 'text',
|
|
356
|
+
text: JSON.stringify(task, null, 2),
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
363
|
+
return {
|
|
364
|
+
content: [
|
|
365
|
+
{
|
|
366
|
+
type: 'text',
|
|
367
|
+
text: JSON.stringify({
|
|
368
|
+
error: 'STATUS_FAILED',
|
|
369
|
+
message,
|
|
370
|
+
taskId,
|
|
371
|
+
}),
|
|
372
|
+
},
|
|
373
|
+
],
|
|
374
|
+
isError: true,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Handler for task_list tool
|
|
380
|
+
*/
|
|
381
|
+
export const handleTaskList = async (args) => {
|
|
382
|
+
const queueId = args.queueId;
|
|
383
|
+
const statusFilter = args.status;
|
|
384
|
+
const priorityFilter = args.priority;
|
|
385
|
+
const agentId = args.agentId;
|
|
386
|
+
const tagsFilter = args.tags;
|
|
387
|
+
const limit = args.limit ?? 50;
|
|
388
|
+
try {
|
|
389
|
+
let tasks = Array.from(taskStore.values());
|
|
390
|
+
if (queueId !== undefined) {
|
|
391
|
+
tasks = tasks.filter((t) => t.queueId === queueId);
|
|
392
|
+
}
|
|
393
|
+
if (statusFilter !== undefined && statusFilter.length > 0) {
|
|
394
|
+
tasks = tasks.filter((t) => statusFilter.includes(t.status));
|
|
395
|
+
}
|
|
396
|
+
if (priorityFilter !== undefined && priorityFilter.length > 0) {
|
|
397
|
+
tasks = tasks.filter((t) => priorityFilter.includes(t.priority));
|
|
398
|
+
}
|
|
399
|
+
if (agentId !== undefined) {
|
|
400
|
+
tasks = tasks.filter((t) => t.agentId === agentId);
|
|
401
|
+
}
|
|
402
|
+
if (tagsFilter !== undefined && tagsFilter.length > 0) {
|
|
403
|
+
tasks = tasks.filter((t) => tagsFilter.some((tag) => t.tags.includes(tag)));
|
|
404
|
+
}
|
|
405
|
+
// Sort by createdAt desc
|
|
406
|
+
tasks.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
407
|
+
tasks = tasks.slice(0, limit);
|
|
408
|
+
return {
|
|
409
|
+
content: [
|
|
410
|
+
{
|
|
411
|
+
type: 'text',
|
|
412
|
+
text: JSON.stringify({
|
|
413
|
+
tasks,
|
|
414
|
+
total: tasks.length,
|
|
415
|
+
hasMore: tasks.length === limit,
|
|
416
|
+
}, null, 2),
|
|
417
|
+
},
|
|
418
|
+
],
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
423
|
+
return {
|
|
424
|
+
content: [
|
|
425
|
+
{
|
|
426
|
+
type: 'text',
|
|
427
|
+
text: JSON.stringify({
|
|
428
|
+
error: 'LIST_FAILED',
|
|
429
|
+
message,
|
|
430
|
+
}),
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
isError: true,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* Handler for task_cancel tool
|
|
439
|
+
*/
|
|
440
|
+
export const handleTaskCancel = async (args) => {
|
|
441
|
+
const taskId = args.taskId;
|
|
442
|
+
const reason = args.reason;
|
|
443
|
+
const force = args.force ?? false;
|
|
444
|
+
try {
|
|
445
|
+
const task = taskStore.get(taskId);
|
|
446
|
+
if (task === undefined) {
|
|
447
|
+
return {
|
|
448
|
+
content: [
|
|
449
|
+
{
|
|
450
|
+
type: 'text',
|
|
451
|
+
text: JSON.stringify({
|
|
452
|
+
error: 'TASK_NOT_FOUND',
|
|
453
|
+
message: `Task with ID "${taskId}" not found`,
|
|
454
|
+
taskId,
|
|
455
|
+
}),
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
isError: true,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
// Check if task can be cancelled
|
|
462
|
+
if (['completed', 'failed', 'cancelled'].includes(task.status)) {
|
|
463
|
+
return {
|
|
464
|
+
content: [
|
|
465
|
+
{
|
|
466
|
+
type: 'text',
|
|
467
|
+
text: JSON.stringify({
|
|
468
|
+
error: 'INVALID_STATE',
|
|
469
|
+
message: `Task is already ${task.status}`,
|
|
470
|
+
taskId,
|
|
471
|
+
currentStatus: task.status,
|
|
472
|
+
}),
|
|
473
|
+
},
|
|
474
|
+
],
|
|
475
|
+
isError: true,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
if (task.status === 'running' && !force) {
|
|
479
|
+
return {
|
|
480
|
+
content: [
|
|
481
|
+
{
|
|
482
|
+
type: 'text',
|
|
483
|
+
text: JSON.stringify({
|
|
484
|
+
error: 'INVALID_STATE',
|
|
485
|
+
message: 'Task is running. Set force=true to cancel.',
|
|
486
|
+
taskId,
|
|
487
|
+
currentStatus: task.status,
|
|
488
|
+
}),
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
isError: true,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
task.status = 'cancelled';
|
|
495
|
+
task.error = reason ?? 'Cancelled by user';
|
|
496
|
+
task.completedAt = new Date().toISOString();
|
|
497
|
+
return {
|
|
498
|
+
content: [
|
|
499
|
+
{
|
|
500
|
+
type: 'text',
|
|
501
|
+
text: JSON.stringify({
|
|
502
|
+
taskId,
|
|
503
|
+
status: 'cancelled',
|
|
504
|
+
reason: task.error,
|
|
505
|
+
cancelledAt: task.completedAt,
|
|
506
|
+
}, null, 2),
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
513
|
+
return {
|
|
514
|
+
content: [
|
|
515
|
+
{
|
|
516
|
+
type: 'text',
|
|
517
|
+
text: JSON.stringify({
|
|
518
|
+
error: 'CANCEL_FAILED',
|
|
519
|
+
message,
|
|
520
|
+
taskId,
|
|
521
|
+
}),
|
|
522
|
+
},
|
|
523
|
+
],
|
|
524
|
+
isError: true,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Handler for task_retry tool
|
|
530
|
+
*/
|
|
531
|
+
export const handleTaskRetry = async (args) => {
|
|
532
|
+
const taskId = args.taskId;
|
|
533
|
+
const resetAttempts = args.resetAttempts ?? false;
|
|
534
|
+
try {
|
|
535
|
+
const task = taskStore.get(taskId);
|
|
536
|
+
if (task === undefined) {
|
|
537
|
+
return {
|
|
538
|
+
content: [
|
|
539
|
+
{
|
|
540
|
+
type: 'text',
|
|
541
|
+
text: JSON.stringify({
|
|
542
|
+
error: 'TASK_NOT_FOUND',
|
|
543
|
+
message: `Task with ID "${taskId}" not found`,
|
|
544
|
+
taskId,
|
|
545
|
+
}),
|
|
546
|
+
},
|
|
547
|
+
],
|
|
548
|
+
isError: true,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
if (!['failed', 'cancelled', 'timeout'].includes(task.status)) {
|
|
552
|
+
return {
|
|
553
|
+
content: [
|
|
554
|
+
{
|
|
555
|
+
type: 'text',
|
|
556
|
+
text: JSON.stringify({
|
|
557
|
+
error: 'INVALID_STATE',
|
|
558
|
+
message: `Can only retry failed, cancelled, or timed out tasks. Current status: ${task.status}`,
|
|
559
|
+
taskId,
|
|
560
|
+
currentStatus: task.status,
|
|
561
|
+
}),
|
|
562
|
+
},
|
|
563
|
+
],
|
|
564
|
+
isError: true,
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
task.status = 'queued';
|
|
568
|
+
task.attempt = resetAttempts ? 1 : task.attempt + 1;
|
|
569
|
+
task.error = undefined;
|
|
570
|
+
task.completedAt = undefined;
|
|
571
|
+
return {
|
|
572
|
+
content: [
|
|
573
|
+
{
|
|
574
|
+
type: 'text',
|
|
575
|
+
text: JSON.stringify({
|
|
576
|
+
taskId,
|
|
577
|
+
status: 'queued',
|
|
578
|
+
attempt: task.attempt,
|
|
579
|
+
retriedAt: new Date().toISOString(),
|
|
580
|
+
}, null, 2),
|
|
581
|
+
},
|
|
582
|
+
],
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
587
|
+
return {
|
|
588
|
+
content: [
|
|
589
|
+
{
|
|
590
|
+
type: 'text',
|
|
591
|
+
text: JSON.stringify({
|
|
592
|
+
error: 'RETRY_FAILED',
|
|
593
|
+
message,
|
|
594
|
+
taskId,
|
|
595
|
+
}),
|
|
596
|
+
},
|
|
597
|
+
],
|
|
598
|
+
isError: true,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
603
|
+
* Handler for queue_create tool
|
|
604
|
+
*/
|
|
605
|
+
export const handleQueueCreate = async (args) => {
|
|
606
|
+
const name = args.name;
|
|
607
|
+
const description = args.description;
|
|
608
|
+
const maxConcurrency = args.maxConcurrency ?? 5;
|
|
609
|
+
const defaultPriority = args.defaultPriority ?? 'medium';
|
|
610
|
+
try {
|
|
611
|
+
// Check for duplicate name
|
|
612
|
+
const existing = Array.from(queueStore.values()).find((q) => q.name === name);
|
|
613
|
+
if (existing !== undefined) {
|
|
614
|
+
return {
|
|
615
|
+
content: [
|
|
616
|
+
{
|
|
617
|
+
type: 'text',
|
|
618
|
+
text: JSON.stringify({
|
|
619
|
+
error: 'QUEUE_EXISTS',
|
|
620
|
+
message: `Queue with name "${name}" already exists`,
|
|
621
|
+
existingQueueId: existing.queueId,
|
|
622
|
+
}),
|
|
623
|
+
},
|
|
624
|
+
],
|
|
625
|
+
isError: true,
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
const queueId = randomUUID();
|
|
629
|
+
const queue = {
|
|
630
|
+
queueId,
|
|
631
|
+
name,
|
|
632
|
+
description,
|
|
633
|
+
maxConcurrency,
|
|
634
|
+
defaultPriority,
|
|
635
|
+
isPaused: false,
|
|
636
|
+
createdAt: new Date().toISOString(),
|
|
637
|
+
};
|
|
638
|
+
queueStore.set(queueId, queue);
|
|
639
|
+
return {
|
|
640
|
+
content: [
|
|
641
|
+
{
|
|
642
|
+
type: 'text',
|
|
643
|
+
text: JSON.stringify(queue, null, 2),
|
|
644
|
+
},
|
|
645
|
+
],
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
650
|
+
return {
|
|
651
|
+
content: [
|
|
652
|
+
{
|
|
653
|
+
type: 'text',
|
|
654
|
+
text: JSON.stringify({
|
|
655
|
+
error: 'CREATE_FAILED',
|
|
656
|
+
message,
|
|
657
|
+
name,
|
|
658
|
+
}),
|
|
659
|
+
},
|
|
660
|
+
],
|
|
661
|
+
isError: true,
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
/**
|
|
666
|
+
* Handler for queue_list tool
|
|
667
|
+
*/
|
|
668
|
+
export const handleQueueList = async (args) => {
|
|
669
|
+
const limit = args.limit ?? 20;
|
|
670
|
+
try {
|
|
671
|
+
const queues = Array.from(queueStore.values())
|
|
672
|
+
.slice(0, limit)
|
|
673
|
+
.map((q) => {
|
|
674
|
+
const tasks = Array.from(taskStore.values()).filter((t) => t.queueId === q.queueId);
|
|
675
|
+
return {
|
|
676
|
+
...q,
|
|
677
|
+
stats: {
|
|
678
|
+
pending: tasks.filter((t) => t.status === 'pending').length,
|
|
679
|
+
queued: tasks.filter((t) => t.status === 'queued').length,
|
|
680
|
+
running: tasks.filter((t) => t.status === 'running').length,
|
|
681
|
+
completed: tasks.filter((t) => t.status === 'completed').length,
|
|
682
|
+
failed: tasks.filter((t) => t.status === 'failed').length,
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
});
|
|
686
|
+
return {
|
|
687
|
+
content: [
|
|
688
|
+
{
|
|
689
|
+
type: 'text',
|
|
690
|
+
text: JSON.stringify({
|
|
691
|
+
queues,
|
|
692
|
+
total: queues.length,
|
|
693
|
+
}, null, 2),
|
|
694
|
+
},
|
|
695
|
+
],
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
catch (error) {
|
|
699
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
700
|
+
return {
|
|
701
|
+
content: [
|
|
702
|
+
{
|
|
703
|
+
type: 'text',
|
|
704
|
+
text: JSON.stringify({
|
|
705
|
+
error: 'LIST_FAILED',
|
|
706
|
+
message,
|
|
707
|
+
}),
|
|
708
|
+
},
|
|
709
|
+
],
|
|
710
|
+
isError: true,
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
//# sourceMappingURL=orchestration.js.map
|