@theoremjs/studio 0.3.4-next.679.gcdf1a3a → 0.3.4-next.711.g78e504a

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 (161) hide show
  1. package/agreement.js +35 -5
  2. package/browser-connection.d.ts +1 -1
  3. package/browser-connection.js +3 -1
  4. package/browser-execution.js +1 -0
  5. package/compile-workspace.js +12 -5
  6. package/compile.d.ts +5 -3
  7. package/compile.js +80 -36
  8. package/cookbooks/catalog.d.ts +2 -2
  9. package/cookbooks/catalog.js +296 -51
  10. package/cookbooks/project.js +1 -0
  11. package/cookbooks/tools.js +64 -0
  12. package/draft.d.ts +23 -4
  13. package/draft.js +25 -2
  14. package/guardrail-probe.d.ts +3 -1
  15. package/guardrail-probe.js +37 -5
  16. package/mod.d.ts +2 -3
  17. package/mod.js +2 -3
  18. package/package.json +4 -4
  19. package/page/assets/Banner-GFaYsfrc.js +3 -0
  20. package/page/assets/Center-CgO0c-qo.js +1 -0
  21. package/page/assets/{ConsoleFrame-BMf3HicW.js → ConsoleFrame-KmyDVQkS.js} +3 -3
  22. package/page/assets/{MenuBottomSheet-sVJMYa4R.js → MenuBottomSheet-BSQO5V7g.js} +1 -1
  23. package/page/assets/{SchemaFields-DYormNVH.js → SchemaFields-CIsMisSq.js} +1 -1
  24. package/page/assets/{ToolResultCharts-Ce4lVdgN.js → ToolResultCharts-95plvcj4.js} +1 -1
  25. package/page/assets/{TraceInspector-DHyj0IHY.js → TraceInspector-D2113s73.js} +1 -1
  26. package/page/assets/{TraceOverview-CeiOIqk9.js → TraceOverview-Bz2EnBzL.js} +3 -3
  27. package/page/assets/{_virtual_studio-type-sources-BwSqfSwd.js → _virtual_studio-type-sources-La9AcR1O.js} +360 -97
  28. package/page/assets/browser-connection-B2a2EaIg.js +3 -0
  29. package/page/assets/browser-engine--lGbAmPM.js +13 -0
  30. package/page/assets/browser-transport-h1KAGUN4.js +45 -0
  31. package/page/assets/{crypto-CD14HeXH.js → crypto-BnoW7FFO.js} +1 -1
  32. package/page/assets/{encode-files-DhoC5hWG.js → encode-files-DoLGXgup.js} +1 -1
  33. package/page/assets/{export-agent-Cs2S0oXB.js → export-agent-CA42Pf8A.js} +3 -3
  34. package/page/assets/{guardrail-tester-IcJWVveC.js → guardrail-tester-fDJlewVB.js} +2 -2
  35. package/page/assets/index-Bd7U_fu_.js +149 -0
  36. package/page/assets/{labels-provider-t4c-5JMk.js → labels-provider-uONlWExD.js} +1 -1
  37. package/page/assets/live-messages-CTL-QEqM.js +1 -0
  38. package/page/assets/people-CIsR0-5R.js +1 -0
  39. package/page/assets/project-address-DjxPZuyn.js +1 -0
  40. package/page/assets/reader-COeSYhdZ.js +5 -0
  41. package/page/assets/{schemas-BQ9Jydzb.js → schemas-D7cgkv3L.js} +1 -1
  42. package/page/assets/shaped-data-7q5Be8sp.js +20 -0
  43. package/page/assets/{stub-nxRsh1jo.js → stub-DJBcKncO.js} +25 -7
  44. package/page/assets/studio-code-pane-MXm30Ppv.js +10 -0
  45. package/page/assets/{studio-console-Cn-v8Vvw.js → studio-console-dHEr6mr5.js} +1 -1
  46. package/page/assets/studio-decision-BoSmTyjn.js +1 -0
  47. package/page/assets/studio-embedding-B5E__vsY.js +2 -0
  48. package/page/assets/studio-host-console-CadL7PPh.js +2 -0
  49. package/page/assets/{studio-labels-CiLuAo3N.js → studio-labels-sxDmOFeL.js} +1 -1
  50. package/page/assets/studio-live-Cgt4zKeL.js +5 -0
  51. package/page/assets/studio-map-BgeqrIh_.js +1 -0
  52. package/page/assets/{studio-session-CjUQSXx0.js → studio-session-ClF2iNCX.js} +1 -1
  53. package/page/assets/studio-trace-replay-BqYGBZ1t.js +3 -0
  54. package/page/assets/{studio-type-checker-BbUSqqOS.js → studio-type-checker-DutkTKte.js} +1 -1
  55. package/page/assets/tool-schema-m1KPujBp.js +17 -0
  56. package/page/assets/{trace-record-DxgSKmYY.js → trace-record-Dm2jEhUR.js} +1 -1
  57. package/page/assets/trace-schema--4IGmLeE.js +1 -0
  58. package/page/assets/tree-5tuw5ISS.js +3 -0
  59. package/page/assets/turn-client-BmadRouD.js +2 -0
  60. package/page/assets/{use-one-call-BZKByPJh.js → use-one-call-IXfdRlUH.js} +1 -1
  61. package/page/assets/use-second-ticker-D6JSf9B3.js +1 -0
  62. package/page/assets/workspace-CMUi6xcQ.js +1 -0
  63. package/page/index.html +22 -20
  64. package/people.d.ts +2 -0
  65. package/people.js +3 -1
  66. package/policy.js +1 -0
  67. package/providers.d.ts +2 -2
  68. package/providers.js +8 -3
  69. package/read-source.js +67 -7
  70. package/registrations.d.ts +32 -4
  71. package/runtime-scope.d.ts +6 -3
  72. package/runtime-scope.js +16 -4
  73. package/runtime.js +15 -2
  74. package/section-notes.d.ts +1 -0
  75. package/section-notes.js +1 -0
  76. package/serve-page.mjs +8 -4
  77. package/server/draft-handler.d.ts +4 -4
  78. package/server/draft-handler.js +3 -2
  79. package/server/draft-probe.d.ts +9 -1
  80. package/server/draft-probe.js +2 -1
  81. package/server/handler.d.ts +0 -3
  82. package/server/handler.js +62 -38
  83. package/server/live.d.ts +7 -2
  84. package/server/live.js +11 -5
  85. package/server/run-traces.d.ts +5 -1
  86. package/server/run-traces.js +7 -3
  87. package/server/save-new.js +5 -5
  88. package/server/save-plan.js +2 -1
  89. package/server/save-session.js +4 -2
  90. package/server/serve.js +2 -1
  91. package/server/test-key.d.ts +2 -2
  92. package/server/test-key.js +1 -1
  93. package/slot-values.d.ts +2 -0
  94. package/slot-values.js +22 -0
  95. package/source.js +11 -4
  96. package/system-markup.d.ts +9 -7
  97. package/system-markup.js +38 -19
  98. package/tool-readers.d.ts +23 -0
  99. package/tool-readers.js +60 -0
  100. package/tools.js +5 -1
  101. package/types.d.ts +6 -1
  102. package/ui/inspector-context.d.ts +1 -8
  103. package/ui/inspector-context.js +0 -7
  104. package/ui/inspector.d.ts +43 -1
  105. package/ui/inspector.js +50 -9
  106. package/ui/lib/entries.d.ts +13 -0
  107. package/ui/lib/entries.js +43 -0
  108. package/ui/lib/project-traces.d.ts +5 -0
  109. package/ui/lib/project-traces.js +11 -1
  110. package/ui/lib/studio-page.d.ts +6 -1
  111. package/ui/lib/studio-page.js +33 -31
  112. package/ui/lib/studio-prefs.d.ts +0 -4
  113. package/ui/lib/studio-prefs.js +0 -7
  114. package/ui/lib/studio-project.d.ts +10 -6
  115. package/ui/lib/studio-project.js +19 -4
  116. package/ui/lib/studio-session.d.ts +2 -0
  117. package/ui/lib/studio-session.js +40 -2
  118. package/ui/lib/studio-store.d.ts +2 -2
  119. package/ui/lib/studio-store.js +9 -5
  120. package/ui/lib/tool-probe.d.ts +2 -0
  121. package/ui/lib/tool-probe.js +3 -2
  122. package/ui/lib/type-icons.d.ts +1 -0
  123. package/ui/lib/type-icons.js +2 -1
  124. package/ui/profile-editor.js +69 -45
  125. package/ui/studio-compare.d.ts +14 -4
  126. package/ui/studio-compare.js +58 -24
  127. package/ui/studio-live.d.ts +1 -1
  128. package/ui/studio-live.js +8 -3
  129. package/ui/studio-runner.d.ts +3 -2
  130. package/ui/studio-runner.js +16 -14
  131. package/ui/studio-screen.d.ts +1 -2
  132. package/ui/studio-screen.js +33 -37
  133. package/ui/studio-settings.js +4 -13
  134. package/ui/studio-trace-replay.js +7 -1
  135. package/workspace.js +3 -2
  136. package/asks.d.ts +0 -54
  137. package/asks.js +0 -69
  138. package/page/assets/Banner-CkcwUyOn.js +0 -4
  139. package/page/assets/Center-nHS1JSux.js +0 -1
  140. package/page/assets/browser-connection-DSUHVCT5.js +0 -3
  141. package/page/assets/browser-engine-BXSD3WU8.js +0 -11
  142. package/page/assets/browser-transport-cp9y8bBz.js +0 -45
  143. package/page/assets/index-JWco7tJJ.js +0 -145
  144. package/page/assets/live-messages-CiLmR89m.js +0 -1
  145. package/page/assets/reader-DrOfMM8I.js +0 -5
  146. package/page/assets/shaped-data-H1miOZm2.js +0 -20
  147. package/page/assets/studio-code-pane-B8MOEW9g.js +0 -8
  148. package/page/assets/studio-decision-CjJ_pqdJ.js +0 -1
  149. package/page/assets/studio-embedding-Cq3ePsfC.js +0 -2
  150. package/page/assets/studio-host-console-D__Of1no.js +0 -2
  151. package/page/assets/studio-live-DvDQbP5V.js +0 -5
  152. package/page/assets/studio-map-BZFYGG_Y.js +0 -1
  153. package/page/assets/studio-trace-replay-D22FgUA5.js +0 -3
  154. package/page/assets/tool-schema-BmRYaywn.js +0 -17
  155. package/page/assets/trace-schema-9CdEyG6Q.js +0 -1
  156. package/page/assets/tree-3N-1RPZz.js +0 -3
  157. package/page/assets/turn-client-DN8PawJr.js +0 -2
  158. package/page/assets/use-second-ticker-CEwOSS-d.js +0 -1
  159. package/page/assets/workspace-CTSW941G.js +0 -1
  160. package/ui/confirm-write.d.ts +0 -12
  161. package/ui/confirm-write.js +0 -45
