capable-kit 0.0.1-alpha.4 → 0.0.1-alpha.6

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.
Files changed (70) hide show
  1. package/dist/ai-sdk.d.mts +2 -2
  2. package/dist/ai-sdk.mjs +1 -1
  3. package/dist/app.d.mts +1 -1
  4. package/dist/app.mjs +1 -1
  5. package/dist/bin.mjs +4 -4
  6. package/dist/cli.d.mts +1 -1
  7. package/dist/cli.mjs +1 -1
  8. package/dist/core.d.mts +3 -3
  9. package/dist/core.mjs +2 -2
  10. package/dist/eve.d.mts +1 -1
  11. package/dist/eve.mjs +1 -1
  12. package/dist/http.d.mts +1 -1
  13. package/dist/http.mjs +1 -1
  14. package/dist/{index-BB5ogMv-.d.mts → index-Be8-UVBC.d.mts} +49 -8
  15. package/dist/{index-DJ--zcWG.d.mts → index-D2CRRUzH.d.mts} +4 -4
  16. package/dist/{index-B_I9n6gN.d.mts → index-Dbc4g9WM.d.mts} +4 -3
  17. package/dist/{index-DCrxWCTv.d.mts → index-DwXlaTXI.d.mts} +3 -3
  18. package/dist/index.d.mts +4 -4
  19. package/dist/index.mjs +3 -3
  20. package/dist/mcp.d.mts +2 -2
  21. package/dist/mcp.mjs +1 -1
  22. package/dist/{mount-BEBJ2Tss.mjs → mount-xvMsjz1B.mjs} +53 -9
  23. package/dist/mount-xvMsjz1B.mjs.map +1 -0
  24. package/dist/runtime-support.d.mts +1 -1
  25. package/dist/runtime-support.mjs +4 -4
  26. package/dist/runtime-support.mjs.map +1 -1
  27. package/dist/server.d.mts +1 -1
  28. package/dist/server.mjs +1 -1
  29. package/dist/{src-D9pLpfeO.mjs → src-BF70JLxI.mjs} +23 -12
  30. package/dist/src-BF70JLxI.mjs.map +1 -0
  31. package/dist/{src-3UaBqI8H.mjs → src-C2MGIlT0.mjs} +17 -18
  32. package/dist/src-C2MGIlT0.mjs.map +1 -0
  33. package/dist/{src-ChDFqZaE.mjs → src-CDxL6w3d.mjs} +3 -3
  34. package/dist/{src-ChDFqZaE.mjs.map → src-CDxL6w3d.mjs.map} +1 -1
  35. package/dist/{src-BjBxOv7x.mjs → src-Db6-XSnU.mjs} +20 -12
  36. package/dist/src-Db6-XSnU.mjs.map +1 -0
  37. package/dist/{src-B53ZbNtC.mjs → src-DdV82An-.mjs} +137 -3
  38. package/dist/src-DdV82An-.mjs.map +1 -0
  39. package/dist/{subscription-McaLyHM2.d.mts → subscription-Bq792Ad2.d.mts} +2 -2
  40. package/docs/CONTEXT.md +8 -3
  41. package/docs/internal/architecture.md +18 -4
  42. package/docs/internal/capability-first-model.md +7 -1
  43. package/docs/internal/implementation-friction.md +68 -7
  44. package/docs/site/capable-orpc-and-trpc.mdx +1 -1
  45. package/docs/site/concepts/architecture.mdx +10 -2
  46. package/docs/site/concepts/capabilities.mdx +6 -6
  47. package/docs/site/concepts/presentations.mdx +161 -0
  48. package/docs/site/hosting/next-js.mdx +1 -1
  49. package/docs/site/introduction.mdx +166 -49
  50. package/docs/site/quickstart.mdx +107 -14
  51. package/docs/site/reference/packages-and-entry-points.mdx +15 -12
  52. package/docs/site/reference/the-cap-cli.mdx +1 -1
  53. package/docs/site/surfaces/cli.mdx +2 -2
  54. package/docs/site/surfaces/http-and-openapi.mdx +1 -1
  55. package/docs/site/surfaces/mcp.mdx +13 -0
  56. package/docs/site/surfaces/react-query.mdx +6 -2
  57. package/docs/site/surfaces/swr.mdx +97 -0
  58. package/docs/site/surfaces.mdx +6 -2
  59. package/package.json +22 -2
  60. package/src/index.test.ts +7 -0
  61. package/src/index.ts +5 -1
  62. package/src/next.ts +1 -0
  63. package/src/package.test.ts +58 -2
  64. package/src/react-query.ts +1 -0
  65. package/src/swr.ts +1 -0
  66. package/dist/mount-BEBJ2Tss.mjs.map +0 -1
  67. package/dist/src-3UaBqI8H.mjs.map +0 -1
  68. package/dist/src-B53ZbNtC.mjs.map +0 -1
  69. package/dist/src-BjBxOv7x.mjs.map +0 -1
  70. package/dist/src-D9pLpfeO.mjs.map +0 -1
