@kumion/cli 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -104,27 +104,62 @@ 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) |
110
111
  | `kumion agents availability <agentId> --revision <rev> [--operating-hours-file <path>] [--off-hours-file <path>]` | `agents:live` (live: no publish) |
112
+ | `kumion agents create-from-template --template <id> --business-name <name> [--name <name>] [--url <url> \| --document <documentId>] [--idempotency-key <key>]` | `agents:write` (a `url` makes it read an external site and call the model; the key makes a resend return the first agent) |
113
+ | `kumion agents capture get <agentId>` | `agents:read` |
114
+ | `kumion agents capture set <agentId> --revision <rev> (--spec <specId> ... \| --clear)` | `agents:live` (live: no publish) |
111
115
  | `kumion flow get <agentId>` | `agents:read` |
112
116
  | `kumion flow update <agentId> --revision <rev> --patch-file <path> [--dry-run]` | `agents:write` |
113
117
  | `kumion flow edit-steps <agentId> --revision <rev> --ops-file <path> [--dry-run]` | `agents:write` |
114
118
  | `kumion templates list` | `agents:read` |
115
- | `kumion agents create-from-template --template <id> --business-name <name> [--name <name>] [--url <url> \| --document <documentId>] [--idempotency-key <key>]` | `agents:write` (a `url` makes it read an external site and call the model; the key makes a resend return the first agent) |
116
119
  | `kumion staff list` | `agents:read` |