@@ -4,31 +4,14 @@
4
4
  */
5
5
  import { useCallback, useSyncExternalStore } from 'react';
6
6
  import { studioPageTools } from "../../mod.js";
7
+ import { choiceValues } from "../../slot-values.js";
7
8
  import { isRecord, session } from "./studio-session.js";
8
9
  const PAGE_PREFIX = 'theorem.studio.v2.page:';
9
- const NO_PAGE_VALUES = { slots: {}, contextJson: '' };
10
+ const NO_PAGE_VALUES = { slots: {}, conditions: {}, contextJson: '' };
10
11
  /** The context a blank preview box suggests. */
11
12
  export const CONTEXT_PLACEHOLDER = `{
12
13
  "page": "Checkout"
13
14
  }`;
14
- function choiceValues(decl) {
15
- if (Array.isArray(decl) &&
16
- decl.length > 0 &&
17
- decl.every((value) => typeof value === 'string' && value.trim() !== '')) {
18
- return decl;
19
- }
20
- if (!isRecord(decl) || !Array.isArray(decl.choices) || decl.choices.length === 0) {
21
- return undefined;
22
- }
23
- const values = [];
24
- for (const choice of decl.choices) {
25
- if (!isRecord(choice) || typeof choice.value !== 'string' || choice.value.trim() === '') {
26
- return undefined;
27
- }
28
- values.push(choice.value);
29
- }
30
- return values;
31
- }
32
15
  /** The slots a draft has so far that a page can pick from: each named, with a value, once. */
