@velaro/cli 1.4.118 → 1.4.120

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/bin/velaro.js CHANGED
@@ -12,6 +12,7 @@ import { ingestCommand } from '../lib/commands/ingest.js';
12
12
  import { indexMoveCommand } from '../lib/commands/index-move.js';
13
13
  import { safetyCommand } from '../lib/commands/safety.js';
14
14
  import { knowledgeAdvisorCommand } from '../lib/commands/knowledge-advisor.js';
15
+ import { productMatchCommand } from '../lib/commands/product-match.js';
15
16
  import { knowledgeCommand } from '../lib/commands/knowledge.js';
16
17
  import { productCommand } from '../lib/commands/product.js';
17
18
  import { mcpKeyCommand } from '../lib/commands/mcp-key.js';
@@ -124,6 +125,7 @@ import { statusNotifyCommand } from '../lib/commands/status-notify.js';
124
125
  import { statusSlaCommand } from '../lib/commands/status-sla.js';
125
126
  import { emailInboxCommand } from '../lib/commands/email-inbox.js';
126
127
  import { callbackCommand } from '../lib/commands/callback.js';
128
+ import { callpresenceCommand } from '../lib/commands/callpresence.js';
127
129
  import { authorityCommand } from '../lib/commands/authority.js';
128
130
  import { caseCommand } from '../lib/commands/case.js';
129
131
  import { ticketCommand } from '../lib/commands/ticket.js';
@@ -180,6 +182,7 @@ await yargs(hideBin(process.argv))
180
182
  .command(indexMoveCommand)
181
183
  .command(safetyCommand)
182
184
  .command(knowledgeAdvisorCommand)
185
+ .command(productMatchCommand)
183
186
  .command(knowledgeCommand)
184
187
  .command(productCommand)
185
188
  .command(mcpKeyCommand)
@@ -294,6 +297,7 @@ await yargs(hideBin(process.argv))
294
297
  .command(statusSlaCommand)
295
298
  .command(emailInboxCommand)
296
299
  .command(callbackCommand)
300
+ .command(callpresenceCommand)
297
301
  .command(authorityCommand)
298
302
  .command(caseCommand)
299
303
  .command(ticketCommand)