117
120
  | `kumion staff create --name <name> [--transfer-target <number>] [--department <text>] [--kana <text>] [--email <address>] [--note <text>] [--enabled false]` | `agents:write` (draft-side: no call reaches a new row until a 用件's 転送 names its key and the agent is published) |
118
121
  | `kumion staff update <staffId> --revision <rev> [--name ...] [--transfer-target ...] [--enabled true\|false]` | `agents:live` (live: no publish) |
122
+ | `kumion hours get [--from <date>] [--to <date>] [--json]` | `agents:read` |
123
+ | `kumion hours update --revision <rev> [--business-hours-file <path>] [--closed-rules-file <path>] [--observe-jp-holidays true\|false] [--dry-run]` | `agents:live` (live: no publish) |
124
+ | `kumion hours exception set <date> --revision <rev> --kind closed\|open\|inherit [--hours-file <path>] [--note <text>] [--dry-run]` | `agents:live` (live: no publish) |
125
+ | `kumion booking get <agentId>` | `agents:read` |
126
+ | `kumion booking calendar update --revision <rev> --patch-file <path> [--dry-run]` | `agents:live` (live: no publish) |
127
+ | `kumion booking services create --revision <rev> --data-file <path> [--dry-run]` | `agents:live` (live: no publish) |
128
+ | `kumion booking services update <serviceId> --revision <rev> --patch-file <path> [--dry-run]` | `agents:live` (live: no publish) |
129
+ | `kumion booking resources create --revision <rev> --data-file <path> [--dry-run]` | `agents:live` (live: no publish) |
130
+ | `kumion booking resources update <resourceId> --revision <rev> --patch-file <path> [--dry-run]` | `agents:live` (live: no publish) |
131
+ | `kumion booking mount <agentId> --mounted true\|false --revision <rev> [--dry-run]` | `agents:live` (live: no publish) |
132
+ | `kumion booking slots <agentId> --resource <resourceId> --date <YYYY-MM-DD> [--service <serviceId>] [--limit <n>]` | `agents:read` |
119
133
  | `kumion facts list <agentId>` | `agents:read` |
120
- | `kumion facts edit <agentId> <factId> --revision <rev> --value <text>` / `facts confirm <agentId> [--fact <id> ...]` | `agents:live` (live: no publish) |
134
+ | `kumion facts edit <agentId> <factId> --revision <rev> --value <text>` | `agents:live` (live: no publish) |
135
+ | `kumion facts confirm <agentId> [--fact <id> ...]` | `agents:live` (live: no publish) |
136
+ | `kumion capture-specs list` | `agents:read` |
137
+ | `kumion capture-specs create --data-file <path>` | `agents:write` (draft: a new spec is mounted on no agent yet) |
138
+ | `kumion capture-specs update <specId> --revision <rev> --patch-file <path>` | `agents:live` (live: every agent mounted with it records differently) |
139
+ | `kumion documents upload (--text-file <path> \| --file <path> [--file <path> ...]) --title <title> --idempotency-key <key> [--template <templateId>] [--dry-run]` | `agents:write` (one counted model extraction; see [From a template to public](#from-a-template-to-public)) |
140
+ | `kumion documents jobs get <jobId>` | `agents:read` (exits 1 when the job failed or timed out) |
141
+ | `kumion documents get <documentId>` | `agents:read` |
142
+ | `kumion documents replace <documentId> --source <sourceDocumentId> --source-revision <rev> --revision <rev> [--dry-run]` | `agents:live` (live: no publish) |
121
143
  | `kumion test-runs start <agentId> [--no-wait] [--interval <sec>] [--timeout <sec>]` | `tests:run` |
122
- | `kumion test-runs get <agentId> <runId>` / `test-runs list <agentId>` | `tests:run` |
144
+ | `kumion test-runs get <agentId> <runId>` | `tests:run` |
145
+ | `kumion test-runs list <agentId>` | `tests:run` |
123
146
  | `kumion calls create <agentId> [--to <phone>] [--campaign-contact <id>] [--var <name>=<value> ...]` | `calls:create` |
124
147
  | `kumion calls list [--agent <id>] [--channel webcall\|sip_did\|trigger] [--from <iso>] [--to <iso>] [--search <text>] [--limit <n>] [--offset <n>]` | `calls:read` |
125
- | `kumion calls get <callId>` / `calls transcript <callId>` | `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` |
151
+ | `kumion calls get <callId>` | `calls:read` |
152
+ | `kumion calls transcript <callId>` | `calls:read` |
126
153
 
127
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.
128
163
  `calls:read` is its own scope: a key that can start calls (`calls:create`) cannot read
129
164
  them. `calls list` returns one page (20 by default, at most 100) and prints the
130
165
  `--offset` of the next one. Every call in `calls list` and `calls get` carries what it came to: `outcome`
@@ -133,6 +168,49 @@ them. `calls list` returns one page (20 by default, at most 100) and prints the
133
168
  items it recorded, never their values). A transcript holds only what the caller and the agent said.
134
169
  Add `--json` to any command for the API's JSON instead of a summary.
135
170
 
171
+ `hours` is the shop clock the call answers 「何時までですか」 from, and it is one calendar for the
172
+ whole tenant. `hours update` replaces a field whole (a `--business-hours-file` holding Mon–Fri makes
173
+ Sat and Sun closed), and an omitted field is left alone. `hours exception set` writes one date:
174
+ `closed` is 臨時休業, `open` is 振替出勤 with its own `--hours-file` (or the weekday's hours), and
175
+ `inherit` deletes the date's row so the weekly rule applies again. Both writes carry `--revision`,
176
+ the number `hours get` prints; anything that changes the same calendar in between — the Portal's
177
+ 予約設定, a 担当 or 内容, a published mount — moves it, and a stale write is refused with a conflict
178
+ and nothing saved. `--dry-run` shows what would be saved without moving the revision.
179
+
180
+ `booking` is 予約設定, the same calendar seen from the booking side. `booking get <agentId>` answers
181
+ the slot length, the lead time, the horizon, the **内容** (what can be booked and how long it takes),
182
+ the **担当**, and whether that agent is mounted — plus the `revision` every write below needs. It is
183
+ per agent because the mount is; the settings themselves are the tenant's. `booking calendar update`
184
+ takes a `--patch-file` holding `defaultSlotMinutes` (1–1440), `minLeadMinutes` (0–43200) and/or
185
+ `maxAdvanceDays` (1–730); an omitted field is left alone. `booking services create --data-file` takes
186
+ `name` and `durationMinutes`, and `durationMinutes: null` means 「枠の長さを使う」 — the same null the
187
+ read-back shows. `booking services update` changes a name and/or a duration, `null` going back to the
188
+ slot length. Values must be JSON numbers: `"30"` is refused, not read as 30. All three writes are
189
+ live, and a create carries the revision too, so two callers holding one revision cannot both add a
190
+ 内容 — the second is refused.
191
+
192
+ `booking resources create|update` is a **担当** — who a booking is with. `--data-file` holds `name`,
193
+ `enabled`, `weeklyHours` (`{ "mon": [{ "start": "09:00", "end": "12:00" }] }`) and `serviceIds`
194
+ (`[]` takes every 内容; a list takes only those; omitted keeps the current setting). A 内容 id that is
195
+ not this tenant's refuses the whole write. `enabled: false` takes a 担当 out of service without
196
+ deleting it. `booking mount <agentId> --mounted true|false` is the switch that lets the agent book at
197
+ all: a template's agent starts unmounted, and mounting also retires the 「仮受付」 promise from the
198
+ 受付サマリー in the same write. `booking slots <agentId> --resource <id> --date <date>` reads one
199
+ 担当's openings for one day, computed the way a call computes them (6 by default, at most 20 with
200
+ `--limit`); it reserves nothing and returns no customer's data.
201
+
202
+ `capture-specs` is 記録項目, what the agent records after a call. A spec is the tenant's and the mount
203
+ is the agent's: `capture-specs create --data-file` makes one (mounted on nothing yet),
204
+ `capture-specs update <specId> --revision` changes it for every agent already mounted, and
205
+ `agents capture get|set <agentId>` reads and replaces the set one agent records (`--spec` repeats,
206
+ `--clear` records nothing). `agents capture get` also answers `readiness` — whether THIS agent would
207
+ record anything after a call; a shop whose other agent records is not evidence for this one.
208
+
209
+ `documents` is 資料, the source a template's facts are extracted from: `upload` accepts the text or the
210
+ files and answers a job, `jobs get` follows it, `get` reads the extracted fields, and `replace` gives
211
+ an existing 資料 another document's content while keeping its id. The next section walks the whole
212
+ path; the limits are there too.
213
+
136
214
  ### Per-call variables
137
215
 
138
216
  `calls create --var 氏名=山田 --var route=B` starts the call with those values; the agent reads
@@ -201,6 +279,27 @@ is written: read it again and re-apply your change.
201
279
  `--graph-file` accepts either a bare flow graph or the whole `agents get --json`
202
280
  output, in which case the revision inside the file is used.
203
281
 
282
+ **External send settings are closed here.** A setting that decides where a call sends
283
+ something, or which recording it plays before the first word, can be sent back
284
+ unchanged but not added, removed or changed — the same fields the Portal's canvas owns
285
+ and the assistant may not write:
286
+
287
+ - a webhook step's `endpoint_url`, `http_method`, `payload_template`, `custom_headers`
288
+ - the start step's `precall_fetch_url`, `precall_fetch_method`, `precall_fetch_headers`
289
+ - a notification step's `notify` (channel, recipients, subject and body templates)
290
+ - a transfer step's target, unless it is the key of an enabled スタッフ with a 転送先
291
+ (`staff list` shows `transferCandidate`)
292
+ - the start step's `opening_audio_url` and `opening_audio_filename`
293
+ - an IVR menu step's `ivr.prompt.audio_url` (the menu recording — its announcement
294
+ text is ordinary text and stays editable)
295
+
296
+ Adding a webhook or notification step at all is refused for the same reason: its
297
+ defaults would decide where it posts or whom it mails. Deleting a whole step that
298
+ carries one of these settings is allowed — that only takes the capability away, which
299
+ is why a graph with an existing setting round-trips. A refused write answers `422`
300
+ with code `external_field_closed` and the `paths` it objected to; nothing is written
301
+ and the draft revision does not move. Edit those settings in the Portal.
302
+
204
303
  ### Settings that reach callers at once
205
304
 
206
305
  Three settings are not part of the draft, so a write to them needs no publish:
@@ -216,13 +315,15 @@ They need the scope **`agents:live`**, which is not part of `agents:write` (that
216
315
 
217
316
  The CLI is a client of the Partner API (the commands above), so it can only do what
218
317
  that API exposes. These Portal features have no Partner API route yet and are not in
219
- the CLI: conversation-edit mode and its monthly count, knowledge-base bulk delete, filtering
220
- bookings by agent, applying 解決策 to pre-publish findings, external-tool rate-limit /
318
+ the CLI: conversation-edit mode and its monthly count, knowledge-base bulk delete,
319
+ making / moving / cancelling a customer's booking record and the notifications that go
320
+ with it, filtering bookings by agent, applying 解決策 to pre-publish findings, external-tool rate-limit /
221
321
  circuit-breaker status, the agent language / English locale, a tool's display name (表示名),
222
322
  the agent's call-outcome categories (通話の結果), and the call model with its TTS voice (`agents get` shows them, `agents patch` cannot
223
323
  change them: it writes only `prompt` and `graph`). Flow-level settings that live inside
224
- the graph (IVR recording, slot sources, transfer nodes) travel with
225
- `agents get --json` / `agents patch --graph-file` unchanged.
324
+ the graph (for example an IVR dial table or what a step asks for) travel with
325
+ `agents get --json` / `agents patch --graph-file`; the external send settings listed under
326
+ `agents patch` above must be sent back unchanged.
226
327
 
227
328
  ### Node configuration reference
228
329
 
@@ -250,10 +351,11 @@ A key a node does not store follows the agent's setting (会話の運用) or the
250
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. |
251
352
  | `trigger_path` | trigger | `internal` | `string` | Generated. Shown read-only as the trigger URL. |
252
353
  | `opening_speech` | start | `required` | `string` | The opening line. Supports {{variables}}. |
253
- | `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). |
254
355
  | `allow_interruptions` | start, agent | `tune` | `boolean` | Absent means the caller may interrupt. Only an explicit false is stored. |
255
356
  | `respond_on_enter` | agent | `tune` | `boolean` | Absent means the node answers on arrival. Only an explicit false (wait for the caller) is stored. |
256
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. |
257
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. |
258
360
  | `quiet_wait` | start, agent | `tune` | `{ seconds, listen?, resume_speech? }` | Node-level wait. { seconds: 0 } turns the agent default off here. |
259
361
  | `optional_slots` | start, agent | `tune` | `string[]` | Slots declared elsewhere that this step may record when the caller volunteers them. |
@@ -316,17 +418,203 @@ the check. When a check before the test calls refuses (most often the dependency
316
418
  cases to print: the server's message after `Server said:` is the whole reason, one
317
419
  problem per line.
318
420
 
421
+ ## From a template to public
422
+
423
+ One path from an empty tenant to a published agent, with nothing but the CLI (each command is also
424
+ an [MCP tool](#use-it-from-an-ai-coding-assistant-mcp)). The key needs `agents:read`,
425
+ `agents:write`, `agents:live` and, for the last step, `agents:publish`.
426
+
427
+ Every write takes the `revision` the step before it printed. Never carry one over from an earlier
428
+ run: a `409` means something moved in between, and the fix is to read again — not to retry with the
429
+ old number. `--json` is on every command below so a script can read the values back.
430
+
431
+ Names used below: `A` is the agent id, `D` the 資料 the agent was created with, `S` the 資料 you
432
+ uploaded.
433
+
434
+ ### 1. Create the agent from a template
435
+
436
+ ```sh
437
+ kumion templates list
438
+ kumion agents create-from-template --template <templateId> --business-name "山田歯科" \
439
+ --idempotency-key create-1 --json
440
+ ```
441
+
442
+ Keep `A` (`agent.id`), its `workflow.id` and `document.id` (`D`). Nothing is published and no fact
443
+ is confirmed; with no source, every fact is 「まだない情報」. A resend with the same
444
+ `--idempotency-key` answers the first agent instead of creating a second. The draft's `revision` is
445
+ not in this answer — it comes from `agents get` / `flow get` when you first write.
446
+
447
+ ### 2. Upload the real 資料
448
+
449
+ ```sh
450
+ kumion documents upload --text-file ./料金表.txt --template <templateId> \
451
+ --title "料金表" --idempotency-key upload-1 --dry-run --json
452
+ # read the size, the model and the allowance left, then send it for real
453
+ kumion documents upload --text-file ./料金表.txt --template <templateId> \
454
+ --title "料金表" --idempotency-key upload-1 --json
455
+ ```
456
+
457
+ `--text-file` sends the text of one file; `--file` (repeatable) sends `.txt`, `.md`, `.pdf`, `.docx`
458
+ or `.xlsx` — up to 10 files and 20 MiB — and the server parses them; several files become one 資料, in
459
+ the order given. Use one or the other, not both.
460
+
461
+ Uploads are counted, not billed: **10 extractions per key per rolling hour**, and never more than the
462
+ tenant's own `document_writes_per_hour` (20 by default); **one upload in flight per key**, two per
463
+ tenant. Any of those is a `429` with `Retry-After`. `--dry-run` runs the same checks and reports
464
+ `bytes`, `chars`, the model and what is left, **without writing a job, spending an allowance or
465
+ calling a model** — the numbers it shows are a reading at one instant, and the real upload checks them
466
+ again. The accept answers at once (`202`) with a job id; the extraction runs after it, so no command
467
+ waits for the model.
468
+
469
+ ### 3. Wait for the extraction
470
+
471
+ ```sh
472
+ kumion documents jobs get <jobId> --json
473
+ kumion documents get <S> --json
474
+ ```
475
+
476
+ Only `succeeded` gives you a document. `failed` and `timed_out` print `error.code` and exit non-zero,
477
+ so a script branches on the exit code rather than parsing the text. A `timed_out` job is **not retried
478
+ on its own**: the platform replays nothing after the 120-second deadline, and sending the same
479
+ `--idempotency-key` again answers the same job — a new attempt needs a new key. `documents get` then
480
+ answers the fields, their candidates, their review state and the `revision` the next step takes. It
481
+ does not return the text.
482
+
483
+ ### 4. Give the agent the uploaded 資料
484
+
485
+ ```sh
486
+ kumion documents replace <D> --source <S> --source-revision <S revision> \
487
+ --revision <D revision> --dry-run --json
488
+ kumion documents replace <D> --source <S> --source-revision <S revision> \
489
+ --revision <D revision> --json
490
+ ```
491
+
492
+ `D` keeps its id, so everything already pointing at it — the agent, its flow — keeps pointing at it.
493
+ No model is called: the source is already extracted, so this is a move, not an extraction. Every fact
494
+ comes back **pending**, and an item the new 資料 does not mention stays as an empty row. The dry run
495
+ lists what is added, kept empty and removed, and `resetConfirmedCount` says how many confirmations it
496
+ would cancel.
497
+
498
+ ### 5. Review and confirm the facts
499
+
500
+ ```sh
501
+ kumion facts list <A> --json
502
+ kumion facts edit <A> <factId> --revision <fact revision> --value "¥3,300(税込)"
503
+ kumion facts confirm <A> --fact <factId>
504
+ ```
505
+
506
+ An unconfirmed fact is not an answer the agent may read out. `facts confirm` without `--fact`
507
+ confirms every pending fact whose candidates agree and skips the ones that disagree — read those and
508
+ edit them. Reviewing is a step of this path, not a formality: a publish with facts nobody confirmed
509
+ still counts them as unconfirmed.
510
+
511
+ ### 6. Shop hours (営業時間)
512
+
513
+ ```sh
514
+ kumion hours get --json
515
+ kumion hours update --revision <calendar revision> --business-hours-file hours.json --json
516
+ kumion hours exception set <date> --revision <revision> --kind closed --json
517
+ ```
518
+
519
+ `hours.json` is the weekly table itself (`{ "mon": [{ "start": "09:00", "end": "18:00" }], … }`), not
520
+ an object wrapping it in `businessHours`. It replaces the whole week, so a file holding Mon–Fri makes
521
+ Sat and Sun closed. Regular closing days go in their own `--closed-rules-file`; an omitted file is
522
+ left alone. `--kind` is `closed` (臨時休業),
523
+ `open` (振替出勤, with `--hours-file` or the weekday's hours) or `inherit` (delete that day's row and
524
+ go back to the weekly rule). The revision is the one `hours get` printed: 営業時間, 例外日, 内容,
525
+ 担当 and the mount are one calendar with one counter.
526
+
527
+ ### 7. Booking (予約設定)
528
+
529
+ ```sh
530
+ kumion booking get <A> --json
531
+ kumion booking services create --revision <revision> --data-file service.json --json
532
+ kumion booking resources create --revision <revision> --data-file resource.json --json
533
+ kumion booking calendar update --revision <revision> --patch-file calendar.json --json
534
+ kumion booking mount <A> --mounted true --revision <revision> --json
535
+ kumion booking slots <A> --resource <resourceId> --service <serviceId> --date 2026-11-02 --json
536
+ ```
537
+
538
+ `service.json` is `{ "name": "初診", "durationMinutes": 30 }`; `resource.json` is
539
+ `{ "name": "山田", "weeklyHours": { "mon": [{ "start": "09:00", "end": "12:00" }] }, "serviceIds": [] }`
540
+ (`[]` takes every 内容); `calendar.json` holds `defaultSlotMinutes`, `minLeadMinutes` and/or
541
+ `maxAdvanceDays`. A 内容 with no duration uses the slot length.
542
+
543
+ A template's agent starts **not mounted** and with no 担当, so both are needed before it can book
544
+ anything. Mount only after a 担当 exists: read `booking get` back and expect `mounted: true` and
545
+ `bookableResourceCount` above zero. `booking slots` then answers the openings a call would offer —
546
+ computed from the same clock, 内容 lengths and existing bookings — and reserves nothing; an empty list
547
+ on an open day usually means no 担当 is enabled for that 内容.
548
+
549
+ ### 8. 記録項目 (what is recorded after a call)
550
+
551
+ ```sh
552
+ kumion capture-specs list --json
553
+ kumion agents capture get <A> --json
554
+ kumion agents capture set <A> --revision <revision> --spec <specId> --json
555
+ ```
556
+
557
+ A template ships with its 受付サマリー already mounted, so this step is often a read: `agents capture
558
+ get` answers the mounted specs, the agent's `revision` and `readiness`. Expect `readiness.ready: true`;
559
+ `false` means a call on this agent records nothing, whatever the shop's other agents do. To use your
560
+ own, `capture-specs create --data-file spec.json` (mounted on nothing yet, so no call changes) and
561
+ mount it with `agents capture set` — the whole set is replaced, `--spec` repeats, `--clear` records
562
+ nothing.
563
+
564
+ ### 9. Fix the flow (用件 and what each asks)
565
+
566
+ ```sh
567
+ kumion flow get <A> --json
568
+ kumion flow update <A> --revision <revision> --patch-file change.json --dry-run --json
569
+ kumion flow update <A> --revision <revision> --patch-file change.json --json
570
+ ```
571
+
572
+ A new 資料 does not recompile the flow: the 用件 and what each asks for stay as the template built
573
+ them, and a new call_intent the extraction found is not added by itself. `flow get`'s `editLayer` says
574
+ whether `flow update` or `flow edit-steps` is the write. Before publishing, `findings.canvas` must hold
575
+ no entry with `severity: "error"` and `findings.structural` must be empty.
576
+
577
+ ### 10. Publish
578
+
579
+ ```sh
580
+ kumion agents get <A> --json
581
+ kumion agents publish <A> --revision <revision> --json
582
+ kumion agents get <A> --json
583
+ ```
584
+
585
+ Publish runs the Portal's pre-publish check (a few minutes) and answers `publishRunId`,
586
+ `agent.publishedSnapshotId` and `unconfirmedFacts`; read the agent back for `publishState.live: true` and
587
+ `unpublishedChanges: false`. `unconfirmedFacts` counts the facts nobody confirmed — a clean publish
588
+ that still lists them is not a finished agent, so go back to step 5.
589
+
590
+ Two things are closed here on purpose:
591
+
592
+ - **External send settings.** A webhook's endpoint, a pre-call fetch, a notification, a transfer target,
593
+ the opening recording and an IVR menu's recording cannot be added or changed through `agents patch` (or
594
+ `flow`): the write is
595
+ refused with `422` and code `external_field_closed`, `paths` naming what it objected to, and nothing
596
+ is saved. Send them back unchanged and edit them in the Portal. The same list is under
597
+ [Editing a draft](#editing-a-draft).
598
+ - **Booking records** (making, moving or cancelling a customer's booking) and notifications are not
599
+ Partner API operations. `booking slots` reads openings; nothing here writes a booking.
600
+
319
601
  ## Use it from an AI coding assistant (MCP)
320
602
 
321
603
  `kumion mcp` serves the same operations as MCP tools over stdio, for Claude Code,
322
604
  Codex or any other MCP host, one tool per command above: `list_agents`, `get_agent`,
323
- `patch_agent`, `get_call_flow`, `update_call_flow`, `edit_call_flow_steps`,
324
- `set_agent_opening_name`, `set_agent_availability`, `list_facts`, `edit_fact`,
325
- `confirm_facts`, `list_agent_templates`, `create_agent_from_template`,
326
- `publish_agent`, `start_test_run`, `get_test_run`, `list_test_runs`, `create_call`,
327
- `list_calls`, `get_call`, `get_call_transcript`, `list_staff`, `create_staff`,
328
- `update_staff`. Each takes the same input as the API route and needs the same scope
329
- as its command.
605
+ `patch_agent`, `publish_agent`, `get_call_flow`, `update_call_flow`,
606
+ `edit_call_flow_steps`, `set_agent_opening_name`, `set_agent_availability`,
607
+ `create_agent_from_template`, `list_agent_templates`, `list_facts`, `edit_fact`,
608
+ `confirm_facts`, `list_staff`, `create_staff`, `update_staff`, `get_store_hours`,
609
+ `update_store_hours`, `set_store_hours_exception`, `get_booking_settings`,
610
+ `update_booking_calendar`, `create_booking_service`, `update_booking_service`,
611
+ `create_booking_resource`, `update_booking_resource`, `set_agent_booking`,
612
+ `list_booking_slots`, `get_agent_spec`, `list_capture_specs`, `create_capture_spec`,
613
+ `update_capture_spec`, `get_agent_capture`, `set_agent_capture`, `upload_document`,
614
+ `get_document_upload_job`, `get_document`, `replace_document`, `start_test_run`,
615
+ `get_test_run`, `list_test_runs`, `create_scheduled_call`, `list_scheduled_calls`, `cancel_scheduled_call`, `create_call`, `list_calls`, `get_call`,
616
+ `get_call_transcript`. Each takes the same input as the API route and needs the same
617
+ scope as its command.
330
618
 
331
619
  The server reads the key the same way every command does — the OS keychain profile,
332
620
  or `KUMION_API_KEY` / `KUMION_TENANT_ID` from its own environment — when it starts.
package/dist/client.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { FormData as UndiciFormData } from "undici";
1
2
  export class ApiError extends Error {
2
3
  status;
3
4
  body;
@@ -23,6 +24,30 @@ export class NetworkError extends Error {
23
24
  this.cause = cause;
24
25
  }
25
26
  }
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
+ }
26
51
  export class KumionClient {
27
52
  creds;
28
53
  fetchImpl;
@@ -45,7 +70,8 @@ export class KumionClient {
45
70
  Authorization: `Bearer ${this.creds.apiKey}`,
46
71
  Accept: "application/json",
47
72
  };
48
- if (options.body !== undefined)
73
+ const isForm = options.body instanceof UndiciFormData;
74
+ if (options.body !== undefined && !isForm)
49
75
  headers["Content-Type"] = "application/json";
50
76
  if (options.ifMatch)
51
77
  headers["If-Match"] = `"${options.ifMatch}"`;
@@ -54,7 +80,11 @@ export class KumionClient {
54
80
  res = await this.fetchImpl(url, {
55
81
  method,
56
82
  headers,
57
- body: options.body === undefined ? undefined : JSON.stringify(options.body),
83
+ body: options.body === undefined
84
+ ? undefined
85
+ : isForm
86
+ ? options.body
87
+ : JSON.stringify(options.body),
58
88
  });
59
89
  }
60
90
  catch (err) {
@@ -84,6 +114,48 @@ export class KumionClient {
84
114
  const { body } = await this.request("GET", this.agentPath(agentId), "agents:read");
85
115
  return body;
86
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
+ }
87
159
  async listAgentTemplates() {
88
160
  const { body } = await this.request("GET", this.tenantPath("/agent-templates"), "agents:read");
89
161
  return body.templates;
@@ -205,6 +277,28 @@ export class KumionClient {
205
277
  const { body } = await this.request("GET", this.tenantPath(`/calls${qs ? `?${qs}` : ""}`), "calls:read");
206
278
  return body;
207
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
+ }
208
302
  async getCall(callId) {
209
303
  const { body } = await this.request("GET", this.tenantPath(`/calls/${encodeURIComponent(callId)}`), "calls:read");
210
304
  return body.call;
@@ -213,4 +307,120 @@ export class KumionClient {
213
307
  const { body } = await this.request("GET", this.tenantPath(`/calls/${encodeURIComponent(callId)}/transcript`), "calls:read");
214
308
  return body.transcript;
215
309
  }
310
+ async getStoreHours(range = {}) {
311
+ const query = new URLSearchParams();
312
+ if (range.from)
313
+ query.set("from", range.from);
314
+ if (range.to)
315
+ query.set("to", range.to);
316
+ const qs = query.toString();
317
+ const { body } = await this.request("GET", this.tenantPath(`/store-hours${qs ? `?${qs}` : ""}`), "agents:read");
318
+ return body;
319
+ }
320
+ async updateStoreHours(patch, revision, options = {}) {
321
+ const { body } = await this.request("PATCH", this.tenantPath(`/store-hours${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", {
322
+ body: patch,
323
+ ifMatch: revision,
324
+ });
325
+ return body;
326
+ }
327
+ async setStoreHoursException(date, input, revision, options = {}) {
328
+ const { body } = await this.request("PATCH", this.tenantPath(`/store-hours/exceptions/${encodeURIComponent(date)}${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: input, ifMatch: revision });
329
+ return body;
330
+ }
331
+ async getBookingSettings(agentId) {
332
+ const { body } = await this.request("GET", this.agentPath(agentId, "/booking"), "agents:read");
333
+ return body;
334
+ }
335
+ async updateBookingCalendar(patch, revision, options = {}) {
336
+ const { body } = await this.request("PATCH", this.tenantPath(`/booking/calendar${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: patch, ifMatch: revision });
337
+ return body;
338
+ }
339
+ async createBookingService(input, revision, options = {}) {
340
+ const { body } = await this.request("POST", this.tenantPath(`/booking/services${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: input, ifMatch: revision });
341
+ return body;
342
+ }
343
+ async updateBookingService(serviceId, patch, revision, options = {}) {
344
+ const { body } = await this.request("PATCH", this.tenantPath(`/booking/services/${encodeURIComponent(serviceId)}${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: patch, ifMatch: revision });
345
+ return body;
346
+ }
347
+ async createBookingResource(input, revision, options = {}) {
348
+ const { body } = await this.request("POST", this.tenantPath(`/booking/resources${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: input, ifMatch: revision });
349
+ return body;
350
+ }
351
+ async updateBookingResource(resourceId, patch, revision, options = {}) {
352
+ const { body } = await this.request("PATCH", this.tenantPath(`/booking/resources/${encodeURIComponent(resourceId)}${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: patch, ifMatch: revision });
353
+ return body;
354
+ }
355
+ async setAgentBooking(agentId, mounted, revision, options = {}) {
356
+ const { body } = await this.request("PATCH", this.agentPath(agentId, `/booking${options.dryRun ? "?dryRun=1" : ""}`), "agents:live", { body: { mounted }, ifMatch: revision });
357
+ return body;
358
+ }
359
+ async listBookingSlots(agentId, query) {
360
+ const params = new URLSearchParams({ resourceId: query.resourceId, date: query.date });
361
+ if (query.serviceId !== undefined)
362
+ params.set("serviceId", query.serviceId);
363
+ if (query.limit !== undefined)
364
+ params.set("limit", String(query.limit));
365
+ const { body } = await this.request("GET", this.agentPath(agentId, `/booking/slots?${params.toString()}`), "agents:read");
366
+ return body;
367
+ }
368
+ async listCaptureSpecs() {
369
+ const { body } = await this.request("GET", this.tenantPath("/capture-specs"), "agents:read");
370
+ return body.captureSpecs;
371
+ }
372
+ async createCaptureSpec(input) {
373
+ const { body } = await this.request("POST", this.tenantPath("/capture-specs"), "agents:write", { body: input });
374
+ return body.captureSpec;
375
+ }
376
+ async updateCaptureSpec(specId, patch, revision) {
377
+ const { body } = await this.request("PATCH", this.tenantPath(`/capture-specs/${encodeURIComponent(specId)}`), "agents:live", { body: patch, ifMatch: revision });
378
+ return body.captureSpec;
379
+ }
380
+ async getAgentCapture(agentId) {
381
+ const { body } = await this.request("GET", this.agentPath(agentId, "/capture"), "agents:read");
382
+ return body;
383
+ }
384
+ async setAgentCapture(agentId, captureSpecIds, revision) {
385
+ const { body } = await this.request("PATCH", this.agentPath(agentId, "/capture"), "agents:live", {
386
+ body: { captureSpecIds },
387
+ ifMatch: revision,
388
+ });
389
+ return body;
390
+ }
391
+ async uploadDocument(input, options = {}) {
392
+ const query = options.dryRun ? "?dryRun=1" : "";
393
+ const metadata = {
394
+ title: input.title,
395
+ idempotencyKey: input.idempotencyKey,
396
+ ...(input.templateId === undefined ? {} : { templateId: input.templateId }),
397
+ };
398
+ let body;
399
+ if (input.files) {
400
+ const form = new UndiciFormData();
401
+ for (const [name, value] of Object.entries(metadata))
402
+ form.append(name, value);
403
+ for (const file of input.files)
404
+ form.append(DOCUMENT_UPLOAD_FILES_PART, new Blob([file.bytes]), file.filename);
405
+ body = form;
406
+ }
407
+ else {
408
+ body = { ...metadata, rawText: input.rawText };
409
+ }
410
+ const { body: answer } = await this.request("POST", this.tenantPath(`/documents${query}`), "agents:write", { body });
411
+ return ("job" in answer ? answer.job : answer);
412
+ }
413
+ async getDocumentUploadJob(jobId) {
414
+ const { body } = await this.request("GET", this.tenantPath(`/documents/jobs/${encodeURIComponent(jobId)}`), "agents:read");
415
+ return body.job;
416
+ }
417
+ async getDocument(documentId) {
418
+ const { body } = await this.request("GET", this.tenantPath(`/documents/${encodeURIComponent(documentId)}`), "agents:read");
419
+ return body;
420
+ }
421
+ async replaceDocument(documentId, input, revision, options = {}) {
422
+ const query = options.dryRun ? "?dryRun=1" : "";
423
+ const { body } = await this.request("POST", this.tenantPath(`/documents/${encodeURIComponent(documentId)}/replace${query}`), "agents:live", { body: input, ifMatch: revision });
424
+ return body;
425
+ }
216
426
  }