@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
@@ -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, newSystemLine, 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', conditionsJson: '' },
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,108 @@ 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: [
465
+ newSystemLine('Summarise the research so far. Keep every source URL, every exact quote, and every open lead.'),
466
+ ],
467
+ }, { tools: { t2Loader: '', parallel: false }, toolSpecs: [] });
468
+ }
469
+ /** The speech agent that reads `research.scout`'s findings as a podcast. */
470
+ function createResearchPodcastDraft() {
471
+ const draft = createNarratorExampleDraft();
472
+ return {
473
+ ...draft,
474
+ identity: { ...draft.identity, agentId: 'research.podcast', handle: 'podcast' },
475
+ };
476
+ }
477
+ /** The image agent that draws a paper's method. */
478
+ function createResearchIllustratorDraft() {
479
+ const draft = setProfileType(createBlankDraft(), 'image', EXAMPLE_PICKS);
480
+ return {
481
+ ...draft,
482
+ identity: { ...draft.identity, agentId: 'research.illustrator', handle: 'illustrator' },
483
+ };
484
+ }
485
+ /** Embeddings to rank abstracts by a question. It keeps no store. */
486
+ function createResearchEmbedderDraft() {
487
+ const draft = createGeminiEmbeddingExampleDraft();
488
+ return {
489
+ ...draft,
490
+ identity: { ...draft.identity, agentId: 'research.embedder', handle: 'embedder' },
491
+ };
492
+ }
493
+ /** The research scout on a call: the same tools, a live model, and an instruction for speech. */
494
+ function createResearchLiveDraft() {
495
+ const draft = setProfileType(createResearchScoutDraft(), 'live', EXAMPLE_PICKS);
496
+ return {
497
+ ...draft,
498
+ identity: {
499
+ ...draft.identity,
500
+ agentId: 'research.scout.live',
501
+ system: [newSystemLine(DEMO_LIVE_RESEARCH_SYSTEM)],
417
502
  },
418
503
  };
419
504
  }
505
+ /** The scout's tools with no model, `read_pages` first, to call by hand. */
506
+ function createResearchConsoleDraft() {
507
+ const draft = createConsoleExampleDraft();
508
+ const tools = exampleTools(DEMO_RESEARCH_TOOLS);
509
+ return {
510
+ ...draft,
511
+ identity: { ...draft.identity, agentId: 'research.console' },
512
+ toolSpecs: [
513
+ ...tools.filter((tool) => tool.toolName === 'read_pages'),
514
+ ...tools.filter((tool) => tool.toolName !== 'read_pages'),
515
+ ],
516
+ };
517
+ }
420
518
  /** The research scout on its own: searches papers, models, datasets, repos, and docs. */
421
519
  export function createResearchScoutDraft() {
422
520
  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) });
521
+ const base = exampleTextDraft({
522
+ agentId: 'research.scout',
523
+ handle: 'scout',
524
+ system: [DEMO_RESEARCH_SYSTEM, ...RESEARCH_READER_LINES].map((line) => newSystemLine(line)),
525
+ }, { tools: { t2Loader: '', parallel: true }, toolSpecs: exampleTools(DEMO_RESEARCH_TOOLS) });
424
526
  return {
425
527
  ...base,
426
528
  // Goals starts here: leave attachments and effort select off so examples earn them.
@@ -431,6 +533,7 @@ export function createResearchScoutDraft() {
431
533
  maxFiles: null,
432
534
  maxBytes: null,
433
535
  maxTurnBytes: null,
536
+ slots: [researchFocusSlot(), researchReaderSlot()],
434
537
  },
435
538
  models: {
436
539
  defaultModel: 'open',
@@ -464,6 +567,7 @@ export function createResearchScoutDraft() {
464
567
  defaultEffort: 'normal',
465
568
  allowEffortSelect: false,
466
569
  summaries: true,
570
+ builtInTools: ['googleSearch'],
467
571
  }),
468
572
  ],
