@kumion/cli 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -104,6 +104,7 @@ would use.
104
104
  | --- | --- |
105
105
  | `kumion agents list` | `agents:read` |
106
106
  | `kumion agents get <agentId> [--json]` | `agents:read` |
107
+ | `kumion agents spec <agentId> [--version published\|draft\|<n>] [--format pdf\|docx\|markdown] [--out <path>]` | `agents:read` (the 応対仕様書 as a file: PDF by default, Word and Markdown too; `--out`, or a file in the current directory for PDF/Word) |
107
108
  | `kumion agents patch <agentId> --revision <rev> [--prompt <text> \| --prompt-file <path>] [--graph-file <path>]` | `agents:write` |
108
109
  | `kumion agents publish <agentId> [--revision <rev>]` | `agents:publish` |
109
110
  | `kumion agents opening-name <agentId> --revision <rev> (--on \| --off)` | `agents:write` (a draft write: live after the next publish) |
@@ -144,10 +145,21 @@ would use.
144
145
  | `kumion test-runs list <agentId>` | `tests:run` |
145
146
  | `kumion calls create <agentId> [--to <phone>] [--campaign-contact <id>] [--var <name>=<value> ...]` | `calls:create` |
146
147
  | `kumion calls list [--agent <id>] [--channel webcall\|sip_did\|trigger] [--from <iso>] [--to <iso>] [--search <text>] [--limit <n>] [--offset <n>]` | `calls:read` |
148
+ | `kumion scheduled-calls create <agentId> --to <phone> --at <iso8601-with-offset>` | `calls:create` |
149
+ | `kumion scheduled-calls list` | `calls:read` |
150
+ | `kumion scheduled-calls cancel <id>` | `calls:create` |
147
151
  | `kumion calls get <callId>` | `calls:read` |
148
152
  | `kumion calls transcript <callId>` | `calls:read` |
149
153
 
150
154
  A command whose key lacks the scope fails with a message naming the scope it needs.
155
+
156
+ `scheduled-calls create` places one dial at the time you give: `--at` must carry a timezone offset
157
+ (`2026-10-31T13:00:00+09:00`; a bare `13:00` is refused), be in the future, and the number a domestic one.
158
+ The dial happens once, with no automatic redial. It is refused with 403 when the tenant's automatic
159
+ outbound dialing is off or the plan is `free`, and with 409 when that number already has a scheduled or
160
+ running dial. `scheduled-calls list` shows the API-scheduled dials, newest first (at most 100), each with a
161
+ `state` (`scheduled`, `dialing`, `done`, ...) and a `reason`. `scheduled-calls cancel` works only before the
162
+ dial starts; after that it answers 404.
151
163
  `calls:read` is its own scope: a key that can start calls (`calls:create`) cannot read
152
164
  them. `calls list` returns one page (20 by default, at most 100) and prints the
153
165
  `--offset` of the next one. Every call in `calls list` and `calls get` carries what it came to: `outcome`
@@ -189,7 +201,7 @@ all: a template's agent starts unmounted, and mounting also retires the 「仮
189
201
 
190
202
  `capture-specs` is 記録項目, what the agent records after a call. A spec is the tenant's and the mount
191
203
  is the agent's: `capture-specs create --data-file` makes one (mounted on nothing yet),
192
- `capture-specs update <specId> --rev` changes it for every agent already mounted, and
204
+ `capture-specs update <specId> --revision` changes it for every agent already mounted, and
193
205
  `agents capture get|set <agentId>` reads and replaces the set one agent records (`--spec` repeats,
194
206
  `--clear` records nothing). `agents capture get` also answers `readiness` — whether THIS agent would
195
207
  record anything after a call; a shop whose other agent records is not evidence for this one.
@@ -339,10 +351,11 @@ A key a node does not store follows the agent's setting (会話の運用) or the
339
351
  | `wait_cover` | start, agent | `tune` | `{ enabled?, on_threshold?, threshold_ms?, on_query_start?, query_grace_ms? }` | Node-level hold phrase. By default it plays only when a lookup tool is still running after `query_grace_ms` (100 to 10000, default 1000); `on_query_start: false` turns that off. `on_threshold: true` also plays it after `threshold_ms` (2000 to 15000, default 2000) of silence on an ordinary turn (default off). `enabled: false` turns it off for this node. The phrase text is set per agent. |
340
352
  | `trigger_path` | trigger | `internal` | `string` | Generated. Shown read-only as the trigger URL. |
341
353
  | `opening_speech` | start | `required` | `string` | The opening line. Supports {{variables}}. |
342
- | `items` | start, agent | `required` | `{key,label?,example?,source?,value_type?,options?,must_ask?,tool?,option_writes?}[]` | What this step collects, one object per item, in the order it asks. `key`: slot key. `label`: display name. `example`: test-call example. `source`: where the value comes from (caller, derived, system, tool). `value_type`: kind (text, select, boolean, ...). `options`: choices of a select item. `must_ask`: ask the caller to confirm on the spot even if already known (advanced). `tool`: `{tool_key,result_field}` for a tool-sourced item. `option_writes`: option → tool that must succeed before that option lets the call leave (advanced). |
354
+ | `items` | start, agent | `required` | `{key,label?,example?,source?,value_type?,options?,must_ask?,min_digits?,max_digits?,tool?,option_writes?}[]` | What this step collects, one object per item, in the order it asks. `key`: slot key. `label`: display name. `example`: test-call example. `source`: where the value comes from (caller, derived, system, tool). `value_type`: kind (text, select, boolean, ...). `options`: choices of a select item. `must_ask`: ask the caller to confirm on the spot even if already known (advanced). `min_digits` / `max_digits`: for a `code` item, the fewest / most digits the value may hold, counted by the platform (the same number twice = exact length). `tool`: `{tool_key,result_field}` for a tool-sourced item. `option_writes`: option → tool that must succeed before that option lets the call leave (advanced). |
343
355
  | `allow_interruptions` | start, agent | `tune` | `boolean` | Absent means the caller may interrupt. Only an explicit false is stored. |