@@ -12,7 +12,7 @@ export const metadata = docMetadata("/quickstart", frontmatter);
12
12
 
13
13
  Capable works two ways: as its own service, or embedded in an app you already have. Both start from the same capability. Pick the path that matches your project.
14
14
 
15
- <Tabs id="quickstart-path">
15
+ <Tabs id="quickstart-path" label="Choose a setup path">
16
16
  <Tab label="Standalone service">
17
17
 
18
18
  1. ### Install Capable
@@ -104,7 +104,68 @@ Capable works two ways: as its own service, or embedded in an app you already ha
104
104
  const todos = await app.todos.list({});
105
105
  ```
106
106
 
107
- 6. ### Call it from another process
107
+ 6. ### Hand the same app to a surface
108
+
109
+ A surface is just a function that takes an app. Nothing about the capability changes — `createAiSdkTools()` reads the same tree, the same schemas, and the same `effect` metadata that HTTP and the CLI read, and returns an AI SDK v7 tool set.
110
+
111
+ ```ts title="agent.ts"
112
+ import { generateText, stepCountIs } from "ai";
113
+ import { createApp } from "capable-kit";
114
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
115
+ import definition from "./capable.app";
116
+
117
+ export const app = createApp(definition);
118
+
119
+ // todos.list -> tool "todos__list", todos.create -> tool "todos__create".
120
+ // Input schemas, output schemas, and execution come from the capabilities.
121
+ const tools = await createAiSdkTools(app);
122
+
123
+ const result = await generateText({
124
+ model: "anthropic/claude-sonnet-4.5",
125
+ tools,
126
+ stopWhen: stepCountIs(5),
127
+ prompt: "Add a todo to read the Capable quickstart, then list the todos.",
128
+ });
129
+ ```
130
+
131
+ The model's tool call goes through the same runtime as `app.todos.create(...)`: input validation, middleware, declared errors, output validation. There is no second definition of the capability, and no hand-written tool wrapper to keep in sync.
132
+
133
+ Swapping the surface swaps the projection, not the app. The same `app` value drives an agent running in your process, a terminal command tree, or a React data layer:
134
+
135
+ ```ts title="surfaces.ts"
136
+ import { createCli } from "capable-kit/cli";
137
+ import { createEveTools } from "capable-kit/eve";
138
+ import { createMcp } from "capable-kit/mcp";
139
+ import { always } from "eve/tools/approval";
140
+ import { app } from "./agent";
141
+
142
+ // Durable in-process agent tools, with approvals derived from effect.
143
+ export const eveTools = createEveTools(app, {
144
+ approval: (capability) =>
145
+ capability.effect === "destructive" ? always() : undefined,
146
+ });
147
+
148
+ // The same app as a command tree, or as MCP tools for an external agent.
149
+ await createCli(app).run(process.argv.slice(2));
150
+ const mcpTools = await createMcp(app);
151
+ ```
152
+
153
+ A surface should often see less than the whole app. `selectApp()` narrows the tree before projection, so an agent can be given reads without ever seeing the destructive capabilities.
154
+
155
+ ```ts title="agent-tools.ts"
156
+ import { selectApp } from "capable-kit";
157
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
158
+ import { app } from "./agent";
159
+
160
+ // The model gets todos__list only. todos__create is not projected at all.
161
+ const readOnly = selectApp(app, { include: { todos: { list: true } } });
162
+
163
+ export const tools = await createAiSdkTools(readOnly);
164
+ ```
165
+
166
+ Per-capability metadata renames or hides a capability on one surface without touching the others — `meta.aiSdk.name` sets the tool name, and `meta.aiSdk: false` keeps a capability out of the tool set entirely. See [AI SDK](/surfaces/ai-sdk), [Eve](/surfaces/eve), and the [metadata reference](/reference/metadata).
167
+
168
+ 7. ### Call it from another process
108
169
 
109
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 a type-only import of the definition.
110
171
 
@@ -126,26 +187,25 @@ Capable works two ways: as its own service, or embedded in an app you already ha
126
187
  const todos = await app.todos.list({});
127
188
  ```
