@theoremjs/studio 0.3.4-next.679.gcdf1a3a → 0.3.4-next.693.g4ab1526

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 (141) hide show
  1. package/asks.d.ts +9 -2
  2. package/asks.js +19 -10
  3. package/browser-connection.d.ts +1 -1
  4. package/browser-connection.js +3 -1
  5. package/browser-execution.js +1 -0
  6. package/compile-workspace.js +12 -5
  7. package/compile.d.ts +4 -2
  8. package/compile.js +58 -37
  9. package/cookbooks/catalog.d.ts +2 -2
  10. package/cookbooks/catalog.js +299 -52
  11. package/cookbooks/project.js +1 -0
  12. package/cookbooks/tools.js +64 -0
  13. package/draft.d.ts +21 -5
  14. package/draft.js +25 -2
  15. package/guardrail-probe.d.ts +3 -1
  16. package/guardrail-probe.js +37 -5
  17. package/mod.d.ts +2 -2
  18. package/mod.js +2 -2
  19. package/package.json +4 -4
  20. package/page/assets/Banner-DrRNC3MG.js +4 -0
  21. package/page/assets/Center-CgO0c-qo.js +1 -0
  22. package/page/assets/{ConsoleFrame-BMf3HicW.js → ConsoleFrame-BvgFGqp2.js} +3 -3
  23. package/page/assets/{MenuBottomSheet-sVJMYa4R.js → MenuBottomSheet-BZecY8fw.js} +1 -1
  24. package/page/assets/{SchemaFields-DYormNVH.js → SchemaFields-BNNkvyyO.js} +1 -1
  25. package/page/assets/{ToolResultCharts-Ce4lVdgN.js → ToolResultCharts-C3CPsfXl.js} +1 -1
  26. package/page/assets/{TraceInspector-DHyj0IHY.js → TraceInspector-36e6ozKD.js} +1 -1
  27. package/page/assets/{TraceOverview-CeiOIqk9.js → TraceOverview-CSdJ_cYY.js} +3 -3
  28. package/page/assets/{_virtual_studio-type-sources-BwSqfSwd.js → _virtual_studio-type-sources-DSpwr3WK.js} +143 -13
  29. package/page/assets/browser-connection-dads1eyK.js +3 -0
  30. package/page/assets/browser-engine-CugH58NS.js +13 -0
  31. package/page/assets/browser-transport-GzhRiBdm.js +45 -0
  32. package/page/assets/{crypto-CD14HeXH.js → crypto-B8dqEoWf.js} +1 -1
  33. package/page/assets/{encode-files-DhoC5hWG.js → encode-files-CHeRLBO8.js} +1 -1
  34. package/page/assets/{export-agent-Cs2S0oXB.js → export-agent-botXSyoH.js} +3 -3
  35. package/page/assets/{guardrail-tester-IcJWVveC.js → guardrail-tester-DYR7EPIy.js} +2 -2
  36. package/page/assets/index-B7sK7d-l.js +153 -0
  37. package/page/assets/live-messages-DN_q2nBN.js +1 -0
  38. package/page/assets/project-address-DjxPZuyn.js +1 -0
  39. package/page/assets/reader-DHN96tSr.js +5 -0
  40. package/page/assets/{schemas-BQ9Jydzb.js → schemas-D7cgkv3L.js} +1 -1
  41. package/page/assets/shaped-data-CJQ3W_RE.js +20 -0
  42. package/page/assets/{stub-nxRsh1jo.js → stub-U6wDGe3P.js} +25 -7
  43. package/page/assets/studio-code-pane-Boy63AK2.js +8 -0
  44. package/page/assets/{studio-console-Cn-v8Vvw.js → studio-console-B7zL133d.js} +1 -1
  45. package/page/assets/studio-decision-CbRjfbvG.js +1 -0
  46. package/page/assets/studio-embedding-DQ0QrEsu.js +2 -0
  47. package/page/assets/{studio-host-console-D__Of1no.js → studio-host-console-DDA2Um2-.js} +2 -2
  48. package/page/assets/{studio-labels-CiLuAo3N.js → studio-labels-jYWBoEyP.js} +1 -1
  49. package/page/assets/studio-live-D0YRu2zQ.js +5 -0
  50. package/page/assets/studio-map-C4Ra1QqL.js +1 -0
  51. package/page/assets/studio-session-CPnJaHc-.js +1 -0
  52. package/page/assets/studio-trace-replay-D-f2p7k9.js +3 -0
  53. package/page/assets/{studio-type-checker-BbUSqqOS.js → studio-type-checker-CVNPnko-.js} +1 -1
  54. package/page/assets/tool-schema-BDG2_rlP.js +17 -0
  55. package/page/assets/{trace-record-DxgSKmYY.js → trace-record-DoXjxrmJ.js} +1 -1
  56. package/page/assets/trace-schema--4IGmLeE.js +1 -0
  57. package/page/assets/tree-CcEbNvms.js +3 -0
  58. package/page/assets/turn-client-BmOSpCgw.js +2 -0
  59. package/page/assets/{use-one-call-BZKByPJh.js → use-one-call-B3t-kfc5.js} +1 -1
  60. package/page/assets/{use-second-ticker-CEwOSS-d.js → use-second-ticker-CWjCHLG6.js} +1 -1
  61. package/page/assets/workspace-DUfaxr-g.js +1 -0
  62. package/page/index.html +20 -19
  63. package/people.d.ts +2 -0
  64. package/people.js +3 -1
  65. package/policy.js +1 -0
  66. package/providers.d.ts +2 -2
  67. package/providers.js +8 -3
  68. package/read-source.js +34 -7
  69. package/registrations.d.ts +23 -3
  70. package/runtime-scope.d.ts +6 -3
  71. package/runtime-scope.js +16 -4
  72. package/runtime.js +14 -2
  73. package/server/draft-handler.d.ts +4 -4
  74. package/server/draft-handler.js +3 -2
  75. package/server/draft-probe.d.ts +9 -1
  76. package/server/draft-probe.js +2 -1
  77. package/server/handler.js +71 -25
  78. package/server/live.d.ts +7 -1
  79. package/server/live.js +11 -4
  80. package/server/run-traces.d.ts +5 -1
  81. package/server/run-traces.js +7 -3
  82. package/server/save-new.js +5 -5
  83. package/server/save-session.js +4 -2
  84. package/server/serve.js +2 -1
  85. package/server/test-key.d.ts +2 -2
  86. package/server/test-key.js +1 -1
  87. package/slot-values.d.ts +2 -0
  88. package/slot-values.js +22 -0
  89. package/source.js +11 -4
  90. package/tool-readers.d.ts +23 -0
  91. package/tool-readers.js +60 -0
  92. package/tools.js +4 -1
  93. package/types.d.ts +3 -1
  94. package/ui/inspector-context.js +1 -1
  95. package/ui/lib/project-traces.d.ts +5 -0
  96. package/ui/lib/project-traces.js +21 -3
  97. package/ui/lib/studio-page.d.ts +6 -1
  98. package/ui/lib/studio-page.js +33 -31
  99. package/ui/lib/studio-project.d.ts +8 -1
  100. package/ui/lib/studio-project.js +19 -1
  101. package/ui/lib/studio-session.d.ts +2 -0
  102. package/ui/lib/studio-session.js +40 -2
  103. package/ui/lib/studio-store.d.ts +2 -2
  104. package/ui/lib/studio-store.js +9 -5
  105. package/ui/lib/tool-probe.d.ts +2 -0
  106. package/ui/lib/tool-probe.js +3 -2
  107. package/ui/lib/type-icons.d.ts +1 -0
  108. package/ui/lib/type-icons.js +2 -1
  109. package/ui/profile-editor.js +57 -21
  110. package/ui/studio-compare.d.ts +14 -4
  111. package/ui/studio-compare.js +58 -24
  112. package/ui/studio-live.d.ts +1 -1
  113. package/ui/studio-live.js +8 -3
  114. package/ui/studio-runner.d.ts +3 -2
  115. package/ui/studio-runner.js +16 -14
  116. package/ui/studio-screen.d.ts +1 -1
  117. package/ui/studio-screen.js +26 -20
  118. package/ui/studio-settings.js +3 -1
  119. package/ui/studio-trace-replay.js +7 -1
  120. package/workspace.js +3 -2
  121. package/page/assets/Banner-CkcwUyOn.js +0 -4
  122. package/page/assets/Center-nHS1JSux.js +0 -1
  123. package/page/assets/browser-connection-DSUHVCT5.js +0 -3
  124. package/page/assets/browser-engine-BXSD3WU8.js +0 -11
  125. package/page/assets/browser-transport-cp9y8bBz.js +0 -45
  126. package/page/assets/index-JWco7tJJ.js +0 -145
  127. package/page/assets/live-messages-CiLmR89m.js +0 -1
  128. package/page/assets/reader-DrOfMM8I.js +0 -5
  129. package/page/assets/shaped-data-H1miOZm2.js +0 -20
  130. package/page/assets/studio-code-pane-B8MOEW9g.js +0 -8
  131. package/page/assets/studio-decision-CjJ_pqdJ.js +0 -1
  132. package/page/assets/studio-embedding-Cq3ePsfC.js +0 -2
  133. package/page/assets/studio-live-DvDQbP5V.js +0 -5
  134. package/page/assets/studio-map-BZFYGG_Y.js +0 -1
  135. package/page/assets/studio-session-CjUQSXx0.js +0 -1
  136. package/page/assets/studio-trace-replay-D22FgUA5.js +0 -3
  137. package/page/assets/tool-schema-BmRYaywn.js +0 -17
  138. package/page/assets/trace-schema-9CdEyG6Q.js +0 -1
  139. package/page/assets/tree-3N-1RPZz.js +0 -3
  140. package/page/assets/turn-client-DN8PawJr.js +0 -2
  141. package/page/assets/workspace-CTSW941G.js +0 -1
