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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/asks.d.ts +9 -2
  2. package/asks.js +19 -10
  3. package/browser-connection.d.ts +1 -1
  4. package/browser-connection.js +3 -1
  5. package/browser-execution.js +1 -0
  6. package/compile-workspace.js +12 -5
  7. package/compile.d.ts +4 -2
  8. package/compile.js +58 -37
  9. package/cookbooks/catalog.d.ts +2 -2
  10. package/cookbooks/catalog.js +299 -52
  11. package/cookbooks/project.js +1 -0
  12. package/cookbooks/tools.js +64 -0
  13. package/draft.d.ts +21 -5
  14. package/draft.js +25 -2
  15. package/guardrail-probe.d.ts +3 -1
  16. package/guardrail-probe.js +37 -5
  17. package/mod.d.ts +2 -2
  18. package/mod.js +2 -2
  19. package/package.json +4 -4
  20. package/page/assets/Banner-DrRNC3MG.js +4 -0
  21. package/page/assets/Center-CgO0c-qo.js +1 -0
  22. package/page/assets/{ConsoleFrame-BMf3HicW.js → ConsoleFrame-BvgFGqp2.js} +3 -3
  23. package/page/assets/{MenuBottomSheet-sVJMYa4R.js → MenuBottomSheet-BZecY8fw.js} +1 -1
  24. package/page/assets/{SchemaFields-DYormNVH.js → SchemaFields-BNNkvyyO.js} +1 -1
  25. package/page/assets/{ToolResultCharts-Ce4lVdgN.js → ToolResultCharts-C3CPsfXl.js} +1 -1
  26. package/page/assets/{TraceInspector-DHyj0IHY.js → TraceInspector-36e6ozKD.js} +1 -1
  27. package/page/assets/{TraceOverview-CeiOIqk9.js → TraceOverview-CSdJ_cYY.js} +3 -3
  28. package/page/assets/{_virtual_studio-type-sources-BwSqfSwd.js → _virtual_studio-type-sources-DSpwr3WK.js} +143 -13
  29. package/page/assets/browser-connection-dads1eyK.js +3 -0
  30. package/page/assets/browser-engine-CugH58NS.js +13 -0
  31. package/page/assets/browser-transport-GzhRiBdm.js +45 -0
  32. package/page/assets/{crypto-CD14HeXH.js → crypto-B8dqEoWf.js} +1 -1
  33. package/page/assets/{encode-files-DhoC5hWG.js → encode-files-CHeRLBO8.js} +1 -1
  34. package/page/assets/{export-agent-Cs2S0oXB.js → export-agent-botXSyoH.js} +3 -3
  35. package/page/assets/{guardrail-tester-IcJWVveC.js → guardrail-tester-DYR7EPIy.js} +2 -2
  36. package/page/assets/index-B7sK7d-l.js +153 -0
  37. package/page/assets/live-messages-DN_q2nBN.js +1 -0
  38. package/page/assets/project-address-DjxPZuyn.js +1 -0
  39. package/page/assets/reader-DHN96tSr.js +5 -0
  40. package/page/assets/{schemas-BQ9Jydzb.js → schemas-D7cgkv3L.js} +1 -1
  41. package/page/assets/shaped-data-CJQ3W_RE.js +20 -0
  42. package/page/assets/{stub-nxRsh1jo.js → stub-U6wDGe3P.js} +25 -7
  43. package/page/assets/studio-code-pane-Boy63AK2.js +8 -0
  44. package/page/assets/{studio-console-Cn-v8Vvw.js → studio-console-B7zL133d.js} +1 -1
  45. package/page/assets/studio-decision-CbRjfbvG.js +1 -0
  46. package/page/assets/studio-embedding-DQ0QrEsu.js +2 -0
  47. package/page/assets/{studio-host-console-D__Of1no.js → studio-host-console-DDA2Um2-.js} +2 -2
  48. package/page/assets/{studio-labels-CiLuAo3N.js → studio-labels-jYWBoEyP.js} +1 -1
  49. package/page/assets/studio-live-D0YRu2zQ.js +5 -0
  50. package/page/assets/studio-map-C4Ra1QqL.js +1 -0
  51. package/page/assets/studio-session-CPnJaHc-.js +1 -0
  52. package/page/assets/studio-trace-replay-D-f2p7k9.js +3 -0
  53. package/page/assets/{studio-type-checker-BbUSqqOS.js → studio-type-checker-CVNPnko-.js} +1 -1
  54. package/page/assets/tool-schema-BDG2_rlP.js +17 -0
  55. package/page/assets/{trace-record-DxgSKmYY.js → trace-record-DoXjxrmJ.js} +1 -1
  56. package/page/assets/trace-schema--4IGmLeE.js +1 -0
  57. package/page/assets/tree-CcEbNvms.js +3 -0
  58. package/page/assets/turn-client-BmOSpCgw.js +2 -0
  59. package/page/assets/{use-one-call-BZKByPJh.js → use-one-call-B3t-kfc5.js} +1 -1
  60. package/page/assets/{use-second-ticker-CEwOSS-d.js → use-second-ticker-CWjCHLG6.js} +1 -1
  61. package/page/assets/workspace-DUfaxr-g.js +1 -0
  62. package/page/index.html +20 -19
  63. package/people.d.ts +2 -0
  64. package/people.js +3 -1
  65. package/policy.js +1 -0
  66. package/providers.d.ts +2 -2
  67. package/providers.js +8 -3
  68. package/read-source.js +34 -7
  69. package/registrations.d.ts +23 -3
  70. package/runtime-scope.d.ts +6 -3
  71. package/runtime-scope.js +16 -4
  72. package/runtime.js +14 -2
  73. package/server/draft-handler.d.ts +4 -4
  74. package/server/draft-handler.js +3 -2
  75. package/server/draft-probe.d.ts +9 -1
  76. package/server/draft-probe.js +2 -1
  77. package/server/handler.js +71 -25
  78. package/server/live.d.ts +7 -1
  79. package/server/live.js +11 -4
  80. package/server/run-traces.d.ts +5 -1
  81. package/server/run-traces.js +7 -3
  82. package/server/save-new.js +5 -5
  83. package/server/save-session.js +4 -2
  84. package/server/serve.js +2 -1
  85. package/server/test-key.d.ts +2 -2
  86. package/server/test-key.js +1 -1
  87. package/slot-values.d.ts +2 -0
  88. package/slot-values.js +22 -0
  89. package/source.js +11 -4
  90. package/tool-readers.d.ts +23 -0
  91. package/tool-readers.js +60 -0
  92. package/tools.js +4 -1
  93. package/types.d.ts +3 -1
  94. package/ui/inspector-context.js +1 -1
  95. package/ui/lib/project-traces.d.ts +5 -0
  96. package/ui/lib/project-traces.js +21 -3
  97. package/ui/lib/studio-page.d.ts +6 -1
  98. package/ui/lib/studio-page.js +33 -31
  99. package/ui/lib/studio-project.d.ts +8 -1
  100. package/ui/lib/studio-project.js +19 -1
  101. package/ui/lib/studio-session.d.ts +2 -0
  102. package/ui/lib/studio-session.js +40 -2
  103. package/ui/lib/studio-store.d.ts +2 -2
  104. package/ui/lib/studio-store.js +9 -5
  105. package/ui/lib/tool-probe.d.ts +2 -0
  106. package/ui/lib/tool-probe.js +3 -2
  107. package/ui/lib/type-icons.d.ts +1 -0
  108. package/ui/lib/type-icons.js +2 -1
  109. package/ui/profile-editor.js +57 -21
  110. package/ui/studio-compare.d.ts +14 -4
  111. package/ui/studio-compare.js +58 -24
  112. package/ui/studio-live.d.ts +1 -1
  113. package/ui/studio-live.js +8 -3
  114. package/ui/studio-runner.d.ts +3 -2
  115. package/ui/studio-runner.js +16 -14
  116. package/ui/studio-screen.d.ts +1 -1
  117. package/ui/studio-screen.js +26 -20
  118. package/ui/studio-settings.js +3 -1
  119. package/ui/studio-trace-replay.js +7 -1
  120. package/workspace.js +3 -2
  121. package/page/assets/Banner-CkcwUyOn.js +0 -4
  122. package/page/assets/Center-nHS1JSux.js +0 -1
  123. package/page/assets/browser-connection-DSUHVCT5.js +0 -3
  124. package/page/assets/browser-engine-BXSD3WU8.js +0 -11
  125. package/page/assets/browser-transport-cp9y8bBz.js +0 -45
  126. package/page/assets/index-JWco7tJJ.js +0 -145
  127. package/page/assets/live-messages-CiLmR89m.js +0 -1
  128. package/page/assets/reader-DrOfMM8I.js +0 -5
  129. package/page/assets/shaped-data-H1miOZm2.js +0 -20
  130. package/page/assets/studio-code-pane-B8MOEW9g.js +0 -8
  131. package/page/assets/studio-decision-CjJ_pqdJ.js +0 -1
  132. package/page/assets/studio-embedding-Cq3ePsfC.js +0 -2
  133. package/page/assets/studio-live-DvDQbP5V.js +0 -5
  134. package/page/assets/studio-map-BZFYGG_Y.js +0 -1
  135. package/page/assets/studio-session-CjUQSXx0.js +0 -1
  136. package/page/assets/studio-trace-replay-D22FgUA5.js +0 -3
  137. package/page/assets/tool-schema-BmRYaywn.js +0 -17
  138. package/page/assets/trace-schema-9CdEyG6Q.js +0 -1
  139. package/page/assets/tree-3N-1RPZz.js +0 -3
  140. package/page/assets/turn-client-DN8PawJr.js +0 -2
  141. package/page/assets/workspace-CTSW941G.js +0 -1
