@theoremjs/studio 0.3.4-next.638.g15efdc1 → 0.3.4-next.643.gd4d1ea8

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 (61) hide show
  1. package/draft.d.ts +3 -1
  2. package/draft.js +5 -1
  3. package/map.js +6 -4
  4. package/mod.d.ts +1 -1
  5. package/mod.js +1 -1
  6. package/package.json +4 -4
  7. package/page/assets/{Banner-BTjY7Mtu.js → Banner-DNvkF9Qd.js} +4 -4
  8. package/page/assets/{ConsoleFrame-Cq5dkghk.js → ConsoleFrame-B876WPIe.js} +3 -3
  9. package/page/assets/{MenuBottomSheet-DretMXoa.js → MenuBottomSheet-DuKvL33Y.js} +1 -1
  10. package/page/assets/{SchemaFields-Bp1YOVR7.js → SchemaFields-B9OePwiw.js} +1 -1
  11. package/page/assets/{ToolResultCharts-CbzInW4B.js → ToolResultCharts-XIG-vtPV.js} +1 -1
  12. package/page/assets/{TraceInspector-CRwY9jwp.js → TraceInspector-BO1sUDv5.js} +1 -1
  13. package/page/assets/{TraceOverview-DIMq_1hE.js → TraceOverview-DO2ScssG.js} +2 -2
  14. package/page/assets/{_virtual_studio-type-sources-DhP7lEDJ.js → _virtual_studio-type-sources-B0cSCDug.js} +1 -1
  15. package/page/assets/{browser-engine-BRyDASgH.js → browser-engine-_avqse9T.js} +2 -2
  16. package/page/assets/browser-transport-BmBmOKD0.js +45 -0
  17. package/page/assets/{export-agent-CYGkBpyC.js → export-agent-B9Xe_1wb.js} +9 -9
  18. package/page/assets/{guardrail-tester-dbXvJBsC.js → guardrail-tester-Bz6hi_5P.js} +2 -2
  19. package/page/assets/{index-CIpIU6Dr.js → index-BpUYOiAK.js} +72 -72
  20. package/page/assets/{studio-code-pane-3FmOfsF4.js → studio-code-pane-B2xhXqYn.js} +3 -3
  21. package/page/assets/{studio-console-J8M0Vgxa.js → studio-console-B_7zbgqu.js} +1 -1
  22. package/page/assets/studio-decision-CP61CMdG.js +1 -0
  23. package/page/assets/{studio-embedding-CoRNiSwb.js → studio-embedding-DAIGP45v.js} +1 -1
  24. package/page/assets/{studio-host-console-b0NBdB1f.js → studio-host-console-2pLKEf5V.js} +2 -2
  25. package/page/assets/{studio-labels-1WTG3UvE.js → studio-labels-BUwgtZIK.js} +1 -1
  26. package/page/assets/{studio-live-BhZC56Lo.js → studio-live-BWDmm-07.js} +3 -3
  27. package/page/assets/studio-map-CZFaDnXx.js +1 -0
  28. package/page/assets/studio-trace-replay-ByFhjbMr.js +3 -0
  29. package/page/assets/{studio-type-checker-DYWojRR2.js → studio-type-checker-BQmVytwu.js} +1 -1
  30. package/page/assets/tree-DM7jRXMx.js +3 -0
  31. package/page/assets/{use-one-call-CzbvFiJr.js → use-one-call--YwtCY2X.js} +1 -1
  32. package/page/assets/{workspace-AKMCUEuK.js → workspace-WKa0_gWg.js} +1 -1
  33. package/page/index.html +6 -6
  34. package/replay.d.ts +16 -8
  35. package/replay.js +73 -31
  36. package/run-payload-core.js +1 -7
  37. package/run-payload.d.ts +0 -3
  38. package/runtime.js +1 -1
  39. package/tree.js +3 -3
  40. package/ui/lib/conversation-types.d.ts +5 -0
  41. package/ui/lib/conversation-types.js +7 -0
  42. package/ui/lib/export-agent.js +2 -2
  43. package/ui/profile-editor.js +22 -23
  44. package/ui/studio-compare.js +2 -3
  45. package/ui/studio-map.js +2 -4
  46. package/ui/studio-run.js +4 -4
  47. package/ui/studio-runner.d.ts +1 -2
  48. package/ui/studio-runner.js +4 -8
  49. package/ui/studio-save.d.ts +2 -0
  50. package/ui/studio-save.js +3 -3
  51. package/ui/studio-screen.js +43 -21
  52. package/ui/studio-settings.js +1 -1
  53. package/ui/studio-trace-replay.js +22 -8
  54. package/ui/trace-button.d.ts +6 -0
  55. package/ui/trace-button.js +10 -0
  56. package/workspace.js +3 -5
  57. package/page/assets/browser-transport-BGH5-w7Y.js +0 -45
  58. package/page/assets/studio-decision-BClNnN2H.js +0 -1
  59. package/page/assets/studio-map-Cs5U1h9e.js +0 -1
  60. package/page/assets/studio-trace-replay-DKsOgyVq.js +0 -3
  61. package/page/assets/tree-D5eWDcqI.js +0 -3
package/ui/studio-map.js CHANGED
@@ -27,7 +27,6 @@ import { PROFILE_TYPE_ICON, profileTypeIcon, toolTypeIcon } from "./lib/type-ico
27
27
  import { MapToken, useTokenWidths } from "./map-token.js";
28
28
  import { drags, fieldStart, follow, scrollOnce, usePan } from "./pan.js";
29
29
  import './studio-map.css';
30
- /** With detail a node holds its icon, its name, and two lines of its note; a card's head, one; a row, a section. */
31
30
  /** A token's slot: as wide as the longest name it shows in full. */
