@tangle-network/agent-app 0.53.4 → 0.53.5

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.
Files changed (34) hide show
  1. package/dist/assistant/index.js +7 -6
  2. package/dist/assistant/index.js.map +1 -1
  3. package/dist/chat-react/index.js +3 -3
  4. package/dist/chunk-2WELYICW.js +78 -0
  5. package/dist/chunk-2WELYICW.js.map +1 -0
  6. package/dist/{chunk-6FYFGQ6I.js → chunk-AUA75YFF.js} +2 -2
  7. package/dist/{chunk-7HMDNSIA.js → chunk-JZ64GXYP.js} +4 -4
  8. package/dist/{chunk-IYK5BRL4.js → chunk-LVSKKDX2.js} +7 -4
  9. package/dist/chunk-LVSKKDX2.js.map +1 -0
  10. package/dist/{chunk-ODP3X4BN.js → chunk-QHLQPK2H.js} +11 -5
  11. package/dist/chunk-QHLQPK2H.js.map +1 -0
  12. package/dist/{chunk-NH32EPWU.js → chunk-WZ2FER6A.js} +15 -72
  13. package/dist/chunk-WZ2FER6A.js.map +1 -0
  14. package/dist/{chunk-BINC6OWR.js → chunk-ZFFBT5BF.js} +2 -2
  15. package/dist/{mention-editor-E6J2RUG4.js → mention-editor-4EWHJ5G5.js} +2 -2
  16. package/dist/studio-react/index.js +3 -2
  17. package/dist/studio-react/index.js.map +1 -1
  18. package/dist/web-react/action-dialog.d.ts +15 -0
  19. package/dist/web-react/controls.d.ts +6 -1
  20. package/dist/web-react/index.js +9 -6
  21. package/dist/web-react/workspace-switcher.d.ts +9 -0
  22. package/dist/workspace-react/index.d.ts +13 -1
  23. package/dist/workspace-react/index.js +589 -20
  24. package/dist/workspace-react/index.js.map +1 -1
  25. package/dist/workspace-react/rail-identity.d.ts +55 -0
  26. package/dist/workspace-react/workspace-list.d.ts +82 -0
  27. package/package.json +1 -1
  28. package/dist/chunk-IYK5BRL4.js.map +0 -1
  29. package/dist/chunk-NH32EPWU.js.map +0 -1
  30. package/dist/chunk-ODP3X4BN.js.map +0 -1
  31. /package/dist/{chunk-6FYFGQ6I.js.map → chunk-AUA75YFF.js.map} +0 -0
  32. /package/dist/{chunk-7HMDNSIA.js.map → chunk-JZ64GXYP.js.map} +0 -0
  33. /package/dist/{chunk-BINC6OWR.js.map → chunk-ZFFBT5BF.js.map} +0 -0
  34. /package/dist/{mention-editor-E6J2RUG4.js.map → mention-editor-4EWHJ5G5.js.map} +0 -0
