@womp/mcp-ui 0.1.3 → 0.1.5
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 +8 -2
- package/dist/cart/index.html +284 -0
- package/dist/image/index.html +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -6
- package/dist/mesh/index.html +1 -1
- package/dist/order/index.html +187 -0
- package/dist/print/index.html +62 -18
- package/package.json +5 -3
- package/src/cart/index.html +210 -0
- package/src/cart/main.ts +157 -0
- package/src/order/index.html +113 -0
- package/src/order/main.ts +110 -0
- package/src/print/index.html +61 -17
- package/src/print/main.ts +210 -55
- package/src/shared/bridge.ts +22 -1
package/src/shared/bridge.ts
CHANGED
|
@@ -69,6 +69,13 @@ export interface CardHooks {
|
|
|
69
69
|
onResult: (data: GenerationResult) => void;
|
|
70
70
|
/** Called when a poll gives up. */
|
|
71
71
|
onTimeout?: () => void;
|
|
72
|
+
/**
|
|
73
|
+
* Called with the tool call's ARGUMENTS when the host announces the input
|
|
74
|
+
* (before any result exists). This is how a configurator card starts on the
|
|
75
|
+
* settings the model was asked for — "print it in resin-clear at 15cm" seeds
|
|
76
|
+
* the controls before the first quote lands.
|
|
77
|
+
*/
|
|
78
|
+
onInput?: (args: Record<string, unknown>) => void;
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
export interface Card {
|
|
@@ -148,7 +155,10 @@ export function createCard(name: string, hooks: CardHooks): Card {
|
|
|
148
155
|
};
|
|
149
156
|
|
|
150
157
|
// Before connect(), always.
|
|
151
|
-
app.ontoolinput = () =>
|
|
158
|
+
app.ontoolinput = (params) => {
|
|
159
|
+
hooks.onInput?.(((params as any)?.arguments as Record<string, unknown>) || {});
|
|
160
|
+
hooks.onResult({ status: "running" });
|
|
161
|
+
};
|
|
152
162
|
app.ontoolresult = (params) => handle(params?.structuredContent as GenerationResult);
|
|
153
163
|
app.onhostcontextchanged = (ctx) => {
|
|
154
164
|
if (ctx?.theme) applyDocumentTheme(ctx.theme);
|
|
@@ -181,6 +191,17 @@ export function openLink(app: App, url: string) {
|
|
|
181
191
|
return app.openLink({ url });
|
|
182
192
|
}
|
|
183
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Call a server tool through the host. Only works for tools that declare
|
|
196
|
+
* `visibility: ["model", "app"]` — the host refuses everything else, which is
|
|
197
|
+
* the security boundary keeping credit-spending tools out of widget reach.
|
|
198
|
+
* Returns the raw result; callers check `isError` themselves because an error
|
|
199
|
+
* here is normal UI state (bad material, mesh gone), not an exception.
|
|
200
|
+
*/
|
|
201
|
+
export async function callTool(app: App, name: string, args: Record<string, unknown>) {
|
|
202
|
+
return app.request({ method: "tools/call", params: { name, arguments: args } }, CallToolResultSchema);
|
|
203
|
+
}
|
|
204
|
+
|
|
184
205
|
/** Toggle fullscreen, trusting the host's answer over our request. */
|
|
185
206
|
export function toggleFullscreen(app: App) {
|
|
186
207
|
const isFull = document.documentElement.dataset.displayMode === "fullscreen";
|