32
31
  const TOKEN_SIZES = {
33
32
  node: { width: 240, height: 24 },
@@ -367,9 +366,8 @@ export function StudioMap({ workspace, shared, selected, onOpen, onClose, }) {
367
366
  const [menuOn, setMenuOn] = useState();
368
367
  const menu = menuOf(nodes.find((node) => node.id === menuOn), onOpen, actions);
369
368
  const Node = expanded ? DetailNode : TokenNode;
370
- const open = nodes.find((node) => isOpen(node, selected))?.id;
371
369
  // The open node's lines are drawn over the rest, and the lit ones over those.
372
- const over = (line) => onLines.has(line.link) ? 2 : line.from === open || line.to === open ? 1 : 0;
370
+ const over = (line) => onLines.has(line.link) ? 2 : line.from === opened || line.to === opened ? 1 : 0;
373
371
  const lines = [...layout.lines].sort((a, b) => over(a) - over(b));
374
372
  return (_jsxs("div", { className: "studio-map-frame",
375
373
  // why: the frame only wraps the map; Escape from anywhere inside it leaves the family.
@@ -388,7 +386,7 @@ export function StudioMap({ workspace, shared, selected, onOpen, onClose, }) {
388
386
  '--map-height': `${String(layout.height)}px`,
389
387
  '--map-slot': `${String(sizes.node.width)}px`,
390
388
  '--map-line': `${String(sizes.card.row)}px`,
391
- }, children: [_jsx("svg", { className: "studio-map-lines", width: layout.width, height: layout.height, "aria-hidden": "true", children: lines.map(({ link, from, to, d }) => (_jsx("path", { className: "map-line", d: d, "data-kind": link.kind, "data-on": onLines.has(link) ? '' : undefined, "data-open": from === open || to === open ? '' : undefined }, `${link.kind}:${link.from}:${link.to}`))) }), layout.headings.map(({ label, x, y }) => (_jsx("div", { className: "studio-map-heading", style: { left: x, top: y }, children: _jsx(Text, { type: "supporting", color: "secondary", weight: "semibold", children: label }) }, label))), nodes.map((node) => {
389
+ }, children: [_jsx("svg", { className: "studio-map-lines", width: layout.width, height: layout.height, "aria-hidden": "true", children: lines.map(({ link, from, to, d }) => (_jsx("path", { className: "map-line", d: d, "data-kind": link.kind, "data-on": onLines.has(link) ? '' : undefined, "data-open": from === opened || to === opened ? '' : undefined }, `${link.kind}:${link.from}:${link.to}`))) }), layout.headings.map(({ label, x, y }) => (_jsx("div", { className: "studio-map-heading", style: { left: x, top: y }, children: _jsx(Text, { type: "supporting", color: "secondary", weight: "semibold", children: label }) }, label))), nodes.map((node) => {
392
390
  const place = layout.nodes[node.id];
393
391
  return (place && (_jsx(Node, { node: node, place: place, joins: mapLinkWords(map, node.id), selected: selected, on: on, isFound: found.includes(node.id), isDragging: dragging === node.id, onOpen: onOpen, lights: lights, drag: draggable(node.id) }, node.id)));
394
392
  })] }) }) }), isNothing && (_jsx(Center, { className: "studio-map-nothing", children: _jsx(EmptyState, { headingLevel: 2, icon: _jsx(Icon, { icon: IconSearch, size: "lg" }), title: "Nothing matches" }) })), _jsx(MapTools, { actions: actions, query: query, onQuery: setQuery, onClose: onClose })] }));
package/ui/studio-run.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button } from '@astryxdesign/core/Button';
3
2
  import { Icon } from '@astryxdesign/core/Icon';
4
- import { IconActivity, IconKey } from '@tabler/icons-react';
3
+ import { IconKey } from '@tabler/icons-react';
5
4
  import { PaneState, TheoremThemeProvider, TracePlacement } from '@theoremjs/react/ui';
6
5
  import { useEffect, useState } from 'react';
7
6
  import { studioKeySlots } from "../browser.js";
@@ -13,6 +12,7 @@ import { useStudioConnection } from "./studio-connection.js";
13
12
  import { StudioRunner } from "./studio-runner.js";
14
13
  import { usePhone } from "./use-phone.js";
15
14
  import './studio-run.css';
15
+ import { TraceButton } from "./trace-button.js";
16
16
  /** The name the page and the document title use. A host has no handle: it's named by its id. */
