stitchkit 0.3.0 → 0.4.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.
Files changed (99) hide show
  1. package/README.md +11 -10
  2. package/dist/browser/client.d.ts.map +1 -1
  3. package/dist/browser/socket-io.d.ts +17 -0
  4. package/dist/browser/socket-io.d.ts.map +1 -1
  5. package/dist/cli.d.ts +23 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +21 -0
  8. package/dist/contract/define.d.ts +35 -2
  9. package/dist/contract/define.d.ts.map +1 -1
  10. package/dist/contract/index.d.ts +1 -1
  11. package/dist/contract/index.d.ts.map +1 -1
  12. package/dist/contract/index.js +2 -1
  13. package/dist/index-0ed3bx43.js +33 -0
  14. package/dist/index-0ma1eqv4.js +1007 -0
  15. package/dist/index-1cf8jkhf.js +219 -0
  16. package/dist/index-37x76zdn.js +4 -0
  17. package/dist/{index-dpj1jcys.js → index-3qmtdfpa.js} +156 -4
  18. package/dist/index-48ffdxgk.js +6 -0
  19. package/dist/{index-4kz3aqpx.js → index-78q1qm7v.js} +4 -1
  20. package/dist/{index-kckky6zw.js → index-afzt3nmx.js} +1 -1
  21. package/dist/{index-4b1j82gp.js → index-d4rwrjbc.js} +1 -1
  22. package/dist/{index-0t460v7k.js → index-vhdvv00d.js} +1 -1
  23. package/dist/index-x3fcszf8.js +8 -0
  24. package/dist/index.js +16 -4
  25. package/dist/internal/http-input.d.ts +13 -0
  26. package/dist/internal/http-input.d.ts.map +1 -0
  27. package/dist/internal/secure-fetch.d.ts +27 -0
  28. package/dist/internal/secure-fetch.d.ts.map +1 -0
  29. package/dist/internal/within-dir.d.ts.map +1 -1
  30. package/dist/node.d.ts +10 -1
  31. package/dist/node.d.ts.map +1 -1
  32. package/dist/node.js +38 -7
  33. package/dist/observability/audit.d.ts.map +1 -1
  34. package/dist/observability/event.d.ts +4 -0
  35. package/dist/observability/event.d.ts.map +1 -1
  36. package/dist/observability/index.js +3 -0
  37. package/dist/react.js +2 -0
  38. package/dist/server/implement.d.ts.map +1 -1
  39. package/dist/server/index.d.ts +5 -2
  40. package/dist/server/index.d.ts.map +1 -1
  41. package/dist/server/index.js +172 -216
  42. package/dist/server/middleware/auth.d.ts +17 -0
  43. package/dist/server/middleware/auth.d.ts.map +1 -1
  44. package/dist/server/middleware/pkce.d.ts +17 -0
  45. package/dist/server/middleware/pkce.d.ts.map +1 -0
  46. package/dist/server/node.d.ts +9 -0
  47. package/dist/server/node.d.ts.map +1 -1
  48. package/dist/server/openapi.d.ts +52 -0
  49. package/dist/server/openapi.d.ts.map +1 -0
  50. package/dist/server/socket-io.d.ts +60 -15
  51. package/dist/server/socket-io.d.ts.map +1 -1
  52. package/dist/server/types.d.ts +5 -1
  53. package/dist/server/types.d.ts.map +1 -1
  54. package/dist/server/websocket.d.ts +73 -0
  55. package/dist/server/websocket.d.ts.map +1 -0
  56. package/dist/tools/cli-args.d.ts +68 -0
  57. package/dist/tools/cli-args.d.ts.map +1 -0
  58. package/dist/tools/cli-format.d.ts +39 -0
  59. package/dist/tools/cli-format.d.ts.map +1 -0
  60. package/dist/tools/cli-wait.d.ts +45 -0
  61. package/dist/tools/cli-wait.d.ts.map +1 -0
  62. package/dist/tools/cli.d.ts +77 -0
  63. package/dist/tools/cli.d.ts.map +1 -0
  64. package/dist/tools/coerce.d.ts.map +1 -1
  65. package/dist/tools/json-schema.d.ts +29 -4
  66. package/dist/tools/json-schema.d.ts.map +1 -1
  67. package/dist/tools/mcp-app.d.ts +59 -0
  68. package/dist/tools/mcp-app.d.ts.map +1 -0
  69. package/dist/tools/mcp-handler.d.ts +18 -0
  70. package/dist/tools/mcp-handler.d.ts.map +1 -1
  71. package/dist/tools/mcp.d.ts +9 -0
  72. package/dist/tools/mcp.d.ts.map +1 -1
  73. package/dist/tools/mount-download.d.ts +30 -0
  74. package/dist/tools/mount-download.d.ts.map +1 -0
  75. package/dist/tools/mount-upload.d.ts +19 -0
  76. package/dist/tools/mount-upload.d.ts.map +1 -0
  77. package/dist/tools/mount-wait.d.ts +36 -0
  78. package/dist/tools/mount-wait.d.ts.map +1 -0
  79. package/dist/tools/mount.d.ts +6 -2
  80. package/dist/tools/mount.d.ts.map +1 -1
  81. package/dist/tools/native-result.d.ts +17 -0
  82. package/dist/tools/native-result.d.ts.map +1 -0
  83. package/dist/tools/oauth-metadata.d.ts +28 -0
  84. package/dist/tools/oauth-metadata.d.ts.map +1 -0
  85. package/dist/tools/oauth-provider.d.ts +85 -0
  86. package/dist/tools/oauth-provider.d.ts.map +1 -0
  87. package/dist/tools/remote.d.ts +2 -2
  88. package/dist/tools/remote.d.ts.map +1 -1
  89. package/dist/tools/toolkit.d.ts +51 -0
  90. package/dist/tools/toolkit.d.ts.map +1 -0
  91. package/dist/tools/view-file.d.ts +12 -0
  92. package/dist/tools/view-file.d.ts.map +1 -1
  93. package/dist/tools/wait-core.d.ts +33 -0
  94. package/dist/tools/wait-core.d.ts.map +1 -0
  95. package/dist/tools.d.ts +12 -1
  96. package/dist/tools.d.ts.map +1 -1
  97. package/dist/tools.js +587 -421
  98. package/package.json +22 -9
  99. package/dist/index-q6ja2qwq.js +0 -7
