capable-kit 0.0.1-alpha.3 → 0.0.1-alpha.4
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 +21 -3
- package/dist/bin.mjs +14 -13
- package/dist/bin.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-AqKbVZ8Z.d.mts → index-DCrxWCTv.d.mts} +2 -2
- package/dist/{index-B2ru1zGQ.d.mts → index-DJ--zcWG.d.mts} +4 -4
- package/dist/mcp.d.mts +1 -1
- package/dist/mcp.mjs +1 -1
- package/dist/{mount--YHrgRHJ.mjs → mount-BEBJ2Tss.mjs} +13 -19
- package/dist/mount-BEBJ2Tss.mjs.map +1 -0
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +5 -5
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +2 -2
- package/dist/{src-DtSY5fzY.mjs → src-ChDFqZaE.mjs} +6 -6
- package/dist/{src-DtSY5fzY.mjs.map → src-ChDFqZaE.mjs.map} +1 -1
- package/dist/{src-DX2xrplP.mjs → src-D9pLpfeO.mjs} +2 -2
- package/dist/src-D9pLpfeO.mjs.map +1 -0
- package/docs/CONTEXT.md +108 -0
- package/docs/README.md +28 -0
- package/docs/internal/README.md +16 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +24 -0
- package/docs/internal/architecture.md +126 -0
- package/docs/internal/capability-first-model.md +154 -0
- package/docs/internal/implementation-friction.md +674 -0
- package/docs/internal/why-capable.md +94 -0
- package/docs/site/capable-orpc-and-trpc.mdx +133 -0
- package/docs/site/concepts/apps.mdx +217 -0
- package/docs/site/concepts/architecture.mdx +75 -0
- package/docs/site/concepts/capabilities.mdx +249 -0
- package/docs/site/concepts/errors.mdx +93 -0
- package/docs/site/hosting/any-fetch-host.mdx +74 -0
- package/docs/site/hosting/next-js.mdx +77 -0
- package/docs/site/hosting/standalone-server.mdx +94 -0
- package/docs/site/introduction.mdx +142 -0
- package/docs/site/patterns/composition.mdx +142 -0
- package/docs/site/patterns/remote-apps.mdx +117 -0
- package/docs/site/patterns/subscriptions.mdx +87 -0
- package/docs/site/quickstart.mdx +293 -0
- package/docs/site/reference/packages-and-entry-points.mdx +70 -0
- package/docs/site/reference/surface-metadata.mdx +84 -0
- package/docs/site/reference/the-cap-cli.mdx +81 -0
- package/docs/site/surfaces/ai-sdk.mdx +94 -0
- package/docs/site/surfaces/cli.mdx +138 -0
- package/docs/site/surfaces/eve.mdx +121 -0
- package/docs/site/surfaces/http-and-openapi.mdx +111 -0
- package/docs/site/surfaces/mcp.mdx +97 -0
- package/docs/site/surfaces/react-query.mdx +80 -0
- package/docs/site/surfaces/typescript.mdx +123 -0
- package/docs/site/surfaces.mdx +78 -0
- package/docs/site/why-capable.mdx +99 -0
- package/package.json +13 -3
- package/src/package.test.ts +101 -0
- package/dist/mount--YHrgRHJ.mjs.map +0 -1
- package/dist/src-DX2xrplP.mjs.map +0 -1
package/dist/runtime-support.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createHttpHandler } from "./src-
|
|
2
|
-
import { t as mcp } from "./mount
|
|
3
|
-
import { n as http, r as
|
|
1
|
+
import { t as createHttpHandler } from "./src-D9pLpfeO.mjs";
|
|
2
|
+
import { t as mcp } from "./mount-BEBJ2Tss.mjs";
|
|
3
|
+
import { n as http, r as protocol, t as createServer } from "./src-ChDFqZaE.mjs";
|
|
4
4
|
//#region packages/nitro-host/src/dev-index.ts
|
|
5
5
|
function devIndex() {
|
|
6
6
|
return {
|
|
@@ -551,12 +551,12 @@ function createCapableNitroEntry(options) {
|
|
|
551
551
|
if (options.server) return options.dev ? withDevIndex(options.server, definition) : withProductionSplash(options.server, definition);
|
|
552
552
|
const server = createServer(definition, { mounts: options.dev ? [
|
|
553
553
|
devIndex(),
|
|
554
|
-
|
|
554
|
+
protocol(),
|
|
555
555
|
http(),
|
|
556
556
|
mcp()
|
|
557
557
|
] : [
|
|
558
558
|
productionSplash(),
|
|
559
|
-
|
|
559
|
+
protocol(),
|
|
560
560
|
http(),
|
|
561
561
|
mcp()
|
|
562
562
|
] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-support.mjs","names":["escapeHtml","styles"],"sources":["../../nitro-host/src/dev-index.ts","../../nitro-host/src/production-splash.ts","../../nitro-host/src/runtime-support.ts"],"sourcesContent":["import type {\n AppDefinition,\n LocatedCapability,\n} from \"@capable/core\";\nimport { createHttpHandler } from \"@capable/fetch\";\nimport type {\n CapableServer,\n ServerMount,\n} from \"@capable/server\";\n\nexport function devIndex(): ServerMount<any> {\n return {\n kind: \"capable.server.mount\",\n compile(app) {\n const html = renderDevIndex(app);\n return {\n name: \"dev-index\",\n fetch(request) {\n const url = new URL(request.url);\n if (request.method !== \"GET\" || url.pathname !== \"/\") {\n return undefined;\n }\n return new Response(html, {\n headers: { \"content-type\": \"text/html; charset=utf-8\" },\n });\n },\n };\n },\n };\n}\n\nexport function withDevIndex(\n server: CapableServer,\n app: AppDefinition<any, any>,\n): CapableServer {\n const index = devIndex().compile(app, undefined);\n return Object.freeze({\n async fetch(request) {\n return await index.fetch(request) ?? server.fetch(request);\n },\n });\n}\n\nexport function renderDevIndex(app: AppDefinition<any, any>): string {\n const routes = createHttpHandler(app).routes;\n const routeByCapability = new Map(\n routes.map((route) => [route.capability.capability, route]),\n );\n const capabilityCount = app.locatedCapabilities.length;\n const firstCommand = app.locatedCapabilities\n .map((entry) => cliCommand(entry))\n .find((command): command is string => command !== undefined);\n const capabilities = app.locatedCapabilities.map((entry) => {\n const capability = entry.capability;\n const route = routeByCapability.get(capability);\n const command = cliCommand(entry);\n const canOpen = route?.method === \"GET\" && capability.input === undefined;\n const badges = [\n capability.toMarkdown ? \"Markdown\" : undefined,\n capability.deprecated ? \"Deprecated\" : undefined,\n ].filter(Boolean) as string[];\n\n return `\n <article class=\"capability\">\n <div class=\"capability-head\">\n <div class=\"capability-title\">\n <h3>${escapeHtml(capability.title ?? entry.path.at(-1)!)}</h3>\n <span class=\"effect ${escapeHtml(capability.effect ?? \"unspecified\")}\">${escapeHtml(capability.effect ?? \"unspecified\")}</span>\n ${badges.map((badge) => `<span class=\"badge\">${escapeHtml(badge)}</span>`).join(\"\")}\n </div>\n ${canOpen\n ? `<a class=\"open\" href=\"${escapeHtml(route.path)}\">Open <span aria-hidden=\"true\">↗</span></a>`\n : \"\"}\n </div>\n ${capability.description\n ? `<p class=\"capability-description\">${escapeHtml(capability.description)}</p>`\n : \"\"}\n ${command ? command_(command) : \"\"}\n <div class=\"identity\">\n <span class=\"method\">${escapeHtml(route?.method ?? \"OP\")}</span>\n ${[\n route?.path ?? entry.path.join(\".\"),\n entry.path.join(\".\"),\n capability.id,\n ]\n .filter((value, index, all) => all.indexOf(value) === index)\n .map((value) => `<code>${escapeHtml(value)}</code>`)\n .join(`<span class=\"identity-sep\" aria-hidden=\"true\">·</span>`)}\n </div>\n </article>`;\n }).join(\"\");\n\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"color-scheme\" content=\"light dark\">\n <title>${escapeHtml(app.name)} · Capable</title>\n <style>${styles}</style>\n </head>\n <body>\n <header class=\"topbar\">\n <div class=\"shell nav\">\n <a class=\"brand\" href=\"/\" aria-label=\"Capable development home\">\n <span class=\"brand-mark\" aria-hidden=\"true\">C</span>\n <span>Capable</span>\n </a>\n <span class=\"environment\"><span aria-hidden=\"true\"></span>Development</span>\n </div>\n </header>\n\n <main class=\"shell\">\n <section class=\"hero\">\n <div class=\"title-row\">\n <h1>${escapeHtml(app.name)}</h1>\n <span class=\"version\">v${escapeHtml(app.version)}</span>\n </div>\n <p>${escapeHtml(app.description ?? \"A capability application powered by Capable.\")}</p>\n </section>\n\n <section class=\"cli\" aria-label=\"Command line\">\n <div class=\"cli-copy\">\n <h2>Run it from your terminal</h2>\n <p>Every capability below is already a command. No client, no URL, no code generation.</p>\n </div>\n <div class=\"cli-commands\">\n ${command_(\"--help\", \"List every command\")}\n ${firstCommand ? command_(firstCommand, \"Call a capability\") : \"\"}\n </div>\n </section>\n\n <section class=\"protocols\" aria-label=\"Application surfaces\">\n ${protocolLink(\"OpenAPI\", \"/openapi.json\", true)}\n ${protocolLink(\"Manifest\", \"/_capable/manifest\", true)}\n ${protocolLink(\"MCP\", \"/mcp\", false)}\n </section>\n\n <section class=\"capabilities-section\">\n <div class=\"section-heading\">\n <h2>Capabilities</h2>\n <span class=\"count\">${capabilityCount}</span>\n </div>\n <div class=\"capabilities\">\n ${capabilities || `<div class=\"empty\">No capabilities have been defined yet.</div>`}\n </div>\n </section>\n </main>\n\n <footer class=\"shell\">\n <span>Generated from the application definition</span>\n <a href=\"/_capable/manifest\">Application manifest <span aria-hidden=\"true\">→</span></a>\n </footer>\n <script>${script}</script>\n </body>\n</html>`;\n}\n\n/** A copyable `cap cli` invocation. Paths are relative, so no URL is needed. */\nfunction command_(command: string, label?: string): string {\n const full = `cap cli ${command}`;\n return `<div class=\"command\">\n ${label ? `<span class=\"command-label\">${escapeHtml(label)}</span>` : \"\"}\n <div class=\"command-line\">\n <span class=\"prompt\" aria-hidden=\"true\">$</span>\n <code>${escapeHtml(full)}</code>\n <button type=\"button\" class=\"copy\" data-copy=\"${escapeHtml(full)}\" aria-label=\"Copy command\">Copy</button>\n </div>\n </div>`;\n}\n\nfunction cliCommand(entry: LocatedCapability): string | undefined {\n const capabilityMeta = entry.capability.meta.cli as\n | false\n | {\n readonly name?: string;\n readonly command?: readonly string[];\n readonly positional?: readonly string[];\n }\n | undefined;\n if (capabilityMeta === false) return undefined;\n\n const command = [...entry.path];\n for (let index = 0; index < entry.groups.length; index++) {\n const groupMeta = entry.groups[index]?.meta.cli as\n | { readonly name?: string }\n | undefined;\n const groupPath = entry.groupPaths[index];\n if (groupMeta?.name && groupPath) {\n command[groupPath.length - 1] = groupMeta.name;\n }\n }\n if (capabilityMeta?.command) {\n command.splice(0, command.length, ...capabilityMeta.command);\n } else if (capabilityMeta?.name) {\n command[command.length - 1] = capabilityMeta.name;\n }\n return [...command, ...(capabilityMeta?.positional ?? []).map((name) =>\n `<${name}>`\n )].join(\" \");\n}\n\nfunction protocolLink(name: string, path: string, navigable: boolean): string {\n const content = `\n <span>${escapeHtml(name)}</span>\n <code>${escapeHtml(path)}</code>\n <span class=\"protocol-arrow\" aria-hidden=\"true\">${navigable ? \"↗\" : \"●\"}</span>`;\n return navigable\n ? `<a class=\"protocol\" href=\"${escapeHtml(path)}\">${content}</a>`\n : `<div class=\"protocol protocol-static\">${content}</div>`;\n}\n\nfunction escapeHtml(value: string): string {\n return value.replace(/[&<>\"']/g, (character) => ({\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n })[character]!);\n}\n\nconst styles = String.raw`\n :root {\n color-scheme: light;\n --background: #fff;\n --foreground: #0a0a0a;\n --secondary: #666;\n --muted: #8f8f8f;\n --border: #ebebeb;\n --border-strong: #dcdcdc;\n --subtle: #fafafa;\n --hover: #f5f5f5;\n --mark-bg: #0a0a0a;\n --mark-fg: #fff;\n --accent: #0070f3;\n }\n @media (prefers-color-scheme: dark) {\n :root {\n color-scheme: dark;\n --background: #000;\n --foreground: #ededed;\n --secondary: #a1a1a1;\n --muted: #737373;\n --border: #1f1f1f;\n --border-strong: #2e2e2e;\n --subtle: #0a0a0a;\n --hover: #141414;\n --mark-bg: #ededed;\n --mark-fg: #000;\n --accent: #3291ff;\n }\n }\n * { box-sizing: border-box; }\n body {\n margin: 0;\n min-height: 100vh;\n background: var(--background);\n color: var(--foreground);\n font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Inter, sans-serif;\n -webkit-font-smoothing: antialiased;\n }\n a { color: inherit; text-decoration: none; }\n code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }\n h1, h2, h3, p { margin: 0; }\n .shell { width: min(880px, calc(100% - 48px)); margin: 0 auto; }\n\n .topbar { position: sticky; top: 0; z-index: 10; height: 60px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--background) 85%, transparent); backdrop-filter: saturate(180%) blur(12px); }\n .nav { height: 100%; display: flex; align-items: center; justify-content: space-between; }\n .brand { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; letter-spacing: -.01em; }\n .brand-mark { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 6px; background: var(--mark-bg); color: var(--mark-fg); font-size: 12px; font-weight: 700; }\n .environment { display: inline-flex; align-items: center; gap: 7px; color: var(--secondary); font-size: 12px; }\n .environment > span { width: 6px; height: 6px; border-radius: 999px; background: #45a557; box-shadow: 0 0 0 3px color-mix(in srgb, #45a557 16%, transparent); }\n\n .hero { padding: 72px 0 40px; }\n .title-row { display: flex; align-items: baseline; gap: 12px; }\n h1 { font-size: clamp(30px, 5vw, 44px); font-weight: 600; letter-spacing: -.045em; line-height: 1.1; }\n .version { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }\n .hero > p { max-width: 600px; margin-top: 14px; color: var(--secondary); font-size: 16px; line-height: 1.6; }\n\n .cli { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 28px; align-items: center; padding: 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--subtle); }\n .cli-copy h2 { font-size: 16px; font-weight: 600; letter-spacing: -.02em; }\n .cli-copy p { margin-top: 6px; color: var(--secondary); font-size: 13px; line-height: 1.6; }\n .cli-commands { display: grid; gap: 10px; }\n\n .command { display: grid; gap: 6px; min-width: 0; }\n .command-label { color: var(--muted); font-size: 11px; letter-spacing: .02em; }\n .command-line { display: flex; align-items: center; gap: 9px; padding: 9px 9px 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--background); }\n .prompt { color: var(--muted); user-select: none; }\n .command-line code { flex: 1; overflow-x: auto; color: var(--foreground); font-size: 12.5px; white-space: nowrap; scrollbar-width: none; }\n .command-line code::-webkit-scrollbar { display: none; }\n .copy { flex: none; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; transition: color 120ms ease, background 120ms ease; }\n .copy:hover { background: var(--hover); color: var(--foreground); }\n .copy[data-copied=\"true\"] { color: #45a557; }\n\n .protocols { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 16px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }\n .protocol { position: relative; display: flex; min-width: 0; flex-direction: column; gap: 7px; padding: 16px 18px; border-right: 1px solid var(--border); transition: background 120ms ease; }\n .protocol:last-child { border-right: 0; }\n a.protocol:hover { background: var(--hover); }\n .protocol > span:first-child { font-size: 13px; font-weight: 550; }\n .protocol code { overflow: hidden; color: var(--secondary); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }\n .protocol-arrow { position: absolute; top: 16px; right: 16px; color: var(--muted); font-size: 11px; }\n .protocol-static .protocol-arrow { color: #45a557; font-size: 8px; }\n\n .capabilities-section { padding: 64px 0 40px; }\n .section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }\n h2 { font-size: 15px; font-weight: 600; letter-spacing: -.02em; }\n .count, .badge, .effect { border: 1px solid var(--border); border-radius: 999px; color: var(--secondary); font-size: 11px; line-height: 1; }\n .count { padding: 5px 8px; font-variant-numeric: tabular-nums; }\n .capabilities { display: grid; gap: 10px; }\n .capability { display: grid; gap: 12px; padding: 18px; border: 1px solid var(--border); border-radius: 12px; transition: border-color 120ms ease; }\n .capability:hover { border-color: var(--border-strong); }\n .capability-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }\n .capability-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }\n h3 { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }\n .effect, .badge { padding: 4px 7px; text-transform: capitalize; }\n .effect.read { color: #27833d; border-color: color-mix(in srgb, #27833d 28%, transparent); }\n .effect.write { color: #a16207; border-color: color-mix(in srgb, #a16207 28%, transparent); }\n .effect.destructive { color: #c03a36; border-color: color-mix(in srgb, #c03a36 28%, transparent); }\n .open { flex: none; color: var(--secondary); font-size: 12px; white-space: nowrap; }\n .open:hover { color: var(--foreground); }\n .capability-description { max-width: 640px; margin-top: -4px; color: var(--secondary); line-height: 1.55; }\n .identity { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 11.5px; }\n .identity code { color: var(--secondary); }\n .method { color: var(--foreground); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 11px; font-weight: 650; }\n .identity-sep { color: var(--border-strong); }\n .empty { padding: 40px; border: 1px dashed var(--border-strong); border-radius: 12px; color: var(--secondary); text-align: center; }\n\n footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 28px 0 48px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }\n footer a:hover { color: var(--foreground); }\n\n @media (max-width: 720px) {\n .shell { width: min(100% - 32px, 880px); }\n .hero { padding: 48px 0 32px; }\n .title-row { align-items: flex-start; flex-direction: column; gap: 8px; }\n .cli { grid-template-columns: 1fr; gap: 18px; }\n .protocols { grid-template-columns: 1fr; }\n .protocol { border-right: 0; border-bottom: 1px solid var(--border); }\n .protocol:last-child { border-bottom: 0; }\n .capabilities-section { padding-top: 48px; }\n .capability-head { align-items: flex-start; flex-direction: column; gap: 10px; }\n footer { align-items: flex-start; flex-direction: column; }\n }\n`;\n\nconst script = String.raw`\n document.addEventListener(\"click\", (event) => {\n const button = event.target.closest(\"button.copy\");\n if (!button) return;\n navigator.clipboard?.writeText(button.dataset.copy ?? \"\").then(() => {\n button.textContent = \"Copied\";\n button.dataset.copied = \"true\";\n setTimeout(() => {\n button.textContent = \"Copy\";\n delete button.dataset.copied;\n }, 1400);\n });\n });\n`;\n","import type { AppDefinition } from \"@capable/core\";\nimport type {\n CapableServer,\n ServerMount,\n} from \"@capable/server\";\n\nconst DEPLOYMENT_URL_PLACEHOLDER = \"{{DEPLOYMENT_URL}}\";\n\nexport function productionSplash(): ServerMount<any> {\n return {\n kind: \"capable.server.mount\",\n compile(app) {\n const html = renderProductionSplash(app);\n return {\n name: \"production-splash\",\n fetch(request) {\n const url = new URL(request.url);\n if (request.method !== \"GET\" || url.pathname !== \"/\") {\n return undefined;\n }\n return productionSplashResponse(html, request);\n },\n };\n },\n };\n}\n\nexport function withProductionSplash(\n server: CapableServer,\n app: AppDefinition<any, any>,\n): CapableServer {\n const splash = productionSplash().compile(app, undefined);\n return Object.freeze({\n async fetch(request) {\n return await splash.fetch(request) ?? server.fetch(request);\n },\n });\n}\n\nexport function renderProductionSplash(app: AppDefinition<any, any>): string {\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"color-scheme\" content=\"light dark\">\n <meta name=\"robots\" content=\"noindex\">\n <meta name=\"referrer\" content=\"no-referrer\">\n <title>${escapeHtml(app.name)} · Capable</title>\n <style>${styles}</style>\n </head>\n <body>\n <main>\n <section class=\"card\" aria-label=\"Deployment status\">\n <header>\n <h1>${escapeHtml(app.name)}</h1>\n <p class=\"status\">\n <span class=\"status-state\"><span class=\"status-dot\" aria-hidden=\"true\"></span>Ready</span>\n <span class=\"status-separator\" aria-hidden=\"true\">·</span>\n <span>Production</span>\n </p>\n </header>\n <div class=\"command\" role=\"group\" aria-label=\"Inspect from your terminal\">\n <div class=\"command-line\">\n <span class=\"command-prompt\" aria-hidden=\"true\">$</span>\n <code>capable cli --app ${DEPLOYMENT_URL_PLACEHOLDER} --help</code>\n </div>\n </div>\n <section class=\"endpoints\" aria-label=\"Deployment endpoints\">\n <a href=\"/openapi.json\">\n <span class=\"endpoint-name\">OpenAPI</span>\n <code class=\"endpoint-path\">/openapi.json</code>\n </a>\n <a href=\"/_capable/manifest\">\n <span class=\"endpoint-name\">Manifest</span>\n <code class=\"endpoint-path\">/_capable/manifest</code>\n </a>\n <div class=\"endpoint\">\n <span class=\"endpoint-name\">MCP</span>\n <code class=\"endpoint-path\">/mcp</code>\n </div>\n </section>\n </section>\n </main>\n </body>\n</html>`;\n}\n\nfunction productionSplashResponse(html: string, request: Request): Response {\n return new Response(\n html.replace(\n DEPLOYMENT_URL_PLACEHOLDER,\n () => escapeHtml(resolveDeploymentUrl(request)),\n ),\n {\n headers: {\n \"cache-control\": \"no-store\",\n \"content-security-policy\":\n \"default-src 'none'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'\",\n \"content-type\": \"text/html; charset=utf-8\",\n \"referrer-policy\": \"no-referrer\",\n \"x-content-type-options\": \"nosniff\",\n \"x-robots-tag\": \"noindex\",\n },\n },\n );\n}\n\nfunction resolveDeploymentUrl(request: Request): string {\n const url = new URL(request.url);\n const host = firstForwardedValue(request.headers.get(\"x-forwarded-host\")) ??\n request.headers.get(\"host\") ??\n url.host;\n const protocol =\n firstForwardedValue(request.headers.get(\"x-forwarded-proto\")) ??\n url.protocol.slice(0, -1);\n return `${protocol}://${host}`;\n}\n\nfunction firstForwardedValue(value: string | null): string | undefined {\n const first = value?.split(\",\")[0]?.trim();\n return first || undefined;\n}\n\nfunction escapeHtml(value: string): string {\n return value.replace(/[&<>\"']/g, (character) => ({\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n })[character]!);\n}\n\nconst styles = String.raw`\n :root {\n color-scheme: light dark;\n --background: #ffffff;\n --foreground: #0a0a0a;\n --muted: #575757;\n --faint: #737373;\n --border: rgba(0, 0, 0, .1);\n --surface: #fafafa;\n --accent: #087a4f;\n --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n --mono: ui-monospace, \"SF Mono\", Menlo, Monaco, Consolas, monospace;\n }\n @media (prefers-color-scheme: dark) {\n :root {\n --background: #0a0a0a;\n --foreground: #ededed;\n --muted: #a1a1a1;\n --faint: #8a8a8a;\n --border: rgba(255, 255, 255, .12);\n --surface: #131313;\n --accent: #3ecf8e;\n }\n }\n * { box-sizing: border-box; }\n html, body { margin: 0; }\n body {\n min-height: 100vh;\n min-height: 100dvh;\n display: grid;\n place-items: center;\n padding: 2rem;\n background: var(--background);\n color: var(--foreground);\n font: 15px/1.55 var(--sans);\n font-feature-settings: \"cv11\", \"ss01\";\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n }\n main {\n width: min(100%, 27rem);\n }\n .card { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }\n header { display: flex; flex-direction: column; gap: .5rem; }\n h1 {\n margin: 0;\n overflow-wrap: anywhere;\n font-size: 1.25rem;\n font-weight: 600;\n letter-spacing: -.021em;\n line-height: 1.3;\n }\n .status {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: .25rem .5rem;\n margin: 0;\n color: var(--muted);\n font-size: .875rem;\n line-height: 1.5;\n }\n .status-state {\n display: inline-flex;\n align-items: center;\n gap: .5rem;\n color: var(--accent);\n font-weight: 500;\n line-height: inherit;\n }\n .status-dot {\n width: 6px;\n height: 6px;\n flex: none;\n border-radius: 50%;\n background: currentColor;\n }\n .status-separator { color: var(--faint); }\n .command {\n display: flex;\n flex-direction: column;\n gap: .5rem;\n padding: 1rem 1.0625rem;\n border: 1px solid var(--border);\n border-radius: .5rem;\n background: var(--surface);\n }\n .command-line {\n display: flex;\n align-items: center;\n gap: .5rem;\n min-width: 0;\n }\n .command-prompt { color: var(--faint); user-select: none; }\n code {\n color: var(--foreground);\n font: .8125rem/1.6 var(--mono);\n font-feature-settings: \"zero\", \"ss01\";\n overflow-wrap: anywhere;\n }\n .endpoints {\n display: flex;\n flex-direction: column;\n border-top: 1px solid var(--border);\n }\n .endpoints a, .endpoint {\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n gap: 1rem;\n padding: .6875rem .125rem;\n border-bottom: 1px solid var(--border);\n color: var(--foreground);\n font-size: .8125rem;\n }\n .endpoints a {\n text-decoration: none;\n }\n .endpoint-name {\n font-weight: 500;\n }\n .endpoint-path {\n color: var(--faint);\n font-size: .75rem;\n text-align: right;\n transition: color .15s ease;\n }\n .endpoints a:hover .endpoint-path { color: var(--foreground); }\n .endpoints a:focus-visible {\n border-radius: 3px;\n outline: 2px solid var(--foreground);\n outline-offset: 2px;\n }\n @media (max-width: 30rem) {\n body { align-items: start; padding: 3rem 1.5rem 2rem; }\n }\n @media (prefers-reduced-motion: reduce) {\n * { transition: none !important; }\n }\n`;\n","import { mcp } from \"@capable/mcp/mount\";\nimport {\n createServer,\n http,\n standard,\n type CapableServer,\n} from \"@capable/server\";\nimport type { AppDefinition } from \"@capable/core\";\nimport { devIndex, withDevIndex } from \"./dev-index.ts\";\nimport {\n productionSplash,\n withProductionSplash,\n} from \"./production-splash.ts\";\n\nexport type CapableNitroEntryOptions = {\n /** The default export of the project's `capable.app.*`. */\n readonly definition: unknown;\n /** The default export of `capable.server.*`, when the project has one. */\n readonly server?: { readonly fetch: (request: Request) => unknown } | undefined;\n readonly dev: boolean;\n};\n\n/**\n * Build the server Nitro hosts. The generated entry in the project supplies the\n * project's own modules, so nothing here depends on how they were resolved.\n */\nexport function createCapableNitroEntry(\n options: CapableNitroEntryOptions,\n): CapableServer {\n const definition = options.definition as AppDefinition<any, undefined>;\n if (options.server) {\n return options.dev\n ? withDevIndex(options.server as never, definition)\n : withProductionSplash(options.server as never, definition);\n }\n const server = createServer(definition, {\n mounts: options.dev\n ? [devIndex(), standard(), http(), mcp()]\n : [productionSplash(), standard(), http(), mcp()],\n });\n return options.dev ? server : withProductionMetadataCache(server);\n}\n\nconst productionMetadataPaths = new Set([\n \"/_capable/manifest\",\n \"/openapi.json\",\n]);\n\nfunction withProductionMetadataCache(server: {\n readonly fetch: (request: Request) => Promise<Response>;\n}) {\n return {\n async fetch(request: Request): Promise<Response> {\n const response = await server.fetch(request);\n if (\n request.method === \"GET\" &&\n response.ok &&\n productionMetadataPaths.has(new URL(request.url).pathname)\n ) {\n response.headers.set(\n \"cache-control\",\n \"public, max-age=0, must-revalidate\",\n );\n response.headers.set(\n \"vercel-cdn-cache-control\",\n \"public, max-age=31536000\",\n );\n }\n return response;\n },\n };\n}\n"],"mappings":";;;;AAUA,SAAgB,WAA6B;CAC3C,OAAO;EACL,MAAM;EACN,QAAQ,KAAK;GACX,MAAM,OAAO,eAAe,GAAG;GAC/B,OAAO;IACL,MAAM;IACN,MAAM,SAAS;KACb,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;KAC/B,IAAI,QAAQ,WAAW,SAAS,IAAI,aAAa,KAC/C;KAEF,OAAO,IAAI,SAAS,MAAM,EACxB,SAAS,EAAE,gBAAgB,2BAA2B,EACxD,CAAC;IACH;GACF;EACF;CACF;AACF;AAEA,SAAgB,aACd,QACA,KACe;CACf,MAAM,QAAQ,SAAS,CAAC,CAAC,QAAQ,KAAK,KAAA,CAAS;CAC/C,OAAO,OAAO,OAAO,EACnB,MAAM,MAAM,SAAS;EACnB,OAAO,MAAM,MAAM,MAAM,OAAO,KAAK,OAAO,MAAM,OAAO;CAC3D,EACF,CAAC;AACH;AAEA,SAAgB,eAAe,KAAsC;CACnE,MAAM,SAAS,kBAAkB,GAAG,CAAC,CAAC;CACtC,MAAM,oBAAoB,IAAI,IAC5B,OAAO,KAAK,UAAU,CAAC,MAAM,WAAW,YAAY,KAAK,CAAC,CAC5D;CACA,MAAM,kBAAkB,IAAI,oBAAoB;CAChD,MAAM,eAAe,IAAI,oBACtB,KAAK,UAAU,WAAW,KAAK,CAAC,CAAC,CACjC,MAAM,YAA+B,YAAY,KAAA,CAAS;CAC7D,MAAM,eAAe,IAAI,oBAAoB,KAAK,UAAU;EAC1D,MAAM,aAAa,MAAM;EACzB,MAAM,QAAQ,kBAAkB,IAAI,UAAU;EAC9C,MAAM,UAAU,WAAW,KAAK;EAChC,MAAM,UAAU,OAAO,WAAW,SAAS,WAAW,UAAU,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,MAAM,MAAM,SAAqC;EAC/C,MAAM,WAAW,MAAM,OAAO,MAAM,OAAO;EAC3C,IACE,QAAQ,WAAW,SACnB,SAAS,MACT,wBAAwB,IAAI,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAC,QAAQ,GACzD;GACA,SAAS,QAAQ,IACf,iBACA,oCACF;GACA,SAAS,QAAQ,IACf,4BACA,0BACF;EACF;EACA,OAAO;CACT,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"runtime-support.mjs","names":["escapeHtml","styles"],"sources":["../../nitro-host/src/dev-index.ts","../../nitro-host/src/production-splash.ts","../../nitro-host/src/runtime-support.ts"],"sourcesContent":["import type {\n AppDefinition,\n LocatedCapability,\n} from \"@capable/core\";\nimport { createHttpHandler } from \"@capable/fetch\";\nimport type {\n CapableServer,\n ServerMount,\n} from \"@capable/server\";\n\nexport function devIndex(): ServerMount<any> {\n return {\n kind: \"capable.server.mount\",\n compile(app) {\n const html = renderDevIndex(app);\n return {\n name: \"dev-index\",\n fetch(request) {\n const url = new URL(request.url);\n if (request.method !== \"GET\" || url.pathname !== \"/\") {\n return undefined;\n }\n return new Response(html, {\n headers: { \"content-type\": \"text/html; charset=utf-8\" },\n });\n },\n };\n },\n };\n}\n\nexport function withDevIndex(\n server: CapableServer,\n app: AppDefinition<any, any>,\n): CapableServer {\n const index = devIndex().compile(app, undefined);\n return Object.freeze({\n async fetch(request) {\n return await index.fetch(request) ?? server.fetch(request);\n },\n });\n}\n\nexport function renderDevIndex(app: AppDefinition<any, any>): string {\n const routes = createHttpHandler(app).routes;\n const routeByCapability = new Map(\n routes.map((route) => [route.capability.capability, route]),\n );\n const capabilityCount = app.locatedCapabilities.length;\n const firstCommand = app.locatedCapabilities\n .map((entry) => cliCommand(entry))\n .find((command): command is string => command !== undefined);\n const capabilities = app.locatedCapabilities.map((entry) => {\n const capability = entry.capability;\n const route = routeByCapability.get(capability);\n const command = cliCommand(entry);\n const canOpen = route?.method === \"GET\" && capability.input === undefined;\n const badges = [\n capability.toMarkdown ? \"Markdown\" : undefined,\n capability.deprecated ? \"Deprecated\" : undefined,\n ].filter(Boolean) as string[];\n\n return `\n <article class=\"capability\">\n <div class=\"capability-head\">\n <div class=\"capability-title\">\n <h3>${escapeHtml(capability.title ?? entry.path.at(-1)!)}</h3>\n <span class=\"effect ${escapeHtml(capability.effect ?? \"unspecified\")}\">${escapeHtml(capability.effect ?? \"unspecified\")}</span>\n ${badges.map((badge) => `<span class=\"badge\">${escapeHtml(badge)}</span>`).join(\"\")}\n </div>\n ${canOpen\n ? `<a class=\"open\" href=\"${escapeHtml(route.path)}\">Open <span aria-hidden=\"true\">↗</span></a>`\n : \"\"}\n </div>\n ${capability.description\n ? `<p class=\"capability-description\">${escapeHtml(capability.description)}</p>`\n : \"\"}\n ${command ? command_(command) : \"\"}\n <div class=\"identity\">\n <span class=\"method\">${escapeHtml(route?.method ?? \"OP\")}</span>\n ${[\n route?.path ?? entry.path.join(\".\"),\n entry.path.join(\".\"),\n capability.id,\n ]\n .filter((value, index, all) => all.indexOf(value) === index)\n .map((value) => `<code>${escapeHtml(value)}</code>`)\n .join(`<span class=\"identity-sep\" aria-hidden=\"true\">·</span>`)}\n </div>\n </article>`;\n }).join(\"\");\n\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"color-scheme\" content=\"light dark\">\n <title>${escapeHtml(app.name)} · Capable</title>\n <style>${styles}</style>\n </head>\n <body>\n <header class=\"topbar\">\n <div class=\"shell nav\">\n <a class=\"brand\" href=\"/\" aria-label=\"Capable development home\">\n <span class=\"brand-mark\" aria-hidden=\"true\">C</span>\n <span>Capable</span>\n </a>\n <span class=\"environment\"><span aria-hidden=\"true\"></span>Development</span>\n </div>\n </header>\n\n <main class=\"shell\">\n <section class=\"hero\">\n <div class=\"title-row\">\n <h1>${escapeHtml(app.name)}</h1>\n <span class=\"version\">v${escapeHtml(app.version)}</span>\n </div>\n <p>${escapeHtml(app.description ?? \"A capability application powered by Capable.\")}</p>\n </section>\n\n <section class=\"cli\" aria-label=\"Command line\">\n <div class=\"cli-copy\">\n <h2>Run it from your terminal</h2>\n <p>Every capability below is already a command. No client, no URL, no code generation.</p>\n </div>\n <div class=\"cli-commands\">\n ${command_(\"--help\", \"List every command\")}\n ${firstCommand ? command_(firstCommand, \"Call a capability\") : \"\"}\n </div>\n </section>\n\n <section class=\"protocols\" aria-label=\"Application surfaces\">\n ${protocolLink(\"OpenAPI\", \"/openapi.json\", true)}\n ${protocolLink(\"Manifest\", \"/_capable/manifest\", true)}\n ${protocolLink(\"MCP\", \"/mcp\", false)}\n </section>\n\n <section class=\"capabilities-section\">\n <div class=\"section-heading\">\n <h2>Capabilities</h2>\n <span class=\"count\">${capabilityCount}</span>\n </div>\n <div class=\"capabilities\">\n ${capabilities || `<div class=\"empty\">No capabilities have been defined yet.</div>`}\n </div>\n </section>\n </main>\n\n <footer class=\"shell\">\n <span>Generated from the application definition</span>\n <a href=\"/_capable/manifest\">Application manifest <span aria-hidden=\"true\">→</span></a>\n </footer>\n <script>${script}</script>\n </body>\n</html>`;\n}\n\n/** A copyable `cap cli` invocation. Paths are relative, so no URL is needed. */\nfunction command_(command: string, label?: string): string {\n const full = `cap cli ${command}`;\n return `<div class=\"command\">\n ${label ? `<span class=\"command-label\">${escapeHtml(label)}</span>` : \"\"}\n <div class=\"command-line\">\n <span class=\"prompt\" aria-hidden=\"true\">$</span>\n <code>${escapeHtml(full)}</code>\n <button type=\"button\" class=\"copy\" data-copy=\"${escapeHtml(full)}\" aria-label=\"Copy command\">Copy</button>\n </div>\n </div>`;\n}\n\nfunction cliCommand(entry: LocatedCapability): string | undefined {\n const capabilityMeta = entry.capability.meta.cli as\n | false\n | {\n readonly name?: string;\n readonly command?: readonly string[];\n readonly positional?: readonly string[];\n }\n | undefined;\n if (capabilityMeta === false) return undefined;\n\n const command = [...entry.path];\n for (let index = 0; index < entry.groups.length; index++) {\n const groupMeta = entry.groups[index]?.meta.cli as\n | { readonly name?: string }\n | undefined;\n const groupPath = entry.groupPaths[index];\n if (groupMeta?.name && groupPath) {\n command[groupPath.length - 1] = groupMeta.name;\n }\n }\n if (capabilityMeta?.command) {\n command.splice(0, command.length, ...capabilityMeta.command);\n } else if (capabilityMeta?.name) {\n command[command.length - 1] = capabilityMeta.name;\n }\n return [...command, ...(capabilityMeta?.positional ?? []).map((name) =>\n `<${name}>`\n )].join(\" \");\n}\n\nfunction protocolLink(name: string, path: string, navigable: boolean): string {\n const content = `\n <span>${escapeHtml(name)}</span>\n <code>${escapeHtml(path)}</code>\n <span class=\"protocol-arrow\" aria-hidden=\"true\">${navigable ? \"↗\" : \"●\"}</span>`;\n return navigable\n ? `<a class=\"protocol\" href=\"${escapeHtml(path)}\">${content}</a>`\n : `<div class=\"protocol protocol-static\">${content}</div>`;\n}\n\nfunction escapeHtml(value: string): string {\n return value.replace(/[&<>\"']/g, (character) => ({\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n })[character]!);\n}\n\nconst styles = String.raw`\n :root {\n color-scheme: light;\n --background: #fff;\n --foreground: #0a0a0a;\n --secondary: #666;\n --muted: #8f8f8f;\n --border: #ebebeb;\n --border-strong: #dcdcdc;\n --subtle: #fafafa;\n --hover: #f5f5f5;\n --mark-bg: #0a0a0a;\n --mark-fg: #fff;\n --accent: #0070f3;\n }\n @media (prefers-color-scheme: dark) {\n :root {\n color-scheme: dark;\n --background: #000;\n --foreground: #ededed;\n --secondary: #a1a1a1;\n --muted: #737373;\n --border: #1f1f1f;\n --border-strong: #2e2e2e;\n --subtle: #0a0a0a;\n --hover: #141414;\n --mark-bg: #ededed;\n --mark-fg: #000;\n --accent: #3291ff;\n }\n }\n * { box-sizing: border-box; }\n body {\n margin: 0;\n min-height: 100vh;\n background: var(--background);\n color: var(--foreground);\n font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Inter, sans-serif;\n -webkit-font-smoothing: antialiased;\n }\n a { color: inherit; text-decoration: none; }\n code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }\n h1, h2, h3, p { margin: 0; }\n .shell { width: min(880px, calc(100% - 48px)); margin: 0 auto; }\n\n .topbar { position: sticky; top: 0; z-index: 10; height: 60px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--background) 85%, transparent); backdrop-filter: saturate(180%) blur(12px); }\n .nav { height: 100%; display: flex; align-items: center; justify-content: space-between; }\n .brand { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; letter-spacing: -.01em; }\n .brand-mark { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 6px; background: var(--mark-bg); color: var(--mark-fg); font-size: 12px; font-weight: 700; }\n .environment { display: inline-flex; align-items: center; gap: 7px; color: var(--secondary); font-size: 12px; }\n .environment > span { width: 6px; height: 6px; border-radius: 999px; background: #45a557; box-shadow: 0 0 0 3px color-mix(in srgb, #45a557 16%, transparent); }\n\n .hero { padding: 72px 0 40px; }\n .title-row { display: flex; align-items: baseline; gap: 12px; }\n h1 { font-size: clamp(30px, 5vw, 44px); font-weight: 600; letter-spacing: -.045em; line-height: 1.1; }\n .version { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }\n .hero > p { max-width: 600px; margin-top: 14px; color: var(--secondary); font-size: 16px; line-height: 1.6; }\n\n .cli { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 28px; align-items: center; padding: 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--subtle); }\n .cli-copy h2 { font-size: 16px; font-weight: 600; letter-spacing: -.02em; }\n .cli-copy p { margin-top: 6px; color: var(--secondary); font-size: 13px; line-height: 1.6; }\n .cli-commands { display: grid; gap: 10px; }\n\n .command { display: grid; gap: 6px; min-width: 0; }\n .command-label { color: var(--muted); font-size: 11px; letter-spacing: .02em; }\n .command-line { display: flex; align-items: center; gap: 9px; padding: 9px 9px 9px 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--background); }\n .prompt { color: var(--muted); user-select: none; }\n .command-line code { flex: 1; overflow-x: auto; color: var(--foreground); font-size: 12.5px; white-space: nowrap; scrollbar-width: none; }\n .command-line code::-webkit-scrollbar { display: none; }\n .copy { flex: none; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; transition: color 120ms ease, background 120ms ease; }\n .copy:hover { background: var(--hover); color: var(--foreground); }\n .copy[data-copied=\"true\"] { color: #45a557; }\n\n .protocols { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 16px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }\n .protocol { position: relative; display: flex; min-width: 0; flex-direction: column; gap: 7px; padding: 16px 18px; border-right: 1px solid var(--border); transition: background 120ms ease; }\n .protocol:last-child { border-right: 0; }\n a.protocol:hover { background: var(--hover); }\n .protocol > span:first-child { font-size: 13px; font-weight: 550; }\n .protocol code { overflow: hidden; color: var(--secondary); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }\n .protocol-arrow { position: absolute; top: 16px; right: 16px; color: var(--muted); font-size: 11px; }\n .protocol-static .protocol-arrow { color: #45a557; font-size: 8px; }\n\n .capabilities-section { padding: 64px 0 40px; }\n .section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }\n h2 { font-size: 15px; font-weight: 600; letter-spacing: -.02em; }\n .count, .badge, .effect { border: 1px solid var(--border); border-radius: 999px; color: var(--secondary); font-size: 11px; line-height: 1; }\n .count { padding: 5px 8px; font-variant-numeric: tabular-nums; }\n .capabilities { display: grid; gap: 10px; }\n .capability { display: grid; gap: 12px; padding: 18px; border: 1px solid var(--border); border-radius: 12px; transition: border-color 120ms ease; }\n .capability:hover { border-color: var(--border-strong); }\n .capability-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }\n .capability-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }\n h3 { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }\n .effect, .badge { padding: 4px 7px; text-transform: capitalize; }\n .effect.read { color: #27833d; border-color: color-mix(in srgb, #27833d 28%, transparent); }\n .effect.write { color: #a16207; border-color: color-mix(in srgb, #a16207 28%, transparent); }\n .effect.destructive { color: #c03a36; border-color: color-mix(in srgb, #c03a36 28%, transparent); }\n .open { flex: none; color: var(--secondary); font-size: 12px; white-space: nowrap; }\n .open:hover { color: var(--foreground); }\n .capability-description { max-width: 640px; margin-top: -4px; color: var(--secondary); line-height: 1.55; }\n .identity { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 11.5px; }\n .identity code { color: var(--secondary); }\n .method { color: var(--foreground); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 11px; font-weight: 650; }\n .identity-sep { color: var(--border-strong); }\n .empty { padding: 40px; border: 1px dashed var(--border-strong); border-radius: 12px; color: var(--secondary); text-align: center; }\n\n footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 28px 0 48px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }\n footer a:hover { color: var(--foreground); }\n\n @media (max-width: 720px) {\n .shell { width: min(100% - 32px, 880px); }\n .hero { padding: 48px 0 32px; }\n .title-row { align-items: flex-start; flex-direction: column; gap: 8px; }\n .cli { grid-template-columns: 1fr; gap: 18px; }\n .protocols { grid-template-columns: 1fr; }\n .protocol { border-right: 0; border-bottom: 1px solid var(--border); }\n .protocol:last-child { border-bottom: 0; }\n .capabilities-section { padding-top: 48px; }\n .capability-head { align-items: flex-start; flex-direction: column; gap: 10px; }\n footer { align-items: flex-start; flex-direction: column; }\n }\n`;\n\nconst script = String.raw`\n document.addEventListener(\"click\", (event) => {\n const button = event.target.closest(\"button.copy\");\n if (!button) return;\n navigator.clipboard?.writeText(button.dataset.copy ?? \"\").then(() => {\n button.textContent = \"Copied\";\n button.dataset.copied = \"true\";\n setTimeout(() => {\n button.textContent = \"Copy\";\n delete button.dataset.copied;\n }, 1400);\n });\n });\n`;\n","import type { AppDefinition } from \"@capable/core\";\nimport type {\n CapableServer,\n ServerMount,\n} from \"@capable/server\";\n\nconst DEPLOYMENT_URL_PLACEHOLDER = \"{{DEPLOYMENT_URL}}\";\n\nexport function productionSplash(): ServerMount<any> {\n return {\n kind: \"capable.server.mount\",\n compile(app) {\n const html = renderProductionSplash(app);\n return {\n name: \"production-splash\",\n fetch(request) {\n const url = new URL(request.url);\n if (request.method !== \"GET\" || url.pathname !== \"/\") {\n return undefined;\n }\n return productionSplashResponse(html, request);\n },\n };\n },\n };\n}\n\nexport function withProductionSplash(\n server: CapableServer,\n app: AppDefinition<any, any>,\n): CapableServer {\n const splash = productionSplash().compile(app, undefined);\n return Object.freeze({\n async fetch(request) {\n return await splash.fetch(request) ?? server.fetch(request);\n },\n });\n}\n\nexport function renderProductionSplash(app: AppDefinition<any, any>): string {\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"color-scheme\" content=\"light dark\">\n <meta name=\"robots\" content=\"noindex\">\n <meta name=\"referrer\" content=\"no-referrer\">\n <title>${escapeHtml(app.name)} · Capable</title>\n <style>${styles}</style>\n </head>\n <body>\n <main>\n <section class=\"card\" aria-label=\"Deployment status\">\n <header>\n <h1>${escapeHtml(app.name)}</h1>\n <p class=\"status\">\n <span class=\"status-state\"><span class=\"status-dot\" aria-hidden=\"true\"></span>Ready</span>\n <span class=\"status-separator\" aria-hidden=\"true\">·</span>\n <span>Production</span>\n </p>\n </header>\n <div class=\"command\" role=\"group\" aria-label=\"Inspect from your terminal\">\n <div class=\"command-line\">\n <span class=\"command-prompt\" aria-hidden=\"true\">$</span>\n <code>capable cli --app ${DEPLOYMENT_URL_PLACEHOLDER} --help</code>\n </div>\n </div>\n <section class=\"endpoints\" aria-label=\"Deployment endpoints\">\n <a href=\"/openapi.json\">\n <span class=\"endpoint-name\">OpenAPI</span>\n <code class=\"endpoint-path\">/openapi.json</code>\n </a>\n <a href=\"/_capable/manifest\">\n <span class=\"endpoint-name\">Manifest</span>\n <code class=\"endpoint-path\">/_capable/manifest</code>\n </a>\n <div class=\"endpoint\">\n <span class=\"endpoint-name\">MCP</span>\n <code class=\"endpoint-path\">/mcp</code>\n </div>\n </section>\n </section>\n </main>\n </body>\n</html>`;\n}\n\nfunction productionSplashResponse(html: string, request: Request): Response {\n return new Response(\n html.replace(\n DEPLOYMENT_URL_PLACEHOLDER,\n () => escapeHtml(resolveDeploymentUrl(request)),\n ),\n {\n headers: {\n \"cache-control\": \"no-store\",\n \"content-security-policy\":\n \"default-src 'none'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'\",\n \"content-type\": \"text/html; charset=utf-8\",\n \"referrer-policy\": \"no-referrer\",\n \"x-content-type-options\": \"nosniff\",\n \"x-robots-tag\": \"noindex\",\n },\n },\n );\n}\n\nfunction resolveDeploymentUrl(request: Request): string {\n const url = new URL(request.url);\n const host = firstForwardedValue(request.headers.get(\"x-forwarded-host\")) ??\n request.headers.get(\"host\") ??\n url.host;\n const protocol =\n firstForwardedValue(request.headers.get(\"x-forwarded-proto\")) ??\n url.protocol.slice(0, -1);\n return `${protocol}://${host}`;\n}\n\nfunction firstForwardedValue(value: string | null): string | undefined {\n const first = value?.split(\",\")[0]?.trim();\n return first || undefined;\n}\n\nfunction escapeHtml(value: string): string {\n return value.replace(/[&<>\"']/g, (character) => ({\n \"&\": \"&\",\n \"<\": \"<\",\n \">\": \">\",\n '\"': \""\",\n \"'\": \"'\",\n })[character]!);\n}\n\nconst styles = String.raw`\n :root {\n color-scheme: light dark;\n --background: #ffffff;\n --foreground: #0a0a0a;\n --muted: #575757;\n --faint: #737373;\n --border: rgba(0, 0, 0, .1);\n --surface: #fafafa;\n --accent: #087a4f;\n --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n --mono: ui-monospace, \"SF Mono\", Menlo, Monaco, Consolas, monospace;\n }\n @media (prefers-color-scheme: dark) {\n :root {\n --background: #0a0a0a;\n --foreground: #ededed;\n --muted: #a1a1a1;\n --faint: #8a8a8a;\n --border: rgba(255, 255, 255, .12);\n --surface: #131313;\n --accent: #3ecf8e;\n }\n }\n * { box-sizing: border-box; }\n html, body { margin: 0; }\n body {\n min-height: 100vh;\n min-height: 100dvh;\n display: grid;\n place-items: center;\n padding: 2rem;\n background: var(--background);\n color: var(--foreground);\n font: 15px/1.55 var(--sans);\n font-feature-settings: \"cv11\", \"ss01\";\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n }\n main {\n width: min(100%, 27rem);\n }\n .card { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }\n header { display: flex; flex-direction: column; gap: .5rem; }\n h1 {\n margin: 0;\n overflow-wrap: anywhere;\n font-size: 1.25rem;\n font-weight: 600;\n letter-spacing: -.021em;\n line-height: 1.3;\n }\n .status {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: .25rem .5rem;\n margin: 0;\n color: var(--muted);\n font-size: .875rem;\n line-height: 1.5;\n }\n .status-state {\n display: inline-flex;\n align-items: center;\n gap: .5rem;\n color: var(--accent);\n font-weight: 500;\n line-height: inherit;\n }\n .status-dot {\n width: 6px;\n height: 6px;\n flex: none;\n border-radius: 50%;\n background: currentColor;\n }\n .status-separator { color: var(--faint); }\n .command {\n display: flex;\n flex-direction: column;\n gap: .5rem;\n padding: 1rem 1.0625rem;\n border: 1px solid var(--border);\n border-radius: .5rem;\n background: var(--surface);\n }\n .command-line {\n display: flex;\n align-items: center;\n gap: .5rem;\n min-width: 0;\n }\n .command-prompt { color: var(--faint); user-select: none; }\n code {\n color: var(--foreground);\n font: .8125rem/1.6 var(--mono);\n font-feature-settings: \"zero\", \"ss01\";\n overflow-wrap: anywhere;\n }\n .endpoints {\n display: flex;\n flex-direction: column;\n border-top: 1px solid var(--border);\n }\n .endpoints a, .endpoint {\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n gap: 1rem;\n padding: .6875rem .125rem;\n border-bottom: 1px solid var(--border);\n color: var(--foreground);\n font-size: .8125rem;\n }\n .endpoints a {\n text-decoration: none;\n }\n .endpoint-name {\n font-weight: 500;\n }\n .endpoint-path {\n color: var(--faint);\n font-size: .75rem;\n text-align: right;\n transition: color .15s ease;\n }\n .endpoints a:hover .endpoint-path { color: var(--foreground); }\n .endpoints a:focus-visible {\n border-radius: 3px;\n outline: 2px solid var(--foreground);\n outline-offset: 2px;\n }\n @media (max-width: 30rem) {\n body { align-items: start; padding: 3rem 1.5rem 2rem; }\n }\n @media (prefers-reduced-motion: reduce) {\n * { transition: none !important; }\n }\n`;\n","import { mcp } from \"@capable/mcp/mount\";\nimport {\n protocol,\n createServer,\n http,\n type CapableServer,\n} from \"@capable/server\";\nimport type { AppDefinition } from \"@capable/core\";\nimport { devIndex, withDevIndex } from \"./dev-index.ts\";\nimport {\n productionSplash,\n withProductionSplash,\n} from \"./production-splash.ts\";\n\nexport type CapableNitroEntryOptions = {\n /** The default export of the project's `capable.app.*`. */\n readonly definition: unknown;\n /** The default export of `capable.server.*`, when the project has one. */\n readonly server?: { readonly fetch: (request: Request) => unknown } | undefined;\n readonly dev: boolean;\n};\n\n/**\n * Build the server Nitro hosts. The generated entry in the project supplies the\n * project's own modules, so nothing here depends on how they were resolved.\n */\nexport function createCapableNitroEntry(\n options: CapableNitroEntryOptions,\n): CapableServer {\n const definition = options.definition as AppDefinition<any, undefined>;\n if (options.server) {\n return options.dev\n ? withDevIndex(options.server as never, definition)\n : withProductionSplash(options.server as never, definition);\n }\n const server = createServer(definition, {\n mounts: options.dev\n ? [devIndex(), protocol(), http(), mcp()]\n : [productionSplash(), protocol(), http(), mcp()],\n });\n return options.dev ? server : withProductionMetadataCache(server);\n}\n\nconst productionMetadataPaths = new Set([\n \"/_capable/manifest\",\n \"/openapi.json\",\n]);\n\nfunction withProductionMetadataCache(server: {\n readonly fetch: (request: Request) => Promise<Response>;\n}) {\n return {\n async fetch(request: Request): Promise<Response> {\n const response = await server.fetch(request);\n if (\n request.method === \"GET\" &&\n response.ok &&\n productionMetadataPaths.has(new URL(request.url).pathname)\n ) {\n response.headers.set(\n \"cache-control\",\n \"public, max-age=0, must-revalidate\",\n );\n response.headers.set(\n \"vercel-cdn-cache-control\",\n \"public, max-age=31536000\",\n );\n }\n return response;\n },\n };\n}\n"],"mappings":";;;;AAUA,SAAgB,WAA6B;CAC3C,OAAO;EACL,MAAM;EACN,QAAQ,KAAK;GACX,MAAM,OAAO,eAAe,GAAG;GAC/B,OAAO;IACL,MAAM;IACN,MAAM,SAAS;KACb,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;KAC/B,IAAI,QAAQ,WAAW,SAAS,IAAI,aAAa,KAC/C;KAEF,OAAO,IAAI,SAAS,MAAM,EACxB,SAAS,EAAE,gBAAgB,2BAA2B,EACxD,CAAC;IACH;GACF;EACF;CACF;AACF;AAEA,SAAgB,aACd,QACA,KACe;CACf,MAAM,QAAQ,SAAS,CAAC,CAAC,QAAQ,KAAK,KAAA,CAAS;CAC/C,OAAO,OAAO,OAAO,EACnB,MAAM,MAAM,SAAS;EACnB,OAAO,MAAM,MAAM,MAAM,OAAO,KAAK,OAAO,MAAM,OAAO;CAC3D,EACF,CAAC;AACH;AAEA,SAAgB,eAAe,KAAsC;CACnE,MAAM,SAAS,kBAAkB,GAAG,CAAC,CAAC;CACtC,MAAM,oBAAoB,IAAI,IAC5B,OAAO,KAAK,UAAU,CAAC,MAAM,WAAW,YAAY,KAAK,CAAC,CAC5D;CACA,MAAM,kBAAkB,IAAI,oBAAoB;CAChD,MAAM,eAAe,IAAI,oBACtB,KAAK,UAAU,WAAW,KAAK,CAAC,CAAC,CACjC,MAAM,YAA+B,YAAY,KAAA,CAAS;CAC7D,MAAM,eAAe,IAAI,oBAAoB,KAAK,UAAU;EAC1D,MAAM,aAAa,MAAM;EAC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,4BAA4B,MAAM;AAClE;AAEA,MAAM,0CAA0B,IAAI,IAAI,CACtC,sBACA,eACF,CAAC;AAED,SAAS,4BAA4B,QAElC;CACD,OAAO,EACL,MAAM,MAAM,SAAqC;EAC/C,MAAM,WAAW,MAAM,OAAO,MAAM,OAAO;EAC3C,IACE,QAAQ,WAAW,SACnB,SAAS,MACT,wBAAwB,IAAI,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAC,QAAQ,GACzD;GACA,SAAS,QAAQ,IACf,iBACA,oCACF;GACA,SAAS,QAAQ,IACf,4BACA,0BACF;EACF;EACA,OAAO;CACT,EACF;AACF"}
|
package/dist/server.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createServer, i as ServerMount, n as CompiledServerMount, o as http, r as ServerMiddleware, s as
|
|
2
|
-
export { CapableServer, CompiledServerMount, ServerMiddleware, ServerMount, createServer, http,
|
|
1
|
+
import { a as createServer, i as ServerMount, n as CompiledServerMount, o as http, r as ServerMiddleware, s as protocol, t as CapableServer } from "./index-DJ--zcWG.mjs";
|
|
2
|
+
export { CapableServer, CompiledServerMount, ServerMiddleware, ServerMount, createServer, http, protocol };
|
package/dist/server.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as http, r as
|
|
2
|
-
export { createServer, http,
|
|
1
|
+
import { n as http, r as protocol, t as createServer } from "./src-ChDFqZaE.mjs";
|
|
2
|
+
export { createServer, http, protocol };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as selectApp, o as createApp } from "./src-3UaBqI8H.mjs";
|
|
2
|
-
import { r as createProtocolHandler, t as createHttpHandler } from "./src-
|
|
2
|
+
import { r as createProtocolHandler, t as createHttpHandler } from "./src-D9pLpfeO.mjs";
|
|
3
3
|
//#region packages/server/src/index.ts
|
|
4
|
-
function
|
|
4
|
+
function protocol(options = {}) {
|
|
5
5
|
return {
|
|
6
6
|
kind: "capable.server.mount",
|
|
7
7
|
compile(app, context) {
|
|
@@ -11,7 +11,7 @@ function standard(options = {}) {
|
|
|
11
11
|
}, { ...options.path ? { basePath: options.path } : {} });
|
|
12
12
|
const base = normalizePath(options.path ?? "/_capable");
|
|
13
13
|
return {
|
|
14
|
-
name: "
|
|
14
|
+
name: "protocol",
|
|
15
15
|
async fetch(request) {
|
|
16
16
|
if (!new URL(request.url).pathname.startsWith(`${base}/`)) return;
|
|
17
17
|
return protocol.fetch(request);
|
|
@@ -46,7 +46,7 @@ function http(options = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
function createServer(app, ...[providedOptions]) {
|
|
48
48
|
const options = providedOptions ?? {};
|
|
49
|
-
const mounts = (options.mounts ?? [
|
|
49
|
+
const mounts = (options.mounts ?? [protocol(), http()]).map((mount) => mount.compile(app, options.context));
|
|
50
50
|
async function dispatch(request) {
|
|
51
51
|
for (const mount of mounts) {
|
|
52
52
|
const response = await mount.fetch(request);
|
|
@@ -77,6 +77,6 @@ function normalizePath(value) {
|
|
|
77
77
|
return `/${value.split("/").filter(Boolean).join("/")}`;
|
|
78
78
|
}
|
|
79
79
|
//#endregion
|
|
80
|
-
export { http as n,
|
|
80
|
+
export { http as n, protocol as r, createServer as t };
|
|
81
81
|
|
|
82
|
-
//# sourceMappingURL=src-
|
|
82
|
+
//# sourceMappingURL=src-ChDFqZaE.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-
|
|
1
|
+
{"version":3,"file":"src-ChDFqZaE.mjs","names":[],"sources":["../../server/src/index.ts"],"sourcesContent":["import type {\n AppDefinition,\n MaybePromise,\n} from \"@capable/core\";\nimport {\n createHttpHandler,\n createProtocolHandler,\n type ContextProvider,\n type CapabilitySelection,\n} from \"@capable/fetch\";\nimport {\n createApp,\n selectApp,\n type ApplicationSelection,\n} from \"@capable/app\";\n\nexport type ServerMount<TContext> = {\n readonly kind: \"capable.server.mount\";\n compile(\n app: AppDefinition<any, TContext>,\n context: ContextProvider<TContext> | undefined,\n ): CompiledServerMount;\n};\n\nexport type CompiledServerMount = {\n readonly name: string;\n readonly fetch: (request: Request) => MaybePromise<Response | undefined>;\n};\n\nexport function protocol<TContext = any>(\n options: {\n readonly path?: string;\n readonly selection?: ApplicationSelection;\n } = {},\n): ServerMount<TContext> {\n return {\n kind: \"capable.server.mount\",\n compile(app, context) {\n const protocol = createProtocolHandler(\n (request) => {\n const executable = createApp(\n app,\n context\n ? { context: () => context({ request }) }\n : undefined as never,\n );\n return options.selection\n ? selectApp(executable, options.selection)\n : executable;\n },\n {\n ...(options.path ? { basePath: options.path } : {}),\n },\n );\n const base = normalizePath(options.path ?? \"/_capable\");\n return {\n name: \"protocol\",\n async fetch(request) {\n if (!new URL(request.url).pathname.startsWith(`${base}/`)) {\n return undefined;\n }\n return protocol.fetch(request);\n },\n };\n },\n };\n}\n\nexport function http<TContext = any>(\n options: {\n readonly path?: string;\n readonly openapiPath?: string | false;\n readonly requireExplicitRoutes?: boolean;\n readonly selection?: CapabilitySelection;\n } = {},\n): ServerMount<TContext> {\n return {\n kind: \"capable.server.mount\",\n compile(app, context) {\n const handler = createHttpHandler(app, {\n ...(context ? { context } : {}),\n ...(options.path ? { basePath: options.path } : {}),\n ...(options.openapiPath !== undefined\n ? { openapiPath: options.openapiPath }\n : {}),\n ...(options.requireExplicitRoutes !== undefined\n ? { requireExplicitRoutes: options.requireExplicitRoutes }\n : {}),\n ...(options.selection ? { selection: options.selection } : {}),\n });\n const base = normalizePath(options.path ?? \"/api\");\n const openapiPath = options.openapiPath === false\n ? undefined\n : normalizePath(options.openapiPath ?? \"/openapi.json\");\n return {\n name: \"http\",\n async fetch(request) {\n const pathname = new URL(request.url).pathname;\n if (\n !pathname.startsWith(`${base}/`) &&\n pathname !== base &&\n pathname !== openapiPath\n ) {\n return undefined;\n }\n return handler.fetch(request);\n },\n };\n },\n };\n}\n\nexport type CapableServer = {\n readonly fetch: (request: Request) => Promise<Response>;\n};\n\nexport type ServerMiddleware = (args: {\n readonly request: Request;\n readonly next: (request?: Request) => Promise<Response>;\n}) => MaybePromise<Response>;\n\ntype CreateServerOptions<TContext> = {\n readonly context?: ContextProvider<TContext>;\n readonly mounts?: readonly ServerMount<TContext>[];\n readonly middleware?: ServerMiddleware;\n readonly onError?: (error: unknown) => void;\n};\n\ntype CreateServerArgs<TContext> = [TContext] extends [undefined]\n ? [options?: CreateServerOptions<TContext>]\n : [options: CreateServerOptions<TContext> & {\n readonly context: ContextProvider<TContext>;\n }];\n\nexport function createServer<TContext>(\n app: AppDefinition<any, TContext>,\n ...[providedOptions]: CreateServerArgs<TContext>\n): CapableServer {\n const options = (providedOptions ?? {}) as CreateServerOptions<TContext>;\n const mounts = (options.mounts ?? [protocol(), http()])\n .map((mount) => mount.compile(app, options.context));\n\n async function dispatch(request: Request): Promise<Response> {\n for (const mount of mounts) {\n const response = await mount.fetch(request);\n if (response) return response;\n }\n return new Response(\"Not Found\", { status: 404 });\n }\n\n return Object.freeze({\n async fetch(request: Request) {\n try {\n return options.middleware\n ? await options.middleware({\n request,\n next: (nextRequest = request) => dispatch(nextRequest),\n })\n : await dispatch(request);\n } catch (error) {\n options.onError?.(error);\n return Response.json({\n ok: false,\n error: {\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Internal Server Error\",\n status: 500,\n },\n }, { status: 500 });\n }\n },\n });\n}\n\nfunction normalizePath(value: string): string {\n return `/${value.split(\"/\").filter(Boolean).join(\"/\")}`;\n}\n"],"mappings":";;;AA6BA,SAAgB,SACd,UAGI,CAAC,GACkB;CACvB,OAAO;EACL,MAAM;EACN,QAAQ,KAAK,SAAS;GACpB,MAAM,WAAW,uBACd,YAAY;IACX,MAAM,aAAa,UACjB,KACA,UACI,EAAE,eAAe,QAAQ,EAAE,QAAQ,CAAC,EAAE,IACtC,KAAA,CACN;IACA,OAAO,QAAQ,YACX,UAAU,YAAY,QAAQ,SAAS,IACvC;GACN,GACA,EACE,GAAI,QAAQ,OAAO,EAAE,UAAU,QAAQ,KAAK,IAAI,CAAC,EACnD,CACF;G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AAO,CAAC;CAErD,eAAe,SAAS,SAAqC;EAC3D,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,WAAW,MAAM,MAAM,MAAM,OAAO;GAC1C,IAAI,UAAU,OAAO;EACvB;EACA,OAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;CAClD;CAEA,OAAO,OAAO,OAAO,EACnB,MAAM,MAAM,SAAkB;EAC5B,IAAI;GACF,OAAO,QAAQ,aACX,MAAM,QAAQ,WAAW;IACzB;IACA,OAAO,cAAc,YAAY,SAAS,WAAW;GACvD,CAAC,IACC,MAAM,SAAS,OAAO;EAC5B,SAAS,OAAO;GACd,QAAQ,UAAU,KAAK;GACvB,OAAO,SAAS,KAAK;IACnB,IAAI;IACJ,OAAO;KACL,MAAM;KACN,SAAS;KACT,QAAQ;IACV;GACF,GAAG,EAAE,QAAQ,IAAI,CAAC;EACpB;CACF,EACF,CAAC;AACH;AAEA,SAAS,cAAc,OAAuB;CAC5C,OAAO,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACtD"}
|
|
@@ -18,7 +18,7 @@ function capabilityErrorResponse(error, fallbackStatus = 500) {
|
|
|
18
18
|
}, { status: data.status });
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
|
-
//#region packages/fetch/src/
|
|
21
|
+
//#region packages/fetch/src/capable.ts
|
|
22
22
|
function createProtocolHandler(application, options = {}) {
|
|
23
23
|
const basePath = normalizePath$1(options.basePath ?? "/_capable");
|
|
24
24
|
const fetch = async (request) => {
|
|
@@ -454,4 +454,4 @@ function joinPath(...parts) {
|
|
|
454
454
|
//#endregion
|
|
455
455
|
export { createHttpTransport as n, createProtocolHandler as r, createHttpHandler as t };
|
|
456
456
|
|
|
457
|
-
//# sourceMappingURL=src-
|
|
457
|
+
//# sourceMappingURL=src-D9pLpfeO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-D9pLpfeO.mjs","names":["normalizePath"],"sources":["../../fetch/src/error-response.ts","../../fetch/src/capable.ts","../../fetch/src/http.ts"],"sourcesContent":["import { CapableError } from \"@capable/core\";\nimport { TransportError } from \"@capable/app\";\n\nexport type CapabilityErrorData = {\n readonly code: string;\n readonly message: string;\n readonly status: number;\n readonly data?: unknown;\n};\n\nexport function capabilityErrorData(\n error: unknown,\n fallbackStatus = 500,\n): CapabilityErrorData {\n const capable = error instanceof CapableError || error instanceof TransportError\n ? error\n : new CapableError(\"INTERNAL_SERVER_ERROR\", { cause: error });\n return {\n code: capable.code,\n message: capable.message,\n status: capable.status ?? fallbackStatus,\n ...(capable.data === undefined ? {} : { data: capable.data }),\n };\n}\n\nexport function capabilityErrorResponse(\n error: unknown,\n fallbackStatus = 500,\n): Response {\n const data = capabilityErrorData(error, fallbackStatus);\n return Response.json({\n ok: false,\n error: data,\n }, { status: data.status });\n}\n","import {\n getAppRuntime,\n isApp,\n TransportError,\n type ApplicationManifest,\n type ApplicationTransport,\n type AnyApp,\n type CapabilityCall,\n type CapabilityResult,\n} from \"@capable/app\";\nimport {\n capabilityErrorData,\n capabilityErrorResponse,\n} from \"./error-response.ts\";\n\nexport type FetchHandler = (request: Request) => Response | Promise<Response>;\n\nexport function createProtocolHandler(\n application:\n | AnyApp\n | ((request: Request) => AnyApp | Promise<AnyApp>),\n options: {\n readonly basePath?: string;\n } = {},\n): {\n readonly fetch: FetchHandler;\n} {\n const basePath = normalizePath(options.basePath ?? \"/_capable\");\n\n const fetch: FetchHandler = async (request) => {\n const url = new URL(request.url);\n const app = isApp(application)\n ? application\n : await application(request);\n const runtime = getAppRuntime(app);\n if (url.pathname === `${basePath}/manifest` && request.method === \"GET\") {\n return Response.json(await runtime.manifest());\n }\n const subscribePrefix = `${basePath}/subscribe/`;\n if (\n url.pathname.startsWith(subscribePrefix) &&\n request.method === \"POST\"\n ) {\n const id = decodeURIComponent(\n url.pathname.slice(subscribePrefix.length),\n );\n const controller = new AbortController();\n let stream: AsyncIterableIterator<CapabilityResult> | undefined;\n try {\n const body = await request.json() as { readonly input?: unknown };\n stream = runtime.subscribe({\n id,\n input: body.input ?? {},\n signal: AbortSignal.any([request.signal, controller.signal]),\n });\n const first = await stream.next();\n return subscriptionResponse(stream, first, controller);\n } catch (error) {\n controller.abort();\n await stream?.return?.().catch(() => undefined);\n return capabilityErrorResponse(error);\n }\n }\n const callPrefix = `${basePath}/call/`;\n if (!url.pathname.startsWith(callPrefix) || request.method !== \"POST\") {\n return new Response(\"Not Found\", { status: 404 });\n }\n const id = decodeURIComponent(url.pathname.slice(callPrefix.length));\n try {\n const body = await request.json() as { readonly input?: unknown };\n const result = await runtime.call({\n id,\n input: body.input ?? {},\n signal: request.signal,\n });\n return Response.json({\n ok: true,\n ...result,\n });\n } catch (error) {\n return capabilityErrorResponse(error);\n }\n };\n\n return { fetch };\n}\n\nexport type TransportHeaders =\n | HeadersInit\n | (() => HeadersInit | Promise<HeadersInit>);\n\nexport function createHttpTransport(options: {\n readonly url: string | URL | (() => string | URL);\n readonly fetch?: (request: Request) => Response | Promise<Response>;\n readonly headers?: TransportHeaders;\n}): ApplicationTransport {\n const fetchImplementation = options.fetch ?? globalThis.fetch;\n\n async function request(\n path: string,\n init: RequestInit,\n ): Promise<Response> {\n const base = normalizeUrl(\n typeof options.url === \"function\" ? options.url() : options.url,\n );\n const configured = typeof options.headers === \"function\"\n ? await options.headers()\n : options.headers;\n const headers = new Headers(configured);\n new Headers(init.headers).forEach((value, name) => headers.set(name, value));\n return fetchImplementation(\n new Request(new URL(path, base), { ...init, headers }),\n );\n }\n\n return Object.freeze({\n async manifest(\n { signal }: { readonly signal?: AbortSignal } = {},\n ) {\n const response = await request(\"manifest\", {\n method: \"GET\",\n ...(signal ? { signal } : {}),\n });\n if (!response.ok) throw await responseError(response);\n return await responseJson<ApplicationManifest>(\n response,\n \"Application manifest\",\n );\n },\n async call({ id, input = {}, signal }: CapabilityCall) {\n const response = await request(`call/${encodeURIComponent(id)}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ input }),\n ...(signal ? { signal } : {}),\n });\n const body = await response.json() as\n | {\n readonly ok: true;\n readonly output: unknown;\n readonly markdown?: string;\n }\n | {\n readonly ok: false;\n readonly error: {\n readonly code: string;\n readonly message?: string;\n readonly status?: number;\n readonly data?: unknown;\n };\n };\n if (!body.ok) {\n throw new TransportError(body.error.code, body.error);\n }\n return {\n output: body.output,\n ...(body.markdown ? { markdown: body.markdown } : {}),\n };\n },\n async *subscribe({\n id,\n input = {},\n signal,\n }: CapabilityCall) {\n const response = await request(`subscribe/${encodeURIComponent(id)}`, {\n method: \"POST\",\n headers: {\n accept: \"text/event-stream\",\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({ input }),\n ...(signal ? { signal } : {}),\n });\n if (!response.ok) throw await responseError(response);\n yield* decodeEventStream(response);\n },\n });\n}\n\nfunction subscriptionResponse(\n stream: AsyncIterableIterator<CapabilityResult>,\n first: IteratorResult<CapabilityResult>,\n subscriptionController: AbortController,\n): Response {\n const encoder = new TextEncoder();\n let initial: IteratorResult<CapabilityResult> | undefined = first;\n\n return new Response(new ReadableStream({\n async pull(controller) {\n try {\n const result = initial ?? await stream.next();\n initial = undefined;\n if (result.done) {\n subscriptionController.abort();\n controller.close();\n return;\n }\n controller.enqueue(encoder.encode(sseFrame(\"output\", result.value)));\n } catch (error) {\n subscriptionController.abort();\n controller.enqueue(encoder.encode(\n sseFrame(\"error\", capabilityErrorData(error)),\n ));\n controller.close();\n await stream.return?.();\n }\n },\n async cancel() {\n subscriptionController.abort();\n await stream.return?.();\n },\n }, {\n highWaterMark: 0,\n }), {\n headers: {\n \"cache-control\": \"no-cache\",\n \"content-type\": \"text/event-stream; charset=utf-8\",\n },\n });\n}\n\nasync function* decodeEventStream(\n response: Response,\n): AsyncIterableIterator<CapabilityResult> {\n if (!response.headers.get(\"content-type\")?.includes(\"text/event-stream\")) {\n throw new TransportError(\"TRANSPORT_ERROR\", {\n status: response.status,\n message: \"Subscription response is not an event stream\",\n });\n }\n if (!response.body) {\n throw new TransportError(\"TRANSPORT_ERROR\", {\n status: response.status,\n message: \"Subscription response has no body\",\n });\n }\n\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n try {\n while (true) {\n const { done, value } = await reader.read();\n buffer += decoder.decode(value, { stream: !done });\n let boundary = eventBoundary(buffer);\n while (boundary) {\n const block = buffer.slice(0, boundary.index);\n buffer = buffer.slice(boundary.index + boundary.length);\n const event = parseEventBlock(block);\n if (event) {\n if (event.type === \"error\") {\n throw new TransportError(event.error.code, event.error);\n }\n yield event.result;\n }\n boundary = eventBoundary(buffer);\n }\n if (done) break;\n }\n } finally {\n await reader.cancel().catch(() => undefined);\n }\n}\n\nfunction eventBoundary(\n value: string,\n): { readonly index: number; readonly length: number } | undefined {\n const lf = value.indexOf(\"\\n\\n\");\n const crlf = value.indexOf(\"\\r\\n\\r\\n\");\n if (lf < 0 && crlf < 0) {\n return undefined;\n }\n if (crlf >= 0 && (lf < 0 || crlf < lf)) {\n return { index: crlf, length: 4 };\n }\n return { index: lf, length: 2 };\n}\n\nfunction parseEventBlock(block: string):\n | { readonly type: \"output\"; readonly result: CapabilityResult }\n | {\n readonly type: \"error\";\n readonly error: {\n readonly code: string;\n readonly message?: string;\n readonly status?: number;\n readonly data?: unknown;\n };\n }\n | undefined {\n let type = \"message\";\n const data: string[] = [];\n for (const line of block.replace(/\\r\\n/g, \"\\n\").split(\"\\n\")) {\n if (line.startsWith(\":\")) continue;\n if (line.startsWith(\"event:\")) type = line.slice(6).trim();\n if (line.startsWith(\"data:\")) data.push(line.slice(5).trimStart());\n }\n if (!data.length) return undefined;\n const value = JSON.parse(data.join(\"\\n\")) as any;\n return type === \"error\"\n ? { type: \"error\", error: value }\n : { type: \"output\", result: value };\n}\n\nfunction sseFrame(event: string, data: unknown): string {\n return `event: ${event}\\ndata: ${JSON.stringify(data)}\\n\\n`;\n}\n\nfunction normalizeUrl(value: string | URL): URL {\n const url = new URL(value);\n if (!url.pathname.endsWith(\"/\")) url.pathname += \"/\";\n url.search = \"\";\n url.hash = \"\";\n return url;\n}\n\nasync function responseError(response: Response): Promise<TransportError> {\n const text = await response.text().catch(() => \"\");\n let data: unknown = text;\n try {\n data = JSON.parse(text);\n } catch {\n // Preserve the response text as transport diagnostics.\n }\n if (\n data &&\n typeof data === \"object\" &&\n \"ok\" in data &&\n data.ok === false &&\n \"error\" in data &&\n data.error &&\n typeof data.error === \"object\" &&\n \"code\" in data.error &&\n typeof data.error.code === \"string\"\n ) {\n const error = data.error as {\n readonly code: string;\n readonly message?: unknown;\n readonly status?: unknown;\n readonly data?: unknown;\n };\n return new TransportError(error.code, {\n ...(typeof error.message === \"string\"\n ? { message: error.message }\n : {}),\n status: typeof error.status === \"number\"\n ? error.status\n : response.status,\n ...(\"data\" in error ? { data: error.data } : {}),\n });\n }\n return new TransportError(\"TRANSPORT_ERROR\", {\n status: response.status,\n message: `Transport request failed with ${response.status}`,\n data,\n });\n}\n\nasync function responseJson<T>(\n response: Response,\n label: string,\n): Promise<T> {\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.toLowerCase().includes(\"json\")) {\n throw new TransportError(\"TRANSPORT_ERROR\", {\n status: response.status,\n message:\n `${label} request returned ${contentType ?? \"a non-JSON response\"}${\n response.url ? ` from ${response.url}` : \"\"\n }`,\n });\n }\n try {\n return await response.json() as T;\n } catch (cause) {\n throw new TransportError(\"TRANSPORT_ERROR\", {\n status: response.status,\n message: `${label} response contained invalid JSON`,\n cause,\n });\n }\n}\n\nfunction normalizePath(value: string): string {\n return `/${value.split(\"/\").filter(Boolean).join(\"/\")}`;\n}\n","import {\n executeLocatedCapability,\n schemaToJsonSchema,\n type AppDefinition,\n type GroupMetaRegistry,\n type LocatedCapability,\n type CapabilityMetaRegistry,\n type CapabilityTree,\n} from \"@capable/core\";\nimport {\n type ApplicationSelection,\n type JsonSchema,\n} from \"@capable/app\";\nimport {\n capabilityErrorResponse,\n} from \"./error-response.ts\";\nimport type { FetchHandler } from \"./capable.ts\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\nexport type HttpCapabilityMeta =\n | false\n | {\n readonly method?: HttpMethod;\n readonly route?: string;\n readonly status?: number;\n };\n\nexport type HttpGroupMeta = {\n readonly prefix?: string;\n};\n\ndeclare module \"@capable/core\" {\n interface CapabilityMetaRegistry {\n readonly http?: HttpCapabilityMeta;\n }\n\n interface GroupMetaRegistry {\n readonly http?: HttpGroupMeta;\n }\n}\n\nexport type ContextProvider<TContext> = (args: {\n readonly request: Request;\n}) => TContext | Promise<TContext>;\n\nexport type CapabilitySelection<\n TTree extends CapabilityTree = CapabilityTree,\n> = ApplicationSelection<TTree>;\n\nexport type CompiledHttpRoute = {\n readonly method: HttpMethod;\n readonly path: string;\n readonly capability: LocatedCapability;\n};\n\nexport function createHttpHandler<\n const TCapabilities extends CapabilityTree,\n TContext,\n>(\n app: AppDefinition<TCapabilities, TContext>,\n options: {\n readonly context?: ContextProvider<TContext>;\n readonly basePath?: string;\n readonly openapiPath?: string | false;\n readonly requireExplicitRoutes?: boolean;\n readonly selection?: CapabilitySelection<TCapabilities>;\n } = {},\n): {\n readonly fetch: FetchHandler;\n readonly routes: readonly CompiledHttpRoute[];\n readonly openapi: Readonly<Record<string, unknown>>;\n} {\n const basePath = normalizePath(options.basePath ?? \"/api\");\n const selected = selectCapabilities(app.locatedCapabilities, options.selection)\n .filter((entry) => capabilityHttp(entry) !== false);\n const routes = selected.map((entry) => compileHttpRoute(entry, basePath));\n assertUniqueRoutes(routes);\n if (options.requireExplicitRoutes) {\n const implicit = selected.find((entry) => {\n const meta = capabilityHttp(entry);\n return !meta || !meta.method || !meta.route;\n });\n if (implicit) {\n throw new Error(\n `Capability \"${implicit.capability.id}\" requires an explicit HTTP method and route`,\n );\n }\n }\n const openapi = createOpenApi(app, routes);\n const openapiPath = options.openapiPath === false\n ? undefined\n : normalizePath(options.openapiPath ?? \"/openapi.json\");\n\n return {\n routes,\n openapi,\n async fetch(request) {\n const url = new URL(request.url);\n if (\n openapiPath &&\n url.pathname === openapiPath &&\n request.method === \"GET\"\n ) {\n return Response.json(openapi);\n }\n const match = routes\n .map((route) => ({ route, params: matchPath(route.path, url.pathname) }))\n .find(({ route, params }) => route.method === request.method && params);\n if (!match?.params) return new Response(\"Not Found\", { status: 404 });\n\n try {\n const input = await readHttpInput(\n request,\n match.params,\n match.route.capability.capability.input,\n );\n const context = options.context\n ? await options.context({ request })\n : undefined as TContext;\n const output = await executeLocatedCapability(match.route.capability, input, {\n context,\n signal: request.signal,\n });\n if (\n request.headers.get(\"accept\")?.includes(\"text/markdown\") &&\n match.route.capability.capability.toMarkdown\n ) {\n return new Response(\n await match.route.capability.capability.toMarkdown(output, { context }),\n {\n status: httpSuccessStatus(match.route.capability),\n headers: { \"content-type\": \"text/markdown; charset=utf-8\" },\n },\n );\n }\n return Response.json(output, {\n status: httpSuccessStatus(match.route.capability),\n });\n } catch (error) {\n return capabilityErrorResponse(error);\n }\n },\n };\n}\n\nfunction compileHttpRoute(\n entry: LocatedCapability,\n basePath: string,\n): CompiledHttpRoute {\n const meta = capabilityHttp(entry);\n const defaultPath = entry.path.flatMap((segment, index) => {\n const groupIndex = entry.groupPaths.findIndex(\n (path) => path.length === index + 1,\n );\n const prefix = groupIndex >= 0\n ? (entry.groups[groupIndex]?.meta.http as HttpGroupMeta | undefined)\n ?.prefix\n : undefined;\n return prefix ? prefix.split(\"/\").filter(Boolean) : [segment];\n }).join(\"/\");\n const groupPrefix = entry.groups.flatMap((group) => {\n const prefix = (group.meta.http as HttpGroupMeta | undefined)?.prefix;\n return prefix ? prefix.split(\"/\").filter(Boolean) : [];\n }).join(\"/\");\n const authoredRoute = meta && meta.route ? meta.route : defaultPath;\n assertPathParameters(entry, authoredRoute);\n return Object.freeze({\n method: meta && meta.method\n ? meta.method\n : entry.capability.effect === \"read\"\n ? \"GET\"\n : \"POST\",\n path: joinPath(\n basePath,\n meta && meta.route ? groupPrefix : \"\",\n authoredRoute,\n ),\n capability: entry,\n });\n}\n\nfunction capabilityHttp(entry: LocatedCapability): HttpCapabilityMeta | undefined {\n return entry.capability.meta.http as HttpCapabilityMeta | undefined;\n}\n\nfunction httpSuccessStatus(entry: LocatedCapability): number {\n const meta = capabilityHttp(entry);\n return meta && typeof meta.status === \"number\" ? meta.status : 200;\n}\n\nasync function readHttpInput(\n request: Request,\n params: Record<string, string>,\n schema: LocatedCapability[\"capability\"][\"input\"],\n): Promise<Record<string, unknown>> {\n const url = new URL(request.url);\n const jsonSchema = schema\n ? schemaToJsonSchema(schema, \"input\")\n : undefined;\n const properties = jsonSchema?.properties as\n | Record<string, Readonly<Record<string, unknown>>>\n | undefined;\n const coerceEntries = (entries: Iterable<readonly [string, string]>) =>\n Object.fromEntries(\n [...entries].map(([key, value]) => [\n key,\n coerceHttpValue(value, properties?.[key]),\n ]),\n );\n const rest: Record<string, unknown> =\n request.method === \"GET\"\n ? coerceEntries(url.searchParams)\n : request.headers.get(\"content-type\")?.includes(\"application/json\")\n ? await request.json() as Record<string, unknown>\n : {};\n return {\n ...rest,\n ...coerceEntries(Object.entries(params)),\n };\n}\n\nfunction coerceHttpValue(\n value: string,\n schema: Readonly<Record<string, unknown>> | undefined,\n): unknown {\n if (schema?.type === \"boolean\") return value === \"true\"\n ? true\n : value === \"false\"\n ? false\n : value;\n if (schema?.type === \"integer\" || schema?.type === \"number\") {\n const number = Number(value);\n return Number.isFinite(number) ? number : value;\n }\n return value;\n}\n\nfunction assertPathParameters(\n entry: LocatedCapability,\n path: string,\n): void {\n const parameters = [...path.matchAll(/:([^/]+)/g)].map((match) => match[1]!);\n if (parameters.length === 0) return;\n const schema = entry.capability.input\n ? schemaToJsonSchema(entry.capability.input, \"input\")\n : undefined;\n const properties = schema?.properties as\n | Record<string, unknown>\n | undefined;\n for (const parameter of parameters) {\n if (!properties?.[parameter]) {\n throw new Error(\n `HTTP path parameter \":${parameter}\" is not present in Capability \"${entry.capability.id}\" input`,\n );\n }\n }\n}\n\nfunction matchPath(\n pattern: string,\n pathname: string,\n): Record<string, string> | undefined {\n const expected = pattern.split(\"/\").filter(Boolean);\n const actual = pathname.split(\"/\").filter(Boolean);\n if (expected.length !== actual.length) return undefined;\n const params: Record<string, string> = {};\n for (let index = 0; index < expected.length; index++) {\n const token = expected[index]!;\n const value = actual[index]!;\n if (token.startsWith(\":\")) params[token.slice(1)] = decodeURIComponent(value);\n else if (token !== value) return undefined;\n }\n return params;\n}\n\nfunction createOpenApi(\n app: AppDefinition<any, any>,\n routes: readonly CompiledHttpRoute[],\n): Readonly<Record<string, unknown>> {\n const paths: Record<string, unknown> = {};\n for (const route of routes) {\n const method = route.method.toLowerCase();\n const path = route.path.replace(/:([^/]+)/g, \"{$1}\");\n const capability = route.capability.capability;\n const input = capability.input\n ? schemaToJsonSchema(capability.input, \"input\")\n : undefined;\n const properties = (input?.properties ?? {}) as Record<string, JsonSchema>;\n const required = new Set((input?.required ?? []) as readonly string[]);\n const pathNames = new Set(\n [...route.path.matchAll(/:([^/]+)/g)].map((match) => match[1]!),\n );\n const parameters = [...pathNames].map((name) => ({\n name,\n in: \"path\",\n required: true,\n schema: properties[name] ?? {},\n }));\n const remaining = Object.fromEntries(\n Object.entries(properties).filter(([name]) => !pathNames.has(name)),\n );\n if (route.method === \"GET\") {\n parameters.push(\n ...Object.entries(remaining).map(([name, schema]) => ({\n name,\n in: \"query\",\n required: required.has(name),\n schema,\n })),\n );\n }\n const responses: Record<string, unknown> = {\n [String(httpSuccessStatus(route.capability))]: {\n description: \"Successful response\",\n content: {\n \"application/json\": {\n schema: capability.output\n ? schemaToJsonSchema(capability.output, \"output\")\n : {},\n },\n },\n },\n };\n for (const [code, error] of Object.entries(route.capability.errors)) {\n const status = typeof error.status === \"number\"\n ? String(error.status)\n : \"default\";\n responses[status] ??= {\n description: error.message ?? code,\n };\n }\n const current = paths[path] as Record<string, unknown> | undefined ?? {};\n current[method] = {\n capabilityId: capability.id,\n ...(capability.title ? { summary: capability.title } : {}),\n ...(capability.description ? { description: capability.description } : {}),\n ...(parameters.length ? { parameters } : {}),\n ...(route.method !== \"GET\" && Object.keys(remaining).length\n ? {\n requestBody: {\n required: [...required].some((name) => !pathNames.has(name)),\n content: {\n \"application/json\": {\n schema: {\n type: \"object\",\n properties: remaining,\n required: [...required].filter((name) =>\n !pathNames.has(name)\n ),\n },\n },\n },\n },\n }\n : {}),\n responses,\n };\n paths[path] = current;\n }\n return {\n openapi: \"3.1.0\",\n info: { title: app.name, version: app.version },\n paths,\n };\n}\n\nfunction selectCapabilities(\n capabilities: readonly LocatedCapability[],\n selection: CapabilitySelection | undefined,\n): readonly LocatedCapability[] {\n return capabilities.filter((entry) => {\n const included = selection?.include\n ? matchesTree(selection.include, entry.path)\n : true;\n return included && !matchesTree(selection?.exclude, entry.path);\n });\n}\n\nfunction matchesTree(\n tree: Readonly<Record<string, unknown>> | undefined,\n path: readonly string[],\n): boolean {\n if (!tree) return false;\n let current: unknown = tree;\n for (const segment of path) {\n if (current === true) return true;\n if (!current || typeof current !== \"object\" || Array.isArray(current)) {\n return false;\n }\n current = (current as Record<string, unknown>)[segment];\n }\n return current === true || (\n Boolean(current) && typeof current === \"object\" && !Array.isArray(current)\n );\n}\n\nfunction assertUniqueRoutes(routes: readonly CompiledHttpRoute[]): void {\n const seen = new Set<string>();\n for (const route of routes) {\n const identity = `${route.method} ${route.path}`;\n if (seen.has(identity)) throw new Error(`Duplicate HTTP route ${identity}`);\n seen.add(identity);\n }\n}\n\nfunction normalizePath(value: string): string {\n return `/${value.split(\"/\").filter(Boolean).join(\"/\")}`;\n}\n\nfunction joinPath(...parts: readonly string[]): string {\n return normalizePath(parts.join(\"/\"));\n}\n"],"mappings":";;;AAUA,SAAgB,oBACd,OACA,iBAAiB,KACI;CACrB,MAAM,UAAU,iBAAiB,gBAAgB,iBAAiB,iBAC9D,QACA,IAAI,aAAa,yBAAyB,EAAE,OAAO,MAA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AAE,OAAO,IAAI;GAAM,SAAS,IAAI;EAAQ;EAC9C;CACF;AACF;AAEA,SAAS,mBACP,cACA,WAC8B;CAC9B,OAAO,aAAa,QAAQ,UAAU;EAIpC,QAHiB,WAAW,UACxB,YAAY,UAAU,SAAS,MAAM,IAAI,IACzC,SACe,CAAC,YAAY,WAAW,SAAS,MAAM,IAAI;CAChE,CAAC;AACH;AAEA,SAAS,YACP,MACA,MACS;CACT,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,UAAmB;CACvB,KAAK,MAAM,WAAW,MAAM;EAC1B,IAAI,YAAY,MAAM,OAAO;EAC7B,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAClE,OAAO;EAET,UAAW,QAAoC;CACjD;CACA,OAAO,YAAY,QACjB,QAAQ,OAAO,KAAK,OAAO,YAAY,YAAY,CAAC,MAAM,QAAQ,OAAO;AAE7E;AAEA,SAAS,mBAAmB,QAA4C;CACtE,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,GAAG,MAAM,OAAO,GAAG,MAAM;EAC1C,IAAI,KAAK,IAAI,QAAQ,GAAG,MAAM,IAAI,MAAM,wBAAwB,UAAU;EAC1E,KAAK,IAAI,QAAQ;CACnB;AACF;AAEA,SAAS,cAAc,OAAuB;CAC5C,OAAO,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACtD;AAEA,SAAS,SAAS,GAAG,OAAkC;CACrD,OAAO,cAAc,MAAM,KAAK,GAAG,CAAC;AACtC"}
|
package/docs/CONTEXT.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Capable domain language
|
|
2
|
+
|
|
3
|
+
**Capability**: one typed capability with a canonical string ID, optional
|
|
4
|
+
object-shaped input, optional output schema, declared errors, middleware,
|
|
5
|
+
optional effect, unary handler, optional replacement subscriber, open surface
|
|
6
|
+
metadata, and optional `toMarkdown`.
|
|
7
|
+
It has no canonical HTTP method or path.
|
|
8
|
+
|
|
9
|
+
**App Definition**: immutable named object nesting created by `defineApp()`
|
|
10
|
+
whose leaves are Capabilities. It carries no context provider or execution
|
|
11
|
+
placement. Its paths drive navigational interfaces and surface defaults.
|
|
12
|
+
|
|
13
|
+
**Group**: an anonymous decorated subtree created with `group()`. It has no ID.
|
|
14
|
+
It contributes semantic middleware and errors and exposes its metadata ancestry
|
|
15
|
+
to surface compilers.
|
|
16
|
+
|
|
17
|
+
**Capability ID**: canonical execution and transport identity. IDs are unique
|
|
18
|
+
within an Application.
|
|
19
|
+
|
|
20
|
+
**Application path**: the unique object path to a Capability, such as
|
|
21
|
+
`admin.users.create`. It drives direct App calls, CLI, and MCP navigation but
|
|
22
|
+
is not the Capability's identity.
|
|
23
|
+
|
|
24
|
+
**Effect**: optional `read`, `write`, or `destructive` intent. HTTP may derive
|
|
25
|
+
GET only from `read`; MCP may derive safety hints. Absence means unknown.
|
|
26
|
+
|
|
27
|
+
**Error set**: a branded contract created by `defineErrors()`. Its named,
|
|
28
|
+
callable members construct type-safe declared errors and narrow those errors
|
|
29
|
+
after local or remote execution. Groups may contribute inherited Error sets.
|
|
30
|
+
Any handler or middleware failure outside the located Capability's declared
|
|
31
|
+
sets becomes `INTERNAL_SERVER_ERROR`.
|
|
32
|
+
|
|
33
|
+
**Context declaration**: the `capabilities<TContext>()` factory used to bind
|
|
34
|
+
Capabilities to a context type without constructing that context.
|
|
35
|
+
|
|
36
|
+
**Context provider**: opt-in, boundary-owned context construction. A
|
|
37
|
+
context-free definition uses `createApp(definition)` with no options. When a
|
|
38
|
+
Capability declares context, local consumers must provide it through
|
|
39
|
+
`createApp()` and Fetch servers derive it from the incoming Request. An App
|
|
40
|
+
Definition derives any required context type from its Capability tree but
|
|
41
|
+
stores no provider.
|
|
42
|
+
|
|
43
|
+
**App**: a context-erased typed callable object tree. `createApp()` closes over
|
|
44
|
+
direct execution and its provider; `createRemoteApp()` wraps a transport
|
|
45
|
+
without performing I/O. Remote manifest discovery is lazy, validated, and
|
|
46
|
+
cached. `mergeApps()` returns the same shape. A low-level
|
|
47
|
+
`manifest() + call() + subscribe()` runtime lives behind internal symbols for
|
|
48
|
+
surfaces and composition.
|
|
49
|
+
|
|
50
|
+
**Application merge**: strict root-tree combination through `mergeApps()`.
|
|
51
|
+
Calls dispatch by immutable Capability ID. All path, ID, double-mount, and
|
|
52
|
+
leaf/subtree conflicts fail when the merged manifest first resolves.
|
|
53
|
+
|
|
54
|
+
**Capable transport**: an asynchronous boundary exposing `manifest()`,
|
|
55
|
+
`call()`, and `subscribe()`. `createRemoteApp()` wraps and caches it without
|
|
56
|
+
turning module evaluation into a network boundary. Its HTTP client/server
|
|
57
|
+
encoding lives in `@capable/fetch` as server plumbing, separate from authored
|
|
58
|
+
HTTP APIs and from transport-neutral App semantics.
|
|
59
|
+
|
|
60
|
+
**HTTP projection**: a server mount that derives routes from the Application
|
|
61
|
+
tree and `effect`, then applies optional `meta.http` overrides. It also owns
|
|
62
|
+
OpenAPI.
|
|
63
|
+
|
|
64
|
+
**AI SDK projection**: an asynchronous projection that resolves an executable
|
|
65
|
+
App manifest into typed AI SDK tools. It derives portable names and JSON
|
|
66
|
+
Schemas, then dispatches execution and cancellation through the App runtime.
|
|
67
|
+
|
|
68
|
+
**Surface metadata**: open Capability or Group metadata interpreted only by its
|
|
69
|
+
surface package. Core preserves ancestry and never performs generic merging.
|
|
70
|
+
|
|
71
|
+
**Selection**: tree-shaped `include` and `exclude` policy owned by an exposure
|
|
72
|
+
boundary. Omitted include means all; exclude wins.
|
|
73
|
+
`selectApp()` applies that policy before passing an App to a
|
|
74
|
+
surface.
|
|
75
|
+
|
|
76
|
+
**Canonical output**: handler output after optional output validation.
|
|
77
|
+
`toMarkdown` is an alternate representation, not a second semantic result.
|
|
78
|
+
|
|
79
|
+
**Replacement subscription**: an optional pull-based execution mode on a
|
|
80
|
+
`read` Capability. It shares that Capability's ID, input, Canonical Output,
|
|
81
|
+
declared errors, middleware, placement, and representations. Every emitted
|
|
82
|
+
item is a complete replacement Canonical Output. `subscribe(appCall, input)`
|
|
83
|
+
keeps App navigation collision-free.
|
|
84
|
+
|
|
85
|
+
## Invariants
|
|
86
|
+
|
|
87
|
+
- `@capable/core` depends on no transport, host, CLI, MCP, or HTTP package.
|
|
88
|
+
- Application and Group capability collections are named object trees, never
|
|
89
|
+
arrays.
|
|
90
|
+
- `then` is reserved at every App path so callable proxies cannot become
|
|
91
|
+
promise-like values.
|
|
92
|
+
- App Definitions never carry context providers.
|
|
93
|
+
- A context-free `createApp()` needs no provider; a contextual one satisfies
|
|
94
|
+
and erases only its own context before merging.
|
|
95
|
+
- A Capability object and ID may each occur only once in an Application.
|
|
96
|
+
- Handlers receive only `{ input, context, signal }`.
|
|
97
|
+
- Semantic middleware and declared errors execute identically for every
|
|
98
|
+
surface.
|
|
99
|
+
- Subscription input is parsed once, every replacement is output-validated,
|
|
100
|
+
middleware encloses the complete iterator lifetime, and cancellation aborts
|
|
101
|
+
before iterator cleanup.
|
|
102
|
+
- Platform adapters only translate their host to Fetch Request/Response.
|
|
103
|
+
- HTTP is a projection and deployment concern, not Capability identity.
|
|
104
|
+
- Generic event streams, patches, buffering, replay, resumption, delivery
|
|
105
|
+
guarantees, and reconnection policy are not replacement subscription
|
|
106
|
+
semantics.
|
|
107
|
+
- Idempotence, approvals, and durable tasks remain deferred until a concrete
|
|
108
|
+
consumer proves their contract.
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Capable documentation
|
|
2
|
+
|
|
3
|
+
This directory is assembled from Capable's canonical documentation sources when
|
|
4
|
+
the npm package is packed. It matches the installed package version.
|
|
5
|
+
|
|
6
|
+
## For coding agents
|
|
7
|
+
|
|
8
|
+
Do not rely on remembered Capable APIs. Read the relevant bundled guide and
|
|
9
|
+
inspect `../src/` when you need a detail the guides do not cover.
|
|
10
|
+
|
|
11
|
+
Start here:
|
|
12
|
+
|
|
13
|
+
1. [Introduction](./site/introduction.mdx)
|
|
14
|
+
2. [Quickstart](./site/quickstart.mdx)
|
|
15
|
+
3. [Capabilities](./site/concepts/capabilities.mdx)
|
|
16
|
+
4. [Apps](./site/concepts/apps.mdx)
|
|
17
|
+
5. [Surfaces](./site/surfaces.mdx)
|
|
18
|
+
6. [Packages and entry points](./site/reference/packages-and-entry-points.mdx)
|
|
19
|
+
|
|
20
|
+
Public guides are grouped by section and named from their frontmatter titles.
|
|
21
|
+
To find a topic, search the files under `site/` or list its `.mdx` files.
|
|
22
|
+
|
|
23
|
+
- `site/` contains the canonical, human- and agent-readable MDX guides.
|
|
24
|
+
- `internal/` contains design notes for contributors.
|
|
25
|
+
- `CONTEXT.md` defines the framework's domain language and invariants.
|
|
26
|
+
|
|
27
|
+
The canonical sources live in `website/`, `docs/`, and `CONTEXT.md` in the
|
|
28
|
+
Capable repository. Edit those sources rather than the generated package copy.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Internal docs
|
|
2
|
+
|
|
3
|
+
User-facing documentation lives in the site under `website/` (`bun run
|
|
4
|
+
docs:dev`). This directory is for people working *on* Capable.
|
|
5
|
+
|
|
6
|
+
| Document | Contains |
|
|
7
|
+
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
|
|
8
|
+
| [../CONTEXT.md](../CONTEXT.md) | The domain language and the invariants every change must preserve |
|
|
9
|
+
| [capability-first-model.md](./capability-first-model.md) | Normative rules of the model: identity, placement, errors, subscriptions |
|
|
10
|
+
| [architecture.md](./architecture.md) | How the packages are layered and why |
|
|
11
|
+
| [adr/](./adr) | Accepted decisions |
|
|
12
|
+
| [implementation-friction.md](./implementation-friction.md) | Live log of awkward or leaky implementation work |
|
|
13
|
+
| [why-capable.md](./why-capable.md) | The original internal argument for the project |
|
|
14
|
+
|
|
15
|
+
If a change contradicts CONTEXT.md, change CONTEXT.md in the same commit or do
|
|
16
|
+
not make the change.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
status: accepted
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Keep Capability as the application-semantic boundary
|
|
6
|
+
|
|
7
|
+
Capable defines protocol-neutral Capabilities and composes them into an Application
|
|
8
|
+
object tree. HTTP endpoints, CLI commands, MCP tools, clients, jobs, and future
|
|
9
|
+
workflows invoke the same Capability executor rather than introducing competing
|
|
10
|
+
business runtimes.
|
|
11
|
+
|
|
12
|
+
A Capability ID is canonical execution identity. The Application path is
|
|
13
|
+
navigational. HTTP method/path and other surface identities are projections.
|
|
14
|
+
|
|
15
|
+
Future approval or durable-task coordination wraps invocation before semantic
|
|
16
|
+
middleware and the handler. It may suspend and resume execution, but it does
|
|
17
|
+
not enter the handler contract or canonical output.
|
|
18
|
+
|
|
19
|
+
App Definitions do not own context provision. `createApp()` satisfies one
|
|
20
|
+
definition's context and erases it into a directly callable App;
|
|
21
|
+
`createRemoteApp()` returns the same callable shape while lazily discovering
|
|
22
|
+
and validating transport execution. `mergeApps()` combines these
|
|
23
|
+
context-erased Apps, so unrelated local contexts never become one giant merged
|
|
24
|
+
context.
|