@@ -13,7 +13,7 @@ import { IconInputAi, IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand
13
13
  import { createComposerPendingMessage, orderComposerPendingMessages, removeComposerPendingMessage, } from '@theoremjs/agents/interface';
14
14
  import { ChatComposerBar, DEFAULT_CHAT_MAX_WIDTH, generationOptions, InPlace, PaneFailure, PaneLoading, TheoremChat, } from '@theoremjs/react/ui';
15
15
  import { clientFailure, composerFieldsFromDraft, composerHasPayload, createHttpTransport, createTraceFeed, encodeComposerDraft, } from '@theoremjs/web/client';
16
- import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
16
+ import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
17
17
  import { atStart } from "../mod.js";
18
18
  import { useActingAs } from "./lib/acting-as.js";
19
19
  import { runsAsConversation } from "./lib/conversation-types.js";
@@ -75,6 +75,17 @@ export function useLoadedStamp(answer) {
75
75
  setLoaded(now);
76
76
  return now;
77
77
  }
78
+ /**
79
+ * What the edited side states. While edits load it still runs the last load, which refuses a
80
+ * condition only the new edits declare, so it states what that load declares.
81
+ */
82
+ export function useLoadedStated(stated, isLoaded) {
83
+ const [loaded, setLoaded] = useState(stated);
84
+ const now = isLoaded ? stated : loaded;
85
+ if (JSON.stringify(now) !== JSON.stringify(loaded))
86
+ setLoaded(now);
87
+ return now;
88
+ }
78
89
  /** A side's chat as it stands, and as it changes. Null until the side is mounted. */
79
90
  function useSideState(chat) {
80
91
  const subscribe = useCallback((listener) => (chat ? chat.subscribe(listener) : () => { }), [chat]);
@@ -397,13 +408,20 @@ function whyNot(failed, isReady) {
397
408
  * is replaced, starts from what was said. Every load seals with the studio run's one key, so the
398
409
  * edited side opens the files' side's ref and goes on from there on its own.
399
410
  */
400
- function useConversations(isEditing) {
401
- const conversations = useRef({});
411
+ function useConversations(isEditing, resumed, report) {
412
+ const conversations = useRef({ saved: resumed });
402
413
  if (!isEditing)
403
414
  conversations.current.edited = undefined;
415
+ const reporting = useRef({ isEditing, report });
416
+ useLayoutEffect(() => {
417
+ reporting.current = { isEditing, report };
418
+ });
404
419
  const [onChange] = useState(() => {
405
420
  const change = (side) => (ref) => {
406
421
  conversations.current[side] = ref;
422
+ // invariant: the page keeps one conversation, so a reload resumes what was shown.
423
+ if (side === 'edited' || !reporting.current.isEditing)
424
+ reporting.current.report?.(ref);
407
425
  };
408
426
  return { saved: change('saved'), edited: change('edited') };
409
427
  });
@@ -448,7 +466,7 @@ export function EditedSide({ refused, isLoading, hasSaved, actions, children, })
448
466
  } })), children: [_jsx(InPlace, { view: refused ? _jsx(NotRunning, { refusal: refused, actions: actions }) : null, children: children }), isLoading && _jsx(PaneLoading, { label: "Loading your edits" })] }));
449
467
  }
