@kumion/cli 0.2.0 → 0.3.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,10 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { parseArgs } from "node:util";
3
- import { ApiError, KumionClient } from "./client.js";
3
+ import { ApiError, KumionClient, } from "./client.js";
4
4
  import { DEFAULT_BASE_URL, keyPrefix, looksLikeApiKey, normalizeBaseUrl, resolveCredentials, } from "./credentials.js";
5
5
  import { DEFAULT_DEVICE_SCOPES, deviceLogin } from "./device-login.js";
6
6
  import { describeError, ReportedFailure, UsageError } from "./errors.js";
7
- export const VERSION = "0.2.0";
7
+ export const VERSION = "0.3.0";
8
8
  const HELP = `kumion — manage your Kumion voice agents over the Partner API
9
9
 
10
10
  Usage: kumion <command> [options]
@@ -28,6 +28,66 @@ Agents
28
28
  Edit the draft (never goes live by itself)
29
29
  agents publish <agentId> [--revision <rev>]
30
30
  Publish the draft through the pre-publish check
31
+ agents opening-name <agentId> --revision <rev> (--on | --off)
32
+ Whether the opening line uses the caller's name (a draft write:
33
+ it reaches callers with the next publish)
34
+ agents availability <agentId> --revision <rev> [--operating-hours-file <path>] [--off-hours-file <path>]
35
+ Set when the agent answers (受付時間) and what happens to a
36
+ call outside it. Each file holds the JSON of that setting, or
37
+ null to clear it. LIVE: callers get it at once, no publish
38
+ (needs a key with agents:live)
39
+ agents create-from-template --template <id> --business-name <name> [--name <name>]
40
+ [--url <url> | --document <documentId>] [--idempotency-key <key>]
41
+ Create a DRAFT agent from an onboarding template. With no
42
+ source, every fact is 「まだない情報」. With a URL (same site,
43
+ up to 10 pages) or a document already uploaded and extracted
44
+ on the Portal's 資料 screen, only facts the source actually
45
+ states are filled, and the response lists both. Nothing is
46
+ published and no fact is confirmed.
47
+
48
+ Flow
49
+ flow get <agentId> Read the draft flow the way the canvas assistant reads it:
50
+ the 用件 (what each one says and asks for), which layer edits
51
+ it (用件 or steps), the staff a 用件 may transfer to, and the
52
+ pre-publish findings
53
+ flow update <agentId> --revision <rev> --patch-file <path> [--dry-run]
54
+ Change the 用件 — what each one says and asks for, and whether it
55
+ hands the caller to a staff member — with the same arguments and
56
+ the same rules the canvas assistant uses. A draft write: it
57
+ reaches callers with the next publish. --dry-run prints the
58
+ change and saves nothing
59
+ flow edit-steps <agentId> --revision <rev> --ops-file <path> [--dry-run]
60
+ Change a step-by-step flow — add or remove a step, join or part two,
61
+ one step's setting, one connection's words — as one batch, with
62
+ the same operations and rules the canvas assistant uses. The batch
63
+ is atomic (one refused operation refuses all of them) and moves the
64
+ revision once. --dry-run prints the change and saves nothing
65
+
66
+ Templates
67
+ templates list List the onboarding templates and their ids
68
+
69
+ Staff (the people a 用件 can transfer a call to)
70
+ staff list List the スタッフ with their transfer key, 転送先 and revision
71
+ staff create --name <name> [--transfer-target <number>] [--department <text>]
72
+ [--kana <text>] [--email <address>] [--note <text>] [--enabled false]
73
+ Register a スタッフ. The transfer key is generated for you and
74
+ printed back (--json shows it). A new row reaches no call until
75
+ a 用件's 転送 names its key
76
+ staff update <staffId> --revision <rev> [--name <name>] [--transfer-target <number>]
77
+ [--department <text>] [--kana <text>] [--email <address>] [--note <text>]
78
+ [--enabled true|false]
79
+ Change a スタッフ; an empty value (--note "") clears a field.
80
+ LIVE: the next call already transfers to the new value, no
81
+ publish (needs a key with agents:live). --enabled false takes
82
+ them out of the 転送 candidates
83
+
84
+ Facts (the agent's 資料)
85
+ facts list <agentId> List the facts with their state and revision
86
+ facts edit <agentId> <factId> --revision <rev> --value <text>
87
+ Confirm one fact with a new value. LIVE (needs agents:live)
88
+ facts confirm <agentId> [--fact <factId> ...]
89
+ Confirm pending facts as extracted (all of them without
90
+ --fact; a fact whose candidates disagree is skipped). LIVE
31
91
 
32
92
  Test runs
33
93
  test-runs start <agentId> [--no-wait] [--interval <sec>] [--timeout <sec>]
@@ -36,8 +96,9 @@ Test runs
36
96
  test-runs list <agentId> [--limit <n>]
37
97
 
38
98
  Calls
39
- calls create <agentId> [--campaign-contact <id>]
40
- Start a web call with the agent
99
+ calls create <agentId> [--to <phone>] [--campaign-contact <id>] [--var <name>=<value> ...]
100
+ Start a web call with the agent; with --to, dial that
101
+ domestic number instead (--var is read as {{vars.<name>}})
41
102
  calls list [--agent <id>] [--channel webcall|sip_did|trigger] [--from <iso>] [--to <iso>]
42
103
  [--search <text>] [--limit <n>] [--offset <n>]
43
104
  List the tenant's call history, newest first (20 per page)
@@ -156,7 +217,7 @@ async function clientFor(values, deps) {
156
217
  function printJson(deps, value) {
157
218
  deps.io.out(JSON.stringify(value, null, 2));
158
219
  }
159
- const COMMANDS = {
220
+ export const COMMANDS = {
160
221
  "auth login": authLogin,
161
222
  "auth status": authStatus,
162
223
  "auth list": authList,
@@ -166,6 +227,19 @@ const COMMANDS = {
166
227
  "agents get": agentsGet,
167
228
  "agents patch": agentsPatch,
168
229
  "agents publish": agentsPublish,
230
+ "agents opening-name": agentsOpeningName,
231
+ "agents availability": agentsAvailability,
232
+ "agents create-from-template": agentsCreateFromTemplate,
233
+ "flow get": flowGet,
234
+ "flow update": flowUpdate,
235
+ "flow edit-steps": flowEditSteps,
236
+ "templates list": templatesList,
237
+ "staff list": staffList,
238
+ "staff create": staffCreate,
239
+ "staff update": staffUpdate,
240
+ "facts list": factsList,
241
+ "facts edit": factsEdit,
242
+ "facts confirm": factsConfirm,
169
243
  "test-runs start": testRunsStart,
170
244
  "test-runs get": testRunsGet,
171
245
  "test-runs list": testRunsList,
@@ -424,6 +498,249 @@ async function agentsPatch(args, deps) {
424
498
  deps.io.out(`Draft saved. New revision: ${view.revision}\nNothing is live until you run \`kumion agents publish ${agentId}\`.`);
