@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/dist/main.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { readFile } from "node:fs/promises";
2
+ import { basename } from "node:path";
2
3
  import { parseArgs } from "node:util";
3
- import { ApiError, KumionClient } from "./client.js";
4
+ import { ApiError, KumionClient, } from "./client.js";
4
5
  import { DEFAULT_BASE_URL, keyPrefix, looksLikeApiKey, normalizeBaseUrl, resolveCredentials, } from "./credentials.js";
5
6
  import { DEFAULT_DEVICE_SCOPES, deviceLogin } from "./device-login.js";
6
7
  import { describeError, ReportedFailure, UsageError } from "./errors.js";
7
- export const VERSION = "0.2.0";
8
+ export const VERSION = "0.4.0";
8
9
  const HELP = `kumion — manage your Kumion voice agents over the Partner API
9
10
 
10
11
  Usage: kumion <command> [options]
@@ -28,6 +29,151 @@ Agents
28
29
  Edit the draft (never goes live by itself)
29
30
  agents publish <agentId> [--revision <rev>]
30
31
  Publish the draft through the pre-publish check
32
+ agents opening-name <agentId> --revision <rev> (--on | --off)
33
+ Whether the opening line uses the caller's name (a draft write:
34
+ it reaches callers with the next publish)
35
+ agents availability <agentId> --revision <rev> [--operating-hours-file <path>] [--off-hours-file <path>]
36
+ Set when the agent answers (受付時間) and what happens to a
37
+ call outside it. Each file holds the JSON of that setting, or
38
+ null to clear it. LIVE: callers get it at once, no publish
39
+ (needs a key with agents:live)
40
+ agents create-from-template --template <id> --business-name <name> [--name <name>]
41
+ [--url <url> | --document <documentId>] [--idempotency-key <key>]
42
+ Create a DRAFT agent from an onboarding template. With no
43
+ source, every fact is 「まだない情報」. With a URL (same site,
44
+ up to 10 pages) or a document already uploaded and extracted
45
+ on the Portal's 資料 screen, only facts the source actually
46
+ states are filled, and the response lists both. Nothing is
47
+ published and no fact is confirmed.
48
+
49
+ Flow
50
+ flow get <agentId> Read the draft flow the way the canvas assistant reads it:
51
+ the 用件 (what each one says and asks for), which layer edits
52
+ it (用件 or steps), the staff a 用件 may transfer to, and the
53
+ pre-publish findings
54
+ flow update <agentId> --revision <rev> --patch-file <path> [--dry-run]
55
+ Change the 用件 — what each one says and asks for, and whether it
56
+ hands the caller to a staff member — with the same arguments and
57
+ the same rules the canvas assistant uses. A draft write: it
58
+ reaches callers with the next publish. --dry-run prints the
59
+ change and saves nothing
60
+ flow edit-steps <agentId> --revision <rev> --ops-file <path> [--dry-run]
61
+ Change a step-by-step flow — add or remove a step, join or part two,
62
+ one step's setting, one connection's words — as one batch, with
63
+ the same operations and rules the canvas assistant uses. The batch
64
+ is atomic (one refused operation refuses all of them) and moves the
65
+ revision once. --dry-run prints the change and saves nothing
66
+
67
+ Templates
68
+ templates list List the onboarding templates and their ids
69
+
70
+ Staff (the people a 用件 can transfer a call to)
71
+ staff list List the スタッフ with their transfer key, 転送先 and revision
72
+ staff create --name <name> [--transfer-target <number>] [--department <text>]
73
+ [--kana <text>] [--email <address>] [--note <text>] [--enabled false]
74
+ Register a スタッフ. The transfer key is generated for you and
75
+ printed back (--json shows it). A new row reaches no call until
76
+ a 用件's 転送 names its key
77
+ staff update <staffId> --revision <rev> [--name <name>] [--transfer-target <number>]
78
+ [--department <text>] [--kana <text>] [--email <address>] [--note <text>]
79
+ [--enabled true|false]
80
+ Change a スタッフ; an empty value (--note "") clears a field.
81
+ LIVE: the next call already transfers to the new value, no
82
+ publish (needs a key with agents:live). --enabled false takes
83
+ them out of the 転送 candidates
84
+
85
+ Hours (when the shop is open — one calendar for the whole tenant)
86
+ hours get [--from <date>] [--to <date>]
87
+ Show 営業時間, 定休日, 祝日休み and the 例外日 in a window,
88
+ with the revision the two writes below need
89
+ hours update --revision <rev> [--business-hours-file <path>] [--closed-rules-file <path>]
90
+ [--observe-jp-holidays true|false] [--dry-run]
91
+ Change the clock. businessHours and closedRules are whole
92
+ replacements; an omitted field is left alone. LIVE: the next
93
+ call answers from it, no publish (needs agents:live)
94
+ hours exception set <date> --revision <rev> --kind closed|open|inherit [--hours-file <path>]
95
+ [--note <text>] [--dry-run]
96
+ One 例外日: closed = 臨時休業, open = 振替出勤 (with its own
97
+ hours, or the weekday's), inherit = back to the weekly rule.
98
+ LIVE (needs agents:live)
99
+
100
+ Booking (予約設定 — one calendar for the tenant, read per agent)
101
+ booking get <agentId> Show the slot length, the lead time and the horizon, the
102
+ 内容 and 担当, and whether this agent takes bookings, with
103
+ the revision every booking write below needs
104
+ booking calendar update --revision <rev> --patch-file <path> [--dry-run]
105
+ Change 枠の長さ (defaultSlotMinutes), 直前予約の締め切り
106
+ (minLeadMinutes) and/or 何日先まで (maxAdvanceDays); an
107
+ omitted field is left alone. LIVE (needs agents:live)
108
+ booking services create --revision <rev> --data-file <path> [--dry-run]
109
+ Add one 内容: name, and durationMinutes (1–1440, or null to
110
+ use the slot length). LIVE (needs agents:live)
111
+ booking services update <serviceId> --revision <rev> --patch-file <path> [--dry-run]
112
+ Change one 内容's name and/or durationMinutes; null goes
113
+ back to the slot length. LIVE (needs agents:live)
114
+ booking resources create --revision <rev> --data-file <path> [--dry-run]
115
+ Add one 担当: name, enabled, weeklyHours (予約枠) and the
116
+ serviceIds it takes ([] = every 内容). One 内容 that is not
117
+ this tenant's refuses the whole write. LIVE (needs agents:live)
118
+ booking resources update <resourceId> --revision <rev> --patch-file <path> [--dry-run]
119
+ Change a 担当; an omitted field is left alone, enabled=false
120
+ takes it out of service without deleting it. LIVE
121
+ booking mount <agentId> --mounted true|false --revision <rev> [--dry-run]
122
+ Start or stop taking bookings. Mounting also retires the
123
+ 「仮受付」 promise from the 受付サマリー, in the same write.
124
+ LIVE (needs agents:live)
125
+ booking slots <agentId> --resource <resourceId> --date <YYYY-MM-DD>
126
+ [--service <serviceId>] [--limit <n>]
127
+ One 担当's openings on one day, computed the way a call
128
+ computes them (6 by default, at most 20). Reads only —
129
+ nothing is reserved (needs agents:read)
130
+
131
+ Facts (the agent's 資料) facts list <agentId> List the facts with their state and revision
132
+ facts edit <agentId> <factId> --revision <rev> --value <text>
133
+ Confirm one fact with a new value. LIVE (needs agents:live)
134
+ facts confirm <agentId> [--fact <factId> ...]
135
+ Confirm pending facts as extracted (all of them without
136
+ --fact; a fact whose candidates disagree is skipped). LIVE
137
+
138
+ Capture specs (記録項目 — what the agent records after a call)
139
+ capture-specs list List the 記録項目 with their revision and the agents each is
140
+ mounted on
141
+ capture-specs create --data-file <path>
142
+ Add one 記録項目 (name, fields, optional 場面). Without an
143
+ instruction the API writes one from those — no model is
144
+ called. It is mounted on no agent yet, so no call changes
145
+ (needs agents:write)
146
+ capture-specs update <specId> --revision <rev> --patch-file <path>
147
+ Change one 記録項目; an omitted field is left alone and key is
148
+ frozen. LIVE: every agent mounted with it records differently
149
+ from its next call (needs agents:live)
150
+ agents capture get <agentId> Show which 記録項目 this agent records, its revision, and
151
+ whether THIS agent would record after a call
152
+ agents capture set <agentId> --revision <rev> (--spec <specId> ... | --clear)
153
+ Replace the whole set this agent records (--spec repeats;
154
+ --clear is []; the two cannot be combined). LIVE: the next
155
+ call's summary is written from the new set, no publish
156
+ (needs agents:live)
157
+
158
+ Documents (資料 — the source an agent's facts are extracted from)
159
+ documents upload (--text-file <path> | --file <path> [--file <path> ...])
160
+ --title <title> --idempotency-key <key> [--template <templateId>] [--dry-run]
161
+ Upload a 資料 — its text, or files (.txt / .md / .pdf / .docx /
162
+ .xlsx, up to 10 files and 20MiB) — and get a job back at once
163
+ (the extraction runs after). Several files become ONE manual,
164
+ in the order given. Same key + same content answers the same
165
+ job; different content under the same key is refused
166
+ (needs agents:write). --dry-run shows the size, the model and
167
+ the remaining allowance, and calls no model
168
+ documents jobs get <jobId> Show an upload job: status, the document it produced, the error.
169
+ Exits non-zero when the job failed or timed out
170
+ documents get <documentId> Show a 資料: its fields, review state and revision (not the text)
171
+ documents replace <documentId> --source <sourceDocumentId> --source-revision <rev> --revision <rev>
172
+ [--dry-run]
173
+ Give a 資料 another document's content and facts, keeping its id, so the
174
+ agents already reading it switch with no re-creation. Every fact comes back
175
+ pending, and a fact the new source does not mention stays as an empty row.
176
+ LIVE: the next call reads the new facts. Needs agents:live
31
177
 
32
178
  Test runs
33
179
  test-runs start <agentId> [--no-wait] [--interval <sec>] [--timeout <sec>]
@@ -36,8 +182,9 @@ Test runs
36
182
  test-runs list <agentId> [--limit <n>]
37
183
 
38
184
  Calls
39
- calls create <agentId> [--campaign-contact <id>]
40
- Start a web call with the agent
185
+ calls create <agentId> [--to <phone>] [--campaign-contact <id>] [--var <name>=<value> ...]
186
+ Start a web call with the agent; with --to, dial that
187
+ domestic number instead (--var is read as {{vars.<name>}})
41
188
  calls list [--agent <id>] [--channel webcall|sip_did|trigger] [--from <iso>] [--to <iso>]
42
189
  [--search <text>] [--limit <n>] [--offset <n>]
43
190
  List the tenant's call history, newest first (20 per page)
@@ -137,11 +284,13 @@ async function dispatch(argv, deps) {
137
284
  }
138
285
  if (group === "mcp")
139
286
  return mcpServe(argv.slice(1), deps);
140
- const handler = COMMANDS[`${group} ${command ?? ""}`.trim()];
141
- if (!handler) {
287
+ const two = `${group} ${command ?? ""}`.trim();
288
+ const three = rest.length > 0 ? `${two} ${rest[0]}` : two;
289
+ const name = Object.hasOwn(COMMANDS, three) ? three : Object.hasOwn(COMMANDS, two) ? two : null;
290
+ if (!name) {
142
291
  throw new UsageError(`Unknown command: kumion ${[group, command].filter(Boolean).join(" ")}\nRun \`kumion --help\` for usage.`);