@@ -1,8 +1,20 @@
1
1
  import {
2
+ WorkspaceInitial,
2
3
  WorkspaceSwitcher
3
- } from "../chunk-ODP3X4BN.js";
4
- import "../chunk-6FYFGQ6I.js";
5
- import "../chunk-IYK5BRL4.js";
4
+ } from "../chunk-QHLQPK2H.js";
5
+ import {
6
+ ActionDialog,
7
+ ActionDialogButton
8
+ } from "../chunk-2WELYICW.js";
9
+ import {
10
+ usePopoverDialog
11
+ } from "../chunk-AUA75YFF.js";
12
+ import {
13
+ CheckGlyph,
14
+ OVERLAY_SHADOW,
15
+ PopoverSurface,
16
+ usePopover
17
+ } from "../chunk-LVSKKDX2.js";
6
18
  import {
7
19
  buildSessionNavItem,
8
20
  composeSidebarSessions,
@@ -14,12 +26,170 @@ import "../chunk-7YA4QNTU.js";
14
26
  // src/workspace-react/index.tsx
15
27
  import { SidebarLayout } from "@tangle-network/sandbox-ui/dashboard";
16
28
 
29
+ // src/workspace-react/rail-identity.tsx
30
+ import { useCallback, useState } from "react";
31
+ import { jsx, jsxs } from "react/jsx-runtime";
32
+ var DEFAULT_WORKSPACE_NOUN = { singular: "workspace", plural: "workspaces" };
33
+ var SEARCH_THRESHOLD = 7;
34
+ var HIDE_ON_RAIL = { md: "md:hidden", lg: "lg:hidden" };
35
+ function capitalize(text) {
36
+ return text.charAt(0).toLocaleUpperCase() + text.slice(1);
37
+ }
38
+ function DefaultLink({ href, to, ...props }) {
39
+ return /* @__PURE__ */ jsx("a", { href: href ?? to, ...props });
40
+ }
41
+ function AgentRailIdentity({ product, workspace, hideBelow = "lg", LinkComponent }) {
42
+ const Link = LinkComponent ?? DefaultLink;
43
+ const mobileMark = /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: `flex h-7 w-7 shrink-0 items-center justify-center ${HIDE_ON_RAIL[hideBelow]}`, children: product.mark });
44
+ if (!workspace) {
45
+ return /* @__PURE__ */ jsxs(
46
+ Link,
47
+ {
48
+ href: product.href,
49
+ to: product.href,
50
+ title: product.name,
51
+ className: "flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 transition-colors hover:bg-accent",
52
+ children: [
53
+ mobileMark,
54
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-sm font-semibold text-foreground", children: product.name })
55
+ ]
56
+ }
57
+ );
58
+ }
59
+ const stack = /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 text-left", children: [
60
+ /* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-semibold leading-5 text-foreground", children: workspace.name }),
61
+ /* @__PURE__ */ jsx("span", { className: "block truncate text-xs leading-4 text-muted-foreground", children: product.name })
62
+ ] });
63
+ const others = (workspace.options ?? []).filter((option) => option.id !== workspace.id);
64
+ const switchable = others.length > 0 && workspace.hrefForWorkspace !== void 0 || Boolean(workspace.listHref) || Boolean(workspace.createHref);
65
+ if (!switchable) {
66
+ return /* @__PURE__ */ jsxs("div", { title: `${workspace.name} \xB7 ${product.name}`, className: "flex w-full min-w-0 items-center gap-2 px-1.5 py-1", children: [
67
+ mobileMark,
68
+ stack
69
+ ] });
70
+ }
71
+ return /* @__PURE__ */ jsx(WorkspaceMenu, { product, workspace, mobileMark, stack, Link });
72
+ }
73
+ function WorkspaceMenu({
74
+ product,
75
+ workspace,
76
+ mobileMark,
77
+ stack,
78
+ Link
79
+ }) {
80
+ const [open, setOpen] = useState(false);
81
+ const [query, setQuery] = useState("");
82
+ const changeOpen = useCallback((next) => {
83
+ setOpen(next);
84
+ if (!next) setQuery("");
85
+ }, []);
86
+ const { containerRef, triggerRef, panelRef, triggerProps, id: panelId } = usePopoverDialog(open, changeOpen);
87
+ const noun = workspace.noun ?? DEFAULT_WORKSPACE_NOUN;
88
+ const options = workspace.hrefForWorkspace ? workspace.options ?? [] : [];
89
+ const search = query.trim().toLocaleLowerCase();
90
+ const visible = search ? options.filter((option) => option.name.toLocaleLowerCase().includes(search)) : options;
91
+ const close = () => changeOpen(false);
92
+ const rowClass = "flex min-h-9 w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-foreground transition-colors hover:bg-accent";
93
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: "w-full min-w-0", children: [
94
+ /* @__PURE__ */ jsxs(
95
+ "button",
96
+ {
97
+ type: "button",
98
+ ...triggerProps,
99
+ "aria-label": `${capitalize(noun.singular)}: ${workspace.name}. Switch ${noun.singular}`,
100
+ title: `${workspace.name} \xB7 ${product.name}`,
101
+ onClick: () => changeOpen(!open),
102
+ className: "flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 transition-colors hover:bg-accent aria-expanded:bg-accent",
103
+ children: [
104
+ mobileMark,
105
+ stack,
106
+ /* @__PURE__ */ jsx("svg", { "aria-hidden": true, className: "h-4 w-4 shrink-0 text-muted-foreground", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.75", children: /* @__PURE__ */ jsx("path", { d: "m8 9 4-4 4 4m-8 6 4 4 4-4" }) })
107
+ ]
108
+ }
109
+ ),
110
+ /* @__PURE__ */ jsxs(
111
+ PopoverSurface,
112
+ {
113
+ open,
114
+ id: panelId,
115
+ role: "dialog",
116
+ "aria-label": `Switch ${noun.singular}`,
117
+ side: "below",
118
+ triggerRef,
119
+ panelRef,
120
+ contentKey: `${query}:${options.length}`,
121
+ className: `w-72 max-w-[calc(100vw-2rem)] overflow-y-auto rounded-lg border border-card-edge bg-popover p-1.5 text-foreground ${OVERLAY_SHADOW}`,
122
+ children: [
123
+ options.length > SEARCH_THRESHOLD && /* @__PURE__ */ jsx(
124
+ "input",
125
+ {
126
+ "data-autofocus": true,
127
+ "aria-label": `Search ${noun.plural}`,
128
+ placeholder: `Search ${noun.plural}`,
129
+ value: query,
130
+ onChange: (event) => setQuery(event.target.value),
131
+ className: "mb-1.5 h-9 w-full rounded-md border border-border bg-background px-2.5 text-sm text-foreground"
132
+ }
133
+ ),
134
+ options.length > 0 && /* @__PURE__ */ jsxs("div", { className: "max-h-72 overflow-y-auto", children: [
135
+ visible.map((option) => /* @__PURE__ */ jsxs(
136
+ Link,
137
+ {
138
+ href: workspace.hrefForWorkspace(option.id),
139
+ to: workspace.hrefForWorkspace(option.id),
140
+ "aria-current": option.id === workspace.id ? "page" : void 0,
141
+ title: option.name,
142
+ onClick: close,
143
+ className: rowClass,
144
+ children: [
145
+ /* @__PURE__ */ jsx(WorkspaceInitial, { name: option.name }),
146
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: option.name }),
147
+ option.id === workspace.id && /* @__PURE__ */ jsx(CheckGlyph, { className: "h-4 w-4 shrink-0 text-primary" })
148
+ ]
149
+ },
150
+ option.id
151
+ )),
152
+ visible.length === 0 && /* @__PURE__ */ jsxs("p", { role: "status", className: "px-2 py-2 text-sm text-muted-foreground", children: [
153
+ "No ",
154
+ noun.plural,
155
+ " match \u201C",
156
+ query.trim(),
157
+ "\u201D."
158
+ ] })
159
+ ] }),
160
+ (workspace.listHref || workspace.createHref) && /* @__PURE__ */ jsxs("div", { className: options.length > 0 ? "mt-1.5 border-t border-border pt-1.5" : void 0, children: [
161
+ workspace.listHref && /* @__PURE__ */ jsxs(Link, { href: workspace.listHref, to: workspace.listHref, onClick: close, className: rowClass, children: [
162
+ /* @__PURE__ */ jsxs("svg", { "aria-hidden": true, className: "h-4 w-4 shrink-0 text-muted-foreground", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.75", children: [
163
+ /* @__PURE__ */ jsx("rect", { x: "4", y: "4", width: "6.5", height: "6.5", rx: "1.5" }),
164
+ /* @__PURE__ */ jsx("rect", { x: "13.5", y: "4", width: "6.5", height: "6.5", rx: "1.5" }),
165
+ /* @__PURE__ */ jsx("rect", { x: "4", y: "13.5", width: "6.5", height: "6.5", rx: "1.5" }),
166
+ /* @__PURE__ */ jsx("rect", { x: "13.5", y: "13.5", width: "6.5", height: "6.5", rx: "1.5" })
167
+ ] }),
168
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 truncate", children: [
169
+ "All ",
170
+ noun.plural
171
+ ] })
172
+ ] }),
173
+ workspace.createHref && /* @__PURE__ */ jsxs(Link, { href: workspace.createHref, to: workspace.createHref, onClick: close, className: rowClass, children: [
174
+ /* @__PURE__ */ jsx("svg", { "aria-hidden": true, className: "h-4 w-4 shrink-0 text-muted-foreground", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.75", children: /* @__PURE__ */ jsx("path", { d: "M12 5v14M5 12h14" }) }),
175
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 truncate", children: [
176
+ "New ",
177
+ noun.singular
178
+ ] })
179
+ ] })
180
+ ] })
181
+ ]
182
+ }
183
+ )
184
+ ] });
185
+ }
186
+
17
187
  // src/workspace-react/companion.tsx