128
189
 
129
- Because a surface is just a function that takes an app, the remote app also drives a CLI, MCP, or React Query — pointed at the deployed service instead of this process.
190
+ Every surface from the previous step still applies, because they take an app rather than a server. Point them at the remote app and they run against the deployed service instead of this process.
130
191
 
131
192
  ```ts title="cli.ts"
132
193
  import { createCli } from "capable-kit/cli";
133
- import { createMcp } from "capable-kit/mcp";
194
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
134
195
  import { app } from "./remote";
135
196
 
136
- // Surfaces take an app, not a server. A remote app works everywhere
137
- // a local one does — this CLI runs against the deployed service.
197
+ // Same projection code as the local app — only placement changed.
138
198
  process.exit(await createCli(app).run(process.argv.slice(2)));
139
199
 
140
- // ...or turn the deployed service into agent tools from here.
141
- const tools = await createMcp(app);
200
+ // ...or give a model tools backed by the deployed service.
201
+ const tools = await createAiSdkTools(app);
142
202
  ```
143
203
 
144
204
  > **Remote apps are apps**
145
205
  >
146
206
  > A remote app can be merged with a local one using `mergeApps()`, so one command tree can mix capabilities that run on the server with capabilities that must run here. See [Composition](/patterns/composition).
147
207
 
148
- 7. ### Build for production
208
+ 8. ### Build for production
149
209
 
150
210
  `cap build` emits a standalone server. A preset changes the output target without touching the app definition.
151
211
 
@@ -170,7 +230,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
170
230
 
171
231
  ```sh title="terminal"
172
232
  # inside your existing Next.js app
173
- pnpm add capable-kit zod @capable/next
233
+ pnpm add capable-kit zod
174
234
  ```
175
235
 
176
236
  2. ### Define capabilities
@@ -232,7 +292,7 @@ Capable works two ways: as its own service, or embedded in an app you already ha
232
292
 
233
293
  ```ts title="capable/server.ts"
234
294
  // capable/server.ts
235
- import { createNextRouteHandlers } from "@capable/next";
295
+ import { createNextRouteHandlers } from "capable-kit/next";
236
296
  import { protocol, createServer, http } from "capable-kit/server";
237
297
  import definition from "./app";
238
298
 
@@ -252,14 +312,47 @@ Capable works two ways: as its own service, or embedded in an app you already ha
252
312
  export { GET, POST } from "@/capable/server";
253
313
  ```
254
314
 
255
- 5. ### Call from React Query
315
+ 5. ### Turn the same capabilities into agent tools
316
+
317
+ The capabilities you already call from a server component are also a tool set. In a chat route, project the app with `createAiSdkTools()` and pass it to `streamText()` — the model calls the same handlers your UI does.
318
+
319
+ ```ts title="app/api/chat/route.ts"
320
+ import { convertToModelMessages, streamText, type UIMessage } from "ai";
321
+ import { createApp, selectApp } from "capable-kit";
322
+ import { createAiSdkTools } from "capable-kit/ai-sdk";
323
+ import definition from "../../../capable/app";
324
+
325
+ const app = createApp(definition);
326
+
327
+ // The agent sees a narrowed tree: reads and creates, nothing destructive.
328
+ const agentApp = selectApp(app, {
329
+ include: { todos: { list: true, create: true } },
330
+ });
331
+ const tools = await createAiSdkTools(agentApp);
332
+
333
+ export async function POST(request: Request) {
334
+ const { messages }: { messages: UIMessage[] } = await request.json();
335
+
336
+ const result = streamText({
337
+ model: "anthropic/claude-sonnet-4.5",
338
+ messages: convertToModelMessages(messages),
339
+ tools,
340
+ });
341
+
342
+ return result.toUIMessageStreamResponse();
343
+ }
344
+ ```
345
+
346
+ Nothing was added to the capability to make this work. `todos.create` became the tool `todos__create` because a surface projected it, with the same input schema, middleware, and errors the server component gets.
347
+
348
+ 6. ### Call from React Query
256
349
 
257
- `@capable/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/_capable`.
350
+ `capable-kit/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/_capable`.
258
351
 