344
356
  | `respond_on_enter` | agent | `tune` | `boolean` | Absent means the node answers on arrival. Only an explicit false (wait for the caller) is stored. |
345
357
  | `confirm_before_end` | agent | `tune` | `boolean` | Absent means off (agents published before this setting keep their behaviour); a node created on the canvas stores true, and a node compiled from a SOP or document stores true when its connection to an end node requires items (the `end_without_readback` rule). On: the platform reads the recorded items back once before the call ends, and the end opens on a later caller turn with caller_confirmed. |
358
+ | `confirm_before_end_keys` | agent | `internal` | `string[]` | Set by the compiler on a 伝言 step. With `confirm_before_end` on, the end readback reads only these item keys (the call-back number); absent means every item the ending requires. |
346
359
  | `entry_lookup` | agent | `tune` | `string` | Absent means no lookup on entry. A tool key from this step's tools (`booking_list`): the platform calls it when the call arrives at this step, and the call and its result are in the step's context before the AI speaks. |
347
360
  | `quiet_wait` | start, agent | `tune` | `{ seconds, listen?, resume_speech? }` | Node-level wait. { seconds: 0 } turns the agent default off here. |
348
361
  | `optional_slots` | start, agent | `tune` | `string[]` | Slots declared elsewhere that this step may record when the caller volunteers them. |
@@ -570,7 +583,7 @@ kumion agents get <A> --json
570
583
  ```
571
584
 
572
585
  Publish runs the Portal's pre-publish check (a few minutes) and answers `publishRunId`,
573
- `publishedSnapshotId` and `unconfirmedFacts`; read the agent back for `publishState.live: true` and
586
+ `agent.publishedSnapshotId` and `unconfirmedFacts`; read the agent back for `publishState.live: true` and
574
587
  `unpublishedChanges: false`. `unconfirmedFacts` counts the facts nobody confirmed — a clean publish
575
588
  that still lists them is not a finished agent, so go back to step 5.
576
589
 
@@ -596,10 +609,10 @@ Codex or any other MCP host, one tool per command above: `list_agents`, `get_age
596
609
  `update_store_hours`, `set_store_hours_exception`, `get_booking_settings`,
597
610
  `update_booking_calendar`, `create_booking_service`, `update_booking_service`,
598
611
  `create_booking_resource`, `update_booking_resource`, `set_agent_booking`,
599
- `list_booking_slots`, `list_capture_specs`, `create_capture_spec`,
612
+ `list_booking_slots`, `get_agent_spec`, `list_capture_specs`, `create_capture_spec`,
600
613
  `update_capture_spec`, `get_agent_capture`, `set_agent_capture`, `upload_document`,
601
614
  `get_document_upload_job`, `get_document`, `replace_document`, `start_test_run`,
602
- `get_test_run`, `list_test_runs`, `create_call`, `list_calls`, `get_call`,
615
+ `get_test_run`, `list_test_runs`, `create_scheduled_call`, `list_scheduled_calls`, `cancel_scheduled_call`, `create_call`, `list_calls`, `get_call`,
603
616
  `get_call_transcript`. Each takes the same input as the API route and needs the same
604
617
  scope as its command.
605
618
 
package/dist/client.js CHANGED
@@ -25,6 +25,29 @@ export class NetworkError extends Error {
25
25
  }
26
26
  }
27
27
  const DOCUMENT_UPLOAD_FILES_PART = "files";