143
292
  }
144
- return handler(rest, deps);
293
+ return COMMANDS[name](name === three ? rest.slice(1) : rest, deps);
145
294
  }
146
295
  async function clientFor(values, deps) {
147
296
  const creds = await resolveCredentials({
@@ -156,7 +305,7 @@ async function clientFor(values, deps) {
156
305
  function printJson(deps, value) {
157
306
  deps.io.out(JSON.stringify(value, null, 2));
158
307
  }
159
- const COMMANDS = {
308
+ export const COMMANDS = {
160
309
  "auth login": authLogin,
161
310
  "auth status": authStatus,
162
311
  "auth list": authList,
@@ -166,6 +315,39 @@ const COMMANDS = {
166
315
  "agents get": agentsGet,
167
316
  "agents patch": agentsPatch,
168
317
  "agents publish": agentsPublish,
318
+ "agents opening-name": agentsOpeningName,
319
+ "agents availability": agentsAvailability,
320
+ "agents create-from-template": agentsCreateFromTemplate,
321
+ "flow get": flowGet,
322
+ "flow update": flowUpdate,
323
+ "flow edit-steps": flowEditSteps,
324
+ "templates list": templatesList,
325
+ "staff list": staffList,
326
+ "staff create": staffCreate,
327
+ "staff update": staffUpdate,
328
+ "hours get": hoursGet,
329
+ "hours update": hoursUpdate,
330
+ "hours exception set": hoursExceptionSet,
331
+ "booking get": bookingGet,
332
+ "booking calendar update": bookingCalendarUpdate,
333
+ "booking services create": bookingServicesCreate,
334
+ "booking services update": bookingServicesUpdate,
335
+ "booking resources create": bookingResourcesCreate,
336
+ "booking resources update": bookingResourcesUpdate,
337
+ "booking mount": bookingMount,
338
+ "booking slots": bookingSlots,
339
+ "facts list": factsList,
340
+ "facts edit": factsEdit,
341
+ "facts confirm": factsConfirm,
342
+ "capture-specs list": captureSpecsList,
343
+ "capture-specs create": captureSpecsCreate,
344
+ "capture-specs update": captureSpecsUpdate,
345
+ "agents capture get": agentsCaptureGet,
346
+ "agents capture set": agentsCaptureSet,
347
+ "documents upload": documentsUpload,
348
+ "documents jobs get": documentsJobsGet,
349
+ "documents get": documentsGet,
350
+ "documents replace": documentsReplace,
169
351
  "test-runs start": testRunsStart,
170
352
  "test-runs get": testRunsGet,
171
353
  "test-runs list": testRunsList,
@@ -424,6 +606,902 @@ async function agentsPatch(args, deps) {
424
606
  deps.io.out(`Draft saved. New revision: ${view.revision}\nNothing is live until you run \`kumion agents publish ${agentId}\`.`);
425
607
  return 0;
426
608
  }
609
+ function requireRevision(revision, what) {
610
+ if (!revision)
611
+ throw new UsageError(`Pass --revision <rev> — ${what}`);
612
+ return revision;
613
+ }
614
+ const AGENT_REVISION_HELP = "the revision `kumion agents get` showed when you read the agent you are changing.";
615
+ async function agentsOpeningName(args, deps) {
616
+ const { values, positionals } = parse(args, { revision: { type: "string" }, on: { type: "boolean" }, off: { type: "boolean" } });
617
+ const agentId = need(positionals, 0, "agentId");
618
+ if (values.on === values.off)
619
+ throw new UsageError("Pass --on or --off.");
620
+ const revision = requireRevision(values.revision, AGENT_REVISION_HELP);
621
+ const view = await (await clientFor(values, deps)).setOpeningName(agentId, values.on === true, revision);
622
+ if (values.json)
623
+ printJson(deps, view);
624
+ else
625
+ deps.io.out(`Saved: the opening line ${values.on ? "uses" : "does not use"} the caller's name. New revision: ${view.revision}\n` +
626
+ `It reaches callers with the next publish (\`kumion agents publish ${agentId}\`).`);
627
+ return 0;
628
+ }
629
+ async function agentsAvailability(args, deps) {
630
+ const { values, positionals } = parse(args, {
631
+ revision: { type: "string" },
632
+ "operating-hours-file": { type: "string" },
633
+ "off-hours-file": { type: "string" },
634
+ });
635
+ const agentId = need(positionals, 0, "agentId");
636
+ const patch = {};
637
+ if (values["operating-hours-file"])
638
+ patch.operatingHours = await readJsonFile(values["operating-hours-file"]);
639
+ if (values["off-hours-file"])
640
+ patch.offHoursPolicy = await readJsonFile(values["off-hours-file"]);
641
+ if (!("operatingHours" in patch) && !("offHoursPolicy" in patch)) {
642
+ throw new UsageError("Nothing to change. Pass --operating-hours-file and/or --off-hours-file.");
643
+ }
644
+ const revision = requireRevision(values.revision, AGENT_REVISION_HELP);
645
+ const view = await (await clientFor(values, deps)).setAvailability(agentId, patch, revision);
646
+ if (values.json)
647
+ printJson(deps, view);
648
+ else
649
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${view.revision}`);
650
+ return 0;
651
+ }
652
+ function factLine(fact) {
653
+ const state = fact.reviewState === "pending" ? `pending${fact.candidates.length > 0 ? ` (candidates: ${fact.candidates.join(" / ")})` : ""}` : (fact.value ?? "");
654
+ return `${fact.id} ${fact.label}: ${state} [revision ${fact.revision}]`;
655
+ }
656
+ async function factsList(args, deps) {
657
+ const { values, positionals } = parse(args, {});
658
+ const agentId = need(positionals, 0, "agentId");
659
+ const facts = await (await clientFor(values, deps)).listFacts(agentId);
660
+ if (values.json)
661
+ printJson(deps, { facts });
662
+ else if (facts.length === 0)
663
+ deps.io.out("No facts.");
664
+ else
665
+ for (const fact of facts)
666
+ deps.io.out(factLine(fact));
667
+ return 0;
668
+ }
669
+ async function templatesList(args, deps) {
670
+ const { values } = parse(args, {});
671
+ const templates = await (await clientFor(values, deps)).listAgentTemplates();
672
+ if (values.json) {
673
+ printJson(deps, { templates });
674
+ return 0;
675
+ }
676
+ if (templates.length === 0)
677
+ deps.io.out("No templates.");
678
+ else {
679
+ for (const template of templates) {
680
+ deps.io.out(`${template.id} ${template.label}`);
681
+ deps.io.out(` ${template.summary}`);
682
+ deps.io.out(` 用件: ${template.intents.map((intent) => intent.label).join("、")}`);
683
+ deps.io.out(` 事実: ${template.facts.map((fact) => fact.label).join("、")}`);
684
+ }
685
+ }
686
+ return 0;
687
+ }
688
+ async function agentsCreateFromTemplate(args, deps) {
689
+ const { values } = parse(args, {
690
+ template: { type: "string" },
691
+ "business-name": { type: "string" },
692
+ name: { type: "string" },
693
+ url: { type: "string" },
694
+ document: { type: "string" },
695
+ "idempotency-key": { type: "string" },
696
+ });
697
+ if (!values.template)
698
+ throw new UsageError("Pass --template <id> (see `kumion templates list`).");
699
+ if (!values["business-name"])
700
+ throw new UsageError("Pass --business-name <name> — it names the agent and greets the caller.");
701
+ if (values.url && values.document)
702
+ throw new UsageError("Pass --url or --document, not both.");
703
+ const result = await (await clientFor(values, deps)).createAgentFromTemplate({
704
+ templateId: values.template,
705
+ businessName: values["business-name"],
706
+ ...(values.name ? { name: values.name } : {}),
707
+ ...(values.url ? { url: values.url } : {}),
708
+ ...(values.document ? { documentId: values.document } : {}),
709
+ ...(values["idempotency-key"] ? { idempotencyKey: values["idempotency-key"] } : {}),
710
+ });
711
+ if (values.json) {
712
+ printJson(deps, result);
713
+ return 0;
714
+ }
715
+ deps.io.out(`Created ${result.agent.name} (${result.agent.id}) — draft, not published.`);
716
+ if (result.notice)
717
+ deps.io.out(result.notice);
718
+ deps.io.out(`用件: ${result.intents.map((intent) => intent.label).join("、")}`);
719
+ for (const fact of result.facts) {
720
+ deps.io.out(fact.value === null
721
+ ? ` まだない情報 ${fact.label}`
722
+ : ` ${fact.label}: ${fact.value}${fact.sourceExcerpt ? ` 「${fact.sourceExcerpt}」` : ""}`);
723
+ }
724
+ if (result.missing.length > 0) {
725
+ deps.io.out("");
726
+ deps.io.out(`${result.missing.length} 件は資料から読み取れませんでした。アシスタントで足すか、このまま公開できます。`);
727
+ }
728
+ deps.io.out("Next: `kumion facts list <id>`, `kumion facts confirm <id>`, `kumion agents get <id>`, `kumion test-runs start <id>`, `kumion agents publish <id>`.");
729
+ return 0;
730
+ }
731
+ function staffLine(staff) {
732
+ const target = staff.transferTarget ?? "no 転送先";
733
+ return `${staff.id} ${staff.enabled ? "enabled " : "disabled"} ${staff.displayName}: ${target} [key ${staff.key ?? "—"} revision ${staff.revision}]`;
734
+ }
735
+ async function staffList(args, deps) {
736
+ const { values } = parse(args, {});
737
+ const staff = await (await clientFor(values, deps)).listStaff();
738
+ if (values.json) {
739
+ printJson(deps, { staff });
740
+ return 0;
741
+ }
742
+ if (staff.length === 0)
743
+ deps.io.out("No staff.");
744
+ else
745
+ for (const row of staff)
746
+ deps.io.out(staffLine(row));
747
+ return 0;
748
+ }
749
+ function parseEnabled(value) {
750
+ if (value === undefined)
751
+ return undefined;
752
+ if (value === "true")
753
+ return true;
754
+ if (value === "false")
755
+ return false;
756
+ throw new UsageError("--enabled takes true or false.");
757
+ }
758
+ const STAFF_WRITE_FLAGS = {
759
+ name: { type: "string" },
760
+ "transfer-target": { type: "string" },
761
+ department: { type: "string" },
762
+ kana: { type: "string" },
763
+ email: { type: "string" },
764
+ note: { type: "string" },
765
+ enabled: { type: "string" },
766
+ };
767
+ async function staffCreate(args, deps) {
768
+ const { values } = parse(args, { ...STAFF_WRITE_FLAGS });
769
+ const displayName = values.name?.trim();
770
+ if (!displayName)
771
+ throw new UsageError("Pass --name <name> — it is what the operator sees when choosing a 転送先.");
772
+ const staff = await (await clientFor(values, deps)).createStaff({
773
+ displayName,
774
+ ...(values["transfer-target"] !== undefined ? { transferTarget: values["transfer-target"] } : {}),
775
+ ...(values.department !== undefined ? { department: values.department } : {}),
776
+ ...(values.kana !== undefined ? { kana: values.kana } : {}),
777
+ ...(values.email !== undefined ? { email: values.email } : {}),
778
+ ...(values.note !== undefined ? { note: values.note } : {}),
779
+ ...(values.enabled !== undefined ? { enabled: parseEnabled(values.enabled) } : {}),
780
+ });
781
+ if (values.json) {
782
+ printJson(deps, { staff });
783
+ return 0;
784
+ }
785
+ deps.io.out(`Created ${staff.displayName} (${staff.id}). Transfer key: ${staff.key}`);
786
+ deps.io.out(staff.transferCandidate
787
+ ? "It is a 転送 candidate now. Next: name this key as a 用件's transfer destination (`kumion flow get` shows the 用件)."
788
+ : "Not a 転送 candidate yet — it needs a 転送先 (--transfer-target) and to be enabled.");
789
+ return 0;
790
+ }
791
+ const STAFF_REVISION_HELP = "the revision `kumion staff list` showed for the スタッフ you are changing.";
792
+ async function staffUpdate(args, deps) {
793
+ const { values, positionals } = parse(args, { ...STAFF_WRITE_FLAGS, revision: { type: "string" } });
794
+ const staffId = need(positionals, 0, "staffId");
795
+ const patch = {};
796
+ if (values.name !== undefined)
797
+ patch.displayName = values.name;
798
+ if (values["transfer-target"] !== undefined)
799
+ patch.transferTarget = values["transfer-target"];
800
+ if (values.department !== undefined)
801
+ patch.department = values.department;
802
+ if (values.kana !== undefined)
803
+ patch.kana = values.kana;
804
+ if (values.email !== undefined)
805
+ patch.email = values.email;
806
+ if (values.note !== undefined)
807
+ patch.note = values.note;
808
+ const enabled = parseEnabled(values.enabled);
809
+ if (enabled !== undefined)
810
+ patch.enabled = enabled;
811
+ if (Object.keys(patch).length === 0) {
812
+ throw new UsageError("Nothing to change. Pass --name, --transfer-target, --department, --kana, --email, --note or --enabled.");
813
+ }
814
+ const revision = requireRevision(values.revision, STAFF_REVISION_HELP);
815
+ const staff = await (await clientFor(values, deps)).updateStaff(staffId, patch, revision);
816
+ if (values.json) {
817
+ printJson(deps, { staff });
818
+ return 0;
819
+ }
820
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${staff.revision}`);
821
+ if (!staff.transferCandidate)
822
+ deps.io.out("This スタッフ is not a 転送 candidate now (disabled, or missing a 転送先).");
823
+ return 0;
824
+ }
825
+ const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
826
+ function hoursText(hours) {
827
+ const lines = [];
828
+ lines.push(`Revision ${hours.revision} (pass to \`hours update --revision\`)`);
829
+ lines.push(`Timezone ${hours.timezone} 祝日休み: ${hours.observeJpHolidays ? "yes" : "no"}`);
830
+ const open = WEEKDAYS.filter((day) => (hours.businessHours[day] ?? []).length > 0);
831
+ if (open.length === 0)
832
+ lines.push("営業時間: not set (every day is answered as 未設定)");
833
+ else {
834
+ lines.push("営業時間:");
835
+ for (const day of WEEKDAYS) {
836
+ const ranges = hours.businessHours[day] ?? [];
837
+ lines.push(` ${day} ${ranges.length === 0 ? "closed" : ranges.map((r) => `${r.start}-${r.end}`).join(", ")}`);
838
+ }
839
+ }
840
+ lines.push(`定休日: ${hours.closedRules.length} rule(s)`);
841
+ if (hours.exceptions.length === 0)
842
+ lines.push("例外日: none in this window");
843
+ else {
844
+ lines.push("例外日:");
845
+ for (const exception of hours.exceptions) {
846
+ const what = exception.kind === "closed" ? "臨時休業" : "振替出勤";
847
+ const when = exception.hours && exception.hours.length > 0
848
+ ? ` ${exception.hours.map((r) => `${r.start}-${r.end}`).join(", ")}`
849
+ : "";
850
+ lines.push(` ${exception.closedOn} ${what}${when}${exception.note ? ` (${exception.note})` : ""}`);
851
+ }
852
+ }
853
+ if (hours.affectedAgentIds.length > 0) {
854
+ lines.push(`This calendar is read by ${hours.affectedAgentIds.length} agent(s): ${hours.affectedAgentIds.join(", ")}`);
855
+ }
856
+ return lines;
857
+ }
858
+ async function hoursGet(args, deps) {
859
+ const { values } = parse(args, { from: { type: "string" }, to: { type: "string" } });
860
+ const hours = await (await clientFor(values, deps)).getStoreHours({ from: values.from, to: values.to });
861
+ if (values.json)
862
+ printJson(deps, hours);
863
+ else
864
+ for (const line of hoursText(hours))
865
+ deps.io.out(line);
866
+ return 0;
867
+ }
868
+ function parseYesNo(raw, flag) {
869
+ if (raw === undefined)
870
+ return undefined;
871
+ if (raw === "true")
872
+ return true;
873
+ if (raw === "false")
874
+ return false;
875
+ throw new UsageError(`--${flag} takes true or false.`);
876
+ }
877
+ const HOURS_REVISION_HELP = "the revision `kumion hours get` showed for the clock you are changing.";
878
+ async function hoursUpdate(args, deps) {
879
+ const { values } = parse(args, {
880
+ revision: { type: "string" },
881
+ "business-hours-file": { type: "string" },
882
+ "closed-rules-file": { type: "string" },
883
+ "observe-jp-holidays": { type: "string" },
884
+ "dry-run": { type: "boolean" },
885
+ });
886
+ const patch = {};
887
+ if (values["business-hours-file"] !== undefined) {
888
+ patch.businessHours = (await readJsonFile(values["business-hours-file"]));
889
+ }
890
+ if (values["closed-rules-file"] !== undefined) {
891
+ patch.closedRules = (await readJsonFile(values["closed-rules-file"]));
892
+ }
893
+ const observe = parseYesNo(values["observe-jp-holidays"], "observe-jp-holidays");
894
+ if (observe !== undefined)
895
+ patch.observeJpHolidays = observe;
896
+ if (Object.keys(patch).length === 0) {
897
+ throw new UsageError("Nothing to change. Pass --business-hours-file, --closed-rules-file or --observe-jp-holidays.");
898
+ }
899
+ const revision = requireRevision(values.revision, HOURS_REVISION_HELP);
900
+ const hours = await (await clientFor(values, deps)).updateStoreHours(patch, revision, { dryRun: values["dry-run"] });
901
+ if (values.json) {
902
+ printJson(deps, hours);
903
+ return 0;
904
+ }
905
+ if (values["dry-run"]) {
906
+ deps.io.out(`Dry run: nothing was saved. The calendar is at revision ${hours.revision}.`);
907
+ for (const line of hoursText(hours).slice(1))
908
+ deps.io.out(line);
909
+ return 0;
910
+ }
911
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${hours.revision}`);
912
+ if (hours.affectedAgentIds.length > 0) {
913
+ deps.io.out(`The next call on ${hours.affectedAgentIds.length} agent(s) answers from this clock.`);
914
+ }
915
+ return 0;
916
+ }
917
+ const EXCEPTION_KINDS = ["closed", "open", "inherit"];
918
+ async function hoursExceptionSet(args, deps) {
919
+ const { values, positionals } = parse(args, {
920
+ revision: { type: "string" },
921
+ kind: { type: "string" },
922
+ "hours-file": { type: "string" },
923
+ note: { type: "string" },
924
+ "dry-run": { type: "boolean" },
925
+ });
926
+ const date = need(positionals, 0, "date");
927
+ const kind = values.kind;
928
+ if (!kind || !EXCEPTION_KINDS.includes(kind)) {
929
+ throw new UsageError("Pass --kind closed|open|inherit.");
930
+ }
931
+ const input = { kind: kind };
932
+ if (values["hours-file"] !== undefined) {
933
+ input.hours = (await readJsonFile(values["hours-file"]));
934
+ }
935
+ if (values.note !== undefined)
936
+ input.note = values.note;
937
+ const revision = requireRevision(values.revision, HOURS_REVISION_HELP);
938
+ const result = await (await clientFor(values, deps)).setStoreHoursException(date, input, revision, {
939
+ dryRun: values["dry-run"],
940
+ });
941
+ if (values.json) {
942
+ printJson(deps, result);
943
+ return 0;
944
+ }
945
+ const what = kind === "inherit"
946
+ ? `${date} の例外を消して、曜日どおりに戻しました`
947
+ : kind === "open"
948
+ ? `${date} を振替出勤にしました`
949
+ : `${date} を臨時休業にしました`;
950
+ if (values["dry-run"]) {
951
+ deps.io.out(`Dry run: nothing was saved. ${what} (would be).`);
952
+ }
953
+ else {
954
+ deps.io.out(`${what}。Saved and live now — no publish needed. New revision: ${result.revision}`);
955
+ if (kind === "inherit" && result.exception === null) {
956
+ if (result.revision === revision)
957
+ deps.io.out("There was no exception on that day — nothing changed.");
958
+ }
959
+ }
960
+ return 0;
961
+ }
962
+ function minutesLabel(value) {
963
+ return value === null ? "枠の長さを使う" : `${value}分`;
964
+ }
965
+ function bookingText(settings) {
966
+ const lines = [];
967
+ lines.push(`Revision ${settings.revision} (pass to \`booking … --revision\`)`);
968
+ lines.push(`枠 ${settings.calendar.defaultSlotMinutes}分 直前予約の締め切り ${settings.calendar.minLeadMinutes}分前 何日先まで ${settings.calendar.maxAdvanceDays}日`);
969
+ lines.push(settings.mounted
970
+ ? "This agent takes bookings now (mounted)."
971
+ : "This agent is not mounted on the calendar, so it takes no bookings.");
972
+ lines.push(`担当 ${settings.resources.length} (予約できる担当 ${settings.bookableResourceCount})`);
973
+ for (const resource of settings.resources) {
974
+ const services = settings.resourceServices.filter((link) => link.resourceId === resource.id);
975
+ lines.push(` ${resource.name} ${resource.enabled ? "enabled" : "disabled"}` +
976
+ (services.length === 0 ? " (no 内容 named: takes every 内容)" : ` ${services.length} 内容`));
977
+ }
978
+ if (settings.services.length === 0)
979
+ lines.push("内容: none (one 枠 of the slot length is booked)");
980
+ else {
981
+ lines.push("内容:");
982
+ for (const service of settings.services) {
983
+ lines.push(` ${service.id} ${service.name} ${minutesLabel(service.durationMinutes)}`);
984
+ }
985
+ }
986
+ if (settings.affectedAgentIds.length > 0) {
987
+ lines.push(`This calendar is read by ${settings.affectedAgentIds.length} agent(s): ${settings.affectedAgentIds.join(", ")}`);
988
+ }
989
+ return lines;
990
+ }
991
+ async function readTextFile(path) {
992
+ try {
993
+ return await readFile(path, "utf8");
994
+ }
995
+ catch (err) {
996
+ throw new UsageError(`Cannot read ${path}: ${err.message}`);
997
+ }
998
+ }
999
+ async function readBinaryFile(path) {
1000
+ try {
1001
+ return new Uint8Array(await readFile(path));
1002
+ }
1003
+ catch (err) {
1004
+ throw new UsageError(`Cannot read ${path}: ${err.message}`);
1005
+ }
1006
+ }
1007
+ async function readJsonObjectFile(path) {
1008
+ const value = await readJsonFile(path);
1009
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1010
+ throw new UsageError(`${path} must hold a JSON object.`);
1011
+ }
1012
+ return value;
1013
+ }
1014
+ async function bookingGet(args, deps) {
1015
+ const { values, positionals } = parse(args, {});
1016
+ const agentId = need(positionals, 0, "agentId");
1017
+ const settings = await (await clientFor(values, deps)).getBookingSettings(agentId);
1018
+ if (values.json)
1019
+ printJson(deps, settings);
1020
+ else
1021
+ for (const line of bookingText(settings))
1022
+ deps.io.out(line);
1023
+ return 0;
1024
+ }
1025
+ const BOOKING_REVISION_HELP = "the revision `kumion booking get` showed for the 予約設定 you are changing.";
1026
+ async function bookingCalendarUpdate(args, deps) {
1027
+ const { values } = parse(args, { revision: { type: "string" }, "patch-file": { type: "string" }, "dry-run": { type: "boolean" } });
1028
+ if (values["patch-file"] === undefined) {
1029
+ throw new UsageError("Pass --patch-file <path> holding defaultSlotMinutes, minLeadMinutes and/or maxAdvanceDays.");
1030
+ }
1031
+ const patch = (await readJsonObjectFile(values["patch-file"]));
1032
+ const revision = requireRevision(values.revision, BOOKING_REVISION_HELP);
1033
+ const result = await (await clientFor(values, deps)).updateBookingCalendar(patch, revision, { dryRun: values["dry-run"] });
1034
+ if (values.json) {
1035
+ printJson(deps, result);
1036
+ return 0;
1037
+ }
1038
+ const calendar = result.calendar;
1039
+ const summary = `枠 ${calendar.defaultSlotMinutes}分 直前予約の締め切り ${calendar.minLeadMinutes}分前 何日先まで ${calendar.maxAdvanceDays}日`;
1040
+ if (values["dry-run"]) {
1041
+ deps.io.out(`Dry run: nothing was saved. The calendar is at revision ${result.revision}.`);
1042
+ deps.io.out(summary);
1043
+ return 0;
1044
+ }
1045
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${result.revision}`);
1046
+ deps.io.out(summary);
1047
+ if (result.affectedAgentIds.length > 0) {
1048
+ deps.io.out(`The next slot on ${result.affectedAgentIds.length} agent(s) uses these settings.`);
1049
+ }
1050
+ return 0;
1051
+ }
1052
+ function bookingServiceText(service) {
1053
+ return `${service.name} ${minutesLabel(service.durationMinutes)}`;
1054
+ }
1055
+ async function bookingServicesCreate(args, deps) {
1056
+ const { values } = parse(args, { revision: { type: "string" }, "data-file": { type: "string" }, "dry-run": { type: "boolean" } });
1057
+ if (values["data-file"] === undefined) {
1058
+ throw new UsageError("Pass --data-file <path> holding name, and durationMinutes (or null for the slot length).");
1059
+ }
1060
+ const service = (await readJsonObjectFile(values["data-file"]));
1061
+ const revision = requireRevision(values.revision, BOOKING_REVISION_HELP);
1062
+ const result = await (await clientFor(values, deps)).createBookingService(service, revision, { dryRun: values["dry-run"] });
1063
+ if (values.json) {
1064
+ printJson(deps, result);
1065
+ return 0;
1066
+ }
1067
+ if (values["dry-run"]) {
1068
+ deps.io.out(`Dry run: nothing was saved. Would add: ${bookingServiceText(result.service)}`);
1069
+ return 0;
1070
+ }
1071
+ deps.io.out(`Added 内容 ${result.service.id} ${bookingServiceText(result.service)}`);
1072
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${result.revision}`);
1073
+ return 0;
1074
+ }
1075
+ async function bookingServicesUpdate(args, deps) {
1076
+ const { values, positionals } = parse(args, {
1077
+ revision: { type: "string" },
1078
+ "patch-file": { type: "string" },
1079
+ "dry-run": { type: "boolean" },
1080
+ });
1081
+ const serviceId = need(positionals, 0, "serviceId");
1082
+ if (values["patch-file"] === undefined) {
1083
+ throw new UsageError("Pass --patch-file <path> holding name and/or durationMinutes (null = the slot length).");
1084
+ }
1085
+ const patch = (await readJsonObjectFile(values["patch-file"]));
1086
+ const revision = requireRevision(values.revision, BOOKING_REVISION_HELP);
1087
+ const result = await (await clientFor(values, deps)).updateBookingService(serviceId, patch, revision, {
1088
+ dryRun: values["dry-run"],
1089
+ });
1090
+ if (values.json) {
1091
+ printJson(deps, result);
1092
+ return 0;
1093
+ }
1094
+ if (values["dry-run"]) {
1095
+ deps.io.out(`Dry run: nothing was saved. Would be: ${bookingServiceText(result.service)}`);
1096
+ return 0;
1097
+ }
1098
+ deps.io.out(`Saved and live now — no publish needed. 内容 ${serviceId}: ${bookingServiceText(result.service)}`);
1099
+ deps.io.out(`New revision: ${result.revision}`);
1100
+ return 0;
1101
+ }
1102
+ function weeklyHoursLabel(hours) {
1103
+ const days = Object.keys(hours).filter((day) => (hours[day] ?? []).length > 0);
1104
+ return days.length === 0 ? "枠なし(この担当には予約が入りません)" : `${days.join("・")} の ${days.length}日`;
1105
+ }
1106
+ function bookingResourceText(resource) {
1107
+ const service = resource.serviceRestriction === "all" ? "すべての内容" : `内容 ${resource.serviceIds.length} 件`;
1108
+ return `${resource.name} ${resource.enabled ? "enabled" : "disabled"} 枠 ${weeklyHoursLabel(resource.weeklyHours)} ${service}`;
1109
+ }
1110
+ async function bookingResourcesCreate(args, deps) {
1111
+ const { values } = parse(args, { revision: { type: "string" }, "data-file": { type: "string" }, "dry-run": { type: "boolean" } });
1112
+ if (values["data-file"] === undefined) {
1113
+ throw new UsageError("Pass --data-file <path> holding name, and enabled / weeklyHours / serviceIds.");
1114
+ }
1115
+ const input = (await readJsonObjectFile(values["data-file"]));
1116
+ const revision = requireRevision(values.revision, BOOKING_REVISION_HELP);
1117
+ const result = await (await clientFor(values, deps)).createBookingResource(input, revision, {
1118
+ dryRun: values["dry-run"],
1119
+ });
1120
+ if (values.json) {
1121
+ printJson(deps, result);
1122
+ return 0;
1123
+ }
1124
+ if (values["dry-run"]) {
1125
+ deps.io.out(`Dry run: nothing was saved. Would add: ${bookingResourceText(result.resource)}`);
1126
+ return 0;
1127
+ }
1128
+ deps.io.out(`Added 担当 ${result.resource.id} ${bookingResourceText(result.resource)}`);
1129
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${result.revision}`);
1130
+ return 0;
1131
+ }
1132
+ async function bookingResourcesUpdate(args, deps) {
1133
+ const { values, positionals } = parse(args, {
1134
+ revision: { type: "string" },
1135
+ "patch-file": { type: "string" },
1136
+ "dry-run": { type: "boolean" },
1137
+ });
1138
+ const resourceId = need(positionals, 0, "resourceId");
1139
+ if (values["patch-file"] === undefined) {
1140
+ throw new UsageError("Pass --patch-file <path> holding name, enabled, weeklyHours and/or serviceIds ([] = every 内容).");
1141
+ }
1142
+ const patch = (await readJsonObjectFile(values["patch-file"]));
1143
+ const revision = requireRevision(values.revision, BOOKING_REVISION_HELP);
1144
+ const result = await (await clientFor(values, deps)).updateBookingResource(resourceId, patch, revision, {
1145
+ dryRun: values["dry-run"],
1146
+ });
1147
+ if (values.json) {
1148
+ printJson(deps, result);
1149
+ return 0;
1150
+ }
1151
+ if (values["dry-run"]) {
1152
+ deps.io.out(`Dry run: nothing was saved. Would be: ${bookingResourceText(result.resource)}`);
1153
+ return 0;
1154
+ }
1155
+ deps.io.out(`Saved and live now — no publish needed. 担当 ${resourceId}: ${bookingResourceText(result.resource)}`);
1156
+ deps.io.out(`New revision: ${result.revision}`);
1157
+ return 0;
1158
+ }
1159
+ async function bookingMount(args, deps) {
1160
+ const { values, positionals } = parse(args, {
1161
+ revision: { type: "string" },
1162
+ mounted: { type: "string" },
1163
+ "dry-run": { type: "boolean" },
1164
+ });
1165
+ const agentId = need(positionals, 0, "agentId");
1166
+ const mounted = parseYesNo(values.mounted, "mounted");
1167
+ if (mounted === undefined)
1168
+ throw new UsageError("Pass --mounted true or --mounted false.");
1169
+ const revision = requireRevision(values.revision, BOOKING_REVISION_HELP);
1170
+ const result = await (await clientFor(values, deps)).setAgentBooking(agentId, mounted, revision, {
1171
+ dryRun: values["dry-run"],
1172
+ });
1173
+ if (values.json) {
1174
+ printJson(deps, result);
1175
+ return 0;
1176
+ }
1177
+ const state = result.mounted ? "takes bookings" : "does not take bookings";
1178
+ if (values["dry-run"]) {
1179
+ deps.io.out(`Dry run: nothing was saved. This agent would ${result.mounted ? "start" : "stop"} taking bookings.`);
1180
+ return 0;
1181
+ }
1182
+ deps.io.out(`Saved and live now — no publish needed. This agent ${state}. New revision: ${result.revision}`);
1183
+ if (result.receptionSummaryRetired > 0) {
1184
+ deps.io.out(`Retired 仮受付 from ${result.receptionSummaryRetired} 受付サマリー spec(s): the calendar confirms for real now.`);
1185
+ }
1186
+ return 0;
1187
+ }
1188
+ function bookingSlotText(slot) {
1189
+ const minutes = Math.round((new Date(slot.endAt).getTime() - new Date(slot.startAt).getTime()) / 60_000);
1190
+ return `${slot.startAt.slice(0, 16).replace("T", " ")}(${minutes}分)`;
1191
+ }
1192
+ async function bookingSlots(args, deps) {
1193
+ const { values, positionals } = parse(args, {
1194
+ resource: { type: "string" },
1195
+ date: { type: "string" },
1196
+ service: { type: "string" },
1197
+ limit: { type: "string" },
1198
+ });
1199
+ const agentId = need(positionals, 0, "agentId");
1200
+ if (values.resource === undefined)
1201
+ throw new UsageError("Pass --resource <resourceId> (the 担当's id, from `booking get`).");
1202
+ if (values.date === undefined)
1203
+ throw new UsageError("Pass --date <YYYY-MM-DD>.");
1204
+ const limit = values.limit === undefined ? undefined : Number(values.limit);
1205
+ if (limit !== undefined && (!Number.isInteger(limit) || limit < 1)) {
1206
+ throw new UsageError("--limit takes a whole number of slots.");
1207
+ }
1208
+ const view = await (await clientFor(values, deps)).listBookingSlots(agentId, {
1209
+ resourceId: values.resource,
1210
+ date: values.date,
1211
+ ...(values.service === undefined ? {} : { serviceId: values.service }),
1212
+ ...(limit === undefined ? {} : { limit }),
1213
+ });
1214
+ if (values.json) {
1215
+ printJson(deps, view);
1216
+ return 0;
1217
+ }
1218
+ deps.io.out(`${view.resource.name} ${view.date} (${view.resource.enabled ? "enabled" : "disabled"})`);
1219
+ if (!view.mounted) {
1220
+ deps.io.out("This agent is not mounted on the calendar, so it will not offer these slots (see `booking mount`).");
1221
+ }
1222
+ if (!view.serviceAllowed) {
1223
+ deps.io.out("This 担当 does not take that 内容, so no slot of that length is offered.");
1224
+ return 0;
1225
+ }
1226
+ if (view.slots.length === 0) {
1227
+ deps.io.out("No openings on that day.");
1228
+ return 0;
1229
+ }
1230
+ for (const slot of view.slots)
1231
+ deps.io.out(` ${bookingSlotText(slot)}`);
1232
+ return 0;
1233
+ }
1234
+ const CAPTURE_SPEC_REVISION_HELP = "the revision `kumion capture-specs list` showed for the 記録項目 you are changing.";
1235
+ function captureSpecScope(spec) {
1236
+ return spec.affectedAgentIds.length === 0 ? "no agent yet" : `${spec.affectedAgentIds.length} agent(s)`;
1237
+ }
1238
+ function captureSpecLine(spec) {
1239
+ return `${spec.id} ${spec.enabled ? "enabled " : "disabled"} ${spec.label} [key ${spec.key} revision ${spec.revision}] ${captureSpecScope(spec)}`;
1240
+ }
1241
+ async function captureSpecsList(args, deps) {
1242
+ const { values } = parse(args, {});
1243
+ const specs = await (await clientFor(values, deps)).listCaptureSpecs();
1244
+ if (values.json) {
1245
+ printJson(deps, { captureSpecs: specs });
1246
+ return 0;
1247
+ }
1248
+ if (specs.length === 0)
1249
+ deps.io.out("No 記録項目.");
1250
+ else
1251
+ for (const spec of specs)
1252
+ deps.io.out(captureSpecLine(spec));
1253
+ return 0;
1254
+ }
1255
+ async function captureSpecsCreate(args, deps) {
1256
+ const { values } = parse(args, { "data-file": { type: "string" } });
1257
+ if (values["data-file"] === undefined) {
1258
+ throw new UsageError("Pass --data-file <path> holding label, fields, and optionally key / scenario / instruction.");
1259
+ }
1260
+ const input = (await readJsonObjectFile(values["data-file"]));
1261
+ if (input.fields === undefined)
1262
+ throw new UsageError(`${values["data-file"]} must hold fields.`);
1263
+ const spec = await (await clientFor(values, deps)).createCaptureSpec({ ...input, fields: input.fields });
1264
+ if (values.json) {
1265
+ printJson(deps, { captureSpec: spec });
1266
+ return 0;
1267
+ }
1268
+ deps.io.out(`Created 記録項目 ${spec.id} ${spec.label} [key ${spec.key} revision ${spec.revision}]`);
1269
+ deps.io.out("No agent records it yet — mount it on an agent before it can record anything.");
1270
+ return 0;
1271
+ }
1272
+ async function captureSpecsUpdate(args, deps) {
1273
+ const { values, positionals } = parse(args, { revision: { type: "string" }, "patch-file": { type: "string" } });
1274
+ const specId = need(positionals, 0, "specId");
1275
+ if (values["patch-file"] === undefined) {
1276
+ throw new UsageError("Pass --patch-file <path> holding the fields to change (see `kumion --help`).");
1277
+ }
1278
+ const patch = (await readJsonObjectFile(values["patch-file"]));
1279
+ const revision = requireRevision(values.revision, CAPTURE_SPEC_REVISION_HELP);
1280
+ const spec = await (await clientFor(values, deps)).updateCaptureSpec(specId, patch, revision);
1281
+ if (values.json) {
1282
+ printJson(deps, { captureSpec: spec });
1283
+ return 0;
1284
+ }
1285
+ deps.io.out(`Saved and live now — no publish needed. 記録項目 ${specId}: ${spec.label}`);
1286
+ deps.io.out(`New revision: ${spec.revision}`);
1287
+ if (spec.affectedAgentIds.length === 0)
1288
+ deps.io.out("No agent is mounted with this 記録項目, so no call records it yet.");
1289
+ else
1290
+ deps.io.out(`Every agent mounted with it records differently from its next call: ${spec.affectedAgentIds.join(", ")}`);
1291
+ return 0;
1292
+ }
1293
+ const AGENT_CAPTURE_REVISION_HELP = "the revision `kumion agents capture get` showed for this agent.";
1294
+ function printAgentCaptureReadiness(capture, deps) {
1295
+ if (capture.readiness.ready) {
1296
+ deps.io.out(`Ready: ${capture.enabledMountedCount} 記録項目 will be extracted after a call.`);
1297
+ return;
1298
+ }
1299
+ deps.io.out("NOT ready — a call on this agent records nothing:");
1300
+ for (const issue of capture.readiness.issues)
1301
+ deps.io.out(` ${issue.message}`);
1302
+ }
1303
+ function printAgentCapture(capture, deps) {
1304
+ if (capture.captureSpecIds.length === 0)
1305
+ deps.io.out("No 記録項目 mounted on this agent.");
1306
+ for (const spec of capture.captureSpecs) {
1307
+ deps.io.out(`${spec.id} ${spec.enabled ? "enabled " : "disabled"} ${spec.label} [key ${spec.key} revision ${spec.revision}]`);
1308
+ }
1309
+ printAgentCaptureReadiness(capture, deps);
1310
+ deps.io.out(`Revision: ${capture.revision}`);
1311
+ }
1312
+ async function agentsCaptureGet(args, deps) {
1313
+ const { values, positionals } = parse(args, {});
1314
+ const agentId = need(positionals, 0, "agentId");
1315
+ const capture = await (await clientFor(values, deps)).getAgentCapture(agentId);
1316
+ if (values.json) {
1317
+ printJson(deps, capture);
1318
+ return 0;
1319
+ }
1320
+ printAgentCapture(capture, deps);
1321
+ return 0;
1322
+ }
1323
+ async function agentsCaptureSet(args, deps) {
1324
+ const { values, positionals } = parse(args, {
1325
+ revision: { type: "string" },
1326
+ spec: { type: "string", multiple: true },
1327
+ clear: { type: "boolean" },
1328
+ });
1329
+ const agentId = need(positionals, 0, "agentId");
1330
+ const specs = values.spec ?? [];
1331
+ if (values.clear && specs.length > 0) {
1332
+ throw new UsageError("Pass either --spec <specId> (repeatable) or --clear, not both.");
1333
+ }
1334
+ if (!values.clear && specs.length === 0) {
1335
+ throw new UsageError("Pass --spec <specId> (repeatable) to mount, or --clear to record nothing.");
1336
+ }
1337
+ const revision = requireRevision(values.revision, AGENT_CAPTURE_REVISION_HELP);
1338
+ const capture = await (await clientFor(values, deps)).setAgentCapture(agentId, specs, revision);
1339
+ if (values.json) {
1340
+ printJson(deps, capture);
1341
+ return 0;
1342
+ }
1343
+ deps.io.out(capture.captureSpecIds.length === 0
1344
+ ? "Saved and live now — no publish needed. This agent records nothing after a call."
1345
+ : `Saved and live now — no publish needed. This agent records: ${capture.captureSpecs.map((spec) => spec.label).join(", ")}`);
1346
+ printAgentCaptureReadiness(capture, deps);
1347
+ deps.io.out(`New revision: ${capture.revision}`);
1348
+ return 0;
1349
+ }
1350
+ function documentJobText(job) {
1351
+ const head = `${job.jobId} ${job.status}`;
1352
+ if (job.status === "succeeded")
1353
+ return `${head} document ${job.documentId}`;
1354
+ if (job.error)
1355
+ return `${head} ${job.error.code}: ${job.error.message}`;
1356
+ return `${head} (deadline ${job.deadlineAt})`;
1357
+ }
1358
+ async function documentsUpload(args, deps) {
1359
+ const { values } = parse(args, {
1360
+ "text-file": { type: "string" },
1361
+ file: { type: "string", multiple: true },
1362
+ title: { type: "string" },
1363
+ template: { type: "string" },
1364
+ "idempotency-key": { type: "string" },
1365
+ "dry-run": { type: "boolean" },
1366
+ });
1367
+ const textFile = values["text-file"];
1368
+ const files = values.file ?? [];
1369
+ if (textFile !== undefined && files.length > 0) {
1370
+ throw new UsageError("Pass either --text-file or --file, not both: the API takes the text OR the files.");
1371
+ }
1372
+ if (textFile === undefined && files.length === 0) {
1373
+ throw new UsageError("Pass --text-file <path> for the text of the 資料, or --file <path> (repeatable) for files.");
1374
+ }
1375
+ if (!values.title)
1376
+ throw new UsageError("Pass --title <title>.");
1377
+ const idempotencyKey = values["idempotency-key"];
1378
+ if (!idempotencyKey) {
1379
+ throw new UsageError("Pass --idempotency-key <key>: a retry with the same key answers the job it already made.");
1380
+ }
1381
+ const payload = textFile === undefined
1382
+ ? {
1383
+ files: await Promise.all(files.map(async (path) => ({ filename: basename(path), bytes: await readBinaryFile(path) }))),
1384
+ }
1385
+ : { rawText: await readTextFile(textFile) };
1386
+ const result = await (await clientFor(values, deps)).uploadDocument({
1387
+ title: values.title,
1388
+ idempotencyKey,
1389
+ ...payload,
1390
+ ...(values.template === undefined ? {} : { templateId: values.template }),
1391
+ }, { dryRun: values["dry-run"] });
1392
+ if (values.json) {
1393
+ printJson(deps, result);
1394
+ return 0;
1395
+ }
1396
+ if ("dryRun" in result) {
1397
+ deps.io.out(`Would upload ${result.filesCount} file(s), ${result.chars.toLocaleString("en-US")} characters (${result.bytes.toLocaleString("en-US")} bytes); nothing is written and no model is called.`);
1398
+ deps.io.out(`Model: ${result.provider}${result.model ? ` / ${result.model}` : ""}`);
1399
+ deps.io.out(`Allowance left: ${result.budget.keyRemaining} for this key, ${result.budget.tenantRemaining} for the tenant (per hour).`);
1400
+ deps.io.out("Price: not available (amount is null) — extractions are counted, not billed per run.");
1401
+ return 0;
1402
+ }
1403
+ deps.io.out(`Accepted. ${documentJobText(result)}`);
1404
+ deps.io.out(`Check it with: kumion documents jobs get ${result.jobId}`);
1405
+ return 0;
1406
+ }
1407
+ async function documentsJobsGet(args, deps) {
1408
+ const { values, positionals } = parse(args, {});
1409
+ const jobId = need(positionals, 0, "jobId");
1410
+ const job = await (await clientFor(values, deps)).getDocumentUploadJob(jobId);
1411
+ if (values.json)
1412
+ printJson(deps, job);
1413
+ else
1414
+ deps.io.out(documentJobText(job));
1415
+ return job.status === "failed" || job.status === "timed_out" ? 1 : 0;
1416
+ }
1417
+ async function documentsGet(args, deps) {
1418
+ const { values, positionals } = parse(args, {});
1419
+ const documentId = need(positionals, 0, "documentId");
1420
+ const document = await (await clientFor(values, deps)).getDocument(documentId);
1421
+ if (values.json) {
1422
+ printJson(deps, document);
1423
+ return 0;
1424
+ }
1425
+ const summary = document.document;
1426
+ deps.io.out(`${summary.id} ${summary.title} [${summary.status}, ${summary.mode}, revision ${document.revision}]`);
1427
+ deps.io.out(`${summary.charCount.toLocaleString("en-US")} characters, ${document.fields.length} field(s)`);
1428
+ for (const field of document.fields) {
1429
+ deps.io.out(` ${field.fieldKey} ${field.label} (${field.category}, ${field.reviewState})`);
1430
+ }
1431
+ for (const reference of document.references) {
1432
+ deps.io.out(reference.kind === "agent"
1433
+ ? ` used by agent ${reference.agentName} (${reference.agentId})`
1434
+ : ` used by node ${reference.nodeName ?? reference.nodeKey} of ${reference.workflowName} (${reference.workflowId})`);
1435
+ }
1436
+ return 0;
1437
+ }
1438
+ async function documentsReplace(args, deps) {
1439
+ const { values, positionals } = parse(args, {
1440
+ source: { type: "string" },
1441
+ "source-revision": { type: "string" },
1442
+ revision: { type: "string" },
1443
+ "dry-run": { type: "boolean" },
1444
+ });
1445
+ const documentId = need(positionals, 0, "documentId");
1446
+ if (!values.source)
1447
+ throw new UsageError("Pass --source <documentId>: the 資料 the new content comes from.");
1448
+ if (!values["source-revision"]) {
1449
+ throw new UsageError("Pass --source-revision <revision> — the source's revision, from `kumion documents get`.");
1450
+ }
1451
+ const revision = requireRevision(values.revision, "the 資料's revision from `kumion documents get`. It changes when anyone confirms or edits a fact.");
1452
+ const result = await (await clientFor(values, deps)).replaceDocument(documentId, { sourceDocumentId: values.source, sourceRevision: values["source-revision"] }, revision, { dryRun: values["dry-run"] });
1453
+ if (values.json) {
1454
+ printJson(deps, result);
1455
+ return 0;
1456
+ }
1457
+ const { changes } = result;
1458
+ const lines = [];
1459
+ lines.push(result.dryRun
1460
+ ? `Would replace ${result.document.id} with the content of ${result.source.documentId} — nothing is written.`
1461
+ : `Replaced ${result.document.id} with the content of ${result.source.documentId}.`);
1462
+ lines.push(`Characters: ${changes.characters.before.toLocaleString("en-US")} → ${changes.characters.after.toLocaleString("en-US")}`);
1463
+ if (changes.fields.added.length > 0)
1464
+ lines.push(`New facts: ${changes.fields.added.join(", ")}`);
1465
+ if (changes.fields.placeholders.length > 0) {
1466
+ lines.push(`Kept as empty (the new 資料 does not mention them): ${changes.fields.placeholders.join(", ")}`);
1467
+ }
1468
+ if (changes.fields.removed.length > 0)
1469
+ lines.push(`Gone: ${changes.fields.removed.join(", ")}`);
1470
+ lines.push(`Confirmations reset: ${result.resetConfirmedCount}. Every fact is pending again — review them before publishing.`);
1471
+ if (result.affectedAgentIds.length > 0) {
1472
+ lines.push(`Read by: ${result.affectedAgentIds.join(", ")} (live from their next call)`);
1473
+ }
1474
+ lines.push(result.dryRun ? `Revision stays: ${result.revision}` : `New revision: ${result.revision}`);
1475
+ deps.io.out(lines.join("\n"));
1476
+ return 0;
1477
+ }
1478
+ async function factsEdit(args, deps) {
1479
+ const { values, positionals } = parse(args, { revision: { type: "string" }, value: { type: "string" } });
1480
+ const agentId = need(positionals, 0, "agentId");
1481
+ const factId = need(positionals, 1, "factId");
1482
+ if (values.value === undefined)
1483
+ throw new UsageError("Pass --value <text>.");
1484
+ const revision = requireRevision(values.revision, "the fact's revision from `kumion facts list`.");
1485
+ const fact = await (await clientFor(values, deps)).editFact(agentId, factId, values.value, revision);
1486
+ if (values.json)
1487
+ printJson(deps, { fact });
1488
+ else
1489
+ deps.io.out(`Saved and live now — no publish needed.\n${factLine(fact)}`);
1490
+ return 0;
1491
+ }
1492
+ async function factsConfirm(args, deps) {
1493
+ const { values, positionals } = parse(args, { fact: { type: "string", multiple: true } });
1494
+ const agentId = need(positionals, 0, "agentId");
1495
+ const result = await (await clientFor(values, deps)).confirmFacts(agentId, values.fact && values.fact.length > 0 ? values.fact : undefined);
1496
+ if (values.json)
1497
+ printJson(deps, result);
1498
+ else {
1499
+ deps.io.out(`Confirmed ${result.confirmed.length} fact(s); live now — no publish needed.`);
1500
+ for (const s of result.skipped)
1501
+ deps.io.out(`Skipped (candidates disagree or none usable): ${s.id} ${s.label}`);
1502
+ }
1503
+ return 0;
1504
+ }
427
1505
  function formatFindings(findings, indent) {
428
1506
  return (findings ?? []).map((f) => `${indent}- ${f.kind}${f.nodeKey ? ` @${f.nodeKey}` : ""}: ${f.detail}`);
429
1507
  }
@@ -439,6 +1517,11 @@ async function agentsPublish(args, deps) {
439
1517
  else {
440
1518
  const agent = result.agent;
441
1519
  deps.io.out(`Published ${agent?.name ?? agentId} at ${agent?.publishedAt ?? "?"} (publish run ${String(result.publishRunId ?? "?")}).`);
1520
+ const unconfirmed = typeof result.unconfirmedFacts === "number" ? result.unconfirmedFacts : 0;
1521
+ if (unconfirmed > 0) {
1522
+ deps.io.out(`${unconfirmed} fact(s) in this agent's 資料 are still unconfirmed, so it will say it will check and call back for them.`);
1523
+ deps.io.out(`Next: \`kumion facts confirm ${agentId}\``);
1524
+ }
442
1525
  }
443
1526
  return 0;
444
1527
  }
@@ -470,6 +1553,150 @@ async function agentsPublish(args, deps) {
470
1553
  throw new ReportedFailure(lines.join("\n"));
471
1554
  }
472
1555
  }
1556
+ function findingLines(view) {
1557
+ return [
1558
+ ...view.findings.canvas.map((f) => ` [${f.severity === "error" ? "エラー" : "注意"}] ${f.message}`),
1559
+ ...view.findings.structural.map((f) => ` [公開前チェック] ${f.detail}`),
1560
+ ];
1561
+ }
1562
+ async function flowGet(args, deps) {
1563
+ const { values, positionals } = parse(args, {});
1564
+ const agentId = need(positionals, 0, "agentId");
1565
+ const view = await (await clientFor(values, deps)).getFlow(agentId);
1566
+ if (values.json) {
1567
+ printJson(deps, view);
1568
+ return 0;
1569
+ }
1570
+ const lines = [`Revision: ${view.revision}`];
1571
+ if (!view.flow) {
1572
+ lines.push("Edit layer: steps — this graph is not the 用件 form; change it with `kumion flow edit-steps` (`kumion agents get --json` shows the steps). --json shows the findings.");
1573
+ }
1574
+ else {
1575
+ lines.push(`Edit layer: flow — ${view.flow.leaves.length} 用件, edited as 用件 (the assistant's form).`);
1576
+ for (const leaf of view.flow.leaves) {
1577
+ lines.push(` ${leaf.key} ${leaf.label}: ${leaf.condition}`);
1578
+ }
1579
+ const steps = view.flow.leaves.filter((leaf) => (leaf.steps?.length ?? 0) > 0);
1580
+ if (steps.length > 0)
1581
+ lines.push(`Split into steps: ${steps.map((leaf) => leaf.key).join(", ")}`);
1582
+ const examples = Object.keys(view.flow.examples);
1583
+ if (examples.length > 0)
1584
+ lines.push(`Confirmed first lines: ${examples.join(", ")}`);
1585
+ }
1586
+ if (view.staffChoices.length > 0)
1587
+ lines.push(`Transfer targets: ${view.staffChoices.map((s) => `${s.key} (${s.name})`).join(", ")}`);
1588
+ if (view.transferRefusal)
1589
+ lines.push(`Transfer refused: ${view.transferRefusal}`);
1590
+ const findings = findingLines(view);
1591
+ lines.push(findings.length === 0 ? "Findings: none." : `Findings (${findings.length}):`, ...findings);
1592
+ lines.push("Use --json for the full 用件 (what each one says and asks for).");
1593
+ deps.io.out(lines.join("\n"));
1594
+ return 0;
1595
+ }
1596
+ function flowChangeLine(change) {
1597
+ const where = change.leafKey ? `${change.kind} ${change.leafKey}` : change.kind;
1598
+ if (change.items)
1599
+ return ` ${where}: ${change.items.before.join("、") || "(なし)"} → ${change.items.after.join("、") || "(なし)"}`;
1600
+ return ` ${where}: 「${change.before}」→「${change.after}」`;
1601
+ }
1602
+ async function flowUpdate(args, deps) {
1603
+ const { values, positionals } = parse(args, {
1604
+ revision: { type: "string" },
1605
+ "patch-file": { type: "string" },
1606
+ "dry-run": { type: "boolean" },
1607
+ });
1608
+ const agentId = need(positionals, 0, "agentId");
1609
+ const patchFile = values["patch-file"];
1610
+ if (!patchFile) {
1611
+ throw new UsageError("Pass --patch-file <path> — a JSON object of the change, in the arguments `flow get` and the canvas assistant use " +
1612
+ "(leaves, personaPrompt, openingSpeech, noRouteSpeech, examples).");
1613
+ }
1614
+ const patch = await readJsonFile(patchFile);
1615
+ if (!patch || typeof patch !== "object" || Array.isArray(patch))
1616
+ throw new UsageError(`${patchFile} must hold a JSON object.`);
1617
+ const revision = requireRevision(values.revision, "the revision `kumion flow get` showed when you read the flow you are changing.");
1618
+ const result = await (await clientFor(values, deps)).updateFlow(agentId, patch, revision, {
1619
+ dryRun: values["dry-run"] === true,
1620
+ });
1621
+ if (values.json) {
1622
+ printJson(deps, result);
1623
+ return 0;
1624
+ }
1625
+ const lines = [
1626
+ values["dry-run"]
1627
+ ? `Dry run — nothing was saved. Revision: ${result.revision}`
1628
+ : `Draft saved. New revision: ${result.revision}`,
1629
+ ];
1630
+ lines.push(result.changes.length === 0 ? "Nothing changed." : `Changes (${result.changes.length}):`);
1631
+ lines.push(...result.changes.map(flowChangeLine));
1632
+ if (result.consequences.length > 0) {
1633
+ lines.push(`Also changes (${result.consequences.length}):`, ...result.consequences.map((c) => ` ${c.text}`));
1634
+ }
1635
+ if (result.warnings.length > 0) {
1636
+ lines.push(`Not applied as asked (${result.warnings.length}):`, ...result.warnings.map((w) => ` ${w}`));
1637
+ }
1638
+ if (!values["dry-run"] && result.changes.length > 0) {
1639
+ lines.push(`Nothing is live until you run \`kumion agents publish ${agentId}\`.`);
1640
+ }
1641
+ deps.io.out(lines.join("\n"));
1642
+ return 0;
1643
+ }
1644
+ function flowStepChangeLine(change) {
1645
+ if (change.kind === "add_step")
1646
+ return ` + ステップ ${change.node}(${change.key}・${change.stepType ?? "agent"})`;
1647
+ if (change.kind === "remove_step")
1648
+ return ` - ステップ ${change.node}(${change.key})`;
1649
+ if (change.kind === "add_edge")
1650
+ return ` + つながり ${change.node}${change.after ? `(${change.after})` : ""}`;
1651
+ if (change.kind === "remove_edge")
1652
+ return ` - つながり ${change.node}`;
1653
+ return ` ${change.node}: ${change.field} 「${change.before}」→「${change.after}」`;
1654
+ }
1655
+ async function flowEditSteps(args, deps) {
1656
+ const { values, positionals } = parse(args, {
1657
+ revision: { type: "string" },
1658
+ "ops-file": { type: "string" },
1659
+ "dry-run": { type: "boolean" },
1660
+ });
1661
+ const agentId = need(positionals, 0, "agentId");
1662
+ const opsFile = values["ops-file"];
1663
+ if (!opsFile) {
1664
+ throw new UsageError("Pass --ops-file <path> — the batch, as a JSON array of operations or an object with \"ops\". Each operation is " +
1665
+ "{ \"op\": \"<name>\", …that operation's arguments }: set_node_field, set_edge_words, add_step, remove_step, " +
1666
+ "connect_steps, reconnect, disconnect (the same names and arguments as the canvas assistant's tools).");
1667
+ }
1668
+ const file = await readJsonFile(opsFile);
1669
+ const ops = Array.isArray(file) ? file : file && typeof file === "object" && Array.isArray(file.ops) ? file.ops : null;
1670
+ if (!ops)
1671
+ throw new UsageError(`${opsFile} must hold a JSON array of operations, or an object with an "ops" array.`);
1672
+ const revision = requireRevision(values.revision, "the revision `kumion flow get` showed when you read the flow you are changing.");
1673
+ const result = await (await clientFor(values, deps)).editFlowSteps(agentId, ops, revision, {
1674
+ dryRun: values["dry-run"] === true,
1675
+ });
1676
+ if (values.json) {
1677
+ printJson(deps, result);
1678
+ return 0;
1679
+ }
1680
+ const lines = [
1681
+ values["dry-run"] ? `Dry run — nothing was saved. Revision: ${result.revision}` : `Draft saved. New revision: ${result.revision}`,
1682
+ ];
1683
+ lines.push(result.changes.length === 0 ? "Nothing changed." : `Changes (${result.changes.length}):`);
1684
+ lines.push(...result.changes.map(flowStepChangeLine));
1685
+ if (result.added.length > 0) {
1686
+ lines.push(`Added (${result.added.length}):`, ...result.added.map((a) => ` ${a.key}: ${a.name}(${a.type})`));
1687
+ }
1688
+ if (result.consequences.length > 0) {
1689
+ lines.push(`Also changes (${result.consequences.length}):`, ...result.consequences.map((c) => ` ${c.text}`));
1690
+ }
1691
+ if (result.warnings.length > 0) {
1692
+ lines.push(`Not applied as asked (${result.warnings.length}):`, ...result.warnings.map((w) => ` ${w}`));
1693
+ }
1694
+ if (!values["dry-run"] && result.changes.length > 0) {
1695
+ lines.push(`Nothing is live until you run \`kumion agents publish ${agentId}\`.`);
1696
+ }
1697
+ deps.io.out(lines.join("\n"));
1698
+ return 0;
1699
+ }
473
1700
  const TERMINAL = new Set(["passed", "failed", "could_not_run", "timeout", "cancelled"]);
474
1701
  export function summarizeTestRun(run) {
475
1702
  const lines = [
@@ -555,11 +1782,28 @@ async function testRunsList(args, deps) {
555
1782
  return 0;
556
1783
  }
557
1784
  async function callsCreate(args, deps) {
558
- const { values, positionals } = parse(args, { "campaign-contact": { type: "string" } });
1785
+ const { values, positionals } = parse(args, {
1786
+ "campaign-contact": { type: "string" },
1787
+ to: { type: "string" },
1788
+ var: { type: "string", multiple: true },
1789
+ });
559
1790
  const agentId = need(positionals, 0, "agentId");
560
- const result = await (await clientFor(values, deps)).createCall(agentId, values["campaign-contact"]);
1791
+ const variables = {};
1792
+ for (const pair of values.var ?? []) {
1793
+ const at = pair.indexOf("=");
1794
+ if (at < 1)
1795
+ throw new UsageError(`--var must be <name>=<value> (got "${pair}").`);
1796
+ variables[pair.slice(0, at)] = pair.slice(at + 1);
1797
+ }
1798
+ const result = await (await clientFor(values, deps)).createCall(agentId, values["campaign-contact"], variables, values.to);
561
1799
  if (values.json)
562
1800
  printJson(deps, result);
1801
+ else if (values.to)
1802
+ deps.io.out([
1803
+ `Dialing ${values.to} with ${String(result.agentName ?? agentId)}.`,
1804
+ `Call log: ${String(result.callLogId)}`,
1805
+ "The result (answered, busy, no answer, failed) is on the call: kumion calls get <callLogId>.",
1806
+ ].join("\n"));
563
1807
  else
564
1808
  deps.io.out([
565
1809
  `Call started with ${String(result.agentName ?? agentId)}.`,
@@ -614,6 +1858,7 @@ async function callsList(args, deps) {
614
1858
  (c.remoteE164 ?? "-").padEnd(14),
615
1859
  c.hasTranscript ? "transcript" : "- ",
616
1860
  c.agentName ?? c.agentId ?? "-",
1861
+ c.outcome?.key ?? "-",
617
1862
  ].join(" "));
618
1863
  }
619
1864
  const last = page.offset + page.calls.length;
@@ -638,6 +1883,10 @@ async function callsGet(args, deps) {
638
1883
  `Answered: ${call.answeredAt ?? "-"}`,
639
1884
  `Ended: ${call.endedAt ?? "(still up)"}${call.endedReason ? ` — ${call.endedReason}` : ""}`,
640
1885
  `Disposition: ${call.disposition ?? "-"}${call.isVoicemail ? " (voicemail)" : ""}`,
1886
+ `Outcome: ${call.outcome ? `${call.outcome.key} — ${call.outcome.text}` : "-"}`,
1887
+ `Ended at: ${call.endedAtNode ? `${call.endedAtNode.name ?? call.endedAtNode.key} (${call.endedAtNode.key})` : "-"}`,
1888
+ `Duration: ${call.durationSec === null ? "-" : `${call.durationSec}s`}${call.transferred ? " — transferred to a person" : ""}`,
1889
+ `Recorded: ${call.capturedItems.length > 0 ? call.capturedItems.join(", ") : "-"}`,
641
1890
  ...(call.ticketNo ? [`Ticket: ${call.ticketNo}`] : []),
642
1891
  `Transcript: ${call.hasTranscript ? `yes — \`kumion calls transcript ${call.id}\`` : "none yet"}`,
643
1892
  ].join("\n"));