capable-kit 0.0.1-alpha.6 → 0.0.1-alpha.8
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/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +1 -1
- package/dist/app.d.mts +1 -1
- package/dist/app.mjs +1 -1
- package/dist/bin.mjs +12 -9
- 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 +2 -2
- package/dist/core.mjs +1 -1
- package/dist/eve.d.mts +1 -1
- package/dist/eve.mjs +1 -1
- package/dist/http.d.mts +2 -2
- package/dist/http.mjs +2 -2
- package/dist/{index-DwXlaTXI.d.mts → index-Dl4NK9G0.d.mts} +20 -4
- package/dist/{index-Dbc4g9WM.d.mts → index-F4ba_olD.d.mts} +3 -3
- package/dist/{index-Be8-UVBC.d.mts → index-_qKFfWV4.d.mts} +4 -2
- package/dist/{index-D2CRRUzH.d.mts → index-hdH_K5Zc.d.mts} +6 -5
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/mcp.d.mts +35 -5
- package/dist/mcp.mjs +1 -1
- package/dist/mount-CEFAplR5.mjs +227 -0
- package/dist/mount-CEFAplR5.mjs.map +1 -0
- package/dist/next.d.mts +14 -0
- package/dist/next.mjs +16 -0
- package/dist/next.mjs.map +1 -0
- package/dist/react-query.d.mts +34 -0
- package/dist/react-query.mjs +47 -0
- package/dist/react-query.mjs.map +1 -0
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +8 -8
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-CDxL6w3d.mjs → src-BWxDO2Ua.mjs} +9 -6
- package/dist/src-BWxDO2Ua.mjs.map +1 -0
- package/dist/{src-DdV82An-.mjs → src-D-cm2gQ6.mjs} +6 -3
- package/dist/src-D-cm2gQ6.mjs.map +1 -0
- package/dist/{src-Db6-XSnU.mjs → src-D_0PIhqq.mjs} +3 -3
- package/dist/{src-Db6-XSnU.mjs.map → src-D_0PIhqq.mjs.map} +1 -1
- package/dist/{src-C2MGIlT0.mjs → src-betOfnDL.mjs} +25 -8
- package/dist/src-betOfnDL.mjs.map +1 -0
- package/dist/{src-BF70JLxI.mjs → src-rkr5j_NH.mjs} +162 -33
- package/dist/src-rkr5j_NH.mjs.map +1 -0
- package/dist/{subscription-Bq792Ad2.d.mts → subscription-B-auXJbm.d.mts} +2 -2
- package/dist/swr.d.mts +36 -0
- package/dist/swr.mjs +48 -0
- package/dist/swr.mjs.map +1 -0
- package/docs/CONTEXT.md +3 -1
- package/docs/internal/adr/0002-version-the-capable-value-codec.md +24 -0
- package/docs/internal/architecture.md +34 -3
- package/docs/internal/capability-first-model.md +1 -1
- package/docs/internal/implementation-friction.md +110 -0
- package/docs/site/capable-orpc-and-trpc.mdx +3 -3
- package/docs/site/concepts/apps.mdx +10 -7
- package/docs/site/concepts/architecture.mdx +1 -1
- package/docs/site/hosting/any-fetch-host.mdx +2 -2
- package/docs/site/hosting/next-js.mdx +38 -4
- package/docs/site/hosting/standalone-server.mdx +2 -2
- package/docs/site/introduction.mdx +9 -6
- package/docs/site/patterns/composition.mdx +7 -3
- package/docs/site/patterns/remote-apps.mdx +62 -8
- package/docs/site/patterns/subscriptions.mdx +2 -2
- package/docs/site/quickstart.mdx +18 -13
- package/docs/site/reference/packages-and-entry-points.mdx +2 -2
- package/docs/site/reference/surface-metadata.mdx +7 -2
- package/docs/site/reference/the-cap-cli.mdx +2 -2
- package/docs/site/surfaces/ai-sdk.mdx +3 -3
- package/docs/site/surfaces/cli.mdx +3 -3
- package/docs/site/surfaces/eve.mdx +5 -5
- package/docs/site/surfaces/mcp.mdx +73 -5
- package/docs/site/surfaces/react-query.mdx +3 -3
- package/docs/site/surfaces/swr.mdx +3 -3
- package/docs/site/surfaces/typescript.mdx +5 -5
- package/docs/site/surfaces.mdx +1 -1
- package/package-docs.mjs +137 -0
- package/package.json +7 -3
- package/prepare-package.mjs +21 -0
- package/src/mcp.ts +4 -0
- package/src/package.test.ts +44 -8
- package/verify-package-exports.mjs +37 -0
- package/dist/mount-xvMsjz1B.mjs +0 -178
- package/dist/mount-xvMsjz1B.mjs.map +0 -1
- package/dist/src-BF70JLxI.mjs.map +0 -1
- package/dist/src-C2MGIlT0.mjs.map +0 -1
- package/dist/src-CDxL6w3d.mjs.map +0 -1
- package/dist/src-DdV82An-.mjs.map +0 -1
|
@@ -8,7 +8,7 @@ Capability definitions
|
|
|
8
8
|
│
|
|
9
9
|
▼
|
|
10
10
|
App Definition ──────────────► createServer(definition, { mounts })
|
|
11
|
-
│ ├─ protocol()
|
|
11
|
+
│ ├─ protocol() /~capable/* manifest, call, subscribe
|
|
12
12
|
│ ├─ http() /api/* routes + /openapi.json
|
|
13
13
|
│ └─ mcp() /mcp Streamable HTTP tools
|
|
14
14
|
│ │
|
|
@@ -98,7 +98,38 @@ Its HTTP encoding lives in `@capable/fetch` — `createHttpTransport()` and
|
|
|
98
98
|
`createProtocolHandler()` — giving request, response, and SSE encoding one home,
|
|
99
99
|
separate from authored HTTP APIs and from transport-neutral App semantics.
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
That private protocol defaults to the versioned `capable.rich-json.v1` codec,
|
|
102
|
+
which preserves runtime values such as `Date` in inputs, outputs, declared-error
|
|
103
|
+
data, and subscription replacements. The codec ID crosses the boundary in the
|
|
104
|
+
`capable-codec` header, so mismatched peers fail before decoding. A deployment
|
|
105
|
+
can replace the value encoding without replacing HTTP or SSE framing:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import {
|
|
109
|
+
createHttpTransport,
|
|
110
|
+
defineProtocolCodec,
|
|
111
|
+
} from "capable-kit/http";
|
|
112
|
+
import { createServer, protocol } from "capable-kit/server";
|
|
113
|
+
|
|
114
|
+
const codec = defineProtocolCodec({
|
|
115
|
+
id: "acme.protocol-values.v1",
|
|
116
|
+
encode: (value) => acmeValues.encode(value),
|
|
117
|
+
decode: (value) => acmeValues.decode(value),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const server = createServer(definition, {
|
|
121
|
+
mounts: [protocol({ codec })],
|
|
122
|
+
});
|
|
123
|
+
const transport = createHttpTransport({
|
|
124
|
+
url: "https://api.example.com/~capable/",
|
|
125
|
+
codec,
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Only the Capable protocol uses this codec. Authored HTTP routes and their
|
|
130
|
+
OpenAPI contracts remain ordinary JSON.
|
|
131
|
+
|
|
132
|
+
Subscriptions are encoded at `POST /~capable/subscribe/:id` as SSE. Errors before
|
|
102
133
|
the first replacement are ordinary HTTP errors; a terminal error after streaming
|
|
103
134
|
began uses a typed SSE error frame.
|
|
104
135
|
|
|
@@ -111,7 +142,7 @@ the first Capability is dispatched. Namespaces belong in the authored App
|
|
|
111
142
|
Definition:
|
|
112
143
|
|
|
113
144
|
```ts
|
|
114
|
-
const remote = createRemoteApp<
|
|
145
|
+
const remote = createRemoteApp<AppDefinition>(transport);
|
|
115
146
|
const app = mergeApps(
|
|
116
147
|
remote,
|
|
117
148
|
createApp(localDefinition, { context: createLocalContext }),
|
|
@@ -98,7 +98,7 @@ local contexts are erased before `mergeApps()` and never become one combined
|
|
|
98
98
|
context:
|
|
99
99
|
|
|
100
100
|
```ts
|
|
101
|
-
const remote = createRemoteApp<
|
|
101
|
+
const remote = createRemoteApp<AppDefinition>(transport);
|
|
102
102
|
const app = mergeApps(
|
|
103
103
|
remote,
|
|
104
104
|
createApp(localDefinition, { context: createLocalContext }),
|
|
@@ -3,6 +3,101 @@
|
|
|
3
3
|
This is a live engineering log. Record awkward, unexpectedly heavy,
|
|
4
4
|
duplicated, or leaky implementation work as it appears.
|
|
5
5
|
|
|
6
|
+
## 2026-09-01 — Surface selection has two execution paths
|
|
7
|
+
|
|
8
|
+
- **Observed:** App and MCP selection filters a resolved manifest, while the
|
|
9
|
+
HTTP projection filters locally located Capabilities. Making selection paths
|
|
10
|
+
fail closed exposed that these paths implement the same tree semantics in
|
|
11
|
+
different packages.
|
|
12
|
+
- **Why it matters:** A stale or misspelled selection must not silently expose
|
|
13
|
+
a different surface, and its validation behavior should not depend on which
|
|
14
|
+
surface consumes it.
|
|
15
|
+
- **Current choice:** Validate resolved App-manifest selection now, which
|
|
16
|
+
covers `selectApp()` and MCP mounts. Keep the existing HTTP projection
|
|
17
|
+
behavior unchanged in this MCP-focused change.
|
|
18
|
+
- **Follow-up:** Move tree matching and path validation behind one
|
|
19
|
+
surface-neutral App helper, then use it from both manifest and HTTP
|
|
20
|
+
selection.
|
|
21
|
+
|
|
22
|
+
## 2026-09-01 — Structured surface metadata crosses remote App boundaries unvalidated
|
|
23
|
+
|
|
24
|
+
- **Observed:** Adding MCP icon descriptors made the projection call array
|
|
25
|
+
operations on `meta.mcp.icons`. Local definitions are type-checked, but a
|
|
26
|
+
remote App manifest preserves open surface metadata as unknown JSON, so a
|
|
27
|
+
malformed icon value could otherwise throw an incidental `TypeError` during
|
|
28
|
+
MCP tool discovery.
|
|
29
|
+
- **Why it matters:** `@capable/app` cannot validate registry-specific metadata
|
|
30
|
+
without depending on every surface, while each surface must still treat a
|
|
31
|
+
remote manifest as untrusted input.
|
|
32
|
+
- **Current choice:** Validate the MCP metadata fields at the MCP projection
|
|
33
|
+
boundary and report the Capability ID plus the invalid field. Keep the App
|
|
34
|
+
manifest open and transport-neutral.
|
|
35
|
+
- **Follow-up:** If another surface needs the same structured-metadata checks,
|
|
36
|
+
extract a small validation helper in `@capable/app`; do not add a generic
|
|
37
|
+
closed metadata schema to core.
|
|
38
|
+
|
|
39
|
+
## 2026-08-05 — An internal-looking protocol path collided with Next routing
|
|
40
|
+
|
|
41
|
+
- **Observed:** The original `/_capable` default looked implementation-private,
|
|
42
|
+
but Next.js treats underscore-prefixed App Router folders as non-routable and
|
|
43
|
+
required the surprising `app/%5Fcapable` spelling. A plain `/capable` path
|
|
44
|
+
removed that friction but gave a framework protocol a common page name.
|
|
45
|
+
- **Why it matters:** The protocol path crosses every host, generated caller,
|
|
46
|
+
development splash, proxy rule, and example. Its default should be literal in
|
|
47
|
+
first-party route files and unlikely to collide with application pages.
|
|
48
|
+
- **Current choice:** Use `/~capable` as the flag-day default with no legacy
|
|
49
|
+
alias. Keep `protocol({ path })` available for custom mounts.
|
|
50
|
+
- **Follow-up:** Keep a literal-folder Next integration test and URL-routing
|
|
51
|
+
coverage so future host changes cannot encode, strip, or reinterpret `~`.
|
|
52
|
+
|
|
53
|
+
## 2026-08-05 — Relative transport URLs only have meaning in a browser
|
|
54
|
+
|
|
55
|
+
- **Observed:** Public browser examples used `"/_capable/"`, but the transport
|
|
56
|
+
passed every configured base through the single-argument `URL` constructor,
|
|
57
|
+
which rejects relative paths. Requiring every client component to defer a
|
|
58
|
+
`window.location.origin` lookup made the common case noisy.
|
|
59
|
+
- **Why it matters:** `createHttpTransport()` is shared by browsers, servers,
|
|
60
|
+
workers, CLIs, and tests. Only browsers provide an unambiguous ambient origin;
|
|
61
|
+
silently inventing one elsewhere would make requests environment-dependent.
|
|
62
|
+
- **Current choice:** Resolve relative URLs against `window.location.origin` at
|
|
63
|
+
request time when `window` exists. Outside a browser, keep the explicit error
|
|
64
|
+
and require an absolute URL or a request-aware `url` function.
|
|
65
|
+
- **Follow-up:** Add another ambient base only if a host exposes one with
|
|
66
|
+
equally clear semantics.
|
|
67
|
+
|
|
68
|
+
## 2026-08-05 — Hand-written MCP output wrapping bypassed protocol projection
|
|
69
|
+
|
|
70
|
+
- **Observed:** The MCP adapter wrapped arrays and primitives under `value` and
|
|
71
|
+
rewrote their output schemas before handing them to the MCP v2 server. The
|
|
72
|
+
SDK already owns an era-aware projection: MCP 2026-07-28 supports natural
|
|
73
|
+
JSON values, while legacy clients require a matching object wrapper.
|
|
74
|
+
- **Why it matters:** The custom wrapper made modern MCP output differ from the
|
|
75
|
+
canonical Capability output and duplicated evolving wire-protocol policy in
|
|
76
|
+
Capable.
|
|
77
|
+
- **Current choice:** Keep the natural Capability output and schema inside the
|
|
78
|
+
projection, then call the SDK's `projectCallToolResult()`. The SDK preserves
|
|
79
|
+
modern values and applies the legacy `result` wrapper consistently to both
|
|
80
|
+
`tools/list` and `tools/call`.
|
|
81
|
+
- **Follow-up:** Keep protocol-version adaptation in the SDK unless Capable has
|
|
82
|
+
a semantic requirement the SDK cannot express.
|
|
83
|
+
|
|
84
|
+
## 2026-08-05 — Runtime values and JSON Schema have different jobs
|
|
85
|
+
|
|
86
|
+
- **Observed:** Plain JSON transport converted a schema-valid `Date` into a
|
|
87
|
+
string before remote output validation, while Zod refused to project
|
|
88
|
+
`z.date()` into the manifest because JSON Schema has no equivalent type.
|
|
89
|
+
- **Why it matters:** A remote App could retain the authored TypeScript type but
|
|
90
|
+
return a different runtime value, and runtime-only schemas could prevent the
|
|
91
|
+
whole manifest from being exposed.
|
|
92
|
+
- **Current choice:** The private Capable protocol uses the versioned
|
|
93
|
+
`capable.rich-json.v1` codec, backed by an isolated SuperJSON instance, and
|
|
94
|
+
accepts matched custom `ProtocolCodec`s. Standard JSON Schema projection asks
|
|
95
|
+
the schema library to represent unrepresentable runtime values as unconstrained
|
|
96
|
+
JSON (`{}`) only for App manifests. Authored HTTP and OpenAPI remain strict,
|
|
97
|
+
plain JSON projections.
|
|
98
|
+
- **Follow-up:** Add a new codec ID and manifest protocol version for any wire
|
|
99
|
+
format change; do not inherit a dependency's format changes silently.
|
|
100
|
+
|
|
6
101
|
## 2026-08-05 — Markdown negotiation must run before static page matching
|
|
7
102
|
|
|
8
103
|
- **Observed:** The `dom-md` Next.js example returns a flat rewrite list, which
|
|
@@ -413,6 +508,21 @@ duplicated, or leaky implementation work as it appears.
|
|
|
413
508
|
The projection's `key`, `swr`, `mutation`, and `subscription` member names are
|
|
414
509
|
reserved until App leaves have synchronous metadata.
|
|
415
510
|
|
|
511
|
+
## 2026-08-05 — npm pack silently accepted missing export targets
|
|
512
|
+
|
|
513
|
+
- **Observed:** `capable-kit@0.0.1-alpha.6` advertised the new `next`,
|
|
514
|
+
`react-query`, and `swr` subpaths, but the publishing worktree's ignored
|
|
515
|
+
`dist/` directory did not contain their built files. npm included the export
|
|
516
|
+
map without warning and published a tarball with phantom entry points.
|
|
517
|
+
- **Why it matters:** Type-aware tooling could see the intended API while every
|
|
518
|
+
runtime import failed. A successful source build in another worktree did not
|
|
519
|
+
prove the contents of the worktree used for publishing.
|
|
520
|
+
- **Current choice:** `prepack` builds from source, verifies every export and bin
|
|
521
|
+
target, and only then assembles documentation. The package test independently
|
|
522
|
+
checks that every manifest target appears in the produced tarball.
|
|
523
|
+
- **Follow-up:** Keep release validation tarball-based; do not treat an ignored
|
|
524
|
+
local `dist/` directory or a source-level test as publication evidence.
|
|
525
|
+
|
|
416
526
|
## 2026-07-28 — A fresh Next.js build can race SQLite initialization
|
|
417
527
|
|
|
418
528
|
- **Observed:** Next.js page-data collection imports the authenticated Todo
|
|
@@ -41,10 +41,10 @@ You do not give up the normal full-stack experience by choosing Capable. A brows
|
|
|
41
41
|
import { createRemoteApp } from "capable-kit";
|
|
42
42
|
import { createHttpTransport } from "capable-kit/http";
|
|
43
43
|
import { createReactQuery } from "capable-kit/react-query";
|
|
44
|
-
import type
|
|
44
|
+
import type { AppDefinition } from "../capable.app";
|
|
45
45
|
|
|
46
|
-
const app = createRemoteApp<
|
|
47
|
-
createHttpTransport({ url: "/
|
|
46
|
+
const app = createRemoteApp<AppDefinition>(
|
|
47
|
+
createHttpTransport({ url: "/~capable/" }),
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
export const query = createReactQuery(app);
|
|
@@ -18,7 +18,7 @@ An app definition gives a set of capabilities one shared structure. Nest them wi
|
|
|
18
18
|
```ts title="capable.app.ts"
|
|
19
19
|
import { defineApp } from "capable-kit";
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const definition = defineApp({
|
|
22
22
|
name: "Todos",
|
|
23
23
|
capabilities: {
|
|
24
24
|
system: { health },
|
|
@@ -29,6 +29,9 @@ export default defineApp({
|
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
});
|
|
32
|
+
|
|
33
|
+
export type AppDefinition = typeof definition;
|
|
34
|
+
export default definition;
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
This file is only the definition. It does not choose where the capabilities run or how people and agents reach them.
|
|
@@ -86,7 +89,7 @@ import definition from "./capable.app";
|
|
|
86
89
|
|
|
87
90
|
export const server = createServer(definition, {
|
|
88
91
|
mounts: [
|
|
89
|
-
protocol(
|
|
92
|
+
protocol(),
|
|
90
93
|
http({ path: "/api" }),
|
|
91
94
|
],
|
|
92
95
|
});
|
|
@@ -96,16 +99,16 @@ Here `http()` creates ordinary HTTP endpoints and `protocol()` exposes the proto
|
|
|
96
99
|
|
|
97
100
|
## Consume it over HTTP [#remote]
|
|
98
101
|
|
|
99
|
-
In another process, create a remote app instead of a local one.
|
|
102
|
+
In another process, create a remote app instead of a local one. Import its named definition type while the transport points to the `protocol()` mount.
|
|
100
103
|
|
|
101
104
|
```ts title="remote.ts"
|
|
102
105
|
import { createRemoteApp } from "capable-kit";
|
|
103
106
|
import { createHttpTransport } from "capable-kit/http";
|
|
104
|
-
import type
|
|
107
|
+
import type { AppDefinition } from "./capable.app";
|
|
105
108
|
|
|
106
|
-
export const app = createRemoteApp<
|
|
109
|
+
export const app = createRemoteApp<AppDefinition>(
|
|
107
110
|
createHttpTransport({
|
|
108
|
-
url: "https://todos.example.com/
|
|
111
|
+
url: "https://todos.example.com/~capable/",
|
|
109
112
|
}),
|
|
110
113
|
);
|
|
111
114
|
|
|
@@ -212,6 +215,6 @@ Putting `requireUser` at the application boundary would also protect product sea
|
|
|
212
215
|
|
|
213
216
|
## The manifest [#manifest]
|
|
214
217
|
|
|
215
|
-
Every app can describe itself: the tree, ids, titles, effects, JSON Schemas, and declared errors. Surfaces are built from that manifest, which is why a [remote app](/patterns/remote-apps#boundary) can produce the same CLI as a local one. A server exposes it at
|
|
218
|
+
Every app can describe itself: the tree, ids, titles, effects, JSON Schemas, and declared errors. Surfaces are built from that manifest, which is why a [remote app](/patterns/remote-apps#boundary) can produce the same CLI as a local one. A server exposes it at `/~capable/manifest` when the `protocol()` mount is enabled.
|
|
216
219
|
|
|
217
220
|
</DocsPage>
|
|
@@ -45,7 +45,7 @@ mergeApps() / selectApp() one typed app
|
|
|
45
45
|
+-- createReactQuery(app) query keys and options
|
|
46
46
|
|
|
47
47
|
defineApp() -> createServer(definition, { mounts }) -> fetch(request)
|
|
48
|
-
protocol()
|
|
48
|
+
protocol() /~capable/* manifest, call, subscribe
|
|
49
49
|
http() /api/* routes and /openapi.json
|
|
50
50
|
mcp() /mcp Streamable HTTP tools
|
|
51
51
|
```
|
|
@@ -43,7 +43,7 @@ app.get("/", (c) => c.html(renderProduct()));
|
|
|
43
43
|
|
|
44
44
|
app.all("/api", (c) => server.fetch(c.req.raw));
|
|
45
45
|
app.all("/api/*", (c) => server.fetch(c.req.raw));
|
|
46
|
-
app.all("
|
|
46
|
+
app.all("/~capable/*", (c) => server.fetch(c.req.raw));
|
|
47
47
|
app.all("/openapi.json", (c) => server.fetch(c.req.raw));
|
|
48
48
|
app.all("/mcp", (c) => server.fetch(c.req.raw));
|
|
49
49
|
|
|
@@ -61,7 +61,7 @@ import server from "./capable.server";
|
|
|
61
61
|
const app = new H3()
|
|
62
62
|
.get("/", () => "Existing H3 application")
|
|
63
63
|
.all("/api/**", (event) => server.fetch(event.req))
|
|
64
|
-
.all("
|
|
64
|
+
.all("/~capable/**", (event) => server.fetch(event.req))
|
|
65
65
|
.all("/openapi.json", (event) => server.fetch(event.req));
|
|
66
66
|
|
|
67
67
|
serve(app, { port: 3000 });
|
|
@@ -38,24 +38,58 @@ Route folders decide what is reachable. Export only the methods a path should an
|
|
|
38
38
|
// app/api/[[...path]]/route.ts
|
|
39
39
|
export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
|
|
40
40
|
|
|
41
|
-
// app
|
|
42
|
-
// %5F keeps Next from treating _capable as a private folder.
|
|
41
|
+
// app/~capable/[[...path]]/route.ts
|
|
43
42
|
export { GET, POST } from "@/capable/server";
|
|
44
43
|
|
|
45
44
|
// app/openapi.json/route.ts
|
|
46
45
|
export { GET } from "@/capable/server";
|
|
46
|
+
|
|
47
|
+
// app/mcp/route.ts
|
|
48
|
+
export { DELETE, GET, OPTIONS, POST } from "@/capable/server";
|
|
47
49
|
```
|
|
48
50
|
|
|
49
51
|
| Route | Serves |
|
|
50
52
|
| --- | --- |
|
|
51
53
|
| `/api/*` | Derived or authored HTTP routes |
|
|
52
|
-
|
|
|
54
|
+
| `/~capable/*` | Capable transport for remote apps, the CLI, and React Query |
|
|
53
55
|
| `/openapi.json` | Generated OpenAPI document |
|
|
54
56
|
| `/mcp` | MCP, when the mcp() mount is included |
|
|
55
57
|
|
|
58
|
+
## Keep server implementations out of client bundles [#client-boundary]
|
|
59
|
+
|
|
60
|
+
A browser caller needs the definition's type, not its runtime implementation.
|
|
61
|
+
Export a named type derived from the definition so the contract stays tied to
|
|
62
|
+
the source of truth:
|
|
63
|
+
|
|
64
|
+
```ts title="capable.app.ts"
|
|
65
|
+
export type AppDefinition = typeof definition;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Import only that named type in client code. Handlers, database clients, and
|
|
69
|
+
environment variables are erased from the client bundle.
|
|
70
|
+
|
|
71
|
+
```tsx title="app/todos.tsx"
|
|
72
|
+
"use client";
|
|
73
|
+
|
|
74
|
+
import { createRemoteApp } from "capable-kit";
|
|
75
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
76
|
+
import type { AppDefinition } from "@/capable.app";
|
|
77
|
+
|
|
78
|
+
const app = createRemoteApp<AppDefinition>(
|
|
79
|
+
createHttpTransport({
|
|
80
|
+
url: "/~capable/",
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If both client and server code need a runtime value such as a status list,
|
|
86
|
+
place it in a dependency-free shared module. Do not import that value from a
|
|
87
|
+
capability module that also imports a database or reads server environment
|
|
88
|
+
variables.
|
|
89
|
+
|
|
56
90
|
## Server components and actions [#server-components]
|
|
57
91
|
|
|
58
|
-
Inside the same deployment, do not go through HTTP. Create a local app and call it directly from a server component or a server action; the browser can still reach the same capabilities through
|
|
92
|
+
Inside the same deployment, do not go through HTTP. Create a local app and call it directly from a server component or a server action; the browser can still reach the same capabilities through `/~capable/*`.
|
|
59
93
|
|
|
60
94
|
```ts title="app/todo-actions.ts"
|
|
61
95
|
// app/todo-actions.ts
|
|
@@ -34,7 +34,7 @@ $ cap dev
|
|
|
34
34
|
◆ Todos 1.0.0
|
|
35
35
|
|
|
36
36
|
Local http://localhost:3000
|
|
37
|
-
Capable
|
|
37
|
+
Capable /~capable
|
|
38
38
|
HTTP /api
|
|
39
39
|
OpenAPI /openapi.json
|
|
40
40
|
MCP /mcp
|
|
@@ -73,7 +73,7 @@ export default createServer(definition, {
|
|
|
73
73
|
db,
|
|
74
74
|
}),
|
|
75
75
|
mounts: [
|
|
76
|
-
protocol(
|
|
76
|
+
protocol(),
|
|
77
77
|
http({ path: "/api", requireExplicitRoutes: true }),
|
|
78
78
|
mcp({ path: "/mcp" }),
|
|
79
79
|
],
|
|
@@ -36,13 +36,16 @@ An app gives capabilities a path: `todos.create`.
|
|
|
36
36
|
import { defineApp } from "capable-kit";
|
|
37
37
|
import { createTodo } from "./capabilities/create-todo";
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const definition = defineApp({
|
|
40
40
|
name: "Todos",
|
|
41
41
|
version: "1.0.0",
|
|
42
42
|
capabilities: {
|
|
43
43
|
todos: { create: createTodo },
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
|
+
|
|
47
|
+
export type AppDefinition = typeof definition;
|
|
48
|
+
export default definition;
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
Add output schemas, errors, middleware, or surface metadata only when the app needs them.
|
|
@@ -74,7 +77,7 @@ $ cap dev
|
|
|
74
77
|
◆ Todos 1.0.0
|
|
75
78
|
|
|
76
79
|
Local http://localhost:3000
|
|
77
|
-
Capable
|
|
80
|
+
Capable /~capable
|
|
78
81
|
HTTP /api
|
|
79
82
|
OpenAPI /openapi.json
|
|
80
83
|
MCP /mcp
|
|
@@ -101,7 +104,7 @@ export const { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } =
|
|
|
101
104
|
createNextRouteHandlers(server.fetch);
|
|
102
105
|
```
|
|
103
106
|
|
|
104
|
-
Re-export those handlers at the `/api`,
|
|
107
|
+
Re-export those handlers at the `/api`, `/~capable`, `/openapi.json`, and `/mcp` URLs. The [Next.js guide](/hosting/next) shows the complete route layout.
|
|
105
108
|
|
|
106
109
|
</Tab>
|
|
107
110
|
<Tab label="Any Fetch host">
|
|
@@ -214,12 +217,12 @@ import { createReactQuery } from "capable-kit/react-query";
|
|
|
214
217
|
import { useMutation } from "@tanstack/react-query";
|
|
215
218
|
import { createRemoteApp } from "capable-kit";
|
|
216
219
|
import { createHttpTransport } from "capable-kit/http";
|
|
217
|
-
import type
|
|
220
|
+
import type { AppDefinition } from "./capable.app";
|
|
218
221
|
|
|
219
222
|
const query = createReactQuery(
|
|
220
|
-
createRemoteApp<
|
|
223
|
+
createRemoteApp<AppDefinition>(
|
|
221
224
|
createHttpTransport({
|
|
222
|
-
url:
|
|
225
|
+
url: "/~capable/",
|
|
223
226
|
}),
|
|
224
227
|
),
|
|
225
228
|
);
|
|
@@ -18,12 +18,12 @@ The product API, on a server. `createRemoteApp()` takes the server definition as
|
|
|
18
18
|
```ts title="remote.ts"
|
|
19
19
|
import { createRemoteApp } from "capable-kit";
|
|
20
20
|
import { createHttpTransport } from "capable-kit/http";
|
|
21
|
-
import type
|
|
21
|
+
import type { AppDefinition } from "../server/capable.app";
|
|
22
22
|
|
|
23
23
|
// The product API, running on a server. Typed from the server
|
|
24
24
|
// definition, no client generated. Talks to the Capable transport.
|
|
25
|
-
export const remote = createRemoteApp<
|
|
26
|
-
createHttpTransport({ url: "https://todos.example.com/
|
|
25
|
+
export const remote = createRemoteApp<AppDefinition>(
|
|
26
|
+
createHttpTransport({ url: "https://todos.example.com/~capable/" }),
|
|
27
27
|
);
|
|
28
28
|
```
|
|
29
29
|
|
|
@@ -139,4 +139,8 @@ const agentApp = selectApp(app, {
|
|
|
139
139
|
await createMcp(agentApp);
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
Every `include` and `exclude` path must exist in the resolved App manifest.
|
|
143
|
+
Unknown paths fail manifest resolution, which keeps stale policy from silently
|
|
144
|
+
changing the exposed surface.
|
|
145
|
+
|
|
142
146
|
</DocsPage>
|
|
@@ -18,14 +18,14 @@ A capability describes what something does. It says nothing about where it runs.
|
|
|
18
18
|
```ts title="apps.ts"
|
|
19
19
|
import { createApp, createRemoteApp } from "capable-kit";
|
|
20
20
|
import { createHttpTransport } from "capable-kit/http";
|
|
21
|
-
import type
|
|
21
|
+
import definition, { type AppDefinition } from "./capable.app";
|
|
22
22
|
|
|
23
23
|
// Runs here, in this process.
|
|
24
24
|
const local = createApp(definition);
|
|
25
25
|
|
|
26
26
|
// Runs there, behind someone else's context and policy.
|
|
27
|
-
const remote = createRemoteApp<
|
|
28
|
-
createHttpTransport({ url: "https://todos.example.com/
|
|
27
|
+
const remote = createRemoteApp<AppDefinition>(
|
|
28
|
+
createHttpTransport({ url: "https://todos.example.com/~capable/" }),
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
// The calling code cannot tell them apart.
|
|
@@ -43,7 +43,7 @@ export async function openTodos(app: typeof local | typeof remote) {
|
|
|
43
43
|
|
|
44
44
|
> **No code generation**
|
|
45
45
|
>
|
|
46
|
-
>
|
|
46
|
+
> Export a named type derived from the definition, then import that type in remote consumers. The type is erased at build time, so no server code or generated client ends up in the caller. Ship the definition's types in a package and any consumer can be typed against it.
|
|
47
47
|
|
|
48
48
|
## What crosses the boundary [#boundary]
|
|
49
49
|
|
|
@@ -57,12 +57,17 @@ import definition from "./capable.app";
|
|
|
57
57
|
|
|
58
58
|
export default createServer(definition, {
|
|
59
59
|
context: ({ request }) => contextFromRequest(request),
|
|
60
|
-
mounts: [protocol(
|
|
60
|
+
mounts: [protocol()],
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
Because surfaces are built from the manifest, a remote app can produce the same [CLI](/surfaces/cli), [MCP tools](/surfaces/mcp), or [React Query](/surfaces/react-query) bindings as a local one. The projection never learns where execution happens.
|
|
65
65
|
|
|
66
|
+
The built-in transport preserves runtime values such as `Date` across inputs,
|
|
67
|
+
outputs, declared errors, and subscriptions. This rich encoding belongs only to
|
|
68
|
+
the private Capable protocol; authored HTTP routes and OpenAPI remain ordinary
|
|
69
|
+
JSON.
|
|
70
|
+
|
|
66
71
|
## Transports [#transports]
|
|
67
72
|
|
|
68
73
|
HTTP is the transport that ships, but it is not privileged. `ApplicationTransport` is an interface with `manifest()`, `call()`, and `subscribe()`, so "remote" can mean a worker, a child process, a message queue, a browser extension port, or a stub in a test.
|
|
@@ -82,26 +87,75 @@ export function createWorkerTransport(worker: Worker): ApplicationTransport {
|
|
|
82
87
|
|
|
83
88
|
```ts title="main.ts"
|
|
84
89
|
import { createRemoteApp } from "capable-kit";
|
|
85
|
-
import type
|
|
90
|
+
import type { AppDefinition } from "./capable.app";
|
|
86
91
|
|
|
87
|
-
const app = createRemoteApp<
|
|
92
|
+
const app = createRemoteApp<AppDefinition>(
|
|
88
93
|
createWorkerTransport(new Worker("./worker.js")),
|
|
89
94
|
);
|
|
90
95
|
|
|
91
96
|
await app.image.resize({ url, width: 512 }); // runs off the main thread
|
|
92
97
|
```
|
|
93
98
|
|
|
99
|
+
### Custom value codecs [#custom-codecs]
|
|
100
|
+
|
|
101
|
+
You can replace the protocol's value encoding while keeping Capable's HTTP and
|
|
102
|
+
SSE framing. Give the codec a stable ID and configure the same codec semantics
|
|
103
|
+
on both peers. A missing or different ID is rejected explicitly.
|
|
104
|
+
|
|
105
|
+
```ts title="codec.ts"
|
|
106
|
+
import { defineProtocolCodec } from "capable-kit/http";
|
|
107
|
+
|
|
108
|
+
export const codec = defineProtocolCodec({
|
|
109
|
+
id: "acme.protocol-values.v1",
|
|
110
|
+
encode: (value) => acmeValues.encode(value),
|
|
111
|
+
decode: (value) => acmeValues.decode(value),
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```ts title="capable.server.ts"
|
|
116
|
+
import { createServer, protocol } from "capable-kit/server";
|
|
117
|
+
import definition from "./capable.app";
|
|
118
|
+
import { codec } from "./codec";
|
|
119
|
+
|
|
120
|
+
export default createServer(definition, {
|
|
121
|
+
mounts: [protocol({ codec })],
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```ts title="client.ts"
|
|
126
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
127
|
+
import { codec } from "./codec";
|
|
128
|
+
|
|
129
|
+
const transport = createHttpTransport({
|
|
130
|
+
url: "https://todos.example.com/~capable/",
|
|
131
|
+
codec,
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
94
135
|
## Credentials and base URLs [#credentials]
|
|
95
136
|
|
|
96
137
|
The transport owns everything about reaching the server, so capabilities never see tokens or hostnames. Both `url` and `headers` accept a function, which is resolved per request — enough for token refresh, environment switching, or per-tenant routing.
|
|
97
138
|
|
|
98
139
|
```ts title="transport.ts"
|
|
99
140
|
createHttpTransport({
|
|
100
|
-
url: () => `${process.env.API_URL}
|
|
141
|
+
url: () => `${process.env.API_URL}/~capable/`,
|
|
101
142
|
headers: async () => ({ authorization: `Bearer ${await accessToken()}` }),
|
|
102
143
|
});
|
|
103
144
|
```
|
|
104
145
|
|
|
146
|
+
In a browser, a relative transport URL resolves against `window.location.origin`
|
|
147
|
+
when the request is made:
|
|
148
|
+
|
|
149
|
+
```ts title="browser-transport.ts"
|
|
150
|
+
createHttpTransport({
|
|
151
|
+
url: "/~capable/",
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The same API also runs in servers, workers, CLIs, and tests, where no browser
|
|
156
|
+
origin exists. Those environments must pass an absolute URL or return one from
|
|
157
|
+
the `url` function.
|
|
158
|
+
|
|
105
159
|
## Choosing where a capability runs [#honesty]
|
|
106
160
|
|
|
107
161
|
Calling is uniform; placement is still a decision you make in source. A remote call is a network call, with the latency and failure modes that implies, and it runs under the server's context and policy rather than yours. Capable does not pretend otherwise — it only removes the boilerplate between the two.
|
|
@@ -64,14 +64,14 @@ Input is parsed once. Every emitted item is validated against the output schema,
|
|
|
64
64
|
|
|
65
65
|
## Over the wire [#transport]
|
|
66
66
|
|
|
67
|
-
The Capable transport encodes subscriptions as server-sent events at `POST /
|
|
67
|
+
The Capable transport encodes subscriptions as server-sent events at `POST /~capable/subscribe/:id`. Errors raised before the first replacement are ordinary HTTP errors; a terminal error after streaming began arrives as a typed SSE error frame.
|
|
68
68
|
|
|
69
69
|
```sh title="terminal"
|
|
70
70
|
curl -N -X POST \
|
|
71
71
|
-H 'accept: text/event-stream' \
|
|
72
72
|
-H 'content-type: application/json' \
|
|
73
73
|
--data '{"input":{}}' \
|
|
74
|
-
http://localhost:3000/
|
|
74
|
+
http://localhost:3000/~capable/subscribe/todos.list
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
The CLI exposes the same mode with `--watch`, and [React Query](/surfaces/react-query) exposes it as `liveQueryOptions()`. MCP always calls the unary snapshot.
|