@theoremjs/studio 0.3.4-next.677.g14b70fe → 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.
- package/asks.d.ts +9 -2
- package/asks.js +19 -10
- package/browser-connection.d.ts +1 -1
- package/browser-connection.js +3 -1
- package/browser-execution.js +1 -0
- package/compile-workspace.js +12 -5
- package/compile.d.ts +4 -2
- package/compile.js +58 -37
- package/cookbooks/catalog.d.ts +2 -2
- package/cookbooks/catalog.js +300 -53
- package/cookbooks/project.js +1 -0
- package/cookbooks/tools.js +64 -0
- package/draft.d.ts +21 -5
- package/draft.js +25 -2
- package/guardrail-probe.d.ts +3 -1
- package/guardrail-probe.js +37 -5
- package/mod.d.ts +2 -2
- package/mod.js +2 -2
- package/package.json +4 -4
- package/page/assets/Banner-DrRNC3MG.js +4 -0
- package/page/assets/Center-CgO0c-qo.js +1 -0
- package/page/assets/{ConsoleFrame-BFCYCApu.js → ConsoleFrame-BvgFGqp2.js} +3 -3
- package/page/assets/{MenuBottomSheet-CezET_qZ.js → MenuBottomSheet-BZecY8fw.js} +1 -1
- package/page/assets/{SchemaFields-CIF3WtC0.js → SchemaFields-BNNkvyyO.js} +1 -1
- package/page/assets/{ToolResultCharts-D3pQGTH1.js → ToolResultCharts-C3CPsfXl.js} +1 -1
- package/page/assets/{TraceInspector-Bx3j_185.js → TraceInspector-36e6ozKD.js} +1 -1
- package/page/assets/{TraceOverview-ChpCMZRa.js → TraceOverview-CSdJ_cYY.js} +3 -3
- package/page/assets/{_virtual_studio-type-sources-BwSqfSwd.js → _virtual_studio-type-sources-DSpwr3WK.js} +143 -13
- package/page/assets/browser-connection-dads1eyK.js +3 -0
- package/page/assets/browser-engine-CugH58NS.js +13 -0
- package/page/assets/browser-transport-GzhRiBdm.js +45 -0
- package/page/assets/{crypto-CD14HeXH.js → crypto-B8dqEoWf.js} +1 -1
- package/page/assets/{encode-files-DhoC5hWG.js → encode-files-CHeRLBO8.js} +1 -1
- package/page/assets/{export-agent-nlvsxs9-.js → export-agent-botXSyoH.js} +3 -3
- package/page/assets/{guardrail-tester-C7r03f5Z.js → guardrail-tester-DYR7EPIy.js} +2 -2
- package/page/assets/index-B7sK7d-l.js +153 -0
- package/page/assets/live-messages-DN_q2nBN.js +1 -0
- package/page/assets/project-address-DjxPZuyn.js +1 -0
- package/page/assets/reader-DHN96tSr.js +5 -0
- package/page/assets/{schemas-BQ9Jydzb.js → schemas-D7cgkv3L.js} +1 -1
- package/page/assets/shaped-data-CJQ3W_RE.js +20 -0
- package/page/assets/{stub-nxRsh1jo.js → stub-U6wDGe3P.js} +25 -7
- package/page/assets/studio-code-pane-Boy63AK2.js +8 -0
- package/page/assets/{studio-console-BgymsByi.js → studio-console-B7zL133d.js} +1 -1
- package/page/assets/studio-decision-CbRjfbvG.js +1 -0
- package/page/assets/studio-embedding-DQ0QrEsu.js +2 -0
- package/page/assets/{studio-host-console-DtepSA77.js → studio-host-console-DDA2Um2-.js} +2 -2
- package/page/assets/{studio-labels-BZbz7-uL.js → studio-labels-jYWBoEyP.js} +1 -1
- package/page/assets/studio-live-D0YRu2zQ.js +5 -0
- package/page/assets/studio-map-C4Ra1QqL.js +1 -0
- package/page/assets/studio-session-CPnJaHc-.js +1 -0
- package/page/assets/studio-trace-replay-D-f2p7k9.js +3 -0
- package/page/assets/{studio-type-checker-BbUSqqOS.js → studio-type-checker-CVNPnko-.js} +1 -1
- package/page/assets/tool-schema-BDG2_rlP.js +17 -0
- package/page/assets/{trace-record-DxgSKmYY.js → trace-record-DoXjxrmJ.js} +1 -1
- package/page/assets/trace-schema--4IGmLeE.js +1 -0
- package/page/assets/tree-CcEbNvms.js +3 -0
- package/page/assets/turn-client-BmOSpCgw.js +2 -0
- package/page/assets/{use-one-call-DE5HvQsv.js → use-one-call-B3t-kfc5.js} +1 -1
- package/page/assets/{use-second-ticker-CEwOSS-d.js → use-second-ticker-CWjCHLG6.js} +1 -1
- package/page/assets/workspace-DUfaxr-g.js +1 -0
- package/page/index.html +20 -19
- package/people.d.ts +2 -0
- package/people.js +3 -1
- package/policy.js +1 -0
- package/providers.d.ts +2 -2
- package/providers.js +8 -3
- package/read-source.js +34 -7
- package/registrations.d.ts +23 -3
- package/runtime-scope.d.ts +6 -3
- package/runtime-scope.js +16 -4
- package/runtime.js +14 -2
- package/server/draft-handler.d.ts +4 -4
- package/server/draft-handler.js +3 -2
- package/server/draft-probe.d.ts +9 -1
- package/server/draft-probe.js +2 -1
- package/server/handler.js +71 -25
- package/server/live.d.ts +7 -1
- package/server/live.js +11 -4
- package/server/run-traces.d.ts +5 -1
- package/server/run-traces.js +7 -3
- package/server/save-new.js +5 -5
- package/server/save-session.js +4 -2
- package/server/serve.js +2 -1
- package/server/test-key.d.ts +2 -2
- package/server/test-key.js +1 -1
- package/slot-values.d.ts +2 -0
- package/slot-values.js +22 -0
- package/source.js +11 -4
- package/tool-readers.d.ts +23 -0
- package/tool-readers.js +60 -0
- package/tools.js +4 -1
- package/types.d.ts +3 -1
- package/ui/inspector-context.js +1 -1
- package/ui/lib/project-traces.d.ts +5 -0
- package/ui/lib/project-traces.js +21 -3
- package/ui/lib/studio-page.d.ts +6 -1
- package/ui/lib/studio-page.js +33 -31
- package/ui/lib/studio-project.d.ts +8 -1
- package/ui/lib/studio-project.js +19 -1
- package/ui/lib/studio-session.d.ts +2 -0
- package/ui/lib/studio-session.js +40 -2
- package/ui/lib/studio-store.d.ts +2 -2
- package/ui/lib/studio-store.js +9 -5
- package/ui/lib/tool-probe.d.ts +2 -0
- package/ui/lib/tool-probe.js +3 -2
- package/ui/lib/type-icons.d.ts +1 -0
- package/ui/lib/type-icons.js +2 -1
- package/ui/profile-editor.js +57 -21
- package/ui/studio-compare.d.ts +14 -4
- package/ui/studio-compare.js +58 -24
- package/ui/studio-live.d.ts +1 -1
- package/ui/studio-live.js +8 -3
- package/ui/studio-runner.d.ts +3 -2
- package/ui/studio-runner.js +16 -14
- package/ui/studio-screen.d.ts +1 -1
- package/ui/studio-screen.js +26 -20
- package/ui/studio-settings.js +3 -1
- package/ui/studio-trace-replay.js +7 -1
- package/workspace.js +3 -2
- package/page/assets/Banner-BkgdSxW_.js +0 -4
- package/page/assets/Center-nHS1JSux.js +0 -1
- package/page/assets/browser-connection-DSUHVCT5.js +0 -3
- package/page/assets/browser-engine-D1mbS8b9.js +0 -11
- package/page/assets/browser-transport-C8PD0IJk.js +0 -45
- package/page/assets/index-B7om06iO.js +0 -145
- package/page/assets/live-messages-CiLmR89m.js +0 -1
- package/page/assets/reader-DrOfMM8I.js +0 -5
- package/page/assets/shaped-data-H1miOZm2.js +0 -20
- package/page/assets/studio-code-pane-DA_z5w6h.js +0 -8
- package/page/assets/studio-decision-DWnr99n-.js +0 -1
- package/page/assets/studio-embedding-DCvI007w.js +0 -2
- package/page/assets/studio-live-CnyzlN29.js +0 -5
- package/page/assets/studio-map-DduCJzK7.js +0 -1
- package/page/assets/studio-session-CjUQSXx0.js +0 -1
- package/page/assets/studio-trace-replay-C0UPMVSt.js +0 -3
- package/page/assets/tool-schema-BmRYaywn.js +0 -17
- package/page/assets/trace-schema-9CdEyG6Q.js +0 -1
- package/page/assets/tree-3N-1RPZz.js +0 -3
- package/page/assets/turn-client-DN8PawJr.js +0 -2
- package/page/assets/workspace-CTSW941G.js +0 -1
package/asks.d.ts
CHANGED
|
@@ -30,10 +30,16 @@ export interface AskTool {
|
|
|
30
30
|
permission: string;
|
|
31
31
|
profile?: string;
|
|
32
32
|
}
|
|
33
|
+
/** The header a run carries the builder's choice of which tools that write ask in. */
|
|
34
|
+
export declare const ASK_WRITES_HEADER = "x-theorem-studio-ask-writes";
|
|
35
|
+
/** The same on a live socket's address: a browser's `WebSocket` sends no headers. */
|
|
36
|
+
export declare const ASK_WRITES_PARAM = "ask-writes";
|
|
33
37
|
/** Which of a project's tools the studio makes ask, and which it cannot. */
|
|
34
38
|
export interface StudioAsks {
|
|
35
39
|
/** The tools that ask before each run here and would not in the application. */
|
|
36
40
|
asked: string[];
|
|
41
|
+
/** Those of `asked` that can reach a destructive tool: they ask whatever the builder chose. */
|
|
42
|
+
destructive: string[];
|
|
37
43
|
/**
|
|
38
44
|
* The tools that write and run unasked: a called agent runs them, and a question inside a called
|
|
39
45
|
* agent has no one to answer it. The call to that agent asks instead.
|
|
@@ -49,6 +55,7 @@ export declare function studioAsks(tools: readonly AskTool[], allowed: (profile:
|
|
|
49
55
|
/**
|
|
50
56
|
* The studio's question before each run of an `asked` tool, as a stage. The tool's registration
|
|
51
57
|
* is left as the project set it, so the project's own code reads its own setting. A call the
|
|
52
|
-
* builder already approved where it stopped is not asked again.
|
|
58
|
+
* builder already approved where it stopped is not asked again. `destructiveOnly` reads the run's
|
|
59
|
+
* own choice, since the builder can change it between two runs.
|
|
53
60
|
*/
|
|
54
|
-
export declare function studioAskStage(asked:
|
|
61
|
+
export declare function studioAskStage({ asked, destructive }: StudioAsks, destructiveOnly: () => boolean): StageHandler | undefined;
|
package/asks.js
CHANGED
|
@@ -23,6 +23,10 @@ export function writeAskLine(ask) {
|
|
|
23
23
|
const set = ask.access === 'destructive' ? 'destructive' : 'read and write';
|
|
24
24
|
return `It is set as ${set}. Run sends a real request: ${ask.sends}`;
|
|
25
25
|
}
|
|
26
|
+
/** The header a run carries the builder's choice of which tools that write ask in. */
|
|
27
|
+
export const ASK_WRITES_HEADER = 'x-theorem-studio-ask-writes';
|
|
28
|
+
/** The same on a live socket's address: a browser's `WebSocket` sends no headers. */
|
|
29
|
+
export const ASK_WRITES_PARAM = 'ask-writes';
|
|
26
30
|
/**
|
|
27
31
|
* The tools the studio makes ask before each run: every one that writes, and every agent tool
|
|
28
32
|
* whose agent can reach one that writes. A tool a called agent runs is left as it is, because the
|
|
@@ -32,22 +36,24 @@ export function studioAsks(tools, allowed) {
|
|
|
32
36
|
const named = new Map(tools.map((tool) => [tool.name, tool]));
|
|
33
37
|
const runs = (tool) => tool.type === 'agent' && tool.profile ? allowed(tool.profile) : [];
|
|
34
38
|
const inside = new Set(tools.flatMap(runs));
|
|
35
|
-
const
|
|
39
|
+
const reaches = (tool, is, seen) => {
|
|
36
40
|
if (seen.has(tool.name))
|
|
37
41
|
return false;
|
|
38
42
|
seen.add(tool.name);
|
|
39
|
-
if (tool
|
|
43
|
+
if (is(tool))
|
|
40
44
|
return true;
|
|
41
45
|
return runs(tool).some((name) => {
|
|
42
46
|
const inner = named.get(name);
|
|
43
|
-
return inner !== undefined &&
|
|
47
|
+
return inner !== undefined && reaches(inner, is, seen);
|
|
44
48
|
});
|
|
45
49
|
};
|
|
46
50
|
// A provider's built-in tool runs on the provider and never stops on a question.
|
|
47
|
-
const writing = tools.filter((tool) => tool.type !== 'builtin' &&
|
|
51
|
+
const writing = tools.filter((tool) => tool.type !== 'builtin' && reaches(tool, (each) => each.access !== 'read-only', new Set()));
|
|
52
|
+
const asked = writing.filter((tool) => !inside.has(tool.name) && tool.permission !== 'always_confirm');
|
|
48
53
|
return {
|
|
49
|
-
asked:
|
|
50
|
-
|
|
54
|
+
asked: asked.map((tool) => tool.name),
|
|
55
|
+
destructive: asked
|
|
56
|
+
.filter((tool) => reaches(tool, (each) => each.access === 'destructive', new Set()))
|
|
51
57
|
.map((tool) => tool.name),
|
|
52
58
|
inside: writing.filter((tool) => inside.has(tool.name)).map((tool) => tool.name),
|
|
53
59
|
};
|
|
@@ -57,13 +63,16 @@ const STUDIO_ASK_SUMMARY = 'The studio asks before every run of a tool that writ
|
|
|
57
63
|
/**
|
|
58
64
|
* The studio's question before each run of an `asked` tool, as a stage. The tool's registration
|
|
59
65
|
* is left as the project set it, so the project's own code reads its own setting. A call the
|
|
60
|
-
* builder already approved where it stopped is not asked again.
|
|
66
|
+
* builder already approved where it stopped is not asked again. `destructiveOnly` reads the run's
|
|
67
|
+
* own choice, since the builder can change it between two runs.
|
|
61
68
|
*/
|
|
62
|
-
export function studioAskStage(asked) {
|
|
69
|
+
export function studioAskStage({ asked, destructive }, destructiveOnly) {
|
|
63
70
|
if (asked.length === 0)
|
|
64
71
|
return undefined;
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
return (ctx) => ctx.stage === 'pre_tool' &&
|
|
73
|
+
!ctx.approved &&
|
|
74
|
+
ctx.tool !== undefined &&
|
|
75
|
+
(destructiveOnly() ? destructive : asked).includes(ctx.tool)
|
|
67
76
|
? { confirm: { summary: STUDIO_ASK_SUMMARY } }
|
|
68
77
|
: undefined;
|
|
69
78
|
}
|
package/browser-connection.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const STUDIO_KEY_SLOT_CAP = 32;
|
|
|
17
17
|
/** The same localhost origin and transport used for inference; never a site proxy. */
|
|
18
18
|
export declare function listLocalStudioModels(local: StudioBrowserConnection['local'], signal?: AbortSignal): Promise<string[]>;
|
|
19
19
|
/** The profile types a model runs for; a provider's list is filtered to the one being edited. */
|
|
20
|
-
export type ListedProfileType = 'text' | 'image' | 'speech' | 'live' | 'embedding';
|
|
20
|
+
export type ListedProfileType = 'text' | 'image' | 'speech' | 'transcription' | 'live' | 'embedding';
|
|
21
21
|
/** A model a provider lists, as the studio's picker shows it. */
|
|
22
22
|
export interface ProviderModel {
|
|
23
23
|
/** What the profile's `apiId` is set to. */
|
package/browser-connection.js
CHANGED
|
@@ -75,12 +75,14 @@ export const KNOWN_OPENROUTER_EMBEDDING_MODELS = [
|
|
|
75
75
|
];
|
|
76
76
|
/**
|
|
77
77
|
* OpenRouter's `output_modalities` for each profile type: chat models for text, `/images` models
|
|
78
|
-
* for image, `/audio/speech` models for speech
|
|
78
|
+
* for image, `/audio/speech` models for speech, `/audio/transcriptions` models for transcription.
|
|
79
|
+
* OpenRouter has no live models.
|
|
79
80
|
*/
|
|
80
81
|
const OPENROUTER_OUTPUT = {
|
|
81
82
|
text: 'text',
|
|
82
83
|
image: 'image',
|
|
83
84
|
speech: 'speech',
|
|
85
|
+
transcription: 'transcription',
|
|
84
86
|
live: undefined,
|
|
85
87
|
embedding: undefined,
|
|
86
88
|
};
|
package/browser-execution.js
CHANGED
|
@@ -6,6 +6,7 @@ export function browserExecution() {
|
|
|
6
6
|
request: new Request('https://studio.local'),
|
|
7
7
|
session: () => id,
|
|
8
8
|
sessionStore: memory,
|
|
9
|
+
pageStatesTurn: true,
|
|
9
10
|
});
|
|
10
11
|
const store = sessionStateStore(memory, undefined, DEFAULT_OPERATION_RETENTION_MS);
|
|
11
12
|
const page = sessionPageDispatch(store, id, createMemoryPageToolBroker());
|
package/compile-workspace.js
CHANGED
|
@@ -9,9 +9,8 @@ import { kernelDefinition, providerProblems, registerStudioProvider } from "./pr
|
|
|
9
9
|
import { registerDefined } from "./tools.js";
|
|
10
10
|
import { modelBindingNodeId, providerNodeId, toolSpecNodeId } from "./tree.js";
|
|
11
11
|
import { agentDraft, agentNodeId, scopedNodeId, } from "./workspace.js";
|
|
12
|
-
/** The agents an agent tool can run
|
|
12
|
+
/** The agents an agent tool can run. */
|
|
13
13
|
const CALLABLE_TYPES = new Set(['text', 'image', 'speech']);
|
|
14
|
-
const STAGE_READER_TYPES = new Set(['decision', 'text']);
|
|
15
14
|
function references(workspace) {
|
|
16
15
|
const tools = new Map(workspace.toolSpecs.map((tool) => [tool.key, tool]));
|
|
17
16
|
return workspace.agents.flatMap((agent) => [
|
|
@@ -156,8 +155,12 @@ function wrongTypeMessage(ref, target) {
|
|
|
156
155
|
if (ref.field === 'agentKey' && !CALLABLE_TYPES.has(type)) {
|
|
157
156
|
return `'${id}' is a ${type} agent. An agent tool runs a text, image, or speech agent.`;
|
|
158
157
|
}
|
|
159
|
-
if (ref.field === 'stageAgentKey' &&
|
|
160
|
-
return `'${id}' is a ${type} agent. A tool reader runs a decision
|
|
158
|
+
if (ref.field === 'stageAgentKey' && type !== 'decision') {
|
|
159
|
+
return `'${id}' is a ${type} agent. A tool reader runs a decision agent.`;
|
|
160
|
+
}
|
|
161
|
+
if (ref.field === 'stageAgentKey' &&
|
|
162
|
+
!target.decision.questions.some((question) => question.type === 'choice')) {
|
|
163
|
+
return `'${id}' has no choice question. A tool reader keeps a passage on the first choice.`;
|
|
161
164
|
}
|
|
162
165
|
if (ref.field === 'compactWith' && type !== 'text') {
|
|
163
166
|
return `'${id}' is a ${type} agent. Only a text agent summarises.`;
|
|
@@ -299,7 +302,11 @@ export function workspaceRunAgent(compiled, agentId) {
|
|
|
299
302
|
customTools,
|
|
300
303
|
...(structured ? { structured } : {}),
|
|
301
304
|
}));
|
|
302
|
-
|
|
305
|
+
const customTools = chatted.customTools.map((tool) => {
|
|
306
|
+
const reader = tool.type === 'agent' ? undefined : byId.get(tool.stageAgent ?? '');
|
|
307
|
+
return reader?.questions ? { ...tool, stageQuestions: reader.questions } : tool;
|
|
308
|
+
});
|
|
309
|
+
return { ...chatted, customTools, dependencies };
|
|
303
310
|
}
|
|
304
311
|
/** The agent ids a compiled agent names: its agent tools', stage readers', and its compaction's. */
|
|
305
312
|
function namedAgents(agent) {
|
package/compile.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type DecisionAsset, type DecisionQuestion, type ImageProfileDefinition, type LiveProfileDefinition, type ProfileGuardrailsSpec, type SpeechProfileDefinition, type TextProfileDefinition } from '@theoremjs/agents';
|
|
1
|
+
import { type DecisionAsset, type DecisionQuestion, type ImageProfileDefinition, type LiveProfileDefinition, type ProfileGuardrailsSpec, type SpeechProfileDefinition, type TextProfileDefinition, type TranscriptionProfileDefinition } from '@theoremjs/agents';
|
|
2
2
|
import { type DecisionProfileDefinition, type EmbeddingProfileDefinition, type HostProfileDefinition, type ProfileDefinition } from '@theoremjs/agents/kernel';
|
|
3
3
|
import type { GuardrailsDraft, StudioDraft } from './draft.ts';
|
|
4
4
|
import type { StudioRunsOn } from './lent-keys.ts';
|
|
5
5
|
import { type StudioProvider } from './providers.ts';
|
|
6
6
|
import type { StructuredRegistration, ToolRegistration } from './registrations.ts';
|
|
7
|
-
export type StudioProfileDefinition = TextProfileDefinition | ImageProfileDefinition | SpeechProfileDefinition | LiveProfileDefinition | DecisionProfileDefinition | EmbeddingProfileDefinition | HostProfileDefinition;
|
|
7
|
+
export type StudioProfileDefinition = TextProfileDefinition | ImageProfileDefinition | SpeechProfileDefinition | TranscriptionProfileDefinition | LiveProfileDefinition | DecisionProfileDefinition | EmbeddingProfileDefinition | HostProfileDefinition;
|
|
8
8
|
/** A profile that runs a model turn: every studio type but decision and host. */
|
|
9
9
|
export type StudioTurnProfileDefinition = Exclude<StudioProfileDefinition, DecisionProfileDefinition | HostProfileDefinition>;
|
|
10
10
|
/**
|
|
@@ -45,6 +45,8 @@ export type AgentIdOf = (key: string) => string | undefined;
|
|
|
45
45
|
* `undefined` when none has that key or an agent tool can't run it.
|
|
46
46
|
*/
|
|
47
47
|
export type AgentToolInputOf = (key: string) => Record<string, unknown> | undefined;
|
|
48
|
+
/** The conditions a draft declares so far: none while they are not JSON. */
|
|
49
|
+
export declare function draftConditions(conditionsJson: string): Record<string, string[]>;
|
|
48
50
|
/** What a tool that runs this draft's agent takes, as the kernel derives it from the agent's inputs. */
|
|
49
51
|
export declare function agentToolInputSchema(draft: StudioDraft): Record<string, unknown> | undefined;
|
|
50
52
|
/** Why these headers can't be saved, when one of them looks like a credential. */
|
package/compile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineProfile, describeError, liveIngressChannelDefault, TheoremError, } from '@theoremjs/agents';
|
|
2
2
|
import { BOUNDARIES, DETECT_DEFAULTS, DETECTOR_META, DETECTORS, detectProblem, hintProblem, patternListProblem, TOOL_BOUNDARIES, validateLabelOverrides, } from '@theoremjs/agents/guardrails';
|
|
3
|
-
import { activityLabelProblem, agentToolInputFor, agentToolOutput, jsonSchemaFromZod, mimeAllowed, outOfScopeFields,
|
|
3
|
+
import { activityLabelProblem, agentToolInputFor, agentToolOutput, jsonSchemaFromZod, mimeAllowed, outOfScopeFields, systemLinesProblem, } from '@theoremjs/agents/kernel';
|
|
4
4
|
import { resolveObservabilityPolicy } from '@theoremjs/agents/observability';
|
|
5
5
|
import { HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, } from '@theoremjs/agents/schema';
|
|
6
6
|
import { isCredentialName, MASK } from '@theoremjs/agents/surface';
|
|
@@ -289,31 +289,40 @@ const isAny = (_value) => true;
|
|
|
289
289
|
function parseHeaders(raw) {
|
|
290
290
|
return parseRecord(raw, isString);
|
|
291
291
|
}
|
|
292
|
-
const
|
|
293
|
-
/**
|
|
294
|
-
function
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
292
|
+
const isValueList = (value) => Array.isArray(value) && value.every(isString);
|
|
293
|
+
/** The conditions a draft declares so far: none while they are not JSON. */
|
|
294
|
+
export function draftConditions(conditionsJson) {
|
|
295
|
+
return parseRecord(conditionsJson, isValueList) ?? {};
|
|
296
|
+
}
|
|
297
|
+
/** The prompt's lines and the facts they read, each problem reported on the identity section. */
|
|
298
|
+
function compilePrompt(draft, report) {
|
|
299
|
+
const conditions = parseRecord(draft.identity.conditionsJson, isValueList);
|
|
300
|
+
if (conditions === null) {
|
|
301
|
+
report('identity', 'Conditions must be a JSON object of lists of values.', 'conditionsJson');
|
|
302
|
+
}
|
|
303
|
+
const lines = draft.identity.system.flatMap(({ text }) => {
|
|
304
|
+
const parsed = parseSystemMarkup(text);
|
|
305
|
+
if (!parsed.ok)
|
|
306
|
+
report('identity', parsed.message, 'system');
|
|
307
|
+
return parsed.ok && parsed.prompt !== undefined ? [parsed.prompt] : [];
|
|
308
|
+
});
|
|
309
|
+
const [first] = lines;
|
|
310
|
+
const system = lines.length === 0
|
|
311
|
+
? undefined
|
|
312
|
+
: lines.length === 1 && typeof first === 'string'
|
|
313
|
+
? first
|
|
314
|
+
: lines;
|
|
315
|
+
const declared = conditions ?? undefined;
|
|
316
|
+
if (system !== undefined && conditions !== null) {
|
|
317
|
+
const slots = Object.fromEntries(draft.inputs.slots.map((slot) => [
|
|
318
|
+
slot.name.trim(),
|
|
319
|
+
slot.choices.map((choice) => choice.value.trim()).filter(Boolean),
|
|
320
|
+
]));
|
|
321
|
+
const problem = systemLinesProblem(system, declared, slots);
|
|
322
|
+
if (problem)
|
|
323
|
+
report('identity', problem, 'system');
|
|
324
|
+
}
|
|
325
|
+
return { system, conditions: declared };
|
|
317
326
|
}
|
|
318
327
|
/** A record field's value, reporting `message` on `field` when it doesn't parse. */
|
|
319
328
|
function recordField(raw, isValue, report) {
|
|
@@ -387,6 +396,7 @@ function toolCommon(tool, fail, agentInputOf) {
|
|
|
387
396
|
permission: tool.permission,
|
|
388
397
|
loadTier: tool.loadTier,
|
|
389
398
|
paths: paths.length ? paths : ['*'],
|
|
399
|
+
...(tool.after ? { after: true } : {}),
|
|
390
400
|
...schemas,
|
|
391
401
|
};
|
|
392
402
|
}
|
|
@@ -756,6 +766,22 @@ function compileLiveInputs(inputs, report) {
|
|
|
756
766
|
return {};
|
|
757
767
|
return { inputs: { ...(slots ? { slots } : {}), ...(context ? { context } : {}) } };
|
|
758
768
|
}
|
|
769
|
+
/** The shapes a slot's value picks: its schemas, and what `outputs.structured` writes. */
|
|
770
|
+
function compileSlotShapes(outputs, fallback, report) {
|
|
771
|
+
const { slot, shapes } = outputs.bySlot ?? { slot: '', shapes: [] };
|
|
772
|
+
const also = [];
|
|
773
|
+
const map = {};
|
|
774
|
+
for (const shape of shapes) {
|
|
775
|
+
const schema = parseJsonSchema(shape.schemaJson, `The reply shape for '${shape.choice}'`);
|
|
776
|
+
if (!schema.ok)
|
|
777
|
+
report('outputs', schema.error, 'schemaJson');
|
|
778
|
+
else {
|
|
779
|
+
also.push({ id: shape.schemaId, spec: { jsonSchema: schema.schema } });
|
|
780
|
+
map[shape.choice] = shape.schemaId;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return also.length ? { also, written: { by: slot, map, fallback } } : undefined;
|
|
784
|
+
}
|
|
759
785
|
/** `shaped`: the type takes a structured reply and its validation (text only). */
|
|
760
786
|
function compileOutputs(outputs, shaped, report) {
|
|
761
787
|
let structured;
|
|
@@ -772,6 +798,9 @@ function compileOutputs(outputs, shaped, report) {
|
|
|
772
798
|
structured = { id, spec: { jsonSchema: schema.schema } };
|
|
773
799
|
}
|
|
774
800
|
}
|
|
801
|
+
const bySlot = structured && compileSlotShapes(outputs, structured.id, report);
|
|
802
|
+
if (structured && bySlot)
|
|
803
|
+
structured = { ...structured, also: bySlot.also };
|
|
775
804
|
if (validationEnabled) {
|
|
776
805
|
checkWhole(report, 'outputs', 'maxRetries', 'Validation max retries', outputs.maxRetries, 0);
|
|
777
806
|
}
|
|
@@ -791,7 +820,7 @@ function compileOutputs(outputs, shaped, report) {
|
|
|
791
820
|
...(outputs.streamThoughts ? {} : { streamThoughts: false }),
|
|
792
821
|
};
|
|
793
822
|
const spec = {
|
|
794
|
-
...(structured ? { structured: structured.id } : {}),
|
|
823
|
+
...(structured ? { structured: bySlot?.written ?? structured.id } : {}),
|
|
795
824
|
...(Object.keys(validation).length ? { validation } : {}),
|
|
796
825
|
...(Object.keys(streaming).length ? { streaming } : {}),
|
|
797
826
|
};
|
|
@@ -1620,15 +1649,7 @@ function compileHost(draft, report, agentIdOf, agentInputOf) {
|
|
|
1620
1649
|
function assemble(draft, type, report, on, agentIdOf, agentInputOf) {
|
|
1621
1650
|
const facets = new Set(draftFacets(draft));
|
|
1622
1651
|
const allows = (path) => draftAllows(draft, path);
|
|
1623
|
-
const
|
|
1624
|
-
? parseSystemMarkup(draft.identity.system)
|
|
1625
|
-
: { ok: false, message: 'The system prompt must be text.' };
|
|
1626
|
-
if (!parsedSystem.ok)
|
|
1627
|
-
report('identity', parsedSystem.message, 'system');
|
|
1628
|
-
const system = parsedSystem.ok ? parsedSystem.prompt : undefined;
|
|
1629
|
-
const systemByRole = compileSystemByRole(draft.identity.systemByRoleJson, (message) => {
|
|
1630
|
-
report('identity', message, 'systemByRoleJson');
|
|
1631
|
-
});
|
|
1652
|
+
const { system, conditions } = compilePrompt(draft, report);
|
|
1632
1653
|
const modelFields = compileModels(draft, type, report, agentIdOf);
|
|
1633
1654
|
const { outputs, structured } = facets.has('outputs')
|
|
1634
1655
|
? compileOutputs(draft.outputs, allows('outputs.structured'), report)
|
|
@@ -1647,8 +1668,8 @@ function assemble(draft, type, report, on, agentIdOf, agentInputOf) {
|
|
|
1647
1668
|
id: draft.identity.agentId.trim(),
|
|
1648
1669
|
identity: {
|
|
1649
1670
|
handle: draft.identity.handle.trim(),
|
|
1671
|
+
...(conditions ? { conditions } : {}),
|
|
1650
1672
|
...(system ? { system } : {}),
|
|
1651
|
-
...(systemByRole ? { systemByRole } : {}),
|
|
1652
1673
|
},
|
|
1653
1674
|
...modelFields,
|
|
1654
1675
|
...(facets.has('image') ? { image: compileImage(draft.image, report) } : {}),
|
package/cookbooks/catalog.d.ts
CHANGED
|
@@ -41,9 +41,9 @@ export declare const RESEARCH_PAGE_READER_STATE: string;
|
|
|
41
41
|
export declare function createPageReaderExampleDraft(): StudioDraft;
|
|
42
42
|
/** The research scout on its own: searches papers, models, datasets, repos, and docs. */
|
|
43
43
|
export declare function createResearchScoutDraft(): StudioDraft;
|
|
44
|
-
/** The research scout and
|
|
44
|
+
/** The research scout and its team, added to a workspace. */
|
|
45
45
|
export declare function addResearchExample(workspace: StudioWorkspace): StudioWorkspace;
|
|
46
|
-
/** A workspace of the research scout and its
|
|
46
|
+
/** A workspace of the research scout and its team, with the scout in the chat. */
|
|
47
47
|
export declare function createResearchWorkspace(): StudioWorkspace;
|
|
48
48
|
/** A fresh copy of the travel concierge draft: a text agent with the tools a trip needs. */
|
|
49
49
|
export declare function createExampleDraft(): StudioDraft;
|