stitchkit 0.36.1 → 0.37.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/README.md +4 -2
- package/dist/browser/http.d.ts +2 -2
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/contract/define.d.ts +28 -2
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/{index-dvrn81q4.js → index-4pvtq6h2.js} +83 -34
- package/dist/{index-0ed3bx43.js → index-frfyw9fa.js} +2 -2
- package/dist/{index-pmftwk2a.js → index-g3jrbd0z.js} +26 -0
- package/dist/{index-82gncajj.js → index-s6yhmg1k.js} +555 -337
- package/dist/{index-bx49hskg.js → index-xq45akyd.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +7 -3
- package/dist/observability/index.js +3 -3
- package/dist/server/bun.d.ts +32 -0
- package/dist/server/bun.d.ts.map +1 -0
- package/dist/server/context.d.ts +1 -1
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/create.d.ts +2 -3
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/index.d.ts +3 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +25 -5
- package/dist/server/logger.d.ts +5 -5
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/logging.d.ts +4 -1
- package/dist/server/logging.d.ts.map +1 -1
- package/dist/server/middleware/auth.d.ts +2 -2
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/server/request-body.d.ts +4 -0
- package/dist/server/request-body.d.ts.map +1 -0
- package/dist/server/router.d.ts +3 -3
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/socket-io-config.d.ts +20 -0
- package/dist/server/socket-io-config.d.ts.map +1 -0
- package/dist/server/socket-io-node.d.ts +14 -0
- package/dist/server/socket-io-node.d.ts.map +1 -0
- package/dist/server/socket-io.d.ts +5 -32
- package/dist/server/socket-io.d.ts.map +1 -1
- package/dist/server/types.d.ts +54 -49
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/execute.d.ts +46 -16
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/flatten-join.d.ts +8 -0
- package/dist/tools/flatten-join.d.ts.map +1 -0
- package/dist/tools/flatten.d.ts +7 -44
- package/dist/tools/flatten.d.ts.map +1 -1
- package/dist/tools/json-schema.d.ts +1 -1
- package/dist/tools/json-schema.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp-handler.d.ts +7 -13
- package/dist/tools/mcp-handler.d.ts.map +1 -1
- package/dist/tools/mcp.d.ts +61 -24
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +9 -6
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/names.d.ts +1 -1
- package/dist/tools/native-mcp.d.ts +57 -0
- package/dist/tools/native-mcp.d.ts.map +1 -0
- package/dist/tools/portable-formats.d.ts +15 -0
- package/dist/tools/portable-formats.d.ts.map +1 -0
- package/dist/tools/presentation.d.ts +15 -0
- package/dist/tools/presentation.d.ts.map +1 -0
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/schema.d.ts +3 -8
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/tool-logger.d.ts.map +1 -1
- package/dist/tools/view-file.d.ts +5 -3
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools.d.ts +7 -4
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +357 -95
- package/llms-full.txt +371 -77
- package/package.json +14 -11
- /package/dist/{index-17rdjw68.js → index-e497hxcy.js} +0 -0
package/dist/server/types.d.ts
CHANGED
|
@@ -28,15 +28,25 @@ type RequiredRequest<E> = E extends {
|
|
|
28
28
|
} ? {
|
|
29
29
|
req: Request;
|
|
30
30
|
} : unknown;
|
|
31
|
+
type RetainedRawBody<E> = E extends {
|
|
32
|
+
rawBody: true;
|
|
33
|
+
} ? {
|
|
34
|
+
req: Request;
|
|
35
|
+
rawBody: string;
|
|
36
|
+
} : unknown;
|
|
31
37
|
export type Handlers<C extends Record<string, EndpointDef>, TCtx extends RuntimeContext = HandlerContext> = {
|
|
32
38
|
[K in keyof C]: (ctx: TCtx & {
|
|
33
39
|
params: InferParams<C[K]>;
|
|
34
40
|
input: InferInput<C[K]>;
|
|
35
|
-
} & RequiredRequest<C[K]>) => HandlerReturn<C[K]>;
|
|
41
|
+
} & RequiredRequest<C[K]> & RetainedRawBody<C[K]>) => HandlerReturn<C[K]>;
|
|
36
42
|
};
|
|
37
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Stable identity shared by HTTP contract endpoints and pathless native tool
|
|
45
|
+
* operations. Tool lifecycle/audit consume this shape; only `MethodDef` adds an
|
|
46
|
+
* HTTP route path and executable contract schemas.
|
|
47
|
+
*/
|
|
48
|
+
export interface OperationIdentity {
|
|
38
49
|
method: HttpMethod;
|
|
39
|
-
path: string;
|
|
40
50
|
desc: string;
|
|
41
51
|
/**
|
|
42
52
|
* Owning contract's prefix — the "service" half of a stable `(service, action)`
|
|
@@ -51,8 +61,21 @@ export interface MethodDef<TParams = unknown, TInput = unknown, TOutput = unknow
|
|
|
51
61
|
*/
|
|
52
62
|
key: string;
|
|
53
63
|
toolName?: string;
|
|
54
|
-
expose?: readonly Transport[];
|
|
55
64
|
scope?: string;
|
|
65
|
+
/** MCP Apps widget metadata — carried onto the MCP tool's `_meta.ui`. */
|
|
66
|
+
ui?: EndpointUiMeta;
|
|
67
|
+
/** MCP behavioural hints — carried onto the MCP tool's `annotations`. */
|
|
68
|
+
annotations?: EndpointToolAnnotations;
|
|
69
|
+
/**
|
|
70
|
+
* Opaque app-defined metadata from `EndpointDef.meta` — the core gives it no
|
|
71
|
+
* meaning. Read it in lifecycle hooks (`endpoint.meta?.X`) or on tool mounts;
|
|
72
|
+
* the consumer narrows the type. Never serialized to OpenAPI. → ADR 0021.
|
|
73
|
+
*/
|
|
74
|
+
meta?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
export interface MethodDef<TParams = unknown, TInput = unknown, TOutput = unknown> extends OperationIdentity {
|
|
77
|
+
path: string;
|
|
78
|
+
expose?: readonly Transport[];
|
|
56
79
|
paramsSchema?: ZodType<TParams>;
|
|
57
80
|
inputSchema?: ZodType<TInput>;
|
|
58
81
|
outputSchema?: ZodType<TOutput>;
|
|
@@ -60,6 +83,8 @@ export interface MethodDef<TParams = unknown, TInput = unknown, TOutput = unknow
|
|
|
60
83
|
/** Per-route upload ceiling (bytes) for a multipart endpoint — overrides the
|
|
61
84
|
* server `maxUploadBytes` default; from `EndpointDef.maxUploadBytes`. */
|
|
62
85
|
maxUploadBytes?: number;
|
|
86
|
+
/** Per-route JSON body ceiling; enforced before full buffering. */
|
|
87
|
+
maxJsonBodyBytes?: number;
|
|
63
88
|
/**
|
|
64
89
|
* Whether the operation is safe to call twice with the same input — from
|
|
65
90
|
* `EndpointDef.idempotent`. The core attaches no behaviour; a retrying
|
|
@@ -67,22 +92,14 @@ export interface MethodDef<TParams = unknown, TInput = unknown, TOutput = unknow
|
|
|
67
92
|
* → ADR 0027.
|
|
68
93
|
*/
|
|
69
94
|
idempotent?: boolean;
|
|
70
|
-
/** MCP Apps widget metadata — carried onto the MCP tool's `_meta.ui`. */
|
|
71
|
-
ui?: EndpointUiMeta;
|
|
72
|
-
/** MCP behavioural hints — carried onto the MCP tool's `annotations`. */
|
|
73
|
-
annotations?: EndpointToolAnnotations;
|
|
74
|
-
/**
|
|
75
|
-
* Opaque app-defined metadata from `EndpointDef.meta` — the core gives it no
|
|
76
|
-
* meaning. Read it in lifecycle hooks (`endpoint.meta?.X`) or on tool mounts;
|
|
77
|
-
* the consumer narrows the type. Never serialized to OpenAPI. → ADR 0021.
|
|
78
|
-
*/
|
|
79
|
-
meta?: Record<string, unknown>;
|
|
80
95
|
/**
|
|
81
96
|
* The handler returns the `Response` itself — from `EndpointDef.rawResponse`. Routed
|
|
82
97
|
* and gated like any endpoint, but never serialized, never validated against
|
|
83
98
|
* an output schema and never mounted as a tool. → ADR 0038.
|
|
84
99
|
*/
|
|
85
100
|
rawResponse?: true;
|
|
101
|
+
/** Retain the decoded JSON request text on `ctx.rawBody`. HTTP-only. */
|
|
102
|
+
rawBody?: true;
|
|
86
103
|
/** Documented response media type of a raw-response endpoint — OpenAPI only. */
|
|
87
104
|
contentType?: string;
|
|
88
105
|
handler: (ctx: RuntimeContext) => Promise<TOutput> | TOutput;
|
|
@@ -113,10 +130,8 @@ export interface RouteGroup {
|
|
|
113
130
|
* but the handler is raw `Request → Response` — no schema parsing and no
|
|
114
131
|
* `beforeHandle` auth gate; the route authorizes itself.
|
|
115
132
|
*/
|
|
116
|
-
/** The concrete `Bun.serve` server instance, passed through to raw handlers. */
|
|
117
|
-
export type BunServer = ReturnType<typeof Bun.serve>;
|
|
118
133
|
/** Context passed to a `RawRoute` handler alongside the raw `Request`. */
|
|
119
|
-
export interface RawRouteContext {
|
|
134
|
+
export interface RawRouteContext<TServer = unknown> {
|
|
120
135
|
/**
|
|
121
136
|
* Matched `:param` path segments. A trailing `/*` wildcard also adds its
|
|
122
137
|
* remainder (everything after the prefix) as `params['*']`. Empty for an exact
|
|
@@ -124,17 +139,18 @@ export interface RawRouteContext {
|
|
|
124
139
|
*/
|
|
125
140
|
params: Record<string, string>;
|
|
126
141
|
/**
|
|
127
|
-
* The
|
|
142
|
+
* The runtime server instance. It defaults to `unknown` at the Fetch-clean
|
|
143
|
+
* boundary and is concrete on runtime-owned APIs such as `createServer`.
|
|
128
144
|
* Absent when the handler runs via the bare `createHandler` fetch.
|
|
129
145
|
*/
|
|
130
|
-
server?:
|
|
146
|
+
server?: TServer;
|
|
131
147
|
/**
|
|
132
148
|
* Client IP — the real socket peer, or the `x-forwarded-for` client when
|
|
133
149
|
* `trustProxy` is set. Resolved by the framework; never spoofable by default.
|
|
134
150
|
*/
|
|
135
151
|
ipAddress?: string;
|
|
136
152
|
}
|
|
137
|
-
export interface RawRoute {
|
|
153
|
+
export interface RawRoute<TServer = unknown> {
|
|
138
154
|
method: HttpMethod | 'ALL';
|
|
139
155
|
/**
|
|
140
156
|
* Exact path, `:param` segments, or a trailing `/*` prefix wildcard. The
|
|
@@ -147,7 +163,7 @@ export interface RawRoute {
|
|
|
147
163
|
* `ctx` (matched path params, the server). Errors thrown here are caught by
|
|
148
164
|
* the router and run through `hooks.onError` — same shape as contract errors.
|
|
149
165
|
*/
|
|
150
|
-
handler: (req: Request, ctx: RawRouteContext) => Response | Promise<Response>;
|
|
166
|
+
handler: (req: Request, ctx: RawRouteContext<TServer>) => Response | Promise<Response>;
|
|
151
167
|
}
|
|
152
168
|
export interface StitchLogger {
|
|
153
169
|
info(msg: string, data?: Record<string, unknown>): void;
|
|
@@ -210,6 +226,12 @@ export interface LoggingConfig {
|
|
|
210
226
|
* `status`, `durationMs`, `errorCode` and `ip` in both sinks, plus `ts`,
|
|
211
227
|
* `level` and `msg` on the built-in production line.
|
|
212
228
|
*
|
|
229
|
+
* One outcome-aware exception: on a `4xx`/`5xx` where the framework derived
|
|
230
|
+
* no code (for example, a raw route returned an error `Response`), enrichment
|
|
231
|
+
* may supply `errorCode`. It still cannot forge one on a `2xx`/`3xx` or
|
|
232
|
+
* replace a framework-derived code. A discarded owned key warns once per
|
|
233
|
+
* handler instead of failing silently.
|
|
234
|
+
*
|
|
213
235
|
* Four things to know:
|
|
214
236
|
* - It reaches the structured output only: the production JSON line and a
|
|
215
237
|
* custom logger's `data`. The development `←` line stays as it is — it is a
|
|
@@ -234,12 +256,12 @@ export interface LoggingConfig {
|
|
|
234
256
|
* the runtime. The optional second argument is the runtime's server handle:
|
|
235
257
|
* Bun passes one (raw routes need it for upgrades), Node adapters never do.
|
|
236
258
|
*/
|
|
237
|
-
export type FetchHandler = (req: Request, server?:
|
|
259
|
+
export type FetchHandler<TServer = unknown> = (req: Request, server?: TServer) => Promise<Response>;
|
|
238
260
|
/**
|
|
239
261
|
* Runtime-neutral handler config — everything `createHandler` needs.
|
|
240
262
|
* No Bun globals, no Bun types. This is the portability seam.
|
|
241
263
|
*/
|
|
242
|
-
export interface HandlerConfig {
|
|
264
|
+
export interface HandlerConfig<TServer = unknown> {
|
|
243
265
|
services?: ServiceDef[];
|
|
244
266
|
groups?: RouteGroup[];
|
|
245
267
|
/**
|
|
@@ -253,13 +275,19 @@ export interface HandlerConfig {
|
|
|
253
275
|
* the core attaches no meaning beyond this lookup. → ADR 0024.
|
|
254
276
|
*/
|
|
255
277
|
scopePrefixes?: Record<string, string>;
|
|
256
|
-
rawRoutes?: RawRoute[];
|
|
278
|
+
rawRoutes?: RawRoute<TServer>[];
|
|
257
279
|
/**
|
|
258
280
|
* Default upload ceiling (bytes) for every `multipart` endpoint. A per-route
|
|
259
281
|
* `EndpointDef.maxUploadBytes` overrides it; without either, multipart uploads
|
|
260
282
|
* are capped at the 25 MB framework default.
|
|
261
283
|
*/
|
|
262
284
|
maxUploadBytes?: number;
|
|
285
|
+
/**
|
|
286
|
+
* Default JSON request-body ceiling in bytes. A per-route
|
|
287
|
+
* `EndpointDef.maxJsonBodyBytes` overrides it. Unset preserves the existing
|
|
288
|
+
* unbounded JSON-body behaviour.
|
|
289
|
+
*/
|
|
290
|
+
maxJsonBodyBytes?: number;
|
|
263
291
|
cors?: CorsConfig;
|
|
264
292
|
hooks?: LifecycleHooks;
|
|
265
293
|
logging?: boolean | LoggingConfig;
|
|
@@ -292,17 +320,6 @@ export interface HandlerConfig {
|
|
|
292
320
|
*/
|
|
293
321
|
trustProxy?: boolean;
|
|
294
322
|
}
|
|
295
|
-
type BunServeOptions = Parameters<typeof Bun.serve>[0];
|
|
296
|
-
type BunWebSocketHandlers = BunServeOptions extends {
|
|
297
|
-
websocket?: infer T;
|
|
298
|
-
} ? T : never;
|
|
299
|
-
type BunRoutes = BunServeOptions extends {
|
|
300
|
-
routes?: infer T;
|
|
301
|
-
} ? T : never;
|
|
302
|
-
type BunDevelopmentOptions = BunServeOptions extends {
|
|
303
|
-
development?: infer T;
|
|
304
|
-
} ? T : never;
|
|
305
|
-
export type ServerPassthrough = Omit<BunServeOptions, 'fetch' | 'port' | 'hostname' | 'unix' | 'routes' | 'websocket' | 'development'>;
|
|
306
323
|
/**
|
|
307
324
|
* The composition seam shared by the servers that own their own `fetch`.
|
|
308
325
|
*
|
|
@@ -318,20 +335,8 @@ export type ServerPassthrough = Omit<BunServeOptions, 'fetch' | 'port' | 'hostna
|
|
|
318
335
|
* createServer({ services, wrapFetch: (h) => wrapInRequestContext(audit.http(h)) })
|
|
319
336
|
* ```
|
|
320
337
|
*/
|
|
321
|
-
export interface FetchComposition {
|
|
322
|
-
wrapFetch?: (fetch: FetchHandler) => FetchHandler
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Full config for `createServer` — extends `HandlerConfig` with Bun-specific
|
|
326
|
-
* options (`Bun.serve` routes, websocket, development, passthrough).
|
|
327
|
-
*/
|
|
328
|
-
export interface BunServerConfig extends HandlerConfig, FetchComposition {
|
|
329
|
-
port?: number;
|
|
330
|
-
hostname?: string;
|
|
331
|
-
routes?: BunRoutes;
|
|
332
|
-
websocket?: BunWebSocketHandlers;
|
|
333
|
-
development?: BunDevelopmentOptions;
|
|
334
|
-
bun?: ServerPassthrough;
|
|
338
|
+
export interface FetchComposition<TServer = unknown> {
|
|
339
|
+
wrapFetch?: (fetch: FetchHandler<TServer>) => FetchHandler<TServer>;
|
|
335
340
|
}
|
|
336
341
|
export {};
|
|
337
342
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EACV,WAAW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1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mEAAmE;IACnE,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC5D,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,UAAU,GAAG,UAAU,EAAE,EACnC,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CAmDT"}
|
package/dist/tools/execute.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ZodType, z } from 'zod';
|
|
1
2
|
import type { RuntimeContext, TransportSource } from '../contract';
|
|
2
|
-
import type {
|
|
3
|
+
import type { OperationIdentity } from '../server/types';
|
|
3
4
|
export type ToolResult = {
|
|
4
5
|
ok: true;
|
|
5
6
|
data: unknown;
|
|
@@ -13,8 +14,26 @@ export interface ToolCallContext {
|
|
|
13
14
|
source: TransportSource;
|
|
14
15
|
[key: string]: unknown;
|
|
15
16
|
}
|
|
17
|
+
export interface BeforeToolCallOptions {
|
|
18
|
+
toolName: string;
|
|
19
|
+
args: Record<string, unknown>;
|
|
20
|
+
context: ToolCallContext;
|
|
21
|
+
endpoint: OperationIdentity;
|
|
22
|
+
}
|
|
23
|
+
export interface AfterToolCallOptions extends BeforeToolCallOptions {
|
|
24
|
+
result: ToolResult;
|
|
25
|
+
durationMs: number;
|
|
26
|
+
/** The value as thrown; absent for failures that did not throw. */
|
|
27
|
+
error?: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ToolErrorOptions {
|
|
30
|
+
toolName: string;
|
|
31
|
+
error: unknown;
|
|
32
|
+
context: ToolCallContext;
|
|
33
|
+
endpoint: OperationIdentity;
|
|
34
|
+
}
|
|
16
35
|
export interface ToolCallHooks {
|
|
17
|
-
beforeToolCall?: (
|
|
36
|
+
beforeToolCall?: (options: BeforeToolCallOptions) => void | Promise<void>;
|
|
18
37
|
/**
|
|
19
38
|
* Every finished call, success and failure alike — the record of the call.
|
|
20
39
|
*
|
|
@@ -24,23 +43,22 @@ export interface ToolCallHooks {
|
|
|
24
43
|
* It is the same value `onToolError` receives, handed here too so a single
|
|
25
44
|
* hook can build one row that names the cause: the `result` alone cannot,
|
|
26
45
|
* because an unexpected throw is scrubbed to a bare `INTERNAL_SERVER_ERROR`.
|
|
27
|
-
* A six-parameter hook is unaffected.
|
|
28
46
|
*/
|
|
29
|
-
afterToolCall?: (
|
|
47
|
+
afterToolCall?: (options: AfterToolCallOptions) => void | Promise<void>;
|
|
30
48
|
/**
|
|
31
|
-
* The
|
|
49
|
+
* The tool execution path threw — the value **as thrown**, before it is normalised
|
|
32
50
|
* into a `ToolResult`. The tool-side answer to HTTP's `hooks.onError`, and the
|
|
33
51
|
* only place the real cause of an unexpected failure is reachable: an error
|
|
34
52
|
* that is not an `AppError` is scrubbed to a bare `INTERNAL_SERVER_ERROR` with
|
|
35
53
|
* no details, so by the time `afterToolCall` sees the result, the stack, the
|
|
36
54
|
* `cause` chain and the message are gone.
|
|
37
55
|
*
|
|
38
|
-
* Fires for a throw from `
|
|
39
|
-
* `lifecycle.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* the
|
|
56
|
+
* Fires for a throw from executable input parsing (`ToolExtend`, params or
|
|
57
|
+
* input), extension resolution, `lifecycle.beforeHandle`, the handler, or
|
|
58
|
+
* `lifecycle.afterHandle` — every span where the raw cause would otherwise be
|
|
59
|
+
* destroyed. It does **not** fire for a normal validation result, a
|
|
60
|
+
* `beforeToolCall` rejection or an output-schema mismatch: each is already
|
|
61
|
+
* described in full by the `ToolResult` that `afterToolCall` receives.
|
|
44
62
|
*
|
|
45
63
|
* This is observation, not an error handler — the tool envelope is always
|
|
46
64
|
* `toolResultFromError`, so the return value is ignored and a throw from the
|
|
@@ -49,7 +67,7 @@ export interface ToolCallHooks {
|
|
|
49
67
|
* records (a request-context error, say) is already in place when the audit
|
|
50
68
|
* hook reads it.
|
|
51
69
|
*/
|
|
52
|
-
onToolError?: (
|
|
70
|
+
onToolError?: (options: ToolErrorOptions) => void | Promise<void>;
|
|
53
71
|
}
|
|
54
72
|
/**
|
|
55
73
|
* A per-tool hint appended to a failed tool result — given the tool name and the
|
|
@@ -75,9 +93,21 @@ export type ErrorHintFn = (toolName: string, errorCode: string) => string | null
|
|
|
75
93
|
*/
|
|
76
94
|
export interface ToolLifecycle {
|
|
77
95
|
/** Auth / scope gate — throw to reject the call. */
|
|
78
|
-
beforeHandle?: (ctx: RuntimeContext, endpoint:
|
|
96
|
+
beforeHandle?: (ctx: RuntimeContext, endpoint: OperationIdentity) => void | Promise<void>;
|
|
79
97
|
/** Transform the handler result before it is returned. */
|
|
80
|
-
afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint:
|
|
98
|
+
afterHandle?: (ctx: RuntimeContext, result: unknown, endpoint: OperationIdentity) => unknown | Promise<unknown>;
|
|
99
|
+
}
|
|
100
|
+
/** Executable tool operation; contract methods and native tools share this runner shape. */
|
|
101
|
+
export interface ToolOperation extends OperationIdentity {
|
|
102
|
+
paramsSchema?: ZodType;
|
|
103
|
+
inputSchema?: ZodType;
|
|
104
|
+
outputSchema?: ZodType;
|
|
105
|
+
handler(ctx: RuntimeContext): unknown | Promise<unknown>;
|
|
106
|
+
}
|
|
107
|
+
/** Executable extension parsed once inside the shared runner before resolution. */
|
|
108
|
+
export interface ToolArgumentExtension {
|
|
109
|
+
schema: z.ZodObject;
|
|
110
|
+
resolve: (args: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
81
111
|
}
|
|
82
112
|
/**
|
|
83
113
|
* Normalise any thrown value into a failed `ToolResult` — the one place an
|
|
@@ -87,7 +117,7 @@ export interface ToolLifecycle {
|
|
|
87
117
|
export declare function toolResultFromError(err: unknown): Extract<ToolResult, {
|
|
88
118
|
ok: false;
|
|
89
119
|
}>;
|
|
90
|
-
export declare function executeToolMethod(method:
|
|
120
|
+
export declare function executeToolMethod(method: ToolOperation, toolName: string, rawArgs: Record<string, unknown>, context: ToolCallContext, hooks?: ToolCallHooks, lifecycle?: ToolLifecycle, coerceJson?: boolean, onOutputStrip?: (paths: string[]) => void, extension?: ToolArgumentExtension): Promise<ToolResult>;
|
|
91
121
|
/**
|
|
92
122
|
* Run `body` in a request context forked for one tool call — the shared rule,
|
|
93
123
|
* so every entry point isolates the same way. A mount uses it around
|
|
@@ -101,6 +131,6 @@ export declare function executeToolMethod(method: MethodDef<unknown, unknown, un
|
|
|
101
131
|
export declare function inToolCallContext<T>(call: {
|
|
102
132
|
source: TransportSource;
|
|
103
133
|
toolName: string;
|
|
104
|
-
method:
|
|
134
|
+
method: OperationIdentity;
|
|
105
135
|
}, body: () => Promise<T>): Promise<T>;
|
|
106
136
|
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIzD,MAAM,MAAM,UAAU,GAClB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC3B;IAAE,EAAE,EAAE,KAAK,CAAC;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a,EACzB,UAAU,UAAQ,EAClB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,EACzC,SAAS,CAAC,EAAE,qBAAqB,GAChC,OAAO,CAAC,UAAU,CAAC,CAyBrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE;IACJ,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,iBAAiB,CAAC;CAC3B,EACD,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolPresentationSchema } from './flatten';
|
|
2
|
+
export interface VariantProperty {
|
|
3
|
+
schema: ToolPresentationSchema;
|
|
4
|
+
labels: string[];
|
|
5
|
+
required: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function mergePropertySchemas(properties: VariantProperty[]): ToolPresentationSchema;
|
|
8
|
+
//# sourceMappingURL=flatten-join.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten-join.d.ts","sourceRoot":"","sources":["../../src/tools/flatten-join.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAgID,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,sBAAsB,CAuB1F"}
|
package/dist/tools/flatten.d.ts
CHANGED
|
@@ -1,47 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
export type ToolPresentationSchema = Record<string, unknown>;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The discriminator becomes a `z.enum(...)` of **all** variant values; each
|
|
7
|
-
* variant's fields become optional with a `.describe()` hint naming the variants
|
|
8
|
-
* that require them. When two variants declare the **same key with different
|
|
9
|
-
* shapes**, the advertised field is widened so it accepts every variant's value —
|
|
10
|
-
* never narrowed to one (which would make the losing variant unsatisfiable):
|
|
11
|
-
*
|
|
12
|
-
* - identical across variants → kept as-is.
|
|
13
|
-
* - all string literal/enum → merged into one widened `z.enum`.
|
|
14
|
-
* - otherwise (object vs array, differing object shapes) → `z.unknown()` (accepts
|
|
15
|
-
* anything; the `.describe()` carries the per-variant shape).
|
|
16
|
-
*
|
|
17
|
-
* This keeps the advertised schema free of `oneOf` / `anyOf` at any depth (→ ADR
|
|
18
|
-
* 0033) **and** a superset of the original union, so a model can always produce a
|
|
19
|
-
* value that passes both the transport SDK and validation.
|
|
20
|
-
*
|
|
21
|
-
* **Key policy is merged, not dropped.** The flat object stands in for every
|
|
22
|
-
* variant, so it takes the policy that cannot remove what any variant would have
|
|
23
|
-
* kept: every variant `.strict()` → strict (sound, because the flat shape is the
|
|
24
|
-
* union of all variant keys); any variant with a catchall → loose; otherwise
|
|
25
|
-
* plain. A *typed* catchall is never copied onto the flat object — it would
|
|
26
|
-
* reject a sibling variant's differently-typed extra key.
|
|
27
|
-
*
|
|
28
|
-
* **Still lossy:** per-variant strictness (a key legal in variant A and illegal
|
|
29
|
-
* in B) is unrepresentable in one flat object, as are object-level refinements.
|
|
30
|
-
* Those stay enforced only by the original union in `executeToolMethod`. What is
|
|
31
|
-
* *not* lossy any more is deletion — the advertised schema can no longer drop a
|
|
32
|
-
* key the contract would have seen. → ADR 0034.
|
|
3
|
+
* Rebuild a JSON Schema and replace every structurally identifiable
|
|
4
|
+
* discriminated object `oneOf` with one conservative object-shaped join.
|
|
5
|
+
* Plain unions remain unions. The source document is never mutated.
|
|
33
6
|
*/
|
|
34
|
-
export declare function
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
* top level and nested inside object fields, array items, plain unions, records,
|
|
38
|
-
* and `optional` / `nullable` / `default` / intersection wrappers — so the
|
|
39
|
-
* advertised JSON Schema carries no `oneOf` / `anyOf` at any depth. A union that
|
|
40
|
-
* cannot be flattened (non-string discriminator, non-object variant) is left
|
|
41
|
-
* untouched rather than crashing the mount (→ ADR 0033).
|
|
42
|
-
*
|
|
43
|
-
* Every object is rebuilt **with its key policy** (`rebuildObject`) — the walk
|
|
44
|
-
* changes union shape, never what an object does with an undeclared key. → ADR 0034.
|
|
45
|
-
*/
|
|
46
|
-
export declare function flattenUnionsDeep(schema: z.core.$ZodType): z.ZodType;
|
|
7
|
+
export declare function flattenToolJsonSchema(schema: ToolPresentationSchema): ToolPresentationSchema;
|
|
8
|
+
/** Freeze every JSON object/array in a prepared presentation document. */
|
|
9
|
+
export declare function freezeToolJsonSchema(schema: ToolPresentationSchema): ToolPresentationSchema;
|
|
47
10
|
//# sourceMappingURL=flatten.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/tools/flatten.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA6J7D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,sBAAsB,GAAG,sBAAsB,CAG5F;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,sBAAsB,GAAG,sBAAsB,CAG3F"}
|
|
@@ -21,7 +21,7 @@ export type JsonSchemaIo = 'input' | 'output';
|
|
|
21
21
|
* The OpenAPI generator wants this: one `z.date()` field must not collapse a
|
|
22
22
|
* whole endpoint's schema to `{}`.
|
|
23
23
|
*/
|
|
24
|
-
export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo, unrepresentable?: 'throw' | 'any'): Record<string, unknown>;
|
|
24
|
+
export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo, unrepresentable?: 'throw' | 'any', target?: 'draft-07' | 'draft-2020-12'): Record<string, unknown>;
|
|
25
25
|
/** One top-level property of an object JSON Schema. */
|
|
26
26
|
export interface JsonSchemaField {
|
|
27
27
|
/** Property name. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/tools/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,CAAC,CAAC,OAAO,EACjB,EAAE,EAAE,YAAY,EAChB,eAAe,GAAE,OAAO,GAAG,KAAe,
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/tools/json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,CAAC,CAAC,OAAO,EACjB,EAAE,EAAE,YAAY,EAChB,eAAe,GAAE,OAAO,GAAG,KAAe,EAC1C,MAAM,GAAE,UAAU,GAAG,eAAiC,GACrD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB;AAED,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAOD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,EAAE,CAqBvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/tools/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,iBAAiB,EAAE,CAM7E"}
|
|
@@ -10,23 +10,17 @@ export interface McpHandlerConfig<TAuth> extends McpServerBuildConfig<TAuth> {
|
|
|
10
10
|
* with `oauthProtectedResourceRoute(protectedResource)`.
|
|
11
11
|
*/
|
|
12
12
|
protectedResource?: ProtectedResourceConfig;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
* session store. A restart / deploy / scale-out therefore never invalidates a
|
|
17
|
-
* client (no `404 Session not found`), which is what most request/response
|
|
18
|
-
* tool servers want. The trade-off is no server-initiated messages
|
|
19
|
-
* (`notifications/progress`, standalone SSE) between requests — fine for
|
|
20
|
-
* synchronous tools. Leave `false` only when you need that server push.
|
|
21
|
-
*/
|
|
22
|
-
stateless?: boolean;
|
|
13
|
+
/** HTTP transport state. Default `'stateless'`; opt into `'stateful'` only
|
|
14
|
+
* for cross-request progress, server push or resumable SSE sessions. */
|
|
15
|
+
sessionMode?: McpSessionMode;
|
|
23
16
|
}
|
|
17
|
+
export type McpSessionMode = 'stateful' | 'stateless';
|
|
24
18
|
/**
|
|
25
19
|
* Build a Streamable-HTTP MCP request handler (`Request → Response`).
|
|
26
20
|
*
|
|
27
|
-
* Owns the
|
|
28
|
-
*
|
|
29
|
-
*
|
|
21
|
+
* Owns the MCP server/transport lifecycle — and, only in explicit stateful
|
|
22
|
+
* mode, the SSE event/session stores — so the consuming app never imports the
|
|
23
|
+
* SDK itself. The app only declares WHAT to expose:
|
|
30
24
|
* how to authenticate and which contract services. MCP tools come from
|
|
31
25
|
* contracts; native multimodal tools attach via `nativeTools`.
|
|
32
26
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-handler.ts"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/tools/mcp-handler.ts"],"names":[],"mappings":"AASA,OAAO,EAGL,KAAK,oBAAoB,EAE1B,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,uBAAuB,EAAyB,MAAM,kBAAkB,CAAC;AAqEvF,MAAM,WAAW,gBAAgB,CAAC,KAAK,CAAE,SAAQ,oBAAoB,CAAC,KAAK,CAAC;IAC1E,uEAAuE;IACvE,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC7D;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C;6EACyE;IACzE,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,WAAW,CAAC;AAoBtD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAC9B,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CA2HrC"}
|