@kumion/cli 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -106,22 +106,87 @@ would use.
106
106
  | `kumion agents get <agentId> [--json]` | `agents:read` |
107
107
  | `kumion agents patch <agentId> --revision <rev> [--prompt <text> \| --prompt-file <path>] [--graph-file <path>]` | `agents:write` |
108
108
  | `kumion agents publish <agentId> [--revision <rev>]` | `agents:publish` |
109
+ | `kumion agents opening-name <agentId> --revision <rev> (--on \| --off)` | `agents:write` (a draft write: live after the next publish) |
110
+ | `kumion agents availability <agentId> --revision <rev> [--operating-hours-file <path>] [--off-hours-file <path>]` | `agents:live` (live: no publish) |
111
+ | `kumion flow get <agentId>` | `agents:read` |
112
+ | `kumion flow update <agentId> --revision <rev> --patch-file <path> [--dry-run]` | `agents:write` |
113
+ | `kumion flow edit-steps <agentId> --revision <rev> --ops-file <path> [--dry-run]` | `agents:write` |
114
+ | `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
+ | `kumion staff list` | `agents:read` |
117
+ | `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
+ | `kumion staff update <staffId> --revision <rev> [--name ...] [--transfer-target ...] [--enabled true\|false]` | `agents:live` (live: no publish) |
119
+ | `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) |
109
121
  | `kumion test-runs start <agentId> [--no-wait] [--interval <sec>] [--timeout <sec>]` | `tests:run` |
110
122
  | `kumion test-runs get <agentId> <runId>` / `test-runs list <agentId>` | `tests:run` |
111
- | `kumion calls create <agentId> [--campaign-contact <id>]` | `calls:create` |
123
+ | `kumion calls create <agentId> [--to <phone>] [--campaign-contact <id>] [--var <name>=<value> ...]` | `calls:create` |
112
124
  | `kumion calls list [--agent <id>] [--channel webcall\|sip_did\|trigger] [--from <iso>] [--to <iso>] [--search <text>] [--limit <n>] [--offset <n>]` | `calls:read` |
113
125
  | `kumion calls get <callId>` / `calls transcript <callId>` | `calls:read` |
114
126
 
115
127
  A command whose key lacks the scope fails with a message naming the scope it needs.
116
128
  `calls:read` is its own scope: a key that can start calls (`calls:create`) cannot read
117
129
  them. `calls list` returns one page (20 by default, at most 100) and prints the
118
- `--offset` of the next one. A transcript holds only what the caller and the agent said.
130
+ `--offset` of the next one. Every call in `calls list` and `calls get` carries what it came to: `outcome`
131
+ (`ai_resolved`, `ai_unresolved_hangup`, `invalid_call`, `handoff`, `system_ended`, or `na` when not judged),
132
+ `endedAtNode` (the node it ended on), `durationSec`, `transferred`, and `capturedItems` (the names of the
133
+ items it recorded, never their values). A transcript holds only what the caller and the agent said.
119
134
  Add `--json` to any command for the API's JSON instead of a summary.
120
135
 
136
+ ### Per-call variables
137
+
138
+ `calls create --var 氏名=山田 --var route=B` starts the call with those values; the agent reads
139
+ them as `{{vars.氏名}}` in a prompt or opening line, and as `vars.route == "B"` in an edge
140
+ condition. The API takes the same values as `variables` in the `POST /api/v1/{tenant}/calls`
141
+ body: an object of strings, at most 50 names, 1000 characters per value, 10000 in total (a
142
+ larger or non-string value is a 400 naming the item). With `--campaign-contact`, the list row's
143
+ columns are the base and `--var` wins. A name that is not passed reads as an empty string.
144
+
145
+ ### Dialing a phone
146
+
147
+ `calls create <agentId> --to 08012345678` places a real call from the phone number assigned to
148
+ the agent instead of opening a web call. The number must be a domestic Japanese landline, 050,
149
+ or 070/080/090 number; international, toll-free (0120/0800), 0570 and short numbers are
150
+ refused. The agent has to be published and have a phone number assigned, otherwise the command
151
+ fails with the reason. It returns at once with the call id; whether the callee answered, was
152
+ busy, did not answer, or the call failed is on `calls get <callLogId>` (`disposition`).
153
+ `--var` and `--campaign-contact` work the same as for a web call. Outbound minutes are metered
154
+ separately from inbound ones. The API takes the same number as `phoneNumber` in the
155
+ `POST /api/v1/{tenant}/calls` body (HTTP 202); without it the call is a web call as before.
156
+
121
157
  ### Editing a draft
122
158
 
123
159
  Edits go to the agent's **draft**. Callers hear nothing new until you publish.
124
160
 
161
+ Start with `flow get`. It shows the flow the way the Portal's canvas assistant sees it,
162
+ and its `editLayer` says which command edits it:
163
+
164
+ - **`flow`** — the flow is in the 用件 form (an agent made from a template is). Change it
165
+ with `flow update`: a JSON object holding only what changes — `personaPrompt`,
166
+ `openingSpeech`, `noRouteSpeech`, `examples`, and `leaves[]`, one entry per 用件 by
167
+ `key` with an `action` (`keep`, `add`, `remove`, `merge_into`). A 用件 hands the caller
168
+ to a staff member with `transferContactKey` (a key from `staff list` / `flow get`'s
169
+ `staffChoices`) and stops with `removeTransfer`.
170
+ - **`steps`** — a step-by-step graph (`flow` is `null`). Change it with `flow edit-steps`:
171
+ a batch of operations, each `{ "op": "<name>", …its arguments }`, from
172
+ `set_node_field`, `set_edge_words`, `add_step`, `remove_step`, `connect_steps`,
173
+ `reconnect`, `disconnect`. They run in order; one refused operation refuses the whole
174
+ batch and nothing is saved. `add_step` may take a `key` so later operations in the
175
+ same batch can name the new step.
176
+
177
+ Both take the same arguments, and are checked by the same rules, as the canvas
178
+ assistant's tools. `--dry-run` prints the change and saves nothing.
179
+
180
+ ```sh
181
+ kumion flow get <agentId> --json > flow.json # note "revision" and "editLayer"
182
+ kumion flow update <agentId> --revision <rev> --patch-file change.json --dry-run
183
+ kumion flow update <agentId> --revision <rev> --patch-file change.json
184
+ kumion flow edit-steps <agentId> --revision <rev> --ops-file ops.json
185
+ ```
186
+
187
+ `agents patch` replaces the prompt or the whole graph. Use it for a prompt-only agent,
188
+ or for a graph change the two commands above do not cover:
189
+
125
190
  ```sh
