kizunajs 2.0.0-beta.2 → 2.0.0-beta.21

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 (81) hide show
  1. package/README.md +3 -2
  2. package/dist/{adapter-CZW-unqX.mjs → adapter-BSqNrxhq.mjs} +522 -104
  3. package/dist/adapter-C3WYdSfx.d.cts +2754 -0
  4. package/dist/{adapter-DDR_yo9L.cjs → adapter-ClaFZoab.cjs} +638 -196
  5. package/dist/adapter-D4bTPElA.d.mts +2754 -0
  6. package/dist/adapter.cjs +37 -29
  7. package/dist/adapter.d.cts +3 -5
  8. package/dist/adapter.d.mts +3 -5
  9. package/dist/adapter.mjs +5 -5
  10. package/dist/{error-response-C8Ragjcd.cjs → error-response-C9ymqSU4.cjs} +25 -5
  11. package/dist/{error-response-C839d8By.mjs → error-response-CNQaKVYd.mjs} +20 -6
  12. package/dist/{security-scheme-BrszwGD5.d.cts → error-response-NoOGdh8H.d.mts} +151 -24
  13. package/dist/{security-scheme-D3nb4XKj.d.mts → error-response-YbkRMKno.d.cts} +151 -24
  14. package/dist/generator.cjs +190 -95
  15. package/dist/generator.d.cts +189 -28
  16. package/dist/generator.d.mts +189 -28
  17. package/dist/generator.mjs +151 -60
  18. package/dist/index.cjs +159 -84
  19. package/dist/index.d.cts +193 -253
  20. package/dist/index.d.mts +193 -253
  21. package/dist/index.mjs +112 -38
  22. package/dist/jobs-entry.cjs +12 -11
  23. package/dist/jobs-entry.d.cts +1 -1
  24. package/dist/jobs-entry.d.mts +1 -1
  25. package/dist/jobs-entry.mjs +3 -2
  26. package/dist/plugin-Dw-yCjTY.cjs +233 -0
  27. package/dist/{cache-CLN5y0Xp.mjs → plugin-server-BztlE1fz.mjs} +188 -49
  28. package/dist/{cache-BgohRj0i.cjs → plugin-server-kUsK7thV.cjs} +238 -93
  29. package/dist/plugin-xxCxibmu.mjs +138 -0
  30. package/dist/plugin.cjs +8 -72
  31. package/dist/plugin.d.cts +3 -3
  32. package/dist/plugin.d.mts +3 -3
  33. package/dist/plugin.mjs +2 -68
  34. package/dist/{protected-resource-metadata-CA0v5cjg.d.mts → protected-resource-metadata-B9hMFQ9N.d.cts} +1 -1
  35. package/dist/{protected-resource-metadata-Cprrv0mt.d.cts → protected-resource-metadata-CfBVsqIk.d.mts} +1 -1
  36. package/dist/{schemas-C56no6bv.cjs → schemas-DNPVDvkd.cjs} +28 -1
  37. package/dist/{schemas-CJQcc97N.mjs → schemas-HW2FDsvz.mjs} +23 -2
  38. package/dist/schemas.cjs +3 -2
  39. package/dist/schemas.d.cts +24 -3
  40. package/dist/schemas.d.mts +24 -3
  41. package/dist/schemas.mjs +3 -3
  42. package/package.json +1 -1
  43. package/src/adapter.ts +245 -29
  44. package/src/api-definition.ts +12 -16
  45. package/src/api.ts +7 -3
  46. package/src/brand.ts +29 -0
  47. package/src/config.ts +51 -10
  48. package/src/configured.ts +13 -6
  49. package/src/define-config.ts +118 -39
  50. package/src/generator.ts +363 -46
  51. package/src/group-routes.ts +106 -0
  52. package/src/groups.ts +140 -0
  53. package/src/handler-pipeline.ts +78 -19
  54. package/src/index.ts +15 -6
  55. package/src/job-runner.ts +5 -0
  56. package/src/job-transport.ts +3 -3
  57. package/src/job.ts +8 -6
  58. package/src/jobs-dev-runner.ts +6 -0
  59. package/src/jobs.ts +61 -8
  60. package/src/kizuna.ts +56 -33
  61. package/src/plugin-server.ts +129 -19
  62. package/src/plugin.ts +269 -127
  63. package/src/routes.ts +80 -32
  64. package/src/schemas.ts +1 -0
  65. package/src/tool-answer.ts +21 -0
  66. package/src/tool-definitions.ts +166 -0
  67. package/src/tool-events.ts +90 -18
  68. package/src/tool-records.ts +11 -3
  69. package/src/tool-runner.ts +298 -0
  70. package/src/types.ts +90 -24
  71. package/src/zod-internals.ts +22 -5
  72. package/src/zod-meta.ts +7 -2
  73. package/dist/adapter-BGfMqEkM.d.cts +0 -563
  74. package/dist/adapter-Ci3cfcoT.d.mts +0 -563
  75. package/dist/api-definition-BHnh15zD.d.mts +0 -803
  76. package/dist/api-definition-DQj-ewHy.d.cts +0 -803
  77. package/dist/error-response-BBGSdgYw.d.mts +0 -67
  78. package/dist/error-response-Do38sr-9.d.cts +0 -67
  79. package/dist/plugin-Cz0kn6Lk.d.mts +0 -830
  80. package/dist/plugin-DhKvx_T0.d.cts +0 -830
  81. package/src/tags.ts +0 -67
