@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.
- package/README.md +4 -1
- package/browser-connection.js +1 -1
- package/compile-workspace.js +26 -7
- package/compile.js +13 -2
- package/{example.d.ts → cookbooks/catalog.d.ts} +35 -5
- package/cookbooks/catalog.js +686 -0
- package/cookbooks/checks.d.ts +10 -0
- package/cookbooks/checks.js +93 -0
- package/cookbooks/exchanges.d.ts +11 -0
- package/cookbooks/exchanges.js +13 -0
- package/cookbooks/fixtures/research.trace.json +4455 -0
- package/cookbooks/mod.d.ts +8 -0
- package/cookbooks/mod.js +5 -0
- package/cookbooks/project.d.ts +66 -0
- package/cookbooks/project.js +195 -0
- package/cookbooks/providers.d.ts +165 -0
- package/cookbooks/providers.js +289 -0
- package/cookbooks/sources.d.ts +10 -0
- package/cookbooks/sources.js +125 -0
- package/cookbooks/tools.d.ts +23 -0
- package/{concierge-demo.js → cookbooks/tools.js} +428 -42
- package/map.js +3 -1
- package/mod.d.ts +3 -3
- package/mod.js +2 -3
- package/package.json +4 -4
- package/page/assets/{Banner-BhKnM-76.js → Banner-BwxDeFY1.js} +2 -2
- package/page/assets/{ConsoleFrame-CnGU8SiE.js → ConsoleFrame-Dewh6VXK.js} +1 -1
- package/page/assets/{ContextMenu-G2oYmfwG.js → ContextMenu-0p_1Utr-.js} +2 -2
- package/page/assets/{ToolResultCharts-DpaHoQFj.js → ToolResultCharts-ei_o_wTg.js} +1 -1
- package/page/assets/{TraceInspector-Bo0PzFVf.js → TraceInspector-DyQAWqOG.js} +1 -1
- package/page/assets/{TraceOverview-CM-sd2zM.js → TraceOverview-BawPHDUZ.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-DVbxNwnP.js → _virtual_studio-type-sources-C1mRXxbj.js} +29 -250
- package/page/assets/browser-engine-BBhaQ73h.js +11 -0
- package/page/assets/browser-transport-BMGb5bKR.js +47 -0
- package/page/assets/{compile-egress-BRGW9qfO.js → compile-egress-C3etX-3o.js} +1 -1
- package/page/assets/{crypto-BAY2nUlu.js → crypto-Dd6XxhqK.js} +1 -1
- package/page/assets/{encode-files-BSTfq_Gp.js → encode-files-CiyHxnUC.js} +1 -1
- package/page/assets/{export-agent-CtklkKZk.js → export-agent-CIOzkXW7.js} +2 -2
- package/page/assets/{guardrail-tester-BXROlU1L.js → guardrail-tester-Vn3HjOBN.js} +1 -1
- package/page/assets/host-patterns-F-KZIzkF.js +1 -0
- package/page/assets/{index-DbHspDC4.js → index-CQx3WisY.js} +120 -72
- package/page/assets/{live-ingress-qi-y5uvH.js → live-ingress-OuSlQ6q7.js} +1 -1
- package/page/assets/{live-messages-DIf_R-NT.js → live-messages-BNhCuiuF.js} +1 -1
- package/page/assets/reader-BT_YeHdq.js +7 -0
- package/page/assets/shaped-data-DYOBdvLJ.js +20 -0
- package/page/assets/{stub-4m0tKRlG.js → stub-DPcZtI0s.js} +78 -40
- package/page/assets/{studio-code-pane-Dt3MWPBE.js → studio-code-pane-CTaPxpwn.js} +3 -3
- package/page/assets/{studio-console-4PMBDYuu.js → studio-console-D2-0qGXG.js} +1 -1
- package/page/assets/{studio-decision-BiN_FO02.js → studio-decision-DjkIYfPm.js} +1 -1
- package/page/assets/{studio-embedding-C7gIUtxM.js → studio-embedding-IRaxgsCF.js} +1 -1
- package/page/assets/{studio-host-console-DOBHkxDj.js → studio-host-console-CpbWUasd.js} +2 -2
- package/page/assets/{studio-labels-Dh_rsQs7.js → studio-labels-7mSwqgwb.js} +1 -1
- package/page/assets/{studio-live-xPsQmJyQ.js → studio-live-DO8aNuBt.js} +1 -1
- package/page/assets/studio-map-GD9XCa23.js +1 -0
- package/page/assets/studio-trace-replay-Bx2YreVs.js +2 -0
- package/page/assets/{studio-type-checker-CHFs7A7H.js → studio-type-checker-B5DVxAZ0.js} +1 -1
- package/page/assets/tool-schema-CxLtS_Zt.js +17 -0
- package/page/assets/{trace-record-D9wgX8kq.js → trace-record-B2MF8flo.js} +1 -1
- package/page/assets/tree-Bi2FOU_h.js +3 -0
- package/page/assets/{turn-client-BWO4ocVM.js → turn-client-BCi5WnI6.js} +2 -2
- package/page/assets/types-s-3wFTyD.js +1 -0
- package/page/assets/{use-one-call-ApIuuZX3.js → use-one-call-OZH6wzzP.js} +1 -1
- package/page/assets/workspace-BiCkglEt.js +1 -0
- package/page/index.html +17 -17
- package/policy.js +1 -1
- package/registrations.d.ts +7 -1
- package/replay.d.ts +11 -0
- package/replay.js +67 -11
- package/runtime-scope.js +27 -3
- package/server/draft-decide.d.ts +1 -1
- package/source.js +2 -1
- package/stub.js +1 -1
- package/surface.js +6 -3
- package/tools.js +12 -6
- package/types.d.ts +2 -0
- package/ui/lib/studio-examples.d.ts +6 -31
- package/ui/lib/studio-examples.js +30 -15
- package/ui/lib/studio-open.d.ts +4 -1
- package/ui/lib/studio-open.js +6 -5
- package/ui/lib/tree-map-layout.js +9 -1
- package/ui/profile-editor.js +9 -8
- package/ui/studio-screen.js +30 -18
- package/workspace.js +8 -2
- package/concierge-demo.d.ts +0 -17
- package/example.js +0 -363
- package/page/assets/browser-engine-BJYQz5d_.js +0 -11
- package/page/assets/browser-transport-YKpXhacP.js +0 -47
- package/page/assets/host-patterns-cSf1U25G.js +0 -1
- package/page/assets/reader-BkaAkeh0.js +0 -7
- package/page/assets/shaped-data-C4jsvipW.js +0 -20
- package/page/assets/studio-map-Cc4_9fe9.js +0 -1
- package/page/assets/studio-trace-replay-D5JoQXyY.js +0 -2
- package/page/assets/tool-schema-DpbtSZtQ.js +0 -17
- package/page/assets/tree-0OoOeHfS.js +0 -3
- package/page/assets/types-BRZU5tBz.js +0 -1
- package/page/assets/workspace-DJBP4Adw.js +0 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider and model cookbooks: hosted builtin tool catalogs, provider-specific
|
|
3
|
+
* media/voice vocabularies, and model/protocol binding rules.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { TheoremError, } from '@theoremjs/agents';
|
|
8
|
+
/** The Gemini API's model list, which a connection check reads with a key. */
|
|
9
|
+
export const GEMINI_MODELS_URL = 'https://generativelanguage.googleapis.com/v1beta/models';
|
|
10
|
+
/** Gemini TTS voice names for `speech.voice` and `live.voice`. */
|
|
11
|
+
export const GOOGLE_SPEECH_VOICES = [
|
|
12
|
+
'Zephyr',
|
|
13
|
+
'Puck',
|
|
14
|
+
'Charon',
|
|
15
|
+
'Kore',
|
|
16
|
+
'Fenrir',
|
|
17
|
+
'Leda',
|
|
18
|
+
'Orus',
|
|
19
|
+
'Aoede',
|
|
20
|
+
'Callirrhoe',
|
|
21
|
+
'Autonoe',
|
|
22
|
+
'Enceladus',
|
|
23
|
+
'Iapetus',
|
|
24
|
+
'Umbriel',
|
|
25
|
+
'Algieba',
|
|
26
|
+
'Despina',
|
|
27
|
+
'Erinome',
|
|
28
|
+
'Algenib',
|
|
29
|
+
'Rasalgethi',
|
|
30
|
+
'Laomedeia',
|
|
31
|
+
'Achernar',
|
|
32
|
+
'Alnilam',
|
|
33
|
+
'Schedar',
|
|
34
|
+
'Gacrux',
|
|
35
|
+
'Pulcherrima',
|
|
36
|
+
'Achird',
|
|
37
|
+
'Zubenelgenubi',
|
|
38
|
+
'Vindemiatrix',
|
|
39
|
+
'Sadachbia',
|
|
40
|
+
'Sadaltager',
|
|
41
|
+
'Sulafat',
|
|
42
|
+
];
|
|
43
|
+
/** The thinking levels Gemini's `thinkingLevel` takes; OpenRouter models take them all. */
|
|
44
|
+
export const GOOGLE_THINKING_LEVELS = ['minimal', 'low', 'medium', 'high'];
|
|
45
|
+
/** The audio format Gemini speech returns (PCM, wrapped as WAV); OpenRouter speech also takes `mp3`. */
|
|
46
|
+
export const GOOGLE_SPEECH_FORMATS = ['pcm'];
|
|
47
|
+
/**
|
|
48
|
+
* A `geminiInteractions` or `geminiLive` binding's `efforts`, typed to the levels Gemini takes.
|
|
49
|
+
* The runtime check refuses an untyped host's level when the binding is built, not when a turn runs.
|
|
50
|
+
*/
|
|
51
|
+
export function googleEfforts(efforts) {
|
|
52
|
+
for (const [alias, level] of Object.entries(efforts)) {
|
|
53
|
+
if (!GOOGLE_THINKING_LEVELS.includes(level)) {
|
|
54
|
+
throw new TheoremError('config', `Effort '${alias}': Gemini does not take '${level}' (${GOOGLE_THINKING_LEVELS.join(', ')})`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return efforts;
|
|
58
|
+
}
|
|
59
|
+
/** The image MIME types a Gemini profile can take as input. */
|
|
60
|
+
export const GOOGLE_IMAGE_INPUT_MIMES = [
|
|
61
|
+
'image/png',
|
|
62
|
+
'image/jpeg',
|
|
63
|
+
'image/webp',
|
|
64
|
+
'image/heic',
|
|
65
|
+
'image/heif',
|
|
66
|
+
];
|
|
67
|
+
/** The audio MIME types a Gemini profile can take as voice input. */
|
|
68
|
+
export const GOOGLE_VOICE_INPUT_MIMES = [
|
|
69
|
+
'audio/webm',
|
|
70
|
+
'audio/wav',
|
|
71
|
+
'audio/mpeg',
|
|
72
|
+
'audio/mp4',
|
|
73
|
+
];
|
|
74
|
+
/**
|
|
75
|
+
* TTS models that reject any history with a model turn, so compaction's summary fails them
|
|
76
|
+
* (live, 29/09/2026).
|
|
77
|
+
*/
|
|
78
|
+
export const GOOGLE_SINGLE_TURN_API_IDS = [
|
|
79
|
+
'gemini-2.5-flash-preview-tts',
|
|
80
|
+
'gemini-3.1-flash-tts-preview',
|
|
81
|
+
'gemini-3.8-flash-tts',
|
|
82
|
+
'gemini-3.8-flash-lite-tts',
|
|
83
|
+
];
|
|
84
|
+
/**
|
|
85
|
+
* Models that reject any thinking setting, `summaries: false` included: leave
|
|
86
|
+
* `efforts` and `summaries` unset (live, 30/09/2026).
|
|
87
|
+
*/
|
|
88
|
+
export const GOOGLE_NO_THINKING_API_IDS = [
|
|
89
|
+
'gemini-2.5-flash-image',
|
|
90
|
+
'antigravity-preview-05-2026',
|
|
91
|
+
'antigravity-preview-09-2026',
|
|
92
|
+
'antigravity-preview-latest',
|
|
93
|
+
];
|
|
94
|
+
/**
|
|
95
|
+
* Models that refuse a thinking level and take `summaries`: leave `efforts` unset
|
|
96
|
+
* (live, 01/10/2026: Live closes 1007 "Thinking level is not supported for this model";
|
|
97
|
+
* 04/10/2026: setup takes `includeThoughts` either way).
|
|
98
|
+
*/
|
|
99
|
+
export const GOOGLE_NO_EFFORT_API_IDS = ['gemini-3.8-live'];
|
|
100
|
+
/**
|
|
101
|
+
* Models that refuse a session without a thinking level: pin `efforts`
|
|
102
|
+
* (live, 01/10/2026: Live closes 1007 "Thinking level must be specified for this model").
|
|
103
|
+
*/
|
|
104
|
+
export const GOOGLE_THINKING_REQUIRED_API_IDS = ['gemini-3.8-live-extended-thinking'];
|
|
105
|
+
const grounding = (googleSearch, googleMaps) => ({
|
|
106
|
+
googleSearch,
|
|
107
|
+
googleMaps,
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* Models with a non-zero free-tier quota, and the grounding each allows (AI Studio, Sep 2026).
|
|
111
|
+
* No model keeps free Maps quota: 3.5 Flash-Lite turns with Maps are refused as over quota
|
|
112
|
+
* (live, 13/10/2026).
|
|
113
|
+
* A builtin with no quota is refused as if over quota: on Live, a close 1011 "You exceeded your
|
|
114
|
+
* current quota" at setup, whatever the key's usage (live, 01/10/2026).
|
|
115
|
+
*/
|
|
116
|
+
export const GOOGLE_FREE_TIER_GROUNDING = {
|
|
117
|
+
'gemini-2.5-flash-lite': grounding(true, false),
|
|
118
|
+
'gemini-2.5-flash': grounding(true, false),
|
|
119
|
+
'gemini-2.5-flash-preview-tts': grounding(true, false),
|
|
120
|
+
'gemini-3-flash-preview': grounding(false, false),
|
|
121
|
+
'gemini-3.1-flash-lite': grounding(false, false),
|
|
122
|
+
'gemini-3.1-flash-lite-image': grounding(false, false),
|
|
123
|
+
'gemini-3.1-flash-tts-preview': grounding(false, false),
|
|
124
|
+
'gemini-3.5-flash-lite': grounding(false, false),
|
|
125
|
+
'gemini-3.5-flash': grounding(false, false),
|
|
126
|
+
'gemini-3.6-flash': grounding(false, false),
|
|
127
|
+
'gemini-3.7-flash': grounding(false, false),
|
|
128
|
+
'gemini-3.8-flash-tts': grounding(false, false),
|
|
129
|
+
'gemini-3.8-flash-lite-tts': grounding(false, false),
|
|
130
|
+
'gemma-4-26b-a4b-it': grounding(false, false),
|
|
131
|
+
'gemma-4-31b-it': grounding(false, false),
|
|
132
|
+
'gemini-3.1-flash-live-preview': grounding(false, false),
|
|
133
|
+
'gemini-3.8-live': grounding(false, false),
|
|
134
|
+
'gemini-3.8-live-extended-thinking': grounding(false, false),
|
|
135
|
+
};
|
|
136
|
+
/** Grounding builtins the free tier allows on `apiId`; none for a model with no free quota. */
|
|
137
|
+
export function googleFreeTierBuiltins(apiId) {
|
|
138
|
+
const allowed = GOOGLE_FREE_TIER_GROUNDING[apiId.trim()];
|
|
139
|
+
if (!allowed)
|
|
140
|
+
return [];
|
|
141
|
+
return ['googleSearch', 'googleMaps'].filter((id) => allowed[id]);
|
|
142
|
+
}
|
|
143
|
+
function pinsEffort(binding) {
|
|
144
|
+
return Object.keys(binding.efforts ?? {}).length > 0;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The first setting Google would refuse on this binding, or `undefined`. With `freeTier`, it
|
|
148
|
+
* also holds the binding to the free-tier table: a listed model, and only the grounding its
|
|
149
|
+
* quota allows.
|
|
150
|
+
*/
|
|
151
|
+
export function googleBindingViolation(binding, options = {}) {
|
|
152
|
+
const apiId = binding.apiId.trim();
|
|
153
|
+
const noThinking = GOOGLE_NO_THINKING_API_IDS;
|
|
154
|
+
const noEffort = GOOGLE_NO_EFFORT_API_IDS;
|
|
155
|
+
const thinkingRequired = GOOGLE_THINKING_REQUIRED_API_IDS;
|
|
156
|
+
if ((noThinking.includes(apiId) || noEffort.includes(apiId)) && pinsEffort(binding)) {
|
|
157
|
+
return {
|
|
158
|
+
field: 'efforts',
|
|
159
|
+
message: `${apiId} takes no thinking level; leave efforts unset.`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (noThinking.includes(apiId) && binding.summaries !== undefined) {
|
|
163
|
+
return {
|
|
164
|
+
field: 'summaries',
|
|
165
|
+
message: `${apiId} takes no thinking setting; leave summaries unset.`,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (thinkingRequired.includes(apiId) && !pinsEffort(binding)) {
|
|
169
|
+
return { field: 'efforts', message: `${apiId} needs a thinking level; pin efforts.` };
|
|
170
|
+
}
|
|
171
|
+
if (!options.freeTier)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (!GOOGLE_FREE_TIER_GROUNDING[apiId]) {
|
|
174
|
+
return { field: 'apiId', message: `${apiId} has no free-tier quota.` };
|
|
175
|
+
}
|
|
176
|
+
const allowed = googleFreeTierBuiltins(apiId);
|
|
177
|
+
for (const builtin of binding.builtInTools ?? []) {
|
|
178
|
+
if ((builtin === 'googleSearch' || builtin === 'googleMaps') && !allowed.includes(builtin)) {
|
|
179
|
+
return { field: 'builtInTools', message: `${apiId} has no free-tier quota for ${builtin}.` };
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
/** The aspect ratios a Gemini image model can return. */
|
|
185
|
+
export const GOOGLE_IMAGE_ASPECT_RATIOS = [
|
|
186
|
+
'1:1',
|
|
187
|
+
'3:2',
|
|
188
|
+
'2:3',
|
|
189
|
+
'3:4',
|
|
190
|
+
'4:3',
|
|
191
|
+
'4:5',
|
|
192
|
+
'5:4',
|
|
193
|
+
'9:16',
|
|
194
|
+
'16:9',
|
|
195
|
+
'21:9',
|
|
196
|
+
];
|
|
197
|
+
/** The resolutions a Gemini image model can return. */
|
|
198
|
+
export const GOOGLE_IMAGE_RESOLUTIONS = ['1K', '2K', '4K'];
|
|
199
|
+
/** What a Gemini image model can be asked to return. */
|
|
200
|
+
export const GOOGLE_IMAGE_OUTPUT_MIMES = ['image/png', 'image/jpeg'];
|
|
201
|
+
/** The tools Gemini runs itself, as `builtin` tool definitions. */
|
|
202
|
+
export const GOOGLE_BUILTIN_TOOLS = [
|
|
203
|
+
{
|
|
204
|
+
type: 'builtin',
|
|
205
|
+
name: 'googleSearch',
|
|
206
|
+
description: 'Google Search grounding',
|
|
207
|
+
category: 'grounding',
|
|
208
|
+
access: 'read-only',
|
|
209
|
+
paths: ['*'],
|
|
210
|
+
loadTier: 'T0',
|
|
211
|
+
permission: 'auto',
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
type: 'builtin',
|
|
215
|
+
name: 'googleMaps',
|
|
216
|
+
description: 'Google Maps grounding',
|
|
217
|
+
category: 'grounding',
|
|
218
|
+
access: 'read-only',
|
|
219
|
+
paths: ['*'],
|
|
220
|
+
loadTier: 'T0',
|
|
221
|
+
permission: 'auto',
|
|
222
|
+
// why: Google refuses a request that carries Maps with Search or URL context.
|
|
223
|
+
conflictsWith: ['googleSearch', 'urlContext'],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
type: 'builtin',
|
|
227
|
+
name: 'urlContext',
|
|
228
|
+
description: 'Fetch URL context',
|
|
229
|
+
category: 'grounding',
|
|
230
|
+
access: 'read-only',
|
|
231
|
+
paths: ['*'],
|
|
232
|
+
loadTier: 'T0',
|
|
233
|
+
permission: 'auto',
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
type: 'builtin',
|
|
237
|
+
name: 'codeExecution',
|
|
238
|
+
description: 'Google code execution',
|
|
239
|
+
category: 'grounding',
|
|
240
|
+
access: 'read-only',
|
|
241
|
+
paths: ['*'],
|
|
242
|
+
loadTier: 'T0',
|
|
243
|
+
permission: 'auto',
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
/** `/images` takes image references only; a profile on it lists nothing wider in `inputs.attachments.accept`. */
|
|
247
|
+
export const OPENROUTER_IMAGES_INPUT_MIMES = ['image/*'];
|
|
248
|
+
/**
|
|
249
|
+
* What `/images` never sends the model: it reads the prompt text and the reference images
|
|
250
|
+
* only. The chat path (`image.includeText`) sends the system prompt and history.
|
|
251
|
+
*/
|
|
252
|
+
export const OPENROUTER_IMAGES_IGNORED_INPUTS = ['system', 'history'];
|
|
253
|
+
/** The tools OpenRouter runs itself, as `builtin` tool definitions. */
|
|
254
|
+
export const OPENROUTER_BUILTIN_TOOLS = [
|
|
255
|
+
{
|
|
256
|
+
type: 'builtin',
|
|
257
|
+
name: 'webSearch',
|
|
258
|
+
description: 'OpenRouter web search',
|
|
259
|
+
category: 'grounding',
|
|
260
|
+
access: 'read-only',
|
|
261
|
+
paths: ['*'],
|
|
262
|
+
loadTier: 'T0',
|
|
263
|
+
permission: 'auto',
|
|
264
|
+
},
|
|
265
|
+
];
|
|
266
|
+
/**
|
|
267
|
+
* Whether an Ollama model thinks, read from the server's `POST /api/show` reply for it:
|
|
268
|
+
* `capabilities` lists `thinking` (Ollama 0.34.0, 04/10/2026). The host fetches the reply.
|
|
269
|
+
*/
|
|
270
|
+
export function ollamaModelThinks(show) {
|
|
271
|
+
if (!show || typeof show !== 'object')
|
|
272
|
+
return false;
|
|
273
|
+
const { capabilities } = show;
|
|
274
|
+
return Array.isArray(capabilities) && capabilities.includes('thinking');
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The first setting a local server would refuse on this binding, or `undefined`. A thinking
|
|
278
|
+
* level goes to the server as `reasoning_effort`; Ollama answers HTTP 400 "does not support
|
|
279
|
+
* thinking" for a model that does not think (04/10/2026).
|
|
280
|
+
*/
|
|
281
|
+
export function localBindingViolation(binding, model) {
|
|
282
|
+
if (!model.thinks && Object.keys(binding.efforts ?? {}).length > 0) {
|
|
283
|
+
return {
|
|
284
|
+
field: 'efforts',
|
|
285
|
+
message: `${binding.apiId.trim()} does not think; leave efforts unset.`,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable `sources` hooks for cookbook tools. Functions cannot cross JSON in
|
|
3
|
+
* `StudioRunPayload`, so `registerCustomTool` attaches the matching hook by
|
|
4
|
+
* tool name when the draft runs.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Source } from '@theoremjs/agents/kernel';
|
|
9
|
+
/** The cookbook `sources` hook for `name`, when that tool cites what it returns. */
|
|
10
|
+
export declare function cookbookToolSources(name: string): ((output: unknown) => Source[]) | undefined;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable `sources` hooks for cookbook tools. Functions cannot cross JSON in
|
|
3
|
+
* `StudioRunPayload`, so `registerCustomTool` attaches the matching hook by
|
|
4
|
+
* tool name when the draft runs.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
function isRecord(value) {
|
|
9
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function stringField(row, key) {
|
|
12
|
+
const value = row[key];
|
|
13
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
14
|
+
}
|
|
15
|
+
/** An http(s) citation. Other schemes never become a footer link. */
|
|
16
|
+
function web(title, uri) {
|
|
17
|
+
if (!URL.canParse(uri))
|
|
18
|
+
return undefined;
|
|
19
|
+
const url = new URL(uri);
|
|
20
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:')
|
|
21
|
+
return undefined;
|
|
22
|
+
const name = title.trim() || url.hostname.replace(/^www\./, '');
|
|
23
|
+
return { title: name, uri: url.href, type: 'web' };
|
|
24
|
+
}
|
|
25
|
+
function unique(sources) {
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
return sources.filter((source) => {
|
|
28
|
+
if (seen.has(source.uri))
|
|
29
|
+
return false;
|
|
30
|
+
seen.add(source.uri);
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** http(s) addresses in free text, including Markdown links. */
|
|
35
|
+
function urlsIn(text) {
|
|
36
|
+
const markdown = [...text.matchAll(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g)];
|
|
37
|
+
const fromLinks = markdown.flatMap((match) => web(match[1] ?? '', match[2] ?? '') ?? []);
|
|
38
|
+
const bare = [...text.matchAll(/https?:\/\/[^\s"'<>\]]+/g)];
|
|
39
|
+
const fromBare = bare.flatMap((match) => {
|
|
40
|
+
const uri = (match[0] ?? '').replace(/[),.;:]+$/, '');
|
|
41
|
+
return web(uri, uri) ?? [];
|
|
42
|
+
});
|
|
43
|
+
return unique([...fromLinks, ...fromBare]);
|
|
44
|
+
}
|
|
45
|
+
function asRows(output) {
|
|
46
|
+
if (Array.isArray(output))
|
|
47
|
+
return output;
|
|
48
|
+
if (!isRecord(output))
|
|
49
|
+
return [];
|
|
50
|
+
for (const key of ['items', 'results', 'search_results', 'models', 'datasets']) {
|
|
51
|
+
const value = output[key];
|
|
52
|
+
if (Array.isArray(value))
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
function fromRows(rows, sourceOf) {
|
|
58
|
+
return unique(rows.flatMap((row) => (isRecord(row) ? (sourceOf(row) ?? []) : [])));
|
|
59
|
+
}
|
|
60
|
+
function hfHub(output, kind) {
|
|
61
|
+
const prefix = kind === 'dataset' ? 'https://huggingface.co/datasets/' : 'https://huggingface.co/';
|
|
62
|
+
return fromRows(asRows(output), (row) => {
|
|
63
|
+
const id = stringField(row, 'id') ?? stringField(row, 'modelId');
|
|
64
|
+
return id ? web(id, `${prefix}${id}`) : undefined;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function githubSearch(output) {
|
|
68
|
+
return fromRows(asRows(output), (row) => {
|
|
69
|
+
const uri = stringField(row, 'html_url');
|
|
70
|
+
const title = stringField(row, 'full_name') ?? stringField(row, 'name');
|
|
71
|
+
return uri ? web(title ?? uri, uri) : undefined;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function stripXml(text) {
|
|
75
|
+
return text
|
|
76
|
+
.replace(/<[^>]+>/g, '')
|
|
77
|
+
.replace(/\s+/g, ' ')
|
|
78
|
+
.trim();
|
|
79
|
+
}
|
|
80
|
+
function arxivFeed(output) {
|
|
81
|
+
if (typeof output !== 'string')
|
|
82
|
+
return urlsIn(JSON.stringify(output));
|
|
83
|
+
const entries = [...output.matchAll(/<entry\b[\s\S]*?<\/entry>/g)];
|
|
84
|
+
if (entries.length === 0)
|
|
85
|
+
return urlsIn(output);
|
|
86
|
+
return unique(entries.flatMap((entry) => {
|
|
87
|
+
const id = /<id>(https?:\/\/[^<]+)<\/id>/.exec(entry[0] ?? '')?.[1];
|
|
88
|
+
const title = /<title>([\s\S]*?)<\/title>/.exec(entry[0] ?? '')?.[1];
|
|
89
|
+
return id ? (web(stripXml(title ?? id), id) ?? []) : [];
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
function fromUnknown(output) {
|
|
93
|
+
if (typeof output === 'string')
|
|
94
|
+
return urlsIn(output);
|
|
95
|
+
if (Array.isArray(output) || isRecord(output)) {
|
|
96
|
+
const rows = fromRows(asRows(output), (row) => {
|
|
97
|
+
const uri = stringField(row, 'html_url') ??
|
|
98
|
+
stringField(row, 'url') ??
|
|
99
|
+
stringField(row, 'source_url') ??
|
|
100
|
+
stringField(row, 'contentUrl');
|
|
101
|
+
const title = stringField(row, 'title') ?? stringField(row, 'name') ?? uri;
|
|
102
|
+
return uri ? web(title ?? uri, uri) : undefined;
|
|
103
|
+
});
|
|
104
|
+
return rows.length > 0 ? rows : urlsIn(JSON.stringify(output));
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const COOKBOOK_TOOL_SOURCES = {
|
|
109
|
+
search_models: (output) => hfHub(output, 'model'),
|
|
110
|
+
search_datasets: (output) => hfHub(output, 'dataset'),
|
|
111
|
+
search_github: githubSearch,
|
|
112
|
+
list_arxiv: arxivFeed,
|
|
113
|
+
search_web: fromUnknown,
|
|
114
|
+
read_pages: fromUnknown,
|
|
115
|
+
read_model_card: fromUnknown,
|
|
116
|
+
read_dataset_card: fromUnknown,
|
|
117
|
+
read_readme: fromUnknown,
|
|
118
|
+
find_library: fromUnknown,
|
|
119
|
+
read_library_docs: fromUnknown,
|
|
120
|
+
ask_repo_docs: fromUnknown,
|
|
121
|
+
};
|
|
122
|
+
/** The cookbook `sources` hook for `name`, when that tool cites what it returns. */
|
|
123
|
+
export function cookbookToolSources(name) {
|
|
124
|
+
return COOKBOOK_TOOL_SOURCES[name];
|
|
125
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StudioToolHandlers } from '../tools.ts';
|
|
2
|
+
import type { StudioInputsSpec, StudioToolSeed } from '../types.ts';
|
|
3
|
+
export declare const DISCOVER_LOADED: readonly ["get_cat_fact", "tell_joke", "get_advice", "random_dog_image"];
|
|
4
|
+
/** Sample inputs for HTTP and MCP cookbook tools (connection tests and smoke scripts). */
|
|
5
|
+
export declare const DEMO_HTTP_SAMPLE_INPUT: Record<string, Record<string, unknown>>;
|
|
6
|
+
export declare function demoHttpSampleInput(toolName: string): Record<string, unknown> | undefined;
|
|
7
|
+
/** Comma-separated hosts for guardrails.network.allowedHosts across the cookbook graphs. */
|
|
8
|
+
export declare const DEMO_ALLOWED_HOSTS = "nominatim.openstreetmap.org, geocoding-api.open-meteo.com, api.open-meteo.com, api.frankfurter.dev, api.sunrise-sunset.org, api.zippopotam.us, en.wikipedia.org, archive.org, pokeapi.co, dog.ceo, api.adviceslip.com, catfact.ninja, official-joke-api.appspot.com, mcp.deepwiki.com, mcp.context7.com, learn.microsoft.com, docs.mcp.cloudflare.com, knowledge-mcp.global.api.aws, huggingface.co, mcp.docs.astro.build, mcp.exa.ai, raw.githubusercontent.com, registry.npmjs.org, export.arxiv.org, api.github.com";
|
|
9
|
+
export declare const RESEARCH_ALLOWED_HOSTS = "mcp.exa.ai, export.arxiv.org, huggingface.co, api.github.com, raw.githubusercontent.com, mcp.context7.com, mcp.deepwiki.com";
|
|
10
|
+
export declare function demoInputsSpec(): StudioInputsSpec;
|
|
11
|
+
/** The tools the research scout allows: web, papers, models, datasets, repos, and library docs. */
|
|
12
|
+
export declare const DEMO_RESEARCH_TOOLS: readonly string[];
|
|
13
|
+
/** The research tools whose output is a full page or card that `research.pagereader` filters at `post_tool`. */
|
|
14
|
+
export declare const DEMO_RESEARCH_STAGE_READ_TOOLS: readonly string[];
|
|
15
|
+
/** The tools the travel concierge allows: places, weather, money, trip helpers, and research. */
|
|
16
|
+
export declare const DEMO_CONCIERGE_TOOLS: readonly string[];
|
|
17
|
+
/** The tools the code architect allows: docs, repositories, packages, and research. */
|
|
18
|
+
export declare const DEMO_ARCHITECT_TOOLS: readonly string[];
|
|
19
|
+
/** The tools the tool console serves: one of each kind of result, and the two no agent allows. */
|
|
20
|
+
export declare const DEMO_CONSOLE_TOOLS: readonly string[];
|
|
21
|
+
export declare function demoToolSpecs(): StudioToolSeed[];
|
|
22
|
+
/** Portable handlers for the cookbook function tools, shared by Studio and the website. */
|
|
23
|
+
export declare const COOKBOOK_TOOL_HANDLERS: StudioToolHandlers;
|