469
573
  turnBehaviour: {
@@ -481,6 +585,16 @@ export function createResearchScoutDraft() {
481
585
  mode: 'structured',
482
586
  schemaId: RESEARCH_REPLY_SCHEMA_ID,
483
587
  schemaJson: RESEARCH_REPLY_SCHEMA_JSON,
588
+ bySlot: {
589
+ slot: 'focus',
590
+ shapes: [
591
+ {
592
+ choice: RESEARCH_MODELS_FOCUS,
593
+ schemaId: RESEARCH_MODELS_SCHEMA_ID,
594
+ schemaJson: researchModelsSchemaJson(),
595
+ },
596
+ ],
597
+ },
484
598
  streamMode: 'sse',
485
599
  streamThoughts: true,
486
600
  validationEnabled: true,
@@ -491,9 +605,62 @@ export function createResearchScoutDraft() {
491
605
  ...blank.guardrails,
492
606
  detect: flagAllDetect(blank.guardrails.detect),
493
607
  allowedHosts: RESEARCH_ALLOWED_HOSTS.split(',').map((host) => host.trim()),
608
+ // why: export_report writes, so a page the scout read can't steer what it saves.
609
+ taintAfterRemoteRead: 'write',
610
+ own: [researchRetractionDetector()],
494
611
  },
495
612
  };
496
613
  }
614
+ /** What the scout adds to its system prompt for a reviewer or a student. */
615
+ const RESEARCH_READER_LINES = [
616
+ 'when reader is reviewer: The reader reviews papers. Lead with weak evidence and what would refute a claim.',
617
+ 'when reader is student: The reader is learning the field. Define each term the first time you use it.',
618
+ ];
619
+ /** The focus that answers in `research.models`. */
620
+ const RESEARCH_MODELS_FOCUS = 'Hugging Face Open Research';
621
+ /** Where a turn looks first. */
622
+ function researchFocusSlot() {
623
+ return {
624
+ key: draftKey('slot'),
625
+ name: 'focus',
626
+ label: 'Focus',
627
+ choices: [RESEARCH_MODELS_FOCUS, 'arXiv', 'GitHub', 'Anywhere'].map((value) => ({
628
+ key: draftKey('choice'),
629
+ value,
630
+ description: '',
631
+ })),
632
+ };
633
+ }
634
+ /** Who the scout writes for, which picks its lines in `RESEARCH_READER_LINES`. */
635
+ function researchReaderSlot() {
636
+ return {
637
+ key: draftKey('slot'),
638
+ name: 'reader',
639
+ label: 'Reader',
640
+ choices: ['anyone', 'reviewer', 'student'].map((value) => ({
641
+ key: draftKey('choice'),
642
+ value,
643
+ description: '',
644
+ })),
645
+ };
646
+ }
647
+ /** Flags a page that says its paper was taken back. */
648
+ function researchRetractionDetector() {
649
+ const blank = newOwnDetector();
650
+ return {
651
+ ...blank,
652
+ key: 'research.retraction',
653
+ label: 'Retracted paper',
654
+ at: { ...blank.at, tool_output_http: 'flag', tool_output_mcp: 'flag' },
655
+ patterns: [
656
+ {
657
+ ...newPattern(),
658
+ name: 'retraction',
659
+ words: ['retracted', 'retraction notice', 'withdrawn by the authors'],
660
+ },
661
+ ],
662
+ };
663
+ }
497
664
  /**
498
665
  * Adds `research.pagereader` after `research.scout` and links the scout's page-reading tools
499
666
  * (`read_pages`, `read_model_card`, `read_dataset_card`, `read_readme`, `read_library_docs`) to it via `stageAgentKey`.
@@ -514,17 +681,66 @@ function withPageReader(workspace) {
514
681
  selected: agentNodeId(scout.key),
515
682
  }, scout.key);
516
683
  }
517
- /** The research scout and the Jev page reader it filters pages with, added to a workspace. */
684
+ /** Has `caller` compact its history with the agent last added. */
685
+ function withCompactor(workspace, caller) {
686
+ const compactWith = workspace.agents.at(-1)?.key;
687
+ return {
688
+ ...workspace,
689
+ agents: workspace.agents.map((agent) => agent.key === caller
690
+ ? {
691
+ ...agent,
692
+ modelBindings: agent.modelBindings.map((binding) => ({
693
+ ...binding,
694
+ ...COMPACTION_DRAFT_DEFAULTS,
695
+ compactTiming: 'before',
696
+ compactWith,
697
+ })),
698
+ }
699
+ : agent),
700
+ };
701
+ }
702
+ /** The page reader and the rest of the scout's team, added after the scout, which stays selected. */
703
+ function withResearchTeam(workspace) {
704
+ const scout = workspace.agents.at(-1);
705
+ if (!scout)
706
+ return workspace;
707
+ const read = withPageReader(workspace);
708
+ const summarised = withCompactor(addAgent(read, createResearchCompactorDraft()), scout.key);
709
+ const voiced = withAgentTool(summarised, scout.key, createResearchPodcastDraft(), {
710
+ toolName: 'record_podcast',
711
+ description: 'Has the podcast agent read a script of the findings aloud and returns the audio.',
712
+ activity: 'Recording the podcast',
713
+ activityPast: 'Recorded the podcast',
714
+ });
715
+ const drawn = withAgentTool(voiced, scout.key, createResearchIllustratorDraft(), {
716
+ toolName: 'draw_method',
717
+ description: "Has the illustrator draw a paper's method and returns the image.",
718
+ activity: 'Drawing the method',
719
+ activityPast: 'Drew the method',
720
+ });
721
+ const team = [
722
+ createResearchEmbedderDraft(),
723
+ createResearchLiveDraft(),
724
+ createResearchConsoleDraft(),
725
+ createResearchJudgeDraft(),
726
+ ].reduce(addAgent, drawn);
727
+ return markAgentStart({ ...team, selected: agentNodeId(scout.key) }, scout.key);
728
+ }
729
+ /** The research scout and its team, added to a workspace. */
518
730
  export function addResearchExample(workspace) {
519
- return withPageReader(addAgent(workspace, createResearchScoutDraft()));
731
+ return withResearchTeam(addAgent(workspace, createResearchScoutDraft()));
520
732
  }