package/asks.d.ts CHANGED
@@ -30,10 +30,16 @@ export interface AskTool {
30
30
  permission: string;
31
31
  profile?: string;
32
32
  }
33
+ /** The header a run carries the builder's choice of which tools that write ask in. */
34
+ export declare const ASK_WRITES_HEADER = "x-theorem-studio-ask-writes";
35
+ /** The same on a live socket's address: a browser's `WebSocket` sends no headers. */
36
+ export declare const ASK_WRITES_PARAM = "ask-writes";
33
37
  /** Which of a project's tools the studio makes ask, and which it cannot. */
34
38
  export interface StudioAsks {
35
39
  /** The tools that ask before each run here and would not in the application. */
36
40
  asked: string[];
41
+ /** Those of `asked` that can reach a destructive tool: they ask whatever the builder chose. */
42
+ destructive: string[];
37
43
  /**
38
44
  * The tools that write and run unasked: a called agent runs them, and a question inside a called
39
45
  * agent has no one to answer it. The call to that agent asks instead.
@@ -49,6 +55,7 @@ export declare function studioAsks(tools: readonly AskTool[], allowed: (profile:
49
55
  /**
50
56
  * The studio's question before each run of an `asked` tool, as a stage. The tool's registration
51
57
  * is left as the project set it, so the project's own code reads its own setting. A call the
52
- * builder already approved where it stopped is not asked again.
58
+ * builder already approved where it stopped is not asked again. `destructiveOnly` reads the run's
59
+ * own choice, since the builder can change it between two runs.
53
60
  */
54
- export declare function studioAskStage(asked: readonly string[]): StageHandler | undefined;
61
+ export declare function studioAskStage({ asked, destructive }: StudioAsks, destructiveOnly: () => boolean): StageHandler | undefined;
package/asks.js CHANGED
@@ -23,6 +23,10 @@ export function writeAskLine(ask) {
23
23
  const set = ask.access === 'destructive' ? 'destructive' : 'read and write';
24
24
  return `It is set as ${set}. Run sends a real request: ${ask.sends}`;
25
25
  }
26
+ /** The header a run carries the builder's choice of which tools that write ask in. */
27
+ export const ASK_WRITES_HEADER = 'x-theorem-studio-ask-writes';
28
+ /** The same on a live socket's address: a browser's `WebSocket` sends no headers. */
29
+ export const ASK_WRITES_PARAM = 'ask-writes';
26
30
  /**
27
31
  * The tools the studio makes ask before each run: every one that writes, and every agent tool
28
32
  * whose agent can reach one that writes. A tool a called agent runs is left as it is, because the
@@ -32,22 +36,24 @@ export function studioAsks(tools, allowed) {
32
36
  const named = new Map(tools.map((tool) => [tool.name, tool]));
33
37
  const runs = (tool) => tool.type === 'agent' && tool.profile ? allowed(tool.profile) : [];
34
38
  const inside = new Set(tools.flatMap(runs));
35
- const writes = (tool, seen) => {
39
+ const reaches = (tool, is, seen) => {
36
40
  if (seen.has(tool.name))
37
41
  return false;
38
42
  seen.add(tool.name);
39
- if (tool.access !== 'read-only')
43
+ if (is(tool))
40
44
  return true;
41
45
  return runs(tool).some((name) => {
42
46
  const inner = named.get(name);
43
- return inner !== undefined && writes(inner, seen);
47
+ return inner !== undefined && reaches(inner, is, seen);
44
48
  });
45
49
  };
46
50
  // A provider's built-in tool runs on the provider and never stops on a question.
47
- const writing = tools.filter((tool) => tool.type !== 'builtin' && writes(tool, new Set()));
51
+ const writing = tools.filter((tool) => tool.type !== 'builtin' && reaches(tool, (each) => each.access !== 'read-only', new Set()));
52
+ const asked = writing.filter((tool) => !inside.has(tool.name) && tool.permission !== 'always_confirm');
48
53
  return {
49
- asked: writing
50
- .filter((tool) => !inside.has(tool.name) && tool.permission !== 'always_confirm')
54
+ asked: asked.map((tool) => tool.name),
55
+ destructive: asked
56
+ .filter((tool) => reaches(tool, (each) => each.access === 'destructive', new Set()))
51
57
  .map((tool) => tool.name),
52
58
  inside: writing.filter((tool) => inside.has(tool.name)).map((tool) => tool.name),
53
59
  };
@@ -57,13 +63,16 @@ const STUDIO_ASK_SUMMARY = 'The studio asks before every run of a tool that writ
57
63
  /**
58
64
  * The studio's question before each run of an `asked` tool, as a stage. The tool's registration
59
65
  * is left as the project set it, so the project's own code reads its own setting. A call the
60
- * builder already approved where it stopped is not asked again.
66
+ * builder already approved where it stopped is not asked again. `destructiveOnly` reads the run's
67
+ * own choice, since the builder can change it between two runs.
61
68
  */
62
- export function studioAskStage(asked) {
69
+ export function studioAskStage({ asked, destructive }, destructiveOnly) {
63
70
  if (asked.length === 0)
64
71
  return undefined;
65
- const ask = new Set(asked);
66
- return (ctx) => ctx.stage === 'pre_tool' && !ctx.approved && ctx.tool !== undefined && ask.has(ctx.tool)
72
+ return (ctx) => ctx.stage === 'pre_tool' &&
73
+ !ctx.approved &&
74
+ ctx.tool !== undefined &&
75
+ (destructiveOnly() ? destructive : asked).includes(ctx.tool)
67
76
  ? { confirm: { summary: STUDIO_ASK_SUMMARY } }
68
77
  : undefined;
69
78
  }
@@ -17,7 +17,7 @@ export declare const STUDIO_KEY_SLOT_CAP = 32;
17
17
  /** The same localhost origin and transport used for inference; never a site proxy. */
18
18
  export declare function listLocalStudioModels(local: StudioBrowserConnection['local'], signal?: AbortSignal): Promise<string[]>;
19
19
  /** The profile types a model runs for; a provider's list is filtered to the one being edited. */
20
- export type ListedProfileType = 'text' | 'image' | 'speech' | 'live' | 'embedding';
20
+ export type ListedProfileType = 'text' | 'image' | 'speech' | 'transcription' | 'live' | 'embedding';
21
21
  /** A model a provider lists, as the studio's picker shows it. */
22
22
  export interface ProviderModel {
23
23
  /** What the profile's `apiId` is set to. */
@@ -75,12 +75,14 @@ export const KNOWN_OPENROUTER_EMBEDDING_MODELS = [
75
75
  ];
76
76
  /**
77
77
  * OpenRouter's `output_modalities` for each profile type: chat models for text, `/images` models
78
- * for image, `/audio/speech` models for speech. OpenRouter has no live models.
78
+ * for image, `/audio/speech` models for speech, `/audio/transcriptions` models for transcription.
79
+ * OpenRouter has no live models.
79
80
  */
80
81
  const OPENROUTER_OUTPUT = {
81
82
  text: 'text',
82
83
  image: 'image',
83
84
  speech: 'speech',
85
+ transcription: 'transcription',
84
86
  live: undefined,
85
87
  embedding: undefined,
86
88
  };
@@ -6,6 +6,7 @@ export function browserExecution() {
6
6
  request: new Request('https://studio.local'),
7
7
  session: () => id,
8
8
  sessionStore: memory,
9
+ pageStatesTurn: true,
9
10
  });
10
11
  const store = sessionStateStore(memory, undefined, DEFAULT_OPERATION_RETENTION_MS);
11
12
  const page = sessionPageDispatch(store, id, createMemoryPageToolBroker());
@@ -9,9 +9,8 @@ import { kernelDefinition, providerProblems, registerStudioProvider } from "./pr
9
9
  import { registerDefined } from "./tools.js";
10
10
  import { modelBindingNodeId, providerNodeId, toolSpecNodeId } from "./tree.js";
11
11
  import { agentDraft, agentNodeId, scopedNodeId, } from "./workspace.js";
12
- /** The agents an agent tool can run, and the one type that can summarise. */
12
+ /** The agents an agent tool can run. */
13
13
  const CALLABLE_TYPES = new Set(['text', 'image', 'speech']);
14
- const STAGE_READER_TYPES = new Set(['decision', 'text']);
15
14
  function references(workspace) {
16
15
  const tools = new Map(workspace.toolSpecs.map((tool) => [tool.key, tool]));
17
16
  return workspace.agents.flatMap((agent) => [
@@ -156,8 +155,12 @@ function wrongTypeMessage(ref, target) {
156
155
  if (ref.field === 'agentKey' && !CALLABLE_TYPES.has(type)) {
157
156
  return `'${id}' is a ${type} agent. An agent tool runs a text, image, or speech agent.`;
158
157
  }
159
- if (ref.field === 'stageAgentKey' && !STAGE_READER_TYPES.has(type)) {
160
- return `'${id}' is a ${type} agent. A tool reader runs a decision or text agent.`;
158
+ if (ref.field === 'stageAgentKey' && type !== 'decision') {
159
+ return `'${id}' is a ${type} agent. A tool reader runs a decision agent.`;
160
+ }
161
+ if (ref.field === 'stageAgentKey' &&
162
+ !target.decision.questions.some((question) => question.type === 'choice')) {
163
+ return `'${id}' has no choice question. A tool reader keeps a passage on the first choice.`;
161
164
  }
162
165
  if (ref.field === 'compactWith' && type !== 'text') {
163
166
  return `'${id}' is a ${type} agent. Only a text agent summarises.`;
@@ -299,7 +302,11 @@ export function workspaceRunAgent(compiled, agentId) {
299
302
  customTools,
300
303
  ...(structured ? { structured } : {}),
301
304
  }));
302
- return { ...chatted, dependencies };
305
+ const customTools = chatted.customTools.map((tool) => {
306
+ const reader = tool.type === 'agent' ? undefined : byId.get(tool.stageAgent ?? '');
307
+ return reader?.questions ? { ...tool, stageQuestions: reader.questions } : tool;
308
+ });
309
+ return { ...chatted, customTools, dependencies };
303
310
  }
304
311
  /** The agent ids a compiled agent names: its agent tools', stage readers', and its compaction's. */
305
312
  function namedAgents(agent) {
package/compile.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { type DecisionAsset, type DecisionQuestion, type ImageProfileDefinition, type LiveProfileDefinition, type ProfileGuardrailsSpec, type SpeechProfileDefinition, type TextProfileDefinition } from '@theoremjs/agents';
1
+ import { type DecisionAsset, type DecisionQuestion, type ImageProfileDefinition, type LiveProfileDefinition, type ProfileGuardrailsSpec, type SpeechProfileDefinition, type TextProfileDefinition, type TranscriptionProfileDefinition } from '@theoremjs/agents';
2
2
  import { type DecisionProfileDefinition, type EmbeddingProfileDefinition, type HostProfileDefinition, type ProfileDefinition } from '@theoremjs/agents/kernel';
3
3
  import type { GuardrailsDraft, StudioDraft } from './draft.ts';
4
4
  import type { StudioRunsOn } from './lent-keys.ts';
5
5
  import { type StudioProvider } from './providers.ts';
6
6
  import type { StructuredRegistration, ToolRegistration } from './registrations.ts';
7
- export type StudioProfileDefinition = TextProfileDefinition | ImageProfileDefinition | SpeechProfileDefinition | LiveProfileDefinition | DecisionProfileDefinition | EmbeddingProfileDefinition | HostProfileDefinition;
7
+ export type StudioProfileDefinition = TextProfileDefinition | ImageProfileDefinition | SpeechProfileDefinition | TranscriptionProfileDefinition | LiveProfileDefinition | DecisionProfileDefinition | EmbeddingProfileDefinition | HostProfileDefinition;
8
8
  /** A profile that runs a model turn: every studio type but decision and host. */
9
9
  export type StudioTurnProfileDefinition = Exclude<StudioProfileDefinition, DecisionProfileDefinition | HostProfileDefinition>;
10
10
  /**
@@ -45,6 +45,8 @@ export type AgentIdOf = (key: string) => string | undefined;
45
45
  * `undefined` when none has that key or an agent tool can't run it.
46
46
  */
47
47
  export type AgentToolInputOf = (key: string) => Record<string, unknown> | undefined;
48
+ /** The conditions a draft declares so far: none while they are not JSON. */
49
+ export declare function draftConditions(conditionsJson: string): Record<string, string[]>;
48
50
  /** What a tool that runs this draft's agent takes, as the kernel derives it from the agent's inputs. */
49
51
  export declare function agentToolInputSchema(draft: StudioDraft): Record<string, unknown> | undefined;
50
52
  /** Why these headers can't be saved, when one of them looks like a credential. */
package/compile.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineProfile, describeError, liveIngressChannelDefault, TheoremError, } from '@theoremjs/agents';
2
2
  import { BOUNDARIES, DETECT_DEFAULTS, DETECTOR_META, DETECTORS, detectProblem, hintProblem, patternListProblem, TOOL_BOUNDARIES, validateLabelOverrides, } from '@theoremjs/agents/guardrails';
3
- import { activityLabelProblem, agentToolInputFor, agentToolOutput, jsonSchemaFromZod, mimeAllowed, outOfScopeFields, systemPromptProblem, } from '@theoremjs/agents/kernel';
3
+ import { activityLabelProblem, agentToolInputFor, agentToolOutput, jsonSchemaFromZod, mimeAllowed, outOfScopeFields, systemLinesProblem, } from '@theoremjs/agents/kernel';
4
4
  import { resolveObservabilityPolicy } from '@theoremjs/agents/observability';
5
5
  import { HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, } from '@theoremjs/agents/schema';
6
6
  import { isCredentialName, MASK } from '@theoremjs/agents/surface';
@@ -289,31 +289,40 @@ const isAny = (_value) => true;
289
289
  function parseHeaders(raw) {
290
290
  return parseRecord(raw, isString);
291
291
  }
292
- const isSystemPrompt = (value) => systemPromptProblem(value, 'system') === undefined;
293
- /** Each role's text takes `{private: …}` sections like the system prompt; a list of parts passes as written. */
294
- function compileSystemByRole(raw, report) {
295
- const byRole = parseRecord(raw, isSystemPrompt);
296
- if (byRole === null) {
297
- report('Instructions by role must be a JSON object of text, or of lists of text and { "private": text }.');
298
- return undefined;
299
- }
300
- if (!byRole)
301
- return undefined;
302
- const compiled = {};
303
- for (const [role, prompt] of Object.entries(byRole)) {
304
- if (typeof prompt !== 'string') {
305
- compiled[role] = prompt;
306
- continue;
307
- }
308
- const parsed = parseSystemMarkup(prompt);
309
- if (!parsed.ok) {
310
- report(`${role}: ${parsed.message}`);
311
- return undefined;
312
- }
313
- if (parsed.prompt !== undefined)
314
- compiled[role] = parsed.prompt;
315
- }
316
- return compiled;
292
+ const isValueList = (value) => Array.isArray(value) && value.every(isString);
293
+ /** The conditions a draft declares so far: none while they are not JSON. */
294
+ export function draftConditions(conditionsJson) {
295
+ return parseRecord(conditionsJson, isValueList) ?? {};
296
+ }
297
+ /** The prompt's lines and the facts they read, each problem reported on the identity section. */
298
+ function compilePrompt(draft, report) {
299
+ const conditions = parseRecord(draft.identity.conditionsJson, isValueList);
300
+ if (conditions === null) {
301
+ report('identity', 'Conditions must be a JSON object of lists of values.', 'conditionsJson');
302
+ }
303
+ const lines = draft.identity.system.flatMap(({ text }) => {
304
+ const parsed = parseSystemMarkup(text);
305
+ if (!parsed.ok)
306
+ report('identity', parsed.message, 'system');
307
+ return parsed.ok && parsed.prompt !== undefined ? [parsed.prompt] : [];
308
+ });
309
+ const [first] = lines;
310
+ const system = lines.length === 0
311
+ ? undefined
312
+ : lines.length === 1 && typeof first === 'string'
313
+ ? first
314
+ : lines;
315
+ const declared = conditions ?? undefined;
316
+ if (system !== undefined && conditions !== null) {
317
+ const slots = Object.fromEntries(draft.inputs.slots.map((slot) => [
318
+ slot.name.trim(),
319
+ slot.choices.map((choice) => choice.value.trim()).filter(Boolean),
320
+ ]));
321
+ const problem = systemLinesProblem(system, declared, slots);
322
+ if (problem)
323
+ report('identity', problem, 'system');
324
+ }
325
+ return { system, conditions: declared };
317
326
  }
318
327
  /** A record field's value, reporting `message` on `field` when it doesn't parse. */
319
328
  function recordField(raw, isValue, report) {
@@ -387,6 +396,7 @@ function toolCommon(tool, fail, agentInputOf) {
387
396
  permission: tool.permission,
388
397
  loadTier: tool.loadTier,
389
398
  paths: paths.length ? paths : ['*'],
399
+ ...(tool.after ? { after: true } : {}),
390
400
  ...schemas,
391
401
  };
392
402
  }
@@ -756,6 +766,22 @@ function compileLiveInputs(inputs, report) {
756
766
  return {};
757
767
  return { inputs: { ...(slots ? { slots } : {}), ...(context ? { context } : {}) } };
758
768
  }
769
+ /** The shapes a slot's value picks: its schemas, and what `outputs.structured` writes. */
770
+ function compileSlotShapes(outputs, fallback, report) {
771
+ const { slot, shapes } = outputs.bySlot ?? { slot: '', shapes: [] };
772
+ const also = [];
773
+ const map = {};
774
+ for (const shape of shapes) {
775
+ const schema = parseJsonSchema(shape.schemaJson, `The reply shape for '${shape.choice}'`);
776
+ if (!schema.ok)
777
+ report('outputs', schema.error, 'schemaJson');
778
+ else {
779
+ also.push({ id: shape.schemaId, spec: { jsonSchema: schema.schema } });
780
+ map[shape.choice] = shape.schemaId;
781
+ }
782
+ }
783
+ return also.length ? { also, written: { by: slot, map, fallback } } : undefined;
784
+ }
759
785
  /** `shaped`: the type takes a structured reply and its validation (text only). */
760
786
  function compileOutputs(outputs, shaped, report) {
761
787
  let structured;
@@ -772,6 +798,9 @@ function compileOutputs(outputs, shaped, report) {
772
798
  structured = { id, spec: { jsonSchema: schema.schema } };
773
799
  }
774
800
  }
801
+ const bySlot = structured && compileSlotShapes(outputs, structured.id, report);
802
+ if (structured && bySlot)
803
+ structured = { ...structured, also: bySlot.also };
775
804
  if (validationEnabled) {
776
805
  checkWhole(report, 'outputs', 'maxRetries', 'Validation max retries', outputs.maxRetries, 0);
777
806
  }
@@ -791,7 +820,7 @@ function compileOutputs(outputs, shaped, report) {
791
820
  ...(outputs.streamThoughts ? {} : { streamThoughts: false }),
792
821
  };
793
822
  const spec = {
794
- ...(structured ? { structured: structured.id } : {}),
823
+ ...(structured ? { structured: bySlot?.written ?? structured.id } : {}),
795
824
  ...(Object.keys(validation).length ? { validation } : {}),
796
825
  ...(Object.keys(streaming).length ? { streaming } : {}),
797
826
  };
@@ -1620,15 +1649,7 @@ function compileHost(draft, report, agentIdOf, agentInputOf) {
1620
1649
  function assemble(draft, type, report, on, agentIdOf, agentInputOf) {
1621
1650
  const facets = new Set(draftFacets(draft));
1622
1651
  const allows = (path) => draftAllows(draft, path);
1623
- const parsedSystem = typeof draft.identity.system === 'string'
1624
- ? parseSystemMarkup(draft.identity.system)
1625
- : { ok: false, message: 'The system prompt must be text.' };
1626
- if (!parsedSystem.ok)
1627
- report('identity', parsedSystem.message, 'system');
1628
- const system = parsedSystem.ok ? parsedSystem.prompt : undefined;
1629
- const systemByRole = compileSystemByRole(draft.identity.systemByRoleJson, (message) => {
1630
- report('identity', message, 'systemByRoleJson');
1631
- });
1652
+ const { system, conditions } = compilePrompt(draft, report);
1632
1653
  const modelFields = compileModels(draft, type, report, agentIdOf);
1633
1654
  const { outputs, structured } = facets.has('outputs')
1634
1655
  ? compileOutputs(draft.outputs, allows('outputs.structured'), report)
@@ -1647,8 +1668,8 @@ function assemble(draft, type, report, on, agentIdOf, agentInputOf) {
1647
1668
  id: draft.identity.agentId.trim(),
1648
1669
  identity: {
1649
1670
  handle: draft.identity.handle.trim(),
1671
+ ...(conditions ? { conditions } : {}),
1650
1672
  ...(system ? { system } : {}),
1651
- ...(systemByRole ? { systemByRole } : {}),
1652
1673
  },
1653
1674
  ...modelFields,
1654
1675
  ...(facets.has('image') ? { image: compileImage(draft.image, report) } : {}),
@@ -41,9 +41,9 @@ export declare const RESEARCH_PAGE_READER_STATE: string;
41
41
  export declare function createPageReaderExampleDraft(): StudioDraft;
42
42
  /** The research scout on its own: searches papers, models, datasets, repos, and docs. */
43
43
  export declare function createResearchScoutDraft(): StudioDraft;
44
- /** The research scout and the Jev page reader it filters pages with, added to a workspace. */
44
+ /** The research scout and its team, added to a workspace. */
45
45
  export declare function addResearchExample(workspace: StudioWorkspace): StudioWorkspace;
46
- /** A workspace of the research scout and its Jev page reader, with the scout in the chat. */
46
+ /** A workspace of the research scout and its team, with the scout in the chat. */
47
47
  export declare function createResearchWorkspace(): StudioWorkspace;
48
48
  /** A fresh copy of the travel concierge draft: a text agent with the tools a trip needs. */
49
49
  export declare function createExampleDraft(): StudioDraft;