@kumion/cli 0.2.0 → 0.4.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/README.md +455 -18
- package/dist/client.js +205 -4
- package/dist/device-login.js +1 -0
- package/dist/errors.js +29 -1
- package/dist/main.js +1259 -10
- package/dist/mcp.js +778 -7
- package/package.json +6 -4
- package/skills/kumion/SKILL.md +245 -14
package/dist/mcp.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { basename } from "node:path";
|
|
2
4
|
import { z } from "zod";
|
|
3
5
|
import { ApiError } from "./client.js";
|
|
4
6
|
import { describeError, UsageError } from "./errors.js";
|
|
@@ -22,22 +24,156 @@ async function attempt(run) {
|
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
const agentId = z.string().min(1).describe("The agent's id, from list_agents.");
|
|
27
|
+
const storeHourRange = z
|
|
28
|
+
.object({ start: z.string().describe("HH:MM"), end: z.string().describe("HH:MM") })
|
|
29
|
+
.passthrough();
|
|
30
|
+
const flowStep = z
|
|
31
|
+
.object({
|
|
32
|
+
key: z.string().min(1).describe("The step's key (an existing one, or a new key with action \"add\")."),
|
|
33
|
+
action: z.enum(["add", "remove"]).optional(),
|
|
34
|
+
afterKey: z.string().optional().describe("add: place it after this step."),
|
|
35
|
+
beforeKey: z.string().optional().describe("add: place it before this step."),
|
|
36
|
+
label: z.string().optional(),
|
|
37
|
+
transitionSpeech: z.string().optional(),
|
|
38
|
+
prompt: z.string().optional().describe("What this step does."),
|
|
39
|
+
requiredBeforeEnd: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
40
|
+
})
|
|
41
|
+
.passthrough();
|
|
42
|
+
const flowLeaf = z
|
|
43
|
+
.object({
|
|
44
|
+
key: z.string().min(1).describe("The 用件's key (an existing one, or a new alphanumeric key with action \"add\")."),
|
|
45
|
+
action: z.enum(["keep", "remove", "merge_into", "add"]).optional(),
|
|
46
|
+
mergeIntoKey: z.string().optional().describe("merge_into: the 用件 this one is folded into."),
|
|
47
|
+
label: z.string().optional(),
|
|
48
|
+
condition: z.string().optional().describe("How a caller's words make this the 用件 the call is taken under."),
|
|
49
|
+
transitionSpeech: z.string().optional(),
|
|
50
|
+
leafPrompt: z.string().optional().describe("What the agent does in this 用件."),
|
|
51
|
+
endSpeech: z.string().optional(),
|
|
52
|
+
transferContactKey: z
|
|
53
|
+
.string()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe("Hand this 用件 to this registered staff member (a `key` from get_call_flow's staffChoices)."),
|
|
56
|
+
removeTransfer: z.boolean().optional().describe("Take the transfer off this 用件 (it goes back to a message)."),
|
|
57
|
+
requiredBeforeEnd: z.array(z.record(z.string(), z.unknown())).optional().describe("The whole list the 用件 must ask."),
|
|
58
|
+
steps: z.array(flowStep).optional(),
|
|
59
|
+
})
|
|
60
|
+
.passthrough();
|
|
25
61
|
export function createKumionMcpServer(client, options) {
|
|
26
62
|
const server = new McpServer({ name: "kumion", version: options.version });
|
|
27
63
|
server.registerTool("list_agents", {
|
|
28
64
|
description: "List the voice agents of the Kumion tenant this key belongs to. Needs the agents:read scope.",
|
|
29
65
|
annotations: { readOnlyHint: true },
|
|
30
66
|
}, () => attempt(async () => ({ tenantId: client.tenantId, agents: await client.listAgents() })));
|
|
67
|
+
server.registerTool("list_agent_templates", {
|
|
68
|
+
description: "List the onboarding templates: the id, what each one is for, and the 用件 and facts it declares. Use an " +
|
|
69
|
+
"id here with create_agent_from_template. Needs agents:read.",
|
|
70
|
+
annotations: { readOnlyHint: true },
|
|
71
|
+
}, () => attempt(async () => ({ templates: await client.listAgentTemplates() })));
|
|
72
|
+
server.registerTool("create_agent_from_template", {
|
|
73
|
+
description: "Create a DRAFT agent from an onboarding template plus the business name, optionally reading a website " +
|
|
74
|
+
"(`url`) or a document already uploaded and extracted on the Portal's 資料 screen (`documentId`; an API key " +
|
|
75
|
+
"cannot upload one). Only facts the source actually states are filled; the rest come back as 「まだない情報」. " +
|
|
76
|
+
"Nothing is published and no fact is confirmed. Needs agents:write.",
|
|
77
|
+
inputSchema: {
|
|
78
|
+
templateId: z.string().min(1).describe("A template id from list_agent_templates."),
|
|
79
|
+
businessName: z.string().min(1).describe("The shop/company name: names the agent and greets the caller."),
|
|
80
|
+
name: z.string().min(1).optional().describe("Agent name; defaults to businessName."),
|
|
81
|
+
url: z.string().url().optional().describe("A site to read (same site, up to 10 pages). Not with documentId."),
|
|
82
|
+
documentId: z.string().min(1).optional().describe("An extracted document id. Not with url."),
|
|
83
|
+
idempotencyKey: z
|
|
84
|
+
.string()
|
|
85
|
+
.min(1)
|
|
86
|
+
.max(200)
|
|
87
|
+
.optional()
|
|
88
|
+
.describe("Safe-retry key: send the same key again to get the agent the first call built instead of a second one."),
|
|
89
|
+
},
|
|
90
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
91
|
+
}, (args) => attempt(() => client.createAgentFromTemplate({
|
|
92
|
+
templateId: args.templateId,
|
|
93
|
+
businessName: args.businessName,
|
|
94
|
+
...(args.name ? { name: args.name } : {}),
|
|
95
|
+
...(args.url ? { url: args.url } : {}),
|
|
96
|
+
...(args.documentId ? { documentId: args.documentId } : {}),
|
|
97
|
+
...(args.idempotencyKey ? { idempotencyKey: args.idempotencyKey } : {}),
|
|
98
|
+
})));
|
|
31
99
|
server.registerTool("get_agent", {
|
|
32
100
|
description: "Read one agent: its draft (prompt, flow graph) and its published version. The returned `revision` is " +
|
|
33
101
|
"what patch_agent needs. Needs agents:read.",
|
|
34
102
|
inputSchema: { agentId },
|
|
35
103
|
annotations: { readOnlyHint: true },
|
|
36
104
|
}, (args) => attempt(() => client.getAgent(args.agentId)));
|
|
105
|
+
server.registerTool("get_call_flow", {
|
|
106
|
+
description: "Read the agent's draft call flow the way the canvas assistant reads it: `editLayer` says whether it is edited " +
|
|
107
|
+
"as 用件 (`flow`, with the 用件 subject, what each one says and asks for, and the confirmed caller examples) or " +
|
|
108
|
+
"as steps (`steps`, where `flow` is null); `staffChoices` is who a 用件 may transfer to, `transferRefusal` why " +
|
|
109
|
+
"it may not, and `findings` the same pre-publish findings the assistant sees. `revision` is the value " +
|
|
110
|
+
"patch_agent needs. Needs agents:read.",
|
|
111
|
+
inputSchema: { agentId },
|
|
112
|
+
annotations: { readOnlyHint: true },
|
|
113
|
+
}, (args) => attempt(() => client.getFlow(args.agentId)));
|
|
114
|
+
server.registerTool("update_call_flow", {
|
|
115
|
+
description: "Change the agent's draft call flow the way the canvas assistant does: the 用件 (what each one says and asks " +
|
|
116
|
+
"for, how callers reach it), and whether a 用件 hands the caller to a registered staff member " +
|
|
117
|
+
"(`leaves[].transferContactKey`, or `removeTransfer` to take it away). Only what you pass changes; the same " +
|
|
118
|
+
"arguments and rules as the assistant's update_call_flow tool, so a field it does not take is a 400. Returns " +
|
|
119
|
+
"`changes` (the rows the proposal card lists), `consequences` (tests and steps the change takes along) and " +
|
|
120
|
+
"`warnings` (what could not be applied as asked); `revision` is the draft revision after the write. `dryRun` " +
|
|
121
|
+
"computes the change and stores nothing. A draft write: it reaches callers with the next publish_agent. " +
|
|
122
|
+
"Needs agents:write. Read the flow with get_call_flow first (its `editLayer` must be `flow`).",
|
|
123
|
+
inputSchema: {
|
|
124
|
+
agentId,
|
|
125
|
+
revision: z.string().min(1).describe("The draft revision your change is based on, from get_call_flow."),
|
|
126
|
+
personaPrompt: z.string().optional().describe("The agent's role and tone."),
|
|
127
|
+
openingSpeech: z.string().optional().describe("The first line of the call."),
|
|
128
|
+
noRouteSpeech: z.string().optional().describe("What it says when no 用件 fits."),
|
|
129
|
+
leaves: z.array(flowLeaf).optional().describe("Per-用件 changes; only the fields you pass change."),
|
|
130
|
+
examples: z.record(z.string(), z.string()).optional().describe("用件 key → the line a caller opens with."),
|
|
131
|
+
dryRun: z.boolean().optional().describe("Compute the change and store nothing."),
|
|
132
|
+
},
|
|
133
|
+
annotations: { destructiveHint: false, idempotentHint: false },
|
|
134
|
+
}, (args) => {
|
|
135
|
+
const source = args;
|
|
136
|
+
const patch = {};
|
|
137
|
+
for (const key of ["personaPrompt", "openingSpeech", "noRouteSpeech", "leaves", "examples"]) {
|
|
138
|
+
if (source[key] !== undefined)
|
|
139
|
+
patch[key] = source[key];
|
|
140
|
+
}
|
|
141
|
+
if (Object.keys(patch).length === 0) {
|
|
142
|
+
return failure(new UsageError("Nothing to change: pass personaPrompt, openingSpeech, noRouteSpeech, leaves or examples."));
|
|
143
|
+
}
|
|
144
|
+
return attempt(() => client.updateFlow(args.agentId, patch, args.revision, { dryRun: args.dryRun === true }));
|
|
145
|
+
});
|
|
146
|
+
server.registerTool("edit_call_flow_steps", {
|
|
147
|
+
description: "Change a step-by-step flow (one the canvas draws, `editLayer` = `steps` in get_call_flow) the way the canvas " +
|
|
148
|
+
"assistant does. `ops` is a batch, run in order, at most 20: each element is `{ op, …that operation's " +
|
|
149
|
+
"arguments }`, with `op` one of set_node_field (nodeKey, field, value), set_edge_words (fromKey, toKey, " +
|
|
150
|
+
"condition?, transitionSpeech?), add_step (type `agent`|`transfer`, name, between?, next_condition?, prompt?, " +
|
|
151
|
+
"items?, staff?, before_speech?, key?), remove_step (node), connect_steps (from, to, condition, speech?, " +
|
|
152
|
+
"only_when?), reconnect (from, to, new_to, via_tool?), disconnect (from, to, via_tool?). The batch is atomic: " +
|
|
153
|
+
"one refused operation refuses all of them, and nothing is stored. `add_step.key` (optional, lowercase " +
|
|
154
|
+
"letters/digits/_) names the new step so a later operation of the same batch can point at it; without one the " +
|
|
155
|
+
"server picks the key and returns it in `added`. A 用件 flow (`editLayer` = `flow`) is refused: use " +
|
|
156
|
+
"update_call_flow. Returns `revision` (the draft revision after the write), `changes` (the rows the proposal " +
|
|
157
|
+
"card lists), `consequences`, `warnings` and `added`. A draft write: it reaches callers with the next " +
|
|
158
|
+
"publish_agent. Needs agents:write.",
|
|
159
|
+
inputSchema: {
|
|
160
|
+
agentId,
|
|
161
|
+
revision: z.string().min(1).describe("The draft revision your change is based on, from get_call_flow."),
|
|
162
|
+
ops: z
|
|
163
|
+
.array(z.record(z.string(), z.unknown()))
|
|
164
|
+
.describe("The batch, in order (at most 20): each element is { op, …that operation's arguments }."),
|
|
165
|
+
dryRun: z.boolean().optional().describe("Compute the change and store nothing."),
|
|
166
|
+
},
|
|
167
|
+
annotations: { destructiveHint: false, idempotentHint: false },
|
|
168
|
+
}, (args) => attempt(() => client.editFlowSteps(args.agentId, args.ops, args.revision, { dryRun: args.dryRun === true })));
|
|
37
169
|
server.registerTool("patch_agent", {
|
|
38
170
|
description: "Edit an agent's draft (never goes live by itself — publish_agent does that). `revision` must be the one " +
|
|
39
171
|
"get_agent returned when you read the draft you are changing; if the draft changed since, nothing is " +
|
|
40
|
-
"written and you get a conflict: read it again and re-apply.
|
|
172
|
+
"written and you get a conflict: read it again and re-apply. External send settings (a webhook, the pre-call " +
|
|
173
|
+
"fetch, a notification, a transfer target, the opening recording, an IVR menu's recording) may only be sent " +
|
|
174
|
+
"back unchanged: adding, " +
|
|
175
|
+
"removing or changing one is refused with `external_field_closed`, and the Portal's canvas is where those " +
|
|
176
|
+
"are edited. Needs agents:write.",
|
|
41
177
|
inputSchema: {
|
|
42
178
|
agentId,
|
|
43
179
|
revision: z.string().min(1).describe("The draft revision your change is based on, from get_agent."),
|
|
@@ -56,10 +192,72 @@ export function createKumionMcpServer(client, options) {
|
|
|
56
192
|
}
|
|
57
193
|
return attempt(() => client.patchAgent(args.agentId, patch, args.revision));
|
|
58
194
|
});
|
|
195
|
+
server.registerTool("set_agent_opening_name", {
|
|
196
|
+
description: "Switch whether the agent's opening line may call the caller by the name the phone number matched. A draft " +
|
|
197
|
+
"write like patch_agent: it reaches callers with the next publish_agent. `revision` is the one get_agent " +
|
|
198
|
+
"returned. Needs agents:write.",
|
|
199
|
+
inputSchema: {
|
|
200
|
+
agentId,
|
|
201
|
+
revision: z.string().min(1).describe("The draft revision your change is based on, from get_agent."),
|
|
202
|
+
enabled: z.boolean().describe("true: use the caller's name; false: do not."),
|
|
203
|
+
},
|
|
204
|
+
annotations: { destructiveHint: false, idempotentHint: true },
|
|
205
|
+
}, (args) => attempt(() => client.setOpeningName(args.agentId, args.enabled, args.revision)));
|
|
206
|
+
server.registerTool("set_agent_availability", {
|
|
207
|
+
description: "Set when the agent answers the phone (operatingHours: { mode: always | staffed | custom, hours? }) and what " +
|
|
208
|
+
"happens to a call outside that (offHoursPolicy: { kind: answer | announce_end | route_to, text?, agent_id? }). " +
|
|
209
|
+
"Pass either or both; null clears a setting to its default. LIVE: it applies to the next call with no " +
|
|
210
|
+
"publish, so confirm with the person first. `revision` is the one get_agent returned (the settings are in " +
|
|
211
|
+
"its `live` block). Needs agents:live, which a key does not get from agents:write.",
|
|
212
|
+
inputSchema: {
|
|
213
|
+
agentId,
|
|
214
|
+
revision: z.string().min(1).describe("The draft revision your change is based on, from get_agent."),
|
|
215
|
+
operatingHours: z.unknown().optional().describe("New 受付時間, or null to clear."),
|
|
216
|
+
offHoursPolicy: z.unknown().optional().describe("New 時間外の対応, or null to clear."),
|
|
217
|
+
},
|
|
218
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
219
|
+
}, (args) => {
|
|
220
|
+
const patch = {};
|
|
221
|
+
if (args.operatingHours !== undefined)
|
|
222
|
+
patch.operatingHours = args.operatingHours;
|
|
223
|
+
if (args.offHoursPolicy !== undefined)
|
|
224
|
+
patch.offHoursPolicy = args.offHoursPolicy;
|
|
225
|
+
if (!("operatingHours" in patch) && !("offHoursPolicy" in patch)) {
|
|
226
|
+
return failure(new UsageError("Nothing to change: pass `operatingHours` or `offHoursPolicy`."));
|
|
227
|
+
}
|
|
228
|
+
return attempt(() => client.setAvailability(args.agentId, patch, args.revision));
|
|
229
|
+
});
|
|
230
|
+
server.registerTool("list_facts", {
|
|
231
|
+
description: "List the facts taken from the agent's 資料 (prices, menu, opening notes) with their state (pending, " +
|
|
232
|
+
"confirmed, edited) and the `revision` edit_fact needs. Needs agents:read.",
|
|
233
|
+
inputSchema: { agentId },
|
|
234
|
+
annotations: { readOnlyHint: true },
|
|
235
|
+
}, (args) => attempt(async () => ({ facts: await client.listFacts(args.agentId) })));
|
|
236
|
+
server.registerTool("edit_fact", {
|
|
237
|
+
description: "Confirm one fact with a new value. LIVE: callers get it at once, with no publish, so confirm with the person " +
|
|
238
|
+
"first. `revision` is the fact's own, from list_facts; if the fact changed since, nothing is written. Needs " +
|
|
239
|
+
"agents:live.",
|
|
240
|
+
inputSchema: {
|
|
241
|
+
agentId,
|
|
242
|
+
factId: z.string().min(1).describe("The fact's id, from list_facts."),
|
|
243
|
+
revision: z.string().min(1).describe("The fact's revision, from list_facts."),
|
|
244
|
+
value: z.string().describe("The value to confirm."),
|
|
245
|
+
},
|
|
246
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
247
|
+
}, (args) => attempt(async () => ({ fact: await client.editFact(args.agentId, args.factId, args.value, args.revision) })));
|
|
248
|
+
server.registerTool("confirm_facts", {
|
|
249
|
+
description: "Confirm pending facts with the value the extraction found: the listed factIds, or every pending one when " +
|
|
250
|
+
"omitted. A fact whose candidates disagree is not confirmed and comes back in `skipped`. LIVE: callers get " +
|
|
251
|
+
"it at once, with no publish. Needs agents:live.",
|
|
252
|
+
inputSchema: { agentId, factIds: z.array(z.string().min(1)).optional().describe("Only these facts (from list_facts).") },
|
|
253
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
254
|
+
}, (args) => attempt(() => client.confirmFacts(args.agentId, args.factIds)));
|
|
59
255
|
server.registerTool("publish_agent", {
|
|
60
256
|
description: "Publish the agent's draft so callers get it. Runs the same pre-publish check as the Portal first and " +
|
|
61
257
|
"publishes only if it passes; there is no way to skip it. Can take a few minutes. On failure the " +
|
|
62
|
-
"failing cases are returned.
|
|
258
|
+
"failing cases are returned. A success carries `unconfirmedFacts`: how many of the agent's 資料 facts " +
|
|
259
|
+
"nobody has confirmed yet — for each of them the agent says it will check and call back instead of " +
|
|
260
|
+
"stating it (confirm_facts confirms them). Needs agents:publish.",
|
|
63
261
|
inputSchema: {
|
|
64
262
|
agentId,
|
|
65
263
|
revision: z.string().optional().describe("Refuse to publish if the draft is no longer at this revision."),
|
|
@@ -104,17 +302,28 @@ export function createKumionMcpServer(client, options) {
|
|
|
104
302
|
}, (args) => attempt(async () => ({ testRuns: await client.listTestRuns(args.agentId, args.limit) })));
|
|
105
303
|
server.registerTool("create_call", {
|
|
106
304
|
description: "Start a web test call with the agent. Returns the LiveKit room and a participant token to join it. " +
|
|
107
|
-
"
|
|
305
|
+
"With phoneNumber (a domestic Japanese number), dials that number instead and returns the call id " +
|
|
306
|
+
"straight away; the outcome is on the call (get_call). Needs calls:create.",
|
|
108
307
|
inputSchema: {
|
|
109
308
|
agentId,
|
|
110
309
|
campaignContactId: z.string().optional().describe("Call as this campaign contact (optional)."),
|
|
310
|
+
phoneNumber: z
|
|
311
|
+
.string()
|
|
312
|
+
.optional()
|
|
313
|
+
.describe("Dial this domestic number (e.g. 08012345678) from the agent's assigned phone number (optional)."),
|
|
314
|
+
variables: z
|
|
315
|
+
.record(z.string(), z.string())
|
|
316
|
+
.optional()
|
|
317
|
+
.describe("Values for {{vars.<name>}} in the agent's prompts, opening line and edge conditions (optional)."),
|
|
111
318
|
},
|
|
112
319
|
annotations: { idempotentHint: false },
|
|
113
|
-
}, (args) => attempt(() => client.createCall(args.agentId, args.campaignContactId)));
|
|
320
|
+
}, (args) => attempt(() => client.createCall(args.agentId, args.campaignContactId, args.variables, args.phoneNumber)));
|
|
114
321
|
const callId = z.string().min(1).describe("The call's id, from list_calls.");
|
|
115
322
|
server.registerTool("list_calls", {
|
|
116
323
|
description: "List the tenant's call history, newest first, one page at a time (default 20, at most 100); `total` " +
|
|
117
|
-
"counts every call matching the filters. Draft test calls are not listed.
|
|
324
|
+
"counts every call matching the filters. Draft test calls are not listed. Each call carries its result: " +
|
|
325
|
+
"`outcome` (ai_resolved, ai_unresolved_hangup, invalid_call, handoff, system_ended, na), `endedAtNode`, " +
|
|
326
|
+
"`durationSec`, `transferred` and `capturedItems` (names only). Needs calls:read.",
|
|
118
327
|
inputSchema: {
|
|
119
328
|
agentId: z.string().optional().describe("Only this agent's calls."),
|
|
120
329
|
channel: z.enum(["webcall", "sip_did", "trigger"]).optional().describe("Only calls in on this channel."),
|
|
@@ -128,8 +337,8 @@ export function createKumionMcpServer(client, options) {
|
|
|
128
337
|
}, (args) => attempt(() => client.listCalls(args)));
|
|
129
338
|
server.registerTool("get_call", {
|
|
130
339
|
description: "Read one call: agent, source and direction, numbers, when it started, was answered and ended, how it " +
|
|
131
|
-
"ended,
|
|
132
|
-
"list_calls. Needs calls:read.",
|
|
340
|
+
"ended, its result (`outcome`, `endedAtNode`, `durationSec`, `transferred`, `capturedItems`), and whether " +
|
|
341
|
+
"a transcript exists (read it with get_call_transcript). The channel is only on list_calls. Needs calls:read.",
|
|
133
342
|
inputSchema: { callId },
|
|
134
343
|
annotations: { readOnlyHint: true },
|
|
135
344
|
}, (args) => attempt(async () => ({ call: await client.getCall(args.callId) })));
|
|
@@ -140,5 +349,567 @@ export function createKumionMcpServer(client, options) {
|
|
|
140
349
|
inputSchema: { callId },
|
|
141
350
|
annotations: { readOnlyHint: true },
|
|
142
351
|
}, (args) => attempt(async () => ({ transcript: await client.getTranscript(args.callId) })));
|
|
352
|
+
server.registerTool("list_staff", {
|
|
353
|
+
description: "List the tenant's スタッフ — the people a 用件's 転送 can be sent to — with `id`, the `key` a transfer names, " +
|
|
354
|
+
"`displayName`, `department`, `transferTarget`, `enabled` and `revision` (what update_staff must pass). " +
|
|
355
|
+
"`transferCandidate: true` means a 用件 may transfer there: enabled, keyed and given a 転送先. Needs agents:read.",
|
|
356
|
+
inputSchema: {},
|
|
357
|
+
annotations: { readOnlyHint: true },
|
|
358
|
+
}, () => attempt(async () => ({ staff: await client.listStaff() })));
|
|
359
|
+
const staffText = (what) => z.string().optional().describe(`${what} (an empty string clears it).`);
|
|
360
|
+
server.registerTool("create_staff", {
|
|
361
|
+
description: "Register a スタッフ so a 用件 can transfer a call to them. The transfer `key` is generated and returned — it " +
|
|
362
|
+
"is not a parameter. Nothing reaches callers until a 用件's 転送 names that key and the agent is published, " +
|
|
363
|
+
"and a row with no `transferTarget` is not a transfer candidate yet. Needs agents:write.",
|
|
364
|
+
inputSchema: {
|
|
365
|
+
displayName: z.string().min(1).describe("The person's name, as the operator sees it in the 転送 list."),
|
|
366
|
+
transferTarget: staffText("The number a transfer dials"),
|
|
367
|
+
department: staffText("Their team or department"),
|
|
368
|
+
kana: staffText("The name in kana"),
|
|
369
|
+
email: staffText("Their email address"),
|
|
370
|
+
note: staffText("A note. Never spoken on a call"),
|
|
371
|
+
enabled: z.boolean().optional().describe("false to leave them out of the 転送 candidates (default true)."),
|
|
372
|
+
},
|
|
373
|
+
annotations: { destructiveHint: false, idempotentHint: false },
|
|
374
|
+
}, (args) => attempt(async () => ({
|
|
375
|
+
staff: await client.createStaff({
|
|
376
|
+
displayName: args.displayName,
|
|
377
|
+
...(args.transferTarget !== undefined ? { transferTarget: args.transferTarget } : {}),
|
|
378
|
+
...(args.department !== undefined ? { department: args.department } : {}),
|
|
379
|
+
...(args.kana !== undefined ? { kana: args.kana } : {}),
|
|
380
|
+
...(args.email !== undefined ? { email: args.email } : {}),
|
|
381
|
+
...(args.note !== undefined ? { note: args.note } : {}),
|
|
382
|
+
...(args.enabled !== undefined ? { enabled: args.enabled } : {}),
|
|
383
|
+
}),
|
|
384
|
+
})));
|
|
385
|
+
server.registerTool("update_staff", {
|
|
386
|
+
description: "Change a スタッフ: their name, 転送先, department, kana, email, note, or whether they are a 転送 candidate " +
|
|
387
|
+
"(enabled: false takes them off the list without deleting the row the flow names). The `key` cannot be " +
|
|
388
|
+
"changed. LIVE: the next call already transfers to the new value — no publish — so confirm with the person " +
|
|
389
|
+
"first. `revision` is the row's, from list_staff; if it changed since, nothing is written and you get a " +
|
|
390
|
+
"conflict: read it again and re-apply. Needs agents:live.",
|
|
391
|
+
inputSchema: {
|
|
392
|
+
staffId: z.string().min(1).describe("The スタッフ's id, from list_staff."),
|
|
393
|
+
revision: z.string().min(1).describe("The row's revision, from list_staff."),
|
|
394
|
+
displayName: z.string().min(1).optional().describe("New name."),
|
|
395
|
+
transferTarget: staffText("New 転送先 number"),
|
|
396
|
+
department: staffText("Their team or department"),
|
|
397
|
+
kana: staffText("The name in kana"),
|
|
398
|
+
email: staffText("Their email address"),
|
|
399
|
+
note: staffText("A note. Never spoken on a call"),
|
|
400
|
+
enabled: z.boolean().optional().describe("false to take them out of the 転送 candidates."),
|
|
401
|
+
},
|
|
402
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
403
|
+
}, (args) => {
|
|
404
|
+
const patch = {};
|
|
405
|
+
if (args.displayName !== undefined)
|
|
406
|
+
patch.displayName = args.displayName;
|
|
407
|
+
if (args.transferTarget !== undefined)
|
|
408
|
+
patch.transferTarget = args.transferTarget;
|
|
409
|
+
if (args.department !== undefined)
|
|
410
|
+
patch.department = args.department;
|
|
411
|
+
if (args.kana !== undefined)
|
|
412
|
+
patch.kana = args.kana;
|
|
413
|
+
if (args.email !== undefined)
|
|
414
|
+
patch.email = args.email;
|
|
415
|
+
if (args.note !== undefined)
|
|
416
|
+
patch.note = args.note;
|
|
417
|
+
if (args.enabled !== undefined)
|
|
418
|
+
patch.enabled = args.enabled;
|
|
419
|
+
if (Object.keys(patch).length === 0) {
|
|
420
|
+
return failure(new UsageError("Nothing to change: pass one of displayName, transferTarget, department, kana, email, note or enabled."));
|
|
421
|
+
}
|
|
422
|
+
return attempt(async () => ({ staff: await client.updateStaff(args.staffId, patch, args.revision) }));
|
|
423
|
+
});
|
|
424
|
+
server.registerTool("get_store_hours", {
|
|
425
|
+
description: "Read the tenant's shop clock: 営業時間 (a weekday → ranges map), 定休日 (the stored rule shapes), whether " +
|
|
426
|
+
"祝日 closes the shop, and the 例外日 in a window. Also the calendar `revision` that update_store_hours and " +
|
|
427
|
+
"set_store_hours_exception need. A tenant that never opened 予約設定 answers with the defaults and revision " +
|
|
428
|
+
"1 — nothing is created. Needs agents:read.",
|
|
429
|
+
inputSchema: {
|
|
430
|
+
from: z.string().optional().describe("First day of the 例外日 window, YYYY-MM-DD. Default: today in Japan."),
|
|
431
|
+
to: z.string().optional().describe("Last day of the window, YYYY-MM-DD. Default: 400 days after from; at most 800."),
|
|
432
|
+
},
|
|
433
|
+
annotations: { readOnlyHint: true },
|
|
434
|
+
}, (args) => attempt(async () => client.getStoreHours({ from: args.from, to: args.to })));
|
|
435
|
+
server.registerTool("update_store_hours", {
|
|
436
|
+
description: "Change the shop clock: 営業時間, 定休日, or whether 祝日 closes the shop. `businessHours` and `closedRules` " +
|
|
437
|
+
"are WHOLE replacements — a weekday or a rule you leave out is gone (read get_store_hours first, change, " +
|
|
438
|
+
"write back). An omitted field is left alone. LIVE: the next call answers from the new clock, no publish, so " +
|
|
439
|
+
"confirm with the person first. `revision` is the calendar's, from get_store_hours; a stale one writes " +
|
|
440
|
+
"nothing and answers a conflict. Needs agents:live.",
|
|
441
|
+
inputSchema: {
|
|
442
|
+
revision: z.string().min(1).describe("The calendar revision, from get_store_hours."),
|
|
443
|
+
businessHours: z
|
|
444
|
+
.record(z.string(), z.array(storeHourRange))
|
|
445
|
+
.optional()
|
|
446
|
+
.describe("The whole week: { mon: [{start,end}], … }. A day left out is closed."),
|
|
447
|
+
closedRules: z
|
|
448
|
+
.array(z.record(z.string(), z.unknown()))
|
|
449
|
+
.optional()
|
|
450
|
+
.describe("The whole 定休日 array, in the shapes get_store_hours returned."),
|
|
451
|
+
observeJpHolidays: z.boolean().optional().describe("Whether 祝日 closes the shop."),
|
|
452
|
+
dryRun: z.boolean().optional().describe("true: answer with the calendar the write would leave and save nothing."),
|
|
453
|
+
},
|
|
454
|
+
annotations: { destructiveHint: true },
|
|
455
|
+
}, (args) => {
|
|
456
|
+
const patch = {};
|
|
457
|
+
if (args.businessHours !== undefined)
|
|
458
|
+
patch.businessHours = args.businessHours;
|
|
459
|
+
if (args.closedRules !== undefined)
|
|
460
|
+
patch.closedRules = args.closedRules;
|
|
461
|
+
if (args.observeJpHolidays !== undefined)
|
|
462
|
+
patch.observeJpHolidays = args.observeJpHolidays;
|
|
463
|
+
if (Object.keys(patch).length === 0) {
|
|
464
|
+
return failure(new UsageError("Nothing to change: pass businessHours, closedRules or observeJpHolidays."));
|
|
465
|
+
}
|
|
466
|
+
return attempt(async () => client.updateStoreHours(patch, args.revision, { dryRun: args.dryRun }));
|
|
467
|
+
});
|
|
468
|
+
server.registerTool("set_store_hours_exception", {
|
|
469
|
+
description: "Set one 例外日: `closed` is 臨時休業, `open` is 振替出勤 (with its own hours, or the weekday's when omitted), " +
|
|
470
|
+
"and `inherit` deletes the day's exception and puts it back under the weekly rules (a no-op when there is " +
|
|
471
|
+
"none, and it takes neither hours nor note). The date must exist in the calendar. LIVE: the next call already " +
|
|
472
|
+
"answers from it, no publish. `revision` is the calendar's, from get_store_hours. Needs agents:live.",
|
|
473
|
+
inputSchema: {
|
|
474
|
+
date: z.string().describe("The day, YYYY-MM-DD."),
|
|
475
|
+
revision: z.string().min(1).describe("The calendar revision, from get_store_hours."),
|
|
476
|
+
kind: z.enum(["closed", "open", "inherit"]).describe("closed = 臨時休業, open = 振替出勤, inherit = back to the weekday rule."),
|
|
477
|
+
hours: z.array(storeHourRange).optional().describe("open only: this day's hours. Omitted = the weekday's."),
|
|
478
|
+
note: z.string().optional().describe("A note. Never spoken on a call."),
|
|
479
|
+
dryRun: z.boolean().optional().describe("true: answer with what would change and save nothing."),
|
|
480
|
+
},
|
|
481
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
482
|
+
}, (args) => {
|
|
483
|
+
if (args.kind === "closed" && args.hours !== undefined) {
|
|
484
|
+
return failure(new UsageError("kind=closed takes no hours: a closed day has none."));
|
|
485
|
+
}
|
|
486
|
+
if (args.kind === "inherit" && (args.hours !== undefined || args.note !== undefined)) {
|
|
487
|
+
return failure(new UsageError("kind=inherit only deletes the day's exception, so it takes neither hours nor note."));
|
|
488
|
+
}
|
|
489
|
+
return attempt(async () => client.setStoreHoursException(args.date, { kind: args.kind, ...(args.hours !== undefined ? { hours: args.hours } : {}), ...(args.note !== undefined ? { note: args.note } : {}) }, args.revision, { dryRun: args.dryRun }));
|
|
490
|
+
});
|
|
491
|
+
server.registerTool("get_booking_settings", {
|
|
492
|
+
description: "Read 予約設定: the slot length, the minimum lead time and how far ahead bookings are taken, the " +
|
|
493
|
+
"内容 (what can be booked, and how long it takes), the 担当, whether THIS agent is mounted on the " +
|
|
494
|
+
"calendar, and how many 担当 can actually be booked. Answers the calendar `revision` every write " +
|
|
495
|
+
"below needs — the same counter get_store_hours shows, because 営業時間 and 予約設定 are one " +
|
|
496
|
+
"calendar. A tenant that never opened 予約設定 answers with the defaults and revision 1; nothing is " +
|
|
497
|
+
"created. Needs agents:read.",
|
|
498
|
+
inputSchema: { agentId },
|
|
499
|
+
annotations: { readOnlyHint: true },
|
|
500
|
+
}, (args) => attempt(() => client.getBookingSettings(args.agentId)));
|
|
501
|
+
server.registerTool("update_booking_calendar", {
|
|
502
|
+
description: "Change how a booking is offered: `defaultSlotMinutes` (1–1440; what a 内容 with no duration " +
|
|
503
|
+
"uses), `minLeadMinutes` (0–43200; 0 = 「いま予約できる」) and `maxAdvanceDays` (1–730). An omitted " +
|
|
504
|
+
"field is left alone. These are JSON numbers: \"30\" and null are refused, not converted. LIVE: " +
|
|
505
|
+
"the next call's slots use them, no publish, so confirm with the person first. `revision` is the " +
|
|
506
|
+
"calendar's, from get_booking_settings; a stale one writes nothing and answers a conflict. Needs " +
|
|
507
|
+
"agents:live.",
|
|
508
|
+
inputSchema: {
|
|
509
|
+
revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
|
|
510
|
+
defaultSlotMinutes: z.number().int().min(1).max(1440).optional().describe("Slot length in minutes."),
|
|
511
|
+
minLeadMinutes: z
|
|
512
|
+
.number()
|
|
513
|
+
.int()
|
|
514
|
+
.min(0)
|
|
515
|
+
.max(43200)
|
|
516
|
+
.optional()
|
|
517
|
+
.describe("How long before a slot a booking may no longer be made, in minutes. 0 = right now."),
|
|
518
|
+
maxAdvanceDays: z.number().int().min(1).max(730).optional().describe("How far ahead bookings are taken, in days."),
|
|
519
|
+
dryRun: z.boolean().optional().describe("true: answer with the settings the write would leave and save nothing."),
|
|
520
|
+
},
|
|
521
|
+
annotations: { destructiveHint: true },
|
|
522
|
+
}, (args) => {
|
|
523
|
+
const patch = {};
|
|
524
|
+
if (args.defaultSlotMinutes !== undefined)
|
|
525
|
+
patch.defaultSlotMinutes = args.defaultSlotMinutes;
|
|
526
|
+
if (args.minLeadMinutes !== undefined)
|
|
527
|
+
patch.minLeadMinutes = args.minLeadMinutes;
|
|
528
|
+
if (args.maxAdvanceDays !== undefined)
|
|
529
|
+
patch.maxAdvanceDays = args.maxAdvanceDays;
|
|
530
|
+
if (Object.keys(patch).length === 0) {
|
|
531
|
+
return failure(new UsageError("Nothing to change: pass defaultSlotMinutes, minLeadMinutes or maxAdvanceDays."));
|
|
532
|
+
}
|
|
533
|
+
return attempt(() => client.updateBookingCalendar(patch, args.revision, { dryRun: args.dryRun }));
|
|
534
|
+
});
|
|
535
|
+
server.registerTool("create_booking_service", {
|
|
536
|
+
description: "Add one 内容 — what a booking is for. `durationMinutes` is 1–1440, and null (or omitted) means " +
|
|
537
|
+
"「枠の長さを使う」. LIVE: a mounted agent offers it on its next call, no publish. It carries the " +
|
|
538
|
+
"calendar `revision` too: adding a 内容 changes the same calendar, so two callers holding one " +
|
|
539
|
+
"revision cannot both succeed — the second writes nothing and answers a conflict. Needs agents:live.",
|
|
540
|
+
inputSchema: {
|
|
541
|
+
revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
|
|
542
|
+
name: z.string().min(1).describe("The 内容's name, as the operator sees it (at most 100 characters)."),
|
|
543
|
+
durationMinutes: z
|
|
544
|
+
.number()
|
|
545
|
+
.int()
|
|
546
|
+
.min(1)
|
|
547
|
+
.max(1440)
|
|
548
|
+
.nullable()
|
|
549
|
+
.optional()
|
|
550
|
+
.describe("How long it takes, in minutes. null = use the calendar's slot length."),
|
|
551
|
+
dryRun: z.boolean().optional().describe("true: answer with the 内容 the write would add and save nothing."),
|
|
552
|
+
},
|
|
553
|
+
annotations: { destructiveHint: true, idempotentHint: false },
|
|
554
|
+
}, (args) => attempt(() => client.createBookingService({ name: args.name, ...(args.durationMinutes !== undefined ? { durationMinutes: args.durationMinutes } : {}) }, args.revision, { dryRun: args.dryRun })));
|
|
555
|
+
server.registerTool("update_booking_service", {
|
|
556
|
+
description: "Change one 内容's name and/or durationMinutes (1–1440; null goes back to 「枠の長さを使う」). An " +
|
|
557
|
+
"omitted field is left alone. LIVE: the next call uses it, no publish. `revision` is the calendar's, " +
|
|
558
|
+
"from get_booking_settings. A serviceId that is not this tenant's is a 404. Needs agents:live.",
|
|
559
|
+
inputSchema: {
|
|
560
|
+
serviceId: z.string().min(1).describe("The 内容's id, from get_booking_settings."),
|
|
561
|
+
revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
|
|
562
|
+
name: z.string().min(1).optional().describe("New name (at most 100 characters)."),
|
|
563
|
+
durationMinutes: z
|
|
564
|
+
.number()
|
|
565
|
+
.int()
|
|
566
|
+
.min(1)
|
|
567
|
+
.max(1440)
|
|
568
|
+
.nullable()
|
|
569
|
+
.optional()
|
|
570
|
+
.describe("New duration in minutes. null = use the calendar's slot length."),
|
|
571
|
+
dryRun: z.boolean().optional().describe("true: answer with the 内容 the write would leave and save nothing."),
|
|
572
|
+
},
|
|
573
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
574
|
+
}, (args) => {
|
|
575
|
+
const patch = {};
|
|
576
|
+
if (args.name !== undefined)
|
|
577
|
+
patch.name = args.name;
|
|
578
|
+
if (args.durationMinutes !== undefined)
|
|
579
|
+
patch.durationMinutes = args.durationMinutes;
|
|
580
|
+
if (Object.keys(patch).length === 0) {
|
|
581
|
+
return failure(new UsageError("Nothing to change: pass name or durationMinutes."));
|
|
582
|
+
}
|
|
583
|
+
return attempt(async () => client.updateBookingService(args.serviceId, patch, args.revision, { dryRun: args.dryRun }));
|
|
584
|
+
});
|
|
585
|
+
server.registerTool("create_booking_resource", {
|
|
586
|
+
description: "Add one 担当 — who a booking is made with — with its 予約枠 and the 内容 it may take, in one write. " +
|
|
587
|
+
"`weeklyHours` is { mon: [{start,end}], … }; `serviceIds` omitted leaves it unset, [] means every 内容, " +
|
|
588
|
+
"and a list means only those. Every id must be one of this tenant's own 内容: one that is not refuses " +
|
|
589
|
+
"the whole write and creates nothing. LIVE: the next call already has this 担当, no publish. Carries the " +
|
|
590
|
+
"calendar `revision` from get_booking_settings. Needs agents:live.",
|
|
591
|
+
inputSchema: {
|
|
592
|
+
revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
|
|
593
|
+
name: z.string().min(1).describe("The 担当's name, as the operator sees it (at most 100 characters)."),
|
|
594
|
+
enabled: z.boolean().optional().describe("Whether it takes bookings at all. Defaults to true."),
|
|
595
|
+
weeklyHours: z
|
|
596
|
+
.record(z.string(), z.array(storeHourRange))
|
|
597
|
+
.optional()
|
|
598
|
+
.describe("This 担当's 予約枠: { mon: [{start,end}], … }. A day left out is no opening that day."),
|
|
599
|
+
serviceIds: z
|
|
600
|
+
.array(z.string())
|
|
601
|
+
.optional()
|
|
602
|
+
.describe("The 内容 it may take (ids from get_booking_settings). [] = every 内容; omitted = not set."),
|
|
603
|
+
dryRun: z.boolean().optional().describe("true: answer with the 担当 the write would add and save nothing."),
|
|
604
|
+
},
|
|
605
|
+
annotations: { destructiveHint: true, idempotentHint: false },
|
|
606
|
+
}, (args) => {
|
|
607
|
+
const input = { name: args.name };
|
|
608
|
+
if (args.enabled !== undefined)
|
|
609
|
+
input.enabled = args.enabled;
|
|
610
|
+
if (args.weeklyHours !== undefined)
|
|
611
|
+
input.weeklyHours = args.weeklyHours;
|
|
612
|
+
if (args.serviceIds !== undefined)
|
|
613
|
+
input.serviceIds = args.serviceIds;
|
|
614
|
+
return attempt(() => client.createBookingResource(input, args.revision, { dryRun: args.dryRun }));
|
|
615
|
+
});
|
|
616
|
+
server.registerTool("update_booking_resource", {
|
|
617
|
+
description: "Change one 担当's name, 予約枠, whether it takes bookings, and/or the 内容 it may take. An omitted field " +
|
|
618
|
+
"is left alone; `serviceIds: []` puts it back to every 内容. Taking a 担当 out of service is " +
|
|
619
|
+
"`enabled: false` — nothing here deletes one. LIVE: the next call uses it, no publish. `revision` is the " +
|
|
620
|
+
"calendar's, from get_booking_settings; a stale one writes nothing and answers a conflict. A resourceId " +
|
|
621
|
+
"that is not this tenant's is a 404. Needs agents:live.",
|
|
622
|
+
inputSchema: {
|
|
623
|
+
resourceId: z.string().min(1).describe("The 担当's id, from get_booking_settings."),
|
|
624
|
+
revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
|
|
625
|
+
name: z.string().min(1).optional().describe("New name (at most 100 characters)."),
|
|
626
|
+
enabled: z.boolean().optional().describe("Whether it takes bookings. false takes it out of service."),
|
|
627
|
+
weeklyHours: z
|
|
628
|
+
.record(z.string(), z.array(storeHourRange))
|
|
629
|
+
.optional()
|
|
630
|
+
.describe("The whole week of 予約枠. A day left out is no opening that day."),
|
|
631
|
+
serviceIds: z
|
|
632
|
+
.array(z.string())
|
|
633
|
+
.optional()
|
|
634
|
+
.describe("The 内容 it may take. [] = every 内容. One id that is not this tenant's refuses the whole write."),
|
|
635
|
+
dryRun: z.boolean().optional().describe("true: answer with the 担当 the write would leave and save nothing."),
|
|
636
|
+
},
|
|
637
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
638
|
+
}, (args) => {
|
|
639
|
+
const patch = {};
|
|
640
|
+
if (args.name !== undefined)
|
|
641
|
+
patch.name = args.name;
|
|
642
|
+
if (args.enabled !== undefined)
|
|
643
|
+
patch.enabled = args.enabled;
|
|
644
|
+
if (args.weeklyHours !== undefined)
|
|
645
|
+
patch.weeklyHours = args.weeklyHours;
|
|
646
|
+
if (args.serviceIds !== undefined)
|
|
647
|
+
patch.serviceIds = args.serviceIds;
|
|
648
|
+
if (Object.keys(patch).length === 0) {
|
|
649
|
+
return failure(new UsageError("Nothing to change: pass name, enabled, weeklyHours or serviceIds."));
|
|
650
|
+
}
|
|
651
|
+
return attempt(() => client.updateBookingResource(args.resourceId, patch, args.revision, { dryRun: args.dryRun }));
|
|
652
|
+
});
|
|
653
|
+
server.registerTool("set_agent_booking", {
|
|
654
|
+
description: "Start or stop bookings for this agent. Mounting also retires the 「仮受付」 promise from the 受付サマリー " +
|
|
655
|
+
"in the same write, and is refused when the calendar has no 担当 (an agent that offers booking tools which " +
|
|
656
|
+
"can never return a slot reads to the caller as an agent that lost the request). Unmounting never puts " +
|
|
657
|
+
"予約/変更 back into the 受付サマリー. LIVE: the next call has the booking tools, or has them no longer. " +
|
|
658
|
+
"`revision` is the calendar's, from get_booking_settings. Needs agents:live.",
|
|
659
|
+
inputSchema: {
|
|
660
|
+
agentId: z.string().min(1).describe("The agent whose bookings are being switched."),
|
|
661
|
+
revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
|
|
662
|
+
mounted: z.boolean().describe("true = take bookings, false = stop."),
|
|
663
|
+
dryRun: z.boolean().optional().describe("true: answer with the mount the write would leave and save nothing."),
|
|
664
|
+
},
|
|
665
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
666
|
+
}, (args) => attempt(() => client.setAgentBooking(args.agentId, args.mounted, args.revision, { dryRun: args.dryRun })));
|
|
667
|
+
server.registerTool("list_booking_slots", {
|
|
668
|
+
description: "One 担当's openings on one day (6 by default, at most 20), computed the way a call computes them: the " +
|
|
669
|
+
"担当's 予約枠, the shop clock (定休日・祝日・例外日), the calendar's slot length and lead time, the 内容's " +
|
|
670
|
+
"duration, and the bookings already in the day. Nothing is reserved, and no other customer's details are " +
|
|
671
|
+
"returned. `serviceAllowed: false` means this 担当 does not take that 内容 at all — a different answer " +
|
|
672
|
+
"from a day that is full. Needs agents:read.",
|
|
673
|
+
inputSchema: {
|
|
674
|
+
agentId: z.string().min(1).describe("The agent whose calendar this is."),
|
|
675
|
+
resourceId: z.string().min(1).describe("The 担当's id, from get_booking_settings."),
|
|
676
|
+
date: z.string().min(1).describe("The day to look at, YYYY-MM-DD."),
|
|
677
|
+
serviceId: z
|
|
678
|
+
.string()
|
|
679
|
+
.optional()
|
|
680
|
+
.describe("The 内容 to check. Its duration decides the slot length; a 担当 that does not take it answers no slots."),
|
|
681
|
+
limit: z.number().int().min(1).max(20).optional().describe("How many slots to answer with. Default 6, at most 20."),
|
|
682
|
+
},
|
|
683
|
+
annotations: { readOnlyHint: true },
|
|
684
|
+
}, (args) => attempt(() => client.listBookingSlots(args.agentId, {
|
|
685
|
+
resourceId: args.resourceId,
|
|
686
|
+
date: args.date,
|
|
687
|
+
...(args.serviceId === undefined ? {} : { serviceId: args.serviceId }),
|
|
688
|
+
...(args.limit === undefined ? {} : { limit: args.limit }),
|
|
689
|
+
})));
|
|
690
|
+
const captureSpecField = z.object({
|
|
691
|
+
key: z.string().optional().describe("The item's key. Omit it and the API generates one; a retired key is never reused."),
|
|
692
|
+
label: z.string().min(1).describe("The item's name, as the operator reads it (例: ご希望の日時)."),
|
|
693
|
+
type: z.enum(["text", "datetime", "select", "boolean"]).describe("text / datetime / select / boolean."),
|
|
694
|
+
required: z.boolean().optional().describe("Whether the model must record it."),
|
|
695
|
+
description: z.string().optional().describe("One line telling the model what to put there."),
|
|
696
|
+
options: z.array(z.string()).optional().describe("The choices, for type=select (required then)."),
|
|
697
|
+
default: z.union([z.string(), z.boolean()]).optional().describe("A default the recording step may fill."),
|
|
698
|
+
pattern: z.string().optional().describe("A regex the value must match (at most 200 characters, no nested quantifiers)."),
|
|
699
|
+
patternMessage: z.string().optional().describe("What to say when the value does not match `pattern`."),
|
|
700
|
+
summary: z.boolean().optional().describe("Show it in the サマリー list (at most 3 per spec)."),
|
|
701
|
+
source: z.string().optional().describe("Where the value comes from (the platform's own slot vocabulary)."),
|
|
702
|
+
reviewMode: z
|
|
703
|
+
.enum(["conflict_only", "strict", "never"])
|
|
704
|
+
.optional()
|
|
705
|
+
.describe("How the recorded value is reviewed. conflict_only is the default."),
|
|
706
|
+
});
|
|
707
|
+
server.registerTool("list_capture_specs", {
|
|
708
|
+
description: "Read the tenant's 記録項目 — what the agent records after a call — each with its `key`, the fields it " +
|
|
709
|
+
"records, `enabled`, `revision` (what update_capture_spec must pass) and `affectedAgentIds` (the agents " +
|
|
710
|
+
"mounted with it, i.e. who an edit here reaches). Needs agents:read.",
|
|
711
|
+
inputSchema: {},
|
|
712
|
+
annotations: { readOnlyHint: true },
|
|
713
|
+
}, () => attempt(async () => ({ captureSpecs: await client.listCaptureSpecs() })));
|
|
714
|
+
server.registerTool("create_capture_spec", {
|
|
715
|
+
description: "Add one 記録項目. It is mounted on NO agent yet, so no call changes until something mounts it. Omit " +
|
|
716
|
+
"`instruction` and the API writes one from the label, 場面 and fields — no model is called. `key` is " +
|
|
717
|
+
"generated when omitted (print it back to the operator) and cannot be changed afterwards. Walls: at most " +
|
|
718
|
+
"10 fields, at most 3 of them `summary`, and at most 5 enabled specs per tenant. Needs agents:write.",
|
|
719
|
+
inputSchema: {
|
|
720
|
+
label: z.string().min(1).describe("The name the operator sees (例: 予約内容)."),
|
|
721
|
+
fields: z.array(captureSpecField).describe("The items to record, in the order they should be asked."),
|
|
722
|
+
key: z
|
|
723
|
+
.string()
|
|
724
|
+
.optional()
|
|
725
|
+
.describe("The tool key (lowercase letters, digits, _, 2–30 characters). Omit to let the API generate one."),
|
|
726
|
+
scenario: z.string().optional().describe("One sentence: after what kind of call is this recorded?"),
|
|
727
|
+
instruction: z.string().optional().describe("What to tell the model. Omit to have it generated."),
|
|
728
|
+
confirmationMessage: z.string().optional().describe("What the agent says after recording. Omit for the generic line."),
|
|
729
|
+
enabled: z.boolean().optional().describe("Whether the spec records at all. Default true."),
|
|
730
|
+
},
|
|
731
|
+
annotations: { destructiveHint: false, idempotentHint: false },
|
|
732
|
+
}, (args) => attempt(() => client.createCaptureSpec({
|
|
733
|
+
label: args.label,
|
|
734
|
+
fields: args.fields,
|
|
735
|
+
...(args.key === undefined ? {} : { key: args.key }),
|
|
736
|
+
...(args.scenario === undefined ? {} : { scenario: args.scenario }),
|
|
737
|
+
...(args.instruction === undefined ? {} : { instruction: args.instruction }),
|
|
738
|
+
...(args.confirmationMessage === undefined ? {} : { confirmationMessage: args.confirmationMessage }),
|
|
739
|
+
...(args.enabled === undefined ? {} : { enabled: args.enabled }),
|
|
740
|
+
})));
|
|
741
|
+
server.registerTool("update_capture_spec", {
|
|
742
|
+
description: "Change one 記録項目. An omitted field is left alone; `key` cannot be changed. A hand-written `instruction` " +
|
|
743
|
+
"is never rewritten by a field edit — only a generated one follows the fields. `scenario` and " +
|
|
744
|
+
"`confirmationMessage` take null to clear. LIVE: every agent mounted with this spec records differently " +
|
|
745
|
+
"from its next call, with no publish. `revision` is the spec's, from list_capture_specs; a stale one writes " +
|
|
746
|
+
"nothing and answers a conflict. Needs agents:live.",
|
|
747
|
+
inputSchema: {
|
|
748
|
+
specId: z.string().min(1).describe("The 記録項目's id, from list_capture_specs."),
|
|
749
|
+
revision: z.string().min(1).describe("The spec's revision, from list_capture_specs."),
|
|
750
|
+
label: z.string().min(1).optional().describe("New name."),
|
|
751
|
+
scenario: z.string().optional().describe("New 場面. An empty string clears it."),
|
|
752
|
+
instruction: z.string().optional().describe("A new instruction. Omit to keep (or auto-regenerate) the current one."),
|
|
753
|
+
confirmationMessage: z
|
|
754
|
+
.string()
|
|
755
|
+
.optional()
|
|
756
|
+
.describe("New closing line. An empty string goes back to the generic one."),
|
|
757
|
+
fields: z.array(captureSpecField).optional().describe("The whole field list, replacing the current one."),
|
|
758
|
+
enabled: z.boolean().optional().describe("false stops recording (past records stay)."),
|
|
759
|
+
},
|
|
760
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
761
|
+
}, (args) => {
|
|
762
|
+
const patch = {};
|
|
763
|
+
if (args.label !== undefined)
|
|
764
|
+
patch.label = args.label;
|
|
765
|
+
if (args.scenario !== undefined)
|
|
766
|
+
patch.scenario = args.scenario === "" ? null : args.scenario;
|
|
767
|
+
if (args.instruction !== undefined)
|
|
768
|
+
patch.instruction = args.instruction;
|
|
769
|
+
if (args.confirmationMessage !== undefined) {
|
|
770
|
+
patch.confirmationMessage = args.confirmationMessage === "" ? null : args.confirmationMessage;
|
|
771
|
+
}
|
|
772
|
+
if (args.fields !== undefined)
|
|
773
|
+
patch.fields = args.fields;
|
|
774
|
+
if (args.enabled !== undefined)
|
|
775
|
+
patch.enabled = args.enabled;
|
|
776
|
+
if (Object.keys(patch).length === 0) {
|
|
777
|
+
return failure(new UsageError("Nothing to change: pass label, scenario, instruction, confirmationMessage, fields or enabled."));
|
|
778
|
+
}
|
|
779
|
+
return attempt(() => client.updateCaptureSpec(args.specId, patch, args.revision));
|
|
780
|
+
});
|
|
781
|
+
server.registerTool("get_agent_capture", {
|
|
782
|
+
description: "Read which 記録項目 this agent records after a call: the mounted specs (each with its own revision), the " +
|
|
783
|
+
"whole mounted id set, `enabledMountedCount`, the agent's `revision` (what set_agent_capture must pass) and " +
|
|
784
|
+
"`readiness` — whether a call on THIS agent would leave a summary, and if not why. An agent with nothing " +
|
|
785
|
+
"mounted records nothing even when other agents in the shop do. Needs agents:read.",
|
|
786
|
+
inputSchema: {
|
|
787
|
+
agentId: z.string().min(1).describe("The agent to read."),
|
|
788
|
+
},
|
|
789
|
+
annotations: { readOnlyHint: true },
|
|
790
|
+
}, (args) => attempt(() => client.getAgentCapture(args.agentId)));
|
|
791
|
+
server.registerTool("set_agent_capture", {
|
|
792
|
+
description: "Replace the whole set of 記録項目 this agent records. `captureSpecIds: []` unmounts everything (the specs " +
|
|
793
|
+
"stay in the tenant; this agent just records none). A repeated id counts once, and one id that is not " +
|
|
794
|
+
"this tenant's refuses the whole write — nothing is unmounted. LIVE: the next call's hangup writes its " +
|
|
795
|
+
"summary from the new set, no publish. `revision` is the agent's, from get_agent_capture; a stale one " +
|
|
796
|
+
"writes nothing and answers a conflict. Needs agents:live.",
|
|
797
|
+
inputSchema: {
|
|
798
|
+
agentId: z.string().min(1).describe("The agent whose recordings are being set."),
|
|
799
|
+
revision: z.string().min(1).describe("The agent's revision, from get_agent_capture."),
|
|
800
|
+
captureSpecIds: z
|
|
801
|
+
.array(z.string())
|
|
802
|
+
.describe("The whole set, from list_capture_specs. [] records nothing."),
|
|
803
|
+
},
|
|
804
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
805
|
+
}, (args) => attempt(() => client.setAgentCapture(args.agentId, args.captureSpecIds, args.revision)));
|
|
806
|
+
server.registerTool("upload_document", {
|
|
807
|
+
description: "Upload a 資料 (a manual, a price list) as TEXT or as FILES and get an upload job back at once — the " +
|
|
808
|
+
"extraction runs after the response. Send either `rawText` or `filePaths`, never both: the files are " +
|
|
809
|
+
"read from this machine and posted as multipart, so a PDF never has to be turned into base64 for you " +
|
|
810
|
+
"(.txt / .md / .pdf / .docx / .xlsx, up to 10 files and 20MiB in total, 32,000 characters after " +
|
|
811
|
+
"merging; several files become ONE manual in the order given). Poll with get_document_upload_job " +
|
|
812
|
+
"until status is succeeded, then read the document with get_document (its id is `documentId`). Same " +
|
|
813
|
+
"`idempotencyKey` + same content answers the SAME job and spends nothing more; the same key with " +
|
|
814
|
+
"different content is refused (409) — use a new key to send new content. `dryRun` runs the same " +
|
|
815
|
+
"validation and answers the usage preview (size, model, remaining allowance) without writing a job, " +
|
|
816
|
+
"spending the budget or calling a model. Limits: 10 uploads per key per hour and never above the " +
|
|
817
|
+
"tenant's own remaining allowance, one running extraction per key / two per tenant. Needs agents:write.",
|
|
818
|
+
inputSchema: {
|
|
819
|
+
title: z.string().min(1).describe("The 資料's name, as the operator sees it (at most 200 characters)."),
|
|
820
|
+
idempotencyKey: z
|
|
821
|
+
.string()
|
|
822
|
+
.min(1)
|
|
823
|
+
.describe("1–200 characters, chosen by you. A retry with the same key and the same content is safe."),
|
|
824
|
+
rawText: z
|
|
825
|
+
.string()
|
|
826
|
+
.min(1)
|
|
827
|
+
.optional()
|
|
828
|
+
.describe("The text of the 資料 (at most 32,000 characters). Exclusive with filePaths."),
|
|
829
|
+
filePaths: z
|
|
830
|
+
.array(z.string())
|
|
831
|
+
.optional()
|
|
832
|
+
.describe("Paths on THIS machine to files to upload (.txt / .md / .pdf / .docx / .xlsx; at most 10). The " +
|
|
833
|
+
"server never receives a path. Exclusive with rawText."),
|
|
834
|
+
templateId: z
|
|
835
|
+
.string()
|
|
836
|
+
.optional()
|
|
837
|
+
.describe("An onboarding template id (from list_agent_templates) whose facts/用件 keys the extraction should line up with."),
|
|
838
|
+
dryRun: z
|
|
839
|
+
.boolean()
|
|
840
|
+
.optional()
|
|
841
|
+
.describe("true: validate and report the usage only — no job, no budget spent, no model call."),
|
|
842
|
+
},
|
|
843
|
+
annotations: { destructiveHint: false, idempotentHint: true },
|
|
844
|
+
}, (args) => attempt(async () => {
|
|
845
|
+
const metadata = {
|
|
846
|
+
title: args.title,
|
|
847
|
+
idempotencyKey: args.idempotencyKey,
|
|
848
|
+
...(args.templateId === undefined ? {} : { templateId: args.templateId }),
|
|
849
|
+
};
|
|
850
|
+
const filePaths = args.filePaths ?? [];
|
|
851
|
+
if (filePaths.length > 0 && args.rawText !== undefined) {
|
|
852
|
+
throw new UsageError("Send either rawText or filePaths, not both: the API takes the text OR the files.");
|
|
853
|
+
}
|
|
854
|
+
if (filePaths.length === 0) {
|
|
855
|
+
if (args.rawText === undefined)
|
|
856
|
+
throw new UsageError("Send rawText, or filePaths to upload files.");
|
|
857
|
+
return client.uploadDocument({ ...metadata, rawText: args.rawText }, { dryRun: args.dryRun === true });
|
|
858
|
+
}
|
|
859
|
+
const files = await Promise.all(filePaths.map(async (path) => ({ filename: basename(path), bytes: new Uint8Array(await readFile(path)) })));
|
|
860
|
+
return client.uploadDocument({ ...metadata, files }, { dryRun: args.dryRun === true });
|
|
861
|
+
}));
|
|
862
|
+
server.registerTool("get_document_upload_job", {
|
|
863
|
+
description: "Read one upload job: `status` (queued / running / succeeded / failed / timed_out), the `documentId` it " +
|
|
864
|
+
"produced, the `error` when it failed, the deadline, and `retryAfterSeconds` to wait before polling " +
|
|
865
|
+
"again. A job past its deadline reads as timed_out and its result can no longer be written; post the " +
|
|
866
|
+
"same idempotencyKey again to see the same job, or use a new key to start a new one. Reading writes " +
|
|
867
|
+
"nothing. Needs agents:read.",
|
|
868
|
+
inputSchema: {
|
|
869
|
+
jobId: z.string().min(1).describe("The job id that upload_document returned."),
|
|
870
|
+
},
|
|
871
|
+
annotations: { readOnlyHint: true },
|
|
872
|
+
}, (args) => attempt(() => client.getDocumentUploadJob(args.jobId)));
|
|
873
|
+
server.registerTool("get_document", {
|
|
874
|
+
description: "Read one 資料: its summary (title, status, mode, character count), what it is wired into (the agents " +
|
|
875
|
+
"and graph nodes in `references`), the extracted `fields` (each with its candidates, sources and review " +
|
|
876
|
+
"state) and the `revision`. The raw text is never returned. This id is what create_from_template's " +
|
|
877
|
+
"`documentId` takes. Needs agents:read.",
|
|
878
|
+
inputSchema: {
|
|
879
|
+
documentId: z.string().min(1).describe("The document id, from get_document_upload_job."),
|
|
880
|
+
},
|
|
881
|
+
annotations: { readOnlyHint: true },
|
|
882
|
+
}, (args) => attempt(() => client.getDocument(args.documentId)));
|
|
883
|
+
server.registerTool("replace_document", {
|
|
884
|
+
description: "Replace a 資料's content and facts with another 資料's, keeping its id — so every agent already " +
|
|
885
|
+
"reading it switches over, with no re-creation and no publish (LIVE: the next call reads the new " +
|
|
886
|
+
"facts). The source must be in the same shop, already extracted (get_document_upload_job's status " +
|
|
887
|
+
"succeeded), and used by no agent or graph node; otherwise nothing is written. Every fact arrives " +
|
|
888
|
+
"PENDING — confirmations are not carried over, because they were decisions about the old text — and " +
|
|
889
|
+
"a fact the new source does not mention is kept as an empty row (「まだない情報」) instead of its old " +
|
|
890
|
+
"value. `revision` is the target's and `sourceRevision` the source's, both from get_document; if " +
|
|
891
|
+
"anyone confirmed or edited a fact since, nothing is written and the answer is a conflict. No model " +
|
|
892
|
+
"is called. `dryRun` answers the same changes without writing. Needs agents:live.",
|
|
893
|
+
inputSchema: {
|
|
894
|
+
documentId: z.string().min(1).describe("The 資料 to replace (its id stays)."),
|
|
895
|
+
sourceDocumentId: z
|
|
896
|
+
.string()
|
|
897
|
+
.min(1)
|
|
898
|
+
.describe("The 資料 the new content comes from — same shop, extracted, bound to nothing."),
|
|
899
|
+
sourceRevision: z
|
|
900
|
+
.string()
|
|
901
|
+
.min(1)
|
|
902
|
+
.describe("The source's revision, from get_document."),
|
|
903
|
+
revision: z
|
|
904
|
+
.string()
|
|
905
|
+
.min(1)
|
|
906
|
+
.describe("The target's revision, from get_document. It moves when a fact is confirmed or edited."),
|
|
907
|
+
dryRun: z
|
|
908
|
+
.boolean()
|
|
909
|
+
.optional()
|
|
910
|
+
.describe("true: report the same changes and nothing written."),
|
|
911
|
+
},
|
|
912
|
+
annotations: { destructiveHint: true, idempotentHint: true },
|
|
913
|
+
}, (args) => attempt(() => client.replaceDocument(args.documentId, { sourceDocumentId: args.sourceDocumentId, sourceRevision: args.sourceRevision }, args.revision, { dryRun: args.dryRun === true })));
|
|
143
914
|
return server;
|
|
144
915
|
}
|