capable-kit 0.0.1-alpha.2 → 0.0.1-alpha.4
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/README.md +37 -3
- package/dist/ai-sdk.d.mts +1 -1
- package/dist/app.d.mts +1 -1
- package/dist/bin.mjs +189 -27
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/eve.d.mts +3 -3
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-BxJhwhKm.d.mts → index-B_I9n6gN.d.mts} +4 -5
- package/dist/{index-Dp-D73pf.d.mts → index-DCrxWCTv.d.mts} +3 -3
- package/dist/{index-CThfifn8.d.mts → index-DJ--zcWG.d.mts} +5 -5
- package/dist/index.d.mts +1 -1
- package/dist/mcp.d.mts +2 -2
- package/dist/mcp.mjs +1 -1
- package/dist/{mount--YHrgRHJ.mjs → mount-BEBJ2Tss.mjs} +13 -19
- package/dist/mount-BEBJ2Tss.mjs.map +1 -0
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +18 -6
- package/dist/runtime-support.mjs.map +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.mjs +2 -2
- package/dist/src-3UaBqI8H.mjs.map +1 -1
- package/dist/src-B53ZbNtC.mjs.map +1 -1
- package/dist/src-BjBxOv7x.mjs.map +1 -1
- package/dist/{src-DpSA-hBO.mjs → src-ChDFqZaE.mjs} +6 -6
- package/dist/{src-DpSA-hBO.mjs.map → src-ChDFqZaE.mjs.map} +1 -1
- package/dist/{src-XRJ9hgYX.mjs → src-D9pLpfeO.mjs} +19 -3
- package/dist/src-D9pLpfeO.mjs.map +1 -0
- package/docs/CONTEXT.md +108 -0
- package/docs/README.md +28 -0
- package/docs/internal/README.md +16 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +24 -0
- package/docs/internal/architecture.md +126 -0
- package/docs/internal/capability-first-model.md +154 -0
- package/docs/internal/implementation-friction.md +674 -0
- package/docs/internal/why-capable.md +94 -0
- package/docs/site/capable-orpc-and-trpc.mdx +133 -0
- package/docs/site/concepts/apps.mdx +217 -0
- package/docs/site/concepts/architecture.mdx +75 -0
- package/docs/site/concepts/capabilities.mdx +249 -0
- package/docs/site/concepts/errors.mdx +93 -0
- package/docs/site/hosting/any-fetch-host.mdx +74 -0
- package/docs/site/hosting/next-js.mdx +77 -0
- package/docs/site/hosting/standalone-server.mdx +94 -0
- package/docs/site/introduction.mdx +142 -0
- package/docs/site/patterns/composition.mdx +142 -0
- package/docs/site/patterns/remote-apps.mdx +117 -0
- package/docs/site/patterns/subscriptions.mdx +87 -0
- package/docs/site/quickstart.mdx +293 -0
- package/docs/site/reference/packages-and-entry-points.mdx +70 -0
- package/docs/site/reference/surface-metadata.mdx +84 -0
- package/docs/site/reference/the-cap-cli.mdx +81 -0
- package/docs/site/surfaces/ai-sdk.mdx +94 -0
- package/docs/site/surfaces/cli.mdx +138 -0
- package/docs/site/surfaces/eve.mdx +121 -0
- package/docs/site/surfaces/http-and-openapi.mdx +111 -0
- package/docs/site/surfaces/mcp.mdx +97 -0
- package/docs/site/surfaces/react-query.mdx +80 -0
- package/docs/site/surfaces/typescript.mdx +123 -0
- package/docs/site/surfaces.mdx +78 -0
- package/docs/site/why-capable.mdx +99 -0
- package/package.json +13 -3
- package/src/package.test.ts +101 -0
- package/dist/mount--YHrgRHJ.mjs.map +0 -1
- package/dist/src-XRJ9hgYX.mjs.map +0 -1
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Quickstart"
|
|
3
|
+
description: "Install Capable, write one capability, run it locally, and deploy it."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../_components/docs-page";
|
|
7
|
+
import { Tab, Tabs } from "../_components/tabs";
|
|
8
|
+
|
|
9
|
+
export const metadata = docMetadata("/quickstart", frontmatter);
|
|
10
|
+
|
|
11
|
+
<DocsPage href="/quickstart" frontmatter={frontmatter}>
|
|
12
|
+
|
|
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
|
+
|
|
15
|
+
<Tabs id="quickstart-path">
|
|
16
|
+
<Tab label="Standalone service">
|
|
17
|
+
|
|
18
|
+
1. ### Install Capable
|
|
19
|
+
|
|
20
|
+
The `capable` package includes the runtime and the `capable` command for development, builds, and derived CLI access. Zod is the schema authoring library in this example; Capable consumes its Standard Schema and Standard JSON Schema interfaces.
|
|
21
|
+
|
|
22
|
+
```sh title="terminal"
|
|
23
|
+
pnpm add capable-kit zod
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. ### Create capable.app.ts
|
|
27
|
+
|
|
28
|
+
The toolchain discovers `capable.app.ts` in the project root. Export an app definition as the default export.
|
|
29
|
+
|
|
30
|
+
```ts title="capable.app.ts"
|
|
31
|
+
import { defineApp, capability } from "capable-kit";
|
|
32
|
+
import { z } from "zod";
|
|
33
|
+
|
|
34
|
+
const listTodos = capability({
|
|
35
|
+
id: "todos.list",
|
|
36
|
+
// Opt in to GET and read-only tool hints.
|
|
37
|
+
effect: "read",
|
|
38
|
+
handler: () => [{ id: "1", title: "Read the docs" }],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const createTodo = capability({
|
|
42
|
+
id: "todos.create",
|
|
43
|
+
input: z.object({ title: z.string().min(1) }),
|
|
44
|
+
handler: ({ input }) => ({ id: "1", title: input.title }),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export default defineApp({
|
|
48
|
+
name: "Todos",
|
|
49
|
+
version: "1.0.0",
|
|
50
|
+
capabilities: {
|
|
51
|
+
todos: { list: listTodos, create: createTodo },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> 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.
|
|
57
|
+
|
|
58
|
+
3. ### Start the dev server
|
|
59
|
+
|
|
60
|
+
`cap dev` watches the dependency graph, validates the manifest, and serves every derived surface. The root is a development-only index of the capabilities.
|
|
61
|
+
|
|
62
|
+
```sh title="terminal"
|
|
63
|
+
$ cap dev
|
|
64
|
+
|
|
65
|
+
◆ Todos 1.0.0
|
|
66
|
+
|
|
67
|
+
Local http://localhost:3000
|
|
68
|
+
Capable /_capable
|
|
69
|
+
HTTP /api
|
|
70
|
+
OpenAPI /openapi.json
|
|
71
|
+
MCP /mcp
|
|
72
|
+
|
|
73
|
+
✓ 2 capabilities ready, watching for changes
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
4. ### Call the capabilities
|
|
77
|
+
|
|
78
|
+
The CLI reads the same tree, so `todos.create` becomes `todos create`. The HTTP routes default to the app path, and `effect: "read"` makes `todos.list` a `GET`. Everything else is a `POST`.
|
|
79
|
+
|
|
80
|
+
```sh title="terminal"
|
|
81
|
+
# The capabilities as commands
|
|
82
|
+
cap cli todos create "Read the quickstart"
|
|
83
|
+
cap cli todos list
|
|
84
|
+
|
|
85
|
+
# The same capabilities as derived HTTP routes
|
|
86
|
+
curl http://localhost:3000/api/todos/list
|
|
87
|
+
curl -X POST http://localhost:3000/api/todos/create \
|
|
88
|
+
-H 'content-type: application/json' \
|
|
89
|
+
-d '{"title":"Read the quickstart"}'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
5. ### Call it in-process
|
|
93
|
+
|
|
94
|
+
The app is an ordinary typed object. `createApp()` executes capabilities in this process — useful from a script, a job, or a test — with the same validation, middleware, and errors the HTTP routes get.
|
|
95
|
+
|
|
96
|
+
```ts title="script.ts"
|
|
97
|
+
import { createApp } from "capable-kit";
|
|
98
|
+
import definition from "./capable.app";
|
|
99
|
+
|
|
100
|
+
// In-process execution: no server, no network.
|
|
101
|
+
const app = createApp(definition);
|
|
102
|
+
|
|
103
|
+
const todo = await app.todos.create({ title: "Read the quickstart" });
|
|
104
|
+
const todos = await app.todos.list({});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
6. ### Call it from another process
|
|
108
|
+
|
|
109
|
+
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
|
+
|
|
111
|
+
```ts title="remote.ts"
|
|
112
|
+
import { createRemoteApp } from "capable-kit";
|
|
113
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
114
|
+
import type definition from "./capable.app";
|
|
115
|
+
|
|
116
|
+
// Same tree, same types, same errors — executed on the server.
|
|
117
|
+
// "typeof definition" is a type-only import, so no client is generated.
|
|
118
|
+
const app = createRemoteApp<typeof definition>(
|
|
119
|
+
createHttpTransport({
|
|
120
|
+
url: process.env.CAPABLE_URL ?? "http://localhost:3000/_capable/",
|
|
121
|
+
headers: () => ({ authorization: `Bearer ${process.env.TOKEN}` }),
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const todo = await app.todos.create({ title: "Read the quickstart" });
|
|
126
|
+
const todos = await app.todos.list({});
|
|
127
|
+
```
|
|
128
|
+
|
|
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.
|
|
130
|
+
|
|
131
|
+
```ts title="cli.ts"
|
|
132
|
+
import { createCli } from "capable-kit/cli";
|
|
133
|
+
import { createMcp } from "capable-kit/mcp";
|
|
134
|
+
import { app } from "./remote";
|
|
135
|
+
|
|
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.
|
|
138
|
+
process.exit(await createCli(app).run(process.argv.slice(2)));
|
|
139
|
+
|
|
140
|
+
// ...or turn the deployed service into agent tools from here.
|
|
141
|
+
const tools = await createMcp(app);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
> **Remote apps are apps**
|
|
145
|
+
>
|
|
146
|
+
> 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
|
+
|
|
148
|
+
7. ### Build for production
|
|
149
|
+
|
|
150
|
+
`cap build` emits a standalone server. A preset changes the output target without touching the app definition.
|
|
151
|
+
|
|
152
|
+
```sh title="terminal"
|
|
153
|
+
# Build a standalone Node server
|
|
154
|
+
cap build
|
|
155
|
+
|
|
156
|
+
# ...or Vercel Build Output
|
|
157
|
+
cap build --preset vercel
|
|
158
|
+
vercel deploy --prebuilt
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Run `cap preview` to serve a `node-server` build locally before shipping it.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
</Tab>
|
|
165
|
+
<Tab label="In your Next.js app">
|
|
166
|
+
|
|
167
|
+
1. ### Install Capable
|
|
168
|
+
|
|
169
|
+
Add Capable to your existing Next.js app. No toolchain needed — you keep your own dev server and deployment. Zod is only the Standard Schema provider used by this example.
|
|
170
|
+
|
|
171
|
+
```sh title="terminal"
|
|
172
|
+
# inside your existing Next.js app
|
|
173
|
+
pnpm add capable-kit zod @capable/next
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
2. ### Define capabilities
|
|
177
|
+
|
|
178
|
+
Capabilities live in an ordinary module. The names and paths here become the typed tree you call.
|
|
179
|
+
|
|
180
|
+
```ts title="capable/app.ts"
|
|
181
|
+
import { defineApp, capability } from "capable-kit";
|
|
182
|
+
import { z } from "zod";
|
|
183
|
+
|
|
184
|
+
const listTodos = capability({
|
|
185
|
+
id: "todos.list",
|
|
186
|
+
// Opt in to GET and read-only tool hints.
|
|
187
|
+
effect: "read",
|
|
188
|
+
handler: () => [{ id: "1", title: "Read the docs" }],
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const createTodo = capability({
|
|
192
|
+
id: "todos.create",
|
|
193
|
+
input: z.object({ title: z.string().min(1) }),
|
|
194
|
+
handler: ({ input }) => ({ id: "1", title: input.title }),
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
export default defineApp({
|
|
198
|
+
name: "Todos",
|
|
199
|
+
capabilities: {
|
|
200
|
+
todos: { list: listTodos, create: createTodo },
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
> Output types are inferred from handlers. Portable output schemas, effects, descriptions, errors, middleware, and surface metadata are opt-in.
|
|
206
|
+
|
|
207
|
+
3. ### Call from a server component
|
|
208
|
+
|
|
209
|
+
This is the tRPC moment. `createApp()` gives you a typed callable object — call it from a server component or a server action. No network, no generated client, and the same validation and errors apply.
|
|
210
|
+
|
|
211
|
+
```tsx title="app/todos/page.tsx"
|
|
212
|
+
import { createApp } from "capable-kit";
|
|
213
|
+
import definition from "../capable/app";
|
|
214
|
+
|
|
215
|
+
// A typed call in a server component or server action.
|
|
216
|
+
// No network, no client generated — same validation and errors.
|
|
217
|
+
const app = createApp(definition);
|
|
218
|
+
|
|
219
|
+
export default async function TodoList() {
|
|
220
|
+
const todos = await app.todos.list({});
|
|
221
|
+
return (
|
|
222
|
+
<ul>
|
|
223
|
+
{todos.map((t) => <li key={t.id}>{t.title}</li>)}
|
|
224
|
+
</ul>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
4. ### Expose it to the browser
|
|
230
|
+
|
|
231
|
+
To call the same capabilities from the client, mount one fetch server and re-export its handlers into two catch-all route files.
|
|
232
|
+
|
|
233
|
+
```ts title="capable/server.ts"
|
|
234
|
+
// capable/server.ts
|
|
235
|
+
import { createNextRouteHandlers } from "@capable/next";
|
|
236
|
+
import { protocol, createServer, http } from "capable-kit/server";
|
|
237
|
+
import definition from "./app";
|
|
238
|
+
|
|
239
|
+
const server = createServer(definition, {
|
|
240
|
+
mounts: [protocol(), http()],
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
export const { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } =
|
|
244
|
+
createNextRouteHandlers(server.fetch);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
```ts title="App Router"
|
|
248
|
+
// app/api/[[...path]]/route.ts
|
|
249
|
+
export { DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT } from "@/capable/server";
|
|
250
|
+
|
|
251
|
+
// app/%5Fcapable/[[...path]]/route.ts — %5F keeps _capable out of Next's private folders
|
|
252
|
+
export { GET, POST } from "@/capable/server";
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
5. ### Call from React Query
|
|
256
|
+
|
|
257
|
+
`@capable/react-query` mirrors the app tree into query keys and options. The browser talks to the Capable transport at `/_capable`.
|
|
258
|
+
|
|
259
|
+
```ts title="app/query.ts"
|
|
260
|
+
import { createRemoteApp } from "capable-kit";
|
|
261
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
262
|
+
import { createReactQuery } from "@capable/react-query";
|
|
263
|
+
import type definition from "../capable/app";
|
|
264
|
+
|
|
265
|
+
const app = createRemoteApp<typeof definition>(
|
|
266
|
+
createHttpTransport({ url: "/_capable/" }),
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
export const query = createReactQuery(app);
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```tsx title="app/todos/todos.tsx"
|
|
273
|
+
import { useQuery } from "@tanstack/react-query";
|
|
274
|
+
import { query } from "./query";
|
|
275
|
+
|
|
276
|
+
export function TodoList() {
|
|
277
|
+
const { data } = useQuery(query.todos.list.queryOptions({}));
|
|
278
|
+
return (
|
|
279
|
+
<ul>
|
|
280
|
+
{data?.map((t) => <li key={t.id}>{t.title}</li>)}
|
|
281
|
+
</ul>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
</Tab>
|
|
287
|
+
</Tabs>
|
|
288
|
+
|
|
289
|
+
> **Both paths are the same Capable**
|
|
290
|
+
>
|
|
291
|
+
> The capability you wrote is identical in either tab. The difference is only where it runs and who calls it. Standalone gives you HTTP, CLI, and MCP from one file; embedded gives you typed calls inside an app you already deploy. Local and remote callers use the same tree — the only difference is `createApp()` versus `createRemoteApp()`. You can move between them without rewriting capabilities.
|
|
292
|
+
|
|
293
|
+
</DocsPage>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Packages and entry points"
|
|
3
|
+
description: "What each import path contains and when to reach for it."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/reference/packages", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/reference/packages" frontmatter={frontmatter}>
|
|
11
|
+
|
|
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
|
+
|
|
14
|
+
## The root entry point [#root]
|
|
15
|
+
|
|
16
|
+
`capable` is deliberately limited to authoring and composing apps. Everything you need to define capabilities lives here.
|
|
17
|
+
|
|
18
|
+
```ts title="import"
|
|
19
|
+
import {
|
|
20
|
+
defineApp, // compose a definition
|
|
21
|
+
defineErrors, // declare an error set
|
|
22
|
+
group, // decorated subtree
|
|
23
|
+
capability, // author a capability
|
|
24
|
+
md, // markdown template tag
|
|
25
|
+
watchQuery, // snapshot + invalidation subscriber
|
|
26
|
+
createApp, // definition + context -> callable app
|
|
27
|
+
createRemoteApp, // transport + definition type -> callable app
|
|
28
|
+
mergeApps, // combine apps
|
|
29
|
+
selectApp, // narrow an app
|
|
30
|
+
subscribe, // iterate replacements
|
|
31
|
+
executeCapability, // run one capability without an app
|
|
32
|
+
} from "capable-kit";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## All entry points [#entry-points]
|
|
36
|
+
|
|
37
|
+
| Import | Contains |
|
|
38
|
+
| --- | --- |
|
|
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()` |
|
|
50
|
+
|
|
51
|
+
> **Dependency direction**
|
|
52
|
+
>
|
|
53
|
+
> `@capable/core` depends on no transport, host, CLI, MCP, or HTTP package. Surface packages depend inward on the core, never the other way around.
|
|
54
|
+
|
|
55
|
+
## Function summary [#functions]
|
|
56
|
+
|
|
57
|
+
| Function | Signature | Notes |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `capability()` | `capability(config)` | `capability<Context>()` or `capability.withContext<Context>()` binds a context type |
|
|
60
|
+
| `defineApp()` | `defineApp({ name, version, capabilities })` | Immutable definition, no context |
|
|
61
|
+
| `group()` | `group({ middleware, errors, meta, capabilities })` | Anonymous decorated subtree |
|
|
62
|
+
| `createApp()` | `createApp(definition)` | Callable tree; context options exist only when declared |
|
|
63
|
+
| `createRemoteApp()` | `createRemoteApp<typeof definition>(transport)` | Lazy, transport-backed remote placement |
|
|
64
|
+
| `mergeApps()` | `mergeApps(a, b, ...)` | Root-tree merge, dispatch by id |
|
|
65
|
+
| `selectApp()` | `selectApp(app, { include, exclude })` | Exclude wins over include |
|
|
66
|
+
| `subscribe()` | `subscribe(app.todos.list, input, { signal })` | Async iterator of replacements |
|
|
67
|
+
| `executeCapability()` | `executeCapability(capability, { input, context, signal })` | No app tree, no group behaviour |
|
|
68
|
+
| `createServer()` | `createServer(definition, { context, mounts, middleware })` | Returns `{ fetch }` |
|
|
69
|
+
|
|
70
|
+
</DocsPage>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Surface metadata"
|
|
3
|
+
description: "Every meta field the built-in surfaces read, and what it changes."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/reference/metadata", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/reference/metadata" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
`meta` is an open record. Each surface package declares its own key through module augmentation, which is how the fields below are type-checked without the core knowing anything about HTTP, terminals, or agents.
|
|
13
|
+
|
|
14
|
+
## In context [#example]
|
|
15
|
+
|
|
16
|
+
```ts title="capabilities.ts"
|
|
17
|
+
const deleteTodo = todo({
|
|
18
|
+
id: "todos.delete",
|
|
19
|
+
effect: "destructive",
|
|
20
|
+
input: z.object({ todoId: z.string() }),
|
|
21
|
+
meta: {
|
|
22
|
+
http: { method: "DELETE", route: "/:todoId", status: 200 },
|
|
23
|
+
cli: { positional: ["todoId"] },
|
|
24
|
+
mcp: { name: "todos_delete" },
|
|
25
|
+
aiSdk: { name: "todos_delete", strict: true },
|
|
26
|
+
eve: false,
|
|
27
|
+
},
|
|
28
|
+
handler: ({ input, context }) => context.todos.delete(input.todoId),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const todos = group({
|
|
32
|
+
meta: {
|
|
33
|
+
http: { prefix: "/todos" },
|
|
34
|
+
cli: { name: "todo" },
|
|
35
|
+
},
|
|
36
|
+
capabilities: { delete: deleteTodo },
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Capability metadata [#capability]
|
|
41
|
+
|
|
42
|
+
| Field | Type | Effect |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| `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
|
+
| `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 `__`. |
|
|
47
|
+
| `eve` | `false \| { name }` | Same, for native in-process Eve tools. |
|
|
48
|
+
| `aiSdk` | `false \| { name, strict }` | Renames, constrains, or hides an AI SDK tool. |
|
|
49
|
+
|
|
50
|
+
## Group metadata [#group]
|
|
51
|
+
|
|
52
|
+
| Field | Type | Effect |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `http.prefix` | `string` | Replaces this group's segment in derived routes and prefixes authored ones. |
|
|
55
|
+
| `cli.name` | `string` | Renames the command group. |
|
|
56
|
+
|
|
57
|
+
> **No generic merging**
|
|
58
|
+
>
|
|
59
|
+
> The core preserves the full group ancestry and never merges metadata itself. Each surface compiler decides what inheritance means, which is why `http.prefix` composes but `mcp.name` does not exist on groups at all.
|
|
60
|
+
|
|
61
|
+
## Effect is not metadata [#effect]
|
|
62
|
+
|
|
63
|
+
`effect` is a core field, because intent is part of the capability rather than of one presentation. Surfaces read it:
|
|
64
|
+
|
|
65
|
+
| Effect | HTTP | MCP | AI SDK | Eve |
|
|
66
|
+
| --- | --- | --- | --- | --- |
|
|
67
|
+
| `read` | `GET` | `readOnlyHint` | `toolMetadata.capable.effect` | Usually no approval |
|
|
68
|
+
| `write` | `POST` | — | `toolMetadata.capable.effect` | Policy of your choice |
|
|
69
|
+
| `destructive` | `POST` | `destructiveHint` | `toolMetadata.capable.effect` | Often `always()` |
|
|
70
|
+
| omitted | `POST` | — | Omitted | Treated as unknown intent |
|
|
71
|
+
|
|
72
|
+
## Your own metadata [#custom]
|
|
73
|
+
|
|
74
|
+
A surface you write can claim its own key the same way the built-in ones do. Unknown keys are preserved and passed through, so nothing in the core has to change.
|
|
75
|
+
|
|
76
|
+
```ts title="dashboard-surface.ts"
|
|
77
|
+
declare module "@capable/core" {
|
|
78
|
+
interface CapabilityMetaRegistry {
|
|
79
|
+
readonly dashboard?: { readonly icon: string };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
</DocsPage>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "The cap CLI"
|
|
3
|
+
description: "Commands, options, and project discovery for the toolchain."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/reference/cli", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/reference/cli" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
The `cap` command ships with the `capable-kit` package. There is no separate CLI package to install. Apps hosted inside another framework can simply ignore the command.
|
|
13
|
+
|
|
14
|
+
## Usage [#usage]
|
|
15
|
+
|
|
16
|
+
```sh title="terminal"
|
|
17
|
+
cap init [directory]
|
|
18
|
+
cap dev [project] [--host localhost] [--port 3000]
|
|
19
|
+
cap build [project] [--output .output] [--preset node-server]
|
|
20
|
+
cap preview [project] [--output .output] [--host localhost] [--port 3000]
|
|
21
|
+
cap cli [--app <project-or-url>] <command...>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts title="new standalone App"
|
|
25
|
+
cap init apps/todos
|
|
26
|
+
cd apps/todos
|
|
27
|
+
pnpm install
|
|
28
|
+
pnpm dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Command | Description |
|
|
32
|
+
| --- | --- |
|
|
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 /\_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
|
+
| `build` | Builds the project into `.output`. Presets are Nitro deployment presets, for example `node-server` or `vercel`. |
|
|
36
|
+
| `preview` | Runs a previously built `node-server` output. Other presets do not produce a locally runnable command. |
|
|
37
|
+
| `cli` | Runs the app's derived command tree without writing a CLI entry point. |
|
|
38
|
+
|
|
39
|
+
## Project discovery [#discovery]
|
|
40
|
+
|
|
41
|
+
The first match wins:
|
|
42
|
+
|
|
43
|
+
```sh title="terminal"
|
|
44
|
+
# 1. Positional argument or --app
|
|
45
|
+
cap dev ./services/todos
|
|
46
|
+
|
|
47
|
+
# 2. CAPABLE_APP environment variable
|
|
48
|
+
CAPABLE_APP=./services/todos cap dev
|
|
49
|
+
|
|
50
|
+
# 3. The "capable" field in package.json
|
|
51
|
+
{ "capable": "./services/todos" }
|
|
52
|
+
|
|
53
|
+
# 4. capable.app.* in the current directory
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Recognized entry files are `capable.app.ts`, `.tsx`, `.js`, `.mjs`, and `.cjs`. If a `capable.server.*` file sits in the same package root, it is used as the server.
|
|
57
|
+
|
|
58
|
+
## Invoking capabilities [#invoke]
|
|
59
|
+
|
|
60
|
+
```sh title="terminal"
|
|
61
|
+
# In-process, using capable.server.ts when present
|
|
62
|
+
cap cli --app ./ todos list
|
|
63
|
+
|
|
64
|
+
# Against a deployed server, over the Capable transport
|
|
65
|
+
cap cli --app https://todos.example.com todos list
|
|
66
|
+
```
|
|
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 `/_capable/`. Both produce the same commands and help, because both read the same manifest.
|
|
69
|
+
|
|
70
|
+
| Option | Applies to | Meaning |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `--app` | `cli` | Project path or server URL |
|
|
73
|
+
| `--json` | Any capability | Print canonical JSON instead of the Markdown rendering |
|
|
74
|
+
| `--watch` | Subscribable read capabilities | Follow replacements, redrawing in place in a TTY |
|
|
75
|
+
| `--help` | Any command | Help for the root, a group, or one capability |
|
|
76
|
+
|
|
77
|
+
> **Exit codes**
|
|
78
|
+
>
|
|
79
|
+
> `0` success, `1` capability failure, `2` usage error. Suitable for scripts and CI.
|
|
80
|
+
|
|
81
|
+
</DocsPage>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "AI SDK"
|
|
3
|
+
description: "Turn an executable app into typed AI SDK tools for generateText, streamText, and agents."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { DocsPage, docMetadata } from "../../_components/docs-page";
|
|
7
|
+
|
|
8
|
+
export const metadata = docMetadata("/surfaces/ai-sdk", frontmatter);
|
|
9
|
+
|
|
10
|
+
<DocsPage href="/surfaces/ai-sdk" frontmatter={frontmatter}>
|
|
11
|
+
|
|
12
|
+
`createAiSdkTools()` turns an executable app into a typed AI SDK v7 tool set. Names, schemas, execution, and cancellation come from the same capabilities used by every other surface.
|
|
13
|
+
|
|
14
|
+
## Create a tool set [#create]
|
|
15
|
+
|
|
16
|
+
```ts title="agent.ts"
|
|
17
|
+
import { generateText, stepCountIs } from "ai";
|
|
18
|
+
import { createApp } from "capable-kit";
|
|
19
|
+
import { createAiSdkTools } from "capable-kit/ai-sdk";
|
|
20
|
+
import definition from "./capable.app";
|
|
21
|
+
|
|
22
|
+
const app = createApp(definition);
|
|
23
|
+
const tools = await createAiSdkTools(app);
|
|
24
|
+
|
|
25
|
+
const result = await generateText({
|
|
26
|
+
model: "anthropic/claude-sonnet-4.5",
|
|
27
|
+
tools,
|
|
28
|
+
stopWhen: stepCountIs(5),
|
|
29
|
+
prompt: "Create a todo to read the Capable documentation.",
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The returned object can go directly into `generateText()`,`streamText()`, or an AI SDK agent. Tool calls run through the app runtime, so middleware, declared errors, validation, and output validation stay in one place. If a capability declares context, bind its provider when creating the app; context-free apps need no options.
|
|
34
|
+
|
|
35
|
+
## What gets projected [#mapping]
|
|
36
|
+
|
|
37
|
+
| AI SDK field | Capable source |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| Object key | Application path joined with \_\_ |
|
|
40
|
+
| `description` | Description, then title |
|
|
41
|
+
| `inputSchema` | Capability input JSON Schema |
|
|
42
|
+
| `outputSchema` | Declared output JSON Schema |
|
|
43
|
+
| `execute` | App runtime call by Capability ID |
|
|
44
|
+
| `metadata.capable` | Capability ID, path, effect, title, and deprecation |
|
|
45
|
+
|
|
46
|
+
A typed local or remote app preserves literal tool names and Capability input/output types in AI SDK tool calls and results. Projection is asynchronous because it discovers the manifest needed to enumerate the tools.
|
|
47
|
+
|
|
48
|
+
## Rename, constrain, or hide tools [#metadata]
|
|
49
|
+
|
|
50
|
+
```ts title="capabilities.ts"
|
|
51
|
+
const createTodo = capability({
|
|
52
|
+
id: "todos.create",
|
|
53
|
+
input: z.object({ title: z.string() }),
|
|
54
|
+
output: TodoSchema,
|
|
55
|
+
meta: {
|
|
56
|
+
aiSdk: {
|
|
57
|
+
name: "create_todo", // default: todos__create
|
|
58
|
+
strict: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
handler: ({ input, context }) => context.todos.create(input),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// meta: { aiSdk: false } keeps a capability out of this tool set.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Duplicate names and names outside the portable 1–64 character tool subset fail while the tool set is created. Use [selectApp()](/patterns/composition) when an entire exposure boundary should see only part of an app.
|
|
68
|
+
|
|
69
|
+
## Local and remote execution [#remote]
|
|
70
|
+
|
|
71
|
+
Conversion reads the App manifest rather than the original live schema objects, so local, remote, merged, and selected Apps use the same path.
|
|
72
|
+
|
|
73
|
+
```ts title="tools.ts"
|
|
74
|
+
import { createRemoteApp } from "capable-kit";
|
|
75
|
+
import { createAiSdkTools } from "capable-kit/ai-sdk";
|
|
76
|
+
import { createHttpTransport } from "capable-kit/http";
|
|
77
|
+
import type definition from "./capable.app";
|
|
78
|
+
|
|
79
|
+
const app = createRemoteApp<typeof definition>(
|
|
80
|
+
createHttpTransport({ url: "https://todos.example.com/_capable/" }),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const tools = await createAiSdkTools(app);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
> **Unary execution only**
|
|
87
|
+
>
|
|
88
|
+
> A subscribable Capability becomes a normal unary tool that returns its current snapshot. AI SDK streamed tool outputs are preliminary execution results, not Capable replacement subscriptions.
|
|
89
|
+
|
|
90
|
+
## Approval stays with the AI SDK call [#approval]
|
|
91
|
+
|
|
92
|
+
Capable exposes `effect` under `toolMetadata.capable.effect`, but does not automatically approve or block a call. Configure AI SDK v7's top-level `toolApproval` policy at `generateText()`, `streamText()`, or agent construction.
|
|
93
|
+
|
|
94
|
+
</DocsPage>
|