@@ -0,0 +1,52 @@
1
+ /**
2
+ * OpenAPI 3.1 generation from contracts. A `defineContract` already carries the
3
+ * full type information — Zod `params` / `input` / `output`, `desc`, `method`,
4
+ * `path`, `scope` — so the spec is generated, not hand-maintained: the contract
5
+ * IS the spec. No decorators, no duplicated annotations. → ADR 0018.
6
+ *
7
+ * Schemas are converted through the same single `toJsonSchema` point the tool
8
+ * layer uses (and `jsonSchemaFields`, shared with the CLI `--help` walker), so
9
+ * the JSON Schema in the spec is the JSON Schema the rest of the framework
10
+ * emits — not a divergent code path. Schemas are inlined (valid OpenAPI);
11
+ * `$ref` de-duplication can come later if a spec grows unwieldy.
12
+ */
13
+ import type { RawRoute, ServiceDef } from './types';
14
+ export interface OpenApiInfo {
15
+ title: string;
16
+ version: string;
17
+ description?: string;
18
+ }
19
+ export interface OpenApiServer {
20
+ url: string;
21
+ description?: string;
22
+ }
23
+ export interface OpenApiConfig {
24
+ info: OpenApiInfo;
25
+ /** Flat services, mounted at their own prefix. */
26
+ services?: ServiceDef[];
27
+ /** Grouped services, each mounted under a path prefix (mirrors `RouteGroup`). */
28
+ groups?: Array<{
29
+ pathPrefix?: string;
30
+ services: ServiceDef[];
31
+ }>;
32
+ /** `servers` block for the spec. */
33
+ servers?: OpenApiServer[];
34
+ }
35
+ export interface OpenApiDocument {
36
+ openapi: '3.1.0';
37
+ info: OpenApiInfo;
38
+ servers?: OpenApiServer[];
39
+ paths: Record<string, Record<string, unknown>>;
40
+ }
41
+ /**
42
+ * Generate an OpenAPI 3.1 document from contract services. Only methods exposed
43
+ * on HTTP are included — a method whose `expose` omits `'HTTP'` (an MCP/agent
44
+ * only tool) is skipped, matching the router's own route-building rule.
45
+ */
46
+ export declare function generateOpenApiDocument(config: OpenApiConfig): OpenApiDocument;
47
+ /**
48
+ * A `RawRoute` that serves a generated OpenAPI document as JSON — mount it
49
+ * alongside contract routes to expose `/openapi.json`.
50
+ */
51
+ export declare function openApiRoute(path: string, document: OpenApiDocument): RawRoute;
52
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/server/openapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACxB,iFAAiF;IACjF,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC,CAAC;IAChE,oCAAoC;IACpC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAChD;AAsED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe,CAgH9E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,QAAQ,CAM9E"}
@@ -1,20 +1,26 @@
1
1
  /**
2
- * Socket.IO server setup — the family WebSocket server boilerplate.
2
+ * Socket.IO server setup — the family WebSocket server boilerplate, runtime-aware.
3
3
  *
4
- * Every project repeats the same wiring: `new SocketIOServer(...)`, a
5
- * `@socket.io/bun-engine` instance, `io.bind(engine)`, `engine.handler()` for
6
- * the `Bun.serve` `websocket` field, and an `/socket.io/*` route delegating to
7
- * `engine.handleRequest`. `createSocketIOServer` is exactly that wiring.
4
+ * The engine differs per runtime, so the socket packages are loaded **lazily**
5
+ * (dynamic `import` inside the function) — a `type`-only import at the top would
6
+ * still be erased, but a top-level *value* import of `@socket.io/bun-engine`
7
+ * (Bun-only) would crash the whole `stitchkit/server` barrel on Node before any
8
+ * socket code runs. Lazy loading keeps the barrel Node-importable for apps that
9
+ * never use sockets.
8
10
  *
9
- * Connection handlers, rooms and handshake auth stay in the project — they are
10
- * domain logic. This helper owns only the transport plumbing: it returns the
11
- * typed `io` to attach handlers to, the `websocket` handler for `Bun.serve`,
12
- * and a ready-made `route` to drop into `createServer({ rawRoutes })`.
11
+ * - **Bun** — `@socket.io/bun-engine` + `io.bind(engine)`; returns the
12
+ * `websocket` handler for `Bun.serve` and a `/socket.io/*` route.
13
+ * - **Node** — `io.attach(server)` onto the `node:http.Server` exposed by
14
+ * `serveNode` (srvx `server.node.server`); Socket.IO owns the `upgrade` event.
15
+ *
16
+ * Connection handlers, rooms and handshake auth stay in the project.
13
17
  */
