@womp/mcp-ui 0.1.15 → 0.1.16
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 +9 -6
- package/dist/index.d.ts +4 -0
- package/dist/index.js +17 -8
- package/dist/openai-camera/index.html +9 -91
- package/dist/openai-quote/index.html +223 -0
- package/package.json +4 -3
- package/src/cart/main.ts +1 -1
- package/src/openai-camera/index.html +2 -84
- package/src/openai-camera/main.ts +23 -80
- package/src/openai-quote/index.html +149 -0
- package/src/openai-quote/main.ts +131 -0
- package/src/print/main.ts +3 -3
- package/src/shared/bridge.ts +41 -0
package/src/shared/bridge.ts
CHANGED
|
@@ -232,3 +232,44 @@ export function toggleFullscreen(app: App) {
|
|
|
232
232
|
if (res?.mode) document.documentElement.dataset.displayMode = res.mode;
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
|
+
|
|
236
|
+
/** What ChatGPT's own `window.openai` adds for things MCP Apps has no message for. */
|
|
237
|
+
interface OpenAiBridge {
|
|
238
|
+
openExternal?: (args: { href: string; redirectUrl?: false }) => unknown;
|
|
239
|
+
sendFollowUpMessage?: (args: { prompt: string }) => unknown;
|
|
240
|
+
}
|
|
241
|
+
const openAiBridge = () => (window as Window & { openai?: OpenAiBridge }).openai;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Open a page outside the chat, such as a checkout. ChatGPT opens a URL on one
|
|
245
|
+
* of the card's declared redirect domains (`openai/widgetCSP.redirect_domains`)
|
|
246
|
+
* without making the user confirm the link, but only through its own
|
|
247
|
+
* `openExternal`; every other host gets the standard `ui/open-link`.
|
|
248
|
+
* `redirectUrl: false` stops ChatGPT adding a query parameter of its own.
|
|
249
|
+
*/
|
|
250
|
+
export async function openExternal(app: App, url: string) {
|
|
251
|
+
const bridge = openAiBridge();
|
|
252
|
+
if (bridge?.openExternal) {
|
|
253
|
+
await bridge.openExternal({ href: url, redirectUrl: false });
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
await app.openLink({ url });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Post a message in the chat as the user, for a button that stands for
|
|
261
|
+
* something they would otherwise type ("Order it"): the model answers it like
|
|
262
|
+
* any other turn. False when the host takes no messages from a card.
|
|
263
|
+
*/
|
|
264
|
+
export async function sendChatMessage(app: App, text: string): Promise<boolean> {
|
|
265
|
+
if ((app.getHostCapabilities() as { message?: unknown } | undefined)?.message) {
|
|
266
|
+
const res = await app.sendMessage({ role: "user", content: [{ type: "text", text }] });
|
|
267
|
+
return !res.isError;
|
|
268
|
+
}
|
|
269
|
+
const bridge = openAiBridge();
|
|
270
|
+
if (bridge?.sendFollowUpMessage) {
|
|
271
|
+
await bridge.sendFollowUpMessage({ prompt: text });
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|