supermemory/apps/mcp/scripts/build-widget.ts
Prasanna721 7e7e820489 fix mcp app contracts (#1394)
Fixes MCP app submission metadata and makes widget delivery consistent across hosts.

- content-hash widget resources and set the production widget domain
- add typed structured outputs to direct tools and scope default-space calls
- keep graph rendering compatible with both initial results and app-side loading

Tested with `bun run check-types` and `bun run test:unit` (42 tests).
2026-08-01 06:41:17 +00:00

29 lines
1.1 KiB
TypeScript

import { createHash } from "node:crypto"
import { mkdir, readFile, writeFile } from "node:fs/promises"
import { fileURLToPath } from "node:url"
import { build } from "vite"
import { WIDGET_RESOURCE_META } from "../src/server/widget-resource-metadata"
const appRoot = fileURLToPath(new URL("../", import.meta.url))
const htmlUrl = new URL("../dist/src/widget/index.html", import.meta.url)
const manifestUrl = new URL("../dist/widget-manifest.json", import.meta.url)
const artifactsUrl = new URL("../dist/widgets/", import.meta.url)
await build({
configFile: fileURLToPath(new URL("../vite.config.ts", import.meta.url)),
root: appRoot,
})
const html = await readFile(htmlUrl, "utf8")
const sha256 = createHash("sha256")
.update(JSON.stringify({ html, meta: WIDGET_RESOURCE_META }))
.digest("hex")
const resourceUri = `ui://supermemory/app-${sha256}.html`
const manifest = { resourceUri, sha256 }
await mkdir(artifactsUrl, { recursive: true })
await writeFile(manifestUrl, `${JSON.stringify(manifest, null, 2)}\n`)
await writeFile(
new URL(`${sha256}.json`, artifactsUrl),
`${JSON.stringify({ ...manifest, html, meta: WIDGET_RESOURCE_META })}\n`,
)