@velaro/cli 1.4.239 → 1.4.241
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 +360 -370
- package/lib/commands/article.js +772 -763
- package/lib/commands/billing-subscription.js +909 -907
- package/lib/commands/conversation-action.js +12 -4
- package/lib/commands/index.js +259 -322
- package/lib/commands/ingest.js +36 -32
- package/lib/commands/mcp-key.js +218 -209
- package/lib/confirm.js +14 -0
- package/package.json +40 -45
- package/assets/billing-doc-patterns/concentric-arcs.png +0 -0
- package/assets/billing-doc-patterns/diagonal-hatch.png +0 -0
- package/assets/billing-doc-patterns/dot-grid.png +0 -0
- package/assets/billing-doc-patterns/hex-grid.png +0 -0
- package/assets/billing-doc-patterns/wave-lines.png +0 -0
- package/assets/velaro-logo-lockup-full-color.png +0 -0
- package/lib/commands/db.js +0 -105
- package/lib/commands/deploy-state.js +0 -26
- package/lib/commands/deployment.js +0 -107
- package/lib/commands/schedule-adherence.js +0 -33
- package/lib/commands/sharepoint.js +0 -168
- package/lib/deploy-state.js +0 -408
- package/lib/deploy-state.test.js +0 -133
- package/lib/kb-screenshot.js +0 -433
- package/lib/migrations/amscro.json +0 -72
- package/lib/migrations/azenta.json +0 -68
- package/lib/migrations/bluefire.json +0 -49
- package/lib/migrations/donaldson.json +0 -75
- package/lib/pdf/billing-document.js +0 -534
- package/lib/pdf/billing-document.test.js +0 -349
- package/lib/sharepoint-auth.js +0 -138
package/lib/kb-screenshot.js
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* kb-screenshot.js — capture a live staging screenshot and drop it into a KB article.
|
|
3
|
-
*
|
|
4
|
-
* Reuses:
|
|
5
|
-
* - the login-form-fill steps from e2e/tests/auth.setup.ts (adapted to run standalone,
|
|
6
|
-
* outside the Playwright test-runner lifecycle)
|
|
7
|
-
* - scripts/polish-screenshot.py for rounded corners / shadow / annotations
|
|
8
|
-
* - cli/lib/commands/article.js's adminRequest() for auth + KB article get/update
|
|
9
|
-
* - server/Velaro.Admin/Controllers/KB/KBArticlesController.cs's upload-image endpoint
|
|
10
|
-
*
|
|
11
|
-
* playwright is an OPTIONAL dependency of @velaro/cli (it pulls down a full Chromium
|
|
12
|
-
* binary) — it's dynamically imported here so a plain `velaro` install never pays that
|
|
13
|
-
* cost unless this command is actually used.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { readFileSync, unlinkSync, existsSync } from 'fs';
|
|
17
|
-
import { tmpdir } from 'os';
|
|
18
|
-
import { join, extname, basename, dirname } from 'path';
|
|
19
|
-
import { fileURLToPath } from 'url';
|
|
20
|
-
import { execFile } from 'child_process';
|
|
21
|
-
import { promisify } from 'util';
|
|
22
|
-
import { getCredentials } from './api.js';
|
|
23
|
-
import { adminRequest } from './commands/article.js';
|
|
24
|
-
|
|
25
|
-
const execFileAsync = promisify(execFile);
|
|
26
|
-
|
|
27
|
-
// Resolve relative to this file's location (cli/lib/), not process.cwd() — the CLI
|
|
28
|
-
// is invoked from wherever the caller happens to be (cli/, repo root, or a global
|
|
29
|
-
// install), and process.cwd()-based resolution silently 404s outside the repo root.
|
|
30
|
-
// Repo layout: <repoRoot>/scripts/polish-screenshot.py, this file at <repoRoot>/cli/lib/.
|
|
31
|
-
const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
32
|
-
|
|
33
|
-
const APP_URLS = {
|
|
34
|
-
admin: process.env.ADMIN_UI_URL || 'https://admin-staging.velaro.com',
|
|
35
|
-
messaging: process.env.MSG_UI_URL || 'https://messaging-staging.velaro.com',
|
|
36
|
-
// v10 (livefluence). Console-staging, never prod -- same "staging only" rule as admin/messaging.
|
|
37
|
-
livefluence: process.env.LIVEFLUENCE_UI_URL || 'https://console-staging.velaro.com',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// Key Vault fallback for credentials — used only when neither E2E_USER_* nor TEST_USER_*
|
|
41
|
-
// env vars are set. Configurable via env so this isn't hardcoded to one account forever.
|
|
42
|
-
const KV_NAME = process.env.KB_SCREENSHOT_KV_NAME || 'velaro-eastus-stg-kv';
|
|
43
|
-
const KV_EMAIL_SECRET = process.env.KB_SCREENSHOT_KV_EMAIL_SECRET || 'claude-test-agent-staging1032-email';
|
|
44
|
-
const KV_PASSWORD_SECRET = process.env.KB_SCREENSHOT_KV_PASSWORD_SECRET || 'claude-test-agent-staging1032-password';
|
|
45
|
-
|
|
46
|
-
// v10 (livefluence) console-staging uses a DIFFERENT test account than admin/messaging's
|
|
47
|
-
// default above -- confirmed live 2026-09-18 (memory: project_test_agent_reset_and_transfer_test_gaps_2026-09-15).
|
|
48
|
-
// Never silently reuse the admin/messaging KV secret names for v10; they resolve to a
|
|
49
|
-
// different account that has no guarantee of being provisioned on site 1032's v10 side.
|
|
50
|
-
const LIVEFLUENCE_KV_NAME = process.env.LIVEFLUENCE_KB_SCREENSHOT_KV_NAME || 'velaro-eastus-stg-kv';
|
|
51
|
-
const LIVEFLUENCE_KV_USERNAME_SECRET = process.env.LIVEFLUENCE_KB_SCREENSHOT_KV_USERNAME_SECRET || 'claude-test-agent-staging1032-username';
|
|
52
|
-
const LIVEFLUENCE_KV_PASSWORD_SECRET = process.env.LIVEFLUENCE_KB_SCREENSHOT_KV_PASSWORD_SECRET || 'claude-test-agent-staging1032-password';
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Pulls the email/password pair from Azure Key Vault via DefaultAzureCredential.
|
|
56
|
-
* Locally this picks up the operator's own `az login` session automatically — no
|
|
57
|
-
* extra config needed. In CI (non-interactive), DefaultAzureCredential would need
|
|
58
|
-
* AZURE_CLIENT_ID/AZURE_TENANT_ID/AZURE_CLIENT_SECRET env vars (or a federated
|
|
59
|
-
* identity) to authenticate — out of scope here since this CLI command is
|
|
60
|
-
* operator-run today, not a CI step.
|
|
61
|
-
*/
|
|
62
|
-
async function loadCredentialsFromKeyVault(vaultName, emailSecretName, passwordSecretName) {
|
|
63
|
-
const { SecretClient } = await import('@azure/keyvault-secrets');
|
|
64
|
-
const { DefaultAzureCredential } = await import('@azure/identity');
|
|
65
|
-
|
|
66
|
-
const vaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
67
|
-
const client = new SecretClient(vaultUrl, new DefaultAzureCredential());
|
|
68
|
-
|
|
69
|
-
const [emailSecret, passwordSecret] = await Promise.all([
|
|
70
|
-
client.getSecret(emailSecretName),
|
|
71
|
-
client.getSecret(passwordSecretName),
|
|
72
|
-
]);
|
|
73
|
-
|
|
74
|
-
return { email: emailSecret.value, password: passwordSecret.value };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function loadPlaywright() {
|
|
78
|
-
try {
|
|
79
|
-
return await import('playwright');
|
|
80
|
-
} catch (err) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
'playwright is not installed. Run "npm install playwright" (or "npm install -g @velaro/cli" ' +
|
|
83
|
-
'again after it is added) before using "velaro kb article screenshot". ' +
|
|
84
|
-
`(${err.message})`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// The SPA can bounce through the CIAM "Pick an account" page; choose the signed-in tile (at most 3 hops).
|
|
90
|
-
async function chooseSignedInAccount(page) {
|
|
91
|
-
for (let i = 0; i < 3; i++) {
|
|
92
|
-
if (!/login\.velaro\.com/.test(page.url())) break;
|
|
93
|
-
const tile = page.getByText('Signed in', { exact: true }).first();
|
|
94
|
-
if (!(await tile.isVisible().catch(() => false))) break;
|
|
95
|
-
await tile.click();
|
|
96
|
-
await page.waitForURL((u) => !/login\.velaro\.com/.test(u.toString()), { timeout: 30_000 }).catch(() => {});
|
|
97
|
-
await page.waitForLoadState('networkidle', { timeout: 15_000 }).catch(() => {});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Logs into the given app on staging using the same form-fill steps as
|
|
103
|
-
* e2e/tests/auth.setup.ts, navigates to `route`, optionally clicks a selector,
|
|
104
|
-
* and screenshots to `outputPath`.
|
|
105
|
-
*
|
|
106
|
-
* @param {object} [opts]
|
|
107
|
-
* @param {string} [opts.click] Selector (any Playwright engine — CSS, `text=`, `role=`) to
|
|
108
|
-
* click after the route loads, before capturing. Needed to reach anything not visible on
|
|
109
|
-
* initial page load — an export menu, a "..." row action, a modal trigger.
|
|
110
|
-
* @param {boolean} [opts.popup] The click in `opts.click` opens a NEW browser window/tab
|
|
111
|
-
* (`window.open`, `target="_blank"`) rather than something in the current page — e.g. a
|
|
112
|
-
* per-transcript "Export" action. Without this, `page.screenshot()` still captures the
|
|
113
|
-
* ORIGINAL page (usually just the button that was clicked), because Playwright never
|
|
114
|
-
* automatically follows focus to a new window. Root cause of the 2026-09-18 KB gap: the
|
|
115
|
-
* transcript-export screenshot needed this and the tool had no way to follow the popup.
|
|
116
|
-
*/
|
|
117
|
-
export async function loginAndScreenshot(app, route, outputPath, opts = {}) {
|
|
118
|
-
const baseUrl = APP_URLS[app];
|
|
119
|
-
if (!baseUrl) throw new Error(`Unknown app "${app}" — expected "admin", "messaging", or "livefluence".`);
|
|
120
|
-
|
|
121
|
-
const isLivefluence = app === 'livefluence';
|
|
122
|
-
|
|
123
|
-
let email = process.env.E2E_USER_EMAIL || process.env.TEST_USER_EMAIL;
|
|
124
|
-
let password = process.env.E2E_USER_PASSWORD || process.env.TEST_USER_PASSWORD;
|
|
125
|
-
|
|
126
|
-
if (!email || !password) {
|
|
127
|
-
try {
|
|
128
|
-
const kvCreds = isLivefluence
|
|
129
|
-
? await loadCredentialsFromKeyVault(LIVEFLUENCE_KV_NAME, LIVEFLUENCE_KV_USERNAME_SECRET, LIVEFLUENCE_KV_PASSWORD_SECRET)
|
|
130
|
-
: await loadCredentialsFromKeyVault(KV_NAME, KV_EMAIL_SECRET, KV_PASSWORD_SECRET);
|
|
131
|
-
email = kvCreds.email;
|
|
132
|
-
password = kvCreds.password;
|
|
133
|
-
} catch (err) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
'E2E_USER_EMAIL/E2E_USER_PASSWORD (or TEST_USER_EMAIL/TEST_USER_PASSWORD) must be set ' +
|
|
136
|
-
'to capture a live screenshot — these are the same env vars used by e2e/tests/auth.setup.ts. ' +
|
|
137
|
-
`Key Vault fallback also failed: ${err.message}`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!email || !password) {
|
|
143
|
-
const [vault, userSecret, passSecret] = isLivefluence
|
|
144
|
-
? [LIVEFLUENCE_KV_NAME, LIVEFLUENCE_KV_USERNAME_SECRET, LIVEFLUENCE_KV_PASSWORD_SECRET]
|
|
145
|
-
: [KV_NAME, KV_EMAIL_SECRET, KV_PASSWORD_SECRET];
|
|
146
|
-
throw new Error(
|
|
147
|
-
'E2E_USER_EMAIL/E2E_USER_PASSWORD (or TEST_USER_EMAIL/TEST_USER_PASSWORD) must be set, ' +
|
|
148
|
-
`and Key Vault (${vault}) did not return usable values for secrets ` +
|
|
149
|
-
`"${userSecret}"/"${passSecret}".`
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const { chromium } = await loadPlaywright();
|
|
154
|
-
const browser = await chromium.launch();
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
const context = await browser.newContext();
|
|
158
|
-
const page = await context.newPage();
|
|
159
|
-
|
|
160
|
-
if (isLivefluence) {
|
|
161
|
-
// ── v10 login (Client.ConsoleNew's own /Account/Login form, no CIAM redirect) ──
|
|
162
|
-
// Direct email+password form on the same host -- confirmed live 2026-09-18 via
|
|
163
|
-
// interactive login at app.velaro.com/Account/Login. Unlike admin/messaging, there
|
|
164
|
-
// is no login.velaro.com hop and no "stay signed in" prompt to handle.
|
|
165
|
-
await page.goto(new URL('/Account/Login', baseUrl).toString());
|
|
166
|
-
// The field's accessible label/placeholder is literally "Username" (an email
|
|
167
|
-
// address is entered into it, but it is NOT labeled "Email") -- confirmed live
|
|
168
|
-
// 2026-09-18 against the real login form; an /email/i selector silently matched
|
|
169
|
-
// nothing and the fill() was a no-op, which the old broad waitForURL(/velaro\.com/)
|
|
170
|
-
// masked because that regex also matches the login page's own URL.
|
|
171
|
-
await page.getByPlaceholder(/username/i).fill(email);
|
|
172
|
-
await page.getByPlaceholder(/password/i).fill(password);
|
|
173
|
-
// Exact match -- "Sign in with SSO" also matches a loose /sign in/i regex and sits
|
|
174
|
-
// right next to the real submit button (confirmed live 2026-09-18, strict-mode
|
|
175
|
-
// violation on first test run).
|
|
176
|
-
await page.getByRole('button', { name: 'Sign In', exact: true }).click();
|
|
177
|
-
// Must NOT match the login page's own URL -- wait for the post-login redirect away
|
|
178
|
-
// from /Account/Login specifically, not just "somewhere on velaro.com".
|
|
179
|
-
await page.waitForURL((url) => !url.pathname.toLowerCase().includes('/account/login'), { timeout: 30_000 });
|
|
180
|
-
} else {
|
|
181
|
-
// ── Login (adapted from e2e/tests/auth.setup.ts) ──────────────────────────
|
|
182
|
-
// Role/label based selectors, not type-attribute selectors — the CIAM login page's
|
|
183
|
-
// markup does not reliably render the email field as a literal input[type="email"]
|
|
184
|
-
// or the submit controls as input[type="submit"] (found 2026-08-01 in auth.setup.ts,
|
|
185
|
-
// confirmed again 2026-08-13 against live admin-staging while verifying the Key
|
|
186
|
-
// Vault credential fallback below: the email step is input[name="username"]
|
|
187
|
-
// type="text", and both submit controls are <button type="submit">). Role/label
|
|
188
|
-
// selectors track the accessible page contract instead of an implementation detail
|
|
189
|
-
// that can change under us.
|
|
190
|
-
await page.goto(baseUrl);
|
|
191
|
-
await page.waitForURL(/login\.velaro\.com/, { timeout: 30_000 });
|
|
192
|
-
|
|
193
|
-
await page.getByRole('textbox', { name: /email/i }).fill(email);
|
|
194
|
-
await page.getByRole('button', { name: /next|sign in/i }).click();
|
|
195
|
-
|
|
196
|
-
await page.getByLabel(/password/i).fill(password);
|
|
197
|
-
await page.getByRole('button', { name: /sign in|next/i }).click();
|
|
198
|
-
|
|
199
|
-
// Handle "Stay signed in?" prompt — not always shown.
|
|
200
|
-
try {
|
|
201
|
-
await page.getByRole('button', { name: 'Yes', exact: true }).click({ timeout: 15_000 });
|
|
202
|
-
} catch { /* prompt not shown — proceed */ }
|
|
203
|
-
|
|
204
|
-
await page.waitForURL(/velaro\.com/, { timeout: 30_000 });
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// ── Navigate + capture ──────────────────────────────────────────────────
|
|
208
|
-
const target = new URL(route, baseUrl).toString();
|
|
209
|
-
await page.goto(target);
|
|
210
|
-
await page.waitForLoadState('networkidle', { timeout: 30_000 }).catch(() => {
|
|
211
|
-
// Some pages keep a long-lived connection (SignalR) open — don't fail the
|
|
212
|
-
// capture just because the network never goes fully idle.
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
// The SPA can bounce through the CIAM "Pick an account" page; choose the signed-in tile.
|
|
216
|
-
await chooseSignedInAccount(page);
|
|
217
|
-
|
|
218
|
-
// The HTML splash and the app's own loading screen both look "idle" to networkidle;
|
|
219
|
-
// a capture taken then is a picture of the loading screen (seen 2026-11-03 on usage page).
|
|
220
|
-
await page.waitForSelector('#app-splash', { state: 'detached', timeout: 30_000 }).catch(() => {});
|
|
221
|
-
await page.waitForFunction(
|
|
222
|
-
() => !/preparing your workspace|before reacting|loading/i.test(document.body.innerText.slice(0, 400)) && document.querySelectorAll('nav, aside, main').length > 0,
|
|
223
|
-
undefined,
|
|
224
|
-
{ timeout: 30_000 }
|
|
225
|
-
).catch(() => {});
|
|
226
|
-
await page.waitForSelector('.vw-lockup', { state: 'detached', timeout: 60_000 }).catch(() => {});
|
|
227
|
-
await page.waitForTimeout(3000);
|
|
228
|
-
|
|
229
|
-
// Again after the app settles: the SPA can bounce through the CIAM "Pick an account" page; choose the signed-in tile.
|
|
230
|
-
await chooseSignedInAccount(page);
|
|
231
|
-
|
|
232
|
-
await page.waitForFunction(
|
|
233
|
-
() => !/preparing your workspace|before reacting|loading/i.test(document.body.innerText.slice(0, 400)),
|
|
234
|
-
undefined,
|
|
235
|
-
{ timeout: 30_000 }
|
|
236
|
-
).catch(() => {});
|
|
237
|
-
await page.waitForTimeout(1500);
|
|
238
|
-
|
|
239
|
-
let captureTarget = page;
|
|
240
|
-
|
|
241
|
-
if (opts.click) {
|
|
242
|
-
if (opts.popup) {
|
|
243
|
-
// context.waitForEvent('page') must be armed BEFORE the click, not after — the
|
|
244
|
-
// popup can open (and even finish loading) before an await on the click resolves.
|
|
245
|
-
const [popup] = await Promise.all([
|
|
246
|
-
context.waitForEvent('page', { timeout: 15_000 }),
|
|
247
|
-
page.click(opts.click),
|
|
248
|
-
]);
|
|
249
|
-
await popup.waitForLoadState('networkidle', { timeout: 30_000 }).catch(() => {});
|
|
250
|
-
captureTarget = popup;
|
|
251
|
-
} else {
|
|
252
|
-
await page.click(opts.click);
|
|
253
|
-
// Give in-page content (a modal, an inline export panel) a moment to render —
|
|
254
|
-
// there's no popup "page" event to wait on for same-page UI.
|
|
255
|
-
await page.waitForLoadState('networkidle', { timeout: 15_000 }).catch(() => {});
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
await captureTarget.screenshot({ path: outputPath, fullPage: true });
|
|
260
|
-
if (captureTarget !== page) await captureTarget.close();
|
|
261
|
-
} finally {
|
|
262
|
-
await browser.close();
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Shells out to scripts/polish-screenshot.py. Flags match that script's argparse
|
|
268
|
-
* definitions exactly: `--annotate "x,y,label"`, repeatable.
|
|
269
|
-
*/
|
|
270
|
-
export async function polishScreenshot(inputPath, annotations, polishOpts) {
|
|
271
|
-
const hasAnnotations = annotations && annotations.length > 0;
|
|
272
|
-
if (!hasAnnotations && !polishOpts) return inputPath;
|
|
273
|
-
|
|
274
|
-
const outputPath = inputPath.replace(/\.(png|jpg|jpeg)$/i, '.polished.png');
|
|
275
|
-
const scriptPath = join(REPO_ROOT, 'scripts', 'polish-screenshot.py');
|
|
276
|
-
|
|
277
|
-
const args = [scriptPath, inputPath, outputPath];
|
|
278
|
-
for (const a of (annotations || [])) {
|
|
279
|
-
if (a.x == null || a.y == null || Number.isNaN(a.x) || Number.isNaN(a.y)) {
|
|
280
|
-
throw new Error(`Invalid annotation: ${JSON.stringify(a)} — expected {x, y, label}`);
|
|
281
|
-
}
|
|
282
|
-
args.push('--annotate', `${a.x},${a.y},${a.label ?? ''}`);
|
|
283
|
-
}
|
|
284
|
-
// Standard KB style-guide defaults (see ~/.claude/skills/polish-screenshot/SKILL.md) — always
|
|
285
|
-
// route product/KB screenshots through this rather than embedding raw captures.
|
|
286
|
-
if (polishOpts) {
|
|
287
|
-
args.push('--bg', polishOpts.bg || 'F4F5F7');
|
|
288
|
-
args.push('--pad', String(polishOpts.pad ?? 40));
|
|
289
|
-
args.push('--radius', String(polishOpts.radius ?? 10));
|
|
290
|
-
args.push('--shadow-size', String(polishOpts.shadowSize ?? 24));
|
|
291
|
-
if (polishOpts.border !== false) args.push('--border');
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
await execFileAsync('python', args);
|
|
296
|
-
} catch (err) {
|
|
297
|
-
throw new Error(`scripts/polish-screenshot.py failed: ${err.message}`);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return outputPath;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function mimeTypeFor(path) {
|
|
304
|
-
const ext = extname(path).toLowerCase();
|
|
305
|
-
if (ext === '.jpg' || ext === '.jpeg') return 'image/jpeg';
|
|
306
|
-
if (ext === '.gif') return 'image/gif';
|
|
307
|
-
if (ext === '.webp') return 'image/webp';
|
|
308
|
-
return 'image/png';
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/** Uploads via the existing KBArticlesController upload-image endpoint. Returns the image URL. */
|
|
312
|
-
export async function uploadImage(imagePath, creds) {
|
|
313
|
-
const apiBase = creds.adminApiBase || 'https://help.velaro.com';
|
|
314
|
-
|
|
315
|
-
const buffer = readFileSync(imagePath);
|
|
316
|
-
const form = new FormData();
|
|
317
|
-
form.append('file', new Blob([buffer], { type: mimeTypeFor(imagePath) }), basename(imagePath));
|
|
318
|
-
|
|
319
|
-
const res = await fetch(`${apiBase}/api/kb/articles/upload-image`, {
|
|
320
|
-
method: 'POST',
|
|
321
|
-
headers: { Authorization: `Bearer ${creds.velaroToken}` },
|
|
322
|
-
body: form,
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
if (!res.ok) {
|
|
326
|
-
let msg = `upload-image -> ${res.status}`;
|
|
327
|
-
try { const t = await res.text(); if (t) msg += `: ${t.slice(0, 300)}`; } catch { /* status already captured */ }
|
|
328
|
-
throw new Error(msg);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const data = await res.json();
|
|
332
|
-
if (!data?.url) throw new Error('upload-image response did not include a url');
|
|
333
|
-
return data.url;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Case-insensitive substring match against <h2>/<h3> text content. Inserts immediately
|
|
338
|
-
* after the matched heading's closing tag; appends to the end if no heading (or no
|
|
339
|
-
* match) was given.
|
|
340
|
-
*/
|
|
341
|
-
export function insertImageAfterHeading(html, heading, imgTag) {
|
|
342
|
-
const body = html ?? '';
|
|
343
|
-
|
|
344
|
-
if (!heading) {
|
|
345
|
-
return { html: `${body}\n${imgTag}`, insertedAfterHeading: false };
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const headingRegex = /<h([23])[^>]*>([\s\S]*?)<\/h\1>/gi;
|
|
349
|
-
let match;
|
|
350
|
-
while ((match = headingRegex.exec(body)) !== null) {
|
|
351
|
-
const text = match[2].replace(/<[^>]+>/g, '').trim();
|
|
352
|
-
if (text.toLowerCase().includes(heading.toLowerCase())) {
|
|
353
|
-
const insertAt = match.index + match[0].length;
|
|
354
|
-
return {
|
|
355
|
-
html: `${body.slice(0, insertAt)}\n${imgTag}\n${body.slice(insertAt)}`,
|
|
356
|
-
insertedAfterHeading: true,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return { html: `${body}\n${imgTag}`, insertedAfterHeading: false };
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export function escapeAttr(s) {
|
|
365
|
-
return String(s).replace(/&/g, '&').replace(/"/g, '"');
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* @param {object} opts
|
|
370
|
-
* @param {"admin"|"messaging"|"livefluence"} opts.app
|
|
371
|
-
* @param {string} opts.route
|
|
372
|
-
* @param {number} opts.articleId
|
|
373
|
-
* @param {string} [opts.heading]
|
|
374
|
-
* @param {{x:number,y:number,label?:string}[]} [opts.annotations]
|
|
375
|
-
* @param {string} [opts.click] Selector to click after the route loads, before capturing.
|
|
376
|
-
* @param {boolean} [opts.popup] The click opens a new browser window — capture that
|
|
377
|
-
* window's content instead of the original page's. See loginAndScreenshot() for why
|
|
378
|
-
* this is required (a popup is invisible to a plain page.screenshot() otherwise).
|
|
379
|
-
* @param {{token:string, apiBase:string}} [opts.auth] Explicit auth override for callers
|
|
380
|
-
* that don't use the CLI's stored login config (e.g. mcp/server.js, which authenticates
|
|
381
|
-
* via VELARO_MCP_KEY/VELARO_JWT env vars). CLI usage omits this and falls back to
|
|
382
|
-
* getCredentials() (the normal `velaro login` flow).
|
|
383
|
-
* @returns {Promise<{articleId:number, imageUrl:string, insertedAfterHeading:boolean}>}
|
|
384
|
-
*/
|
|
385
|
-
export async function captureKbScreenshot({ app, route, articleId, heading, annotations, click, popup, auth }) {
|
|
386
|
-
if (!app || !APP_URLS[app]) throw new Error('app must be "admin", "messaging", or "livefluence"');
|
|
387
|
-
if (!route) throw new Error('route is required');
|
|
388
|
-
if (!articleId) throw new Error('articleId is required');
|
|
389
|
-
if (popup && !click) throw new Error('--popup requires --click (nothing to click that would open one)');
|
|
390
|
-
|
|
391
|
-
const rawPath = join(tmpdir(), `kb-screenshot-${articleId}-${Date.now()}.png`);
|
|
392
|
-
let polishedPath = rawPath;
|
|
393
|
-
|
|
394
|
-
try {
|
|
395
|
-
const creds = auth
|
|
396
|
-
? { velaroToken: auth.token, adminApiBase: auth.apiBase }
|
|
397
|
-
: await getCredentials();
|
|
398
|
-
|
|
399
|
-
await loginAndScreenshot(app, route, rawPath, { click, popup });
|
|
400
|
-
polishedPath = await polishScreenshot(rawPath, annotations);
|
|
401
|
-
const imageUrl = await uploadImage(polishedPath, creds);
|
|
402
|
-
|
|
403
|
-
const article = await adminRequest('GET', `/api/kb/articles?id=${articleId}`, undefined, creds);
|
|
404
|
-
if (!article) throw new Error(`Article ${articleId} not found`);
|
|
405
|
-
|
|
406
|
-
const imgTag = `<img src="${imageUrl}" alt="${heading ? escapeAttr(heading) : 'Screenshot'}" />`;
|
|
407
|
-
const { html: newContent, insertedAfterHeading } = insertImageAfterHeading(article.content, heading, imgTag);
|
|
408
|
-
|
|
409
|
-
await adminRequest('PUT', `/api/kb/articles?id=${articleId}`, {
|
|
410
|
-
title: article.title,
|
|
411
|
-
slug: article.slug,
|
|
412
|
-
topicId: article.topicId,
|
|
413
|
-
description: article.description,
|
|
414
|
-
content: newContent,
|
|
415
|
-
visibility: article.visibility,
|
|
416
|
-
searchTags: article.searchTags,
|
|
417
|
-
isPublished: article.isPublished,
|
|
418
|
-
displayPriority: article.displayPriority,
|
|
419
|
-
enableBotResponse: article.enableBotResponse,
|
|
420
|
-
botSummary: article.botSummary,
|
|
421
|
-
isFeatured: article.isFeatured,
|
|
422
|
-
}, creds);
|
|
423
|
-
|
|
424
|
-
return { articleId, imageUrl, insertedAfterHeading };
|
|
425
|
-
} catch (err) {
|
|
426
|
-
throw new Error(`kb screenshot capture failed: ${err.message}`);
|
|
427
|
-
} finally {
|
|
428
|
-
// Best-effort cleanup — never let a temp-file error mask the real result/error.
|
|
429
|
-
for (const p of new Set([rawPath, polishedPath])) {
|
|
430
|
-
try { if (existsSync(p)) unlinkSync(p); } catch { /* ignore cleanup failure */ }
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Amscro / Oxygen Concentrator",
|
|
3
|
-
"slug": "amscro",
|
|
4
|
-
"description": "Healthcare DME: new/existing patient intake routing, widget hidden on insurance pages, ServiceNow post-chat.",
|
|
5
|
-
"patterns": ["healthcare", "prechat-intake", "url-routing", "widget-hide", "post-chat-crm"],
|
|
6
|
-
"notes": [
|
|
7
|
-
"HIPAA-adjacent — no PHI in chat. Conversations are sensitive.",
|
|
8
|
-
"Widget hidden on /insurance/* — those patients use the phone",
|
|
9
|
-
"Pre-chat form asks 'New patient or existing patient?' — feeds routing conditions",
|
|
10
|
-
"ServiceNow integration required for post-chat ticket creation (CSAT 1-2 stars)"
|
|
11
|
-
],
|
|
12
|
-
"resolve": {
|
|
13
|
-
"ai_configs": {
|
|
14
|
-
"INTAKE_BOT": "New Patient Intake Bot"
|
|
15
|
-
},
|
|
16
|
-
"teams": {
|
|
17
|
-
"INTAKE_TEAM": "Intake",
|
|
18
|
-
"PATIENT_SUPPORT_TEAM": "Patient Support",
|
|
19
|
-
"SERVICE_TEAM": "Equipment Service",
|
|
20
|
-
"GENERAL_TEAM": "General Support"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"routing_rules": [
|
|
24
|
-
{
|
|
25
|
-
"name": "New Patient — Intake Bot",
|
|
26
|
-
"trigger": "use-ai",
|
|
27
|
-
"priority": 100,
|
|
28
|
-
"expression": [[{"type": "surveyAnswer", "data": "{\"answer\":\"new\",\"comparator\":\"equals\"}"}]],
|
|
29
|
-
"value": {"aiConfig": "@INTAKE_BOT"},
|
|
30
|
-
"notes": "Condition fires when pre-chat survey answer = 'new'. Adjust surveyAnswer key to match your actual pre-chat survey field."
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"name": "Existing Patient Support",
|
|
34
|
-
"trigger": "route-to-team",
|
|
35
|
-
"priority": 200,
|
|
36
|
-
"expression": [[{"type": "surveyAnswer", "data": "{\"answer\":\"existing\",\"comparator\":\"equals\"}"}]],
|
|
37
|
-
"value": {"teamId": "@PATIENT_SUPPORT_TEAM"},
|
|
38
|
-
"notes": "Condition fires when pre-chat survey answer = 'existing'."
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"name": "Equipment Service",
|
|
42
|
-
"trigger": "route-to-team",
|
|
43
|
-
"priority": 300,
|
|
44
|
-
"expression": [[{"type": "url", "data": "{\"url\":\"/equipment\",\"comparator\":\"contains\"}"}]],
|
|
45
|
-
"value": {"teamId": "@SERVICE_TEAM"}
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"name": "Default — General Support",
|
|
49
|
-
"trigger": "route-to-team",
|
|
50
|
-
"priority": 9999,
|
|
51
|
-
"expression": [],
|
|
52
|
-
"value": {"teamId": "@GENERAL_TEAM"}
|
|
53
|
-
}
|
|
54
|
-
],
|
|
55
|
-
"workflows": [
|
|
56
|
-
{
|
|
57
|
-
"name": "Missed Chat Alert — Unresponsive Visitor (5 min)",
|
|
58
|
-
"trigger": "unresponsive_visitor",
|
|
59
|
-
"notes": "Configure email-to-supervisor action after creation. Set timeout to 5 minutes."
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"name": "CSAT Recovery — ServiceNow Ticket",
|
|
63
|
-
"trigger": "csat_submitted",
|
|
64
|
-
"notes": "Filter to 1-2 star ratings. Create ServiceNow incident. Wire ServiceNow integration credentials first."
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"name": "Widget — Hide on Insurance Portal",
|
|
68
|
-
"trigger": "widget_loaded",
|
|
69
|
-
"notes": "Add URL condition (/insurance/*) and Hide Widget action. This is the widget_loaded workflow that suppresses chat on insurance pages."
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Azenta Life Sciences",
|
|
3
|
-
"slug": "azenta",
|
|
4
|
-
"description": "Multi-department life sciences: Genewiz, Sample Management, Storage. URL-based routing, SLA alerts, LIMS post-chat push.",
|
|
5
|
-
"patterns": ["multi-department", "url-routing", "sla-alert", "post-chat-crm"],
|
|
6
|
-
"notes": [
|
|
7
|
-
"Victoria is the technical contact — she handles the API side (LIMS config)",
|
|
8
|
-
"Lisa Hague owns analytics and sentiment reporting",
|
|
9
|
-
"LIMS: clims4.genewiz.com — no public REST, needs IT credentials for integration",
|
|
10
|
-
"Phase 1: read-only LIMS lookup and how-to flows, web chat only",
|
|
11
|
-
"AI config names in this profile are suggestions — match to your actual bot names"
|
|
12
|
-
],
|
|
13
|
-
"resolve": {
|
|
14
|
-
"ai_configs": {
|
|
15
|
-
"GENEWIZ_BOT": "Genewiz Sales Bot",
|
|
16
|
-
"SAMPLE_BOT": "Sample Support Bot",
|
|
17
|
-
"TRIAGE_BOT": "AI Triage Bot"
|
|
18
|
-
},
|
|
19
|
-
"teams": {
|
|
20
|
-
"GENEWIZ_TEAM": "Genewiz Sales",
|
|
21
|
-
"SAMPLE_TEAM": "Sample Management",
|
|
22
|
-
"STORAGE_TEAM": "Storage",
|
|
23
|
-
"SKILLS_TEAM": "Skills"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"routing_rules": [
|
|
27
|
-
{
|
|
28
|
-
"name": "Genewiz Orders — AI Bot",
|
|
29
|
-
"trigger": "use-ai",
|
|
30
|
-
"priority": 100,
|
|
31
|
-
"expression": [[{"type": "url", "data": "{\"url\":\"/genewiz/\",\"comparator\":\"contains\"}"}]],
|
|
32
|
-
"value": {"aiConfig": "@GENEWIZ_BOT"}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "Sample Management — AI Bot",
|
|
36
|
-
"trigger": "use-ai",
|
|
37
|
-
"priority": 200,
|
|
38
|
-
"expression": [[{"type": "url", "data": "{\"url\":\"/samples/\",\"comparator\":\"contains\"}"}]],
|
|
39
|
-
"value": {"aiConfig": "@SAMPLE_BOT"}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"name": "Storage — Direct Team",
|
|
43
|
-
"trigger": "route-to-team",
|
|
44
|
-
"priority": 300,
|
|
45
|
-
"expression": [[{"type": "url", "data": "{\"url\":\"/storage/\",\"comparator\":\"contains\"}"}]],
|
|
46
|
-
"value": {"teamId": "@STORAGE_TEAM"}
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
"name": "Default — AI Triage",
|
|
50
|
-
"trigger": "use-ai",
|
|
51
|
-
"priority": 9999,
|
|
52
|
-
"expression": [],
|
|
53
|
-
"value": {"aiConfig": "@TRIAGE_BOT"}
|
|
54
|
-
}
|
|
55
|
-
],
|
|
56
|
-
"workflows": [
|
|
57
|
-
{
|
|
58
|
-
"name": "SLA Breach Alert — Genewiz (10 min)",
|
|
59
|
-
"trigger": "sla_breach",
|
|
60
|
-
"notes": "Configure webhook to #life-sciences-alerts Slack channel after creation"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"name": "CSAT Recovery — LIMS Push",
|
|
64
|
-
"trigger": "conversation_resolved",
|
|
65
|
-
"notes": "Post-chat CSAT + push summary to LIMS. Wire LIMS credentials in integration settings after creation."
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Bluefire Industrial Services",
|
|
3
|
-
"slug": "bluefire",
|
|
4
|
-
"description": "Front-door AI disambiguates department (Sales/Parts/Service/Billing) then routes. Single priority-100 bot handles all routing internally. Post-chat label workflow creates Salesforce tickets.",
|
|
5
|
-
"patterns": ["front-door-ai", "department-routing", "post-chat-crm"],
|
|
6
|
-
"notes": [
|
|
7
|
-
"Key difference from Azenta/Donaldson: ONE workflow at priority #100 does all routing via AI branching",
|
|
8
|
-
"The AI bot classifies intent (Sales/Parts/Service/Billing) and transfers to the right team",
|
|
9
|
-
"No URL conditions needed — front-door AI handles everything",
|
|
10
|
-
"Fallback at #9999 catches anything the AI doesn't classify",
|
|
11
|
-
"Salesforce integration required for the 'urgent' label workflow"
|
|
12
|
-
],
|
|
13
|
-
"resolve": {
|
|
14
|
-
"ai_configs": {
|
|
15
|
-
"FRONT_DOOR_BOT": "Bluefire Front Door Bot"
|
|
16
|
-
},
|
|
17
|
-
"teams": {
|
|
18
|
-
"SALES_TEAM": "Sales",
|
|
19
|
-
"PARTS_TEAM": "Parts",
|
|
20
|
-
"SERVICE_TEAM": "Service",
|
|
21
|
-
"BILLING_TEAM": "Billing",
|
|
22
|
-
"DEFAULT_TEAM": "General Support"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"routing_rules": [
|
|
26
|
-
{
|
|
27
|
-
"name": "Front Door AI — All Routing",
|
|
28
|
-
"trigger": "use-ai",
|
|
29
|
-
"priority": 100,
|
|
30
|
-
"expression": [],
|
|
31
|
-
"value": {"aiConfig": "@FRONT_DOOR_BOT"},
|
|
32
|
-
"notes": "This single rule handles all routing. Configure the AI bot with transfer actions for Sales/Parts/Service/Billing intents."
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "Default Fallback",
|
|
36
|
-
"trigger": "route-to-team",
|
|
37
|
-
"priority": 9999,
|
|
38
|
-
"expression": [],
|
|
39
|
-
"value": {"teamId": "@DEFAULT_TEAM"}
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
"workflows": [
|
|
43
|
-
{
|
|
44
|
-
"name": "Urgent Label — Salesforce Ticket",
|
|
45
|
-
"trigger": "label_applied",
|
|
46
|
-
"notes": "Filter to 'urgent' label. Create Salesforce case. Wire Salesforce integration first."
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|