@velaro/cli 1.4.176 → 1.4.177

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/api.js CHANGED
@@ -104,6 +104,26 @@ export const messagingPut = (path, body) => messagingRequest('PUT', path, bod
104
104
  export const messagingPatch = (path, body) => messagingRequest('PATCH', path, body);
105
105
  export const messagingDel = (path) => messagingRequest('DELETE', path);
106
106
 
107
+ // multipart/form-data POST (ChatWindow/Update takes [FromForm]); fetch sets the boundary header itself.
108
+ export async function messagingPostForm(path, form, envOverride) {
109
+ const creds = await getCredentials(envOverride);
110
+ const res = await fetch(joinUrl(creds.messagingApiBase, path), {
111
+ method: 'POST',
112
+ headers: {
113
+ Authorization: `Bearer ${creds.velaroToken}`,
114
+ ...(creds.siteId ? { 'vmsg-siteId': String(creds.siteId) } : {}),
115
+ },
116
+ body: form,
117
+ });
118
+ if (!res.ok) {
119
+ let msg = `POST ${path} → ${res.status}`;
120
+ try { const t = await res.text(); if (t) msg += `: ${t}`; } catch { /* status already captured */ }
121
+ throw new Error(msg);
122
+ }
123
+ const text = await res.text();
124
+ return text ? JSON.parse(text) : null;
125
+ }
126
+
107
127
  // Same as messagingRequest but returns the raw response text (for CSV downloads).
108
128
  export async function messagingRequestText(method, path, envOverride) {
109
129
  const creds = await getCredentials(envOverride);
@@ -0,0 +1,27 @@
1
+ // Per-chat-window multi-tab mode (velaro-messaging MessengerStyleConfig.MultiTabMode).
2
+ // null/absent = follow the site/platform default. ChatWindow/Update is a full replace
3
+ // (multipart name + styleConfig + languageConfig), so we read first and merge.
4
+ export const MULTI_TAB_MODES = ['active-only', 'all-live'];
5
+
6
+ /** Returns 'active-only' | 'all-live' | null (follow default). Throws on anything else. */
7
+ export function normalizeMultiTabMode(raw) {
8
+ if (raw === null || raw === undefined) return null;
9
+ const v = String(raw).trim().toLowerCase();
10
+ if (v === '' || v === 'default' || v === 'follow-default' || v === 'null') return null;
11
+ if (!MULTI_TAB_MODES.includes(v)) {
12
+ throw new Error('multiTabMode must be "active-only", "all-live" or "default" (follows the site/platform default).');
13
+ }
14
+ return v;
15
+ }
16
+
17
+ /** Fields of the update form for a chat window with only multiTabMode changed. */
18
+ export function buildMultiTabUpdateFields(current, mode) {
19
+ if (!current || typeof current !== 'object') throw new Error('chat window not found');
20
+ const styleConfig = { ...(current.styleConfig ?? {}) };
21
+ if (mode === null) delete styleConfig.multiTabMode; else styleConfig.multiTabMode = mode;
22
+ return {
23
+ name: current.name ?? '',
24
+ styleConfig: JSON.stringify(styleConfig),
25
+ languageConfig: JSON.stringify(current.languageConfig ?? {}),
26
+ };
27
+ }
@@ -0,0 +1,25 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { normalizeMultiTabMode, buildMultiTabUpdateFields } from './chat-window-style.js';
4
+
5
+ test('normalize accepts the two modes and maps default to null', () => {
6
+ assert.equal(normalizeMultiTabMode('Active-Only'), 'active-only');
7
+ assert.equal(normalizeMultiTabMode('all-live'), 'all-live');
8
+ assert.equal(normalizeMultiTabMode('default'), null);
9
+ assert.equal(normalizeMultiTabMode(''), null);
10
+ assert.equal(normalizeMultiTabMode(undefined), null);
11
+ });
12
+
13
+ test('normalize rejects unknown values', () => {
14
+ assert.throws(() => normalizeMultiTabMode('both'), /multiTabMode must be/);
15
+ });
16
+
17
+ test('update fields keep the rest of the window and only change multiTabMode', () => {
18
+ const cw = { name: 'Main', styleConfig: { launcherText: 'Help', multiTabMode: 'all-live' }, languageConfig: { greeting: 'Hi' } };
19
+ const f = buildMultiTabUpdateFields(cw, 'active-only');
20
+ assert.equal(f.name, 'Main');
21
+ assert.deepEqual(JSON.parse(f.styleConfig), { launcherText: 'Help', multiTabMode: 'active-only' });
22
+ assert.deepEqual(JSON.parse(f.languageConfig), { greeting: 'Hi' });
23
+ assert.ok(!('multiTabMode' in JSON.parse(buildMultiTabUpdateFields(cw, null).styleConfig)));
24
+ assert.equal(cw.styleConfig.multiTabMode, 'all-live');
25
+ });
@@ -2,7 +2,8 @@
2
2
  // Site isolation is enforced server-side (ClientControllerBase SiteId), never passed by the client.
3
3
  // To show different copy on different pages: create one chat window per page type, set its
4
4
  // label/greeting here, then pick it with a Select Chat Window workflow node.
5
- import { messagingGet, messagingPut } from '../api.js';
5
+ import { messagingGet, messagingPut, messagingPostForm } from '../api.js';
6
+ import { normalizeMultiTabMode, buildMultiTabUpdateFields } from '../chat-window-style.js';
6
7
  import { runCommand } from '../run.js';
7
8
 
8
9
  export const chatWindowCommand = {
@@ -42,6 +43,31 @@ export const chatWindowCommand = {
42
43
  console.log(` greeting: ${r.greeting ?? '(none)'}`);
43
44
  }),
44
45
  })
45
- .demandCommand(1, 'Specify a subcommand: list, set-copy'),
46
+ .command({
47
+ command: 'get-style <id>',
48
+ describe: 'Show a chat window style and its multi-tab mode',
49
+ builder: (y) => y.positional('id', { type: 'number', describe: 'Chat window ID' }),
50
+ handler: runCommand(async (argv) => {
51
+ const w = await messagingGet(`/ChatWindow/get/${argv.id}`);
52
+ console.log(`${w.id} ${w.name ?? '(unnamed)'}`);
53
+ console.log(` multiTabMode: ${w.styleConfig?.multiTabMode ?? '(follow site/platform default)'}`);
54
+ }),
55
+ })
56
+ .command({
57
+ command: 'set-multi-tab-mode <id> <mode>',
58
+ describe: 'How the chat behaves across several open tabs: active-only | all-live | default',
59
+ builder: (y) => y
60
+ .positional('id', { type: 'number', describe: 'Chat window ID' })
61
+ .positional('mode', { type: 'string', choices: ['active-only', 'all-live', 'default'], describe: '"default" follows the site/platform default' }),
62
+ handler: runCommand(async (argv) => {
63
+ const mode = normalizeMultiTabMode(argv.mode);
64
+ const current = await messagingGet(`/ChatWindow/get/${argv.id}`);
65
+ const form = new FormData();
66
+ for (const [k, v] of Object.entries(buildMultiTabUpdateFields(current, mode))) form.append(k, v);
67
+ const r = await messagingPostForm(`/ChatWindow/Update/${argv.id}`, form);
68
+ console.log(`Updated chat window ${r.id}. multiTabMode: ${r.styleConfig?.multiTabMode ?? '(follow default)'}`);
69
+ }),
70
+ })
71
+ .demandCommand(1, 'Specify a subcommand: list, set-copy, get-style, set-multi-tab-mode'),
46
72
  handler: () => {},
47
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.176",
3
+ "version": "1.4.177",
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": {