@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
package/system-markup.js CHANGED
@@ -1,14 +1,34 @@
1
1
  const OPEN = /\{\s*private\s*:/g;
2
- function lineAt(text, index) {
3
- return text.slice(0, index).split('\n').length;
2
+ const BLANK_LINE = /\n(?:[ \t]*\n)+/;
3
+ /** A line as the profile holds it, without the white space at its ends. */
4
+ function promptLine(parts) {
5
+ const [first, ...rest] = parts;
6
+ if (first === undefined)
7
+ return undefined;
8
+ if (rest.length === 0 && typeof first === 'string')
9
+ return first.trim() || undefined;
10
+ const line = [...parts];
11
+ const last = parts.at(-1);
12
+ if (typeof first === 'string')
13
+ line[0] = first.trimStart();
14
+ if (typeof last === 'string')
15
+ line[line.length - 1] = last.trimEnd();
16
+ const kept = line.filter((part) => part !== '');
17
+ const [only, ...others] = kept;
18
+ return others.length === 0 && typeof only === 'string' ? only : kept;
4
19
  }
5
20
  /**
6
21
  * A section closes at the `}` that balances its `{`, so braces inside it pair
7
- * up as written. Its text is trimmed; the text around it is kept as written,
8
- * apart from the ends of the whole prompt.
22
+ * up as written, and a blank line inside it stays in it. Its text is trimmed;
23
+ * the text around it is kept as written, apart from the ends of each line.
9
24
  */
10
25
  function parseSystemMarkup(text) {
11
- const parts = [];
26
+ const lines = [[]];
27
+ const addText = (chunk) => {
28
+ const [head = '', ...rest] = chunk.split(BLANK_LINE);
29
+ lines.at(-1)?.push(head);
30
+ lines.push(...rest.map((line) => [line]));
31
+ };
12
32
  let at = 0;
13
33
  for (const open of text.matchAll(OPEN)) {
14
34
  if (open.index < at)
@@ -21,31 +41,30 @@ function parseSystemMarkup(text) {
21
41
  else if (text[close] === '}')
22
42
  depth--;
23
43
  }
44
+ addText(text.slice(at, open.index));
24
45
  if (depth > 0) {
25
46
  return {
26
47
  ok: false,
27
- message: `The {private: section on line ${String(lineAt(text, open.index))} has no closing }.`,
48
+ message: `The {private: section on line ${String(lines.length)} has no closing }.`,
28
49
  };
29
50
  }
30
51
  const secret = text.slice(open.index + open[0].length, close - 1).trim();
31
52
  if (!secret) {
32
53
  return {
33
54
  ok: false,
34
- message: `The {private: section on line ${String(lineAt(text, open.index))} is empty.`,
55
+ message: `The {private: section on line ${String(lines.length)} is empty.`,
35
56
  };
36
57
  }
37
- parts.push(text.slice(at, open.index), { private: secret });
58
+ lines.at(-1)?.push({ private: secret });
38
59
  at = close;
39
60
  }
40
- parts.push(text.slice(at));
41
- if (parts.length === 1)
42
- return { ok: true, prompt: text.trim() || undefined };
43
- const first = parts[0];
44
- const last = parts.at(-1);
45
- if (typeof first === 'string')
46
- parts[0] = first.trimStart();
47
- if (typeof last === 'string')
48
- parts[parts.length - 1] = last.trimEnd();
49
- return { ok: true, prompt: parts.filter((part) => part !== '') };
61
+ addText(text.slice(at));
62
+ return {
63
+ ok: true,
64
+ lines: lines.flatMap((parts) => {
65
+ const line = promptLine(parts.filter((part) => part !== ''));
66
+ return line === undefined ? [] : [line];
67
+ }),
68
+ };
50
69
  }
51
- export { parseSystemMarkup };
70
+ export { parseSystemMarkup, promptLine };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A tool's reader: a decision agent that keeps the passages of the tool's output that bear on the
3
+ * model's question, so the model reads less. The kernel has no such setting. A host writes it at
4
+ * `post_tool`, and this is the studio's.
5
+ */
6
+ import type { DecisionQuestion, DecisionResult, StageHandler } from '@theoremjs/agents';
7
+ import type { ToolRegistration } from './registrations.ts';
8
+ /** The decision agent that reads a tool's output, and what it asks of each passage. */
9
+ export interface ToolReader {
10
+ profile: string;
11
+ questions: Record<string, DecisionQuestion>;
12
+ }
13
+ /** Runs a reader on one passage. */
14
+ export type ReadPassage = (reader: ToolReader, state: {
15
+ question: string;
16
+ passage: string;
17
+ }) => Promise<DecisionResult>;
18
+ /** Each tool with a reader, by the tool's name. */
19
+ export declare function toolReaders(tools: readonly ToolRegistration[]): Map<string, ToolReader>;
20
+ /** Runs each tool's reader on its finished output. */
21
+ export declare function toolReaderStage(readers: ReadonlyMap<string, ToolReader>, read: ReadPassage): StageHandler;
22
+ /** One handler for a turn: `steer` keeps its stages, and `readers` adds what it asks. */
23
+ export declare function bothStages(steer: StageHandler, readers: StageHandler): StageHandler;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * A tool's reader: a decision agent that keeps the passages of the tool's output that bear on the
3
+ * model's question, so the model reads less. The kernel has no such setting. A host writes it at
4
+ * `post_tool`, and this is the studio's.
5
+ */
6
+ /** Each tool with a reader, by the tool's name. */
7
+ export function toolReaders(tools) {
8
+ return new Map(tools.flatMap((tool) => tool.type !== 'agent' && tool.stageAgent && tool.stageQuestions
9
+ ? [
10
+ [tool.name, { profile: tool.stageAgent, questions: tool.stageQuestions }],
11
+ ]
12
+ : []));
13
+ }
14
+ /** Every choice question came out on its first choice, which keeps the passage. */
15
+ function kept(reader, result) {
16
+ return Object.entries(reader.questions).every(([id, question]) => {
17
+ if (question.type !== 'choice')
18
+ return true;
19
+ const answer = result.answers[id];
20
+ return answer?.type === 'choice' && answer.choice === Object.keys(question.criteria)[0];
21
+ });
22
+ }
23
+ async function readOutput(reader, ctx, read) {
24
+ const { outputRaw: output, input } = ctx;
25
+ const question = input?.question;
26
+ if (typeof output !== 'string' || typeof question !== 'string')
27
+ return undefined;
28
+ const passages = output
29
+ .split(/\n\s*\n/)
30
+ .map((passage) => passage.trim())
31
+ .filter(Boolean);
32
+ try {
33
+ const results = await Promise.all(passages.map((passage) => read(reader, { question, passage })));
34
+ const left = passages.filter((_, at) => {
35
+ const result = results[at];
36
+ return result !== undefined && kept(reader, result);
37
+ });
38
+ return left.length === passages.length ? undefined : { mutate: { output: left.join('\n\n') } };
39
+ }
40
+ catch {
41
+ // why: A filter that failed drops nothing: the model reads the page whole.
42
+ return undefined;
43
+ }
44
+ }
45
+ /** Runs each tool's reader on its finished output. */
46
+ export function toolReaderStage(readers, read) {
47
+ return (ctx) => {
48
+ if (ctx.stage !== 'post_tool' || ctx.failure || ctx.callNotStarted || ctx.awaiting)
49
+ return;
50
+ const reader = ctx.tool ? readers.get(ctx.tool) : undefined;
51
+ return reader && readOutput(reader, ctx, read);
52
+ };
53
+ }
54
+ /** One handler for a turn: `steer` keeps its stages, and `readers` adds what it asks. */
55
+ export function bothStages(steer, readers) {
56
+ return async (ctx) => {
57
+ const [steered, filtered] = await Promise.all([steer(ctx), readers(ctx)]);
58
+ return steered || filtered ? { ...steered, ...filtered } : undefined;
59
+ };
60
+ }
package/tools.js CHANGED
@@ -22,6 +22,8 @@ export function registerCustomTool(tools, tool, handlers = {}) {
22
22
  loadTier: tool.loadTier,
23
23
  permission: tool.permission,
24
24
  ...(tool.labels ? { labels: tool.labels } : {}),
25
+ ...(tool.after ? { after: true } : {}),
26
+ ...(tool.background ? { background: tool.background } : {}),
25
27
  };
26
28
  if (tool.type === 'agent') {
27
29
  tools.register({
@@ -93,7 +95,9 @@ export function registerStudioTools(tools, customTools, handlers) {
93
95
  export function registerDefined(registry, profile, customTools, structured, handlers) {
94
96
  registerStudioTools(registry.tools, customTools, handlers);
95
97
  if (structured && profile.type !== 'live') {
96
- registry.schemas.register(structured.id, structured.spec);
98
+ for (const { id, spec } of [structured, ...(structured.also ?? [])]) {
99
+ registry.schemas.register(id, spec);
100
+ }
97
101
  }
98
102
  registry.profiles.register(profile);
99
103
  return profile;
package/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ToolBackground } from '@theoremjs/agents/kernel';
1
2
  import { type AuthUnauthenticatedPolicy, type CustomToolType, type HttpMethod, type StudioAuthType, type ToolAccess, type ToolLoadTier, type ToolPermission } from '@theoremjs/agents/schema';
2
3
  /** The tool types a studio draft builds. */
3
4
  export type StudioToolType = CustomToolType;
@@ -24,6 +25,10 @@ export type StudioToolSpecSeed = {
24
25
  stubOutputJson?: string;
25
26
  /** A function tool the page answers; the studio's page answers with the stub. */
26
27
  answeredBy?: 'page';
28
+ /** The model can name tools of its step that finish before this one starts. */
29
+ after?: boolean;
30
+ /** When the model gets its reply while the body goes on. */
31
+ background?: ToolBackground;
27
32
  endpoint?: string;
28
33
  method?: HttpMethod;
29
34
  headersJson?: string;
@@ -40,7 +45,7 @@ export type StudioToolSpecSeed = {
40
45
  sessionMax?: number | null;
41
46
  /** An agent tool's agent, by its workspace key. */
42
47
  agentKey?: string;
43
- /** A decision or text agent that filters this tool's output at `post_tool`, by its workspace key. */
48
+ /** A decision agent that filters this tool's output at `post_tool`, by its workspace key. */
44
49
  stageAgentKey?: string;
45
50
  /** An agent tool's calls in one turn of its caller; `null` or absent: no cap but max steps. */
46
51
  maxCallsPerTurn?: number | null;
@@ -1,5 +1,5 @@
1
1
  import type { InputStatus } from '@astryxdesign/core/Field';
2
- import { type NodeOrigins, type StudioAsks, type StudioIssue, type StudioProvider, type StudioRunPayload, type StudioRunsOn, type WriteAsk } from '../mod.ts';
2
+ import { type NodeOrigins, type StudioIssue, type StudioProvider, type StudioRunPayload, type StudioRunsOn } from '../mod.ts';
3
3
  import type { SettingOrigin } from '../server/save-wire.ts';
4
4
  /** The compile issues for the node being edited; rows show the ones on their field. */
5
5
  export declare const NodeIssues: import("react").Context<readonly StudioIssue[]>;
@@ -16,13 +16,6 @@ export declare const RowOrigins: import("react").Context<{
16
16
  scope: NodeOrigins;
17
17
  open: (origin: SettingOrigin) => void;
18
18
  } | null>;
19
- /**
20
- * Asks the builder before a real run of a tool that writes, and answers whether to run it. Where
21
- * no page mounts the question, the run is refused.
22
- */
23
- export declare const ConfirmWrite: import("react").Context<(ask: WriteAsk) => Promise<boolean>>;
24
- /** The project's tools that write: the ones the studio makes ask, and the ones it cannot. */
25
- export declare const ProjectAsks: import("react").Context<StudioAsks>;
26
19
  /** The origin a section around a row has already named, so the row does not name it again. */
27
20
  export declare const SaidOrigin: import("react").Context<SettingOrigin | undefined>;
28
21
  /**
@@ -23,13 +23,6 @@ export function useFieldStatus() {
23
23
  * builder's editor. `null` when no project is open, or the files do not hold the node.
24
24
  */
25
25
  export const RowOrigins = createContext(null);
26
- /**
27
- * Asks the builder before a real run of a tool that writes, and answers whether to run it. Where
28
- * no page mounts the question, the run is refused.
29
- */
30
- export const ConfirmWrite = createContext(() => Promise.resolve(false));
31
- /** The project's tools that write: the ones the studio makes ask, and the ones it cannot. */
32
- export const ProjectAsks = createContext({ asked: [], inside: [] });
33
26
  /** The origin a section around a row has already named, so the row does not name it again. */
34
27
  export const SaidOrigin = createContext(undefined);
35
28
  /**
package/ui/inspector.d.ts CHANGED
@@ -3,6 +3,16 @@ import { type IconType } from '@astryxdesign/core/Icon';
3
3
  import { type SelectorOptionType } from '@astryxdesign/core/Selector';
4
4
  import { type ReactNode } from 'react';
5
5
  import type { SettingOrigin } from '../server/save-wire.ts';
6
+ /**
7
+ * Inspector building blocks: captioned sections of label-and-control rows, after Astryx's
8
+ * canvas editor template. Every control is `sm` and hides its own label, because the row's
9
+ * label column names it; that column is one fixed width, so every control starts on one edge.
10
+ */
11
+ /**
12
+ * The label column, wide enough for the longest label ("Temperature", "Attachments") on one line.
13
+ * The template's is 80, which fits its shorter labels.
14
+ */
15
+ export declare const LABEL_COLUMN = 96;
6
16
  /**
7
17
  * Controls the project's files set in code: they show their value and take no edit. A disabled
8
18
  * fieldset turns off every control inside it, whatever kind it is.
@@ -65,6 +75,24 @@ export type FieldRowProps = {
65
75
  /** The draft field whose issues show on this row. */
66
76
  field?: string;
67
77
  } & IsRequired;
78
+ /**
79
+ * The names and values of an object the draft holds as JSON text, a row each. The rows are kept
80
+ * here while they are typed, since a row with no name is no part of the object yet, and start
81
+ * again from `value` when something else changes it. `typed` takes any JSON as a value.
82
+ */
83
+ export declare function EntriesRow({ label, noun, path, field, value, typed, namePlaceholder, valuePlaceholder, onChange, }: {
84
+ label: string;
85
+ /** What one row is: "Header" gives "Add header" and "Header 1 name". */
86
+ noun: string;
87
+ path: string;
88
+ /** The draft field whose issues show on this row. */
89
+ field: string;
90
+ value: string;
91
+ typed?: boolean;
92
+ namePlaceholder: string;
93
+ valuePlaceholder: string;
94
+ onChange: (next: string) => void;
95
+ }): import("react").JSX.Element;
68
96
  /**
69
97
  * Free text. Left blank, it shows `placeholder`, a value Tab takes up to edit (an example, or the
70
98
  * default); else `hint`, or what leaving it out does.
@@ -197,6 +225,8 @@ export type ChoiceRowProps<T extends string> = {
197
225
  value: T | '';
198
226
  options: readonly Choice<T>[];
199
227
  isDisabled?: boolean;
228
+ /** False for a choice that always holds a value, so it offers no way to clear it. */
229
+ hasClear?: boolean;
200
230
  hasSearch?: boolean;
201
231
  /** The options are still arriving. */
202
232
  isLoading?: boolean;
@@ -215,7 +245,7 @@ export type ChoiceRowProps<T extends string> = {
215
245
  * leaving it out does while blank. `hasSearch` filters a long list. A value the list leaves out
216
246
  * shows as itself, marked "Not in the list", so a list never hides or rewrites what the file says.
217
247
  */
218
- export declare function ChoiceRow<T extends string>({ label, path, field, value, options, isDisabled, isRequired, hasSearch, isLoading, emptyText, placeholder, status: given, hasHoverDescriptions, onChange, }: ChoiceRowProps<T>): import("react").JSX.Element;
248
+ export declare function ChoiceRow<T extends string>({ label, path, field, value, options, isDisabled, isRequired, hasClear, hasSearch, isLoading, emptyText, placeholder, status: given, hasHoverDescriptions, onChange, }: ChoiceRowProps<T>): import("react").JSX.Element;
219
249
  /**
220
250
  * Several choices from a list, the first few as badges and the rest counted (`ListBadges`): the
221
251
  * trigger is one line tall, and Astryx wraps badges past it. Left empty, it shows what leaving it
@@ -230,6 +260,18 @@ export declare function ListRow({ label, path, field, value, options, onChange,
230
260
  options: SelectorOptionType[];
231
261
  onChange: (next: string[]) => void;
232
262
  }): import("react").JSX.Element;
263
+ /** Names as tokens, typed and committed with Enter. Duplicates and blanks never make a token. */
264
+ export declare function NamesInput({ label, status, value, placeholder, isDisabled, disabledMessage, overflow, onChange, }: {
265
+ label: string;
266
+ status?: InputStatus;
267
+ value: string[];
268
+ placeholder?: string;
269
+ isDisabled?: boolean;
270
+ disabledMessage?: string;
271
+ /** `none` keeps every token in sight, at the same height, focused or not. */
272
+ overflow?: 'none' | 'unfocusedInline';
273
+ onChange: (next: string[]) => void;
274
+ }): import("react").JSX.Element;
233
275
  /**
234
276
  * Free-form names, typed and committed with Enter, each a token. Duplicates and blanks never make
235
277
  * it in. `disabledMessage` says why, when `isDisabled`.
package/ui/inspector.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from '@astryxdesign/core/Button';
2
3
  import { FieldStatus } from '@astryxdesign/core/FieldStatus';
3
4
  import { HoverCard } from '@astryxdesign/core/HoverCard';
4
5
  import { HStack } from '@astryxdesign/core/HStack';
@@ -20,11 +21,12 @@ import { Token } from '@astryxdesign/core/Token';
20
21
  import { Tokenizer } from '@astryxdesign/core/Tokenizer';
21
22
  import { Tooltip } from '@astryxdesign/core/Tooltip';
22
23
  import { VStack } from '@astryxdesign/core/VStack';
23
- import { IconArrowBackUp, IconCheck, IconCode, IconCopy } from '@tabler/icons-react';
24
+ import { IconArrowBackUp, IconCheck, IconCode, IconCopy, IconPlus, IconX, } from '@tabler/icons-react';
24
25
  import { fieldMeta } from '@theoremjs/agents';
25
26
  import { useContext, useState } from 'react';
26
- import { originLabel, originPlace, originShortLabel, STUDIO_PROFILE_TYPES } from "../mod.js";
27
+ import { draftKey, originLabel, originPlace, originShortLabel, STUDIO_PROFILE_TYPES, } from "../mod.js";
27
28
  import { ISSUE_ROW_ATTRIBUTE, ListBadges, SaidOrigin, useFieldStatus, useRowOrigin, } from "./inspector-context.js";
29
+ import { entriesOf, entriesText } from "./lib/entries.js";
28
30
  import { tabFills } from "./lib/tab-fills.js";
29
31
  /**
30
32
  * Inspector building blocks: captioned sections of label-and-control rows, after Astryx's
@@ -35,7 +37,7 @@ import { tabFills } from "./lib/tab-fills.js";
35
37
  * The label column, wide enough for the longest label ("Temperature", "Attachments") on one line.
36
38
  * The template's is 80, which fits its shorter labels.
37
39
  */
38
- const LABEL_COLUMN = 96;
40
+ export const LABEL_COLUMN = 96;
39
41
  /**
40
42
  * Whether the field at `path` must be set, and what leaving it out does, from the kernel's catalog.
41
43
  * `isRequired` overrides it for a field required only in some cases, saying whether it is now.
@@ -140,6 +142,41 @@ function useFieldRow({ label, path, field, isRequired }) {
140
142
  function FillRow({ label, path, required, status, note, children, }) {
141
143
  return (_jsx(InspectorRow, { label: label, path: path, isRequired: required, hasIssue: status !== undefined, hasNote: Boolean((status ?? note)?.message), children: _jsx(StackItem, { size: "fill", children: children }) }));
142
144
  }
145
+ /**
146
+ * The names and values of an object the draft holds as JSON text, a row each. The rows are kept
147
+ * here while they are typed, since a row with no name is no part of the object yet, and start
148
+ * again from `value` when something else changes it. `typed` takes any JSON as a value.
149
+ */
150
+ export function EntriesRow({ label, noun, path, field, value, typed = false, namePlaceholder, valuePlaceholder, onChange, }) {
151
+ const status = useFieldStatus()(field);
152
+ const [entries, setEntries] = useState(() => entriesOf(value, typed));
153
+ const [held, setHeld] = useState(value);
154
+ if (value !== held) {
155
+ setHeld(value);
156
+ setEntries(entriesOf(value, typed));
157
+ }
158
+ const change = (next) => {
159
+ const text = entriesText(next, typed);
160
+ setEntries(next);
161
+ setHeld(text);
162
+ onChange(text);
163
+ };
164
+ return (_jsxs(VStack, { gap: 1, children: [_jsx(Tooltip, { content: fieldMeta(path)?.doc, hasHoverIndication: false, children: _jsx(Text, { type: "label", weight: "semibold", children: label }) }), entries.map((entry, at) => {
165
+ const row = `${noun} ${String(at + 1)}`;
166
+ const set = (patch) => {
167
+ change(entries.map((each) => (each.key === entry.key ? { ...each, ...patch } : each)));
168
+ };
169
+ return (_jsxs(HStack, { gap: 1, vAlign: "center", children: [_jsx(StackItem, { size: "fill", children: _jsx(TextInput, { label: `${row} name`, isLabelHidden: true, size: "sm", status: status, value: entry.name, placeholder: namePlaceholder, onChange: (name) => {
170
+ set({ name });
171
+ } }) }), _jsx(StackItem, { size: "fill", children: _jsx(TextInput, { label: `${row} value`, isLabelHidden: true, size: "sm", value: entry.value, placeholder: valuePlaceholder, onChange: (next) => {
172
+ set({ value: next });
173
+ } }) }), _jsx(IconButton, { label: `Remove ${row.toLowerCase()}`, variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: IconX, size: "sm" }), onClick: () => {
174
+ change(entries.filter((each) => each.key !== entry.key));
175
+ } })] }, entry.key));
176
+ }), _jsx(HStack, { children: _jsx(Button, { label: `Add ${noun.toLowerCase()}`, variant: "ghost", size: "sm", icon: _jsx(Icon, { icon: IconPlus, size: "sm" }), onClick: () => {
177
+ change([...entries, { key: draftKey('entry'), name: '', value: '' }]);
178
+ } }) })] }));
179
+ }
143
180
  /**
144
181
  * Free text. Left blank, it shows `placeholder`, a value Tab takes up to edit (an example, or the
145
182
  * default); else `hint`, or what leaving it out does.
@@ -229,7 +266,7 @@ export function SegmentedRow({ label, path, field, value, segments, isDisabled,
229
266
  * leaving it out does while blank. `hasSearch` filters a long list. A value the list leaves out
230
267
  * shows as itself, marked "Not in the list", so a list never hides or rewrites what the file says.
231
268
  */
232
- export function ChoiceRow({ label, path, field, value, options, isDisabled, isRequired, hasSearch, isLoading, emptyText, placeholder, status: given, hasHoverDescriptions, onChange, }) {
269
+ export function ChoiceRow({ label, path, field, value, options, isDisabled, isRequired, hasClear = true, hasSearch, isLoading, emptyText, placeholder, status: given, hasHoverDescriptions, onChange, }) {
233
270
  const status = useFieldStatus()(field) ?? given;
234
271
  const { required, unset } = presence(path, isRequired);
235
272
  const listed = options.some((option) => (typeof option === 'string' ? option : option.value) === value);
@@ -256,7 +293,7 @@ export function ChoiceRow({ label, path, field, value, options, isDisabled, isRe
256
293
  emptyText,
257
294
  ...(hasHoverDescriptions ? { renderOption: hoverDescribed } : {}),
258
295
  };
259
- return (_jsx(InspectorRow, { label: label, path: path, isRequired: required, hasIssue: status !== undefined, hasNote: Boolean(status?.message), children: _jsx(StackItem, { size: "fill", children: required ? (_jsx(Selector, { ...shared, isRequired: true, value: value, placeholder: placeholder, onChange: choose })) : (_jsx(Selector, { ...shared, value: value || null, placeholder: placeholder ?? unset, hasClear: true, onChange: choose })) }) }));
296
+ return (_jsx(InspectorRow, { label: label, path: path, isRequired: required, hasIssue: status !== undefined, hasNote: Boolean(status?.message), children: _jsx(StackItem, { size: "fill", children: required || !hasClear ? (_jsx(Selector, { ...shared, isRequired: required, value: value, placeholder: placeholder, onChange: choose })) : (_jsx(Selector, { ...shared, value: value || null, placeholder: placeholder ?? unset, hasClear: true, onChange: choose })) }) }));
260
297
  }
261
298
  /** An option named on its row, with its description in a tooltip. */
262
299
  function hoverDescribed(option) {
@@ -276,6 +313,13 @@ export function ListRow({ label, path, field, value, options, onChange, }) {
276
313
  }
277
314
  /** A names row suggests nothing; every token is one the user typed. */
278
315
  const NO_SUGGESTIONS = { search: () => [], bootstrap: () => [] };
316
+ /** Names as tokens, typed and committed with Enter. Duplicates and blanks never make a token. */
317
+ export function NamesInput({ label, status, value, placeholder, isDisabled, disabledMessage, overflow = 'unfocusedInline', onChange, }) {
318
+ return (_jsx(Tokenizer, { label: label, status: status, isLabelHidden: true, size: "sm", value: value.map((name) => ({ id: name, label: name })), searchSource: NO_SUGGESTIONS, hasCreate: true, debounceMs: 0, placeholder: placeholder, isDisabled: isDisabled, disabledMessage: disabledMessage, tokenOverflowBehavior: overflow, onChange: (items) => {
319
+ const names = items.map((item) => item.label.trim()).filter(Boolean);
320
+ onChange([...new Set(names)]);
321
+ } }));
322
+ }
279
323
  /**
280
324
  * Free-form names, typed and committed with Enter, each a token. Duplicates and blanks never make
281
325
  * it in. `disabledMessage` says why, when `isDisabled`.
@@ -283,8 +327,5 @@ const NO_SUGGESTIONS = { search: () => [], bootstrap: () => [] };
283
327
  export function NamesRow({ label, path, field, value, placeholder, isDisabled, disabledMessage, onChange, }) {
284
328
  const status = useFieldStatus()(field);
285
329
  const { unset } = presence(path);
286
- return (_jsx(InspectorRow, { label: label, path: path, hasIssue: status !== undefined, hasNote: Boolean(status?.message), children: _jsx(StackItem, { size: "fill", children: _jsx(Tokenizer, { label: label, status: status, isLabelHidden: true, size: "sm", value: value.map((name) => ({ id: name, label: name })), searchSource: NO_SUGGESTIONS, hasCreate: true, debounceMs: 0, placeholder: placeholder ?? unset, isDisabled: isDisabled, disabledMessage: disabledMessage, tokenOverflowBehavior: "unfocusedInline", onChange: (items) => {
287
- const names = items.map((item) => item.label.trim()).filter(Boolean);
288
- onChange([...new Set(names)]);
289
- } }) }) }));
330
+ return (_jsx(InspectorRow, { label: label, path: path, hasIssue: status !== undefined, hasNote: Boolean(status?.message), children: _jsx(StackItem, { size: "fill", children: _jsx(NamesInput, { label: label, status: status, value: value, placeholder: placeholder ?? unset, isDisabled: isDisabled, disabledMessage: disabledMessage, onChange: onChange }) }) }));
290
331
  }
@@ -0,0 +1,13 @@
1
+ /** One name and value of a JSON object, as a row of the editor holds it. */
2
+ export interface Entry {
3
+ key: string;
4
+ name: string;
5
+ value: string;
6
+ }
7
+ /**
8
+ * The rows of a JSON object held as text: none while it is not one. With `typed`, a value can be
9
+ * any JSON and plain text is a string, so a string that reads as JSON shows in its quotes.
10
+ */
11
+ export declare function entriesOf(text: string, typed: boolean): Entry[];
12
+ /** The JSON object the named rows make, as text: blank when none is named. */
13
+ export declare function entriesText(entries: readonly Entry[], typed: boolean): string;
@@ -0,0 +1,43 @@
1
+ import { draftKey } from "../../draft.js";
2
+ import { isRecord } from "./studio-session.js";
3
+ function readsAsJson(text) {
4
+ try {
5
+ JSON.parse(text);
6
+ return true;
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }
12
+ function valueText(value, typed) {
13
+ if (typeof value !== 'string')
14
+ return JSON.stringify(value);
15
+ return typed && readsAsJson(value) ? JSON.stringify(value) : value;
16
+ }
17
+ function typedValue(text) {
18
+ return readsAsJson(text) ? JSON.parse(text) : text;
19
+ }
20
+ /**
21
+ * The rows of a JSON object held as text: none while it is not one. With `typed`, a value can be
22
+ * any JSON and plain text is a string, so a string that reads as JSON shows in its quotes.
23
+ */
24
+ export function entriesOf(text, typed) {
25
+ if (!readsAsJson(text))
26
+ return [];
27
+ const parsed = JSON.parse(text);
28
+ if (!isRecord(parsed))
29
+ return [];
30
+ return Object.entries(parsed).map(([name, value]) => ({
31
+ key: draftKey('entry'),
32
+ name,
33
+ value: valueText(value, typed),
34
+ }));
35
+ }
36
+ /** The JSON object the named rows make, as text: blank when none is named. */
37
+ export function entriesText(entries, typed) {
38
+ const named = entries.flatMap(({ name, value }) => {
39
+ const trimmed = name.trim();
40
+ return trimmed ? [[trimmed, typed ? typedValue(value) : value]] : [];
41
+ });
42
+ return named.length > 0 ? JSON.stringify(Object.fromEntries(named)) : '';
43
+ }
@@ -8,6 +8,11 @@ export declare function recordsTraces(payload: StudioRunPayload | null): boolean
8
8
  * trace panel reads them: the same panel a draft's run fills in the playground. Each run carries
9
9
  * who it acts as, so the project's tools act for that person.
10
10
  */
11
+ /**
12
+ * A live call's socket on `endpoint`, carrying what a run's headers carry.
13
+ * why: a browser's `WebSocket` sends no headers.
14
+ */
15
+ export declare function liveSocketAddress(endpoint: string, actingAs: StudioActingAs | undefined): string;
11
16
  export declare function tracedTransport<T extends object>(make: (options: {
12
17
  endpoint: string;
13
18
  fetch: typeof fetch;
@@ -1,5 +1,5 @@
1
1
  import { resolveObservabilityPolicy } from '@theoremjs/agents';
2
- import { actingAsHeaders } from "../../people.js";
2
+ import { ACTING_AS_PARAM, actingAsHeader, actingAsHeaders, } from "../../people.js";
3
3
  import { eachLine, NDJSON } from "../../stream-lines.js";
4
4
  import { studioTraceLine } from "../../transport.js";
5
5
  /** Whether the agent records traces, so the page can offer them: the rule every view reads. */
@@ -46,6 +46,16 @@ function tracedFetch(traces) {
46
46
  * trace panel reads them: the same panel a draft's run fills in the playground. Each run carries
47
47
  * who it acts as, so the project's tools act for that person.
48
48
  */
49
+ /**
50
+ * A live call's socket on `endpoint`, carrying what a run's headers carry.
51
+ * why: a browser's `WebSocket` sends no headers.
52
+ */
53
+ export function liveSocketAddress(endpoint, actingAs) {
54
+ const address = new URL(endpoint.replace(/^http/, 'ws'));
55
+ if (actingAs)
56
+ address.searchParams.set(ACTING_AS_PARAM, actingAsHeader(actingAs));
57
+ return address.href;
58
+ }
49
59
  export function tracedTransport(make, endpoint, traces, actingAs) {
50
60
  return {
51
61
  ...make({ endpoint, fetch: tracedFetch(traces), headers: actingAsHeaders(actingAs) }),
@@ -2,16 +2,20 @@
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 { StatedTurn } from '@theoremjs/web/client';
5
6
  import { type SlotDraft, type StudioRunPayload } from '../../mod.ts';
6
- /** What the builder set: the value picked for each slot, and the context as typed. */
7
+ /** What the builder set: the value picked for each slot and condition, and the context as typed. */
7
8
  export interface PageValues {
8
9
  slots: Record<string, string>;
10
+ conditions: Record<string, string>;
9
11
  contextJson: string;
10
12
  }
11
13
  /** What the agent takes from a page. */
12
14
  export interface PageInputs {
13
15
  /** Allowed values per slot name (descriptions stay on the profile / chat UI). */
14
16
  slots: Record<string, readonly string[]>;
17
+ /** Allowed values per condition name: which prompt lines the turn gets. */
18
+ conditions: Record<string, readonly string[]>;
15
19
  takesContext: boolean;
16
20
  /** The tools the page answers. Only a call asks the page. */
17
21
  pageTools: string[];
@@ -31,6 +35,7 @@ export declare function pageInputsOf(payload: StudioRunPayload): PageInputs | nu
31
35
  /** What goes with a turn or a call. Context that is not JSON is not sent, and says why. */
32
36
  export declare function sentPageValues(inputs: PageInputs | null, values: PageValues): {
33
37
  slots?: Record<string, string>;
38
+ stated?: StatedTurn;
34
39
  context?: unknown;
35
40
  contextError?: string;
36
41
  };