@arjun-shah/agentbar-cli 0.1.9 → 0.1.10

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 CHANGED
@@ -24,7 +24,13 @@ agentbar stats
24
24
  ```
25
25
 
26
26
  The CLI writes `agentbar.config.json` in your project directory. `agentbar init` only asks
27
- for your site URL.
27
+ for your site URL and syncs settings to the hosted dashboard so your embed is a single line:
28
+
29
+ ```html
30
+ <script src="https://agent-pug.vercel.app/agentbar.js" data-site-key="your-site-key"></script>
31
+ ```
32
+
33
+ Open the deployed dashboard to edit settings and copy the snippet again.
28
34
 
29
35
  ## Customization
30
36
 
package/bin/agentbar.js CHANGED
@@ -90,6 +90,26 @@ const saveConfig = (config) => {
90
90
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
91
91
  };
92
92
 
93
+ const syncConfig = async (config) => {
94
+ const apiBase = (config.apiBase || DEFAULT_CONFIG.apiBase).replace(/\/$/, "");
95
+ const siteKey = resolveSiteKey(config);
96
+ if (!siteKey) {
97
+ return;
98
+ }
99
+ try {
100
+ await fetch(`${apiBase}/api/config`, {
101
+ method: "POST",
102
+ headers: { "Content-Type": "application/json" },
103
+ body: JSON.stringify({
104
+ siteKey,
105
+ config: { ...config, siteKey },
106
+ }),
107
+ });
108
+ } catch (_error) {
109
+ console.warn("Could not sync settings to the hosted dashboard.");
110
+ }
111
+ };
112
+
93
113
  const normalizeUrl = (value) => {
94
114
  if (!value || typeof value !== "string") {
95
115
  return "";
@@ -120,196 +140,9 @@ const resolveSiteKey = (config) => {
120
140
  };
121
141
 
122
142
  const renderSnippet = (config) => {
123
- const lines = [
124
- "<script",
125
- ` src=\"${config.apiBase.replace(/\/$/, "")}/agentbar.js\"`,
126
- ` data-site=\"${config.siteUrl || "https://your-site.com"}\"`,
127
- ` data-api=\"${config.apiBase.replace(/\/$/, "")}\"`,
128
- ` data-depth=\"${config.depth}\"`,
129
- ` data-max-pages=\"${config.maxPages}\"`,
130
- ];
131
- if (config.siteKey) {
132
- lines.push(` data-site-key=\"${config.siteKey}\"`);
133
- }
134
- if (config.themeColor) {
135
- lines.push(` data-theme-color=\"${config.themeColor}\"`);
136
- }
137
- if (config.position) {
138
- lines.push(` data-position=\"${config.position}\"`);
139
- }
140
- if (config.title) {
141
- lines.push(` data-title=\"${config.title}\"`);
142
- }
143
- if (config.subtitle) {
144
- lines.push(` data-subtitle=\"${config.subtitle}\"`);
145
- }
146
- if (config.buttonLabel) {
147
- lines.push(` data-button-label=\"${config.buttonLabel}\"`);
148
- }
149
- if (config.fontFamily) {
150
- lines.push(` data-font-family=\"${config.fontFamily}\"`);
151
- }
152
- if (config.panelBackground) {
153
- lines.push(` data-panel-background=\"${config.panelBackground}\"`);
154
- }
155
- if (config.textColor) {
156
- lines.push(` data-text-color=\"${config.textColor}\"`);
157
- }
158
- if (config.mutedTextColor) {
159
- lines.push(` data-muted-text-color=\"${config.mutedTextColor}\"`);
160
- }
161
- if (config.borderColor) {
162
- lines.push(` data-border-color=\"${config.borderColor}\"`);
163
- }
164
- if (config.buttonBackground) {
165
- lines.push(` data-button-background=\"${config.buttonBackground}\"`);
166
- }
167
- if (config.buttonTextColor) {
168
- lines.push(` data-button-text-color=\"${config.buttonTextColor}\"`);
169
- }
170
- if (config.accentTextColor) {
171
- lines.push(` data-accent-text-color=\"${config.accentTextColor}\"`);
172
- }
173
- if (config.buttonShadow) {
174
- lines.push(` data-button-shadow=\"${config.buttonShadow}\"`);
175
- }
176
- if (config.panelShadow) {
177
- lines.push(` data-panel-shadow=\"${config.panelShadow}\"`);
178
- }
179
- if (config.badgeLabel) {
180
- lines.push(` data-badge-label=\"${config.badgeLabel}\"`);
181
- }
182
- if (config.badgeBackground) {
183
- lines.push(` data-badge-background=\"${config.badgeBackground}\"`);
184
- }
185
- if (config.badgeTextColor) {
186
- lines.push(` data-badge-text-color=\"${config.badgeTextColor}\"`);
187
- }
188
- if (config.userBubbleBackground) {
189
- lines.push(` data-user-bubble-background=\"${config.userBubbleBackground}\"`);
190
- }
191
- if (config.userBubbleText) {
192
- lines.push(` data-user-bubble-text=\"${config.userBubbleText}\"`);
193
- }
194
- if (config.userBubbleBorder) {
195
- lines.push(` data-user-bubble-border=\"${config.userBubbleBorder}\"`);
196
- }
197
- if (config.assistantBubbleBackground) {
198
- lines.push(` data-assistant-bubble-background=\"${config.assistantBubbleBackground}\"`);
199
- }
200
- if (config.assistantBubbleText) {
201
- lines.push(` data-assistant-bubble-text=\"${config.assistantBubbleText}\"`);
202
- }
203
- if (config.assistantBubbleBorder) {
204
- lines.push(` data-assistant-bubble-border=\"${config.assistantBubbleBorder}\"`);
205
- }
206
- if (config.panelWidth) {
207
- lines.push(` data-panel-width=\"${config.panelWidth}\"`);
208
- }
209
- if (config.panelMaxHeight) {
210
- lines.push(` data-panel-max-height=\"${config.panelMaxHeight}\"`);
211
- }
212
- if (config.panelRadius) {
213
- lines.push(` data-panel-radius=\"${config.panelRadius}\"`);
214
- }
215
- if (config.buttonRadius) {
216
- lines.push(` data-button-radius=\"${config.buttonRadius}\"`);
217
- }
218
- if (typeof config.offsetX === "number") {
219
- lines.push(` data-offset-x=\"${config.offsetX}\"`);
220
- }
221
- if (typeof config.offsetY === "number") {
222
- lines.push(` data-offset-y=\"${config.offsetY}\"`);
223
- }
224
- if (config.inputPlaceholder) {
225
- lines.push(` data-input-placeholder=\"${config.inputPlaceholder}\"`);
226
- }
227
- if (config.sendLabel) {
228
- lines.push(` data-send-label=\"${config.sendLabel}\"`);
229
- }
230
- if (config.suggestions?.length) {
231
- lines.push(` data-suggestions=\"${config.suggestions.join(" | ")}\"`);
232
- }
233
- if (config.greeting) {
234
- lines.push(` data-greeting=\"${config.greeting}\"`);
235
- }
236
- if (typeof config.draggable === "boolean") {
237
- lines.push(` data-draggable=\"${config.draggable}\"`);
238
- }
239
- if (typeof config.dragOffset === "number" && config.dragOffset !== 0) {
240
- lines.push(` data-drag-offset=\"${config.dragOffset}\"`);
241
- }
242
- if (typeof config.persistPosition === "boolean") {
243
- lines.push(` data-persist-position=\"${config.persistPosition}\"`);
244
- }
245
- if (config.positionKey) {
246
- lines.push(` data-position-key=\"${config.positionKey}\"`);
247
- }
248
- if (config.openOnLoad) {
249
- lines.push(` data-open=\"${config.openOnLoad}\"`);
250
- }
251
- if (config.showReset) {
252
- lines.push(` data-show-reset=\"${config.showReset}\"`);
253
- }
254
- if (config.persist) {
255
- lines.push(` data-persist=\"${config.persist}\"`);
256
- }
257
- if (config.storageKey) {
258
- lines.push(` data-storage-key=\"${config.storageKey}\"`);
259
- }
260
- if (typeof config.showTypingIndicator === "boolean") {
261
- lines.push(` data-show-typing-indicator=\"${config.showTypingIndicator}\"`);
262
- }
263
- if (typeof config.showExport === "boolean") {
264
- lines.push(` data-show-export=\"${config.showExport}\"`);
265
- }
266
- if (config.exportLabel) {
267
- lines.push(` data-export-label=\"${config.exportLabel}\"`);
268
- }
269
- if (typeof config.showScrollButton === "boolean") {
270
- lines.push(` data-show-scroll-button=\"${config.showScrollButton}\"`);
271
- }
272
- if (config.scrollLabel) {
273
- lines.push(` data-scroll-label=\"${config.scrollLabel}\"`);
274
- }
275
- if (typeof config.showMinimize === "boolean") {
276
- lines.push(` data-show-minimize=\"${config.showMinimize}\"`);
277
- }
278
- if (typeof config.minimizedOnLoad === "boolean") {
279
- lines.push(` data-minimized-on-load=\"${config.minimizedOnLoad}\"`);
280
- }
281
- if (config.minimizeLabel) {
282
- lines.push(` data-minimize-label=\"${config.minimizeLabel}\"`);
283
- }
284
- if (config.expandLabel) {
285
- lines.push(` data-expand-label=\"${config.expandLabel}\"`);
286
- }
287
- if (typeof config.showTimestamps === "boolean") {
288
- lines.push(` data-show-timestamps=\"${config.showTimestamps}\"`);
289
- }
290
- if (config.timestampLocale) {
291
- lines.push(` data-timestamp-locale=\"${config.timestampLocale}\"`);
292
- }
293
- if (typeof config.autoScroll === "boolean") {
294
- lines.push(` data-auto-scroll=\"${config.autoScroll}\"`);
295
- }
296
- if (typeof config.autoScrollThreshold === "number") {
297
- lines.push(` data-auto-scroll-threshold=\"${config.autoScrollThreshold}\"`);
298
- }
299
- if (config.messageMaxWidth) {
300
- lines.push(` data-message-max-width=\"${config.messageMaxWidth}\"`);
301
- }
302
- if (config.launcherTooltip) {
303
- lines.push(` data-launcher-tooltip=\"${config.launcherTooltip}\"`);
304
- }
305
- if (typeof config.autoIngest === "boolean") {
306
- lines.push(` data-auto-ingest=\"${config.autoIngest}\"`);
307
- }
308
- if (typeof config.closeOnOutsideClick === "boolean") {
309
- lines.push(` data-close-on-outside-click=\"${config.closeOnOutsideClick}\"`);
310
- }
311
- lines.push("></script>");
312
- return lines.join("\n");
143
+ const apiBase = (config.apiBase || DEFAULT_CONFIG.apiBase).replace(/\/$/, "");
144
+ const siteKey = resolveSiteKey(config) || "your-site-key";
145
+ return `<script src="${apiBase}/agentbar.js" data-site-key="${siteKey}"></script>`;
313
146
  };
