@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
@@ -1,6 +1,6 @@
1
1
  import { embeddingModelLimits } from '@theoremjs/agents';
2
2
  import { DETECTOR_BOUNDARIES, DETECTORS } from '@theoremjs/agents/guardrails';
3
- import { createBlankDraft, defaultModelBinding, defaultToolSpec, draftKey, freeName, includableFacets, includeFacet, setProfileType, } from "../draft.js";
3
+ import { COMPACTION_DRAFT_DEFAULTS, createBlankDraft, defaultModelBinding, defaultToolSpec, draftKey, freeName, includableFacets, includeFacet, newOwnDetector, newPattern, setProfileType, } from "../draft.js";
4
4
  import { firstServed } from "../policy.js";
5
5
  import { addAgent, agentNodeId, markAgentStart, workspaceFromDraft, } from "../workspace.js";
6
6
  import { DEMO_ALLOWED_HOSTS, DEMO_ARCHITECT_TOOLS, DEMO_CONCIERGE_TOOLS, DEMO_CONSOLE_TOOLS, DEMO_RESEARCH_STAGE_READ_TOOLS, DEMO_RESEARCH_TOOLS, demoInputsSpec, demoToolSpecs, RESEARCH_ALLOWED_HOSTS, } from "./tools.js";
@@ -21,6 +21,11 @@ const EXAMPLE_PICKS = {
21
21
  return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-tts-preview' };
22
22
  case 'image':
23
23
  return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-lite-image' };
24
+ case 'transcription':
25
+ return {
26
+ ...firstServed('openrouter', type),
27
+ apiId: 'mistralai/voxtral-mini-transcribe-3-0',
28
+ };
24
29
  case 'text':
25
30
  return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-lite' };
26
31
  case 'embedding':
@@ -72,6 +77,15 @@ Tool & Fact Grounding:
72
77
 
73
78
  Audio briefings:
74
79
  - When asked for a podcast, a briefing, or anything to listen to, write a short spoken script of what you found, in plain sentences with no markdown, and pass it to narrate. Then say in one line what the briefing covers.`;
80
+ const DEMO_LIVE_RESEARCH_SYSTEM = `Role: A research scout, on a call.
81
+
82
+ Speaking:
83
+ - Speak in short, natural sentences. No lists, no markdown, no reading out of URLs or ids unless asked.
84
+ - Give the finding first, then say where it came from.
85
+
86
+ Tool & Fact Grounding:
87
+ - Ground every claim about a paper, model, or dataset in the tools before you answer. Never invent one.
88
+ - Never name a tool or say that you are calling one.`;
75
89
  export const DEMO_LIVE_CONCIERGE_SYSTEM = `Role: Elite, charismatic travel concierge, on a call.
76
90
 
77
91
  Speaking:
@@ -148,6 +162,24 @@ export const RESEARCH_REPLY_SCHEMA_JSON = JSON.stringify({
148
162
  },
149
163
  required: ['summary', 'candidates', 'searched', 'open'],
150
164
  }, null, 2);
165
+ const RESEARCH_MODELS_SCHEMA_ID = 'research.models';
166
+ /** `research.reply` when the focus is the Hub: its `candidates` hold one entry per model. */
167
+ function researchModelsSchemaJson() {
168
+ const reply = JSON.parse(RESEARCH_REPLY_SCHEMA_JSON);
169
+ const { candidates } = reply.properties;
170
+ const model = {
171
+ ...candidates.items,
172
+ properties: {
173
+ ...candidates.items.properties,
174
+ kind: { type: 'string', enum: ['model'] },
175
+ task: { type: 'string', description: 'The pipeline task the Hub lists for it.' },
176
+ license: { type: 'string', description: 'Its license as the Hub lists it.' },
177
+ },
178
+ required: [...candidates.items.required, 'task', 'license'],
179
+ };
180
+ const properties = { ...reply.properties, candidates: { ...candidates, items: model } };
181
+ return JSON.stringify({ ...reply, properties }, null, 2);
182
+ }
151
183
  /** The agent id the decision example opens under; its run starts with the pantry's state and pictures. */
152
184
  export const DECISION_EXAMPLE_AGENT_ID = 'pantry.jev';
153
185
  /** What the decision example's questions are asked about: the shelf, and why we ask. */