18
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
188
+ import { forwardRef, useCallback as useCallback2, useEffect, useImperativeHandle, useRef, useState as useState2 } from "react";
19
189
  import { Tabs, TabsContent, TabsList, TabsTrigger } from "@tangle-network/sandbox-ui/primitives";
20
190
  import { WorkspaceLayout } from "@tangle-network/sandbox-ui/workspace";
21
191
  import { FlaskConical, FolderOpen, GitCompare, Monitor, Terminal } from "lucide-react";
22
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
192
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
23
193
  var companionTools = [
24
194
  { id: "files", label: "Files", Icon: FolderOpen },
25
195
  { id: "agent", label: "Agent", Icon: FlaskConical },
@@ -30,7 +200,7 @@ var companionTools = [
30
200
  function createAgentWorkspaceCompanionTabs(tools) {
31
201
  return companionTools.flatMap(({ id, label, Icon }) => {
32
202
  const renderContent = tools[id];
33
- return renderContent ? [{ id, label, icon: /* @__PURE__ */ jsx(Icon, { className: "h-3.5 w-3.5", "aria-hidden": true }), keepMounted: true, renderContent }] : [];
203
+ return renderContent ? [{ id, label, icon: /* @__PURE__ */ jsx2(Icon, { className: "h-3.5 w-3.5", "aria-hidden": true }), keepMounted: true, renderContent }] : [];
34
204
  });
35
205
  }
36
206
  var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
@@ -51,10 +221,10 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
51
221
  className
52
222
  }, ref) {
53
223
  const tabs = customTabs ?? createAgentWorkspaceCompanionTabs(tools ?? {});
54
- const [uncontrolledOpen, setOpen] = useState(defaultOpen);
224
+ const [uncontrolledOpen, setOpen] = useState2(defaultOpen);
55
225
  const open = controlledOpen ?? uncontrolledOpen;
56
- const [selection, setSelection] = useState({ key: persistenceKey, id: defaultActiveTabId });
57
- const [visits, setVisits] = useState(() => ({ key: persistenceKey, ids: /* @__PURE__ */ new Set() }));
226
+ const [selection, setSelection] = useState2({ key: persistenceKey, id: defaultActiveTabId });
227
+ const [visits, setVisits] = useState2(() => ({ key: persistenceKey, ids: /* @__PURE__ */ new Set() }));
58
228
  const requested = activeTabId ?? (selection.key === persistenceKey ? selection.id : defaultActiveTabId);
59
229
  const active = tabs.find((tab) => tab.id === requested)?.id ?? tabs[0]?.id;
60
230
  const visited = visits.key === persistenceKey ? visits.ids : /* @__PURE__ */ new Set();
@@ -105,7 +275,7 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
105
275
  return ids.has(active) ? previous : { key: persistenceKey, ids: /* @__PURE__ */ new Set([...ids, active]) };
106
276
  });
107
277
  }, [open, active, persistenceKey]);
108
- const selectTab = useCallback((id) => {
278
+ const selectTab = useCallback2((id) => {
109
279
  if (!tabs.some((tab) => tab.id === id)) return false;
110
280
  setSelection({ key: persistenceKey, id });
111
281
  onActiveTabChange?.(id);
@@ -117,7 +287,7 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
117
287
  }
118
288
  return true;
119
289
  }, [tabs, persistenceKey, storageKey, onActiveTabChange]);
120
- const changeOpen = useCallback((next) => {
290
+ const changeOpen = useCallback2((next) => {
121
291
  setOpen(next);
122
292
  onOpenChange?.(next);
123
293
  }, [onOpenChange]);
@@ -128,8 +298,8 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
128
298
  return true;
129
299
  }
130
300
  }), [selectTab, changeOpen]);
