@theoremjs/studio 0.3.4-next.528.g44c76f9 → 0.3.4-next.540.g67b727f

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 (96) hide show
  1. package/README.md +4 -1
  2. package/browser-connection.js +1 -1
  3. package/compile-workspace.js +26 -7
  4. package/compile.js +13 -2
  5. package/{example.d.ts → cookbooks/catalog.d.ts} +35 -5
  6. package/cookbooks/catalog.js +686 -0
  7. package/cookbooks/checks.d.ts +10 -0
  8. package/cookbooks/checks.js +93 -0
  9. package/cookbooks/exchanges.d.ts +11 -0
  10. package/cookbooks/exchanges.js +13 -0
  11. package/cookbooks/fixtures/research.trace.json +4455 -0
  12. package/cookbooks/mod.d.ts +8 -0
  13. package/cookbooks/mod.js +5 -0
  14. package/cookbooks/project.d.ts +66 -0
  15. package/cookbooks/project.js +195 -0
  16. package/cookbooks/providers.d.ts +165 -0
  17. package/cookbooks/providers.js +289 -0
  18. package/cookbooks/sources.d.ts +10 -0
  19. package/cookbooks/sources.js +125 -0
  20. package/cookbooks/tools.d.ts +23 -0
  21. package/{concierge-demo.js → cookbooks/tools.js} +428 -42
  22. package/map.js +3 -1
  23. package/mod.d.ts +3 -3
  24. package/mod.js +2 -3
  25. package/package.json +4 -4
  26. package/page/assets/{Banner-BhKnM-76.js → Banner-BwxDeFY1.js} +2 -2
  27. package/page/assets/{ConsoleFrame-CnGU8SiE.js → ConsoleFrame-Dewh6VXK.js} +1 -1
  28. package/page/assets/{ContextMenu-G2oYmfwG.js → ContextMenu-0p_1Utr-.js} +2 -2
  29. package/page/assets/{ToolResultCharts-DpaHoQFj.js → ToolResultCharts-ei_o_wTg.js} +1 -1
  30. package/page/assets/{TraceInspector-Bo0PzFVf.js → TraceInspector-DyQAWqOG.js} +1 -1
  31. package/page/assets/{TraceOverview-CM-sd2zM.js → TraceOverview-BawPHDUZ.js} +1 -1
  32. package/page/assets/{_virtual_studio-type-sources-DVbxNwnP.js → _virtual_studio-type-sources-C1mRXxbj.js} +29 -250
  33. package/page/assets/browser-engine-BBhaQ73h.js +11 -0
  34. package/page/assets/browser-transport-BMGb5bKR.js +47 -0
  35. package/page/assets/{compile-egress-BRGW9qfO.js → compile-egress-C3etX-3o.js} +1 -1
  36. package/page/assets/{crypto-BAY2nUlu.js → crypto-Dd6XxhqK.js} +1 -1
  37. package/page/assets/{encode-files-BSTfq_Gp.js → encode-files-CiyHxnUC.js} +1 -1
  38. package/page/assets/{export-agent-CtklkKZk.js → export-agent-CIOzkXW7.js} +2 -2
  39. package/page/assets/{guardrail-tester-BXROlU1L.js → guardrail-tester-Vn3HjOBN.js} +1 -1
  40. package/page/assets/host-patterns-F-KZIzkF.js +1 -0
  41. package/page/assets/{index-DbHspDC4.js → index-CQx3WisY.js} +120 -72
  42. package/page/assets/{live-ingress-qi-y5uvH.js → live-ingress-OuSlQ6q7.js} +1 -1
  43. package/page/assets/{live-messages-DIf_R-NT.js → live-messages-BNhCuiuF.js} +1 -1
  44. package/page/assets/reader-BT_YeHdq.js +7 -0
  45. package/page/assets/shaped-data-DYOBdvLJ.js +20 -0
  46. package/page/assets/{stub-4m0tKRlG.js → stub-DPcZtI0s.js} +78 -40
  47. package/page/assets/{studio-code-pane-Dt3MWPBE.js → studio-code-pane-CTaPxpwn.js} +3 -3
  48. package/page/assets/{studio-console-4PMBDYuu.js → studio-console-D2-0qGXG.js} +1 -1
  49. package/page/assets/{studio-decision-BiN_FO02.js → studio-decision-DjkIYfPm.js} +1 -1
  50. package/page/assets/{studio-embedding-C7gIUtxM.js → studio-embedding-IRaxgsCF.js} +1 -1
  51. package/page/assets/{studio-host-console-DOBHkxDj.js → studio-host-console-CpbWUasd.js} +2 -2
  52. package/page/assets/{studio-labels-Dh_rsQs7.js → studio-labels-7mSwqgwb.js} +1 -1
  53. package/page/assets/{studio-live-xPsQmJyQ.js → studio-live-DO8aNuBt.js} +1 -1
  54. package/page/assets/studio-map-GD9XCa23.js +1 -0
  55. package/page/assets/studio-trace-replay-Bx2YreVs.js +2 -0
  56. package/page/assets/{studio-type-checker-CHFs7A7H.js → studio-type-checker-B5DVxAZ0.js} +1 -1
  57. package/page/assets/tool-schema-CxLtS_Zt.js +17 -0
  58. package/page/assets/{trace-record-D9wgX8kq.js → trace-record-B2MF8flo.js} +1 -1
  59. package/page/assets/tree-Bi2FOU_h.js +3 -0
  60. package/page/assets/{turn-client-BWO4ocVM.js → turn-client-BCi5WnI6.js} +2 -2
  61. package/page/assets/types-s-3wFTyD.js +1 -0
  62. package/page/assets/{use-one-call-ApIuuZX3.js → use-one-call-OZH6wzzP.js} +1 -1
  63. package/page/assets/workspace-BiCkglEt.js +1 -0
  64. package/page/index.html +17 -17
  65. package/policy.js +1 -1
  66. package/registrations.d.ts +7 -1
  67. package/replay.d.ts +11 -0
  68. package/replay.js +67 -11
  69. package/runtime-scope.js +27 -3
  70. package/server/draft-decide.d.ts +1 -1
  71. package/source.js +2 -1
  72. package/stub.js +1 -1
  73. package/surface.js +6 -3
  74. package/tools.js +12 -6
  75. package/types.d.ts +2 -0
  76. package/ui/lib/studio-examples.d.ts +6 -31
  77. package/ui/lib/studio-examples.js +30 -15
  78. package/ui/lib/studio-open.d.ts +4 -1
  79. package/ui/lib/studio-open.js +6 -5
  80. package/ui/lib/tree-map-layout.js +9 -1
  81. package/ui/profile-editor.js +9 -8
  82. package/ui/studio-screen.js +30 -18
  83. package/workspace.js +8 -2
  84. package/concierge-demo.d.ts +0 -17
  85. package/example.js +0 -363
  86. package/page/assets/browser-engine-BJYQz5d_.js +0 -11
  87. package/page/assets/browser-transport-YKpXhacP.js +0 -47
  88. package/page/assets/host-patterns-cSf1U25G.js +0 -1
  89. package/page/assets/reader-BkaAkeh0.js +0 -7
  90. package/page/assets/shaped-data-C4jsvipW.js +0 -20
  91. package/page/assets/studio-map-Cc4_9fe9.js +0 -1
  92. package/page/assets/studio-trace-replay-D5JoQXyY.js +0 -2
  93. package/page/assets/tool-schema-DpbtSZtQ.js +0 -17
  94. package/page/assets/tree-0OoOeHfS.js +0 -3
  95. package/page/assets/types-BRZU5tBz.js +0 -1
  96. package/page/assets/workspace-DJBP4Adw.js +0 -1
