holon-ui 0.0.1-dev.14 → 0.0.1-dev.15
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/package.json +1 -1
- package/runtime.d.ts +19 -8
- package/runtime.host.mjs +1 -2
- package/runtime.web.mjs +1 -1
package/package.json
CHANGED
package/runtime.d.ts
CHANGED
|
@@ -27,17 +27,28 @@ type Tools<C> = C extends { tools: infer T } ? T : never;
|
|
|
27
27
|
export type Opened<C> =
|
|
28
28
|
| { [K in keyof Tools<C> & string]: Tools<C>[K] extends (input: infer I, ...rest: never[]) => Promise<infer O> ? { tool: K; input: I; output: O } : never }[keyof Tools<C> & string]
|
|
29
29
|
| { tool: undefined; input: Record<string, unknown>; output: unknown };
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
readonly
|
|
34
|
-
/** In an MCP Apps host, the tool call that opened the view, with the output its tool returns; undefined on a web page. */
|
|
35
|
-
readonly opened: Promise<Opened<C>> | undefined;
|
|
30
|
+
type Resources<C> = C extends { readonly resources: infer R } ? R : never;
|
|
31
|
+
/** What a view can do with its app: call its tools and read its resources. */
|
|
32
|
+
type Relayed<C> = Pick<C, Extract<keyof C, "tools" | "callTool" | "close">> & {
|
|
33
|
+
readonly resources: { readonly [U in keyof Resources<C>]: Pick<Resources<C>[U], Extract<keyof Resources<C>[U], "read">> };
|
|
36
34
|
};
|
|
35
|
+
/** The page's own app C, as a view in an MCP Apps host or as a web page, told apart by view. Only a web page can list the app's tools, watch a resource or subscribe to events. close() also unregisters the page's tools and closes the view. */
|
|
36
|
+
export type Page<C> =
|
|
37
|
+
| (Relayed<C> & {
|
|
38
|
+
/** The connected ext-apps App, for host-only features. */
|
|
39
|
+
readonly view: App;
|
|
40
|
+
/** The tool call that opened the view, with the output its tool returns. */
|
|
41
|
+
readonly opened: Promise<Opened<C>>;
|
|
42
|
+
})
|
|
43
|
+
| (C & {
|
|
44
|
+
/** Undefined on a web page. */
|
|
45
|
+
readonly view: undefined;
|
|
46
|
+
readonly opened: undefined;
|
|
47
|
+
});
|
|
37
48
|
/** 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. */
|
|
38
49
|
export type Connect<C> = <S extends Record<string, unknown> = {}>(options?: ConnectOptions<S> & { tools?: { [K in keyof Tools<C>]?: never } }) => Promise<Page<C>>;
|
|
39
50
|
/** 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. */
|
|
40
|
-
export declare function connect<S extends Record<string, unknown> = {}>(
|
|
41
|
-
app: { identity: Identity; contracts: Record<string, Contract | null>; own:
|
|
51
|
+
export declare function connect<S extends Record<string, unknown> = {}, Own extends string = string>(
|
|
52
|
+
app: { identity: Identity; /** Must include the contract of the page's own app. */ contracts: Record<string, Contract | null> & Record<NoInfer<Own>, Contract>; own: Own; /** The app's MCP endpoint on the page's origin, such as "/mcp/checkout". */ endpoint: string },
|
|
42
53
|
options?: ConnectOptions<S>,
|
|
43
54
|
): Promise<Page<RuntimeClient>>;
|
package/runtime.host.mjs
CHANGED
|
@@ -46,10 +46,9 @@ export async function connect({ identity, contracts, own }, { tools = {}, view:
|
|
|
46
46
|
const client = bind({
|
|
47
47
|
callTool: (request, { signal, timeout }) => app.callServerTool(request, { signal, timeout }),
|
|
48
48
|
readResource: (request, { signal, timeout }) => app.readServerResource(request, { signal, timeout }),
|
|
49
|
-
listTools: async () => { throw new Error("An MCP Apps host owns the tool catalog, so a view cannot list tools."); },
|
|
50
49
|
});
|
|
51
50
|
// Closing the view removes its tools from the host.
|
|
52
|
-
return Object.freeze({
|
|
51
|
+
return Object.freeze({ tools: client.tools, callTool: client.callTool, resources: client.resources, view: app, opened, close: () => app.close() });
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
function toolResult(value) {
|
package/runtime.web.mjs
CHANGED
|
@@ -16,7 +16,7 @@ export async function connect({ identity, contracts, own, endpoint }, { tools =
|
|
|
16
16
|
const { signal } = lifetime;
|
|
17
17
|
const offer = tool => context.registerTool(tool, { signal }).catch(error => console.warn(`WebMCP did not accept the tool ${tool.name}:`, error));
|
|
18
18
|
for (const [name, tool] of Object.entries(tools)) offer(pageTool(name, tool));
|
|
19
|
-
const contracted = name =>
|
|
19
|
+
const contracted = name => contracts[own].tools.some(tool => tool.name === name);
|
|
20
20
|
client.listTools({ signal }).then(
|
|
21
21
|
({ tools: listed }) => {
|
|
22
22
|
for (const tool of listed) {
|