@theoremjs/web 0.3.5-next.918.g28ade76 → 0.3.5-next.926.g05c82e3
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 +1 -1
- package/client/index.d.ts +1 -1
- package/client/index.js +1 -1
- package/client/tool-result.d.ts +12 -5
- package/client/tool-result.js +16 -42
- package/client/transcript-schema.js +5 -3
- package/package.json +2 -2
- package/server/mcp-handler.js +16 -9
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ export const mcp = createTheoremMcpHandler({ profile: docsTools, version: '1.0.0
|
|
|
103
103
|
|
|
104
104
|
- `tools/list` gives each allowed tool with its input schema. A tool's `access` becomes the read-only and destructive hints of MCP.
|
|
105
105
|
- Clients of the current revision may cache the tool list for 5 minutes and the discovery result for an hour. Neither holds anything about the caller, so a shared cache may keep them.
|
|
106
|
-
- `tools/call` runs the tool through the gates, the guardrails, and the trace of the kernel. The client receives the text a model would read, not the raw output.
|
|
106
|
+
- `tools/call` runs the tool through the gates, the guardrails, and the trace of the kernel. The client receives the text and media a model would read, not the raw output. A reference a tool returned, which no model reads, is left out. So is all the media of a hidden tool (`exposeToModel: false`), whose model reads only that the call completed.
|
|
107
107
|
- A tool that fails returns a result marked `isError`, so the model can read it and try again.
|
|
108
108
|
- No one can approve a call over MCP. The handler refuses a profile when an allowed tool has a permission other than `auto`.
|
|
109
109
|
- A browser page on another origin is refused unless `origins` lists it.
|
package/client/index.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export { fieldLabel, fieldReading, humanize, isPart, isPlain, isProse, isRow, js
|
|
|
29
29
|
export { citationsFromBlock, type SourceCitation, type SourceCitationBlock, } from './source-citations.ts';
|
|
30
30
|
export type { QueryMatch } from './space-geometry.ts';
|
|
31
31
|
export { DOT_FLOATS, FRAME_SLOT, queryGeometry, SEGMENT_FLOATS, type SpaceGeometry, spaceGeometry, } from './space-geometry.ts';
|
|
32
|
-
export { hasLead, layoutResult, type ResultChart, type ResultFigure, type ResultImage, type ResultLayout, type ResultMedia, returnedMedia, timeFormats, } from './tool-result.ts';
|
|
32
|
+
export { hasLead, layoutResult, type ResultChart, type ResultFigure, type ResultImage, type ResultLayout, type ResultMedia, referencesIn, returnedMedia, timeFormats, } from './tool-result.ts';
|
|
33
33
|
export type { AnsweringGate, ToolDecisionAction, ToolGateResolution, } from './tool-resume.ts';
|
|
34
34
|
export { continueGatedToolInvocation, type PersonGateResolution } from './tool-resume.ts';
|
|
35
35
|
export { createTraceFeed, recordedFeed, type TraceFeed } from './trace-feed.ts';
|
package/client/index.js
CHANGED
|
@@ -24,7 +24,7 @@ export { blankRow, missingFields, sampleFromSchema, schemaControl, schemaFields,
|
|
|
24
24
|
export { fieldLabel, fieldReading, humanize, isPart, isPlain, isProse, isRow, json, layoutChars, MAX_ROWS, plainReading, rowHeading, shapeOf, splitFields, unpacked, withUnit, } from "./shaped-data.js";
|
|
25
25
|
export { citationsFromBlock, } from "./source-citations.js";
|
|
26
26
|
export { DOT_FLOATS, FRAME_SLOT, queryGeometry, SEGMENT_FLOATS, spaceGeometry, } from "./space-geometry.js";
|
|
27
|
-
export { hasLead, layoutResult, returnedMedia, timeFormats, } from "./tool-result.js";
|
|
27
|
+
export { hasLead, layoutResult, referencesIn, returnedMedia, timeFormats, } from "./tool-result.js";
|
|
28
28
|
export { continueGatedToolInvocation } from "./tool-resume.js";
|
|
29
29
|
export { createTraceFeed, recordedFeed } from "./trace-feed.js";
|
|
30
30
|
export { CHAT_LINES, createHttpTransport, fetchConversation, fetchRewound, fetchStarted, hostError, isTheoremStreamError, postJson, postNdjson, readNdjsonStream, TheoremStreamError, } from "./transport.js";
|
package/client/tool-result.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
+
import { type MediaInputKind } from '@theoremjs/agents';
|
|
9
10
|
import { type Row } from './shaped-data.ts';
|
|
10
11
|
/** One number that answers the call, as a stat card shows it. */
|
|
11
12
|
export type ResultFigure = {
|
|
@@ -45,15 +46,15 @@ export type ResultImage = {
|
|
|
45
46
|
export type ResultLayout = {
|
|
46
47
|
figures: ResultFigure[];
|
|
47
48
|
charts: ResultChart[];
|
|
48
|
-
images: ResultImage[];
|
|
49
49
|
};
|
|
50
|
-
/** Media a tool returned beside its value, as the complete event carries it. */
|
|
50
|
+
/** Media a tool returned beside its value, as the complete event carries it: bytes, or a reference (`uri`). */
|
|
51
51
|
export type ResultMedia = {
|
|
52
52
|
type: string;
|
|
53
53
|
mimeType?: string;
|
|
54
54
|
data?: string;
|
|
55
|
+
uri?: string;
|
|
55
56
|
};
|
|
56
|
-
/** What a call returned to see or hear: its image parts
|
|
57
|
+
/** What a call returned to see or hear: its image parts and its audio parts. */
|
|
57
58
|
export type ReturnedMedia = {
|
|
58
59
|
images: ResultImage[];
|
|
59
60
|
audio: {
|
|
@@ -63,8 +64,14 @@ export type ReturnedMedia = {
|
|
|
63
64
|
};
|
|
64
65
|
/** What a tool's output leads with. Empty when nothing stands out: the data alone reads best. */
|
|
65
66
|
export declare function layoutResult(output: unknown): ResultLayout;
|
|
66
|
-
/** The images and audio a call returned, each with its bytes; parts without them are left out. */
|
|
67
|
-
export declare function returnedMedia(
|
|
67
|
+
/** The images and audio a call returned, each with its bytes; parts without them (references) are left out. */
|
|
68
|
+
export declare function returnedMedia(parts: readonly ResultMedia[], imageAlt: string): ReturnedMedia;
|
|
69
|
+
/** The references a call returned, which only the app's resolver turns into something to show. */
|
|
70
|
+
export declare function referencesIn(parts: readonly ResultMedia[]): {
|
|
71
|
+
type: MediaInputKind;
|
|
72
|
+
mimeType: string;
|
|
73
|
+
uri: string;
|
|
74
|
+
}[];
|
|
68
75
|
/** Whether the result has anything to lead with above its data. */
|
|
69
76
|
export declare function hasLead(layout: ResultLayout, media: ReturnedMedia): boolean;
|
|
70
77
|
/**
|
package/client/tool-result.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
+
import { MEDIA_INPUT_KIND_VALUES } from '@theoremjs/agents';
|
|
9
10
|
import { columnStore, fieldLabel, humanize, ISO_DATE, isPlain, isRow, printableUnit, shownEntries, storeRows, titleKey, unitsOf, unpacked, } from "./shaped-data.js";
|
|
10
11
|
const MAX_FIGURES = 4;
|
|
11
12
|
const MAX_CHARTS = 3;
|
|
@@ -13,25 +14,12 @@ const MAX_CHARTS = 3;
|
|
|
13
14
|
const MAX_SERIES = 3;
|
|
14
15
|
/** Bars a category chart ranks. */
|
|
15
16
|
const MAX_BARS = 8;
|
|
16
|
-
const MAX_IMAGES = 6;
|
|
17
17
|
/** Rows a list needs before it reads as a chart. */
|
|
18
18
|
const MIN_POINTS = 3;
|
|
19
|
-
/** Levels searched for charts
|
|
19
|
+
/** Levels searched for charts. */
|
|
20
20
|
const MAX_SEARCH_DEPTH = 3;
|
|
21
21
|
/** Numbers that locate or name a thing rather than measure it. */
|
|
22
22
|
const NOT_A_MEASURE = /(^|_)(id|ids|lat|lon|lng|latitude|longitude|offset|interval|index|rank|order)$|Id$|^(generationtime_ms|utc_offset_seconds)$/i;
|
|
23
|
-
const IMAGE_PATH = /\.(png|jpe?g|gif|webp|avif|svg)$/i;
|
|
24
|
-
function isImageUrl(text) {
|
|
25
|
-
if (/\s/.test(text))
|
|
26
|
-
return false;
|
|
27
|
-
try {
|
|
28
|
-
const url = new URL(text);
|
|
29
|
-
return (url.protocol === 'http:' || url.protocol === 'https:') && IMAGE_PATH.test(url.pathname);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
23
|
function isMeasure(key) {
|
|
36
24
|
return !NOT_A_MEASURE.test(key);
|
|
37
25
|
}
|
|
@@ -215,55 +203,41 @@ function chartsIn(value, path, title, units, depth) {
|
|
|
215
203
|
}
|
|
216
204
|
return entries.flatMap(([key, entry]) => chartsIn(unpacked(entry), path ? `${path}.${key}` : key, depth === 0 ? humanize(key) : `${title} › ${humanize(key)}`, unitsOf(value, key), depth + 1));
|
|
217
205
|
}
|
|
218
|
-
/** Image URLs anywhere in the value, first found first, each once. */
|
|
219
|
-
function imagesIn(value, key, depth, found) {
|
|
220
|
-
if (found.size >= MAX_IMAGES || depth > MAX_SEARCH_DEPTH + 1)
|
|
221
|
-
return;
|
|
222
|
-
const inner = unpacked(value);
|
|
223
|
-
if (typeof inner === 'string') {
|
|
224
|
-
if (isImageUrl(inner) && !found.has(inner))
|
|
225
|
-
found.set(inner, { src: inner, alt: humanize(key || 'image') });
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (Array.isArray(inner)) {
|
|
229
|
-
for (const item of inner)
|
|
230
|
-
imagesIn(item, key, depth + 1, found);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
if (isRow(inner))
|
|
234
|
-
for (const [child, entry] of Object.entries(inner))
|
|
235
|
-
imagesIn(entry, child, depth + 1, found);
|
|
236
|
-
}
|
|
237
206
|
/** What a tool's output leads with. Empty when nothing stands out: the data alone reads best. */
|
|
238
207
|
export function layoutResult(output) {
|
|
239
208
|
const value = unpacked(output);
|
|
240
|
-
const images = new Map();
|
|
241
|
-
imagesIn(value, '', 0, images);
|
|
242
209
|
return {
|
|
243
210
|
figures: leadFigures(value),
|
|
244
211
|
charts: chartsIn(value, '', '', undefined, 0).slice(0, MAX_CHARTS),
|
|
245
|
-
images: [...images.values()],
|
|
246
212
|
};
|
|
247
213
|
}
|
|
248
214
|
function mediaSrc(part) {
|
|
249
215
|
return part.mimeType && part.data ? `data:${part.mimeType};base64,${part.data}` : undefined;
|
|
250
216
|
}
|
|
251
|
-
/** The images and audio a call returned, each with its bytes; parts without them are left out. */
|
|
252
|
-
export function returnedMedia(
|
|
217
|
+
/** The images and audio a call returned, each with its bytes; parts without them (references) are left out. */
|
|
218
|
+
export function returnedMedia(parts, imageAlt) {
|
|
253
219
|
const sourced = parts.flatMap((part) => {
|
|
254
220
|
const src = mediaSrc(part);
|
|
255
221
|
return src ? [{ type: part.type, src, mimeType: part.mimeType }] : [];
|
|
256
222
|
});
|
|
257
223
|
return {
|
|
258
|
-
images:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
],
|
|
224
|
+
images: sourced
|
|
225
|
+
.filter((part) => part.type === 'image')
|
|
226
|
+
.map(({ src }) => ({ src, alt: imageAlt })),
|
|
262
227
|
audio: sourced
|
|
263
228
|
.filter((part) => part.type === 'audio')
|
|
264
229
|
.map(({ src, mimeType }) => ({ src, ...(mimeType ? { mimeType } : {}) })),
|
|
265
230
|
};
|
|
266
231
|
}
|
|
232
|
+
/** The references a call returned, which only the app's resolver turns into something to show. */
|
|
233
|
+
export function referencesIn(parts) {
|
|
234
|
+
return parts.flatMap((part) => part.uri !== undefined && part.mimeType !== undefined && isMediaKind(part.type)
|
|
235
|
+
? [{ type: part.type, mimeType: part.mimeType, uri: part.uri }]
|
|
236
|
+
: []);
|
|
237
|
+
}
|
|
238
|
+
function isMediaKind(type) {
|
|
239
|
+
return MEDIA_INPUT_KIND_VALUES.includes(type);
|
|
240
|
+
}
|
|
267
241
|
/** Whether the result has anything to lead with above its data. */
|
|
268
242
|
export function hasLead(layout, media) {
|
|
269
243
|
return (layout.figures.length + layout.charts.length + media.images.length + media.audio.length > 0);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import { reasoningPartSchema, TURN_STOP_KINDS, turnEventSchema, z, } from '@theoremjs/agents';
|
|
7
|
+
import { MEDIA_INPUT_KIND_VALUES, reasoningPartSchema, TURN_STOP_KINDS, turnEventSchema, z, } from '@theoremjs/agents';
|
|
8
8
|
import { guardrailEventSchema } from '@theoremjs/agents/guardrails';
|
|
9
9
|
// why: The block shapes' event parts have one schema, the turn event's; a probe event reuses it.
|
|
10
10
|
function eventPart(probe) {
|
|
@@ -74,8 +74,10 @@ const transcriptBlock = z.discriminatedUnion('kind', [
|
|
|
74
74
|
kind: z.literal('media'),
|
|
75
75
|
mimeType: z.string(),
|
|
76
76
|
data: z.string().optional(),
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
uri: z.string().optional(),
|
|
78
|
+
type: z.enum(MEDIA_INPUT_KIND_VALUES).optional(),
|
|
79
|
+
fromTool: z.literal(true).optional(),
|
|
80
|
+
sent: z.literal(true).optional(),
|
|
79
81
|
}),
|
|
80
82
|
z.object({
|
|
81
83
|
...blockId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/web",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.926.g05c82e3",
|
|
4
4
|
"description": "Theorem on the web platform, with no UI framework: Web-standard server handlers that serve a profile, and the browser client that talks to them.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"zod": "^4.6.5",
|
|
28
|
-
"@theoremjs/agents": "^0.3.5-next.
|
|
28
|
+
"@theoremjs/agents": "^0.3.5-next.926.g05c82e3"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/server/mcp-handler.js
CHANGED
|
@@ -144,7 +144,8 @@ function callResult(events, labels) {
|
|
|
144
144
|
return {
|
|
145
145
|
content: [
|
|
146
146
|
{ type: 'text', text: tool.readBack ?? '' },
|
|
147
|
-
|
|
147
|
+
// why: A hidden tool's model read only `readBack`; what it sent is for the person, not this agent.
|
|
148
|
+
...(tool.hidden ? [] : (tool.parts ?? []).flatMap(partContent)),
|
|
148
149
|
],
|
|
149
150
|
isError: false,
|
|
150
151
|
};
|
|
@@ -165,17 +166,23 @@ function callResult(events, labels) {
|
|
|
165
166
|
isError: true,
|
|
166
167
|
};
|
|
167
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* A part as MCP content, as a model reads it: text and bytes. The client is another agent, so a
|
|
171
|
+
* reference, which no model reads, is left out.
|
|
172
|
+
*/
|
|
168
173
|
function partContent(part, index) {
|
|
169
174
|
if (part.type === 'text')
|
|
170
|
-
return { type: 'text', text: part.text };
|
|
171
|
-
if ('
|
|
172
|
-
return
|
|
175
|
+
return [{ type: 'text', text: part.text }];
|
|
176
|
+
if (!('data' in part))
|
|
177
|
+
return [];
|
|
173
178
|
if (part.type === 'image' || part.type === 'audio')
|
|
174
|
-
return { type: part.type, data: part.data, mimeType: part.mimeType };
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
return [{ type: part.type, data: part.data, mimeType: part.mimeType }];
|
|
180
|
+
return [
|
|
181
|
+
{
|
|
182
|
+
type: 'resource',
|
|
183
|
+
resource: { uri: `part:${index}`, mimeType: part.mimeType, blob: part.data },
|
|
184
|
+
},
|
|
185
|
+
];
|
|
179
186
|
}
|
|
180
187
|
/** Same origin, or one the host lists; a request with no `Origin` is not from a page. */
|
|
181
188
|
function originAllowed(request, origins) {
|