capable-kit 0.0.1-alpha.8 → 0.1.0-alpha.9
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 +108 -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 +2 -2
- package/dist/bin.mjs +4 -4
- package/dist/cli.d.mts +4 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +2 -2
- package/dist/core.mjs +1 -1
- package/dist/eve.d.mts +82 -5
- package/dist/eve.mjs +358 -19
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-F4ba_olD.d.mts → index-D63DSGZG.d.mts} +10 -5
- package/dist/{index-Dl4NK9G0.d.mts → index-D8DWjQ9f.d.mts} +3 -3
- package/dist/{index-hdH_K5Zc.d.mts → index-DgxvtAmv.d.mts} +4 -4
- package/dist/{index-_qKFfWV4.d.mts → index-ftQx6OMr.d.mts} +23 -13
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +2 -2
- package/dist/mcp.mjs +1 -1
- package/dist/{mount-CEFAplR5.mjs → mount-B9TrHWHh.mjs} +3 -3
- package/dist/{mount-CEFAplR5.mjs.map → mount-B9TrHWHh.mjs.map} +1 -1
- 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-betOfnDL.mjs → src-B592M-6b.mjs} +143 -44
- package/dist/src-B592M-6b.mjs.map +1 -0
- package/dist/{src-D-cm2gQ6.mjs → src-Bd1Vnze8.mjs} +16 -2
- package/dist/src-Bd1Vnze8.mjs.map +1 -0
- package/dist/{src-BWxDO2Ua.mjs → src-CKC1BdXO.mjs} +3 -3
- package/dist/{src-BWxDO2Ua.mjs.map → src-CKC1BdXO.mjs.map} +1 -1
- package/dist/{src-D_0PIhqq.mjs → src-CL9eA6_p.mjs} +42 -25
- package/dist/src-CL9eA6_p.mjs.map +1 -0
- package/dist/{src-rkr5j_NH.mjs → src-Hw9WBgEW.mjs} +3 -3
- package/dist/{src-rkr5j_NH.mjs.map → src-Hw9WBgEW.mjs.map} +1 -1
- package/dist/{subscription-B-auXJbm.d.mts → subscription-DbnHcm7C.d.mts} +2 -2
- package/dist/swr.d.mts +1 -1
- package/dist/swr.mjs +1 -1
- package/docs/CONTEXT.md +17 -10
- package/docs/README.md +3 -0
- package/docs/internal/README.md +3 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +1 -1
- package/docs/internal/architecture.md +11 -10
- package/docs/internal/capability-first-model.md +31 -8
- package/docs/internal/eve-recovery-validation.md +86 -0
- package/docs/internal/feedback/v-ray/README.md +258 -0
- package/docs/internal/feedback/v-ray/inference.mjs +43 -0
- package/docs/internal/feedback/v-ray/reproduce.mjs +36 -0
- package/docs/internal/implementation-friction.md +301 -1
- package/docs/internal/releases.md +79 -0
- package/docs/site/capable-orpc-and-trpc.mdx +2 -2
- package/docs/site/concepts/apps.mdx +6 -0
- package/docs/site/concepts/architecture.mdx +1 -1
- package/docs/site/concepts/capabilities.mdx +39 -2
- package/docs/site/concepts/errors.mdx +11 -1
- package/docs/site/concepts/presentations.mdx +16 -0
- package/docs/site/patterns/composition.mdx +50 -8
- package/docs/site/patterns/remote-apps.mdx +1 -1
- package/docs/site/quickstart.mdx +1 -1
- package/docs/site/reference/packages-and-entry-points.mdx +11 -3
- package/docs/site/surfaces/cli.mdx +33 -0
- package/docs/site/surfaces/eve.mdx +65 -18
- package/docs/site/surfaces/typescript.mdx +1 -1
- package/package-docs.mjs +3 -0
- package/package.json +10 -11
- package/src/bin.ts +0 -0
- package/src/index.test.ts +1 -1
- package/src/index.ts +1 -1
- package/dist/src-D-cm2gQ6.mjs.map +0 -1
- package/dist/src-D_0PIhqq.mjs.map +0 -1
- package/dist/src-betOfnDL.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as normalizePresentation, a as isCapabilityGroup, f as subscribeLocatedCapability, h as schemaToJsonSchema, l as executeLocatedCapability, u as isCapability, x as CapableError } from "./src-
|
|
1
|
+
import { _ as normalizePresentation, a as isCapabilityGroup, f as subscribeLocatedCapability, h as schemaToJsonSchema, l as executeLocatedCapability, u as isCapability, x as CapableError } from "./src-Bd1Vnze8.mjs";
|
|
2
2
|
//#region packages/app/src/manifest.ts
|
|
3
3
|
function createAppManifest(definition) {
|
|
4
4
|
const byCapability = new Map(definition.locatedCapabilities.map((entry) => [entry.capability, entry]));
|
|
@@ -13,24 +13,27 @@ function createAppManifest(definition) {
|
|
|
13
13
|
function validateManifest(manifest, label) {
|
|
14
14
|
if (manifest.protocol !== "capable.capabilities.v3") throw new Error(`${label} uses unsupported protocol "${manifest.protocol}"`);
|
|
15
15
|
const capabilities = flattenManifestCapabilities(manifest.capabilities);
|
|
16
|
-
const ids = /* @__PURE__ */ new
|
|
16
|
+
const ids = /* @__PURE__ */ new Map();
|
|
17
17
|
const paths = /* @__PURE__ */ new Set();
|
|
18
18
|
for (const capability of capabilities) {
|
|
19
19
|
const path = capability.path.join(".");
|
|
20
|
-
|
|
20
|
+
const previous = ids.get(capability.id);
|
|
21
|
+
if (previous && !sameCapabilityContract(previous, capability)) throw new Error(`${label} contains conflicting definitions for Capability id "${capability.id}"`);
|
|
21
22
|
if (paths.has(path)) throw new Error(`${label} contains duplicate Capability path "${path}"`);
|
|
22
|
-
ids.
|
|
23
|
+
ids.set(capability.id, capability);
|
|
23
24
|
paths.add(path);
|
|
24
25
|
}
|
|
25
26
|
validateManifestPaths(manifest.capabilities, [], label);
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
const conflicts = collectManifestConflicts(
|
|
29
|
-
if (conflicts.length) throw new Error(`Cannot
|
|
28
|
+
function composeApplicationManifests(sources) {
|
|
29
|
+
const conflicts = collectManifestConflicts(sources);
|
|
30
|
+
if (conflicts.length) throw new Error(`Cannot compose Apps:\n${conflicts.map((item) => `- ${item}`).join("\n")}`);
|
|
31
|
+
const manifests = sources.map(({ manifest }) => manifest);
|
|
32
|
+
const applications = sources.filter((source, index) => sources.findIndex(({ owner }) => owner === source.owner) === index).map(({ manifest }) => manifest);
|
|
30
33
|
return Object.freeze({
|
|
31
34
|
protocol: "capable.capabilities.v3",
|
|
32
|
-
name:
|
|
33
|
-
version:
|
|
35
|
+
name: applications.map(({ name }) => name).join(" + "),
|
|
36
|
+
version: applications.map(({ version }) => version).join(" + "),
|
|
34
37
|
capabilities: mergeManifestNodes(manifests.flatMap(({ capabilities }) => capabilities))
|
|
35
38
|
});
|
|
36
39
|
}
|
|
@@ -119,19 +122,20 @@ function validateManifestPaths(nodes, parent, label) {
|
|
|
119
122
|
validateManifestPaths(node.children, [...parent, node.key], label);
|
|
120
123
|
continue;
|
|
121
124
|
}
|
|
122
|
-
if (!samePath(node.path, [...parent, node.path.at(-1)])) throw new Error(`${label} Capability "${node.id}" declares path "${node.path.join(".")}" that does not match its manifest placement`);
|
|
125
|
+
if (!samePath$1(node.path, [...parent, node.path.at(-1)])) throw new Error(`${label} Capability "${node.id}" declares path "${node.path.join(".")}" that does not match its manifest placement`);
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
|
-
function collectManifestConflicts(
|
|
128
|
+
function collectManifestConflicts(sources) {
|
|
126
129
|
const conflicts = [];
|
|
127
|
-
for (const manifest of
|
|
130
|
+
for (const { manifest } of sources) try {
|
|
128
131
|
validateManifest(manifest, manifest.name);
|
|
129
132
|
} catch (error) {
|
|
130
133
|
conflicts.push(error instanceof Error ? error.message : String(error));
|
|
131
134
|
}
|
|
132
|
-
const capabilities =
|
|
135
|
+
const capabilities = sources.flatMap(({ manifest, owner }, source) => flattenManifestCapabilities(manifest.capabilities).map((capability) => ({
|
|
133
136
|
capability,
|
|
134
137
|
source,
|
|
138
|
+
owner,
|
|
135
139
|
label: manifest.name
|
|
136
140
|
})));
|
|
137
141
|
for (let leftIndex = 0; leftIndex < capabilities.length; leftIndex++) for (let rightIndex = leftIndex + 1; rightIndex < capabilities.length; rightIndex++) {
|
|
@@ -139,11 +143,13 @@ function collectManifestConflicts(manifests) {
|
|
|
139
143
|
const right = capabilities[rightIndex];
|
|
140
144
|
if (left.source === right.source) continue;
|
|
141
145
|
const sameId = left.capability.id === right.capability.id;
|
|
142
|
-
if (samePath(left.capability.path, right.capability.path)) {
|
|
143
|
-
conflicts.push(sameId ? `Capability "${left.capability.id}" is
|
|
146
|
+
if (samePath$1(left.capability.path, right.capability.path)) {
|
|
147
|
+
conflicts.push(sameId ? `Capability "${left.capability.id}" is placed twice at "${left.capability.path.join(".")}" by "${left.label}" and "${right.label}"` : `Path "${left.capability.path.join(".")}" contains both "${left.capability.id}" from "${left.label}" and "${right.capability.id}" from "${right.label}"`);
|
|
144
148
|
continue;
|
|
145
149
|
}
|
|
146
|
-
if (sameId)
|
|
150
|
+
if (sameId) {
|
|
151
|
+
if (left.owner !== right.owner) conflicts.push(`Capability id "${left.capability.id}" is owned by different Apps at "${left.capability.path.join(".")}" in "${left.label}" and "${right.capability.path.join(".")}"`);
|
|
152
|
+
}
|
|
147
153
|
if (isPathPrefix(left.capability.path, right.capability.path) || isPathPrefix(right.capability.path, left.capability.path)) {
|
|
148
154
|
const leaf = left.capability.path.length < right.capability.path.length ? left : right;
|
|
149
155
|
const subtree = leaf === left ? right : left;
|
|
@@ -152,6 +158,11 @@ function collectManifestConflicts(manifests) {
|
|
|
152
158
|
}
|
|
153
159
|
return [...new Set(conflicts)];
|
|
154
160
|
}
|
|
161
|
+
function sameCapabilityContract(left, right) {
|
|
162
|
+
const { path: _leftPath, ...leftContract } = left;
|
|
163
|
+
const { path: _rightPath, ...rightContract } = right;
|
|
164
|
+
return JSON.stringify(leftContract) === JSON.stringify(rightContract);
|
|
165
|
+
}
|
|
155
166
|
function mergeManifestNodes(nodes) {
|
|
156
167
|
const merged = /* @__PURE__ */ new Map();
|
|
157
168
|
for (const node of nodes) {
|
|
@@ -190,7 +201,7 @@ function filterManifestNodes(nodes, selection) {
|
|
|
190
201
|
const filtered = [];
|
|
191
202
|
for (const node of nodes) {
|
|
192
203
|
if (node.type === "capability") {
|
|
193
|
-
if ((selection.include ?
|
|
204
|
+
if ((selection.include ? matchesManifestSelection(selection.include, node.path) : true) && !matchesManifestSelection(selection.exclude, node.path)) filtered.push(node);
|
|
194
205
|
continue;
|
|
195
206
|
}
|
|
196
207
|
const children = filterManifestNodes(node.children, selection);
|
|
@@ -201,7 +212,7 @@ function filterManifestNodes(nodes, selection) {
|
|
|
201
212
|
}
|
|
202
213
|
return filtered;
|
|
203
214
|
}
|
|
204
|
-
function
|
|
215
|
+
function matchesManifestSelection(tree, path) {
|
|
205
216
|
let current = tree;
|
|
206
217
|
for (const segment of path) {
|
|
207
218
|
if (current === true) return true;
|
|
@@ -210,7 +221,7 @@ function matchesSelection(tree, path) {
|
|
|
210
221
|
}
|
|
211
222
|
return current === true || Boolean(current) && typeof current === "object" && !Array.isArray(current);
|
|
212
223
|
}
|
|
213
|
-
function samePath(left, right) {
|
|
224
|
+
function samePath$1(left, right) {
|
|
214
225
|
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
215
226
|
}
|
|
216
227
|
function isPathPrefix(prefix, path) {
|
|
@@ -224,6 +235,12 @@ const APP_CALL_SYMBOL = Symbol.for("capable.app.call");
|
|
|
224
235
|
function getAppRuntime(app) {
|
|
225
236
|
return app[APP_RUNTIME_SYMBOL];
|
|
226
237
|
}
|
|
238
|
+
/** @internal Composition uses path bindings without exposing them to transports. */
|
|
239
|
+
function getInternalAppRuntime(app) {
|
|
240
|
+
const runtime = app[APP_RUNTIME_SYMBOL];
|
|
241
|
+
if (!("resolve" in runtime) || typeof runtime.resolve !== "function") throw new TypeError("Capable App is missing its internal path resolver");
|
|
242
|
+
return runtime;
|
|
243
|
+
}
|
|
227
244
|
function isApp(value) {
|
|
228
245
|
return Boolean(value && (typeof value === "object" || typeof value === "function") && value[APP_RUNTIME_SYMBOL]);
|
|
229
246
|
}
|
|
@@ -247,12 +264,13 @@ function appFromRuntime(runtime) {
|
|
|
247
264
|
return read(path, false, key);
|
|
248
265
|
},
|
|
249
266
|
async apply(_target, _this, args) {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
267
|
+
const signal = args[1]?.signal;
|
|
268
|
+
const binding = await runtime.resolve(path);
|
|
269
|
+
if (!binding) throw new Error(`No Capability exists at "${path.join(".")}"`);
|
|
270
|
+
return (await binding.transport.call({
|
|
271
|
+
id: binding.capability.id,
|
|
254
272
|
input: args[0] ?? {},
|
|
255
|
-
...
|
|
273
|
+
...signal ? { signal } : {}
|
|
256
274
|
})).output;
|
|
257
275
|
}
|
|
258
276
|
});
|
|
@@ -263,13 +281,14 @@ function subscribe(capabilityCall, ...args) {
|
|
|
263
281
|
const binding = capabilityCall[APP_CALL_SYMBOL];
|
|
264
282
|
if (!binding) throw new Error("subscribe() requires a Capability call from a Capable App");
|
|
265
283
|
return (async function* () {
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
if (!
|
|
269
|
-
|
|
270
|
-
|
|
284
|
+
const signal = args[1]?.signal;
|
|
285
|
+
const resolved = await binding.runtime.resolve(binding.path);
|
|
286
|
+
if (!resolved) throw new Error(`No Capability exists at "${binding.path.join(".")}"`);
|
|
287
|
+
if (!resolved.capability.subscription) throw new Error(`Capability "${resolved.capability.id}" is not subscribable`);
|
|
288
|
+
const stream = resolved.transport.subscribe({
|
|
289
|
+
id: resolved.capability.id,
|
|
271
290
|
input: args[0] ?? {},
|
|
272
|
-
...
|
|
291
|
+
...signal ? { signal } : {}
|
|
273
292
|
});
|
|
274
293
|
try {
|
|
275
294
|
for await (const result of stream) yield result.output;
|
|
@@ -291,10 +310,17 @@ function createApp(definition, ...[options]) {
|
|
|
291
310
|
byId = new Map(definition.locatedCapabilities.map((entry) => [entry.capability.id, entry]));
|
|
292
311
|
localCapabilityCache.set(definition, byId);
|
|
293
312
|
}
|
|
294
|
-
|
|
313
|
+
const runtime = Object.freeze({
|
|
295
314
|
async manifest() {
|
|
296
315
|
return manifest;
|
|
297
316
|
},
|
|
317
|
+
async resolve(path) {
|
|
318
|
+
const capability = findManifestCapability(manifest.capabilities, path);
|
|
319
|
+
return capability ? {
|
|
320
|
+
capability,
|
|
321
|
+
transport: runtime
|
|
322
|
+
} : void 0;
|
|
323
|
+
},
|
|
298
324
|
async call({ id, input = {}, signal, presentation: wantsPresentation }) {
|
|
299
325
|
const located = byId.get(id);
|
|
300
326
|
if (!located) throw new TransportError("NOT_FOUND", { status: 404 });
|
|
@@ -359,7 +385,8 @@ function createApp(definition, ...[options]) {
|
|
|
359
385
|
await stream.return?.();
|
|
360
386
|
}
|
|
361
387
|
}
|
|
362
|
-
})
|
|
388
|
+
});
|
|
389
|
+
return appFromRuntime(runtime);
|
|
363
390
|
}
|
|
364
391
|
function createRemoteApp(transport) {
|
|
365
392
|
const manifest = createManifestResolver(async () => {
|
|
@@ -369,6 +396,13 @@ function createRemoteApp(transport) {
|
|
|
369
396
|
});
|
|
370
397
|
return appFromRuntime(Object.freeze({
|
|
371
398
|
manifest,
|
|
399
|
+
async resolve(path) {
|
|
400
|
+
const capability = findManifestCapability((await manifest()).capabilities, path);
|
|
401
|
+
return capability ? {
|
|
402
|
+
capability,
|
|
403
|
+
transport
|
|
404
|
+
} : void 0;
|
|
405
|
+
},
|
|
372
406
|
async call(call) {
|
|
373
407
|
await manifest();
|
|
374
408
|
return transport.call(call);
|
|
@@ -424,21 +458,48 @@ function toTransportError(error) {
|
|
|
424
458
|
}
|
|
425
459
|
//#endregion
|
|
426
460
|
//#region packages/app/src/composition.ts
|
|
427
|
-
|
|
428
|
-
|
|
461
|
+
/** Compose root Apps and tree-shaped App placements into one executable App. */
|
|
462
|
+
function composeApps(...nodes) {
|
|
463
|
+
const placements = nodes.flatMap((node) => collectPlacements(node, []));
|
|
464
|
+
return appFromRuntime(createCompositionRuntime(placements.filter((placement, index) => placements.findIndex((candidate) => candidate.runtime === placement.runtime && samePath(candidate.path, placement.path)) === index)));
|
|
465
|
+
}
|
|
466
|
+
function collectPlacements(node, path) {
|
|
467
|
+
if (isApp(node)) return [{
|
|
468
|
+
path: Object.freeze(path),
|
|
469
|
+
runtime: getInternalAppRuntime(node)
|
|
470
|
+
}];
|
|
471
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) throw new TypeError("composeApps() entries must be Apps or named object trees");
|
|
472
|
+
const entries = Object.entries(node);
|
|
473
|
+
if (entries.length === 0) throw new Error(`composeApps() contains an empty object at "${path.join(".") || "<root>"}"`);
|
|
474
|
+
return entries.flatMap(([key, child]) => {
|
|
475
|
+
if (!key) throw new Error("composeApps() keys must not be empty");
|
|
476
|
+
if (key === "then") throw new Error("composeApps() uses reserved key \"then\"");
|
|
477
|
+
return collectPlacements(child, [...path, key]);
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
function createCompositionRuntime(placements) {
|
|
429
481
|
let dispatch;
|
|
430
482
|
const resolve = createManifestResolver(async () => {
|
|
431
|
-
const
|
|
483
|
+
const sources = await Promise.all(placements.map(async (placement) => ({
|
|
484
|
+
manifest: placeManifest(placement.path, await placement.runtime.manifest()),
|
|
485
|
+
owner: placement.runtime
|
|
486
|
+
})));
|
|
487
|
+
const composed = composeApplicationManifests(sources);
|
|
432
488
|
const nextDispatch = /* @__PURE__ */ new Map();
|
|
433
|
-
|
|
434
|
-
for (const capability of flattenManifestCapabilities(manifest.capabilities)) nextDispatch.set(capability.id,
|
|
489
|
+
sources.forEach(({ manifest }, index) => {
|
|
490
|
+
for (const capability of flattenManifestCapabilities(manifest.capabilities)) nextDispatch.set(capability.id, placements[index].runtime);
|
|
435
491
|
});
|
|
436
|
-
const merged = mergeApplicationManifests(manifests);
|
|
437
492
|
dispatch = nextDispatch;
|
|
438
|
-
return
|
|
493
|
+
return composed;
|
|
439
494
|
});
|
|
440
|
-
return
|
|
495
|
+
return Object.freeze({
|
|
441
496
|
manifest: resolve,
|
|
497
|
+
async resolve(path) {
|
|
498
|
+
const matches = (await Promise.all(placements.filter((placement) => isPathPrefixOrEqual(placement.path, path)).map((placement) => placement.runtime.resolve(path.slice(placement.path.length))))).filter((match) => match !== void 0).filter((match, index, all) => all.findIndex((candidate) => candidate.capability.id === match.capability.id && candidate.transport === match.transport) === index);
|
|
499
|
+
if (matches.length === 0) return void 0;
|
|
500
|
+
if (matches.length > 1) throw new Error(`Cannot resolve ambiguous App path "${path.join(".")}"`);
|
|
501
|
+
return matches[0];
|
|
502
|
+
},
|
|
442
503
|
async call(call) {
|
|
443
504
|
await resolve();
|
|
444
505
|
const target = dispatch?.get(call.id);
|
|
@@ -451,10 +512,10 @@ function mergeApps(...applications) {
|
|
|
451
512
|
if (!target) throw new TransportError("NOT_FOUND", { status: 404 });
|
|
452
513
|
yield* target.subscribe(call);
|
|
453
514
|
}
|
|
454
|
-
})
|
|
515
|
+
});
|
|
455
516
|
}
|
|
456
517
|
function selectApp(application, selection) {
|
|
457
|
-
const runtime =
|
|
518
|
+
const runtime = getInternalAppRuntime(application);
|
|
458
519
|
let ids;
|
|
459
520
|
const manifest = createManifestResolver(async () => {
|
|
460
521
|
const selected = selectManifest(await runtime.manifest(), selection);
|
|
@@ -463,6 +524,10 @@ function selectApp(application, selection) {
|
|
|
463
524
|
});
|
|
464
525
|
return appFromRuntime(Object.freeze({
|
|
465
526
|
manifest,
|
|
527
|
+
async resolve(path) {
|
|
528
|
+
if (!findManifestCapability((await manifest()).capabilities, path)) return;
|
|
529
|
+
return runtime.resolve(path);
|
|
530
|
+
},
|
|
466
531
|
async call(call) {
|
|
467
532
|
await manifest();
|
|
468
533
|
if (!ids?.has(call.id)) throw new TransportError("NOT_FOUND", { status: 404 });
|
|
@@ -475,7 +540,41 @@ function selectApp(application, selection) {
|
|
|
475
540
|
}
|
|
476
541
|
}));
|
|
477
542
|
}
|
|
543
|
+
function placeManifest(path, source) {
|
|
544
|
+
if (path.length === 0) return source;
|
|
545
|
+
let capabilities = prefixManifestPaths(source.capabilities, path);
|
|
546
|
+
for (let index = path.length - 1; index >= 0; index--) {
|
|
547
|
+
const leaf = index === path.length - 1;
|
|
548
|
+
capabilities = Object.freeze([Object.freeze({
|
|
549
|
+
type: "group",
|
|
550
|
+
key: path[index],
|
|
551
|
+
...leaf ? { title: source.name } : {},
|
|
552
|
+
...leaf && source.description ? { description: source.description } : {},
|
|
553
|
+
meta: Object.freeze({}),
|
|
554
|
+
children: capabilities
|
|
555
|
+
})]);
|
|
556
|
+
}
|
|
557
|
+
return Object.freeze({
|
|
558
|
+
...source,
|
|
559
|
+
capabilities
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
function prefixManifestPaths(nodes, prefix) {
|
|
563
|
+
return Object.freeze(nodes.map((node) => node.type === "capability" ? Object.freeze({
|
|
564
|
+
...node,
|
|
565
|
+
path: Object.freeze([...prefix, ...node.path])
|
|
566
|
+
}) : Object.freeze({
|
|
567
|
+
...node,
|
|
568
|
+
children: prefixManifestPaths(node.children, prefix)
|
|
569
|
+
})));
|
|
570
|
+
}
|
|
571
|
+
function isPathPrefixOrEqual(prefix, path) {
|
|
572
|
+
return prefix.length <= path.length && prefix.every((segment, index) => segment === path[index]);
|
|
573
|
+
}
|
|
574
|
+
function samePath(left, right) {
|
|
575
|
+
return left.length === right.length && left.every((segment, index) => segment === right[index]);
|
|
576
|
+
}
|
|
478
577
|
//#endregion
|
|
479
|
-
export { TransportError as a, getAppRuntime as c, createAppManifest as d, APP_RUNTIME_SYMBOL as i, isApp as l, selectApp as n, createApp as o, APP_CAPABILITIES_SYMBOL as r, createRemoteApp as s,
|
|
578
|
+
export { TransportError as a, getAppRuntime as c, createAppManifest as d, APP_RUNTIME_SYMBOL as i, isApp as l, selectApp as n, createApp as o, APP_CAPABILITIES_SYMBOL as r, createRemoteApp as s, composeApps as t, subscribe as u };
|
|
480
579
|
|
|
481
|
-
//# sourceMappingURL=src-
|
|
580
|
+
//# sourceMappingURL=src-B592M-6b.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-B592M-6b.mjs","names":["samePath"],"sources":["../../app/src/manifest.ts","../../app/src/runtime.ts","../../app/src/composition.ts"],"sourcesContent":["import {\n isCapability,\n isCapabilityGroup,\n schemaToJsonSchema,\n type AnySchema,\n type AppDefinition,\n type LocatedCapability,\n} from \"@capable/core\";\n\nexport type JsonSchema = Readonly<Record<string, unknown>>;\n\nexport type ManifestError = {\n readonly message?: string;\n readonly data?: JsonSchema;\n readonly status?: number;\n readonly meta?: Readonly<Record<string, unknown>>;\n};\n\nexport type ManifestCapability = {\n readonly type: \"capability\";\n readonly id: string;\n readonly path: readonly string[];\n readonly title?: string;\n readonly description?: string;\n readonly deprecated: boolean;\n readonly effect?: \"read\" | \"write\" | \"destructive\";\n readonly subscription?: { readonly mode: \"replace\" };\n readonly input?: JsonSchema;\n readonly output?: JsonSchema;\n readonly errors: Readonly<Record<string, ManifestError>>;\n readonly meta: Readonly<Record<string, unknown>>;\n};\n\nexport type ManifestGroup = {\n readonly type: \"group\";\n readonly key: string;\n readonly title?: string;\n readonly description?: string;\n readonly meta: Readonly<Record<string, unknown>>;\n readonly children: readonly ManifestNode[];\n};\n\nexport type ManifestNode = ManifestGroup | ManifestCapability;\n\nexport type ApplicationManifest = {\n readonly protocol: \"capable.capabilities.v3\";\n readonly name: string;\n readonly version: string;\n readonly description?: string;\n readonly capabilities: readonly ManifestNode[];\n};\n\nexport function createAppManifest(\n definition: AppDefinition<any>,\n): ApplicationManifest {\n const byCapability = new Map(\n definition.locatedCapabilities.map((entry) => [entry.capability, entry]),\n );\n return Object.freeze({\n protocol: \"capable.capabilities.v3\",\n name: definition.name,\n version: definition.version,\n ...(definition.description ? { description: definition.description } : {}),\n capabilities: manifestNodes(definition.capabilities, byCapability),\n });\n}\n\nexport function validateManifest(\n manifest: ApplicationManifest,\n label: string,\n): void {\n if (manifest.protocol !== \"capable.capabilities.v3\") {\n throw new Error(`${label} uses unsupported protocol \"${manifest.protocol}\"`);\n }\n const capabilities = flattenManifestCapabilities(manifest.capabilities);\n const ids = new Map<string, ManifestCapability>();\n const paths = new Set<string>();\n for (const capability of capabilities) {\n const path = capability.path.join(\".\");\n const previous = ids.get(capability.id);\n if (previous && !sameCapabilityContract(previous, capability)) {\n throw new Error(\n `${label} contains conflicting definitions for Capability id \"${capability.id}\"`,\n );\n }\n if (paths.has(path)) {\n throw new Error(`${label} contains duplicate Capability path \"${path}\"`);\n }\n ids.set(capability.id, capability);\n paths.add(path);\n }\n validateManifestPaths(manifest.capabilities, [], label);\n}\n\nexport type ApplicationManifestSource = {\n readonly manifest: ApplicationManifest;\n readonly owner: object;\n};\n\nexport function composeApplicationManifests(\n sources: readonly ApplicationManifestSource[],\n): ApplicationManifest {\n const conflicts = collectManifestConflicts(sources);\n if (conflicts.length) {\n throw new Error(\n `Cannot compose Apps:\\n${conflicts.map((item) => `- ${item}`).join(\"\\n\")}`,\n );\n }\n const manifests = sources.map(({ manifest }) => manifest);\n const applications = sources.filter((source, index) =>\n sources.findIndex(({ owner }) => owner === source.owner) === index\n ).map(({ manifest }) => manifest);\n return Object.freeze({\n protocol: \"capable.capabilities.v3\",\n name: applications.map(({ name }) => name).join(\" + \"),\n version: applications.map(({ version }) => version).join(\" + \"),\n capabilities: mergeManifestNodes(\n manifests.flatMap(({ capabilities }) => capabilities),\n ),\n });\n}\n\nexport function selectManifest(\n source: ApplicationManifest,\n selection: {\n readonly include?: unknown;\n readonly exclude?: unknown;\n },\n): ApplicationManifest {\n validateSelectionTree(selection.include, source.capabilities, \"include\", []);\n validateSelectionTree(selection.exclude, source.capabilities, \"exclude\", []);\n return Object.freeze({\n ...source,\n capabilities: filterManifestNodes(source.capabilities, selection),\n });\n}\n\nfunction validateSelectionTree(\n tree: unknown,\n nodes: readonly ManifestNode[],\n label: \"include\" | \"exclude\",\n parent: readonly string[],\n): void {\n if (tree === undefined || tree === true) return;\n if (!tree || typeof tree !== \"object\" || Array.isArray(tree)) {\n throw new Error(\n `Application selection ${label} at \"${parent.join(\".\") || \"<root>\"}\" must be an object or true`,\n );\n }\n for (const [key, child] of Object.entries(tree)) {\n const path = [...parent, key];\n const node = nodes.find((candidate) =>\n candidate.type === \"group\"\n ? candidate.key === key\n : candidate.path.at(-1) === key\n );\n if (!node) {\n throw new Error(\n `Application selection ${label} references unknown path \"${path.join(\".\")}\"`,\n );\n }\n if (child === true) continue;\n if (node.type === \"capability\") {\n throw new Error(\n `Application selection ${label} at \"${path.join(\".\")}\" must be true`,\n );\n }\n validateSelectionTree(child, node.children, label, path);\n }\n}\n\nexport function flattenManifestCapabilities(\n nodes: readonly ManifestNode[],\n): readonly ManifestCapability[] {\n return nodes.flatMap((node) =>\n node.type === \"capability\"\n ? [node]\n : flattenManifestCapabilities(node.children)\n );\n}\n\nexport function findManifestCapability(\n nodes: readonly ManifestNode[],\n path: readonly string[],\n): ManifestCapability | undefined {\n let current = nodes;\n for (let index = 0; index < path.length; index++) {\n const key = path[index]!;\n const node = current.find((candidate) =>\n candidate.type === \"group\"\n ? candidate.key === key\n : candidate.path.at(-1) === key\n );\n if (!node) return undefined;\n if (node.type === \"capability\") {\n return index === path.length - 1 ? node : undefined;\n }\n current = node.children;\n }\n return undefined;\n}\n\nfunction manifestNodes(\n tree: Readonly<Record<string, unknown>>,\n located: ReadonlyMap<unknown, LocatedCapability>,\n): readonly ManifestNode[] {\n const nodes: ManifestNode[] = [];\n for (const [key, value] of Object.entries(tree)) {\n if (isCapability(value)) {\n const entry = located.get(value);\n if (entry) nodes.push(manifestCapability(entry));\n continue;\n }\n const decorated = isCapabilityGroup(value);\n const childTree = decorated\n ? value.capabilities\n : value as Readonly<Record<string, unknown>>;\n const children = manifestNodes(childTree, located);\n nodes.push(Object.freeze({\n type: \"group\",\n key,\n ...(decorated && value.title ? { title: value.title } : {}),\n ...(decorated && value.description\n ? { description: value.description }\n : {}),\n meta: decorated ? value.meta : {},\n children,\n } satisfies ManifestGroup));\n }\n return nodes;\n}\n\nfunction manifestCapability(entry: LocatedCapability): ManifestCapability {\n const capability = entry.capability;\n return Object.freeze({\n type: \"capability\",\n id: capability.id,\n path: entry.path,\n ...(capability.title ? { title: capability.title } : {}),\n ...(capability.description ? { description: capability.description } : {}),\n deprecated: capability.deprecated,\n ...(capability.effect ? { effect: capability.effect } : {}),\n ...(capability.subscribe\n ? { subscription: { mode: \"replace\" as const } }\n : {}),\n ...(capability.input\n ? { input: manifestJsonSchema(capability.input, \"input\") }\n : {}),\n ...(capability.output\n ? { output: manifestJsonSchema(capability.output, \"output\") }\n : {}),\n errors: Object.fromEntries(\n Object.entries(entry.errors).map(([code, definition]) => [\n code,\n {\n ...(definition.message ? { message: definition.message } : {}),\n ...(typeof definition.status === \"number\"\n ? { status: definition.status }\n : {}),\n ...(definition.data\n ? { data: manifestJsonSchema(definition.data, \"output\") }\n : {}),\n ...(definition.meta ? { meta: definition.meta } : {}),\n } satisfies ManifestError,\n ]),\n ),\n meta: capability.meta,\n });\n}\n\nfunction manifestJsonSchema(\n schema: AnySchema,\n direction: \"input\" | \"output\",\n): JsonSchema {\n return schemaToJsonSchema(schema, direction, {\n allowUnrepresentable: true,\n });\n}\n\nfunction validateManifestPaths(\n nodes: readonly ManifestNode[],\n parent: readonly string[],\n label: string,\n): void {\n for (const node of nodes) {\n if (node.type === \"group\") {\n validateManifestPaths(node.children, [...parent, node.key], label);\n continue;\n }\n if (!samePath(node.path, [...parent, node.path.at(-1)!])) {\n throw new Error(\n `${label} Capability \"${node.id}\" declares path \"${node.path.join(\".\")}\" that does not match its manifest placement`,\n );\n }\n }\n}\n\nfunction collectManifestConflicts(\n sources: readonly ApplicationManifestSource[],\n): readonly string[] {\n const conflicts: string[] = [];\n for (const { manifest } of sources) {\n try {\n validateManifest(manifest, manifest.name);\n } catch (error) {\n conflicts.push(error instanceof Error ? error.message : String(error));\n }\n }\n const capabilities = sources.flatMap(({ manifest, owner }, source) =>\n flattenManifestCapabilities(manifest.capabilities).map((capability) => ({\n capability,\n source,\n owner,\n label: manifest.name,\n }))\n );\n for (let leftIndex = 0; leftIndex < capabilities.length; leftIndex++) {\n for (\n let rightIndex = leftIndex + 1;\n rightIndex < capabilities.length;\n rightIndex++\n ) {\n const left = capabilities[leftIndex]!;\n const right = capabilities[rightIndex]!;\n if (left.source === right.source) continue;\n const sameId = left.capability.id === right.capability.id;\n const sameCapabilityPath = samePath(\n left.capability.path,\n right.capability.path,\n );\n if (sameCapabilityPath) {\n conflicts.push(\n sameId\n ? `Capability \"${left.capability.id}\" is placed twice at \"${left.capability.path.join(\".\")}\" by \"${left.label}\" and \"${right.label}\"`\n : `Path \"${left.capability.path.join(\".\")}\" contains both \"${left.capability.id}\" from \"${left.label}\" and \"${right.capability.id}\" from \"${right.label}\"`,\n );\n continue;\n }\n if (sameId) {\n if (left.owner !== right.owner) {\n conflicts.push(\n `Capability id \"${left.capability.id}\" is owned by different Apps at \"${left.capability.path.join(\".\")}\" in \"${left.label}\" and \"${right.capability.path.join(\".\")}\"`,\n );\n }\n }\n if (\n isPathPrefix(left.capability.path, right.capability.path) ||\n isPathPrefix(right.capability.path, left.capability.path)\n ) {\n const leaf = left.capability.path.length < right.capability.path.length\n ? left\n : right;\n const subtree = leaf === left ? right : left;\n conflicts.push(\n `Leaf \"${leaf.capability.path.join(\".\")}\" from \"${leaf.label}\" collides with subtree Capability \"${subtree.capability.path.join(\".\")}\" from \"${subtree.label}\"`,\n );\n }\n }\n }\n return [...new Set(conflicts)];\n}\n\nfunction sameCapabilityContract(\n left: ManifestCapability,\n right: ManifestCapability,\n): boolean {\n const { path: _leftPath, ...leftContract } = left;\n const { path: _rightPath, ...rightContract } = right;\n return JSON.stringify(leftContract) === JSON.stringify(rightContract);\n}\n\nfunction mergeManifestNodes(\n nodes: readonly ManifestNode[],\n): readonly ManifestNode[] {\n const merged = new Map<string, ManifestNode>();\n for (const node of nodes) {\n const key = node.type === \"group\" ? node.key : node.path.at(-1)!;\n const previous = merged.get(key);\n if (!previous) {\n merged.set(key, node);\n continue;\n }\n if (previous.type !== \"group\" || node.type !== \"group\") {\n throw new Error(`Manifest node collision at \"${key}\"`);\n }\n merged.set(key, Object.freeze({\n type: \"group\",\n key,\n ...mergeGroupField(\"title\", previous.title, node.title, key),\n ...mergeGroupField(\n \"description\",\n previous.description,\n node.description,\n key,\n ),\n meta: mergeGroupMeta(previous.meta, node.meta, key),\n children: mergeManifestNodes([...previous.children, ...node.children]),\n }));\n }\n return [...merged.values()];\n}\n\nfunction mergeGroupField(\n field: \"title\" | \"description\",\n left: string | undefined,\n right: string | undefined,\n path: string,\n): Record<string, string> {\n if (left && right && left !== right) {\n throw new Error(`Group \"${path}\" has conflicting ${field}`);\n }\n const value = left ?? right;\n return value ? { [field]: value } : {};\n}\n\nfunction mergeGroupMeta(\n left: Readonly<Record<string, unknown>>,\n right: Readonly<Record<string, unknown>>,\n path: string,\n): Readonly<Record<string, unknown>> {\n const merged: Record<string, unknown> = { ...left };\n for (const [key, value] of Object.entries(right)) {\n if (\n key in merged &&\n JSON.stringify(merged[key]) !== JSON.stringify(value)\n ) {\n throw new Error(\n `Group \"${path}\" has conflicting metadata for \"${key}\"`,\n );\n }\n merged[key] = value;\n }\n return Object.freeze(merged);\n}\n\nfunction filterManifestNodes(\n nodes: readonly ManifestNode[],\n selection: {\n readonly include?: unknown;\n readonly exclude?: unknown;\n },\n): readonly ManifestNode[] {\n const filtered: ManifestNode[] = [];\n for (const node of nodes) {\n if (node.type === \"capability\") {\n const included = selection.include\n ? matchesManifestSelection(selection.include, node.path)\n : true;\n if (\n included && !matchesManifestSelection(selection.exclude, node.path)\n ) {\n filtered.push(node);\n }\n continue;\n }\n const children = filterManifestNodes(node.children, selection);\n if (children.length) filtered.push(Object.freeze({ ...node, children }));\n }\n return filtered;\n}\n\nfunction matchesManifestSelection(\n tree: unknown,\n path: readonly string[],\n): boolean {\n let current = 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 samePath(\n left: readonly string[],\n right: readonly string[],\n): boolean {\n return left.length === right.length &&\n left.every((segment, index) => segment === right[index]);\n}\n\nfunction isPathPrefix(\n prefix: readonly string[],\n path: readonly string[],\n): boolean {\n return prefix.length < path.length &&\n prefix.every((segment, index) => segment === path[index]);\n}\n","import {\n CapableError,\n executeLocatedCapability,\n normalizePresentation,\n subscribeLocatedCapability,\n type AnyCapability,\n type AnyObjectSchema,\n type AppDefinition,\n type AppContext,\n type InferSchemaInput,\n type LocatedCapability,\n type MaybePromise,\n type PresentationPart,\n type CapabilityDefinition,\n type CapabilityGroupDefinition,\n type CapabilityOutput,\n type CapabilityTree,\n type SubscribableCapability,\n} from \"@capable/core\";\nimport {\n createAppManifest,\n findManifestCapability,\n validateManifest,\n type ApplicationManifest,\n type ManifestCapability,\n} from \"./manifest.ts\";\n\nexport type CapabilityCall = {\n readonly id: string;\n readonly input?: unknown;\n readonly signal?: AbortSignal;\n readonly presentation?: boolean;\n};\n\nexport type CapabilityResult = {\n readonly output: unknown;\n readonly presentation?: readonly PresentationPart[];\n};\n\nexport interface ApplicationTransport {\n manifest(\n options?: { readonly signal?: AbortSignal },\n ): Promise<ApplicationManifest>;\n call(call: CapabilityCall): Promise<CapabilityResult>;\n subscribe(call: CapabilityCall): AsyncIterableIterator<CapabilityResult>;\n}\n\nexport type ResolvedCapability = {\n readonly capability: ManifestCapability;\n readonly transport: ApplicationTransport;\n};\n\n/** The in-process runtime can bind one path without resolving sibling Apps. */\nexport interface ApplicationRuntime extends ApplicationTransport {\n resolve(path: readonly string[]): Promise<ResolvedCapability | undefined>;\n}\n\nexport const APP_RUNTIME_SYMBOL: unique symbol = Symbol.for(\n \"capable.app.runtime\",\n) as never;\nexport const APP_CAPABILITIES_SYMBOL: unique symbol = Symbol.for(\n \"capable.app.capabilities\",\n) as never;\nconst APP_CALL_SYMBOL = Symbol.for(\"capable.app.call\");\n\ntype AppCapabilityType<TCapability extends AnyCapability> = {\n readonly \"~capable/capability\"?: TCapability;\n};\n\ntype AppCapabilityInput<TCapability extends AnyCapability> =\n TCapability extends CapabilityDefinition<any, infer TInput, any, any, any>\n ? TInput extends AnyObjectSchema\n ? InferSchemaInput<TInput>\n : Record<never, never>\n : never;\n\ntype AppCapabilityOutput<TCapability extends AnyCapability> =\n TCapability extends CapabilityDefinition<any, any, infer TOutput, any, any>\n ? TOutput\n : never;\n\ntype AppCapabilityOptions = { readonly signal?: AbortSignal };\n\ntype AppCapabilityArgs<TCapability extends AnyCapability> =\n TCapability extends CapabilityDefinition<any, infer TInput, any, any, any>\n ? TInput extends undefined\n ? [\n input?: Record<never, never>,\n options?: AppCapabilityOptions,\n ]\n : Record<never, never> extends AppCapabilityInput<TCapability>\n ? [\n input?: AppCapabilityInput<TCapability>,\n options?: AppCapabilityOptions,\n ]\n : [\n input: AppCapabilityInput<TCapability>,\n options?: AppCapabilityOptions,\n ]\n : never;\n\nexport type AppCapabilityCall<TCapability extends AnyCapability> = ((\n ...args: AppCapabilityArgs<TCapability>\n) => Promise<AppCapabilityOutput<TCapability>>) &\n AppCapabilityType<TCapability>;\n\nexport type AppCapabilityIsSubscribable<TCall> =\n TCall extends AppCapabilityType<infer TCapability>\n ? TCapability extends CapabilityDefinition<any, any, any, any, any, true>\n ? true\n : false\n : false;\n\nexport type CallableTree<TTree> =\n TTree extends AnyCapability\n ? AppCapabilityCall<TTree>\n : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any>\n ? CallableTree<TCapabilities>\n : TTree extends CapabilityTree\n ? { readonly [TKey in keyof TTree]: CallableTree<TTree[TKey]> }\n : never;\n\nexport type App<\n TCapabilities extends CapabilityTree = CapabilityTree,\n> = CallableTree<TCapabilities> & {\n readonly [APP_RUNTIME_SYMBOL]: ApplicationTransport;\n readonly [APP_CAPABILITIES_SYMBOL]?: TCapabilities;\n};\n\nexport type AnyApp = {\n readonly [APP_RUNTIME_SYMBOL]: ApplicationTransport;\n readonly [APP_CAPABILITIES_SYMBOL]?: CapabilityTree;\n};\n\ntype DefinitionCapabilities<TDefinition extends AppDefinition<any, any>> =\n TDefinition extends AppDefinition<infer TCapabilities>\n ? TCapabilities\n : never;\n\nexport type AppCapabilities<\n TApplication extends AnyApp,\n> = TApplication extends {\n readonly [APP_CAPABILITIES_SYMBOL]?: infer TCapabilities extends CapabilityTree;\n}\n ? TCapabilities\n : never;\n\nexport function getAppRuntime(\n app: AnyApp,\n): ApplicationTransport {\n return app[APP_RUNTIME_SYMBOL];\n}\n\n/** @internal Composition uses path bindings without exposing them to transports. */\nexport function getInternalAppRuntime(\n app: AnyApp,\n): ApplicationRuntime {\n const runtime = app[APP_RUNTIME_SYMBOL];\n if (!(\"resolve\" in runtime) || typeof runtime.resolve !== \"function\") {\n throw new TypeError(\"Capable App is missing its internal path resolver\");\n }\n return runtime as ApplicationRuntime;\n}\n\nexport function isApp(value: unknown): value is AnyApp {\n return Boolean(\n value &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n (value as Partial<AnyApp>)[APP_RUNTIME_SYMBOL],\n );\n}\n\nexport function appFromRuntime<\n TCapabilities extends CapabilityTree,\n>(\n runtime: ApplicationRuntime,\n): App<TCapabilities> {\n const read = (path: readonly string[], root: boolean, key: PropertyKey) => {\n if (root && key === APP_RUNTIME_SYMBOL) return runtime;\n if (!root && key === APP_CALL_SYMBOL) return { runtime, path };\n if (key === \"then\") return undefined;\n if (typeof key !== \"string\") return undefined;\n return proxy([...path, key], false);\n };\n\n const proxy = (path: readonly string[], root: boolean): unknown => {\n if (root) {\n return new Proxy({}, {\n get(_target, key) {\n return read(path, true, key);\n },\n });\n }\n return new Proxy(() => undefined, {\n get(_target, key) {\n return read(path, false, key);\n },\n async apply(_target, _this, args: [unknown?, { signal?: AbortSignal }?]) {\n const signal = args[1]?.signal;\n const binding = await runtime.resolve(path);\n if (!binding) {\n throw new Error(`No Capability exists at \"${path.join(\".\")}\"`);\n }\n const result = await binding.transport.call({\n id: binding.capability.id,\n input: args[0] ?? {},\n ...(signal ? { signal } : {}),\n });\n return result.output;\n },\n });\n };\n\n return proxy([], true) as App<TCapabilities>;\n}\n\nexport function subscribe<\n const TCapability extends SubscribableCapability,\n>(\n capabilityCall: AppCapabilityCall<TCapability>,\n ...args: AppCapabilityArgs<TCapability>\n): AsyncIterableIterator<CapabilityOutput<TCapability>> {\n const binding = (\n capabilityCall as unknown as Record<PropertyKey, unknown>\n )[APP_CALL_SYMBOL] as\n | {\n readonly runtime: ApplicationRuntime;\n readonly path: readonly string[];\n }\n | undefined;\n if (!binding) {\n throw new Error(\"subscribe() requires a Capability call from a Capable App\");\n }\n\n return (async function* () {\n const signal = args[1]?.signal;\n const resolved = await binding.runtime.resolve(binding.path);\n if (!resolved) {\n throw new Error(`No Capability exists at \"${binding.path.join(\".\")}\"`);\n }\n if (!resolved.capability.subscription) {\n throw new Error(\n `Capability \"${resolved.capability.id}\" is not subscribable`,\n );\n }\n const stream = resolved.transport.subscribe({\n id: resolved.capability.id,\n input: args[0] ?? {},\n ...(signal ? { signal } : {}),\n });\n try {\n for await (const result of stream) {\n yield result.output as CapabilityOutput<TCapability>;\n }\n } finally {\n await stream.return?.();\n }\n })();\n}\n\nexport type AppContextProvider<TContext> = (call: {\n readonly id: string;\n readonly signal?: AbortSignal;\n}) => MaybePromise<TContext>;\n\ntype CreateAppOptions<TContext> = {\n readonly context: AppContextProvider<TContext>;\n};\n\ntype CreateAppArgs<TContext> = [TContext] extends [undefined]\n ? [options?: Partial<CreateAppOptions<TContext>>]\n : [options: CreateAppOptions<TContext>];\n\nconst localManifestCache = new WeakMap<object, ApplicationManifest>();\nconst localCapabilityCache = new WeakMap<\n object,\n ReadonlyMap<string, LocatedCapability>\n>();\n\nexport function createApp<\n const TDefinition extends AppDefinition<any, any>,\n>(\n definition: TDefinition,\n ...[options]: CreateAppArgs<AppContext<TDefinition>>\n): App<DefinitionCapabilities<TDefinition>> {\n let manifest = localManifestCache.get(definition);\n if (!manifest) {\n manifest = createAppManifest(definition);\n localManifestCache.set(definition, manifest);\n }\n let byId = localCapabilityCache.get(definition);\n if (!byId) {\n byId = new Map(\n definition.locatedCapabilities.map((entry) => [entry.capability.id, entry]),\n );\n localCapabilityCache.set(definition, byId);\n }\n const runtime: ApplicationRuntime = Object.freeze({\n async manifest() {\n return manifest;\n },\n async resolve(path: readonly string[]) {\n const capability = findManifestCapability(manifest.capabilities, path);\n return capability ? { capability, transport: runtime } : undefined;\n },\n async call({ id, input = {}, signal, presentation: wantsPresentation }: CapabilityCall) {\n const located = byId.get(id);\n if (!located) throw new TransportError(\"NOT_FOUND\", { status: 404 });\n\n let context: unknown;\n try {\n context = options?.context\n ? await options.context({\n id,\n ...(signal ? { signal } : {}),\n })\n : undefined;\n } catch (cause) {\n throw new TransportError(\"INTERNAL_SERVER_ERROR\", { cause });\n }\n\n let output: unknown;\n try {\n output = await executeLocatedCapability(located, input, {\n context,\n ...(signal ? { signal } : {}),\n });\n } catch (error) {\n if (error instanceof CapableError) {\n throw new TransportError(error.code, {\n ...(error.message ? { message: error.message } : {}),\n ...(typeof error.status === \"number\"\n ? { status: error.status }\n : {}),\n ...(error.data === undefined ? {} : { data: error.data }),\n cause: error,\n });\n }\n throw new TransportError(\"INTERNAL_SERVER_ERROR\", { cause: error });\n }\n\n const presentation = await materializePresentation(\n located.capability,\n output,\n context,\n wantsPresentation,\n );\n\n return {\n output,\n ...(presentation ? { presentation } : {}),\n };\n },\n async *subscribe({\n id,\n input = {},\n signal,\n presentation: wantsPresentation,\n }: CapabilityCall) {\n const located = byId.get(id);\n if (!located) throw new TransportError(\"NOT_FOUND\", { status: 404 });\n if (!located.capability.subscribe) {\n throw new TransportError(\"NOT_FOUND\", { status: 404 });\n }\n\n let context: unknown;\n try {\n context = options?.context\n ? await options.context({\n id,\n ...(signal ? { signal } : {}),\n })\n : undefined;\n } catch (cause) {\n throw new TransportError(\"INTERNAL_SERVER_ERROR\", { cause });\n }\n\n const stream = subscribeLocatedCapability(located, input, {\n context,\n ...(signal ? { signal } : {}),\n });\n try {\n for await (const output of stream) {\n const presentation = await materializePresentation(\n located.capability,\n output,\n context,\n wantsPresentation,\n );\n yield {\n output,\n ...(presentation ? { presentation } : {}),\n };\n }\n } catch (error) {\n throw toTransportError(error);\n } finally {\n await stream.return?.();\n }\n },\n });\n return appFromRuntime(runtime);\n}\n\nexport function createRemoteApp<\n TDefinition extends AppDefinition<any, any> = AppDefinition<CapabilityTree>,\n>(\n transport: ApplicationTransport,\n): App<DefinitionCapabilities<TDefinition>> {\n const manifest = createManifestResolver(async () => {\n const manifest = await transport.manifest();\n validateManifest(manifest, \"Remote App\");\n return manifest;\n });\n const runtime: ApplicationRuntime = Object.freeze({\n manifest,\n async resolve(path: readonly string[]) {\n const capability = findManifestCapability(\n (await manifest()).capabilities,\n path,\n );\n return capability ? { capability, transport } : undefined;\n },\n async call(call: CapabilityCall) {\n await manifest();\n return transport.call(call);\n },\n async *subscribe(call: CapabilityCall) {\n await manifest();\n yield* transport.subscribe(call);\n },\n });\n return appFromRuntime(runtime);\n}\n\nexport function createManifestResolver(\n load: () => Promise<ApplicationManifest>,\n): () => Promise<ApplicationManifest> {\n let cached: Promise<ApplicationManifest> | undefined;\n return () => {\n if (cached) return cached;\n const attempt = Promise.resolve().then(load);\n cached = attempt;\n void attempt.catch(() => {\n if (cached === attempt) cached = undefined;\n });\n return attempt;\n };\n}\n\nexport class TransportError extends Error {\n readonly code: string;\n readonly status: number | undefined;\n readonly data: unknown;\n\n constructor(\n code: string,\n options: {\n readonly message?: string;\n readonly status?: number;\n readonly data?: unknown;\n readonly cause?: unknown;\n } = {},\n ) {\n super(options.message ?? code, { cause: options.cause });\n this.name = \"TransportError\";\n this.code = code;\n this.status = options.status;\n this.data = options.data;\n }\n}\n\nasync function materializePresentation(\n capability: AnyCapability,\n output: unknown,\n context: unknown,\n requested: boolean | undefined,\n): Promise<readonly PresentationPart[] | undefined> {\n if (!requested || !capability.toPresentation) return undefined;\n try {\n const presentation = normalizePresentation(\n await capability.toPresentation(output, { context }),\n );\n return presentation.length > 0 ? presentation : undefined;\n } catch (cause) {\n throw new TransportError(\"INTERNAL_SERVER_ERROR\", { cause });\n }\n}\n\nfunction toTransportError(error: unknown): TransportError {\n if (error instanceof TransportError) return error;\n if (error instanceof CapableError) {\n return new TransportError(error.code, {\n ...(error.message ? { message: error.message } : {}),\n ...(typeof error.status === \"number\" ? { status: error.status } : {}),\n ...(error.data === undefined ? {} : { data: error.data }),\n cause: error,\n });\n }\n return new TransportError(\"INTERNAL_SERVER_ERROR\", { cause: error });\n}\n","import type {\n AnyCapability,\n CapabilityGroupDefinition,\n CapabilityTree,\n} from \"@capable/core\";\nimport {\n appFromRuntime,\n createManifestResolver,\n getInternalAppRuntime,\n isApp,\n TransportError,\n type AnyApp,\n type App,\n type AppCapabilities,\n type ApplicationRuntime,\n type ApplicationTransport,\n type CapabilityCall,\n} from \"./runtime.ts\";\nimport {\n flattenManifestCapabilities,\n composeApplicationManifests,\n findManifestCapability,\n selectManifest,\n type ApplicationManifest,\n type ManifestNode,\n} from \"./manifest.ts\";\n\ntype UnionToIntersection<TValue> =\n (TValue extends unknown ? (value: TValue) => void : never) extends\n (value: infer TIntersection) => void ? TIntersection : never;\n\ntype AppComposition = AnyApp | {\n readonly [key: string]: AppComposition;\n};\n\ntype ComposedNode<TNode> = TNode extends AnyApp\n ? AppCapabilities<TNode>\n : TNode extends Readonly<Record<string, unknown>>\n ? { readonly [TKey in keyof TNode]: ComposedNode<TNode[TKey]> }\n : never;\n\ntype ComposedCapabilities<\n TNodes extends readonly AppComposition[],\n> = UnionToIntersection<ComposedNode<TNodes[number]>> extends\n infer TCapabilities extends CapabilityTree ? TCapabilities : never;\n\n/** Compose root Apps and tree-shaped App placements into one executable App. */\nexport function composeApps<\n const TNodes extends readonly [\n AppComposition,\n ...AppComposition[],\n ],\n>(\n ...nodes: TNodes\n): App<ComposedCapabilities<TNodes>> {\n const placements = nodes.flatMap((node) => collectPlacements(node, []));\n const uniquePlacements = placements.filter((placement, index) =>\n placements.findIndex((candidate) =>\n candidate.runtime === placement.runtime &&\n samePath(candidate.path, placement.path)\n ) === index\n );\n return appFromRuntime(\n createCompositionRuntime(uniquePlacements),\n ) as App<ComposedCapabilities<TNodes>>;\n}\n\ntype AppPlacement = {\n readonly path: readonly string[];\n readonly runtime: ApplicationRuntime;\n};\n\nfunction collectPlacements(\n node: AppComposition,\n path: readonly string[],\n): readonly AppPlacement[] {\n if (isApp(node)) {\n return [{ path: Object.freeze(path), runtime: getInternalAppRuntime(node) }];\n }\n if (!node || typeof node !== \"object\" || Array.isArray(node)) {\n throw new TypeError(\n \"composeApps() entries must be Apps or named object trees\",\n );\n }\n const entries = Object.entries(node);\n if (entries.length === 0) {\n throw new Error(\n `composeApps() contains an empty object at \"${path.join(\".\") || \"<root>\"}\"`,\n );\n }\n return entries.flatMap(([key, child]) => {\n if (!key) throw new Error(\"composeApps() keys must not be empty\");\n if (key === \"then\") {\n throw new Error('composeApps() uses reserved key \"then\"');\n }\n return collectPlacements(child, [...path, key]);\n });\n}\n\nfunction createCompositionRuntime(\n placements: readonly AppPlacement[],\n): ApplicationRuntime {\n let dispatch: ReadonlyMap<string, ApplicationTransport> | undefined;\n\n const resolve = createManifestResolver(async () => {\n const sources = await Promise.all(placements.map(async (placement) => ({\n manifest: placeManifest(\n placement.path,\n await placement.runtime.manifest(),\n ),\n owner: placement.runtime,\n })));\n const composed = composeApplicationManifests(sources);\n const nextDispatch = new Map<string, ApplicationTransport>();\n sources.forEach(({ manifest }, index) => {\n for (\n const capability of flattenManifestCapabilities(\n manifest.capabilities,\n )\n ) {\n nextDispatch.set(capability.id, placements[index]!.runtime);\n }\n });\n dispatch = nextDispatch;\n return composed;\n });\n\n return Object.freeze({\n manifest: resolve,\n async resolve(path: readonly string[]) {\n const matches = (await Promise.all(\n placements\n .filter((placement) => isPathPrefixOrEqual(placement.path, path))\n .map((placement) =>\n placement.runtime.resolve(path.slice(placement.path.length))\n ),\n )).filter((match) => match !== undefined).filter((match, index, all) =>\n all.findIndex((candidate) =>\n candidate.capability.id === match.capability.id &&\n candidate.transport === match.transport\n ) === index\n );\n if (matches.length === 0) return undefined;\n if (matches.length > 1) {\n throw new Error(`Cannot resolve ambiguous App path \"${path.join(\".\")}\"`);\n }\n return matches[0];\n },\n async call(call: CapabilityCall) {\n await resolve();\n const target = dispatch?.get(call.id);\n if (!target) throw new TransportError(\"NOT_FOUND\", { status: 404 });\n return target.call(call);\n },\n async *subscribe(call: CapabilityCall) {\n await resolve();\n const target = dispatch?.get(call.id);\n if (!target) throw new TransportError(\"NOT_FOUND\", { status: 404 });\n yield* target.subscribe(call);\n },\n });\n}\n\ntype SelectionNode<TTree> =\n TTree extends AnyCapability\n ? true\n : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any>\n ? true | SelectionNode<TCapabilities>\n : TTree extends CapabilityTree\n ? true | {\n readonly [TKey in keyof TTree]?: SelectionNode<TTree[TKey]>;\n }\n : never;\n\nexport type ApplicationSelection<\n TCapabilities extends CapabilityTree = CapabilityTree,\n> = {\n readonly include?: Exclude<SelectionNode<TCapabilities>, true>;\n readonly exclude?: Exclude<SelectionNode<TCapabilities>, true>;\n};\n\nexport function selectApp<\n const TCapabilities extends CapabilityTree,\n>(\n application: App<TCapabilities>,\n selection: ApplicationSelection<TCapabilities>,\n): App<TCapabilities> {\n const runtime = getInternalAppRuntime(application);\n let ids: ReadonlySet<string> | undefined;\n const manifest = createManifestResolver(async () => {\n const selected = selectManifest(await runtime.manifest(), selection);\n ids = new Set(\n flattenManifestCapabilities(selected.capabilities).map(\n (capability) => capability.id,\n ),\n );\n return selected;\n });\n const selectedRuntime: ApplicationRuntime = Object.freeze({\n manifest,\n async resolve(path: readonly string[]) {\n const selected = await manifest();\n if (!findManifestCapability(selected.capabilities, path)) {\n return undefined;\n }\n return runtime.resolve(path);\n },\n async call(call: CapabilityCall) {\n await manifest();\n if (!ids?.has(call.id)) {\n throw new TransportError(\"NOT_FOUND\", { status: 404 });\n }\n return runtime.call(call);\n },\n async *subscribe(call: CapabilityCall) {\n await manifest();\n if (!ids?.has(call.id)) {\n throw new TransportError(\"NOT_FOUND\", { status: 404 });\n }\n yield* runtime.subscribe(call);\n },\n });\n return appFromRuntime(selectedRuntime);\n}\n\nfunction placeManifest(\n path: readonly string[],\n source: ApplicationManifest,\n): ApplicationManifest {\n if (path.length === 0) return source;\n let capabilities = prefixManifestPaths(source.capabilities, path);\n for (let index = path.length - 1; index >= 0; index--) {\n const leaf = index === path.length - 1;\n capabilities = Object.freeze([Object.freeze({\n type: \"group\" as const,\n key: path[index]!,\n ...(leaf ? { title: source.name } : {}),\n ...(leaf && source.description\n ? { description: source.description }\n : {}),\n meta: Object.freeze({}),\n children: capabilities,\n })]);\n }\n return Object.freeze({\n ...source,\n capabilities,\n });\n}\n\nfunction prefixManifestPaths(\n nodes: readonly ManifestNode[],\n prefix: readonly string[],\n): readonly ManifestNode[] {\n return Object.freeze(nodes.map((node) =>\n node.type === \"capability\"\n ? Object.freeze({\n ...node,\n path: Object.freeze([...prefix, ...node.path]),\n })\n : Object.freeze({\n ...node,\n children: prefixManifestPaths(node.children, prefix),\n })\n ));\n}\n\nfunction isPathPrefixOrEqual(\n prefix: readonly string[],\n path: readonly string[],\n): boolean {\n return prefix.length <= path.length &&\n prefix.every((segment, index) => segment === path[index]);\n}\n\nfunction samePath(left: readonly string[], right: readonly string[]): boolean {\n return left.length === right.length &&\n left.every((segment, index) => segment === right[index]);\n}\n"],"mappings":";;AAoDA,SAAgB,kBACd,YACqB;CACrB,MAAM,eAAe,IAAI,IACvB,WAAW,oBAAoB,KAAK,UAAU,CAAC,MAAM,YAAY,KAAK,CAAC,CACzE;CACA,OAAO,OAAO,OAAO;EACnB,UAAU;EACV,MAA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,OAAO,EAAE,OAAO,OAAO,KAAK,IAAI,CAAC;GACrC,GAAI,QAAQ,OAAO,cACf,EAAE,aAAa,OAAO,YAAY,IAClC,CAAC;GACL,MAAM,OAAO,OAAO,CAAC,CAAC;GACtB,UAAU;EACZ,CAAC,CAAC,CAAC;CACL;CACA,OAAO,OAAO,OAAO;EACnB,GAAG;EACH;CACF,CAAC;AACH;AAEA,SAAS,oBACP,OACA,QACyB;CACzB,OAAO,OAAO,OAAO,MAAM,KAAK,SAC9B,KAAK,SAAS,eACV,OAAO,OAAO;EACZ,GAAG;EACH,MAAM,OAAO,OAAO,CAAC,GAAG,QAAQ,GAAG,KAAK,IAAI,CAAC;CAC/C,CAAC,IACD,OAAO,OAAO;EACZ,GAAG;EACH,UAAU,oBAAoB,KAAK,UAAU,MAAM;CACrD,CAAC,CACP,CAAC;AACH;AAEA,SAAS,oBACP,QACA,MACS;CACT,OAAO,OAAO,UAAU,KAAK,UAC3B,OAAO,OAAO,SAAS,UAAU,YAAY,KAAK,MAAM;AAC5D;AAEA,SAAS,SAAS,MAAyB,OAAmC;CAC5E,OAAO,KAAK,WAAW,MAAM,UAC3B,KAAK,OAAO,SAAS,UAAU,YAAY,MAAM,MAAM;AAC3D"}
|
|
@@ -405,6 +405,11 @@ async function executeLocatedCapability(located, input, options) {
|
|
|
405
405
|
let rawOutput;
|
|
406
406
|
try {
|
|
407
407
|
rawOutput = await runCapabilityMiddleware(located.middleware, {
|
|
408
|
+
capability: Object.freeze({
|
|
409
|
+
id: located.capability.id,
|
|
410
|
+
effect: located.capability.effect
|
|
411
|
+
}),
|
|
412
|
+
mode: "call",
|
|
408
413
|
input: parsedInput,
|
|
409
414
|
context: options.context,
|
|
410
415
|
...options.signal ? { signal: options.signal } : {}
|
|
@@ -457,6 +462,11 @@ function subscribeLocatedCapability(located, input, options) {
|
|
|
457
462
|
stream.onCancel(() => cleanupSource(true));
|
|
458
463
|
let emitted = false;
|
|
459
464
|
await runCapabilityMiddleware(located.middleware, {
|
|
465
|
+
capability: Object.freeze({
|
|
466
|
+
id: located.capability.id,
|
|
467
|
+
effect: located.capability.effect
|
|
468
|
+
}),
|
|
469
|
+
mode: "subscribe",
|
|
460
470
|
input: parsedInput,
|
|
461
471
|
context: options.context,
|
|
462
472
|
signal
|
|
@@ -589,13 +599,17 @@ function group(config) {
|
|
|
589
599
|
}
|
|
590
600
|
function defineApp(config) {
|
|
591
601
|
assertCapabilityTree(config.capabilities, "application.capabilities");
|
|
592
|
-
const
|
|
602
|
+
const errors = config.errors ?? NO_ERRORS;
|
|
603
|
+
const middleware = Object.freeze([...config.middleware ?? []]);
|
|
604
|
+
const located = locateCapabilities(config.capabilities, [], [], [], errorDefinitions(errors), middleware);
|
|
593
605
|
assertUniqueCapabilities(located);
|
|
594
606
|
return Object.freeze({
|
|
595
607
|
[APPLICATION_SYMBOL]: true,
|
|
596
608
|
name: config.name ?? "Capable application",
|
|
597
609
|
version: config.version ?? "0.0.0",
|
|
598
610
|
...config.description ? { description: config.description } : {},
|
|
611
|
+
errors,
|
|
612
|
+
middleware,
|
|
599
613
|
capabilities: config.capabilities,
|
|
600
614
|
locatedCapabilities: Object.freeze(located)
|
|
601
615
|
});
|
|
@@ -672,4 +686,4 @@ function isRecord(value) {
|
|
|
672
686
|
//#endregion
|
|
673
687
|
export { defineErrors as S, normalizePresentation as _, isCapabilityGroup as a, CAPABILITY_ERRORS_SYMBOL as b, executeCapability as c, subscribeCapability as d, subscribeLocatedCapability as f, watchQuery as g, schemaToJsonSchema as h, group as i, executeLocatedCapability as l, parseSchema as m, CAPABILITY_GROUP_SYMBOL as n, CAPABILITY_SYMBOL as o, SchemaValidationError as p, defineApp as r, capability as s, APPLICATION_SYMBOL as t, isCapability as u, present as v, CapableError as x, renderPresentationMarkdown as y };
|
|
674
688
|
|
|
675
|
-
//# sourceMappingURL=src-
|
|
689
|
+
//# sourceMappingURL=src-Bd1Vnze8.mjs.map
|