14
- import { Server as BunEngine } from '@socket.io/bun-engine';
15
- import { Server as SocketIOServer } from 'socket.io';
18
+ import type { Server as HttpServer } from 'node:http';
19
+ import type { Server as BunEngine } from '@socket.io/bun-engine';
20
+ import type { Server as SocketIOServer } from 'socket.io';
16
21
  import type { SocketEventMap } from '../browser/socket-io';
17
22
  import type { RawRoute } from './types';
23
+ import { type ComposedLane } from './websocket';
18
24
  export interface SocketIOServerConfig {
19
25
  /** CORS — the browser origin(s) allowed to open a socket. */
20
26
  cors: {
@@ -23,7 +29,13 @@ export interface SocketIOServerConfig {
23
29
  };
24
30
  /** Socket.IO endpoint path. Default `/socket.io/`. */
25
31
  path?: string;
26
- /** Transports offered to clients. Default `['websocket', 'polling']`. */
32
+ /**
33
+ * Transports offered to clients. Default `['websocket', 'polling']` on Bun;
34
+ * on Node the default is `['websocket']` — Socket.IO shares the HTTP server
35
+ * with srvx there, so its polling request-handler would collide with srvx's;
36
+ * WebSocket uses the separate `upgrade` event and does not. Configure the
37
+ * client with `transports: ['websocket']` to match.
38
+ */
27
39
  transports?: Array<'websocket' | 'polling'>;
28
40
  /** Heartbeat: ms without a pong before the connection is dropped. Default `20000`. */
29
41
  pingTimeout?: number;
@@ -33,10 +45,43 @@ export interface SocketIOServerConfig {
33
45
  export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> {
34
46
  /** The typed Socket.IO server — attach `io.on('connection', ...)` handlers. */
35
47
  io: SocketIOServer<TClientEvents, TServerEvents>;
36
- /** WebSocket handler for `Bun.serve({ websocket })`. */
48
+ /**
49
+ * WebSocket handler for `Bun.serve({ websocket })`. Real on Bun; on Node it is
50
+ * an inert no-op — sockets there are driven by the `node:http.Server`
51
+ * `upgrade` event via `serveNode({ socket })`, never by this field — so a Bun
52
+ * consumer can pass it unconditionally without a runtime guard.
53
+ */
37
54
  websocket: ReturnType<BunEngine['handler']>['websocket'];
38
- /** Ready `/socket.io/*` route — drop into `createServer({ rawRoutes })`. */
55
+ /**
56
+ * `/socket.io/*` route for `createServer({ rawRoutes })`. Real on Bun; on Node
57
+ * it is unused (sockets attach to the http.Server via `serveNode({ socket })`)
58
+ * and throws if it is ever mounted — so it is safe to spread into `rawRoutes`
59
+ * unconditionally on either runtime.
60
+ */
39
61
  route: RawRoute;
62
+ /**
63
+ * Node only — attach the Socket.IO server to the `node:http.Server` from
64
+ * `serveNode`. A no-op on Bun (the engine + route handle transport there).
65
+ * `serveNode({ socket })` calls this for you.
66
+ */
67
+ attach(server: HttpServer): void;
40
68
  }
41
- export declare function createSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): SocketIOServerHandle<TServerEvents, TClientEvents>;
69
+ export declare function createSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): Promise<SocketIOServerHandle<TServerEvents, TClientEvents>>;
70
+ /**
71
+ * Wrap a Socket.IO handle's `websocket` as a catch-all {@link ComposedLane} for
72
+ * {@link composeWebSocketHandlers} — when a second, raw WebSocket lane shares
73
+ * the one `Bun.serve` websocket handler. It claims every socket no earlier
74
+ * (raw-marker) lane matched, so the engine owns whatever the raw lanes did not
75
+ * — and it never inspects the engine's opaque `ws.data`. Place it **last**.
76
+ *
77
+ * ```ts
78
+ * const ws = composeWebSocketHandlers([
79
+ * webSocketLane({ match: isPcmSocket, handlers: pcmHandlers }),
80
+ * socketIoLane(socket.websocket),
81
+ * ])
82
+ * ```
83
+ *
84
+ * Bun-only (so is the raw-lane composition it serves).
85
+ */
86
+ export declare function socketIoLane(websocket: SocketIOServerHandle<SocketEventMap, SocketEventMap>['websocket']): ComposedLane;
42
87
  //# sourceMappingURL=socket-io.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket-io.d.ts","sourceRoot":"","sources":["../../src/server/socket-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,oBAAoB;IACnC,6DAA6D;IAC7D,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3D,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,UAAU,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC5C,sFAAsF;IACtF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB,CACnC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc;IAEpC,+EAA+E;IAC/E,EAAE,EAAE,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACjD,wDAAwD;IACxD,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACzD,4EAA4E;IAC5E,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,aAAa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,CAAC,CAAC;IACzD;;;;;OAKG;IACH,KAAK,EAAE,QAAQ,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;CAClC;AAOD,wBAAsB,oBAAoB,CACxC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CA8D3F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,oBAAoB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,WAAW,CAAC,GAC3E,YAAY,CAMd"}
@@ -1,5 +1,5 @@
1
1
  import type { ZodType } from 'zod';
2
- import type { EndpointDef, HandlerContext, HttpMethod, RuntimeContext, Transport } from '../contract';
2
+ import type { EndpointDef, EndpointToolAnnotations, EndpointUiMeta, HandlerContext, HttpMethod, RuntimeContext, Transport } from '../contract';
3
3
  import type { CorsConfig } from './middleware/cors';
4
4
  type Prop<T, K extends string> = K extends keyof T ? T[K] : undefined;
5
5
  type InferParams<E> = Prop<E, 'params'> extends ZodType<infer P> ? P : undefined;
@@ -22,6 +22,10 @@ export interface MethodDef<TParams = unknown, TInput = unknown, TOutput = unknow
22
22
  inputSchema?: ZodType<TInput>;
23
23
  outputSchema?: ZodType<TOutput>;
24
24
  multipart?: string;
25
+ /** MCP Apps widget metadata — carried onto the MCP tool's `_meta.ui`. */
26
+ ui?: EndpointUiMeta;
27
+ /** MCP behavioural hints — carried onto the MCP tool's `annotations`. */
28
+ annotations?: EndpointToolAnnotations;
25
29
  handler: (ctx: RuntimeContext) => Promise<TOutput> | TOutput;
26
30
  }
