callkaro-cli-unofficial 0.2.0 → 0.2.1
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/dist/commands/agents.js +6 -1
- package/dist/index.js +1 -0
- package/dist/lib/agentUpdate.js +30 -0
- package/package.json +1 -1
package/dist/commands/agents.js
CHANGED
|
@@ -427,9 +427,14 @@ async function agentsUpdateCommand(agentId, opts) {
|
|
|
427
427
|
// *target* version: without one, getAgent returns the default version, and
|
|
428
428
|
// its siblings (provider, voice id, …) would be written onto a different
|
|
429
429
|
// version. Wholesale keys are version-level, so --versions is set here.
|
|
430
|
-
|
|
430
|
+
// `functions` is a whole array on the backend: merge by name unless the
|
|
431
|
+
// caller asked to replace the list.
|
|
432
|
+
const mergeFns = Array.isArray(patch.functions) && !opts.replaceFunctions;
|
|
433
|
+
if (wholesaleKeys.length || mergeFns) {
|
|
431
434
|
const { agent } = await api.getAgent(agentId, (0, versions_1.firstVersion)(opts.versions));
|
|
432
435
|
patch = (0, agentUpdate_1.mergeWholesaleKeys)(patch, agent);
|
|
436
|
+
if (mergeFns)
|
|
437
|
+
patch.functions = (0, agentUpdate_1.mergeFunctions)(patch.functions, agent.functions);
|
|
433
438
|
}
|
|
434
439
|
// A commit message is recorded against a version. Version-level updates
|
|
435
440
|
// already name one; for an agent-level-only update with --commit, attach it
|
package/dist/index.js
CHANGED
|
@@ -325,6 +325,7 @@ agents.command('update <agentId>').description('update fields via --set \'{json}
|
|
|
325
325
|
.option('--set <json>', "JSON object of fields (or @file.json), e.g. '{\"name\":\"x\",\"temperature\":5}'")
|
|
326
326
|
.option('--versions <id>', 'target a specific version (needed for version-level fields)')
|
|
327
327
|
.option('--commit <msg>', 'commit message for the version change')
|
|
328
|
+
.option('--replace-functions', 'replace the whole functions list instead of merging by name (default merges; omitted functions are kept)')
|
|
328
329
|
.option('--json', 'output the raw updated-agent response')
|
|
329
330
|
.action(agents_1.agentsUpdateCommand);
|
|
330
331
|
// Phone assignment (agent-centric). The one-inbound-agent rule is enforced server-side.
|
package/dist/lib/agentUpdate.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.preparePatch = preparePatch;
|
|
|
9
9
|
exports.coerce = coerce;
|
|
10
10
|
exports.deepMerge = deepMerge;
|
|
11
11
|
exports.mergeWholesaleKeys = mergeWholesaleKeys;
|
|
12
|
+
exports.mergeFunctions = mergeFunctions;
|
|
12
13
|
exports.isAgentLevelKey = isAgentLevelKey;
|
|
13
14
|
exports.normalizeStringArray = normalizeStringArray;
|
|
14
15
|
const agentImport_1 = require("./agentImport");
|
|
@@ -251,6 +252,35 @@ function mergeWholesaleKeys(patch, current) {
|
|
|
251
252
|
}
|
|
252
253
|
return out;
|
|
253
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Merge a partial `functions` array into the version's current one, by `name`:
|
|
257
|
+
* a matching name is replaced, a new name is appended, the rest are kept.
|
|
258
|
+
*
|
|
259
|
+
* The backend replaces the whole array, so sending one function would delete
|
|
260
|
+
* every other function on the version while reporting success.
|
|
261
|
+
*/
|
|
262
|
+
function mergeFunctions(incoming, current) {
|
|
263
|
+
if (!Array.isArray(incoming))
|
|
264
|
+
throw new Error('"functions" must be an array of function objects.');
|
|
265
|
+
const out = Array.isArray(current) ? [...current] : [];
|
|
266
|
+
const seen = new Set();
|
|
267
|
+
incoming.forEach((fn, i) => {
|
|
268
|
+
const name = fn && typeof fn === 'object' ? fn.name : undefined;
|
|
269
|
+
if (typeof name !== 'string' || !name.trim()) {
|
|
270
|
+
throw new Error(`functions[${i}] has no "name". Functions are merged by name, so each needs one.\n` +
|
|
271
|
+
' To replace the whole list on purpose, pass --replace-functions.');
|
|
272
|
+
}
|
|
273
|
+
if (seen.has(name))
|
|
274
|
+
throw new Error(`functions lists "${name}" twice.`);
|
|
275
|
+
seen.add(name);
|
|
276
|
+
const at = out.findIndex((c) => c && c.name === name);
|
|
277
|
+
if (at >= 0)
|
|
278
|
+
out[at] = fn;
|
|
279
|
+
else
|
|
280
|
+
out.push(fn);
|
|
281
|
+
});
|
|
282
|
+
return out;
|
|
283
|
+
}
|
|
254
284
|
function isAgentLevelKey(key) {
|
|
255
285
|
return agentImport_1.AGENT_LEVEL_KEYS.has(key);
|
|
256
286
|
}
|