@velaro/cli 1.4.133 → 1.4.135

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.
@@ -1,14 +1,15 @@
1
- // velaro part-finder - the per-site Part Finder: one ordered lookup (cross-reference matrix, business system, own catalog, spec search, hand-off).
1
+ // velaro part-finder (alias: velaro smart-match) - Smart Match, the per-site ordered lookup that matches anything a customer names or shows in a photo to the company's own item (cross-reference matrix, business system, own catalog, spec search, hand-off).
2
2
  //
3
3
  // velaro part-finder find "<part, model or description>" Run the same lookup the bot uses (shows the trace)
4
4
  // velaro part-finder config get Show the order, time limits, confidence and no-result action
5
5
  // velaro part-finder config set [--enabled true|false] [--order matrix,erp,catalog_exact,spec_search] [--disable erp,...]
6
- // [--min-confidence 0.8] [--no-result handoff|categories|handoff_and_categories|capture_lead]
7
- // velaro part-finder sources list|add|sync|preview|remove Matrix sources (SharePoint, OneDrive); preview shows the diff, nothing applied
6
+ // [--item-noun part|product|service|plan|policy|course] [--min-confidence 0.8] [--no-result handoff|categories|handoff_and_categories|capture_lead]
7
+ // velaro part-finder sources list|sync|preview|remove [id] Matrix sources (SharePoint, OneDrive); preview shows the diff, nothing applied
8
+ // velaro part-finder sources add --url <share link> [--type sharepoint|onedrive] [--load-mode preload|live] [--sync-hours N] [--auto-approve]
8
9
  // velaro part-finder misses [--dismiss <id>] What customers asked that found nothing
9
10
  // velaro part-finder suggestions list|generate|approve <id>|reject <id>
10
11
  //
11
- // Calls messaging /PartFinder endpoints. Site scope comes from the signed-in identity. Needs the Part Finder package (EnablePartFinder);
12
+ // Calls messaging /PartFinder endpoints (live contract, name kept). Site scope comes from the signed-in identity. Needs the Smart Match package (EnablePartFinder);
12
13
  // without it the server answers 403 / not enabled.
13
14
  import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
14
15
  import { runCommand } from '../run.js';
@@ -49,6 +50,12 @@ export function buildConfigPatch(current, flags) {
49
50
  if (!Number.isFinite(v) || v < 0 || v > 1) throw new Error('--min-confidence must be between 0 and 1.');
50
51
  patch.minConfidence = v;
51
52
  }