126
191
  kumion agents get <agentId> --json > agent.json # note "revision"
127
192
  # edit agent.json's draft.graph, or write a new prompt to prompt.txt
@@ -129,22 +194,112 @@ kumion agents patch <agentId> --graph-file agent.json
129
194
  kumion agents patch <agentId> --revision <rev> --prompt-file prompt.txt
130
195
  ```
131
196
 
132
- `--revision` says which version of the draft your change is based on. If someone saved
133
- the agent in the Portal (or from another client) since you read it, the patch is
134
- refused with a conflict and nothing is written: read it again and re-apply your change.
197
+ `--revision` says which version of the draft your change is based on; `flow get` and
198
+ `agents get` show the same one. If someone saved the agent in the Portal (or from
199
+ another client) since you read it, the write is refused with a conflict and nothing
200
+ is written: read it again and re-apply your change.
135
201
  `--graph-file` accepts either a bare flow graph or the whole `agents get --json`
136
202
  output, in which case the revision inside the file is used.
137
203
 
204
+ ### Settings that reach callers at once
205
+
206
+ Three settings are not part of the draft, so a write to them needs no publish:
207
+
208
+ - `agents availability`: 受付時間 (`--operating-hours-file`, JSON `{ "mode": "always" | "staffed" | "custom", "hours": { "mon": [{ "start": "09:00", "end": "18:00" }] } }`) and 時間外の対応 (`--off-hours-file`, JSON `{ "kind": "answer" | "announce_end" | "route_to", ... }`). A file holding `null` clears the setting. `agents get --json` shows both under `live`.
209
+ - `facts edit` and `facts confirm`: the facts taken from the agent's 資料 (prices, menu). `facts list` shows each fact's `revision`; `facts edit` is refused when that fact changed since.
210
+
211
+ They need the scope **`agents:live`**, which is not part of `agents:write` (that scope only writes the draft and never publishes) and is not added to keys issued before it existed: issue a new key with it on 設定 → 開発者. `agents opening-name` is an ordinary draft write (`agents:write`): it reaches callers with the next publish.
212
+
213
+ `staff update` is the third: a 用件's 転送 looks its スタッフ up by key when the transfer happens and reads 転送先 and whether the row is enabled then, so `staff update --enabled false` takes someone off the 転送 candidates from the next call on, with no publish. `--revision` is the row's own, from `staff list`; a write based on a stale one is refused with a conflict and nothing is written. The transfer key is generated when the row is created and cannot be changed — a published flow stores it.
214
+
138
215
  ### What the CLI does not cover
139
216
 
140
217
  The CLI is a client of the Partner API (the commands above), so it can only do what
141
218
  that API exposes. These Portal features have no Partner API route yet and are not in
142
- the CLI: conversation-edit mode and its monthly count, per-agent operating hours and the
143
- hand-off to another agent outside them, knowledge-base confirm / bulk delete, filtering
144
- bookings by agent, applying 解決策 to pre-publish findings, the opening-line name toggle,
145
- external-tool rate-limit / circuit-breaker status, and the agent language / English
146
- locale. Flow-level settings that live inside the graph (IVR recording, slot sources,
147
- transfer nodes) travel with `agents get --json` / `agents patch --graph-file` unchanged.
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 /
221
+ circuit-breaker status, the agent language / English locale, a tool's display name (表示名),
222
+ the agent's call-outcome categories (通話の結果), and the call model with its TTS voice (`agents get` shows them, `agents patch` cannot
223
+ 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.
226
+
227
+ ### Node configuration reference
228
+
229
+ Each node in `draft.graph.nodes[]` keeps its settings in `config`. This table is
230
+ generated from the Portal's field list by `scripts/node-config-reference.ts`; a test
231
+ fails when the two disagree.
232
+
233
+ <!-- BEGIN node-config-reference: generated by scripts/node-config-reference.ts (npm run docs:node-config); do not edit -->
234
+ `layer` says where the Portal's node inspector shows the key:
235
+
236
+ - `required` — always shown
237
+ - `tune` — 「動きの調整」 card: a one-line summary that opens to edit
238
+ - `advanced` — folded under 「詳細」, or a required item's 「細かい設定」
239
+ - `internal` — no editor in the Portal: set by another surface, or API only
240
+
241
+ A key a node does not store follows the agent's setting (会話の運用) or the tenant's
242
+ (運用設定); the inspector shows it as 「既定」 and a stored one as 「変更あり」.
243
+
244
+ | Key | Node types | Layer | Type | Note |
245
+ | --- | --- | --- | --- | --- |
246
+ | `display_name` | start, agent, end, global, trigger, webhook, qa, ivr, transfer, notify | `internal` | `string` | The name shown on the canvas. Edited by renaming the node. |
247
+ | `leaf_label` | start, agent | `internal` | `string` | Set by the manual compiler. The purpose name the diagnostics quote. |
248
+ | `canvas_flow` | start, agent, end, global, trigger, webhook, qa, ivr, transfer, notify | `internal` | `object` | Canvas layout state. Not a setting. |
249
+ | `flow_expectations` | global | `internal` | `object` | Written by the scenario interview. Not a setting. |
250
+ | `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
+ | `trigger_path` | trigger | `internal` | `string` | Generated. Shown read-only as the trigger URL. |
252
+ | `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). |
254
+ | `allow_interruptions` | start, agent | `tune` | `boolean` | Absent means the caller may interrupt. Only an explicit false is stored. |
255
+ | `respond_on_enter` | agent | `tune` | `boolean` | Absent means the node answers on arrival. Only an explicit false (wait for the caller) is stored. |
256
+ | `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. |
257
+ | `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
+ | `quiet_wait` | start, agent | `tune` | `{ seconds, listen?, resume_speech? }` | Node-level wait. { seconds: 0 } turns the agent default off here. |
259
+ | `optional_slots` | start, agent | `tune` | `string[]` | Slots declared elsewhere that this step may record when the caller volunteers them. |
260
+ | `switch_agent_id` | agent | `tune` | `uuid` | A published agent this step hands the call to. |
261
+ | `opening_audio_url` | start | `tune` | `string` | kumion-asset:// upload (or a legacy allow-listed URL) played instead of TTS for the opening line. |
262
+ | `opening_audio_filename` | start | `internal` | `string` | Display name of the uploaded opening audio. |
263
+ | `precall_fetch_url` | start | `advanced` | `string` | URL fetched before the call starts; the response becomes call variables. |
264
+ | `precall_fetch_method` | start | `advanced` | `string` | HTTP method of the pre-call fetch. |
265
+ | `precall_fetch_headers` | start | `advanced` | `{ key, value }[]` | Headers of the pre-call fetch. |
266
+ | `no_response` | start, agent | `advanced` | `{ timeout_s, reprompt_speech?, max_reprompts, then }` | Node-level no-response timer. { timeout_s: 0 } turns the agent default off here. |
267
+ | `kb_fallback` | start, agent | `advanced` | `{ noResult?, unavailable? }` | Wording when a knowledge search finds nothing or is unavailable. Overrides the tenant operations setting. |
268
+ | `end_speech` | end | `required` | `string` | Default goodbye line. A connection into this node can override it. |
269
+ | `caller_leaves` | end | `required` | `boolean` | Marks the end a caller who walks away is sent to from every agent step, connected or not. Required on exactly one end when the flow has two or more end nodes. |
270
+ | `ivr` | ivr | `required` | `object` | Announcement, digit table and wait time. input and max_retries are fixed; other values are rejected. |
271
+ | `transfer` | transfer | `required` | `object` | Transfer target and the line spoken before transferring. |
272
+ | `notify` | notify | `required` | `object` | Recipients, subject and body templates. |
273
+ | `http_method` | webhook | `required` | `string` | GET, POST, PUT, PATCH or DELETE. |
274
+ | `endpoint_url` | webhook | `required` | `string` | Destination URL. |
275
+ | `payload_template` | webhook | `required` | `string` | Request body template with {{variables}}. |
276
+ | `custom_headers` | webhook | `advanced` | `{ key, value }[]` | Extra request headers. |
277
+ | `qa_system_prompt` | qa | `required` | `string` | Evaluation prompt. |
278
+ | `qa_sample_rate` | qa | `required` | `number` | Percentage of calls analysed, 1 to 100. |
279
+ | `qa_min_call_duration` | qa | `required` | `number` | Shortest call (seconds) that is analysed. |
280
+ | `qa_model` | qa | `advanced` | `string` | Model override for this analysis. |
281
+ | `qa_voicemail_calls` | qa | `advanced` | `boolean` | Whether voicemail calls are analysed (default true). |
282
+
283
+ A required item's 種類 is stored as a pair on the item: `source` and `value_type`.
284
+ These are the pairs the Portal offers:
285
+
286
+ | 種類 | `source` | `value_type` |
287
+ | --- | --- | --- |
288
+ | お客様の言葉のまま (`verbatim`) | `caller` | `text` |
289
+ | AIがまとめた内容 (`summary`) | `derived` | `text` |
290
+ | 番号 (`code`) | `caller` | `code` |
291
+ | 電話番号 (`phone`) | `caller` | `phone` |
292
+ | 生年月日 (`birthdate`) | `caller` | `birthdate` |
293
+ | 日時 (`datetime`) | `caller` | `datetime` |
294
+ | 選択肢 (`select`) | `derived` | `select` |
295
+ | ツールの結果 (`tool`) | `tool` | `text` |
296
+ <!-- END node-config-reference -->
297
+
298
+ Two settings have no (or only partial) Portal screen: the agent-level `model_config.wait_cover`
299
+ (hold phrase text and repeats are API only; the delay, `on_threshold`, `on_query_start` and `query_grace_ms` have an agent card
300
+ and a row in a node's 「動きの調整」), and an IVR node's `ivr.input` and `ivr.max_retries` are fixed
301
+ (`{ "mode": "single", "max_digits": 1, "finish_key": null }` and `0`): any other value
302
+ makes the patch fail.
148
303
 
149
304
  ### Testing and publishing
150
305
 
@@ -156,15 +311,22 @@ kumion agents publish <agentId> # runs the pre-publish check, then publishe
156
311
  `test-runs start` checks the draft without publishing anything. `agents publish` runs
157
312
  the Portal's pre-publish check and publishes only when it passes; when it does not, the
158
313
  failing cases are printed and nothing goes live. The CLI has no way to skip or override
159
- the check.
314
+ the check. When a check before the test calls refuses (most often the dependency check:
315
+ コンタクト or the booking calendar not connected, a tool not enabled), there are no
316
+ cases to print: the server's message after `Server said:` is the whole reason, one
317
+ problem per line.
160
318
 
161
319
  ## Use it from an AI coding assistant (MCP)
162
320
 
163
321
  `kumion mcp` serves the same operations as MCP tools over stdio, for Claude Code,
164
- Codex or any other MCP host: `list_agents`, `get_agent`, `patch_agent`,
322
+ 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`,
165
326
  `publish_agent`, `start_test_run`, `get_test_run`, `list_test_runs`, `create_call`,
