holon-ui 0.0.1-dev.21 → 0.0.1-dev.23
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 -0
- package/package.json +1 -1
- package/runtime.d.ts +12 -9
- package/runtime.host.mjs +7 -3
- package/runtime.web.mjs +18 -8
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ const app = await connect({
|
|
|
70
70
|
select_shapes: {
|
|
71
71
|
description: "Select shapes on the board the person is looking at.",
|
|
72
72
|
inputSchema: z.object({ ids: z.array(z.string()) }),
|
|
73
|
+
outputSchema: z.object({ selected: z.array(z.string()) }),
|
|
73
74
|
annotations: { destructiveHint: false, openWorldHint: false },
|
|
74
75
|
execute: ({ ids }) => ({ selected: board.select(ids) }),
|
|
75
76
|
},
|
package/package.json
CHANGED
package/runtime.d.ts
CHANGED
|
@@ -5,20 +5,23 @@ export type { CreateOptions, EndpointBinding, Identity, Contract, RuntimeClient
|
|
|
5
5
|
export type { AuthProvider, CallOptions, CallMetadata, ToolResult, ToolClient } from "holon-sh/runtime";
|
|
6
6
|
export { bindApps, ToolCallError } from "holon-sh/runtime";
|
|
7
7
|
|
|
8
|
-
/** A tool the page declares. It runs in the browser and acts on what the person is looking at. S
|
|
9
|
-
export interface PageTool<S = undefined> {
|
|
8
|
+
/** A tool the page declares. It runs in the browser and acts on what the person is looking at. S and O are its input and output schemas' types. */
|
|
9
|
+
export interface PageTool<S = undefined, O = undefined> {
|
|
10
10
|
/** Shown to the agent. Required and non-empty. */
|
|
11
11
|
description: string;
|
|
12
12
|
/** Validates the agent's arguments, such as a Zod 4 object. Without one the tool takes no arguments. */
|
|
13
13
|
inputSchema?: S & StandardSchemaWithJSON;
|
|
14
|
+
/** Describes and validates the object execute returns, such as a Zod 4 object. */
|
|
15
|
+
outputSchema?: O & StandardSchemaWithJSON;
|
|
14
16
|
annotations?: ToolAnnotations;
|
|
15
17
|
/** Receives validated input. Returns a JSON value, or a promise of one; throwing reports failure. signal aborts when the agent cancels. */
|
|
16
|
-
execute: (input: S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : Record<string, never>, options: { signal: AbortSignal }) => unknown;
|
|
18
|
+
execute: (input: S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : Record<string, never>, options: { signal: AbortSignal }) => O extends StandardSchemaV1 ? StandardSchemaV1.InferInput<O> | Promise<StandardSchemaV1.InferInput<O>> : unknown;
|
|
17
19
|
}
|
|
18
|
-
// S
|
|
19
|
-
export interface ConnectOptions<S extends Record<string, unknown> = {}> {
|
|
20
|
+
// S and O are inferred per tool. A tool without a schema leaves its slot unknown, so the slots are unconstrained.
|
|
21
|
+
export interface ConnectOptions<S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}> {
|
|
20
22
|
/** Page tools by name, offered to the host's agent in an MCP Apps host and to the browser's agent through WebMCP. */
|
|
21
|
-
tools?: { [K in keyof S]: PageTool<S[K]> };
|
|
23
|
+
tools?: { [K in keyof S]: PageTool<S[K], O[K & keyof O]> } & { [K in keyof O]: { outputSchema?: O[K] & StandardSchemaWithJSON } };
|
|
24
|
+
/** On a web page, also offer call_tools, which runs several of the other offered tools in one call. Ignored in an MCP Apps host, whose agent calls the app's tools itself. */
|
|
22
25
|
batch?: "call_tools" extends keyof S ? false : boolean;
|
|
23
26
|
/** The ext-apps App's options in an MCP Apps host, and the transport to connect it with; ignored on a web page. */
|
|
24
27
|
view?: AppOptions & { transport?: Parameters<App["connect"]>[0] };
|
|
@@ -49,9 +52,9 @@ export type Page<C> =
|
|
|
49
52
|
readonly opened: undefined;
|
|
50
53
|
});
|
|
51
54
|
/** connect, narrowed by the generated #holon-ui module to the client C of the project's own app. A page tool cannot take the name of one of the app's tools. */
|
|
52
|
-
export type Connect<C> = <S extends Record<string, unknown> = {}>(options?: ConnectOptions<S> & { tools?: { [K in keyof Tools<C>]?: never }; batch?: "call_tools" extends keyof Tools<C> ? false : boolean }) => Promise<Page<C>>;
|
|
55
|
+
export type Connect<C> = <S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(options?: ConnectOptions<S, O> & { tools?: { [K in keyof Tools<C>]?: never }; batch?: "call_tools" extends keyof Tools<C> ? false : boolean }) => Promise<Page<C>>;
|
|
53
56
|
/** Bind the page to its own app on the surface its build chose, and offer every tool to whichever agent is present. Most pages call the generated connect from #holon-ui. */
|
|
54
|
-
export declare function connect<S extends Record<string, unknown> = {}>(
|
|
57
|
+
export declare function connect<S extends Record<string, unknown> = {}, O extends Record<string, unknown> = {}>(
|
|
55
58
|
app: { identity: Identity; contracts: Record<string, Contract | null>; own: string; /** The app's MCP endpoint on the page's origin, such as "/mcp/checkout". */ endpoint: string },
|
|
56
|
-
options?: ConnectOptions<S>,
|
|
59
|
+
options?: ConnectOptions<S, O>,
|
|
57
60
|
): Promise<Page<RuntimeClient>>;
|
package/runtime.host.mjs
CHANGED
|
@@ -11,10 +11,14 @@ export async function connect({ identity, contracts, own }, { tools = {}, view:
|
|
|
11
11
|
const bind = session => bindApps(identity, contracts, { [own]: { session } })[own];
|
|
12
12
|
const app = new App({ name: identity.name, version: identity.version }, {}, options);
|
|
13
13
|
// Registered before connecting, so the view declares the tools capability in ui/initialize.
|
|
14
|
-
for (const [name, { description, inputSchema, annotations, execute }] of Object.entries(tools)) {
|
|
14
|
+
for (const [name, { description, inputSchema, outputSchema, annotations, execute }] of Object.entries(tools)) {
|
|
15
|
+
const output = outputSchema?.["~standard"];
|
|
15
16
|
const run = async (input, { mcpReq: { signal } }) => {
|
|
16
17
|
try {
|
|
17
|
-
|
|
18
|
+
const result = await execute(input, { signal });
|
|
19
|
+
const checked = output ? await output.validate(result) : { value: result };
|
|
20
|
+
if (checked.issues) throw new Error(`Invalid output for ${name}: ${JSON.stringify(checked.issues)}`);
|
|
21
|
+
return toolResult(checked.value);
|
|
18
22
|
} catch (error) {
|
|
19
23
|
// A tool's own failure is a result the agent can read, not a protocol error.
|
|
20
24
|
// https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling
|
|
@@ -22,7 +26,7 @@ export async function connect({ identity, contracts, own }, { tools = {}, view:
|
|
|
22
26
|
}
|
|
23
27
|
};
|
|
24
28
|
// ext-apps validates input against inputSchema first, and calls a tool without one with the request context alone.
|
|
25
|
-
app.registerTool(name, { description, inputSchema, annotations }, inputSchema ? run : extra => run({}, extra));
|
|
29
|
+
app.registerTool(name, { description, inputSchema, outputSchema: output && { "~standard": { ...output, validate: value => ({ value }) } }, annotations }, inputSchema ? run : extra => run({}, extra));
|
|
26
30
|
}
|
|
27
31
|
// The host sends the call that opened the view once, right after the handshake, so listen before connecting.
|
|
28
32
|
// https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#data-passing
|
package/runtime.web.mjs
CHANGED
|
@@ -17,10 +17,9 @@ export async function connect({ identity, contracts, own, endpoint }, { tools =
|
|
|
17
17
|
const offered = new Map();
|
|
18
18
|
const register = tool => context.registerTool(tool, { signal }).then(() => true, error => console.warn(`WebMCP did not accept the tool ${tool.name}:`, error));
|
|
19
19
|
const offer = async tool => await register(tool) && offered.set(tool.name, tool);
|
|
20
|
-
|
|
21
|
-
for (const [name, tool] of Object.entries(tools)) offer(pageTool(name, tool));
|
|
20
|
+
const offers = Object.entries(tools).map(([name, tool]) => offer(pageTool(name, tool)));
|
|
22
21
|
const contracted = name => !contracts[own] || contracts[own].tools.some(tool => tool.name === name);
|
|
23
|
-
client.listTools({ signal }).then(
|
|
22
|
+
const listed = client.listTools({ signal }).then(
|
|
24
23
|
({ tools: listed }) => {
|
|
25
24
|
for (const tool of listed) {
|
|
26
25
|
// MCP Apps: a tool whose visibility omits "model" must not reach the agent; absent means ["model", "app"].
|
|
@@ -28,24 +27,30 @@ export async function connect({ identity, contracts, own, endpoint }, { tools =
|
|
|
28
27
|
// A typed client calls only its contract's tools, and an agent cannot write a file argument.
|
|
29
28
|
if (!(tool._meta?.ui?.visibility ?? ["model"]).includes("model") || !contracted(tool.name)) continue;
|
|
30
29
|
const inputSchema = withoutFiles(tool.inputSchema);
|
|
31
|
-
if (inputSchema !== FILE) offer(serverTool(own, client, tool, inputSchema));
|
|
30
|
+
if (inputSchema !== FILE) offers.push(offer(serverTool(own, client, tool, inputSchema)));
|
|
32
31
|
}
|
|
33
32
|
},
|
|
34
33
|
error => signal.aborted || console.warn(`Could not list the tools of ${own} for WebMCP:`, error),
|
|
35
34
|
);
|
|
35
|
+
if (batch) listed.then(() => Promise.all(offers)).then(() => offered.size && register(batchTool(offered)));
|
|
36
36
|
}
|
|
37
37
|
return Object.freeze({ ...client, view: undefined, opened: undefined, close: async () => { lifetime.abort(); await client.close(); } });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function pageTool(name, { description, inputSchema, annotations, execute }) {
|
|
40
|
+
function pageTool(name, { description, inputSchema, outputSchema, annotations, execute }) {
|
|
41
41
|
const standard = inputSchema?.["~standard"];
|
|
42
|
+
const output = outputSchema?.["~standard"];
|
|
42
43
|
return {
|
|
43
44
|
name, title: annotations?.title, description, annotations: hints(annotations),
|
|
44
45
|
inputSchema: standard?.jsonSchema.input({ target: "draft-2020-12" }),
|
|
46
|
+
outputSchema: output?.jsonSchema.output({ target: "draft-2020-12" }),
|
|
45
47
|
execute: async (input, { signal }) => {
|
|
46
48
|
const parsed = standard ? await standard.validate(input) : { value: {} };
|
|
47
49
|
if (parsed.issues) throw new Error(`Invalid arguments for ${name}: ${JSON.stringify(parsed.issues)}`);
|
|
48
|
-
|
|
50
|
+
const result = await execute(parsed.value, { signal });
|
|
51
|
+
const checked = output ? await output.validate(result) : { value: result };
|
|
52
|
+
if (checked.issues) throw new Error(`Invalid output for ${name}: ${JSON.stringify(checked.issues)}`);
|
|
53
|
+
return checked.value;
|
|
49
54
|
},
|
|
50
55
|
};
|
|
51
56
|
}
|
|
@@ -65,12 +70,17 @@ function serverTool(own, client, tool, inputSchema) {
|
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
function batchTool(offered) {
|
|
68
|
-
const call = { type: "object", properties: { tool: {
|
|
73
|
+
const call = { type: "object", properties: { tool: { enum: [...offered.keys()] }, input: { type: "object" } }, required: ["tool", "input"] };
|
|
74
|
+
const members = [...offered.values()].map(tool => tool.annotations);
|
|
69
75
|
return {
|
|
70
76
|
name: "call_tools",
|
|
71
77
|
description: "Run several of this page's tools in order, in one call. Stops at the first that fails, and returns the outputs before it and its error.",
|
|
72
78
|
inputSchema: { type: "object", properties: { calls: { type: "array", items: call } }, required: ["calls"] },
|
|
73
|
-
annotations:
|
|
79
|
+
annotations: {
|
|
80
|
+
readOnlyHint: members.every(hint => hint.readOnlyHint),
|
|
81
|
+
consequentialHint: members.some(hint => hint.consequentialHint),
|
|
82
|
+
untrustedContentHint: members.some(hint => hint.untrustedContentHint),
|
|
83
|
+
},
|
|
74
84
|
execute: async ({ calls }, client) => {
|
|
75
85
|
const outputs = [];
|
|
76
86
|
try {
|