450
468
  /** What the comparison shows now: which sides there are, and what each one runs. */
451
- function useComparison({ project, profileId, tested, note, traces }) {
469
+ function useComparison({ project, profileId, tested, note, traces, conversation, onConversationChange, }) {
452
470
  const edits = useMemo(() => unsavedEdits(tested, project.profiles), [tested, project.profiles]);
453
471
  const pair = usePair();
454
472
  const isBusy = pair.busy.length > 0;
@@ -459,7 +477,7 @@ function useComparison({ project, profileId, tested, note, traces }) {
459
477
  // A profile the edits made a chat is another type in the files, which a chat cannot talk to.
460
478
  const chatsInFiles = !saved || runsAsConversation(saved.profileType);
461
479
  const inFiles = !isEditing || (chatsInFiles && (answer?.saved ?? project.profiles).includes(ids.saved));
462
- const { conversations, onChange } = useConversations(isEditing);
480
+ const { conversations, onChange } = useConversations(isEditing, conversation, onConversationChange);
463
481
  const stamp = useLoadedStamp(answer);
464
482
  const transports = useTransports(project, ids, stamp, { note, traces });
465
483
  const refused = answer && !answer.ok && !pending ? answer : undefined;
@@ -482,8 +500,11 @@ function useComparison({ project, profileId, tested, note, traces }) {
482
500
  * to the one side otherwise. It answers with what the edits said, and its controller is theirs.
483
501
  */
484
502
  function useChatHandle(chatRef, pair, only, canSendBoth, sharedInput) {
485
- const { send, stop, handles } = pair;
486
- useImperativeHandle(chatRef, () => ({
503
+ const { send, stop, handles, chats } = pair;
504
+ const controller = chats[only ?? 'edited'];
505
+ useImperativeHandle(
506
+ // invariant: a screen holds this handle only while the chat behind it is open.
507
+ chatRef, () => controller && {
487
508
  send: (text, options) => {
488
509
  if (only)
489
510
  return handles.current[only]?.send(text, options) ?? Promise.resolve(null);
@@ -498,13 +519,22 @@ function useChatHandle(chatRef, pair, only, canSendBoth, sharedInput) {
498
519
  else
499
520
  sharedInput.current?.focus();
500
521
  },
501
- get controller() {
502
- const chat = handles.current[only ?? 'edited']?.controller;
503
- if (!chat)
504
- throw new Error('The chat is not open yet.');
505
- return chat;
506
- },
507
- }), [only, canSendBoth, send, stop, handles, sharedInput]);
522
+ controller,
523
+ }, [only, canSendBoth, send, stop, handles, sharedInput, controller]);
524
+ }
525
+ /** The one composer under a split, or why it waits. */
526
+ function SharedSlot({ sides, edited, inputRef, handle, why, }) {
527
+ if (edited)
528
+ return _jsx(SharedComposer, { sides: sides, edited: edited, inputRef: inputRef });
529
+ return _jsx(WaitingComposer, { handle: handle, why: why ?? 'Loading your edits' });
530
+ }
531
+ /** The sides whose chats have opened. */
532
+ function openSides(pair) {
533
+ return SIDES.flatMap((side) => {
534
+ const chat = pair.chats[side];
535
+ const state = pair.states[side];
536
+ return chat && state ? [{ side, chat, state }] : [];
537
+ });
508
538
  }
509
539
  /**
510
540
  * A project's text or image profile, run by the studio's local server. While the builder has
@@ -512,20 +542,18 @@ function useChatHandle(chatRef, pair, only, canSendBoth, sharedInput) {
512
542
  * the files with the edits laid over them.
513
543
  */
514
544
  export function ProjectChat(props) {
515
- const { profileId, trace, className, chatRef, slots, context } = props;
545
+ const { profileId, trace, className, chatRef, slots, stated, savedStated, context } = props;
546
+ const { conversationView, initialText, initialFiles, initialVoice, initialPending } = props;
516
547
  const view = useComparison(props);
517
548
  const { pair, isBusy, transports, refused, isReady } = view;
549
+ const loadedStated = useLoadedStated(stated, isReady);
518
550
  const isSavedHidden = useSavedHidden();
519
551
  const showsSaved = view.inFiles && !(view.isEditing && isSavedHidden);
520
552
  const isShared = view.isShared && showsSaved;
521
553
  const only = isShared ? undefined : showsSaved ? 'saved' : 'edited';
522
554
  const sharedInput = useRef(null);
523
555
  useChatHandle(chatRef, pair, only, !isBusy && isReady, sharedInput);
524
- const shared = SIDES.flatMap((side) => {
525
- const chat = pair.chats[side];
526
- const state = pair.states[side];
527
- return chat && state ? [{ side, chat, state }] : [];
528
- });
556
+ const shared = openSides(pair);
529
557
  const common = {
530
558
  detectCodeLanguage: true,
531
559
  labels: STUDIO_LABELS,
@@ -534,13 +562,19 @@ export function ProjectChat(props) {
534
562
  slots,
535
563
  context,
536
564
  composer: !isShared,
565
+ // A greeting says where to start; both sides start at the one composer under them.
566
+ emptyState: isShared ? null : undefined,
567
+ conversationView,
568
+ initialText,
569
+ initialFiles,
570
+ initialVoice,
571
+ initialPending,
537
572
  };
538
- return (_jsxs(VStack, { height: "100%", children: [_jsx(StackItem, { size: "fill", children: _jsxs(HStack, { height: "100%", children: [_jsx(SavedSlot, { isShown: showsSaved, hasDivider: view.isShared, children: view.inFiles && (_jsx(SavedSide, { isCompared: view.isEditing, children: _jsx(TheoremChat, { ...common, transport: transports.saved,
573
+ return (_jsxs(VStack, { height: "100%", children: [_jsx(StackItem, { size: "fill", children: _jsxs(HStack, { height: "100%", children: [_jsx(SavedSlot, { isShown: showsSaved, hasDivider: view.isShared, children: view.inFiles && (_jsx(SavedSide, { isCompared: view.isEditing, children: _jsx(TheoremChat, { ...common, stated: savedStated, transport: transports.saved,
539
574
  // A side that comes back starts from what it had said.
540
- conversation: view.conversations.current.saved, onConversationChange: view.onChange.saved, chatRef: pair.refs.saved }) })) }), view.isEditing && (_jsx("div", { className: "studio-edited-slot", children: _jsx(EditedSide, { refused: refused, isLoading: !transports.edited && !refused, hasSaved: view.inFiles, children: transports.edited && (_jsx(TheoremChat, { ...common,
575
+ conversation: view.conversations.current.saved, onConversationChange: view.onChange.saved, chatRef: pair.refs.saved }) })) }), view.isEditing && (_jsx("div", { className: "studio-edited-slot", children: _jsx(EditedSide, { refused: refused, isLoading: !transports.edited && !refused, hasSaved: view.inFiles, children: transports.edited && (_jsx(TheoremChat, { ...common, stated: loadedStated,
541
576
  // A new load is a new transport: the chat reads it in place and keeps its transcript.
542
577
  transport: transports.edited, conversation: view.conversations.current.edited ?? view.conversations.current.saved, onConversationChange: view.onChange.edited,
543
578
  // Under a refusal nothing reaches it: the edits it ran are not loaded.
544
- chatRef: refused ? undefined : pair.refs.edited })) }) }, "edited"))] }) }), isShared &&
545
- (isReady && pair.states.edited ? (_jsx(SharedComposer, { sides: shared, edited: pair.states.edited, inputRef: sharedInput })) : (_jsx(WaitingComposer, { handle: profileId, why: whyNot(refused !== undefined, isReady) ?? 'Loading your edits' })))] }));
579
+ chatRef: refused ? undefined : pair.refs.edited })) }) }, "edited"))] }) }), isShared && (_jsx(SharedSlot, { sides: shared, edited: isReady ? (pair.states.edited ?? undefined) : undefined, inputRef: sharedInput, handle: profileId, why: whyNot(refused !== undefined, isReady) }))] }));
546
580
  }
@@ -2,7 +2,7 @@ import { type LiveRunnerProps } from '@theoremjs/react/live';
2
2
  import { type StudioBrowserRuntime } from '../browser.ts';
3
3
  import { type StudioRunPayload } from '../mod.ts';
4
4
  /** What a live call is run with, wherever it runs. */
5
- export type StudioLiveProps = Pick<LiveRunnerProps, 'trace' | 'slots' | 'context'> & {
5
+ export type StudioLiveProps = Pick<LiveRunnerProps, 'trace' | 'slots' | 'stated' | 'context'> & {
6
6
  payload: StudioRunPayload;
7
7
  /** Called as each call starts. */
8
8
  note: () => void;
package/ui/studio-live.js CHANGED
@@ -3,6 +3,8 @@ import { LiveRunner } from '@theoremjs/react/live';
3
3
  import { useMemo } from 'react';
4
4
  import { browserStudioLiveConnection } from "../browser.js";
5
5
  import { studioInterface, studioLiveConnection, studioPageTools, } from "../mod.js";
6
+ import { useActingAs } from "./lib/acting-as.js";
7
+ import { liveSocketAddress } from "./lib/project-traces.js";
6
8
  import { STUDIO_LABELS } from "./lib/studio-labels.js";
7
9
  /** A live profile's call: in the browser's runtime when there is one, else through the studio's server. */
8
10
  export function StudioLive({ runtime, ...props }) {
@@ -11,9 +13,12 @@ export function StudioLive({ runtime, ...props }) {
11
13
  }
12
14
  /** A project's live profile: the call runs in the project, through the studio's local server. */
13
15
  export function ProjectLive({ endpoint, ...props }) {
14
- return (_jsx(LiveView, { ...props, connect: () => ({ createSocket: () => new WebSocket(endpoint.replace(/^http/, 'ws')) }) }));
16
+ const { actingAs } = useActingAs();
17
+ return (_jsx(LiveView, { ...props, connect: () => ({
18
+ createSocket: () => new WebSocket(liveSocketAddress(endpoint, actingAs)),
19
+ }) }));
15
20
  }
16
- function LiveView({ payload, note, connect, trace, slots, context, }) {
21
+ function LiveView({ payload, note, connect, trace, slots, stated, context, }) {
17
22
  const iface = useMemo(() => studioInterface(payload), [payload]);
18
23
  /** The studio's page answers each page tool with the tool's stub. */
19
24
  const pageTools = useMemo(() => studioPageTools(payload), [payload]);
@@ -22,5 +27,5 @@ function LiveView({ payload, note, connect, trace, slots, context, }) {
22
27
  return (_jsx(LiveRunner, { labels: STUDIO_LABELS, iface: iface, connection: () => {
23
28
  note();
24
29
  return connect();
25
- }, trace: trace, slots: slots, context: context, pageTools: pageTools }));
30
+ }, trace: trace, slots: slots, stated: stated, context: context, pageTools: pageTools }));
26
31
  }
@@ -15,8 +15,7 @@ export interface StudioRunnerProps {
15
15
  /** Called on each request the conversation sends: a turn, call, decision, or live session. */
16
16
  onActivity?: () => void;
17
17
  /**
18
- * The ref of a chat conversation to resume, as `onConversationChange` reported it (text and
19
- * image agents run in the page). A project's chat is not resumed: its key is the run's.
18
+ * The ref of a chat conversation to resume, as `onConversationChange` reported it.
20
19
  */
21
20
  conversation?: ChatProps['conversation'];
22
21
  /** The conversation under `conversation` as the server showed it, drawn at once. */
@@ -33,6 +32,8 @@ export interface StudioRunnerProps {
33
32
  chatRef?: ChatProps['chatRef'];
34
33
  /** The value the page picked for each slot, for a chat's turns and a call's start. */
35
34
  slots?: ChatProps['slots'];
35
+ /** What a run of a profile states: it declares its own conditions. */
36
+ statedOf?: (of: StudioRunPayload) => ChatProps['stated'];
36
37
  /** What the page tells the agent. */
37
38
  context?: ChatProps['context'];
38
39
  /**
@@ -15,7 +15,7 @@ import { pageConversationKey } from "./lib/studio-conversation.js";
15
15
  import { STUDIO_LABELS } from "./lib/studio-labels.js";
16
16
  import { editedProfileEndpoint, projectProfileEndpoint, useProject, } from "./lib/studio-project.js";
17
17
  import { warmWhenIdle } from "./lib/when-idle.js";
18
- import { EditedSide, ProjectChat, SavedSide, SavedSlot, unsavedEdits, useEditedLoad, useLoadedStamp, useSavedHidden, } from "./studio-compare.js";
18
+ import { EditedSide, ProjectChat, SavedSide, SavedSlot, unsavedEdits, useEditedLoad, useLoadedStamp, useLoadedStated, useSavedHidden, } from "./studio-compare.js";
19
19
  import { ChooseConflictsContext } from "./studio-conflicts.js";
20
20
  import { clearRemoves, useProjectSave } from "./studio-save.js";
21
21
  // Each type that is not a chat loads when an agent of it first runs, or once the page is idle.
@@ -58,16 +58,16 @@ export function StudioRunner({ onActivity, traces: given, ...props }) {
58
58
  }, []);
59
59
  return (_jsx(Suspense, { fallback: _jsx(RunLoading, {}), children: _jsx(Run, { ...props, project: project, traces: traces, note: note }) }));
60
60
  }
61
- function Run({ payload, 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, statedOf, context, tested, project, traces, note, }) {
62
62
  if (project)
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 }));
63
+ return (_jsx(ProjectRun, { project: project, payload: payload, traces: traces, trace: trace, className: className, flush: flush, columns: columns, note: note, conversation: conversation, conversationView: conversationView, initialText: initialText, initialFiles: initialFiles, initialVoice: initialVoice, initialPending: initialPending, onConversationChange: onConversationChange, chatRef: chatRef, slots: slots, statedOf: statedOf, context: context, tested: tested }));
64
64
  if (payload.profile.type === 'decision')
65
65
  return (_jsx(StudioDecision, { payload: payload, runtime: runtime, traces: traces, trace: trace, className: className, onActivity: note, flush: flush, columns: columns }));
66
66
  if (payload.profile.type === 'host')
67
67
  return (_jsx(StudioHostConsole, { payload: payload, runtime: runtime, traces: traces, trace: trace, className: className, onActivity: note, flush: flush, columns: columns }));
68
68
  if (payload.profile.type === 'embedding')
69
69
  return (_jsx(StudioEmbedding, { payload: payload, runtime: runtime, traces: traces, trace: trace, className: className, onActivity: note, flush: flush, columns: columns }));
70
- return (_jsx(TurnRun, { payload: payload, runtime: runtime, traces: traces, trace: trace, className: className, note: note, conversation: conversation, conversationView: conversationView, initialText: initialText, initialFiles: initialFiles, initialVoice: initialVoice, initialPending: initialPending, onConversationChange: onConversationChange, chatRef: chatRef, slots: slots, context: context }));
70
+ return (_jsx(TurnRun, { payload: payload, runtime: runtime, traces: traces, trace: trace, className: className, note: note, conversation: conversation, conversationView: conversationView, initialText: initialText, initialFiles: initialFiles, initialVoice: initialVoice, initialPending: initialPending, onConversationChange: onConversationChange, chatRef: chatRef, slots: slots, statedOf: statedOf, context: context }));
71
71
  }
72
72
  /**
73
73
  * The two ways out of a run that waits on a Save: write the edits, or drop them. Dropping an
@@ -116,7 +116,7 @@ function savedPayload(edits, files, payload) {
116
116
  return { ...payload, agentId, profile, customTools, structured, questions, dependencies };
117
117
  }
118
118
  /** One profile on one endpoint, as its type runs: a chat, a decision, an embedding, a tool console, or a call. */
119
- function SideRun({ payload, endpoint, load, traces, note, trace, className, flush, columns, chatRef, slots, context, }) {
119
+ function SideRun({ payload, endpoint, load, traces, note, trace, className, flush, columns, chatRef, slots, stated, context, }) {
120
120
  const { type } = payload.profile;
121
121
  // One per load, so each transport below is made again when the edits load again.
122
122
  const at = useMemo(() => ({ endpoint, load }), [endpoint, load]);
@@ -136,7 +136,7 @@ function SideRun({ payload, endpoint, load, traces, note, trace, className, flus
136
136
  ? noting({ ...createEmbeddingTransport({ endpoint: at.endpoint }), traces }, note)
137
137
  : null, [type, at, traces, note]);
138
138
  if (chat)
139
- return (_jsx(TheoremChat, { detectCodeLanguage: true, labels: STUDIO_LABELS, transport: chat, pageTools: pageTools, trace: trace, className: className, chatRef: chatRef, slots: slots, context: context }));
139
+ return (_jsx(TheoremChat, { detectCodeLanguage: true, labels: STUDIO_LABELS, transport: chat, pageTools: pageTools, trace: trace, className: className, chatRef: chatRef, slots: slots, stated: stated, context: context }));
140
140
  const view = { payload, trace, flush, columns, className };
141
141
  if (decision)
142
142
  return _jsx(DecisionView, { ...view, transport: decision });
@@ -144,20 +144,21 @@ function SideRun({ payload, endpoint, load, traces, note, trace, className, flus
144
144
  return _jsx(EmbeddingView, { ...view, transport: embedding });
145
145
  if (host)
146
146
  return _jsx(HostView, { ...view, transport: host });
147
- return (_jsx(ProjectLive, { payload: payload, endpoint: endpoint, note: note, trace: trace, slots: slots, context: context }));
147
+ return (_jsx(ProjectLive, { payload: payload, endpoint: endpoint, note: note, trace: trace, slots: slots, stated: stated, context: context }));
148
148
  }
149
149
  /**
150
150
  * A project's profile with edits the files do not hold, where either side is not a chat: the
151
151
  * files' run and the edits' run side by side, each its own. The files' side can be put away.
152
152
  */
153
- function ProjectSides({ project, payload, saved, edits, traces, chatRef, ...shared }) {
153
+ function ProjectSides({ project, payload, saved, edits, traces, chatRef, statedOf, ...shared }) {
154
154
  const { answer, pending } = useEditedLoad(project, edits, false);
155
155
  const stamp = useLoadedStamp(answer);
156
156
  const refused = answer && !answer.ok && !pending ? answer : undefined;
157
+ const stated = useLoadedStated(statedOf?.(payload), !pending && !refused);
157
158
  const isSavedHidden = useSavedHidden();
158
159
  // The edited side's own feed, so its traces are not the files' side's.
159
160
  const [editedTraces] = useState(createTraceFeed);
160
- return (_jsxs(HStack, { height: "100%", children: [_jsx(SavedSlot, { isShown: !isSavedHidden, hasDivider: true, children: saved && (_jsx(SavedSide, { children: _jsx(SideRun, { ...shared, payload: saved, endpoint: projectProfileEndpoint(project, saved.agentId), traces: traces }) })) }), _jsx("div", { className: "studio-edited-slot", children: _jsx(EditedSide, { refused: refused, isLoading: stamp === undefined && !refused, hasSaved: saved !== undefined, actions: _jsx(UnsavedActions, { agentId: payload.agentId, isNew: clearRemoves(edits, payload.agentId, project.profiles) }), children: stamp !== undefined && (_jsx(SideRun, { ...shared, load: stamp, payload: payload, endpoint: editedProfileEndpoint(project, payload.agentId), traces: editedTraces, chatRef: chatRef })) }) }, "edited")] }));
161
+ return (_jsxs(HStack, { height: "100%", children: [_jsx(SavedSlot, { isShown: !isSavedHidden, hasDivider: true, children: saved && (_jsx(SavedSide, { children: _jsx(SideRun, { ...shared, payload: saved, stated: statedOf?.(saved), endpoint: projectProfileEndpoint(project, saved.agentId), traces: traces }) })) }), _jsx("div", { className: "studio-edited-slot", children: _jsx(EditedSide, { refused: refused, isLoading: stamp === undefined && !refused, hasSaved: saved !== undefined, actions: _jsx(UnsavedActions, { agentId: payload.agentId, isNew: clearRemoves(edits, payload.agentId, project.profiles) }), children: stamp !== undefined && (_jsx(SideRun, { ...shared, load: stamp, payload: payload, stated: stated, endpoint: editedProfileEndpoint(project, payload.agentId), traces: editedTraces, chatRef: chatRef })) }) }, "edited")] }));
161
162
  }
162
163
  /**
163
164
  * A project's profile, run by the studio's local server: the project's own tools and models.
@@ -165,7 +166,7 @@ function ProjectSides({ project, payload, saved, edits, traces, chatRef, ...shar
165
166
  * and as the files with the edits laid over them. Two chats share one message.
166
167
  */
167
168
  function ProjectRun({ project, tested, ...run }) {
168
- const { payload } = run;
169
+ const { payload, statedOf } = run;
169
170
  const edits = useMemo(() => unsavedEdits(tested, project.profiles), [tested, project.profiles]);
170
171
  const starts = edits?.starts;
171
172
  const providers = edits?.providers;
@@ -173,12 +174,13 @@ function ProjectRun({ project, tested, ...run }) {
173
174
  const files = useMemo(() => (starts && providers ? compileFiles(starts, providers, project.profiles) : undefined), [starts, providers, project.profiles]);
174
175
  const saved = useMemo(() => (edits && files ? savedPayload(edits, files, payload) : undefined), [edits, files, payload]);
175
176
  if (isChat(payload) && (!saved || isChat(saved)))
176
- return (_jsx(ProjectChat, { project: project, profileId: payload.agentId, tested: tested, note: run.note, traces: run.traces, trace: run.trace, className: run.className, chatRef: run.chatRef, slots: run.slots, context: run.context }));
177
+ return (_jsx(ProjectChat, { project: project, profileId: payload.agentId, tested: tested, note: run.note, traces: run.traces, trace: run.trace, className: run.className, conversation: run.conversation, conversationView: run.conversationView, initialText: run.initialText, initialFiles: run.initialFiles, initialVoice: run.initialVoice, initialPending: run.initialPending, onConversationChange: run.onConversationChange, chatRef: run.chatRef, slots: run.slots, stated: statedOf?.(payload), savedStated: statedOf?.(saved ?? payload), context: run.context }));
177
178
  if (!edits)
178
- return _jsx(SideRun, { ...run, endpoint: projectProfileEndpoint(project, payload.agentId) });
179
+ return (_jsx(SideRun, { ...run, stated: statedOf?.(payload), endpoint: projectProfileEndpoint(project, payload.agentId) }));
179
180
  return _jsx(ProjectSides, { ...run, project: project, saved: saved, edits: edits });
180
181
  }
181
- function TurnRun({ payload, runtime, traces, trace, className, note, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, slots, context, }) {
182
+ function TurnRun({ payload, runtime, traces, trace, className, note, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, slots, statedOf, context, }) {
183
+ const stated = statedOf?.(payload);
182
184
  const iface = useMemo(() => studioInterface(payload), [payload]);
183
185
  /** The studio's page answers each page tool with the tool's stub. */
184
186
  const pageTools = useMemo(() => studioPageTools(payload), [payload]);
@@ -188,5 +190,5 @@ function TurnRun({ payload, runtime, traces, trace, className, note, conversatio
188
190
  traces,
189
191
  })
190
192
  : createStudioTransport(payload, { traces }), note), [payload, runtime, traces, note]);
191
- return iface.type === 'live' ? (_jsx(StudioLive, { payload: payload, runtime: runtime, note: note, trace: trace, slots: slots, context: context })) : (_jsx(TheoremChat, { detectCodeLanguage: true, labels: STUDIO_LABELS, transport: transport, trace: trace, className: className, conversation: conversation, conversationView: conversationView, initialText: initialText, initialFiles: initialFiles, initialVoice: initialVoice, initialPending: initialPending, onConversationChange: onConversationChange, chatRef: chatRef, slots: slots, context: context, pageTools: pageTools }));
193
+ return iface.type === 'live' ? (_jsx(StudioLive, { payload: payload, runtime: runtime, note: note, trace: trace, slots: slots, stated: stated, context: context })) : (_jsx(TheoremChat, { detectCodeLanguage: true, labels: STUDIO_LABELS, transport: transport, trace: trace, className: className, conversation: conversation, conversationView: conversationView, initialText: initialText, initialFiles: initialFiles, initialVoice: initialVoice, initialPending: initialPending, onConversationChange: onConversationChange, chatRef: chatRef, slots: slots, stated: stated, context: context, pageTools: pageTools }));
192
194
  }
@@ -26,7 +26,7 @@ declare function useStudioWorkspace(start: RestoredStudio, project: ProjectSessi
26
26
  setQuiet: (quiet: boolean) => void;
27
27
  cancelShared: () => void;
28
28
  standOn: (files: string) => void;
29
- flush(): void;
29
+ flush(isLeaving?: boolean): void;
30
30
  };
31
31
  workspace: StudioWorkspace;
32
32
  draft: StudioDraft;
@@ -525,12 +525,6 @@ function editorTitle(draft, id) {
525
525
  return nodeLabel(studioTree(draft), id);
526
526
  return profileGraphFacet(ref.facet)?.label;
527
527
  }
528
- /** The editor's heading: Tools with the tools list and no tool open; else the open node's title. */
529
- function headingOf(list, editing, title) {
530
- return list === 'tools' && toolSpecKeyOf(editing) === undefined
531
- ? profileGraphFacet('tools')?.label
532
- : title;
533
- }
534
528
  /** Waits before compiling after an edit, so typing doesn't recompile on every key. */
535
529
  const COMPILE_DEBOUNCE_MS = 300;
536
530
  /** The part of a compile the agent runs from: what the run tab and the preview both take. */
@@ -968,13 +962,13 @@ function useStudioWorkspace(start, project) {
968
962
  store.update(change);
969
963
  }, [store]);
970
964
  useEffect(() => {
971
- const flush = () => {
972
- store.flush();
965
+ const leave = () => {
966
+ store.flush(true);
973
967
  };
974
- globalThis.addEventListener('pagehide', flush);
968
+ globalThis.addEventListener('pagehide', leave);
975
969
  return () => {
976
- globalThis.removeEventListener('pagehide', flush);
977
- flush();
970
+ globalThis.removeEventListener('pagehide', leave);
971
+ store.flush();
978
972
  };
979
973
  }, [store]);
980
974
  const { files, refreshOrigins, filesChanged, conflict, settle, showConflict, watchFiles } = useProjectFiles(project, store);
@@ -1103,14 +1097,19 @@ function useProjectFiles(project, store) {
1103
1097
  keep(conflict.read);
1104
1098
  setConflict(undefined);
1105
1099
  }, [conflict, project, store, keep]);
1100
+ const [watch, setWatch] = useState({ available: false, on: getPref('watch') === 'on' });
1101
+ const watching = useRef(watch.on);
1106
1102
  useEffect(() => {
1107
- globalThis.addEventListener('focus', refreshOrigins);
1103
+ // why: coming back from the editor is when its saves wait; with the watch off they keep waiting.
1104
+ const onFocus = () => {
1105
+ if (watching.current)
1106
+ refreshOrigins();
1107
+ };
1108
+ globalThis.addEventListener('focus', onFocus);
1108
1109
  return () => {
1109
- globalThis.removeEventListener('focus', refreshOrigins);
1110
+ globalThis.removeEventListener('focus', onFocus);
1110
1111
  };
1111
1112
  }, [refreshOrigins]);
1112
- const [watch, setWatch] = useState({ available: false, on: getPref('watch') === 'on' });
1113
- const watching = useRef(watch.on);
1114
1113
  const setWatching = useCallback((on) => {
1115
1114
  watching.current = on;
1116
1115
  setPref('watch', on ? 'on' : 'off');
@@ -1859,6 +1858,7 @@ function PreviewBody({ compile, run, connection, chatRef, chatWith, profileId, t
1859
1858
  const pageInputs = useMemo(() => (payload ? pageInputsOf(payload) : null), [payload]);
1860
1859
  const [pageValues] = usePageValues(chatWith);
1861
1860
  const sent = useMemo(() => sentPageValues(pageInputs, pageValues), [pageInputs, pageValues]);
1861
+ const statedOf = useCallback((of) => sentPageValues(pageInputsOf(of), pageValues).stated, [pageValues]);
1862
1862
  const shown = payload && !unserved
1863
1863
  ? {
1864
1864
  chatKey: run.chatKey,
@@ -1876,6 +1876,7 @@ function PreviewBody({ compile, run, connection, chatRef, chatWith, profileId, t
1876
1876
  clearConversation(run.chatKey);
1877
1877
  },
1878
1878
  slots: sent.slots,
1879
+ statedOf,
1879
1880
  context: sent.context,
1880
1881
  tested,
1881
1882
  },
@@ -2112,7 +2113,7 @@ function Studio({ opened }) {
2112
2113
  }
2113
2114
  : null, [compile.payload, testing, setSheet]);
2114
2115
  return (_jsx(ProjectContext.Provider, { value: project, children: _jsx(ActingAsContext.Provider, { value: actingAs, children: _jsx(ConfirmWrite, { value: asking.confirm, children: _jsxs(ProjectAsks, { value: state.asks ?? NO_ASKS, children: [asking.dialog, _jsx(SharedChange, { store: state.store }), _jsx(SaveScope, { project: project, state: state, blocked: Boolean(compile.blocked), children: _jsx(QuestionLink, { value: questionLink, children: _jsx(GuardrailTest.Provider, { value: guardrailTest, children: _jsx(Layout, { ref: frame.layoutCallbackRef, className: frameClass(sheet, view.mapOpen, view.settingsOpen), padding: 0, start: _jsx(SidePanel, { frame: frame, tree: tree, draft: draft, onAddAgent: addAgentFrom, setSheet: setSheet, settings: view.settingsOpen &&
2115
- project && (_jsx(SettingsPane, { state: state, connection: connection, project: project, setConversation: run.setConversation })), map: view.mapOpen && (_jsx(Suspense, { fallback: null, children: _jsx(StudioMap, { workspace: state.workspace, shared: state.shared, selected: view.keysOpen ? '' : selected, onOpen: view.open, onClose: closeMap }) })), children: _jsx(EditorColumn, { heading: view.keysOpen ? 'Keys' : headingOf(tree.list, editing, title), state: state, connection: connection, view: view, compile: compile, selected: selected, editing: editing, frame: frame, issueReveal: issueReveal, goToIssue: goToIssue, copy: copy, setSheet: setSheet }) }), content: _jsx(PreviewPane, { store: store, chatAgents: chatAgents, chatWith: state.workspace.chatWith, compile: compile, run: run, connection: connection, chatRef: chatRef, setSheet: setSheet, onIssue: goToIssue, testing: testing && Boolean(compile.payload) }) }) }) }) })] }) }) }) }));
2116
+ project && (_jsx(SettingsPane, { state: state, connection: connection, project: project, setConversation: run.setConversation })), map: view.mapOpen && (_jsx(Suspense, { fallback: null, children: _jsx(StudioMap, { workspace: state.workspace, shared: state.shared, selected: view.keysOpen ? '' : selected, onOpen: view.open, onClose: closeMap }) })), children: _jsx(EditorColumn, { heading: view.keysOpen ? 'Keys' : title, state: state, connection: connection, view: view, compile: compile, selected: selected, editing: editing, frame: frame, issueReveal: issueReveal, goToIssue: goToIssue, copy: copy, setSheet: setSheet }) }), content: _jsx(PreviewPane, { store: store, chatAgents: chatAgents, chatWith: state.workspace.chatWith, compile: compile, run: run, connection: connection, chatRef: chatRef, setSheet: setSheet, onIssue: goToIssue, testing: testing && Boolean(compile.payload) }) }) }) }) })] }) }) }) }));
2116
2117
  }