27
31
  export interface ServiceDef {
@@ -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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C;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxC,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Compose one Bun `websocket` handler from several independent lanes.
3
+ *
4
+ * `Bun.serve` accepts a **single** `websocket` handler. `@socket.io/bun-engine`
5
+ * claims it (via `createSocketIOServer().websocket`). A project that also wants a
6
+ * second, truly-raw binary WebSocket lane on the same server — a high-frequency
7
+ * stream (PCM, video, large transfers) with no Socket.IO framing — has to
8
+ * hand-compose that one handler: route each socket to the engine or to its own
9
+ * raw handlers.
10
+ *
11
+ * The fragile part is the discriminator. Routing *to* Socket.IO means asking
12
+ * "is this an engine socket?", which forces inspecting the engine's opaque
13
+ * `ws.data` — a brittle guard, hard to keep cast-free. The fix here is to invert
14
+ * it: a raw lane stamps **its own** marker onto `ws.data` at upgrade time and is
15
+ * matched positively; Socket.IO is simply the **fallback** lane (matched last,
16
+ * `() => true`). The engine's data is therefore never inspected.
17
+ *
18
+ * Cast-free: each lane carries a type-predicate `match` that narrows
19
+ * `ServerWebSocket<unknown>` to its own data type, so the typed handlers are
20
+ * invoked without a single `as`.
21
+ *
22
+ * Bun-only. On Node, Socket.IO drives sockets through the `node:http.Server`
23
+ * `upgrade` event (`serveNode({ socket })`) — a different model, and a raw lane
24
+ * there would be a separate upgrade handler, not this composition.
25
+ */
26
+ import type { ServerWebSocket, WebSocketHandler } from 'bun';
27
+ /** One lane of a composed handler — a typed slice of the single Bun websocket. */
28
+ export interface WebSocketLane<TData> {
29
+ /**
30
+ * Type-predicate selecting the sockets this lane owns — usually a check on
31
+ * `ws.data` set at upgrade. As a predicate it narrows `ws` to the lane's data
32
+ * type, which is what keeps the handler call cast-free.
33
+ */
34
+ match: (ws: ServerWebSocket<unknown>) => ws is ServerWebSocket<TData>;
35
+ /** Handlers for this lane's sockets — `ws.data` is fully typed as `TData`. */
36
+ handlers: WebSocketHandler<TData>;
37
+ }
38
+ /** A lane already bridged to the loose (`unknown`) data type, ready to compose. */
39
+ export interface ComposedLane {
40
+ match: (ws: ServerWebSocket<unknown>) => boolean;
41
+ handlers: WebSocketHandler<unknown>;
42
+ }
43
+ /**
44
+ * Server-wide WebSocket tuning for the composed handler. Bun applies these to
45
+ * every socket on the server (they cannot be per-lane), so set them to the most
46
+ * permissive value across lanes — a raw binary lane typically needs a larger
47
+ * `maxPayloadLength` than Socket.IO's default (its `maxHttpBufferSize`, 1 MB).
48
+ */
49
+ export type WebSocketComposeConfig = Omit<WebSocketHandler<unknown>, 'open' | 'message' | 'close' | 'drain' | 'ping' | 'pong'>;
50
+ /**
51
+ * Build a `ComposedLane` from typed handlers. Each callback is wrapped so it
52
+ * fires only for sockets the lane's `match` predicate claims — narrowing `ws`
53
+ * to `ServerWebSocket<TData>` for the typed handler. This is the one bridge from
54
+ * Bun's single untyped `websocket` to a typed, per-lane handler, and it holds
55
+ * no casts.
56
+ */
57
+ export declare function webSocketLane<TData>(lane: WebSocketLane<TData>): ComposedLane;
58
+ /**
59
+ * Compose lanes into the single `websocket` handler for `createServer`. On each
60
+ * callback the first lane whose `match` claims the socket handles it — so put
61
+ * specific lanes (raw markers) first and the catch-all (Socket.IO,
62
+ * `socketIoLane`) last. `config` carries the server-wide tuning.
63
+ *
64
+ * ```ts
65
+ * const ws = composeWebSocketHandlers(
66
+ * [webSocketLane({ match: isPcmSocket, handlers: pcmHandlers }), socketIoLane(socket.websocket)],
67
+ * { maxPayloadLength: 16 * 1024 * 1024 },
68
+ * )
69
+ * createServer({ websocket: ws, rawRoutes: [socket.route, pcmUpgradeRoute] })
70
+ * ```
71
+ */
72
+ export declare function composeWebSocketHandlers(lanes: ComposedLane[], config?: WebSocketComposeConfig): WebSocketHandler<unknown>;
73
+ //# sourceMappingURL=websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/server/websocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAE7D,kFAAkF;AAClF,MAAM,WAAW,aAAa,CAAC,KAAK;IAClC;;;;OAIG;IACH,KAAK,EAAE,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;IACtE,8EAA8E;IAC9E,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;CACnC;AAED,mFAAmF;AACnF,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,CAAC,EAAE,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC;IACjD,QAAQ,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;CACrC;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,gBAAgB,CAAC,OAAO,CAAC,EACzB,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CACzD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,YAAY,CAyB7E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,YAAY,EAAE,EACrB,MAAM,CAAC,EAAE,sBAAsB,GAC9B,gBAAgB,CAAC,OAAO,CAAC,CAyB3B"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Turn a CLI `argv` slice into the flat argument object `executeToolMethod`
3
+ * parses — the CLI transport's front half, the counterpart of how the HTTP
4
+ * transport slices a `Request`.
5
+ *
6
+ * Two jobs the other transports never face:
7
+ * 1. **Reserved options.** `--json`, `--wait`, `--output-dir`, … are CLI
8
+ * behaviour, not tool arguments — they are stripped before the rest is read
9
+ * as tool args.
10
+ * 2. **String → typed coercion.** Every argv token is a string; the tool's Zod
11
+ * schema says what each field should be. We coerce primitives here
12
+ * (`--count 5` → `5`, `--flag` → `true`) and leave array / object values as
13
+ * strings for `executeToolMethod`'s `coerceJson` pass (the same path the MCP
14
+ * transport uses for an LLM's double-serialized JSON).
15
+ *
16
+ * The advertised schema is never mutated — coercion operates on the arguments,
17
+ * so a CLI call validates against the exact same contract schema an HTTP or MCP
18
+ * call does (ADR 0014 parity).
19
+ */
20
+ import { z } from 'zod';
21
+ /** CLI-behaviour flags, parsed out of argv before the tool arguments. */
22
+ export interface CliRunOptions {
23
+ /** `--json` — emit raw JSON on stdout for piping. */
24
+ json: boolean;
25
+ /** `--wait` — block-poll an async result to a terminal state. */
26
+ wait: boolean;
27
+ /** `--wait-timeout <seconds>` — override the poll timeout. */
28
+ waitTimeout?: number;
29
+ /** `--output-dir <dir>` — download result media into this directory. */
30
+ outputDir?: string;
31
+ /** `--quiet` — suppress non-essential stderr chatter. */
32
+ quiet: boolean;
33
+ /** `--dry-run` — print the resolved call instead of executing it. */
34
+ dryRun: boolean;
35
+ /** `--help` / `-h` — print usage for the command. */
36
+ help: boolean;
37
+ }
38
+ export interface ParsedCliArgs {
39
+ /** The flat tool-argument object handed to `executeToolMethod`. */
40
+ toolArgs: Record<string, unknown>;
41
+ /** The CLI-behaviour flags. */
42
+ options: CliRunOptions;
43
+ }
44
+ type FieldKind = 'boolean' | 'number' | 'bigint' | 'date' | 'string' | 'enum' | 'array' | 'object' | 'other';
45
+ interface FieldInfo {
46
+ kind: FieldKind;
47
+ /** Element kind for an `array` field — drives per-element coercion. */
48
+ elementKind?: FieldKind;
49
+ }
50
+ /**
51
+ * Map a merged tool schema to per-field kind info — what each `--flag` should
52
+ * coerce to. A non-object schema (a union) yields an empty map: every value is
53
+ * left as a string and the schema validates it.
54
+ */
55
+ export declare function describeSchemaFields(schema: z.ZodType | undefined): Map<string, FieldInfo>;
56
+ /**
57
+ * Parse a command's argv slice (everything after the command name) against its
58
+ * merged tool schema.
59
+ *
60
+ * Supported forms:
61
+ * - `--key value` / `--key=value` / `-` repeated for arrays
62
+ * - `--flag` boolean presence, `--no-flag` to negate
63
+ * - `--a.b=c` dotted path → nested object (loose-coerced leaf)
64
+ * - positional args fill non-boolean fields in schema-declaration order
65
+ */
66
+ export declare function parseCliArgs(argv: string[], schema: z.ZodType | undefined): ParsedCliArgs;
67
+ export {};
68
+ //# sourceMappingURL=cli-args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../src/tools/cli-args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,IAAI,EAAE,OAAO,CAAC;IACd,iEAAiE;IACjE,IAAI,EAAE,OAAO,CAAC;IACd,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,KAAK,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,MAAM,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,KAAK,SAAS,GACV,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,MAAM,GACN,OAAO,GACP,QAAQ,GACR,OAAO,CAAC;AAEZ,UAAU,SAAS;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,uEAAuE;IACvE,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB;AA6BD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAa1F;AAmFD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,aAAa,CAkIzF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Render a `ToolResult` for the CLI surface and map it to a process exit code.
3
+ *
4
+ * Output is JSON — the CLI's audience is agents (Skills via Bash), scripts and
5
+ * `| jq`, for which structured JSON is the right shape, not a hand-formatted
6
+ * table. The default is pretty-printed (indented, the same shape an MCP tool
7
+ * returns); `--json` switches to a compact single line for piping.
8
+ *
9
+ * stdout is reserved for that result; an error goes to stderr as the same
10
+ * model-facing `{ error, details, _hint }` object the MCP / agent transports
11
+ * return (`formatToolError`), so a script can keep `2>/dev/null` clean while
12
+ * still parsing a success.
13
+ */
14
+ import type { ToolResult } from './execute';
15
+ /** Map a `ToolResult.code` to a process exit code. */
16
+ export type ExitCodeMap = Record<string, number>;
17
+ /**
18
+ * Conventional exit codes — `0` success, distinct non-zero per error class so a
19
+ * script can branch on `$?`. Merged under any `CliConfig.exitCodes` override.
20
+ */
21
+ export declare const DEFAULT_EXIT_CODES: ExitCodeMap;
22
+ export interface CliWriters {
23
+ stdout: (text: string) => void;
24
+ stderr: (text: string) => void;
25
+ }
26
+ export interface EmitOptions {
27
+ /** Compact single-line JSON (for `| jq` / scripts); otherwise pretty-printed. */
28
+ json: boolean;
29
+ toolName: string;
30
+ errorHint?: (toolName: string, errorCode: string) => string | null;
31
+ exitCodes?: ExitCodeMap;
32
+ }
33
+ /**
34
+ * Write a result to the right stream and return the exit code. Success → JSON
35
+ * on stdout (pretty by default, compact with `--json`), exit `0`. Failure → the
36
+ * error JSON on stderr, exit per the code map (unknown code → `1`).
37
+ */
38
+ export declare function emitResult(result: ToolResult, writers: CliWriters, opts: EmitOptions): number;
39
+ //# sourceMappingURL=cli-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-format.d.ts","sourceRoot":"","sources":["../../src/tools/cli-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAUhC,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,iFAAiF;IACjF,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACnE,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAChB,MAAM,CAeR"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `--wait` polling — block on an async tool result until it reaches a terminal
3
+ * state. The headline CLI feature (a `Bash(run_in_background)` generation that
4
+ * notifies when done), kept strictly generic per ADR 0002: the core knows
5
+ * nothing about generations or statuses. The consumer supplies how to read the
6
+ * poll target from the first result (`poll`), which tool to re-call (`tool`)
7
+ * and when it is done (`done`).
8
+ */
9
+ import type { ToolResult } from './execute';
10
+ export interface CliWaitConfig {
11
+ /**
12
+ * Extract the poll-tool arguments from the initial result (e.g. `{ id }` from
13
+ * a `generate` response). Return `null` when there is nothing to wait on.
14
+ */
15
+ poll: (result: unknown) => Record<string, unknown> | null;
16
+ /** The tool/command name to call on each poll tick (e.g. `get_generation`). */
17
+ tool: string;
18
+ /** Done when this returns `true` for a poll result. */
19
+ done: (result: unknown) => boolean;
20
+ /** Backoff schedule in seconds; the last entry repeats. Default `[2,3,5,5,8,10]`. */
21
+ backoff?: number[];
22
+ /** Max seconds before giving up. Default `600`. */
23
+ timeout?: number;
24
+ }
25
+ export interface PollParams {
26
+ /** The result of the initial (non-poll) call. */
27
+ initial: ToolResult;
28
+ wait: CliWaitConfig;
29
+ /** Run a tool by name — the CLI binds this to its tool map + runner. */
30
+ call: (toolName: string, args: Record<string, unknown>) => Promise<ToolResult>;
31
+ /** Override `wait.timeout` (from `--wait-timeout`). */
32
+ timeoutSec?: number;
33
+ /** Progress callback — the CLI logs ticks to stderr unless `--quiet`. */
34
+ onTick?: (attempt: number, elapsedSec: number) => void;
35
+ /** Injectable sleep for tests. */
36
+ sleepFn?: (ms: number) => Promise<void>;
37
+ }
38
+ /**
39
+ * Poll `wait.tool` until `wait.done` or the timeout. Returns the last poll
40
+ * result; returns the initial result untouched when the initial call failed,
41
+ * already satisfies `done`, or yields no poll target. A timeout produces a
42
+ * `TIMEOUT` failed `ToolResult`.
43
+ */
44
+ export declare function pollUntilDone(params: PollParams): Promise<ToolResult>;
45
+ //# sourceMappingURL=cli-wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-wait.d.ts","sourceRoot":"","sources":["../../src/tools/cli-wait.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1D,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IACnC,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,aAAa,CAAC;IACpB,wEAAwE;IACxE,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/E,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CA0B3E"}
@@ -0,0 +1,77 @@
1
+ import type { ServiceDef, StitchLogger } from '../server/types';
2
+ import { type ExitCodeMap } from './cli-format';
3
+ import { type CliWaitConfig } from './cli-wait';
4
+ import { type ToolCallHooks, type ToolLifecycle } from './execute';
5
+ export interface CliConfig<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>> {
6
+ /** Program name — shown in help and unknown-command messages. */
7
+ name: string;
8
+ /** Program version — printed by `--version`. */
9
+ version: string;
10
+ /** Contract services exposed as commands — may depend on the resolved identity. */
11
+ services: ServiceDef[] | ((auth: Awaited<TAuth> | undefined) => ServiceDef[]);
12
+ /**
13
+ * Identity for the single CLI invocation — resolved ONCE at startup (from an
14
+ * env var / token file), like a stdio MCP server, not per call. A value or a
15
+ * promise of one.
16
+ */
17
+ auth?: TAuth | Promise<TAuth>;
18
+ /**
19
+ * Context merged into every handler. Typed against the app's context shape
20
+ * when the CLI is built via `createToolkit<AppContext>()`.
21
+ */
22
+ context?: (auth: Awaited<TAuth> | undefined) => TContext;
23
+ /** Tool-call observability hooks — `afterToolCall` fires for every result. */
24
+ hooks?: ToolCallHooks;
25
+ /**
26
+ * Auth / scope gate — pass the same `createAuthHook` result used for the HTTP
27
+ * server's `beforeHandle` so a CLI command is guarded identically. Without it
28
+ * a scoped command bypasses the gate.
29
+ */
30
+ lifecycle?: ToolLifecycle;
31
+ /** Logger for diagnostics — defaults to stderr-safe `console.error`. */
32
+ logger?: StitchLogger;
33
+ /** Coerce JSON-stringified arrays/objects in arguments. Default: true. */
34
+ coerceJsonArgs?: boolean;
35
+ /** Global error hint appended to every failed command's error. */
36
+ errorHint?: (toolName: string, errorCode: string) => string | null;
37
+ /** Override exit codes per `ToolResult.code`, merged over the defaults. */
38
+ exitCodes?: ExitCodeMap;
39
+ /**
40
+ * Route a command's unknown `--flags` into a freeform object field, keyed by
41
+ * command name → field. Lets `generate <model> --prompt … --aspect_ratio 16:9`
42
+ * fill the model's `parameters` directly, instead of a `--parameters '{json}'`
43
+ * blob. Values are loosely coerced (`"30"` → `30`, `"true"` → `true`).
44
+ */
45
+ passthrough?: Record<string, string>;
46
+ /** Per-command `--wait` polling behaviour, keyed by command name. */
47
+ wait?: Record<string, CliWaitConfig>;
48
+ /** Extract downloadable media URLs from a result for `--output-dir`. */
49
+ download?: (result: unknown) => Array<{
50
+ url: string;
51
+ name: string;
52
+ }>;
53
+ /**
54
+ * Allow `--output-dir` downloads from private / internal / loopback hosts.
55
+ * Default `false` — the SSRF guard, since the URLs come from handler output.
56
+ */
57
+ allowPrivateDownloadHosts?: boolean;
58
+ /** Max bytes per `--output-dir` download before aborting. Default 100 MB. */
59
+ maxDownloadBytes?: number;
60
+ /** argv to parse — default `process.argv.slice(2)`; injectable for tests. */
61
+ argv?: string[];
62
+ /** stdout sink — default `process.stdout`; injectable for tests. */
63
+ stdout?: (text: string) => void;
64
+ /** stderr sink — default `process.stderr`; injectable for tests. */
65
+ stderr?: (text: string) => void;
66
+ /** Exit hook — default `process.exit`; injectable for tests. */
67
+ exit?: (code: number) => void;
68
+ /** Read piped stdin — default reads when not a TTY; injectable for tests. */
69
+ stdin?: () => Promise<string | null>;
70
+ }
71
+ /**
72
+ * Build and run a CLI from contract services, then exit. Parses `process.argv`
73
+ * (or `config.argv`), routes to a command, executes it through the shared tool
74
+ * pipeline and writes the result. Resolves identity once up front.
75
+ */
76
+ export declare function createCli<TAuth = unknown, TContext extends Record<string, unknown> = Record<string, unknown>>(config: CliConfig<TAuth, TContext>): Promise<void>;
77
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/tools/cli.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,EAAsB,KAAK,WAAW,EAAc,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAC;AAKnB,MAAM,WAAW,SAAS,CACxB,KAAK,GAAG,OAAO,EACf,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAElE,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,KAAK,UAAU,EAAE,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ChC,gEAAgE;IAChE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACtC;AAyLD;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,KAAK,GAAG,OAAO,EACf,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkInD"}
@@ -1 +1 @@
1
- {"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/tools/coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB"}
1
+ {"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/tools/coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsBxB;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,SAAS,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB"}
@@ -10,9 +10,34 @@ import { z } from 'zod';
10
10
  /** Conversion direction — `input` for tool arguments, `output` for results. */
11
11
  export type JsonSchemaIo = 'input' | 'output';
12
12
  /**
13
- * Convert a Zod schema to JSON Schema. Throws on a construct JSON Schema cannot
14
- * represent (`z.date()`, `z.bigint()`, `z.map()`, …). The caller decides what
15
- * to do with that failure — see `onIncompatibleSchema`.
13
+ * Convert a Zod schema to JSON Schema (draft-2020-12, the dialect OpenAPI 3.1
14
+ * uses). `unrepresentable` controls a construct JSON Schema cannot represent
15
+ * (`z.date()`, `z.bigint()`, `z.map()`, …):
16
+ *
17
+ * - `'throw'` (default) — throws for the whole schema. The tools layer wants
18
+ * this: it mirrors what the MCP SDK does, so a build-time probe catches an
19
+ * incompatible schema instead of shipping a tool the SDK would later reject.
20
+ * - `'any'` — degrades only the offending field to `{}` and keeps the rest.
21
+ * The OpenAPI generator wants this: one `z.date()` field must not collapse a
22
+ * whole endpoint's schema to `{}`.
23
+ */
24
+ export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo, unrepresentable?: 'throw' | 'any'): Record<string, unknown>;
25
+ /** One top-level property of an object JSON Schema. */
26
+ export interface JsonSchemaField {
27
+ /** Property name. */
28
+ name: string;
29
+ /** The property's own JSON Schema sub-document. */
30
+ schema: Record<string, unknown>;
31
+ /** Whether the property is in the schema's `required` list. */
32
+ required: boolean;
33
+ /** `description` (a Zod `.describe()`), when present. */
34
+ description?: string;
35
+ }
36
+ /**
37
+ * Extract the top-level object properties of a JSON Schema as a flat field list
38
+ * — the shared traversal behind CLI `--help` flag tables and OpenAPI
39
+ * `parameters`. Returns `[]` for a non-object schema (a union, a scalar); the
40
+ * caller decides how to degrade.
16
41
  */
17
- export declare function toJsonSchema(schema: z.ZodType, io: JsonSchemaIo): Record<string, unknown>;
42
+ export declare function jsonSchemaFields(jsonSchema: Record<string, unknown>): JsonSchemaField[];
18
43
  //# sourceMappingURL=json-schema.d.ts.map
@@ -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;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzF"}
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,GACzC,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"}