@beignet/core 0.0.33 → 0.0.35
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 +24 -0
- package/README.md +207 -30
- package/dist/agent-capabilities/index.d.ts +167 -0
- package/dist/agent-capabilities/index.d.ts.map +1 -0
- package/dist/agent-capabilities/index.js +275 -0
- package/dist/agent-capabilities/index.js.map +1 -0
- package/dist/application/index.d.ts +2 -2
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +13 -3
- package/dist/application/index.js.map +1 -1
- package/dist/client/client.d.ts +2 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +33 -16
- package/dist/client/client.js.map +1 -1
- package/dist/contracts/contract-builder.d.ts +5 -7
- package/dist/contracts/contract-builder.d.ts.map +1 -1
- package/dist/contracts/contract-builder.js +3 -18
- package/dist/contracts/contract-builder.js.map +1 -1
- package/dist/contracts/contract-group.d.ts +2 -2
- package/dist/contracts/contract-group.d.ts.map +1 -1
- package/dist/contracts/contract-group.js +2 -1
- package/dist/contracts/contract-group.js.map +1 -1
- package/dist/contracts/metadata.d.ts +3 -0
- package/dist/contracts/metadata.d.ts.map +1 -0
- package/dist/contracts/metadata.js +14 -0
- package/dist/contracts/metadata.js.map +1 -0
- package/dist/contracts/types.d.ts +20 -0
- package/dist/contracts/types.d.ts.map +1 -1
- package/dist/contracts/types.js.map +1 -1
- package/dist/events/index.d.ts +4 -4
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +5 -5
- package/dist/events/index.js.map +1 -1
- package/dist/flags/index.d.ts +0 -4
- package/dist/flags/index.d.ts.map +1 -1
- package/dist/flags/index.js +0 -4
- package/dist/flags/index.js.map +1 -1
- package/dist/idempotency/index.d.ts.map +1 -1
- package/dist/idempotency/index.js +14 -9
- package/dist/idempotency/index.js.map +1 -1
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +10 -4
- package/dist/jobs/index.js.map +1 -1
- package/dist/notifications/index.d.ts +194 -10
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +397 -59
- package/dist/notifications/index.js.map +1 -1
- package/dist/openapi/index.js +15 -8
- package/dist/openapi/index.js.map +1 -1
- package/dist/ports/auth.d.ts +2 -0
- package/dist/ports/auth.d.ts.map +1 -1
- package/dist/ports/auth.js +2 -0
- package/dist/ports/auth.js.map +1 -1
- package/dist/ports/events.d.ts +2 -2
- package/dist/ports/index.d.ts +1 -1
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/provider.d.ts +10 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js.map +1 -1
- package/dist/schedules/index.d.ts +6 -13
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +24 -44
- package/dist/schedules/index.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/request-executor.d.ts +72 -0
- package/dist/server/request-executor.d.ts.map +1 -0
- package/dist/server/request-executor.js +781 -0
- package/dist/server/request-executor.js.map +1 -0
- package/dist/server/request-preparation.d.ts +39 -0
- package/dist/server/request-preparation.d.ts.map +1 -0
- package/dist/server/request-preparation.js +248 -0
- package/dist/server/request-preparation.js.map +1 -0
- package/dist/server/response-finalization.d.ts +34 -0
- package/dist/server/response-finalization.d.ts.map +1 -0
- package/dist/server/response-finalization.js +279 -0
- package/dist/server/response-finalization.js.map +1 -0
- package/dist/server/route-definitions.d.ts +139 -0
- package/dist/server/route-definitions.d.ts.map +1 -0
- package/dist/server/route-definitions.js +94 -0
- package/dist/server/route-definitions.js.map +1 -0
- package/dist/server/route-matching.d.ts +15 -0
- package/dist/server/route-matching.d.ts.map +1 -0
- package/dist/server/route-matching.js +46 -0
- package/dist/server/route-matching.js.map +1 -0
- package/dist/server/server.d.ts +6 -157
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +29 -1340
- package/dist/server/server.js.map +1 -1
- package/dist/server/use-case-route.d.ts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.d.ts.map +1 -1
- package/dist/tracing/index.js.map +1 -1
- package/dist/uploads/client.js +4 -7
- package/dist/uploads/client.js.map +1 -1
- package/dist/uploads/index.d.ts.map +1 -1
- package/dist/uploads/index.js +59 -12
- package/dist/uploads/index.js.map +1 -1
- package/package.json +5 -5
- package/skills/app-architecture/SKILL.md +31 -1
- package/src/agent-capabilities/index.ts +578 -0
- package/src/application/index.ts +19 -5
- package/src/client/client.ts +41 -17
- package/src/contracts/contract-builder.ts +8 -23
- package/src/contracts/contract-group.ts +4 -6
- package/src/contracts/metadata.ts +20 -0
- package/src/contracts/types.ts +39 -0
- package/src/events/index.ts +16 -20
- package/src/flags/index.ts +0 -5
- package/src/idempotency/index.ts +17 -9
- package/src/jobs/index.ts +8 -3
- package/src/notifications/index.ts +678 -70
- package/src/openapi/index.ts +24 -12
- package/src/ports/auth.ts +2 -0
- package/src/ports/events.ts +2 -2
- package/src/ports/index.ts +0 -1
- package/src/providers/index.ts +1 -0
- package/src/providers/provider.ts +18 -3
- package/src/schedules/index.ts +57 -63
- package/src/server/index.ts +4 -2
- package/src/server/request-executor.ts +1170 -0
- package/src/server/request-preparation.ts +409 -0
- package/src/server/response-finalization.ts +385 -0
- package/src/server/route-definitions.ts +338 -0
- package/src/server/route-matching.ts +64 -0
- package/src/server/server.ts +63 -2171
- package/src/server/use-case-route.ts +1 -1
- package/src/testing/index.ts +2 -0
- package/src/tracing/index.ts +1 -0
- package/src/uploads/client.ts +4 -7
- package/src/uploads/index.ts +70 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @beignet/core
|
|
2
2
|
|
|
3
|
+
## 0.0.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2101386: Authorize agent capabilities against their exact parsed input and keep custom Agent Auth locations outside the Beignet execution bridge.
|
|
8
|
+
- 2290c4a: Add typed, validated agent capability registries and execution, plus a Better Auth Agent Auth bridge with constraint-safe validation, verified principals, grants, and redacted protocol errors.
|
|
9
|
+
- 42921da: Keep agent capability registries type-safe, observe pre-context failures, and preserve application error codes across Agent Auth execution modes.
|
|
10
|
+
- 2a5b224: Preserve idempotency and outbox delivery guarantees on persistence and handler failures, enforce multipart limits from actual bytes, support Date and JSON query serialization, and add bounded MySQL deadlock backoff.
|
|
11
|
+
- 74aad51: Replace the schedule-specific instrumentation sink with shared provider targets, serve bodyless HEAD responses from GET routes, improve missing JSON content-type diagnostics, and expose the auth error HTTP status.
|
|
12
|
+
- db79263: Align route, listener, auth-provider, and webhook-integration APIs before 1.0. Route declarations now use an app-bound `createRoutes<AppContext>()` builder, listeners put their stable name first, Better Auth exports `createBetterAuthProvider(...)`, and vendor webhook verifiers live in `@beignet/webhooks-*` packages outside provider audits.
|
|
13
|
+
- 397f106: Standardize framework-owned operational errors, degrade opaque OpenAPI path parameters safely, and add direct Redis, Pino, and Upstash adapters.
|
|
14
|
+
- 40f4155: Refresh package-shipped agent guidance for app-bound route builders, configured route-builder paths, webhook integrations, and operational error responses.
|
|
15
|
+
- d1c0efd: Make contract and contract-group OpenAPI metadata compose consistently across `meta()` and `openapi()` calls.
|
|
16
|
+
- c403db2: Isolate use-case observers, authenticate operational routes before context creation, honor configured generated-test roots, correct feature-helper linting, preserve optional OpenAPI descriptions, and keep upload resets stable.
|
|
17
|
+
- 4cc5254: Decompose the server runtime into focused internal modules while preserving the existing public API and request behavior.
|
|
18
|
+
- 7d0c795: Expose stable named provider types while keeping private config schemas out of package declarations and preserving validated config and contributed-port inference. Drizzle's Postgres and MySQL config schema constants are now internal; use the exported config interfaces for validated shapes.
|
|
19
|
+
|
|
20
|
+
## 0.0.34
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 8226b4c: Isolate notification channel failures, add app-owned preference checks, provide independently retryable queued delivery through existing job dispatchers, and document the app structure for queued notification workers.
|
|
25
|
+
- 9345cc9: Stabilize the pre-1.0 public surface around factory-only providers, canonical server and testing imports, consistent memory naming, and the removal of deprecated aliases.
|
|
26
|
+
|
|
3
27
|
## 0.0.33
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
> evaluation, and APIs may change between releases while the framework settles.
|
|
8
8
|
|
|
9
9
|
This package provides Beignet's framework primitives: contracts, server runtime,
|
|
10
|
-
typed client, use cases, ports, domain helpers, app errors, config, events,
|
|
10
|
+
typed client, use cases, agent capabilities, ports, domain helpers, app errors, config, events,
|
|
11
11
|
idempotency, locks, outbox, mail, notifications, payments, search, webhooks,
|
|
12
12
|
feature flags, error reporting, schedules, uploads, entitlements, pagination
|
|
13
13
|
helpers, testing helpers, and OpenAPI generation.
|
|
@@ -46,6 +46,7 @@ name the framework area they depend on.
|
|
|
46
46
|
|
|
47
47
|
| Import path | Responsibility |
|
|
48
48
|
| --- | --- |
|
|
49
|
+
| `@beignet/core/agent-capabilities` | Typed agent capability definitions, registries, validation, and execution |
|
|
49
50
|
| `@beignet/core/application` | Use case builder and test helpers |
|
|
50
51
|
| `@beignet/core/client` | Typed HTTP client |
|
|
51
52
|
| `@beignet/core/client-only` | Static lint marker for modules intended for client-side imports |
|
|
@@ -68,7 +69,6 @@ name the framework area they depend on.
|
|
|
68
69
|
| `@beignet/core/payments` | Payments port, memory payments adapter, and memory payments provider |
|
|
69
70
|
| `@beignet/core/pagination` | Offset/cursor page types, normalizers, and result helpers |
|
|
70
71
|
| `@beignet/core/ports` | App-facing ports, auth, audit, policies, cache, storage, logging, and redaction |
|
|
71
|
-
| `@beignet/core/ports/testing` | Port and policy test helpers |
|
|
72
72
|
| `@beignet/core/providers` | Provider lifecycle and instrumentation primitives |
|
|
73
73
|
| `@beignet/core/search` | Search index definitions, SearchPort, memory adapter, memory provider, and helpers |
|
|
74
74
|
| `@beignet/core/schedules` | Schedule primitives |
|
|
@@ -76,7 +76,7 @@ name the framework area they depend on.
|
|
|
76
76
|
| `@beignet/core/server-only` | Static lint marker for modules that must stay out of client bundles |
|
|
77
77
|
| `@beignet/core/tasks` | Operational task definitions and inline task execution |
|
|
78
78
|
| `@beignet/core/tenancy` | Branded tenant scope helpers for repository boundaries |
|
|
79
|
-
| `@beignet/core/testing` |
|
|
79
|
+
| `@beignet/core/testing` | Port and policy assertions, recording adapters, test context factories, memory port fixtures, provider install helper, factories, seeds, and database harnesses |
|
|
80
80
|
| `@beignet/core/tracing` | Dependency-free W3C trace context primitives |
|
|
81
81
|
| `@beignet/core/uploads` | Upload definitions (`createUploads<AppContext>()` app-bound builder), router, signer port, and test signer |
|
|
82
82
|
| `@beignet/core/uploads/client` | Browser upload client for server and direct uploads |
|
|
@@ -90,6 +90,74 @@ import "@beignet/core/client-only";
|
|
|
90
90
|
import "@beignet/core/server-only";
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
## Agent capabilities
|
|
94
|
+
|
|
95
|
+
Agent capabilities are validated application entrypoints for authenticated AI
|
|
96
|
+
agent transports. Definitions remain transport-neutral and should delegate
|
|
97
|
+
business behavior to the same use cases called by HTTP routes, jobs, and
|
|
98
|
+
scripts.
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import {
|
|
102
|
+
createAgentCapabilities,
|
|
103
|
+
createAgentCapabilityExecutor,
|
|
104
|
+
} from "@beignet/core/agent-capabilities";
|
|
105
|
+
import { z } from "zod";
|
|
106
|
+
import type { AppContext } from "@/app-context";
|
|
107
|
+
import { createIssueUseCase } from "@/features/issues/use-cases";
|
|
108
|
+
|
|
109
|
+
type AgentPrincipal = { agentId: string; userId: string };
|
|
110
|
+
|
|
111
|
+
const { defineAgentCapability, defineAgentCapabilityRegistry } =
|
|
112
|
+
createAgentCapabilities<AppContext, AgentPrincipal>();
|
|
113
|
+
|
|
114
|
+
const createIssue = defineAgentCapability("issues.create", {
|
|
115
|
+
description: "Create an issue in one workspace.",
|
|
116
|
+
input: z.object({ workspaceId: z.string(), title: z.string().min(1) }),
|
|
117
|
+
output: z.object({ id: z.string(), title: z.string() }),
|
|
118
|
+
async handle({ ctx, input }) {
|
|
119
|
+
const { workspaceId: _workspaceId, ...useCaseInput } = input;
|
|
120
|
+
return createIssueUseCase.run({ ctx, input: useCaseInput });
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const registry = defineAgentCapabilityRegistry([createIssue]);
|
|
125
|
+
|
|
126
|
+
export const executor = createAgentCapabilityExecutor({
|
|
127
|
+
registry,
|
|
128
|
+
async createContext({ principal, input }) {
|
|
129
|
+
const membership = await server.ports.members.findMembership({
|
|
130
|
+
workspaceId: input.workspaceId,
|
|
131
|
+
userId: principal.userId,
|
|
132
|
+
});
|
|
133
|
+
if (!membership) throw new Error("Not a workspace member");
|
|
134
|
+
|
|
135
|
+
return server.createServiceContext({
|
|
136
|
+
asUser: { id: principal.userId, role: membership.role },
|
|
137
|
+
tenantId: input.workspaceId,
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Input is validated before `createContext(...)` runs. Output is validated before
|
|
144
|
+
it reaches the transport. Context construction remains app-owned: authenticate
|
|
145
|
+
the transport first, re-read tenant membership from an authoritative port, and
|
|
146
|
+
call `server.createServiceContext(...)` instead of assembling `AppContext` by
|
|
147
|
+
hand. Use `@beignet/agent-auth-better-auth` to expose a registry through Better
|
|
148
|
+
Auth Agent Auth.
|
|
149
|
+
|
|
150
|
+
Registry creation comes from the same app-bound factory as
|
|
151
|
+
`defineAgentCapability`, so definitions with another context or principal type
|
|
152
|
+
are rejected. Executor hooks observe the complete attempt and include a
|
|
153
|
+
`stage`; `ctx` is undefined until context construction succeeds. Dynamic
|
|
154
|
+
transport adapters may provide `authorize(...)` to inspect the exact parsed
|
|
155
|
+
input before context construction without causing a second validation pass. Pass
|
|
156
|
+
an independent `instrumentation` target and `tracing` port to the executor when
|
|
157
|
+
lookup, input-validation, and context failures must be visible before an app
|
|
158
|
+
context exists. Without those options, successful context construction lets
|
|
159
|
+
the executor derive observability ports from `ctx`.
|
|
160
|
+
|
|
93
161
|
## Durable failure language
|
|
94
162
|
|
|
95
163
|
Jobs, outbox delivery, and schedule runners use the same terms:
|
|
@@ -230,6 +298,13 @@ import type { providers } from "@/server/providers";
|
|
|
230
298
|
export type AppRuntimePorts = AppPorts & InferProviderPorts<typeof providers>;
|
|
231
299
|
```
|
|
232
300
|
|
|
301
|
+
Reusable provider packages should export a named `ServiceProvider` return type
|
|
302
|
+
and use `AnyProviderConfigSchema<Config>` for its config generic. That keeps a
|
|
303
|
+
private Zod or other Standard Schema implementation out of the package
|
|
304
|
+
declaration while preserving the validated config output and exact
|
|
305
|
+
contributed-port inference. App-local providers should keep their concrete
|
|
306
|
+
schema inference because they do not have a package compatibility boundary.
|
|
307
|
+
|
|
233
308
|
App-local providers can declare required ports, app context, and
|
|
234
309
|
service-context input through the curried `createProvider()` form. `setup`
|
|
235
310
|
then receives typed `ports` and a `createServiceContext` factory that returns
|
|
@@ -271,9 +346,12 @@ provider `name` that defaults to `"memory-mailer"`.
|
|
|
271
346
|
`{ notifications: NotificationPort }` backed by
|
|
272
347
|
`createInlineNotificationDispatcher(...)`. Channel handlers receive an app
|
|
273
348
|
service context built lazily through the server context blueprint on each
|
|
274
|
-
send, so registration order does not matter.
|
|
275
|
-
|
|
276
|
-
`
|
|
349
|
+
send, so registration order does not matter. One failed channel does not block
|
|
350
|
+
the remaining channels. Inline sends return ordered `sent`, `skipped`, and
|
|
351
|
+
`failed` results; queued dispatchers also return `queued`. Set
|
|
352
|
+
`failureMode: "throw"` to reject after every channel has run. Options also
|
|
353
|
+
accept an app-owned `preferences` evaluator, the dispatcher's `onError` result
|
|
354
|
+
mapper, and a provider `name` that defaults to `"inline-notifications"`.
|
|
277
355
|
|
|
278
356
|
```typescript
|
|
279
357
|
// server/providers.ts
|
|
@@ -290,8 +368,56 @@ export const providers = [
|
|
|
290
368
|
|
|
291
369
|
Replace `createMemoryMailerProvider(...)` with a real mail provider such as
|
|
292
370
|
`@beignet/provider-mail-resend` for production delivery. Production apps can
|
|
293
|
-
keep the inline
|
|
294
|
-
|
|
371
|
+
keep the inline provider or define a central notification registry and a
|
|
372
|
+
`defineNotificationDeliveryJob(...)`. Install
|
|
373
|
+
`createQueuedNotificationsProvider(...)` after the app's jobs provider to
|
|
374
|
+
enqueue one independently retryable job per channel. Register the delivery job
|
|
375
|
+
with every BullMQ/Inngest worker or outbox registry that can receive it.
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
// server/notifications.ts
|
|
379
|
+
import {
|
|
380
|
+
defineNotificationDeliveryJob,
|
|
381
|
+
defineNotificationRegistry,
|
|
382
|
+
} from "@beignet/core/notifications";
|
|
383
|
+
import type { AppContext } from "@/app-context";
|
|
384
|
+
import { WelcomeNotification } from "@/features/users/notifications";
|
|
385
|
+
|
|
386
|
+
export const notificationRegistry = defineNotificationRegistry<AppContext>([
|
|
387
|
+
WelcomeNotification,
|
|
388
|
+
]);
|
|
389
|
+
|
|
390
|
+
export const DeliverNotificationJob =
|
|
391
|
+
defineNotificationDeliveryJob<AppContext>({
|
|
392
|
+
registry: notificationRegistry,
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
// server/index.ts
|
|
398
|
+
import { createQueuedNotificationsProvider } from "@beignet/core/notifications";
|
|
399
|
+
import { createNextServer, createNextServerLoader } from "@beignet/next";
|
|
400
|
+
|
|
401
|
+
export const getServer = createNextServerLoader(async () => {
|
|
402
|
+
const { providers } = await import("./providers");
|
|
403
|
+
const { DeliverNotificationJob } = await import("./notifications");
|
|
404
|
+
|
|
405
|
+
return createNextServer({
|
|
406
|
+
// ...
|
|
407
|
+
providers: [
|
|
408
|
+
...providers,
|
|
409
|
+
createQueuedNotificationsProvider({
|
|
410
|
+
deliveryJob: DeliverNotificationJob,
|
|
411
|
+
}),
|
|
412
|
+
],
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
The delivery job defaults to three attempts with exponential backoff. The
|
|
418
|
+
queued dispatcher validates notification payloads before enqueueing and uses
|
|
419
|
+
the app's existing `jobs` port, so the same setup works with direct job
|
|
420
|
+
providers or `createOutboxJobDispatcher(...)`.
|
|
295
421
|
|
|
296
422
|
## Entitlements
|
|
297
423
|
|
|
@@ -499,6 +625,15 @@ can compute the digest before `prepare`. Use `verifyFile(...)` for app-owned
|
|
|
499
625
|
scanning, moderation, and quarantine decisions that run after the object exists
|
|
500
626
|
in storage and before `onComplete(...)`.
|
|
501
627
|
|
|
628
|
+
`createUploadRouter(...)` bounds JSON request bodies and server-handled
|
|
629
|
+
multipart bodies. Multipart limits are enforced against both a declared
|
|
630
|
+
`Content-Length` and the bytes actually read, so chunked requests cannot bypass
|
|
631
|
+
`limits.multipartMaxBytes` before `formData()` parsing.
|
|
632
|
+
|
|
633
|
+
Upload route failures use Beignet's flat `{ code, message, details? }` error
|
|
634
|
+
body. The typed upload client maps that response to `UploadClientError` with
|
|
635
|
+
the same code, status, and details.
|
|
636
|
+
|
|
502
637
|
## Webhooks
|
|
503
638
|
|
|
504
639
|
Use `@beignet/core/webhooks` for provider-neutral inbound webhook definitions,
|
|
@@ -534,8 +669,8 @@ export const issueWebhook = defineWebhook("issues.provider", {
|
|
|
534
669
|
|
|
535
670
|
Use `createMemoryWebhookVerifier(...)` in tests and `createWebhookRoute(...)`
|
|
536
671
|
from `@beignet/next` to expose raw-body webhook routes in Next.js apps. Use a
|
|
537
|
-
provider package such as `@beignet/
|
|
538
|
-
`@beignet/
|
|
672
|
+
provider package such as `@beignet/webhooks-github` or
|
|
673
|
+
`@beignet/webhooks-stripe` when a vendor has signature semantics beyond
|
|
539
674
|
the generic HMAC verifier. For billing flows backed by `ctx.ports.payments`,
|
|
540
675
|
use `@beignet/core/payments` with `createPaymentWebhookRoute(...)` from
|
|
541
676
|
`@beignet/next` instead of a generic webhook catalog.
|
|
@@ -575,7 +710,7 @@ without importing provider implementation code.
|
|
|
575
710
|
"requiredTables": ["cache_entries"],
|
|
576
711
|
"registration": {
|
|
577
712
|
"required": true,
|
|
578
|
-
"tokens": ["
|
|
713
|
+
"tokens": ["createCacheProvider"]
|
|
579
714
|
},
|
|
580
715
|
"watchers": ["cache"]
|
|
581
716
|
}
|
|
@@ -730,10 +865,14 @@ may only be registered once, contract names must be unique across the route
|
|
|
730
865
|
registry because typed clients, OpenAPI operations, and devtools key on them,
|
|
731
866
|
and an introspectable `.pathParams(...)` object schema must declare exactly the
|
|
732
867
|
`:param` keys from the path template. Mismatches fail server startup with the
|
|
733
|
-
contract name and path.
|
|
868
|
+
contract name and path. Opaque Standard Schemas skip that registration-time key
|
|
869
|
+
comparison; OpenAPI falls back to required string parameters from the literal
|
|
870
|
+
path template unless a custom schema introspector is supplied. At dispatch
|
|
871
|
+
time, a request that matches a registered
|
|
734
872
|
path with an unregistered method receives a framework-owned `405
|
|
735
873
|
METHOD_NOT_ALLOWED` response with an `Allow` header listing the registered
|
|
736
|
-
methods
|
|
874
|
+
methods. `GET` routes also serve `HEAD` when no explicit `HEAD` route exists;
|
|
875
|
+
explicit `HEAD` routes take precedence, and every `HEAD` response is bodyless.
|
|
737
876
|
|
|
738
877
|
### Runtime integrity
|
|
739
878
|
|
|
@@ -794,6 +933,10 @@ the returned handler at the route's own path.
|
|
|
794
933
|
Use `.headers(...)` for request headers that are part of the endpoint contract. Declare header keys in lowercase; server and client runtime matching is case-insensitive.
|
|
795
934
|
|
|
796
935
|
Request bodies are supported for `POST`, `PUT`, and `PATCH` contracts only.
|
|
936
|
+
JSON bodies require `Content-Type: application/json`; otherwise the runtime
|
|
937
|
+
passes the body to validation as text. When a missing content type accompanies
|
|
938
|
+
a valid JSON object or array that fails validation, the framework-owned error
|
|
939
|
+
includes a targeted `details.hint` without changing the response code.
|
|
797
940
|
|
|
798
941
|
If you do not pass `name`, Beignet generates one from the HTTP method and full path:
|
|
799
942
|
|
|
@@ -841,7 +984,7 @@ import { createTestContextFactory, createTestPorts } from "@beignet/core/testing
|
|
|
841
984
|
import {
|
|
842
985
|
createTestTenant,
|
|
843
986
|
createTestUserActor,
|
|
844
|
-
} from "@beignet/core/
|
|
987
|
+
} from "@beignet/core/testing";
|
|
845
988
|
|
|
846
989
|
const fixture = createTestPorts<AppContext["ports"]>({
|
|
847
990
|
base: appPorts,
|
|
@@ -1037,12 +1180,13 @@ Use `installProviderForTest(...)` to run provider setup against test ports
|
|
|
1037
1180
|
without hand-rolling setup, port merge, and lifecycle plumbing:
|
|
1038
1181
|
|
|
1039
1182
|
```ts
|
|
1183
|
+
import type { CachePort } from "@beignet/core/ports";
|
|
1040
1184
|
import { installProviderForTest } from "@beignet/core/testing";
|
|
1185
|
+
import { createRedisCacheProvider } from "@beignet/provider-cache-redis";
|
|
1041
1186
|
|
|
1042
1187
|
const { ports, result, start, stop } = await installProviderForTest(
|
|
1043
|
-
|
|
1188
|
+
createRedisCacheProvider(),
|
|
1044
1189
|
{
|
|
1045
|
-
ports: { devtools },
|
|
1046
1190
|
config: { URL: "redis://localhost:6379" },
|
|
1047
1191
|
},
|
|
1048
1192
|
);
|
|
@@ -1123,7 +1267,7 @@ ORM table objects, or provider SDKs directly.
|
|
|
1123
1267
|
|
|
1124
1268
|
### Port testing helpers
|
|
1125
1269
|
|
|
1126
|
-
Use `@beignet/core/
|
|
1270
|
+
Use `@beignet/core/testing` when tests need stable actor, tenant,
|
|
1127
1271
|
authorization, or audit assertions:
|
|
1128
1272
|
|
|
1129
1273
|
```ts
|
|
@@ -1133,7 +1277,7 @@ import {
|
|
|
1133
1277
|
createTestActivityContext,
|
|
1134
1278
|
createTestTenant,
|
|
1135
1279
|
createTestUserActor,
|
|
1136
|
-
} from "@beignet/core/
|
|
1280
|
+
} from "@beignet/core/testing";
|
|
1137
1281
|
|
|
1138
1282
|
const activity = createTestActivityContext({
|
|
1139
1283
|
actor: createTestUserActor("user_1", { role: "admin" }),
|
|
@@ -1187,7 +1331,7 @@ import {
|
|
|
1187
1331
|
createRecordingEventBus,
|
|
1188
1332
|
createRecordingJobDispatcher,
|
|
1189
1333
|
createRecordingProviderInstrumentation,
|
|
1190
|
-
} from "@beignet/core/
|
|
1334
|
+
} from "@beignet/core/testing";
|
|
1191
1335
|
import { drainOutbox } from "@beignet/core/outbox";
|
|
1192
1336
|
import { createProviderInstrumentation } from "@beignet/core/providers";
|
|
1193
1337
|
|
|
@@ -1468,6 +1612,11 @@ a transaction-scoped `tx.idempotency` port from the app Unit of Work so
|
|
|
1468
1612
|
reservation, business writes, audit records, domain-event records, and
|
|
1469
1613
|
idempotency completion commit together.
|
|
1470
1614
|
|
|
1615
|
+
`runIdempotently(...)` releases a reservation only when the protected work
|
|
1616
|
+
throws. If the work succeeds but `complete(...)` fails, the reservation stays
|
|
1617
|
+
in progress and the completion error is rethrown so an immediate retry cannot
|
|
1618
|
+
repeat the successful work.
|
|
1619
|
+
|
|
1471
1620
|
### Outbox
|
|
1472
1621
|
|
|
1473
1622
|
Use `@beignet/core/outbox` when events or jobs must be recorded in the same
|
|
@@ -1518,6 +1667,11 @@ await drainOutbox({
|
|
|
1518
1667
|
The outbox is at-least-once delivery. Use idempotent listeners or jobs when a
|
|
1519
1668
|
duplicate delivery would be harmful.
|
|
1520
1669
|
|
|
1670
|
+
When an inline dispatcher exposes Beignet's single-attempt delivery hook, an
|
|
1671
|
+
`onError` observer is still notified but cannot swallow the failure. The outbox
|
|
1672
|
+
retains retry and dead-letter ownership instead of marking the message
|
|
1673
|
+
delivered.
|
|
1674
|
+
|
|
1521
1675
|
Use `OutboxAdminPort` only from operational contexts. It lets `beignet outbox`
|
|
1522
1676
|
list, show, requeue, purge dead-lettered rows, and prune delivered rows without
|
|
1523
1677
|
exposing those destructive operations to transaction-scoped use cases.
|
|
@@ -1534,7 +1688,7 @@ import { createInlineScheduleRunner } from "@beignet/core/schedules";
|
|
|
1534
1688
|
|
|
1535
1689
|
const runner = createInlineScheduleRunner<AppContext>({
|
|
1536
1690
|
ctx,
|
|
1537
|
-
instrumentation: ctx.ports
|
|
1691
|
+
instrumentation: ctx.ports,
|
|
1538
1692
|
instrumentationContext: {
|
|
1539
1693
|
requestId: ctx.requestId,
|
|
1540
1694
|
traceId: ctx.traceId,
|
|
@@ -1545,9 +1699,10 @@ await runner.run(SendDailyDigestSchedule, { source: "vercel-cron" });
|
|
|
1545
1699
|
```
|
|
1546
1700
|
|
|
1547
1701
|
`instrumentationContext` attaches request correlation fields to recorded
|
|
1548
|
-
events.
|
|
1549
|
-
|
|
1550
|
-
|
|
1702
|
+
events. The shared provider instrumentation helper applies watcher checks,
|
|
1703
|
+
redaction, and sink-failure isolation. Lifecycle hook failures still reach
|
|
1704
|
+
`onHookError` when provided. Handler failures reject `runner.run(...)` after
|
|
1705
|
+
`onError` runs so trigger hosts can retry.
|
|
1551
1706
|
|
|
1552
1707
|
### Contract metadata and route hooks
|
|
1553
1708
|
|
|
@@ -1580,8 +1735,13 @@ install `createRateLimitHooks(...)` and `createIdempotencyHooks(...)` where the
|
|
|
1580
1735
|
server is composed. Use route hooks for runtime enforcement of route-specific
|
|
1581
1736
|
policy where the route is wired:
|
|
1582
1737
|
|
|
1738
|
+
Bind route declarations to the app context once in `lib/routes.ts` with
|
|
1739
|
+
`createRoutes<AppContext>()`, then import the resulting builders in feature
|
|
1740
|
+
route files.
|
|
1741
|
+
|
|
1583
1742
|
```ts
|
|
1584
|
-
import { createAuthHooks
|
|
1743
|
+
import { createAuthHooks } from "@beignet/core/server";
|
|
1744
|
+
import { defineRouteGroup } from "@/lib/routes";
|
|
1585
1745
|
import type { AppContext } from "@/app-context";
|
|
1586
1746
|
|
|
1587
1747
|
const auth = createAuthHooks<AppContext>()({
|
|
@@ -1590,7 +1750,7 @@ const auth = createAuthHooks<AppContext>()({
|
|
|
1590
1750
|
},
|
|
1591
1751
|
});
|
|
1592
1752
|
|
|
1593
|
-
export const messageRoutes = defineRouteGroup
|
|
1753
|
+
export const messageRoutes = defineRouteGroup({
|
|
1594
1754
|
name: "messages",
|
|
1595
1755
|
routes: [
|
|
1596
1756
|
{
|
|
@@ -1612,7 +1772,7 @@ contract's sole request schema by reference, the server skips the use case's
|
|
|
1612
1772
|
input re-parse — one schema, one parse.
|
|
1613
1773
|
|
|
1614
1774
|
Use `{ contract, handle }` as the escape hatch for response headers,
|
|
1615
|
-
streaming, and multi-status responses. `defineRoute
|
|
1775
|
+
streaming, and multi-status responses. `defineRoute` remains
|
|
1616
1776
|
available for full handlers that read hook-added `ctx` fields.
|
|
1617
1777
|
|
|
1618
1778
|
When credentials live in request headers, declare a `headers` schema on the
|
|
@@ -1806,6 +1966,10 @@ port is installed, it also creates an active child span. Pass
|
|
|
1806
1966
|
`instrumentation: false` to opt out of instrumentation events; tracing is
|
|
1807
1967
|
controlled by whether the app installs `ports.tracing`.
|
|
1808
1968
|
|
|
1969
|
+
App-owned `onRun` observers are best-effort. Synchronous throws and rejected
|
|
1970
|
+
observer promises are ignored so instrumentation cannot fail a use case or
|
|
1971
|
+
replace its original error.
|
|
1972
|
+
|
|
1809
1973
|
`createInstrumentedAuditLog({ audit, instrumentation })` from
|
|
1810
1974
|
`@beignet/core/ports` writes durable audit entries first and mirrors sanitized
|
|
1811
1975
|
audit activity into the resolved instrumentation sink.
|
|
@@ -1867,12 +2031,23 @@ export const getTodo = todos
|
|
|
1867
2031
|
});
|
|
1868
2032
|
```
|
|
1869
2033
|
|
|
2034
|
+
`.openapi(...)` and `.meta({ openapi: ... })` share the same shallow merge
|
|
2035
|
+
semantics. OpenAPI fields from contract groups and earlier calls are preserved,
|
|
2036
|
+
while a later value replaces the same field. Structured fields such as
|
|
2037
|
+
`responses` are replaced as a whole rather than deep-merged. Prefer
|
|
2038
|
+
`.openapi(...)` for operation metadata; use `.meta(...)` when composing it with
|
|
2039
|
+
other metadata conventions.
|
|
2040
|
+
|
|
1870
2041
|
Use `requestBody`, `responses`, and `parameters` overrides when an operation
|
|
1871
2042
|
needs non-JSON media such as multipart uploads, binary downloads, event streams,
|
|
1872
2043
|
or cookie parameters. `contractsToOpenAPI(...)` accepts `schemaConverters` for
|
|
1873
2044
|
non-Zod Standard Schema libraries; custom converters run before Beignet's
|
|
1874
2045
|
default Zod converter.
|
|
1875
2046
|
|
|
2047
|
+
Descriptions attached before `.optional()` are preserved on generated query
|
|
2048
|
+
and header parameters, matching descriptions attached to the outer optional
|
|
2049
|
+
schema.
|
|
2050
|
+
|
|
1876
2051
|
### Schema introspection
|
|
1877
2052
|
|
|
1878
2053
|
Contracts expose their schemas for runtime introspection:
|
|
@@ -1883,7 +2058,6 @@ getTodo.schema.query; // Query parameter schema
|
|
|
1883
2058
|
getTodo.schema.body; // Request body schema
|
|
1884
2059
|
getTodo.schema.responses; // Response schemas by status code
|
|
1885
2060
|
getTodo.path; // "/api/todos/:id"
|
|
1886
|
-
getTodo.pathTemplate; // "/api/todos/:id" (alias)
|
|
1887
2061
|
getTodo.method; // "GET"
|
|
1888
2062
|
getTodo.metadata; // { auth: "required", ... }
|
|
1889
2063
|
```
|
|
@@ -1930,8 +2104,8 @@ standard error envelope.
|
|
|
1930
2104
|
| `.body(schema)` | Define request body schema |
|
|
1931
2105
|
| `.responses({ ... })` | Define or merge response schemas by status code |
|
|
1932
2106
|
| `.errors({ ... })` | Declare route-owned catalog errors using Beignet's standard error envelope; merges with group and earlier declarations |
|
|
1933
|
-
| `.meta(metadata)` |
|
|
1934
|
-
| `.openapi(options)` |
|
|
2107
|
+
| `.meta(metadata)` | Merge custom metadata; nested `openapi` fields merge one level deep |
|
|
2108
|
+
| `.openapi(options)` | Merge OpenAPI metadata (summary, tags, etc.) |
|
|
1935
2109
|
|
|
1936
2110
|
## Standard Schema support
|
|
1937
2111
|
|
|
@@ -1941,7 +2115,10 @@ This package works with any [Standard Schema](https://github.com/standard-schema
|
|
|
1941
2115
|
- **Valibot** - Lightweight alternative to Zod
|
|
1942
2116
|
- **ArkType** - High-performance runtime validation
|
|
1943
2117
|
|
|
1944
|
-
OpenAPI generation
|
|
2118
|
+
OpenAPI generation includes a Zod converter and introspector by default. Other
|
|
2119
|
+
Standard Schema libraries can supply `schemaConverters` and a
|
|
2120
|
+
`schemaIntrospector`; opaque path parameter schemas degrade to required string
|
|
2121
|
+
parameters derived from the contract path.
|
|
1945
2122
|
|
|
1946
2123
|
## Related packages
|
|
1947
2124
|
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
import { type ProviderInstrumentationTarget } from "../providers/index.js";
|
|
3
|
+
import type { TracingPort } from "../tracing/index.js";
|
|
4
|
+
/** Any Standard Schema compatible validator. */
|
|
5
|
+
export type AgentCapabilitySchema = StandardSchemaV1<unknown, unknown>;
|
|
6
|
+
/** Value or promise of that value. */
|
|
7
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
8
|
+
/** Infer the input accepted by a capability schema. */
|
|
9
|
+
export type InferAgentCapabilitySchemaInput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferInput<Schema>;
|
|
10
|
+
/** Infer the parsed output produced by a capability schema. */
|
|
11
|
+
export type InferAgentCapabilitySchemaOutput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema>;
|
|
12
|
+
/** A typed action that an authenticated agent transport may expose. */
|
|
13
|
+
export interface AgentCapabilityDef<Name extends string = string, Input extends AgentCapabilitySchema = AgentCapabilitySchema, Output extends AgentCapabilitySchema = AgentCapabilitySchema, Ctx = unknown, Principal = unknown> {
|
|
14
|
+
readonly kind: "agentCapability";
|
|
15
|
+
readonly name: Name;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly input: Input;
|
|
18
|
+
readonly output: Output;
|
|
19
|
+
readonly handle: (args: {
|
|
20
|
+
capability: AgentCapabilityDef<Name, Input, Output, Ctx, Principal>;
|
|
21
|
+
ctx: Ctx;
|
|
22
|
+
principal: Principal;
|
|
23
|
+
input: InferAgentCapabilitySchemaOutput<Input>;
|
|
24
|
+
}) => MaybePromise<InferAgentCapabilitySchemaInput<Output>>;
|
|
25
|
+
}
|
|
26
|
+
/** Broad capability definition shape tied to one context and principal. */
|
|
27
|
+
export interface AgentCapabilityFor<Ctx, Principal> {
|
|
28
|
+
readonly kind: "agentCapability";
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly description: string;
|
|
31
|
+
readonly input: AgentCapabilitySchema;
|
|
32
|
+
readonly output: AgentCapabilitySchema;
|
|
33
|
+
readonly handle: (args: {
|
|
34
|
+
capability: never;
|
|
35
|
+
ctx: Ctx;
|
|
36
|
+
principal: Principal;
|
|
37
|
+
input: never;
|
|
38
|
+
}) => MaybePromise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
/** Broad capability definition shape used by registries and adapters. */
|
|
41
|
+
export type AnyAgentCapabilityDef = AgentCapabilityFor<never, never>;
|
|
42
|
+
/** Infer a capability's application context. */
|
|
43
|
+
export type AgentCapabilityContext<Capability extends AnyAgentCapabilityDef> = Capability extends {
|
|
44
|
+
handle(args: {
|
|
45
|
+
ctx: infer Ctx;
|
|
46
|
+
}): unknown;
|
|
47
|
+
} ? Ctx : never;
|
|
48
|
+
/** Infer a capability's verified principal. */
|
|
49
|
+
export type AgentCapabilityPrincipal<Capability extends AnyAgentCapabilityDef> = Capability extends {
|
|
50
|
+
handle(args: {
|
|
51
|
+
principal: infer Principal;
|
|
52
|
+
}): unknown;
|
|
53
|
+
} ? Principal : never;
|
|
54
|
+
/** Infer a capability's raw input. */
|
|
55
|
+
export type AgentCapabilityInput<Capability extends AnyAgentCapabilityDef> = InferAgentCapabilitySchemaInput<Capability["input"]>;
|
|
56
|
+
/** Infer a capability's validated output. */
|
|
57
|
+
export type AgentCapabilityOutput<Capability extends AnyAgentCapabilityDef> = InferAgentCapabilitySchemaOutput<Capability["output"]>;
|
|
58
|
+
/** Options accepted by `defineAgentCapability(...)`. */
|
|
59
|
+
export interface DefineAgentCapabilityOptions<Name extends string, Input extends AgentCapabilitySchema, Output extends AgentCapabilitySchema, Ctx, Principal> {
|
|
60
|
+
description: string;
|
|
61
|
+
input: Input;
|
|
62
|
+
output: Output;
|
|
63
|
+
handle(args: {
|
|
64
|
+
capability: AgentCapabilityDef<Name, Input, Output, Ctx, Principal>;
|
|
65
|
+
ctx: Ctx;
|
|
66
|
+
principal: Principal;
|
|
67
|
+
input: InferAgentCapabilitySchemaOutput<Input>;
|
|
68
|
+
}): MaybePromise<InferAgentCapabilitySchemaInput<Output>>;
|
|
69
|
+
}
|
|
70
|
+
/** Context-bound capability definition helpers. */
|
|
71
|
+
export interface AgentCapabilities<Ctx, Principal> {
|
|
72
|
+
defineAgentCapability<const Name extends string, Input extends AgentCapabilitySchema, Output extends AgentCapabilitySchema>(name: Name, options: DefineAgentCapabilityOptions<Name, Input, Output, Ctx, Principal>): AgentCapabilityDef<Name, Input, Output, Ctx, Principal>;
|
|
73
|
+
defineAgentCapabilityRegistry<const Definitions extends readonly AgentCapabilityFor<Ctx, Principal>[]>(definitions: Definitions): AgentCapabilityRegistry<Definitions>;
|
|
74
|
+
}
|
|
75
|
+
/** Bind application context and principal types once for capability definitions. */
|
|
76
|
+
export declare function createAgentCapabilities<Ctx, Principal>(): AgentCapabilities<Ctx, Principal>;
|
|
77
|
+
/** Error thrown when a capability registry is ambiguous. */
|
|
78
|
+
export declare class AgentCapabilityRegistryError extends Error {
|
|
79
|
+
constructor(message: string);
|
|
80
|
+
}
|
|
81
|
+
/** Registered capability definitions available to execution adapters. */
|
|
82
|
+
export interface AgentCapabilityRegistry<Definitions extends readonly AnyAgentCapabilityDef[] = readonly AnyAgentCapabilityDef[]> {
|
|
83
|
+
readonly definitions: Definitions;
|
|
84
|
+
get(name: string): Definitions[number] | undefined;
|
|
85
|
+
}
|
|
86
|
+
/** Stable capability execution failure categories. */
|
|
87
|
+
export type AgentCapabilityErrorCode = "unknown_capability" | "invalid_input" | "invalid_output" | "execution_failed";
|
|
88
|
+
/** Error raised by capability lookup, validation, or execution. */
|
|
89
|
+
export declare class AgentCapabilityError extends Error {
|
|
90
|
+
readonly code: AgentCapabilityErrorCode;
|
|
91
|
+
readonly capabilityName: string;
|
|
92
|
+
readonly issues?: readonly StandardSchemaV1.Issue[];
|
|
93
|
+
readonly cause?: unknown;
|
|
94
|
+
constructor(args: {
|
|
95
|
+
code: AgentCapabilityErrorCode;
|
|
96
|
+
capabilityName: string;
|
|
97
|
+
message: string;
|
|
98
|
+
issues?: readonly StandardSchemaV1.Issue[];
|
|
99
|
+
cause?: unknown;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** A parsed invocation passed to the app-owned context resolver. */
|
|
103
|
+
export type AgentCapabilityContextRequest<Definitions extends readonly AnyAgentCapabilityDef[], Principal> = {
|
|
104
|
+
[Capability in Definitions[number] as Capability["name"]]: {
|
|
105
|
+
capability: Capability;
|
|
106
|
+
name: Capability["name"];
|
|
107
|
+
principal: Principal;
|
|
108
|
+
input: InferAgentCapabilitySchemaOutput<Capability["input"]>;
|
|
109
|
+
};
|
|
110
|
+
}[Definitions[number]["name"]];
|
|
111
|
+
/** Stage reached by an agent capability attempt. */
|
|
112
|
+
export type AgentCapabilityRunStage = "lookup" | "input" | "authorization" | "context" | "handler" | "output";
|
|
113
|
+
/** Lifecycle event observed around a capability attempt. */
|
|
114
|
+
export interface AgentCapabilityRunEvent<Ctx, Principal> {
|
|
115
|
+
name: string;
|
|
116
|
+
phase: "start" | "end" | "error";
|
|
117
|
+
stage: AgentCapabilityRunStage;
|
|
118
|
+
ctx?: Ctx;
|
|
119
|
+
principal: Principal;
|
|
120
|
+
durationMs?: number;
|
|
121
|
+
error?: unknown;
|
|
122
|
+
}
|
|
123
|
+
/** Best-effort lifecycle observer for capability execution. */
|
|
124
|
+
export type AgentCapabilityHook<Ctx, Principal> = (event: AgentCapabilityRunEvent<Ctx, Principal>) => MaybePromise<void>;
|
|
125
|
+
/** Options for a capability executor. */
|
|
126
|
+
export interface CreateAgentCapabilityExecutorOptions<Ctx, Principal, Definitions extends readonly AnyAgentCapabilityDef[]> {
|
|
127
|
+
registry: AgentCapabilityRegistry<Definitions>;
|
|
128
|
+
createContext(request: AgentCapabilityContextRequest<Definitions, Principal>): MaybePromise<Ctx>;
|
|
129
|
+
hooks?: readonly AgentCapabilityHook<Ctx, Principal>[];
|
|
130
|
+
/** Independent target used to observe failures before context exists. */
|
|
131
|
+
instrumentation?: ProviderInstrumentationTarget;
|
|
132
|
+
tracing?: TracingPort;
|
|
133
|
+
}
|
|
134
|
+
/** Raw dynamic invocation accepted by protocol adapters. */
|
|
135
|
+
export interface DynamicAgentCapabilityInvocation<Principal> {
|
|
136
|
+
name: string;
|
|
137
|
+
principal: Principal;
|
|
138
|
+
input: unknown;
|
|
139
|
+
/**
|
|
140
|
+
* Transport-owned authorization against the exact parsed input that will be
|
|
141
|
+
* passed to context construction and the capability handler.
|
|
142
|
+
*/
|
|
143
|
+
authorize?(request: DynamicAgentCapabilityAuthorization<Principal>): MaybePromise<void>;
|
|
144
|
+
}
|
|
145
|
+
/** Parsed invocation exposed to a dynamic transport authorization callback. */
|
|
146
|
+
export interface DynamicAgentCapabilityAuthorization<Principal> {
|
|
147
|
+
capability: AnyAgentCapabilityDef;
|
|
148
|
+
name: string;
|
|
149
|
+
principal: Principal;
|
|
150
|
+
input: unknown;
|
|
151
|
+
}
|
|
152
|
+
/** Typed and dynamic execution surface for one capability registry. */
|
|
153
|
+
export interface AgentCapabilityExecutor<Principal, Definitions extends readonly AnyAgentCapabilityDef[]> {
|
|
154
|
+
execute<Name extends Definitions[number]["name"]>(args: {
|
|
155
|
+
name: Name;
|
|
156
|
+
principal: Principal;
|
|
157
|
+
input: AgentCapabilityInput<Extract<Definitions[number], {
|
|
158
|
+
name: Name;
|
|
159
|
+
}>>;
|
|
160
|
+
}): Promise<AgentCapabilityOutput<Extract<Definitions[number], {
|
|
161
|
+
name: Name;
|
|
162
|
+
}>>>;
|
|
163
|
+
executeDynamic(args: DynamicAgentCapabilityInvocation<Principal>): Promise<unknown>;
|
|
164
|
+
}
|
|
165
|
+
/** Create a validated, traced executor for a capability registry. */
|
|
166
|
+
export declare function createAgentCapabilityExecutor<const Definitions extends readonly AnyAgentCapabilityDef[]>(options: CreateAgentCapabilityExecutorOptions<AgentCapabilityContext<Definitions[number]>, AgentCapabilityPrincipal<Definitions[number]>, Definitions>): AgentCapabilityExecutor<AgentCapabilityPrincipal<Definitions[number]>, Definitions>;
|
|
167
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-capabilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,gDAAgD;AAChD,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEvE,sCAAsC;AACtC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,uDAAuD;AACvD,MAAM,MAAM,+BAA+B,CAAC,MAAM,SAAS,gBAAgB,IACzE,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAEtC,+DAA+D;AAC/D,MAAM,MAAM,gCAAgC,CAAC,MAAM,SAAS,gBAAgB,IAC1E,gBAAg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