@theoremjs/studio 0.3.4-next.544.gb5ef325 → 0.3.4-next.550.gf20b9cd

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 (173) hide show
  1. package/README.md +57 -17
  2. package/agreement.js +22 -7
  3. package/compile.js +61 -13
  4. package/cookbooks/catalog.d.ts +26 -3
  5. package/cookbooks/catalog.js +114 -60
  6. package/cookbooks/exchanges.d.ts +3 -0
  7. package/cookbooks/exchanges.js +7 -2
  8. package/cookbooks/mod.d.ts +3 -3
  9. package/cookbooks/mod.js +2 -2
  10. package/cookbooks/project.js +1 -3
  11. package/draft.d.ts +23 -5
  12. package/draft.js +10 -2
  13. package/media-accept.d.ts +7 -0
  14. package/media-accept.js +17 -0
  15. package/mod.d.ts +4 -4
  16. package/mod.js +3 -3
  17. package/package.json +4 -4
  18. package/page/assets/Banner-Bvkdyf59.js +2 -0
  19. package/page/assets/BottomSheet-Dbh6A5Vl.js +1 -0
  20. package/page/assets/{Card-Ghe4ozhC.js → Card-DruykyeB.js} +1 -1
  21. package/page/assets/CheckboxInput-CFZ_Wq8-.js +2 -0
  22. package/page/assets/CodeBlock-CfVOtDeO.js +52 -0
  23. package/page/assets/CollapsibleGroup-FIawJRo4.js +1 -0
  24. package/page/assets/ConsoleFrame-BTL67qHr.js +3 -0
  25. package/page/assets/ContextMenu-BngxR9na.js +2 -0
  26. package/page/assets/DateInput-B1ICJtHn.js +1 -0
  27. package/page/assets/{Dialog-BDUExlk_.js → Dialog-Sd04KQS2.js} +1 -1
  28. package/page/assets/EmptyState-C_uF9Wyj.js +1 -0
  29. package/page/assets/HoverCard-DMyWUvwP.js +1 -0
  30. package/page/assets/Icon-BqkS-pIq.js +3 -0
  31. package/page/assets/IconButton-DVUFx-8p.js +1 -0
  32. package/page/assets/ListItem-QF7KFt0h.js +1 -0
  33. package/page/assets/MenuBottomSheet-C4fG_GyZ.js +1 -0
  34. package/page/assets/MenuBottomSheetActionList-3L0HS4Kf.js +1 -0
  35. package/page/assets/SchemaFields-BT2XCbid.js +1 -0
  36. package/page/assets/ScrollableArea-BHfY7sWH.js +1 -0
  37. package/page/assets/SegmentedControlItem-BBGRPrxp.js +1 -0
  38. package/page/assets/{Text-BsiAsowd.js → Text-BOqCfzZC.js} +2 -2
  39. package/page/assets/{TimestampHoverCard-CCnmnVlQ.js → TimestampHoverCard-CDCVpEWM.js} +1 -1
  40. package/page/assets/{ToolResultCharts-BAIAtrxa.js → ToolResultCharts-rJr0Ksno.js} +1 -1
  41. package/page/assets/Tooltip-BWs5DLrM.js +1 -0
  42. package/page/assets/TraceInspector-DQI_wNzL.js +1 -0
  43. package/page/assets/{TraceOverview-C6T0S77W.js → TraceOverview-DmfmwSR6.js} +2 -2
  44. package/page/assets/{_virtual_studio-type-sources-C1mRXxbj.js → _virtual_studio-type-sources-CxP3L28S.js} +158 -78
  45. package/page/assets/browser-engine-B1PxEekk.js +11 -0
  46. package/page/assets/browser-transport-BOHBmYvp.js +47 -0
  47. package/page/assets/{embedding-space-view-BU2AjjAx.js → embedding-space-view-CN0VHXXH.js} +1 -1
  48. package/page/assets/{export-agent-m6Z0No6j.js → export-agent-BvEVKW_C.js} +8 -8
  49. package/page/assets/fieldParts-B7DYLgh4.js +1 -0
  50. package/page/assets/focusableSelector-DXZeMU85.js +1 -0
  51. package/page/assets/{guardrail-tester-oVuyo5d2.js → guardrail-tester-08T-hMFL.js} +2 -2
  52. package/page/assets/index-eSb7kilv.js +146 -0
  53. package/page/assets/isRenderable-DHkzpAoQ.js +1 -0
  54. package/page/assets/{labels-provider-Gus3heEH.js → labels-provider-DkA22zkP.js} +2 -2
  55. package/page/assets/{live-messages-BNhCuiuF.js → live-messages-DmTC8qc8.js} +1 -1
  56. package/page/assets/plainDate-BHiJcj7o.js +1 -0
  57. package/page/assets/reader-DoTXxl0W.js +7 -0
  58. package/page/assets/{stub-DPcZtI0s.js → stub-CKo_lxer.js} +1 -1
  59. package/page/assets/studio-code-pane-CEG07Zk7.js +8 -0
  60. package/page/assets/{studio-console-DoZMv_gr.js → studio-console-udt4MmTi.js} +1 -1
  61. package/page/assets/studio-decision-tocwLzxr.js +1 -0
  62. package/page/assets/studio-embedding-DQ84xzlj.js +2 -0
  63. package/page/assets/studio-host-console-BJOUpXHR.js +2 -0
  64. package/page/assets/studio-labels-Zqd84hcs.js +3 -0
  65. package/page/assets/studio-live-BmuHpeF4.js +5 -0
  66. package/page/assets/{studio-map-Dv8iCayn.js → studio-map-qP_i4hWG.js} +1 -1
  67. package/page/assets/studio-trace-replay-JUMs6EMA.js +2 -0
  68. package/page/assets/{studio-type-checker-B5DVxAZ0.js → studio-type-checker-B_CHmWnf.js} +1 -1
  69. package/page/assets/{tool-schema-CxLtS_Zt.js → tool-schema-CWGccblZ.js} +6 -6
  70. package/page/assets/{trace-patterns-CS99kExN.js → trace-patterns-D6TbkLLr.js} +1 -1
  71. package/page/assets/tree-B7VVMg1s.js +3 -0
  72. package/page/assets/{turn-client-BCi5WnI6.js → turn-client-CoLR6hrl.js} +1 -1
  73. package/page/assets/types-CL44MvsT.js +1 -0
  74. package/page/assets/{use-one-call-TEvndb3j.js → use-one-call-BKeMtY5F.js} +1 -1
  75. package/page/assets/use-second-ticker-GWBt83pd.css +1 -0
  76. package/page/assets/use-trace-records-B1vrKQmA.js +1 -0
  77. package/page/assets/useAdaptivePresentation-Bma4-u1a.js +1 -0
  78. package/page/assets/useAnnounce-DTSHZvjg.js +1 -0
  79. package/page/assets/useClipboard-CbN9bb4J.js +1 -0
  80. package/page/assets/useDevWarning-Z9SoixOP.js +1 -0
  81. package/page/assets/useFocusReturnVisibility-BHKv5Jwr.js +1 -0
  82. package/page/assets/useMenuPress-DLG1QOiE.js +1 -0
  83. package/page/assets/useResolvedRequired-DbsOcDqy.js +1 -0
  84. package/page/assets/useScrollableArea-DuF_pz9m.js +1 -0
  85. package/page/assets/useTooltip-c097gL_-.js +1 -0
  86. package/page/assets/workspace-NGa3jjDc.js +1 -0
  87. package/page/index.html +45 -38
  88. package/read-source.js +35 -8
  89. package/read-studio.mjs +99 -0
  90. package/replay.d.ts +3 -1
  91. package/replay.js +53 -5
  92. package/requirements.d.ts +3 -0
  93. package/requirements.js +10 -0
  94. package/server/alerts.d.ts +23 -0
  95. package/server/alerts.js +82 -0
  96. package/server/draft-handler.d.ts +3 -0
  97. package/server/draft-handler.js +5 -1
  98. package/server/events.d.ts +38 -0
  99. package/server/events.js +95 -0
  100. package/server/handler.d.ts +11 -3
  101. package/server/handler.js +64 -8
  102. package/server/project-source.d.ts +6 -3
  103. package/server/project-source.js +45 -4
  104. package/server/project.js +25 -3
  105. package/server/save-session.d.ts +2 -0
  106. package/server/save-session.js +7 -1
  107. package/server/serve.d.ts +1 -1
  108. package/server/serve.js +174 -18
  109. package/server/test-key.d.ts +19 -2
  110. package/server/test-key.js +51 -74
  111. package/server/watch.d.ts +8 -0
  112. package/server/watch.js +16 -5
  113. package/start.mjs +95 -5
  114. package/surface.js +1 -2
  115. package/ui/built/theme.css +2 -2
  116. package/ui/built/theme.css.d.ts +2 -2
  117. package/ui/built/theorem-studio.d.ts +2 -2
  118. package/ui/built/theorem-studio.js +3 -3
  119. package/ui/built/theorem-studio.variants.d.ts +2 -2
  120. package/ui/lib/export-agent.js +20 -2
  121. package/ui/lib/page-errors.d.ts +13 -0
  122. package/ui/lib/page-errors.js +31 -0
  123. package/ui/lib/studio-examples.js +0 -4
  124. package/ui/lib/studio-page.d.ts +8 -3
  125. package/ui/lib/studio-page.js +34 -13
  126. package/ui/profile-editor.js +186 -34
  127. package/ui/studio-decision.js +4 -1
  128. package/ui/studio-runner.d.ts +1 -1
  129. package/ui/studio-runner.js +7 -3
  130. package/ui/studio-screen.js +24 -18
  131. package/ui/studio-trace-replay.js +1 -8
  132. package/workspace.d.ts +1 -0
  133. package/workspace.js +3 -2
  134. package/page/assets/Banner-BUrqNrQ9.js +0 -2
  135. package/page/assets/BottomSheet-BQPskY35.js +0 -1
  136. package/page/assets/CheckboxInput-C9kbVyhK.js +0 -2
  137. package/page/assets/CodeBlock-Kjgv83A6.js +0 -52
  138. package/page/assets/CollapsibleGroup-PavPZ114.js +0 -1
  139. package/page/assets/ConsoleFrame-BpbXMWsq.js +0 -3
  140. package/page/assets/ContextMenu-D_6fLWw7.js +0 -2
  141. package/page/assets/DateInput-BJt-UTCy.js +0 -1
  142. package/page/assets/EmptyState-C8W4JKBZ.js +0 -1
  143. package/page/assets/HoverCard-C6thuzrf.js +0 -1
  144. package/page/assets/Icon-ZfFwTt8n.js +0 -3
  145. package/page/assets/IconButton-CG5klqF1.js +0 -1
  146. package/page/assets/ScrollableArea-C8AVuqnt.js +0 -1
  147. package/page/assets/Section-DJ97F7QE.js +0 -1
  148. package/page/assets/SegmentedControlItem-BLuJOusN.js +0 -1
  149. package/page/assets/Tooltip-CTEuMRLe.js +0 -1
  150. package/page/assets/TraceInspector-CvaN-GcS.js +0 -1
  151. package/page/assets/browser-engine-BS9Kn2Gx.js +0 -11
  152. package/page/assets/browser-transport-eqZ9n2AK.js +0 -47
  153. package/page/assets/fieldParts-Cs6Amprh.js +0 -1
  154. package/page/assets/index-Q8T7gvHP.js +0 -149
  155. package/page/assets/reader-BT_YeHdq.js +0 -7
  156. package/page/assets/studio-code-pane-BB8Q348A.js +0 -8
  157. package/page/assets/studio-decision-BPT3x1kT.js +0 -1
  158. package/page/assets/studio-embedding-cH6PQupx.js +0 -2
  159. package/page/assets/studio-host-console-ZvV5TFC4.js +0 -2
  160. package/page/assets/studio-labels-Dwd-ojX5.js +0 -3
  161. package/page/assets/studio-live-DDInnfd7.js +0 -5
  162. package/page/assets/studio-trace-replay-Dl792A2v.js +0 -2
  163. package/page/assets/tree-Bi2FOU_h.js +0 -3
  164. package/page/assets/types-s-3wFTyD.js +0 -1
  165. package/page/assets/use-second-ticker-CnxaP3LD.css +0 -1
  166. package/page/assets/use-trace-records-BkAYJz0M.js +0 -1
  167. package/page/assets/useAdaptivePresentation-BY_zvjIp.js +0 -1
  168. package/page/assets/useClipboard-B1amtN2V.js +0 -1
  169. package/page/assets/useDevWarning-Cna3kqg1.js +0 -1
  170. package/page/assets/useScrollableArea-vxuztwym.js +0 -1
  171. package/page/assets/useTooltip-rxACYEAC.js +0 -1
  172. package/page/assets/workspace-BiCkglEt.js +0 -1
  173. /package/page/assets/{use-second-ticker-VX91zrxj.js → use-second-ticker-DhbZ0Soz.js} +0 -0
