@dbx-tools/ui-mastra 0.3.3 → 0.3.4

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/package.json CHANGED
@@ -26,19 +26,19 @@
26
26
  "shiki": "^3.0.0",
27
27
  "sql-formatter": "^15.6.9",
28
28
  "streamdown": "^2.5.0",
29
- "@dbx-tools/shared-genie": "0.3.3",
30
- "@dbx-tools/shared-core": "0.3.3",
31
- "@dbx-tools/shared-mastra": "0.3.3",
32
- "@dbx-tools/shared-model": "0.3.3",
33
- "@dbx-tools/ui-appkit": "0.3.3",
34
- "@dbx-tools/ui-branding": "0.3.3"
29
+ "@dbx-tools/shared-core": "0.3.4",
30
+ "@dbx-tools/shared-genie": "0.3.4",
31
+ "@dbx-tools/shared-mastra": "0.3.4",
32
+ "@dbx-tools/ui-appkit": "0.3.4",
33
+ "@dbx-tools/ui-branding": "0.3.4",
34
+ "@dbx-tools/shared-model": "0.3.4"
35
35
  },
36
36
  "main": "index.ts",
37
37
  "license": "UNLICENSED",
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "version": "0.3.3",
41
+ "version": "0.3.4",
42
42
  "types": "index.ts",
43
43
  "type": "module",