2117
2118
  /** Save for the screen under it, when the studio is open on a project. */
2118
2119
  function SaveScope({ project, state, blocked, children, }) {
@@ -2217,11 +2218,16 @@ function SharedLine({ entry, workspace, selected, onOpen, }) {
2217
2218
  return (_jsx(Section, { variant: "transparent", padding: 3, children: _jsx(Banner, { status: "info", title: `${entry.setting.label} · used by ${String(count)} other ${count === 1 ? 'profile' : 'profiles'}`, description: `${declaredAt(entry)}. A change here changes ${others.join(', ')} too.`, endContent: onOpen && _jsx(Button, { label: "Open", variant: "ghost", size: "sm", onClick: onOpen }) }) }));
2218
2219
  }
2219
2220
  /** Over a node one place in the project's files sets whole: what sets it, where, and the way there. */
2220
- function OriginBanner({ origin, onOpen }) {
2221
+ function OriginBanner({ origin, unloaded, onOpen, }) {
2221
2222
  const place = originPlace(origin);
2223
+ const broken = unloaded && origin.kind === 'unfound';
2222
2224
  // The cause is the title. Here: what it does to this page, then the way out.
2223
- const way = place ? `Edit it at ${place}.` : originWay(origin);
2224
- return (_jsx(Section, { variant: "transparent", padding: 3, children: _jsx(Banner, { status: "info", title: originLabel(origin), description: `Read-only here. ${way}`, endContent: place && _jsx(Button, { label: "Open", variant: "ghost", size: "sm", onClick: onOpen }) }) }));
2225
+ const way = broken
2226
+ ? 'The alert above says what stopped them.'
2227
+ : place
2228
+ ? `Edit it at ${place}.`
2229
+ : originWay(origin);
2230
+ return (_jsx(Section, { variant: "transparent", padding: 3, children: _jsx(Banner, { status: "info", title: broken ? 'Your files stopped loading' : originLabel(origin), description: `Read-only here. ${way}`, endContent: place && _jsx(Button, { label: "Open", variant: "ghost", size: "sm", onClick: onOpen }) }) }));
2225
2231
  }
2226
2232
  /** The editor column: its toolbar over the Keys panel, the open node's editor, or its code. */
2227
2233
  function EditorColumn({ heading, state, connection, view, compile, selected, editing, frame, issueReveal, goToIssue, copy, setSheet, }) {
@@ -2248,7 +2254,7 @@ function EditorColumn({ heading, state, connection, view, compile, selected, edi
2248
2254
  line: shared.setting.line,
2249
2255
  });
2250
2256
  }
2251
- : undefined })), said && (_jsx(OriginBanner, { origin: said, onOpen: () => {
2257
+ : undefined })), said && (_jsx(OriginBanner, { origin: said, unloaded: state.files?.unloaded !== undefined, onOpen: () => {
2252
2258
  openOrigin(said);
2253
2259
  } })), _jsx(StackItem, { size: "fill", children: _jsx(RowOrigins, { value: rowOrigins, children: _jsx(LeavePage, { value: leavePage, children: _jsx(EditorColumnBody, { state: state, connection: connection, view: view, compile: compile, rowIssues: shown, selected: selected, editing: editing, frame: frame, editorRef: editorRef }) }) }) })] }));
