@velaro/cli 1.4.120 → 1.4.122
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/README.md +0 -19
- package/bin/velaro.js +21 -92
- package/lib/avatar-motion.test.js +1 -1
- package/lib/avatar-switch.test.js +1 -1
- package/lib/commands/agent.js +7 -58
- package/lib/commands/ai-config.js +8 -34
- package/lib/commands/index.js +18 -14
- package/lib/commands/kb.js +4 -94
- package/lib/commands/knowledge.js +2 -2
- package/lib/commands/ops-groups.js +0 -13
- package/lib/commands/safety.js +1 -1
- package/lib/commands/salesforce.js +1 -1
- package/lib/commands/sap.js +1 -1
- package/lib/commands/schedule-adherence.js +1 -1
- package/lib/commands/signature.js +39 -3
- package/lib/commands/teams.js +1 -1
- package/lib/commands/woocommerce.js +1 -1
- package/lib/commands/workflow.js +4 -31
- package/lib/signature-policy.js +42 -0
- package/lib/signature-policy.test.js +28 -2
- package/lib/staff-optional.js +10 -0
- package/package.json +2 -2
- package/lib/cobrowse-settings.js +0 -90
- package/lib/cobrowse-settings.test.js +0 -45
- package/lib/commands/activity.js +0 -147
- package/lib/commands/acuity.js +0 -66
- package/lib/commands/ai-federation.js +0 -55
- package/lib/commands/ai-models.js +0 -203
- package/lib/commands/ai-spend.js +0 -71
- package/lib/commands/avatar.js +0 -253
- package/lib/commands/bigcommerce.js +0 -50
- package/lib/commands/calendly.js +0 -62
- package/lib/commands/cobrowse.js +0 -99
- package/lib/commands/coupon-grant.js +0 -192
- package/lib/commands/diag-groups.js +0 -108
- package/lib/commands/diagnostics.js +0 -298
- package/lib/commands/email-inbox.js +0 -110
- package/lib/commands/entitlement.js +0 -375
- package/lib/commands/image-analysis.js +0 -27
- package/lib/commands/logs-insights.js +0 -342
- package/lib/commands/logs.js +0 -1248
- package/lib/commands/migrate.js +0 -379
- package/lib/commands/migration-status.js +0 -66
- package/lib/commands/ops.js +0 -266
- package/lib/commands/parity-staff-tools.js +0 -205
- package/lib/commands/pricing.js +0 -132
- package/lib/commands/report-speed.js +0 -112
- package/lib/commands/scraper.js +0 -38
- package/lib/commands/site-provision.js +0 -68
- package/lib/commands/sitesync.js +0 -158
- package/lib/commands/skill-usage.js +0 -39
- package/lib/commands/staff.js +0 -31
- package/lib/commands/status-page.js +0 -95
- package/lib/commands/status-sla.js +0 -47
- package/lib/commands/subscription.js +0 -102
- package/lib/commands/support.js +0 -309
- package/lib/commands/tour-policy.js +0 -61
- package/lib/commands/triage.js +0 -66
- package/lib/entitlement-report-packages.test.js +0 -47
- package/lib/log-search.js +0 -252
- package/lib/log-search.test.js +0 -374
- package/lib/logs-insights.test.js +0 -146
- package/lib/messaging-routes.test.js +0 -37
- package/lib/report-speed.test.js +0 -26
- package/lib/siteUser.js +0 -35
- package/lib/siteUser.test.js +0 -45
- package/lib/skill-usage.test.js +0 -36
- package/lib/status-sla.test.js +0 -23
package/lib/commands/activity.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { get, getCredentials, messagingGet } from '../api.js';
|
|
2
|
-
|
|
3
|
-
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
4
|
-
|
|
5
|
-
const RESET = '\x1b[0m';
|
|
6
|
-
const DIM = '\x1b[2m';
|
|
7
|
-
const RED = '\x1b[31m';
|
|
8
|
-
const YEL = '\x1b[33m';
|
|
9
|
-
const CYN = '\x1b[36m';
|
|
10
|
-
|
|
11
|
-
function formatEntry(item) {
|
|
12
|
-
const ts = new Date(item.createdAt).toISOString().replace('T', ' ').slice(0, 19);
|
|
13
|
-
const sev = (item.severity ?? 'Info').padEnd(8);
|
|
14
|
-
const color = item.severity === 'Error' ? RED : item.severity === 'Warning' ? YEL : RESET;
|
|
15
|
-
const cat = `${DIM}[${item.category ?? '?'}]${RESET}`;
|
|
16
|
-
const int = item.integration ? `${CYN}${item.integration}${RESET} ` : '';
|
|
17
|
-
const lines = [`${DIM}${ts}${RESET} ${color}${sev}${RESET} ${int}${cat} ${item.message ?? ''}`];
|
|
18
|
-
if (item.additionalInfo) lines.push(` ${DIM}${item.additionalInfo}${RESET}`);
|
|
19
|
-
if (item.suppressedCount > 0) lines.push(` ${DIM}(+${item.suppressedCount} suppressed)${RESET}`);
|
|
20
|
-
return lines.join('\n');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function formatAuditEntry(e) {
|
|
24
|
-
const ts = new Date(e.createdAt).toISOString().replace('T', ' ').slice(0, 19);
|
|
25
|
-
const actor = e.actorType === 'AI_Moshky'
|
|
26
|
-
? `${CYN}Moshky${RESET} (on behalf of ${e.initiatedByEmail ?? 'unknown'})`
|
|
27
|
-
: `${e.actorType === 'HumanStaff' ? YEL : RESET}${e.actorType}${RESET} ${e.actorEmail ?? ''}`.trim();
|
|
28
|
-
const lines = [`${DIM}${ts}${RESET} [${e.entityType}#${e.entityId}] ${e.action} ${DIM}by${RESET} ${actor}`];
|
|
29
|
-
if (e.oldValueJson) lines.push(` ${DIM}before:${RESET} ${e.oldValueJson}`);
|
|
30
|
-
if (e.newValueJson) lines.push(` ${DIM}after: ${RESET} ${e.newValueJson}`);
|
|
31
|
-
return lines.join('\n');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ── audit-trail handler (distinct shape/endpoint from integration activity logs) ───
|
|
35
|
-
|
|
36
|
-
async function auditTrailHandler(argv) {
|
|
37
|
-
await getCredentials();
|
|
38
|
-
|
|
39
|
-
const params = new URLSearchParams();
|
|
40
|
-
if (argv.entityType) params.set('entityType', argv.entityType);
|
|
41
|
-
if (argv.entityId) params.set('entityId', argv.entityId);
|
|
42
|
-
params.set('take', String(Math.min(500, argv.take ?? 200)));
|
|
43
|
-
|
|
44
|
-
const qs = params.toString();
|
|
45
|
-
const data = await get(`/AuditTrail${qs ? '?' + qs : ''}`);
|
|
46
|
-
|
|
47
|
-
if (!data?.entries?.length) {
|
|
48
|
-
console.log('\nNo audit trail entries.');
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log(`\n${data.entries.length} audit trail entries`);
|
|
53
|
-
if (!data.fullDetailAvailable) {
|
|
54
|
-
console.log(`${DIM}${data.complianceUpsellMessage ?? 'Upgrade to a Compliance package for full before/after detail.'}${RESET}`);
|
|
55
|
-
}
|
|
56
|
-
console.log('');
|
|
57
|
-
|
|
58
|
-
for (const e of data.entries) console.log(formatAuditEntry(e));
|
|
59
|
-
console.log('');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ── integration activity handler ────────────────────────────────────────────────
|
|
63
|
-
|
|
64
|
-
async function activityHandler(argv) {
|
|
65
|
-
await getCredentials(); // ensure logged in
|
|
66
|
-
|
|
67
|
-
if (argv.slug === 'audit-trail') return auditTrailHandler(argv);
|
|
68
|
-
|
|
69
|
-
// 'skills' is a convenience alias for AI tool logs
|
|
70
|
-
const isSkills = argv.slug === 'skills';
|
|
71
|
-
let path;
|
|
72
|
-
if (isSkills) {
|
|
73
|
-
path = '/Integration/Logs';
|
|
74
|
-
argv.category = 'AiTool';
|
|
75
|
-
} else if (argv.slug) {
|
|
76
|
-
path = `/Integration/Logs/${encodeURIComponent(argv.slug)}`;
|
|
77
|
-
} else {
|
|
78
|
-
path = '/Integration/Logs';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const params = new URLSearchParams();
|
|
82
|
-
if (argv.severity && argv.severity !== 'All') params.set('severity', argv.severity);
|
|
83
|
-
if (argv.category && argv.category !== 'All') params.set('category', argv.category);
|
|
84
|
-
if (argv.search) params.set('search', argv.search);
|
|
85
|
-
params.set('page', String(Math.max(1, argv.page ?? 1)));
|
|
86
|
-
params.set('pageSize', String(Math.min(100, argv.pageSize ?? 25)));
|
|
87
|
-
|
|
88
|
-
const qs = params.toString();
|
|
89
|
-
let data;
|
|
90
|
-
if (argv.site) {
|
|
91
|
-
// Staff: read ANOTHER site's Activity Log (customer/test site) without logging in as it.
|
|
92
|
-
const sp = new URLSearchParams();
|
|
93
|
-
if (isSkills) sp.set('slug', 'AiTool');
|
|
94
|
-
else if (argv.slug) sp.set('slug', argv.slug);
|
|
95
|
-
if (argv.severity && argv.severity !== 'All') sp.set('severity', argv.severity);
|
|
96
|
-
if (argv.search) sp.set('search', argv.search);
|
|
97
|
-
sp.set('take', String(Math.min(200, argv.pageSize ?? 25)));
|
|
98
|
-
const r = await messagingGet(`/SupportTools/sites/${argv.site}/integration-logs?${sp.toString()}`);
|
|
99
|
-
data = { items: r?.items ?? [], total: r?.count ?? 0 };
|
|
100
|
-
} else {
|
|
101
|
-
data = await get(`${path}${qs ? '?' + qs : ''}`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!data?.items?.length) {
|
|
105
|
-
console.log('\nNo activity log entries.');
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const label = isSkills ? 'AI skill calls' : argv.slug ? `${argv.slug} activity` : 'integration activity';
|
|
110
|
-
console.log(`\n${data.items.length} of ${data.total} ${label} entries\n`);
|
|
111
|
-
|
|
112
|
-
for (const item of data.items) console.log(formatEntry(item));
|
|
113
|
-
|
|
114
|
-
if (data.total > data.page * data.pageSize) {
|
|
115
|
-
console.log(`\n${DIM}More results — use --page ${data.page + 1}${RESET}`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
console.log('');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ── command export ────────────────────────────────────────────────────────────
|
|
122
|
-
|
|
123
|
-
export const activityCommand = {
|
|
124
|
-
command: 'activity [slug]',
|
|
125
|
-
describe: 'View integration activity logs, or "audit-trail" for who-changed-what settings history',
|
|
126
|
-
builder: y => y
|
|
127
|
-
.positional('slug', {
|
|
128
|
-
describe: 'Integration name (HubSpot, Square…), "skills" for AI tool logs, or "audit-trail" for settings change history',
|
|
129
|
-
type: 'string',
|
|
130
|
-
})
|
|
131
|
-
.option('severity', {
|
|
132
|
-
describe: 'Info, Warning, Error',
|
|
133
|
-
type: 'string',
|
|
134
|
-
})
|
|
135
|
-
.option('category', {
|
|
136
|
-
describe: 'Auth, Config, Request, Response, AiTool, Setup, Error',
|
|
137
|
-
type: 'string',
|
|
138
|
-
})
|
|
139
|
-
.option('search', { describe: 'Message search', type: 'string' })
|
|
140
|
-
.option('site', { describe: "Staff only: read this site's Activity Log instead of your own", type: 'number' })
|
|
141
|
-
.option('page', { describe: 'Page number', default: 1, type: 'number' })
|
|
142
|
-
.option('pageSize', { describe: 'Results per page', default: 25, type: 'number' })
|
|
143
|
-
.option('entityType', { describe: '[audit-trail] Filter to one entity type, e.g. Workflow', type: 'string' })
|
|
144
|
-
.option('entityId', { describe: '[audit-trail] Filter to one specific entity', type: 'string' })
|
|
145
|
-
.option('take', { describe: '[audit-trail] Max results (default 200, max 500)', type: 'number' }),
|
|
146
|
-
handler: activityHandler,
|
|
147
|
-
};
|
package/lib/commands/acuity.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { request } from '../api.js';
|
|
2
|
-
import { runCommand } from '../run.js';
|
|
3
|
-
|
|
4
|
-
// ── velaro acuity ─────────────────────────────────────────────────────────────
|
|
5
|
-
// Superadmin commands to configure Acuity Scheduling for any customer site.
|
|
6
|
-
// Requires a Velaro admin JWT (site 1032).
|
|
7
|
-
|
|
8
|
-
export const acuityCommand = {
|
|
9
|
-
command: 'acuity <subcommand>',
|
|
10
|
-
describe: 'Manage Acuity Scheduling integration for any site (Velaro admin only)',
|
|
11
|
-
builder: yargs => yargs
|
|
12
|
-
.command({
|
|
13
|
-
command: 'status',
|
|
14
|
-
describe: 'Show Acuity config for a site',
|
|
15
|
-
builder: y => y.option('site', { type: 'number', demandOption: true, describe: 'Site ID' }),
|
|
16
|
-
handler: runCommand(async argv => {
|
|
17
|
-
const data = await request('GET', `/Acuity/superadmin/status?siteId=${argv.site}`);
|
|
18
|
-
if (!data.configured) {
|
|
19
|
-
console.log(`\nSite ${argv.site}: Acuity NOT configured.\n`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
console.log(`\nSite ${argv.site}: Acuity configured ✓`);
|
|
23
|
-
console.log(` Account: ${data.accountName}`);
|
|
24
|
-
console.log(` Display name: ${data.displayName || '(none)'}`);
|
|
25
|
-
console.log(` Default type: ${data.defaultAppointmentTypeName || '(none)'}`);
|
|
26
|
-
console.log(` Timezone: ${data.timezone || '(none)'}\n`);
|
|
27
|
-
}),
|
|
28
|
-
})
|
|
29
|
-
.command({
|
|
30
|
-
command: 'configure',
|
|
31
|
-
describe: 'Set up or update Acuity for a site',
|
|
32
|
-
builder: y => y
|
|
33
|
-
.option('site', { type: 'number', demandOption: true, describe: 'Site ID' })
|
|
34
|
-
.option('user-id', { type: 'string', demandOption: true, describe: 'Acuity user ID' })
|
|
35
|
-
.option('api-key', { type: 'string', demandOption: true, describe: 'Acuity API key' })
|
|
36
|
-
.option('label', { type: 'string', demandOption: false, describe: 'Display name' })
|
|
37
|
-
.option('type-id', { type: 'number', demandOption: false, describe: 'Default appointment type ID' })
|
|
38
|
-
.option('type-name', { type: 'string', demandOption: false, describe: 'Default appointment type name' })
|
|
39
|
-
.option('calendar-id', { type: 'number', demandOption: false, describe: 'Default calendar ID' })
|
|
40
|
-
.option('timezone', { type: 'string', default: 'America/New_York', describe: 'IANA timezone' }),
|
|
41
|
-
handler: runCommand(async argv => {
|
|
42
|
-
const data = await request('POST', `/Acuity/superadmin/config?siteId=${argv.site}`, {
|
|
43
|
-
userId: argv['user-id'],
|
|
44
|
-
apiKey: argv['api-key'],
|
|
45
|
-
displayName: argv.label || '',
|
|
46
|
-
defaultAppointmentTypeId: argv['type-id'] || null,
|
|
47
|
-
defaultAppointmentTypeName: argv['type-name'] || '',
|
|
48
|
-
defaultCalendarId: argv['calendar-id'] || null,
|
|
49
|
-
timezone: argv.timezone,
|
|
50
|
-
});
|
|
51
|
-
if (!data.success) throw new Error(data.error || 'Configure failed');
|
|
52
|
-
console.log(`\n✓ Acuity configured for site ${argv.site}`);
|
|
53
|
-
console.log(` Account: ${data.accountName}\n`);
|
|
54
|
-
}),
|
|
55
|
-
})
|
|
56
|
-
.command({
|
|
57
|
-
command: 'disconnect',
|
|
58
|
-
describe: 'Remove Acuity config from a site',
|
|
59
|
-
builder: y => y.option('site', { type: 'number', demandOption: true, describe: 'Site ID' }),
|
|
60
|
-
handler: runCommand(async argv => {
|
|
61
|
-
await request('DELETE', `/Acuity/superadmin/config?siteId=${argv.site}`);
|
|
62
|
-
console.log(`\n✓ Acuity disconnected from site ${argv.site}\n`);
|
|
63
|
-
}),
|
|
64
|
-
})
|
|
65
|
-
.demandCommand(1, 'Specify a subcommand: status | configure | disconnect'),
|
|
66
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { get, post } from '../api.js';
|
|
2
|
-
|
|
3
|
-
function fmtPT(ts) {
|
|
4
|
-
if (!ts) return '-';
|
|
5
|
-
return new Date(ts).toLocaleString('en-US', { timeZone: 'America/Los_Angeles', dateStyle: 'short', timeStyle: 'short' }) + ' PT';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function printStatus(s) {
|
|
9
|
-
console.log(`Anthropic federation: ${s.enabled ? 'ENABLED' : 'disabled'}${s.enabled && !s.configured ? ' (NOT fully configured)' : ''}`);
|
|
10
|
-
console.log(` breaker: ${s.breakerState}${s.breakerOpenUntil ? ' until ' + fmtPT(s.breakerOpenUntil) : ''}`);
|
|
11
|
-
console.log(` last success: ${fmtPT(s.lastSuccessUtc)}`);
|
|
12
|
-
console.log(` last failure: ${fmtPT(s.lastFailureUtc)}${s.lastFailureReason ? ' ' + s.lastFailureReason : ''}`);
|
|
13
|
-
console.log(` calls: federated ${s.federatedCalls}, api-key fallback ${s.fallbackCalls}, breaker opens ${s.breakerOpens}`);
|
|
14
|
-
console.log(` token expires: ${fmtPT(s.tokenExpiresUtc)}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const statusCommand = {
|
|
18
|
-
command: 'status',
|
|
19
|
-
describe: 'Anthropic federation state: enabled, breaker, last success/failure, federated vs fallback counts (superadmin only)',
|
|
20
|
-
builder: (y) => y.option('json', { type: 'boolean', default: false }),
|
|
21
|
-
handler: async (argv) => {
|
|
22
|
-
const s = await get('AiFederation/status');
|
|
23
|
-
if (argv.json) { console.log(JSON.stringify(s, null, 2)); return; }
|
|
24
|
-
printStatus(s);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const testCommand = {
|
|
29
|
-
command: 'test',
|
|
30
|
-
describe: 'Real token exchange plus a 1-token Haiku message; reports which auth path served it',
|
|
31
|
-
builder: (y) => y.option('json', { type: 'boolean', default: false }),
|
|
32
|
-
handler: async (argv) => {
|
|
33
|
-
const r = await post('AiFederation/test', {});
|
|
34
|
-
if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
35
|
-
console.log(`exchange: ${r.exchangeOk ? 'OK' : 'FAILED ' + (r.exchangeError ?? '')}`);
|
|
36
|
-
console.log(`message: HTTP ${r.messageStatus ?? '-'}${r.messageError ? ' ' + r.messageError : ''}`);
|
|
37
|
-
console.log(`path used: ${r.pathUsed ?? 'unknown'}`);
|
|
38
|
-
printStatus(r.status);
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const resetCommand = {
|
|
43
|
-
command: 'reset-breaker',
|
|
44
|
-
describe: 'Close the federation circuit breaker so the next call retries federated auth',
|
|
45
|
-
builder: (y) => y,
|
|
46
|
-
handler: async () => { printStatus(await post('AiFederation/reset-breaker', {})); },
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const aiFederationCommand = {
|
|
50
|
-
command: 'ai-federation <subcommand>',
|
|
51
|
-
describe: 'Anthropic Workload Identity Federation status, test and breaker reset (superadmin only)',
|
|
52
|
-
builder: (y) => y.command(statusCommand).command(testCommand).command(resetCommand)
|
|
53
|
-
.demandCommand(1, 'Specify a subcommand: status, test, reset-breaker').strict(),
|
|
54
|
-
handler: () => {},
|
|
55
|
-
};
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { getCredentials } from '../api.js';
|
|
2
|
-
import { readConfig, ENVS } from '../config.js';
|
|
3
|
-
|
|
4
|
-
// -- helpers -------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
const RESET = '\x1b[0m';
|
|
7
|
-
const DIM = '\x1b[2m';
|
|
8
|
-
const BOLD = '\x1b[1m';
|
|
9
|
-
const GREEN = '\x1b[32m';
|
|
10
|
-
const YEL = '\x1b[33m';
|
|
11
|
-
const CYN = '\x1b[36m';
|
|
12
|
-
|
|
13
|
-
async function getMsgBase(argv) {
|
|
14
|
-
const cfg = readConfig();
|
|
15
|
-
const env = argv.env || cfg.env || 'staging';
|
|
16
|
-
return cfg.envs?.[env]?.messagingApiBase ?? ENVS[env]?.messagingApiBase
|
|
17
|
-
?? 'https://velaro-messaging-api-staging.azurewebsites.net';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function requireAdmin(creds) {
|
|
21
|
-
if (creds.siteId !== 1032) {
|
|
22
|
-
console.error('velaro ai-models is only available to Velaro staff (site 1032).');
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function callResolver(argv, path, opts = {}) {
|
|
28
|
-
const creds = await getCredentials();
|
|
29
|
-
await requireAdmin(creds);
|
|
30
|
-
const msgBase = await getMsgBase(argv);
|
|
31
|
-
|
|
32
|
-
const res = await fetch(`${msgBase}/superadmin/ai-models/${path}`, {
|
|
33
|
-
method: opts.method ?? 'GET',
|
|
34
|
-
headers: {
|
|
35
|
-
Authorization: `Bearer ${creds.velaroToken}`,
|
|
36
|
-
'X-Internal-SiteId': String(creds.siteId),
|
|
37
|
-
...(opts.body ? { 'Content-Type': 'application/json' } : {}),
|
|
38
|
-
},
|
|
39
|
-
body: opts.body ? JSON.stringify(opts.body) : undefined,
|
|
40
|
-
signal: AbortSignal.timeout(20000),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (!res.ok) {
|
|
44
|
-
const body = await res.text().catch(() => '');
|
|
45
|
-
console.error(`HTTP ${res.status}: ${body}`);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
return res.json();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// -- resolver-map (the full "what is everything actually using" dashboard) ----
|
|
52
|
-
|
|
53
|
-
async function showResolverMap(argv) {
|
|
54
|
-
const data = await callResolver(argv, 'resolver-map');
|
|
55
|
-
const roles = argv.role
|
|
56
|
-
? data.roles.filter(r => r.role === argv.role)
|
|
57
|
-
: data.roles;
|
|
58
|
-
|
|
59
|
-
if (argv.role && !roles.length) {
|
|
60
|
-
console.error(`Unknown role '${argv.role}'. Known roles: ${data.roles.map(r => r.role).join(', ')}`);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log(`\n${BOLD}AI Model Resolver, ${argv.role ? `role: ${argv.role}` : 'all roles'}${RESET}\n`);
|
|
65
|
-
for (const r of roles) {
|
|
66
|
-
console.log(`${CYN}${r.role}${RESET} ${DIM}(code default: ${r.codeDefault})${RESET}`);
|
|
67
|
-
console.log(` global: ${r.globalDefault ?? `${DIM}(none, falls back to code default)${RESET}`}`);
|
|
68
|
-
const activeTiers = r.tierDefaults.filter(t => t.model);
|
|
69
|
-
if (activeTiers.length) {
|
|
70
|
-
for (const t of activeTiers) console.log(` tier: ${t.tier.padEnd(12)} -> ${t.model}`);
|
|
71
|
-
}
|
|
72
|
-
if (r.siteOverrideCount > 0) {
|
|
73
|
-
console.log(` ${YEL}site overrides (${r.siteOverrideCount}):${RESET}`);
|
|
74
|
-
for (const o of r.siteOverrides) console.log(` site ${o.siteId}: ${o.model} ${DIM}(${o.updatedBy}, ${o.updatedAt})${RESET}`);
|
|
75
|
-
}
|
|
76
|
-
console.log('');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (data.unrecognizedTierRows?.length) {
|
|
80
|
-
console.log(`${YEL}WARNING: unrecognized tier rows (legacy format, should self-migrate on next deploy):${RESET}`);
|
|
81
|
-
for (const row of data.unrecognizedTierRows) console.log(` ${row.key} = ${row.value}`);
|
|
82
|
-
console.log('');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// -- effective (what a specific site actually resolves to, per role) ----------
|
|
87
|
-
|
|
88
|
-
async function showEffective(argv) {
|
|
89
|
-
if (!argv.site) {
|
|
90
|
-
console.error('--site is required, e.g. velaro ai-models effective --site 1032');
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
const data = await callResolver(argv, `site/${argv.site}/effective`);
|
|
94
|
-
console.log(`\n${BOLD}Effective models, site ${argv.site}${RESET}\n`);
|
|
95
|
-
for (const r of data) {
|
|
96
|
-
const marker = r.isOverridden ? `${GREEN}[override]${RESET}` : `${DIM}[default] ${RESET}`;
|
|
97
|
-
console.log(`${marker} ${r.role.padEnd(28)} ${r.model}${r.isOverridden ? `${DIM} (code default: ${r.codeDefault})${RESET}` : ''}`);
|
|
98
|
-
}
|
|
99
|
-
console.log(`\n${DIM}[override] = overridden from code default [default] = using code default${RESET}\n`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// -- set / clear a role-scoped tier default ------------------------------------
|
|
103
|
-
|
|
104
|
-
async function setTierDefault(argv) {
|
|
105
|
-
const data = await callResolver(argv, `tier/${argv.tier}/${argv.role}`, {
|
|
106
|
-
method: 'POST',
|
|
107
|
-
body: { model: argv.model, updatedBy: 'velaro-cli' },
|
|
108
|
-
});
|
|
109
|
-
console.log(`\n${GREEN}OK${RESET} Tier '${data.tier}' role '${data.role}' set to ${data.model}\n`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function clearTierDefault(argv) {
|
|
113
|
-
await callResolver(argv, `tier/${argv.tier}/${argv.role}`, { method: 'DELETE' });
|
|
114
|
-
console.log(`\n${GREEN}OK${RESET} Cleared tier '${argv.tier}' role '${argv.role}'. Reverts to global default.\n`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// -- per-site thinking + version pin -------------------------------------------
|
|
118
|
-
|
|
119
|
-
async function setSiteThinking(argv) {
|
|
120
|
-
const data = await callResolver(argv, `site/${argv.site}/thinking`, {
|
|
121
|
-
method: 'POST',
|
|
122
|
-
body: { effort: argv.effort, ...(argv.role ? { role: argv.role } : {}) },
|
|
123
|
-
});
|
|
124
|
-
console.log(`
|
|
125
|
-
${GREEN}OK${RESET} Site ${data.siteId}: ${data.key} = ${data.effort}`);
|
|
126
|
-
console.log(`${DIM}Thinking bills as output tokens; only active if the site holds EnableAiThinking.${RESET}
|
|
127
|
-
`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async function setSitePin(argv) {
|
|
131
|
-
const data = await callResolver(argv, `site/${argv.site}`, {
|
|
132
|
-
method: 'POST',
|
|
133
|
-
body: { role: argv.role, model: argv.model, pinVersion: argv.pin === true, updatedBy: 'velaro-cli' },
|
|
134
|
-
});
|
|
135
|
-
console.log(`
|
|
136
|
-
${GREEN}OK${RESET} Site ${data.siteId} role '${data.role}' -> ${data.model} (pinVersion=${data.pinVersion})
|
|
137
|
-
`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// -- command export -------------------------------------------------------------
|
|
141
|
-
|
|
142
|
-
export const aiModelsCommand = {
|
|
143
|
-
command: 'ai-models <subcommand>',
|
|
144
|
-
describe: 'AI model resolver diagnostics (Velaro staff only)',
|
|
145
|
-
builder: yargs => yargs
|
|
146
|
-
.command({
|
|
147
|
-
command: 'resolver [role]',
|
|
148
|
-
describe: 'Show the full resolver map: code default, global default, tier defaults, and every site override, per role',
|
|
149
|
-
builder: y => y
|
|
150
|
-
.positional('role', { describe: 'Show only this role (e.g. ivr, chatbot, skill_synthesis)', type: 'string' })
|
|
151
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
152
|
-
handler: showResolverMap,
|
|
153
|
-
})
|
|
154
|
-
.command({
|
|
155
|
-
command: 'effective',
|
|
156
|
-
describe: 'Show what a specific site actually resolves to for every role',
|
|
157
|
-
builder: y => y
|
|
158
|
-
.option('site', { describe: 'Site ID', type: 'number', demandOption: true })
|
|
159
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
160
|
-
handler: showEffective,
|
|
161
|
-
})
|
|
162
|
-
.command({
|
|
163
|
-
command: 'set-tier <tier> <role> <model>',
|
|
164
|
-
describe: 'Set a role-scoped tier default, e.g. velaro ai-models set-tier enterprise ivr claude-sonnet-4-6',
|
|
165
|
-
builder: y => y
|
|
166
|
-
.positional('tier', { describe: 'starter, professional, or enterprise', type: 'string' })
|
|
167
|
-
.positional('role', { describe: 'e.g. ivr, chatbot, skill_synthesis', type: 'string' })
|
|
168
|
-
.positional('model', { describe: 'Model alias/ID', type: 'string' })
|
|
169
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
170
|
-
handler: setTierDefault,
|
|
171
|
-
})
|
|
172
|
-
.command({
|
|
173
|
-
command: 'clear-tier <tier> <role>',
|
|
174
|
-
describe: 'Clear a role-scoped tier default, reverting to the global default',
|
|
175
|
-
builder: y => y
|
|
176
|
-
.positional('tier', { describe: 'starter, professional, or enterprise', type: 'string' })
|
|
177
|
-
.positional('role', { describe: 'e.g. ivr, chatbot, skill_synthesis', type: 'string' })
|
|
178
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
179
|
-
handler: clearTierDefault,
|
|
180
|
-
})
|
|
181
|
-
.command({
|
|
182
|
-
command: 'set-thinking',
|
|
183
|
-
describe: 'Set the extended-thinking level for a site (off default; needs EnableAiThinking entitlement)',
|
|
184
|
-
builder: y => y
|
|
185
|
-
.option('site', { describe: 'Site ID', type: 'number', demandOption: true })
|
|
186
|
-
.option('effort', { describe: 'off, low, medium, or high', type: 'string', choices: ['off', 'low', 'medium', 'high'], demandOption: true })
|
|
187
|
-
.option('role', { describe: 'Scope to one role (omit for site-wide)', type: 'string' })
|
|
188
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
189
|
-
handler: setSiteThinking,
|
|
190
|
-
})
|
|
191
|
-
.command({
|
|
192
|
-
command: 'set-site-model',
|
|
193
|
-
describe: 'Set a site role override, optionally pinned to its exact version (--pin), e.g. velaro ai-models set-site-model --site 1032 --role chatbot --model claude-opus-5 --pin',
|
|
194
|
-
builder: y => y
|
|
195
|
-
.option('site', { describe: 'Site ID', type: 'number', demandOption: true })
|
|
196
|
-
.option('role', { describe: 'e.g. chatbot, ivr, skill_synthesis', type: 'string', demandOption: true })
|
|
197
|
-
.option('model', { describe: 'Model alias/ID', type: 'string', demandOption: true })
|
|
198
|
-
.option('pin', { describe: 'Keep this exact model, do not auto-upgrade', type: 'boolean', default: false })
|
|
199
|
-
.option('env', { describe: 'staging or prod', type: 'string' }),
|
|
200
|
-
handler: setSitePin,
|
|
201
|
-
})
|
|
202
|
-
.demandCommand(1, 'Specify a subcommand: resolver, effective, set-tier, clear-tier, set-thinking, or set-site-model'),
|
|
203
|
-
};
|
package/lib/commands/ai-spend.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { get, post } from '../api.js';
|
|
2
|
-
|
|
3
|
-
const usd = (n) => `$${Number(n ?? 0).toFixed(2)}`;
|
|
4
|
-
|
|
5
|
-
function fmtPT(ts) {
|
|
6
|
-
if (!ts) return '-';
|
|
7
|
-
return new Date(ts).toLocaleString('en-US', { timeZone: 'America/Los_Angeles', dateStyle: 'short', timeStyle: 'short' }) + ' PT';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const reportCommand = {
|
|
11
|
-
command: 'report',
|
|
12
|
-
describe: 'AI spend by environment (prod/staging), site, model and key source (superadmin only)',
|
|
13
|
-
builder: (y) => y
|
|
14
|
-
.option('env', { type: 'string', default: 'both', choices: ['both', 'prod', 'staging'] })
|
|
15
|
-
.option('days', { type: 'number', default: 7 })
|
|
16
|
-
.option('json', { type: 'boolean', default: false }),
|
|
17
|
-
handler: async (argv) => {
|
|
18
|
-
const to = new Date();
|
|
19
|
-
const from = new Date(to.getTime() - argv.days * 86400000);
|
|
20
|
-
const r = await get(`SuperAdmin/AiSpend/Report?env=${argv.env}&from=${encodeURIComponent(from.toISOString())}&to=${encodeURIComponent(to.toISOString())}`);
|
|
21
|
-
if (argv.json) { console.log(JSON.stringify(r, null, 2)); return; }
|
|
22
|
-
console.log(`AI spend ${fmtPT(r.from)} to ${fmtPT(r.to)} (breaker trips: not available)`);
|
|
23
|
-
for (const e of r.environments ?? []) {
|
|
24
|
-
if (!e.available) { console.log(`\n[${e.environment}] unavailable: ${e.error}`); continue; }
|
|
25
|
-
const c = e.current;
|
|
26
|
-
console.log(`\n[${e.environment}] ${usd(c.totalEstimatedCostUsd)} / ${c.totalCalls} calls (prev ${usd(e.previous?.totalEstimatedCostUsd)}), cache read ${(e.cacheReadRatio * 100).toFixed(1)}%, QA ${e.qaSharePercent}%`);
|
|
27
|
-
(c.bySite ?? []).slice(0, 10).forEach(s => console.log(` site ${s.siteId}: ${usd(s.estimatedCostUsd)} (${s.calls} calls)`));
|
|
28
|
-
(e.anomalies ?? []).forEach(a => console.log(` ANOMALY site ${a.siteId}: ${a.kind} ${a.detail}`));
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const reconcileCommand = {
|
|
34
|
-
command: 'reconcile',
|
|
35
|
-
describe: 'Record a provider console total and compare to logged spend',
|
|
36
|
-
builder: (y) => y
|
|
37
|
-
.option('env', { type: 'string', default: 'prod', choices: ['both', 'prod', 'staging'] })
|
|
38
|
-
.option('days', { type: 'number', default: 7 })
|
|
39
|
-
.option('provider', { type: 'string', default: 'Anthropic' })
|
|
40
|
-
.option('key', { type: 'string', describe: 'key bucket: platform, copilot, byok (omit for provider total)' })
|
|
41
|
-
.option('entered', { type: 'number', demandOption: true, describe: 'console total in USD' })
|
|
42
|
-
.option('threshold', { type: 'number', default: 25 })
|
|
43
|
-
.option('notes', { type: 'string' }),
|
|
44
|
-
handler: async (argv) => {
|
|
45
|
-
const to = new Date();
|
|
46
|
-
const from = new Date(to.getTime() - argv.days * 86400000);
|
|
47
|
-
const r = await post('SuperAdmin/AiSpend/Reconciliations', {
|
|
48
|
-
periodStartUtc: from.toISOString(), periodEndUtc: to.toISOString(), environment: argv.env,
|
|
49
|
-
provider: argv.provider, keyLabel: argv.key ?? null, enteredUsd: argv.entered, thresholdUsd: argv.threshold, notes: argv.notes ?? null,
|
|
50
|
-
});
|
|
51
|
-
console.log(`logged ${usd(r.loggedUsd)} vs console ${usd(r.enteredUsd)}: gap ${usd(r.gapUsd)} (${r.gapPercent ?? 'n/a'}%)${r.unloggedSpendFlagged ? ' FLAG: unlogged spend' : ''}`);
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const historyCommand = {
|
|
56
|
-
command: 'history',
|
|
57
|
-
describe: 'List saved reconciliations',
|
|
58
|
-
builder: (y) => y,
|
|
59
|
-
handler: async () => {
|
|
60
|
-
const rows = await get('SuperAdmin/AiSpend/Reconciliations?take=50');
|
|
61
|
-
for (const r of rows) console.log(`${fmtPT(r.createdUtc)} ${r.environment} ${r.provider}${r.keyLabel ? '/' + r.keyLabel : ''} logged ${usd(r.loggedUsd)} console ${usd(r.enteredUsd)} gap ${usd(r.gapUsd)}${r.unloggedSpendFlagged ? ' FLAG' : ''}`);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const aiSpendCommand = {
|
|
66
|
-
command: 'ai-spend <subcommand>',
|
|
67
|
-
describe: 'AI spend report and provider reconciliation (superadmin only)',
|
|
68
|
-
builder: (y) => y.command(reportCommand).command(reconcileCommand).command(historyCommand)
|
|
69
|
-
.demandCommand(1, 'Specify a subcommand: report, reconcile, history').strict(),
|
|
70
|
-
handler: () => {},
|
|
71
|
-
};
|