@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,8 @@
|
|
|
1
|
+
export type { CookbookEntry, CookbookId, } from './catalog.ts';
|
|
2
|
+
export { addArchitectExample, addResearchExample, COOKBOOK_IDS, COOKBOOKS, createArchitectWorkspace, createConsoleExampleDraft, createDecisionExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft, createPageReaderExampleDraft, createResearchScoutDraft, createResearchWorkspace, createSpanExampleDraft, DECISION_EXAMPLE_AGENT_ID, DECISION_EXAMPLE_STATE, DEMO_ARCHITECT_SYSTEM, DEMO_CONCIERGE_SYSTEM, DEMO_LIVE_CONCIERGE_SYSTEM, DEMO_RESEARCH_SYSTEM, decisionExampleAssets, decisionExampleDraft, exampleTools, RESEARCH_FIRST_TURN_PROMPT, RESEARCH_REPLY_SCHEMA_ID, RESEARCH_REPLY_SCHEMA_JSON, } from './catalog.ts';
|
|
3
|
+
export { cookbookOpening } from './exchanges.ts';
|
|
4
|
+
export type { ProfileSliceOptions, StitchRecipe, ToolSliceField, ToolSliceOptions, } from './project.ts';
|
|
5
|
+
export { projectProfileSlice, projectToolSlice, resolveCookbookSlice, stitchCookbook, } from './project.ts';
|
|
6
|
+
export type { GoogleBindingViolation, GoogleFreeTierGrounding, GoogleImageAspectRatio, GoogleImageInputMime, GoogleImageOutputMime, GoogleImagePins, GoogleImageResolution, GoogleLivePins, GoogleSpeechPins, GoogleSpeechVoice, GoogleThinkingLevel, GoogleVoiceInputMime, LocalBindingViolation, } from './providers.ts';
|
|
7
|
+
export { GEMINI_MODELS_URL, GOOGLE_BUILTIN_TOOLS, GOOGLE_FREE_TIER_GROUNDING, GOOGLE_IMAGE_ASPECT_RATIOS, GOOGLE_IMAGE_INPUT_MIMES, GOOGLE_IMAGE_OUTPUT_MIMES, GOOGLE_IMAGE_RESOLUTIONS, GOOGLE_NO_EFFORT_API_IDS, GOOGLE_NO_THINKING_API_IDS, GOOGLE_SINGLE_TURN_API_IDS, GOOGLE_SPEECH_FORMATS, GOOGLE_SPEECH_VOICES, GOOGLE_THINKING_LEVELS, GOOGLE_THINKING_REQUIRED_API_IDS, GOOGLE_VOICE_INPUT_MIMES, googleBindingViolation, googleEfforts, googleFreeTierBuiltins, localBindingViolation, OPENROUTER_BUILTIN_TOOLS, OPENROUTER_IMAGES_IGNORED_INPUTS, OPENROUTER_IMAGES_INPUT_MIMES, ollamaModelThinks, } from './providers.ts';
|
|
8
|
+
export { COOKBOOK_TOOL_HANDLERS, DEMO_ALLOWED_HOSTS, DEMO_ARCHITECT_TOOLS, DEMO_CONCIERGE_TOOLS, DEMO_CONSOLE_TOOLS, DEMO_HTTP_SAMPLE_INPUT, DEMO_RESEARCH_STAGE_READ_TOOLS, DEMO_RESEARCH_TOOLS, DISCOVER_LOADED, demoHttpSampleInput, demoInputsSpec, demoToolSpecs, RESEARCH_ALLOWED_HOSTS, } from './tools.ts';
|
package/cookbooks/mod.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { addArchitectExample, addResearchExample, COOKBOOK_IDS, COOKBOOKS, createArchitectWorkspace, createConsoleExampleDraft, createDecisionExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft, createPageReaderExampleDraft, createResearchScoutDraft, createResearchWorkspace, createSpanExampleDraft, DECISION_EXAMPLE_AGENT_ID, DECISION_EXAMPLE_STATE, DEMO_ARCHITECT_SYSTEM, DEMO_CONCIERGE_SYSTEM, DEMO_LIVE_CONCIERGE_SYSTEM, DEMO_RESEARCH_SYSTEM, decisionExampleAssets, decisionExampleDraft, exampleTools, RESEARCH_FIRST_TURN_PROMPT, RESEARCH_REPLY_SCHEMA_ID, RESEARCH_REPLY_SCHEMA_JSON, } from "./catalog.js";
|
|
2
|
+
export { cookbookOpening } from "./exchanges.js";
|
|
3
|
+
export { projectProfileSlice, projectToolSlice, resolveCookbookSlice, stitchCookbook, } from "./project.js";
|
|
4
|
+
export { GEMINI_MODELS_URL, GOOGLE_BUILTIN_TOOLS, GOOGLE_FREE_TIER_GROUNDING, GOOGLE_IMAGE_ASPECT_RATIOS, GOOGLE_IMAGE_INPUT_MIMES, GOOGLE_IMAGE_OUTPUT_MIMES, GOOGLE_IMAGE_RESOLUTIONS, GOOGLE_NO_EFFORT_API_IDS, GOOGLE_NO_THINKING_API_IDS, GOOGLE_SINGLE_TURN_API_IDS, GOOGLE_SPEECH_FORMATS, GOOGLE_SPEECH_VOICES, GOOGLE_THINKING_LEVELS, GOOGLE_THINKING_REQUIRED_API_IDS, GOOGLE_VOICE_INPUT_MIMES, googleBindingViolation, googleEfforts, googleFreeTierBuiltins, localBindingViolation, OPENROUTER_BUILTIN_TOOLS, OPENROUTER_IMAGES_IGNORED_INPUTS, OPENROUTER_IMAGES_INPUT_MIMES, ollamaModelThinks, } from "./providers.js";
|
|
5
|
+
export { COOKBOOK_TOOL_HANDLERS, DEMO_ALLOWED_HOSTS, DEMO_ARCHITECT_TOOLS, DEMO_CONCIERGE_TOOLS, DEMO_CONSOLE_TOOLS, DEMO_HTTP_SAMPLE_INPUT, DEMO_RESEARCH_STAGE_READ_TOOLS, DEMO_RESEARCH_TOOLS, DISCOVER_LOADED, demoHttpSampleInput, demoInputsSpec, demoToolSpecs, RESEARCH_ALLOWED_HOSTS, } from "./tools.js";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable Cookbook Projector: extracts and stitches profile facets, tool sub-objects,
|
|
3
|
+
* and multi-agent systems from the canonical `COOKBOOKS` store into clean TypeScript source.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type StudioWorkspace } from '../workspace.ts';
|
|
8
|
+
import { type CookbookId } from './catalog.ts';
|
|
9
|
+
export interface ProfileSliceOptions {
|
|
10
|
+
/** Profile top-level keys to keep (e.g. `['identity', 'inputs']`). Omit for the whole profile. */
|
|
11
|
+
pick?: readonly string[];
|
|
12
|
+
/** Override `tools.allow` to a focused list of tool names for the slice. */
|
|
13
|
+
toolsAllow?: readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* - `'fields'`: bare `key: value,` lines (for `ts frame=profile:<type>` fences).
|
|
16
|
+
* - `'defineProfile'`: `const profile = defineProfile({ ... });`.
|
|
17
|
+
* - `'module'`: full standalone module (`studioSource`).
|
|
18
|
+
*/
|
|
19
|
+
mode?: 'fields' | 'defineProfile' | 'module';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Projects a single profile (or a subset of its facets/fields) from a cookbook in `COOKBOOKS`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function projectProfileSlice(cookbookId: CookbookId, agentId?: string, options?: ProfileSliceOptions): string;
|
|
25
|
+
export type ToolSliceField = 'type' | 'name' | 'description' | 'category' | 'access' | 'permission' | 'loadTier' | 'paths' | 'endpoint' | 'method' | 'headers' | 'mapping' | 'serverUrl' | 'mcpToolName' | 'session' | 'auth' | 'maxResponseBytes' | 'labels' | 'profile' | 'maxCallsPerTurn' | 'answeredBy';
|
|
26
|
+
export interface ToolSliceOptions {
|
|
27
|
+
/** Sub-fields of the tool registration to project (e.g. `['auth']`, `['mapping', 'headers']`). */
|
|
28
|
+
pick?: readonly ToolSliceField[];
|
|
29
|
+
/**
|
|
30
|
+
* - `'fields'`: bare `key: value,` lines (for focused explanations of `auth`, `mapping`, `labels`, etc.).
|
|
31
|
+
* - `'registerTool'`: `registerTool({ ... });`.
|
|
32
|
+
*/
|
|
33
|
+
mode?: 'fields' | 'registerTool';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Projects a tool (or specific sub-objects of a tool, such as `auth`, `mapping`, `labels`) from `COOKBOOKS`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function projectToolSlice(cookbookId: CookbookId, toolName: string, options?: ToolSliceOptions): string;
|
|
39
|
+
export interface StitchRecipe {
|
|
40
|
+
agentId?: string;
|
|
41
|
+
/** Optional subset of tools to include on the stitched profile. */
|
|
42
|
+
toolsAllow?: readonly string[];
|
|
43
|
+
/** Optional prompt for a `runTurn` entrypoint function. */
|
|
44
|
+
runner?: {
|
|
45
|
+
exportName: string;
|
|
46
|
+
prompt: string;
|
|
47
|
+
keySlot?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Stitches a cookbook (or a focused tool/facet subset of it) into a complete runnable TypeScript program
|
|
52
|
+
* and a matching `StudioWorkspace` for opening in Studio.
|
|
53
|
+
*/
|
|
54
|
+
export declare function stitchCookbook(cookbookId: CookbookId, recipe?: StitchRecipe): {
|
|
55
|
+
code: string;
|
|
56
|
+
workspace: StudioWorkspace;
|
|
57
|
+
question: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Resolves a declarative slice specifier (`<cookbook>:<target>[#<pick1>,<pick2>]`)
|
|
61
|
+
* for `/docs` fences (`ts slice=...`).
|
|
62
|
+
* Examples:
|
|
63
|
+
* - `research:profile:research.scout#identity,inputs`
|
|
64
|
+
* - `research:tool:search_github#headers,mapping`
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveCookbookSlice(spec: string): string;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composable Cookbook Projector: extracts and stitches profile facets, tool sub-objects,
|
|
3
|
+
* and multi-agent systems from the canonical `COOKBOOKS` store into clean TypeScript source.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { compileStudio } from "../compile.js";
|
|
8
|
+
import { compileWorkspace } from "../compile-workspace.js";
|
|
9
|
+
import { ON_OWN_KEYS } from "../lent-keys.js";
|
|
10
|
+
import { studioSource, valueSource } from "../source.js";
|
|
11
|
+
import { keySource, quoteSource } from "../tool-schema.js";
|
|
12
|
+
import { agentDraft, withAgentDraft, workspaceFromDraft, } from "../workspace.js";
|
|
13
|
+
import { COOKBOOKS, createArchitectWorkspace, createConsoleExampleDraft, createExampleDraft, createGeminiEmbeddingExampleDraft, createLiveExampleDraft, createNarratorExampleDraft, createResearchWorkspace, createSpanExampleDraft, decisionExampleDraft, } from "./catalog.js";
|
|
14
|
+
const SLICE_STYLE = { unit: ' ', base: '', template: false };
|
|
15
|
+
function syncWorkspace(cookbookId) {
|
|
16
|
+
switch (cookbookId) {
|
|
17
|
+
case 'research':
|
|
18
|
+
return createResearchWorkspace();
|
|
19
|
+
case 'concierge':
|
|
20
|
+
return workspaceFromDraft(createExampleDraft());
|
|
21
|
+
case 'architect':
|
|
22
|
+
return createArchitectWorkspace();
|
|
23
|
+
case 'live-concierge':
|
|
24
|
+
return workspaceFromDraft(createLiveExampleDraft());
|
|
25
|
+
case 'decision':
|
|
26
|
+
return workspaceFromDraft(decisionExampleDraft());
|
|
27
|
+
case 'span-decision':
|
|
28
|
+
return workspaceFromDraft(createSpanExampleDraft());
|
|
29
|
+
case 'gemini-embedding-2':
|
|
30
|
+
return workspaceFromDraft(createGeminiEmbeddingExampleDraft());
|
|
31
|
+
case 'narrator':
|
|
32
|
+
return workspaceFromDraft(createNarratorExampleDraft());
|
|
33
|
+
case 'console':
|
|
34
|
+
return workspaceFromDraft(createConsoleExampleDraft());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function compileFailed(what, issues) {
|
|
38
|
+
return new Error(`${what} failed to compile: ${issues.map((i) => i.message).join('; ')}`);
|
|
39
|
+
}
|
|
40
|
+
function compiledCookbook(cookbookId) {
|
|
41
|
+
const compiled = compileWorkspace(syncWorkspace(cookbookId), ON_OWN_KEYS);
|
|
42
|
+
if (!compiled.ok)
|
|
43
|
+
throw compileFailed(`Cookbook '${cookbookId}'`, compiled.issues);
|
|
44
|
+
return compiled;
|
|
45
|
+
}
|
|
46
|
+
function compileCookbookAgent(cookbookId, agentId) {
|
|
47
|
+
const compiled = compiledCookbook(cookbookId);
|
|
48
|
+
const found = agentId
|
|
49
|
+
? compiled.agents.find((agent) => agent.agentId === agentId)
|
|
50
|
+
: compiled.agents.at(-1);
|
|
51
|
+
if (!found) {
|
|
52
|
+
throw new Error(`Cookbook '${cookbookId}' has no agent '${agentId ?? ''}' (have: ${compiled.agents.map((a) => a.agentId).join(', ')})`);
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
function formatPickedRecord(record, keys, asFields, callPrefix, callSuffix = ');') {
|
|
57
|
+
const picked = Object.fromEntries(keys.filter((key) => record[key] !== undefined).map((key) => [key, record[key]]));
|
|
58
|
+
if (asFields) {
|
|
59
|
+
return Object.entries(picked)
|
|
60
|
+
.map(([key, value]) => `${keySource(key)}: ${valueSource(value, SLICE_STYLE)},`)
|
|
61
|
+
.join('\n');
|
|
62
|
+
}
|
|
63
|
+
return `${callPrefix}${valueSource(picked, SLICE_STYLE)}${callSuffix}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Projects a single profile (or a subset of its facets/fields) from a cookbook in `COOKBOOKS`.
|
|
67
|
+
*/
|
|
68
|
+
export function projectProfileSlice(cookbookId, agentId, options = {}) {
|
|
69
|
+
const compiled = compileCookbookAgent(cookbookId, agentId);
|
|
70
|
+
const mode = options.mode ?? (options.pick?.length ? 'fields' : 'defineProfile');
|
|
71
|
+
const rawProfile = { ...compiled.profile };
|
|
72
|
+
if (options.toolsAllow && 'tools' in rawProfile && rawProfile.tools) {
|
|
73
|
+
rawProfile.tools = {
|
|
74
|
+
...rawProfile.tools,
|
|
75
|
+
allow: [...options.toolsAllow],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (mode === 'module') {
|
|
79
|
+
const customTools = options.toolsAllow
|
|
80
|
+
? compiled.customTools.filter((tool) => options.toolsAllow?.includes(tool.name))
|
|
81
|
+
: compiled.customTools;
|
|
82
|
+
return studioSource({
|
|
83
|
+
...compiled,
|
|
84
|
+
profile: rawProfile,
|
|
85
|
+
customTools,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const keys = options.pick?.length ? options.pick : Object.keys(rawProfile);
|
|
89
|
+
return formatPickedRecord(rawProfile, keys, mode === 'fields', 'const profile = defineProfile(');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Projects a tool (or specific sub-objects of a tool, such as `auth`, `mapping`, `labels`) from `COOKBOOKS`.
|
|
93
|
+
*/
|
|
94
|
+
export function projectToolSlice(cookbookId, toolName, options = {}) {
|
|
95
|
+
const compiled = compiledCookbook(cookbookId);
|
|
96
|
+
const allTools = compiled.agents.flatMap((agent) => agent.customTools);
|
|
97
|
+
const tool = allTools.find((entry) => entry.name === toolName);
|
|
98
|
+
if (!tool) {
|
|
99
|
+
throw new Error(`Cookbook '${cookbookId}' has no tool '${toolName}'`);
|
|
100
|
+
}
|
|
101
|
+
const mode = options.mode ?? (options.pick?.length ? 'fields' : 'registerTool');
|
|
102
|
+
const record = tool;
|
|
103
|
+
const keys = options.pick?.length
|
|
104
|
+
? options.pick
|
|
105
|
+
: Object.keys(record).filter((key) => key !== 'inputSchema' && key !== 'outputSchema' && key !== 'stageAgent');
|
|
106
|
+
return formatPickedRecord(record, keys, mode === 'fields', 'registerTool(');
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Stitches a cookbook (or a focused tool/facet subset of it) into a complete runnable TypeScript program
|
|
110
|
+
* and a matching `StudioWorkspace` for opening in Studio.
|
|
111
|
+
*/
|
|
112
|
+
export function stitchCookbook(cookbookId, recipe = {}) {
|
|
113
|
+
const ws = syncWorkspace(cookbookId);
|
|
114
|
+
const targetAgent = recipe.agentId
|
|
115
|
+
? ws.agents.find((agent) => agent.identity.agentId === recipe.agentId)
|
|
116
|
+
: ws.agents.at(0);
|
|
117
|
+
const baseDraft = targetAgent ? agentDraft(ws, targetAgent.key) : undefined;
|
|
118
|
+
if (!baseDraft || !targetAgent) {
|
|
119
|
+
throw new Error(`Cookbook '${cookbookId}' could not resolve agent '${recipe.agentId ?? ''}'`);
|
|
120
|
+
}
|
|
121
|
+
const draft = recipe.toolsAllow
|
|
122
|
+
? {
|
|
123
|
+
...baseDraft,
|
|
124
|
+
toolSpecs: baseDraft.toolSpecs
|
|
125
|
+
.filter((tool) => recipe.toolsAllow?.includes(tool.toolName))
|
|
126
|
+
.map(({ stageAgentKey: _stage, ...tool }) => tool),
|
|
127
|
+
}
|
|
128
|
+
: baseDraft;
|
|
129
|
+
const compiled = compileStudio(draft, ON_OWN_KEYS);
|
|
130
|
+
if (!compiled.ok)
|
|
131
|
+
throw compileFailed(`Stitched cookbook '${cookbookId}'`, compiled.issues);
|
|
132
|
+
let code = studioSource(compiled);
|
|
133
|
+
if (recipe.runner) {
|
|
134
|
+
const { exportName, prompt, keySlot = 'gemini' } = recipe.runner;
|
|
135
|
+
code = code.replace(/\} from '@theoremjs\/agents';/, ` runTurn,\n} from '@theoremjs/agents';`);
|
|
136
|
+
code = `${code}
|
|
137
|
+
export async function ${exportName}(apiKey: string) {
|
|
138
|
+
const hostOptions = {
|
|
139
|
+
vault: { ${keySource(keySlot)}: apiKey },
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
for await (const event of runTurn(
|
|
143
|
+
{
|
|
144
|
+
profile: ${quoteSource(compiled.agentId)},
|
|
145
|
+
input: {
|
|
146
|
+
text: ${quoteSource(prompt)},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
hostOptions,
|
|
150
|
+
)) {
|
|
151
|
+
if (event.type === 'text') process.stdout.write(event.text);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
const workspace = recipe.toolsAllow
|
|
157
|
+
? withAgentDraft({ ...ws, agents: [targetAgent], toolSpecs: draft.toolSpecs }, targetAgent.key, draft)
|
|
158
|
+
: ws;
|
|
159
|
+
return {
|
|
160
|
+
code,
|
|
161
|
+
workspace,
|
|
162
|
+
question: recipe.runner?.prompt ?? COOKBOOKS[cookbookId].question,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Resolves a declarative slice specifier (`<cookbook>:<target>[#<pick1>,<pick2>]`)
|
|
167
|
+
* for `/docs` fences (`ts slice=...`).
|
|
168
|
+
* Examples:
|
|
169
|
+
* - `research:profile:research.scout#identity,inputs`
|
|
170
|
+
* - `research:tool:search_github#headers,mapping`
|
|
171
|
+
*/
|
|
172
|
+
export function resolveCookbookSlice(spec) {
|
|
173
|
+
const [head = '', pickPart] = spec.split('#');
|
|
174
|
+
const [cookbookRaw = '', kind = 'profile', target] = head.split(':');
|
|
175
|
+
if (!(cookbookRaw in COOKBOOKS)) {
|
|
176
|
+
throw new Error(`Unknown cookbook in slice '${spec}': '${cookbookRaw}'`);
|
|
177
|
+
}
|
|
178
|
+
const cookbookId = cookbookRaw;
|
|
179
|
+
const pick = pickPart
|
|
180
|
+
? pickPart
|
|
181
|
+
.split(',')
|
|
182
|
+
.map((item) => item.trim())
|
|
183
|
+
.filter(Boolean)
|
|
184
|
+
: undefined;
|
|
185
|
+
if (kind === 'tool') {
|
|
186
|
+
if (!target)
|
|
187
|
+
throw new Error(`Tool slice '${spec}' must name a tool: <cookbook>:tool:<name>`);
|
|
188
|
+
return projectToolSlice(cookbookId, target, {
|
|
189
|
+
...(pick ? { pick: pick } : {}),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return projectProfileSlice(cookbookId, target, {
|
|
193
|
+
...(pick ? { pick } : {}),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
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 { type ModelBinding, type ProfileImageSpec, type ProfileLiveSpec, type ProfileSpeechSpec } from '@theoremjs/agents';
|
|
8
|
+
/** The Gemini API's model list, which a connection check reads with a key. */
|
|
9
|
+
export declare const GEMINI_MODELS_URL = "https://generativelanguage.googleapis.com/v1beta/models";
|
|
10
|
+
/** Gemini TTS voice names for `speech.voice` and `live.voice`. */
|
|
11
|
+
export declare const GOOGLE_SPEECH_VOICES: readonly ["Zephyr", "Puck", "Charon", "Kore", "Fenrir", "Leda", "Orus", "Aoede", "Callirrhoe", "Autonoe", "Enceladus", "Iapetus", "Umbriel", "Algieba", "Despina", "Erinome", "Algenib", "Rasalgethi", "Laomedeia", "Achernar", "Alnilam", "Schedar", "Gacrux", "Pulcherrima", "Achird", "Zubenelgenubi", "Vindemiatrix", "Sadachbia", "Sadaltager", "Sulafat"];
|
|
12
|
+
/** The name of a Gemini speech voice. */
|
|
13
|
+
export type GoogleSpeechVoice = (typeof GOOGLE_SPEECH_VOICES)[number];
|
|
14
|
+
/** The thinking levels Gemini's `thinkingLevel` takes; OpenRouter models take them all. */
|
|
15
|
+
export declare const GOOGLE_THINKING_LEVELS: readonly ["minimal", "low", "medium", "high"];
|
|
16
|
+
/** The audio format Gemini speech returns (PCM, wrapped as WAV); OpenRouter speech also takes `mp3`. */
|
|
17
|
+
export declare const GOOGLE_SPEECH_FORMATS: readonly ["pcm"];
|
|
18
|
+
/** A thinking level Gemini takes: minimal, low, medium, or high. */
|
|
19
|
+
export type GoogleThinkingLevel = (typeof GOOGLE_THINKING_LEVELS)[number];
|
|
20
|
+
/**
|
|
21
|
+
* A `geminiInteractions` or `geminiLive` binding's `efforts`, typed to the levels Gemini takes.
|
|
22
|
+
* The runtime check refuses an untyped host's level when the binding is built, not when a turn runs.
|
|
23
|
+
*/
|
|
24
|
+
export declare function googleEfforts<Efforts extends Record<string, GoogleThinkingLevel>>(efforts: Efforts): Efforts;
|
|
25
|
+
/** The image MIME types a Gemini profile can take as input. */
|
|
26
|
+
export declare const GOOGLE_IMAGE_INPUT_MIMES: readonly ["image/png", "image/jpeg", "image/webp", "image/heic", "image/heif"];
|
|
27
|
+
/** The audio MIME types a Gemini profile can take as voice input. */
|
|
28
|
+
export declare const GOOGLE_VOICE_INPUT_MIMES: readonly ["audio/webm", "audio/wav", "audio/mpeg", "audio/mp4"];
|
|
29
|
+
/**
|
|
30
|
+
* TTS models that reject any history with a model turn, so compaction's summary fails them
|
|
31
|
+
* (live, 29/09/2026).
|
|
32
|
+
*/
|
|
33
|
+
export declare const GOOGLE_SINGLE_TURN_API_IDS: readonly ["gemini-2.5-flash-preview-tts", "gemini-3.1-flash-tts-preview", "gemini-3.8-flash-tts", "gemini-3.8-flash-lite-tts"];
|
|
34
|
+
/**
|
|
35
|
+
* Models that reject any thinking setting, `summaries: false` included: leave
|
|
36
|
+
* `efforts` and `summaries` unset (live, 30/09/2026).
|
|
37
|
+
*/
|
|
38
|
+
export declare const GOOGLE_NO_THINKING_API_IDS: readonly ["gemini-2.5-flash-image", "antigravity-preview-05-2026", "antigravity-preview-09-2026", "antigravity-preview-latest"];
|
|
39
|
+
/**
|
|
40
|
+
* Models that refuse a thinking level and take `summaries`: leave `efforts` unset
|
|
41
|
+
* (live, 01/10/2026: Live closes 1007 "Thinking level is not supported for this model";
|
|
42
|
+
* 04/10/2026: setup takes `includeThoughts` either way).
|
|
43
|
+
*/
|
|
44
|
+
export declare const GOOGLE_NO_EFFORT_API_IDS: readonly ["gemini-3.8-live"];
|
|
45
|
+
/**
|
|
46
|
+
* Models that refuse a session without a thinking level: pin `efforts`
|
|
47
|
+
* (live, 01/10/2026: Live closes 1007 "Thinking level must be specified for this model").
|
|
48
|
+
*/
|
|
49
|
+
export declare const GOOGLE_THINKING_REQUIRED_API_IDS: readonly ["gemini-3.8-live-extended-thinking"];
|
|
50
|
+
/** Which grounding builtins a model's free-tier quota allows. */
|
|
51
|
+
export interface GoogleFreeTierGrounding {
|
|
52
|
+
googleSearch: boolean;
|
|
53
|
+
googleMaps: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Models with a non-zero free-tier quota, and the grounding each allows (AI Studio, Sep 2026).
|
|
57
|
+
* No model keeps free Maps quota: 3.5 Flash-Lite turns with Maps are refused as over quota
|
|
58
|
+
* (live, 13/10/2026).
|
|
59
|
+
* A builtin with no quota is refused as if over quota: on Live, a close 1011 "You exceeded your
|
|
60
|
+
* current quota" at setup, whatever the key's usage (live, 01/10/2026).
|
|
61
|
+
*/
|
|
62
|
+
export declare const GOOGLE_FREE_TIER_GROUNDING: Readonly<Record<string, GoogleFreeTierGrounding>>;
|
|
63
|
+
/** Grounding builtins the free tier allows on `apiId`; none for a model with no free quota. */
|
|
64
|
+
export declare function googleFreeTierBuiltins(apiId: string): Array<'googleSearch' | 'googleMaps'>;
|
|
65
|
+
/** A Gemini binding field that breaks a Gemini rule, and what is wrong with it. */
|
|
66
|
+
export interface GoogleBindingViolation {
|
|
67
|
+
field: 'apiId' | 'efforts' | 'summaries' | 'builtInTools';
|
|
68
|
+
message: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The first setting Google would refuse on this binding, or `undefined`. With `freeTier`, it
|
|
72
|
+
* also holds the binding to the free-tier table: a listed model, and only the grounding its
|
|
73
|
+
* quota allows.
|
|
74
|
+
*/
|
|
75
|
+
export declare function googleBindingViolation(binding: Pick<ModelBinding, 'apiId' | 'efforts' | 'summaries' | 'builtInTools'>, options?: {
|
|
76
|
+
freeTier?: boolean;
|
|
77
|
+
}): GoogleBindingViolation | undefined;
|
|
78
|
+
/** The speech settings a Gemini profile may pin, with the voice narrowed to Gemini's. */
|
|
79
|
+
export type GoogleSpeechPins = Omit<ProfileSpeechSpec, 'voice'> & {
|
|
80
|
+
voice?: GoogleSpeechVoice;
|
|
81
|
+
};
|
|
82
|
+
/** The live settings a Gemini profile may pin, with the voice narrowed to Gemini's. */
|
|
83
|
+
export type GoogleLivePins = Omit<ProfileLiveSpec, 'voice'> & {
|
|
84
|
+
voice?: GoogleSpeechVoice;
|
|
85
|
+
};
|
|
86
|
+
/** The aspect ratios a Gemini image model can return. */
|
|
87
|
+
export declare const GOOGLE_IMAGE_ASPECT_RATIOS: readonly ["1:1", "3:2", "2:3", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"];
|
|
88
|
+
/** The resolutions a Gemini image model can return. */
|
|
89
|
+
export declare const GOOGLE_IMAGE_RESOLUTIONS: readonly ["1K", "2K", "4K"];
|
|
90
|
+
/** What a Gemini image model can be asked to return. */
|
|
91
|
+
export declare const GOOGLE_IMAGE_OUTPUT_MIMES: readonly ["image/png", "image/jpeg"];
|
|
92
|
+
/** One of {@linkcode GOOGLE_IMAGE_INPUT_MIMES}. */
|
|
93
|
+
export type GoogleImageInputMime = (typeof GOOGLE_IMAGE_INPUT_MIMES)[number];
|
|
94
|
+
/** One of {@linkcode GOOGLE_VOICE_INPUT_MIMES}. */
|
|
95
|
+
export type GoogleVoiceInputMime = (typeof GOOGLE_VOICE_INPUT_MIMES)[number];
|
|
96
|
+
/** One of {@linkcode GOOGLE_IMAGE_ASPECT_RATIOS}. */
|
|
97
|
+
export type GoogleImageAspectRatio = (typeof GOOGLE_IMAGE_ASPECT_RATIOS)[number];
|
|
98
|
+
/** One of {@linkcode GOOGLE_IMAGE_RESOLUTIONS}. */
|
|
99
|
+
export type GoogleImageResolution = (typeof GOOGLE_IMAGE_RESOLUTIONS)[number];
|
|
100
|
+
/** One of {@linkcode GOOGLE_IMAGE_OUTPUT_MIMES}. */
|
|
101
|
+
export type GoogleImageOutputMime = (typeof GOOGLE_IMAGE_OUTPUT_MIMES)[number];
|
|
102
|
+
/** The image settings a Gemini profile may pin, narrowed to what Gemini accepts. */
|
|
103
|
+
export type GoogleImagePins = Omit<ProfileImageSpec, 'aspectRatio' | 'resolution' | 'mimeType'> & {
|
|
104
|
+
aspectRatio?: GoogleImageAspectRatio;
|
|
105
|
+
resolution?: GoogleImageResolution;
|
|
106
|
+
mimeType?: GoogleImageOutputMime;
|
|
107
|
+
};
|
|
108
|
+
/** The tools Gemini runs itself, as `builtin` tool definitions. */
|
|
109
|
+
export declare const GOOGLE_BUILTIN_TOOLS: ({
|
|
110
|
+
type: "builtin";
|
|
111
|
+
name: string;
|
|
112
|
+
description: string;
|
|
113
|
+
category: string;
|
|
114
|
+
access: "read-only";
|
|
115
|
+
paths: string[];
|
|
116
|
+
loadTier: "T0";
|
|
117
|
+
permission: "auto";
|
|
118
|
+
conflictsWith?: undefined;
|
|
119
|
+
} | {
|
|
120
|
+
type: "builtin";
|
|
121
|
+
name: string;
|
|
122
|
+
description: string;
|
|
123
|
+
category: string;
|
|
124
|
+
access: "read-only";
|
|
125
|
+
paths: string[];
|
|
126
|
+
loadTier: "T0";
|
|
127
|
+
permission: "auto";
|
|
128
|
+
conflictsWith: string[];
|
|
129
|
+
})[];
|
|
130
|
+
/** `/images` takes image references only; a profile on it lists nothing wider in `inputs.attachments.accept`. */
|
|
131
|
+
export declare const OPENROUTER_IMAGES_INPUT_MIMES: readonly ["image/*"];
|
|
132
|
+
/**
|
|
133
|
+
* What `/images` never sends the model: it reads the prompt text and the reference images
|
|
134
|
+
* only. The chat path (`image.includeText`) sends the system prompt and history.
|
|
135
|
+
*/
|
|
136
|
+
export declare const OPENROUTER_IMAGES_IGNORED_INPUTS: readonly ["system", "history"];
|
|
137
|
+
/** The tools OpenRouter runs itself, as `builtin` tool definitions. */
|
|
138
|
+
export declare const OPENROUTER_BUILTIN_TOOLS: {
|
|
139
|
+
type: "builtin";
|
|
140
|
+
name: string;
|
|
141
|
+
description: string;
|
|
142
|
+
category: string;
|
|
143
|
+
access: "read-only";
|
|
144
|
+
paths: string[];
|
|
145
|
+
loadTier: "T0";
|
|
146
|
+
permission: "auto";
|
|
147
|
+
}[];
|
|
148
|
+
/**
|
|
149
|
+
* Whether an Ollama model thinks, read from the server's `POST /api/show` reply for it:
|
|
150
|
+
* `capabilities` lists `thinking` (Ollama 0.34.0, 04/10/2026). The host fetches the reply.
|
|
151
|
+
*/
|
|
152
|
+
export declare function ollamaModelThinks(show: unknown): boolean;
|
|
153
|
+
/** A local binding field its model would refuse, and what is wrong with it. */
|
|
154
|
+
export interface LocalBindingViolation {
|
|
155
|
+
field: 'efforts';
|
|
156
|
+
message: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The first setting a local server would refuse on this binding, or `undefined`. A thinking
|
|
160
|
+
* level goes to the server as `reasoning_effort`; Ollama answers HTTP 400 "does not support
|
|
161
|
+
* thinking" for a model that does not think (04/10/2026).
|
|
162
|
+
*/
|
|
163
|
+
export declare function localBindingViolation(binding: Pick<ModelBinding, 'apiId' | 'efforts'>, model: {
|
|
164
|
+
thinks: boolean;
|
|
165
|
+
}): LocalBindingViolation | undefined;
|