166
- `list_calls`, `get_call`, `get_call_transcript`.
167
- Each needs the same scope as its command above.
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.
168
330
 
169
331
  The server reads the key the same way every command does — the OS keychain profile,
170
332
  or `KUMION_API_KEY` / `KUMION_TENANT_ID` from its own environment — when it starts.
package/dist/client.js CHANGED
@@ -84,6 +84,51 @@ export class KumionClient {
84
84
  const { body } = await this.request("GET", this.agentPath(agentId), "agents:read");
85
85
  return body;
86
86
  }
87
+ async listAgentTemplates() {
88
+ const { body } = await this.request("GET", this.tenantPath("/agent-templates"), "agents:read");
89
+ return body.templates;
90
+ }
91
+ async createAgentFromTemplate(input) {
92
+ const { body } = await this.request("POST", this.tenantPath("/agents/from-template"), "agents:write", {
93
+ body: input,
94
+ });
95
+ return body;
96
+ }
97
+ async getFlow(agentId) {
98
+ const { body } = await this.request("GET", this.agentPath(agentId, "/flow"), "agents:read");
99
+ return body;
100
+ }
101
+ async listStaff() {
102
+ const { body } = await this.request("GET", this.tenantPath("/staff"), "agents:read");
103
+ return body.staff;
104
+ }
105
+ async createStaff(input) {
106
+ const { body } = await this.request("POST", this.tenantPath("/staff"), "agents:write", { body: input });
107
+ return body.staff;
108
+ }
109
+ async updateStaff(staffId, patch, revision) {
110
+ const { body } = await this.request("PATCH", this.tenantPath(`/staff/${encodeURIComponent(staffId)}`), "agents:live", {
111
+ body: patch,
112
+ ifMatch: revision,
113
+ });
114
+ return body.staff;
115
+ }
116
+ async updateFlow(agentId, patch, revision, options = {}) {
117
+ const query = options.dryRun ? "?dryRun=1" : "";
118
+ const { body } = await this.request("PATCH", this.agentPath(agentId, `/flow${query}`), "agents:write", {
119
+ body: patch,
120
+ ifMatch: revision,
121
+ });
122
+ return body;
123
+ }
124
+ async editFlowSteps(agentId, ops, revision, options = {}) {
125
+ const query = options.dryRun ? "?dryRun=1" : "";
126
+ const { body } = await this.request("POST", this.agentPath(agentId, `/flow/steps${query}`), "agents:write", {
127
+ body: { ops },
128
+ ifMatch: revision,
129
+ });
130
+ return body;
131
+ }
87
132
  async patchAgent(agentId, patch, revision) {
88
133
  const { body } = await this.request("PATCH", this.agentPath(agentId), "agents:write", {
89
134
  body: patch,
@@ -91,6 +136,34 @@ export class KumionClient {
91
136
  });
92
137
  return body;
93
138
  }
139
+ async setOpeningName(agentId, enabled, revision) {
140
+ const { body } = await this.request("PATCH", this.agentPath(agentId, "/opening-name"), "agents:write", {
141
+ body: { enabled },
142
+ ifMatch: revision,
143
+ });
144
+ return body;
145
+ }
146
+ async setAvailability(agentId, patch, revision) {
147
+ const { body } = await this.request("PATCH", this.agentPath(agentId, "/availability"), "agents:live", {
148
+ body: patch,
149
+ ifMatch: revision,
150
+ });
151
+ return body;
152
+ }
153
+ async listFacts(agentId) {
154
+ const { body } = await this.request("GET", this.agentPath(agentId, "/facts"), "agents:read");
155
+ return body.facts;
156
+ }
157
+ async editFact(agentId, factId, value, revision) {
158
+ const { body } = await this.request("PATCH", this.agentPath(agentId, `/facts/${encodeURIComponent(factId)}`), "agents:live", { body: { value }, ifMatch: revision });
159
+ return body.fact;
160
+ }
161
+ async confirmFacts(agentId, factIds) {
162
+ const { body } = await this.request("POST", this.agentPath(agentId, "/facts/confirm"), "agents:live", {
163
+ body: factIds ? { factIds } : {},
164
+ });
165
+ return body;
166
+ }
94
167
  async publishAgent(agentId, revision) {
95
168
  const { body } = await this.request("POST", this.agentPath(agentId, "/publish"), "agents:publish", {
96
169
  body: {},
@@ -111,9 +184,14 @@ export class KumionClient {
111
184
  const { body } = await this.request("GET", this.agentPath(agentId, `/test-runs${query}`), "tests:run");
112
185
  return body.testRuns;
113
186
  }
114
- async createCall(agentId, campaignContactId) {
187
+ async createCall(agentId, campaignContactId, variables, phoneNumber) {
115
188
  const { body } = await this.request("POST", this.tenantPath("/calls"), "calls:create", {
116
- body: campaignContactId ? { agentId, campaignContactId } : { agentId },
189
+ body: {
190
+ agentId,
191
+ ...(campaignContactId ? { campaignContactId } : {}),
192
+ ...(phoneNumber ? { phoneNumber } : {}),
193
+ ...(variables && Object.keys(variables).length > 0 ? { variables } : {}),
194
+ },
117
195
  });
118
196
  return body;
119
197
  }
@@ -5,6 +5,7 @@ export const DEFAULT_DEVICE_SCOPES = [
5
5
  "agents:read",
6
6
  "agents:write",
7
7
  "agents:publish",
8
+ "agents:live",
8
9
  "tests:run",
9
10
  "calls:create",
10
11
  "calls:read",
package/dist/errors.js CHANGED
@@ -24,7 +24,7 @@ export function describeApiError(err) {
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
26
  if (err.scope === "calls:create") {
27
- return ("The call was refused (403): the tenant has reached its call-minute limit (the 30-minute cap for an " +
27
+ return ("The call was refused (403): the tenant has reached its call-minute limit (the trial minutes cap for an " +
28
28
  "unsigned tenant, or the monthly cap), or its plan cannot start calls. Check 設定 in the Kumion Portal." +
29
29
  serverSaid(err));
30
30
  }
@@ -39,6 +39,11 @@ export function describeApiError(err) {
39
39
  "change on top of it, and try again." +
40
40
  serverSaid(err));
41
41
  }
42
+ if (err.code === "fact_revision_conflict") {
43
+ return ("That fact changed since you read it (409): someone confirmed or edited it in the Portal or from another " +
44
+ "client. Nothing was written. Run `kumion facts list <agentId>` for its new revision and try again." +
45
+ serverSaid(err));
46
+ }
42
47
  if (err.code === "test_run_in_progress") {
43
48
  return ("This agent already has a test run in progress (409). Wait for it with " +
44
49
  "`kumion test-runs list <agentId>` / `kumion test-runs get <agentId> <runId>`, then start another." +
@@ -52,6 +57,20 @@ export function describeApiError(err) {
52
57
  return `Conflict (409).${serverSaid(err)}`;
53
58
  case 428:
54
59
  return `The API asked for an If-Match revision the CLI did not send (428). This is a CLI bug.${serverSaid(err)}`;
60
+ case 422: {
61
+ const reasons = Array.isArray(err.body.reasons) ? err.body.reasons.filter((reason) => typeof reason === "string") : [];
62
+ const reason = typeof err.body.reason === "string" ? err.body.reason : null;
63
+ if (err.code === "flow_edit_blocked" && reasons.length > 0) {
64
+ return `The change was not stored (422). Nothing was written — the draft would be left with these problems:\n${reasons
65
+ .map((line) => ` - ${line}`)
66
+ .join("\n")}`;
67
+ }
68
+ if (err.code === "flow_edit_refused" && reason) {
69
+ const which = typeof err.body.opIndex === "number" ? `Operation ${err.body.opIndex + 1} was refused` : "The change was refused";
70
+ return `${which} (422). Nothing was written.\nServer said: ${reason}`;
71
+ }
72
+ return `Request failed (422).${serverSaid(err)}`;
73
+ }
55
74
  case 429:
56
75
  return `Rate limited (429).${err.retryAfter ? ` Retry in ${err.retryAfter}s.` : ""}${serverSaid(err)}`;
57
76
  default: