@channlize/mcp 0.4.0 → 0.5.0
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/CHANGELOG.md +36 -0
- package/README.md +143 -11
- package/dist/agents.d.mts +84 -0
- package/dist/agents.d.ts +84 -0
- package/dist/agents.js +821 -0
- package/dist/agents.js.map +1 -0
- package/dist/agents.mjs +784 -0
- package/dist/agents.mjs.map +1 -0
- package/dist/inbox-BfpFVoK7.d.mts +194 -0
- package/dist/inbox-BfpFVoK7.d.ts +194 -0
- package/dist/inbox.d.mts +3 -0
- package/dist/inbox.d.ts +3 -0
- package/dist/inbox.js +587 -0
- package/dist/inbox.js.map +1 -0
- package/dist/inbox.mjs +547 -0
- package/dist/inbox.mjs.map +1 -0
- package/dist/index.d.mts +21 -68
- package/dist/index.d.ts +21 -68
- package/dist/index.js +1611 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1589 -216
- package/dist/index.mjs.map +1 -1
- package/dist/server.js +1534 -219
- package/dist/server.js.map +1 -1
- package/package.json +12 -2
package/dist/agents.mjs
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
// src/agents.ts
|
|
2
|
+
import * as z from "zod/v4";
|
|
3
|
+
|
|
4
|
+
// src/api.ts
|
|
5
|
+
import {
|
|
6
|
+
ChannlizeClient,
|
|
7
|
+
ChannlizeError,
|
|
8
|
+
parseApiError
|
|
9
|
+
} from "@channlize/core";
|
|
10
|
+
var ToolError = class extends Error {
|
|
11
|
+
constructor(message2, statusCode, code, retryAt) {
|
|
12
|
+
super(message2);
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.retryAt = retryAt;
|
|
16
|
+
this.name = "ToolError";
|
|
17
|
+
}
|
|
18
|
+
statusCode;
|
|
19
|
+
code;
|
|
20
|
+
retryAt;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/agents.ts
|
|
24
|
+
function defineTool(tool) {
|
|
25
|
+
return tool;
|
|
26
|
+
}
|
|
27
|
+
var AGENT_TASK_STATUSES = [
|
|
28
|
+
"open",
|
|
29
|
+
"working",
|
|
30
|
+
"input_required",
|
|
31
|
+
"completed",
|
|
32
|
+
"failed",
|
|
33
|
+
"canceled",
|
|
34
|
+
"rejected"
|
|
35
|
+
];
|
|
36
|
+
var uuid = (what) => z.string().uuid().describe(what);
|
|
37
|
+
var agentId = uuid(
|
|
38
|
+
"The agent to act as (from list_agents). Needed with a multi-agent key unless the server has a default agent (CHANNLIZE_AGENT_ID); leave it out with an agent key."
|
|
39
|
+
).optional();
|
|
40
|
+
var channelId = uuid("Agent channel ID (from list_agent_channels)");
|
|
41
|
+
var threadId = uuid(
|
|
42
|
+
"Reply in this thread: the id of any message in it (thread_id or id from read_agent_inbox)"
|
|
43
|
+
).optional();
|
|
44
|
+
var mentions = z.array(z.string().uuid()).max(50).optional().describe("Agent IDs to mention (from list_agents)");
|
|
45
|
+
var data = z.record(z.string(), z.unknown()).optional().describe("Structured data for the recipients (JSON object)");
|
|
46
|
+
var usage = {
|
|
47
|
+
tokens: z.number().int().min(0).optional().describe("Tokens you used for this message (reporting)"),
|
|
48
|
+
cost: z.number().min(0).optional().describe("What this message cost you, in USD (reporting)")
|
|
49
|
+
};
|
|
50
|
+
var message = z.looseObject({
|
|
51
|
+
id: z.string(),
|
|
52
|
+
channel_id: z.string(),
|
|
53
|
+
thread_id: z.string().nullable(),
|
|
54
|
+
type: z.string(),
|
|
55
|
+
text: z.string(),
|
|
56
|
+
sender: z.looseObject({ kind: z.string() }),
|
|
57
|
+
task_status: z.string().nullable().optional()
|
|
58
|
+
});
|
|
59
|
+
var sendOutput = z.object({
|
|
60
|
+
message,
|
|
61
|
+
deliveries: z.array(
|
|
62
|
+
z.looseObject({ id: z.string(), agent_id: z.string(), status: z.string() })
|
|
63
|
+
)
|
|
64
|
+
});
|
|
65
|
+
var dueAt = z.string().max(40).optional().describe("Due date: an ISO date (2026-11-30) or date-time");
|
|
66
|
+
var task = z.looseObject({
|
|
67
|
+
id: z.string(),
|
|
68
|
+
channel_id: z.string(),
|
|
69
|
+
text: z.string(),
|
|
70
|
+
board_status: z.string(),
|
|
71
|
+
assignee_agent_id: z.string().nullable(),
|
|
72
|
+
due_at: z.string().nullable()
|
|
73
|
+
});
|
|
74
|
+
var deliveries = z.array(
|
|
75
|
+
z.looseObject({ id: z.string(), agent_id: z.string(), status: z.string() })
|
|
76
|
+
);
|
|
77
|
+
var question = z.looseObject({
|
|
78
|
+
id: z.string(),
|
|
79
|
+
kind: z.string(),
|
|
80
|
+
question: z.string(),
|
|
81
|
+
status: z.string(),
|
|
82
|
+
answer: z.looseObject({}).nullable()
|
|
83
|
+
});
|
|
84
|
+
var questionId = uuid("The question ID (from ask_human or list_questions)");
|
|
85
|
+
var BOARD_STATUSES = [
|
|
86
|
+
"open",
|
|
87
|
+
"in_progress",
|
|
88
|
+
"blocked",
|
|
89
|
+
"done",
|
|
90
|
+
"failed"
|
|
91
|
+
];
|
|
92
|
+
var QUESTION_WAIT_MAX_SECONDS = 25;
|
|
93
|
+
var READ = {
|
|
94
|
+
readOnlyHint: true,
|
|
95
|
+
destructiveHint: false,
|
|
96
|
+
idempotentHint: true,
|
|
97
|
+
openWorldHint: false
|
|
98
|
+
};
|
|
99
|
+
var SEND = {
|
|
100
|
+
readOnlyHint: false,
|
|
101
|
+
destructiveHint: false,
|
|
102
|
+
idempotentHint: false,
|
|
103
|
+
openWorldHint: true
|
|
104
|
+
};
|
|
105
|
+
function actingAs(api, id) {
|
|
106
|
+
return id ?? api.agentId;
|
|
107
|
+
}
|
|
108
|
+
function requireAgent(api, id) {
|
|
109
|
+
const agent = actingAs(api, id);
|
|
110
|
+
if (!agent) {
|
|
111
|
+
throw new ToolError(
|
|
112
|
+
"Pass agentId (from list_agents), or set CHANNLIZE_AGENT_ID / --agent-id on the MCP server."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return agent;
|
|
116
|
+
}
|
|
117
|
+
async function send(api, body) {
|
|
118
|
+
const r = await api.request(
|
|
119
|
+
"POST",
|
|
120
|
+
"/v1/agents/messages",
|
|
121
|
+
{ body }
|
|
122
|
+
);
|
|
123
|
+
return { message: r.message, deliveries: r.deliveries ?? [] };
|
|
124
|
+
}
|
|
125
|
+
var enc = encodeURIComponent;
|
|
126
|
+
function outcomeMessage(status, q) {
|
|
127
|
+
const answer = q.answer ?? {};
|
|
128
|
+
const choice = answer.option_label ?? answer.option_id;
|
|
129
|
+
const comment = answer.comment ? `: ${String(answer.comment)}` : "";
|
|
130
|
+
switch (status) {
|
|
131
|
+
case "answered":
|
|
132
|
+
if (q.kind === "approval") {
|
|
133
|
+
return answer.approved ? `Approved${comment}. Go ahead.` : `Denied${comment}. Don't do it.`;
|
|
134
|
+
}
|
|
135
|
+
return `Answered: ${[choice, answer.text].filter(Boolean).join(" / ") || "(empty)"}.`;
|
|
136
|
+
case "expired_default":
|
|
137
|
+
return `Nobody answered by the deadline: the default option applies (${String(choice ?? "none")}).`;
|
|
138
|
+
case "expired":
|
|
139
|
+
return "Nobody answered by the deadline and there is no default: decide whether to ask again or drop it. For an approval, treat it as not approved.";
|
|
140
|
+
case "canceled":
|
|
141
|
+
return "The question was canceled.";
|
|
142
|
+
default:
|
|
143
|
+
return `Status: ${status}.`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
var AGENT_TOOLS = [
|
|
147
|
+
defineTool({
|
|
148
|
+
name: "send_agent_message",
|
|
149
|
+
title: "Send agent message",
|
|
150
|
+
description: "Post a message to an agent channel as your agent. Every other agent in the channel receives it (webhook, inbox or A2A), people see it in Slack and the dashboard, and it counts as one Event. Reply in a thread with threadId; mention agents with mentions. Needs the agents:send scope, and the agent must be a member of the channel.",
|
|
151
|
+
scope: "agents:send",
|
|
152
|
+
endpoint: "POST /v1/agents/messages",
|
|
153
|
+
inputSchema: z.object({
|
|
154
|
+
agentId,
|
|
155
|
+
channelId,
|
|
156
|
+
text: z.string().min(1).max(4e4).describe("Message text"),
|
|
157
|
+
threadId,
|
|
158
|
+
mentions,
|
|
159
|
+
data,
|
|
160
|
+
...usage
|
|
161
|
+
}),
|
|
162
|
+
outputSchema: sendOutput,
|
|
163
|
+
annotations: SEND,
|
|
164
|
+
handler: (api, a) => send(api, {
|
|
165
|
+
agent_id: actingAs(api, a.agentId),
|
|
166
|
+
channel_id: a.channelId,
|
|
167
|
+
type: "message",
|
|
168
|
+
text: a.text,
|
|
169
|
+
thread_id: a.threadId,
|
|
170
|
+
mentions: a.mentions,
|
|
171
|
+
data: a.data,
|
|
172
|
+
tokens: a.tokens,
|
|
173
|
+
cost: a.cost
|
|
174
|
+
})
|
|
175
|
+
}),
|
|
176
|
+
defineTool({
|
|
177
|
+
name: "create_task",
|
|
178
|
+
title: "Create task",
|
|
179
|
+
description: "Hand a task to an agent of a channel: creates a task (board status open) that starts its own thread, optionally assigned to a member agent (assigneeAgentId, who is mentioned) and with a due date. The returned taskId is for update_task, update_task_status and handoff_task. Your policy may refuse the channel or the assignee (POLICY_* errors). Needs the agents:send scope.",
|
|
180
|
+
scope: "agents:send",
|
|
181
|
+
endpoint: "POST /v1/agents/tasks",
|
|
182
|
+
inputSchema: z.object({
|
|
183
|
+
agentId,
|
|
184
|
+
channelId,
|
|
185
|
+
text: z.string().min(1).max(4e4).describe("What should be done, with enough context to do it"),
|
|
186
|
+
assigneeAgentId: uuid(
|
|
187
|
+
"The agent that should do it: a member of the channel (from list_agents)"
|
|
188
|
+
).optional(),
|
|
189
|
+
dueAt,
|
|
190
|
+
threadId,
|
|
191
|
+
mentions,
|
|
192
|
+
data
|
|
193
|
+
}),
|
|
194
|
+
// `message` is the task too (a task is its `task` message plus board fields).
|
|
195
|
+
outputSchema: z.object({ taskId: z.string(), task, message, deliveries }),
|
|
196
|
+
annotations: SEND,
|
|
197
|
+
handler: async (api, a) => {
|
|
198
|
+
const r = await api.request(
|
|
199
|
+
"POST",
|
|
200
|
+
"/v1/agents/tasks",
|
|
201
|
+
{
|
|
202
|
+
body: {
|
|
203
|
+
agent_id: actingAs(api, a.agentId),
|
|
204
|
+
channel_id: a.channelId,
|
|
205
|
+
text: a.text,
|
|
206
|
+
assignee_agent_id: a.assigneeAgentId,
|
|
207
|
+
due_at: a.dueAt,
|
|
208
|
+
thread_id: a.threadId,
|
|
209
|
+
mentions: a.mentions,
|
|
210
|
+
data: a.data
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
return {
|
|
215
|
+
taskId: String(r.task.id),
|
|
216
|
+
task: r.task,
|
|
217
|
+
message: r.task,
|
|
218
|
+
deliveries: r.deliveries ?? []
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}),
|
|
222
|
+
defineTool({
|
|
223
|
+
name: "update_task_status",
|
|
224
|
+
title: "Update task status",
|
|
225
|
+
description: "Report progress on a task (from create_task or a task in your inbox): working, input_required, completed, failed, canceled or rejected, with an optional note and result data. It is posted in the task thread and moves the task on the board (working \u2192 in_progress, input_required \u2192 blocked, completed \u2192 done; canceled and rejected show as failed). completed, failed, canceled and rejected are final: a closed task cannot be reopened (TASK_CLOSED). To change the due date, use update_task. Needs the agents:send scope.",
|
|
226
|
+
scope: "agents:send",
|
|
227
|
+
endpoint: "POST /v1/agents/messages",
|
|
228
|
+
inputSchema: z.object({
|
|
229
|
+
agentId,
|
|
230
|
+
channelId,
|
|
231
|
+
taskId: uuid("The task message ID"),
|
|
232
|
+
status: z.enum(AGENT_TASK_STATUSES).describe("The new status of the task"),
|
|
233
|
+
text: z.string().max(4e4).optional().describe("What changed, e.g. the result or what input is needed"),
|
|
234
|
+
data,
|
|
235
|
+
...usage
|
|
236
|
+
}),
|
|
237
|
+
outputSchema: sendOutput,
|
|
238
|
+
annotations: SEND,
|
|
239
|
+
handler: (api, a) => send(api, {
|
|
240
|
+
agent_id: actingAs(api, a.agentId),
|
|
241
|
+
channel_id: a.channelId,
|
|
242
|
+
type: "status",
|
|
243
|
+
text: a.text ?? "",
|
|
244
|
+
task_id: a.taskId,
|
|
245
|
+
task_status: a.status,
|
|
246
|
+
data: a.data,
|
|
247
|
+
tokens: a.tokens,
|
|
248
|
+
cost: a.cost
|
|
249
|
+
})
|
|
250
|
+
}),
|
|
251
|
+
defineTool({
|
|
252
|
+
name: "update_task",
|
|
253
|
+
title: "Update task",
|
|
254
|
+
description: "Move a task on the board (open, in_progress, blocked, done, failed) and/or change its due date, with a note: posted as a status update in the task thread, recorded in the task's history and shown on its Slack card. Only the task's assignee or creator can change it (NOT_TASK_PARTICIPANT), and a closed task can't change (TASK_CLOSED). To cancel or reject, or to attach result data, use update_task_status. Needs the agents:send scope.",
|
|
255
|
+
scope: "agents:send",
|
|
256
|
+
endpoint: "PATCH /v1/agents/tasks/:taskId",
|
|
257
|
+
inputSchema: z.object({
|
|
258
|
+
agentId,
|
|
259
|
+
taskId: uuid("The task ID"),
|
|
260
|
+
status: z.enum(BOARD_STATUSES).optional().describe("The board column"),
|
|
261
|
+
dueAt: z.string().max(40).nullable().optional().describe("New due date (ISO date or date-time); null clears it"),
|
|
262
|
+
note: z.string().max(2e3).optional().describe("What changed, shown with the update")
|
|
263
|
+
}),
|
|
264
|
+
outputSchema: z.object({ task, changed: z.boolean() }),
|
|
265
|
+
annotations: SEND,
|
|
266
|
+
handler: async (api, a) => {
|
|
267
|
+
if (a.status === void 0 && a.dueAt === void 0) {
|
|
268
|
+
throw new ToolError("Pass status or dueAt.");
|
|
269
|
+
}
|
|
270
|
+
const r = await api.request(
|
|
271
|
+
"PATCH",
|
|
272
|
+
`/v1/agents/tasks/${enc(a.taskId)}`,
|
|
273
|
+
{
|
|
274
|
+
body: {
|
|
275
|
+
agent_id: actingAs(api, a.agentId),
|
|
276
|
+
status: a.status,
|
|
277
|
+
due_at: a.dueAt,
|
|
278
|
+
note: a.note
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
return { task: r.task, changed: Boolean(r.changed) };
|
|
283
|
+
}
|
|
284
|
+
}),
|
|
285
|
+
defineTool({
|
|
286
|
+
name: "handoff_task",
|
|
287
|
+
title: "Hand off task",
|
|
288
|
+
description: "Hand a task you are assigned to (or created) to another member agent of its channel, with the reason: the new and the previous assignee get a status message (data.handoff), and it's recorded in the task's history. Use it when another agent is better placed, then stop working on the task. Errors: ALREADY_ASSIGNED, AGENT_NOT_IN_CHANNEL, TASK_CLOSED, NOT_TASK_PARTICIPANT, POLICY_DM_NOT_ALLOWED. Needs the agents:send scope.",
|
|
289
|
+
scope: "agents:send",
|
|
290
|
+
endpoint: "POST /v1/agents/tasks/:taskId/handoff",
|
|
291
|
+
inputSchema: z.object({
|
|
292
|
+
agentId,
|
|
293
|
+
taskId: uuid("The task ID"),
|
|
294
|
+
toAgentId: uuid("The new assignee (from list_agents or get_org_chart)"),
|
|
295
|
+
reason: z.string().max(2e3).optional().describe("Why, and what the new assignee needs to know")
|
|
296
|
+
}),
|
|
297
|
+
outputSchema: z.object({ task, deliveries }),
|
|
298
|
+
annotations: SEND,
|
|
299
|
+
handler: async (api, a) => {
|
|
300
|
+
const r = await api.request(
|
|
301
|
+
"POST",
|
|
302
|
+
`/v1/agents/tasks/${enc(a.taskId)}/handoff`,
|
|
303
|
+
{
|
|
304
|
+
body: {
|
|
305
|
+
agent_id: actingAs(api, a.agentId),
|
|
306
|
+
to_agent_id: a.toAgentId,
|
|
307
|
+
reason: a.reason
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
return {
|
|
312
|
+
task: r.task,
|
|
313
|
+
deliveries: r.deliveries ?? []
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}),
|
|
317
|
+
defineTool({
|
|
318
|
+
name: "list_tasks",
|
|
319
|
+
title: "List tasks",
|
|
320
|
+
description: "List a channel's tasks, newest first, with their board status (open, in_progress, blocked, done, failed), assignee, due date and last handoff. Filter by assignee (your own agent id for your work) or status. channelId is required unless the key is an agents:admin key. Needs the agents:read scope.",
|
|
321
|
+
scope: "agents:read",
|
|
322
|
+
endpoint: "GET /v1/agents/tasks",
|
|
323
|
+
inputSchema: z.object({
|
|
324
|
+
agentId,
|
|
325
|
+
channelId: channelId.optional(),
|
|
326
|
+
assigneeAgentId: uuid("Only tasks assigned to this agent").optional(),
|
|
327
|
+
status: z.enum(BOARD_STATUSES).optional(),
|
|
328
|
+
limit: z.number().int().min(1).max(500).default(50).describe("How many to return (1-500, default 50)")
|
|
329
|
+
}),
|
|
330
|
+
outputSchema: z.object({ tasks: z.array(task) }),
|
|
331
|
+
annotations: READ,
|
|
332
|
+
handler: async (api, a) => {
|
|
333
|
+
const r = await api.request(
|
|
334
|
+
"GET",
|
|
335
|
+
"/v1/agents/tasks",
|
|
336
|
+
{
|
|
337
|
+
query: {
|
|
338
|
+
agent_id: actingAs(api, a.agentId),
|
|
339
|
+
channel_id: a.channelId,
|
|
340
|
+
assignee_agent_id: a.assigneeAgentId,
|
|
341
|
+
status: a.status,
|
|
342
|
+
limit: a.limit
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
return { tasks: r.tasks ?? [] };
|
|
347
|
+
}
|
|
348
|
+
}),
|
|
349
|
+
defineTool({
|
|
350
|
+
name: "get_task_board",
|
|
351
|
+
title: "Get task board",
|
|
352
|
+
description: "A channel's task board: tasks grouped by column (open, in_progress, blocked, done, failed), counts per column, and the agents on it. Needs the agents:read scope.",
|
|
353
|
+
scope: "agents:read",
|
|
354
|
+
endpoint: "GET /v1/agents/tasks/board",
|
|
355
|
+
inputSchema: z.object({
|
|
356
|
+
agentId,
|
|
357
|
+
channelId,
|
|
358
|
+
assigneeAgentId: uuid("Only tasks assigned to this agent").optional()
|
|
359
|
+
}),
|
|
360
|
+
outputSchema: z.object({
|
|
361
|
+
channel_id: z.string(),
|
|
362
|
+
columns: z.record(z.string(), z.array(task)),
|
|
363
|
+
counts: z.record(z.string(), z.number()),
|
|
364
|
+
agents: z.array(z.looseObject({ id: z.string() })),
|
|
365
|
+
truncated: z.boolean()
|
|
366
|
+
}),
|
|
367
|
+
annotations: READ,
|
|
368
|
+
handler: async (api, a) => await api.request("GET", "/v1/agents/tasks/board", {
|
|
369
|
+
query: {
|
|
370
|
+
agent_id: actingAs(api, a.agentId),
|
|
371
|
+
channel_id: a.channelId,
|
|
372
|
+
assignee_agent_id: a.assigneeAgentId
|
|
373
|
+
}
|
|
374
|
+
})
|
|
375
|
+
}),
|
|
376
|
+
defineTool({
|
|
377
|
+
name: "ask_human",
|
|
378
|
+
title: "Ask a human",
|
|
379
|
+
description: "Ask people a question, or for an approval (kind approval: Approve / Deny), when you can't or shouldn't decide alone. It's posted in Slack (the channel's linked Slack channel, else the escalation channel) with a button per option, and escalates (manager, owner, supervisors, escalation channel) until someone answers or the deadline passes; with a defaultOption, the default applies at the deadline. Returns at once with the questionId: then call get_answer, which waits for the answer. Don't act on what you asked about before the answer. Counts as one Event. Your policy may refuse (POLICY_ASK_HUMAN_NOT_ALLOWED, POLICY_URGENCY_NOT_ALLOWED). Needs the agents:ask_human scope.",
|
|
380
|
+
scope: "agents:ask_human",
|
|
381
|
+
endpoint: "POST /v1/agents/questions",
|
|
382
|
+
inputSchema: z.object({
|
|
383
|
+
agentId,
|
|
384
|
+
kind: z.enum(["question", "approval"]).default("question").describe("question (default) or approval (answered Approve / Deny)"),
|
|
385
|
+
question: z.string().min(1).max(3e3).describe("The question, with what people need to answer it"),
|
|
386
|
+
options: z.array(
|
|
387
|
+
z.object({
|
|
388
|
+
id: z.string().min(1).max(100),
|
|
389
|
+
label: z.string().min(1).max(75)
|
|
390
|
+
})
|
|
391
|
+
).max(10).optional().describe("Up to 10 answers to pick from (ignored for approvals)"),
|
|
392
|
+
freeText: z.boolean().optional().describe("Allow a typed answer (always on without options)"),
|
|
393
|
+
urgency: z.enum(["low", "normal", "high", "urgent"]).optional().describe("How fast it escalates (default normal)"),
|
|
394
|
+
deadline: z.string().max(40).optional().describe("ISO date-time, at most 30 days away"),
|
|
395
|
+
defaultOption: z.string().max(100).optional().describe("Option id applied at the deadline when nobody answered"),
|
|
396
|
+
channelId: channelId.optional().describe("Post it in this agent channel (from list_agent_channels)"),
|
|
397
|
+
threadId,
|
|
398
|
+
context: z.record(z.string(), z.unknown()).optional().describe("Facts shown with the question (JSON object)"),
|
|
399
|
+
amount: z.number().min(0).optional().describe("Approvals: the amount at stake"),
|
|
400
|
+
currency: z.string().regex(/^[A-Za-z]{3}$/).optional().describe("Approvals: ISO 4217 currency code"),
|
|
401
|
+
resource: z.record(z.string(), z.unknown()).optional().describe("Approvals: what is being approved (JSON object)"),
|
|
402
|
+
requiredRoles: z.array(z.string().min(1).max(40)).max(10).optional().describe('Approvals: roles that may answer, e.g. ["admin"]')
|
|
403
|
+
}),
|
|
404
|
+
outputSchema: z.object({ questionId: z.string(), question }),
|
|
405
|
+
annotations: SEND,
|
|
406
|
+
handler: async (api, a) => {
|
|
407
|
+
const r = await api.request(
|
|
408
|
+
"POST",
|
|
409
|
+
"/v1/agents/questions",
|
|
410
|
+
{
|
|
411
|
+
body: {
|
|
412
|
+
agent_id: actingAs(api, a.agentId),
|
|
413
|
+
kind: a.kind,
|
|
414
|
+
question: a.question,
|
|
415
|
+
options: a.options,
|
|
416
|
+
free_text: a.freeText,
|
|
417
|
+
urgency: a.urgency,
|
|
418
|
+
deadline: a.deadline,
|
|
419
|
+
default_option: a.defaultOption,
|
|
420
|
+
channel_id: a.channelId,
|
|
421
|
+
thread_id: a.threadId,
|
|
422
|
+
context: a.context,
|
|
423
|
+
amount: a.amount,
|
|
424
|
+
currency: a.currency,
|
|
425
|
+
resource: a.resource,
|
|
426
|
+
required_roles: a.requiredRoles
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
);
|
|
430
|
+
return {
|
|
431
|
+
questionId: String(r.question.id),
|
|
432
|
+
question: r.question
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
}),
|
|
436
|
+
defineTool({
|
|
437
|
+
name: "get_answer",
|
|
438
|
+
title: "Get answer",
|
|
439
|
+
description: `Wait for the answer to a question from ask_human: holds up to waitSeconds (default and maximum ${QUESTION_WAIT_MAX_SECONDS}) and returns as soon as it closes. status is answered (answer.option_id / answer.text; approvals have answer.approved), expired_default (the default option applied), expired (no answer by the deadline) or canceled. When waiting is true nobody has answered yet: call get_answer again, or do other work and come back. Needs the agents:ask_human scope (or agents:read).`,
|
|
440
|
+
scope: "agents:ask_human",
|
|
441
|
+
endpoint: "GET /v1/agents/questions/:id/wait",
|
|
442
|
+
inputSchema: z.object({
|
|
443
|
+
agentId,
|
|
444
|
+
questionId,
|
|
445
|
+
waitSeconds: z.number().int().min(0).max(QUESTION_WAIT_MAX_SECONDS).default(QUESTION_WAIT_MAX_SECONDS).describe(
|
|
446
|
+
`Seconds to wait for an answer (0-${QUESTION_WAIT_MAX_SECONDS}, default ${QUESTION_WAIT_MAX_SECONDS}); 0 only checks`
|
|
447
|
+
)
|
|
448
|
+
}),
|
|
449
|
+
outputSchema: z.object({
|
|
450
|
+
questionId: z.string(),
|
|
451
|
+
status: z.string(),
|
|
452
|
+
waiting: z.boolean(),
|
|
453
|
+
answer: z.looseObject({}).nullable(),
|
|
454
|
+
message: z.string(),
|
|
455
|
+
question
|
|
456
|
+
}),
|
|
457
|
+
annotations: READ,
|
|
458
|
+
handler: async (api, a) => {
|
|
459
|
+
const r = await api.request(
|
|
460
|
+
"GET",
|
|
461
|
+
`/v1/agents/questions/${enc(a.questionId)}/wait`,
|
|
462
|
+
{
|
|
463
|
+
query: {
|
|
464
|
+
agent_id: actingAs(api, a.agentId),
|
|
465
|
+
timeout: a.waitSeconds
|
|
466
|
+
},
|
|
467
|
+
// The API holds the request for up to waitSeconds.
|
|
468
|
+
timeout: (a.waitSeconds + 10) * 1e3
|
|
469
|
+
}
|
|
470
|
+
);
|
|
471
|
+
const status = String(r.question.status);
|
|
472
|
+
const waiting = status === "open";
|
|
473
|
+
return {
|
|
474
|
+
questionId: a.questionId,
|
|
475
|
+
status,
|
|
476
|
+
waiting,
|
|
477
|
+
answer: r.question.answer ?? null,
|
|
478
|
+
message: waiting ? `Still waiting: nobody has answered yet. Call get_answer again with questionId ${a.questionId}, or check back later; don't act on the question meanwhile.` : outcomeMessage(status, r.question),
|
|
479
|
+
question: r.question
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}),
|
|
483
|
+
defineTool({
|
|
484
|
+
name: "list_questions",
|
|
485
|
+
title: "List questions",
|
|
486
|
+
description: "List your questions and the ones escalated to you as a manager agent, newest first. Filter with status open to find what still needs an answer (answer_escalated_question). Needs the agents:read scope (or agents:ask_human).",
|
|
487
|
+
scope: "agents:read",
|
|
488
|
+
endpoint: "GET /v1/agents/questions",
|
|
489
|
+
inputSchema: z.object({
|
|
490
|
+
agentId,
|
|
491
|
+
status: z.enum(["open", "answered", "expired_default", "expired", "canceled"]).optional(),
|
|
492
|
+
kind: z.enum(["question", "approval"]).optional(),
|
|
493
|
+
channelId: channelId.optional(),
|
|
494
|
+
cursor: z.string().max(300).optional().describe("nextCursor of the previous call"),
|
|
495
|
+
limit: z.number().int().min(1).max(200).default(20).describe("How many to return (1-200, default 20)")
|
|
496
|
+
}),
|
|
497
|
+
outputSchema: z.object({
|
|
498
|
+
questions: z.array(question),
|
|
499
|
+
nextCursor: z.string().nullable()
|
|
500
|
+
}),
|
|
501
|
+
annotations: READ,
|
|
502
|
+
handler: async (api, a) => {
|
|
503
|
+
const r = await api.request("GET", "/v1/agents/questions", {
|
|
504
|
+
query: {
|
|
505
|
+
agent_id: actingAs(api, a.agentId),
|
|
506
|
+
status: a.status,
|
|
507
|
+
kind: a.kind,
|
|
508
|
+
channel_id: a.channelId,
|
|
509
|
+
cursor: a.cursor,
|
|
510
|
+
limit: a.limit
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
return {
|
|
514
|
+
questions: r.questions ?? [],
|
|
515
|
+
nextCursor: r.next_cursor ?? null
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
}),
|
|
519
|
+
defineTool({
|
|
520
|
+
name: "cancel_question",
|
|
521
|
+
title: "Cancel question",
|
|
522
|
+
description: "Cancel one of your open questions when it no longer matters (you found the answer, the work was dropped): its Slack post is updated and escalation stops. Only the agent that asked can cancel, and a closed question can't be (QUESTION_CLOSED). Needs the agents:ask_human scope.",
|
|
523
|
+
scope: "agents:ask_human",
|
|
524
|
+
endpoint: "DELETE /v1/agents/questions/:id",
|
|
525
|
+
inputSchema: z.object({ agentId, questionId }),
|
|
526
|
+
outputSchema: z.object({ question }),
|
|
527
|
+
annotations: {
|
|
528
|
+
readOnlyHint: false,
|
|
529
|
+
destructiveHint: true,
|
|
530
|
+
idempotentHint: false,
|
|
531
|
+
openWorldHint: true
|
|
532
|
+
},
|
|
533
|
+
handler: async (api, a) => {
|
|
534
|
+
const r = await api.request(
|
|
535
|
+
"DELETE",
|
|
536
|
+
`/v1/agents/questions/${enc(a.questionId)}`,
|
|
537
|
+
{ query: { agent_id: actingAs(api, a.agentId) } }
|
|
538
|
+
);
|
|
539
|
+
return { question: r.question };
|
|
540
|
+
}
|
|
541
|
+
}),
|
|
542
|
+
defineTool({
|
|
543
|
+
name: "answer_escalated_question",
|
|
544
|
+
title: "Answer escalated question",
|
|
545
|
+
description: "Answer a question another agent asked, when it was escalated to you as its manager agent (a question.escalated delivery, or list_questions with status open). Pick an optionId (approve / deny for approvals, with a comment), or give text when free text is allowed. The first answer wins (QUESTION_CLOSED after), approvals that require a role need a person (APPROVAL_ROLE_REQUIRED), and you can't answer your own question. Needs the agents:send scope.",
|
|
546
|
+
scope: "agents:send",
|
|
547
|
+
endpoint: "POST /v1/agents/questions/:id/answer",
|
|
548
|
+
inputSchema: z.object({
|
|
549
|
+
agentId,
|
|
550
|
+
questionId,
|
|
551
|
+
optionId: z.string().min(1).max(100).optional().describe("One of the question options (approve / deny for approvals)"),
|
|
552
|
+
text: z.string().max(3e3).optional().describe("A typed answer, when the question allows free text"),
|
|
553
|
+
comment: z.string().max(2e3).optional().describe("Why (shown with the answer; say why on a deny)")
|
|
554
|
+
}),
|
|
555
|
+
outputSchema: z.object({ question }),
|
|
556
|
+
annotations: SEND,
|
|
557
|
+
handler: async (api, a) => {
|
|
558
|
+
if (!a.optionId && !a.text) throw new ToolError("Pass optionId or text.");
|
|
559
|
+
const r = await api.request(
|
|
560
|
+
"POST",
|
|
561
|
+
`/v1/agents/questions/${enc(a.questionId)}/answer`,
|
|
562
|
+
{
|
|
563
|
+
body: {
|
|
564
|
+
agent_id: actingAs(api, a.agentId),
|
|
565
|
+
option_id: a.optionId,
|
|
566
|
+
text: a.text,
|
|
567
|
+
comment: a.comment
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
return { question: r.question };
|
|
572
|
+
}
|
|
573
|
+
}),
|
|
574
|
+
defineTool({
|
|
575
|
+
name: "get_org_chart",
|
|
576
|
+
title: "Get org chart",
|
|
577
|
+
description: "The organization's agents with their manager (an agent or a person), owner and teams, the teams, and the reporting tree. Use it to find who to hand a task off to, or who manages an agent. Needs the agents:read scope.",
|
|
578
|
+
scope: "agents:read",
|
|
579
|
+
endpoint: "GET /v1/agents/org-chart",
|
|
580
|
+
inputSchema: z.object({
|
|
581
|
+
teamId: uuid("Only this team").optional(),
|
|
582
|
+
channelId: uuid("Only the agents of this channel").optional(),
|
|
583
|
+
includeRetired: z.boolean().optional().describe("Include retired agents (default false)")
|
|
584
|
+
}),
|
|
585
|
+
outputSchema: z.object({
|
|
586
|
+
agents: z.array(z.looseObject({ id: z.string() })),
|
|
587
|
+
users: z.array(z.looseObject({ id: z.string() })),
|
|
588
|
+
teams: z.array(z.looseObject({ id: z.string() })),
|
|
589
|
+
tree: z.array(z.looseObject({}))
|
|
590
|
+
}),
|
|
591
|
+
annotations: READ,
|
|
592
|
+
handler: async (api, a) => await api.request("GET", "/v1/agents/org-chart", {
|
|
593
|
+
query: {
|
|
594
|
+
team_id: a.teamId,
|
|
595
|
+
channel_id: a.channelId,
|
|
596
|
+
include_retired: a.includeRetired ? "true" : void 0
|
|
597
|
+
}
|
|
598
|
+
})
|
|
599
|
+
}),
|
|
600
|
+
defineTool({
|
|
601
|
+
name: "get_effective_policy",
|
|
602
|
+
title: "Get effective policy",
|
|
603
|
+
description: "The policy in force for an agent (in a channel): the merged rules (allowed channels, direct messages, asking humans, rate, budgets, working hours, thread depth, humans-win minutes), which policy set each, current usage, working hours now, and with a channel whether it may post and read there now. Read-only. Needs an unbound key with the agents:admin scope: a key bound to agents gets 403 AGENT_ADMIN_KEY_REQUIRED.",
|
|
604
|
+
scope: "agents:admin",
|
|
605
|
+
endpoint: "GET /v1/agents/policies/preview",
|
|
606
|
+
inputSchema: z.object({
|
|
607
|
+
agentId: uuid(
|
|
608
|
+
"The agent (from list_agents). Default: the server agent (CHANNLIZE_AGENT_ID)"
|
|
609
|
+
).optional(),
|
|
610
|
+
channelId: channelId.optional()
|
|
611
|
+
}),
|
|
612
|
+
outputSchema: z.looseObject({
|
|
613
|
+
agent_id: z.string(),
|
|
614
|
+
channel_id: z.string().nullable(),
|
|
615
|
+
rules: z.looseObject({}),
|
|
616
|
+
working_hours: z.looseObject({}),
|
|
617
|
+
usage: z.looseObject({}),
|
|
618
|
+
checks: z.looseObject({}).nullable()
|
|
619
|
+
}),
|
|
620
|
+
annotations: READ,
|
|
621
|
+
handler: async (api, a) => await api.request("GET", "/v1/agents/policies/preview", {
|
|
622
|
+
query: {
|
|
623
|
+
agent_id: requireAgent(api, a.agentId),
|
|
624
|
+
channel_id: a.channelId
|
|
625
|
+
}
|
|
626
|
+
})
|
|
627
|
+
}),
|
|
628
|
+
defineTool({
|
|
629
|
+
name: "read_agent_inbox",
|
|
630
|
+
title: "Read agent inbox",
|
|
631
|
+
description: "Read your agent's unacknowledged messages, oldest first: messages, tasks and task status updates from other agents and people, each with its channel, thread and sender. Messages stay until ack_agent_messages acknowledges them, so read, handle, then ack. Needs the agents:read scope.",
|
|
632
|
+
scope: "agents:read",
|
|
633
|
+
endpoint: "GET /v1/agents/:id/inbox",
|
|
634
|
+
inputSchema: z.object({
|
|
635
|
+
agentId,
|
|
636
|
+
cursor: z.string().max(200).optional().describe("Read after this cursor (nextCursor of the previous call)"),
|
|
637
|
+
limit: z.number().int().min(1).max(200).default(20).describe("How many to return (1-200, default 20)")
|
|
638
|
+
}),
|
|
639
|
+
outputSchema: z.object({
|
|
640
|
+
agentId: z.string(),
|
|
641
|
+
messages: z.array(
|
|
642
|
+
z.looseObject({
|
|
643
|
+
delivery_id: z.string(),
|
|
644
|
+
cursor: z.string(),
|
|
645
|
+
message
|
|
646
|
+
})
|
|
647
|
+
),
|
|
648
|
+
nextCursor: z.string().nullable(),
|
|
649
|
+
hasMore: z.boolean()
|
|
650
|
+
}),
|
|
651
|
+
annotations: READ,
|
|
652
|
+
handler: async (api, a) => {
|
|
653
|
+
const id = requireAgent(api, a.agentId);
|
|
654
|
+
const r = await api.request("GET", `/v1/agents/${enc(id)}/inbox`, {
|
|
655
|
+
query: { cursor: a.cursor, limit: a.limit }
|
|
656
|
+
});
|
|
657
|
+
return {
|
|
658
|
+
agentId: id,
|
|
659
|
+
messages: r.messages ?? [],
|
|
660
|
+
nextCursor: r.next_cursor ?? null,
|
|
661
|
+
hasMore: Boolean(r.has_more)
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
}),
|
|
665
|
+
defineTool({
|
|
666
|
+
name: "ack_agent_messages",
|
|
667
|
+
title: "Acknowledge agent messages",
|
|
668
|
+
description: "Acknowledge inbox messages you handled so read_agent_inbox stops returning them: upTo acks everything up to and including that delivery or message ID, ids acks just those. Acking twice is harmless. Needs the agents:read scope.",
|
|
669
|
+
scope: "agents:read",
|
|
670
|
+
endpoint: "POST /v1/agents/:id/inbox/ack",
|
|
671
|
+
inputSchema: z.object({
|
|
672
|
+
agentId,
|
|
673
|
+
upTo: z.string().uuid().optional().describe("Ack everything up to and including this delivery_id"),
|
|
674
|
+
ids: z.array(z.string().uuid()).min(1).max(500).optional().describe("Ack these delivery (or message) IDs")
|
|
675
|
+
}),
|
|
676
|
+
outputSchema: z.object({ acked: z.number() }),
|
|
677
|
+
annotations: {
|
|
678
|
+
readOnlyHint: false,
|
|
679
|
+
destructiveHint: false,
|
|
680
|
+
idempotentHint: true,
|
|
681
|
+
openWorldHint: false
|
|
682
|
+
},
|
|
683
|
+
handler: async (api, a) => {
|
|
684
|
+
if (!a.upTo === !a.ids) {
|
|
685
|
+
throw new ToolError("Pass either upTo or ids.");
|
|
686
|
+
}
|
|
687
|
+
const id = requireAgent(api, a.agentId);
|
|
688
|
+
const r = await api.request(
|
|
689
|
+
"POST",
|
|
690
|
+
`/v1/agents/${enc(id)}/inbox/ack`,
|
|
691
|
+
{ body: a.upTo ? { up_to: a.upTo } : { ids: a.ids } }
|
|
692
|
+
);
|
|
693
|
+
return { acked: Number(r.acked ?? 0) };
|
|
694
|
+
}
|
|
695
|
+
}),
|
|
696
|
+
defineTool({
|
|
697
|
+
name: "list_agents",
|
|
698
|
+
title: "List agents",
|
|
699
|
+
description: "List the organization's agents: id, slug, name, role, description, status (active, paused, retired) and how they receive messages. Use the ids for mentions and agentId. Needs the agents:read scope.",
|
|
700
|
+
scope: "agents:read",
|
|
701
|
+
endpoint: "GET /v1/agents",
|
|
702
|
+
inputSchema: z.object({
|
|
703
|
+
includeRetired: z.boolean().optional().describe("Include retired agents (default false)")
|
|
704
|
+
}),
|
|
705
|
+
outputSchema: z.object({
|
|
706
|
+
agents: z.array(
|
|
707
|
+
z.looseObject({
|
|
708
|
+
id: z.string(),
|
|
709
|
+
slug: z.string(),
|
|
710
|
+
name: z.string(),
|
|
711
|
+
status: z.string()
|
|
712
|
+
})
|
|
713
|
+
)
|
|
714
|
+
}),
|
|
715
|
+
annotations: READ,
|
|
716
|
+
handler: async (api, a) => {
|
|
717
|
+
const r = await api.request("GET", "/v1/agents", {
|
|
718
|
+
query: { include_retired: a.includeRetired || void 0 }
|
|
719
|
+
});
|
|
720
|
+
return { agents: r.agents ?? [] };
|
|
721
|
+
}
|
|
722
|
+
}),
|
|
723
|
+
defineTool({
|
|
724
|
+
name: "list_agent_channels",
|
|
725
|
+
title: "List agent channels",
|
|
726
|
+
description: "List the agent channels your key's agents are members or observers of: id, slug, name, description and whether they are archived. Post with send_agent_message (members only). Needs the agents:read scope.",
|
|
727
|
+
scope: "agents:read",
|
|
728
|
+
endpoint: "GET /v1/agents/channels",
|
|
729
|
+
inputSchema: z.object({
|
|
730
|
+
includeArchived: z.boolean().optional().describe("Include archived channels (default false)")
|
|
731
|
+
}),
|
|
732
|
+
outputSchema: z.object({
|
|
733
|
+
channels: z.array(
|
|
734
|
+
z.looseObject({
|
|
735
|
+
id: z.string(),
|
|
736
|
+
slug: z.string(),
|
|
737
|
+
name: z.string(),
|
|
738
|
+
archived: z.boolean()
|
|
739
|
+
})
|
|
740
|
+
)
|
|
741
|
+
}),
|
|
742
|
+
annotations: READ,
|
|
743
|
+
handler: async (api, a) => {
|
|
744
|
+
const r = await api.request(
|
|
745
|
+
"GET",
|
|
746
|
+
"/v1/agents/channels",
|
|
747
|
+
{ query: { include_archived: a.includeArchived || void 0 } }
|
|
748
|
+
);
|
|
749
|
+
return { channels: r.channels ?? [] };
|
|
750
|
+
}
|
|
751
|
+
})
|
|
752
|
+
];
|
|
753
|
+
var AGENT_TOOL_NAMES = AGENT_TOOLS.map((t) => t.name);
|
|
754
|
+
function getAgentTool(name) {
|
|
755
|
+
return AGENT_TOOLS.find((t) => t.name === name);
|
|
756
|
+
}
|
|
757
|
+
async function runAgentTool(api, name, args) {
|
|
758
|
+
const tool = getAgentTool(name);
|
|
759
|
+
if (!tool) throw new ToolError(`Unknown agent tool "${name}"`);
|
|
760
|
+
const parsed = tool.inputSchema.safeParse(args ?? {});
|
|
761
|
+
if (!parsed.success) {
|
|
762
|
+
throw new ToolError(
|
|
763
|
+
`Invalid arguments for ${name}: ${parsed.error.issues.map((i) => `${i.path.join(".") || "input"}: ${i.message}`).join("; ")}`
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
return await tool.handler(api, parsed.data);
|
|
767
|
+
}
|
|
768
|
+
function agentToolsAsJsonSchema(filter = () => true) {
|
|
769
|
+
return AGENT_TOOLS.filter(filter).map((t) => ({
|
|
770
|
+
name: t.name,
|
|
771
|
+
description: t.description,
|
|
772
|
+
parameters: z.toJSONSchema(t.inputSchema, { io: "input" })
|
|
773
|
+
}));
|
|
774
|
+
}
|
|
775
|
+
export {
|
|
776
|
+
AGENT_TASK_STATUSES,
|
|
777
|
+
AGENT_TOOLS,
|
|
778
|
+
AGENT_TOOL_NAMES,
|
|
779
|
+
QUESTION_WAIT_MAX_SECONDS,
|
|
780
|
+
agentToolsAsJsonSchema,
|
|
781
|
+
getAgentTool,
|
|
782
|
+
runAgentTool
|
|
783
|
+
};
|
|
784
|
+
//# sourceMappingURL=agents.mjs.map
|