131
- if (tabs.length === 0 && !navigation) return /* @__PURE__ */ jsx(Fragment, { children });
132
- return /* @__PURE__ */ jsx(Tabs, { value: active, onValueChange: selectTab, className: `flex h-full min-h-0 min-w-0 flex-1 flex-col ${className ?? ""}`, children: /* @__PURE__ */ jsx(
301
+ if (tabs.length === 0 && !navigation) return /* @__PURE__ */ jsx2(Fragment, { children });
302
+ return /* @__PURE__ */ jsx2(Tabs, { value: active, onValueChange: selectTab, className: `flex h-full min-h-0 min-w-0 flex-1 flex-col ${className ?? ""}`, children: /* @__PURE__ */ jsx2(
133
303
  WorkspaceLayout,
134
304
  {
135
305
  className: "h-full min-h-0 min-w-0 flex-1",
@@ -138,7 +308,7 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
138
308
  center: children,
139
309
  left: navigation?.content,
140
310
  leftContentClassName: "py-0",
141
- leftHeader: navigation && (navigation.header !== void 0 ? navigation.header : /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: navigation.label ?? "Chats" })),
311
+ leftHeader: navigation && (navigation.header !== void 0 ? navigation.header : /* @__PURE__ */ jsx2("span", { className: "text-sm font-medium", children: navigation.label ?? "Chats" })),
142
312
  leftOpen: navigation?.open,
143
313
  onLeftOpenChange: navigation?.onOpenChange,
144
314
  leftLabel: navigation?.label ?? "Chats",
@@ -154,15 +324,15 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
154
324
  persistenceKey,
155
325
  minRightWidth: 280,
156
326
  rightContentClassName: "flex flex-col overflow-hidden",
157
- rightHeader: tabs.length > 0 ? /* @__PURE__ */ jsx(TabsList, { "aria-label": label, className: "h-9 max-w-full justify-start overflow-x-auto bg-transparent p-0", children: tabs.map((tab) => /* @__PURE__ */ jsxs(TabsTrigger, { value: tab.id, className: "gap-1.5 px-2.5 text-sm", children: [
327
+ rightHeader: tabs.length > 0 ? /* @__PURE__ */ jsx2(TabsList, { "aria-label": label, className: "h-9 max-w-full justify-start overflow-x-auto bg-transparent p-0", children: tabs.map((tab) => /* @__PURE__ */ jsxs2(TabsTrigger, { value: tab.id, className: "gap-1.5 px-2.5 text-sm", children: [
158
328
  tab.icon,
159
- /* @__PURE__ */ jsx("span", { children: tab.label })
329
+ /* @__PURE__ */ jsx2("span", { children: tab.label })
160
330
  ] }, tab.id)) }) : void 0,
161
331
  right: tabs.length > 0 ? tabs.map((tab) => {
162
332
  const isActive = tab.id === active;
163
333
  const retained = tab.keepMounted && visited.has(tab.id);
164
334
  if (!(open && isActive) && !retained) return null;
165
- return /* @__PURE__ */ jsx(
335
+ return /* @__PURE__ */ jsx2(
166
336
  TabsContent,
167
337
  {
168
338
  value: tab.id,
@@ -178,8 +348,386 @@ var AgentWorkspaceCompanion = forwardRef(function AgentWorkspaceCompanion2({
178
348
  ) }, persistenceKey);
179
349
  });
180
350
 
351
+ // src/workspace-react/workspace-list.tsx
352
+ import { useId, useMemo, useState as useState3 } from "react";
353
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
354
+ var SEARCH_THRESHOLD2 = 8;
355
+ var FIELD_CELL = "hidden w-32 min-w-0 shrink-0 md:block";
356
+ var DATE_CELL = "w-20 shrink-0 text-right sm:w-24";
357
+ function DefaultLink2({ href, to, ...props }) {
358
+ return /* @__PURE__ */ jsx3("a", { href: href ?? to, ...props });
359
+ }
360
+ function capitalize2(text) {
361
+ return text.charAt(0).toLocaleUpperCase() + text.slice(1);
362
+ }
363
+ function defaultFormatDate(value) {
364
+ const sameYear = value.getFullYear() === (/* @__PURE__ */ new Date()).getFullYear();
365
+ return value.toLocaleDateString(void 0, sameYear ? { month: "short", day: "numeric" } : { month: "short", day: "numeric", year: "numeric" });
366
+ }
367
+ function present(value) {
368
+ return value !== null && value !== void 0 && value !== false && value !== "";
369
+ }
370
+ function toDate(value) {
371
+ if (value === null || value === void 0 || value === "") return null;
372
+ const date = value instanceof Date ? value : new Date(value);
373
+ return Number.isNaN(date.getTime()) ? null : date;
374
+ }
375
+ function usefulDescription(item) {
376
+ const text = item.description?.trim();
377
+ if (!text) return null;
378
+ return text.toLocaleLowerCase() === item.name.trim().toLocaleLowerCase() ? null : text;
379
+ }
380
+ function WorkspaceList({
381
+ items,
382
+ noun = DEFAULT_WORKSPACE_NOUN,
383
+ title,
384
+ description,
385
+ layout = "list",
386
+ fields = [],
387
+ create,
388
+ empty,
389
+ rename,
390
+ remove,
391
+ removeConsequence,
392
+ actions,
393
+ children,
394
+ LinkComponent,
395
+ formatDate = defaultFormatDate
396
+ }) {
397
+ const Link = LinkComponent ?? DefaultLink2;
398
+ const headingId = useId();
399
+ const [query, setQuery] = useState3("");
400
+ const [renaming, setRenaming] = useState3(null);
401
+ const [renameValue, setRenameValue] = useState3("");
402
+ const [removing, setRemoving] = useState3(null);
403
+ const [creating, setCreating] = useState3(false);
404
+ const [createValue, setCreateValue] = useState3("");
405
+ const [busy, setBusy] = useState3(false);
406
+ const [error, setError] = useState3(null);
407
+ const search = query.trim().toLocaleLowerCase();
408
+ const visible = useMemo(
409
+ () => search ? items.filter((item) => item.name.toLocaleLowerCase().includes(search)) : items,
410
+ [items, search]
411
+ );
412
+ const createLabel = create?.label ?? `New ${noun.singular}`;
413
+ const openCreate = () => {
414
+ setError(null);
415
+ setCreateValue("");
416
+ setCreating(true);
417
+ };
418
+ const createControl = create ? /* @__PURE__ */ jsx3(CreateButton, { create: create.onCreate && !create.href ? { ...create, onSelect: openCreate } : create, label: createLabel, Link }) : null;
419
+ const submitCreate = () => {
420
+ const name = createValue.trim();
421
+ if (!name || !create?.onCreate) return;
422
+ void run(() => create.onCreate(name), () => setCreating(false));
423
+ };
424
+ const hasDates = items.some((item) => toDate(item.updatedAt) !== null);
425
+ const hasMenu = Boolean(rename) || Boolean(remove) || Boolean(actions);
426
+ const menuFor = (item) => [
427
+ ...rename ? [{ id: "rename", label: "Rename", onSelect: () => {
428
+ setError(null);
429
+ setRenaming(item);
430
+ setRenameValue(item.name);
431
+ } }] : [],
432
+ ...(actions?.(item) ?? []).map((action) => ({ id: action.id, label: action.label, onSelect: () => action.onSelect(item) })),
433
+ ...remove ? [{ id: "delete", label: "Delete", destructive: true, onSelect: () => {
434
+ setError(null);
435
+ setRemoving(item);
436
+ } }] : []
437
+ ];
438
+ const run = async (work, done) => {
439
+ setBusy(true);
440
+ setError(null);
441
+ try {
442
+ await work();
443
+ done();
444
+ } catch (cause) {
445
+ setError(cause instanceof Error && cause.message ? cause.message : "That did not save. Try again.");
446
+ } finally {
447
+ setBusy(false);
448
+ }
449
+ };
450
+ const submitRename = () => {
451
+ if (!renaming || !rename) return;
452
+ const name = renameValue.trim();
453
+ if (!name || name === renaming.name) {
454
+ setRenaming(null);
455
+ return;
456
+ }
457
+ void run(() => rename(renaming, name), () => setRenaming(null));
458
+ };
459
+ return /* @__PURE__ */ jsxs3("section", { "aria-labelledby": headingId, className: "mx-auto w-full max-w-5xl px-4 py-6 sm:px-6 sm:py-8 lg:px-8", children: [
460
+ /* @__PURE__ */ jsxs3("header", { className: "flex flex-wrap items-start justify-between gap-x-4 gap-y-3", children: [
461
+ /* @__PURE__ */ jsxs3("div", { className: "min-w-0 flex-1", children: [
462
+ /* @__PURE__ */ jsx3("h1", { id: headingId, className: "text-xl font-semibold tracking-tight text-foreground", children: title ?? capitalize2(noun.plural) }),
463
+ description != null && /* @__PURE__ */ jsx3("div", { className: "mt-1 max-w-prose text-sm text-muted-foreground", children: description })
464
+ ] }),
465
+ items.length > 0 && createControl
466
+ ] }),
467
+ children != null && /* @__PURE__ */ jsx3("div", { className: "mt-6", children }),
468
+ items.length === 0 ? /* @__PURE__ */ jsxs3("div", { className: "mt-6 flex flex-col items-center rounded-xl border border-dashed border-border px-6 py-14 text-center", children: [
469
+ /* @__PURE__ */ jsx3("span", { "aria-hidden": true, className: "flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10 text-primary", children: /* @__PURE__ */ jsxs3("svg", { className: "h-5 w-5", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.75", children: [
470
+ /* @__PURE__ */ jsx3("rect", { x: "4", y: "4", width: "6.5", height: "6.5", rx: "1.5" }),
471
+ /* @__PURE__ */ jsx3("rect", { x: "13.5", y: "4", width: "6.5", height: "6.5", rx: "1.5" }),
472
+ /* @__PURE__ */ jsx3("rect", { x: "4", y: "13.5", width: "6.5", height: "6.5", rx: "1.5" }),
473
+ /* @__PURE__ */ jsx3("path", { d: "M16.75 13.5v6.5M13.5 16.75H20" })
474
+ ] }) }),
475
+ /* @__PURE__ */ jsx3("h2", { className: "mt-4 text-base font-semibold text-foreground", children: empty?.title ?? `No ${noun.plural} yet` }),
476
+ empty?.description && /* @__PURE__ */ jsx3("p", { className: "mt-1.5 max-w-sm text-sm text-muted-foreground", children: empty.description }),
477
+ createControl && /* @__PURE__ */ jsx3("div", { className: "mt-5", children: createControl })
478
+ ] }) : /* @__PURE__ */ jsxs3(Fragment2, { children: [
479
+ items.length > SEARCH_THRESHOLD2 && /* @__PURE__ */ jsx3("div", { className: "mt-6", children: /* @__PURE__ */ jsx3(
480
+ "input",
481
+ {
482
+ type: "search",
483
+ "aria-label": `Search ${noun.plural}`,
484
+ placeholder: `Search ${noun.plural}`,
485
+ value: query,
486
+ onChange: (event) => setQuery(event.target.value),
487
+ className: "h-9 w-full max-w-sm rounded-md border border-border bg-background px-3 text-sm text-foreground placeholder:text-muted-foreground"
488
+ }
489
+ ) }),
490
+ visible.length === 0 ? /* @__PURE__ */ jsxs3("p", { role: "status", className: "mt-6 rounded-xl border border-border px-4 py-8 text-center text-sm text-muted-foreground", children: [
491
+ "No ",
492
+ noun.plural,
493
+ " match \u201C",
494
+ query.trim(),
495
+ "\u201D.",
496
+ " ",
497
+ /* @__PURE__ */ jsx3("button", { type: "button", onClick: () => setQuery(""), className: "font-medium text-foreground underline underline-offset-2", children: "Clear search" })
498
+ ] }) : layout === "grid" ? /* @__PURE__ */ jsx3("ul", { className: `grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 ${items.length > SEARCH_THRESHOLD2 ? "mt-3" : "mt-6"}`, children: visible.map((item) => /* @__PURE__ */ jsx3(GridCard, { item, fields, menu: menuFor(item), Link, formatDate }, item.id)) }) : /* @__PURE__ */ jsxs3("div", { className: `overflow-hidden rounded-xl border border-border bg-card ${items.length > SEARCH_THRESHOLD2 ? "mt-3" : "mt-6"}`, children: [
499
+ fields.length > 0 && /* @__PURE__ */ jsxs3("div", { "aria-hidden": true, className: "hidden items-center gap-3 border-b border-border px-4 py-2 text-xs font-medium text-muted-foreground md:flex", children: [
500
+ /* @__PURE__ */ jsx3("span", { className: "w-10 shrink-0" }),
501
+ /* @__PURE__ */ jsx3("span", { className: "min-w-0 flex-1", children: "Name" }),
502
+ fields.map((field) => /* @__PURE__ */ jsx3("span", { className: `${FIELD_CELL} truncate`, children: field.label }, field.id)),
503
+ /* @__PURE__ */ jsx3("span", { className: DATE_CELL, children: hasDates ? "Updated" : "" }),
504
+ hasMenu && /* @__PURE__ */ jsx3("span", { className: "w-8 shrink-0" })
505
+ ] }),
506
+ /* @__PURE__ */ jsx3("ul", { className: "divide-y divide-border", children: visible.map((item) => /* @__PURE__ */ jsx3(ListRow, { item, fields, menu: menuFor(item), reserveMenu: hasMenu, Link, formatDate }, item.id)) })
507
+ ] })
508
+ ] }),
509
+ renaming && /* @__PURE__ */ jsxs3(
510
+ ActionDialog,
511
+ {
512
+ title: `Rename ${noun.singular}`,
513
+ onClose: () => setRenaming(null),
514
+ busy,
515
+ error,
516
+ footer: /* @__PURE__ */ jsxs3(Fragment2, { children: [
517
+ /* @__PURE__ */ jsx3(ActionDialogButton, { variant: "ghost", onClick: () => setRenaming(null), disabled: busy, children: "Cancel" }),
518
+ /* @__PURE__ */ jsx3(ActionDialogButton, { onClick: submitRename, disabled: busy || !renameValue.trim(), children: "Save" })
519
+ ] }),
520
+ children: [
521
+ /* @__PURE__ */ jsx3("label", { htmlFor: `${headingId}-rename`, className: "text-xs text-muted-foreground", children: "Name" }),
522
+ /* @__PURE__ */ jsx3(
523
+ "input",
524
+ {
525
+ id: `${headingId}-rename`,
526
+ value: renameValue,
527
+ autoFocus: true,
528
+ onChange: (event) => setRenameValue(event.target.value),
529
+ onKeyDown: (event) => {
530
+ if (event.key === "Enter" && !busy) {
531
+ event.preventDefault();
532
+ submitRename();
533
+ }
534
+ },
535
+ className: "mt-1.5 h-9 w-full rounded-md border border-border bg-background px-3 text-sm text-foreground"
536
+ }
537
+ )
538
+ ]
539
+ }
540
+ ),
541
+ creating && create?.onCreate && /* @__PURE__ */ jsxs3(
542
+ ActionDialog,
543
+ {
544
+ title: createLabel,
545
+ onClose: () => setCreating(false),
546
+ busy,
547
+ error,
548
+ footer: /* @__PURE__ */ jsxs3(Fragment2, { children: [
549
+ /* @__PURE__ */ jsx3(ActionDialogButton, { variant: "ghost", onClick: () => setCreating(false), disabled: busy, children: "Cancel" }),
550
+ /* @__PURE__ */ jsx3(ActionDialogButton, { onClick: submitCreate, disabled: busy || !createValue.trim(), children: "Create" })
551
+ ] }),
552
+ children: [
553
+ /* @__PURE__ */ jsx3("label", { htmlFor: `${headingId}-create`, className: "text-xs text-muted-foreground", children: "Name" }),
554
+ /* @__PURE__ */ jsx3(
555
+ "input",
556
+ {
557
+ id: `${headingId}-create`,
558
+ value: createValue,
559
+ autoFocus: true,
560
+ placeholder: create.namePlaceholder ?? `${capitalize2(noun.singular)} name`,
561
+ onChange: (event) => setCreateValue(event.target.value),
562
+ onKeyDown: (event) => {
563
+ if (event.key === "Enter" && !busy) {
564
+ event.preventDefault();
565
+ submitCreate();
566
+ }
567
+ },
568
+ className: "mt-1.5 h-9 w-full rounded-md border border-border bg-background px-3 text-sm text-foreground placeholder:text-muted-foreground"
569
+ }
570
+ )
571
+ ]
572
+ }
573
+ ),
574
+ removing && remove && /* @__PURE__ */ jsx3(
575
+ ActionDialog,
576
+ {
577
+ title: `Delete ${noun.singular}?`,
578
+ onClose: () => setRemoving(null),
579
+ busy,
580
+ error,
581
+ footer: /* @__PURE__ */ jsxs3(Fragment2, { children: [
582
+ /* @__PURE__ */ jsx3(ActionDialogButton, { variant: "ghost", onClick: () => setRemoving(null), disabled: busy, children: "Cancel" }),
583
+ /* @__PURE__ */ jsx3(ActionDialogButton, { variant: "destructive", onClick: () => void run(() => remove(removing), () => setRemoving(null)), disabled: busy, children: "Delete" })
584
+ ] }),
585
+ children: /* @__PURE__ */ jsx3("p", { className: "break-words text-sm text-muted-foreground", children: removeConsequence?.(removing) ?? `\u201C${removing.name}\u201D and everything in it will be deleted. This cannot be undone.` })
586
+ }
587
+ )
588
+ ] });
589
+ }
590
+ function UpdatedAt({ value, formatDate, className = "shrink-0" }) {
591
+ const date = toDate(value);
592
+ if (!date) return /* @__PURE__ */ jsx3("span", { className });
593
+ return (
594
+ // Server and browser can format a date differently (zone, locale); the
595
+ // browser's reading is the one the user should see.
596
+ /* @__PURE__ */ jsx3("time", { dateTime: date.toISOString(), suppressHydrationWarning: true, className: `${className} text-xs tabular-nums text-muted-foreground`, children: formatDate(date) })
597
+ );
598
+ }
599
+ function ListRow({ item, fields, menu, reserveMenu, Link, formatDate }) {
600
+ const detail = usefulDescription(item);
601
+ return /* @__PURE__ */ jsxs3("li", { className: "group relative isolate flex min-h-16 items-center gap-3 px-4 py-3 transition-colors hover:bg-accent/60", children: [
602
+ item.avatar ?? /* @__PURE__ */ jsx3(WorkspaceInitial, { name: item.name, size: "lg" }),
603
+ /* @__PURE__ */ jsxs3("div", { className: "min-w-0 flex-1", children: [
604
+ /* @__PURE__ */ jsx3(
605
+ Link,
606
+ {
607
+ href: item.href,
608
+ to: item.href,
609
+ title: item.name,
610
+ className: "block truncate text-sm font-medium text-foreground after:absolute after:inset-0 after:content-[''] focus-visible:outline-none focus-visible:after:rounded-[inherit] focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-ring",
611
+ children: item.name
612
+ }
613
+ ),
614
+ detail && /* @__PURE__ */ jsx3("p", { className: "truncate text-xs text-muted-foreground", title: detail, children: detail })
615
+ ] }),
616
+ fields.map((field) => /* @__PURE__ */ jsxs3("div", { className: `${FIELD_CELL} truncate text-sm text-muted-foreground`, children: [
617
+ /* @__PURE__ */ jsxs3("span", { className: "sr-only", children: [
618
+ field.label,
619
+ ": "
620
+ ] }),
621
+ present(item.values?.[field.id]) ? item.values[field.id] : "\u2014"
622
+ ] }, field.id)),
623
+ /* @__PURE__ */ jsx3(UpdatedAt, { value: item.updatedAt, formatDate, className: DATE_CELL }),
624
+ menu.length > 0 ? /* @__PURE__ */ jsx3(ItemMenu, { item, entries: menu }) : reserveMenu ? /* @__PURE__ */ jsx3("span", { className: "w-8 shrink-0" }) : null
625
+ ] });
626
+ }
627
+ function GridCard({ item, fields, menu, Link, formatDate }) {
628
+ const detail = usefulDescription(item);
629
+ const shownFields = fields.filter((field) => present(item.values?.[field.id]));
630
+ return /* @__PURE__ */ jsxs3("li", { className: "group relative isolate flex min-h-36 flex-col overflow-hidden rounded-xl border border-border bg-card p-4 transition-[border-color,box-shadow] hover:border-primary/40 hover:shadow-sm", children: [
631
+ /* @__PURE__ */ jsx3("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-x-0 top-0 -z-10 h-16 bg-gradient-to-b from-primary/[0.07] to-transparent" }),
632
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-start gap-3", children: [
633
+ item.avatar ?? /* @__PURE__ */ jsx3(WorkspaceInitial, { name: item.name, size: "lg" }),
634
+ /* @__PURE__ */ jsxs3("div", { className: "min-w-0 flex-1 pt-0.5", children: [
635
+ /* @__PURE__ */ jsx3(
636
+ Link,
637
+ {
638
+ href: item.href,
639
+ to: item.href,
640
+ title: item.name,
641
+ className: "line-clamp-2 break-words text-sm font-semibold text-foreground after:absolute after:inset-0 after:content-[''] focus-visible:outline-none focus-visible:after:rounded-xl focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-ring",
642
+ children: item.name
643
+ }
644
+ ),
645
+ detail && /* @__PURE__ */ jsx3("p", { className: "mt-0.5 truncate text-xs text-muted-foreground", title: detail, children: detail })
646
+ ] }),
647
+ menu.length > 0 && /* @__PURE__ */ jsx3(ItemMenu, { item, entries: menu })
648
+ ] }),
649
+ /* @__PURE__ */ jsxs3("div", { className: "mt-auto flex items-end justify-between gap-3 pt-4", children: [
650
+ shownFields.length > 0 ? /* @__PURE__ */ jsx3("dl", { className: "flex min-w-0 flex-wrap gap-x-4 gap-y-1 text-xs", children: shownFields.map((field) => /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 gap-1", children: [
651
+ /* @__PURE__ */ jsx3("dt", { className: "text-muted-foreground", children: field.label }),
652
+ /* @__PURE__ */ jsx3("dd", { className: "truncate font-medium text-foreground", children: item.values?.[field.id] })
653
+ ] }, field.id)) }) : /* @__PURE__ */ jsx3("span", {}),
654
+ /* @__PURE__ */ jsx3(UpdatedAt, { value: item.updatedAt, formatDate })
655
+ ] })
656
+ ] });
657
+ }
658
+ function ItemMenu({ item, entries }) {
659
+ const [open, setOpen] = useState3(false);
660
+ const panelId = useId();
661
+ const { containerRef, triggerRef, panelRef, triggerProps } = usePopover(open, setOpen);
662
+ return /* @__PURE__ */ jsxs3("div", { ref: containerRef, className: "relative z-10 shrink-0", children: [
663
+ /* @__PURE__ */ jsx3(
664
+ "button",
665
+ {
666
+ type: "button",
667
+ ...triggerProps,
668
+ "aria-label": `Actions for ${item.name}`,
669
+ "aria-controls": open ? panelId : void 0,
670
+ onClick: () => setOpen(!open),
671
+ className: "flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition hover:bg-muted hover:text-foreground focus-visible:opacity-100 aria-expanded:opacity-100 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover:opacity-100",
672
+ children: /* @__PURE__ */ jsxs3("svg", { "aria-hidden": true, className: "h-4 w-4", viewBox: "0 0 24 24", fill: "currentColor", children: [
673
+ /* @__PURE__ */ jsx3("circle", { cx: "5", cy: "12", r: "1.6" }),
674
+ /* @__PURE__ */ jsx3("circle", { cx: "12", cy: "12", r: "1.6" }),
675
+ /* @__PURE__ */ jsx3("circle", { cx: "19", cy: "12", r: "1.6" })
676
+ ] })
677
+ }
678
+ ),
679
+ /* @__PURE__ */ jsx3(
680
+ PopoverSurface,
681
+ {
682
+ open,
683
+ id: panelId,
684
+ role: "menu",
685
+ "aria-label": `Actions for ${item.name}`,
686
+ side: "below",
687
+ align: "end",
688
+ triggerRef,
689
+ panelRef,
690
+ className: `w-44 overflow-hidden rounded-md border border-card-edge bg-popover py-1 ${OVERLAY_SHADOW}`,
691
+ children: entries.map((entry, index) => /* @__PURE__ */ jsx3(
692
+ "button",
693
+ {
694
+ type: "button",
695
+ role: "menuitem",
696
+ onClick: () => {
697
+ setOpen(false);
698
+ triggerRef.current?.focus();
699
+ entry.onSelect();
700
+ },
701
+ className: `block w-full px-3 py-1.5 text-left text-sm transition ${entry.destructive ? "text-destructive hover:bg-destructive/10" : "text-foreground hover:bg-accent"} ${entry.destructive && index > 0 ? "mt-1 border-t border-border pt-2" : ""}`,
702
+ children: entry.label
703
+ },
704
+ entry.id
705
+ ))
706
+ }
707
+ )
708
+ ] });
709
+ }
710
+ function CreateButton({
711
+ create,
712
+ label,
713
+ Link
714
+ }) {
715
+ const className = "inline-flex h-9 shrink-0 items-center gap-1.5 rounded-md bg-primary px-3.5 text-sm font-medium text-primary-foreground transition hover:opacity-90 active:scale-[0.98]";
716
+ const icon = /* @__PURE__ */ jsx3("svg", { "aria-hidden": true, className: "h-4 w-4", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx3("path", { d: "M12 5v14M5 12h14" }) });
717
+ if (create.href) {
718
+ return /* @__PURE__ */ jsxs3(Link, { href: create.href, to: create.href, className, children: [
719
+ icon,
720
+ label
721
+ ] });
722
+ }
723
+ return /* @__PURE__ */ jsxs3("button", { type: "button", onClick: create.onSelect, className, children: [
724
+ icon,
725
+ label
726
+ ] });
727
+ }
728
+
181
729
  // src/workspace-react/index.tsx
182
- import { jsx as jsx2 } from "react/jsx-runtime";
730
+ import { jsx as jsx4 } from "react/jsx-runtime";
183
731
  function routePathFromHref(href, base) {
184
732
  const path = href.split(/[?#]/, 1)[0] ?? "";
185
733
  const root = base.replace(/\/+$/, "");
@@ -194,6 +742,8 @@ function AgentWorkspaceLayout({
194
742
  apps,
195
743
  activeRoute,
196
744
  activeId,
745
+ product,
746
+ workspace,
197
747
  ...sidebarProps
198
748
  }) {
199
749
  const sessionNav = sessions ? (() => {
@@ -271,12 +821,27 @@ function AgentWorkspaceLayout({
271
821
  ...appGroup ? [appGroup] : [],
272
822
  ...sessionNav ? [sessionNav] : []
273
823
  ];
824
+ const hideBelow = sidebarProps.hideBelow ?? "lg";
825
+ const identityProps = product ? {
826
+ logo: product.mark,
827
+ logoHref: product.href,
828
+ railHeaderContent: /* @__PURE__ */ jsx4(
829
+ AgentRailIdentity,
830
+ {
831
+ product,
832
+ workspace,
833
+ hideBelow,
834
+ LinkComponent: sidebarProps.LinkComponent
835
+ }
836
+ )
837
+ } : {};
274
838
  const layoutProps = {
275
- hideBelow: "lg",
839
+ hideBelow,
276
840
  railLabels: true,
841
+ ...identityProps,
277
842
  ...sidebarProps
278
843
  };
279
- return /* @__PURE__ */ jsx2(
844
+ return /* @__PURE__ */ jsx4(
280
845
  SidebarLayout,
281
846
  {
282
847
  ...layoutProps,
@@ -287,8 +852,12 @@ function AgentWorkspaceLayout({
287
852
  );
288
853
  }
289
854
  export {
855
+ AgentRailIdentity,
290
856
  AgentWorkspaceCompanion,
291
857
  AgentWorkspaceLayout,
858
+ DEFAULT_WORKSPACE_NOUN,
859
+ WorkspaceInitial,
860
+ WorkspaceList,
292
861
  WorkspaceSwitcher,
293
862
  createAgentWorkspaceCompanionTabs
294
863
  };