@kumion/cli 0.3.0 → 0.4.0

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