2254
2260
  }
@@ -250,7 +250,9 @@ function SectionBody({ section, ...props }) {
250
250
  case 'confirmations':
251
251
  return _jsx(ConfirmationSettings, { shared: props.shared });
252
252
  case 'keys':
253
- return (_jsx(Group, { title: "Model keys", about: "Your own keys, to run an agent with. Never saved, never written to your project.", children: props.keys }));
253
+ return (_jsx(Group, { title: "Model keys", about: props.project
254
+ ? "This project's runs sign with the keys in its entry's provider vault. The studio does not read or change them."
255
+ : 'Your own keys, to run an agent with. Never saved, never written to your project.', children: props.project ? null : props.keys }));
254
256
  case 'people':
255
257
  return _jsx(PeopleSettings, { project: props.project });
256
258
  case 'project':
@@ -25,8 +25,10 @@ import { createTraceFeed, recordedFeed, } from '@theoremjs/web/client';
25
25
  import { useEffect, useMemo, useRef, useState } from 'react';
26
26
  import { createBrowserStudioTransport, startBrowserStudioConversation, } from "../browser.js";
27
27
  import { createReplay, parseTraceFile, recordedPayload, recordedTranscript, replayScripts, startStudioConversation, studioInterface, studioPageTools, } from "../mod.js";
28
+ import { useActingAs } from "./lib/acting-as.js";
28
29
  import { pageConversationKey } from "./lib/studio-conversation.js";
29
30
  import { STUDIO_LABELS } from "./lib/studio-labels.js";
31
+ import { startProjectConversation, useProject } from "./lib/studio-project.js";
30
32
  /**
31
33
  * A live conversation on `blocks`, kept where the live chat keeps its own: sealed in the page
32
34
  * when it runs there, else in this visitor's session on the server.
@@ -153,6 +155,8 @@ function StatusBanner({ status, turns, onContinue, onLive, }) {
153
155
  }
154
156
  /** A replay of the imported trace: driven turn by turn, beside what the trace recorded. */
155
157
  function ReplayConsole({ payload, iface, trace, card, records, script, shown, liveTools, runtime, onLive, }) {
158
+ const project = useProject();
159
+ const { actingAs } = useActingAs();
156
160
  const diverged = useRef(undefined);
157
161
  const [status, setStatus] = useState({ kind: 'running', turn: 0 });
158
162
  const [traces] = useState(createTraceFeed);
@@ -222,7 +226,9 @@ function ReplayConsole({ payload, iface, trace, card, records, script, shown, li
222
226
  }, [from, replay, script, sendText]);
223
227
  const live = async (turn) => {
224
228
  const blocks = script.turns.slice(0, turn).flatMap((each) => each.blocks);
225
- const started = await startLive(payload, runtime, blocks);
229
+ const started = project
230
+ ? await startProjectConversation(project, payload.agentId, blocks, actingAs)
231
+ : await startLive(payload, runtime, blocks);
226
232
  onLive({ ...started, text: script.turns[turn]?.text ?? '' });
227
233
  };
228
234
  const replayed = shown === 'replayed';
package/workspace.js CHANGED
@@ -608,11 +608,12 @@ export function filesPrint(workspace) {
608
608
  export function editedSince(workspace, files) {
609
609
  return filesPrint(workspace) !== files;
610
610
  }
611
- const DRAFT_KEY = /^(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}$/;
611
+ const KEY_SHAPE = '(agent|line|model|tool|question|criterion|reference)-[0-9a-f]{8}';
612
+ const DRAFT_KEY = new RegExp(`^${KEY_SHAPE}$`);
612
613
  /** A value as text with each key named by where it first stands, so two opens of one thing read the same. */
613
614
  function keyless(value) {
614
615
  const names = new Map();
615
- return JSON.stringify(value).replace(/\b(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}\b/g, (key) => {
616
+ return JSON.stringify(value).replace(new RegExp(`\\b${KEY_SHAPE}\\b`, 'g'), (key) => {
616
617
  if (!names.has(key))
617
618
  names.set(key, `#${names.size}`);
618
619
  return names.get(key) ?? key;