@@ -1,830 +0,0 @@
1
- import { F as HandlerContextBrand, H as ResponseHeaders, J as Routes, L as Method, M as GuardStatus, O as AutoResponsesBrand, P as HANDLER_CONTEXT_BRAND, Q as StreamResponseDefinition, T as AUTO_RESPONSES_BRAND, W as RouteDefinition, Z as StreamDefinition, a as SecurityScheme, d as CatalogOf, f as GrantNamesOf, nt as ProblemDetails, r as OAuthFlows, rt as StripProblemEnvelope, t as ContextOf, v as RoleNamesOf, w as AUTO_GUARD_WRITTEN_BRAND, y as Roles } from "./security-scheme-BrszwGD5.cjs";
2
- import { z } from "zod";
3
-
4
- //#region src/identity.d.ts
5
- /**
6
- * The token a `bearer`, `oauth2`, or `openIdConnect` method extracts from the
7
- * `Authorization` header.
8
- */
9
- interface BearerCredential {
10
- token: string;
11
- }
12
- /**
13
- * The username and password a `basic` method decodes from the
14
- * `Authorization: Basic <base64>` header.
15
- */
16
- interface BasicCredential {
17
- username: string;
18
- password: string;
19
- }
20
- /**
21
- * The value an `apiKey` method reads from the header, query parameter, or cookie
22
- * the identity named, with `in`/`name` echoing where it came from.
23
- *
24
- * @example
25
- * // for k.identity.apiKey({ name: 'x-workspace-token', in: 'header' }):
26
- * // { in: 'header'; name: 'x-workspace-token'; value: string }
27
- */
28
- interface ApiKeyCredential<In extends 'header' | 'query' | 'cookie' = 'header' | 'query' | 'cookie', Name extends string = string> {
29
- in: In;
30
- name: Name;
31
- value: string;
32
- }
33
- /**
34
- * The credential a guard receives, keyed by the identity's authentication method.
35
- * A guard destructures the one key its identity declares, `{ bearer }`,
36
- * `{ apiKey }`, `{ basic }`, `{ oauth2 }`, or `{ openIdConnect }`. The value is
37
- * `null` when the request carried no such credential.
38
- */
39
- type Credential = {
40
- bearer: BearerCredential | null;
41
- } | {
42
- oauth2: BearerCredential | null;
43
- } | {
44
- openIdConnect: BearerCredential | null;
45
- } | {
46
- basic: BasicCredential | null;
47
- } | {
48
- apiKey: ApiKeyCredential | null;
49
- };
50
- /**
51
- * The empty credential a `custom` identity carries. Its guard receives no
52
- * credential key and reads the credential itself (e.g. `params.token`).
53
- */
54
- type NoCredential = Record<never, never>;
55
- declare const CREDENTIAL: unique symbol;
56
- /**
57
- * An authenticated caller, defined with the `k.identity` builders. Extends
58
- * {@link SecurityScheme} with what its callers hold and the credential its
59
- * authentication method extracts from the request.
60
- */
61
- interface Identity<ContextSchema extends z.ZodType | undefined = z.ZodType | undefined, RolesType extends Roles | undefined = Roles | undefined, CredentialType extends Credential | NoCredential = Credential, ParamsSchema extends z.ZodType | undefined = z.ZodType | undefined> extends SecurityScheme<ContextSchema> {
62
- /**
63
- * The path parameters this identity's guard reads. A route whose `auth`
64
- * names the identity has to carry them, and the guard receives them typed.
65
- */
66
- readonly params: ParamsSchema;
67
- /**
68
- * The roles this identity's callers hold. The guard returns `role`.
69
- */
70
- readonly roles: RolesType;
71
- /**
72
- * Phantom marker carrying the {@link Credential} the method extracts. Never
73
- * present at runtime.
74
- */
75
- readonly [CREDENTIAL]?: CredentialType;
76
- }
77
- /**
78
- * The {@link Credential} an identity's authentication method extracts and passes
79
- * to its guard, a single discriminated member, e.g. `{ apiKey: { in; name;
80
- * value } | null }` for an `apiKey` identity.
81
- */
82
- type CredentialOf<Id> = Id extends Identity<z.ZodType | undefined, Roles | undefined, infer Extracted> ? Extracted : Credential;
83
- /**
84
- * The path params an identity's guard receives: what its `params` schema
85
- * declares, or the adapter's raw record when it declares none.
86
- */
87
- type IdentityParamsOf<Id> = Id extends {
88
- params: infer ParamsSchema;
89
- } ? ParamsSchema extends z.ZodType ? z.output<ParamsSchema> : Record<string, string> : Record<string, string>;
90
- /**
91
- * The {@link Roles} an identity declares, or `never` when it declares none.
92
- */
93
- type RolesOf<Id> = Id extends Identity<z.ZodType | undefined, infer RolesType> ? (RolesType extends Roles ? RolesType : never) : never;
94
- /**
95
- * The role a guard returns and a handler reads: one declared name, or several.
96
- */
97
- type RoleOf<Id> = RoleNamesOf<RolesOf<Id>> | readonly RoleNamesOf<RolesOf<Id>>[];
98
- /**
99
- * What a caller holds, as permission names, when the identity's roles come from a catalog.
100
- */
101
- type GrantsOf<Id> = readonly GrantNamesOf<RolesOf<Id>>[];
102
- /**
103
- * What roles add to a guard's return: `role` when the identity declares them,
104
- * with optional `permissions` when they come from a catalog, the subset of the
105
- * role's this caller was given, `{}` otherwise.
106
- */
107
- type GuardHoldings<Id> = [RolesOf<Id>] extends [never] ? {} : [CatalogOf<RolesOf<Id>>] extends [never] ? {
108
- role: RoleOf<Id>;
109
- } : {
110
- role: RoleOf<Id>;
111
- permissions?: GrantsOf<Id>;
112
- };
113
- /**
114
- * What roles add to a handler's `auth`: `role` when the identity declares them,
115
- * and `permissions`, what the caller holds, when they come from a catalog: the
116
- * role's, or the subset the guard returned.
117
- */
118
- type IdentityRole<Id> = [RolesOf<Id>] extends [never] ? {} : [CatalogOf<RolesOf<Id>>] extends [never] ? {
119
- role: RoleOf<Id>;
120
- } : {
121
- role: RoleOf<Id>;
122
- permissions: GrantsOf<Id>;
123
- };
124
- interface BearerConfig<ContextSchema extends z.ZodType | undefined, RolesType extends Roles | undefined> {
125
- context?: ContextSchema;
126
- roles?: RolesType;
127
- bearerFormat?: string;
128
- description?: string;
129
- scheme?: string;
130
- }
131
- interface ApiKeyConfig<ContextSchema extends z.ZodType | undefined, RolesType extends Roles | undefined, Name extends string, In extends 'header' | 'query' | 'cookie'> {
132
- name: Name;
133
- in: In;
134
- context?: ContextSchema;
135
- roles?: RolesType;
136
- description?: string;
137
- scheme?: string;
138
- }
139
- interface BasicConfig<ContextSchema extends z.ZodType | undefined, RolesType extends Roles | undefined> {
140
- context?: ContextSchema;
141
- roles?: RolesType;
142
- description?: string;
143
- scheme?: string;
144
- }
145
- interface OAuth2Config<ContextSchema extends z.ZodType | undefined, RolesType extends Roles | undefined> {
146
- flows: OAuthFlows;
147
- /**
148
- * Issuer identifier of the authorization server (RFC 8414), for consumers
149
- * that advertise it, such as RFC 9728 metadata. The flow URLs cannot stand
150
- * in for it: an issuer may carry a path the endpoint URLs do not reveal.
151
- */
152
- issuer?: string;
153
- /**
154
- * URL of this API's RFC 9728 metadata document, sent as `resource_metadata`
155
- * in every `Bearer` challenge so a client can find the authorization server.
156
- */
157
- resourceMetadata?: string;
158
- context?: ContextSchema;
159
- roles?: RolesType;
160
- description?: string;
161
- scheme?: string;
162
- }
163
- interface OpenIdConnectConfig<ContextSchema extends z.ZodType | undefined, RolesType extends Roles | undefined> {
164
- openIdConnectUrl: string;
165
- /**
166
- * URL of this API's RFC 9728 metadata document, sent as `resource_metadata`
167
- * in every `Bearer` challenge so a client can find the authorization server.
168
- */
169
- resourceMetadata?: string;
170
- context?: ContextSchema;
171
- roles?: RolesType;
172
- description?: string;
173
- scheme?: string;
174
- }
175
- interface CustomConfig<ContextSchema extends z.ZodType | undefined, RolesType extends Roles | undefined, ParamsSchema extends z.ZodType | undefined = undefined> {
176
- context?: ContextSchema;
177
- roles?: RolesType;
178
- description?: string;
179
- scheme?: string;
180
- /**
181
- * The path parameters this identity's guard reads, for a credential that
182
- * travels in the path. A route whose `auth` names the identity has to carry
183
- * them.
184
- *
185
- * @example
186
- * params: z.object({
187
- * token: z.string(),
188
- * }),
189
- */
190
- params?: ParamsSchema;
191
- }
192
- //#endregion
193
- //#region src/tool-events.d.ts
194
- /**
195
- * Every route in a tree as its dotted key, e.g. `'weather.getForecast'`. A tool
196
- * is addressed by that key everywhere, the way a job is.
197
- */
198
- type ToolKeys<R extends Routes, Prefix extends string = ''> = { [Name in keyof R & string]: R[Name] extends RouteDefinition ? `${Prefix}${Name}` : R[Name] extends Routes ? ToolKeys<R[Name], `${Prefix}${Name}.`> : never }[keyof R & string];
199
- /**
200
- * The route one dotted key names.
201
- */
202
- type ToolAt<R extends Routes, Key extends string> = Key extends `${infer Head}.${infer Rest}` ? R[Head] extends Routes ? ToolAt<R[Head], Rest> : never : R[Key] extends RouteDefinition ? R[Key] : never;
203
- type SchemaSide<Schema extends z.ZodType, Io extends 'input' | 'output'> = Io extends 'input' ? z.input<Schema> : z.output<Schema>;
204
- /**
205
- * Collapse an intersection into one object, so a call reads as the record it
206
- * is rather than as the pieces it was built from.
207
- */
208
- type Flatten<Shape> = { [Key in keyof Shape]: Shape[Key] } & {};
209
- /**
210
- * What a model sends to call a route: the same `{ params, query, body }` the
211
- * MCP endpoint takes, with each part present only when the route declares it.
212
- */
213
- type ToolInput<Route, Io extends 'input' | 'output'> = Flatten<(Route extends {
214
- pathParams: infer Params extends z.ZodType;
215
- } ? {
216
- params: SchemaSide<Params, Io>;
217
- } : {}) & (Route extends {
218
- query: infer Query extends z.ZodType;
219
- } ? {
220
- query: SchemaSide<Query, Io>;
221
- } : {}) & (Route extends {
222
- body: infer Body extends z.ZodType;
223
- } ? {
224
- body: SchemaSide<Body, Io>;
225
- } : {})>;
226
- /**
227
- * What the route answers with, read from its `200`.
228
- */
229
- type ToolOutput<Route, Io extends 'input' | 'output'> = Route extends {
230
- responses: {
231
- 200: infer Response;
232
- };
233
- } ? Response extends z.ZodType ? SchemaSide<Response, Io> : Response extends {
234
- body: infer Body extends z.ZodType;
235
- } ? SchemaSide<Body, Io> : never : never;
236
- /**
237
- * The `input` field of a call, absent for a route that takes nothing.
238
- */
239
- type InputField<Route, Io extends 'input' | 'output'> = [keyof ToolInput<Route, Io>] extends [never] ? {} : {
240
- input: ToolInput<Route, Io>;
241
- };
242
- /**
243
- * The `output` field of a result, absent for a route that reports nothing.
244
- */
245
- type OutputField<Route, Io extends 'input' | 'output'> = [ToolOutput<Route, Io>] extends [never] ? {} : {
246
- output: ToolOutput<Route, Io>;
247
- };
248
- /**
249
- * One tool call, discriminated on `name` so `input` narrows to the route's own
250
- * argument type.
251
- */
252
- type ToolCall<R extends Routes, Io extends 'input' | 'output' = 'output'> = { [Key in ToolKeys<R>]: Flatten<{
253
- id: string;
254
- name: Key;
255
- } & InputField<ToolAt<R, Key>, Io>> }[ToolKeys<R>];
256
- /**
257
- * One tool result, discriminated on `name` so `output` narrows to the route's
258
- * own result type.
259
- */
260
- type ToolResult<R extends Routes, Io extends 'input' | 'output' = 'output'> = { [Key in ToolKeys<R>]: Flatten<{
261
- id: string;
262
- name: Key;
263
- } & OutputField<ToolAt<R, Key>, Io>> }[ToolKeys<R>];
264
- /**
265
- * A tool that failed. The payload is the same whichever route it was, so this
266
- * carries the name as a plain enum rather than a discriminated union.
267
- */
268
- interface ToolError<R extends Routes> {
269
- id: string;
270
- name: ToolKeys<R>;
271
- message: string;
272
- }
273
- /**
274
- * The events {@link toolEvents} adds to a stream.
275
- */
276
- interface ToolEvents<R extends Routes> {
277
- tool_call: z.ZodType<ToolCall<R, 'output'>, ToolCall<R, 'input'>>;
278
- tool_result: z.ZodType<ToolResult<R, 'output'>, ToolResult<R, 'input'>>;
279
- tool_error: z.ZodType<ToolError<R>>;
280
- }
281
- /**
282
- * Server-sent events for the routes a model may call, to spread into a route's
283
- * `stream`. Each one is discriminated on the route's dotted key, so a client's
284
- * `for await` narrows the payload to the route that produced it.
285
- *
286
- * @example
287
- * ```ts
288
- * stream: {
289
- * delta: z.object({
290
- * text: z.string(),
291
- * }),
292
- * },
293
- * tools: assistantTools,
294
- * ```
295
- */
296
- declare const toolEvents: <const R extends Routes>(tools: R) => ToolEvents<R>;
297
- /**
298
- * The events a stream carries once its `tools` have been folded in. A response
299
- * declaring none is its `stream` untouched.
300
- */
301
- type StreamWithTools<Def extends StreamResponseDefinition> = Def extends {
302
- tools: infer R extends Routes;
303
- } ? Def['stream'] & ToolEvents<R> : Def['stream'];
304
- /**
305
- * Fold a response's `tools` into its `stream`, so everything downstream reads
306
- * one record of named events and never learns a tool was involved. Called by
307
- * `k.routes` before a route is validated.
308
- */
309
- declare const expandStreamTools: (route: RouteDefinition, routeKey: string) => void;
310
- //#endregion
311
- //#region src/stream.d.ts
312
- interface StreamContext {
313
- signal: AbortSignal;
314
- }
315
- interface EventFields {
316
- id?: string;
317
- retry?: number;
318
- }
319
- interface StreamComment {
320
- comment: string;
321
- }
322
- /**
323
- * What a handler yields per event, on the schema's input side.
324
- */
325
- type StreamYield<Stream extends StreamDefinition> = (Stream extends z.ZodType ? {
326
- data: z.input<Stream>;
327
- } & EventFields : { [Name in keyof Stream & string]: {
328
- event: Name;
329
- data: z.input<Stream[Name]>;
330
- } & EventFields }[keyof Stream & string]) | StreamComment;
331
- /**
332
- * What a client reads per event, on the schema's output side.
333
- */
334
- type StreamMessage<Stream extends StreamDefinition> = Stream extends z.ZodType ? {
335
- data: z.output<Stream>;
336
- } & EventFields : { [Name in keyof Stream & string]: {
337
- event: Name;
338
- data: z.output<Stream[Name]>;
339
- } & EventFields }[keyof Stream & string];
340
- type IsEventStream<Def> = Def extends {
341
- contentType: infer ContentType;
342
- } ? (ContentType extends 'text/event-stream' ? true : false) : true;
343
- type StreamChunk<Def extends StreamResponseDefinition> = IsEventStream<Def> extends true ? StreamYield<StreamWithTools<Def>> : Def['stream'] extends z.ZodType ? z.input<Def['stream']> : never;
344
- type StreamMessageOf<Def extends StreamResponseDefinition> = IsEventStream<Def> extends true ? StreamMessage<StreamWithTools<Def>> : Def['stream'] extends z.ZodType ? z.output<Def['stream']> : never;
345
- /**
346
- * The `body` of a streamed status: an async generator function receiving `{ signal }`, or any async iterable.
347
- */
348
- type StreamBodyOf<Def extends StreamResponseDefinition> = ((context: StreamContext) => AsyncIterable<StreamChunk<Def>>) | AsyncIterable<StreamChunk<Def>>;
349
- /**
350
- * The `body` type of one streamed status, for a generator written outside its handler.
351
- *
352
- * @example
353
- * ```ts
354
- * const cannedReply: StreamBody<typeof replyRoute, 200> = async function* () {
355
- * yield {
356
- * event: 'delta',
357
- * data: {
358
- * text: 'Hello',
359
- * },
360
- * };
361
- * };
362
- * ```
363
- */
364
- type StreamBody<R extends Pick<RouteDefinition, 'responses'>, Status extends keyof R['responses']> = R['responses'][Status] extends StreamResponseDefinition ? StreamBodyOf<R['responses'][Status]> : never;
365
- declare const EVENT_STREAM_MEDIA_TYPE = "text/event-stream";
366
- type StreamMode = 'events' | 'text' | 'binary';
367
- declare const streamContentType: (definition: StreamResponseDefinition) => string;
368
- declare const streamMode: (definition: StreamResponseDefinition) => StreamMode;
369
- declare const isNamedStream: (stream: StreamDefinition) => stream is Record<string, z.ZodType>;
370
- declare const streamStatuses: (route: Pick<RouteDefinition, "responses">) => number[];
371
- /**
372
- * Whether any status of the route streams.
373
- */
374
- declare const routeStreams: (route: Pick<RouteDefinition, "responses">) => boolean;
375
- /**
376
- * The one streamed 2xx of a route with no other 2xx beside it, the shape the
377
- * native clients generate. `undefined` for a route that does not stream, or one
378
- * that mixes a stream with another success status.
379
- */
380
- declare const soleStreamResponse: (route: Pick<RouteDefinition, "responses">) => {
381
- status: number;
382
- definition: StreamResponseDefinition;
383
- } | undefined;
384
- declare const streamSchemas: (stream: StreamDefinition) => z.ZodType[];
385
- interface EncodeStreamOptions {
386
- signal: AbortSignal;
387
- validate?: boolean;
388
- onError?: (error: unknown) => void;
389
- }
390
- interface StreamSource {
391
- routeKey: string;
392
- route: RouteDefinition;
393
- status: number;
394
- body: unknown;
395
- }
396
- /**
397
- * The bytes of a streamed response, pulled from the handler's body as the consumer reads.
398
- */
399
- declare const encodeStreamBody: (source: StreamSource, options: EncodeStreamOptions) => ReadableStream<Uint8Array>;
400
- //#endregion
401
- //#region src/path-params.d.ts
402
- type LowercaseLetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
403
- type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
404
- /**
405
- * The characters {@link parsePath}'s `/:([a-zA-Z_][a-zA-Z0-9_]*)/` accepts.
406
- */
407
- type IdentifierStart = LowercaseLetter | Uppercase<LowercaseLetter> | '_';
408
- type IdentifierChar = IdentifierStart | Digit;
409
- type TakeIdentifierRest<Text extends string, Name extends string> = Text extends `${infer Head}${infer Tail}` ? Head extends IdentifierChar ? TakeIdentifierRest<Tail, `${Name}${Head}`> : Name : Name;
410
- type TakeIdentifier<Text extends string> = Text extends `${infer Head}${infer Tail}` ? Head extends IdentifierStart ? TakeIdentifierRest<Tail, Head> : '' : '';
411
- /**
412
- * The `:param` names in a path, as a union. The type-level {@link parsePath}.
413
- */
414
- type PathParamName<Path extends string> = Path extends `${string}:${infer AfterColon}` ? TakeIdentifier<AfterColon> extends infer Name extends string ? Name extends '' ? PathParamName<AfterColon> : Name | PathParamName<AfterColon> : never : never;
415
- type ExtractPathParams<T extends string> = { [Name in PathParamName<T>]: string };
416
- type HasPathParams<T extends string> = [PathParamName<T>] extends [never] ? false : true;
417
- /**
418
- * Resolves to `string` for schemas without a known key set, which switches the
419
- * check off.
420
- */
421
- type DeclaredParamName<Schema> = Schema extends z.ZodType ? Extract<keyof z.output<Schema>, string> : never;
422
- type UndeclaredParam<Path extends string, Schema> = Exclude<PathParamName<Path>, DeclaredParamName<Schema>>;
423
- type UnmatchedParam<Path extends string, Schema> = Exclude<DeclaredParamName<Schema>, PathParamName<Path>>;
424
- type PathParamsMismatch<Path extends string, Schema> = string extends DeclaredParamName<Schema> ? never : [UnmatchedParam<Path, Schema>] extends [never] ? [UndeclaredParam<Path, Schema>] extends [never] ? never : `kizuna: path "${Path}" has parameter ":${UndeclaredParam<Path, Schema>}", which pathParams does not declare` : `kizuna: pathParams declares "${UnmatchedParam<Path, Schema>}", which is not a parameter in path "${Path}"`;
425
- /**
426
- * Every mismatch in a route tree, as a union. The `string extends keyof Node`
427
- * arm stops the walk at a generic that fell back to its constraint.
428
- */
429
- type TreeMismatch<Node> = Node extends {
430
- method: Method;
431
- path: string;
432
- } ? Node extends {
433
- path: infer Path extends string;
434
- pathParams: infer Schema;
435
- } ? PathParamsMismatch<Path, Schema> : never : Node extends object ? string extends keyof Node ? never : { [Key in keyof Node]: TreeMismatch<Node[Key]> }[keyof Node] : never;
436
- type MismatchShape<Node> = { [Key in keyof Node]: Node[Key] extends {
437
- method: Method;
438
- path: infer Path extends string;
439
- pathParams: infer Schema;
440
- } ? [PathParamsMismatch<Path, Schema>] extends [never] ? unknown : {
441
- pathParams: PathParamsMismatch<Path, Schema>;
442
- } : Node[Key] extends object ? MismatchShape<Node[Key]> : unknown };
443
- /**
444
- * Reports routes whose `pathParams` keys disagree with their path's `:param`
445
- * placeholders. Intersect it with the inferred route tree
446
- * (`defs: T & PathParamsCheck<T>`): a clean tree gives `unknown`, leaving `T`
447
- * untouched, and a mismatch resolves the offending `pathParams` to an error
448
- * message. Routes that omit `pathParams` are left alone.
449
- */
450
- type PathParamsCheck<RouteTree> = [TreeMismatch<RouteTree>] extends [never] ? unknown : MismatchShape<RouteTree>;
451
- /**
452
- * The {@link PathParamsCheck} of one route, for `k.route`. Intersect it with the
453
- * inferred definition: a route whose `pathParams` keys match its path gives
454
- * `unknown`, and a mismatch resolves `pathParams` to an error message.
455
- */
456
- type RoutePathParamsCheck<Definition> = Definition extends {
457
- path: infer Path extends string;
458
- pathParams: infer Schema;
459
- } ? [PathParamsMismatch<Path, Schema>] extends [never] ? unknown : {
460
- pathParams: PathParamsMismatch<Path, Schema>;
461
- } : unknown;
462
- interface PathSegment {
463
- kind: 'literal' | 'param';
464
- value: string;
465
- }
466
- declare const parsePath: (path: string) => {
467
- segments: PathSegment[];
468
- paramNames: string[];
469
- };
470
- declare const buildPath: (path: string, params?: Record<string, string | number | bigint | Date>) => string;
471
- //#endregion
472
- //#region src/handler-pipeline.d.ts
473
- /**
474
- * True when a literal status key is in the 4xx/5xx range. Widened `number` keys (no
475
- * `const` inference) resolve to `false`, so enforcement only kicks in when the concrete
476
- * status is known, exactly where the wire output matters.
477
- */
478
- type IsErrorStatus<Status> = `${Status & number}` extends `4${string}` | `5${string}` ? true : false;
479
- /**
480
- * Error responses (4xx/5xx) must be RFC 9457 Problem Details, a schema assignable to the
481
- * envelope. Anything else resolves to `never`, surfacing as a compile error at the handler
482
- * return / `throwError()` site. Success responses pass through unchanged.
483
- */
484
- type ApplyErrorEnvelope<Input, Status> = IsErrorStatus<Status> extends true ? (Input extends ProblemDetails ? StripProblemEnvelope<Input> : never) : Input;
485
- type HandlerBody<S, Status> = S extends z.ZodType ? ApplyErrorEnvelope<z.input<S>, Status> : S extends StreamResponseDefinition ? IsErrorStatus<Status> extends true ? never : StreamBodyOf<S> : S extends {
486
- body: z.ZodType;
487
- } ? ApplyErrorEnvelope<z.input<S['body']>, Status> : never;
488
- type ResponseReturn<R extends Pick<RouteDefinition, 'responses'>, Status extends keyof R['responses']> = {
489
- status: Status extends number ? Status : never;
490
- body: HandlerBody<R['responses'][Status], Status>;
491
- headers?: ResponseHeaders;
492
- };
493
- /**
494
- * Constrained to `responses` alone so a job, which has no method or path, reuses it.
495
- */
496
- type HandlerReturn<R extends Pick<RouteDefinition, 'responses'>> = { [Status in keyof R['responses']]: ResponseReturn<R, Status> }[keyof R['responses']];
497
- type StreamStatuses<R extends Pick<RouteDefinition, 'responses'>> = { [Status in keyof R['responses']]: R['responses'][Status] extends StreamResponseDefinition ? Status : never }[keyof R['responses']];
498
- /**
499
- * The responses `throwError` takes: every declared status except the streamed
500
- * ones. A stream is a body to produce, and bailing out is what `throwError` is for.
501
- */
502
- type ThrowableReturn<R extends Pick<RouteDefinition, 'responses'>> = { [Status in Exclude<keyof R['responses'], StreamStatuses<R>>]: ResponseReturn<R, Status> }[Exclude<keyof R['responses'], StreamStatuses<R>>];
503
- type HandlerArgs<R extends RouteDefinition> = {
504
- params: R extends {
505
- pathParams: z.ZodType;
506
- } ? z.output<R['pathParams']> : ExtractPathParams<R['path']>;
507
- query: R extends {
508
- query: z.ZodType;
509
- } ? z.output<R['query']> : undefined;
510
- body: R extends {
511
- body: z.ZodType;
512
- } ? z.output<R['body']> : undefined;
513
- headers: R extends {
514
- headers: z.ZodType;
515
- } ? z.output<R['headers']> : Record<string, string | string[] | undefined>;
516
- /**
517
- * Throws a typed error response. Takes the same `{ status, body }` shape as a handler return.
518
- *
519
- * This function throws internally and never returns.
520
- */
521
- throwError: (response: ThrowableReturn<R> | GuardAnswer<R>) => never;
522
- };
523
- type RouteHandler<R extends RouteDefinition, HandlerContext = unknown> = (args: HandlerArgs<R> & HandlerContext & BrandedHandlerContext<R>) => Promise<HandlerReturn<R> | GuardAnswer<R>> | HandlerReturn<R> | GuardAnswer<R>;
524
- /**
525
- * The `403` a guarded route already declares, which its handler may answer
526
- * itself.
527
- */
528
- type GuardAnswer<R> = typeof AUTO_RESPONSES_BRAND extends keyof R ? 403 extends NonNullable<R[typeof AUTO_RESPONSES_BRAND]> ? {
529
- status: 403;
530
- body: typeof AUTO_GUARD_WRITTEN_BRAND extends keyof R ? NonNullable<R[typeof AUTO_GUARD_WRITTEN_BRAND]> : {
531
- detail: string;
532
- };
533
- headers?: ResponseHeaders;
534
- } : never : never;
535
- type Router<T extends Routes, HandlerContext = unknown> = { [Key in keyof T as Key extends symbol ? never : Key]: T[Key] extends RouteDefinition ? RouteHandler<T[Key], HandlerContext> : T[Key] extends Routes ? Router<T[Key], HandlerContext> : never };
536
- /**
537
- * What a handler reads for an identity: its `context` and, when the identity
538
- * declares roles, the caller's `role`, with `permissions` for roles built from
539
- * a catalog, flattened into one type.
540
- * Read in a handler under the identity's name. Flattened (rather than left as
541
- * an intersection) so it works as a contextual type, letting a guard return a
542
- * literal `role: 'owner'` without an annotation.
543
- */
544
- type GuardSuccess<S> = { [Field in keyof (ContextOf<S> & IdentityRole<S>)]: (ContextOf<S> & IdentityRole<S>)[Field] };
545
- /**
546
- * What a guard returns to allow a request: the identity's context and its
547
- * `role`. `permissions` is optional beside the role, since kizuna fills it in
548
- * from the role before the handler runs.
549
- */
550
- type GuardReturn<S> = { [Field in keyof (ContextOf<S> & GuardHoldings<S>)]: (ContextOf<S> & GuardHoldings<S>)[Field] };
551
- /**
552
- * The identity names a route's `auth` requires: a name, several, the `identity`
553
- * of a rule, or none for `false`.
554
- */
555
- type AuthIdentityNames<Value> = Value extends false ? never : Value extends string ? Value : Value extends readonly (infer Name extends string)[] ? Name : Value extends {
556
- identity: infer Identity;
557
- } ? Identity extends string ? Identity : Identity extends readonly (infer Name extends string)[] ? Name : never : never;
558
- /**
559
- * What a route requires of its caller, `false` for one that declares nothing.
560
- */
561
- type AuthOf<R> = R extends {
562
- auth: infer Value;
563
- } ? Value : false;
564
- /**
565
- * The scheme-keyed security context a route's handler receives, derived from
566
- * its `auth`: `false` (public) contributes nothing; each identity it names
567
- * yields that identity's context, the caller's role, and for roles built from a
568
- * catalog, the caller's permissions.
569
- *
570
- * @example
571
- * type Context = ContextFromAuth<{ identity: 'member' }, { member: typeof member }>;
572
- * // { member: { workspaceUserId: string; role: 'owner' | 'admin' | readonly ('owner' | 'admin')[]; permissions: readonly ('workspace:read' | 'workspace:delete')[] } }
573
- */
574
- type ContextFromAuth<Value, Identities> = { [Name in AuthIdentityNames<Value> & keyof Identities as [keyof GuardSuccess<Identities[Name]>] extends [never] ? never : Name]: GuardSuccess<Identities[Name]> };
575
- /**
576
- * The `auth` argument one route's handler receives, from the route's own rule.
577
- */
578
- type AuthContextOf<Route, Identities> = AuthArg<AuthOf<Route>, Identities>;
579
- /**
580
- * The `auth` argument a secured route's handler receives.
581
- */
582
- type AuthArg<Value, Identities> = ContextFromAuth<Value, Identities> extends infer Ctx ? ([keyof Ctx] extends [never] ? {} : {
583
- auth: Ctx;
584
- }) : never;
585
- /**
586
- * The `requestContext` argument a handler receives.
587
- */
588
- type RequestContextValues<RequestContext> = string extends keyof RequestContext ? {} : [keyof RequestContext] extends [never] ? {} : {
589
- requestContext: { [Name in keyof RequestContext]: RequestContext[Name] extends {
590
- context: infer Schema extends z.ZodType;
591
- } ? z.output<Schema> : never };
592
- };
593
- /**
594
- * The path param names of every route the identity `Name` secures.
595
- */
596
- type GuardedParamNames<R extends Routes, Name extends string> = { [Key in keyof R & string]: R[Key] extends RouteDefinition ? Name extends AuthIdentityNames<AuthOf<R[Key]>> ? keyof ExtractPathParams<R[Key]['path']> & string : never : R[Key] extends Routes ? GuardedParamNames<R[Key], Name> : never }[keyof R & string];
597
- /**
598
- * The `params` a guard for identity `Name` receives: the param names of the
599
- * routes it secures, each optional since the guard runs across all of them.
600
- * Falls back to `Record<string, string>` when no params are derivable.
601
- */
602
- type GuardParams<R extends Routes, Name extends string> = [GuardedParamNames<R, Name>] extends [never] ? Record<string, string> : { [Param in GuardedParamNames<R, Name>]?: string };
603
- /**
604
- * The handler tree for an api or route group: every route typed with its
605
- * inputs, the adapter's handler context, and the scheme-keyed security context
606
- * its `auth` resolves to. The identities a route requires appear in the handler
607
- * args under `auth`, keyed by each identity's name, each carrying its context
608
- * and the caller's role.
609
- */
610
- type HandlersFromRoutes<R extends Routes, HandlerContext, Identities> = { [Key in keyof R as Key extends symbol ? never : Key]: R[Key] extends RouteDefinition ? RouteHandlerFromContext<R[Key], HandlerContext, AuthArg<AuthOf<R[Key]>, Identities>> : R[Key] extends Routes ? HandlersFromRoutes<R[Key], HandlerContext, Identities> : never };
611
- type RouteHandlerFromContext<R extends RouteDefinition, HandlerContext, SecurityContext> = (args: HandlerArgs<R> & HandlerContext & SecurityContext) => Promise<HandlerReturn<R> | GuardAnswer<R>> | HandlerReturn<R> | GuardAnswer<R>;
612
- /**
613
- * A route's brand, skipped when the resolved context is empty.
614
- */
615
- type RouteContextBrand<Context> = [keyof Context] extends [never] ? unknown : HandlerContextBrand<Context>;
616
- type RouteGuardBrand<Value, Body, Written> = [AuthIdentityNames<Value>] extends [never] ? unknown : AutoResponsesBrand<GuardStatus, Body, Written>;
617
- /**
618
- * The `401` and `403` a route's own `auth` gives it, so a handler written at the
619
- * route may answer the `403` itself.
620
- */
621
- type RouteGuardBrandOf<Route, Body, Written> = RouteGuardBrand<AuthOf<Route>, Body, Written>;
622
- type HandlerContextOverlay<R extends Routes, Identities, Context, GuardBody_, GuardWritten_> = { [Key in keyof R]: R[Key] extends RouteDefinition ? RouteContextBrand<AuthArg<AuthOf<R[Key]>, Identities> & Context> & RouteGuardBrand<AuthOf<R[Key]>, GuardBody_, GuardWritten_> : R[Key] extends Routes ? HandlerContextOverlay<R[Key], Identities, Context, GuardBody_, GuardWritten_> : unknown };
623
- /**
624
- * An api's routes, each branded with what the api adds to a handler's
625
- * args: `auth`, `requestContext`, plugins, and jobs. Read back by
626
- * {@link RouteHandler}.
627
- */
628
- type RoutesWithHandlerContext<R extends Routes, Identities, RequestContext, ApiContext = unknown, GuardBody_ = ProblemDetails, GuardWritten_ = {
629
- detail: string;
630
- }> = R & HandlerContextOverlay<R, Identities, RequestContextValues<RequestContext> & ApiContext, GuardBody_, GuardWritten_>;
631
- type BrandedHandlerContext<R> = typeof HANDLER_CONTEXT_BRAND extends keyof R ? NonNullable<R[typeof HANDLER_CONTEXT_BRAND]> : {};
632
- declare const isRouteDefinition: (value: unknown) => value is RouteDefinition;
633
- interface FlattenedRoute {
634
- routeKey: string;
635
- route: RouteDefinition;
636
- routeTags: string[];
637
- }
638
- declare const flattenRoutes: (routes: Routes, prefix?: string, inheritedTags?: string[]) => FlattenedRoute[];
639
- interface RawInputs {
640
- params: unknown;
641
- query: unknown;
642
- body: unknown;
643
- headers: unknown;
644
- }
645
- type ValidationStage = 'params' | 'query' | 'headers' | 'body';
646
- interface ValidationFailure {
647
- stage: ValidationStage;
648
- issues: z.core.$ZodIssue[];
649
- }
650
- declare const formatValidationError: (failure: ValidationFailure) => {
651
- detail: string;
652
- issues: z.core.$ZodIssue[];
653
- };
654
- declare const validateRequest: (route: RouteDefinition, raw: RawInputs) => {
655
- ok: true;
656
- parsed: RawInputs;
657
- } | {
658
- ok: false;
659
- error: ValidationFailure;
660
- };
661
- declare const allowedMethodsForPath: (routes: Routes, path: string) => Method[];
662
- //#endregion
663
- //#region src/raw-response.d.ts
664
- declare const RAW_RESPONSE: unique symbol;
665
- interface RawResponse {
666
- readonly [RAW_RESPONSE]: true;
667
- readonly response?: unknown;
668
- }
669
- /**
670
- * Answer with a response kizuna will neither validate nor render. For plugin
671
- * routes whose wire format is not JSON, such as MCP's JSON-RPC over
672
- * server-sent events. Ordinary route handlers cannot reach it.
673
- */
674
- declare const rawResponse: (response?: unknown) => RawResponse;
675
- declare const isRawResponse: (value: unknown) => value is RawResponse;
676
- //#endregion
677
- //#region src/plugin.d.ts
678
- declare const PLUGIN_ROUTES_META_KEY: unique symbol;
679
- declare const PLUGIN_SERVERS_META_KEY: unique symbol;
680
- /**
681
- * The routes a plugin serves. `api.mount` serves them through the same pipeline
682
- * as the api's own, but they never join `api.routes`, so the client
683
- * and the generators do not see them.
684
- */
685
- type PluginRoutes = Record<string, RouteDefinition>;
686
- /**
687
- * What a plugin is: the routes it declares, the props it was configured with,
688
- * and the `serve` that answers them.
689
- */
690
- interface PluginDeclaration<R extends PluginRoutes = PluginRoutes, Props = unknown, Exports = unknown, Slug extends string = string, HandlerContext = unknown> {
691
- /**
692
- * What handlers reach this plugin under, and the key it is installed at.
693
- */
694
- /**
695
- * What handlers reach this plugin under, and the key it is installed at.
696
- * Each plugin defaults it; an app installing two of the same plugin gives
697
- * the second one its own.
698
- */
699
- slug: Slug;
700
- routes: R;
701
- /**
702
- * Passed to `serve`, so the app never restates it.
703
- */
704
- props: Props;
705
- /**
706
- * What answers this plugin's routes, and what it hands handlers under
707
- * `plugins.<slug>`.
708
- */
709
- serve: (props: Props, api: unknown) => PluginServe<R, Exports, HandlerContext>;
710
- }
711
- /**
712
- * What a plugin's `serve` returns: one handler per declared route, and whatever
713
- * it hands handlers under `plugins.<slug>`.
714
- */
715
- interface PluginServe<R extends PluginRoutes, Exports, HandlerContext> {
716
- router: PluginRouter<R, HandlerContext>;
717
- exports?: Exports;
718
- }
719
- /**
720
- * What {@link createPlugin} takes.
721
- */
722
- interface PluginDefinition<R extends PluginRoutes, Props, Exports, Slug extends string, HandlerContext> {
723
- slug: Slug;
724
- routes: R;
725
- /**
726
- * Passed to `serve`, so the app never restates it.
727
- */
728
- props?: Props;
729
- serve: (props: NoInfer<Props>, api: unknown) => PluginServe<NoInfer<R>, Exports, HandlerContext>;
730
- }
731
- /**
732
- * Declare a plugin: the routes it serves, the props an app configures it with,
733
- * and the `serve` that answers those routes. Whatever `serve` returns under
734
- * `exports` reaches every handler as `plugins.<slug>`.
735
- *
736
- * Give the factory a `Slug` parameter and {@link WithSlug} so an app can rename
737
- * what it installs, or install two of them.
738
- *
739
- * @example
740
- * ```ts
741
- * const declare = (slug: string, props: AuditProps) =>
742
- * createPlugin({
743
- * slug,
744
- * routes: {
745
- * recent: {
746
- * method: 'GET',
747
- * path: props.path ?? '/audit/recent',
748
- * responses: {
749
- * 200: z.array(EntrySchema),
750
- * },
751
- * },
752
- * },
753
- * props,
754
- * serve: ({ store }) => ({
755
- * router: {
756
- * recent: async () => ({ status: 200, body: await store.recent() }),
757
- * },
758
- * exports: {
759
- * record: (routeKey: string) => store.write(routeKey),
760
- * },
761
- * }),
762
- * });
763
- *
764
- * export function auditPlugin<const Slug extends string = 'audit'>(
765
- * props: AuditProps<Slug>
766
- * ): WithSlug<ReturnType<typeof declare>, Slug> {
767
- * return declare(props.slug ?? 'audit', props) as never;
768
- * }
769
- * ```
770
- */
771
- declare const createPlugin: <Props, const R extends PluginRoutes, const Slug extends string, Exports = undefined, HandlerContext = unknown>(definition: PluginDefinition<R, Props, Exports, Slug, HandlerContext>) => PluginDeclaration<R, Props, Exports, Slug, HandlerContext>;
772
- /**
773
- * Plugins keyed by their slug, which is what `plugins.*` in handler args
774
- * resolves against.
775
- */
776
- type ApiPlugins = Record<string, AnyPlugin>;
777
- /**
778
- * Any plugin, whatever it declares. `serve` reads its own props, so a concrete
779
- * plugin is not assignable to a widened one; this stands in wherever a plugin
780
- * is a constraint rather than a value.
781
- */
782
- type AnyPlugin = PluginDeclaration<any, any, any, string, any>;
783
- /**
784
- * The plugins a config installs, as an array. Each carries its own slug, which
785
- * is what handlers reach it under.
786
- */
787
- type PluginList = readonly AnyPlugin[];
788
- /**
789
- * One plugin declaration under a different slug, for a factory that lets an app
790
- * rename what it installs.
791
- *
792
- * @example
793
- * export function auditPlugin<const Slug extends string = 'audit'>(
794
- * props?: AuditProps<Slug>
795
- * ): WithSlug<ReturnType<typeof declare>, Slug> {
796
- * return declare(props?.slug ?? 'audit', props ?? {}) as never;
797
- * }
798
- */
799
- type WithSlug<Declaration, Slug extends string> = Declaration extends PluginDeclaration<infer R, infer Props, infer Exports, string, infer HandlerContext> ? PluginDeclaration<R, Props, Exports, Slug, HandlerContext> : never;
800
- /**
801
- * A plugin list as a record keyed by each plugin's own slug.
802
- */
803
- type PluginsBySlug<Plugins extends PluginList> = { [Plugin in Plugins[number] as Plugin['slug']]: Plugin };
804
- type PluginRoutesOf<Declaration> = Declaration extends PluginDeclaration<infer R, infer _P, infer _E, string, infer _H> ? R : never;
805
- type PluginPropsOf<Declaration> = Declaration extends PluginDeclaration<infer _R, infer Props, infer _E, string, infer _H> ? Props : never;
806
- type PluginExportsOf<Declaration> = Declaration extends PluginDeclaration<infer _R, infer _P, infer Exports, string, infer _H> ? Exports : never;
807
- type PluginExportValues<Plugins extends ApiPlugins> = { [Key in keyof Plugins]: PluginExportsOf<Plugins[Key]> };
808
- /**
809
- * The `plugins` handler argument, or nothing when no plugins are installed, so
810
- * handler args are unchanged without them.
811
- */
812
- type PluginArgs<Plugins extends ApiPlugins> = string extends keyof Plugins ? unknown : [keyof Plugins] extends [never] ? unknown : {
813
- plugins: PluginExportValues<Plugins>;
814
- };
815
- /**
816
- * Every plugin's routes as one tree, keyed by install name, for the adapter to
817
- * walk as it walks the api's own.
818
- */
819
- declare const pluginRouteTree: (plugins: ApiPlugins | undefined) => Routes;
820
- /**
821
- * A plugin's handlers, typed against its routes. A plugin may also answer with
822
- * {@link rawResponse} when its wire format is not JSON.
823
- */
824
- type PluginRouter<R extends PluginRoutes, HandlerContext> = { [Key in keyof R]: (args: HandlerArgs<R[Key]> & HandlerContext) => Promise<HandlerReturn<R[Key]> | RawResponse> | HandlerReturn<R[Key]> | RawResponse };
825
- /**
826
- * Every plugin in a list, keyed by its own slug.
827
- */
828
- declare const pluginsBySlug: (plugins: PluginList | undefined) => ApiPlugins;
829
- //#endregion
830
- export { PathParamsCheck as $, GuardReturn as A, expandStreamTools as At, Router as B, CustomConfig as Bt, rawResponse as C, StreamWithTools as Ct, FlattenedRoute as D, ToolEvents as Dt, ContextFromAuth as E, ToolError as Et, HandlersFromRoutes as F, BasicCredential as Ft, allowedMethodsForPath as G, IdentityRole as Gt, ThrowableReturn as H, GuardHoldings as Ht, RawInputs as I, BearerConfig as It, isRouteDefinition as J, OpenIdConnectConfig as Jt, flattenRoutes as K, NoCredential as Kt, RequestContextValues as L, BearerCredential as Lt, GuardedParamNames as M, ApiKeyConfig as Mt, HandlerArgs as N, ApiKeyCredential as Nt, GuardAnswer as O, ToolKeys as Ot, HandlerReturn as P, BasicConfig as Pt, PathParamName as Q, RouteGuardBrandOf as R, Credential as Rt, isRawResponse as S, streamStatuses as St, BrandedHandlerContext as T, ToolCall as Tt, ValidationFailure as U, Identity as Ut, RoutesWithHandlerContext as V, GrantsOf as Vt, ValidationStage as W, IdentityParamsOf as Wt, ExtractPathParams as X, RolesOf as Xt, validateRequest as Y, RoleOf as Yt, HasPathParams as Z, WithSlug as _, routeStreams as _t, PluginArgs as a, EncodeStreamOptions as at, pluginsBySlug as b, streamMode as bt, PluginExportValues as c, StreamChunk as ct, PluginPropsOf as d, StreamMessage as dt, PathSegment as et, PluginRouter as f, StreamMessageOf as ft, PluginsBySlug as g, isNamedStream as gt, PluginServe as h, encodeStreamBody as ht, PLUGIN_SERVERS_META_KEY as i, EVENT_STREAM_MEDIA_TYPE as it, GuardSuccess as j, toolEvents as jt, GuardParams as k, ToolResult as kt, PluginExportsOf as l, StreamComment as lt, PluginRoutesOf as m, StreamYield as mt, ApiPlugins as n, buildPath as nt, PluginDeclaration as o, StreamBody as ot, PluginRoutes as p, StreamMode as pt, formatValidationError as q, OAuth2Config as qt, PLUGIN_ROUTES_META_KEY as r, parsePath as rt, PluginDefinition as s, StreamBodyOf as st, AnyPlugin as t, RoutePathParamsCheck as tt, PluginList as u, StreamContext as ut, createPlugin as v, soleStreamResponse as vt, AuthContextOf as w, ToolAt as wt, RawResponse as x, streamSchemas as xt, pluginRouteTree as y, streamContentType as yt, RouteHandler as z, CredentialOf as zt };