@velaro/cli 1.4.134 → 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.
- package/lib/commands/part-finder.js +14 -6
- package/lib/part-finder.test.js +26 -1
- package/package.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
// velaro part-finder - the per-site
|
|
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]
|
|
6
|
+
// [--item-noun part|product|service|plan|policy|course] [--min-confidence 0.8] [--no-result handoff|categories|handoff_and_categories|capture_lead]
|
|
7
7
|
// velaro part-finder sources list|sync|preview|remove [id] Matrix sources (SharePoint, OneDrive); preview shows the diff, nothing applied
|
|
8
8
|
// velaro part-finder sources add --url <share link> [--type sharepoint|onedrive] [--load-mode preload|live] [--sync-hours N] [--auto-approve]
|
|
9
9
|
// velaro part-finder misses [--dismiss <id>] What customers asked that found nothing
|
|
10
10
|
// velaro part-finder suggestions list|generate|approve <id>|reject <id>
|
|
11
11
|
//
|
|
12
|
-
// Calls messaging /PartFinder endpoints. Site scope comes from the signed-in identity. Needs the
|
|
12
|
+
// Calls messaging /PartFinder endpoints (live contract, name kept). Site scope comes from the signed-in identity. Needs the Smart Match package (EnablePartFinder);
|
|
13
13
|
// without it the server answers 403 / not enabled.
|
|
14
14
|
import { messagingGet, messagingPost, messagingPut, messagingDel } from '../api.js';
|
|
15
15
|
import { runCommand } from '../run.js';
|
|
@@ -50,6 +50,12 @@ export function buildConfigPatch(current, flags) {
|
|
|
50
50
|
if (!Number.isFinite(v) || v < 0 || v > 1) throw new Error('--min-confidence must be between 0 and 1.');
|
|
51
51
|
patch.minConfidence = v;
|
|
52
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
|
+
}
|
|
53
59
|
if (flags['no-result'] !== undefined) {
|
|
54
60
|
if (!NO_RESULT_ACTIONS.includes(flags['no-result'])) throw new Error(`--no-result must be one of ${NO_RESULT_ACTIONS.join(', ')}.`);
|
|
55
61
|
patch.noResultAction = flags['no-result'];
|
|
@@ -94,9 +100,10 @@ const J = { type: 'boolean', describe: 'print raw JSON' };
|
|
|
94
100
|
|
|
95
101
|
export const partFinderCommand = {
|
|
96
102
|
command: 'part-finder',
|
|
97
|
-
|
|
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',
|
|
98
105
|
builder: (yargs) => yargs
|
|
99
|
-
.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),
|
|
100
107
|
runCommand(async (a) => {
|
|
101
108
|
const r = await messagingPost('/PartFinder/Find', { query: a.query });
|
|
102
109
|
if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
@@ -110,12 +117,13 @@ export const partFinderCommand = {
|
|
|
110
117
|
.option('enable', { type: 'string' })
|
|
111
118
|
.option('min-confidence', { type: 'string' })
|
|
112
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)' })
|
|
113
121
|
.option('json', J),
|
|
114
122
|
runCommand(async (a) => {
|
|
115
123
|
let r = await messagingGet('/PartFinder/Config');
|
|
116
124
|
if (a.action === 'set') r = await messagingPut('/PartFinder/Config', buildConfigPatch(r, a));
|
|
117
125
|
if (a.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
118
|
-
console.log(`
|
|
126
|
+
console.log(`Smart Match: ${r.enabled ? 'on' : 'off'} min confidence ${r.minConfidence} no result: ${r.noResultAction} item noun: ${r.itemNoun ?? 'item'}`);
|
|
119
127
|
(r.steps ?? []).forEach((s, i) => console.log(` ${i + 1}. ${s.id} ${s.enabled ? 'on' : 'off'} ${s.timeoutMs} ms`));
|
|
120
128
|
}))
|
|
121
129
|
.command('sources <action> [id]', 'list, add, sync, preview or remove matrix sources', (y) => y
|
package/lib/part-finder.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { test } from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
|
-
import { buildConfigPatch, buildSourceBody, 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 = () => ({
|
|
@@ -124,3 +124,28 @@ test('sources add (MCP): body carries shareUrl, upload is refused, input schema
|
|
|
124
124
|
await assert.rejects(() => handlers.part_finder_source_add({ shareUrl: 'Cross.xlsx' }, ctx), /https/);
|
|
125
125
|
await assert.rejects(() => handlers.part_finder_source_add({ shareUrl: LINK, type: 'upload' }, ctx), /sharepoint or onedrive/);
|
|
126
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