theokit 0.19.4 → 0.20.0
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/dist/chunk-WLKFWVOM.js +278 -0
- package/dist/chunk-WLKFWVOM.js.map +1 -0
- package/dist/index.d.ts +29 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/server/define/index.d.ts +269 -4
- package/dist/server/define/index.js +15 -3
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +22 -14
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-CWVBDUDC.js +0 -108
- package/dist/chunk-CWVBDUDC.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { UIMessageChunk } from 'ai';
|
|
3
|
-
import { b as WebSocketLike } from '../../define-websocket-CdK94O-D.js';
|
|
4
|
-
export {
|
|
3
|
+
import { W as WebSocketHandler, b as WebSocketLike } from '../../define-websocket-CdK94O-D.js';
|
|
4
|
+
export { a as WebSocketHandlerWeb, d as defineWebSocket, c as defineWebSocketWeb } from '../../define-websocket-CdK94O-D.js';
|
|
5
5
|
import { IncomingMessage } from 'node:http';
|
|
6
|
-
import { T as TheoPlugin } from '../../plugin-types-DNJGxr4Z.js';
|
|
6
|
+
import { T as TheoPlugin, f as OnRequestHook, i as PreHandlerHook, g as OnResponseHook, O as OnErrorHook } from '../../plugin-types-DNJGxr4Z.js';
|
|
7
7
|
export { H as HEALTH_PATH, a as HealthRouteConfig, b as READY_PATH, c as ReadyRouteConfig, d as ReservedResponse, R as ReservedRoutes, e as defineHealthRoute, f as defineReadyRoute, s as serveReservedRoute } from '../../health-route-C0hk64_U.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -64,6 +64,65 @@ interface RouteConfig<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z
|
|
|
64
64
|
*/
|
|
65
65
|
declare function defineRoute<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx = unknown, TResponse = unknown>(config: RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>): RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>;
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* M31 Phase 3 — `route()`, the fluent builder that replaces `defineRoute({...})`.
|
|
69
|
+
*
|
|
70
|
+
* Pure type-state (mirrors `tool-builder.ts`). `.query/.body/.params` set Zod schemas whose
|
|
71
|
+
* `z.infer<>` flows into the handler's `ctx`; `.handler()` is required before `.build()`. `.build()`
|
|
72
|
+
* delegates to the internal {@link defineRoute} (an identity fn), emitting the identical
|
|
73
|
+
* `RouteConfig` — the scan/execute path is UNCHANGED (identity-shape delegation, blueprint §2).
|
|
74
|
+
*
|
|
75
|
+
* export const POST = route()
|
|
76
|
+
* .params(z.object({ id: z.string() }))
|
|
77
|
+
* .body(z.object({ text: z.string() }))
|
|
78
|
+
* .handler(({ params, body }) => save(params.id, body.text))
|
|
79
|
+
* .build()
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/** Compile-error carrier: `.build()` called before `.handler()`. */
|
|
83
|
+
interface MissingHandlerError {
|
|
84
|
+
readonly __theokitError: 'a route needs .handler(fn) before .build()';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The fluent route builder. `TQuery/TBody/TParams` track the input schemas (default `z.ZodUndefined`,
|
|
88
|
+
* matching {@link RouteConfig}); `TResponse` tracks the handler return; `THandlerSet` gates `.build()`.
|
|
89
|
+
*/
|
|
90
|
+
interface RouteBuilder<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx = unknown, TResponse = unknown, THandlerSet extends boolean = false> {
|
|
91
|
+
/** Set the URL search-params schema. Inferred into `ctx.query`. */
|
|
92
|
+
query<S extends z.ZodType>(schema: S): RouteBuilder<S, TBody, TParams, TCtx, TResponse, THandlerSet>;
|
|
93
|
+
/** Set the request-body schema. Inferred into `ctx.body`. */
|
|
94
|
+
body<S extends z.ZodType>(schema: S): RouteBuilder<TQuery, S, TParams, TCtx, TResponse, THandlerSet>;
|
|
95
|
+
/** Set the path-params schema. Inferred into `ctx.params`. */
|
|
96
|
+
params<S extends z.ZodType>(schema: S): RouteBuilder<TQuery, TBody, S, TCtx, TResponse, THandlerSet>;
|
|
97
|
+
/** Runtime-only validation of the handler's plain-object return (500 on mismatch). Not inferred (YAGNI). */
|
|
98
|
+
response(schema: z.ZodType): RouteBuilder<TQuery, TBody, TParams, TCtx, TResponse, THandlerSet>;
|
|
99
|
+
/** Override the HTTP status for a plain-object return (default 200; 204 for void). */
|
|
100
|
+
status(code: number): RouteBuilder<TQuery, TBody, TParams, TCtx, TResponse, THandlerSet>;
|
|
101
|
+
/** Opt out of CSRF enforcement for this route (webhooks / OAuth callbacks). */
|
|
102
|
+
csrf(disabled: false): RouteBuilder<TQuery, TBody, TParams, TCtx, TResponse, THandlerSet>;
|
|
103
|
+
/**
|
|
104
|
+
* Set the handler. Its `ctx` infers `query/body/params` from the schemas set above. Required
|
|
105
|
+
* before `.build()`.
|
|
106
|
+
*/
|
|
107
|
+
handler<R>(fn: (ctx: {
|
|
108
|
+
query: z.infer<TQuery>;
|
|
109
|
+
body: z.infer<TBody>;
|
|
110
|
+
params: z.infer<TParams>;
|
|
111
|
+
request: Request;
|
|
112
|
+
ctx: TCtx;
|
|
113
|
+
}) => R | Promise<R>): RouteBuilder<TQuery, TBody, TParams, TCtx, R, true>;
|
|
114
|
+
/**
|
|
115
|
+
* Resolve to the `RouteConfig` — the SAME value `defineRoute({...})` returns. COMPILE ERROR when
|
|
116
|
+
* `.handler()` was never called.
|
|
117
|
+
*/
|
|
118
|
+
build(...guard: THandlerSet extends true ? [] : [error: MissingHandlerError]): RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Start a fluent route definition. Chain `.query/.body/.params/.response/.status/.csrf` (all
|
|
122
|
+
* optional), then `.handler()` (required) and `.build()` for the `RouteConfig`.
|
|
123
|
+
*/
|
|
124
|
+
declare function route(): RouteBuilder;
|
|
125
|
+
|
|
67
126
|
/**
|
|
68
127
|
* Action wire-protocol accept mode per plan g3-server-actions-and-useaction
|
|
69
128
|
* v1.2 ADR D1. Default behavior (when omitted) is `'json'`. `'form'` opts the
|
|
@@ -112,6 +171,62 @@ interface ActionConfig<TInput extends z.ZodType, TCtx = unknown> {
|
|
|
112
171
|
*/
|
|
113
172
|
declare function defineAction<TInput extends z.ZodType, TCtx = unknown>(config: ActionConfig<TInput, TCtx>): ActionConfig<TInput, TCtx>;
|
|
114
173
|
|
|
174
|
+
/**
|
|
175
|
+
* M31 Phase 3 — `action()`, the fluent builder that replaces `defineAction({...})`.
|
|
176
|
+
*
|
|
177
|
+
* Pure type-state (mirrors `route-builder.ts`). `.input()` (required) sets the Zod schema whose
|
|
178
|
+
* `z.infer<>` types the handler's `ctx.input`; `.handler()` (required) closes the chain. `.build()`
|
|
179
|
+
* delegates to the internal {@link defineAction} (identity) — the action-execute path is UNCHANGED.
|
|
180
|
+
*
|
|
181
|
+
* export const createUser = action()
|
|
182
|
+
* .input(z.object({ email: z.string().email() }))
|
|
183
|
+
* .handler(({ input }) => createUser(input.email))
|
|
184
|
+
* .build()
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
/** Compile-error carrier: `.execute`/`.build()` reached before `.input()`. */
|
|
188
|
+
interface MissingInputError$1 {
|
|
189
|
+
readonly __theokitError: 'call .input(schema) before .handler(fn)';
|
|
190
|
+
}
|
|
191
|
+
/** Compile-error carrier: `.build()` before both `.input()` and `.handler()` are set. */
|
|
192
|
+
interface IncompleteActionError {
|
|
193
|
+
readonly __theokitError: 'an action needs .input(schema) and .handler(fn) before .build()';
|
|
194
|
+
}
|
|
195
|
+
/** A required-but-unset field. Branded so no ordinary value satisfies it (tRPC UnsetMarker). */
|
|
196
|
+
type UnsetMarker$1 = 'theokit.unset' & {
|
|
197
|
+
readonly __brand: 'theokit.unset';
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* The fluent action builder. `TInput` tracks the Zod schema (drives `ctx.input` inference);
|
|
201
|
+
* `THandlerSet` gates `.build()`.
|
|
202
|
+
*/
|
|
203
|
+
interface ActionBuilder<TInput extends z.ZodType | UnsetMarker$1 = UnsetMarker$1, TCtx = unknown, THandlerSet extends boolean = false> {
|
|
204
|
+
/** Set the Zod input schema. Required — every action declares its input contract (zod-is-SSOT). */
|
|
205
|
+
input<S extends z.ZodType>(schema: S): ActionBuilder<S, TCtx, THandlerSet>;
|
|
206
|
+
/** Wire-protocol accept mode (`'json'` default, `'form'` for FormData multipart). */
|
|
207
|
+
accept(mode: ActionAccept): ActionBuilder<TInput, TCtx, THandlerSet>;
|
|
208
|
+
/** Opt out of CSRF enforcement for this action. */
|
|
209
|
+
csrf(disabled: false): ActionBuilder<TInput, TCtx, THandlerSet>;
|
|
210
|
+
/**
|
|
211
|
+
* Set the handler. COMPILE ERROR before `.input()` — the param type collapses to
|
|
212
|
+
* {@link MissingInputError}. `ctx.input` is inferred via `z.infer<TInput>`.
|
|
213
|
+
*/
|
|
214
|
+
handler(fn: TInput extends z.ZodType ? (ctx: {
|
|
215
|
+
input: z.infer<TInput>;
|
|
216
|
+
ctx: TCtx;
|
|
217
|
+
}) => unknown : MissingInputError$1): ActionBuilder<TInput, TCtx, true>;
|
|
218
|
+
/**
|
|
219
|
+
* Resolve to the `ActionConfig` — the SAME value `defineAction({...})` returns. COMPILE ERROR when
|
|
220
|
+
* `.input()` or `.handler()` was never called.
|
|
221
|
+
*/
|
|
222
|
+
build(...guard: THandlerSet extends true ? TInput extends z.ZodType ? [] : [error: IncompleteActionError] : [error: IncompleteActionError]): ActionConfig<TInput extends z.ZodType ? TInput : z.ZodType, TCtx>;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Start a fluent action definition. Chain `.input()` (required), optionally `.accept()` / `.csrf()`,
|
|
226
|
+
* then `.handler()` (required) and `.build()` for the `ActionConfig`.
|
|
227
|
+
*/
|
|
228
|
+
declare function action(): ActionBuilder;
|
|
229
|
+
|
|
115
230
|
type MiddlewareHandler = (request: Request, next: (request: Request) => Promise<Response>) => Response | Promise<Response>;
|
|
116
231
|
/**
|
|
117
232
|
* Define a middleware handler.
|
|
@@ -119,6 +234,36 @@ type MiddlewareHandler = (request: Request, next: (request: Request) => Promise<
|
|
|
119
234
|
*/
|
|
120
235
|
declare function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler;
|
|
121
236
|
|
|
237
|
+
/**
|
|
238
|
+
* M31 Phase 3 — `middleware()`, the fluent builder that replaces `defineMiddleware(fn)`.
|
|
239
|
+
*
|
|
240
|
+
* A middleware IS a single function `(request, next) => Response`. The builder's `.handle()` sets it
|
|
241
|
+
* (required); `.build()` delegates to the internal {@link defineMiddleware} (identity) and returns
|
|
242
|
+
* the handler the runtime expects.
|
|
243
|
+
*
|
|
244
|
+
* export default middleware()
|
|
245
|
+
* .handle(async (request, next) => {
|
|
246
|
+
* const res = await next(request)
|
|
247
|
+
* res.headers.set('x-mw', '1')
|
|
248
|
+
* return res
|
|
249
|
+
* })
|
|
250
|
+
* .build()
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
/** Compile-error carrier: `.build()` called before `.handle()`. */
|
|
254
|
+
interface MissingHandleError {
|
|
255
|
+
readonly __theokitError: 'middleware needs .handle(fn) before .build()';
|
|
256
|
+
}
|
|
257
|
+
/** The fluent middleware builder. `THandleSet` gates `.build()`. */
|
|
258
|
+
interface MiddlewareBuilder<THandleSet extends boolean = false> {
|
|
259
|
+
/** Set the `(request, next) => Response` handler. Required before `.build()`. */
|
|
260
|
+
handle(fn: MiddlewareHandler): MiddlewareBuilder<true>;
|
|
261
|
+
/** Resolve to the `MiddlewareHandler`. COMPILE ERROR when `.handle()` was never called. */
|
|
262
|
+
build(...guard: THandleSet extends true ? [] : [error: MissingHandleError]): MiddlewareHandler;
|
|
263
|
+
}
|
|
264
|
+
/** Start a fluent middleware definition. Chain `.handle()` (required), then `.build()`. */
|
|
265
|
+
declare function middleware(): MiddlewareBuilder;
|
|
266
|
+
|
|
122
267
|
declare function uiMessageStreamResponse(chunks: AsyncIterable<UIMessageChunk>): Response;
|
|
123
268
|
|
|
124
269
|
/**
|
|
@@ -225,6 +370,95 @@ declare function defineAgentTool<T extends z.ZodType, R = string>(spec: DefineAg
|
|
|
225
370
|
*/
|
|
226
371
|
declare function applyTransform(tool: CustomTool, result: unknown, target: 'display' | 'transcript'): unknown;
|
|
227
372
|
|
|
373
|
+
/**
|
|
374
|
+
* M31 Phase 1 — `tool()`, the fluent builder that replaces `defineAgentTool({...})`.
|
|
375
|
+
*
|
|
376
|
+
* Pure type-state (tRPC `UnsetMarker` technique, mirroring `agent-builder.ts`). The runtime is a
|
|
377
|
+
* plain accumulator; `.build()` delegates to the internal {@link defineAgentTool}, so the emitted
|
|
378
|
+
* `CustomTool` is byte-for-byte the legacy shape — the SDK/agent compile path is UNCHANGED
|
|
379
|
+
* (identity-shape delegation, blueprint §2).
|
|
380
|
+
*
|
|
381
|
+
* PURE metadata (G2 / sdk-runtime.md): a tool describes a capability; it NEVER calls an LLM.
|
|
382
|
+
*
|
|
383
|
+
* tool('read')
|
|
384
|
+
* .describe('Read a UTF-8 file')
|
|
385
|
+
* .input(z.object({ path: z.string() }))
|
|
386
|
+
* .execute(async ({ path }, ctx) => readFile(resolveInProject(ctx, path)))
|
|
387
|
+
* .build()
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
/** A required-but-unset builder field. Branded so no ordinary value satisfies it (tRPC UnsetMarker). */
|
|
391
|
+
type UnsetMarker = 'theokit.unset' & {
|
|
392
|
+
readonly __brand: 'theokit.unset';
|
|
393
|
+
};
|
|
394
|
+
/** Compile-error carrier: `.execute()` called before `.input()`. */
|
|
395
|
+
interface MissingInputError {
|
|
396
|
+
readonly __theokitError: 'call .input(schema) before .execute(handler)';
|
|
397
|
+
}
|
|
398
|
+
/** Compile-error carrier: `.build()` called before both `.input()` and `.execute()` are set. */
|
|
399
|
+
interface IncompleteToolError {
|
|
400
|
+
readonly __theokitError: 'a tool needs .input(schema) and .execute(handler) before .build()';
|
|
401
|
+
}
|
|
402
|
+
/** The run context a tool handler receives (M7). */
|
|
403
|
+
interface ToolCtx {
|
|
404
|
+
signal?: AbortSignal;
|
|
405
|
+
context?: unknown;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* The fluent tool builder. Each method returns a NEW builder type with the relevant type parameter
|
|
409
|
+
* advanced. `TInput` tracks the Zod schema (drives `execute` input inference); `R` tracks the
|
|
410
|
+
* handler result; `THandlerSet` gates `.build()`.
|
|
411
|
+
*/
|
|
412
|
+
interface ToolBuilder<TName extends string = string, TInput extends z.ZodType | UnsetMarker = UnsetMarker, R = string, THandlerSet extends boolean = false> {
|
|
413
|
+
/** Set the LLM-facing description. Optional; an empty description warns at build (LLM selection). */
|
|
414
|
+
describe(description: string): ToolBuilder<TName, TInput, R, THandlerSet>;
|
|
415
|
+
/** Set the Zod input schema (must be `z.object(...)` at the root). Required before `.execute()`. */
|
|
416
|
+
input<S extends z.ZodType>(schema: S): ToolBuilder<TName, S, R, THandlerSet>;
|
|
417
|
+
/**
|
|
418
|
+
* Set the handler. COMPILE ERROR when `.input()` was not called first — the parameter type
|
|
419
|
+
* collapses to {@link MissingInputError}. The `input` argument is inferred via `z.infer<TInput>`.
|
|
420
|
+
*/
|
|
421
|
+
execute<R2>(handler: TInput extends z.ZodType ? (input: z.infer<TInput>, ctx?: ToolCtx) => R2 | Promise<R2> : MissingInputError): ToolBuilder<TName, TInput, R2, true>;
|
|
422
|
+
/** M18 — map a rich handler result to the model-visible string. */
|
|
423
|
+
toModelOutput(fn: (result: R) => string): ToolBuilder<TName, TInput, R, THandlerSet>;
|
|
424
|
+
/** M18 — per-target formatters (`display` / `transcript`) for the app UI/transcript. */
|
|
425
|
+
transform(t: ToolTransform<R>): ToolBuilder<TName, TInput, R, THandlerSet>;
|
|
426
|
+
/**
|
|
427
|
+
* Resolve to the `CustomTool` — the SAME value `defineAgentTool({...})` returns. COMPILE ERROR
|
|
428
|
+
* when `.input()` or `.execute()` was never called.
|
|
429
|
+
*/
|
|
430
|
+
build(...guard: THandlerSet extends true ? TInput extends z.ZodType ? [] : [error: IncompleteToolError] : [error: IncompleteToolError]): CustomTool;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Start a fluent tool definition. Chain `.input()` + `.execute()` (both required), optionally
|
|
434
|
+
* `.describe()` / `.toModelOutput()` / `.transform()`, then `.build()` for the `CustomTool`.
|
|
435
|
+
*/
|
|
436
|
+
declare function tool<TName extends string>(name: TName): ToolBuilder<TName>;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* M31 Phase 3 — `websocket()`, the fluent builder that replaces `defineWebSocket({...})`.
|
|
440
|
+
*
|
|
441
|
+
* Lifecycle setters (`onOpen/onMessage/onClose/onError`), all optional; `.build()` delegates to the
|
|
442
|
+
* internal {@link defineWebSocket} (identity) — the ws handler loading path is UNCHANGED.
|
|
443
|
+
*
|
|
444
|
+
* export default websocket()
|
|
445
|
+
* .onOpen((ws) => ws.send('hi'))
|
|
446
|
+
* .onMessage((ws, data) => ws.send(`echo:${data}`))
|
|
447
|
+
* .build()
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
/** The fluent WebSocket builder. Each lifecycle hook is optional; `.build()` returns the handler. */
|
|
451
|
+
interface WebSocketBuilder {
|
|
452
|
+
onOpen(fn: NonNullable<WebSocketHandler['onOpen']>): WebSocketBuilder;
|
|
453
|
+
onMessage(fn: NonNullable<WebSocketHandler['onMessage']>): WebSocketBuilder;
|
|
454
|
+
onClose(fn: NonNullable<WebSocketHandler['onClose']>): WebSocketBuilder;
|
|
455
|
+
onError(fn: NonNullable<WebSocketHandler['onError']>): WebSocketBuilder;
|
|
456
|
+
/** Resolve to the `WebSocketHandler` — the SAME value `defineWebSocket({...})` returns. */
|
|
457
|
+
build(): WebSocketHandler;
|
|
458
|
+
}
|
|
459
|
+
/** Start a fluent WebSocket definition. Chain any of the lifecycle hooks, then `.build()`. */
|
|
460
|
+
declare function websocket(): WebSocketBuilder;
|
|
461
|
+
|
|
228
462
|
interface ChannelHandler<TMessage = unknown> {
|
|
229
463
|
onSubscribe?: (ws: WebSocketLike, room: string, req: IncomingMessage) => void;
|
|
230
464
|
onMessage?: (ws: WebSocketLike, room: string, data: TMessage) => void;
|
|
@@ -279,4 +513,35 @@ declare function defineWebChannel<TMessage = unknown>(handler: WebChannelHandler
|
|
|
279
513
|
*/
|
|
280
514
|
declare function defineTheoPlugin(plugin: TheoPlugin): TheoPlugin;
|
|
281
515
|
|
|
282
|
-
|
|
516
|
+
/**
|
|
517
|
+
* M31 Phase 3 — `plugin()`, the fluent builder that replaces `definePlugin({...})`.
|
|
518
|
+
*
|
|
519
|
+
* Collects lifecycle hooks + request decorations and SYNTHESIZES the `register(app)` function, so
|
|
520
|
+
* authors never write the imperative `register` body. `.build()` returns a `TheoPlugin` the plugin
|
|
521
|
+
* runner consumes UNCHANGED.
|
|
522
|
+
*
|
|
523
|
+
* export default plugin('request-id')
|
|
524
|
+
* .onRequest((ctx) => { ctx.ctx.requestId = crypto.randomUUID() })
|
|
525
|
+
* .onResponse((ctx) => { ctx.response.setHeader('x-request-id', String(ctx.ctx.requestId)) })
|
|
526
|
+
* .build()
|
|
527
|
+
*/
|
|
528
|
+
|
|
529
|
+
/** The fluent plugin builder. `name` is set at entry; every hook is optional and may repeat. */
|
|
530
|
+
interface PluginBuilder {
|
|
531
|
+
/** Register an `onRequest` hook (runs before the CSRF gate). May be called multiple times. */
|
|
532
|
+
onRequest(fn: OnRequestHook): PluginBuilder;
|
|
533
|
+
/** Register a `preHandler` hook (after CSRF, before the route handler). */
|
|
534
|
+
preHandler(fn: PreHandlerHook): PluginBuilder;
|
|
535
|
+
/** Register an `onResponse` hook (after the handler returns). */
|
|
536
|
+
onResponse(fn: OnResponseHook): PluginBuilder;
|
|
537
|
+
/** Register an `onError` hook (error path). */
|
|
538
|
+
onError(fn: OnErrorHook): PluginBuilder;
|
|
539
|
+
/** Decorate every request with a key/value pair (available on `ctx.ctx[key]`). */
|
|
540
|
+
decorateRequest<T>(key: string, value: T): PluginBuilder;
|
|
541
|
+
/** Resolve to the `TheoPlugin` — a synthesized `{ name, register }` the runner consumes. */
|
|
542
|
+
build(): TheoPlugin;
|
|
543
|
+
}
|
|
544
|
+
/** Start a fluent plugin definition. `name` is required; chain hooks/decorations, then `.build()`. */
|
|
545
|
+
declare function plugin(name: string): PluginBuilder;
|
|
546
|
+
|
|
547
|
+
export { type ActionAccept, type ActionBuilder, type ActionConfig, type ChannelHandler, type CustomTool, type DefineAgentToolSpec, type MiddlewareBuilder, type MiddlewareHandler, type PluginBuilder, type RouteBuilder, type RouteConfig, type ToolBuilder, type ToolTransform, type WebChannelHandler, type WebSocketBuilder, WebSocketHandler, WebSocketLike, action, applyTransform, defineAction, defineAgentTool, defineChannel, defineMiddleware, defineRoute, defineTheoPlugin, defineWebChannel, middleware, plugin, route, tool, uiMessageStreamResponse, websocket };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
action,
|
|
2
3
|
applyTransform,
|
|
3
4
|
defineAction,
|
|
4
5
|
defineAgentTool,
|
|
@@ -8,8 +9,13 @@ import {
|
|
|
8
9
|
defineTheoPlugin,
|
|
9
10
|
defineWebChannel,
|
|
10
11
|
defineWebSocket,
|
|
11
|
-
defineWebSocketWeb
|
|
12
|
-
|
|
12
|
+
defineWebSocketWeb,
|
|
13
|
+
middleware,
|
|
14
|
+
plugin,
|
|
15
|
+
route,
|
|
16
|
+
tool,
|
|
17
|
+
websocket
|
|
18
|
+
} from "../../chunk-WLKFWVOM.js";
|
|
13
19
|
import {
|
|
14
20
|
uiMessageStreamResponse
|
|
15
21
|
} from "../../chunk-JZHT3LW7.js";
|
|
@@ -24,6 +30,7 @@ import "../../chunk-DGUM43GV.js";
|
|
|
24
30
|
export {
|
|
25
31
|
HEALTH_PATH,
|
|
26
32
|
READY_PATH,
|
|
33
|
+
action,
|
|
27
34
|
applyTransform,
|
|
28
35
|
defineAction,
|
|
29
36
|
defineAgentTool,
|
|
@@ -36,7 +43,12 @@ export {
|
|
|
36
43
|
defineWebChannel,
|
|
37
44
|
defineWebSocket,
|
|
38
45
|
defineWebSocketWeb,
|
|
46
|
+
middleware,
|
|
47
|
+
plugin,
|
|
48
|
+
route,
|
|
39
49
|
serveReservedRoute,
|
|
40
|
-
|
|
50
|
+
tool,
|
|
51
|
+
uiMessageStreamResponse,
|
|
52
|
+
websocket
|
|
41
53
|
};
|
|
42
54
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RouteConfig, CustomTool } from './define/index.js';
|
|
2
|
-
export { ActionAccept, ActionConfig, ChannelHandler, DefineAgentToolSpec, MiddlewareHandler, ToolTransform, WebChannelHandler, applyTransform, defineAction, defineAgentTool, defineChannel, defineMiddleware, defineRoute, defineTheoPlugin, defineWebChannel, uiMessageStreamResponse } from './define/index.js';
|
|
2
|
+
export { ActionAccept, ActionBuilder, ActionConfig, ChannelHandler, DefineAgentToolSpec, MiddlewareBuilder, MiddlewareHandler, PluginBuilder, RouteBuilder, ToolBuilder, ToolTransform, WebChannelHandler, WebSocketBuilder, action, applyTransform, defineAction, defineAgentTool, defineChannel, defineMiddleware, defineRoute, defineTheoPlugin, defineWebChannel, middleware, plugin, route, tool, uiMessageStreamResponse, websocket } from './define/index.js';
|
|
3
3
|
export { W as WebSocketHandler, a as WebSocketHandlerWeb, b as WebSocketLike, d as defineWebSocket, c as defineWebSocketWeb } from '../define-websocket-CdK94O-D.js';
|
|
4
4
|
export { H as HEALTH_PATH, a as HealthRouteConfig, b as READY_PATH, c as ReadyRouteConfig, d as ReservedResponse, R as ReservedRoutes, e as defineHealthRoute, f as defineReadyRoute, s as serveReservedRoute } from '../health-route-C0hk64_U.js';
|
|
5
5
|
export { B as BATCH_PATH, a as BatchExecuteFn, b as BatchPathConflictError, c as BatchPayload, d as BatchRequestItem, e as BatchResponse, f as BatchResultItem, C as CookieOptions, g as CorsConfig, h as CorsHandler, i as CorsOrigin, j as CorsWebHandler, k as CustomErrorPages, E as ExecuteActionOptions, l as ExecuteRouteContext, H as HandleBatchOptions, M as MAX_ERROR_HTML_BYTES, m as MiddlewareResult, N as NotFoundError, S as STRIPPED_HEADERS, n as SendErrorInput, o as SendErrorOptions, T as TRACE_HEADER, p as TRACE_PARENT_HEADER, q as TheoError, r as TheoTransformer, _ as _resetMiddlewareCacheForTests, s as appendCookieToHeaders, t as appendDeleteCookieToHeaders, u as createCorsHandler, v as createCorsWebHandler, w as deleteCookie, x as envelopeCodeToStatus, y as executeAction, z as executeRoute, A as extractTraceId, D as extractTraceIdFromRequest, F as fromUnknown, G as getCookie, I as getCookieFromRequest, J as handleBatchRequest, K as handleRequestError, L as handleWebRequestError, O as jsonTransformer, P as loadCustomErrorPages, Q as matchesOrigin, R as parseCookieHeader, U as parseTraceparent, V as resolveTransformer, W as runMiddlewareAndContext, X as sendError, Y as sendJson, Z as serializeCookie, $ as serveStaticFile, a0 as serverErrorToEnvelope, a1 as setCookie, a2 as superjsonTransformer } from '../index-B40qUSrQ.js';
|
package/dist/server/index.js
CHANGED
|
@@ -165,17 +165,24 @@ import "../chunk-6NEXVBPY.js";
|
|
|
165
165
|
import "../chunk-7MQOHNHE.js";
|
|
166
166
|
import "../chunk-X2VVCJ4V.js";
|
|
167
167
|
import {
|
|
168
|
+
action,
|
|
168
169
|
applyTransform,
|
|
169
170
|
defineAction,
|
|
170
171
|
defineAgentTool,
|
|
171
172
|
defineChannel,
|
|
172
173
|
defineMiddleware,
|
|
174
|
+
definePlugin,
|
|
173
175
|
defineRoute,
|
|
174
176
|
defineTheoPlugin,
|
|
175
177
|
defineWebChannel,
|
|
176
178
|
defineWebSocket,
|
|
177
|
-
defineWebSocketWeb
|
|
178
|
-
|
|
179
|
+
defineWebSocketWeb,
|
|
180
|
+
middleware,
|
|
181
|
+
plugin,
|
|
182
|
+
route,
|
|
183
|
+
tool,
|
|
184
|
+
websocket
|
|
185
|
+
} from "../chunk-WLKFWVOM.js";
|
|
179
186
|
import {
|
|
180
187
|
uiMessageStreamResponse
|
|
181
188
|
} from "../chunk-JZHT3LW7.js";
|
|
@@ -1218,9 +1225,9 @@ function createVendorAgentTool(config) {
|
|
|
1218
1225
|
|
|
1219
1226
|
// src/server/agent/code-mode.ts
|
|
1220
1227
|
var CodeModePermissionDeniedError = class extends Error {
|
|
1221
|
-
constructor(
|
|
1228
|
+
constructor(tool2, reason) {
|
|
1222
1229
|
const suffix = reason ? `: ${reason}` : "";
|
|
1223
|
-
super(`code-mode: tool '${
|
|
1230
|
+
super(`code-mode: tool '${tool2}' denied by permission gate${suffix}`);
|
|
1224
1231
|
this.name = "CodeModePermissionDeniedError";
|
|
1225
1232
|
}
|
|
1226
1233
|
};
|
|
@@ -1237,11 +1244,11 @@ function createCodeMode(config) {
|
|
|
1237
1244
|
);
|
|
1238
1245
|
}
|
|
1239
1246
|
const api = {};
|
|
1240
|
-
for (const
|
|
1241
|
-
api[
|
|
1242
|
-
const decision = await config.onPermissionRequest({ tool:
|
|
1243
|
-
if (!decision.granted) throw new CodeModePermissionDeniedError(
|
|
1244
|
-
return
|
|
1247
|
+
for (const tool2 of config.tools) {
|
|
1248
|
+
api[tool2.name] = async (args) => {
|
|
1249
|
+
const decision = await config.onPermissionRequest({ tool: tool2.name, args });
|
|
1250
|
+
if (!decision.granted) throw new CodeModePermissionDeniedError(tool2.name, decision.reason);
|
|
1251
|
+
return tool2.handler(args);
|
|
1245
1252
|
};
|
|
1246
1253
|
}
|
|
1247
1254
|
return {
|
|
@@ -1349,11 +1356,6 @@ function deserializeResponse(serialized) {
|
|
|
1349
1356
|
return superjson.deserialize(serialized);
|
|
1350
1357
|
}
|
|
1351
1358
|
|
|
1352
|
-
// src/server/plugin-types.ts
|
|
1353
|
-
function definePlugin(plugin) {
|
|
1354
|
-
return plugin;
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
1359
|
// src/server/index.ts
|
|
1358
1360
|
if (typeof globalThis !== "undefined") {
|
|
1359
1361
|
const WARN_KEY = "__theokit_server_umbrella_warn_emitted__";
|
|
@@ -1429,6 +1431,7 @@ export {
|
|
|
1429
1431
|
_resetKeyCacheForTests,
|
|
1430
1432
|
_resetMiddlewareCacheForTests,
|
|
1431
1433
|
_resetWarnOnceForTests,
|
|
1434
|
+
action,
|
|
1432
1435
|
appendCookieToHeaders,
|
|
1433
1436
|
appendDeleteCookieToHeaders,
|
|
1434
1437
|
applySecurityHeaders,
|
|
@@ -1542,6 +1545,7 @@ export {
|
|
|
1542
1545
|
matchRoute,
|
|
1543
1546
|
matchRoutePattern,
|
|
1544
1547
|
matchesOrigin,
|
|
1548
|
+
middleware,
|
|
1545
1549
|
normalizeLegacy,
|
|
1546
1550
|
normalizeNew,
|
|
1547
1551
|
parseChannelPath,
|
|
@@ -1549,6 +1553,7 @@ export {
|
|
|
1549
1553
|
parseRequestBody,
|
|
1550
1554
|
parseTraceparent,
|
|
1551
1555
|
pkceChallengeFromVerifier,
|
|
1556
|
+
plugin,
|
|
1552
1557
|
readAppResource,
|
|
1553
1558
|
readRawBody,
|
|
1554
1559
|
recordAttempt,
|
|
@@ -1560,6 +1565,7 @@ export {
|
|
|
1560
1565
|
revalidateTag,
|
|
1561
1566
|
rotateIfNeeded,
|
|
1562
1567
|
rotateIfNeededWeb,
|
|
1568
|
+
route,
|
|
1563
1569
|
runMiddlewareAndContext,
|
|
1564
1570
|
safeAudit,
|
|
1565
1571
|
scanCrons,
|
|
@@ -1581,6 +1587,7 @@ export {
|
|
|
1581
1587
|
setCookie,
|
|
1582
1588
|
superjsonTransformer,
|
|
1583
1589
|
timingSafeEqual,
|
|
1590
|
+
tool,
|
|
1584
1591
|
totpUri,
|
|
1585
1592
|
trackAgentRun,
|
|
1586
1593
|
trackAgentTools,
|
|
@@ -1602,6 +1609,7 @@ export {
|
|
|
1602
1609
|
verifyOAuthState,
|
|
1603
1610
|
verifyTotp,
|
|
1604
1611
|
warnOnce,
|
|
1612
|
+
websocket,
|
|
1605
1613
|
writeCronManifest,
|
|
1606
1614
|
writeJobManifest,
|
|
1607
1615
|
writeManifest
|