259
352
  ```ts title="app/query.ts"
260
353
  import { createRemoteApp } from "capable-kit";
261
354
  import { createHttpTransport } from "capable-kit/http";
262
- import { createReactQuery } from "@capable/react-query";
355
+ import { createReactQuery } from "capable-kit/react-query";
263
356
  import type definition from "../capable/app";
264
357
 
265
358
  const app = createRemoteApp<typeof definition>(
@@ -13,7 +13,7 @@ Entry points are explicit so that a server mount, a UI projection, or an agent i
13
13
 
14
14
  ## The root entry point [#root]
15
15
 
16
- `capable` is deliberately limited to authoring and composing apps. Everything you need to define capabilities lives here.
16
+ `capable-kit` is deliberately limited to authoring and composing apps. Everything you need to define capabilities lives here.
17
17
 
18
18
  ```ts title="import"
19
19
  import {
@@ -22,6 +22,7 @@ import {
22
22
  group, // decorated subtree
23
23
  capability, // author a capability
24
24
  md, // markdown template tag
25
+ present, // table, image, and file builders
25
26
  watchQuery, // snapshot + invalidation subscriber
26
27
  createApp, // definition + context -> callable app
27
28
  createRemoteApp, // transport + definition type -> callable app
@@ -36,17 +37,18 @@ import {
36
37
 
37
38
  | Import | Contains |
38
39
  | --- | --- |
39
- | `capable` | Capability authoring, app definitions, executable and remote apps, composition, and the capable command |
40
- | `capable/server` | `createServer()` plus the `protocol()` and `http()` mounts |
41
- | `capable/http` | Capable transport client and server encoding: `createHttpTransport()`, `createHttpHandler()` |
42
- | `capable/cli` | `createCli()` |
43
- | `capable/mcp` | `createMcp()` and the `mcp()` server mount |
44
- | `capable/eve` | `createEveTools()` |
45
- | `capable/ai-sdk` | `createAiSdkTools()` |
46
- | `capable/app` | App runtime internals: manifests, transport types, selection |
47
- | `capable/core` | Execution and schema primitives for building your own surface |
48
- | `@capable/react-query` | `createReactQuery()` |
49
- | `@capable/next` | `createNextRouteHandlers()` |
40
+ | `capable-kit` | Capability authoring, app definitions, executable and remote apps, composition, and the capable command |
41
+ | `capable-kit/server` | `createServer()` plus the `protocol()` and `http()` mounts |
42
+ | `capable-kit/http` | Capable transport client and server encoding: `createHttpTransport()`, `createHttpHandler()` |
43
+ | `capable-kit/cli` | `createCli()` |
44
+ | `capable-kit/mcp` | `createMcp()` and the `mcp()` server mount |
45
+ | `capable-kit/eve` | `createEveTools()` |
46
+ | `capable-kit/ai-sdk` | `createAiSdkTools()` |
47
+ | `capable-kit/app` | App runtime internals: manifests, transport types, selection |
48
+ | `capable-kit/core` | Execution and schema primitives for building your own surface |
49
+ | `capable-kit/react-query` | `createReactQuery()` |
50
+ | `capable-kit/swr` | `createSWR()` |
51
+ | `capable-kit/next` | `createNextRouteHandlers()` |
50
52
 
51
53
  > **Dependency direction**
52
54
  >
@@ -57,6 +59,7 @@ import {
57
59
  | Function | Signature | Notes |
58
60
  | --- | --- | --- |
59
61
  | `capability()` | `capability(config)` | `capability<Context>()` or `capability.withContext<Context>()` binds a context type |
62
+ | `present` | `present.table(), .image(), .file()` | Portable presentation parts for `toPresentation` |
60
63
  | `defineApp()` | `defineApp({ name, version, capabilities })` | Immutable definition, no context |
61
64
  | `group()` | `group({ middleware, errors, meta, capabilities })` | Anonymous decorated subtree |
62
65
  | `createApp()` | `createApp(definition)` | Callable tree; context options exist only when declared |
@@ -70,7 +70,7 @@ A local project runs in-process, so no development server is needed. A URL is tr
70
70
  | Option | Applies to | Meaning |
71
71
  | --- | --- | --- |
72
72
  | `--app` | `cli` | Project path or server URL |
73
- | `--json` | Any capability | Print canonical JSON instead of the Markdown rendering |
73
+ | `--json` | Any capability | Print canonical JSON without computing the presentation |
74
74
  | `--watch` | Subscribable read capabilities | Follow replacements, redrawing in place in a TTY |
75
75
  | `--help` | Any command | Help for the root, a group, or one capability |
76
76
 
@@ -61,7 +61,7 @@ todo --help
61
61
  | Field listed in `cli.positional` | `<title>` |
62
62
  | Boolean field `notify` | `--notify` |
63
63
  | `title` and `description` | Help text for the command |
64
- | `toMarkdown` | Default terminal output |
64
+ | `toPresentation` | Default terminal output |
65
65
 
66
66
  ```sh title="terminal"
67
67
  todo --help
@@ -71,7 +71,7 @@ todo todos create --help
71
71
  # Positional argument plus flags
72
72
  todo todos create "Read the docs" --due 2025-01-31
73
73
 
74
- # Canonical JSON instead of the Markdown rendering
74
+ # Canonical JSON instead of the presentation
75
75
  todo todos list --json
76
76
 
77
77
  # Follow a subscribable read capability
@@ -101,7 +101,7 @@ Declared errors are serialized with their code, message, status, and validated d
101
101
  }
102
102
  ```
103
103
 
104
- If a capability defines `toMarkdown`, requesting `text/markdown` returns that rendering of the same canonical output.
104
+ If a capability defines `toPresentation`, requesting `text/markdown` returns a Markdown lowering of the same canonical output. Markdown and tables are rendered directly, images become labeled placeholders, and files become links.
105
105
 
106
106
  ```sh title="terminal"
107
107
  curl http://localhost:3000/api/todos/list \
@@ -64,6 +64,19 @@ const getTodo = todo({
64
64
  >
65
65
  > An agent chooses tools by reading them. A precise `description` is as load-bearing as the input schema, and it is written once for every surface instead of separately for each one.
66
66
 
67
+ ## Rich tool results [#presentation]
68
+
69
+ MCP requests a capability's optional `toPresentation` result and lowers the portable parts into native content. The capability does not author MCP content blocks directly.
70
+
71
+ | Presentation part | MCP result |
72
+ | --- | --- |
73
+ | Markdown | Text content |
74
+ | Table | Markdown table as text content |
75
+ | Image | Alt text followed by image content |
76
+ | File | Resource link with its name and metadata |
77
+
78
+ The canonical output remains available as the tool's structured content. This lets an agent inspect exact data while a client displays the richer view. See [Presentations](/concepts/presentations) for the surface-neutral API.
79
+
67
80
  ## Expose less than everything [#scope]
68
81
 
69
82
  Most apps should not offer their whole tree to an agent. Set `meta.mcp: false` on the capabilities that are never tools, and narrow a projected app with `selectApp()`.
@@ -9,16 +9,20 @@ export const metadata = docMetadata("/surfaces/react-query", frontmatter);
9
9
 
10
10
  <DocsPage href="/surfaces/react-query" frontmatter={frontmatter}>
11
11
 
12
- `@capable/react-query` mirrors the app tree into TanStack Query primitives. Keys, query functions, and mutation functions are derived, so components stop repeating endpoint names and cache keys.
12
+ `capable-kit/react-query` mirrors the app tree into TanStack Query primitives. Keys, query functions, and mutation functions are derived, so components stop repeating endpoint names and cache keys.
13
13
 
14
14
  ## Create the client [#create]
15
15
 
16
16
  Point it at any app. In the browser this is usually a remote app over the Capable transport; on the server it can be a local app. Both App creation and the React Query projection are synchronous. Manifest discovery is deferred until a query actually executes.
17
17
 
18
+ ```sh title="terminal"
19
+ pnpm add capable-kit @tanstack/react-query
20
+ ```
21
+
18
22
  ```ts title="query.ts"
19
23
  import { createRemoteApp } from "capable-kit";
20
24
  import { createHttpTransport } from "capable-kit/http";
21
- import { createReactQuery } from "@capable/react-query";
25
+ import { createReactQuery } from "capable-kit/react-query";
22
26
  import type definition from "../capable.app";
23
27
 
24
28
  const app = createRemoteApp<typeof definition>(
@@ -0,0 +1,97 @@
1
+ ---
2
+ title: "SWR"
3
+ description: "Derive typed keys and hook arguments for SWR."
4
+ ---
5
+
6
+ import { DocsPage, docMetadata } from "../../_components/docs-page";
7
+
8
+ export const metadata = docMetadata("/surfaces/swr", frontmatter);
9
+
10
+ <DocsPage href="/surfaces/swr" frontmatter={frontmatter}>
11
+
12
+ `capable-kit/swr` mirrors the app tree into SWR keys, fetchers, mutation fetchers,
13
+ and subscribers. Components keep using SWR's hooks and configuration directly,
14
+ without repeating Capability paths or input types.
15
+
16
+ ## Create the projection [#create]
17
+
18
+ Point it at a local or remote App. Manifest discovery remains lazy and starts
19
+ only when SWR calls a generated fetcher.
20
+
21
+ ```sh title="terminal"
22
+ pnpm add capable-kit swr
23
+ ```
24
+
25
+ ```ts title="swr.ts"
26
+ import { createRemoteApp } from "capable-kit";
27
+ import { createHttpTransport } from "capable-kit/http";
28
+ import { createSWR } from "capable-kit/swr";
29
+ import type definition from "../capable.app";
30
+
31
+ const app = createRemoteApp<typeof definition>(
32
+ createHttpTransport({ url: "/_capable/" }),
33
+ );
34
+
35
+ export const capableSWR = createSWR(app);
36
+ ```
37
+
38
+ ## Use it in components [#use]
39
+
40
+ Each operation returns the arguments for its corresponding SWR hook, so the
41
+ generated types flow through a normal spread call.
42
+
43
+ ```tsx title="todo-list.tsx"
44
+ import useSWR, { useSWRConfig } from "swr";
45
+ import useSWRMutation from "swr/mutation";
46
+ import { capableSWR } from "./swr";
47
+
48
+ export function TodoList() {
49
+ const { mutate } = useSWRConfig();
50
+ const todos = useSWR(...capableSWR.todos.list.swr({}));
51
+ const createTodo = useSWRMutation(
52
+ ...capableSWR.todos.create.mutation({
53
+ onSuccess: () => mutate(capableSWR.todos.list.key()),
54
+ }),
55
+ );
56
+
57
+ if (todos.isLoading) return <Spinner />;
58
+ if (todos.error) return <Error error={todos.error} />;
59
+
60
+ return (
61
+ <>
62
+ <ul>{todos.data?.map((todo) => <li key={todo.id}>{todo.title}</li>)}</ul>
63
+ <button onClick={() => createTodo.trigger({ title: "New" })}>Add</button>
64
+ </>
65
+ );
66
+ }
67
+ ```
68
+
69
+ | Method | Returns |
70
+ | --- | --- |
71
+ | `key(input?)` | `["capable", ...path, input?]`, for cache access and revalidation |
72
+ | `swr(input, options?)` | Typed arguments for `useSWR` |
73
+ | `mutation(options?)` | Typed arguments for `useSWRMutation`; `trigger` takes the Capability input |
74
+ | `subscription(input, options?)` | Typed arguments for `useSWRSubscription`, only on subscribable Capabilities |
75
+
76
+ Pass `keyPrefix` to `createSWR()` if the `capable` prefix collides with existing
77
+ keys.
78
+
79
+ ## Subscriptions [#subscriptions]
80
+
81
+ When a Capability defines [subscribe](/patterns/subscriptions), the projection
82
+ adds `subscription()`. Unmounting aborts the Capability subscription.
83
+
84
+ ```tsx title="live-todos.tsx"
85
+ import useSWRSubscription from "swr/subscription";
86
+ import { capableSWR } from "./swr";
87
+
88
+ const todos = useSWRSubscription(
89
+ ...capableSWR.todos.list.subscription({}),
90
+ );
91
+ ```
92
+
93
+ > SWR does not provide an `AbortSignal` to unary fetchers, so unary Capability
94
+ > calls cannot be cancelled by hook disposal. Subscription cleanup is wired to
95
+ > an `AbortController`.
96
+
97
+ </DocsPage>
@@ -36,12 +36,14 @@ A projection needs no server at all. It takes an executable app and returns comm
36
36
  import { createCli } from "capable-kit/cli";
37
37
  import { createAiSdkTools } from "capable-kit/ai-sdk";
38
38
  import { createEveTools } from "capable-kit/eve";
39
- import { createReactQuery } from "@capable/react-query";
39
+ import { createReactQuery } from "capable-kit/react-query";
40
+ import { createSWR } from "capable-kit/swr";
40
41
 
41
42
  createCli(app); // process-level command tree
42
43
  await createAiSdkTools(app); // typed AI SDK tools
43
44
  createEveTools(app); // durable in-process agent tools
44
45
  createReactQuery(app); // query keys and options for a UI
46
+ createSWR(app); // SWR keys and hook arguments for a UI
45
47
  ```
46
48
 
47
49
  ## Choosing surfaces [#choose]
@@ -55,7 +57,8 @@ createReactQuery(app); // query keys and options for a UI
55
57
  | [MCP](/surfaces/mcp) | External agents connect over the network | `capable/mcp` |
56
58
  | [Eve](/surfaces/eve) | An agent runs in your process | `capable/eve` |
57
59
  | [AI SDK](/surfaces/ai-sdk) | An AI SDK model or agent calls your app | `capable/ai-sdk` |
58
- | [React Query](/surfaces/react-query) | A React UI reads and mutates the app | `@capable/react-query` |
60
+ | [React Query](/surfaces/react-query) | A React UI reads and mutates the app | `capable-kit/react-query` |
61
+ | [SWR](/surfaces/swr) | A React UI reads, mutates, and subscribes with SWR | `capable-kit/swr` |
59
62
 
60
63
  > **Nothing is implicit**
61
64
  >
@@ -74,5 +77,6 @@ createReactQuery(app); // query keys and options for a UI
74
77
  - [**AI SDK**](/surfaces/ai-sdk) — Typed tools for generateText, streamText, and agents.
75
78
  - [**Eve**](/surfaces/eve) — Native in-process tools with approvals.
76
79
  - [**React Query**](/surfaces/react-query) — Query keys, mutations, and live queries.
80
+ - [**SWR**](/surfaces/swr) — Keys and arguments for queries, mutations, and subscriptions.
77
81
 
78
82
  </DocsPage>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capable-kit",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "cap": "dist/bin.mjs",
@@ -39,9 +39,21 @@
39
39
  "types": "./dist/mcp.d.mts",
40
40
  "import": "./dist/mcp.mjs"
41
41
  },
42
+ "./next": {
43
+ "types": "./dist/next.d.mts",
44
+ "import": "./dist/next.mjs"
45
+ },
46
+ "./react-query": {
47
+ "types": "./dist/react-query.d.mts",
48
+ "import": "./dist/react-query.mjs"
49
+ },
42
50
  "./server": {
43
51
  "types": "./dist/server.d.mts",
44
52
  "import": "./dist/server.mjs"
53
+ },
54
+ "./swr": {
55
+ "types": "./dist/swr.d.mts",
56
+ "import": "./dist/swr.mjs"
45
57
  }
46
58
  },
47
59
  "files": [
@@ -73,15 +85,23 @@
73
85
  "nitro": "3.0.260610-beta"
74
86
  },
75
87
  "peerDependencies": {
88
+ "@tanstack/react-query": ">=5.80.2 <6",
76
89
  "ai": "^7.0.0",
77
- "eve": ">=0.27.1"
90
+ "eve": ">=0.27.1",
91
+ "swr": ">=2.3.0 <3"
78
92
  },
79
93
  "peerDependenciesMeta": {
94
+ "@tanstack/react-query": {
95
+ "optional": true
96
+ },
80
97
  "ai": {
81
98
  "optional": true
82
99
  },
83
100
  "eve": {
84
101
  "optional": true
102
+ },
103
+ "swr": {
104
+ "optional": true
85
105
  }
86
106
  }
87
107
  }
package/src/index.test.ts CHANGED
@@ -7,7 +7,10 @@ import { executeCapability } from "./core.ts";
7
7
  import { createEveTools } from "./eve.ts";
8
8
  import { createHttpHandler, createHttpTransport } from "./http.ts";
9
9
  import { createMcp, mcp } from "./mcp.ts";
10
+ import { createNextRouteHandlers } from "./next.ts";
11
+ import { createReactQuery } from "./react-query.ts";
10
12
  import { createServer } from "./server.ts";
13
+ import { createSWR } from "./swr.ts";
11
14
 
12
15
  describe("capable public entry points", () => {
13
16
  test("ships cap as the primary command with the capable alias", async () => {
@@ -34,6 +37,7 @@ describe("capable public entry points", () => {
34
37
  "group",
35
38
  "md",
36
39
  "mergeApps",
40
+ "present",
37
41
  "selectApp",
38
42
  "subscribe",
39
43
  "watchQuery",
@@ -48,8 +52,11 @@ describe("capable public entry points", () => {
48
52
  createEveTools,
49
53
  createHttpHandler,
50
54
  createMcp,
55
+ createNextRouteHandlers,
56
+ createReactQuery,
51
57
  mcp,
52
58
  createServer,
59
+ createSWR,
53
60
  createHttpTransport,
54
61
  ].every((value) => typeof value === "function")).toBe(true);
55
62
  });
package/src/index.ts CHANGED
@@ -4,13 +4,17 @@ export {
4
4
  executeCapability,
5
5
  group,
6
6
  md,
7
+ present,
7
8
  capability,
8
9
  watchQuery,
9
10
  type AppContext,
10
11
  type AppDefinition,
11
12
  type DefinedErrors,
12
13
  type ExecuteCapabilityOptions,
13
- type MarkdownRenderer,
14
+ type PresentationPart,
15
+ type PresentationRenderer,
16
+ type PresentationTableCell,
17
+ type PresentationValue,
14
18
  type CapabilityDefinition,
15
19
  type CapabilityContext,
16
20
  type CapabilityEffect,
package/src/next.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@capable/next";
@@ -1,5 +1,11 @@
1
1
  import { execFileSync } from "node:child_process";
2
- import { existsSync, mkdtempSync, rmSync } from "node:fs";
2
+ import {
3
+ existsSync,
4
+ mkdtempSync,
5
+ readdirSync,
6
+ readFileSync,
7
+ rmSync,
8
+ } from "node:fs";
3
9
  import { tmpdir } from "node:os";
4
10
  import { join } from "node:path";
5
11
  import { fileURLToPath } from "node:url";
@@ -39,6 +45,11 @@ describe("published package", () => {
39
45
  ),
40
46
  ) as {
41
47
  readonly directories?: { readonly doc?: string };
48
+ readonly exports?: Readonly<Record<string, unknown>>;
49
+ readonly peerDependenciesMeta?: Readonly<Record<
50
+ string,
51
+ { readonly optional?: boolean }
52
+ >>;
42
53
  readonly scripts?: Record<string, string>;
43
54
  };
44
55
  const quickstart = execFileSync(
@@ -66,8 +77,10 @@ describe("published package", () => {
66
77
  (path) =>
67
78
  path.startsWith("docs/site/") && path.endsWith(".mdx"),
68
79
  ),
69
- ).toHaveLength(25);
80
+ ).toHaveLength(27);
70
81
  expect(paths).toContain("docs/site/introduction.mdx");
82
+ expect(paths).toContain("docs/site/concepts/presentations.mdx");
83
+ expect(paths).toContain("docs/site/surfaces/swr.mdx");
71
84
  expect(
72
85
  [...paths].some(
73
86
  (path) =>
@@ -85,6 +98,24 @@ describe("published package", () => {
85
98
  expect(manifest.directories?.doc).toBe("./docs");
86
99
  expect(manifest.scripts?.prepack).toBeUndefined();
87
100
  expect(manifest.scripts?.postpack).toBeUndefined();
101
+ expect(Object.keys(manifest.exports ?? {})).toEqual([
102
+ ".",
103
+ "./ai-sdk",
104
+ "./app",
105
+ "./cli",
106
+ "./core",
107
+ "./eve",
108
+ "./http",
109
+ "./mcp",
110
+ "./next",
111
+ "./react-query",
112
+ "./server",
113
+ "./swr",
114
+ ]);
115
+ expect(manifest.peerDependenciesMeta).toMatchObject({
116
+ "@tanstack/react-query": { optional: true },
117
+ swr: { optional: true },
118
+ });
88
119
  expect(quickstart).toMatch(
89
120
  /^---\ntitle: "Quickstart"\ndescription: ".+"\n---/,
90
121
  );
@@ -98,4 +129,29 @@ describe("published package", () => {
98
129
  });
99
130
  }
100
131
  });
132
+
133
+ test("keeps scoped workspace packages private", () => {
134
+ const packagesDirectory = new URL("../../", import.meta.url);
135
+
136
+ for (const entry of readdirSync(packagesDirectory, {
137
+ withFileTypes: true,
138
+ })) {
139
+ if (!entry.isDirectory()) continue;
140
+ const manifestPath = new URL(
141
+ `./${entry.name}/package.json`,
142
+ packagesDirectory,
143
+ );
144
+ if (!existsSync(manifestPath)) continue;
145
+
146
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as {
147
+ readonly name?: string;
148
+ readonly private?: boolean;
149
+ readonly publishConfig?: unknown;
150
+ };
151
+ if (!manifest.name?.startsWith("@capable/")) continue;
152
+
153
+ expect(manifest.private, manifest.name).toBe(true);
154
+ expect(manifest.publishConfig, manifest.name).toBeUndefined();
155
+ }
156
+ });
101
157
  });
@@ -0,0 +1 @@
1
+ export * from "@capable/react-query";
package/src/swr.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@capable/swr";