capable-kit 0.1.0-alpha.10 → 0.1.0-alpha.11
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/CHANGELOG.md +171 -0
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +1 -1
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +1 -1
- package/dist/bin.mjs +19 -15
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +2 -2
- package/dist/eve.d.mts +20 -14
- package/dist/eve.mjs +450 -211
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-WiBWfyTn.d.mts → index-BIO_hbXJ.d.mts} +8 -2
- package/dist/{index-D-NV4PiU.d.mts → index-C0tU5Y2n.d.mts} +4 -4
- package/dist/{index-CHuCLJIs.d.mts → index-CwvjDizW.d.mts} +5 -3
- package/dist/{index-1A44jLuE.d.mts → index-F_eaksy8.d.mts} +7 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/mcp.d.mts +14 -4
- package/dist/mcp.mjs +2 -2
- package/dist/{mount-BmLHp349.mjs → mount-pvIaehZC.mjs} +148 -104
- package/dist/mount-pvIaehZC.mjs.map +1 -0
- package/dist/react-query.d.mts +1 -1
- package/dist/react-query.mjs +1 -1
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +3 -3
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-_6OmFRYa.mjs → src-Bk3lEhI7.mjs} +38 -18
- package/dist/src-Bk3lEhI7.mjs.map +1 -0
- package/dist/{src-DePlcG_t.mjs → src-C2OEkZ3c.mjs} +38 -65
- package/dist/src-C2OEkZ3c.mjs.map +1 -0
- package/dist/{src-C5jGDnuu.mjs → src-DFrxQ_S6.mjs} +9 -7
- package/dist/src-DFrxQ_S6.mjs.map +1 -0
- package/dist/{src-3LE9S4QE.mjs → src-DklM1g7V.mjs} +5 -5
- package/dist/src-DklM1g7V.mjs.map +1 -0
- package/dist/{src-B2WeUwUT.mjs → src-TCQGaWar.mjs} +60 -18
- package/dist/src-TCQGaWar.mjs.map +1 -0
- package/dist/{subscription-DPdwovhw.d.mts → subscription-fVgS4T8P.d.mts} +2 -2
- package/dist/swr.d.mts +1 -1
- package/dist/swr.mjs +1 -1
- package/docs/CONTEXT.md +5 -2
- package/docs/internal/eve-recovery-validation.md +12 -11
- package/docs/internal/implementation-friction.md +59 -0
- package/docs/site/concepts/errors.mdx +15 -3
- package/docs/site/hosting/standalone-server.mdx +2 -0
- package/docs/site/patterns/remote-apps.mdx +23 -1
- package/docs/site/quickstart.mdx +2 -1
- package/docs/site/reference/packages-and-entry-points.mdx +2 -1
- package/docs/site/reference/the-cap-cli.mdx +2 -2
- package/docs/site/surfaces/eve.mdx +6 -4
- package/docs/site/surfaces/mcp.mdx +84 -2
- package/package.json +13 -7
- package/src/index.ts +2 -0
- package/src/package.test.ts +6 -0
- package/dist/mount-BmLHp349.mjs.map +0 -1
- package/dist/src-3LE9S4QE.mjs.map +0 -1
- package/dist/src-B2WeUwUT.mjs.map +0 -1
- package/dist/src-C5jGDnuu.mjs.map +0 -1
- package/dist/src-DePlcG_t.mjs.map +0 -1
- package/dist/src-_6OmFRYa.mjs.map +0 -1
|
@@ -1,8 +1,138 @@
|
|
|
1
|
-
import { y as renderPresentationMarkdown } from "./src-
|
|
2
|
-
import { a as getCapabilityNavigationMeta, c as TransportError, d as getAppRuntime, h as flattenManifestCapabilities, i as getCapabilityDisplay, l as createApp, n as selectApp } from "./src-
|
|
1
|
+
import { C as isPublicError, x as CapableError, y as renderPresentationMarkdown } from "./src-TCQGaWar.mjs";
|
|
2
|
+
import { a as getCapabilityNavigationMeta, c as TransportError, d as getAppRuntime, h as flattenManifestCapabilities, i as getCapabilityDisplay, l as createApp, n as selectApp } from "./src-C2OEkZ3c.mjs";
|
|
3
3
|
import { Server, createMcpHandler } from "@modelcontextprotocol/server";
|
|
4
|
+
//#region packages/mcp/src/presentation.ts
|
|
5
|
+
function toMcpContent(presentation, output) {
|
|
6
|
+
if (!presentation?.length) return [{
|
|
7
|
+
type: "text",
|
|
8
|
+
text: stringify(output)
|
|
9
|
+
}];
|
|
10
|
+
const content = [];
|
|
11
|
+
for (const part of presentation) {
|
|
12
|
+
if (part.type === "markdown") {
|
|
13
|
+
content.push({
|
|
14
|
+
type: "text",
|
|
15
|
+
text: renderPresentationMarkdown(part)
|
|
16
|
+
});
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (part.type === "table") {
|
|
20
|
+
content.push({
|
|
21
|
+
type: "text",
|
|
22
|
+
text: renderPresentationMarkdown(part)
|
|
23
|
+
});
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (part.type === "image") {
|
|
27
|
+
content.push({
|
|
28
|
+
type: "text",
|
|
29
|
+
text: `[Image: ${part.alt}]`
|
|
30
|
+
}, {
|
|
31
|
+
type: "image",
|
|
32
|
+
data: part.base64,
|
|
33
|
+
mimeType: part.mimeType
|
|
34
|
+
});
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
content.push({
|
|
38
|
+
type: "resource_link",
|
|
39
|
+
uri: part.url,
|
|
40
|
+
name: part.name,
|
|
41
|
+
...part.description ? { description: part.description } : {},
|
|
42
|
+
...part.mimeType ? { mimeType: part.mimeType } : {},
|
|
43
|
+
...part.size === void 0 ? {} : { size: part.size }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return content;
|
|
47
|
+
}
|
|
48
|
+
function stringify(value) {
|
|
49
|
+
return typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region packages/mcp/src/protocol.ts
|
|
53
|
+
async function callMcpTool(tool, input, signal, onError) {
|
|
54
|
+
try {
|
|
55
|
+
const result = await tool.call(input ?? {}, { signal });
|
|
56
|
+
return {
|
|
57
|
+
content: toMcpContent(result.presentation, result.output),
|
|
58
|
+
structuredContent: result.output
|
|
59
|
+
};
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (isPublicError(error) && (error instanceof CapableError || error instanceof TransportError)) {
|
|
62
|
+
if (error.code === "INTERNAL_SERVER_ERROR") onError?.(error);
|
|
63
|
+
return toolError(error.message, {
|
|
64
|
+
code: error.code,
|
|
65
|
+
status: error.status,
|
|
66
|
+
data: error.data
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (signal.aborted) throw error;
|
|
70
|
+
onError?.(error);
|
|
71
|
+
return toolError("INTERNAL_SERVER_ERROR", {
|
|
72
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
73
|
+
status: 500
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function toProtocolTool(tool) {
|
|
78
|
+
return {
|
|
79
|
+
name: tool.name,
|
|
80
|
+
...tool.title ? { title: tool.title } : {},
|
|
81
|
+
...tool.description ? { description: tool.description } : {},
|
|
82
|
+
...tool.icons ? { icons: toProtocolIcons(tool.icons) } : {},
|
|
83
|
+
inputSchema: tool.inputSchema,
|
|
84
|
+
...tool.outputSchema ? { outputSchema: tool.outputSchema } : {},
|
|
85
|
+
_meta: tool._meta,
|
|
86
|
+
annotations: tool.annotations
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function toProtocolIcons(icons) {
|
|
90
|
+
return icons.map((icon) => ({
|
|
91
|
+
src: icon.src,
|
|
92
|
+
...icon.mimeType !== void 0 ? { mimeType: icon.mimeType } : {},
|
|
93
|
+
...icon.sizes !== void 0 ? { sizes: [...icon.sizes] } : {},
|
|
94
|
+
...icon.theme !== void 0 ? { theme: icon.theme } : {}
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
function toolError(message, details) {
|
|
98
|
+
return {
|
|
99
|
+
isError: true,
|
|
100
|
+
content: [{
|
|
101
|
+
type: "text",
|
|
102
|
+
text: details ? JSON.stringify({
|
|
103
|
+
message,
|
|
104
|
+
...details
|
|
105
|
+
}) : message
|
|
106
|
+
}]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region packages/mcp/src/register.ts
|
|
111
|
+
/** Register App-backed tools alongside native SDK tools and resources. */
|
|
112
|
+
function registerCapableTools(server, tools) {
|
|
113
|
+
return tools.map((tool) => {
|
|
114
|
+
const { name, inputSchema, outputSchema, ...descriptor } = toProtocolTool(tool);
|
|
115
|
+
return server.registerTool(name, {
|
|
116
|
+
...descriptor,
|
|
117
|
+
inputSchema: protocolSchema(inputSchema),
|
|
118
|
+
...outputSchema ? { outputSchema: protocolSchema(outputSchema) } : {}
|
|
119
|
+
}, (input, context) => callMcpTool(tool, input, context.mcpReq.signal));
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function protocolSchema(schema) {
|
|
123
|
+
return { "~standard": {
|
|
124
|
+
version: 1,
|
|
125
|
+
vendor: "capable",
|
|
126
|
+
validate: (value) => ({ value }),
|
|
127
|
+
jsonSchema: {
|
|
128
|
+
input: () => schema,
|
|
129
|
+
output: () => schema
|
|
130
|
+
}
|
|
131
|
+
} };
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
4
134
|
//#region packages/mcp/src/index.ts
|
|
5
|
-
async function createMcp(app) {
|
|
135
|
+
async function createMcp(app, options = {}) {
|
|
6
136
|
const runtime = getAppRuntime(app);
|
|
7
137
|
const tools = flattenManifestCapabilities((await runtime.manifest()).capabilities).map((capability) => ({
|
|
8
138
|
...capability,
|
|
@@ -16,9 +146,9 @@ async function createMcp(app) {
|
|
|
16
146
|
}).map((capability) => {
|
|
17
147
|
const meta = readMcpMeta(capability);
|
|
18
148
|
const navigation = getCapabilityNavigationMeta(capability, "mcp");
|
|
19
|
-
const
|
|
149
|
+
const explicitName = navigation === false ? void 0 : navigation?.name;
|
|
20
150
|
return Object.freeze({
|
|
21
|
-
name:
|
|
151
|
+
name: explicitName ?? formatToolName(capability, options.toolName),
|
|
22
152
|
...capability.title ? { title: capability.title } : {},
|
|
23
153
|
...capability.description ? { description: capability.description } : {},
|
|
24
154
|
...meta?.icons ? { icons: meta.icons } : {},
|
|
@@ -52,6 +182,12 @@ async function createMcp(app) {
|
|
|
52
182
|
}
|
|
53
183
|
return tools;
|
|
54
184
|
}
|
|
185
|
+
function formatToolName(capability, formatter) {
|
|
186
|
+
if (!formatter) return capability.path.join("__");
|
|
187
|
+
const name = formatter(capability);
|
|
188
|
+
if (typeof name !== "string" || name.length === 0) throw new Error(`Capability "${capability.id}" produced an invalid MCP tool name: toolName must return a non-empty string`);
|
|
189
|
+
return name;
|
|
190
|
+
}
|
|
55
191
|
function readMcpMeta(capability) {
|
|
56
192
|
const value = capability.meta.mcp;
|
|
57
193
|
if (value === void 0) return void 0;
|
|
@@ -75,54 +211,6 @@ function invalidMcpMeta(capability, reason) {
|
|
|
75
211
|
throw new Error(`Capability "${capability.id}" has invalid MCP metadata: ${reason}`);
|
|
76
212
|
}
|
|
77
213
|
//#endregion
|
|
78
|
-
//#region packages/mcp/src/presentation.ts
|
|
79
|
-
function toMcpContent(presentation, output) {
|
|
80
|
-
if (!presentation?.length) return [{
|
|
81
|
-
type: "text",
|
|
82
|
-
text: stringify(output)
|
|
83
|
-
}];
|
|
84
|
-
const content = [];
|
|
85
|
-
for (const part of presentation) {
|
|
86
|
-
if (part.type === "markdown") {
|
|
87
|
-
content.push({
|
|
88
|
-
type: "text",
|
|
89
|
-
text: renderPresentationMarkdown(part)
|
|
90
|
-
});
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (part.type === "table") {
|
|
94
|
-
content.push({
|
|
95
|
-
type: "text",
|
|
96
|
-
text: renderPresentationMarkdown(part)
|
|
97
|
-
});
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (part.type === "image") {
|
|
101
|
-
content.push({
|
|
102
|
-
type: "text",
|
|
103
|
-
text: `[Image: ${part.alt}]`
|
|
104
|
-
}, {
|
|
105
|
-
type: "image",
|
|
106
|
-
data: part.base64,
|
|
107
|
-
mimeType: part.mimeType
|
|
108
|
-
});
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
content.push({
|
|
112
|
-
type: "resource_link",
|
|
113
|
-
uri: part.url,
|
|
114
|
-
name: part.name,
|
|
115
|
-
...part.description ? { description: part.description } : {},
|
|
116
|
-
...part.mimeType ? { mimeType: part.mimeType } : {},
|
|
117
|
-
...part.size === void 0 ? {} : { size: part.size }
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return content;
|
|
121
|
-
}
|
|
122
|
-
function stringify(value) {
|
|
123
|
-
return typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
124
|
-
}
|
|
125
|
-
//#endregion
|
|
126
214
|
//#region packages/mcp/src/mount.ts
|
|
127
215
|
function mcp(options = {}) {
|
|
128
216
|
validateCacheHint(options.cache?.discovery, "discovery");
|
|
@@ -136,14 +224,14 @@ function mcp(options = {}) {
|
|
|
136
224
|
try {
|
|
137
225
|
if (!requestInfo) throw new Error("The MCP HTTP handler requires request information");
|
|
138
226
|
const executable = createApp(app, context ? { context: () => context({ request: requestInfo }) } : void 0);
|
|
139
|
-
return createMcpServer(await createMcp(options.selection ? selectApp(executable, options.selection) : executable), {
|
|
227
|
+
return createMcpServer(await createMcp(options.selection ? selectApp(executable, options.selection) : executable, options.toolName ? { toolName: options.toolName } : void 0), {
|
|
140
228
|
name: options.name ?? app.name ?? "capable",
|
|
141
229
|
version: options.version ?? app.version ?? "0.0.0",
|
|
142
230
|
...options.title !== void 0 ? { title: options.title } : {},
|
|
143
231
|
...description !== void 0 ? { description } : {},
|
|
144
232
|
...options.websiteUrl !== void 0 ? { websiteUrl: options.websiteUrl } : {},
|
|
145
233
|
...options.icons !== void 0 ? { icons: toProtocolIcons(options.icons) } : {}
|
|
146
|
-
}, options);
|
|
234
|
+
}, options, onError);
|
|
147
235
|
} catch (error) {
|
|
148
236
|
onError?.(error);
|
|
149
237
|
throw error;
|
|
@@ -159,7 +247,7 @@ function mcp(options = {}) {
|
|
|
159
247
|
}
|
|
160
248
|
};
|
|
161
249
|
}
|
|
162
|
-
function createMcpServer(tools, info, options) {
|
|
250
|
+
function createMcpServer(tools, info, options, onError) {
|
|
163
251
|
const server = new Server(info, {
|
|
164
252
|
capabilities: { tools: {} },
|
|
165
253
|
...options.instructions !== void 0 ? { instructions: options.instructions } : {},
|
|
@@ -172,55 +260,11 @@ function createMcpServer(tools, info, options) {
|
|
|
172
260
|
server.setRequestHandler("tools/call", async (request, context) => {
|
|
173
261
|
const tool = tools.find(({ name }) => name === request.params.name);
|
|
174
262
|
if (!tool) return toolError(`Unknown tool "${request.params.name}"`);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return server.projectCallToolResult({
|
|
178
|
-
content: toMcpContent(result.presentation, result.output),
|
|
179
|
-
structuredContent: result.output
|
|
180
|
-
}, tool.outputSchema);
|
|
181
|
-
} catch (error) {
|
|
182
|
-
if (!(error instanceof TransportError)) throw error;
|
|
183
|
-
return toolError(error.message, {
|
|
184
|
-
code: error.code,
|
|
185
|
-
status: error.status,
|
|
186
|
-
data: error.data
|
|
187
|
-
});
|
|
188
|
-
}
|
|
263
|
+
const result = await callMcpTool(tool, request.params.arguments, context.mcpReq.signal, onError);
|
|
264
|
+
return result.isError ? result : server.projectCallToolResult(result, tool.outputSchema);
|
|
189
265
|
});
|
|
190
266
|
return server;
|
|
191
267
|
}
|
|
192
|
-
function toProtocolTool(tool) {
|
|
193
|
-
return {
|
|
194
|
-
name: tool.name,
|
|
195
|
-
...tool.title ? { title: tool.title } : {},
|
|
196
|
-
...tool.description ? { description: tool.description } : {},
|
|
197
|
-
...tool.icons ? { icons: toProtocolIcons(tool.icons) } : {},
|
|
198
|
-
inputSchema: tool.inputSchema,
|
|
199
|
-
...tool.outputSchema ? { outputSchema: tool.outputSchema } : {},
|
|
200
|
-
_meta: tool._meta,
|
|
201
|
-
annotations: tool.annotations
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function toProtocolIcons(icons) {
|
|
205
|
-
return icons.map((icon) => ({
|
|
206
|
-
src: icon.src,
|
|
207
|
-
...icon.mimeType !== void 0 ? { mimeType: icon.mimeType } : {},
|
|
208
|
-
...icon.sizes !== void 0 ? { sizes: [...icon.sizes] } : {},
|
|
209
|
-
...icon.theme !== void 0 ? { theme: icon.theme } : {}
|
|
210
|
-
}));
|
|
211
|
-
}
|
|
212
|
-
function toolError(message, details) {
|
|
213
|
-
return {
|
|
214
|
-
isError: true,
|
|
215
|
-
content: [{
|
|
216
|
-
type: "text",
|
|
217
|
-
text: details ? JSON.stringify({
|
|
218
|
-
message,
|
|
219
|
-
...details
|
|
220
|
-
}) : message
|
|
221
|
-
}]
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
268
|
function normalizePath(value) {
|
|
225
269
|
return `/${value.split("/").filter(Boolean).join("/")}`;
|
|
226
270
|
}
|
|
@@ -230,6 +274,6 @@ function validateCacheHint(hint, field) {
|
|
|
230
274
|
if (hint.cacheScope !== void 0 && hint.cacheScope !== "public" && hint.cacheScope !== "private") throw new RangeError(`MCP ${field} cache cacheScope must be "public" or "private"`);
|
|
231
275
|
}
|
|
232
276
|
//#endregion
|
|
233
|
-
export { createMcp as n, mcp as t };
|
|
277
|
+
export { createMcp as n, registerCapableTools as r, mcp as t };
|
|
234
278
|
|
|
235
|
-
//# sourceMappingURL=mount-
|
|
279
|
+
//# sourceMappingURL=mount-pvIaehZC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-pvIaehZC.mjs","names":[],"sources":["../../mcp/src/presentation.ts","../../mcp/src/protocol.ts","../../mcp/src/register.ts","../../mcp/src/index.ts","../../mcp/src/mount.ts"],"sourcesContent":["import {\n renderPresentationMarkdown,\n type PresentationPart,\n} from \"@capable/core\";\nimport type { CallToolResult } from \"@modelcontextprotocol/server\";\n\nexport function toMcpContent(\n presentation: readonly PresentationPart[] | undefined,\n output: unknown,\n): CallToolResult[\"content\"] {\n if (!presentation?.length) {\n return [{ type: \"text\", text: stringify(output) }];\n }\n const content: CallToolResult[\"content\"] = [];\n for (const part of presentation) {\n if (part.type === \"markdown\") {\n content.push({ type: \"text\", text: renderPresentationMarkdown(part) });\n continue;\n }\n if (part.type === \"table\") {\n content.push({\n type: \"text\",\n text: renderPresentationMarkdown(part),\n });\n continue;\n }\n if (part.type === \"image\") {\n content.push(\n { type: \"text\", text: `[Image: ${part.alt}]` },\n {\n type: \"image\",\n data: part.base64,\n mimeType: part.mimeType,\n },\n );\n continue;\n }\n content.push({\n type: \"resource_link\",\n uri: part.url,\n name: part.name,\n ...(part.description ? { description: part.description } : {}),\n ...(part.mimeType ? { mimeType: part.mimeType } : {}),\n ...(part.size === undefined ? {} : { size: part.size }),\n });\n }\n return content;\n}\n\nfunction stringify(value: unknown): string {\n return typeof value === \"string\"\n ? value\n : JSON.stringify(value) ?? String(value);\n}\n","import { CapableError, isPublicError } from \"@capable/core\";\nimport { TransportError } from \"@capable/app\";\nimport type { CallToolResult, Icon, Tool } from \"@modelcontextprotocol/server\";\nimport type { McpIcon, McpTool } from \"./index.ts\";\nimport { toMcpContent } from \"./presentation.ts\";\n\nexport async function callMcpTool(\n tool: McpTool,\n input: unknown,\n signal: AbortSignal,\n onError?: (error: unknown) => void,\n): Promise<CallToolResult> {\n try {\n const result = await tool.call(input ?? {}, { signal });\n return {\n content: toMcpContent(result.presentation, result.output),\n structuredContent: result.output,\n };\n } catch (error) {\n if (\n isPublicError(error) &&\n (error instanceof CapableError || error instanceof TransportError)\n ) {\n if (error.code === \"INTERNAL_SERVER_ERROR\") onError?.(error);\n return toolError(error.message, {\n code: error.code,\n status: error.status,\n data: error.data,\n });\n }\n if (signal.aborted) throw error;\n onError?.(error);\n return toolError(\"INTERNAL_SERVER_ERROR\", {\n code: \"INTERNAL_SERVER_ERROR\",\n status: 500,\n });\n }\n}\n\nexport function toProtocolTool(tool: McpTool) {\n return {\n name: tool.name,\n ...(tool.title ? { title: tool.title } : {}),\n ...(tool.description ? { description: tool.description } : {}),\n ...(tool.icons ? { icons: toProtocolIcons(tool.icons) } : {}),\n inputSchema: tool.inputSchema as Tool[\"inputSchema\"],\n ...(tool.outputSchema\n ? { outputSchema: tool.outputSchema as Tool[\"outputSchema\"] }\n : {}),\n _meta: tool._meta,\n annotations: tool.annotations,\n } satisfies Tool;\n}\n\nexport function toProtocolIcons(icons: readonly McpIcon[]): Icon[] {\n return icons.map((icon) => ({\n src: icon.src,\n ...(icon.mimeType !== undefined ? { mimeType: icon.mimeType } : {}),\n ...(icon.sizes !== undefined ? { sizes: [...icon.sizes] } : {}),\n ...(icon.theme !== undefined ? { theme: icon.theme } : {}),\n }));\n}\n\nexport function toolError(\n message: string,\n details?: Record<string, unknown>,\n): CallToolResult {\n return {\n isError: true,\n content: [{\n type: \"text\",\n text: details ? JSON.stringify({ message, ...details }) : message,\n }],\n };\n}\n\n","import type {\n McpServer,\n RegisteredTool,\n StandardSchemaWithJSON,\n} from \"@modelcontextprotocol/server\";\nimport type { McpTool } from \"./index.ts\";\nimport { callMcpTool, toProtocolTool } from \"./protocol.ts\";\n\n/** Register App-backed tools alongside native SDK tools and resources. */\nexport function registerCapableTools(\n server: McpServer,\n tools: readonly McpTool[],\n): RegisteredTool[] {\n return tools.map((tool) => {\n const { name, inputSchema, outputSchema, ...descriptor } = toProtocolTool(tool);\n return server.registerTool<StandardSchemaWithJSON, StandardSchemaWithJSON>(\n name,\n {\n ...descriptor,\n inputSchema: protocolSchema(inputSchema),\n ...(outputSchema ? { outputSchema: protocolSchema(outputSchema) } : {}),\n },\n (input, context) => callMcpTool(tool, input, context.mcpReq.signal),\n );\n });\n}\n\nfunction protocolSchema(schema: McpTool[\"inputSchema\"]): StandardSchemaWithJSON {\n // Advertise the original schema, but delegate parsing to the source App\n // executor. SDK validation before execution would change BAD_REQUEST errors\n // and could apply defaults/transforms twice. Output validation also stays\n // with the source executor; the SDK still owns output presence and projection.\n return {\n \"~standard\": {\n version: 1,\n vendor: \"capable\",\n validate: (value) => ({ value }),\n jsonSchema: {\n input: () => schema,\n output: () => schema,\n },\n },\n };\n}\n","import type { CapabilityMetaRegistry } from \"@capable/core\";\nimport {\n getAppRuntime,\n getCapabilityDisplay,\n getCapabilityNavigationMeta,\n flattenManifestCapabilities,\n type AnyApp,\n type JsonSchema,\n type ManifestCapability,\n type CapabilityResult,\n} from \"@capable/app\";\n\nexport type McpCapabilityMeta =\n | false\n | {\n readonly name?: string;\n readonly icons?: readonly McpIcon[];\n readonly idempotentHint?: boolean;\n readonly openWorldHint?: boolean;\n };\n\ndeclare global {\n interface CapableCustomizationMeta {\n readonly mcp?: McpCapabilityMeta;\n }\n}\n\nexport type McpIcon = {\n readonly src: string;\n readonly mimeType?: string;\n readonly sizes?: readonly string[];\n readonly theme?: \"light\" | \"dark\";\n};\n\ndeclare module \"@capable/core\" {\n interface CapabilityMetaRegistry {\n readonly mcp?: McpCapabilityMeta;\n }\n}\n\nexport type McpToolNameFormatter = (capability: ManifestCapability) => string;\n\nexport type CreateMcpOptions = {\n readonly toolName?: McpToolNameFormatter;\n};\n\nexport type McpTool = {\n readonly name: string;\n readonly title?: string;\n readonly description?: string;\n readonly icons?: readonly McpIcon[];\n readonly inputSchema: JsonSchema;\n readonly outputSchema?: JsonSchema;\n readonly _meta: {\n readonly \"dev.capable/capabilityId\": string;\n };\n readonly annotations: {\n readonly readOnlyHint: boolean;\n readonly destructiveHint: boolean;\n readonly idempotentHint?: boolean;\n readonly openWorldHint?: boolean;\n };\n call(\n input: unknown,\n options?: { readonly signal?: AbortSignal },\n ): Promise<CapabilityResult>;\n};\n\nexport async function createMcp(\n app: AnyApp,\n options: CreateMcpOptions = {},\n): Promise<readonly McpTool[]> {\n const runtime = getAppRuntime(app);\n const manifest = await runtime.manifest();\n const tools = flattenManifestCapabilities(manifest.capabilities)\n .map((capability) => ({ ...capability, ...getCapabilityDisplay(capability) }))\n .filter((capability) => {\n const meta = capability.meta.mcp;\n if (meta === false) return false;\n if (capability.execution !== \"events\") return true;\n if (meta !== undefined) {\n throw new Error(\n `Event Capability \"${capability.id}\" cannot be exposed as an MCP tool`,\n );\n }\n return false;\n })\n .map((capability) => {\n const meta = readMcpMeta(capability);\n const navigation = getCapabilityNavigationMeta(capability, \"mcp\");\n const explicitName = navigation === false ? undefined : navigation?.name;\n return Object.freeze({\n name: explicitName ?? formatToolName(capability, options.toolName),\n ...(capability.title ? { title: capability.title } : {}),\n ...(capability.description ? { description: capability.description } : {}),\n ...(meta?.icons ? { icons: meta.icons } : {}),\n inputSchema: capability.input ?? {\n type: \"object\",\n properties: {},\n additionalProperties: false,\n },\n ...(capability.output\n ? { outputSchema: capability.output }\n : {}),\n _meta: {\n \"dev.capable/capabilityId\": capability.id,\n },\n annotations: {\n readOnlyHint: capability.effect === \"read\",\n destructiveHint: capability.effect === \"destructive\",\n ...(meta?.idempotentHint !== undefined\n ? { idempotentHint: meta.idempotentHint }\n : {}),\n ...(meta?.openWorldHint !== undefined\n ? { openWorldHint: meta.openWorldHint }\n : {}),\n },\n call(input: unknown, options?: { readonly signal?: AbortSignal }) {\n return runtime.call({\n id: capability.id,\n input,\n presentation: true,\n ...(options?.signal ? { signal: options.signal } : {}),\n });\n },\n });\n });\n const names = new Set<string>();\n for (const tool of tools) {\n if (names.has(tool.name)) {\n throw new Error(`Duplicate MCP tool name \"${tool.name}\"`);\n }\n names.add(tool.name);\n }\n return tools;\n}\n\nfunction formatToolName(\n capability: ManifestCapability,\n formatter: McpToolNameFormatter | undefined,\n): string {\n if (!formatter) return capability.path.join(\"__\");\n const name: unknown = formatter(capability);\n if (typeof name !== \"string\" || name.length === 0) {\n throw new Error(\n `Capability \"${capability.id}\" produced an invalid MCP tool name: toolName must return a non-empty string`,\n );\n }\n return name;\n}\n\nfunction readMcpMeta(\n capability: ManifestCapability,\n): Exclude<McpCapabilityMeta, false> | undefined {\n const value = capability.meta.mcp;\n if (value === undefined) return undefined;\n if (!isRecord(value)) return invalidMcpMeta(capability, \"must be an object\");\n if (value.name !== undefined && typeof value.name !== \"string\") {\n return invalidMcpMeta(capability, \"name must be a string\");\n }\n if (\n value.idempotentHint !== undefined &&\n typeof value.idempotentHint !== \"boolean\"\n ) {\n return invalidMcpMeta(capability, \"idempotentHint must be a boolean\");\n }\n if (\n value.openWorldHint !== undefined &&\n typeof value.openWorldHint !== \"boolean\"\n ) {\n return invalidMcpMeta(capability, \"openWorldHint must be a boolean\");\n }\n if (\n value.icons !== undefined &&\n (!Array.isArray(value.icons) || !value.icons.every(isMcpIcon))\n ) {\n return invalidMcpMeta(capability, \"icons must be MCP icon descriptors\");\n }\n return value as Exclude<McpCapabilityMeta, false>;\n}\n\nfunction isMcpIcon(value: unknown): value is McpIcon {\n if (!isRecord(value) || typeof value.src !== \"string\") return false;\n if (value.mimeType !== undefined && typeof value.mimeType !== \"string\") {\n return false;\n }\n if (\n value.sizes !== undefined &&\n (!Array.isArray(value.sizes) ||\n !value.sizes.every((size) => typeof size === \"string\"))\n ) {\n return false;\n }\n return value.theme === undefined || value.theme === \"light\" ||\n value.theme === \"dark\";\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction invalidMcpMeta(\n capability: ManifestCapability,\n reason: string,\n): never {\n throw new Error(\n `Capability \"${capability.id}\" has invalid MCP metadata: ${reason}`,\n );\n}\n\nexport { registerCapableTools } from \"./register.ts\";\n","import type { ServerMount } from \"@capable/server\";\nimport {\n createApp,\n selectApp,\n type ApplicationSelection,\n} from \"@capable/app\";\nimport {\n createMcpHandler,\n Server,\n type Implementation,\n} from \"@modelcontextprotocol/server\";\nimport {\n createMcp,\n type McpIcon,\n type McpTool,\n type McpToolNameFormatter,\n} from \"./index.ts\";\nimport {\n callMcpTool,\n toProtocolIcons,\n toProtocolTool,\n toolError,\n} from \"./protocol.ts\";\n\nexport type McpCacheHint = {\n readonly ttlMs?: number;\n readonly cacheScope?: \"public\" | \"private\";\n};\n\nexport type McpMountOptions = {\n readonly path?: string;\n readonly name?: string;\n readonly version?: string;\n readonly title?: string;\n readonly description?: string;\n readonly websiteUrl?: string;\n readonly icons?: readonly McpIcon[];\n readonly instructions?: string;\n readonly selection?: ApplicationSelection;\n readonly toolName?: McpToolNameFormatter;\n readonly cache?: {\n readonly discovery?: McpCacheHint;\n readonly tools?: McpCacheHint;\n };\n};\n\nexport function mcp<TContext = any>(\n options: McpMountOptions = {},\n): ServerMount<TContext> {\n validateCacheHint(options.cache?.discovery, \"discovery\");\n validateCacheHint(options.cache?.tools, \"tools\");\n const path = normalizePath(options.path ?? \"/mcp\");\n return {\n kind: \"capable.server.mount\",\n compile(app, context, onError) {\n const description = options.description ?? app.description;\n const handler = createMcpHandler(async ({ requestInfo }) => {\n try {\n if (!requestInfo) {\n throw new Error(\n \"The MCP HTTP handler requires request information\",\n );\n }\n const executable = createApp(\n app,\n context\n ? { context: () => context({ request: requestInfo }) }\n : undefined as never,\n );\n const exposed = options.selection\n ? selectApp(executable, options.selection)\n : executable;\n const tools = await createMcp(\n exposed,\n options.toolName ? { toolName: options.toolName } : undefined,\n );\n return createMcpServer(tools, {\n name: options.name ?? app.name ?? \"capable\",\n version: options.version ?? app.version ?? \"0.0.0\",\n ...(options.title !== undefined ? { title: options.title } : {}),\n ...(description !== undefined\n ? { description }\n : {}),\n ...(options.websiteUrl !== undefined\n ? { websiteUrl: options.websiteUrl }\n : {}),\n ...(options.icons !== undefined\n ? { icons: toProtocolIcons(options.icons) }\n : {}),\n }, options, onError);\n } catch (error) {\n onError?.(error);\n throw error;\n }\n }, {\n legacy: \"stateless\",\n });\n return {\n name: \"mcp\",\n async fetch(request) {\n if (new URL(request.url).pathname !== path) return undefined;\n return handler.fetch(request);\n },\n };\n },\n };\n}\n\nfunction createMcpServer(\n tools: readonly McpTool[],\n info: Implementation,\n options: Pick<McpMountOptions, \"instructions\" | \"cache\">,\n onError?: (error: unknown) => void,\n): Server {\n const server = new Server(info, {\n capabilities: { tools: {} },\n ...(options.instructions !== undefined\n ? { instructions: options.instructions }\n : {}),\n ...(options.cache !== undefined\n ? {\n cacheHints: {\n ...(options.cache.discovery !== undefined\n ? { \"server/discover\": options.cache.discovery }\n : {}),\n ...(options.cache.tools !== undefined\n ? { \"tools/list\": options.cache.tools }\n : {}),\n },\n }\n : {}),\n });\n server.setRequestHandler(\"tools/list\", () => ({\n tools: tools.map(toProtocolTool),\n }));\n server.setRequestHandler(\"tools/call\", async (request, context) => {\n const tool = tools.find(({ name }) => name === request.params.name);\n if (!tool) {\n return toolError(`Unknown tool \"${request.params.name}\"`);\n }\n const result = await callMcpTool(\n tool,\n request.params.arguments,\n context.mcpReq.signal,\n onError,\n );\n return result.isError\n ? result\n : server.projectCallToolResult(result, tool.outputSchema);\n });\n return server;\n}\n\nfunction normalizePath(value: string): string {\n return `/${value.split(\"/\").filter(Boolean).join(\"/\")}`;\n}\n\nfunction validateCacheHint(\n hint: McpCacheHint | undefined,\n field: \"discovery\" | \"tools\",\n): void {\n if (!hint) return;\n if (\n hint.ttlMs !== undefined &&\n (!Number.isSafeInteger(hint.ttlMs) || hint.ttlMs < 0)\n ) {\n throw new RangeError(\n `MCP ${field} cache ttlMs must be a non-negative safe integer`,\n );\n }\n if (\n hint.cacheScope !== undefined &&\n hint.cacheScope !== \"public\" &&\n hint.cacheScope !== \"private\"\n ) {\n throw new RangeError(\n `MCP ${field} cache cacheScope must be \"public\" or \"private\"`,\n );\n }\n}\n"],"mappings":";;;;AAMA,SAAgB,aACd,cACA,QAC2B;CAC3B,IAAI,CAAC,cAAc,QACjB,OAAO,CAAC;EAAE,MAAM;EAAQ,MAAM,UAAU,MAAM;CAAE,CAAC;CAEnD,MAAM,UAAqC,CAAC;CAC5C,KAAK,MAAM,QAAQ,cAAc;EAC/B,IA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qB,EAC5C,OAAO,MAAM,IAAI,cAAc,EACjC,EAAE;CACF,OAAO,kBAAkB,cAAc,OAAO,SAAS,YAAY;EACjE,MAAM,OAAO,MAAM,MAAM,EAAE,WAAW,SAAS,QAAQ,OAAO,IAAI;EAClE,IAAI,CAAC,MACH,OAAO,UAAU,iBAAiB,QAAQ,OAAO,KAAK,EAAE;EAE1D,MAAM,SAAS,MAAM,YACnB,MACA,QAAQ,OAAO,WACf,QAAQ,OAAO,QACf,OACF;EACA,OAAO,OAAO,UACV,SACA,OAAO,sBAAsB,QAAQ,KAAK,YAAY;CAC5D,CAAC;CACD,OAAO;AACT;AAEA,SAAS,cAAc,OAAuB;CAC5C,OAAO,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACtD;AAEA,SAAS,kBACP,MACA,OACM;CACN,IAAI,CAAC,MAAM;CACX,IACE,KAAK,UAAU,KAAA,MACd,CAAC,OAAO,cAAc,KAAK,KAAK,KAAK,KAAK,QAAQ,IAEnD,MAAM,IAAI,WACR,OAAO,MAAM,iDACf;CAEF,IACE,KAAK,eAAe,KAAA,KACpB,KAAK,eAAe,YACpB,KAAK,eAAe,WAEpB,MAAM,IAAI,WACR,OAAO,MAAM,gDACf;AAEJ"}
|
package/dist/react-query.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as AppCapabilityReference, h as AppCapabilityIsLive } from "./index-
|
|
1
|
+
import { _ as AppCapabilityReference, h as AppCapabilityIsLive } from "./index-F_eaksy8.mjs";
|
|
2
2
|
import { QueryFunction, QueryKey, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
3
3
|
//#region packages/react-query/src/index.d.ts
|
|
4
4
|
type CapabilityCall = (...args: any[]) => Promise<any>;
|
package/dist/react-query.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as CapableServer } from "./index-
|
|
1
|
+
import { t as CapableServer } from "./index-C0tU5Y2n.mjs";
|
|
2
2
|
//#region packages/nitro-host/src/runtime-support.d.ts
|
|
3
3
|
type CapableNitroEntryOptions = {
|
|
4
4
|
/** The default export of the project's `capable.app.*`. */
|
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 protocol, t as createServer } from "./src-
|
|
1
|
+
import { t as createHttpHandler } from "./src-Bk3lEhI7.mjs";
|
|
2
|
+
import { t as mcp } from "./mount-pvIaehZC.mjs";
|
|
3
|
+
import { n as http, r as protocol, t as createServer } from "./src-DFrxQ_S6.mjs";
|
|
4
4
|
//#region packages/nitro-host/src/dev-index.ts
|
|
5
5
|
function devIndex() {
|
|
6
6
|
return {
|
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 protocol, t as CapableServer } from "./index-
|
|
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-C0tU5Y2n.mjs";
|
|
2
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 protocol, t as createServer } from "./src-
|
|
1
|
+
import { n as http, r as protocol, t as createServer } from "./src-DFrxQ_S6.mjs";
|
|
2
2
|
export { createServer, http, protocol };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { _ as normalizePresentation, h as schemaToJsonSchema, l as executeLocatedCapability, x as CapableError, y as renderPresentationMarkdown } from "./src-
|
|
2
|
-
import { c as TransportError, d as getAppRuntime, f as isApp, h as flattenManifestCapabilities } from "./src-
|
|
1
|
+
import { C as isPublicError, T as unmarkPublicError, _ as normalizePresentation, h as schemaToJsonSchema, l as executeLocatedCapability, w as markPublicError, x as CapableError, y as renderPresentationMarkdown } from "./src-TCQGaWar.mjs";
|
|
2
|
+
import { c as TransportError, d as getAppRuntime, f as isApp, h as flattenManifestCapabilities } from "./src-C2OEkZ3c.mjs";
|
|
3
3
|
import SuperJSON from "superjson";
|
|
4
4
|
//#region packages/fetch/src/error-response.ts
|
|
5
|
+
function isInternalCapabilityError(error) {
|
|
6
|
+
if (!isPublicError(error) || !(error instanceof CapableError || error instanceof TransportError)) return true;
|
|
7
|
+
return error.code === "INTERNAL_SERVER_ERROR";
|
|
8
|
+
}
|
|
5
9
|
function capabilityErrorData(error, fallbackStatus = 500) {
|
|
6
|
-
const capable = error instanceof CapableError || error instanceof TransportError ? error : new CapableError("INTERNAL_SERVER_ERROR", { cause: error });
|
|
10
|
+
const capable = isPublicError(error) && (error instanceof CapableError || error instanceof TransportError) ? error : new CapableError("INTERNAL_SERVER_ERROR", { cause: error });
|
|
7
11
|
return {
|
|
8
12
|
code: capable.code,
|
|
9
13
|
message: capable.message,
|
|
@@ -64,10 +68,11 @@ function createProtocolHandler(application, options = {}) {
|
|
|
64
68
|
});
|
|
65
69
|
let first;
|
|
66
70
|
if (execution === "live") first = await stream.next();
|
|
67
|
-
return subscriptionResponse(stream, first, controller, codec);
|
|
71
|
+
return subscriptionResponse(stream, first, controller, codec, options.onError);
|
|
68
72
|
} catch (error) {
|
|
69
73
|
controller.abort();
|
|
70
74
|
await stream?.return?.().catch(() => void 0);
|
|
75
|
+
if (isInternalCapabilityError(error)) options.onError?.(error);
|
|
71
76
|
return protocolErrorResponse(error, codec);
|
|
72
77
|
}
|
|
73
78
|
}
|
|
@@ -87,6 +92,7 @@ function createProtocolHandler(application, options = {}) {
|
|
|
87
92
|
...result
|
|
88
93
|
});
|
|
89
94
|
} catch (error) {
|
|
95
|
+
if (isInternalCapabilityError(error)) options.onError?.(error);
|
|
90
96
|
return protocolErrorResponse(error, codec);
|
|
91
97
|
}
|
|
92
98
|
};
|
|
@@ -94,28 +100,28 @@ function createProtocolHandler(application, options = {}) {
|
|
|
94
100
|
}
|
|
95
101
|
async function protocolRequestJson(request, codec) {
|
|
96
102
|
const received = request.headers.get(PROTOCOL_CODEC_HEADER);
|
|
97
|
-
if (received !== codec.id) throw new TransportError("UNSUPPORTED_CODEC", {
|
|
103
|
+
if (received !== codec.id) throw markPublicError(new TransportError("UNSUPPORTED_CODEC", {
|
|
98
104
|
status: 415,
|
|
99
105
|
message: `Protocol codec mismatch: expected "${codec.id}", received "${received ?? "none"}"`,
|
|
100
106
|
data: {
|
|
101
107
|
expected: codec.id,
|
|
102
108
|
received
|
|
103
109
|
}
|
|
104
|
-
});
|
|
110
|
+
}));
|
|
105
111
|
let decoded;
|
|
106
112
|
try {
|
|
107
113
|
decoded = codec.decode(await request.json());
|
|
108
114
|
} catch (cause) {
|
|
109
|
-
throw new TransportError("BAD_REQUEST", {
|
|
115
|
+
throw markPublicError(new TransportError("BAD_REQUEST", {
|
|
110
116
|
status: 400,
|
|
111
117
|
message: "Protocol request could not be decoded",
|
|
112
118
|
cause
|
|
113
|
-
});
|
|
119
|
+
}));
|
|
114
120
|
}
|
|
115
|
-
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) throw new TransportError("BAD_REQUEST", {
|
|
121
|
+
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) throw markPublicError(new TransportError("BAD_REQUEST", {
|
|
116
122
|
status: 400,
|
|
117
123
|
message: "Protocol request must decode to an object"
|
|
118
|
-
});
|
|
124
|
+
}));
|
|
119
125
|
return decoded;
|
|
120
126
|
}
|
|
121
127
|
function protocolResponse(codec, value, init = {}) {
|
|
@@ -172,7 +178,7 @@ function createHttpTransport(options) {
|
|
|
172
178
|
});
|
|
173
179
|
if (!response.ok) throw await responseError(response, codec);
|
|
174
180
|
const body = await protocolResponseJson(response, codec, "Capability call");
|
|
175
|
-
if (!body.ok) throw new TransportError(body.error.code, body.error);
|
|
181
|
+
if (!body.ok) throw markPublicError(new TransportError(body.error.code, body.error));
|
|
176
182
|
return {
|
|
177
183
|
output: body.output,
|
|
178
184
|
...body.presentation ? { presentation: body.presentation } : {}
|
|
@@ -198,7 +204,7 @@ function createHttpTransport(options) {
|
|
|
198
204
|
}
|
|
199
205
|
});
|
|
200
206
|
}
|
|
201
|
-
function subscriptionResponse(stream, first, subscriptionController, codec) {
|
|
207
|
+
function subscriptionResponse(stream, first, subscriptionController, codec, onError) {
|
|
202
208
|
const encoder = new TextEncoder();
|
|
203
209
|
let initial = first;
|
|
204
210
|
let cancelled = false;
|
|
@@ -220,6 +226,7 @@ function subscriptionResponse(stream, first, subscriptionController, codec) {
|
|
|
220
226
|
} catch (error) {
|
|
221
227
|
if (cancelled) return;
|
|
222
228
|
subscriptionController.abort();
|
|
229
|
+
if (isInternalCapabilityError(error)) onError?.(error);
|
|
223
230
|
controller.enqueue(encoder.encode(sseFrame("error", capabilityErrorData(error), codec)));
|
|
224
231
|
controller.close();
|
|
225
232
|
await stream.return?.();
|
|
@@ -261,7 +268,7 @@ async function* decodeEventStreamBody(body, codec) {
|
|
|
261
268
|
buffer = buffer.slice(boundary.index + boundary.length);
|
|
262
269
|
const event = parseEventBlock(block, codec);
|
|
263
270
|
if (event) {
|
|
264
|
-
if (event.type === "error") throw new TransportError(event.error.code, event.error);
|
|
271
|
+
if (event.type === "error") throw markPublicError(new TransportError(event.error.code, event.error));
|
|
265
272
|
yield event.result;
|
|
266
273
|
}
|
|
267
274
|
boundary = eventBoundary(buffer);
|
|
@@ -375,11 +382,11 @@ async function responseError(response, codec) {
|
|
|
375
382
|
}
|
|
376
383
|
if (data && typeof data === "object" && "ok" in data && data.ok === false && "error" in data && data.error && typeof data.error === "object" && "code" in data.error && typeof data.error.code === "string") {
|
|
377
384
|
const error = data.error;
|
|
378
|
-
return new TransportError(error.code, {
|
|
385
|
+
return markPublicError(new TransportError(error.code, {
|
|
379
386
|
...typeof error.message === "string" ? { message: error.message } : {},
|
|
380
387
|
status: typeof error.status === "number" ? error.status : response.status,
|
|
381
388
|
..."data" in error ? { data: error.data } : {}
|
|
382
|
-
});
|
|
389
|
+
}));
|
|
383
390
|
}
|
|
384
391
|
return new TransportError("TRANSPORT_ERROR", {
|
|
385
392
|
status: response.status,
|
|
@@ -441,13 +448,25 @@ function createHttpHandler(app, options = {}) {
|
|
|
441
448
|
if (!match?.params) return new Response("Not Found", { status: 404 });
|
|
442
449
|
try {
|
|
443
450
|
const input = await readHttpInput(request, match.params, match.route.capability.capability.input);
|
|
444
|
-
|
|
451
|
+
let context;
|
|
452
|
+
try {
|
|
453
|
+
context = options.context ? await options.context({ request }) : void 0;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
if (error instanceof CapableError || error instanceof TransportError) markPublicError(error);
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
445
458
|
const output = await executeLocatedCapability(match.route.capability, input, {
|
|
446
459
|
context,
|
|
447
460
|
signal: request.signal
|
|
448
461
|
});
|
|
449
462
|
if (request.headers.get("accept")?.includes("text/markdown") && match.route.capability.capability.toPresentation) {
|
|
450
|
-
|
|
463
|
+
let presentation;
|
|
464
|
+
try {
|
|
465
|
+
presentation = normalizePresentation(await match.route.capability.capability.toPresentation(output, { context }));
|
|
466
|
+
} catch (error) {
|
|
467
|
+
unmarkPublicError(error);
|
|
468
|
+
throw error;
|
|
469
|
+
}
|
|
451
470
|
if (presentation.length > 0) return new Response(renderPresentationMarkdown(presentation), {
|
|
452
471
|
status: httpSuccessStatus(match.route.capability),
|
|
453
472
|
headers: { "content-type": "text/markdown; charset=utf-8" }
|
|
@@ -455,6 +474,7 @@ function createHttpHandler(app, options = {}) {
|
|
|
455
474
|
}
|
|
456
475
|
return Response.json(output, { status: httpSuccessStatus(match.route.capability) });
|
|
457
476
|
} catch (error) {
|
|
477
|
+
if (isInternalCapabilityError(error)) options.onError?.(error);
|
|
458
478
|
return capabilityErrorResponse(error);
|
|
459
479
|
}
|
|
460
480
|
}
|
|
@@ -612,4 +632,4 @@ function joinPath(...parts) {
|
|
|
612
632
|
//#endregion
|
|
613
633
|
export { defineProtocolCodec as i, createHttpTransport as n, createProtocolHandler as r, createHttpHandler as t };
|
|
614
634
|
|
|
615
|
-
//# sourceMappingURL=src-
|
|
635
|
+
//# sourceMappingURL=src-Bk3lEhI7.mjs.map
|