425
499
  return 0;
426
500
  }
501
+ function requireRevision(revision, what) {
502
+ if (!revision)
503
+ throw new UsageError(`Pass --revision <rev> — ${what}`);
504
+ return revision;
505
+ }
506
+ const AGENT_REVISION_HELP = "the revision `kumion agents get` showed when you read the agent you are changing.";
507
+ async function agentsOpeningName(args, deps) {
508
+ const { values, positionals } = parse(args, { revision: { type: "string" }, on: { type: "boolean" }, off: { type: "boolean" } });
509
+ const agentId = need(positionals, 0, "agentId");
510
+ if (values.on === values.off)
511
+ throw new UsageError("Pass --on or --off.");
512
+ const revision = requireRevision(values.revision, AGENT_REVISION_HELP);
513
+ const view = await (await clientFor(values, deps)).setOpeningName(agentId, values.on === true, revision);
514
+ if (values.json)
515
+ printJson(deps, view);
516
+ else
517
+ deps.io.out(`Saved: the opening line ${values.on ? "uses" : "does not use"} the caller's name. New revision: ${view.revision}\n` +
518
+ `It reaches callers with the next publish (\`kumion agents publish ${agentId}\`).`);
519
+ return 0;
520
+ }
521
+ async function agentsAvailability(args, deps) {
522
+ const { values, positionals } = parse(args, {
523
+ revision: { type: "string" },
524
+ "operating-hours-file": { type: "string" },
525
+ "off-hours-file": { type: "string" },
526
+ });
527
+ const agentId = need(positionals, 0, "agentId");
528
+ const patch = {};
529
+ if (values["operating-hours-file"])
530
+ patch.operatingHours = await readJsonFile(values["operating-hours-file"]);
531
+ if (values["off-hours-file"])
532
+ patch.offHoursPolicy = await readJsonFile(values["off-hours-file"]);
533
+ if (!("operatingHours" in patch) && !("offHoursPolicy" in patch)) {
534
+ throw new UsageError("Nothing to change. Pass --operating-hours-file and/or --off-hours-file.");
535
+ }
536
+ const revision = requireRevision(values.revision, AGENT_REVISION_HELP);
537
+ const view = await (await clientFor(values, deps)).setAvailability(agentId, patch, revision);
538
+ if (values.json)
539
+ printJson(deps, view);
540
+ else
541
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${view.revision}`);
542
+ return 0;
543
+ }
544
+ function factLine(fact) {
545
+ const state = fact.reviewState === "pending" ? `pending${fact.candidates.length > 0 ? ` (candidates: ${fact.candidates.join(" / ")})` : ""}` : (fact.value ?? "");
546
+ return `${fact.id} ${fact.label}: ${state} [revision ${fact.revision}]`;
547
+ }
548
+ async function factsList(args, deps) {
549
+ const { values, positionals } = parse(args, {});
550
+ const agentId = need(positionals, 0, "agentId");
551
+ const facts = await (await clientFor(values, deps)).listFacts(agentId);
552
+ if (values.json)
553
+ printJson(deps, { facts });
554
+ else if (facts.length === 0)
555
+ deps.io.out("No facts.");
556
+ else
557
+ for (const fact of facts)
558
+ deps.io.out(factLine(fact));
559
+ return 0;
560
+ }
561
+ async function templatesList(args, deps) {
562
+ const { values } = parse(args, {});
563
+ const templates = await (await clientFor(values, deps)).listAgentTemplates();
564
+ if (values.json) {
565
+ printJson(deps, { templates });
566
+ return 0;
567
+ }
568
+ if (templates.length === 0)
569
+ deps.io.out("No templates.");
570
+ else {
571
+ for (const template of templates) {
572
+ deps.io.out(`${template.id} ${template.label}`);
573
+ deps.io.out(` ${template.summary}`);
574
+ deps.io.out(` 用件: ${template.intents.map((intent) => intent.label).join("、")}`);
575
+ deps.io.out(` 事実: ${template.facts.map((fact) => fact.label).join("、")}`);
576
+ }
577
+ }
578
+ return 0;
579
+ }
580
+ async function agentsCreateFromTemplate(args, deps) {
581
+ const { values } = parse(args, {
582
+ template: { type: "string" },
583
+ "business-name": { type: "string" },
584
+ name: { type: "string" },
585
+ url: { type: "string" },
586
+ document: { type: "string" },
587
+ "idempotency-key": { type: "string" },
588
+ });
589
+ if (!values.template)
590
+ throw new UsageError("Pass --template <id> (see `kumion templates list`).");
591
+ if (!values["business-name"])
592
+ throw new UsageError("Pass --business-name <name> — it names the agent and greets the caller.");
593
+ if (values.url && values.document)
594
+ throw new UsageError("Pass --url or --document, not both.");
595
+ const result = await (await clientFor(values, deps)).createAgentFromTemplate({
596
+ templateId: values.template,
597
+ businessName: values["business-name"],
598
+ ...(values.name ? { name: values.name } : {}),
599
+ ...(values.url ? { url: values.url } : {}),
600
+ ...(values.document ? { documentId: values.document } : {}),
601
+ ...(values["idempotency-key"] ? { idempotencyKey: values["idempotency-key"] } : {}),
602
+ });
603
+ if (values.json) {
604
+ printJson(deps, result);
605
+ return 0;
606
+ }
607
+ deps.io.out(`Created ${result.agent.name} (${result.agent.id}) — draft, not published.`);
608
+ if (result.notice)
609
+ deps.io.out(result.notice);
610
+ deps.io.out(`用件: ${result.intents.map((intent) => intent.label).join("、")}`);
611
+ for (const fact of result.facts) {
612
+ deps.io.out(fact.value === null
613
+ ? ` まだない情報 ${fact.label}`
614
+ : ` ${fact.label}: ${fact.value}${fact.sourceExcerpt ? ` 「${fact.sourceExcerpt}」` : ""}`);
615
+ }
616
+ if (result.missing.length > 0) {
617
+ deps.io.out("");
618
+ deps.io.out(`${result.missing.length} 件は資料から読み取れませんでした。アシスタントで足すか、このまま公開できます。`);
619
+ }
620
+ deps.io.out("Next: `kumion agents get <id>`, `kumion test-runs start <id>`, `kumion agents publish <id>`.");
621
+ return 0;
622
+ }
623
+ function staffLine(staff) {
624
+ const target = staff.transferTarget ?? "no 転送先";
625
+ return `${staff.id} ${staff.enabled ? "enabled " : "disabled"} ${staff.displayName}: ${target} [key ${staff.key ?? "—"} revision ${staff.revision}]`;
626
+ }
627
+ async function staffList(args, deps) {
628
+ const { values } = parse(args, {});
629
+ const staff = await (await clientFor(values, deps)).listStaff();
630
+ if (values.json) {
631
+ printJson(deps, { staff });
632
+ return 0;
633
+ }
634
+ if (staff.length === 0)
635
+ deps.io.out("No staff.");
636
+ else
637
+ for (const row of staff)
638
+ deps.io.out(staffLine(row));
639
+ return 0;
640
+ }
641
+ function parseEnabled(value) {
642
+ if (value === undefined)
643
+ return undefined;
644
+ if (value === "true")
645
+ return true;
646
+ if (value === "false")
647
+ return false;
648
+ throw new UsageError("--enabled takes true or false.");
649
+ }
650
+ const STAFF_WRITE_FLAGS = {
651
+ name: { type: "string" },
652
+ "transfer-target": { type: "string" },
653
+ department: { type: "string" },
654
+ kana: { type: "string" },
655
+ email: { type: "string" },
656
+ note: { type: "string" },
657
+ enabled: { type: "string" },
658
+ };
659
+ async function staffCreate(args, deps) {
660
+ const { values } = parse(args, { ...STAFF_WRITE_FLAGS });
661
+ const displayName = values.name?.trim();
662
+ if (!displayName)
663
+ throw new UsageError("Pass --name <name> — it is what the operator sees when choosing a 転送先.");
664
+ const staff = await (await clientFor(values, deps)).createStaff({
665
+ displayName,
666
+ ...(values["transfer-target"] !== undefined ? { transferTarget: values["transfer-target"] } : {}),
667
+ ...(values.department !== undefined ? { department: values.department } : {}),
668
+ ...(values.kana !== undefined ? { kana: values.kana } : {}),
669
+ ...(values.email !== undefined ? { email: values.email } : {}),
670
+ ...(values.note !== undefined ? { note: values.note } : {}),
671
+ ...(values.enabled !== undefined ? { enabled: parseEnabled(values.enabled) } : {}),
672
+ });
673
+ if (values.json) {
674
+ printJson(deps, { staff });
675
+ return 0;
676
+ }
677
+ deps.io.out(`Created ${staff.displayName} (${staff.id}). Transfer key: ${staff.key}`);
678
+ deps.io.out(staff.transferCandidate
679
+ ? "It is a 転送 candidate now. Next: name this key as a 用件's transfer destination (`kumion flow get` shows the 用件)."
680
+ : "Not a 転送 candidate yet — it needs a 転送先 (--transfer-target) and to be enabled.");
681
+ return 0;
682
+ }
683
+ const STAFF_REVISION_HELP = "the revision `kumion staff list` showed for the スタッフ you are changing.";
684
+ async function staffUpdate(args, deps) {
685
+ const { values, positionals } = parse(args, { ...STAFF_WRITE_FLAGS, revision: { type: "string" } });
686
+ const staffId = need(positionals, 0, "staffId");
687
+ const patch = {};
688
+ if (values.name !== undefined)
689
+ patch.displayName = values.name;
690
+ if (values["transfer-target"] !== undefined)
691
+ patch.transferTarget = values["transfer-target"];
692
+ if (values.department !== undefined)
693
+ patch.department = values.department;
694
+ if (values.kana !== undefined)
695
+ patch.kana = values.kana;
696
+ if (values.email !== undefined)
697
+ patch.email = values.email;
698
+ if (values.note !== undefined)
699
+ patch.note = values.note;
700
+ const enabled = parseEnabled(values.enabled);
701
+ if (enabled !== undefined)
702
+ patch.enabled = enabled;
703
+ if (Object.keys(patch).length === 0) {
704
+ throw new UsageError("Nothing to change. Pass --name, --transfer-target, --department, --kana, --email, --note or --enabled.");
705
+ }
706
+ const revision = requireRevision(values.revision, STAFF_REVISION_HELP);
707
+ const staff = await (await clientFor(values, deps)).updateStaff(staffId, patch, revision);
708
+ if (values.json) {
709
+ printJson(deps, { staff });
710
+ return 0;
711
+ }
712
+ deps.io.out(`Saved and live now — no publish needed. New revision: ${staff.revision}`);
713
+ if (!staff.transferCandidate)
714
+ deps.io.out("This スタッフ is not a 転送 candidate now (disabled, or missing a 転送先).");
715
+ return 0;
716
+ }
717
+ async function factsEdit(args, deps) {
718
+ const { values, positionals } = parse(args, { revision: { type: "string" }, value: { type: "string" } });
719
+ const agentId = need(positionals, 0, "agentId");
720
+ const factId = need(positionals, 1, "factId");
721
+ if (values.value === undefined)
722
+ throw new UsageError("Pass --value <text>.");
723
+ const revision = requireRevision(values.revision, "the fact's revision from `kumion facts list`.");
724
+ const fact = await (await clientFor(values, deps)).editFact(agentId, factId, values.value, revision);
725
+ if (values.json)
726
+ printJson(deps, { fact });
727
+ else
728
+ deps.io.out(`Saved and live now — no publish needed.\n${factLine(fact)}`);
729
+ return 0;
730
+ }
731
+ async function factsConfirm(args, deps) {
732
+ const { values, positionals } = parse(args, { fact: { type: "string", multiple: true } });
733
+ const agentId = need(positionals, 0, "agentId");
734
+ const result = await (await clientFor(values, deps)).confirmFacts(agentId, values.fact && values.fact.length > 0 ? values.fact : undefined);
735
+ if (values.json)
736
+ printJson(deps, result);
737
+ else {
738
+ deps.io.out(`Confirmed ${result.confirmed.length} fact(s); live now — no publish needed.`);
739
+ for (const s of result.skipped)
740
+ deps.io.out(`Skipped (candidates disagree or none usable): ${s.id} ${s.label}`);
741
+ }
742
+ return 0;
743
+ }
427
744
  function formatFindings(findings, indent) {
428
745
  return (findings ?? []).map((f) => `${indent}- ${f.kind}${f.nodeKey ? ` @${f.nodeKey}` : ""}: ${f.detail}`);
429
746
  }
@@ -470,6 +787,150 @@ async function agentsPublish(args, deps) {
470
787
  throw new ReportedFailure(lines.join("\n"));
471
788
  }
472
789
  }
790
+ function findingLines(view) {
791
+ return [
792
+ ...view.findings.canvas.map((f) => ` [${f.severity === "error" ? "エラー" : "注意"}] ${f.message}`),
793
+ ...view.findings.structural.map((f) => ` [公開前チェック] ${f.detail}`),
794
+ ];
795
+ }
796
+ async function flowGet(args, deps) {
797
+ const { values, positionals } = parse(args, {});
798
+ const agentId = need(positionals, 0, "agentId");
799
+ const view = await (await clientFor(values, deps)).getFlow(agentId);
800
+ if (values.json) {
801
+ printJson(deps, view);
802
+ return 0;
803
+ }
804
+ const lines = [`Revision: ${view.revision}`];
805
+ if (!view.flow) {
806
+ 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.");
807
+ }
808
+ else {
809
+ lines.push(`Edit layer: flow — ${view.flow.leaves.length} 用件, edited as 用件 (the assistant's form).`);
810
+ for (const leaf of view.flow.leaves) {
811
+ lines.push(` ${leaf.key} ${leaf.label}: ${leaf.condition}`);
812
+ }
813
+ const steps = view.flow.leaves.filter((leaf) => (leaf.steps?.length ?? 0) > 0);
814
+ if (steps.length > 0)
815
+ lines.push(`Split into steps: ${steps.map((leaf) => leaf.key).join(", ")}`);
816
+ const examples = Object.keys(view.flow.examples);
817
+ if (examples.length > 0)
818
+ lines.push(`Confirmed first lines: ${examples.join(", ")}`);
819
+ }
820
+ if (view.staffChoices.length > 0)
821
+ lines.push(`Transfer targets: ${view.staffChoices.map((s) => `${s.key} (${s.name})`).join(", ")}`);
822
+ if (view.transferRefusal)
823
+ lines.push(`Transfer refused: ${view.transferRefusal}`);
824
+ const findings = findingLines(view);
825
+ lines.push(findings.length === 0 ? "Findings: none." : `Findings (${findings.length}):`, ...findings);
826
+ lines.push("Use --json for the full 用件 (what each one says and asks for).");
827
+ deps.io.out(lines.join("\n"));
828
+ return 0;
829
+ }
830
+ function flowChangeLine(change) {
831
+ const where = change.leafKey ? `${change.kind} ${change.leafKey}` : change.kind;
832
+ if (change.items)
833
+ return ` ${where}: ${change.items.before.join("、") || "(なし)"} → ${change.items.after.join("、") || "(なし)"}`;
834
+ return ` ${where}: 「${change.before}」→「${change.after}」`;
835
+ }
836
+ async function flowUpdate(args, deps) {
837
+ const { values, positionals } = parse(args, {
838
+ revision: { type: "string" },
839
+ "patch-file": { type: "string" },
840
+ "dry-run": { type: "boolean" },
841
+ });
842
+ const agentId = need(positionals, 0, "agentId");
843
+ const patchFile = values["patch-file"];
844
+ if (!patchFile) {
845
+ throw new UsageError("Pass --patch-file <path> — a JSON object of the change, in the arguments `flow get` and the canvas assistant use " +
846
+ "(leaves, personaPrompt, openingSpeech, noRouteSpeech, examples).");
847
+ }
848
+ const patch = await readJsonFile(patchFile);
849
+ if (!patch || typeof patch !== "object" || Array.isArray(patch))
850
+ throw new UsageError(`${patchFile} must hold a JSON object.`);
851
+ const revision = requireRevision(values.revision, "the revision `kumion flow get` showed when you read the flow you are changing.");
852
+ const result = await (await clientFor(values, deps)).updateFlow(agentId, patch, revision, {
853
+ dryRun: values["dry-run"] === true,
854
+ });
855
+ if (values.json) {
856
+ printJson(deps, result);
857
+ return 0;
858
+ }
859
+ const lines = [
860
+ values["dry-run"]
861
+ ? `Dry run — nothing was saved. Revision: ${result.revision}`
862
+ : `Draft saved. New revision: ${result.revision}`,
863
+ ];
864
+ lines.push(result.changes.length === 0 ? "Nothing changed." : `Changes (${result.changes.length}):`);
865
+ lines.push(...result.changes.map(flowChangeLine));
866
+ if (result.consequences.length > 0) {
867
+ lines.push(`Also changes (${result.consequences.length}):`, ...result.consequences.map((c) => ` ${c.text}`));
868
+ }
869
+ if (result.warnings.length > 0) {
870
+ lines.push(`Not applied as asked (${result.warnings.length}):`, ...result.warnings.map((w) => ` ${w}`));
871
+ }
872
+ if (!values["dry-run"] && result.changes.length > 0) {
873
+ lines.push(`Nothing is live until you run \`kumion agents publish ${agentId}\`.`);
874
+ }
875
+ deps.io.out(lines.join("\n"));
876
+ return 0;
877
+ }
878
+ function flowStepChangeLine(change) {
879
+ if (change.kind === "add_step")
880
+ return ` + ステップ ${change.node}(${change.key}・${change.stepType ?? "agent"})`;
881
+ if (change.kind === "remove_step")
882
+ return ` - ステップ ${change.node}(${change.key})`;
883
+ if (change.kind === "add_edge")
884
+ return ` + つながり ${change.node}${change.after ? `(${change.after})` : ""}`;
885
+ if (change.kind === "remove_edge")
886
+ return ` - つながり ${change.node}`;
887
+ return ` ${change.node}: ${change.field} 「${change.before}」→「${change.after}」`;
888
+ }
889
+ async function flowEditSteps(args, deps) {
890
+ const { values, positionals } = parse(args, {
891
+ revision: { type: "string" },
892
+ "ops-file": { type: "string" },
893
+ "dry-run": { type: "boolean" },
894
+ });
895
+ const agentId = need(positionals, 0, "agentId");
896
+ const opsFile = values["ops-file"];
897
+ if (!opsFile) {
898
+ throw new UsageError("Pass --ops-file <path> — the batch, as a JSON array of operations or an object with \"ops\". Each operation is " +
899
+ "{ \"op\": \"<name>\", …that operation's arguments }: set_node_field, set_edge_words, add_step, remove_step, " +
900
+ "connect_steps, reconnect, disconnect (the same names and arguments as the canvas assistant's tools).");
901
+ }
902
+ const file = await readJsonFile(opsFile);
903
+ const ops = Array.isArray(file) ? file : file && typeof file === "object" && Array.isArray(file.ops) ? file.ops : null;
904
+ if (!ops)
905
+ throw new UsageError(`${opsFile} must hold a JSON array of operations, or an object with an "ops" array.`);
906
+ const revision = requireRevision(values.revision, "the revision `kumion flow get` showed when you read the flow you are changing.");
907
+ const result = await (await clientFor(values, deps)).editFlowSteps(agentId, ops, revision, {
908
+ dryRun: values["dry-run"] === true,
909
+ });
910
+ if (values.json) {
911
+ printJson(deps, result);
912
+ return 0;
913
+ }
914
+ const lines = [
915
+ values["dry-run"] ? `Dry run — nothing was saved. Revision: ${result.revision}` : `Draft saved. New revision: ${result.revision}`,
916
+ ];
917
+ lines.push(result.changes.length === 0 ? "Nothing changed." : `Changes (${result.changes.length}):`);
918
+ lines.push(...result.changes.map(flowStepChangeLine));
919
+ if (result.added.length > 0) {
920
+ lines.push(`Added (${result.added.length}):`, ...result.added.map((a) => ` ${a.key}: ${a.name}(${a.type})`));
921
+ }
922
+ if (result.consequences.length > 0) {
923
+ lines.push(`Also changes (${result.consequences.length}):`, ...result.consequences.map((c) => ` ${c.text}`));
924
+ }
925
+ if (result.warnings.length > 0) {
926
+ lines.push(`Not applied as asked (${result.warnings.length}):`, ...result.warnings.map((w) => ` ${w}`));
927
+ }
928
+ if (!values["dry-run"] && result.changes.length > 0) {
929
+ lines.push(`Nothing is live until you run \`kumion agents publish ${agentId}\`.`);
930
+ }
931
+ deps.io.out(lines.join("\n"));
932
+ return 0;
933
+ }
473
934
  const TERMINAL = new Set(["passed", "failed", "could_not_run", "timeout", "cancelled"]);