53
+ if (flags['item-noun'] !== undefined) {
54
+ const t = String(flags['item-noun']).trim();
55
+ if (t.length > 40) throw new Error('--item-noun must be 40 characters or fewer.');
56
+ if (t !== '' && !/^[\p{L}\p{N} -]+$/u.test(t)) throw new Error('--item-noun can use letters, digits, spaces and hyphens only.');
57
+ patch.itemNoun = t === '' ? 'item' : t;
58
+ }
52
59
  if (flags['no-result'] !== undefined) {
53
60
  if (!NO_RESULT_ACTIONS.includes(flags['no-result'])) throw new Error(`--no-result must be one of ${NO_RESULT_ACTIONS.join(', ')}.`);
54
61
  patch.noResultAction = flags['no-result'];
@@ -58,6 +65,23 @@ export function buildConfigPatch(current, flags) {
58
65
  return patch;
59
66
  }
60
67
 
68
+ /** Body for POST /PartFinder/Sources from the add flags. Pure, so it is unit tested. The server resolves the link to the file. */
69
+ export function buildSourceBody(flags) {
70
+ const shareUrl = String(flags.url ?? '').trim();
71
+ if (!shareUrl) throw new Error('--url is required for add: the Share link to the .xlsx or .csv file in SharePoint or OneDrive.');
72
+ if (!/^https:\/\//i.test(shareUrl)) throw new Error('--url must be an https link to the file in SharePoint or OneDrive.');
73
+ const type = String(flags.type ?? 'sharepoint').toLowerCase();
74
+ if (type !== 'sharepoint' && type !== 'onedrive') throw new Error('--type must be sharepoint or onedrive.');
75
+ const body = { type, shareUrl, loadMode: flags['load-mode'] ?? 'preload', enabled: true };
76
+ if (flags['sync-hours'] !== undefined) {
77
+ const h = Number(flags['sync-hours']);
78
+ if (!Number.isFinite(h) || h <= 0) throw new Error('--sync-hours must be a positive number.');
79
+ body.syncIntervalHours = h;
80
+ }
81
+ if (flags['auto-approve'] === true) body.autoApproveRows = true;
82
+ return body;
83
+ }
84
+
61
85
  export function listOf(r, ...keys) {
62
86
  if (Array.isArray(r)) return r;
63
87
  for (const k of keys) if (Array.isArray(r?.[k])) return r[k];
@@ -76,9 +100,10 @@ const J = { type: 'boolean', describe: 'print raw JSON' };
76
100
 
77
101
  export const partFinderCommand = {
78
102
  command: 'part-finder',
79
- describe: 'Part Finder: find the right part from a photo, a part number or a competitor model, in the order you choose',
103
+ aliases: ['smart-match'],
104
+ describe: 'Smart Match: match a photo, a number, a name or a competitor name to the right item of yours, in the order you choose',
80
105
  builder: (yargs) => yargs
81
- .command('find <query>', 'Run the lookup the bot uses', (y) => y.positional('query', { type: 'string' }).option('json', J),
106
+ .command('find <query>', 'Run the lookup the bot uses for a name, number, model or description', (y) => y.positional('query', { type: 'string' }).option('json', J),
82
107
  runCommand(async (a) => {
83
108
  const r = await messagingPost('/PartFinder/Find', { query: a.query });
84
109
  if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
@@ -92,27 +117,29 @@ export const partFinderCommand = {
92
117
  .option('enable', { type: 'string' })
93
118
  .option('min-confidence', { type: 'string' })
94
119
  .option('no-result', { type: 'string' })
120
+ .option('item-noun', { type: 'string', describe: 'what you call the things customers look for: part, product, service, plan, policy, course (default item)' })
95
121
  .option('json', J),
96
122
  runCommand(async (a) => {
97
123
  let r = await messagingGet('/PartFinder/Config');
98
124
  if (a.action === 'set') r = await messagingPut('/PartFinder/Config', buildConfigPatch(r, a));
99
125
  if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
100
- console.log(`Part Finder: ${r.enabled ? 'on' : 'off'} min confidence ${r.minConfidence} no result: ${r.noResultAction}`);
126
+ console.log(`Smart Match: ${r.enabled ? 'on' : 'off'} min confidence ${r.minConfidence} no result: ${r.noResultAction} item noun: ${r.itemNoun ?? 'item'}`);
101
127
  (r.steps ?? []).forEach((s, i) => console.log(` ${i + 1}. ${s.id} ${s.enabled ? 'on' : 'off'} ${s.timeoutMs} ms`));
102
128
  }))
103
129
  .command('sources <action> [id]', 'list, add, sync, preview or remove matrix sources', (y) => y
104
130
  .positional('action', { choices: ['list', 'add', 'sync', 'preview', 'remove'] })
105
131
  .positional('id', { type: 'number' })
106
132
  .option('type', { type: 'string', default: 'sharepoint', describe: 'sharepoint or onedrive (add)' })
107
- .option('file', { type: 'string', describe: 'file name or link (add)' })
133
+ .option('url', { type: 'string', describe: 'Share link to the .xlsx or .csv file in SharePoint or OneDrive (add)' })
134
+ .option('sync-hours', { type: 'number', describe: 'how often to check the file, in hours (add)' })
135
+ .option('auto-approve', { type: 'boolean', describe: 'approve new rows automatically (add)' })
108
136
  .option('load-mode', { type: 'string', default: 'preload', describe: 'preload or live (add)' })
109
137
  .option('json', J),
110
138
  runCommand(async (a) => {
111
139
  let r;
112
140
  if (a.action === 'list') r = await messagingGet('/PartFinder/Sources');
113
141
  else if (a.action === 'add') {
114
- if (!a.file) throw new Error('--file is required for add.');
115
- r = await messagingPost('/PartFinder/Sources', { type: a.type, fileName: a.file, loadMode: a['load-mode'], enabled: true });
142
+ r = await messagingPost('/PartFinder/Sources', buildSourceBody(a));
116
143
  } else {
117
144
  if (!a.id) throw new Error(`An id is required for ${a.action}.`);
118
145
  if (a.action === 'remove') { await messagingDel(`/PartFinder/Sources/${a.id}`); console.log(`Removed source ${a.id}`); return; }
@@ -1,6 +1,6 @@
1
1
  import { test } from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
- import { buildConfigPatch, describeFind, listOf, parseList } from './commands/part-finder.js';
3
+ import { partFinderCommand, buildConfigPatch, buildSourceBody, describeFind, listOf, parseList } from './commands/part-finder.js';
4
4
  import { tools, handlers } from '../../mcp/parity/part-finder.customer.js';
5
5
 
6
6
  const current = () => ({
@@ -52,6 +52,8 @@ test('reads bare or wrapped lists and describes a find result with its trace', (
52
52
  assert.match(text, /trace: matrix -> miss \(3 ms\)/);
53
53
  });
54
54
 
55
+ const LINK = 'https://contoso.sharepoint.com/:x:/s/parts/EabC123?e=1';
56
+
55
57
  test('MCP parity: every tool has a handler, none takes a siteId, endpoints match the CLI', async () => {
56
58
  for (const t of tools) {
57
59
  assert.equal(typeof handlers[t.name], 'function');
@@ -69,6 +71,7 @@ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match
69
71
  await handlers.part_finder_config({}, ctx);
70
72
  await handlers.part_finder_config({ minConfidence: 0.9 }, ctx);
71
73
  await handlers.part_finder_sources({}, ctx);
74
+ await handlers.part_finder_source_add({ shareUrl: LINK }, ctx);
72
75
  await handlers.part_finder_source_preview({ id: 4 }, ctx);
73
76
  await handlers.part_finder_source_sync({ id: 4 }, ctx);
74
77
  await handlers.part_finder_source_remove({ id: 4 }, ctx);
@@ -81,6 +84,7 @@ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match
81
84
  ['GET', '/PartFinder/Config'],
82
85
  ['PUT', '/PartFinder/Config'],
83
86
  ['GET', '/PartFinder/Sources'],
87
+ ['POST', '/PartFinder/Sources'],
84
88
  ['GET', '/PartFinder/Sources/4/Preview'],
85
89
  ['POST', '/PartFinder/Sources/4/SyncNow'],
86
90
  ['DEL', '/PartFinder/Sources/4'],
@@ -93,3 +97,55 @@ test('MCP parity: every tool has a handler, none takes a siteId, endpoints match
93
97
  await assert.rejects(() => handlers.part_finder_source_sync({ id: 0 }, ctx), /positive integer/);
94
98
  await assert.rejects(() => handlers.part_finder_config({ minConfidence: 3 }, ctx), /between 0 and 1/);
95
99
  });
100
+
101
+ test('sources add (CLI): sends shareUrl, never fileName, and validates the link and type', () => {
102
+ const b = buildSourceBody({ url: ' ' + LINK + ' ' });
103
+ assert.deepEqual(b, { type: 'sharepoint', shareUrl: LINK, loadMode: 'preload', enabled: true });
104
+ assert.equal('fileName' in b, false);
105
+ const full = buildSourceBody({ url: LINK, type: 'OneDrive', 'load-mode': 'live', 'sync-hours': 6, 'auto-approve': true });
106
+ assert.equal(full.type, 'onedrive');
107
+ assert.equal(full.syncIntervalHours, 6);
108
+ assert.equal(full.autoApproveRows, true);
109
+ assert.throws(() => buildSourceBody({}), /--url is required/);
110
+ assert.throws(() => buildSourceBody({ url: 'Cross.xlsx' }), /https/);
111
+ assert.throws(() => buildSourceBody({ url: LINK, type: 'upload' }), /sharepoint or onedrive/);
112
+ assert.throws(() => buildSourceBody({ url: LINK, 'sync-hours': 0 }), /positive/);
113
+ });
114
+
115
+ test('sources add (MCP): body carries shareUrl, upload is refused, input schema requires shareUrl only', async () => {
116
+ const tool = tools.find((t) => t.name === 'part_finder_source_add');
117
+ assert.deepEqual(tool.inputSchema.required, ['shareUrl']);
118
+ assert.equal('fileName' in tool.inputSchema.properties, false);
119
+ const sent = [];
120
+ const ctx = { messagingPost: async (p, b) => { sent.push([p, b]); return {}; } };
121
+ await handlers.part_finder_source_add({ shareUrl: LINK, type: 'onedrive', autoApproveRows: true, syncIntervalHours: 12 }, ctx);
122
+ assert.deepEqual(sent[0], ['/PartFinder/Sources', { type: 'onedrive', shareUrl: LINK, loadMode: 'preload', enabled: true, syncIntervalHours: 12, autoApproveRows: true }]);
123
+ await assert.rejects(() => handlers.part_finder_source_add({}, ctx), /shareUrl is required/);
124
+ await assert.rejects(() => handlers.part_finder_source_add({ shareUrl: 'Cross.xlsx' }, ctx), /https/);
125
+ await assert.rejects(() => handlers.part_finder_source_add({ shareUrl: LINK, type: 'upload' }, ctx), /sharepoint or onedrive/);
126
+ });
127
+
128
+ test('item noun: trimmed, validated like the server, empty resets to item, and goes in the config patch', () => {
129
+ assert.equal(buildConfigPatch(current(), { 'item-noun': ' plan ' }).itemNoun, 'plan');
130
+ assert.equal(buildConfigPatch(current(), { 'item-noun': 'service plan' }).itemNoun, 'service plan');
131
+ assert.equal(buildConfigPatch(current(), { 'item-noun': ' ' }).itemNoun, 'item');
132
+ assert.throws(() => buildConfigPatch(current(), { 'item-noun': 'plan!' }), /letters, digits, spaces and hyphens/);
133
+ assert.throws(() => buildConfigPatch(current(), { 'item-noun': 'x'.repeat(41) }), /40 characters/);
134
+ });
135
+
136
+ test('MCP part_finder_config accepts itemNoun, sends it, and refuses a bad one', async () => {
137
+ const cfgTool = tools.find((t) => t.name === 'part_finder_config');
138
+ assert.ok(cfgTool.inputSchema.properties.itemNoun);
139
+ const calls = [];
140
+ const ctx = { messagingGet: async () => ({}), messagingPut: async (p, b) => { calls.push([p, b]); return {}; } };
141
+ await handlers.part_finder_config({ itemNoun: ' policy ' }, ctx);
142
+ assert.deepEqual(calls[0], ['/PartFinder/Config', { itemNoun: 'policy' }]);
143
+ await assert.rejects(() => handlers.part_finder_config({ itemNoun: 'a/b' }, ctx), /itemNoun/);
144
+ });
145
+
146
+ test('customer-facing text says Smart Match, the CLI keeps part-finder and adds the smart-match alias', () => {
147
+ assert.equal(partFinderCommand.command, 'part-finder');
148
+ assert.ok(partFinderCommand.aliases.includes('smart-match'));
149
+ assert.match(partFinderCommand.describe, /Smart Match/);
150
+ for (const t of tools) assert.doesNotMatch(t.description, /Part Finder/, t.name);
151
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.133",
3
+ "version": "1.4.135",
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": {