314
147
 
315
148
  const printHelp = () => {
@@ -384,9 +217,11 @@ const init = async () => {
384
217
  }
385
218
 
386
219
  saveConfig(config);
220
+ await syncConfig(config);
387
221
  console.log("\nSaved config to", configPath);
388
222
  console.log("\nEmbed snippet:\n");
389
223
  console.log(renderSnippet(config));
224
+ console.log(`\nDashboard: ${(config.apiBase || DEFAULT_CONFIG.apiBase).replace(/\/$/, "")}\n`);
390
225
  };
391
226
 
392
227
  const printStats = async () => {
@@ -427,7 +262,7 @@ const printStats = async () => {
427
262
  }
428
263
  };
429
264
 
430
- const setValue = (key, value) => {
265
+ const setValue = async (key, value) => {
431
266
  if (!key || typeof value === "undefined") {
432
267
  console.error("Usage: agentbar set <key> <value>");
433
268
  process.exit(1);
@@ -484,11 +319,15 @@ const setValue = (key, value) => {
484
319
  .split(/[|,]/)
485
320
  .map((item) => item.trim())
486
321
  .filter(Boolean);
322
+ } else if (key === "siteUrl") {
323
+ config[key] = normalizeUrl(value);
324
+ config.siteKey = resolveSiteKey(config);
487
325
  } else {
488
326
  config[key] = value;
489
327
  }
490
328
 
491
329
  saveConfig(config);
330
+ await syncConfig(config);
492
331
  console.log("Updated", key, "in", configPath);
493
332
  };
494
333
 
@@ -508,7 +347,7 @@ const main = async () => {
508
347
  await printStats();
509
348
  return;
510
349
  case "set":
511
- setValue(arg1, arg2);
350
+ await setValue(arg1, arg2);
512
351
  return;
513
352
  case "config":
514
353
  console.log(JSON.stringify(loadConfig(), null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arjun-shah/agentbar-cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "Agent Plugin Bar CLI helper.",
6
6
  "bin": {