28
+ export function specText(file) {
29
+ const type = file.contentType ?? "";
30
+ if (!type.startsWith("text/"))
31
+ throw new Error(`this 仕様書 is a ${type || "binary"} file, not text`);
32
+ return new TextDecoder("utf-8").decode(file.body);
33
+ }
34
+ export function isTextFile(file) {
35
+ return (file.contentType ?? "").startsWith("text/");
36
+ }
37
+ function filenameOf(header) {
38
+ if (!header)
39
+ return null;
40
+ const extended = /filename\*=UTF-8''([^;]+)/i.exec(header);
41
+ if (extended?.[1]) {
42
+ try {
43
+ return decodeURIComponent(extended[1].trim());
44
+ }
45
+ catch {
46
+ }
47
+ }
48
+ const plain = /filename="([^"]*)"/i.exec(header) ?? /filename=([^;]+)/i.exec(header);
49
+ return plain?.[1]?.trim() ?? null;
50
+ }
28
51
  export class KumionClient {
29
52
  creds;
30
53
  fetchImpl;
@@ -91,6 +114,48 @@ export class KumionClient {
91
114
  const { body } = await this.request("GET", this.agentPath(agentId), "agents:read");
92
115
  return body;
93
116
  }
117
+ async getAgentSpec(agentId, options = {}) {
118
+ const query = new URLSearchParams();
119
+ if (options.version !== undefined)
120
+ query.set("version", options.version);
121
+ if (options.format !== undefined)
122
+ query.set("format", options.format);
123
+ const suffix = query.size > 0 ? `?${query.toString()}` : "";
124
+ return this.requestFile(this.agentPath(agentId, `/spec${suffix}`), "agents:read");
125
+ }
126
+ async requestFile(path, scope) {
127
+ const url = this.creds.baseUrl + path;
128
+ let res;
129
+ try {
130
+ res = await this.fetchImpl(url, {
131
+ method: "GET",
132
+ headers: { Authorization: `Bearer ${this.creds.apiKey}`, Accept: "*/*" },
133
+ });
134
+ }
135
+ catch (err) {
136
+ throw new NetworkError(url, err);
137
+ }
138
+ const bytes = new Uint8Array(await res.arrayBuffer());
139
+ if (res.status < 200 || res.status >= 300) {
140
+ let body = {};
141
+ const text = new TextDecoder("utf-8").decode(bytes);
142
+ if (text) {
143
+ try {
144
+ const parsed = JSON.parse(text);
145
+ body = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
146
+ }
147
+ catch {
148
+ body = { error: `Unexpected non-JSON response: ${text.slice(0, 200)}` };
149
+ }
150
+ }
151
+ throw new ApiError(res.status, body, scope, res.headers.get("retry-after"));
152
+ }
153
+ return {
154
+ body: bytes,
155
+ contentType: res.headers.get("content-type"),
156
+ filename: filenameOf(res.headers.get("content-disposition")),
157
+ };
158
+ }
94
159
  async listAgentTemplates() {
95
160
  const { body } = await this.request("GET", this.tenantPath("/agent-templates"), "agents:read");
96
161
  return body.templates;
@@ -212,6 +277,28 @@ export class KumionClient {
212
277
  const { body } = await this.request("GET", this.tenantPath(`/calls${qs ? `?${qs}` : ""}`), "calls:read");
213
278
  return body;
214
279
  }
280
+ async createScheduledCall(agentId, phoneNumber, scheduledAt) {
281
+ try {
282
+ const { body } = await this.request("POST", this.tenantPath("/scheduled-calls"), "calls:create", {
283
+ body: { agentId, phoneNumber, scheduledAt },
284
+ });
285
+ return body;
286
+ }
287
+ catch (err) {
288
+ if (err instanceof ApiError && err.status === 403 && !String(err.body.error ?? "").includes(err.scope)) {
289
+ throw new ApiError(403, { ...err.body, code: "scheduled_dialing_unavailable" }, err.scope, err.retryAfter);
290
+ }
291
+ throw err;
292
+ }
293
+ }
294
+ async listScheduledCalls() {
295
+ const { body } = await this.request("GET", this.tenantPath("/scheduled-calls"), "calls:read");
296
+ return body.scheduledCalls;
297
+ }
298
+ async cancelScheduledCall(scheduledCallId) {
299
+ const { body } = await this.request("DELETE", this.tenantPath(`/scheduled-calls/${encodeURIComponent(scheduledCallId)}`), "calls:create");
300
+ return body;
301
+ }
215
302
  async getCall(callId) {
216
303
  const { body } = await this.request("GET", this.tenantPath(`/calls/${encodeURIComponent(callId)}`), "calls:read");
217
304
  return body.call;
package/dist/errors.js CHANGED
@@ -23,6 +23,11 @@ export function describeApiError(err) {
23
23
  if (err.code === "plan_publish_required") {
24
24
  return `This tenant's plan cannot publish agents (403). Upgrade the plan in the Kumion Portal; no key change helps.${serverSaid(err)}`;
25
25
  }
26
+ if (err.code === "scheduled_dialing_unavailable") {
27
+ return ("This tenant cannot schedule calls (403): automatic outbound dialing is off for it, or its plan is free. " +
28
+ "Nothing was scheduled. Turn automatic dialing on in the Kumion Portal (設定), or dial now with `kumion calls create`." +
29
+ serverSaid(err));
30
+ }
26
31
  if (err.scope === "calls:create") {
27
32
  return ("The call was refused (403): the tenant has reached its call-minute limit (the trial minutes cap for an " +
28
33
  "unsigned tenant, or the monthly cap), or its plan cannot start calls. Check 設定 in the Kumion Portal." +
@@ -30,7 +35,26 @@ export function describeApiError(err) {
30
35
  }
31
36
  return `Access refused (403).${serverSaid(err)}`;
32
37
  }
38
+ case 400:
39
+ if (err.code === "no_versions") {
40
+ return ("This agent has no versions (400 no_versions): it answers from a prompt alone, with no canvas to publish, so " +
41
+ `there is no version number to name. Leave --version out.${serverSaid(err)}`);
42
+ }
43
+ if (err.code === "unsupported_format") {
44
+ return `That --format is not one this server produces (400 unsupported_format).${serverSaid(err)}`;
45
+ }
46
+ if (err.code === "invalid_version") {
47
+ return `--version takes published, draft, or a version number (400 invalid_version).${serverSaid(err)}`;
48
+ }
49
+ return `Request failed (400).${serverSaid(err)}`;
33
50
  case 404:
51
+ if (err.code === "not_published") {
52
+ return ("This agent has never been published (404 not_published), so there is no 公開中 version to export. Pass " +
53
+ `--version draft to export the draft instead.${serverSaid(err)}`);
54
+ }
55
+ if (err.code === "version_not_found") {
56
+ return `There is no such version of this agent (404 version_not_found). See the versions in \`kumion agents get <agentId>\`.${serverSaid(err)}`;
57
+ }
34
58
  return `Not found (404) — check the id, and that it belongs to this tenant.${serverSaid(err)}`;
35
59
  case 409:
36
60
  if (err.code === "draft_revision_conflict") {
@@ -39,6 +63,11 @@ export function describeApiError(err) {
39
63
  "change on top of it, and try again." +
40
64
  serverSaid(err));
41
65
  }
66
+ if (err.code === "agent_name_taken") {
67
+ return ("Another agent in this tenant already has that name (409 agent_name_taken). Nothing was created or renamed. " +
68
+ "Pick a different name and try again." +
69
+ serverSaid(err));
70
+ }
42
71
  if (err.code === "fact_revision_conflict") {
43
72
  return ("That fact changed since you read it (409): someone confirmed or edited it in the Portal or from another " +
44
73
  "client. Nothing was written. Run `kumion facts list <agentId>` for its new revision and try again." +
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- import { readFile } from "node:fs/promises";
2
- import { basename } from "node:path";
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { basename, join } from "node:path";
3
3
  import { parseArgs } from "node:util";
4
- import { ApiError, KumionClient, } from "./client.js";
4
+ import { ApiError, KumionClient, isTextFile, specText, } from "./client.js";
5
5
  import { DEFAULT_BASE_URL, keyPrefix, looksLikeApiKey, normalizeBaseUrl, resolveCredentials, } from "./credentials.js";
6
6
  import { DEFAULT_DEVICE_SCOPES, deviceLogin } from "./device-login.js";
7
7
  import { describeError, ReportedFailure, UsageError } from "./errors.js";
8
- export const VERSION = "0.4.0";
8
+ export const VERSION = "0.5.0";
9
9
  const HELP = `kumion — manage your Kumion voice agents over the Partner API
10
10
 
11
11
  Usage: kumion <command> [options]
@@ -25,6 +25,13 @@ Auth
25
25
  Agents
26
26
  agents list List the tenant's agents
27
27
  agents get <agentId> Show an agent's draft and published version
28
+ agents spec <agentId> [--version published|draft|<n>] [--format pdf|docx|markdown] [--out <path>]
29
+ Download the 応対仕様書 (the agent's settings as a document) for
30
+ a version: 公開中 by default, or the draft / a version number.
31
+ PDF by default; Word (docx) and Markdown too. Writes to --out;
32
+ Markdown without --out goes to stdout, and PDF/Word without --out
33
+ to the file the server names, in the current directory. The
34
+ 出力日時 on the cover is the moment of the export
28
35
  agents patch <agentId> --revision <rev> [--prompt <text> | --prompt-file <path>] [--graph-file <path>]
29
36
  Edit the draft (never goes live by itself)
30
37
  agents publish <agentId> [--revision <rev>]
@@ -128,7 +135,8 @@ Booking (予約設定 — one calendar for the tenant, read per agent)
128
135
  computes them (6 by default, at most 20). Reads only —
129
136
  nothing is reserved (needs agents:read)
130
137
 
131
- Facts (the agent's 資料) facts list <agentId> List the facts with their state and revision
138
+ Facts (the agent's 資料)
139
+ facts list <agentId> List the facts with their state and revision
132
140
  facts edit <agentId> <factId> --revision <rev> --value <text>
133
141
  Confirm one fact with a new value. LIVE (needs agents:live)
134
142
  facts confirm <agentId> [--fact <factId> ...]
@@ -188,6 +196,10 @@ Calls
188
196
  calls list [--agent <id>] [--channel webcall|sip_did|trigger] [--from <iso>] [--to <iso>]
189
197
  [--search <text>] [--limit <n>] [--offset <n>]
190
198
  List the tenant's call history, newest first (20 per page)
199
+ scheduled-calls create <agentId> --to <phone> --at <iso8601-with-offset>
200
+ Schedule one dial at that time (e.g. 2026-10-31T13:00:00+09:00)
201
+ scheduled-calls list List the dials scheduled through the API, newest first
202
+ scheduled-calls cancel <id> Cancel a scheduled dial that has not started
191
203
  calls get <callId> Show one call: source, numbers, times, how it ended
192
204
  calls transcript <callId> Print what the caller and the agent said
193
205
  (list/get/transcript need a key with calls:read)
@@ -313,6 +325,7 @@ export const COMMANDS = {
313
325
  "auth logout": authLogout,
314
326
  "agents list": agentsList,
315
327
  "agents get": agentsGet,
328
+ "agents spec": agentsSpec,
316
329
  "agents patch": agentsPatch,
317
330
  "agents publish": agentsPublish,
318
331
  "agents opening-name": agentsOpeningName,
@@ -351,6 +364,9 @@ export const COMMANDS = {
351
364
  "test-runs start": testRunsStart,
352
365
  "test-runs get": testRunsGet,
353
366
  "test-runs list": testRunsList,
367
+ "scheduled-calls create": scheduledCallsCreate,
368
+ "scheduled-calls list": scheduledCallsList,
369
+ "scheduled-calls cancel": scheduledCallsCancel,
354
370
  "calls create": callsCreate,
355
371
  "calls list": callsList,
356
372
  "calls get": callsGet,
@@ -556,6 +572,50 @@ async function agentsGet(args, deps) {
556
572
  ].join("\n"));
557
573
  return 0;
558
574
  }
575
+ async function agentsSpec(args, deps) {
576
+ const { values, positionals } = parse(args, {
577
+ version: { type: "string" },
578
+ format: { type: "string" },
579
+ out: { type: "string" },
580
+ });
581
+ const agentId = need(positionals, 0, "agentId");
582
+ const version = values.version;
583
+ if (version !== undefined && version !== "published" && version !== "draft" && !/^[1-9]\d*$/.test(version)) {
584
+ throw new UsageError("--version takes published (公開中), draft (下書き), or a version number (1, 2, …).");
585
+ }
586
+ const file = await (await clientFor(values, deps)).getAgentSpec(agentId, {
587
+ ...(version === undefined ? {} : { version }),
588
+ ...(values.format === undefined ? {} : { format: values.format }),
589
+ });
590
+ const text = isTextFile(file);
591
+ const bytes = file.body.byteLength;
592
+ const target = values.out ?? (text ? null : file.filename ?? defaultSpecName(agentId, file.contentType));
593
+ if (target === null) {
594
+ if (values.json) {
595
+ printJson(deps, { filename: file.filename, contentType: file.contentType, markdown: specText(file) });
596
+ return 0;
597
+ }
598
+ deps.io.out(specText(file).replace(/\n$/, ""));
599
+ return 0;
600
+ }
601
+ const path = values.out ? values.out : join((deps.cwd ?? process.cwd)(), target);
602
+ try {
603
+ await writeFile(path, file.body);
604
+ }
605
+ catch (err) {
606
+ throw new UsageError(`Cannot write ${path}: ${err.message}`);
607
+ }
608
+ if (values.json) {
609
+ printJson(deps, { path, filename: file.filename, contentType: file.contentType, bytes });
610
+ return 0;
611
+ }
612
+ deps.io.out(`Wrote ${path} (${file.filename ?? "仕様書"}, ${bytes} bytes)`);
613
+ return 0;
614
+ }
615
+ function defaultSpecName(agentId, contentType) {
616
+ const extension = contentType === "application/pdf" ? "pdf" : contentType?.includes("wordprocessingml") ? "docx" : "bin";
617
+ return `仕様書_${agentId}.${extension}`;
618
+ }
559
619
  async function agentsPatch(args, deps) {
560
620
  const { values, positionals } = parse(args, {
561
621
  revision: { type: "string" },
@@ -1781,6 +1841,42 @@ async function testRunsList(args, deps) {
1781
1841
  deps.io.out(`${r.id} ${r.status.padEnd(13)} ${r.casesDone}/${r.casesTotal} ${r.startedAt}`);
1782
1842
  return 0;
1783
1843
  }
1844
+ async function scheduledCallsCreate(args, deps) {
1845
+ const { values, positionals } = parse(args, { to: { type: "string" }, at: { type: "string" } });
1846
+ const agentId = need(positionals, 0, "agentId");
1847
+ if (!values.to)
1848
+ throw new UsageError("--to <phone> is required.");
1849
+ if (!values.at)
1850
+ throw new UsageError("--at <iso8601 with offset> is required.");
1851
+ const result = await (await clientFor(values, deps)).createScheduledCall(agentId, values.to, values.at);
1852
+ if (values.json)
1853
+ printJson(deps, result);
1854
+ else
1855
+ deps.io.out(`Scheduled ${String(result.phoneNumber)} for ${String(result.scheduledAt)}.\nId: ${String(result.id)}`);
1856
+ return 0;
1857
+ }
1858
+ async function scheduledCallsList(args, deps) {
1859
+ const { values } = parse(args, {});
1860
+ const rows = await (await clientFor(values, deps)).listScheduledCalls();
1861
+ if (values.json)
1862
+ printJson(deps, { scheduledCalls: rows });
1863
+ else if (rows.length === 0)
1864
+ deps.io.out("No scheduled calls.");
1865
+ else
1866
+ for (const r of rows)
1867
+ deps.io.out(`${String(r.id)} ${String(r.state).padEnd(9)} ${String(r.scheduledAt)} ${String(r.phoneNumber)}${r.reason ? ` (${String(r.reason)})` : ""}`);
1868
+ return 0;
1869
+ }
1870
+ async function scheduledCallsCancel(args, deps) {
1871
+ const { values, positionals } = parse(args, {});
1872
+ const id = need(positionals, 0, "id");
1873
+ const result = await (await clientFor(values, deps)).cancelScheduledCall(id);
1874
+ if (values.json)
1875
+ printJson(deps, result);
1876
+ else
1877
+ deps.io.out(`Canceled ${String(result.id)}.`);
1878
+ return 0;
1879
+ }
1784
1880
  async function callsCreate(args, deps) {
1785
1881
  const { values, positionals } = parse(args, {
1786
1882
  "campaign-contact": { type: "string" },
package/dist/mcp.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import { readFile } from "node:fs/promises";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
3
  import { basename } from "node:path";
4
4
  import { z } from "zod";
5
- import { ApiError } from "./client.js";
5
+ import { ApiError, isTextFile, specText } from "./client.js";
6
6
  import { describeError, UsageError } from "./errors.js";
7
7
  export const MAX_TEST_RUN_WAIT_SECONDS = 120;
8
8
  const TERMINAL = new Set(["passed", "failed", "could_not_run", "timeout", "cancelled"]);
@@ -71,8 +71,9 @@ export function createKumionMcpServer(client, options) {
71
71
  }, () => attempt(async () => ({ templates: await client.listAgentTemplates() })));
72
72
  server.registerTool("create_agent_from_template", {
73
73
  description: "Create a DRAFT agent from an onboarding template plus the business name, optionally reading a website " +
74
- "(`url`) or a document already uploaded and extracted on the Portal's 資料 screen (`documentId`; an API key " +
75
- "cannot upload one). Only facts the source actually states are filled; the rest come back as 「まだない情報」. " +
74
+ "(`url`) or a document already uploaded and extracted on the Portal's 資料 screen (`documentId`; upload it " +
75
+ "with `upload_document` first). Only facts the source actually states are filled; the rest come back as " +
76
+ "「まだない情報」. " +
76
77
  "Nothing is published and no fact is confirmed. Needs agents:write.",
77
78
  inputSchema: {
78
79
  templateId: z.string().min(1).describe("A template id from list_agent_templates."),
@@ -102,6 +103,53 @@ export function createKumionMcpServer(client, options) {
102
103
  inputSchema: { agentId },
103
104
  annotations: { readOnlyHint: true },
104
105
  }, (args) => attempt(() => client.getAgent(args.agentId)));
106
+ server.registerTool("get_agent_spec", {
107
+ description: "Download the agent's 応対仕様書 — the document that says, in Japanese, how the agent answers: the opening, " +
108
+ "the flow of a call, transfers, booking, the facts it may read out, what it records, who it notifies, and the " +
109
+ "AI instructions verbatim. `version` is published (the default), draft, or a version number. `format` is pdf " +
110
+ "(the default), docx (Word) or markdown; markdown comes back as the document itself, and pdf/docx are written " +
111
+ "to `outputPath`, which those two formats require. Chapters marked 〔出力時点〕 read settings that no version " +
112
+ "froze (hours, booking, 記録項目, 資料, 転送先, notifications) and are as they stand now. Needs agents:read.",
113
+ inputSchema: {
114
+ agentId,
115
+ version: z.string().min(1).optional().describe("published (default), draft, or a version number such as 3."),
116
+ format: z
117
+ .enum(["pdf", "docx", "markdown"])
118
+ .optional()
119
+ .describe("The output format: pdf (default), docx, or markdown. The first two answer with a file."),
120
+ outputPath: z
121
+ .string()
122
+ .min(1)
123
+ .optional()
124
+ .describe("Local file to write the document to. Required for pdf and docx — a binary file cannot travel as tool text. " +
125
+ "Ignored for markdown, which is returned as text."),
126
+ },
127
+ annotations: { readOnlyHint: true },
128
+ }, async (args) => {
129
+ try {
130
+ const file = await client.getAgentSpec(args.agentId, {
131
+ ...(args.version === undefined ? {} : { version: args.version }),
132
+ ...(args.format === undefined ? {} : { format: args.format }),
133
+ });
134
+ if (isTextFile(file)) {
135
+ return { content: [{ type: "text", text: specText(file) }] };
136
+ }
137
+ if (args.outputPath === undefined) {
138
+ throw new UsageError(`format=${args.format ?? "pdf"} answers with a file, not text: pass outputPath (a local path to write it to). ` +
139
+ "Use format=markdown for the document as text.");
140
+ }
141
+ await writeFile(args.outputPath, file.body);
142
+ return json({
143
+ path: args.outputPath,
144
+ bytes: file.body.byteLength,
145
+ filename: file.filename,
146
+ contentType: file.contentType,
147
+ });
148
+ }
149
+ catch (err) {
150
+ return failure(err);
151
+ }
152
+ });
105
153
  server.registerTool("get_call_flow", {
106
154
  description: "Read the agent's draft call flow the way the canvas assistant reads it: `editLayer` says whether it is edited " +
107
155
  "as 用件 (`flow`, with the 用件 subject, what each one says and asks for, and the confirmed caller examples) or " +
@@ -318,6 +366,25 @@ export function createKumionMcpServer(client, options) {
318
366
  },
319
367
  annotations: { idempotentHint: false },
320
368
  }, (args) => attempt(() => client.createCall(args.agentId, args.campaignContactId, args.variables, args.phoneNumber)));
369
+ server.registerTool("create_scheduled_call", {
370
+ description: "Schedule one outbound call at a stated time; the dialer places it once, with no automatic redial. " +
371
+ "scheduledAt must carry a timezone offset (2026-10-31T13:00:00+09:00). Needs calls:create.",
372
+ inputSchema: {
373
+ agentId,
374
+ phoneNumber: z.string().describe("Domestic Japanese number to dial."),
375
+ scheduledAt: z.string().describe("When to dial, ISO 8601 with a timezone offset."),
376
+ },
377
+ annotations: { idempotentHint: false },
378
+ }, (args) => attempt(() => client.createScheduledCall(args.agentId, args.phoneNumber, args.scheduledAt)));
379
+ server.registerTool("list_scheduled_calls", {
380
+ description: "List the calls scheduled through the API, newest first (at most 100), with state and reason. Needs calls:read.",
381
+ inputSchema: {},
382
+ annotations: { readOnlyHint: true },
383
+ }, () => attempt(async () => ({ scheduledCalls: await client.listScheduledCalls() })));
384
+ server.registerTool("cancel_scheduled_call", {
385
+ description: "Cancel a scheduled call that has not started. Needs calls:create.",
386
+ inputSchema: { scheduledCallId: z.string().min(1).describe("The id from create_scheduled_call or list_scheduled_calls.") },
387
+ }, (args) => attempt(() => client.cancelScheduledCall(args.scheduledCallId)));
321
388
  const callId = z.string().min(1).describe("The call's id, from list_calls.");
322
389
  server.registerTool("list_calls", {
323
390
  description: "List the tenant's call history, newest first, one page at a time (default 20, at most 100); `total` " +
@@ -715,7 +782,7 @@ export function createKumionMcpServer(client, options) {
715
782
  description: "Add one 記録項目. It is mounted on NO agent yet, so no call changes until something mounts it. Omit " +
716
783
  "`instruction` and the API writes one from the label, 場面 and fields — no model is called. `key` is " +
717
784
  "generated when omitted (print it back to the operator) and cannot be changed afterwards. Walls: at most " +
718
- "10 fields, at most 3 of them `summary`, and at most 5 enabled specs per tenant. Needs agents:write.",
785
+ "10 fields, at most 3 of them `summary`, and at most 20 enabled specs per tenant. Needs agents:write.",
719
786
  inputSchema: {
720
787
  label: z.string().min(1).describe("The name the operator sees (例: 予約内容)."),
721
788
  fields: z.array(captureSpecField).describe("The items to record, in the order they should be asked."),
@@ -741,7 +808,7 @@ export function createKumionMcpServer(client, options) {
741
808
  server.registerTool("update_capture_spec", {
742
809
  description: "Change one 記録項目. An omitted field is left alone; `key` cannot be changed. A hand-written `instruction` " +
743
810
  "is never rewritten by a field edit — only a generated one follows the fields. `scenario` and " +
744
- "`confirmationMessage` take null to clear. LIVE: every agent mounted with this spec records differently " +
811
+ "`confirmationMessage` take an empty string to clear. LIVE: every agent mounted with this spec records differently " +
745
812
  "from its next call, with no publish. `revision` is the spec's, from list_capture_specs; a stale one writes " +
746
813
  "nothing and answers a conflict. Needs agents:live.",
747
814
  inputSchema: {
@@ -873,7 +940,7 @@ export function createKumionMcpServer(client, options) {
873
940
  server.registerTool("get_document", {
874
941
  description: "Read one 資料: its summary (title, status, mode, character count), what it is wired into (the agents " +
875
942
  "and graph nodes in `references`), the extracted `fields` (each with its candidates, sources and review " +
876
- "state) and the `revision`. The raw text is never returned. This id is what create_from_template's " +
943
+ "state) and the `revision`. The raw text is never returned. This id is what create_agent_from_template's " +
877
944
  "`documentId` takes. Needs agents:read.",
878
945
  inputSchema: {
879
946
  documentId: z.string().min(1).describe("The document id, from get_document_upload_job."),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumion/cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Manage your Kumion voice agents from the terminal over the Kumion Partner API",
5
5
  "author": "KAOPA株式会社",
6
6
  "license": "MIT",
@@ -12,8 +12,8 @@ repository to clone and no local agent file to keep in sync — do not create on
12
12
  Two ways in, same operations and same permissions:
13
13
 
14
14
  - **MCP tools** when the host has the `kumion` MCP server registered. Each CLI
15
- command has one: `list_agents`, `get_agent`, `patch_agent`, `publish_agent`,
16
- `get_call_flow`, `update_call_flow`, `edit_call_flow_steps`,
15
+ command has one: `list_agents`, `get_agent`, `get_agent_spec`, `patch_agent`,
16
+ `publish_agent`, `get_call_flow`, `update_call_flow`, `edit_call_flow_steps`,
17
17
  `set_agent_opening_name`, `set_agent_availability`, `create_agent_from_template`,
18
18
  `list_agent_templates`, `list_facts`, `edit_fact`, `confirm_facts`,
19
19
  `list_staff`, `create_staff`, `update_staff`, `get_store_hours`,
@@ -93,6 +93,10 @@ A partner with several customers has one profile per customer tenant
93
93
  places a real outbound call instead (a domestic number; the agent must be published
94
94
  and have a phone number assigned) — only when the user asked to dial a real person.
95
95
  The outcome is on `get_call` / `kumion calls get`.
96
+ To dial at a stated time instead, `create_scheduled_call` / `kumion scheduled-calls create <agentId> --to <phone> --at <iso8601-with-offset>`
97
+ (the offset is required, the time must be in the future, one dial with no redial; 403 when the tenant's
98
+ automatic outbound dialing is off or the plan is free, 409 when the number already has a pending dial).
99
+ `list_scheduled_calls` shows the state; `cancel_scheduled_call` works only before the dial starts.
96
100
 
97
101
  ## From a template to a published agent
98
102
 
@@ -132,7 +136,7 @@ number. `--json` everywhere; the names below are the CLI's, the MCP tool is in t
132
136
  `severity: "error"` entry in `findings.canvas` and `findings.structural` must be empty.
133
137
  10. **Publish** — `kumion agents publish <A> --revision <rev> --json`, then `kumion agents get <A>`:
134
138
  `publishState.live: true`, `unpublishedChanges: false`, and the publish answer's
135
- `publishedSnapshotId`. `unconfirmedFacts` above zero means the agent is not finished.
139
+ `agent.publishedSnapshotId`. `unconfirmedFacts` above zero means the agent is not finished.
136
140
 
137
141
  ## Reading real calls
138
142
 
@@ -146,6 +150,34 @@ silent call. Use a transcript to find where the agent went wrong before editing
146
150
  draft. Transcripts are the tenant's customers' conversations: quote only what the task
147
151
  needs.
148
152
 
153
+ ## The 応対仕様書 (the agent's settings as one document)
154
+
155
+ `get_agent_spec` / `kumion agents spec <agentId>` writes the 応対仕様書: the Japanese
156
+ document that states how this agent answers — the opening, the flow of a call, transfers,
157
+ booking, the facts it may read out, what it records, who it notifies, and the AI
158
+ instructions verbatim. It is built from the stored settings; no model writes or rewords
159
+ any of it. It is what a customer files, or hands to someone reviewing what the agent says.
160
+ Needs `agents:read`.
161
+
162
+ - **`version`** — `published` (the default; the version answering calls today), `draft`,
163
+ or a version number such as `3`. An agent with no canvas has no versions at all, and
164
+ `published` answers its 現在の設定; an agent that was never published answers with its
165
+ draft, labelled 未公開.
166
+ - **`format`** — `pdf` (the default), `docx`, or `markdown`. Markdown is text and comes
167
+ back as the answer itself (MCP tool content, CLI stdout). PDF and Word are binary: MCP
168
+ writes them to `outputPath`, which those two require, and the CLI writes them to `--out`
169
+ — or, with no `--out`, to the server's own filename in the current directory.
170
+ - **Two kinds of chapter.** 〔この版〕 chapters were frozen when the chosen version was
171
+ published. 〔出力時点〕 chapters read settings no version froze — 店舗, 予約, 記録項目,
172
+ 資料, 転送先, 通知 — and state them as they stand at export. Exporting an older version
173
+ therefore mixes that version's content with today's settings on purpose; say so when
174
+ handing one over. A draft carries 「下書き」 on every page.
175
+ - **Exporting changes nothing.** It is a read: 公開中 stays the version it was, and the
176
+ next call answers from it. The export date on the cover is the moment of the export.
177
+
178
+ Do not retype or summarise the document into the conversation: save it and give the user
179
+ the path (or hand it to them where the host can attach files).
180
+
149
181
  ## The shop clock (営業時間)
150
182
 
151
183
  When the call answers 「何時までですか」, it reads the tenant's one booking calendar.
@@ -224,10 +256,11 @@ A key a node does not store follows the agent's setting (会話の運用) or the
224
256
  | `wait_cover` | start, agent | `tune` | `{ enabled?, on_threshold?, threshold_ms?, on_query_start?, query_grace_ms? }` | Node-level hold phrase. By default it plays only when a lookup tool is still running after `query_grace_ms` (100 to 10000, default 1000); `on_query_start: false` turns that off. `on_threshold: true` also plays it after `threshold_ms` (2000 to 15000, default 2000) of silence on an ordinary turn (default off). `enabled: false` turns it off for this node. The phrase text is set per agent. |
225
257
  | `trigger_path` | trigger | `internal` | `string` | Generated. Shown read-only as the trigger URL. |
226
258
  | `opening_speech` | start | `required` | `string` | The opening line. Supports {{variables}}. |
227
- | `items` | start, agent | `required` | `{key,label?,example?,source?,value_type?,options?,must_ask?,tool?,option_writes?}[]` | What this step collects, one object per item, in the order it asks. `key`: slot key. `label`: display name. `example`: test-call example. `source`: where the value comes from (caller, derived, system, tool). `value_type`: kind (text, select, boolean, ...). `options`: choices of a select item. `must_ask`: ask the caller to confirm on the spot even if already known (advanced). `tool`: `{tool_key,result_field}` for a tool-sourced item. `option_writes`: option → tool that must succeed before that option lets the call leave (advanced). |
259
+ | `items` | start, agent | `required` | `{key,label?,example?,source?,value_type?,options?,must_ask?,min_digits?,max_digits?,tool?,option_writes?}[]` | What this step collects, one object per item, in the order it asks. `key`: slot key. `label`: display name. `example`: test-call example. `source`: where the value comes from (caller, derived, system, tool). `value_type`: kind (text, select, boolean, ...). `options`: choices of a select item. `must_ask`: ask the caller to confirm on the spot even if already known (advanced). `min_digits` / `max_digits`: for a `code` item, the fewest / most digits the value may hold, counted by the platform (the same number twice = exact length). `tool`: `{tool_key,result_field}` for a tool-sourced item. `option_writes`: option → tool that must succeed before that option lets the call leave (advanced). |
228
260
  | `allow_interruptions` | start, agent | `tune` | `boolean` | Absent means the caller may interrupt. Only an explicit false is stored. |
229
261
  | `respond_on_enter` | agent | `tune` | `boolean` | Absent means the node answers on arrival. Only an explicit false (wait for the caller) is stored. |
230
262
  | `confirm_before_end` | agent | `tune` | `boolean` | Absent means off (agents published before this setting keep their behaviour); a node created on the canvas stores true, and a node compiled from a SOP or document stores true when its connection to an end node requires items (the `end_without_readback` rule). On: the platform reads the recorded items back once before the call ends, and the end opens on a later caller turn with caller_confirmed. |
263
+ | `confirm_before_end_keys` | agent | `internal` | `string[]` | Set by the compiler on a 伝言 step. With `confirm_before_end` on, the end readback reads only these item keys (the call-back number); absent means every item the ending requires. |
231
264
  | `entry_lookup` | agent | `tune` | `string` | Absent means no lookup on entry. A tool key from this step's tools (`booking_list`): the platform calls it when the call arrives at this step, and the call and its result are in the step's context before the AI speaks. |
232
265
  | `quiet_wait` | start, agent | `tune` | `{ seconds, listen?, resume_speech? }` | Node-level wait. { seconds: 0 } turns the agent default off here. |
233
266
  | `optional_slots` | start, agent | `tune` | `string[]` | Slots declared elsewhere that this step may record when the caller volunteers them. |