package/example.js DELETED
@@ -1,363 +0,0 @@
1
- import { embeddingModelLimits } from '@theoremjs/agents';
2
- import { DETECTOR_BOUNDARIES, DETECTORS } from '@theoremjs/agents/guardrails';
3
- import { DEMO_ALLOWED_HOSTS, DEMO_ARCHITECT_SYSTEM, DEMO_ARCHITECT_TOOLS, DEMO_CONCIERGE_SYSTEM, DEMO_CONCIERGE_TOOLS, DEMO_CONSOLE_TOOLS, DEMO_LIVE_CONCIERGE_SYSTEM, demoInputsSpec, demoToolSpecs, } from "./concierge-demo.js";
4
- import { createBlankDraft, defaultModelBinding, defaultToolSpec, draftKey, freeName, includableFacets, includeFacet, setProfileType, } from "./draft.js";
5
- import { firstServed } from "./policy.js";
6
- import { addAgent, agentNodeId, markAgentStart, workspaceFromDraft, } from "./workspace.js";
7
- /**
8
- * Where each example's models start: Google's Flash models and TypeSafe's Jev, which free keys
9
- * run. The examples list no models, so a type switch keeps whatever the kernel says serves the
10
- * new type.
11
- */
12
- const EXAMPLE_PICKS = {
13
- models: () => [],
14
- start: (type) => {
15
- switch (type) {
16
- case 'decision':
17
- return { ...firstServed('typesafe', type), apiId: 'jev-latest' };
18
- case 'live':
19
- return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-live-preview' };
20
- case 'speech':
21
- return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-tts-preview' };
22
- case 'image':
23
- return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-lite-image' };
24
- case 'text':
25
- return { ...firstServed('gemini', type), apiId: 'gemini-3.1-flash-lite' };
26
- case 'embedding':
27
- return { ...firstServed('gemini', type), apiId: 'gemini-embedding-2-preview' };
28
- }
29
- },
30
- };
31
- /** The agent id the decision example opens under; its run starts with the pantry's state and pictures. */
32
- export const DECISION_EXAMPLE_AGENT_ID = 'pantry.jev';
33
- /** What the decision example's questions are asked about: the shelf, and why we ask. */
34
- export const DECISION_EXAMPLE_STATE = JSON.stringify({
35
- photo: '<pantry_shelf>',
36
- note: 'Friends are coming round for brunch.',
37
- }, null, 2);
38
- /** The example's pictures, which load only when the example is made: they are most of its weight. */
39
- const exampleImages = async () => (await import("./decision-example-images.js")).DECISION_EXAMPLE_IMAGES;
40
- /** The picture the decision example's state starts with, by the reference it writes: the shelf. */
41
- export async function decisionExampleAssets() {
42
- const { '<pantry_shelf>': shelf } = await exampleImages();
43
- return { '<pantry_shelf>': shelf };
44
- }
45
- /** The example's own pictures, sent with every decision: the ginger, the colour chart and the flag its questions name. */
46
- async function decisionImages() {
47
- const { '<pantry_shelf>': _shelf, ...fixed } = await exampleImages();
48
- return Object.entries(fixed).map(([reference, image]) => ({
49
- key: draftKey('image'),
50
- name: reference.slice(1, -1),
51
- ...image,
52
- }));
53
- }
54
- function exampleQuestion(id, type, instructions, options = []) {
55
- return {
56
- key: draftKey('question'),
57
- id,
58
- type,
59
- instructions,
60
- criteria: options.map(([label, text]) => ({ key: draftKey('criterion'), label, text })),
61
- };
62
- }
63
- /**
64
- * A look at a pantry shelf on TypeSafe's Jev 1.14: boxes around what it finds, a colour chart and
65
- * a flag to match against, and plain questions about what is there. The draft a blank agent becomes
66
- * when its type is set to decision, with every section that type brings, and the pictures ship with
67
- * it, so it runs as it opens.
68
- */
69
- export async function createDecisionExampleDraft() {
70
- return decisionExampleDraft(await decisionImages());
71
- }
72
- /** The decision example with the pictures given: none for a page that only shows its shape. */
73
- export function decisionExampleDraft(images = []) {
74
- const blank = createBlankDraft();
75
- const had = new Set(includableFacets(blank));
76
- const decision = setProfileType(blank, 'decision', EXAMPLE_PICKS);
77
- const draft = includableFacets(decision)
78
- .filter((facet) => !had.has(facet))
79
- .reduce(includeFacet, decision);
80
- const binding = draft.modelBindings[0];
81
- return {
82
- ...draft,
83
- identity: { ...draft.identity, agentId: DECISION_EXAMPLE_AGENT_ID, handle: 'jev' },
84
- modelBindings: binding ? [{ ...binding, apiId: 'jev-1.14.0', options: { images: true } }] : [],
85
- decision: {
86
- ...draft.decision,
87
- contract: 'pantry.v1',
88
- questions: [
89
- { ...exampleQuestion('Ginger', 'box', 'Where is <ginger> in `photo`?'), image: 'photo' },
90
- exampleQuestion('Something to drink', 'noul', "There's something to drink in `photo`."),
91
- exampleQuestion('Fruit salad', 'noul', 'Do we have what we need for a fruit salad?'),
92
- {
93
- ...exampleQuestion('Where the green apple lands on the chart', 'box', 'Where on <apple_ripeness> would the green apple in `photo` sit?'),
94
- image: '<apple_ripeness>',
95
- },
96
- exampleQuestion('Bread on the shelf', 'noul', 'Does the shelf have bread?'),
97
- {
98
- ...exampleQuestion('Union Jack', 'box', 'Which jar in `photo` matches <union_jack>?'),
99
- image: 'photo',
100
- },
101
- exampleQuestion('Brunch', 'choice', 'What can we make for brunch from `photo`?', [
102
- ['toast', 'Toast with a spread.'],
103
- ['fruit', 'A bowl of fruit.'],
104
- ['shop', 'Nothing yet. Someone goes to the shop.'],
105
- ]),
106
- ],
107
- images,
108
- },
109
- };
110
- }
111
- /** A tool-call safety decision using the free Span model and its Number question shape. */
112
- export function createSpanExampleDraft() {
113
- const draft = setProfileType(createBlankDraft(), 'decision', EXAMPLE_PICKS);
114
- return {
115
- ...draft,
116
- identity: { ...draft.identity, agentId: 'guardrails.tool_call.span', handle: 'span' },
117
- modelBindings: [
118
- {
119
- ...draft.modelBindings[0],
120
- ...firstServed('openrouter', 'decision'),
121
- apiId: 'respan/span-01-lite:free',
122
- },
123
- ],
124
- decision: {
125
- ...draft.decision,
126
- questions: [
127
- {
128
- key: draftKey('question'),
129
- id: 'verdict',
130
- type: 'noul',
131
- instructions: 'Is this tool call unsafe or beyond what the user asked for?',
132
- criteria: [
133
- {
134
- key: draftKey('criterion'),
135
- label: 'true',
136
- text: 'The call is unsafe or beyond the user request.',
137
- },
138
- {
139
- key: draftKey('criterion'),
140
- label: 'false',
141
- text: 'The call is safe and within the user request.',
142
- },
143
- ],
144
- },
145
- ],
146
- },
147
- };
148
- }
149
- const GEMINI_EMBEDDING = {
150
- protocol: firstServed('gemini', 'embedding').protocol,
151
- apiId: 'gemini-embedding-2-preview',
152
- };
153
- /** A multimodal embedding profile using Gemini Embeddings 2's free preview model, taking every file type it does. */
154
- export function createGeminiEmbeddingExampleDraft() {
155
- const draft = setProfileType(createBlankDraft(), 'embedding', EXAMPLE_PICKS);
156
- const binding = draft.modelBindings[0];
157
- return {
158
- ...draft,
159
- identity: {
160
- ...draft.identity,
161
- agentId: 'studio.gemini-embeddings-2',
162
- handle: 'embeddings',
163
- },
164
- models: {
165
- ...draft.models,
166
- defaultModel: binding?.modelId ?? '',
167
- key: 'gemini',
168
- },
169
- modelBindings: binding
170
- ? [
171
- {
172
- ...binding,
173
- provider: 'gemini',
174
- protocol: GEMINI_EMBEDDING.protocol,
175
- apiId: GEMINI_EMBEDDING.apiId,
176
- options: { outputDimensionality: 768 },
177
- },
178
- ]
179
- : [],
180
- inputs: {
181
- ...draft.inputs,
182
- text: true,
183
- attachmentsAccept: (embeddingModelLimits(GEMINI_EMBEDDING)?.media ?? []).flatMap((kind) => [
184
- ...kind.accept,
185
- ]),
186
- // why: the most media Gemini Embedding 2 takes in one input is 6 images.
187
- maxFiles: 6,
188
- maxBytes: 10_000_000,
189
- maxTurnBytes: 10_000_000,
190
- },
191
- };
192
- }
193
- /**
194
- * The example's `detect`: a reply that carries sensitive data or injection phrasing is blocked.
195
- * Network addresses are left alone, since a reply cites them, and so are tool names, since a
196
- * reply repeats one the visitor asks about.
197
- */
198
- function exampleDetect(detect) {
199
- const next = structuredClone(detect);
200
- for (const detector of DETECTORS) {
201
- if (detector === 'network' || detector === 'tool_leak')
202
- continue;
203
- for (const boundary of ['reply', 'reply_structured', 'live_reply']) {
204
- if (DETECTOR_BOUNDARIES[detector].includes(boundary))
205
- next[detector][boundary] = 'block';
206
- }
207
- }
208
- return next;
209
- }
210
- /** The demo tools named, in the library's order. */
211
- function exampleTools(names) {
212
- const wanted = new Set(names);
213
- return demoToolSpecs()
214
- .filter((seed) => wanted.has(seed.data.toolName ?? ''))
215
- .map((seed) => defaultToolSpec(seed.data));
216
- }
217
- /** A text agent on the studio's models, with the example's inputs and guardrails. */
218
- function exampleTextDraft(identity, tools) {
219
- const blank = createBlankDraft();
220
- const inputs = demoInputsSpec();
221
- return {
222
- ...blank,
223
- identity: { ...identity, profileType: 'text', systemByRoleJson: '' },
224
- included: ['outputs', 'turnBehaviour', 'guardrails', 'observability', 'labels'],
225
- models: { defaultModel: 'smart', allowModelSelect: true, maxSteps: 12, key: 'gemini' },
226
- modelBindings: [
227
- defaultModelBinding({
228
- modelId: 'fast',
229
- ...firstServed('gemini', 'text'),
230
- apiId: 'gemini-3.1-flash-lite',
231
- efforts: [
232
- { alias: 'fast', level: 'minimal' },
233
- { alias: 'deep', level: 'high' },
234
- ],
235
- defaultEffort: 'fast',
236
- allowEffortSelect: true,
237
- summaries: true,
238
- }),
239
- defaultModelBinding({
240
- modelId: 'smart',
241
- ...firstServed('gemini', 'text'),
242
- apiId: 'gemini-3.5-flash-lite',
243
- efforts: [
244
- { alias: 'normal', level: 'low' },
245
- { alias: 'deep', level: 'high' },
246
- ],
247
- defaultEffort: 'normal',
248
- allowEffortSelect: true,
249
- summaries: true,
250
- }),
251
- defaultModelBinding({
252
- modelId: 'open',
253
- ...firstServed('openrouter', 'text'),
254
- apiId: 'openrouter/free',
255
- efforts: [{ alias: 'default', level: 'minimal' }],
256
- defaultEffort: 'default',
257
- // Its own slot: a slot two providers share can hold neither's key.
258
- keySlot: 'openrouter',
259
- }),
260
- ],
261
- ...tools,
262
- inputs: {
263
- text: inputs.text,
264
- attachmentsAccept: [...inputs.attachmentsAccept],
265
- voiceAccept: [...inputs.voiceAccept],
266
- maxFiles: inputs.maxFiles,
267
- maxBytes: inputs.maxBytes,
268
- maxTurnBytes: inputs.maxTurnBytes,
269
- limitsByMimeJson: '',
270
- slotsJson: '',
271
- contextFrom: [],
272
- contextMaxChars: null,
273
- },
274
- guardrails: {
275
- ...blank.guardrails,
276
- detect: exampleDetect(blank.guardrails.detect),
277
- blockedReplyOnBlock: 'refuse',
278
- allowedHosts: DEMO_ALLOWED_HOSTS.split(',').map((host) => host.trim()),
279
- },
280
- };
281
- }
282
- /** A fresh copy of the travel concierge draft: a text agent with the tools a trip needs. */
283
- export function createExampleDraft() {
284
- return exampleTextDraft({ agentId: 'travel.concierge', handle: 'concierge', system: DEMO_CONCIERGE_SYSTEM }, {
285
- tools: { t2Loader: 'discover_tools', parallel: false },
286
- toolSpecs: exampleTools(DEMO_CONCIERGE_TOOLS),
287
- });
288
- }
289
- /** The travel concierge on a call: the same tools, a live model, and an instruction for speech. */
290
- export function createLiveExampleDraft() {
291
- const draft = setProfileType(createExampleDraft(), 'live', EXAMPLE_PICKS);
292
- return {
293
- ...draft,
294
- identity: {
295
- ...draft.identity,
296
- agentId: 'travel.concierge.live',
297
- system: DEMO_LIVE_CONCIERGE_SYSTEM,
298
- },
299
- };
300
- }
301
- /** A speech agent that reads a script aloud. */
302
- export function createNarratorExampleDraft() {
303
- const draft = includeFacet(setProfileType(createBlankDraft(), 'speech', EXAMPLE_PICKS), 'guardrails');
304
- return {
305
- ...draft,
306
- identity: { ...draft.identity, agentId: 'studio.narrator', handle: 'narrator' },
307
- speech: {
308
- ...draft.speech,
309
- style: 'Warm and unhurried, like a podcast host talking to one listener.',
310
- },
311
- };
312
- }
313
- /** A host with no model: a few demo tools, one of each kind of result. */
314
- export function createConsoleExampleDraft() {
315
- const draft = setProfileType(createBlankDraft(), 'host');
316
- return {
317
- ...draft,
318
- identity: { ...draft.identity, agentId: 'tools.console' },
319
- toolSpecs: exampleTools(DEMO_CONSOLE_TOOLS),
320
- };
321
- }
322
- /** The code architect on its own: the code and docs tools, before the narrator joins it. */
323
- function architectDraft() {
324
- return exampleTextDraft({ agentId: 'code.architect', handle: 'architect', system: DEMO_ARCHITECT_SYSTEM }, { tools: { t2Loader: '', parallel: false }, toolSpecs: exampleTools(DEMO_ARCHITECT_TOOLS) });
325
- }
326
- /**
327
- * Adds the narrator after the workspace's last agent, the architect, and the `narrate` agent tool
328
- * that lets the architect call it. The architect is left selected.
329
- */
330
- function withNarrator(workspace) {
331
- const architect = workspace.agents.at(-1);
332
- const pair = addAgent(workspace, createNarratorExampleDraft());
333
- const narrator = pair.agents.at(-1);
334
- if (!architect || !narrator)
335
- return pair;
336
- const taken = pair.toolSpecs.map((tool) => tool.toolName);
337
- const narrate = defaultToolSpec({
338
- toolName: freeName('narrate', taken, (n) => `narrate_${n}`),
339
- toolType: 'agent',
340
- agentKey: narrator.key,
341
- description: 'Has the narrator read a script aloud and returns the audio.',
342
- activity: 'Recording the briefing',
343
- activityPast: 'Recorded the briefing',
344
- category: 'demo',
345
- });
346
- // The architect starts with `narrate` allowed, so a reset keeps the two linked.
347
- return markAgentStart({
348
- ...pair,
349
- agents: pair.agents.map((agent) => agent.key === architect.key
350
- ? { ...agent, tools: { ...agent.tools, allow: [...agent.tools.allow, narrate.key] } }
351
- : agent),
352
- toolSpecs: [...pair.toolSpecs, narrate],
353
- selected: agentNodeId(architect.key),
354
- }, architect.key);
355
- }
356
- /** The code architect and the narrator it calls, added to a workspace that keeps its other agents. */
357
- export function addArchitectExample(workspace) {
358
- return withNarrator(addAgent(workspace, architectDraft()));
359
- }
360
- /** A workspace of the code architect and its narrator, with the architect in the chat. */
361
- export function createArchitectWorkspace() {
362
- return withNarrator(workspaceFromDraft(architectDraft()));
363
- }