17
17
  export function studioRunTitle(payload) {
18
18
  return 'identity' in payload.profile ? payload.profile.identity.handle : payload.agentId;
@@ -52,9 +52,9 @@ export function StudioRunScreen({ opened, supplies, }) {
52
52
  const phone = usePhone();
53
53
  const { mode, runtime } = connection;
54
54
  const title = studioRunTitle(payload);
55
- return (_jsxs(TheoremThemeProvider, { mode: "dark", children: [_jsx("title", { children: `${title} · theorem studio` }), _jsx(TracePlacement, { value: "panel", children: _jsxs("div", { className: "run-page", children: [_jsx("div", { className: "run-controls", children: traced ? (_jsx(Button, { label: traceOpen ? 'Hide trace' : 'View trace', variant: "ghost", isIconOnly: phone, icon: _jsx(Icon, { icon: IconActivity, size: "sm" }), "aria-pressed": traceOpen, onClick: () => {
55
+ return (_jsxs(TheoremThemeProvider, { mode: "dark", children: [_jsx("title", { children: `${title} · theorem studio` }), _jsx(TracePlacement, { value: "panel", children: _jsxs("div", { className: "run-page", children: [_jsx("div", { className: "run-controls", children: traced ? (_jsx(TraceButton, { open: traceOpen, isIconOnly: phone, onToggle: () => {
56
56
  setTraceOpen((open) => !open);
57
- } })) : null }), keysFromStudio === 'gone' ? (_jsx(PaneState, { icon: _jsx(Icon, { icon: IconKey, size: "lg", color: "secondary" }), title: "Set your keys in the studio", description: "This tab takes its keys from the studio tab that opened it, and that tab is closed. Open the agent in a new tab from the studio again." })) : (_jsx(ProjectContext.Provider, { value: opened.project, children: _jsx(StudioRunner, { payload: payload, mode: mode, runtime: runtime, trace: traced ? traceOpen : undefined, flush: true, columns: true, className: "run-chat" }, mode) }))] }) })] }));
57
+ } })) : null }), keysFromStudio === 'gone' ? (_jsx(PaneState, { icon: _jsx(Icon, { icon: IconKey, size: "lg", color: "secondary" }), title: "Set your keys in the studio", description: "This tab takes its keys from the studio tab that opened it, and that tab is closed. Open the agent in a new tab from the studio again." })) : (_jsx(ProjectContext.Provider, { value: opened.project, children: _jsx(StudioRunner, { payload: payload, runtime: runtime, trace: traced ? traceOpen : undefined, flush: true, columns: true, className: "run-chat" }, mode) }))] }) })] }));
58
58
  }
59
59
  /**
60
60
  * Fills the vault from the studio tab that opened this one, when the run reads this browser's
@@ -2,10 +2,9 @@ import { TheoremChat } from '@theoremjs/react/ui';
2
2
  import { type TraceFeed } from '@theoremjs/web/client';
3
3
  import { type ComponentProps } from 'react';
4
4
  import { type StudioBrowserRuntime } from '../browser.ts';
5
- import { type StudioConnectionMode, type StudioRunPayload, type StudioWorkspace } from '../mod.ts';
5
+ import { type StudioRunPayload, type StudioWorkspace } from '../mod.ts';
6
6
  export interface StudioRunnerProps {
7
7
  payload: StudioRunPayload;
8
- mode: StudioConnectionMode;
9
8
  runtime: StudioBrowserRuntime | null;
10
9
  trace?: boolean;
11
10
  className?: string;
@@ -1,15 +1,14 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Button } from '@astryxdesign/core/Button';
3
3
  import { HStack } from '@astryxdesign/core/HStack';
4
- import { Icon } from '@astryxdesign/core/Icon';
5
4
  import { Token } from '@astryxdesign/core/Token';
6
- import { IconKey } from '@tabler/icons-react';
7
- import { PaneLoading, PaneState, TheoremChat, TheoremLabelsProvider, useLabels, } from '@theoremjs/react/ui';
5
+ import { PaneLoading, TheoremChat, TheoremLabelsProvider, useLabels } from '@theoremjs/react/ui';
8
6
  import { createDecisionTransport, createEmbeddingTransport, createHostTransport, createHttpTransport, createTraceFeed, } from '@theoremjs/web/client';
9
7
  import { lazy, Suspense, useContext, useEffect, useMemo, useRef, useState, } from 'react';
10
8
  import { createBrowserStudioTransport } from "../browser.js";
11
9
  import { compileWorkspace, createStudioTransport, ON_OWN_KEYS, studioInterface, studioPageTools, workspaceRunAgent, } from "../mod.js";
12
10
  import { useActingAs } from "./lib/acting-as.js";
11
+ import { runsAsConversation } from "./lib/conversation-types.js";
13
12
  import { tracedTransport } from "./lib/project-traces.js";
14
13
  import { noting } from "./lib/studio-activity.js";
15
14
  import { pageConversationKey } from "./lib/studio-conversation.js";
@@ -59,11 +58,9 @@ export function StudioRunner({ onActivity, traces: given, ...props }) {
59
58
  }, []);
60
59
  return (_jsx(Suspense, { fallback: _jsx(RunLoading, {}), children: _jsx(Run, { ...props, project: project, traces: traces, note: note }) }));
61
60
  }
62
- function Run({ payload, mode, runtime, trace, className, flush, columns, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, slots, context, tested, project, traces, note, }) {
61
+ function Run({ payload, runtime, trace, className, flush, columns, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, slots, context, tested, project, traces, note, }) {
63
62
  if (project)
64
63
  return (_jsx(ProjectRun, { project: project, payload: payload, traces: traces, trace: trace, className: className, flush: flush, columns: columns, note: note, chatRef: chatRef, slots: slots, context: context, tested: tested }));
65
- if (mode !== 'demo' && !runtime)
66
- return (_jsx(PaneState, { icon: _jsx(Icon, { icon: IconKey, size: "lg", color: "secondary" }), title: "Connect to run", description: "Add your provider keys or local endpoint under Keys." }));
67
64
  if (payload.profile.type === 'decision')
68
65
  return (_jsx(StudioDecision, { payload: payload, runtime: runtime, traces: traces, trace: trace, className: className, onActivity: note, flush: flush, columns: columns }));
69
66
  if (payload.profile.type === 'host')
@@ -86,8 +83,7 @@ function UnsavedActions({ agentId, isNew }) {
86
83
  } })] }));
87
84
  }
88
85
  /** The types that are not a conversation: a chat cannot sit beside one of these. */
89
- const NOT_A_CHAT = new Set(['decision', 'host', 'live']);
90
- const isChat = (payload) => !NOT_A_CHAT.has(payload.profile.type);
86
+ const isChat = (payload) => runsAsConversation(payload.profile.type);
91
87
  /**
92
88
  * The agents the files hold, compiled from where the workspace started: an edit may have renamed
93
89
  * one or made it another type. Undefined when the files hold none of them.
@@ -2,6 +2,8 @@ import { type ReactNode } from 'react';
2
2
  import { type StudioWorkspace } from '../mod.ts';
3
3
  import { type ProjectSession } from './lib/studio-project.ts';
4
4
  export type Update = (change: (current: StudioWorkspace) => StudioWorkspace) => void;
5
+ /** How long a toast with Undo stays, in milliseconds: long enough to reach Undo. */
6
+ export declare const UNDO_WINDOW = 15000;
5
7
  /** Save, for whatever on the page offers it. */
6
8
  export interface ProjectSaveActions {
7
9
  /** Whether the studio holds edits the project's files do not. */
package/ui/studio-save.js CHANGED
@@ -62,8 +62,8 @@ const ALERTS_WIDTH = 320;
62
62
  /** The most of the alerts a hover shows before it scrolls: a project can have one for every agent. */
63
63
  const ALERTS_MAX_HEIGHT = 'min(24rem, 60vh)';
64
64
  const DIALOG_WIDTH = 720;
65
- /** How long the saved line stays, in milliseconds: long enough to reach Undo. */
66
- const UNDO_WINDOW = 15_000;
65
+ /** How long a toast with Undo stays, in milliseconds: long enough to reach Undo. */
66
+ export const UNDO_WINDOW = 15_000;
67
67
  /** Why nothing was written, as the builder reads it. */
68
68
  const REFUSED = {
69
69
  issues: 'Fix the issues in the editor first.',
@@ -335,7 +335,7 @@ export function ProjectSave({ project, workspace, update, onFilesChanged, onDisc
335
335
  setStep({ at: 'closed' });
336
336
  } }), step.at === 'review' && (_jsx(Button, { label: "Save", variant: "primary", isDisabled: !step.review.writable, isLoading: writing, onClick: () => {
337
337
  write(step.review);
338
- } }))] })] }) }) }) }), _jsx(AlertDialog, { isOpen: asking, onOpenChange: setAsking, title: "Discard every unsaved edit?", description: "All unsaved edits will be lost. This action cannot be reversed.", actionLabel: "Discard all", actionVariant: "destructive", onAction: () => {
338
+ } }))] })] }) }) }) }), _jsx(AlertDialog, { isOpen: asking, onOpenChange: setAsking, title: "Discard every unsaved edit?", description: "The project goes back to its files. Undo in the next message brings the edits back.", actionLabel: "Discard all", actionVariant: "destructive", onAction: () => {
339
339
  setAsking(false);
340
340
  setStep({ at: 'closed' });
341
341
  onDiscard();
@@ -21,7 +21,7 @@ import { Token } from '@astryxdesign/core/Token';
21
21
  import { Tooltip } from '@astryxdesign/core/Tooltip';
22
22
  import { TreeList } from '@astryxdesign/core/TreeList';
23
23
  import { VStack } from '@astryxdesign/core/VStack';
24
- import { IconActivity, IconAdjustmentsHorizontal, IconArrowBarToDown, IconArrowLeft, IconBrowserShare, IconCheck, IconCloud, IconCode, IconCopy, IconCopyPlus, IconFile, IconFileImport, IconFileZip, IconKey, IconMenu2, IconPlayerPlay, IconPlaylistX, IconPlus, IconRotateClockwise, IconSearch, IconSitemap, IconSparkles, IconTool, IconX, } from '@tabler/icons-react';
24
+ import { IconAdjustmentsHorizontal, IconArrowBarToDown, IconArrowLeft, IconBrowserShare, IconCheck, IconCloud, IconCode, IconCopy, IconCopyPlus, IconFile, IconFileImport, IconFileZip, IconKey, IconMenu2, IconPlayerPlay, IconPlaylistX, IconPlus, IconRotateClockwise, IconSearch, IconSitemap, IconSparkles, IconTool, IconX, } from '@tabler/icons-react';
25
25
  import { profileGraphFacet } from '@theoremjs/agents';
26
26
  import { InPlace, PaneFailure, RaisedPane, useDisclosureMotion, } from '@theoremjs/react/ui';
27
27
  import { canonical } from "../canonical.js";
@@ -37,6 +37,7 @@ import { AddProviderButton } from "./add-provider.js";
37
37
  import { useConfirmWrite } from "./confirm-write.js";
38
38
  import { ConfirmWrite, GuardrailTest, ISSUE_ROW_ATTRIBUTE, LeavePage, ListBadges, LocalConnection, ProbedAgent, ProjectAsks, QuestionLink, RowOrigins, RunsOn, WorkspaceContext, } from "./inspector-context.js";
39
39
  import { ActingAsContext, chatKeyOf, useActingAsState } from "./lib/acting-as.js";
40
+ import { runsAsConversation } from "./lib/conversation-types.js";
40
41
  import { FACET_ICON } from "./lib/facet-icons.js";
41
42
  import { movePanel } from "./lib/panel-motion.js";
42
43
  import { screenEndpoint } from "./lib/project-address.js";
@@ -66,7 +67,8 @@ import { StudioKeys, useStudioConnection, } from "./studio-connection.js";
66
67
  import { StudioHostContext, useStudioHost, } from "./studio-host.js";
67
68
  import { NAV_WIDTH } from "./studio-nav.js";
68
69
  import { StudioRunner } from "./studio-runner.js";
69
- import { ProjectSave, ProjectTokens, useProjectSave } from "./studio-save.js";
70
+ import { ProjectSave, ProjectTokens, UNDO_WINDOW, useProjectSave } from "./studio-save.js";
71
+ import { TraceButton } from "./trace-button.js";
70
72
  import { useBelowDesktop } from "./use-phone.js";
71
73
  // The tester, Settings, the map and the code view load when they first open, or once the page is idle.
72
74
  const testerPanel = () => import("./guardrail-tester.js");
@@ -189,7 +191,7 @@ function agentItems(state) {
189
191
  const isOnly = workspace.agents.length === 1;
190
192
  return workspace.agents.map((agent) => {
191
193
  const draft = libraryDraft(workspace, agent.key) ?? createBlankDraft();
192
- const name = agent.identity.agentId || 'this agent';
194
+ const name = agent.identity.agentId.trim() || 'this agent';
193
195
  const whole = resetAgent(workspace, agent.key);
194
196
  return agentItem({
195
197
  draft,
@@ -259,7 +261,7 @@ function providerItems(tree) {
259
261
  return [
260
262
  {
261
263
  id: `${id}:${agent.key}`,
262
- label: agent.identity.agentId || 'New agent',
264
+ label: agent.identity.agentId.trim() || 'Unnamed agent',
263
265
  startContent: (_jsx(Icon, { icon: PROFILE_TYPE_ICON[agent.identity.profileType || 'text'], size: "sm", color: "secondary" })),
264
266
  onClick: () => {
265
267
  onSelect(agentNodeId(agent.key, modelBindingNodeId(binding.key)));
@@ -492,7 +494,7 @@ function useChatAgents(agents) {
492
494
  const names = JSON.stringify(agents.map((agent) => [agent.key, agent.identity.agentId]));
493
495
  return useMemo(() => JSON.parse(names).map(([value, agentId]) => ({
494
496
  value,
495
- label: agentId || 'Unnamed agent',
497
+ label: agentId.trim() || 'Unnamed agent',
496
498
  })), [names]);
497
499
  }
498
500
  /** A tree group's heading and its add button. */
@@ -692,7 +694,7 @@ function issueCount(compiled) {
692
694
  /** What a host that follows along is told about the draft on screen. */
693
695
  function screenReport(draft, compiled, section) {
694
696
  return {
695
- agent: draft.identity.handle || draft.identity.agentId || 'unnamed',
697
+ agent: draft.identity.handle || draft.identity.agentId.trim() || 'unnamed',
696
698
  type: draft.identity.profileType || 'not chosen',
697
699
  issues: compiled.ok ? 0 : compiled.issues.length,
698
700
  section,
@@ -884,7 +886,9 @@ function useLeftIssues(issues, page, revealed) {
884
886
  /** Open in a new tab, for the agent being chatted with; off while the workspace has issues. */
885
887
  function OpenInNewTabButton({ compiled, chattedId, blocked, connection, isIconOnly, }) {
886
888
  const project = useProject();
887
- return (_jsx(Button, { label: "Open in a new tab", isIconOnly: isIconOnly, variant: "ghost", icon: _jsx(Icon, { icon: IconBrowserShare, size: "sm" }), isDisabled: !compiled, tooltip: blocked ??
889
+ const unserved = project?.problems.find((problem) => problem.profile === chattedId);
890
+ return (_jsx(Button, { label: "Open in a new tab", isIconOnly: isIconOnly, variant: "ghost", icon: _jsx(Icon, { icon: IconBrowserShare, size: "sm" }), isDisabled: !compiled || unserved !== undefined, tooltip: blocked ??
891
+ unserved?.message ??
888
892
  'Run this agent on a full page of its own, in a new tab, the way a person using it would see it', onClick: () => {
889
893
  const run = compiled && workspaceRunAgent(compiled, chattedId);
890
894
  if (run)
@@ -1497,6 +1501,7 @@ function usePageActions(store, view, setConversation) {
1497
1501
  setConversation((count) => count + 1);
1498
1502
  const dismiss = toast({
1499
1503
  body: message,
1504
+ autoHideDuration: UNDO_WINDOW,
1500
1505
  endContent: (_jsx(Button, { label: "Undo", variant: "ghost", size: "sm", onClick: () => {
1501
1506
  store.update(previous);
1502
1507
  dismiss();
@@ -1675,6 +1680,7 @@ function useDiscardAll({ store, filesChanged }) {
1675
1680
  filesChanged();
1676
1681
  const dismiss = toast({
1677
1682
  body: 'Discarded every unsaved edit.',
1683
+ autoHideDuration: UNDO_WINDOW,
1678
1684
  endContent: (_jsx(Button, { label: "Undo", variant: "ghost", size: "sm", onClick: () => {
1679
1685
  store.update(before);
1680
1686
  dismiss();
@@ -1788,27 +1794,41 @@ function EditorBody({ state, connection, selected, editing, issues, listBadges,
1788
1794
  }, issues: issues })) }) }) }) }) }, selected));
1789
1795
  }
1790
1796
  /** Clears the conversation and its traces; the profile stays. */
1791
- function ClearHistoryButton({ run }) {
1792
- return (_jsx(IconButton, { label: "Clear history", variant: "ghost", icon: _jsx(Icon, { icon: IconPlaylistX, size: "sm" }), tooltip: "Clear the conversation and its traces. Your profile stays.", onClick: run.clear }));
1797
+ function ClearHistoryButton({ onClear }) {
1798
+ return (_jsx(IconButton, { label: "Clear history", variant: "ghost", icon: _jsx(Icon, { icon: IconPlaylistX, size: "sm" }), tooltip: "Clear the conversation and its traces. Your profile stays.", onClick: onClear }));
1799
+ }
1800
+ /**
1801
+ * Clears the chat and puts the keyboard in the new one's composer.
1802
+ * why: the Clear history button leaves with the conversation, and focus would fall to the page.
1803
+ */
1804
+ function useClearAndFocus(run, chatRef) {
1805
+ /** The run that was cleared; the next run takes the focus. */
1806
+ const clearedRun = useRef(undefined);
1807
+ const { clear, runKey } = run;
1808
+ useEffect(() => {
1809
+ if (clearedRun.current === undefined || clearedRun.current === runKey)
1810
+ return;
1811
+ clearedRun.current = undefined;
1812
+ chatRef.current?.focus();
1813
+ }, [runKey, chatRef]);
1814
+ return useCallback(() => {
1815
+ clearedRun.current = runKey;
1816
+ clear();
1817
+ }, [clear, runKey]);
1793
1818
  }
1794
- /** The types whose conversation a trace can hold, and so open and replay. */
1795
- const NO_CONVERSATION = new Set(['decision', 'host', 'embedding', 'live']);
1796
1819
  /** A type whose conversation a trace holds, and so can open and replay. */
1797
- const holdsConversation = (payload) => payload != null && !NO_CONVERSATION.has(payload.profile.type);
1820
+ const holdsConversation = (payload) => payload != null && runsAsConversation(payload.profile.type);
1798
1821
  /** Replay exchange: switches between the live conversation and the replay, which keeps its trace. */
1799
1822
  function ReplayExchangeButton({ tracing, isIconOnly, }) {
1800
1823
  return (_jsx(Button, { label: "Replay exchange", isIconOnly: isIconOnly, variant: tracing.open ? 'secondary' : 'ghost', tooltip: tracing.open
1801
1824
  ? 'Back to the live conversation. The trace stays loaded.'
1802
- : 'Open a recorded conversation (a .trace.json file) to see what happened, then replay its messages through this agent as it is now and compare', icon: _jsx(Icon, { icon: IconFileImport, size: "sm" }), "aria-pressed": tracing.open, onClick: tracing.toggle }));
1825
+ : 'Open a recorded conversation (a .json or .jsonl trace file) to see what happened, then replay its messages through this agent as it is now and compare', icon: _jsx(Icon, { icon: IconFileImport, size: "sm" }), "aria-pressed": tracing.open, onClick: tracing.toggle }));
1803
1826
  }
1804
1827
  /** The preview's header: back to the editor, the agent to chat with, history, trace, and Export. */
1805
- function PreviewHeader({ store, chatAgents, chatWith, compile, run, connection, trace, testing, tracing, setSheet, }) {
1806
- const traceLabel = trace.open ? 'Hide trace' : 'View trace';
1828
+ function PreviewHeader({ store, chatAgents, chatWith, compile, run, connection, trace, testing, tracing, setSheet, onClear, }) {
1807
1829
  const { ref, below: iconsOnly } = useBelowDesktop();
1808
1830
  const { compiled } = compile;
1809
- return (_jsx(Section, { ref: ref, variant: "transparent", paddingInline: 3, paddingBlock: 0, children: _jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(SheetButton, { label: "Back to the editor", icon: IconArrowLeft, sheet: null, setSheet: setSheet }), _jsx(StackItem, { size: "fill", children: _jsx(ChatPicker, { agents: chatAgents, chatWith: chatWith, onChange: store.chatWith }) }), _jsx(StackItem, { size: "static", children: _jsxs(HStack, { gap: 1, vAlign: "center", children: [_jsx(ActingAsButton, { isIconOnly: iconsOnly }), compile.payload && run.isUsed && !testing && !tracing.open && (_jsx(ClearHistoryButton, { run: run })), !testing && holdsConversation(compile.payload) && (_jsx(ReplayExchangeButton, { tracing: tracing, isIconOnly: iconsOnly })), (compile.traced || tracing.open) && !testing ? (_jsx(Button, { label: traceLabel, isIconOnly: iconsOnly, variant: trace.open ? 'secondary' : 'ghost', tooltip: trace.open
1810
- ? 'Close the trace'
1811
- : 'See how each reply was made, step by step: every model and tool call, guardrail check and gate, with its timing', icon: _jsx(Icon, { icon: IconActivity, size: "sm" }), "aria-pressed": trace.open, onClick: trace.toggle })) : null, _jsx(OpenInNewTabButton, { isIconOnly: iconsOnly, compiled: compiled.ok ? compiled : undefined, chattedId: compile.chattedId, blocked: compile.blocked, connection: {
1831
+ return (_jsx(Section, { ref: ref, variant: "transparent", paddingInline: 3, paddingBlock: 0, children: _jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(SheetButton, { label: "Back to the editor", icon: IconArrowLeft, sheet: null, setSheet: setSheet }), _jsx(StackItem, { size: "fill", children: _jsx(ChatPicker, { agents: chatAgents, chatWith: chatWith, onChange: store.chatWith }) }), _jsx(StackItem, { size: "static", children: _jsxs(HStack, { gap: 1, vAlign: "center", children: [_jsx(ActingAsButton, { isIconOnly: iconsOnly }), compile.payload && run.isUsed && !testing && !tracing.open && (_jsx(ClearHistoryButton, { onClear: onClear })), !testing && holdsConversation(compile.payload) && (_jsx(ReplayExchangeButton, { tracing: tracing, isIconOnly: iconsOnly })), (compile.traced || tracing.open) && !testing ? (_jsx(TraceButton, { open: trace.open, onToggle: trace.toggle, isIconOnly: iconsOnly })) : null, _jsx(OpenInNewTabButton, { isIconOnly: iconsOnly, compiled: compiled.ok ? compiled : undefined, chattedId: compile.chattedId, blocked: compile.blocked, connection: {
1812
1832
  connectionMode: connection.mode,
1813
1833
  localBaseUrl: connection.local.baseUrl,
1814
1834
  } })] }) })] }) }));
@@ -1866,7 +1886,7 @@ function PreviewBody({ compile, run, connection, chatRef, chatWith, profileId, t
1866
1886
  const blocked = unserved ? (_jsx(PaneFailure, { title: `${unserved.profile} does not run here yet`, description: unserved.message })) : payload ? null : (_jsx(ConfigIssues, { compile: compile, chatWith: chatWith, onIssue: onIssue }));
1867
1887
  return (_jsxs(InPlace, { view: testing && payload ? (_jsx(RaisedPane, { children: (isWide) => (_jsx(Suspense, { fallback: null, children: _jsx(GuardrailTester, { payload: payload, isWide: isWide }) })) })) : null, children: [_jsx("div", { style: { display: replaying ? 'contents' : 'none' }, children: tracing }), _jsx("div", { style: { display: replaying ? 'none' : 'contents' }, children: _jsx(VStack, { height: "100%", children: _jsxs(StackItem, { size: "fill", children: [blocked, kept.map(([key, { props }]) => {
1868
1888
  const isShown = shown !== null && key === run.runKey;
1869
- return (_jsx("div", { style: { display: isShown ? 'contents' : 'none' }, children: _jsx(StudioRunner, { ...props, mode: connection.mode, runtime: connection.runtime, trace: traced ? traceOpen : undefined, chatRef: isShown ? chatRef : undefined, traces: feedOf(key) }) }, key));
1889
+ return (_jsx("div", { style: { display: isShown ? 'contents' : 'none' }, children: _jsx(StudioRunner, { ...props, runtime: connection.runtime, trace: traced ? traceOpen : undefined, chatRef: isShown ? chatRef : undefined, traces: feedOf(key) }) }, key));
1870
1890
  })] }) }) })] }));
1871
1891
  }
1872
1892
  /**
@@ -1934,6 +1954,7 @@ const PreviewPane = memo(function PreviewPane({ store, chatAgents, chatWith, com
1934
1954
  const feedOf = useRunFeeds(run.generation);
1935
1955
  const profileId = chatAgents.find((agent) => agent.value === chatWith)?.label;
1936
1956
  const sendNext = useSendAfterResume(chatRef, run.runKey);
1957
+ const clearChat = useClearAndFocus(run, chatRef);
1937
1958
  const { payload } = compile;
1938
1959
  const replay = replaying && holdsConversation(payload);
1939
1960
  // why: the console stays mounted while it holds a file, so the way back finds its replay as it was.
@@ -1944,7 +1965,7 @@ const PreviewPane = memo(function PreviewPane({ store, chatAgents, chatWith, com
1944
1965
  setReplaying(false);
1945
1966
  sendNext(text);
1946
1967
  } }) })) : null;
1947
- return (_jsx(LayoutContent, { className: "studio-preview shell-fade", isScrollable: false, padding: 0, children: _jsxs(VStack, { height: "100%", children: [_jsx(PreviewHeader, { store: store, chatAgents: chatAgents, chatWith: chatWith, compile: compile, run: run, connection: connection, trace: {
1968
+ return (_jsx(LayoutContent, { className: "studio-preview shell-fade", isScrollable: false, padding: 0, children: _jsxs(VStack, { height: "100%", children: [_jsx(PreviewHeader, { store: store, onClear: clearChat, chatAgents: chatAgents, chatWith: chatWith, compile: compile, run: run, connection: connection, trace: {
1948
1969
  open: traceOpen,
1949
1970
  toggle: () => {
1950
1971
  setTraceOpen((open) => !open);
@@ -2131,6 +2152,7 @@ function useWorkspaceTree(state, view, selected, setSheet) {
2131
2152
  update(() => to);
2132
2153
  const dismiss = toast({
2133
2154
  body,
2155
+ autoHideDuration: UNDO_WINDOW,
2134
2156
  endContent: (_jsx(Button, { label: "Undo", variant: "ghost", size: "sm", onClick: () => {
2135
2157
  update(() => workspace);
2136
2158
  dismiss();
@@ -2189,7 +2211,7 @@ function SharedLine({ entry, workspace, selected, onOpen, }) {
2189
2211
  const others = entry.agents.flatMap((key) => {
2190
2212
  const agent = workspace.agents.find((each) => each.key === key);
2191
2213
  return agent && !selected.startsWith(`${agentNodeId(key)}/`)
2192
- ? [agent.identity.agentId || 'New agent']
2214
+ ? [agent.identity.agentId.trim() || 'Unnamed agent']
2193
2215
  : [];
2194
2216
  });
2195
2217
  const count = others.length;
@@ -262,7 +262,7 @@ function SectionBody({ section, ...props }) {
262
262
  const isSection = (value) => SETTINGS_SECTIONS.includes(value);
263
263
  /** The nav's head, as the studio's tree and the docs head theirs: the name, what is open, then the search. */
264
264
  function SettingsNavHead({ project, version }) {
265
- return (_jsxs(VStack, { gap: 4, children: [_jsxs(VStack, { gap: 1, className: "studio-nav-head", children: [_jsx(Heading, { level: 3, children: "theorem studio" }), _jsx(Text, { type: "supporting", color: "secondary", children: `${project.name} · @theoremjs/agents ${version}` })] }), _jsx(Typeahead, { label: "Search", isLabelHidden: true, placeholder: "Search settings...", searchSource: settingsSource, value: null, onChange: (item) => {
265
+ return (_jsxs(VStack, { gap: 4, children: [_jsxs(VStack, { gap: 1, className: "studio-nav-head", children: [_jsx(Heading, { level: 3, children: "theorem studio" }), _jsx(Text, { type: "supporting", color: "secondary", children: `${project.name} · @theoremjs/agents ${version}` })] }), _jsx(Typeahead, { label: "Search", isLabelHidden: true, placeholder: "Search settings", searchSource: settingsSource, value: null, onChange: (item) => {
266
266
  const found = SETTINGS.find((setting) => setting.id === item?.id);
267
267
  if (found)
268
268
  showSettingsSection(found.section);
@@ -66,7 +66,10 @@ function TraceFileInput({ onImport }) {
66
66
  return;
67
67
  setReading(true);
68
68
  try {
69
- onImport({ name: file.name, records: parseTraceFile(await file.text()) });
69
+ const records = parseTraceFile(await file.text());
70
+ // why: a file the replay cannot read is refused here, where the card can say why.
71
+ replayScript(records);
72
+ onImport({ name: file.name, records });
70
73
  setProblem(undefined);
71
74
  }
72
75
  catch (error) {
@@ -130,9 +133,14 @@ function StatusBanner({ status, turns, onContinue, onLive, }) {
130
133
  case 'missing':
131
134
  return (_jsx(Banner, { status: "warning", title: `Replay stopped before ${ordinal(status.turn)}`, description: "It was sent with files, and a trace never holds a file's bytes. Continue live to send it again with yours.", endContent: live(status.turn) }));
132
135
  case 'diverged': {
133
- const { turn, call, reason } = status.divergence;
134
- return (_jsx(Banner, { status: "warning", title: `Replay stopped at ${ordinal(turn)}, model call ${String(call)}`, description: reason, endContent: live(turn) }));
136
+ const divergence = status.divergence;
137
+ const at = 'tool' in divergence
138
+ ? `the ${divergence.tool} tool`
139
+ : `${divergence.agent}'s model call ${String(divergence.call)}`;
140
+ return (_jsx(Banner, { status: "warning", title: `Replay stopped at ${ordinal(divergence.turn)}, ${at}`, description: divergence.reason, endContent: live(divergence.turn) }));
135
141
  }
142
+ case 'stopped':
143
+ return (_jsx(Banner, { status: "info", title: `Replay stopped at ${ordinal(status.turn)}`, description: "You stopped it. Continue live to go on from here with the profile's model.", endContent: live(status.turn) }));
136
144
  case 'failed':
137
145
  return (_jsx(Banner, { status: "error", title: `Replay stopped at ${ordinal(status.turn)}`, description: status.message, endContent: live(status.turn) }));
138
146
  case 'done':
@@ -161,6 +169,12 @@ function ReplayConsole({ payload, iface, trace, card, opened, script, shown, liv
161
169
  const phase = useRef(chat.phase);
162
170
  phase.current = chat.phase;
163
171
  const [from, setFrom] = useState(0);
172
+ /** The builder pressed Stop: the replay sends no further turn. */
173
+ const halted = useRef(false);
174
+ // invariant: only leaving the replay stops its reply; Continue replay restarts the loop while a resumed reply streams.
175
+ const stopReply = useRef(handleStop);
176
+ stopReply.current = handleStop;
177
+ useEffect(() => () => stopReply.current(), []);
164
178
  useEffect(() => {
165
179
  let stopped = false;
166
180
  /** Until a reply still streaming (one a stop is ending) has ended. */
@@ -171,7 +185,7 @@ function ReplayConsole({ payload, iface, trace, card, opened, script, shown, liv
171
185
  void (async () => {
172
186
  for (let turn = from; turn < script.turns.length; turn += 1) {
173
187
  await settled();
174
- if (stopped)
188
+ if (stopped || halted.current)
175
189
  return;
176
190
  if (phase.current === 'gated') {
177
191
  // The turn before waits on a gate: its reply goes on with the calls it has left.
@@ -185,7 +199,7 @@ function ReplayConsole({ payload, iface, trace, card, opened, script, shown, liv
185
199
  setStatus({ kind: 'running', turn });
186
200
  try {
187
201
  const sent = await sendText(text);
188
- if (stopped)
202
+ if (stopped || halted.current)
189
203
  return;
190
204
  if (diverged.current)
191
205
  return setStatus({ kind: 'diverged', divergence: diverged.current });
@@ -202,9 +216,8 @@ function ReplayConsole({ payload, iface, trace, card, opened, script, shown, liv
202
216
  })();
203
217
  return () => {
204
218
  stopped = true;
205
- handleStop();
206
219
  };
207
- }, [from, replay, script, sendText, handleStop]);
220
+ }, [from, replay, script, sendText]);
208
221
  const live = async (turn) => {
209
222
  const blocks = script.turns.slice(0, turn).flatMap((each) => each.blocks);
210
223
  const started = await startLive(payload, runtime, blocks);
@@ -214,8 +227,9 @@ function ReplayConsole({ payload, iface, trace, card, opened, script, shown, liv
214
227
  return (_jsx(TraceFrame, { iface: iface, feed: replayed ? traces : recorded, trace: trace, card: card({
215
228
  isRunning: status.kind === 'running',
216
229
  onStop: () => {
230
+ halted.current = true;
217
231
  handleStop();
218
- setStatus({ kind: 'done' });
232
+ setStatus((now) => (now.kind === 'running' ? { kind: 'stopped', turn: now.turn } : now));
219
233
  },
220
234
  }), conversation: _jsx(Conversation, { iface: iface, blocks: replayed ? [...chat.blocks, ...chat.streamBlocks] : recordedTranscript(script), chat: replayed ? chat : undefined, banner: replayed ? (_jsx(StatusBanner, { status: status, turns: script.turns.length, onContinue: setFrom, onLive: live })) : undefined }) }));
221
235
  }
@@ -0,0 +1,6 @@
1
+ /** View trace / Hide trace: the same control in the preview's header and a run tab's. */
2
+ export declare function TraceButton({ open, onToggle, isIconOnly, }: {
3
+ open: boolean;
4
+ onToggle: () => void;
5
+ isIconOnly: boolean;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from '@astryxdesign/core/Button';
3
+ import { Icon } from '@astryxdesign/core/Icon';
4
+ import { IconActivity } from '@tabler/icons-react';
5
+ /** View trace / Hide trace: the same control in the preview's header and a run tab's. */
6
+ export function TraceButton({ open, onToggle, isIconOnly, }) {
7
+ return (_jsx(Button, { label: open ? 'Hide trace' : 'View trace', isIconOnly: isIconOnly, variant: open ? 'secondary' : 'ghost', tooltip: open
8
+ ? 'Hide the trace'
9
+ : 'See how each reply was made, step by step: every model and tool call, guardrail check and gate, with its timing', icon: _jsx(Icon, { icon: IconActivity, size: "sm" }), "aria-pressed": open, onClick: onToggle }));
10
+ }
package/workspace.js CHANGED
@@ -1031,10 +1031,10 @@ export function modelSharers(workspace, agentKey, bindingKey, id, apiId) {
1031
1031
  return {
1032
1032
  models: own
1033
1033
  .filter((binding) => binding.key !== bindingKey && calls(binding))
1034
- .map((binding) => binding.modelId.trim() || 'new'),
1034
+ .map((binding) => binding.modelId.trim() || 'Unnamed model'),
1035
1035
  agents: workspace.agents
1036
1036
  .filter((agent) => agent.key !== agentKey && agent.modelBindings.some(calls))
1037
- .map((agent) => agent.identity.agentId.trim() || 'New agent'),
1037
+ .map((agent) => agent.identity.agentId.trim() || 'Unnamed agent'),
1038
1038
  };
1039
1039
  }
1040
1040
  /** A provider from the kernel definition `definition` under the first free id: what the + beside a provider picker adds. */
@@ -1113,10 +1113,8 @@ function scopeTree(agentKey, node) {
1113
1113
  children: node.children.map((child) => scopeTree(agentKey, child)),
1114
1114
  };
1115
1115
  }
1116
- /** Beside other agents, one with no id yet is named as an agent, not by its Identity facet. */
1117
1116
  function agentRoot(agent, providers) {
1118
- const root = scopeTree(agent.key, studioTree(draftOf(agent, [], providers)));
1119
- return agent.identity.agentId.trim() ? root : { ...root, label: 'New agent' };
1117
+ return scopeTree(agent.key, studioTree(draftOf(agent, [], providers)));
1120
1118
  }
1121
1119
  export function workspaceTree(workspace) {
1122
1120
  return {