474
935
  export function summarizeTestRun(run) {
475
936
  const lines = [
@@ -555,11 +1016,28 @@ async function testRunsList(args, deps) {
555
1016
  return 0;
556
1017
  }
557
1018
  async function callsCreate(args, deps) {
558
- const { values, positionals } = parse(args, { "campaign-contact": { type: "string" } });
1019
+ const { values, positionals } = parse(args, {
1020
+ "campaign-contact": { type: "string" },
1021
+ to: { type: "string" },
1022
+ var: { type: "string", multiple: true },
1023
+ });
559
1024
  const agentId = need(positionals, 0, "agentId");
560
- const result = await (await clientFor(values, deps)).createCall(agentId, values["campaign-contact"]);
1025
+ const variables = {};
1026
+ for (const pair of values.var ?? []) {
1027
+ const at = pair.indexOf("=");
1028
+ if (at < 1)
1029
+ throw new UsageError(`--var must be <name>=<value> (got "${pair}").`);
1030
+ variables[pair.slice(0, at)] = pair.slice(at + 1);
1031
+ }
1032
+ const result = await (await clientFor(values, deps)).createCall(agentId, values["campaign-contact"], variables, values.to);
561
1033
  if (values.json)
562
1034
  printJson(deps, result);
1035
+ else if (values.to)
1036
+ deps.io.out([
1037
+ `Dialing ${values.to} with ${String(result.agentName ?? agentId)}.`,
1038
+ `Call log: ${String(result.callLogId)}`,
1039
+ "The result (answered, busy, no answer, failed) is on the call: kumion calls get <callLogId>.",
1040
+ ].join("\n"));
563
1041
  else
564
1042
  deps.io.out([
565
1043
  `Call started with ${String(result.agentName ?? agentId)}.`,
@@ -614,6 +1092,7 @@ async function callsList(args, deps) {
614
1092
  (c.remoteE164 ?? "-").padEnd(14),
615
1093
  c.hasTranscript ? "transcript" : "- ",
616
1094
  c.agentName ?? c.agentId ?? "-",
1095
+ c.outcome?.key ?? "-",
617
1096
  ].join(" "));
618
1097
  }
619
1098
  const last = page.offset + page.calls.length;
@@ -638,6 +1117,10 @@ async function callsGet(args, deps) {
638
1117
  `Answered: ${call.answeredAt ?? "-"}`,
639
1118
  `Ended: ${call.endedAt ?? "(still up)"}${call.endedReason ? ` — ${call.endedReason}` : ""}`,
640
1119
  `Disposition: ${call.disposition ?? "-"}${call.isVoicemail ? " (voicemail)" : ""}`,
1120
+ `Outcome: ${call.outcome ? `${call.outcome.key} — ${call.outcome.text}` : "-"}`,
1121
+ `Ended at: ${call.endedAtNode ? `${call.endedAtNode.name ?? call.endedAtNode.key} (${call.endedAtNode.key})` : "-"}`,
1122
+ `Duration: ${call.durationSec === null ? "-" : `${call.durationSec}s`}${call.transferred ? " — transferred to a person" : ""}`,
1123
+ `Recorded: ${call.capturedItems.length > 0 ? call.capturedItems.join(", ") : "-"}`,
641
1124
  ...(call.ticketNo ? [`Ticket: ${call.ticketNo}`] : []),
642
1125
  `Transcript: ${call.hasTranscript ? `yes — \`kumion calls transcript ${call.id}\`` : "none yet"}`,
643
1126
  ].join("\n"));