@@ -353,7 +385,7 @@ function exampleTextDraft(identity, tools) {
353
385
  const inputs = demoInputsSpec();
354
386
  return {
355
387
  ...blank,
356
- identity: { ...identity, profileType: 'text', systemByRoleJson: '' },
388
+ identity: { ...identity, profileType: 'text', conditions: [] },
357
389
  included: ['outputs', 'turnBehaviour', 'guardrails', 'observability', 'labels'],
358
390
  models: { defaultModel: 'open', allowModelSelect: true, maxSteps: 12, key: 'gemini' },
359
391
  modelBindings: defaultTextModelBindings(),
@@ -389,38 +421,106 @@ export const RESEARCH_PAGE_READER_STATE = JSON.stringify({
389
421
  passage: 'MemGPT (Packer et al.) pages conversational history into an external store and reloads ' +
390
422
  'relevant spans on later turns, treating context as a virtual memory hierarchy rather than a single prompt window.',
391
423
  }, null, 2);
392
- /** The decision page-reader (`research.pagereader`) that filters passages for `research.scout` at `post_tool`. */
393
- export function createPageReaderExampleDraft() {
424
+ /** A research agent on Jev, which answers on the state it is given. */
425
+ function researchDecisionDraft(identity, contract, questions) {
394
426
  const draft = setProfileType(createBlankDraft(), 'decision', EXAMPLE_PICKS);
395
427
  const binding = draft.modelBindings[0];
396
428
  return {
397
429
  ...draft,
398
- identity: {
399
- ...draft.identity,
400
- agentId: RESEARCH_PAGE_READER_AGENT_ID,
401
- handle: 'pagereader',
402
- },
430
+ identity: { ...draft.identity, ...identity },
403
431
  models: { ...draft.models, key: 'typesafe' },
404
- modelBindings: binding ? [{ ...binding, apiId: 'jev-latest', keySlot: 'typesafe' }] : [],
405
- decision: {
406
- ...draft.decision,
407
- contract: 'research.page-passages.v1',
408
- questions: [
409
- exampleQuestion('passage', 'choice', 'Does `passage` state a fact a careful researcher would want when answering `question`, including facts that do not settle it and anything contradictory?', [
410
- ['relevant', 'The passage states such a fact.'],
411
- [
412
- 'not_relevant',
413
- 'The passage does not: it is about something else, or is only a heading, navigation, a reference or a list of links.',
414
- ],
415
- ]),
432
+ modelBindings: binding
433
+ ? [{ ...binding, apiId: 'jev-1.14.0', keySlot: 'typesafe', options: { images: true } }]
434
+ : [],
435
+ decision: { ...draft.decision, contract, questions },
436
+ };
437
+ }
438
+ /** The decision page-reader (`research.pagereader`) that filters passages for `research.scout` at `post_tool`. */
439
+ export function createPageReaderExampleDraft() {
440
+ return researchDecisionDraft({ agentId: RESEARCH_PAGE_READER_AGENT_ID, handle: 'pagereader' }, 'research.page-passages.v1', [
441
+ exampleQuestion('passage', 'choice', 'Does `passage` state a fact a careful researcher would want when answering `question`, including facts that do not settle it and anything contradictory?', [
442
+ ['relevant', 'The passage states such a fact.'],
443
+ [
444
+ 'not_relevant',
445
+ 'The passage does not: it is about something else, or is only a heading, navigation, a reference or a list of links.',
416
446
  ],
447
+ ]),
448
+ ]);
449
+ }
450
+ /** A standalone check: does a quote back the claim made from it. */
451
+ function createResearchJudgeDraft() {
452
+ return researchDecisionDraft({ agentId: 'research.judge', handle: 'judge' }, 'research.quote-check.v1', [
453
+ exampleQuestion('backing', 'choice', 'Does `quote` back `claim`?', [
454
+ ['backed', 'The quote states the claim, or something that plainly entails it.'],
455
+ ['not_backed', 'The quote is about something else, or says less than the claim.'],
456
+ ]),
457
+ ]);
458
+ }
459
+ /** The agent `research.scout` compacts its history with. */
460
+ function createResearchCompactorDraft() {
461
+ return exampleTextDraft({
462
+ agentId: 'research.compactor',
463
+ handle: 'compactor',
464
+ system: 'Summarise the research so far. Keep every source URL, every exact quote, and every open lead.',
465
+ }, { tools: { t2Loader: '', parallel: false }, toolSpecs: [] });
466
+ }
467
+ /** The speech agent that reads `research.scout`'s findings as a podcast. */
468
+ function createResearchPodcastDraft() {
469
+ const draft = createNarratorExampleDraft();
470
+ return {
471
+ ...draft,
472
+ identity: { ...draft.identity, agentId: 'research.podcast', handle: 'podcast' },
473
+ };
474
+ }
475
+ /** The image agent that draws a paper's method. */
476
+ function createResearchIllustratorDraft() {
477
+ const draft = setProfileType(createBlankDraft(), 'image', EXAMPLE_PICKS);
478
+ return {
479
+ ...draft,
480
+ identity: { ...draft.identity, agentId: 'research.illustrator', handle: 'illustrator' },
481
+ };
482
+ }
483
+ /** Embeddings to rank abstracts by a question. It keeps no store. */
484
+ function createResearchEmbedderDraft() {
485
+ const draft = createGeminiEmbeddingExampleDraft();
486
+ return {
487
+ ...draft,
488
+ identity: { ...draft.identity, agentId: 'research.embedder', handle: 'embedder' },
489
+ };
490
+ }
491
+ /** The research scout on a call: the same tools, a live model, and an instruction for speech. */
492
+ function createResearchLiveDraft() {
493
+ const draft = setProfileType(createResearchScoutDraft(), 'live', EXAMPLE_PICKS);
494
+ return {
495
+ ...draft,
496
+ identity: {
497
+ ...draft.identity,
498
+ agentId: 'research.scout.live',
499
+ system: DEMO_LIVE_RESEARCH_SYSTEM,
417
500
  },
418
501
  };
419
502
  }
503
+ /** The scout's tools with no model, `read_pages` first, to call by hand. */
504
+ function createResearchConsoleDraft() {
505
+ const draft = createConsoleExampleDraft();
506
+ const tools = exampleTools(DEMO_RESEARCH_TOOLS);
507
+ return {
508
+ ...draft,
509
+ identity: { ...draft.identity, agentId: 'research.console' },
510
+ toolSpecs: [
511
+ ...tools.filter((tool) => tool.toolName === 'read_pages'),
512
+ ...tools.filter((tool) => tool.toolName !== 'read_pages'),
513
+ ],
514
+ };
515
+ }
420
516
  /** The research scout on its own: searches papers, models, datasets, repos, and docs. */
421
517
  export function createResearchScoutDraft() {
422
518
  const blank = createBlankDraft();
423
- const base = exampleTextDraft({ agentId: 'research.scout', handle: 'scout', system: DEMO_RESEARCH_SYSTEM }, { tools: { t2Loader: '', parallel: true }, toolSpecs: exampleTools(DEMO_RESEARCH_TOOLS) });
519
+ const base = exampleTextDraft({
520
+ agentId: 'research.scout',
521
+ handle: 'scout',
522
+ system: [DEMO_RESEARCH_SYSTEM, ...RESEARCH_READER_LINES].join('\n\n'),
523
+ }, { tools: { t2Loader: '', parallel: true }, toolSpecs: exampleTools(DEMO_RESEARCH_TOOLS) });
424
524
  return {
425
525
  ...base,
426
526
  // Goals starts here: leave attachments and effort select off so examples earn them.
@@ -431,6 +531,7 @@ export function createResearchScoutDraft() {
431
531
  maxFiles: null,
432
532
  maxBytes: null,
433
533
  maxTurnBytes: null,
534
+ slots: [researchFocusSlot(), researchReaderSlot()],
434
535
  },
435
536
  models: {
436
537
  defaultModel: 'open',
@@ -464,6 +565,7 @@ export function createResearchScoutDraft() {
464
565
  defaultEffort: 'normal',
465
566
  allowEffortSelect: false,
466
567
  summaries: true,
568
+ builtInTools: ['googleSearch'],
467
569
  }),
468
570
  ],
469
571
  turnBehaviour: {
@@ -481,6 +583,16 @@ export function createResearchScoutDraft() {
481
583
  mode: 'structured',
482
584
  schemaId: RESEARCH_REPLY_SCHEMA_ID,
483
585
  schemaJson: RESEARCH_REPLY_SCHEMA_JSON,
586
+ bySlot: {
587
+ slot: 'focus',
588
+ shapes: [
589
+ {
590
+ choice: RESEARCH_MODELS_FOCUS,
591
+ schemaId: RESEARCH_MODELS_SCHEMA_ID,
592
+ schemaJson: researchModelsSchemaJson(),
593
+ },
594
+ ],
595
+ },
484
596
  streamMode: 'sse',
485
597
  streamThoughts: true,
486
598
  validationEnabled: true,
@@ -491,9 +603,62 @@ export function createResearchScoutDraft() {
491
603
  ...blank.guardrails,
492
604
  detect: flagAllDetect(blank.guardrails.detect),
493
605
  allowedHosts: RESEARCH_ALLOWED_HOSTS.split(',').map((host) => host.trim()),
606
+ // why: export_report writes, so a page the scout read can't steer what it saves.
607
+ taintAfterRemoteRead: 'write',
608
+ own: [researchRetractionDetector()],
494
609
  },
495
610
  };
496
611
  }
612
+ /** What the scout adds to its system prompt for a reviewer or a student. */
613
+ const RESEARCH_READER_LINES = [
614
+ 'when reader is reviewer: The reader reviews papers. Lead with weak evidence and what would refute a claim.',
615
+ 'when reader is student: The reader is learning the field. Define each term the first time you use it.',
616
+ ];
617
+ /** The focus that answers in `research.models`. */
618
+ const RESEARCH_MODELS_FOCUS = 'Hugging Face Open Research';
619
+ /** Where a turn looks first. */
620
+ function researchFocusSlot() {
621
+ return {
622
+ key: draftKey('slot'),
623
+ name: 'focus',
624
+ label: 'Focus',
625
+ choices: [RESEARCH_MODELS_FOCUS, 'arXiv', 'GitHub', 'Anywhere'].map((value) => ({
626
+ key: draftKey('choice'),
627
+ value,
628
+ description: '',
629
+ })),
630
+ };
631
+ }
632
+ /** Who the scout writes for, which picks its lines in `RESEARCH_READER_LINES`. */
633
+ function researchReaderSlot() {
634
+ return {
635
+ key: draftKey('slot'),
636
+ name: 'reader',
637
+ label: 'Reader',
638
+ choices: ['anyone', 'reviewer', 'student'].map((value) => ({
639
+ key: draftKey('choice'),
640
+ value,
641
+ description: '',
642
+ })),
643
+ };
644
+ }
645
+ /** Flags a page that says its paper was taken back. */
646
+ function researchRetractionDetector() {
647
+ const blank = newOwnDetector();
648
+ return {
649
+ ...blank,
650
+ key: 'research.retraction',
651
+ label: 'Retracted paper',
652
+ at: { ...blank.at, tool_output_http: 'flag', tool_output_mcp: 'flag' },
653
+ patterns: [
654
+ {
655
+ ...newPattern(),
656
+ name: 'retraction',
657
+ words: ['retracted', 'retraction notice', 'withdrawn by the authors'],
658
+ },
659
+ ],
660
+ };
661
+ }
497
662
  /**
498
663
  * Adds `research.pagereader` after `research.scout` and links the scout's page-reading tools
499
664
  * (`read_pages`, `read_model_card`, `read_dataset_card`, `read_readme`, `read_library_docs`) to it via `stageAgentKey`.
@@ -514,17 +679,66 @@ function withPageReader(workspace) {
514
679
  selected: agentNodeId(scout.key),
515
680
  }, scout.key);
516
681
  }
517
- /** The research scout and the Jev page reader it filters pages with, added to a workspace. */
682
+ /** Has `caller` compact its history with the agent last added. */
683
+ function withCompactor(workspace, caller) {
684
+ const compactWith = workspace.agents.at(-1)?.key;
685
+ return {
686
+ ...workspace,
687
+ agents: workspace.agents.map((agent) => agent.key === caller
688
+ ? {
689
+ ...agent,
690
+ modelBindings: agent.modelBindings.map((binding) => ({
691
+ ...binding,
692
+ ...COMPACTION_DRAFT_DEFAULTS,
693
+ compactTiming: 'before',
694
+ compactWith,
695
+ })),
696
+ }
697
+ : agent),
698
+ };
699
+ }
700
+ /** The page reader and the rest of the scout's team, added after the scout, which stays selected. */
701
+ function withResearchTeam(workspace) {
702
+ const scout = workspace.agents.at(-1);
703
+ if (!scout)
704
+ return workspace;
705
+ const read = withPageReader(workspace);
706
+ const summarised = withCompactor(addAgent(read, createResearchCompactorDraft()), scout.key);
707
+ const voiced = withAgentTool(summarised, scout.key, createResearchPodcastDraft(), {
708
+ toolName: 'record_podcast',
709
+ description: 'Has the podcast agent read a script of the findings aloud and returns the audio.',
710
+ activity: 'Recording the podcast',
711
+ activityPast: 'Recorded the podcast',
712
+ });
713
+ const drawn = withAgentTool(voiced, scout.key, createResearchIllustratorDraft(), {
714
+ toolName: 'draw_method',
715
+ description: "Has the illustrator draw a paper's method and returns the image.",
716
+ activity: 'Drawing the method',
717
+ activityPast: 'Drew the method',
718
+ });
719
+ const team = [
720
+ createResearchEmbedderDraft(),
721
+ createResearchLiveDraft(),
722
+ createResearchConsoleDraft(),
723
+ createResearchJudgeDraft(),
724
+ ].reduce(addAgent, drawn);
725
+ return markAgentStart({ ...team, selected: agentNodeId(scout.key) }, scout.key);
726
+ }
727
+ /** The research scout and its team, added to a workspace. */
518
728
  export function addResearchExample(workspace) {
519
- return withPageReader(addAgent(workspace, createResearchScoutDraft()));
729
+ return withResearchTeam(addAgent(workspace, createResearchScoutDraft()));
520
730
  }
521
- /** A workspace of the research scout and its Jev page reader, with the scout in the chat. */
731
+ /** A workspace of the research scout and its team, with the scout in the chat. */
522
732
  export function createResearchWorkspace() {
523
- return withPageReader(workspaceFromDraft(createResearchScoutDraft()));
733
+ return withResearchTeam(workspaceFromDraft(createResearchScoutDraft()));
524
734
  }
525
735
  /** A fresh copy of the travel concierge draft: a text agent with the tools a trip needs. */
526
736
  export function createExampleDraft() {
527
- return exampleTextDraft({ agentId: 'travel.concierge', handle: 'concierge', system: DEMO_CONCIERGE_SYSTEM }, {
737
+ return exampleTextDraft({
738
+ agentId: 'travel.concierge',
739
+ handle: 'concierge',
740
+ system: DEMO_CONCIERGE_SYSTEM,
741
+ }, {
528
742
  tools: { t2Loader: 'discover_tools', parallel: false },
529
743
  toolSpecs: exampleTools(DEMO_CONCIERGE_TOOLS),
530
744
  });
@@ -564,7 +778,34 @@ export function createConsoleExampleDraft() {
564
778
  }
565
779
  /** The code architect on its own: the code and docs tools, before the narrator joins it. */
566
780
  function architectDraft() {
567
- return exampleTextDraft({ agentId: 'code.architect', handle: 'architect', system: DEMO_ARCHITECT_SYSTEM }, { tools: { t2Loader: '', parallel: false }, toolSpecs: exampleTools(DEMO_ARCHITECT_TOOLS) });
781
+ return exampleTextDraft({
782
+ agentId: 'code.architect',
783
+ handle: 'architect',
784
+ system: DEMO_ARCHITECT_SYSTEM,
785
+ }, { tools: { t2Loader: '', parallel: false }, toolSpecs: exampleTools(DEMO_ARCHITECT_TOOLS) });
786
+ }
787
+ /** Adds `draft` as an agent, and an agent tool that lets `caller` run it, leaving `caller` selected. */
788
+ function withAgentTool(workspace, caller, draft, tool) {
789
+ const pair = addAgent(workspace, draft);
790
+ const called = pair.agents.at(-1);
791
+ if (!called)
792
+ return pair;
793
+ const taken = pair.toolSpecs.map((spec) => spec.toolName);
794
+ const spec = defaultToolSpec({
795
+ ...tool,
796
+ toolName: freeName(tool.toolName, taken, (n) => `${tool.toolName}_${n}`),
797
+ toolType: 'agent',
798
+ agentKey: called.key,
799
+ category: 'demo',
800
+ });
801
+ return {
802
+ ...pair,
803
+ agents: pair.agents.map((agent) => agent.key === caller
804
+ ? { ...agent, tools: { ...agent.tools, allow: [...agent.tools.allow, spec.key] } }
805
+ : agent),
806
+ toolSpecs: [...pair.toolSpecs, spec],
807
+ selected: agentNodeId(caller),
808
+ };
568
809
  }
569
810
  /**
570
811
  * Adds the narrator after the workspace's last agent, the architect, and the `narrate` agent tool
@@ -572,29 +813,15 @@ function architectDraft() {
572
813
  */
573
814
  function withNarrator(workspace) {
574
815
  const architect = workspace.agents.at(-1);
575
- const pair = addAgent(workspace, createNarratorExampleDraft());
576
- const narrator = pair.agents.at(-1);
577
- if (!architect || !narrator)
578
- return pair;
579
- const taken = pair.toolSpecs.map((tool) => tool.toolName);
580
- const narrate = defaultToolSpec({
581
- toolName: freeName('narrate', taken, (n) => `narrate_${n}`),
582
- toolType: 'agent',
583
- agentKey: narrator.key,
816
+ if (!architect)
817
+ return workspace;
818
+ // The architect starts with `narrate` allowed, so a reset keeps the two linked.
819
+ return markAgentStart(withAgentTool(workspace, architect.key, createNarratorExampleDraft(), {
820
+ toolName: 'narrate',
584
821
  description: 'Has the narrator read a script aloud and returns the audio.',
585
822
  activity: 'Recording the briefing',
586
823
  activityPast: 'Recorded the briefing',
587
- category: 'demo',
588
- });
589
- // The architect starts with `narrate` allowed, so a reset keeps the two linked.
590
- return markAgentStart({
591
- ...pair,
592
- agents: pair.agents.map((agent) => agent.key === architect.key
593
- ? { ...agent, tools: { ...agent.tools, allow: [...agent.tools.allow, narrate.key] } }
594
- : agent),
595
- toolSpecs: [...pair.toolSpecs, narrate],
596
- selected: agentNodeId(architect.key),
597
- }, architect.key);
824
+ }), architect.key);
598
825
  }
599
826
  /** The code architect and the narrator it calls, added to a workspace that keeps its other agents. */
600
827
  export function addArchitectExample(workspace) {
@@ -616,13 +843,31 @@ export const COOKBOOKS = {
616
843
  label: 'Research scout',
617
844
  description: 'Ask a hard question about models, papers, or memory. It searches the Hub, arXiv, and GitHub, cuts each page to the passages that bear on the question, and will not let a quote through unchecked.',
618
845
  tags: {
619
- includes: ['text', 'decision', 'http-tools', 'mcp-tools', 'guardrails', 'post-tool'],
846
+ includes: [
847
+ 'text',
848
+ 'decision',
849
+ 'embedding',
850
+ 'speech',
851
+ 'live',
852
+ 'host',
853
+ 'http-tools',
854
+ 'mcp-tools',
855
+ 'agent-tools',
856
+ 'function-tools',
857
+ 'guardrails',
858
+ 'post-tool',
859
+ ],
620
860
  },
621
861
  teaches: [
622
862
  'A multi-agent system: text agent `research.scout` plus decision agent `research.pagereader` (Jev).',
863
+ 'One agent of each type around it: `research.compactor` (text), `research.podcast` (speech), `research.illustrator` (image), `research.embedder` (embedding), `research.scout.live` (live), `research.console` (host), and `research.judge` (decision).',
864
+ 'A reply shaped by what the turn states: `focus` picks `research.models` or `research.reply` through `outputs.structured.by`.',
865
+ 'Call order the model chooses: a tool with `after` runs once the tools it names in the same step have settled.',
866
+ 'A write tool (`export_report`) that `taintAfterRemoteRead` refuses once a page has been read, and a tool the page answers (`check_device`).',
867
+ 'One custom detector, `research.retraction`, and a prompt line for each `reader` through a `when` line.',
623
868
  'Staging page-read tools at `post_tool` via `stageAgentKey`: `read_pages`, `read_model_card`, `read_dataset_card`, `read_readme`, and `read_library_docs` are filtered by the page-reader before the scout sees them.',
624
869
  'Parallel tool calls (`tools.parallel: true`) across HTTP tools (arXiv, GitHub, Hub cards) and MCP tools (Exa `search_web` / `read_pages`, Context7 library docs, DeepWiki `ask_repo_docs`).',
625
- 'Guardrails that flag every detector on untrusted page text, with `allowedHosts` limited to the research hosts.',
870
+ 'Guardrails that flag every detector on untrusted page text. `allowedHosts` names the research hosts, which exempts them from the private-address check. It does not limit tools to them.',
626
871
  'Turn behaviour with resume, auto-continue on length / stream_incomplete / provider_error, and steering.',
627
872
  ],
628
873
  question: RESEARCH_FIRST_TURN_PROMPT,
@@ -643,7 +888,7 @@ export const COOKBOOKS = {
643
888
  'A turn-time tool loader (`t2Loader: discover_tools`) that can pull in extra demo tools during the turn.',
644
889
  'Mixing HTTP tools (geocode, weather, currency, Wikipedia), MCP (`search_web`), and local function tools (distances, day plan, packing, budget).',
645
890
  'Silent tool use in the system prompt: no narrating tool names; findings land in the reply.',
646
- 'Reply-side detect set to block sensitive and injection phrasing, with `allowedHosts` for the travel hosts.',
891
+ 'Reply-side detect set to block sensitive and injection phrasing. `allowedHosts` names the travel hosts, which exempts them from the private-address check.',
647
892
  ],
648
893
  createWorkspace: workspaceOf(createExampleDraft),
649
894
  addToWorkspace: addsDraft(createExampleDraft),
@@ -119,6 +119,7 @@ export function stitchCookbook(cookbookId, recipe = {}) {
119
119
  const draft = recipe.toolsAllow
120
120
  ? {
121
121
  ...baseDraft,
122
+ modelBindings: baseDraft.modelBindings.map(({ compactTiming: _timing, compactWith: _with, ...binding }) => binding),
122
123
  toolSpecs: baseDraft.toolSpecs
123
124
  .filter((tool) => recipe.toolsAllow?.includes(tool.toolName))
124
125
  .map(({ stageAgentKey: _stage, ...tool }) => tool),
@@ -67,11 +67,69 @@ export function demoInputsSpec() {
67
67
  }
68
68
  const QUESTION_PROPERTY = `"question": { "type": "string", "minLength": 1, "description": "What you need from this source, as one specific question.", "examples": ["What datasets are evaluated?"] }`;
69
69
  const COOKBOOK_TOOL_SPECS = [
70
+ {
71
+ id: 'tool-export-report',
72
+ data: {
73
+ toolName: 'export_report',
74
+ activity: 'Exporting {title}',
75
+ activityPast: 'Exported {title}',
76
+ request: 'export a report called {title}',
77
+ toolType: 'function',
78
+ description: "Save a finished report to the reader's workspace (studio stub).",
79
+ category: 'demo',
80
+ access: 'read-write',
81
+ permission: 'auto',
82
+ loadTier: 'T0',
83
+ paths: ['*'],
84
+ inputJson: `{
85
+ "type": "object",
86
+ "properties": {
87
+ "title": { "type": "string", "description": "The report's title", "examples": ["Episodic memory for agents"] },
88
+ "body": { "type": "string", "description": "The report, in Markdown" }
89
+ },
90
+ "required": ["title", "body"]
91
+ }`,
92
+ outputJson: `{
93
+ "type": "object",
94
+ "properties": { "saved": { "type": "boolean" } },
95
+ "required": ["saved"]
96
+ }`,
97
+ stubOutputJson: `{ "saved": true }`,
98
+ },
99
+ },
100
+ {
101
+ id: 'tool-check-device',
102
+ data: {
103
+ toolName: 'check_device',
104
+ activity: 'Checking this device',
105
+ activityPast: 'Checked this device',
106
+ request: 'check what this device can run',
107
+ toolType: 'function',
108
+ answeredBy: 'page',
109
+ description: 'Report whether this device has WebGPU and how much memory it has, to judge which models it can run.',
110
+ category: 'demo',
111
+ access: 'read-only',
112
+ permission: 'auto',
113
+ loadTier: 'T0',
114
+ paths: ['*'],
115
+ inputJson: `{ "type": "object", "properties": {} }`,
116
+ outputJson: `{
117
+ "type": "object",
118
+ "properties": {
119
+ "webgpu": { "type": "boolean" },
120
+ "memoryGb": { "type": "number" }
121
+ },
122
+ "required": ["webgpu", "memoryGb"]
123
+ }`,
124
+ stubOutputJson: `{ "webgpu": true, "memoryGb": 16 }`,
125
+ },
126
+ },
70
127
  // --- Research Scout tools (Exa, arXiv, Hugging Face, GitHub, Context7, DeepWiki) ---
71
128
  {
72
129
  id: 'tool-read-pages',
73
130
  data: {
74
131
  toolName: 'read_pages',
132
+ after: true,
75
133
  activity: 'Reading {urls.0}',
76
134
  activityPast: `when urls.length is 1: Read {urls.0}
77
135
  Read {urls.length} pages
@@ -189,6 +247,7 @@ Found hits for {search|that query}`,
189
247
  id: 'tool-read-model-card',
190
248
  data: {
191
249
  toolName: 'read_model_card',
250
+ after: true,
192
251
  activity: 'Reading model card {owner}/{name}',
193
252
  activityPast: 'Read model card {owner}/{name}',
194
253
  activityFailed: 'Could not read model card {owner}/{name}',
@@ -219,6 +278,7 @@ Found hits for {search|that query}`,
219
278
  id: 'tool-read-dataset-card',
220
279
  data: {
221
280
  toolName: 'read_dataset_card',
281
+ after: true,
222
282
  activity: 'Reading dataset card {owner}/{name}',
223
283
  activityPast: 'Read dataset card {owner}/{name}',
224
284
  activityFailed: 'Could not read dataset card {owner}/{name}',
@@ -285,6 +345,7 @@ Found hits for {q|that query}`,
285
345
  id: 'tool-read-readme',
286
346
  data: {
287
347
  toolName: 'read_readme',
348
+ after: true,
288
349
  activity: 'Reading README of {owner}/{repo}',
289
350
  activityPast: 'Read README of {owner}/{repo}',
290
351
  activityFailed: 'Could not read README of {owner}/{repo}',
@@ -751,6 +812,7 @@ Found hits for {q|that query}`,
751
812
  id: 'tool-context7-docs',
752
813
  data: {
753
814
  toolName: 'read_library_docs',
815
+ after: true,
754
816
  activity: 'Reading the {libraryId} docs',
755
817
  activityPast: 'Read the {libraryId} docs',
756
818
  activityFailed: 'Could not read the {libraryId|library} docs',
@@ -1432,6 +1494,8 @@ export const DEMO_RESEARCH_TOOLS = [
1432
1494
  'find_library',
1433
1495
  'read_library_docs',
1434
1496
  'ask_repo_docs',
1497
+ 'export_report',
1498
+ 'check_device',
1435
1499
  ];
1436
1500
  /** The research tools whose output is a full page or card that `research.pagereader` filters at `post_tool`. */
1437
1501
  export const DEMO_RESEARCH_STAGE_READ_TOOLS = [
package/draft.d.ts CHANGED
@@ -15,14 +15,22 @@ export type StudioProfileType = ProfileType;
15
15
  /** The types that run a model turn; a decision asks questions, and a host runs its tools. */
16
16
  export type StudioTurnProfileType = Exclude<StudioProfileType, 'decision' | 'host'>;
17
17
  export declare const STUDIO_PROFILE_TYPES: readonly StudioProfileType[];
18
+ /** A fact each turn states: its name and the values it can take. */
19
+ export interface ConditionDraft {
20
+ key: string;
21
+ name: string;
22
+ values: string[];
23
+ }
18
24
  export interface IdentityDraft {
19
25
  agentId: string;
20
26
  profileType: StudioProfileType | '';
21
27
  handle: string;
22
- /** Private sections are wrapped as `{private: …}`. Unused on speech, which has no system channel. */
28
+ /**
29
+ * The whole prompt as typed: a blank line starts a new line, and private sections are wrapped as
30
+ * `{private: …}`. Unused on speech, which has no system channel.
31
+ */
23
32
  system: string;
24
- /** Other instructions by the role a turn names, as a JSON object of strings (with `{private: …}` sections) or parts; blank omits it. */
25
- systemByRoleJson: string;
33
+ conditions: ConditionDraft[];
26
34
  }
27
35
  export interface ModelsDraft {
28
36
  /** Who holds the conversation a saved state continues; unset is the kernel's default, the host. */
@@ -176,10 +184,20 @@ export interface InputsDraft {
176
184
  /** The longest context package from each sender, in characters of JSON. */
177
185
  contextMaxChars: number | null;
178
186
  }
187
+ /** The reply shapes a slot's value picks; any other value takes the outputs' own schema. */
188
+ export interface SlotShapesDraft {
189
+ slot: string;
190
+ shapes: {
191
+ choice: string;
192
+ schemaId: string;
193
+ schemaJson: string;
194
+ }[];
195
+ }
179
196
  export interface OutputsDraft {
180
197
  mode: 'text' | 'structured';
181
198
  schemaId: string;
182
199
  schemaJson: string;
200
+ bySlot?: SlotShapesDraft;
183
201
  /** `''` omits it (kernel default: SSE). */
184
202
  streamMode: '' | StreamMode;
185
203
  streamThoughts: boolean;
@@ -404,7 +422,7 @@ export interface StudioDraft {
404
422
  decision: DecisionDraft;
405
423
  labels: LabelsDraft;
406
424
  }
407
- export declare function draftKey(prefix: 'agent' | 'model' | 'tool' | 'question' | 'criterion' | 'reference' | 'image' | 'slot' | 'choice'): string;
425
+ export declare function draftKey(prefix: 'agent' | 'condition' | 'entry' | 'model' | 'tool' | 'question' | 'criterion' | 'reference' | 'image' | 'slot' | 'choice'): string;
408
426
  export declare function defaultModelBinding(partial?: Partial<ModelBindingDraft>): ModelBindingDraft;
409
427
  export declare function defaultToolSpec(partial?: Partial<ToolSpecDraft>): ToolSpecDraft;
410
428
  /**
@@ -438,6 +456,7 @@ export declare function newDecisionImage(draft: StudioDraft, file: string, image
438
456
  }): DecisionImageDraft;
439
457
  /** A new slot, with a name the draft doesn't use yet and two blank choices. */
440
458
  export declare function newSlot(slots: readonly SlotDraft[]): SlotDraft;
459
+ export declare function newCondition(): ConditionDraft;
441
460
  export declare function newSlotChoice(): SlotChoiceDraft;
442
461
  /** One blank row: an option, a level, or a criterion. */
443
462
  export declare function newCriterion(): DecisionCriterionDraft;