@kumion/cli 0.2.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 +455 -18
- package/dist/client.js +205 -4
- package/dist/device-login.js +1 -0
- package/dist/errors.js +29 -1
- package/dist/main.js +1259 -10
- package/dist/mcp.js +778 -7
- package/package.json +6 -4
- package/skills/kumion/SKILL.md +245 -14
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
|
-
|
|
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
|
|
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) {
|
|
@@ -84,6 +91,51 @@ export class KumionClient {
|
|
|
84
91
|
const { body } = await this.request("GET", this.agentPath(agentId), "agents:read");
|
|
85
92
|
return body;
|
|
86
93
|
}
|
|
94
|
+
async listAgentTemplates() {
|
|
95
|
+
const { body } = await this.request("GET", this.tenantPath("/agent-templates"), "agents:read");
|
|
96
|
+
return body.templates;
|
|
97
|
+
}
|
|
98
|
+
async createAgentFromTemplate(input) {
|
|
99
|
+
const { body } = await this.request("POST", this.tenantPath("/agents/from-template"), "agents:write", {
|
|
100
|
+
body: input,
|
|
101
|
+
});
|
|
102
|
+
return body;
|
|
103
|
+
}
|
|
104
|
+
async getFlow(agentId) {
|
|
105
|
+
const { body } = await this.request("GET", this.agentPath(agentId, "/flow"), "agents:read");
|
|
106
|
+
return body;
|
|
107
|
+
}
|
|
108
|
+
async listStaff() {
|
|
109
|
+
const { body } = await this.request("GET", this.tenantPath("/staff"), "agents:read");
|
|
110
|
+
return body.staff;
|
|
111
|
+
}
|
|
112
|
+
async createStaff(input) {
|
|
113
|
+
const { body } = await this.request("POST", this.tenantPath("/staff"), "agents:write", { body: input });
|
|
114
|
+
return body.staff;
|
|
115
|
+
}
|
|
116
|
+
async updateStaff(staffId, patch, revision) {
|
|
117
|
+
const { body } = await this.request("PATCH", this.tenantPath(`/staff/${encodeURIComponent(staffId)}`), "agents:live", {
|
|
118
|
+
body: patch,
|
|
119
|
+
ifMatch: revision,
|
|
120
|
+
});
|
|
121
|
+
return body.staff;
|
|
122
|
+
}
|
|
123
|
+
async updateFlow(agentId, patch, revision, options = {}) {
|
|
124
|
+
const query = options.dryRun ? "?dryRun=1" : "";
|
|
125
|
+
const { body } = await this.request("PATCH", this.agentPath(agentId, `/flow${query}`), "agents:write", {
|
|
126
|
+
body: patch,
|
|
127
|
+
ifMatch: revision,
|
|
128
|
+
});
|
|
129
|
+
return body;
|
|
130
|
+
}
|
|
131
|
+
async editFlowSteps(agentId, ops, revision, options = {}) {
|
|
132
|
+
const query = options.dryRun ? "?dryRun=1" : "";
|
|
133
|
+
const { body } = await this.request("POST", this.agentPath(agentId, `/flow/steps${query}`), "agents:write", {
|
|
134
|
+
body: { ops },
|
|
135
|
+
ifMatch: revision,
|
|
136
|
+
});
|
|
137
|
+
return body;
|
|
138
|
+
}
|
|
87
139
|
async patchAgent(agentId, patch, revision) {
|
|
88
140
|
const { body } = await this.request("PATCH", this.agentPath(agentId), "agents:write", {
|
|
89
141
|
body: patch,
|
|
@@ -91,6 +143,34 @@ export class KumionClient {
|
|
|
91
143
|
});
|
|
92
144
|
return body;
|
|
93
145
|
}
|
|
146
|
+
async setOpeningName(agentId, enabled, revision) {
|
|
147
|
+
const { body } = await this.request("PATCH", this.agentPath(agentId, "/opening-name"), "agents:write", {
|
|
148
|
+
body: { enabled },
|
|
149
|
+
ifMatch: revision,
|
|
150
|
+
});
|
|
151
|
+
return body;
|
|
152
|
+
}
|
|
153
|
+
async setAvailability(agentId, patch, revision) {
|
|
154
|
+
const { body } = await this.request("PATCH", this.agentPath(agentId, "/availability"), "agents:live", {
|
|
155
|
+
body: patch,
|
|
156
|
+
ifMatch: revision,
|
|
157
|
+
});
|
|
158
|
+
return body;
|
|
159
|
+
}
|
|
160
|
+
async listFacts(agentId) {
|
|
161
|
+
const { body } = await this.request("GET", this.agentPath(agentId, "/facts"), "agents:read");
|
|
162
|
+
return body.facts;
|
|
163
|
+
}
|
|
164
|
+
async editFact(agentId, factId, value, revision) {
|
|
165
|
+
const { body } = await this.request("PATCH", this.agentPath(agentId, `/facts/${encodeURIComponent(factId)}`), "agents:live", { body: { value }, ifMatch: revision });
|
|
166
|
+
return body.fact;
|
|
167
|
+
}
|
|
168
|
+
async confirmFacts(agentId, factIds) {
|
|
169
|
+
const { body } = await this.request("POST", this.agentPath(agentId, "/facts/confirm"), "agents:live", {
|
|
170
|
+
body: factIds ? { factIds } : {},
|
|
171
|
+
});
|
|
172
|
+
return body;
|
|
173
|
+
}
|
|
94
174
|
async publishAgent(agentId, revision) {
|
|
95
175
|
const { body } = await this.request("POST", this.agentPath(agentId, "/publish"), "agents:publish", {
|
|
96
176
|
body: {},
|
|
@@ -111,9 +191,14 @@ export class KumionClient {
|
|
|
111
191
|
const { body } = await this.request("GET", this.agentPath(agentId, `/test-runs${query}`), "tests:run");
|
|
112
192
|
return body.testRuns;
|
|
113
193
|
}
|
|
114
|
-
async createCall(agentId, campaignContactId) {
|
|
194
|
+
async createCall(agentId, campaignContactId, variables, phoneNumber) {
|
|
115
195
|
const { body } = await this.request("POST", this.tenantPath("/calls"), "calls:create", {
|
|
116
|
-
body:
|
|
196
|
+
body: {
|
|
197
|
+
agentId,
|
|
198
|
+
...(campaignContactId ? { campaignContactId } : {}),
|
|
199
|
+
...(phoneNumber ? { phoneNumber } : {}),
|
|
200
|
+
...(variables && Object.keys(variables).length > 0 ? { variables } : {}),
|
|
201
|
+
},
|
|
117
202
|
});
|
|
118
203
|
return body;
|
|
119
204
|
}
|
|
@@ -135,4 +220,120 @@ export class KumionClient {
|
|
|
135
220
|
const { body } = await this.request("GET", this.tenantPath(`/calls/${encodeURIComponent(callId)}/transcript`), "calls:read");
|
|
136
221
|
return body.transcript;
|
|
137
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
|
+
}
|
|
138
339
|
}
|
package/dist/device-login.js
CHANGED
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
|
|
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,29 @@ 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 === "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
|
+
}
|
|
77
|
+
if (err.code === "flow_edit_refused" && reason) {
|
|
78
|
+
const which = typeof err.body.opIndex === "number" ? `Operation ${err.body.opIndex + 1} was refused` : "The change was refused";
|
|
79
|
+
return `${which} (422). Nothing was written.\nServer said: ${reason}`;
|
|
80
|
+
}
|
|
81
|
+
return `Request failed (422).${serverSaid(err)}`;
|
|
82
|
+
}
|
|
55
83
|
case 429:
|
|
56
84
|
return `Rate limited (429).${err.retryAfter ? ` Retry in ${err.retryAfter}s.` : ""}${serverSaid(err)}`;
|
|
57
85
|
default:
|