33
16
  export function draftSlots(slots) {
34
17
  const seen = new Set();
@@ -57,7 +40,11 @@ export function contextErrorOf(contextJson) {
57
40
  /** What the compiled agent takes from a page, or null when it takes nothing. */
58
41
  export function pageInputsOf(payload) {
59
42
  const { profile } = payload;
60
- if (profile.type === 'decision' || profile.type === 'host' || profile.type === 'embedding') {
43
+ if (profile.type === 'decision' ||
44
+ profile.type === 'host' ||
45
+ profile.type === 'embedding' ||
46
+ profile.type === 'speech' ||
47
+ profile.type === 'transcription') {
61
48
  return null;
62
49
  }
63
50
  const inputs = 'inputs' in profile ? profile.inputs : undefined;
@@ -66,17 +53,25 @@ export function pageInputsOf(payload) {
66
53
  const values = choiceValues(decl);
67
54
  return values ? [[name, values]] : [];
68
55
  }));
56
+ const conditions = profile.identity.conditions ?? {};
69
57
  const takesContext = inputs?.context?.from.includes('client') ?? false;
70
58
  const pageTools = Object.keys(studioPageTools(payload));
71
- if (!Object.keys(slots).length && !takesContext && !pageTools.length)
59
+ const takesNothing = !Object.keys(slots).length && !Object.keys(conditions).length && !takesContext;
60
+ if (takesNothing && !pageTools.length)
72
61
  return null;
73
- return { slots, takesContext, pageTools };
62
+ return { slots, conditions, takesContext, pageTools };
74
63
  }
75
- /** The value a slot sends: the one picked while the profile still lists it, else its first. */
76
- function slotValue(inputs, values, name) {
77
- const allowed = inputs.slots[name] ?? [];
78
- const picked = allowed.find((value) => value === values.slots[name]);
79
- return picked ?? allowed.at(0) ?? '';
64
+ /** The value a pick sends: the one picked while the profile still lists it, else its first. */
65
+ function pickedValue(allowed, picked) {
66
+ return allowed.find((value) => value === picked) ?? allowed.at(0) ?? '';
67
+ }
68
+ /** The turn's path and conditions as picked: the `path` condition is the turn's own path. */
69
+ function statedTurn(inputs, values) {
70
+ const picks = Object.entries(inputs.conditions).map(([name, allowed]) => [name, pickedValue(allowed, values.conditions[name])]);
71
+ if (!picks.length)
72
+ return undefined;
73
+ const { path, ...conditions } = Object.fromEntries(picks);
74
+ return { ...(path === undefined ? {} : { path }), conditions };
80
75
  }
81
76
  /** What goes with a turn or a call. Context that is not JSON is not sent, and says why. */
82
77
  export function sentPageValues(inputs, values) {
@@ -84,13 +79,17 @@ export function sentPageValues(inputs, values) {
84
79
  return {};
85
80
  const names = Object.keys(inputs.slots);
86
81
  const slots = names.length
87
- ? Object.fromEntries(names.map((name) => [name, slotValue(inputs, values, name)]))
82
+ ? Object.fromEntries(names.map((name) => [name, pickedValue(inputs.slots[name] ?? [], values.slots[name])]))
88
83
  : undefined;
84
+ const stated = statedTurn(inputs, values);
85
+ const sent = { slots, ...(stated ? { stated } : {}) };
89
86
  const typed = inputs.takesContext ? values.contextJson.trim() : '';
90
87
  if (!typed)
91
- return { slots };
88
+ return sent;
92
89
  const contextError = contextErrorOf(typed);
93
- return contextError ? { slots, contextError } : { slots, context: JSON.parse(typed) };
90
+ return contextError
91
+ ? { ...sent, contextError }
92
+ : { ...sent, context: JSON.parse(typed) };
94
93
  }
95
94
  function loadPageValues(agentKey) {
96
95
  try {
@@ -99,7 +98,10 @@ function loadPageValues(agentKey) {
99
98
  return NO_PAGE_VALUES;
100
99
  }
101
100
  const slots = Object.fromEntries(Object.entries(kept.slots).filter((entry) => typeof entry[1] === 'string'));
102
- return { slots, contextJson: kept.contextJson };
101
+ const conditions = isRecord(kept.conditions)
102
+ ? Object.fromEntries(Object.entries(kept.conditions).filter((entry) => typeof entry[1] === 'string'))
103
+ : {};
104
+ return { slots, conditions, contextJson: kept.contextJson };
103
105
  }
104
106
  catch {
105
107
  return NO_PAGE_VALUES;
@@ -7,8 +7,6 @@ export interface StudioPrefs {
7
7
  filesToast: 'on' | 'off';
8
8
  /** Whether changing a value several agents share is asked about first. */
9
9
  askShared: 'always' | 'never';
10
- /** Which tools that write ask before a run: all of them, or only the destructive ones. */
11
- askWrites: 'always' | 'destructive';
12
10
  }
13
11
  export type StudioPref = keyof StudioPrefs;
14
12
  export declare const PREF_DEFAULTS: StudioPrefs;
@@ -22,5 +20,3 @@ export declare function getPref<K extends StudioPref>(name: K): StudioPrefs[K];
22
20
  export declare function setPref<K extends StudioPref>(name: K, value: StudioPrefs[K]): void;
23
21
  /** A preference, and the screen drawn again when it changes. */
24
22
  export declare function usePref<K extends StudioPref>(name: K): StudioPrefs[K];
25
- /** Whether a run of a tool that writes asks first: a destructive one always, another unless the builder said not to. */
26
- export declare function writeAsks(access: string): boolean;
@@ -10,14 +10,12 @@ export const PREF_DEFAULTS = {
10
10
  watch: 'on',
11
11
  filesToast: 'on',
12
12
  askShared: 'always',
13
- askWrites: 'always',
14
13
  };
15
14
  const PREF_KEYS = {
16
15
  editor: 'theorem.studio.editor',
17
16
  watch: 'theorem.studio.watch',
18
17
  filesToast: 'theorem.studio.files-toast',
19
18
  askShared: 'theorem.studio.ask-shared',
20
- askWrites: 'theorem.studio.ask-writes',
21
19
  };
22
20
  /** Whether a kept text is a value the preference takes. */
23
21
  const PREF_TAKES = {
@@ -25,7 +23,6 @@ const PREF_TAKES = {
25
23
  watch: (kept) => kept === 'off',
26
24
  filesToast: (kept) => kept === 'off',
27
25
  askShared: (kept) => kept === 'never',
28
- askWrites: (kept) => kept === 'destructive',
29
26
  };
30
27
  /** A preference as `storage` keeps it, or its default. */
31
28
  export function readPref(storage, name) {
@@ -81,7 +78,3 @@ function subscribePrefs(listener) {
81
78
  export function usePref(name) {
82
79
  return useSyncExternalStore(subscribePrefs, () => getPref(name), () => PREF_DEFAULTS[name]);
83
80
  }
84
- /** Whether a run of a tool that writes asks first: a destructive one always, another unless the builder said not to. */
85
- export function writeAsks(access) {
86
- return access === 'destructive' || getPref('askWrites') === 'always';
87
- }
@@ -3,8 +3,10 @@
3
3
  * the page the project's registered profiles and tools as a workspace, and runs each profile's
4
4
  * own code.
5
5
  */
6
- import { type ProjectCode, type StudioAsks, type StudioWorkspace } from '../../mod.ts';
7
- import type { StudioPeopleOffer } from '../../people.ts';
6
+ import type { TranscriptBlock } from '@theoremjs/agents/interface';
7
+ import type { TheoremRewound } from '@theoremjs/web/client';
8
+ import { type ProjectCode, type StudioWorkspace } from '../../mod.ts';
9
+ import { type StudioActingAs, type StudioPeopleOffer } from '../../people.ts';
8
10
  import { type ReadStep } from '../../read-steps.ts';
9
11
  import type { EditedAnswer, OpenAnswer, OpenRequest, ProjectOrigins, ProviderPlace, SaveDone, SaveRefusal, SaveReview, SharedSetting, Unregistered } from '../../server/save-wire.ts';
10
12
  export interface ProjectSession {
@@ -42,8 +44,6 @@ export interface ProjectSession {
42
44
  origins: ProjectOrigins;
43
45
  /** Where the files define each provider the project registered. */
44
46
  providerPlaces: ProviderPlace[];
45
- /** The tools that write: the ones the studio makes ask, and the ones it cannot. */
46
- asks: StudioAsks;
47
47
  /** The files as the server read them, as a short text that changes when they do. */
48
48
  print: string;
49
49
  /** What the project printed when its files stopped loading; the page shows the last load that did. */
@@ -62,7 +62,6 @@ export interface ProjectSession {
62
62
  * builder changed is left out, so the code writes it as the studio holds it.
63
63
  */
64
64
  export declare function projectCode(project: ProjectSession | null, workspace: StudioWorkspace): ProjectCode | undefined;
65
- export declare const NO_ASKS: StudioAsks;
66
65
  /** Set while the page has a project open; `null` on the website's own page. */
67
66
  export declare const ProjectContext: import("react").Context<ProjectSession | null>;
68
67
  export declare function useProject(): ProjectSession | null;
@@ -83,10 +82,15 @@ export declare function undoSave(project: ProjectSession): Promise<SaveDone | Sa
83
82
  export declare function openEdited(project: ProjectSession, workspace: StudioWorkspace): Promise<EditedAnswer>;
84
83
  /** Where the local server runs the profile with this id as the builder's edits make it. */
85
84
  export declare function editedProfileEndpoint(project: ProjectSession, profileId: string): string;
85
+ /**
86
+ * A chat that opens on `blocks`, on the project's server: its ref and view. Every load seals with
87
+ * the run's one key, so whichever side goes on opens it.
88
+ */
89
+ export declare function startProjectConversation(project: ProjectSession, profileId: string, blocks: readonly TranscriptBlock[], actingAs: StudioActingAs | undefined): Promise<TheoremRewound>;
86
90
  /** Shows a line of one of the project's files in the editor the builder chose, or the studio command's. */
87
91
  export declare function openInEditor(project: ProjectSession, place: OpenRequest): Promise<OpenAnswer>;
88
92
  /** What a project's files say, which a Save or an edit in the builder's editor changes. */
89
- export type ProjectFiles = Pick<ProjectSession, 'profiles' | 'providers' | 'problems' | 'modelProblems' | 'differences' | 'unheld' | 'origins' | 'providerPlaces' | 'asks' | 'print' | 'unloaded' | 'people' | 'peopleProblem'>;
93
+ export type ProjectFiles = Pick<ProjectSession, 'profiles' | 'providers' | 'problems' | 'modelProblems' | 'differences' | 'unheld' | 'origins' | 'providerPlaces' | 'print' | 'unloaded' | 'people' | 'peopleProblem'>;
90
94
  /**
91
95
  * What the project's files say now that the page does not hold as edits: the profiles they hold
92
96
  * and the ones the studio cannot run, the settings they set in code, whose lines a Save moves,
@@ -4,7 +4,8 @@
4
4
  * own code.
5
5
  */
6
6
  import { createContext, useContext } from 'react';
7
- import { filesPrint, providersAtStart, } from "../../mod.js";
7
+ import { filesPrint, providersAtStart } from "../../mod.js";
8
+ import { actingAsHeaders } from "../../people.js";
8
9
  import { READ_STEPS } from "../../read-steps.js";
9
10
  import { projectEndpoint } from "./project-address.js";
10
11
  import { getPref } from "./studio-prefs.js";
@@ -21,7 +22,6 @@ export function projectCode(project, workspace) {
21
22
  origins: project.origins.profiles,
22
23
  };
23
24
  }
24
- export const NO_ASKS = { asked: [], inside: [] };
25
25
  const NO_ORIGINS = { profiles: {}, tools: {}, providers: {} };
26
26
  /** Set while the page has a project open; `null` on the website's own page. */
27
27
  export const ProjectContext = createContext(null);
@@ -43,7 +43,6 @@ export function projectSession(name) {
43
43
  unregistered: [],
44
44
  origins: NO_ORIGINS,
45
45
  providerPlaces: [],
46
- asks: NO_ASKS,
47
46
  print: '',
48
47
  people: undefined,
49
48
  peopleProblem: undefined,
@@ -86,6 +85,23 @@ export function openEdited(project, workspace) {
86
85
  export function editedProfileEndpoint(project, profileId) {
87
86
  return `${project.endpoint}/edited/profiles/${encodeURIComponent(profileId)}`;
88
87
  }
88
+ /**
89
+ * A chat that opens on `blocks`, on the project's server: its ref and view. Every load seals with
90
+ * the run's one key, so whichever side goes on opens it.
91
+ */
92
+ export async function startProjectConversation(project, profileId, blocks, actingAs) {
93
+ const endpoint = project.profiles.includes(profileId)
94
+ ? projectProfileEndpoint(project, profileId)
95
+ : editedProfileEndpoint(project, profileId);
96
+ const response = await fetch(`${endpoint}/conversation/start`, {
97
+ method: 'POST',
98
+ headers: { 'content-type': 'application/json', ...actingAsHeaders(actingAs) },
99
+ body: JSON.stringify({ blocks }),
100
+ });
101
+ if (!response.ok)
102
+ throw new Error(`The studio server answered ${String(response.status)}.`);
103
+ return response.json();
104
+ }
89
105
  /** Shows a line of one of the project's files in the editor the builder chose, or the studio command's. */
90
106
  export function openInEditor(project, place) {
91
107
  const editor = getPref('editor');
@@ -139,7 +155,6 @@ function filesOf(opened) {
139
155
  unheld: opened.unheld ?? [],
140
156
  origins: opened.origins ?? NO_ORIGINS,
141
157
  providerPlaces: opened.providerPlaces ?? [],
142
- asks: opened.asks ?? NO_ASKS,
143
158
  print: filesPrint(opened.workspace),
144
159
  // Set even when absent, so a setup file that stops offering people stops being offered.
145
160
  people: opened.people,
@@ -36,6 +36,8 @@ export interface StoredWorkspace {
36
36
  export interface TabStorage {
37
37
  getItem(name: string): string | null;
38
38
  setItem(name: string, value: string): void;
39
+ /** `setItem` as the page goes: the next load of this tab reads it, whether or not the keep did. */
40
+ setItemLeaving(name: string, value: string): void;
39
41
  removeItem(name: string): void;
40
42
  keys(): string[];
41
43
  }
@@ -7,6 +7,8 @@ export const CHAT_PREFIX = 'theorem.studio.v2.chat:';
7
7
  /** In this tab's sessionStorage: the id its records are kept under. */
8
8
  const TAB_ID = 'theorem.studio.tab';
9
9
  const TAB_LOCK = 'theorem.studio.tab:';
10
+ /** In this tab's sessionStorage: the record the page wrote as it went, until the next load. */
11
+ const LEAVING = 'theorem.studio.leaving';
10
12
  /** Held while a tab claims its records and while a sweep runs, so a sweep never sees a tab half open. */
11
13
  const SWEEP_LOCK = 'theorem.studio.sweep';
12
14
  let open;
@@ -27,6 +29,28 @@ export function tabSession() {
27
29
  return null;
28
30
  }
29
31
  }
32
+ /** Sets aside or clears the record in `LEAVING`. A full or blocked sessionStorage keeps nothing. */
33
+ function setLeaving(record) {
34
+ try {
35
+ if (record)
36
+ tabSession()?.setItem(LEAVING, JSON.stringify(record));
37
+ else
38
+ tabSession()?.removeItem(LEAVING);
39
+ }
40
+ catch {
41
+ // The keep's own write may still land.
42
+ }
43
+ }
44
+ /** The record the last page set aside, if it left one. */
45
+ function readLeaving() {
46
+ try {
47
+ const raw = tabSession()?.getItem(LEAVING);
48
+ return raw ? JSON.parse(raw) : undefined;
49
+ }
50
+ catch {
51
+ return undefined;
52
+ }
53
+ }
30
54
  /** Holds `name` for as long as the page lives, if no one holds it now. */
31
55
  function hold(locks, name) {
32
56
  return new Promise((resolve) => {
@@ -98,11 +122,25 @@ export async function openTabStorage(options = {}) {
98
122
  };
99
123
  const { id, kept } = locks ? await locks.request(SWEEP_LOCK, claim) : await claim();
100
124
  const records = new Map(kept);
125
+ const setItem = (name, value) => {
126
+ records.set(name, value);
127
+ keep.put(id, name, value);
128
+ };
129
+ const leaving = readLeaving();
130
+ if (leaving)
131
+ setItem(leaving.name, leaving.value);
132
+ setLeaving();
101
133
  const storage = {
102
134
  getItem: (name) => records.get(name) ?? null,
103
135
  setItem: (name, value) => {
104
- records.set(name, value);
105
- keep.put(id, name, value);
136
+ setItem(name, value);
137
+ // why: a page brought back from the browser's cache goes on, and this write is newer.
138
+ setLeaving();
139
+ },
140
+ // why: a write to the keep begun on pagehide does not finish before a reload reads it.
141
+ setItemLeaving: (name, value) => {
142
+ setItem(name, value);
143
+ setLeaving({ name, value });
106
144
  },
107
145
  removeItem: (name) => {
108
146
  if (records.delete(name))
@@ -59,6 +59,6 @@ export declare function createStudioStore(initial: RestoredStudio, sites?: Share
59
59
  /** Drops the held change: no agent has it. */
60
60
  cancelShared: () => void;
61
61
  standOn: (files: string) => void;
62
- /** Writes now if a write is pending; the route calls it on pagehide and unmount. */
63
- flush(): void;
62
+ /** Writes now if a write is pending; the route calls it on pagehide, as `isLeaving`, and unmount. */
63
+ flush(isLeaving?: boolean): void;
64
64
  };
@@ -109,7 +109,7 @@ function agentOf(workspace, id) {
109
109
  })?.key;
110
110
  }
111
111
  /** Keeps the workspace, masked, in the tab's records. */
112
- function writeWorkspace(state) {
112
+ function writeWorkspace(state, isLeaving = false) {
113
113
  state.timer = undefined;
114
114
  const record = {
115
115
  v: STUDIO_WORKSPACE_VERSION,
@@ -117,7 +117,11 @@ function writeWorkspace(state) {
117
117
  revision: state.revision,
118
118
  ...(state.files === undefined ? {} : { files: state.files }),
119
119
  };
120
- session()?.setItem(state.slot, JSON.stringify(record));
120
+ const text = JSON.stringify(record);
121
+ if (isLeaving)
122
+ session()?.setItemLeaving(state.slot, text);
123
+ else
124
+ session()?.setItem(state.slot, text);
121
125
  }
122
126
  /** Queues a write, unless one is already queued. */
123
127
  function scheduleWrite(state) {
@@ -378,12 +382,12 @@ export function createStudioStore(initial, sites, toolSites) {
378
382
  state.files = files;
379
383
  scheduleWrite(state);
380
384
  },
381
- /** Writes now if a write is pending; the route calls it on pagehide and unmount. */
382
- flush() {
385
+ /** Writes now if a write is pending; the route calls it on pagehide, as `isLeaving`, and unmount. */
386
+ flush(isLeaving = false) {
383
387
  if (state.timer === undefined)
384
388
  return;
385
389
  clearTimeout(state.timer);
386
- writeWorkspace(state);
390
+ writeWorkspace(state, isLeaving);
387
391
  },
388
392
  };
389
393
  }
@@ -6,6 +6,8 @@ export interface ProbeResult {
6
6
  status?: number;
7
7
  statusText?: string;
8
8
  error?: string;
9
+ /** Why it got no answer: `ssrf_blocked` when the network guard refused the address. */
10
+ code?: string;
9
11
  preview?: string;
10
12
  elapsedMs?: number;
11
13
  tools?: string[];
@@ -1,6 +1,7 @@
1
1
  /**
2
- * One real call to a draft tool, from the server, which reaches public hosts only: the editor's
3
- * Test and th30's `test` action both go through here.
2
+ * One real call to a draft tool, from the server, which reaches public hosts only, or on a project
3
+ * what the agent's network guardrail allows: the editor's Test and th30's `test` action both go
4
+ * through here.
4
5
  */
5
6
  import { HTTP_METHODS } from '@theoremjs/agents';
6
7
  import { draftNetwork } from "../../compile.js";
@@ -12,6 +12,7 @@ export declare const PROFILE_TYPE_ICON: {
12
12
  text: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
13
13
  image: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
14
14
  speech: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
15
+ transcription: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
15
16
  live: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
16
17
  decision: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
17
18
  embedding: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
@@ -1,4 +1,4 @@
1
- import { IconChartBar, IconChartScatter3d, IconFileSmile, IconGavel, IconHeadset, IconLetterT, IconListCheck, IconMathFunction, IconNumber, IconPhoto, IconServer, IconSquareDashed, IconTool, IconVolume, IconWorld, } from '@tabler/icons-react';
1
+ import { IconChartBar, IconChartScatter3d, IconFileSmile, IconGavel, IconHeadset, IconLetterT, IconListCheck, IconMathFunction, IconMicrophone, IconNumber, IconPhoto, IconServer, IconSquareDashed, IconTool, IconVolume, IconWorld, } from '@tabler/icons-react';
2
2
  import { IconMcp } from "../mcp-icon.js";
3
3
  /** An agent's icon, wherever one shows: the workspace's Agents list, an agent tool, a profile file. */
4
4
  export const AGENT_ICON = IconFileSmile;
@@ -7,6 +7,7 @@ export const PROFILE_TYPE_ICON = {
7
7
  text: IconLetterT,
8
8
  image: IconPhoto,
9
9
  speech: IconVolume,
10
+ transcription: IconMicrophone,
10
11
  live: IconHeadset,
11
12
  decision: IconGavel,
12
13
  embedding: IconChartScatter3d,