521
- /** A workspace of the research scout and its Jev page reader, with the scout in the chat. */
733
+ /** A workspace of the research scout and its team, with the scout in the chat. */
522
734
  export function createResearchWorkspace() {
523
- return withPageReader(workspaceFromDraft(createResearchScoutDraft()));
735
+ return withResearchTeam(workspaceFromDraft(createResearchScoutDraft()));
524
736
  }
525
737
  /** A fresh copy of the travel concierge draft: a text agent with the tools a trip needs. */
526
738
  export function createExampleDraft() {
527
- return exampleTextDraft({ agentId: 'travel.concierge', handle: 'concierge', system: DEMO_CONCIERGE_SYSTEM }, {
739
+ return exampleTextDraft({
740
+ agentId: 'travel.concierge',
741
+ handle: 'concierge',
742
+ system: [newSystemLine(DEMO_CONCIERGE_SYSTEM)],
743
+ }, {
528
744
  tools: { t2Loader: 'discover_tools', parallel: false },
529
745
  toolSpecs: exampleTools(DEMO_CONCIERGE_TOOLS),
530
746
  });
@@ -537,7 +753,7 @@ export function createLiveExampleDraft() {
537
753
  identity: {
538
754
  ...draft.identity,
539
755
  agentId: 'travel.concierge.live',
540
- system: DEMO_LIVE_CONCIERGE_SYSTEM,
756
+ system: [newSystemLine(DEMO_LIVE_CONCIERGE_SYSTEM)],
541
757
  },
542
758
  };
543
759
  }
@@ -564,7 +780,34 @@ export function createConsoleExampleDraft() {
564
780
  }
565
781
  /** The code architect on its own: the code and docs tools, before the narrator joins it. */
566
782
  function architectDraft() {
567
- return exampleTextDraft({ agentId: 'code.architect', handle: 'architect', system: DEMO_ARCHITECT_SYSTEM }, { tools: { t2Loader: '', parallel: false }, toolSpecs: exampleTools(DEMO_ARCHITECT_TOOLS) });
783
+ return exampleTextDraft({
784
+ agentId: 'code.architect',
785
+ handle: 'architect',
786
+ system: [newSystemLine(DEMO_ARCHITECT_SYSTEM)],
787
+ }, { tools: { t2Loader: '', parallel: false }, toolSpecs: exampleTools(DEMO_ARCHITECT_TOOLS) });
788
+ }
789
+ /** Adds `draft` as an agent, and an agent tool that lets `caller` run it, leaving `caller` selected. */
790
+ function withAgentTool(workspace, caller, draft, tool) {
791
+ const pair = addAgent(workspace, draft);
792
+ const called = pair.agents.at(-1);
793
+ if (!called)
794
+ return pair;
795
+ const taken = pair.toolSpecs.map((spec) => spec.toolName);
796
+ const spec = defaultToolSpec({
797
+ ...tool,
798
+ toolName: freeName(tool.toolName, taken, (n) => `${tool.toolName}_${n}`),
799
+ toolType: 'agent',
800
+ agentKey: called.key,
801
+ category: 'demo',
802
+ });
803
+ return {
804
+ ...pair,
805
+ agents: pair.agents.map((agent) => agent.key === caller
806
+ ? { ...agent, tools: { ...agent.tools, allow: [...agent.tools.allow, spec.key] } }
807
+ : agent),
808
+ toolSpecs: [...pair.toolSpecs, spec],
809
+ selected: agentNodeId(caller),
810
+ };
568
811
  }
569
812
  /**
570
813
  * Adds the narrator after the workspace's last agent, the architect, and the `narrate` agent tool
@@ -572,29 +815,15 @@ function architectDraft() {
572
815
  */
573
816
  function withNarrator(workspace) {
574
817
  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,
818
+ if (!architect)
819
+ return workspace;
820
+ // The architect starts with `narrate` allowed, so a reset keeps the two linked.
821
+ return markAgentStart(withAgentTool(workspace, architect.key, createNarratorExampleDraft(), {
822
+ toolName: 'narrate',
584
823
  description: 'Has the narrator read a script aloud and returns the audio.',
585
824
  activity: 'Recording the briefing',
586
825
  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);
826
+ }), architect.key);
598
827
  }
599
828
  /** The code architect and the narrator it calls, added to a workspace that keeps its other agents. */
600
829
  export function addArchitectExample(workspace) {
@@ -616,13 +845,31 @@ export const COOKBOOKS = {
616
845
  label: 'Research scout',
617
846
  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
847
  tags: {
619
- includes: ['text', 'decision', 'http-tools', 'mcp-tools', 'guardrails', 'post-tool'],
848
+ includes: [
849
+ 'text',
850
+ 'decision',
851
+ 'embedding',
852
+ 'speech',
853
+ 'live',
854
+ 'host',
855
+ 'http-tools',
856
+ 'mcp-tools',
857
+ 'agent-tools',
858
+ 'function-tools',
859
+ 'guardrails',
860
+ 'post-tool',
861
+ ],
620
862
  },
621
863
  teaches: [
622
864
  'A multi-agent system: text agent `research.scout` plus decision agent `research.pagereader` (Jev).',
865
+ '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).',
866
+ 'A reply shaped by what the turn states: `focus` picks `research.models` or `research.reply` through `outputs.structured.by`.',
867
+ 'Call order the model chooses: a tool with `after` runs once the tools it names in the same step have settled.',
868
+ 'A write tool (`export_report`) that `taintAfterRemoteRead` refuses once a page has been read, and a tool the page answers (`check_device`).',
869
+ 'One custom detector, `research.retraction`, and a prompt line for each `reader` through a `when` line.',
623
870
  '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
871
  '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.',
872
+ '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
873
  'Turn behaviour with resume, auto-continue on length / stream_incomplete / provider_error, and steering.',
627
874
  ],
628
875
  question: RESEARCH_FIRST_TURN_PROMPT,
@@ -643,7 +890,7 @@ export const COOKBOOKS = {
643
890
  'A turn-time tool loader (`t2Loader: discover_tools`) that can pull in extra demo tools during the turn.',
644
891
  'Mixing HTTP tools (geocode, weather, currency, Wikipedia), MCP (`search_web`), and local function tools (distances, day plan, packing, budget).',
645
892
  '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.',
893
+ 'Reply-side detect set to block sensitive and injection phrasing. `allowedHosts` names the travel hosts, which exempts them from the private-address check.',
647
894
  ],
648
895
  createWorkspace: workspaceOf(createExampleDraft),
649
896
  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,19 @@ 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
+ /** One line of the prompt, with private sections wrapped as `{private: …}`. */
19
+ export interface SystemLineDraft {
20
+ key: string;
21
+ text: string;
22
+ }
18
23
  export interface IdentityDraft {
19
24
  agentId: string;
20
25
  profileType: StudioProfileType | '';
21
26
  handle: string;
22
- /** Private sections are wrapped as `{private: …}`. Unused on speech, which has no system channel. */
23
- 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;
27
+ /** Unused on speech, which has no system channel. */
28
+ system: SystemLineDraft[];
29
+ /** The facts each turn states, as a JSON object of lists of values; blank omits them. */
30
+ conditionsJson: string;
26
31
  }
27
32
  export interface ModelsDraft {
28
33
  /** Who holds the conversation a saved state continues; unset is the kernel's default, the host. */
@@ -176,10 +181,20 @@ export interface InputsDraft {
176
181
  /** The longest context package from each sender, in characters of JSON. */
177
182
  contextMaxChars: number | null;
178
183
  }
184
+ /** The reply shapes a slot's value picks; any other value takes the outputs' own schema. */
185
+ export interface SlotShapesDraft {
186
+ slot: string;
187
+ shapes: {
188
+ choice: string;
189
+ schemaId: string;
190
+ schemaJson: string;
191
+ }[];
192
+ }
179
193
  export interface OutputsDraft {
180
194
  mode: 'text' | 'structured';
181
195
  schemaId: string;
182
196
  schemaJson: string;
197
+ bySlot?: SlotShapesDraft;
183
198
  /** `''` omits it (kernel default: SSE). */
184
199
  streamMode: '' | StreamMode;
185
200
  streamThoughts: boolean;
@@ -404,7 +419,7 @@ export interface StudioDraft {
404
419
  decision: DecisionDraft;
405
420
  labels: LabelsDraft;
406
421
  }
407
- export declare function draftKey(prefix: 'agent' | 'model' | 'tool' | 'question' | 'criterion' | 'reference' | 'image' | 'slot' | 'choice'): string;
422
+ export declare function draftKey(prefix: 'agent' | 'line' | 'model' | 'tool' | 'question' | 'criterion' | 'reference' | 'image' | 'slot' | 'choice'): string;
408
423
  export declare function defaultModelBinding(partial?: Partial<ModelBindingDraft>): ModelBindingDraft;
409
424
  export declare function defaultToolSpec(partial?: Partial<ToolSpecDraft>): ToolSpecDraft;
410
425
  /**
@@ -438,6 +453,7 @@ export declare function newDecisionImage(draft: StudioDraft, file: string, image
438
453
  }): DecisionImageDraft;
439
454
  /** A new slot, with a name the draft doesn't use yet and two blank choices. */
440
455
  export declare function newSlot(slots: readonly SlotDraft[]): SlotDraft;
456
+ export declare function newSystemLine(text?: string): SystemLineDraft;
441
457
  export declare function newSlotChoice(): SlotChoiceDraft;
442
458
  /** One blank row: an option, a level, or a criterion. */
443
459
  export declare function newCriterion(): DecisionCriterionDraft;