package/server/watch.js CHANGED
@@ -50,8 +50,11 @@ export function watchFiles(options) {
50
50
  },
51
51
  };
52
52
  }
53
- /** The page's subscriptions to file changes, as server-sent events. */
54
- export function createWatchFeed() {
53
+ /**
54
+ * Subscriptions to a stream of values, as server-sent events: each value a line of JSON. A new
55
+ * subscription is sent `first()` before anything new.
56
+ */
57
+ export function createEventFeed() {
55
58
  const encoder = new TextEncoder();
56
59
  const pages = new Set();
57
60
  const send = (page, text) => {
@@ -62,12 +65,13 @@ export function createWatchFeed() {
62
65
  pages.delete(page);
63
66
  }
64
67
  };
68
+ const line = (value) => `data: ${JSON.stringify(value)}\n\n`;
65
69
  return {
66
- tell: (files) => {
70
+ tell: (value) => {
67
71
  for (const page of pages)
68
- send(page, `data: ${JSON.stringify({ files })}\n\n`);
72
+ send(page, line(value));
69
73
  },
70
- subscribe: (headers) => {
74
+ subscribe: (headers, first = []) => {
71
75
  let mine;
72
76
  let beat;
73
77
  const body = new ReadableStream({
@@ -75,6 +79,8 @@ export function createWatchFeed() {
75
79
  mine = controller;
76
80
  pages.add(controller);
77
81
  send(controller, ': watching\n\n');
82
+ for (const value of first)
83
+ send(controller, line(value));
78
84
  // A line now and then keeps a quiet connection open.
79
85
  beat = setInterval(() => send(controller, ': still watching\n\n'), 25_000);
80
86
  },
@@ -91,3 +97,8 @@ export function createWatchFeed() {
91
97
  },
92
98
  };
93
99
  }
100
+ /** The page's subscriptions to file changes, as server-sent events. */
101
+ export function createWatchFeed() {
102
+ const feed = createEventFeed();
103
+ return { tell: (files) => feed.tell({ files }), subscribe: (headers) => feed.subscribe(headers) };
104
+ }
package/start.mjs CHANGED
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
6
6
  /**
7
7
  * Opens the studio on a project, with one command:
8
8
  *
9
- * theorem-studio [setup] [--editor <command>] [--deno-config <file>] [--no-watch]
9
+ * theorem-studio [setup] [--editor <command>] [--deno-config <file>] [--no-watch] [--quiet] [--offline] [--verbose]
10
10
  *
11
11
  * That is the installed package's command (`npx theorem-studio`); in the repo it is
12
12
  * `node studio/start.mjs`.
@@ -23,29 +23,54 @@ import { fileURLToPath } from 'node:url';
23
23
  * does not start, the machine's default editor opens the file.
24
24
  * The studio watches the files the setup reads and takes in what the builder's editor changes;
25
25
  * `--no-watch` turns that off, and the studio then reads them when the builder comes back to it.
26
+ * When the project opens the command prints what it loaded (the setup, its entry, the agents
27
+ * with their providers, the tools), what the project has to look at, as the page flags it, and
28
+ * then whether each provider takes its key: one request to each, which `--offline` leaves out.
29
+ * It prints again when what to look at changes, and a line for each run that fails and each
30
+ * error the page meets. `--verbose` adds a line for every run; `--quiet` turns all of it off.
26
31
  * The project loads with its own Deno config: the one `--deno-config` names, else the `deno.json`
27
32
  * or `deno.jsonc` in the folder the command ran in, else the studio's.
28
33
  * A project already open in a studio is not opened twice: the command says where it is. A second
29
34
  * project opens beside the first, on the next free pair of ports.
35
+ *
36
+ * theorem-studio status [setup]
37
+ * theorem-studio errors [setup] [--follow]
38
+ *
39
+ * read a studio that is open on this project, and change nothing: `status` prints what it loaded,
40
+ * what its keys said and what to look at; `errors` prints the last 200 things it told the
41
+ * terminal, and `--follow` then prints each new one until the studio stops.
30
42
  * The studio is opt-in, so this checks for its install and never installs it.
31
43
  */
32
44
  import { builtPage } from './installed.mjs';
33
45
  import { heldPairs, pageAddress, placeFor, serverAddress } from './ports.mjs';
46
+ import { readStudio, studiosOn } from './read-studio.mjs';
34
47
  import { chooseSetup, findSetups, setupLines, setupsNamed } from './setups.mjs';
35
48
 
36
49
  const here = path.dirname(fileURLToPath(import.meta.url));
37
50
 
38
- const USAGE = `usage: ${builtPage ? 'theorem-studio' : 'node studio/start.mjs'} [setup] [--editor <command>] [--deno-config <file>] [--no-watch]`;
51
+ const COMMAND = builtPage ? 'theorem-studio' : 'node studio/start.mjs';
52
+ const USAGE = `usage: ${COMMAND} [setup] [--editor <command>] [--deno-config <file>] [--no-watch] [--quiet] [--offline] [--verbose]
53
+ ${COMMAND} status [setup]
54
+ ${COMMAND} errors [setup] [--follow]`;
55
+ // The setup module is named from where the command was run, which is also the project's name.
56
+ const from = process.env.INIT_CWD ?? process.cwd();
57
+ const args = process.argv.slice(2);
58
+ if (args[0] === 'status' || args[0] === 'errors') await read(args[0], args.slice(1));
39
59
  /** The value after each flag that takes one. A flag with none, a second setup, or anything else, is a mistake. */
40
60
  const VALUED = ['--editor', '--deno-config'];
41
61
  const given = {};
42
62
  let wanted;
43
63
  let noWatch = false;
64
+ let quiet = false;
65
+ let offline = false;
66
+ let verbose = false;
44
67
  let mistaken = false;
45
- const args = process.argv.slice(2);
46
68
  for (let at = 0; at < args.length; at += 1) {
47
69
  const arg = args[at];
48
70
  if (arg === '--no-watch') noWatch = true;
71
+ else if (arg === '--quiet') quiet = true;
72
+ else if (arg === '--offline') offline = true;
73
+ else if (arg === '--verbose') verbose = true;
49
74
  else if (VALUED.includes(arg)) {
50
75
  const value = args[at + 1];
51
76
  if (!value || value.startsWith('--')) mistaken = true;
@@ -60,10 +85,72 @@ if (mistaken) {
60
85
  }
61
86
  const editor = given['--editor'];
62
87
 
63
- // The setup module is named from where the command was run, which is also the project's name.
64
- const from = process.env.INIT_CWD ?? process.cwd();
65
88
  const setup = await setupToOpen();
66
89
 
90
+ /**
91
+ * Reads the studio open on this project's setup, or on the one named, and stops: the setup to read
92
+ * is found as one to open is, except that only one open in a studio counts.
93
+ */
94
+ async function read(command, rest) {
95
+ const follow = command === 'errors' && rest.includes('--follow');
96
+ const named = rest.filter((arg) => arg !== '--follow' || command !== 'errors');
97
+ if (named.length > 1 || named.some((arg) => arg.startsWith('--'))) stopWith(2, USAGE);
98
+ const [name] = named;
99
+ const studio = await studioToRead(name);
100
+ if (command === 'status') {
101
+ console.log(
102
+ `theorem studio: ${path.relative(from, studio.setup)} on ${pageAddress(studio.pair)}/studio/`,
103
+ );
104
+ }
105
+ try {
106
+ await readStudio(studio, command, { follow });
107
+ } catch (error) {
108
+ stopWith(1, `theorem studio: ${error instanceof Error ? error.message : String(error)}`);
109
+ }
110
+ process.exit(0);
111
+ }
112
+
113
+ /** The setups a read may mean: the file named, else the ones with the name, else all of them. */
114
+ function setupsToRead(name) {
115
+ if (name !== undefined && existsSync(path.resolve(from, name))) return [name];
116
+ const found = findSetups(from);
117
+ return (name === undefined ? found : setupsNamed(found, name)).map((one) => one.file);
118
+ }
119
+
120
+ /** The one studio open on those setups; says why there is none, or more than one, and stops. */
121
+ async function studioToRead(name) {
122
+ const setups = setupsToRead(name);
123
+ if (name !== undefined && setups.length === 0) {
124
+ stopWith(
125
+ 2,
126
+ `theorem studio: no setup is named ${name}. This project has:\n\n${setupLines(findSetups(from)).join('\n')}`,
127
+ );
128
+ }
129
+ const open = studiosOn(
130
+ await heldPairs(),
131
+ new Set(setups.map((file) => realpathSync(path.resolve(from, file)))),
132
+ );
133
+ if (open.length === 0) {
134
+ stopWith(
135
+ 1,
136
+ `theorem studio: no studio is open on ${name ?? from}. Open one: ${COMMAND}${name ? ` ${name}` : ''}`,
137
+ );
138
+ }
139
+ if (open.length > 1) {
140
+ stopWith(
141
+ 2,
142
+ `theorem studio: more than one studio is open here. Name the setup:\n\n${open.map((one) => ` ${path.relative(from, one.setup)}`).join('\n')}`,
143
+ );
144
+ }
145
+ return open[0];
146
+ }
147
+
148
+ /** Says why the command stops, and stops with `code`. */
149
+ function stopWith(code, message) {
150
+ console.error(message);
151
+ process.exit(code);
152
+ }
153
+
67
154
  /** Says why no setup opens, and stops. */
68
155
  function refuse(message) {
69
156
  console.error(`${message}\n\n${USAGE}`);
@@ -125,6 +212,9 @@ const server = spawn(
125
212
  projectConfig,
126
213
  ...(editor ? ['--editor', editor] : []),
127
214
  ...(noWatch ? ['--no-watch'] : []),
215
+ ...(quiet ? ['--quiet'] : []),
216
+ ...(offline ? ['--offline'] : []),
217
+ ...(verbose ? ['--verbose'] : []),
128
218
  ],
129
219
  { cwd: from, stdio: ['ignore', 'ignore', 'inherit'] },
130
220
  );
package/surface.js CHANGED
@@ -7,7 +7,7 @@ import { fieldMeta, profileGraphFacet } from '@theoremjs/agents/schema';
7
7
  import { defineAction, secretCard, } from '@theoremjs/agents/surface';
8
8
  import { z } from 'zod';
9
9
  import { compileStudio } from "./compile.js";
10
- import { createConsoleExampleDraft, createDecisionExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft, createResearchScoutDraft, createSpanExampleDraft, } from "./cookbooks/catalog.js";
10
+ import { createConsoleExampleDraft, createDecisionExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft, createResearchScoutDraft, } from "./cookbooks/catalog.js";
11
11
  import { createBlankDraft, defaultModelBinding, defaultToolSpec, draftFacets, excludeFacet, includableFacets, includeFacet, newModelBinding, newToolSpec, removeModelBinding, STUDIO_PROFILE_TYPES, setProfileType, updateModelBinding, } from "./draft.js";
12
12
  import { modelBindingViolation } from "./policy.js";
13
13
  import { modelRoute } from "./providers.js";
@@ -207,7 +207,6 @@ const EXAMPLE_DRAFTS = {
207
207
  narrator: createNarratorExampleDraft,
208
208
  console: createConsoleExampleDraft,
209
209
  decision: createDecisionExampleDraft,
210
- 'span-decision': createSpanExampleDraft,
211
210
  'gemini-embedding-2': createGeminiEmbeddingExampleDraft,
212
211
  };
213
212
  const exampleInput = z.enum(Object.keys(EXAMPLE_DRAFTS));
@@ -2,8 +2,8 @@
2
2
  * @generated by `astryx theme build` — do not edit manually.
3
3
  * Source: ui/studio-theme.ts
4
4
  * Command: astryx theme build ui/studio-theme.ts --out ui/built/theme.css
5
- * CLI: @astryxdesign/cli@0.7.1
6
- * Core: @astryxdesign/core@0.7.1
5
+ * CLI: @astryxdesign/cli@0.7.4
6
+ * Core: @astryxdesign/core@0.7.4
7
7
  */
8
8
 
9
9
  @layer reset, astryx-base, astryx-theme;
@@ -2,8 +2,8 @@
2
2
  * @generated by `astryx theme build` — do not edit manually.
3
3
  * Source: ui/studio-theme.ts
4
4
  * Command: astryx theme build ui/studio-theme.ts --out ui/built/theme.css
5
- * CLI: @astryxdesign/cli@0.7.1
6
- * Core: @astryxdesign/core@0.7.1
5
+ * CLI: @astryxdesign/cli@0.7.4
6
+ * Core: @astryxdesign/core@0.7.4
7
7
  */
8
8
 
9
9
  export {};
@@ -2,8 +2,8 @@
2
2
  * @generated by `astryx theme build` — do not edit manually.
3
3
  * Source: ui/studio-theme.ts
4
4
  * Command: astryx theme build ui/studio-theme.ts --out ui/built/theme.css
5
- * CLI: @astryxdesign/cli@0.7.1
6
- * Core: @astryxdesign/core@0.7.1
5
+ * CLI: @astryxdesign/cli@0.7.4
6
+ * Core: @astryxdesign/core@0.7.4
7
7
  */
8
8
 
9
9
  /// <reference path="./theorem-studio.variants.d.ts" />
@@ -2,15 +2,15 @@
2
2
  * @generated by `astryx theme build` — do not edit manually.
3
3
  * Source: ui/studio-theme.ts
4
4
  * Command: astryx theme build ui/studio-theme.ts --out ui/built/theme.css
5
- * CLI: @astryxdesign/cli@0.7.1
6
- * Core: @astryxdesign/core@0.7.1
5
+ * CLI: @astryxdesign/cli@0.7.4
6
+ * Core: @astryxdesign/core@0.7.4
7
7
  */
8
8
 
9
9
  import { theoremTheme } from '@theoremjs/react/ui/theme';
10
10
  import { tablerIcons } from "@theoremjs/react/ui/icons";
11
11
  const themeIcons = {...theoremTheme["icons"], ...tablerIcons};
12
12
  /**
13
- * theorem-studio theme — built by `npx @astryxdesign/cli theme build`
13
+ * theorem-studio theme — built by `npx @astryxdesign/cli@0.7.4 theme build`
14
14
  * Import the CSS file alongside this module:
15
15
  *
16
16
  * import { theoremStudioTheme } from './theorem-studio';
@@ -2,8 +2,8 @@
2
2
  * @generated by `astryx theme build` — do not edit manually.
3
3
  * Source: ui/studio-theme.ts
4
4
  * Command: astryx theme build ui/studio-theme.ts --out ui/built/theme.css
5
- * CLI: @astryxdesign/cli@0.7.1
6
- * Core: @astryxdesign/core@0.7.1
5
+ * CLI: @astryxdesign/cli@0.7.4
6
+ * Core: @astryxdesign/core@0.7.4
7
7
  */
8
8
 
9
9
  // Generated by astryx theme build
@@ -94,12 +94,30 @@ function browserFile(path, name, component, endpoint, what, props = []) {
94
94
  ].join('\n')}\n`,
95
95
  };
96
96
  }
97
+ /** Allowed value strings from a slot declaration (legacy list or `{ choices }`). */
98
+ function slotChoiceValues(decl) {
99
+ if (Array.isArray(decl)) {
100
+ return decl.filter((value) => typeof value === 'string');
101
+ }
102
+ if (!decl || typeof decl !== 'object' || Array.isArray(decl))
103
+ return [];
104
+ const choices = decl.choices;
105
+ if (!Array.isArray(choices))
106
+ return [];
107
+ return choices.flatMap((choice) => {
108
+ if (!choice || typeof choice !== 'object' || Array.isArray(choice))
109
+ return [];
110
+ const value = choice.value;
111
+ return typeof value === 'string' ? [value] : [];
112
+ });
113
+ }
97
114
  /** What the agent takes from its page and its server: `inputs.slots` and `inputs.context`. */
98
115
  function pageInputs({ profile }) {
99
116
  const inputs = 'inputs' in profile ? profile.inputs : undefined;
100
- const slots = inputs && 'slots' in inputs ? (inputs.slots ?? {}) : {};
117
+ const raw = inputs && 'slots' in inputs ? (inputs.slots ?? {}) : {};
118
+ const slots = Object.entries(raw).map(([name, decl]) => [name, slotChoiceValues(decl)]);
101
119
  const context = inputs && 'context' in inputs ? inputs.context : undefined;
102
- return { slots: Object.entries(slots), from: context?.from ?? [] };
120
+ return { slots, from: context?.from ?? [] };
103
121
  }
104
122
  /** The chat's prop for the tools this page answers: a function per tool, returning its output. */
105
123
  function pageToolsProp(agent) {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Tells the studio command what went wrong in the page, so the builder's terminal, and
3
+ * `theorem-studio errors`, see what the builder saw. Only the studio's own page does this: its
4
+ * project's server keeps the page's errors with the rest of what happened.
5
+ *
6
+ * @module
7
+ */
8
+ /** What an error says, with where it came from when the browser knows. */
9
+ export declare function errorText(error: unknown): string;
10
+ /** Sends `text` to the project's server at `endpoint`. Never throws: a page that cannot tell, does not. */
11
+ export declare function tellServer(endpoint: string, text: string): void;
12
+ /** Sends each error the page does not catch, and each promise nothing waits on that fails. */
13
+ export declare function reportPageErrors(endpoint: string): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Tells the studio command what went wrong in the page, so the builder's terminal, and
3
+ * `theorem-studio errors`, see what the builder saw. Only the studio's own page does this: its
4
+ * project's server keeps the page's errors with the rest of what happened.
5
+ *
6
+ * @module
7
+ */
8
+ /** The longest error the page sends; the server refuses more. */
9
+ const SENT_CAP = 4000;
10
+ /** What an error says, with where it came from when the browser knows. */
11
+ export function errorText(error) {
12
+ if (error instanceof Error) {
13
+ const where = error.stack?.split('\n').find((line) => line.includes('at '));
14
+ return `${error.name}: ${error.message}${where ? ` (${where.trim()})` : ''}`;
15
+ }
16
+ return String(error);
17
+ }
18
+ /** Sends `text` to the project's server at `endpoint`. Never throws: a page that cannot tell, does not. */
19
+ export function tellServer(endpoint, text) {
20
+ fetch(`${endpoint}/events`, {
21
+ method: 'POST',
22
+ headers: { 'Content-Type': 'application/json' },
23
+ body: JSON.stringify({ text: text.slice(0, SENT_CAP) }),
24
+ keepalive: true,
25
+ }).catch(() => { });
26
+ }
27
+ /** Sends each error the page does not catch, and each promise nothing waits on that fails. */
28
+ export function reportPageErrors(endpoint) {
29
+ addEventListener('error', (event) => tellServer(endpoint, errorText(event.error ?? event.message)));
30
+ addEventListener('unhandledrejection', (event) => tellServer(endpoint, errorText(event.reason)));
31
+ }
@@ -21,10 +21,6 @@ export const STUDIO_EXAMPLES = {
21
21
  label: COOKBOOKS.decision.label,
22
22
  description: COOKBOOKS.decision.description,
23
23
  },
24
- 'span-decision': {
25
- label: COOKBOOKS['span-decision'].label,
26
- description: COOKBOOKS['span-decision'].description,
27
- },
28
24
  'gemini-embedding-2': {
29
25
  label: COOKBOOKS['gemini-embedding-2'].label,
30
26
  description: COOKBOOKS['gemini-embedding-2'].description,
@@ -2,7 +2,7 @@
2
2
  * What the studio's page sends an agent: a value for each of its slots and its context
3
3
  * package. Kept in this tab beside the conversation, never in the profile.
4
4
  */
5
- import { type StudioRunPayload } from '../../mod.ts';
5
+ import { type SlotDraft, type StudioRunPayload } from '../../mod.ts';
6
6
  /** What the builder set: the value picked for each slot, and the context as typed. */
7
7
  export interface PageValues {
8
8
  slots: Record<string, string>;
@@ -10,6 +10,7 @@ export interface PageValues {
10
10
  }
11
11
  /** What the agent takes from a page. */
12
12
  export interface PageInputs {
13
+ /** Allowed values per slot name (descriptions stay on the profile / chat UI). */
13
14
  slots: Record<string, readonly string[]>;
14
15
  takesContext: boolean;
15
16
  /** The tools the page answers. Only a call asks the page. */
@@ -17,8 +18,12 @@ export interface PageInputs {
17
18
  }
18
19
  /** The context a blank preview box suggests. */
19
20
  export declare const CONTEXT_PLACEHOLDER = "{\n \"page\": \"Checkout\"\n}";
20
- /** The slots a draft's JSON declares so far: each name with a list of text. Anything else is left out. */
21
- export declare function draftSlots(slotsJson: string): Record<string, readonly string[]>;
21
+ /** The slots a draft has so far that a page can pick from: each named, with a value, once. */
22
+ export declare function draftSlots(slots: readonly SlotDraft[]): {
23
+ name: string;
24
+ label: string;
25
+ values: string[];
26
+ }[];
22
27
  /** Why typed context is not sent, when it is not JSON. */
23
28
  export declare function contextErrorOf(contextJson: string): string | undefined;
24
29
  /** What the compiled agent takes from a page, or null when it takes nothing. */
@@ -11,19 +11,35 @@ const NO_PAGE_VALUES = { slots: {}, contextJson: '' };
11
11
  export const CONTEXT_PLACEHOLDER = `{
12
12
  "page": "Checkout"
13
13
  }`;
14
- /** The slots a draft's JSON declares so far: each name with a list of text. Anything else is left out. */
15
- export function draftSlots(slotsJson) {
16
- try {
17
- const typed = JSON.parse(slotsJson.trim() || '{}');
18
- if (!isRecord(typed))
19
- return {};
20
- return Object.fromEntries(Object.entries(typed).filter((entry) => Array.isArray(entry[1]) &&
21
- entry[1].length > 0 &&
22
- entry[1].every((value) => typeof value === 'string')));
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;
23
19
  }
24
- catch {
25
- return {};
20
+ if (!isRecord(decl) || !Array.isArray(decl.choices) || decl.choices.length === 0) {
21
+ return undefined;
26
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
+ /** The slots a draft has so far that a page can pick from: each named, with a value, once. */
33
+ export function draftSlots(slots) {
34
+ const seen = new Set();
35
+ return slots.flatMap((slot) => {
36
+ const name = slot.name.trim();
37
+ const values = slot.choices.map((choice) => choice.value.trim()).filter(Boolean);
38
+ if (!name || !values.length || seen.has(name))
39
+ return [];
40
+ seen.add(name);
41
+ return [{ name, label: slot.label.trim() || name, values }];
42
+ });
27
43
  }
28
44
  /** Why typed context is not sent, when it is not JSON. */
29
45
  export function contextErrorOf(contextJson) {
@@ -41,10 +57,15 @@ export function contextErrorOf(contextJson) {
41
57
  /** What the compiled agent takes from a page, or null when it takes nothing. */
42
58
  export function pageInputsOf(payload) {
43
59
  const { profile } = payload;
44
- if (profile.type === 'decision' || profile.type === 'host' || profile.type === 'embedding')
60
+ if (profile.type === 'decision' || profile.type === 'host' || profile.type === 'embedding') {
45
61
  return null;
62
+ }
46
63
  const inputs = 'inputs' in profile ? profile.inputs : undefined;
47
- const slots = inputs?.slots ?? {};
64
+ const raw = inputs?.slots ?? {};
65
+ const slots = Object.fromEntries(Object.entries(raw).flatMap(([name, decl]) => {
66
+ const values = choiceValues(decl);
67
+ return values ? [[name, values]] : [];
68
+ }));
48
69
  const takesContext = inputs?.context?.from.includes('client') ?? false;
49
70
  const pageTools = Object.keys(studioPageTools(payload));
50
71
  if (!Object.keys(slots).length && !takesContext && !pageTools.length)