capable-kit 0.0.1-alpha.7 → 0.1.0-alpha.10
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 +214 -0
- package/README.md +6 -0
- package/dist/ai-sdk.d.mts +3 -3
- package/dist/ai-sdk.mjs +9 -7
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +2 -2
- package/dist/bin.mjs +12 -9
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +9 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +1 -1
- package/dist/eve.d.mts +82 -5
- package/dist/eve.mjs +364 -23
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +2 -2
- package/dist/http.mjs +2 -2
- package/dist/{index-Dbc4g9WM.d.mts → index-1A44jLuE.d.mts} +54 -16
- package/dist/{index-DwXlaTXI.d.mts → index-CHuCLJIs.d.mts} +20 -4
- package/dist/{index-D2CRRUzH.d.mts → index-D-NV4PiU.d.mts} +6 -5
- package/dist/{index-Be8-UVBC.d.mts → index-WiBWfyTn.d.mts} +66 -27
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +40 -5
- package/dist/mcp.mjs +1 -1
- package/dist/mount-BmLHp349.mjs +235 -0
- package/dist/mount-BmLHp349.mjs.map +1 -0
- package/dist/react-query.d.mts +2 -2
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- 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-Db6-XSnU.mjs → src-3LE9S4QE.mjs} +67 -38
- package/dist/src-3LE9S4QE.mjs.map +1 -0
- package/dist/{src-DdV82An-.mjs → src-B2WeUwUT.mjs} +69 -34
- package/dist/src-B2WeUwUT.mjs.map +1 -0
- package/dist/{src-CDxL6w3d.mjs → src-C5jGDnuu.mjs} +9 -6
- package/dist/src-C5jGDnuu.mjs.map +1 -0
- package/dist/src-DePlcG_t.mjs +787 -0
- package/dist/src-DePlcG_t.mjs.map +1 -0
- package/dist/{src-BF70JLxI.mjs → src-_6OmFRYa.mjs} +185 -38
- package/dist/src-_6OmFRYa.mjs.map +1 -0
- package/dist/{subscription-Bq792Ad2.d.mts → subscription-DPdwovhw.d.mts} +2 -2
- package/dist/swr.d.mts +2 -2
- package/dist/swr.mjs +1 -1
- package/dist/swr.mjs.map +1 -1
- package/docs/CONTEXT.md +42 -21
- 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/adr/0002-version-the-capable-value-codec.md +24 -0
- package/docs/internal/adr/0003-capability-reference-customization.md +68 -0
- package/docs/internal/architecture.md +64 -19
- package/docs/internal/capability-first-model.md +127 -18
- 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 +481 -1
- package/docs/internal/releases.md +79 -0
- package/docs/site/capable-orpc-and-trpc.mdx +5 -5
- package/docs/site/concepts/apps.mdx +17 -8
- package/docs/site/concepts/architecture.mdx +10 -2
- package/docs/site/concepts/capabilities.mdx +41 -4
- package/docs/site/concepts/errors.mdx +11 -1
- package/docs/site/concepts/presentations.mdx +20 -0
- 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 +159 -11
- package/docs/site/patterns/remote-apps.mdx +68 -10
- package/docs/site/patterns/subscriptions.mdx +79 -32
- package/docs/site/quickstart.mdx +19 -14
- package/docs/site/reference/packages-and-entry-points.mdx +52 -5
- 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 +47 -3
- package/docs/site/surfaces/eve.mdx +67 -20
- 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 +8 -8
- package/docs/site/surfaces.mdx +1 -1
- package/package-docs.mjs +3 -0
- package/package.json +11 -11
- package/src/bin.ts +0 -0
- package/src/index.test.ts +2 -1
- package/src/index.ts +6 -1
- package/src/mcp.ts +4 -0
- package/src/package.test.ts +9 -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 +0 -464
- package/dist/src-C2MGIlT0.mjs.map +0 -1
- package/dist/src-CDxL6w3d.mjs.map +0 -1
- package/dist/src-Db6-XSnU.mjs.map +0 -1
- package/dist/src-DdV82An-.mjs.map +0 -1
|
@@ -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,16 +57,25 @@ 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.
|
|
69
74
|
|
|
75
|
+
`subscribe()` resolves after the remote stream is opened, then returns its async
|
|
76
|
+
iterator. This keeps request and authorization failures separate from errors
|
|
77
|
+
emitted after streaming begins.
|
|
78
|
+
|
|
70
79
|
```ts title="worker-transport.ts"
|
|
71
80
|
import type { ApplicationTransport } from "capable-kit/app";
|
|
72
81
|
|
|
@@ -75,33 +84,82 @@ export function createWorkerTransport(worker: Worker): ApplicationTransport {
|
|
|
75
84
|
return {
|
|
76
85
|
manifest: (options) => send(worker, { kind: "manifest" }, options),
|
|
77
86
|
call: (call) => send(worker, { kind: "call", call }),
|
|
78
|
-
subscribe: (call) => stream(worker, call),
|
|
87
|
+
subscribe: async (call) => stream(worker, call),
|
|
79
88
|
};
|
|
80
89
|
}
|
|
81
90
|
```
|
|
82
91
|
|
|
83
92
|
```ts title="main.ts"
|
|
84
93
|
import { createRemoteApp } from "capable-kit";
|
|
85
|
-
import type
|
|
94
|
+
import type { AppDefinition } from "./capable.app";
|
|
86
95
|
|
|
87
|
-
const app = createRemoteApp<
|
|
96
|
+
const app = createRemoteApp<AppDefinition>(
|
|
88
97
|
createWorkerTransport(new Worker("./worker.js")),
|
|
89
98
|
);
|
|
90
99
|
|
|
91
100
|
await app.image.resize({ url, width: 512 }); // runs off the main thread
|
|
92
101
|
```
|
|
93
102
|
|
|
103
|
+
### Custom value codecs [#custom-codecs]
|
|
104
|
+
|
|
105
|
+
You can replace the protocol's value encoding while keeping Capable's HTTP and
|
|
106
|
+
SSE framing. Give the codec a stable ID and configure the same codec semantics
|
|
107
|
+
on both peers. A missing or different ID is rejected explicitly.
|
|
108
|
+
|
|
109
|
+
```ts title="codec.ts"
|
|
110
|
+
import { defineProtocolCodec } from "capable-kit/http";
|
|
111
|
+
|
|
112
|
+
export const codec = defineProtocolCodec({
|
|
113
|
+
id: "acme.protocol-values.v1",
|
|
114
|
+
encode: (value) => acmeValues.encode(value),
|
|
115
|
+
decode: (value) => acmeValues.decode(value),
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```ts title="capable.server.ts"
|
|
120
|
+
import { createServer, protocol } from "capable-kit/server";
|
|
121
|
+
import definition from "./capable.app";
|
|
122
|
+
import { codec } from "./codec";
|
|
123
|
+
|
|
124
|
+
export default createServer(definition, {
|
|
125
|
+
mounts: [protocol({ codec })],
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
```ts title="client.ts"
|
|
130
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
131
|
+
import { codec } from "./codec";
|
|
132
|
+
|
|
133
|
+
const transport = createHttpTransport({
|
|
134
|
+
url: "https://todos.example.com/~capable/",
|
|
135
|
+
codec,
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
94
139
|
## Credentials and base URLs [#credentials]
|
|
95
140
|
|
|
96
141
|
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
142
|
|
|
98
143
|
```ts title="transport.ts"
|
|
99
144
|
createHttpTransport({
|
|
100
|
-
url: () => `${process.env.API_URL}
|
|
145
|
+
url: () => `${process.env.API_URL}/~capable/`,
|
|
101
146
|
headers: async () => ({ authorization: `Bearer ${await accessToken()}` }),
|
|
102
147
|
});
|
|
103
148
|
```
|
|
104
149
|
|
|
150
|
+
In a browser, a relative transport URL resolves against `window.location.origin`
|
|
151
|
+
when the request is made:
|
|
152
|
+
|
|
153
|
+
```ts title="browser-transport.ts"
|
|
154
|
+
createHttpTransport({
|
|
155
|
+
url: "/~capable/",
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The same API also runs in servers, workers, CLIs, and tests, where no browser
|
|
160
|
+
origin exists. Those environments must pass an absolute URL or return one from
|
|
161
|
+
the `url` function.
|
|
162
|
+
|
|
105
163
|
## Choosing where a capability runs [#honesty]
|
|
106
164
|
|
|
107
165
|
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.
|
|
@@ -112,6 +170,6 @@ Calling is uniform; placement is still a decision you make in source. A remote c
|
|
|
112
170
|
| It needs to work offline or without a server | It enforces authorization the client must not be trusted with |
|
|
113
171
|
| Latency per call matters more than trust | The implementation must not ship to the caller |
|
|
114
172
|
|
|
115
|
-
When one process needs both,
|
|
173
|
+
When one process needs both, compose them: [composition](/patterns/composition) combines a remote app and a local app into a single tree that dispatches each call to whichever app owns it.
|
|
116
174
|
|
|
117
175
|
</DocsPage>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Subscriptions"
|
|
3
|
-
description: "
|
|
3
|
+
description: "Follow replacement snapshots or individual events with typed read capabilities."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
@@ -9,11 +9,48 @@ export const metadata = docMetadata("/patterns/subscriptions", frontmatter);
|
|
|
9
9
|
|
|
10
10
|
<DocsPage href="/patterns/subscriptions" frontmatter={frontmatter}>
|
|
11
11
|
|
|
12
|
-
A `read` capability can
|
|
12
|
+
A `read` capability can subscribe to changing state or individual events. The operations you define determine its meaning:
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
| Definition | Meaning |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `handler` | One result |
|
|
17
|
+
| `handler` + `subscribe` | One result and a subscription yielding complete replacement snapshots |
|
|
18
|
+
| `subscribe` | Individual events, with no unary operation |
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
## Follow logs and events [#events]
|
|
21
|
+
|
|
22
|
+
Omit `handler` when each value is another event. No dummy unary result or initial event is required, and a stream may complete without yielding anything.
|
|
23
|
+
|
|
24
|
+
```ts title="capabilities.ts"
|
|
25
|
+
import { capability } from "capable-kit";
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
|
|
28
|
+
const runCapability = capability.withContext<RunContext>();
|
|
29
|
+
|
|
30
|
+
export const logs = runCapability({
|
|
31
|
+
id: "runs.logs",
|
|
32
|
+
effect: "read",
|
|
33
|
+
input: z.object({ runId: z.string() }),
|
|
34
|
+
output: z.object({
|
|
35
|
+
at: z.date(),
|
|
36
|
+
level: z.enum(["info", "warn", "error"]),
|
|
37
|
+
message: z.string(),
|
|
38
|
+
}),
|
|
39
|
+
subscribe: ({ input, context, signal }) =>
|
|
40
|
+
context.runs.followLogs(input.runId, { signal }),
|
|
41
|
+
toPresentation: entry => `**${entry.level}** ${entry.message}`,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Without an `output` schema, the event type is inferred from the subscriber's yielded values. With a schema, each yielded value is parsed before delivery; schema transforms also apply before `toPresentation` runs.
|
|
46
|
+
|
|
47
|
+
An event stream can emit a discriminated union, such as `started`, `progress`, and `completed` events from an existing job. For a progress bar that must immediately reflect current state when opened, use replacement snapshots instead.
|
|
48
|
+
|
|
49
|
+
## Follow replacement state [#define]
|
|
50
|
+
|
|
51
|
+
Keep `handler` alongside `subscribe` when each update describes the entire current value. Both operations share one ID, input, output, errors, middleware, and presentation.
|
|
52
|
+
|
|
53
|
+
`watchQuery()` reads a snapshot, then re-reads it whenever an invalidation source signals a change. It pulls the invalidation iterator before reading the first snapshot, so a change that races with the read produces another snapshot instead of being lost.
|
|
17
54
|
|
|
18
55
|
```ts title="capabilities.ts"
|
|
19
56
|
import { capability, watchQuery } from "capable-kit";
|
|
@@ -35,53 +72,63 @@ export const listTodos = todoCapability({
|
|
|
35
72
|
});
|
|
36
73
|
```
|
|
37
74
|
|
|
38
|
-
|
|
75
|
+
The subscriber supplies its own initial snapshot. Subscribing does not invoke the unary handler first. A replacement stream that completes without yielding a snapshot is an error.
|
|
39
76
|
|
|
40
|
-
|
|
41
|
-
subscribe: async function* ({ signal }) {
|
|
42
|
-
while (!signal.aborted) {
|
|
43
|
-
yield { now: new Date().toISOString() };
|
|
44
|
-
await wait(1000, signal);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
```
|
|
77
|
+
Adding a handler to an event-only capability changes its contract to replacement state. Define separate capabilities when you need a snapshot and unrelated events.
|
|
48
78
|
|
|
49
|
-
## Consume
|
|
79
|
+
## Consume a subscription [#consume]
|
|
50
80
|
|
|
51
|
-
`subscribe()` takes a capability
|
|
81
|
+
`subscribe()` takes a capability reference from an app, keeping app navigation free of extra method names. It works against local, remote, composed, and selected apps.
|
|
52
82
|
|
|
53
83
|
```ts title="watch.ts"
|
|
54
84
|
import { subscribe } from "capable-kit";
|
|
55
85
|
|
|
56
|
-
const
|
|
86
|
+
for await (const entry of subscribe(app.runs.logs, { runId }, { signal })) {
|
|
87
|
+
appendLog(entry); // another individual event
|
|
88
|
+
}
|
|
57
89
|
|
|
58
|
-
for await (const todos of
|
|
59
|
-
render(todos); // a complete
|
|
90
|
+
for await (const todos of subscribe(app.todos.list, {}, { signal })) {
|
|
91
|
+
render(todos); // a complete replacement list
|
|
60
92
|
}
|
|
61
93
|
```
|
|
62
94
|
|
|
63
|
-
|
|
95
|
+
Event references have no unary call signature: `app.runs.logs({ runId })` is a type error, and untyped unary calls fail with `METHOD_NOT_ALLOWED`. `app.todos.list()` remains callable.
|
|
64
96
|
|
|
65
|
-
|
|
97
|
+
Input is parsed once. Every emitted item is validated against the output schema, middleware encloses the iterator lifetime, and cancellation aborts the subscriber's signal before cleanup. Sources must observe that signal to release pending work.
|
|
66
98
|
|
|
67
|
-
|
|
99
|
+
## Present each value [#presentation]
|
|
100
|
+
|
|
101
|
+
`toPresentation` describes one validated value. Typed `subscribe()` consumers receive canonical values without materializing presentation. A presentation-aware surface can request canonical values plus their derived presentations.
|
|
102
|
+
|
|
103
|
+
The CLI appends each event's presentation. For replacement subscriptions, it redraws the current snapshot in a terminal and separates snapshots in piped output. An empty presentation falls back to canonical output; it does not hide an event.
|
|
68
104
|
|
|
69
105
|
```sh title="terminal"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
# Events stream automatically; no --watch is needed.
|
|
107
|
+
radar runs logs --run-id run_123
|
|
108
|
+
|
|
109
|
+
# Each canonical event becomes one JSON line; presentation is not generated.
|
|
110
|
+
radar runs logs --run-id run_123 --json
|
|
111
|
+
|
|
112
|
+
# Replacement snapshots still use --watch.
|
|
113
|
+
radar todos list --watch
|
|
75
114
|
```
|
|
76
115
|
|
|
77
|
-
|
|
116
|
+
## Over the wire [#transport]
|
|
117
|
+
|
|
118
|
+
The Capable transport encodes subscriptions as server-sent events at `POST /~capable/subscribe/:id`, using its rich-value codec for events, replacements, and errors.
|
|
119
|
+
|
|
120
|
+
Replacement streams preserve ordinary HTTP errors before the first snapshot; subsequent failures arrive as typed SSE error frames. Event streams establish without waiting for an event. Before committing the response, Capable parses input, resolves context, enters middleware, invokes the subscriber, and verifies its AsyncIterable result. Failures in that preparation retain their HTTP status. An initial SSE comment then flushes the response without creating a canonical event.
|
|
121
|
+
|
|
122
|
+
An async-generator body starts only when its iterator is pulled. Failures, authorization, or listener setup inside that body therefore happen after establishment; failures arrive as typed SSE error frames. Put request rejection in middleware when it must determine the HTTP status. Listener readiness requires an application-level handshake if it must be known before returning the response.
|
|
123
|
+
|
|
124
|
+
Manifest protocol `capable.capabilities.v4` identifies each capability with `execution: "unary"`, `"live"`, or `"events"`. Upgrade clients and servers together and regenerate bundled manifests when migrating from v3. The value codec remains `capable.rich-json.v1`.
|
|
125
|
+
|
|
126
|
+
## Other surfaces and scope [#scope]
|
|
78
127
|
|
|
79
|
-
|
|
128
|
+
[React Query](/surfaces/react-query) and [SWR](/surfaces/swr) expose replacement subscriptions as state updates. Event-only capabilities are excluded from those typed projections and from automatic unary HTTP/OpenAPI, MCP, AI SDK, and Eve tools. Explicit unsupported HTTP or tool metadata is rejected; use `false` to disable that surface. Unary tools can still call a replacement capability's handler.
|
|
80
129
|
|
|
81
|
-
|
|
82
|
-
>
|
|
83
|
-
> Replacement subscriptions are not an event system. There are no patches, no domain events, no buffering, no replay, no resumption, no delivery guarantees, and no reconnection policy. Every item is a complete replacement of the canonical output.
|
|
130
|
+
Subscriptions observe work and require `effect: "read"`. A command that starts work and streams results from that same invocation is outside this API.
|
|
84
131
|
|
|
85
|
-
|
|
132
|
+
Buffering, replay, resumption, delivery guarantees, and reconnection policy remain application responsibilities. Starting a job and then subscribing can miss early events unless the backing service retains them. A pull-based iterator alone does not guarantee lossless capture of a push-based event source.
|
|
86
133
|
|
|
87
134
|
</DocsPage>
|
package/docs/site/quickstart.mdx
CHANGED
|
@@ -44,13 +44,16 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
44
44
|
handler: ({ input }) => ({ id: "1", title: input.title }),
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const definition = defineApp({
|
|
48
48
|
name: "Todos",
|
|
49
49
|
version: "1.0.0",
|
|
50
50
|
capabilities: {
|
|
51
51
|
todos: { list: listTodos, create: createTodo },
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
|
+
|
|
55
|
+
export type AppDefinition = typeof definition;
|
|
56
|
+
export default definition;
|
|
54
57
|
```
|
|
55
58
|
|
|
56
59
|
> This starts with the minimum useful contract. The list Capability declares `effect: "read"` only because HTTP and tool projections need its read-only intent. Add an `output` schema when you need runtime output validation or a portable output contract.
|
|
@@ -65,7 +68,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
65
68
|
◆ Todos 1.0.0
|
|
66
69
|
|
|
67
70
|
Local http://localhost:3000
|
|
68
|
-
Capable
|
|
71
|
+
Capable /~capable
|
|
69
72
|
HTTP /api
|
|
70
73
|
OpenAPI /openapi.json
|
|
71
74
|
MCP /mcp
|
|
@@ -167,18 +170,17 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
167
170
|
|
|
168
171
|
7. ### Call it from another process
|
|
169
172
|
|
|
170
|
-
Swap `createApp()` for `createRemoteApp()` and the calls are identical—only placement changed. The manifest is discovered lazily on first use, and types come from
|
|
173
|
+
Swap `createApp()` for `createRemoteApp()` and the calls are identical—only placement changed. The manifest is discovered lazily on first use, and types come from the named definition type.
|
|
171
174
|
|
|
172
175
|
```ts title="remote.ts"
|
|
173
176
|
import { createRemoteApp } from "capable-kit";
|
|
174
177
|
import { createHttpTransport } from "capable-kit/http";
|
|
175
|
-
import type
|
|
178
|
+
import type { AppDefinition } from "./capable.app";
|
|
176
179
|
|
|
177
180
|
// Same tree, same types, same errors — executed on the server.
|
|
178
|
-
|
|
179
|
-
const app = createRemoteApp<typeof definition>(
|
|
181
|
+
const app = createRemoteApp<AppDefinition>(
|
|
180
182
|
createHttpTransport({
|
|
181
|
-
url: process.env.CAPABLE_URL ?? "http://localhost:3000/
|
|
183
|
+
url: process.env.CAPABLE_URL ?? "http://localhost:3000/~capable/",
|
|
182
184
|
headers: () => ({ authorization: `Bearer ${process.env.TOKEN}` }),
|
|
183
185
|
}),
|
|
184
186
|
);
|
|
@@ -203,7 +205,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
203
205
|
|
|
204
206
|
> **Remote apps are apps**
|
|
205
207
|
>
|
|
206
|
-
> A remote app can be
|
|
208
|
+
> A remote app can be combined with a local one using `composeApps()`, so one command tree can mix capabilities that run on the server with capabilities that must run here. See [Composition](/patterns/composition).
|
|
207
209
|
|
|
208
210
|
8. ### Build for production
|
|
209
211
|
|
|
@@ -254,12 +256,15 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
254
256
|
handler: ({ input }) => ({ id: "1", title: input.title }),
|
|
255
257
|
});
|
|
256
258
|
|
|
257
|
-
|
|
259
|
+
const definition = defineApp({
|
|
258
260
|
name: "Todos",
|
|
259
261
|
capabilities: {
|
|
260
262
|
todos: { list: listTodos, create: createTodo },
|
|
261
263
|
},
|
|
262
264
|
});
|
|
265
|
+
|
|
266
|
+
export type AppDefinition = typeof definition;
|
|
267
|
+
export default definition;
|
|
263
268
|
```
|
|
264
269
|
|
|
265
270
|
> Output types are inferred from handlers. Portable output schemas, effects, descriptions, errors, middleware, and surface metadata are opt-in.
|
|
@@ -308,7 +313,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
308
313
|
// app/api/[[...path]]/route.ts
|
|
309
314
|
export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
|
|
310
315
|
|
|
311
|
-
// app
|
|
316
|
+
// app/~capable/[[...path]]/route.ts
|
|
312
317
|
export { GET, POST } from "@/capable/server";
|
|
313
318
|
```
|
|
314
319
|
|
|
@@ -347,16 +352,16 @@ Capable works two ways: as its own service, or embedded in an app you already ha
|
|
|
347
352
|
|
|
348
353
|
6. ### Call from React Query
|
|
349
354
|
|
|
350
|
-
`capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at
|
|
355
|
+
`capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/~capable`.
|
|
351
356
|
|
|
352
357
|
```ts title="app/query.ts"
|
|
353
358
|
import { createRemoteApp } from "capable-kit";
|
|
354
359
|
import { createHttpTransport } from "capable-kit/http";
|
|
355
360
|
import { createReactQuery } from "capable-kit/react-query";
|
|
356
|
-
import type
|
|
361
|
+
import type { AppDefinition } from "../capable/app";
|
|
357
362
|
|
|
358
|
-
const app = createRemoteApp<
|
|
359
|
-
createHttpTransport({ url: "/
|
|
363
|
+
const app = createRemoteApp<AppDefinition>(
|
|
364
|
+
createHttpTransport({ url: "/~capable/" }),
|
|
360
365
|
);
|
|
361
366
|
|
|
362
367
|
export const query = createReactQuery(app);
|
|
@@ -11,6 +11,14 @@ export const metadata = docMetadata("/reference/packages", frontmatter);
|
|
|
11
11
|
|
|
12
12
|
Entry points are explicit so that a server mount, a UI projection, or an agent integration never gets pulled into an application that does not use it.
|
|
13
13
|
|
|
14
|
+
## Changes and upgrades [#changes]
|
|
15
|
+
|
|
16
|
+
Read the [versioned changelog](https://github.com/vercel-labs/capable/blob/main/packages/capable/CHANGELOG.md)
|
|
17
|
+
for features, fixes, and breaking changes. It also ships at
|
|
18
|
+
`node_modules/capable-kit/CHANGELOG.md`. When upgrading, read the target version’s
|
|
19
|
+
changelog and apply entries after your installed version through your target
|
|
20
|
+
version, oldest first. Repository main may be ahead of your installed version.
|
|
21
|
+
|
|
14
22
|
## The root entry point [#root]
|
|
15
23
|
|
|
16
24
|
`capable-kit` is deliberately limited to authoring and composing apps. Everything you need to define capabilities lives here.
|
|
@@ -26,7 +34,8 @@ import {
|
|
|
26
34
|
watchQuery, // snapshot + invalidation subscriber
|
|
27
35
|
createApp, // definition + context -> callable app
|
|
28
36
|
createRemoteApp, // transport + definition type -> callable app
|
|
29
|
-
|
|
37
|
+
composeApps, // place apps, subtrees, and individual references
|
|
38
|
+
customize, // customize a reference for presentation
|
|
30
39
|
selectApp, // narrow an app
|
|
31
40
|
subscribe, // iterate replacements
|
|
32
41
|
executeCapability, // run one capability without an app
|
|
@@ -39,7 +48,7 @@ import {
|
|
|
39
48
|
| --- | --- |
|
|
40
49
|
| `capable-kit` | Capability authoring, app definitions, executable and remote apps, composition, and the capable command |
|
|
41
50
|
| `capable-kit/server` | `createServer()` plus the `protocol()` and `http()` mounts |
|
|
42
|
-
| `capable-kit/http` | Capable transport
|
|
51
|
+
| `capable-kit/http` | Capable transport and HTTP projection: `createHttpTransport()`, `createHttpHandler()`, `defineProtocolCodec()` |
|
|
43
52
|
| `capable-kit/cli` | `createCli()` |
|
|
44
53
|
| `capable-kit/mcp` | `createMcp()` and the `mcp()` server mount |
|
|
45
54
|
| `capable-kit/eve` | `createEveTools()` |
|
|
@@ -60,14 +69,52 @@ import {
|
|
|
60
69
|
| --- | --- | --- |
|
|
61
70
|
| `capability()` | `capability(config)` | `capability<Context>()` or `capability.withContext<Context>()` binds a context type |
|
|
62
71
|
| `present` | `present.table(), .image(), .file()` | Portable presentation parts for `toPresentation` |
|
|
63
|
-
| `defineApp()` | `defineApp({ name, version, capabilities })` | Immutable definition, no context |
|
|
72
|
+
| `defineApp()` | `defineApp({ name, version, capabilities, middleware, errors })` | Immutable definition, no context |
|
|
64
73
|
| `group()` | `group({ middleware, errors, meta, capabilities })` | Anonymous decorated subtree |
|
|
65
74
|
| `createApp()` | `createApp(definition)` | Callable tree; context options exist only when declared |
|
|
66
|
-
| `createRemoteApp()` | `createRemoteApp<
|
|
67
|
-
| `
|
|
75
|
+
| `createRemoteApp()` | `createRemoteApp<AppDefinition>(transport)` | Lazy, transport-backed remote placement |
|
|
76
|
+
| `composeApps()` | `composeApps(a, { tools: b.plugins })` | Place whole Apps, executable subtrees, or individual references; dispatch by ID |
|
|
77
|
+
| `customize()` | `customize(app.status, { description, meta: { cli: { positional: ["id"] } } })` | Immutable title, description, and CLI/MCP overrides for a composition entry |
|
|
68
78
|
| `selectApp()` | `selectApp(app, { include, exclude })` | Exclude wins over include |
|
|
69
79
|
| `subscribe()` | `subscribe(app.todos.list, input, { signal })` | Async iterator of replacements |
|
|
70
80
|
| `executeCapability()` | `executeCapability(capability, { input, context, signal })` | No app tree, no group behaviour |
|
|
71
81
|
| `createServer()` | `createServer(definition, { context, mounts, middleware })` | Returns `{ fetch }` |
|
|
72
82
|
|
|
83
|
+
## Custom surface display [#custom-display]
|
|
84
|
+
|
|
85
|
+
Custom surfaces can read placement settings without replacing the source
|
|
86
|
+
contract used for execution or policy:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import {
|
|
90
|
+
flattenManifestCapabilities, getAppRuntime, getCapabilityDisplay,
|
|
91
|
+
} from "capable-kit/app";
|
|
92
|
+
|
|
93
|
+
const manifest = await getAppRuntime(app).manifest();
|
|
94
|
+
const help = flattenManifestCapabilities(manifest.capabilities).map(capability => ({
|
|
95
|
+
id: capability.id,
|
|
96
|
+
path: capability.path,
|
|
97
|
+
...getCapabilityDisplay(capability),
|
|
98
|
+
}));
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`getCapabilityDisplay()` returns the effective title, description, and metadata.
|
|
102
|
+
To opt a custom surface into `customize()` metadata, augment the global
|
|
103
|
+
`CapableCustomizationMeta` interface in the surface's types and explicitly read
|
|
104
|
+
that namespace when compiling its display. This registry is separate from the
|
|
105
|
+
open metadata on authored capabilities.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// In a custom surface module:
|
|
109
|
+
declare global {
|
|
110
|
+
interface CapableCustomizationMeta {
|
|
111
|
+
readonly inspector?: { readonly label?: string };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const reference = customize(app.status, {
|
|
116
|
+
meta: { inspector: { label: "Instance status" } },
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
73
120
|
</DocsPage>
|
|
@@ -21,7 +21,12 @@ const deleteTodo = todo({
|
|
|
21
21
|
meta: {
|
|
22
22
|
http: { method: "DELETE", route: "/:todoId", status: 200 },
|
|
23
23
|
cli: { positional: ["todoId"] },
|
|
24
|
-
mcp: {
|
|
24
|
+
mcp: {
|
|
25
|
+
name: "todos_delete",
|
|
26
|
+
idempotentHint: true,
|
|
27
|
+
openWorldHint: false,
|
|
28
|
+
icons: [{ src: "https://example.com/delete.svg" }],
|
|
29
|
+
},
|
|
25
30
|
aiSdk: { name: "todos_delete", strict: true },
|
|
26
31
|
eve: false,
|
|
27
32
|
},
|
|
@@ -43,7 +48,7 @@ const todos = group({
|
|
|
43
48
|
| --- | --- | --- |
|
|
44
49
|
| `http` | `false \| { method, route, status }` | Overrides the derived route. `false` removes the capability from HTTP. `route` may contain `:params` that must exist in the input schema. |
|
|
45
50
|
| `cli` | `false \| { name, command, positional }` | `positional` promotes input fields to arguments, `name` renames the command, `command` replaces the whole path. |
|
|
46
|
-
| `mcp` | `false \| { name }` | Renames the tool. Default is the app path joined with `__`. |
|
|
51
|
+
| `mcp` | `false \| { name, icons, idempotentHint, openWorldHint }` | Renames, decorates, or hides the MCP tool. Default name is the app path joined with `__`; the canonical Capability ID remains available in tool `_meta`. |
|
|
47
52
|
| `eve` | `false \| { name }` | Same, for native in-process Eve tools. |
|
|
48
53
|
| `aiSdk` | `false \| { name, strict }` | Renames, constrains, or hides an AI SDK tool. |
|
|
49
54
|
|
|
@@ -31,7 +31,7 @@ pnpm dev
|
|
|
31
31
|
| Command | Description |
|
|
32
32
|
| --- | --- |
|
|
33
33
|
| `init` | Creates capable.app.ts and a runnable package.json in the current directory or a supplied directory. Existing fields and Capable App entries are never overwritten. |
|
|
34
|
-
| `dev` | Starts a watching development server. Without a capable.server.ts it serves
|
|
34
|
+
| `dev` | Starts a watching development server. Without a capable.server.ts it serves /~capable, /api, /openapi.json, and /mcp, plus a read-only capability index at /. With one, it wraps the authored server and adds only the index. |
|
|
35
35
|
| `build` | Builds the project into `.output`. Presets are Nitro deployment presets, for example `node-server` or `vercel`. |
|
|
36
36
|
| `preview` | Runs a previously built `node-server` output. Other presets do not produce a locally runnable command. |
|
|
37
37
|
| `cli` | Runs the app's derived command tree without writing a CLI entry point. |
|
|
@@ -65,7 +65,7 @@ cap cli --app ./ todos list
|
|
|
65
65
|
cap cli --app https://todos.example.com todos list
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
A local project runs in-process, so no development server is needed. A URL is treated as the root of a Capable server and reached through
|
|
68
|
+
A local project runs in-process, so no development server is needed. A URL is treated as the root of a Capable server and reached through `/~capable/`. Both produce the same commands and help, because both read the same manifest.
|
|
69
69
|
|
|
70
70
|
| Option | Applies to | Meaning |
|
|
71
71
|
| --- | --- | --- |
|
|
@@ -74,10 +74,10 @@ Conversion reads the App manifest rather than the original live schema objects,
|
|
|
74
74
|
import { createRemoteApp } from "capable-kit";
|
|
75
75
|
import { createAiSdkTools } from "capable-kit/ai-sdk";
|
|
76
76
|
import { createHttpTransport } from "capable-kit/http";
|
|
77
|
-
import type
|
|
77
|
+
import type { AppDefinition } from "./capable.app";
|
|
78
78
|
|
|
79
|
-
const app = createRemoteApp<
|
|
80
|
-
createHttpTransport({ url: "https://todos.example.com/
|
|
79
|
+
const app = createRemoteApp<AppDefinition>(
|
|
80
|
+
createHttpTransport({ url: "https://todos.example.com/~capable/" }),
|
|
81
81
|
);
|
|
82
82
|
|
|
83
83
|
export const tools = await createAiSdkTools(app);
|
|
@@ -52,6 +52,39 @@ todo --help
|
|
|
52
52
|
|
|
53
53
|
`run()` resolves to an exit code: `0` on success, `1` for a failed capability, and `2` for a usage error.
|
|
54
54
|
|
|
55
|
+
For a single-operation CLI, map the Capability to an empty command path:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
capability({
|
|
59
|
+
id: "analysis.url",
|
|
60
|
+
input: z.object({ url: z.string() }),
|
|
61
|
+
meta: { cli: { command: [], positional: ["url"] } },
|
|
62
|
+
handler: ({ input }) => analyzeURL(input.url),
|
|
63
|
+
});
|
|
64
|
+
// pnpm cli vercel.com
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Bare invocation and `--help` keep the app name and command listing, with the root
|
|
68
|
+
Capability's arguments and options underneath. `--json`
|
|
69
|
+
or `--watch` selects execution even without positional arguments, applying schema
|
|
70
|
+
defaults or reporting missing required input. Only one Capability may map to the
|
|
71
|
+
root; longer subcommands still take precedence.
|
|
72
|
+
|
|
73
|
+
Pass markdansi's `RenderOptions` directly through `markdown` to customize terminal
|
|
74
|
+
presentations:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
createCli(app, {
|
|
78
|
+
invocationName: "pnpm cli",
|
|
79
|
+
markdown: { codeBox: false, tableBorder: "none", tableDense: true },
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
These options are forwarded unchanged for ordinary and watched presentations in
|
|
84
|
+
a TTY. `markdown.color` and `markdown.width`, when supplied, override the CLI's
|
|
85
|
+
color and columns defaults for presentation rendering. Redirected output remains
|
|
86
|
+
Markdown, and `--json` returns canonical output.
|
|
87
|
+
|
|
55
88
|
## How commands are derived [#mapping]
|
|
56
89
|
|
|
57
90
|
| Authored | Becomes |
|
|
@@ -107,11 +140,11 @@ A remote app produces an identical command tree, because help and arguments are
|
|
|
107
140
|
import { createRemoteApp } from "capable-kit";
|
|
108
141
|
import { createCli } from "capable-kit/cli";
|
|
109
142
|
import { createHttpTransport } from "capable-kit/http";
|
|
110
|
-
import type
|
|
143
|
+
import type { AppDefinition } from "./capable.app";
|
|
111
144
|
|
|
112
|
-
const remote = createRemoteApp<
|
|
145
|
+
const remote = createRemoteApp<AppDefinition>(
|
|
113
146
|
createHttpTransport({
|
|
114
|
-
url: process.env.CAPABLE_URL ?? "http://localhost:3000/
|
|
147
|
+
url: process.env.CAPABLE_URL ?? "http://localhost:3000/~capable/",
|
|
115
148
|
headers: () => ({ authorization: `Bearer ${readToken()}` }),
|
|
116
149
|
}),
|
|
117
150
|
);
|
|
@@ -135,4 +168,15 @@ cap cli --app ./ todos list
|
|
|
135
168
|
cap cli --app https://todos.example.com todos list
|
|
136
169
|
```
|
|
137
170
|
|
|
171
|
+
## Stream events and live state [#subscriptions]
|
|
172
|
+
|
|
173
|
+
A capability with only `subscribe` streams individual events by default. Readable output appends each event's presentation, with canonical output as the fallback. `--json` emits one canonical event per line without generating presentations.
|
|
174
|
+
|
|
175
|
+
```sh title="terminal"
|
|
176
|
+
radar runs logs --run-id run_123
|
|
177
|
+
radar runs logs --run-id run_123 --json
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Capabilities with both `handler` and `subscribe` keep their unary command and use `--watch` for replacement snapshots. See [Subscriptions](/patterns/subscriptions).
|
|
181
|
+
|
|
138
182
|
</DocsPage>
|