@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/agreement.js CHANGED
@@ -8,6 +8,7 @@
8
8
  import { BOUNDARIES, DETECTORS, resolveAllow, resolveDetect, TOOL_BOUNDARIES, } from '@theoremjs/agents/guardrails';
9
9
  import { unsetValue } from '@theoremjs/agents/kernel';
10
10
  import { STUDIO_POLICY_UNSET } from "./policy.js";
11
+ import { promptLine } from "./system-markup.js";
11
12
  function isRecord(value) {
12
13
  return value !== null && typeof value === 'object' && !Array.isArray(value);
13
14
  }
@@ -51,11 +52,40 @@ function detectAsRead(detect, boundaries) {
51
52
  allow: Object.fromEntries(allow),
52
53
  };
53
54
  }
54
- /** A profile with its `detect` as the kernel reads it. */
55
- function asRead(profile) {
56
- if (!isRecord(profile) ||
57
- !isRecord(profile.guardrails) ||
58
- profile.guardrails.detect === undefined)
55
+ /**
56
+ * A prompt as the studio holds it: no white space at the ends of a line or a private section.
57
+ * why: this is studio policy, so a prompt written with a closing newline opens as the same prompt.
58
+ */
59
+ function promptAsHeld(system) {
60
+ if (typeof system === 'string')
61
+ return system.trim();
62
+ if (!Array.isArray(system))
63
+ return system;
64
+ return system.map((line) => {
65
+ if (typeof line === 'string')
66
+ return line.trim();
67
+ if (!Array.isArray(line))
68
+ return line;
69
+ return promptLine(line.map((part) => isRecord(part) && typeof part.private === 'string'
70
+ ? { private: part.private.trim() }
71
+ : part));
72
+ });
73
+ }
74
+ /** A profile with its prompt as the studio holds it. */
75
+ function promptRead(profile) {
76
+ if (!isRecord(profile.identity) || profile.identity.system === undefined)
77
+ return profile;
78
+ return {
79
+ ...profile,
80
+ identity: { ...profile.identity, system: promptAsHeld(profile.identity.system) },
81
+ };
82
+ }
83
+ /** A profile with its prompt as the studio holds it and its `detect` as the kernel reads it. */
84
+ function asRead(project) {
85
+ if (!isRecord(project))
86
+ return project;
87
+ const profile = promptRead(project);
88
+ if (!isRecord(profile.guardrails) || profile.guardrails.detect === undefined)
59
89
  return profile;
60
90
  return {
61
91
  ...profile,
@@ -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
- import type { GuardrailsDraft, StudioDraft } from './draft.ts';
3
+ import type { ConditionDraft, 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: each one named with a value, the first of a name. */
49
+ export declare function draftConditions(conditions: readonly ConditionDraft[]): 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,62 @@ 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;
292
+ /** The conditions a draft declares so far: each one named with a value, the first of a name. */
293
+ export function draftConditions(conditions) {
294
+ const declared = {};
295
+ for (const { name, values } of conditions) {
296
+ const named = name.trim();
297
+ if (named && values.length > 0 && !Object.hasOwn(declared, named))
298
+ declared[named] = values;
299
+ }
300
+ return declared;
301
+ }
302
+ /** What is wrong with each condition, reported on its row. Gives whether any was. */
303
+ function reportConditions(conditions, slots, report) {
304
+ const seen = new Set();
305
+ let wrong = false;
306
+ conditions.forEach(({ name, values }, at) => {
307
+ const named = name.trim();
308
+ if (!named && values.length === 0)
309
+ return;
310
+ const problem = !named
311
+ ? 'This condition needs a name.'
312
+ : seen.has(named)
313
+ ? `Two conditions are called "${named}".`
314
+ : systemLinesProblem('', { [named]: values }, slots);
315
+ seen.add(named);
316
+ if (!problem)
317
+ return;
318
+ wrong = true;
319
+ report('identity', problem, 'conditions', at);
320
+ });
321
+ return wrong;
322
+ }
323
+ /** The prompt's lines and the facts they read, each problem reported on the identity section. */
324
+ function compilePrompt(draft, report) {
325
+ const parsed = parseSystemMarkup(draft.identity.system);
326
+ if (!parsed.ok)
327
+ report('identity', parsed.message, 'system');
328
+ const lines = parsed.ok ? parsed.lines : [];
329
+ const [first] = lines;
330
+ const system = lines.length === 0
331
+ ? undefined
332
+ : lines.length === 1 && typeof first === 'string'
333
+ ? first
334
+ : lines;
335
+ const slots = Object.fromEntries(draft.inputs.slots.map((slot) => [
336
+ slot.name.trim(),
337
+ slot.choices.map((choice) => choice.value.trim()).filter(Boolean),
338
+ ]));
339
+ const wrong = reportConditions(draft.identity.conditions, slots, report);
340
+ const conditions = draftConditions(draft.identity.conditions);
341
+ const declared = Object.keys(conditions).length > 0 ? conditions : undefined;
342
+ if (system !== undefined && !wrong) {
343
+ const problem = systemLinesProblem(system, declared, slots);
344
+ if (problem)
345
+ report('identity', problem, 'system');
315
346
  }
316
- return compiled;
347
+ return { system, conditions: declared };
317
348
  }
318
349
  /** A record field's value, reporting `message` on `field` when it doesn't parse. */
319
350
  function recordField(raw, isValue, report) {
@@ -387,6 +418,8 @@ function toolCommon(tool, fail, agentInputOf) {
387
418
  permission: tool.permission,
388
419
  loadTier: tool.loadTier,
389
420
  paths: paths.length ? paths : ['*'],
421
+ ...(tool.after ? { after: true } : {}),
422
+ ...(tool.background ? { background: tool.background } : {}),
390
423
  ...schemas,
391
424
  };
392
425
  }
@@ -756,6 +789,22 @@ function compileLiveInputs(inputs, report) {
756
789
  return {};
757
790
  return { inputs: { ...(slots ? { slots } : {}), ...(context ? { context } : {}) } };
758
791
  }
792
+ /** The shapes a slot's value picks: its schemas, and what `outputs.structured` writes. */
793
+ function compileSlotShapes(outputs, fallback, report) {
794
+ const { slot, shapes } = outputs.bySlot ?? { slot: '', shapes: [] };
795
+ const also = [];
796
+ const map = {};
797
+ for (const shape of shapes) {
798
+ const schema = parseJsonSchema(shape.schemaJson, `The reply shape for '${shape.choice}'`);
799
+ if (!schema.ok)
800
+ report('outputs', schema.error, 'schemaJson');
801
+ else {
802
+ also.push({ id: shape.schemaId, spec: { jsonSchema: schema.schema } });
803
+ map[shape.choice] = shape.schemaId;
804
+ }
805
+ }
806
+ return also.length ? { also, written: { by: slot, map, fallback } } : undefined;
807
+ }
759
808
  /** `shaped`: the type takes a structured reply and its validation (text only). */
760
809
  function compileOutputs(outputs, shaped, report) {
761
810
  let structured;
@@ -772,6 +821,9 @@ function compileOutputs(outputs, shaped, report) {
772
821
  structured = { id, spec: { jsonSchema: schema.schema } };
773
822
  }
774
823
  }
824
+ const bySlot = structured && compileSlotShapes(outputs, structured.id, report);
825
+ if (structured && bySlot)
826
+ structured = { ...structured, also: bySlot.also };
775
827
  if (validationEnabled) {
776
828
  checkWhole(report, 'outputs', 'maxRetries', 'Validation max retries', outputs.maxRetries, 0);
777
829
  }
@@ -791,7 +843,7 @@ function compileOutputs(outputs, shaped, report) {
791
843
  ...(outputs.streamThoughts ? {} : { streamThoughts: false }),
792
844
  };
793
845
  const spec = {
794
- ...(structured ? { structured: structured.id } : {}),
846
+ ...(structured ? { structured: bySlot?.written ?? structured.id } : {}),
795
847
  ...(Object.keys(validation).length ? { validation } : {}),
796
848
  ...(Object.keys(streaming).length ? { streaming } : {}),
797
849
  };
@@ -1620,15 +1672,7 @@ function compileHost(draft, report, agentIdOf, agentInputOf) {
1620
1672
  function assemble(draft, type, report, on, agentIdOf, agentInputOf) {
1621
1673
  const facets = new Set(draftFacets(draft));
1622
1674
  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
- });
1675
+ const { system, conditions } = compilePrompt(draft, report);
1632
1676
  const modelFields = compileModels(draft, type, report, agentIdOf);
1633
1677
  const { outputs, structured } = facets.has('outputs')
1634
1678
  ? compileOutputs(draft.outputs, allows('outputs.structured'), report)
@@ -1647,8 +1691,8 @@ function assemble(draft, type, report, on, agentIdOf, agentInputOf) {
1647
1691
  id: draft.identity.agentId.trim(),
1648
1692
  identity: {
1649
1693
  handle: draft.identity.handle.trim(),
1694
+ ...(conditions ? { conditions } : {}),
1650
1695
  ...(system ? { system } : {}),
1651
- ...(systemByRole ? { systemByRole } : {}),
1652
1696
  },
1653
1697
  ...modelFields,
1654
1698
  ...(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;