@kumion/cli 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
+ import { basename } from "node:path";
2
4
  import { z } from "zod";
3
- import { ApiError } from "./client.js";
5
+ import { ApiError, isTextFile, specText } from "./client.js";
4
6
  import { describeError, UsageError } from "./errors.js";
5
7
  export const MAX_TEST_RUN_WAIT_SECONDS = 120;
6
8
  const TERMINAL = new Set(["passed", "failed", "could_not_run", "timeout", "cancelled"]);
@@ -22,6 +24,9 @@ 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();
25
30
  const flowStep = z
26
31
  .object({
27
32
  key: z.string().min(1).describe("The step's key (an existing one, or a new key with action \"add\")."),
@@ -66,8 +71,9 @@ export function createKumionMcpServer(client, options) {
66
71
  }, () => attempt(async () => ({ templates: await client.listAgentTemplates() })));
67
72
  server.registerTool("create_agent_from_template", {
68
73
  description: "Create a DRAFT agent from an onboarding template plus the business name, optionally reading a website " +
69
- "(`url`) or a document already uploaded and extracted on the Portal's 資料 screen (`documentId`; an API key " +
70
- "cannot upload one). Only facts the source actually states are filled; the rest come back as 「まだない情報」. " +
74
+ "(`url`) or a document already uploaded and extracted on the Portal's 資料 screen (`documentId`; upload it " +
75
+ "with `upload_document` first). Only facts the source actually states are filled; the rest come back as " +
76
+ "「まだない情報」. " +
71
77
  "Nothing is published and no fact is confirmed. Needs agents:write.",
72
78
  inputSchema: {
73
79
  templateId: z.string().min(1).describe("A template id from list_agent_templates."),
@@ -97,6 +103,53 @@ export function createKumionMcpServer(client, options) {
97
103
  inputSchema: { agentId },
98
104
  annotations: { readOnlyHint: true },
99
105
  }, (args) => attempt(() => client.getAgent(args.agentId)));
106
+ server.registerTool("get_agent_spec", {
107
+ description: "Download the agent's 応対仕様書 — the document that says, in Japanese, how the agent answers: the opening, " +
108
+ "the flow of a call, transfers, booking, the facts it may read out, what it records, who it notifies, and the " +
109
+ "AI instructions verbatim. `version` is published (the default), draft, or a version number. `format` is pdf " +
110
+ "(the default), docx (Word) or markdown; markdown comes back as the document itself, and pdf/docx are written " +
111
+ "to `outputPath`, which those two formats require. Chapters marked 〔出力時点〕 read settings that no version " +
112
+ "froze (hours, booking, 記録項目, 資料, 転送先, notifications) and are as they stand now. Needs agents:read.",
113
+ inputSchema: {
114
+ agentId,
115
+ version: z.string().min(1).optional().describe("published (default), draft, or a version number such as 3."),
116
+ format: z
117
+ .enum(["pdf", "docx", "markdown"])
118
+ .optional()
119
+ .describe("The output format: pdf (default), docx, or markdown. The first two answer with a file."),
120
+ outputPath: z
121
+ .string()
122
+ .min(1)
123
+ .optional()
124
+ .describe("Local file to write the document to. Required for pdf and docx — a binary file cannot travel as tool text. " +
125
+ "Ignored for markdown, which is returned as text."),
126
+ },
127
+ annotations: { readOnlyHint: true },
128
+ }, async (args) => {
129
+ try {
130
+ const file = await client.getAgentSpec(args.agentId, {
131
+ ...(args.version === undefined ? {} : { version: args.version }),
132
+ ...(args.format === undefined ? {} : { format: args.format }),
133
+ });
134
+ if (isTextFile(file)) {
135
+ return { content: [{ type: "text", text: specText(file) }] };
136
+ }
137
+ if (args.outputPath === undefined) {
138
+ throw new UsageError(`format=${args.format ?? "pdf"} answers with a file, not text: pass outputPath (a local path to write it to). ` +
139
+ "Use format=markdown for the document as text.");
140
+ }
141
+ await writeFile(args.outputPath, file.body);
142
+ return json({
143
+ path: args.outputPath,
144
+ bytes: file.body.byteLength,
145
+ filename: file.filename,
146
+ contentType: file.contentType,
147
+ });
148
+ }
149
+ catch (err) {
150
+ return failure(err);
151
+ }
152
+ });
100
153
  server.registerTool("get_call_flow", {
101
154
  description: "Read the agent's draft call flow the way the canvas assistant reads it: `editLayer` says whether it is edited " +
102
155
  "as 用件 (`flow`, with the 用件 subject, what each one says and asks for, and the confirmed caller examples) or " +
@@ -164,7 +217,11 @@ export function createKumionMcpServer(client, options) {
164
217
  server.registerTool("patch_agent", {
165
218
  description: "Edit an agent's draft (never goes live by itself — publish_agent does that). `revision` must be the one " +
166
219
  "get_agent returned when you read the draft you are changing; if the draft changed since, nothing is " +
167
- "written and you get a conflict: read it again and re-apply. Needs agents:write.",
220
+ "written and you get a conflict: read it again and re-apply. External send settings (a webhook, the pre-call " +
221
+ "fetch, a notification, a transfer target, the opening recording, an IVR menu's recording) may only be sent " +
222
+ "back unchanged: adding, " +
223
+ "removing or changing one is refused with `external_field_closed`, and the Portal's canvas is where those " +
224
+ "are edited. Needs agents:write.",
168
225
  inputSchema: {
169
226
  agentId,
170
227
  revision: z.string().min(1).describe("The draft revision your change is based on, from get_agent."),
@@ -246,7 +303,9 @@ export function createKumionMcpServer(client, options) {
246
303
  server.registerTool("publish_agent", {
247
304
  description: "Publish the agent's draft so callers get it. Runs the same pre-publish check as the Portal first and " +
248
305
  "publishes only if it passes; there is no way to skip it. Can take a few minutes. On failure the " +
249
- "failing cases are returned. Needs agents:publish.",
306
+ "failing cases are returned. A success carries `unconfirmedFacts`: how many of the agent's 資料 facts " +
307
+ "nobody has confirmed yet — for each of them the agent says it will check and call back instead of " +
308
+ "stating it (confirm_facts confirms them). Needs agents:publish.",
250
309
  inputSchema: {
251
310
  agentId,
252
311
  revision: z.string().optional().describe("Refuse to publish if the draft is no longer at this revision."),
@@ -307,6 +366,25 @@ export function createKumionMcpServer(client, options) {
307
366
  },
308
367
  annotations: { idempotentHint: false },
309
368
  }, (args) => attempt(() => client.createCall(args.agentId, args.campaignContactId, args.variables, args.phoneNumber)));
369
+ server.registerTool("create_scheduled_call", {
370
+ description: "Schedule one outbound call at a stated time; the dialer places it once, with no automatic redial. " +
371
+ "scheduledAt must carry a timezone offset (2026-10-31T13:00:00+09:00). Needs calls:create.",
372
+ inputSchema: {
373
+ agentId,
374
+ phoneNumber: z.string().describe("Domestic Japanese number to dial."),
375
+ scheduledAt: z.string().describe("When to dial, ISO 8601 with a timezone offset."),
376
+ },
377
+ annotations: { idempotentHint: false },
378
+ }, (args) => attempt(() => client.createScheduledCall(args.agentId, args.phoneNumber, args.scheduledAt)));
379
+ server.registerTool("list_scheduled_calls", {
380
+ description: "List the calls scheduled through the API, newest first (at most 100), with state and reason. Needs calls:read.",
381
+ inputSchema: {},
382
+ annotations: { readOnlyHint: true },
383
+ }, () => attempt(async () => ({ scheduledCalls: await client.listScheduledCalls() })));
384
+ server.registerTool("cancel_scheduled_call", {
385
+ description: "Cancel a scheduled call that has not started. Needs calls:create.",
386
+ inputSchema: { scheduledCallId: z.string().min(1).describe("The id from create_scheduled_call or list_scheduled_calls.") },
387
+ }, (args) => attempt(() => client.cancelScheduledCall(args.scheduledCallId)));
310
388
  const callId = z.string().min(1).describe("The call's id, from list_calls.");
311
389
  server.registerTool("list_calls", {
312
390
  description: "List the tenant's call history, newest first, one page at a time (default 20, at most 100); `total` " +
@@ -410,5 +488,495 @@ export function createKumionMcpServer(client, options) {
410
488
  }
411
489
  return attempt(async () => ({ staff: await client.updateStaff(args.staffId, patch, args.revision) }));
412
490
  });
491
+ server.registerTool("get_store_hours", {
492
+ description: "Read the tenant's shop clock: 営業時間 (a weekday → ranges map), 定休日 (the stored rule shapes), whether " +
493
+ "祝日 closes the shop, and the 例外日 in a window. Also the calendar `revision` that update_store_hours and " +
494
+ "set_store_hours_exception need. A tenant that never opened 予約設定 answers with the defaults and revision " +
495
+ "1 — nothing is created. Needs agents:read.",
496
+ inputSchema: {
497
+ from: z.string().optional().describe("First day of the 例外日 window, YYYY-MM-DD. Default: today in Japan."),
498
+ to: z.string().optional().describe("Last day of the window, YYYY-MM-DD. Default: 400 days after from; at most 800."),
499
+ },
500
+ annotations: { readOnlyHint: true },
501
+ }, (args) => attempt(async () => client.getStoreHours({ from: args.from, to: args.to })));
502
+ server.registerTool("update_store_hours", {
503
+ description: "Change the shop clock: 営業時間, 定休日, or whether 祝日 closes the shop. `businessHours` and `closedRules` " +
504
+ "are WHOLE replacements — a weekday or a rule you leave out is gone (read get_store_hours first, change, " +
505
+ "write back). An omitted field is left alone. LIVE: the next call answers from the new clock, no publish, so " +
506
+ "confirm with the person first. `revision` is the calendar's, from get_store_hours; a stale one writes " +
507
+ "nothing and answers a conflict. Needs agents:live.",
508
+ inputSchema: {
509
+ revision: z.string().min(1).describe("The calendar revision, from get_store_hours."),
510
+ businessHours: z
511
+ .record(z.string(), z.array(storeHourRange))
512
+ .optional()
513
+ .describe("The whole week: { mon: [{start,end}], … }. A day left out is closed."),
514
+ closedRules: z
515
+ .array(z.record(z.string(), z.unknown()))
516
+ .optional()
517
+ .describe("The whole 定休日 array, in the shapes get_store_hours returned."),
518
+ observeJpHolidays: z.boolean().optional().describe("Whether 祝日 closes the shop."),
519
+ dryRun: z.boolean().optional().describe("true: answer with the calendar the write would leave and save nothing."),
520
+ },
521
+ annotations: { destructiveHint: true },
522
+ }, (args) => {
523
+ const patch = {};
524
+ if (args.businessHours !== undefined)
525
+ patch.businessHours = args.businessHours;
526
+ if (args.closedRules !== undefined)
527
+ patch.closedRules = args.closedRules;
528
+ if (args.observeJpHolidays !== undefined)
529
+ patch.observeJpHolidays = args.observeJpHolidays;
530
+ if (Object.keys(patch).length === 0) {
531
+ return failure(new UsageError("Nothing to change: pass businessHours, closedRules or observeJpHolidays."));
532
+ }
533
+ return attempt(async () => client.updateStoreHours(patch, args.revision, { dryRun: args.dryRun }));
534
+ });
535
+ server.registerTool("set_store_hours_exception", {
536
+ description: "Set one 例外日: `closed` is 臨時休業, `open` is 振替出勤 (with its own hours, or the weekday's when omitted), " +
537
+ "and `inherit` deletes the day's exception and puts it back under the weekly rules (a no-op when there is " +
538
+ "none, and it takes neither hours nor note). The date must exist in the calendar. LIVE: the next call already " +
539
+ "answers from it, no publish. `revision` is the calendar's, from get_store_hours. Needs agents:live.",
540
+ inputSchema: {
541
+ date: z.string().describe("The day, YYYY-MM-DD."),
542
+ revision: z.string().min(1).describe("The calendar revision, from get_store_hours."),
543
+ kind: z.enum(["closed", "open", "inherit"]).describe("closed = 臨時休業, open = 振替出勤, inherit = back to the weekday rule."),
544
+ hours: z.array(storeHourRange).optional().describe("open only: this day's hours. Omitted = the weekday's."),
545
+ note: z.string().optional().describe("A note. Never spoken on a call."),
546
+ dryRun: z.boolean().optional().describe("true: answer with what would change and save nothing."),
547
+ },
548
+ annotations: { destructiveHint: true, idempotentHint: true },
549
+ }, (args) => {
550
+ if (args.kind === "closed" && args.hours !== undefined) {
551
+ return failure(new UsageError("kind=closed takes no hours: a closed day has none."));
552
+ }
553
+ if (args.kind === "inherit" && (args.hours !== undefined || args.note !== undefined)) {
554
+ return failure(new UsageError("kind=inherit only deletes the day's exception, so it takes neither hours nor note."));
555
+ }
556
+ 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 }));
557
+ });
558
+ server.registerTool("get_booking_settings", {
559
+ description: "Read 予約設定: the slot length, the minimum lead time and how far ahead bookings are taken, the " +
560
+ "内容 (what can be booked, and how long it takes), the 担当, whether THIS agent is mounted on the " +
561
+ "calendar, and how many 担当 can actually be booked. Answers the calendar `revision` every write " +
562
+ "below needs — the same counter get_store_hours shows, because 営業時間 and 予約設定 are one " +
563
+ "calendar. A tenant that never opened 予約設定 answers with the defaults and revision 1; nothing is " +
564
+ "created. Needs agents:read.",
565
+ inputSchema: { agentId },
566
+ annotations: { readOnlyHint: true },
567
+ }, (args) => attempt(() => client.getBookingSettings(args.agentId)));
568
+ server.registerTool("update_booking_calendar", {
569
+ description: "Change how a booking is offered: `defaultSlotMinutes` (1–1440; what a 内容 with no duration " +
570
+ "uses), `minLeadMinutes` (0–43200; 0 = 「いま予約できる」) and `maxAdvanceDays` (1–730). An omitted " +
571
+ "field is left alone. These are JSON numbers: \"30\" and null are refused, not converted. LIVE: " +
572
+ "the next call's slots use them, no publish, so confirm with the person first. `revision` is the " +
573
+ "calendar's, from get_booking_settings; a stale one writes nothing and answers a conflict. Needs " +
574
+ "agents:live.",
575
+ inputSchema: {
576
+ revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
577
+ defaultSlotMinutes: z.number().int().min(1).max(1440).optional().describe("Slot length in minutes."),
578
+ minLeadMinutes: z
579
+ .number()
580
+ .int()
581
+ .min(0)
582
+ .max(43200)
583
+ .optional()
584
+ .describe("How long before a slot a booking may no longer be made, in minutes. 0 = right now."),
585
+ maxAdvanceDays: z.number().int().min(1).max(730).optional().describe("How far ahead bookings are taken, in days."),
586
+ dryRun: z.boolean().optional().describe("true: answer with the settings the write would leave and save nothing."),
587
+ },
588
+ annotations: { destructiveHint: true },
589
+ }, (args) => {
590
+ const patch = {};
591
+ if (args.defaultSlotMinutes !== undefined)
592
+ patch.defaultSlotMinutes = args.defaultSlotMinutes;
593
+ if (args.minLeadMinutes !== undefined)
594
+ patch.minLeadMinutes = args.minLeadMinutes;
595
+ if (args.maxAdvanceDays !== undefined)
596
+ patch.maxAdvanceDays = args.maxAdvanceDays;
597
+ if (Object.keys(patch).length === 0) {
598
+ return failure(new UsageError("Nothing to change: pass defaultSlotMinutes, minLeadMinutes or maxAdvanceDays."));
599
+ }
600
+ return attempt(() => client.updateBookingCalendar(patch, args.revision, { dryRun: args.dryRun }));
601
+ });
602
+ server.registerTool("create_booking_service", {
603
+ description: "Add one 内容 — what a booking is for. `durationMinutes` is 1–1440, and null (or omitted) means " +
604
+ "「枠の長さを使う」. LIVE: a mounted agent offers it on its next call, no publish. It carries the " +
605
+ "calendar `revision` too: adding a 内容 changes the same calendar, so two callers holding one " +
606
+ "revision cannot both succeed — the second writes nothing and answers a conflict. Needs agents:live.",
607
+ inputSchema: {
608
+ revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
609
+ name: z.string().min(1).describe("The 内容's name, as the operator sees it (at most 100 characters)."),
610
+ durationMinutes: z
611
+ .number()
612
+ .int()
613
+ .min(1)
614
+ .max(1440)
615
+ .nullable()
616
+ .optional()
617
+ .describe("How long it takes, in minutes. null = use the calendar's slot length."),
618
+ dryRun: z.boolean().optional().describe("true: answer with the 内容 the write would add and save nothing."),
619
+ },
620
+ annotations: { destructiveHint: true, idempotentHint: false },
621
+ }, (args) => attempt(() => client.createBookingService({ name: args.name, ...(args.durationMinutes !== undefined ? { durationMinutes: args.durationMinutes } : {}) }, args.revision, { dryRun: args.dryRun })));
622
+ server.registerTool("update_booking_service", {
623
+ description: "Change one 内容's name and/or durationMinutes (1–1440; null goes back to 「枠の長さを使う」). An " +
624
+ "omitted field is left alone. LIVE: the next call uses it, no publish. `revision` is the calendar's, " +
625
+ "from get_booking_settings. A serviceId that is not this tenant's is a 404. Needs agents:live.",
626
+ inputSchema: {
627
+ serviceId: z.string().min(1).describe("The 内容's id, from get_booking_settings."),
628
+ revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
629
+ name: z.string().min(1).optional().describe("New name (at most 100 characters)."),
630
+ durationMinutes: z
631
+ .number()
632
+ .int()
633
+ .min(1)
634
+ .max(1440)
635
+ .nullable()
636
+ .optional()
637
+ .describe("New duration in minutes. null = use the calendar's slot length."),
638
+ dryRun: z.boolean().optional().describe("true: answer with the 内容 the write would leave and save nothing."),
639
+ },
640
+ annotations: { destructiveHint: true, idempotentHint: true },
641
+ }, (args) => {
642
+ const patch = {};
643
+ if (args.name !== undefined)
644
+ patch.name = args.name;
645
+ if (args.durationMinutes !== undefined)
646
+ patch.durationMinutes = args.durationMinutes;
647
+ if (Object.keys(patch).length === 0) {
648
+ return failure(new UsageError("Nothing to change: pass name or durationMinutes."));
649
+ }
650
+ return attempt(async () => client.updateBookingService(args.serviceId, patch, args.revision, { dryRun: args.dryRun }));
651
+ });
652
+ server.registerTool("create_booking_resource", {
653
+ description: "Add one 担当 — who a booking is made with — with its 予約枠 and the 内容 it may take, in one write. " +
654
+ "`weeklyHours` is { mon: [{start,end}], … }; `serviceIds` omitted leaves it unset, [] means every 内容, " +
655
+ "and a list means only those. Every id must be one of this tenant's own 内容: one that is not refuses " +
656
+ "the whole write and creates nothing. LIVE: the next call already has this 担当, no publish. Carries the " +
657
+ "calendar `revision` from get_booking_settings. Needs agents:live.",
658
+ inputSchema: {
659
+ revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
660
+ name: z.string().min(1).describe("The 担当's name, as the operator sees it (at most 100 characters)."),
661
+ enabled: z.boolean().optional().describe("Whether it takes bookings at all. Defaults to true."),
662
+ weeklyHours: z
663
+ .record(z.string(), z.array(storeHourRange))
664
+ .optional()
665
+ .describe("This 担当's 予約枠: { mon: [{start,end}], … }. A day left out is no opening that day."),
666
+ serviceIds: z
667
+ .array(z.string())
668
+ .optional()
669
+ .describe("The 内容 it may take (ids from get_booking_settings). [] = every 内容; omitted = not set."),
670
+ dryRun: z.boolean().optional().describe("true: answer with the 担当 the write would add and save nothing."),
671
+ },
672
+ annotations: { destructiveHint: true, idempotentHint: false },
673
+ }, (args) => {
674
+ const input = { name: args.name };
675
+ if (args.enabled !== undefined)
676
+ input.enabled = args.enabled;
677
+ if (args.weeklyHours !== undefined)
678
+ input.weeklyHours = args.weeklyHours;
679
+ if (args.serviceIds !== undefined)
680
+ input.serviceIds = args.serviceIds;
681
+ return attempt(() => client.createBookingResource(input, args.revision, { dryRun: args.dryRun }));
682
+ });
683
+ server.registerTool("update_booking_resource", {
684
+ description: "Change one 担当's name, 予約枠, whether it takes bookings, and/or the 内容 it may take. An omitted field " +
685
+ "is left alone; `serviceIds: []` puts it back to every 内容. Taking a 担当 out of service is " +
686
+ "`enabled: false` — nothing here deletes one. LIVE: the next call uses it, no publish. `revision` is the " +
687
+ "calendar's, from get_booking_settings; a stale one writes nothing and answers a conflict. A resourceId " +
688
+ "that is not this tenant's is a 404. Needs agents:live.",
689
+ inputSchema: {
690
+ resourceId: z.string().min(1).describe("The 担当's id, from get_booking_settings."),
691
+ revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
692
+ name: z.string().min(1).optional().describe("New name (at most 100 characters)."),
693
+ enabled: z.boolean().optional().describe("Whether it takes bookings. false takes it out of service."),
694
+ weeklyHours: z
695
+ .record(z.string(), z.array(storeHourRange))
696
+ .optional()
697
+ .describe("The whole week of 予約枠. A day left out is no opening that day."),
698
+ serviceIds: z
699
+ .array(z.string())
700
+ .optional()
701
+ .describe("The 内容 it may take. [] = every 内容. One id that is not this tenant's refuses the whole write."),
702
+ dryRun: z.boolean().optional().describe("true: answer with the 担当 the write would leave and save nothing."),
703
+ },
704
+ annotations: { destructiveHint: true, idempotentHint: true },
705
+ }, (args) => {
706
+ const patch = {};
707
+ if (args.name !== undefined)
708
+ patch.name = args.name;
709
+ if (args.enabled !== undefined)
710
+ patch.enabled = args.enabled;
711
+ if (args.weeklyHours !== undefined)
712
+ patch.weeklyHours = args.weeklyHours;
713
+ if (args.serviceIds !== undefined)
714
+ patch.serviceIds = args.serviceIds;
715
+ if (Object.keys(patch).length === 0) {
716
+ return failure(new UsageError("Nothing to change: pass name, enabled, weeklyHours or serviceIds."));
717
+ }
718
+ return attempt(() => client.updateBookingResource(args.resourceId, patch, args.revision, { dryRun: args.dryRun }));
719
+ });
720
+ server.registerTool("set_agent_booking", {
721
+ description: "Start or stop bookings for this agent. Mounting also retires the 「仮受付」 promise from the 受付サマリー " +
722
+ "in the same write, and is refused when the calendar has no 担当 (an agent that offers booking tools which " +
723
+ "can never return a slot reads to the caller as an agent that lost the request). Unmounting never puts " +
724
+ "予約/変更 back into the 受付サマリー. LIVE: the next call has the booking tools, or has them no longer. " +
725
+ "`revision` is the calendar's, from get_booking_settings. Needs agents:live.",
726
+ inputSchema: {
727
+ agentId: z.string().min(1).describe("The agent whose bookings are being switched."),
728
+ revision: z.string().min(1).describe("The calendar revision, from get_booking_settings."),
729
+ mounted: z.boolean().describe("true = take bookings, false = stop."),
730
+ dryRun: z.boolean().optional().describe("true: answer with the mount the write would leave and save nothing."),
731
+ },
732
+ annotations: { destructiveHint: true, idempotentHint: true },
733
+ }, (args) => attempt(() => client.setAgentBooking(args.agentId, args.mounted, args.revision, { dryRun: args.dryRun })));
734
+ server.registerTool("list_booking_slots", {
735
+ description: "One 担当's openings on one day (6 by default, at most 20), computed the way a call computes them: the " +
736
+ "担当's 予約枠, the shop clock (定休日・祝日・例外日), the calendar's slot length and lead time, the 内容's " +
737
+ "duration, and the bookings already in the day. Nothing is reserved, and no other customer's details are " +
738
+ "returned. `serviceAllowed: false` means this 担当 does not take that 内容 at all — a different answer " +
739
+ "from a day that is full. Needs agents:read.",
740
+ inputSchema: {
741
+ agentId: z.string().min(1).describe("The agent whose calendar this is."),
742
+ resourceId: z.string().min(1).describe("The 担当's id, from get_booking_settings."),
743
+ date: z.string().min(1).describe("The day to look at, YYYY-MM-DD."),
744
+ serviceId: z
745
+ .string()
746
+ .optional()
747
+ .describe("The 内容 to check. Its duration decides the slot length; a 担当 that does not take it answers no slots."),
748
+ limit: z.number().int().min(1).max(20).optional().describe("How many slots to answer with. Default 6, at most 20."),
749
+ },
750
+ annotations: { readOnlyHint: true },
751
+ }, (args) => attempt(() => client.listBookingSlots(args.agentId, {
752
+ resourceId: args.resourceId,
753
+ date: args.date,
754
+ ...(args.serviceId === undefined ? {} : { serviceId: args.serviceId }),
755
+ ...(args.limit === undefined ? {} : { limit: args.limit }),
756
+ })));
757
+ const captureSpecField = z.object({
758
+ key: z.string().optional().describe("The item's key. Omit it and the API generates one; a retired key is never reused."),
759
+ label: z.string().min(1).describe("The item's name, as the operator reads it (例: ご希望の日時)."),
760
+ type: z.enum(["text", "datetime", "select", "boolean"]).describe("text / datetime / select / boolean."),
761
+ required: z.boolean().optional().describe("Whether the model must record it."),
762
+ description: z.string().optional().describe("One line telling the model what to put there."),
763
+ options: z.array(z.string()).optional().describe("The choices, for type=select (required then)."),
764
+ default: z.union([z.string(), z.boolean()]).optional().describe("A default the recording step may fill."),
765
+ pattern: z.string().optional().describe("A regex the value must match (at most 200 characters, no nested quantifiers)."),
766
+ patternMessage: z.string().optional().describe("What to say when the value does not match `pattern`."),
767
+ summary: z.boolean().optional().describe("Show it in the サマリー list (at most 3 per spec)."),
768
+ source: z.string().optional().describe("Where the value comes from (the platform's own slot vocabulary)."),
769
+ reviewMode: z
770
+ .enum(["conflict_only", "strict", "never"])
771
+ .optional()
772
+ .describe("How the recorded value is reviewed. conflict_only is the default."),
773
+ });
774
+ server.registerTool("list_capture_specs", {
775
+ description: "Read the tenant's 記録項目 — what the agent records after a call — each with its `key`, the fields it " +
776
+ "records, `enabled`, `revision` (what update_capture_spec must pass) and `affectedAgentIds` (the agents " +
777
+ "mounted with it, i.e. who an edit here reaches). Needs agents:read.",
778
+ inputSchema: {},
779
+ annotations: { readOnlyHint: true },
780
+ }, () => attempt(async () => ({ captureSpecs: await client.listCaptureSpecs() })));
781
+ server.registerTool("create_capture_spec", {
782
+ description: "Add one 記録項目. It is mounted on NO agent yet, so no call changes until something mounts it. Omit " +
783
+ "`instruction` and the API writes one from the label, 場面 and fields — no model is called. `key` is " +
784
+ "generated when omitted (print it back to the operator) and cannot be changed afterwards. Walls: at most " +
785
+ "10 fields, at most 3 of them `summary`, and at most 20 enabled specs per tenant. Needs agents:write.",
786
+ inputSchema: {
787
+ label: z.string().min(1).describe("The name the operator sees (例: 予約内容)."),
788
+ fields: z.array(captureSpecField).describe("The items to record, in the order they should be asked."),
789
+ key: z
790
+ .string()
791
+ .optional()
792
+ .describe("The tool key (lowercase letters, digits, _, 2–30 characters). Omit to let the API generate one."),
793
+ scenario: z.string().optional().describe("One sentence: after what kind of call is this recorded?"),
794
+ instruction: z.string().optional().describe("What to tell the model. Omit to have it generated."),
795
+ confirmationMessage: z.string().optional().describe("What the agent says after recording. Omit for the generic line."),
796
+ enabled: z.boolean().optional().describe("Whether the spec records at all. Default true."),
797
+ },
798
+ annotations: { destructiveHint: false, idempotentHint: false },
799
+ }, (args) => attempt(() => client.createCaptureSpec({
800
+ label: args.label,
801
+ fields: args.fields,
802
+ ...(args.key === undefined ? {} : { key: args.key }),
803
+ ...(args.scenario === undefined ? {} : { scenario: args.scenario }),
804
+ ...(args.instruction === undefined ? {} : { instruction: args.instruction }),
805
+ ...(args.confirmationMessage === undefined ? {} : { confirmationMessage: args.confirmationMessage }),
806
+ ...(args.enabled === undefined ? {} : { enabled: args.enabled }),
807
+ })));
808
+ server.registerTool("update_capture_spec", {
809
+ description: "Change one 記録項目. An omitted field is left alone; `key` cannot be changed. A hand-written `instruction` " +
810
+ "is never rewritten by a field edit — only a generated one follows the fields. `scenario` and " +
811
+ "`confirmationMessage` take an empty string to clear. LIVE: every agent mounted with this spec records differently " +
812
+ "from its next call, with no publish. `revision` is the spec's, from list_capture_specs; a stale one writes " +
813
+ "nothing and answers a conflict. Needs agents:live.",
814
+ inputSchema: {
815
+ specId: z.string().min(1).describe("The 記録項目's id, from list_capture_specs."),
816
+ revision: z.string().min(1).describe("The spec's revision, from list_capture_specs."),
817
+ label: z.string().min(1).optional().describe("New name."),
818
+ scenario: z.string().optional().describe("New 場面. An empty string clears it."),
819
+ instruction: z.string().optional().describe("A new instruction. Omit to keep (or auto-regenerate) the current one."),
820
+ confirmationMessage: z
821
+ .string()
822
+ .optional()
823
+ .describe("New closing line. An empty string goes back to the generic one."),
824
+ fields: z.array(captureSpecField).optional().describe("The whole field list, replacing the current one."),
825
+ enabled: z.boolean().optional().describe("false stops recording (past records stay)."),
826
+ },
827
+ annotations: { destructiveHint: true, idempotentHint: true },
828
+ }, (args) => {
829
+ const patch = {};
830
+ if (args.label !== undefined)
831
+ patch.label = args.label;
832
+ if (args.scenario !== undefined)
833
+ patch.scenario = args.scenario === "" ? null : args.scenario;
834
+ if (args.instruction !== undefined)
835
+ patch.instruction = args.instruction;
836
+ if (args.confirmationMessage !== undefined) {
837
+ patch.confirmationMessage = args.confirmationMessage === "" ? null : args.confirmationMessage;
838
+ }
839
+ if (args.fields !== undefined)
840
+ patch.fields = args.fields;
841
+ if (args.enabled !== undefined)
842
+ patch.enabled = args.enabled;
843
+ if (Object.keys(patch).length === 0) {
844
+ return failure(new UsageError("Nothing to change: pass label, scenario, instruction, confirmationMessage, fields or enabled."));
845
+ }
846
+ return attempt(() => client.updateCaptureSpec(args.specId, patch, args.revision));
847
+ });
848
+ server.registerTool("get_agent_capture", {
849
+ description: "Read which 記録項目 this agent records after a call: the mounted specs (each with its own revision), the " +
850
+ "whole mounted id set, `enabledMountedCount`, the agent's `revision` (what set_agent_capture must pass) and " +
851
+ "`readiness` — whether a call on THIS agent would leave a summary, and if not why. An agent with nothing " +
852
+ "mounted records nothing even when other agents in the shop do. Needs agents:read.",
853
+ inputSchema: {
854
+ agentId: z.string().min(1).describe("The agent to read."),
855
+ },
856
+ annotations: { readOnlyHint: true },
857
+ }, (args) => attempt(() => client.getAgentCapture(args.agentId)));
858
+ server.registerTool("set_agent_capture", {
859
+ description: "Replace the whole set of 記録項目 this agent records. `captureSpecIds: []` unmounts everything (the specs " +
860
+ "stay in the tenant; this agent just records none). A repeated id counts once, and one id that is not " +
861
+ "this tenant's refuses the whole write — nothing is unmounted. LIVE: the next call's hangup writes its " +
862
+ "summary from the new set, no publish. `revision` is the agent's, from get_agent_capture; a stale one " +
863
+ "writes nothing and answers a conflict. Needs agents:live.",
864
+ inputSchema: {
865
+ agentId: z.string().min(1).describe("The agent whose recordings are being set."),
866
+ revision: z.string().min(1).describe("The agent's revision, from get_agent_capture."),
867
+ captureSpecIds: z
868
+ .array(z.string())
869
+ .describe("The whole set, from list_capture_specs. [] records nothing."),
870
+ },
871
+ annotations: { destructiveHint: true, idempotentHint: true },
872
+ }, (args) => attempt(() => client.setAgentCapture(args.agentId, args.captureSpecIds, args.revision)));
873
+ server.registerTool("upload_document", {
874
+ description: "Upload a 資料 (a manual, a price list) as TEXT or as FILES and get an upload job back at once — the " +
875
+ "extraction runs after the response. Send either `rawText` or `filePaths`, never both: the files are " +
876
+ "read from this machine and posted as multipart, so a PDF never has to be turned into base64 for you " +
877
+ "(.txt / .md / .pdf / .docx / .xlsx, up to 10 files and 20MiB in total, 32,000 characters after " +
878
+ "merging; several files become ONE manual in the order given). Poll with get_document_upload_job " +
879
+ "until status is succeeded, then read the document with get_document (its id is `documentId`). Same " +
880
+ "`idempotencyKey` + same content answers the SAME job and spends nothing more; the same key with " +
881
+ "different content is refused (409) — use a new key to send new content. `dryRun` runs the same " +
882
+ "validation and answers the usage preview (size, model, remaining allowance) without writing a job, " +
883
+ "spending the budget or calling a model. Limits: 10 uploads per key per hour and never above the " +
884
+ "tenant's own remaining allowance, one running extraction per key / two per tenant. Needs agents:write.",
885
+ inputSchema: {
886
+ title: z.string().min(1).describe("The 資料's name, as the operator sees it (at most 200 characters)."),
887
+ idempotencyKey: z
888
+ .string()
889
+ .min(1)
890
+ .describe("1–200 characters, chosen by you. A retry with the same key and the same content is safe."),
891
+ rawText: z
892
+ .string()
893
+ .min(1)
894
+ .optional()
895
+ .describe("The text of the 資料 (at most 32,000 characters). Exclusive with filePaths."),
896
+ filePaths: z
897
+ .array(z.string())
898
+ .optional()
899
+ .describe("Paths on THIS machine to files to upload (.txt / .md / .pdf / .docx / .xlsx; at most 10). The " +
900
+ "server never receives a path. Exclusive with rawText."),
901
+ templateId: z
902
+ .string()
903
+ .optional()
904
+ .describe("An onboarding template id (from list_agent_templates) whose facts/用件 keys the extraction should line up with."),
905
+ dryRun: z
906
+ .boolean()
907
+ .optional()
908
+ .describe("true: validate and report the usage only — no job, no budget spent, no model call."),
909
+ },
910
+ annotations: { destructiveHint: false, idempotentHint: true },
911
+ }, (args) => attempt(async () => {
912
+ const metadata = {
913
+ title: args.title,
914
+ idempotencyKey: args.idempotencyKey,
915
+ ...(args.templateId === undefined ? {} : { templateId: args.templateId }),
916
+ };
917
+ const filePaths = args.filePaths ?? [];
918
+ if (filePaths.length > 0 && args.rawText !== undefined) {
919
+ throw new UsageError("Send either rawText or filePaths, not both: the API takes the text OR the files.");
920
+ }
921
+ if (filePaths.length === 0) {
922
+ if (args.rawText === undefined)
923
+ throw new UsageError("Send rawText, or filePaths to upload files.");
924
+ return client.uploadDocument({ ...metadata, rawText: args.rawText }, { dryRun: args.dryRun === true });
925
+ }
926
+ const files = await Promise.all(filePaths.map(async (path) => ({ filename: basename(path), bytes: new Uint8Array(await readFile(path)) })));
927
+ return client.uploadDocument({ ...metadata, files }, { dryRun: args.dryRun === true });
928
+ }));
929
+ server.registerTool("get_document_upload_job", {
930
+ description: "Read one upload job: `status` (queued / running / succeeded / failed / timed_out), the `documentId` it " +
931
+ "produced, the `error` when it failed, the deadline, and `retryAfterSeconds` to wait before polling " +
932
+ "again. A job past its deadline reads as timed_out and its result can no longer be written; post the " +
933
+ "same idempotencyKey again to see the same job, or use a new key to start a new one. Reading writes " +
934
+ "nothing. Needs agents:read.",
935
+ inputSchema: {
936
+ jobId: z.string().min(1).describe("The job id that upload_document returned."),
937
+ },
938
+ annotations: { readOnlyHint: true },
939
+ }, (args) => attempt(() => client.getDocumentUploadJob(args.jobId)));
940
+ server.registerTool("get_document", {
941
+ description: "Read one 資料: its summary (title, status, mode, character count), what it is wired into (the agents " +
942
+ "and graph nodes in `references`), the extracted `fields` (each with its candidates, sources and review " +
943
+ "state) and the `revision`. The raw text is never returned. This id is what create_agent_from_template's " +
944
+ "`documentId` takes. Needs agents:read.",
945
+ inputSchema: {
946
+ documentId: z.string().min(1).describe("The document id, from get_document_upload_job."),
947
+ },
948
+ annotations: { readOnlyHint: true },
949
+ }, (args) => attempt(() => client.getDocument(args.documentId)));
950
+ server.registerTool("replace_document", {
951
+ description: "Replace a 資料's content and facts with another 資料's, keeping its id — so every agent already " +
952
+ "reading it switches over, with no re-creation and no publish (LIVE: the next call reads the new " +
953
+ "facts). The source must be in the same shop, already extracted (get_document_upload_job's status " +
954
+ "succeeded), and used by no agent or graph node; otherwise nothing is written. Every fact arrives " +
955
+ "PENDING — confirmations are not carried over, because they were decisions about the old text — and " +
956
+ "a fact the new source does not mention is kept as an empty row (「まだない情報」) instead of its old " +
957
+ "value. `revision` is the target's and `sourceRevision` the source's, both from get_document; if " +
958
+ "anyone confirmed or edited a fact since, nothing is written and the answer is a conflict. No model " +
959
+ "is called. `dryRun` answers the same changes without writing. Needs agents:live.",
960
+ inputSchema: {
961
+ documentId: z.string().min(1).describe("The 資料 to replace (its id stays)."),
962
+ sourceDocumentId: z
963
+ .string()
964
+ .min(1)
965
+ .describe("The 資料 the new content comes from — same shop, extracted, bound to nothing."),
966
+ sourceRevision: z
967
+ .string()
968
+ .min(1)
969
+ .describe("The source's revision, from get_document."),
970
+ revision: z
971
+ .string()
972
+ .min(1)
973
+ .describe("The target's revision, from get_document. It moves when a fact is confirmed or edited."),
974
+ dryRun: z
975
+ .boolean()
976
+ .optional()
977
+ .describe("true: report the same changes and nothing written."),
978
+ },
979
+ annotations: { destructiveHint: true, idempotentHint: true },
980
+ }, (args) => attempt(() => client.replaceDocument(args.documentId, { sourceDocumentId: args.sourceDocumentId, sourceRevision: args.sourceRevision }, args.revision, { dryRun: args.dryRun === true })));
413
981
  return server;
414
982
  }