44
44
  "exports": {
@@ -1,6 +1,14 @@
1
1
  import {
2
2
  Alert,
3
3
  AlertDescription,
4
+ AlertDialog,
5
+ AlertDialogAction,
6
+ AlertDialogCancel,
7
+ AlertDialogContent,
8
+ AlertDialogDescription,
9
+ AlertDialogFooter,
10
+ AlertDialogHeader,
11
+ AlertDialogTitle,
4
12
  AlertTitle,
5
13
  Button,
6
14
  Empty,
@@ -286,18 +294,20 @@ export const ChatView = ({
286
294
  // otherwise as static text.
287
295
  const showModelDisplay = Boolean(onModelChange);
288
296
  const modelChangeable = Boolean(models && models.length > 0);
289
- // Human-readable name for an endpoint id, using the catalogue's
290
- // `displayName` when present, else the raw id.
297
+ // Human-readable name for a pinned endpoint id, using the catalogue's
298
+ // `displayName`. Returns undefined until the catalogue has an entry for it,
299
+ // so we never fall back to the raw id (no raw-name flash on load).
291
300
  const modelLabel = (name?: string): string | undefined => {
292
301
  if (!name) return undefined;
293
- return models?.find((m) => m.name === name)?.displayName || name;
302
+ return models?.find((m) => m.name === name)?.displayName;
294
303
  };
295
- // The default option shows the server's fallback model by name when known
296
- // (from `defaultModelName`), else a neutral "Default" - no "server default"
297
- // phrasing either way.
298
- const defaultOptionLabel = modelLabel(defaultModelName) ?? "Default";
299
- // Label the current model by its human-readable name when a model is
300
- // pinned, else the default-option label.
304
+ // The default option shows the server's fallback model by its already-
305
+ // humanized name (`defaultModelName` is the server's `displayName`), else a
306
+ // neutral "Default". No "server default" phrasing, no raw id.
307
+ const defaultOptionLabel = defaultModelName || "Default";
308
+ // Label the current model by its human-readable name when a model is pinned
309
+ // and the catalogue has resolved it; else the default-option label. Never
310
+ // shows a raw endpoint id.
301
311
  const currentModelLabel = modelLabel(model) || defaultOptionLabel;
302
312
  // Picker entries sorted by their human-readable label (case-insensitive).
303
313
  const sortedModels = [...(models ?? [])].sort((a, b) =>
@@ -339,29 +349,26 @@ export const ChatView = ({
339
349
  if (isMobile) setMobileDrawerOpen((open) => !open);
340
350
  else toggleDesktopSidebar();
341
351
  };
342
- // Top bar carries only the sidebar toggle + Clear now; the model picker and
343
- // export live in a toolbar row just above the composer (Janna-style), closer
344
- // to where the user is typing.
345
- const showHeader = showClear || showSidebar;
346
- const showComposerToolbar = showModelDisplay || showExport;
352
+ // Top bar carries only the sidebar toggle now; the model picker, export, and
353
+ // clear all live in a toolbar row below the composer, closer to where the
354
+ // user is typing.
355
+ const showHeader = showSidebar;
356
+ const showComposerToolbar = showModelDisplay || showExport || showClear;
347
357
 
348
- // Local "in-flight" + confirm latch for the clear button so the
349
- // user can't double-fire the DELETE and so a stray click doesn't
350
- // wipe history without a beat to back out. Resets back to idle
351
- // after the parent's `onClear` settles (success or failure).
352
- const [clearState, setClearState] = useState<"idle" | "confirm" | "clearing">("idle");
358
+ // Clear confirmation is an AppKit `AlertDialog` (a real modal), plus an
359
+ // in-flight flag so the DELETE can't be double-fired. `clearing` disables
360
+ // the confirm action while `onClear` runs; the dialog closes on settle.
361
+ const [clearOpen, setClearOpen] = useState(false);
362
+ const [clearing, setClearing] = useState(false);
353
363
 
354
- const handleClearClick = async () => {
355
- if (clearState === "clearing" || !onClear) return;
356
- if (clearState === "idle") {
357
- setClearState("confirm");
358
- return;
359
- }
360
- setClearState("clearing");
364
+ const handleClearConfirm = async () => {
365
+ if (clearing || !onClear) return;
366
+ setClearing(true);
361
367
  try {
362
368
  await onClear();
369
+ setClearOpen(false);
363
370
  } finally {
364
- setClearState("idle");
371
+ setClearing(false);
365
372
  }
366
373
  };
367
374
 
@@ -466,44 +473,6 @@ export const ChatView = ({
466
473
  </Tooltip>
467
474
  )}
468
475
  </div>
469
- <div className="flex min-w-0 items-center justify-end gap-2 md:gap-3">
470
- {showClear && (
471
- <Tooltip>
472
- <TooltipTrigger asChild>
473
- <Button
474
- type="button"
475
- variant={clearState === "confirm" ? "destructive" : "outline"}
476
- size="sm"
477
- onClick={handleClearClick}
478
- onBlur={() =>
479
- // Drop the confirm latch when focus leaves so a
480
- // half-armed button doesn't sit destructive-red
481
- // forever after the user clicks away.
482
- setClearState((s) => (s === "confirm" ? "idle" : s))
483
- }
484
- disabled={clearState === "clearing"}
485
- className="gap-1.5"
486
- >
487
- {clearState === "clearing" ? (
488
- <Spinner className="size-3" />
489
- ) : (
490
- <Trash2Icon className="size-3" />
491
- )}
492
- {clearState === "confirm"
493
- ? "Confirm clear"
494
- : clearState === "clearing"
495
- ? "Clearing..."
496
- : "Clear"}
497
- </Button>
498
- </TooltipTrigger>
499
- <TooltipContent>
500
- {clearState === "confirm"
501
- ? "Click again to confirm; wipes this conversation."
502
- : "Clear chat history for this thread"}
503
- </TooltipContent>
504
- </Tooltip>
505
- )}
506
- </div>
507
476
  </div>
508
477
  )}
509
478
  <div className="relative flex flex-1 flex-col overflow-hidden">
@@ -719,6 +688,51 @@ export const ChatView = ({
719
688
  tooltip="Export conversation"
720
689
  />
721
690
  )}
691
+ {showClear && (
692
+ <>
693
+ <Tooltip>
694
+ <TooltipTrigger asChild>
695
+ <Button
696
+ type="button"
697
+ variant="outline"
698
+ size="sm"
699
+ onClick={() => setClearOpen(true)}
700
+ className="h-7 gap-1 rounded-full px-2.5 text-xs [&_svg]:size-3"
701
+ >
702
+ <Trash2Icon className="size-3" />
703
+ Clear
704
+ </Button>
705
+ </TooltipTrigger>
706
+ <TooltipContent>Clear chat history for this thread</TooltipContent>
707
+ </Tooltip>
708
+ <AlertDialog open={clearOpen} onOpenChange={setClearOpen}>
709
+ <AlertDialogContent>
710
+ <AlertDialogHeader>
711
+ <AlertDialogTitle>Clear this conversation?</AlertDialogTitle>
712
+ <AlertDialogDescription>
713
+ This permanently deletes the chat history for this thread. This
714
+ can&apos;t be undone.
715
+ </AlertDialogDescription>
716
+ </AlertDialogHeader>
717
+ <AlertDialogFooter>
718
+ <AlertDialogCancel disabled={clearing}>Cancel</AlertDialogCancel>
719
+ <AlertDialogAction
720
+ onClick={(e) => {
721
+ // Keep the dialog open while the DELETE runs; we
722
+ // close it ourselves once `onClear` settles.
723
+ e.preventDefault();
724
+ void handleClearConfirm();
725
+ }}
726
+ disabled={clearing}
727
+ >
728
+ {clearing ? <Spinner className="size-3" /> : null}
729
+ {clearing ? "Clearing..." : "Clear"}
730
+ </AlertDialogAction>
731
+ </AlertDialogFooter>
732
+ </AlertDialogContent>
733
+ </AlertDialog>
734
+ </>
735
+ )}
722
736
  </div>
723
737
  )}
724
738
  </form>
@@ -175,12 +175,13 @@ export class MastraPluginClient extends MastraClient {
175
175
  }
176
176
 
177
177
  /**
178
- * Fetch the static default serving-endpoint id `agentId` falls back to
179
- * when no model is pinned, from `GET ${basePath}/default-model`. Returns
180
- * `null` when the agent resolves its model dynamically at call time (or the
181
- * agent id is unknown) - there's nothing static to advertise. The picker
182
- * uses this to name its "Server default" option. Defaults to the server's
183
- * default agent when `agentId` is omitted.
178
+ * Fetch the humanized name of the static default model `agentId` falls back
179
+ * to when no model is pinned, from `GET ${basePath}/default-model`. Returns
180
+ * the server-humanized `displayName` (never a raw endpoint id), or `null`
181
+ * when the agent resolves its model dynamically at call time (or the agent
182
+ * id is unknown) - there's nothing static to advertise. The picker uses this
183
+ * to label its default option on load, before the `/models` catalogue
184
+ * arrives. Defaults to the server's default agent when `agentId` is omitted.
184
185
  */
185
186
  async defaultModel(agentId?: string, signal?: AbortSignal): Promise<string | null> {
186
187
  const query = agentId ? `?agentId=${encodeURIComponent(agentId)}` : "";
@@ -189,7 +190,7 @@ export class MastraPluginClient extends MastraClient {
189
190
  wire.DefaultModelResponseSchema,
190
191
  signal,
191
192
  );
192
- return payload.model;
193
+ return payload.displayName ?? payload.model;
193
194
  }
194
195
 
195
196
  /**