@@ -0,0 +1,143 @@
1
+ import { messagingGet, messagingPut, messagingDel } from '../api.js';
2
+ import { runCommand } from '../run.js';
3
+
4
+ // -- velaro callpresence ---------------------------------------------------------
5
+ // Call-presence policy: what chat and call routing do while an agent is on a phone call, and what happens
6
+ // when the call ends. Site default -> routing group override -> agent override (only when the site permits
7
+ // agent overrides). Backend: velaro-messaging CallPresencePolicyController (route CallPresencePolicy).
8
+ // The site always comes from the credential (vmsg-siteId header), never from CLI args.
9
+
10
+ const WHILE_ON_CALL = ['NoChats', 'TakeChats', 'FinishThenOffline'];
11
+ const AFTER_CALL = ['ReturnAutomatically', 'AskAgent', 'StayOffline'];
12
+ const CALLS_WHILE_BUSY = ['NoCallsWhileBusy', 'RingEvenWhenBusy'];
13
+ const SCOPES = ['site', 'group', 'agent'];
14
+
15
+ const BOLD = '\x1b[1m';
16
+ const DIM = '\x1b[2m';
17
+ const RST = '\x1b[0m';
18
+
19
+ function printEffective(eff) {
20
+ for (const [key, label] of [['whileOnCall', 'While on a call'], ['afterCall', 'After the call'], ['callsWhileBusy', 'Calls while busy on chats']]) {
21
+ const f = eff?.[key];
22
+ if (f) console.log(` ${label.padEnd(26)} ${f.value} ${DIM}(${f.source})${RST}`);
23
+ }
24
+ }
25
+
26
+ async function getHandler(argv) {
27
+ const data = await messagingGet('/CallPresencePolicy');
28
+ if (argv.json) { console.log(JSON.stringify(data, null, 2)); return; }
29
+ console.log(`\n${BOLD}Call presence policy${RST}`);
30
+ console.log(' Site default:');
31
+ printEffective(data.effectiveSite);
32
+ console.log(` Agents may set their own override: ${data.allowAgentOverrides ? 'yes' : 'no'}`);
33
+ const groups = (data.groups ?? []).filter((g) => g.policy && (g.policy.whileOnCall || g.policy.afterCall || g.policy.callsWhileBusy));
34
+ if (groups.length) {
35
+ console.log(' Group overrides:');
36
+ for (const g of groups) console.log(` ${g.teamName} (#${g.teamId}): ${g.policy.whileOnCall ?? '-'} / ${g.policy.afterCall ?? '-'} / ${g.policy.callsWhileBusy ?? '-'} ring: ${g.ringStrategy}`);
37
+ }
38
+ if ((data.agents ?? []).length) {
39
+ console.log(' Agent overrides:');
40
+ for (const a of data.agents) console.log(` ${a.agentName} (#${a.agentId}): ${a.policy.whileOnCall ?? '-'} / ${a.policy.afterCall ?? '-'} / ${a.policy.callsWhileBusy ?? '-'}`);
41
+ }
42
+ console.log('');
43
+ }
44
+
45
+ async function setHandler(argv) {
46
+ const scope = argv.scope;
47
+ const id = scope === 'site' ? 0 : argv.id;
48
+ if (scope !== 'site' && !id) throw new Error('--id is required for group (team id) and agent (agent id) scope');
49
+ const body = {
50
+ whileOnCall: argv.whileOnCall ?? null,
51
+ afterCall: argv.afterCall ?? null,
52
+ callsWhileBusy: argv.callsWhileBusy ?? null,
53
+ };
54
+ if (scope === 'site' && argv.allowAgentOverrides !== undefined) body.allowAgentOverrides = argv.allowAgentOverrides;
55
+ const res = await messagingPut(`/CallPresencePolicy/${scope}/${id}`, body);
56
+ console.log(argv.json ? JSON.stringify(res, null, 2) : `Saved ${scope} ${id}.`);
57
+ }
58
+
59
+ async function clearHandler(argv) {
60
+ const id = argv.scope === 'site' ? 0 : argv.id;
61
+ if (argv.scope !== 'site' && !id) throw new Error('--id is required for group and agent scope');
62
+ await messagingDel(`/CallPresencePolicy/${argv.scope}/${id}`);
63
+ console.log(`Cleared ${argv.scope} ${id}. That level now inherits.`);
64
+ }
65
+
66
+ async function effectiveHandler(argv) {
67
+ const q = argv.team ? `?teamId=${argv.team}` : '';
68
+ const res = await messagingGet(`/CallPresencePolicy/effective/${argv.agentId}${q}`);
69
+ if (argv.json) { console.log(JSON.stringify(res, null, 2)); return; }
70
+ console.log(`\n${BOLD}Effective policy for agent ${res.agentId}${RST}`);
71
+ printEffective(res.effective);
72
+ console.log('');
73
+ }
74
+
75
+ async function statusHandler(argv) {
76
+ const res = await messagingGet('/CallPresencePolicy/presence');
77
+ if (argv.json) { console.log(JSON.stringify(res, null, 2)); return; }
78
+ if (!res.length) { console.log('\n No agents are on a call right now.\n'); return; }
79
+ console.log(`\n${BOLD}Agents on a call${RST}`);
80
+ for (const a of res) console.log(` ${a.agentName} (#${a.agentId}) calls: ${a.activeCallCount}${a.hasSecondCall ? ' [second call]' : ''} current: ${a.currentCallState}`);
81
+ console.log('');
82
+ }
83
+
84
+ const getCommand = {
85
+ command: 'get',
86
+ describe: 'Show the site default, group overrides, agent overrides and the allowed values',
87
+ builder: (y) => y.option('json', { type: 'boolean', describe: 'Raw JSON' }),
88
+ handler: runCommand(getHandler),
89
+ };
90
+
91
+ const setCommand = {
92
+ command: 'set',
93
+ describe: 'Set the policy for the site, a routing group or an agent (omit a setting to inherit)',
94
+ builder: (y) => y
95
+ .option('scope', { choices: SCOPES, demandOption: true, describe: 'Level to set' })
96
+ .option('id', { type: 'number', describe: 'Team id (group scope) or agent id (agent scope)' })
97
+ .option('while-on-call', { choices: WHILE_ON_CALL, describe: 'Chats while on a phone call' })
98
+ .option('after-call', { choices: AFTER_CALL, describe: 'After the call ends' })
99
+ .option('calls-while-busy', { choices: CALLS_WHILE_BUSY, describe: 'Calls for an agent busy on chats' })
100
+ .option('allow-agent-overrides', { type: 'boolean', describe: 'Site scope only: may agents set their own override' })
101
+ .option('json', { type: 'boolean', describe: 'Raw JSON' }),
102
+ handler: runCommand(setHandler),
103
+ };
104
+
105
+ const clearCommand = {
106
+ command: 'clear',
107
+ describe: 'Remove the policy at one level so it inherits again',
108
+ builder: (y) => y
109
+ .option('scope', { choices: SCOPES, demandOption: true })
110
+ .option('id', { type: 'number', describe: 'Team id (group) or agent id (agent)' }),
111
+ handler: runCommand(clearHandler),
112
+ };
113
+
114
+ const effectiveCommand = {
115
+ command: 'effective <agentId>',
116
+ describe: 'Show the resolved policy for one agent and where each setting comes from',
117
+ builder: (y) => y
118
+ .positional('agentId', { type: 'number' })
119
+ .option('team', { type: 'number', describe: 'Routing group to resolve against (agents in several groups)' })
120
+ .option('json', { type: 'boolean', describe: 'Raw JSON' }),
121
+ handler: runCommand(effectiveHandler),
122
+ };
123
+
124
+ const statusCommand = {
125
+ command: 'status',
126
+ describe: 'Agents who are on a live call right now (derived from call records)',
127
+ builder: (y) => y.option('json', { type: 'boolean', describe: 'Raw JSON' }),
128
+ handler: runCommand(statusHandler),
129
+ };
130
+
131
+ export const callpresenceCommand = {
132
+ command: 'callpresence <subcommand>',
133
+ describe: 'Call presence policy: chat and call routing while an agent is on a phone call',
134
+ builder: (y) => y
135
+ .command(getCommand)
136
+ .command(setCommand)
137
+ .command(clearCommand)
138
+ .command(effectiveCommand)
139
+ .command(statusCommand)
140
+ .demandCommand(1, 'Specify a callpresence subcommand.')
141
+ .strict(),
142
+ handler: () => {},
143
+ };
@@ -0,0 +1,81 @@
1
+ // velaro product-match - the per-site Product Match matrix (competitor, old or discontinued part -> your OWN catalog SKU).
2
+ //
3
+ // velaro product-match match "<part or model>" Look a part up (same deterministic action the bot uses)
4
+ // velaro product-match import <file.csv|file.xlsx> Upload the cross-reference matrix (approval column defaults to NO)
5
+ // velaro product-match list [--q text] [--page n] Show matrix rows
6
+ // velaro product-match approve <id> [--revoke] Approve (or revoke) one row; only approved rows are ever recommended
7
+ // velaro product-match remove <id> Delete one row
8
+ // velaro product-match deny list|set "Brand A,Brand B" Brands / competitors the bot must never name
9
+ //
10
+ // Calls messaging POST /BusinessActions/match_product/Execute and the /ProductMatch endpoints. Site scope comes from the signed-in
11
+ // identity. Needs the Product Match package (EnableProductMatch); without it the server answers 403 / not enabled.
12
+ import fs from 'node:fs';
13
+ import path from 'node:path';
14
+ import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
15
+ import { runCommand } from '../run.js';
16
+
17
+ export function buildImportBody(filePath) {
18
+ const ext = path.extname(filePath).toLowerCase();
19
+ if (ext !== '.csv' && ext !== '.xlsx') throw new Error('Only .csv and .xlsx files are supported.');
20
+ const bytes = fs.readFileSync(filePath);
21
+ if (bytes.length === 0) throw new Error('The file is empty.');
22
+ if (bytes.length > 5 * 1024 * 1024) throw new Error('The file is over the 5 MB limit.');
23
+ return { fileName: path.basename(filePath), contentBase64: bytes.toString('base64') };
24
+ }
25
+
26
+ export function parseTerms(text) {
27
+ return String(text ?? '').split(/[,\n;]/).map((t) => t.trim()).filter(Boolean);
28
+ }
29
+
30
+ export const productMatchCommand = {
31
+ command: 'product-match',
32
+ describe: 'Product Match matrix: map competitor, old or discontinued parts to your own catalog SKUs',
33
+ builder: (yargs) => yargs
34
+ .command('match <query>', 'Look up the match for a part number, SKU or model', (y) => y
35
+ .positional('query', { type: 'string' }).option('json', { type: 'boolean' }),
36
+ runCommand(async (a) => {
37
+ const r = await messagingPost('/BusinessActions/match_product/Execute', { query: a.query });
38
+ if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
39
+ if (!r.success) { console.log(`Not available: ${r.error ?? r.errorKind}`); process.exitCode = 1; return; }
40
+ const d = r.data;
41
+ console.log(`Status: ${d.status}${d.handoff ? ' (hand off to a person, no recommendation)' : ''}`);
42
+ for (const m of d.recommendations ?? []) console.log(` ${m.sku} ${m.name} [${m.matchType}]`);
43
+ }))
44
+ .command('import <file>', 'Upload a .csv or .xlsx cross-reference matrix', (y) => y
45
+ .positional('file', { type: 'string' }).option('json', { type: 'boolean' }),
46
+ runCommand(async (a) => {
47
+ const r = await messagingPost('/ProductMatch/ImportFile', buildImportBody(a.file));
48
+ if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
49
+ console.log(`Added ${r.added}, updated ${r.updated}, skipped ${r.skipped}. Targets not in your catalog (never recommended): ${r.targetsNotInCatalog}.`);
50
+ for (const e of r.errors ?? []) console.log(` ${e}`);
51
+ console.log('Rows are NOT approved unless the file had an Approved column set to yes. Approve with: velaro product-match approve <id>');
52
+ }))
53
+ .command('list', 'List matrix rows', (y) => y
54
+ .option('q', { type: 'string' }).option('page', { type: 'number', default: 1 }).option('json', { type: 'boolean' }),
55
+ runCommand(async (a) => {
56
+ const qs = new URLSearchParams({ page: String(a.page) });
57
+ if (a.q) qs.set('q', a.q);
58
+ const r = await messagingGet(`/ProductMatch/Entries?${qs}`);
59
+ if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
60
+ console.log(`${r.total} row(s)`);
61
+ for (const e of r.entries ?? []) console.log(` #${e.id} ${e.source} -> ${e.target} [${e.matchType}] ${e.approved ? 'approved' : 'NOT approved'}`);
62
+ }))
63
+ .command('approve <id>', 'Approve (or --revoke) one row', (y) => y
64
+ .positional('id', { type: 'number' }).option('revoke', { type: 'boolean', default: false }),
65
+ runCommand(async (a) => {
66
+ const r = await messagingPut(`/ProductMatch/Entries/${a.id}/Approve`, { approved: !a.revoke });
67
+ console.log(`Row ${r.id}: ${r.approved ? 'approved' : 'not approved'}`);
68
+ }))
69
+ .command('remove <id>', 'Delete one row', (y) => y.positional('id', { type: 'number' }),
70
+ runCommand(async (a) => { await messagingDel(`/ProductMatch/Entries/${a.id}`); console.log(`Removed row ${a.id}`); }))
71
+ .command('deny <action> [terms]', 'list or set the brands / competitors the bot must never name', (y) => y
72
+ .positional('action', { choices: ['list', 'set'] }).positional('terms', { type: 'string', describe: 'comma separated (set replaces the whole list)' }),
73
+ runCommand(async (a) => {
74
+ const r = a.action === 'set'
75
+ ? await messagingPut('/ProductMatch/DenyTerms', { terms: parseTerms(a.terms) })
76
+ : await messagingGet('/ProductMatch/DenyTerms');
77
+ console.log((r.terms ?? []).length ? r.terms.join(', ') : '(none)');
78
+ }))
79
+ .demandCommand(1),
80
+ handler: () => {},
81
+ };
@@ -0,0 +1,48 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { buildImportBody, parseTerms } from './commands/product-match.js';
7
+ import { tools, handlers } from '../../mcp/parity/product-match.customer.js';
8
+
9
+ test('builds a base64 import body for csv and rejects other types and empty files', () => {
10
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pm-'));
11
+ const csv = path.join(dir, 'm.csv');
12
+ fs.writeFileSync(csv, 'Competitor SKU,Our SKU\nA-1,B-1\n');
13
+ const body = buildImportBody(csv);
14
+ assert.equal(body.fileName, 'm.csv');
15
+ assert.match(Buffer.from(body.contentBase64, 'base64').toString(), /A-1,B-1/);
16
+ const pdf = path.join(dir, 'm.pdf');
17
+ fs.writeFileSync(pdf, 'x');
18
+ assert.throws(() => buildImportBody(pdf), /csv and .xlsx/);
19
+ const empty = path.join(dir, 'e.csv');
20
+ fs.writeFileSync(empty, '');
21
+ assert.throws(() => buildImportBody(empty), /empty/);
22
+ });
23
+
24
+ test('parses deny terms from commas, semicolons and newlines', () => {
25
+ assert.deepEqual(parseTerms('Philips, ResMed;Inogen\n Drive '), ['Philips', 'ResMed', 'Inogen', 'Drive']);
26
+ assert.deepEqual(parseTerms(undefined), []);
27
+ });
28
+
29
+ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match the CLI', async () => {
30
+ for (const t of tools) {
31
+ assert.equal(typeof handlers[t.name], 'function');
32
+ assert.ok(!Object.keys(t.inputSchema.properties ?? {}).includes('siteId'));
33
+ }
34
+ const calls = [];
35
+ const ctx = {
36
+ messagingGet: async (p) => { calls.push(['GET', p]); return {}; },
37
+ messagingPost: async (p, b) => { calls.push(['POST', p, b]); return {}; },
38
+ messagingPut: async (p, b) => { calls.push(['PUT', p, b]); return {}; },
39
+ messagingDel: async (p) => { calls.push(['DEL', p]); return {}; },
40
+ };
41
+ await handlers.product_match_lookup({ query: 'ACME-100' }, ctx);
42
+ await handlers.product_match_approve({ id: 5 }, ctx);
43
+ await handlers.product_match_deny_terms({ terms: ['Philips'] }, ctx);
44
+ assert.deepEqual(calls[0], ['POST', '/BusinessActions/match_product/Execute', { query: 'ACME-100' }]);
45
+ assert.deepEqual(calls[1], ['PUT', '/ProductMatch/Entries/5/Approve', { approved: true }]);
46
+ assert.deepEqual(calls[2], ['PUT', '/ProductMatch/DenyTerms', { terms: ['Philips'] }]);
47
+ await assert.rejects(() => handlers.product_match_approve({ id: 'x' }, ctx), /positive integer/);
48
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.118",
3
+ "version": "1.4.120",
4
4
  "description": "Velaro Workspace v20 — command-line interface for managing bots, knowledge base ingestion, MCP API keys, search indexes, and ops health.",
5
5
  "type": "module",
6
6
  "bin": {