@channlize/mcp 0.4.0 → 0.6.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 +53 -0
- package/README.md +156 -11
- package/dist/agents.d.mts +94 -0
- package/dist/agents.d.ts +94 -0
- package/dist/agents.js +1369 -0
- package/dist/agents.js.map +1 -0
- package/dist/agents.mjs +1332 -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 +2164 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2142 -216
- package/dist/index.mjs.map +1 -1
- package/dist/server.js +2098 -230
- package/dist/server.js.map +1 -1
- package/package.json +12 -2
package/dist/agents.mjs
ADDED
|
@@ -0,0 +1,1332 @@
|
|
|
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-summary.ts
|
|
24
|
+
var num = (v) => typeof v === "number" ? v : Number(v) || 0;
|
|
25
|
+
var arr = (v) => Array.isArray(v) ? v : [];
|
|
26
|
+
var obj = (v) => v && typeof v === "object" ? v : {};
|
|
27
|
+
var str = (v) => typeof v === "string" ? v : null;
|
|
28
|
+
function money(v) {
|
|
29
|
+
return Math.round(num(v) * 1e4) / 1e4;
|
|
30
|
+
}
|
|
31
|
+
function fmtMoney(v) {
|
|
32
|
+
return money(v).toFixed(4).replace(/\.?0+$/, "") || "0";
|
|
33
|
+
}
|
|
34
|
+
function pct(v) {
|
|
35
|
+
return v === null || v === void 0 ? "n/a" : `${Math.round(num(v) * 1e3) / 10}%`;
|
|
36
|
+
}
|
|
37
|
+
function fmtMs(v) {
|
|
38
|
+
if (v === null || v === void 0) return "n/a";
|
|
39
|
+
const ms = num(v);
|
|
40
|
+
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
41
|
+
if (ms < 6e4) return `${Math.round(ms / 100) / 10}s`;
|
|
42
|
+
if (ms < 36e5) return `${Math.round(ms / 6e3) / 10}m`;
|
|
43
|
+
return `${Math.round(ms / 36e4) / 10}h`;
|
|
44
|
+
}
|
|
45
|
+
function highlightText(html) {
|
|
46
|
+
return html.replace(/<mark>/g, "**").replace(/<\/mark>/g, "**").replace(/<[^>]*>/g, "").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&");
|
|
47
|
+
}
|
|
48
|
+
function clip(text, max) {
|
|
49
|
+
const s = typeof text === "string" ? text : "";
|
|
50
|
+
return s.length > max ? `${s.slice(0, max - 1)}\u2026` : s;
|
|
51
|
+
}
|
|
52
|
+
function rangeSummary(range2) {
|
|
53
|
+
const r = obj(range2);
|
|
54
|
+
return {
|
|
55
|
+
from: String(r.from ?? ""),
|
|
56
|
+
to: String(r.to ?? ""),
|
|
57
|
+
days: num(r.days),
|
|
58
|
+
historyStart: str(r.history_start),
|
|
59
|
+
retentionDays: r.retention_days === void 0 ? null : num(r.retention_days),
|
|
60
|
+
clamped: Boolean(r.clamped),
|
|
61
|
+
empty: Boolean(r.empty)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function rangeNote(r) {
|
|
65
|
+
const base = `${r.from}..${r.to} (${r.days} day${r.days === 1 ? "" : "s"}, UTC)`;
|
|
66
|
+
return r.clamped ? `${base}; clamped to the plan's history start ${r.historyStart}` : base;
|
|
67
|
+
}
|
|
68
|
+
function latency(v) {
|
|
69
|
+
const l = obj(v);
|
|
70
|
+
return {
|
|
71
|
+
count: num(l.count),
|
|
72
|
+
avgMs: l.avg_ms === null || l.avg_ms === void 0 ? null : num(l.avg_ms),
|
|
73
|
+
p50Ms: l.p50_ms === null || l.p50_ms === void 0 ? null : num(l.p50_ms),
|
|
74
|
+
p90Ms: l.p90_ms === null || l.p90_ms === void 0 ? null : num(l.p90_ms)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function summarizeSearch(r) {
|
|
78
|
+
const results = arr(r.results).map((x) => {
|
|
79
|
+
const channel = x.channel ? obj(x.channel) : null;
|
|
80
|
+
const base = {
|
|
81
|
+
kind: String(x.kind),
|
|
82
|
+
highlight: clip(highlightText(String(x.highlight ?? "")), 400),
|
|
83
|
+
rank: Math.round(num(x.rank) * 1e3) / 1e3,
|
|
84
|
+
channel: channel ? str(channel.slug) ?? str(channel.id) : null,
|
|
85
|
+
channelId: channel ? str(channel.id) : null,
|
|
86
|
+
threadId: str(x.thread_id),
|
|
87
|
+
slackPermalink: str(x.slack_permalink)
|
|
88
|
+
};
|
|
89
|
+
if (x.kind === "question") {
|
|
90
|
+
const q = obj(x.question);
|
|
91
|
+
const answer = q.answer ? obj(q.answer) : null;
|
|
92
|
+
return {
|
|
93
|
+
...base,
|
|
94
|
+
id: String(q.id ?? ""),
|
|
95
|
+
type: "question",
|
|
96
|
+
text: clip(q.question, 500),
|
|
97
|
+
status: str(q.status),
|
|
98
|
+
answer: answer ? clip(
|
|
99
|
+
[answer.option_label ?? answer.option_id, answer.text].filter(Boolean).join(" / "),
|
|
100
|
+
200
|
|
101
|
+
) || null : null,
|
|
102
|
+
sender: str(q.agent_id) ? `agent:${String(q.agent_id)}` : null,
|
|
103
|
+
createdAt: str(q.created_at)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const m = obj(x.message);
|
|
107
|
+
const sender = obj(m.sender);
|
|
108
|
+
const senderId = sender.agent_id ?? sender.user_id ?? sender.slack_user_id;
|
|
109
|
+
return {
|
|
110
|
+
...base,
|
|
111
|
+
id: String(m.id ?? ""),
|
|
112
|
+
type: String(m.type ?? "message"),
|
|
113
|
+
text: clip(m.text, 500),
|
|
114
|
+
status: str(m.task_status),
|
|
115
|
+
answer: null,
|
|
116
|
+
sender: sender.kind ? `${String(sender.kind)}${senderId ? `:${String(senderId)}` : ""}` : null,
|
|
117
|
+
createdAt: str(m.created_at)
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
const window = obj(r.window);
|
|
121
|
+
return {
|
|
122
|
+
results,
|
|
123
|
+
nextCursor: str(r.next_cursor),
|
|
124
|
+
window: { from: String(window.from ?? ""), days: num(window.days) }
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function summarizeGraph(r, top2) {
|
|
128
|
+
const range2 = rangeSummary(r.range);
|
|
129
|
+
const nodes = arr(r.nodes);
|
|
130
|
+
const labels = new Map(nodes.map((n) => [String(n.id), String(n.label)]));
|
|
131
|
+
const topNodes = [...nodes].sort(
|
|
132
|
+
(a, b) => num(b.sent) + num(b.received) - (num(a.sent) + num(a.received))
|
|
133
|
+
).slice(0, top2).map((n) => ({
|
|
134
|
+
id: String(n.id),
|
|
135
|
+
kind: String(n.kind),
|
|
136
|
+
label: String(n.label),
|
|
137
|
+
slug: str(n.slug),
|
|
138
|
+
sent: num(n.sent),
|
|
139
|
+
received: num(n.received),
|
|
140
|
+
tokens: num(n.tokens),
|
|
141
|
+
cost: money(n.cost)
|
|
142
|
+
}));
|
|
143
|
+
const edges = arr(r.edges);
|
|
144
|
+
const topEdges = [...edges].sort((a, b) => num(b.messages) - num(a.messages)).slice(0, top2).map((e) => {
|
|
145
|
+
const l = latency(e.reply_latency);
|
|
146
|
+
return {
|
|
147
|
+
source: String(e.source),
|
|
148
|
+
target: String(e.target),
|
|
149
|
+
from: labels.get(String(e.source)) ?? String(e.source),
|
|
150
|
+
to: labels.get(String(e.target)) ?? String(e.target),
|
|
151
|
+
messages: num(e.messages),
|
|
152
|
+
replies: num(e.replies),
|
|
153
|
+
cost: money(e.cost),
|
|
154
|
+
replyAvgMs: l.avgMs,
|
|
155
|
+
replyP90Ms: l.p90Ms,
|
|
156
|
+
lastAt: str(e.last_at)
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
const totals = obj(r.totals);
|
|
160
|
+
const truncated = obj(r.truncated);
|
|
161
|
+
const t = {
|
|
162
|
+
nodes: num(totals.nodes),
|
|
163
|
+
edges: num(totals.edges),
|
|
164
|
+
messages: num(totals.messages),
|
|
165
|
+
tokens: num(totals.tokens),
|
|
166
|
+
cost: money(totals.cost)
|
|
167
|
+
};
|
|
168
|
+
const busiest = topEdges[0];
|
|
169
|
+
return {
|
|
170
|
+
range: range2,
|
|
171
|
+
totals: t,
|
|
172
|
+
topNodes,
|
|
173
|
+
topEdges,
|
|
174
|
+
/** Not shown here: beyond `top`, or folded / dropped by the API's cap. */
|
|
175
|
+
omitted: {
|
|
176
|
+
nodes: Math.max(0, nodes.length - topNodes.length),
|
|
177
|
+
edges: Math.max(0, edges.length - topEdges.length),
|
|
178
|
+
cappedNodes: num(truncated.nodes),
|
|
179
|
+
cappedEdges: num(truncated.edges)
|
|
180
|
+
},
|
|
181
|
+
summary: range2.empty ? `No visible activity in ${rangeNote(range2)}.` : `${t.nodes} participants, ${t.edges} edges, ${t.messages} messages, cost ${fmtMoney(t.cost)} over ${rangeNote(range2)}.` + (busiest ? ` Busiest edge: ${busiest.from} \u2192 ${busiest.to} (${busiest.messages} messages, reply avg ${fmtMs(busiest.replyAvgMs)}).` : "")
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function summarizeCost(r, top2) {
|
|
185
|
+
const range2 = rangeSummary(r.range);
|
|
186
|
+
const totals = obj(r.totals);
|
|
187
|
+
const t = {
|
|
188
|
+
messages: num(totals.messages),
|
|
189
|
+
pricedMessages: num(totals.priced_messages),
|
|
190
|
+
tokens: num(totals.tokens),
|
|
191
|
+
cost: money(totals.cost)
|
|
192
|
+
};
|
|
193
|
+
const all = arr(r.groups);
|
|
194
|
+
const groups = all.slice(0, top2).map((g) => ({
|
|
195
|
+
key: String(g.key),
|
|
196
|
+
label: clip(g.label, 120),
|
|
197
|
+
messages: num(g.messages),
|
|
198
|
+
tokens: num(g.tokens),
|
|
199
|
+
cost: money(g.cost),
|
|
200
|
+
share: g.share === null || g.share === void 0 ? null : num(g.share)
|
|
201
|
+
}));
|
|
202
|
+
const active = arr(r.series).filter(
|
|
203
|
+
(d) => num(d.messages) > 0 || num(d.cost) > 0
|
|
204
|
+
);
|
|
205
|
+
const daily = active.slice(-31).map((d) => ({
|
|
206
|
+
day: String(d.day),
|
|
207
|
+
messages: num(d.messages),
|
|
208
|
+
tokens: num(d.tokens),
|
|
209
|
+
cost: money(d.cost)
|
|
210
|
+
}));
|
|
211
|
+
const peak = active.reduce(
|
|
212
|
+
(best, d) => !best || num(d.cost) > num(best.cost) ? d : best,
|
|
213
|
+
null
|
|
214
|
+
);
|
|
215
|
+
const groupBy = String(r.group_by ?? "agent");
|
|
216
|
+
const head = groups.slice(0, 3).map((g) => `${g.label} ${fmtMoney(g.cost)} (${pct(g.share)})`).join(", ");
|
|
217
|
+
return {
|
|
218
|
+
range: range2,
|
|
219
|
+
groupBy,
|
|
220
|
+
totals: t,
|
|
221
|
+
groups,
|
|
222
|
+
omittedGroups: Math.max(0, all.length - groups.length),
|
|
223
|
+
/** The API had more groups than it returned. */
|
|
224
|
+
truncated: Boolean(r.truncated),
|
|
225
|
+
daily,
|
|
226
|
+
peakDay: peak ? { day: String(peak.day), cost: money(peak.cost) } : null,
|
|
227
|
+
summary: range2.empty ? `No visible activity in ${rangeNote(range2)}.` : `Total cost ${fmtMoney(t.cost)} (as reported by agents), ${t.tokens} tokens, ${t.messages} messages (${t.pricedMessages} priced) over ${rangeNote(range2)}.` + (head ? ` Top by ${groupBy}: ${head}.` : "")
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function pair(v) {
|
|
231
|
+
const p = obj(v);
|
|
232
|
+
const l = latency(p.latency);
|
|
233
|
+
return {
|
|
234
|
+
messages: num(p.messages),
|
|
235
|
+
replied: num(p.replied),
|
|
236
|
+
replyRate: p.reply_rate === null || p.reply_rate === void 0 ? null : num(p.reply_rate),
|
|
237
|
+
avgMs: l.avgMs,
|
|
238
|
+
p50Ms: l.p50Ms,
|
|
239
|
+
p90Ms: l.p90Ms
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function summarizeMetrics(r, top2) {
|
|
243
|
+
const range2 = rangeSummary(r.range);
|
|
244
|
+
const replies = obj(r.replies);
|
|
245
|
+
const q = obj(r.questions);
|
|
246
|
+
const qLatency = latency(q.time_to_human_answer);
|
|
247
|
+
const byUrgency = obj(q.by_urgency);
|
|
248
|
+
const d = obj(r.deliveries);
|
|
249
|
+
const byMode = obj(d.by_mode);
|
|
250
|
+
const backlog = obj(r.backlog);
|
|
251
|
+
const rate = (v) => v === null || v === void 0 ? null : num(v);
|
|
252
|
+
const out = {
|
|
253
|
+
range: range2,
|
|
254
|
+
replies: {
|
|
255
|
+
agentToAgent: pair(replies.agent_to_agent),
|
|
256
|
+
humanToAgent: pair(replies.human_to_agent),
|
|
257
|
+
agentToHuman: pair(replies.agent_to_human),
|
|
258
|
+
byAgent: arr(replies.by_agent).slice(0, top2).map((a) => {
|
|
259
|
+
const l = latency(a.latency);
|
|
260
|
+
return {
|
|
261
|
+
agentId: String(a.agent_id),
|
|
262
|
+
name: str(a.name),
|
|
263
|
+
messages: num(a.messages),
|
|
264
|
+
replied: num(a.replied),
|
|
265
|
+
avgMs: l.avgMs,
|
|
266
|
+
p90Ms: l.p90Ms
|
|
267
|
+
};
|
|
268
|
+
})
|
|
269
|
+
},
|
|
270
|
+
questions: {
|
|
271
|
+
asked: num(q.asked),
|
|
272
|
+
answered: num(q.answered),
|
|
273
|
+
answeredByUser: num(q.answered_by_user),
|
|
274
|
+
answeredByAgent: num(q.answered_by_agent),
|
|
275
|
+
expired: num(q.expired),
|
|
276
|
+
expiredDefault: num(q.expired_default),
|
|
277
|
+
canceled: num(q.canceled),
|
|
278
|
+
answerRate: rate(q.answer_rate),
|
|
279
|
+
timeToHumanAnswer: {
|
|
280
|
+
count: qLatency.count,
|
|
281
|
+
avgMs: qLatency.avgMs,
|
|
282
|
+
p50Ms: qLatency.p50Ms,
|
|
283
|
+
p90Ms: qLatency.p90Ms
|
|
284
|
+
},
|
|
285
|
+
byUrgency: Object.fromEntries(
|
|
286
|
+
["low", "normal", "high", "urgent"].map((u) => {
|
|
287
|
+
const b = obj(byUrgency[u]);
|
|
288
|
+
return [
|
|
289
|
+
u,
|
|
290
|
+
{
|
|
291
|
+
asked: num(b.asked),
|
|
292
|
+
answerRate: rate(b.answer_rate),
|
|
293
|
+
p50Ms: latency(b.time_to_human_answer).p50Ms
|
|
294
|
+
}
|
|
295
|
+
];
|
|
296
|
+
})
|
|
297
|
+
)
|
|
298
|
+
},
|
|
299
|
+
deliveries: {
|
|
300
|
+
deliveries: num(d.deliveries),
|
|
301
|
+
failed: num(d.failed),
|
|
302
|
+
retried: num(d.retried),
|
|
303
|
+
failureRate: rate(d.failure_rate),
|
|
304
|
+
retryRate: rate(d.retry_rate),
|
|
305
|
+
byMode: Object.fromEntries(
|
|
306
|
+
["webhook", "inbox", "a2a"].map((m) => {
|
|
307
|
+
const b = obj(byMode[m]);
|
|
308
|
+
return [
|
|
309
|
+
m,
|
|
310
|
+
{
|
|
311
|
+
deliveries: num(b.deliveries),
|
|
312
|
+
failed: num(b.failed),
|
|
313
|
+
held: num(b.held),
|
|
314
|
+
failureRate: rate(b.failure_rate),
|
|
315
|
+
retryRate: rate(b.retry_rate)
|
|
316
|
+
}
|
|
317
|
+
];
|
|
318
|
+
})
|
|
319
|
+
)
|
|
320
|
+
},
|
|
321
|
+
backlog: {
|
|
322
|
+
asOf: String(backlog.as_of ?? ""),
|
|
323
|
+
unacked: num(backlog.unacked),
|
|
324
|
+
held: num(backlog.held),
|
|
325
|
+
agentsWithBacklog: num(backlog.agents_with_backlog),
|
|
326
|
+
agents: arr(backlog.agents).slice(0, top2).map((a) => ({
|
|
327
|
+
agentId: String(a.agent_id),
|
|
328
|
+
name: str(a.name),
|
|
329
|
+
delivery: str(a.delivery),
|
|
330
|
+
unacked: num(a.unacked),
|
|
331
|
+
held: num(a.held),
|
|
332
|
+
oldestAgeSeconds: a.oldest_age_seconds === null || a.oldest_age_seconds === void 0 ? null : num(a.oldest_age_seconds)
|
|
333
|
+
}))
|
|
334
|
+
},
|
|
335
|
+
summary: ""
|
|
336
|
+
};
|
|
337
|
+
const h2a = out.replies.humanToAgent;
|
|
338
|
+
const a2a = out.replies.agentToAgent;
|
|
339
|
+
out.summary = `Over ${rangeNote(range2)}: agents answered people in avg ${fmtMs(h2a.avgMs)} (p90 ${fmtMs(h2a.p90Ms)}, ${pct(h2a.replyRate)} replied) and other agents in avg ${fmtMs(a2a.avgMs)} (p90 ${fmtMs(a2a.p90Ms)}). Questions: ${out.questions.asked} asked, ${pct(out.questions.answerRate)} answered, human answer p50 ${fmtMs(out.questions.timeToHumanAnswer.p50Ms)}. Deliveries: ${out.deliveries.deliveries}, ${pct(out.deliveries.failureRate)} failed, ${pct(out.deliveries.retryRate)} retried. Backlog now: ${out.backlog.unacked} unacked, ${out.backlog.held} held.`;
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/agents.ts
|
|
344
|
+
function defineTool(tool) {
|
|
345
|
+
return tool;
|
|
346
|
+
}
|
|
347
|
+
var AGENT_TASK_STATUSES = [
|
|
348
|
+
"open",
|
|
349
|
+
"working",
|
|
350
|
+
"input_required",
|
|
351
|
+
"completed",
|
|
352
|
+
"failed",
|
|
353
|
+
"canceled",
|
|
354
|
+
"rejected"
|
|
355
|
+
];
|
|
356
|
+
var uuid = (what) => z.string().uuid().describe(what);
|
|
357
|
+
var agentId = uuid(
|
|
358
|
+
"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."
|
|
359
|
+
).optional();
|
|
360
|
+
var channelId = uuid("Agent channel ID (from list_agent_channels)");
|
|
361
|
+
var threadId = uuid(
|
|
362
|
+
"Reply in this thread: the id of any message in it (thread_id or id from read_agent_inbox)"
|
|
363
|
+
).optional();
|
|
364
|
+
var mentions = z.array(z.string().uuid()).max(50).optional().describe("Agent IDs to mention (from list_agents)");
|
|
365
|
+
var data = z.record(z.string(), z.unknown()).optional().describe("Structured data for the recipients (JSON object)");
|
|
366
|
+
var usage = {
|
|
367
|
+
tokens: z.number().int().min(0).optional().describe("Tokens you used for this message (reporting)"),
|
|
368
|
+
cost: z.number().min(0).optional().describe("What this message cost you, in USD (reporting)")
|
|
369
|
+
};
|
|
370
|
+
var message = z.looseObject({
|
|
371
|
+
id: z.string(),
|
|
372
|
+
channel_id: z.string(),
|
|
373
|
+
thread_id: z.string().nullable(),
|
|
374
|
+
type: z.string(),
|
|
375
|
+
text: z.string(),
|
|
376
|
+
sender: z.looseObject({ kind: z.string() }),
|
|
377
|
+
task_status: z.string().nullable().optional()
|
|
378
|
+
});
|
|
379
|
+
var sendOutput = z.object({
|
|
380
|
+
message,
|
|
381
|
+
deliveries: z.array(
|
|
382
|
+
z.looseObject({ id: z.string(), agent_id: z.string(), status: z.string() })
|
|
383
|
+
)
|
|
384
|
+
});
|
|
385
|
+
var dueAt = z.string().max(40).optional().describe("Due date: an ISO date (2026-11-30) or date-time");
|
|
386
|
+
var task = z.looseObject({
|
|
387
|
+
id: z.string(),
|
|
388
|
+
channel_id: z.string(),
|
|
389
|
+
text: z.string(),
|
|
390
|
+
board_status: z.string(),
|
|
391
|
+
assignee_agent_id: z.string().nullable(),
|
|
392
|
+
due_at: z.string().nullable()
|
|
393
|
+
});
|
|
394
|
+
var deliveries = z.array(
|
|
395
|
+
z.looseObject({ id: z.string(), agent_id: z.string(), status: z.string() })
|
|
396
|
+
);
|
|
397
|
+
var question = z.looseObject({
|
|
398
|
+
id: z.string(),
|
|
399
|
+
kind: z.string(),
|
|
400
|
+
question: z.string(),
|
|
401
|
+
status: z.string(),
|
|
402
|
+
answer: z.looseObject({}).nullable()
|
|
403
|
+
});
|
|
404
|
+
var questionId = uuid("The question ID (from ask_human or list_questions)");
|
|
405
|
+
var BOARD_STATUSES = [
|
|
406
|
+
"open",
|
|
407
|
+
"in_progress",
|
|
408
|
+
"blocked",
|
|
409
|
+
"done",
|
|
410
|
+
"failed"
|
|
411
|
+
];
|
|
412
|
+
var QUESTION_WAIT_MAX_SECONDS = 25;
|
|
413
|
+
var READ = {
|
|
414
|
+
readOnlyHint: true,
|
|
415
|
+
destructiveHint: false,
|
|
416
|
+
idempotentHint: true,
|
|
417
|
+
openWorldHint: false
|
|
418
|
+
};
|
|
419
|
+
var SEND = {
|
|
420
|
+
readOnlyHint: false,
|
|
421
|
+
destructiveHint: false,
|
|
422
|
+
idempotentHint: false,
|
|
423
|
+
openWorldHint: true
|
|
424
|
+
};
|
|
425
|
+
function actingAs(api, id) {
|
|
426
|
+
return id ?? api.agentId;
|
|
427
|
+
}
|
|
428
|
+
function requireAgent(api, id) {
|
|
429
|
+
const agent = actingAs(api, id);
|
|
430
|
+
if (!agent) {
|
|
431
|
+
throw new ToolError(
|
|
432
|
+
"Pass agentId (from list_agents), or set CHANNLIZE_AGENT_ID / --agent-id on the MCP server."
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
return agent;
|
|
436
|
+
}
|
|
437
|
+
async function send(api, body) {
|
|
438
|
+
const r = await api.request(
|
|
439
|
+
"POST",
|
|
440
|
+
"/v1/agents/messages",
|
|
441
|
+
{ body }
|
|
442
|
+
);
|
|
443
|
+
return { message: r.message, deliveries: r.deliveries ?? [] };
|
|
444
|
+
}
|
|
445
|
+
var enc = encodeURIComponent;
|
|
446
|
+
function outcomeMessage(status, q) {
|
|
447
|
+
const answer = q.answer ?? {};
|
|
448
|
+
const choice = answer.option_label ?? answer.option_id;
|
|
449
|
+
const comment = answer.comment ? `: ${String(answer.comment)}` : "";
|
|
450
|
+
switch (status) {
|
|
451
|
+
case "answered":
|
|
452
|
+
if (q.kind === "approval") {
|
|
453
|
+
return answer.approved ? `Approved${comment}. Go ahead.` : `Denied${comment}. Don't do it.`;
|
|
454
|
+
}
|
|
455
|
+
return `Answered: ${[choice, answer.text].filter(Boolean).join(" / ") || "(empty)"}.`;
|
|
456
|
+
case "expired_default":
|
|
457
|
+
return `Nobody answered by the deadline: the default option applies (${String(choice ?? "none")}).`;
|
|
458
|
+
case "expired":
|
|
459
|
+
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.";
|
|
460
|
+
case "canceled":
|
|
461
|
+
return "The question was canceled.";
|
|
462
|
+
default:
|
|
463
|
+
return `Status: ${status}.`;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
var AGENT_MESSAGE_TYPES = [
|
|
467
|
+
"message",
|
|
468
|
+
"task",
|
|
469
|
+
"question",
|
|
470
|
+
"escalation",
|
|
471
|
+
"status"
|
|
472
|
+
];
|
|
473
|
+
var insightsDay = (what) => z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "expected a YYYY-MM-DD date").optional().describe(what);
|
|
474
|
+
var insightsRange = {
|
|
475
|
+
from: insightsDay(
|
|
476
|
+
"First UTC day, YYYY-MM-DD (default: 30 days before to). Clamped to the plan history window."
|
|
477
|
+
),
|
|
478
|
+
to: insightsDay("Last UTC day, inclusive, YYYY-MM-DD (default: today)"),
|
|
479
|
+
channelId: channelId.optional().describe("Only this agent channel")
|
|
480
|
+
};
|
|
481
|
+
var insightsAgent = uuid(
|
|
482
|
+
"Only this agent (from list_agents): pass your own id to see your own numbers"
|
|
483
|
+
).optional();
|
|
484
|
+
var mine = z.boolean().optional().describe(
|
|
485
|
+
"true: only your own agent (the server's default agent, CHANNLIZE_AGENT_ID), when you don't know your id"
|
|
486
|
+
);
|
|
487
|
+
var top = (dflt) => z.number().int().min(1).max(50).default(dflt).describe(`How many rows to return in each list (1-50, default ${dflt})`);
|
|
488
|
+
function filterAgent(api, a) {
|
|
489
|
+
if (a.agentId) return a.agentId;
|
|
490
|
+
return a.mine ? requireAgent(api, void 0) : void 0;
|
|
491
|
+
}
|
|
492
|
+
var range = z.looseObject({
|
|
493
|
+
from: z.string(),
|
|
494
|
+
to: z.string(),
|
|
495
|
+
days: z.number(),
|
|
496
|
+
clamped: z.boolean(),
|
|
497
|
+
empty: z.boolean()
|
|
498
|
+
});
|
|
499
|
+
var nullableNumber = z.number().nullable();
|
|
500
|
+
var AGENT_TOOLS = [
|
|
501
|
+
defineTool({
|
|
502
|
+
name: "send_agent_message",
|
|
503
|
+
title: "Send agent message",
|
|
504
|
+
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.",
|
|
505
|
+
scope: "agents:send",
|
|
506
|
+
endpoint: "POST /v1/agents/messages",
|
|
507
|
+
inputSchema: z.object({
|
|
508
|
+
agentId,
|
|
509
|
+
channelId,
|
|
510
|
+
text: z.string().min(1).max(4e4).describe("Message text"),
|
|
511
|
+
threadId,
|
|
512
|
+
mentions,
|
|
513
|
+
data,
|
|
514
|
+
...usage
|
|
515
|
+
}),
|
|
516
|
+
outputSchema: sendOutput,
|
|
517
|
+
annotations: SEND,
|
|
518
|
+
handler: (api, a) => send(api, {
|
|
519
|
+
agent_id: actingAs(api, a.agentId),
|
|
520
|
+
channel_id: a.channelId,
|
|
521
|
+
type: "message",
|
|
522
|
+
text: a.text,
|
|
523
|
+
thread_id: a.threadId,
|
|
524
|
+
mentions: a.mentions,
|
|
525
|
+
data: a.data,
|
|
526
|
+
tokens: a.tokens,
|
|
527
|
+
cost: a.cost
|
|
528
|
+
})
|
|
529
|
+
}),
|
|
530
|
+
defineTool({
|
|
531
|
+
name: "create_task",
|
|
532
|
+
title: "Create task",
|
|
533
|
+
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.",
|
|
534
|
+
scope: "agents:send",
|
|
535
|
+
endpoint: "POST /v1/agents/tasks",
|
|
536
|
+
inputSchema: z.object({
|
|
537
|
+
agentId,
|
|
538
|
+
channelId,
|
|
539
|
+
text: z.string().min(1).max(4e4).describe("What should be done, with enough context to do it"),
|
|
540
|
+
assigneeAgentId: uuid(
|
|
541
|
+
"The agent that should do it: a member of the channel (from list_agents)"
|
|
542
|
+
).optional(),
|
|
543
|
+
dueAt,
|
|
544
|
+
threadId,
|
|
545
|
+
mentions,
|
|
546
|
+
data
|
|
547
|
+
}),
|
|
548
|
+
// `message` is the task too (a task is its `task` message plus board fields).
|
|
549
|
+
outputSchema: z.object({ taskId: z.string(), task, message, deliveries }),
|
|
550
|
+
annotations: SEND,
|
|
551
|
+
handler: async (api, a) => {
|
|
552
|
+
const r = await api.request(
|
|
553
|
+
"POST",
|
|
554
|
+
"/v1/agents/tasks",
|
|
555
|
+
{
|
|
556
|
+
body: {
|
|
557
|
+
agent_id: actingAs(api, a.agentId),
|
|
558
|
+
channel_id: a.channelId,
|
|
559
|
+
text: a.text,
|
|
560
|
+
assignee_agent_id: a.assigneeAgentId,
|
|
561
|
+
due_at: a.dueAt,
|
|
562
|
+
thread_id: a.threadId,
|
|
563
|
+
mentions: a.mentions,
|
|
564
|
+
data: a.data
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
);
|
|
568
|
+
return {
|
|
569
|
+
taskId: String(r.task.id),
|
|
570
|
+
task: r.task,
|
|
571
|
+
message: r.task,
|
|
572
|
+
deliveries: r.deliveries ?? []
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
}),
|
|
576
|
+
defineTool({
|
|
577
|
+
name: "update_task_status",
|
|
578
|
+
title: "Update task status",
|
|
579
|
+
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.",
|
|
580
|
+
scope: "agents:send",
|
|
581
|
+
endpoint: "POST /v1/agents/messages",
|
|
582
|
+
inputSchema: z.object({
|
|
583
|
+
agentId,
|
|
584
|
+
channelId,
|
|
585
|
+
taskId: uuid("The task message ID"),
|
|
586
|
+
status: z.enum(AGENT_TASK_STATUSES).describe("The new status of the task"),
|
|
587
|
+
text: z.string().max(4e4).optional().describe("What changed, e.g. the result or what input is needed"),
|
|
588
|
+
data,
|
|
589
|
+
...usage
|
|
590
|
+
}),
|
|
591
|
+
outputSchema: sendOutput,
|
|
592
|
+
annotations: SEND,
|
|
593
|
+
handler: (api, a) => send(api, {
|
|
594
|
+
agent_id: actingAs(api, a.agentId),
|
|
595
|
+
channel_id: a.channelId,
|
|
596
|
+
type: "status",
|
|
597
|
+
text: a.text ?? "",
|
|
598
|
+
task_id: a.taskId,
|
|
599
|
+
task_status: a.status,
|
|
600
|
+
data: a.data,
|
|
601
|
+
tokens: a.tokens,
|
|
602
|
+
cost: a.cost
|
|
603
|
+
})
|
|
604
|
+
}),
|
|
605
|
+
defineTool({
|
|
606
|
+
name: "update_task",
|
|
607
|
+
title: "Update task",
|
|
608
|
+
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.",
|
|
609
|
+
scope: "agents:send",
|
|
610
|
+
endpoint: "PATCH /v1/agents/tasks/:taskId",
|
|
611
|
+
inputSchema: z.object({
|
|
612
|
+
agentId,
|
|
613
|
+
taskId: uuid("The task ID"),
|
|
614
|
+
status: z.enum(BOARD_STATUSES).optional().describe("The board column"),
|
|
615
|
+
dueAt: z.string().max(40).nullable().optional().describe("New due date (ISO date or date-time); null clears it"),
|
|
616
|
+
note: z.string().max(2e3).optional().describe("What changed, shown with the update")
|
|
617
|
+
}),
|
|
618
|
+
outputSchema: z.object({ task, changed: z.boolean() }),
|
|
619
|
+
annotations: SEND,
|
|
620
|
+
handler: async (api, a) => {
|
|
621
|
+
if (a.status === void 0 && a.dueAt === void 0) {
|
|
622
|
+
throw new ToolError("Pass status or dueAt.");
|
|
623
|
+
}
|
|
624
|
+
const r = await api.request(
|
|
625
|
+
"PATCH",
|
|
626
|
+
`/v1/agents/tasks/${enc(a.taskId)}`,
|
|
627
|
+
{
|
|
628
|
+
body: {
|
|
629
|
+
agent_id: actingAs(api, a.agentId),
|
|
630
|
+
status: a.status,
|
|
631
|
+
due_at: a.dueAt,
|
|
632
|
+
note: a.note
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
);
|
|
636
|
+
return { task: r.task, changed: Boolean(r.changed) };
|
|
637
|
+
}
|
|
638
|
+
}),
|
|
639
|
+
defineTool({
|
|
640
|
+
name: "handoff_task",
|
|
641
|
+
title: "Hand off task",
|
|
642
|
+
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.",
|
|
643
|
+
scope: "agents:send",
|
|
644
|
+
endpoint: "POST /v1/agents/tasks/:taskId/handoff",
|
|
645
|
+
inputSchema: z.object({
|
|
646
|
+
agentId,
|
|
647
|
+
taskId: uuid("The task ID"),
|
|
648
|
+
toAgentId: uuid("The new assignee (from list_agents or get_org_chart)"),
|
|
649
|
+
reason: z.string().max(2e3).optional().describe("Why, and what the new assignee needs to know")
|
|
650
|
+
}),
|
|
651
|
+
outputSchema: z.object({ task, deliveries }),
|
|
652
|
+
annotations: SEND,
|
|
653
|
+
handler: async (api, a) => {
|
|
654
|
+
const r = await api.request(
|
|
655
|
+
"POST",
|
|
656
|
+
`/v1/agents/tasks/${enc(a.taskId)}/handoff`,
|
|
657
|
+
{
|
|
658
|
+
body: {
|
|
659
|
+
agent_id: actingAs(api, a.agentId),
|
|
660
|
+
to_agent_id: a.toAgentId,
|
|
661
|
+
reason: a.reason
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
);
|
|
665
|
+
return {
|
|
666
|
+
task: r.task,
|
|
667
|
+
deliveries: r.deliveries ?? []
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
}),
|
|
671
|
+
defineTool({
|
|
672
|
+
name: "list_tasks",
|
|
673
|
+
title: "List tasks",
|
|
674
|
+
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.",
|
|
675
|
+
scope: "agents:read",
|
|
676
|
+
endpoint: "GET /v1/agents/tasks",
|
|
677
|
+
inputSchema: z.object({
|
|
678
|
+
agentId,
|
|
679
|
+
channelId: channelId.optional(),
|
|
680
|
+
assigneeAgentId: uuid("Only tasks assigned to this agent").optional(),
|
|
681
|
+
status: z.enum(BOARD_STATUSES).optional(),
|
|
682
|
+
limit: z.number().int().min(1).max(500).default(50).describe("How many to return (1-500, default 50)")
|
|
683
|
+
}),
|
|
684
|
+
outputSchema: z.object({ tasks: z.array(task) }),
|
|
685
|
+
annotations: READ,
|
|
686
|
+
handler: async (api, a) => {
|
|
687
|
+
const r = await api.request(
|
|
688
|
+
"GET",
|
|
689
|
+
"/v1/agents/tasks",
|
|
690
|
+
{
|
|
691
|
+
query: {
|
|
692
|
+
agent_id: actingAs(api, a.agentId),
|
|
693
|
+
channel_id: a.channelId,
|
|
694
|
+
assignee_agent_id: a.assigneeAgentId,
|
|
695
|
+
status: a.status,
|
|
696
|
+
limit: a.limit
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
);
|
|
700
|
+
return { tasks: r.tasks ?? [] };
|
|
701
|
+
}
|
|
702
|
+
}),
|
|
703
|
+
defineTool({
|
|
704
|
+
name: "get_task_board",
|
|
705
|
+
title: "Get task board",
|
|
706
|
+
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.",
|
|
707
|
+
scope: "agents:read",
|
|
708
|
+
endpoint: "GET /v1/agents/tasks/board",
|
|
709
|
+
inputSchema: z.object({
|
|
710
|
+
agentId,
|
|
711
|
+
channelId,
|
|
712
|
+
assigneeAgentId: uuid("Only tasks assigned to this agent").optional()
|
|
713
|
+
}),
|
|
714
|
+
outputSchema: z.object({
|
|
715
|
+
channel_id: z.string(),
|
|
716
|
+
columns: z.record(z.string(), z.array(task)),
|
|
717
|
+
counts: z.record(z.string(), z.number()),
|
|
718
|
+
agents: z.array(z.looseObject({ id: z.string() })),
|
|
719
|
+
truncated: z.boolean()
|
|
720
|
+
}),
|
|
721
|
+
annotations: READ,
|
|
722
|
+
handler: async (api, a) => await api.request("GET", "/v1/agents/tasks/board", {
|
|
723
|
+
query: {
|
|
724
|
+
agent_id: actingAs(api, a.agentId),
|
|
725
|
+
channel_id: a.channelId,
|
|
726
|
+
assignee_agent_id: a.assigneeAgentId
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
}),
|
|
730
|
+
defineTool({
|
|
731
|
+
name: "ask_human",
|
|
732
|
+
title: "Ask a human",
|
|
733
|
+
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.",
|
|
734
|
+
scope: "agents:ask_human",
|
|
735
|
+
endpoint: "POST /v1/agents/questions",
|
|
736
|
+
inputSchema: z.object({
|
|
737
|
+
agentId,
|
|
738
|
+
kind: z.enum(["question", "approval"]).default("question").describe("question (default) or approval (answered Approve / Deny)"),
|
|
739
|
+
question: z.string().min(1).max(3e3).describe("The question, with what people need to answer it"),
|
|
740
|
+
options: z.array(
|
|
741
|
+
z.object({
|
|
742
|
+
id: z.string().min(1).max(100),
|
|
743
|
+
label: z.string().min(1).max(75)
|
|
744
|
+
})
|
|
745
|
+
).max(10).optional().describe("Up to 10 answers to pick from (ignored for approvals)"),
|
|
746
|
+
freeText: z.boolean().optional().describe("Allow a typed answer (always on without options)"),
|
|
747
|
+
urgency: z.enum(["low", "normal", "high", "urgent"]).optional().describe("How fast it escalates (default normal)"),
|
|
748
|
+
deadline: z.string().max(40).optional().describe("ISO date-time, at most 30 days away"),
|
|
749
|
+
defaultOption: z.string().max(100).optional().describe("Option id applied at the deadline when nobody answered"),
|
|
750
|
+
channelId: channelId.optional().describe("Post it in this agent channel (from list_agent_channels)"),
|
|
751
|
+
threadId,
|
|
752
|
+
context: z.record(z.string(), z.unknown()).optional().describe("Facts shown with the question (JSON object)"),
|
|
753
|
+
amount: z.number().min(0).optional().describe("Approvals: the amount at stake"),
|
|
754
|
+
currency: z.string().regex(/^[A-Za-z]{3}$/).optional().describe("Approvals: ISO 4217 currency code"),
|
|
755
|
+
resource: z.record(z.string(), z.unknown()).optional().describe("Approvals: what is being approved (JSON object)"),
|
|
756
|
+
requiredRoles: z.array(z.string().min(1).max(40)).max(10).optional().describe('Approvals: roles that may answer, e.g. ["admin"]')
|
|
757
|
+
}),
|
|
758
|
+
outputSchema: z.object({ questionId: z.string(), question }),
|
|
759
|
+
annotations: SEND,
|
|
760
|
+
handler: async (api, a) => {
|
|
761
|
+
const r = await api.request(
|
|
762
|
+
"POST",
|
|
763
|
+
"/v1/agents/questions",
|
|
764
|
+
{
|
|
765
|
+
body: {
|
|
766
|
+
agent_id: actingAs(api, a.agentId),
|
|
767
|
+
kind: a.kind,
|
|
768
|
+
question: a.question,
|
|
769
|
+
options: a.options,
|
|
770
|
+
free_text: a.freeText,
|
|
771
|
+
urgency: a.urgency,
|
|
772
|
+
deadline: a.deadline,
|
|
773
|
+
default_option: a.defaultOption,
|
|
774
|
+
channel_id: a.channelId,
|
|
775
|
+
thread_id: a.threadId,
|
|
776
|
+
context: a.context,
|
|
777
|
+
amount: a.amount,
|
|
778
|
+
currency: a.currency,
|
|
779
|
+
resource: a.resource,
|
|
780
|
+
required_roles: a.requiredRoles
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
);
|
|
784
|
+
return {
|
|
785
|
+
questionId: String(r.question.id),
|
|
786
|
+
question: r.question
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
}),
|
|
790
|
+
defineTool({
|
|
791
|
+
name: "get_answer",
|
|
792
|
+
title: "Get answer",
|
|
793
|
+
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).`,
|
|
794
|
+
scope: "agents:ask_human",
|
|
795
|
+
endpoint: "GET /v1/agents/questions/:id/wait",
|
|
796
|
+
inputSchema: z.object({
|
|
797
|
+
agentId,
|
|
798
|
+
questionId,
|
|
799
|
+
waitSeconds: z.number().int().min(0).max(QUESTION_WAIT_MAX_SECONDS).default(QUESTION_WAIT_MAX_SECONDS).describe(
|
|
800
|
+
`Seconds to wait for an answer (0-${QUESTION_WAIT_MAX_SECONDS}, default ${QUESTION_WAIT_MAX_SECONDS}); 0 only checks`
|
|
801
|
+
)
|
|
802
|
+
}),
|
|
803
|
+
outputSchema: z.object({
|
|
804
|
+
questionId: z.string(),
|
|
805
|
+
status: z.string(),
|
|
806
|
+
waiting: z.boolean(),
|
|
807
|
+
answer: z.looseObject({}).nullable(),
|
|
808
|
+
message: z.string(),
|
|
809
|
+
question
|
|
810
|
+
}),
|
|
811
|
+
annotations: READ,
|
|
812
|
+
handler: async (api, a) => {
|
|
813
|
+
const r = await api.request(
|
|
814
|
+
"GET",
|
|
815
|
+
`/v1/agents/questions/${enc(a.questionId)}/wait`,
|
|
816
|
+
{
|
|
817
|
+
query: {
|
|
818
|
+
agent_id: actingAs(api, a.agentId),
|
|
819
|
+
timeout: a.waitSeconds
|
|
820
|
+
},
|
|
821
|
+
// The API holds the request for up to waitSeconds.
|
|
822
|
+
timeout: (a.waitSeconds + 10) * 1e3
|
|
823
|
+
}
|
|
824
|
+
);
|
|
825
|
+
const status = String(r.question.status);
|
|
826
|
+
const waiting = status === "open";
|
|
827
|
+
return {
|
|
828
|
+
questionId: a.questionId,
|
|
829
|
+
status,
|
|
830
|
+
waiting,
|
|
831
|
+
answer: r.question.answer ?? null,
|
|
832
|
+
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),
|
|
833
|
+
question: r.question
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
}),
|
|
837
|
+
defineTool({
|
|
838
|
+
name: "list_questions",
|
|
839
|
+
title: "List questions",
|
|
840
|
+
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).",
|
|
841
|
+
scope: "agents:read",
|
|
842
|
+
endpoint: "GET /v1/agents/questions",
|
|
843
|
+
inputSchema: z.object({
|
|
844
|
+
agentId,
|
|
845
|
+
status: z.enum(["open", "answered", "expired_default", "expired", "canceled"]).optional(),
|
|
846
|
+
kind: z.enum(["question", "approval"]).optional(),
|
|
847
|
+
channelId: channelId.optional(),
|
|
848
|
+
cursor: z.string().max(300).optional().describe("nextCursor of the previous call"),
|
|
849
|
+
limit: z.number().int().min(1).max(200).default(20).describe("How many to return (1-200, default 20)")
|
|
850
|
+
}),
|
|
851
|
+
outputSchema: z.object({
|
|
852
|
+
questions: z.array(question),
|
|
853
|
+
nextCursor: z.string().nullable()
|
|
854
|
+
}),
|
|
855
|
+
annotations: READ,
|
|
856
|
+
handler: async (api, a) => {
|
|
857
|
+
const r = await api.request("GET", "/v1/agents/questions", {
|
|
858
|
+
query: {
|
|
859
|
+
agent_id: actingAs(api, a.agentId),
|
|
860
|
+
status: a.status,
|
|
861
|
+
kind: a.kind,
|
|
862
|
+
channel_id: a.channelId,
|
|
863
|
+
cursor: a.cursor,
|
|
864
|
+
limit: a.limit
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
return {
|
|
868
|
+
questions: r.questions ?? [],
|
|
869
|
+
nextCursor: r.next_cursor ?? null
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
}),
|
|
873
|
+
defineTool({
|
|
874
|
+
name: "cancel_question",
|
|
875
|
+
title: "Cancel question",
|
|
876
|
+
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.",
|
|
877
|
+
scope: "agents:ask_human",
|
|
878
|
+
endpoint: "DELETE /v1/agents/questions/:id",
|
|
879
|
+
inputSchema: z.object({ agentId, questionId }),
|
|
880
|
+
outputSchema: z.object({ question }),
|
|
881
|
+
annotations: {
|
|
882
|
+
readOnlyHint: false,
|
|
883
|
+
destructiveHint: true,
|
|
884
|
+
idempotentHint: false,
|
|
885
|
+
openWorldHint: true
|
|
886
|
+
},
|
|
887
|
+
handler: async (api, a) => {
|
|
888
|
+
const r = await api.request(
|
|
889
|
+
"DELETE",
|
|
890
|
+
`/v1/agents/questions/${enc(a.questionId)}`,
|
|
891
|
+
{ query: { agent_id: actingAs(api, a.agentId) } }
|
|
892
|
+
);
|
|
893
|
+
return { question: r.question };
|
|
894
|
+
}
|
|
895
|
+
}),
|
|
896
|
+
defineTool({
|
|
897
|
+
name: "answer_escalated_question",
|
|
898
|
+
title: "Answer escalated question",
|
|
899
|
+
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.",
|
|
900
|
+
scope: "agents:send",
|
|
901
|
+
endpoint: "POST /v1/agents/questions/:id/answer",
|
|
902
|
+
inputSchema: z.object({
|
|
903
|
+
agentId,
|
|
904
|
+
questionId,
|
|
905
|
+
optionId: z.string().min(1).max(100).optional().describe("One of the question options (approve / deny for approvals)"),
|
|
906
|
+
text: z.string().max(3e3).optional().describe("A typed answer, when the question allows free text"),
|
|
907
|
+
comment: z.string().max(2e3).optional().describe("Why (shown with the answer; say why on a deny)")
|
|
908
|
+
}),
|
|
909
|
+
outputSchema: z.object({ question }),
|
|
910
|
+
annotations: SEND,
|
|
911
|
+
handler: async (api, a) => {
|
|
912
|
+
if (!a.optionId && !a.text) throw new ToolError("Pass optionId or text.");
|
|
913
|
+
const r = await api.request(
|
|
914
|
+
"POST",
|
|
915
|
+
`/v1/agents/questions/${enc(a.questionId)}/answer`,
|
|
916
|
+
{
|
|
917
|
+
body: {
|
|
918
|
+
agent_id: actingAs(api, a.agentId),
|
|
919
|
+
option_id: a.optionId,
|
|
920
|
+
text: a.text,
|
|
921
|
+
comment: a.comment
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
);
|
|
925
|
+
return { question: r.question };
|
|
926
|
+
}
|
|
927
|
+
}),
|
|
928
|
+
defineTool({
|
|
929
|
+
name: "get_org_chart",
|
|
930
|
+
title: "Get org chart",
|
|
931
|
+
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.",
|
|
932
|
+
scope: "agents:read",
|
|
933
|
+
endpoint: "GET /v1/agents/org-chart",
|
|
934
|
+
inputSchema: z.object({
|
|
935
|
+
teamId: uuid("Only this team").optional(),
|
|
936
|
+
channelId: uuid("Only the agents of this channel").optional(),
|
|
937
|
+
includeRetired: z.boolean().optional().describe("Include retired agents (default false)")
|
|
938
|
+
}),
|
|
939
|
+
outputSchema: z.object({
|
|
940
|
+
agents: z.array(z.looseObject({ id: z.string() })),
|
|
941
|
+
users: z.array(z.looseObject({ id: z.string() })),
|
|
942
|
+
teams: z.array(z.looseObject({ id: z.string() })),
|
|
943
|
+
tree: z.array(z.looseObject({}))
|
|
944
|
+
}),
|
|
945
|
+
annotations: READ,
|
|
946
|
+
handler: async (api, a) => await api.request("GET", "/v1/agents/org-chart", {
|
|
947
|
+
query: {
|
|
948
|
+
team_id: a.teamId,
|
|
949
|
+
channel_id: a.channelId,
|
|
950
|
+
include_retired: a.includeRetired ? "true" : void 0
|
|
951
|
+
}
|
|
952
|
+
})
|
|
953
|
+
}),
|
|
954
|
+
defineTool({
|
|
955
|
+
name: "get_effective_policy",
|
|
956
|
+
title: "Get effective policy",
|
|
957
|
+
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.",
|
|
958
|
+
scope: "agents:admin",
|
|
959
|
+
endpoint: "GET /v1/agents/policies/preview",
|
|
960
|
+
inputSchema: z.object({
|
|
961
|
+
agentId: uuid(
|
|
962
|
+
"The agent (from list_agents). Default: the server agent (CHANNLIZE_AGENT_ID)"
|
|
963
|
+
).optional(),
|
|
964
|
+
channelId: channelId.optional()
|
|
965
|
+
}),
|
|
966
|
+
outputSchema: z.looseObject({
|
|
967
|
+
agent_id: z.string(),
|
|
968
|
+
channel_id: z.string().nullable(),
|
|
969
|
+
rules: z.looseObject({}),
|
|
970
|
+
working_hours: z.looseObject({}),
|
|
971
|
+
usage: z.looseObject({}),
|
|
972
|
+
checks: z.looseObject({}).nullable()
|
|
973
|
+
}),
|
|
974
|
+
annotations: READ,
|
|
975
|
+
handler: async (api, a) => await api.request("GET", "/v1/agents/policies/preview", {
|
|
976
|
+
query: {
|
|
977
|
+
agent_id: requireAgent(api, a.agentId),
|
|
978
|
+
channel_id: a.channelId
|
|
979
|
+
}
|
|
980
|
+
})
|
|
981
|
+
}),
|
|
982
|
+
defineTool({
|
|
983
|
+
name: "read_agent_inbox",
|
|
984
|
+
title: "Read agent inbox",
|
|
985
|
+
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.",
|
|
986
|
+
scope: "agents:read",
|
|
987
|
+
endpoint: "GET /v1/agents/:id/inbox",
|
|
988
|
+
inputSchema: z.object({
|
|
989
|
+
agentId,
|
|
990
|
+
cursor: z.string().max(200).optional().describe("Read after this cursor (nextCursor of the previous call)"),
|
|
991
|
+
limit: z.number().int().min(1).max(200).default(20).describe("How many to return (1-200, default 20)")
|
|
992
|
+
}),
|
|
993
|
+
outputSchema: z.object({
|
|
994
|
+
agentId: z.string(),
|
|
995
|
+
messages: z.array(
|
|
996
|
+
z.looseObject({
|
|
997
|
+
delivery_id: z.string(),
|
|
998
|
+
cursor: z.string(),
|
|
999
|
+
message
|
|
1000
|
+
})
|
|
1001
|
+
),
|
|
1002
|
+
nextCursor: z.string().nullable(),
|
|
1003
|
+
hasMore: z.boolean()
|
|
1004
|
+
}),
|
|
1005
|
+
annotations: READ,
|
|
1006
|
+
handler: async (api, a) => {
|
|
1007
|
+
const id = requireAgent(api, a.agentId);
|
|
1008
|
+
const r = await api.request("GET", `/v1/agents/${enc(id)}/inbox`, {
|
|
1009
|
+
query: { cursor: a.cursor, limit: a.limit }
|
|
1010
|
+
});
|
|
1011
|
+
return {
|
|
1012
|
+
agentId: id,
|
|
1013
|
+
messages: r.messages ?? [],
|
|
1014
|
+
nextCursor: r.next_cursor ?? null,
|
|
1015
|
+
hasMore: Boolean(r.has_more)
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
}),
|
|
1019
|
+
defineTool({
|
|
1020
|
+
name: "ack_agent_messages",
|
|
1021
|
+
title: "Acknowledge agent messages",
|
|
1022
|
+
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.",
|
|
1023
|
+
scope: "agents:read",
|
|
1024
|
+
endpoint: "POST /v1/agents/:id/inbox/ack",
|
|
1025
|
+
inputSchema: z.object({
|
|
1026
|
+
agentId,
|
|
1027
|
+
upTo: z.string().uuid().optional().describe("Ack everything up to and including this delivery_id"),
|
|
1028
|
+
ids: z.array(z.string().uuid()).min(1).max(500).optional().describe("Ack these delivery (or message) IDs")
|
|
1029
|
+
}),
|
|
1030
|
+
outputSchema: z.object({ acked: z.number() }),
|
|
1031
|
+
annotations: {
|
|
1032
|
+
readOnlyHint: false,
|
|
1033
|
+
destructiveHint: false,
|
|
1034
|
+
idempotentHint: true,
|
|
1035
|
+
openWorldHint: false
|
|
1036
|
+
},
|
|
1037
|
+
handler: async (api, a) => {
|
|
1038
|
+
if (!a.upTo === !a.ids) {
|
|
1039
|
+
throw new ToolError("Pass either upTo or ids.");
|
|
1040
|
+
}
|
|
1041
|
+
const id = requireAgent(api, a.agentId);
|
|
1042
|
+
const r = await api.request(
|
|
1043
|
+
"POST",
|
|
1044
|
+
`/v1/agents/${enc(id)}/inbox/ack`,
|
|
1045
|
+
{ body: a.upTo ? { up_to: a.upTo } : { ids: a.ids } }
|
|
1046
|
+
);
|
|
1047
|
+
return { acked: Number(r.acked ?? 0) };
|
|
1048
|
+
}
|
|
1049
|
+
}),
|
|
1050
|
+
defineTool({
|
|
1051
|
+
name: "search_agent_messages",
|
|
1052
|
+
title: "Search agent messages",
|
|
1053
|
+
description: `Full-text search over agent channel history: messages, tasks, status updates and questions to people (with their answers), best match first. Use it to find what was said or decided before, a past task, or an answer a human already gave, instead of asking again. q takes websearch syntax: "exact phrase", or, -word; codes and ids match as substrings (INV-20 finds INV-2041). Each result has a highlight (hits in **bold**), the channel, threadId and a Slack link when mirrored. Searches the channels your key's agents can read and their own questions (the whole org for an agents:admin key), within the plan's history window. Page with cursor. Needs the agents:read scope.`,
|
|
1054
|
+
scope: "agents:read",
|
|
1055
|
+
endpoint: "GET /v1/agents/search",
|
|
1056
|
+
inputSchema: z.object({
|
|
1057
|
+
q: z.string().trim().min(2).max(200).describe("What to look for (2-200 characters)"),
|
|
1058
|
+
agentId: uuid(
|
|
1059
|
+
"Only messages sent by or mentioning this agent, and questions it asked (from list_agents). With a multi-agent key it also picks whose channels are searched."
|
|
1060
|
+
).optional(),
|
|
1061
|
+
channelId: channelId.optional().describe("Only this agent channel"),
|
|
1062
|
+
type: z.enum(AGENT_MESSAGE_TYPES).optional().describe("Only this message type"),
|
|
1063
|
+
include: z.enum(["messages", "questions", "both"]).default("both").describe("messages, questions, or both (default)"),
|
|
1064
|
+
from: z.string().max(40).optional().describe("ISO date-time: the earliest to search"),
|
|
1065
|
+
to: z.string().max(40).optional().describe("ISO date-time: the latest to search"),
|
|
1066
|
+
cursor: z.string().max(300).optional().describe("nextCursor of the previous call"),
|
|
1067
|
+
limit: z.number().int().min(1).max(50).default(10).describe("How many results (1-50, default 10)")
|
|
1068
|
+
}),
|
|
1069
|
+
outputSchema: z.object({
|
|
1070
|
+
results: z.array(
|
|
1071
|
+
z.looseObject({
|
|
1072
|
+
kind: z.string(),
|
|
1073
|
+
id: z.string(),
|
|
1074
|
+
type: z.string(),
|
|
1075
|
+
text: z.string(),
|
|
1076
|
+
highlight: z.string(),
|
|
1077
|
+
channel: z.string().nullable(),
|
|
1078
|
+
threadId: z.string().nullable()
|
|
1079
|
+
})
|
|
1080
|
+
),
|
|
1081
|
+
nextCursor: z.string().nullable(),
|
|
1082
|
+
window: z.object({ from: z.string(), days: z.number() })
|
|
1083
|
+
}),
|
|
1084
|
+
annotations: READ,
|
|
1085
|
+
handler: async (api, a) => {
|
|
1086
|
+
const r = await api.request("GET", "/v1/agents/search", {
|
|
1087
|
+
query: {
|
|
1088
|
+
q: a.q,
|
|
1089
|
+
agent_id: a.agentId,
|
|
1090
|
+
channel_id: a.channelId,
|
|
1091
|
+
type: a.type,
|
|
1092
|
+
include: a.include === "both" ? void 0 : a.include,
|
|
1093
|
+
from: a.from,
|
|
1094
|
+
to: a.to,
|
|
1095
|
+
cursor: a.cursor,
|
|
1096
|
+
limit: a.limit
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
return summarizeSearch(r);
|
|
1100
|
+
}
|
|
1101
|
+
}),
|
|
1102
|
+
defineTool({
|
|
1103
|
+
name: "get_agent_graph",
|
|
1104
|
+
title: "Get agent communication graph",
|
|
1105
|
+
description: "Who talks to whom among agents and people over a range of days: the busiest participants (messages sent and received, tokens, cost) and the busiest sender \u2192 recipient edges (messages, replies, reply latency), with totals and a one-line summary. Rows beyond top are counted in omitted. Filter to one agent (agentId, or mine for your own), a team or a channel. Sees the channels your key's agents can read (the whole org for an agents:admin key). Needs the agents:read scope.",
|
|
1106
|
+
scope: "agents:read",
|
|
1107
|
+
endpoint: "GET /v1/agents/insights/graph",
|
|
1108
|
+
inputSchema: z.object({
|
|
1109
|
+
...insightsRange,
|
|
1110
|
+
agentId: insightsAgent,
|
|
1111
|
+
mine,
|
|
1112
|
+
teamId: uuid("Only edges touching this team").optional(),
|
|
1113
|
+
top: top(10)
|
|
1114
|
+
}),
|
|
1115
|
+
outputSchema: z.object({
|
|
1116
|
+
range,
|
|
1117
|
+
totals: z.object({
|
|
1118
|
+
nodes: z.number(),
|
|
1119
|
+
edges: z.number(),
|
|
1120
|
+
messages: z.number(),
|
|
1121
|
+
tokens: z.number(),
|
|
1122
|
+
cost: z.number()
|
|
1123
|
+
}),
|
|
1124
|
+
topNodes: z.array(
|
|
1125
|
+
z.looseObject({ id: z.string(), label: z.string(), sent: z.number() })
|
|
1126
|
+
),
|
|
1127
|
+
topEdges: z.array(
|
|
1128
|
+
z.looseObject({
|
|
1129
|
+
source: z.string(),
|
|
1130
|
+
target: z.string(),
|
|
1131
|
+
messages: z.number(),
|
|
1132
|
+
replyAvgMs: nullableNumber
|
|
1133
|
+
})
|
|
1134
|
+
),
|
|
1135
|
+
omitted: z.looseObject({ nodes: z.number(), edges: z.number() }),
|
|
1136
|
+
summary: z.string()
|
|
1137
|
+
}),
|
|
1138
|
+
annotations: READ,
|
|
1139
|
+
handler: async (api, a) => {
|
|
1140
|
+
const r = await api.request("GET", "/v1/agents/insights/graph", {
|
|
1141
|
+
query: {
|
|
1142
|
+
from: a.from,
|
|
1143
|
+
to: a.to,
|
|
1144
|
+
channel_id: a.channelId,
|
|
1145
|
+
agent_id: filterAgent(api, a),
|
|
1146
|
+
team_id: a.teamId
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
return summarizeGraph(r, a.top);
|
|
1150
|
+
}
|
|
1151
|
+
}),
|
|
1152
|
+
defineTool({
|
|
1153
|
+
name: "get_agent_cost",
|
|
1154
|
+
title: "Get agent cost",
|
|
1155
|
+
description: "What agents spent, from the tokens and cost they reported on their messages: the range's totals, the top groups by cost (groupBy agent, channel, team, task or day) with their share, the active days and the peak day, and a one-line summary. Check your own spend with mine (or agentId), e.g. before starting expensive work or to report it. Cost is in whatever currency agents report (usually USD). Sees the channels your key's agents can read (the whole org for an agents:admin key). Needs the agents:read scope.",
|
|
1156
|
+
scope: "agents:read",
|
|
1157
|
+
endpoint: "GET /v1/agents/insights/cost",
|
|
1158
|
+
inputSchema: z.object({
|
|
1159
|
+
...insightsRange,
|
|
1160
|
+
groupBy: z.enum(["agent", "channel", "team", "task", "day"]).default("agent").describe("How to break the cost down (default agent)"),
|
|
1161
|
+
agentId: insightsAgent,
|
|
1162
|
+
mine,
|
|
1163
|
+
teamId: uuid("Only what this team's agents sent").optional(),
|
|
1164
|
+
top: top(10)
|
|
1165
|
+
}),
|
|
1166
|
+
outputSchema: z.object({
|
|
1167
|
+
range,
|
|
1168
|
+
groupBy: z.string(),
|
|
1169
|
+
totals: z.object({
|
|
1170
|
+
messages: z.number(),
|
|
1171
|
+
pricedMessages: z.number(),
|
|
1172
|
+
tokens: z.number(),
|
|
1173
|
+
cost: z.number()
|
|
1174
|
+
}),
|
|
1175
|
+
groups: z.array(
|
|
1176
|
+
z.looseObject({
|
|
1177
|
+
key: z.string(),
|
|
1178
|
+
label: z.string(),
|
|
1179
|
+
cost: z.number(),
|
|
1180
|
+
share: nullableNumber
|
|
1181
|
+
})
|
|
1182
|
+
),
|
|
1183
|
+
omittedGroups: z.number(),
|
|
1184
|
+
truncated: z.boolean(),
|
|
1185
|
+
daily: z.array(z.looseObject({ day: z.string(), cost: z.number() })),
|
|
1186
|
+
peakDay: z.object({ day: z.string(), cost: z.number() }).nullable(),
|
|
1187
|
+
summary: z.string()
|
|
1188
|
+
}),
|
|
1189
|
+
annotations: READ,
|
|
1190
|
+
handler: async (api, a) => {
|
|
1191
|
+
const r = await api.request("GET", "/v1/agents/insights/cost", {
|
|
1192
|
+
query: {
|
|
1193
|
+
from: a.from,
|
|
1194
|
+
to: a.to,
|
|
1195
|
+
channel_id: a.channelId,
|
|
1196
|
+
agent_id: filterAgent(api, a),
|
|
1197
|
+
team_id: a.teamId,
|
|
1198
|
+
group_by: a.groupBy,
|
|
1199
|
+
// Day groups come back whole; the others only need the top ones.
|
|
1200
|
+
limit: a.groupBy === "day" ? void 0 : a.top
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
return summarizeCost(r, a.top);
|
|
1204
|
+
}
|
|
1205
|
+
}),
|
|
1206
|
+
defineTool({
|
|
1207
|
+
name: "get_agent_metrics",
|
|
1208
|
+
title: "Get agent metrics",
|
|
1209
|
+
description: "Response metrics over a range of days: reply latency (agent \u2192 agent, human \u2192 agent, agent \u2192 human: avg, p50, p90 and reply rate) and per responding agent, questions to people (answer rate, time to a human answer, by urgency), delivery failure and retry rates per mode, and the inbox backlog right now, with a one-line summary. Use mine (or agentId) to check how fast you answer and whether your inbox is backing up. Needs the agents:read scope.",
|
|
1210
|
+
scope: "agents:read",
|
|
1211
|
+
endpoint: "GET /v1/agents/insights/metrics",
|
|
1212
|
+
inputSchema: z.object({
|
|
1213
|
+
...insightsRange,
|
|
1214
|
+
agentId: insightsAgent,
|
|
1215
|
+
mine,
|
|
1216
|
+
top: top(5)
|
|
1217
|
+
}),
|
|
1218
|
+
outputSchema: z.object({
|
|
1219
|
+
range,
|
|
1220
|
+
replies: z.looseObject({
|
|
1221
|
+
agentToAgent: z.looseObject({ avgMs: nullableNumber }),
|
|
1222
|
+
humanToAgent: z.looseObject({ avgMs: nullableNumber }),
|
|
1223
|
+
agentToHuman: z.looseObject({ avgMs: nullableNumber }),
|
|
1224
|
+
byAgent: z.array(z.looseObject({ agentId: z.string() }))
|
|
1225
|
+
}),
|
|
1226
|
+
questions: z.looseObject({ asked: z.number() }),
|
|
1227
|
+
deliveries: z.looseObject({ deliveries: z.number() }),
|
|
1228
|
+
backlog: z.looseObject({ unacked: z.number(), held: z.number() }),
|
|
1229
|
+
summary: z.string()
|
|
1230
|
+
}),
|
|
1231
|
+
annotations: READ,
|
|
1232
|
+
handler: async (api, a) => {
|
|
1233
|
+
const r = await api.request("GET", "/v1/agents/insights/metrics", {
|
|
1234
|
+
query: {
|
|
1235
|
+
from: a.from,
|
|
1236
|
+
to: a.to,
|
|
1237
|
+
channel_id: a.channelId,
|
|
1238
|
+
agent_id: filterAgent(api, a)
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
return summarizeMetrics(r, a.top);
|
|
1242
|
+
}
|
|
1243
|
+
}),
|
|
1244
|
+
defineTool({
|
|
1245
|
+
name: "list_agents",
|
|
1246
|
+
title: "List agents",
|
|
1247
|
+
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.",
|
|
1248
|
+
scope: "agents:read",
|
|
1249
|
+
endpoint: "GET /v1/agents",
|
|
1250
|
+
inputSchema: z.object({
|
|
1251
|
+
includeRetired: z.boolean().optional().describe("Include retired agents (default false)")
|
|
1252
|
+
}),
|
|
1253
|
+
outputSchema: z.object({
|
|
1254
|
+
agents: z.array(
|
|
1255
|
+
z.looseObject({
|
|
1256
|
+
id: z.string(),
|
|
1257
|
+
slug: z.string(),
|
|
1258
|
+
name: z.string(),
|
|
1259
|
+
status: z.string()
|
|
1260
|
+
})
|
|
1261
|
+
)
|
|
1262
|
+
}),
|
|
1263
|
+
annotations: READ,
|
|
1264
|
+
handler: async (api, a) => {
|
|
1265
|
+
const r = await api.request("GET", "/v1/agents", {
|
|
1266
|
+
query: { include_retired: a.includeRetired || void 0 }
|
|
1267
|
+
});
|
|
1268
|
+
return { agents: r.agents ?? [] };
|
|
1269
|
+
}
|
|
1270
|
+
}),
|
|
1271
|
+
defineTool({
|
|
1272
|
+
name: "list_agent_channels",
|
|
1273
|
+
title: "List agent channels",
|
|
1274
|
+
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.",
|
|
1275
|
+
scope: "agents:read",
|
|
1276
|
+
endpoint: "GET /v1/agents/channels",
|
|
1277
|
+
inputSchema: z.object({
|
|
1278
|
+
includeArchived: z.boolean().optional().describe("Include archived channels (default false)")
|
|
1279
|
+
}),
|
|
1280
|
+
outputSchema: z.object({
|
|
1281
|
+
channels: z.array(
|
|
1282
|
+
z.looseObject({
|
|
1283
|
+
id: z.string(),
|
|
1284
|
+
slug: z.string(),
|
|
1285
|
+
name: z.string(),
|
|
1286
|
+
archived: z.boolean()
|
|
1287
|
+
})
|
|
1288
|
+
)
|
|
1289
|
+
}),
|
|
1290
|
+
annotations: READ,
|
|
1291
|
+
handler: async (api, a) => {
|
|
1292
|
+
const r = await api.request(
|
|
1293
|
+
"GET",
|
|
1294
|
+
"/v1/agents/channels",
|
|
1295
|
+
{ query: { include_archived: a.includeArchived || void 0 } }
|
|
1296
|
+
);
|
|
1297
|
+
return { channels: r.channels ?? [] };
|
|
1298
|
+
}
|
|
1299
|
+
})
|
|
1300
|
+
];
|
|
1301
|
+
var AGENT_TOOL_NAMES = AGENT_TOOLS.map((t) => t.name);
|
|
1302
|
+
function getAgentTool(name) {
|
|
1303
|
+
return AGENT_TOOLS.find((t) => t.name === name);
|
|
1304
|
+
}
|
|
1305
|
+
async function runAgentTool(api, name, args) {
|
|
1306
|
+
const tool = getAgentTool(name);
|
|
1307
|
+
if (!tool) throw new ToolError(`Unknown agent tool "${name}"`);
|
|
1308
|
+
const parsed = tool.inputSchema.safeParse(args ?? {});
|
|
1309
|
+
if (!parsed.success) {
|
|
1310
|
+
throw new ToolError(
|
|
1311
|
+
`Invalid arguments for ${name}: ${parsed.error.issues.map((i) => `${i.path.join(".") || "input"}: ${i.message}`).join("; ")}`
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
return await tool.handler(api, parsed.data);
|
|
1315
|
+
}
|
|
1316
|
+
function agentToolsAsJsonSchema(filter = () => true) {
|
|
1317
|
+
return AGENT_TOOLS.filter(filter).map((t) => ({
|
|
1318
|
+
name: t.name,
|
|
1319
|
+
description: t.description,
|
|
1320
|
+
parameters: z.toJSONSchema(t.inputSchema, { io: "input" })
|
|
1321
|
+
}));
|
|
1322
|
+
}
|
|
1323
|
+
export {
|
|
1324
|
+
AGENT_TASK_STATUSES,
|
|
1325
|
+
AGENT_TOOLS,
|
|
1326
|
+
AGENT_TOOL_NAMES,
|
|
1327
|
+
QUESTION_WAIT_MAX_SECONDS,
|
|
1328
|
+
agentToolsAsJsonSchema,
|
|
1329
|
+
getAgentTool,
|
|
1330
|
+
runAgentTool
|
|
1331
|
+
};
|
|
1332
|
+
//# sourceMappingURL=agents.mjs.map
|