@workerstack/clients 0.0.0-stage → 1.0.0-rc.23
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/LICENSE +21 -0
- package/README.md +619 -2
- package/bin/honey-clients.js +94 -0
- package/dist/cli.d.ts +102 -0
- package/dist/cli.js +190 -0
- package/dist/emit/cli/channels.d.ts +73 -0
- package/dist/emit/cli/channels.js +197 -0
- package/dist/emit/cli/commands.d.ts +27 -0
- package/dist/emit/cli/commands.js +187 -0
- package/dist/emit/cli/discovery.d.ts +35 -0
- package/dist/emit/cli/discovery.js +202 -0
- package/dist/emit/cli/flags.d.ts +59 -0
- package/dist/emit/cli/flags.js +186 -0
- package/dist/emit/cli/index.d.ts +1 -0
- package/dist/emit/cli/index.js +1 -0
- package/dist/emit/cli/install.d.ts +37 -0
- package/dist/emit/cli/install.js +88 -0
- package/dist/emit/cli/layout.d.ts +23 -0
- package/dist/emit/cli/layout.js +118 -0
- package/dist/emit/cli/module.d.ts +30 -0
- package/dist/emit/cli/module.js +186 -0
- package/dist/emit/cli/release.d.ts +40 -0
- package/dist/emit/cli/release.js +183 -0
- package/dist/emit/cli/skills.d.ts +11 -0
- package/dist/emit/cli/skills.js +56 -0
- package/dist/emit/csharp/errors.d.ts +7 -0
- package/dist/emit/csharp/errors.js +69 -0
- package/dist/emit/csharp/index.d.ts +1 -0
- package/dist/emit/csharp/index.js +1 -0
- package/dist/emit/csharp/json.d.ts +13 -0
- package/dist/emit/csharp/json.js +113 -0
- package/dist/emit/csharp/realtime.d.ts +10 -0
- package/dist/emit/csharp/realtime.js +33 -0
- package/dist/emit/csharp/sdk-answer.d.ts +48 -0
- package/dist/emit/csharp/sdk-answer.js +85 -0
- package/dist/emit/csharp/sdk-body.d.ts +10 -0
- package/dist/emit/csharp/sdk-body.js +87 -0
- package/dist/emit/csharp/sdk-client.d.ts +32 -0
- package/dist/emit/csharp/sdk-client.js +177 -0
- package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
- package/dist/emit/csharp/sdk-csproj.js +136 -0
- package/dist/emit/csharp/sdk-doc.d.ts +12 -0
- package/dist/emit/csharp/sdk-doc.js +35 -0
- package/dist/emit/csharp/sdk-method.d.ts +26 -0
- package/dist/emit/csharp/sdk-method.js +187 -0
- package/dist/emit/csharp/sdk-plan.d.ts +38 -0
- package/dist/emit/csharp/sdk-plan.js +1 -0
- package/dist/emit/csharp/sdk.d.ts +40 -0
- package/dist/emit/csharp/sdk.js +105 -0
- package/dist/emit/csharp/sse.d.ts +18 -0
- package/dist/emit/csharp/sse.js +29 -0
- package/dist/emit/csharp/transport.d.ts +11 -0
- package/dist/emit/csharp/transport.js +67 -0
- package/dist/emit/csharp/types-enum.d.ts +19 -0
- package/dist/emit/csharp/types-enum.js +63 -0
- package/dist/emit/csharp/types-names.d.ts +33 -0
- package/dist/emit/csharp/types-names.js +182 -0
- package/dist/emit/csharp/types-record.d.ts +25 -0
- package/dist/emit/csharp/types-record.js +65 -0
- package/dist/emit/csharp/types-union.d.ts +27 -0
- package/dist/emit/csharp/types-union.js +113 -0
- package/dist/emit/csharp/types.d.ts +36 -0
- package/dist/emit/csharp/types.js +126 -0
- package/dist/emit/csharp/ws.d.ts +20 -0
- package/dist/emit/csharp/ws.js +14 -0
- package/dist/emit/go/errors.d.ts +7 -0
- package/dist/emit/go/errors.js +44 -0
- package/dist/emit/go/http.d.ts +11 -0
- package/dist/emit/go/http.js +50 -0
- package/dist/emit/go/index.d.ts +1 -0
- package/dist/emit/go/index.js +1 -0
- package/dist/emit/go/module-path.d.ts +2 -0
- package/dist/emit/go/module-path.js +27 -0
- package/dist/emit/go/sdk-answer.d.ts +28 -0
- package/dist/emit/go/sdk-answer.js +41 -0
- package/dist/emit/go/sdk-body.d.ts +24 -0
- package/dist/emit/go/sdk-body.js +76 -0
- package/dist/emit/go/sdk-client.d.ts +29 -0
- package/dist/emit/go/sdk-client.js +141 -0
- package/dist/emit/go/sdk-method.d.ts +68 -0
- package/dist/emit/go/sdk-method.js +172 -0
- package/dist/emit/go/sdk-mirror.d.ts +23 -0
- package/dist/emit/go/sdk-mirror.js +97 -0
- package/dist/emit/go/sdk-opts.d.ts +55 -0
- package/dist/emit/go/sdk-opts.js +100 -0
- package/dist/emit/go/sdk.d.ts +26 -0
- package/dist/emit/go/sdk.js +111 -0
- package/dist/emit/go/sse.d.ts +16 -0
- package/dist/emit/go/sse.js +26 -0
- package/dist/emit/go/types-codec.d.ts +15 -0
- package/dist/emit/go/types-codec.js +171 -0
- package/dist/emit/go/types-names.d.ts +14 -0
- package/dist/emit/go/types-names.js +64 -0
- package/dist/emit/go/types-struct.d.ts +29 -0
- package/dist/emit/go/types-struct.js +65 -0
- package/dist/emit/go/types-union.d.ts +17 -0
- package/dist/emit/go/types-union.js +84 -0
- package/dist/emit/go/types.d.ts +32 -0
- package/dist/emit/go/types.js +177 -0
- package/dist/emit/go/ws.d.ts +12 -0
- package/dist/emit/go/ws.js +70 -0
- package/dist/emit/java/gradle.d.ts +57 -0
- package/dist/emit/java/gradle.js +221 -0
- package/dist/emit/java/index.d.ts +2 -0
- package/dist/emit/java/index.js +2 -0
- package/dist/emit/java/json.d.ts +13 -0
- package/dist/emit/java/json.js +84 -0
- package/dist/emit/java/layout-ast.d.ts +146 -0
- package/dist/emit/java/layout-ast.js +102 -0
- package/dist/emit/java/layout-decl.d.ts +20 -0
- package/dist/emit/java/layout-decl.js +155 -0
- package/dist/emit/java/layout-doc.d.ts +55 -0
- package/dist/emit/java/layout-doc.js +166 -0
- package/dist/emit/java/layout-dot.d.ts +18 -0
- package/dist/emit/java/layout-dot.js +127 -0
- package/dist/emit/java/layout-strings.d.ts +8 -0
- package/dist/emit/java/layout-strings.js +76 -0
- package/dist/emit/java/layout-types.d.ts +11 -0
- package/dist/emit/java/layout-types.js +95 -0
- package/dist/emit/java/layout-visitor.d.ts +38 -0
- package/dist/emit/java/layout-visitor.js +232 -0
- package/dist/emit/java/layout.d.ts +61 -0
- package/dist/emit/java/layout.js +121 -0
- package/dist/emit/java/models-enum.d.ts +17 -0
- package/dist/emit/java/models-enum.js +51 -0
- package/dist/emit/java/models-names.d.ts +29 -0
- package/dist/emit/java/models-names.js +97 -0
- package/dist/emit/java/models-record.d.ts +24 -0
- package/dist/emit/java/models-record.js +79 -0
- package/dist/emit/java/models-union.d.ts +27 -0
- package/dist/emit/java/models-union.js +86 -0
- package/dist/emit/java/models.d.ts +28 -0
- package/dist/emit/java/models.js +118 -0
- package/dist/emit/java/realtime.d.ts +50 -0
- package/dist/emit/java/realtime.js +69 -0
- package/dist/emit/java/sdk-client.d.ts +66 -0
- package/dist/emit/java/sdk-client.js +207 -0
- package/dist/emit/java/sdk-decl.d.ts +11 -0
- package/dist/emit/java/sdk-decl.js +63 -0
- package/dist/emit/java/sdk-errors.d.ts +13 -0
- package/dist/emit/java/sdk-errors.js +141 -0
- package/dist/emit/java/sdk-headers.d.ts +12 -0
- package/dist/emit/java/sdk-headers.js +74 -0
- package/dist/emit/java/sdk-mirror.d.ts +14 -0
- package/dist/emit/java/sdk-mirror.js +107 -0
- package/dist/emit/java/sdk-models.d.ts +16 -0
- package/dist/emit/java/sdk-models.js +68 -0
- package/dist/emit/java/sdk-op.d.ts +57 -0
- package/dist/emit/java/sdk-op.js +216 -0
- package/dist/emit/java/sdk-params.d.ts +38 -0
- package/dist/emit/java/sdk-params.js +133 -0
- package/dist/emit/java/sdk-plan.d.ts +52 -0
- package/dist/emit/java/sdk-plan.js +1 -0
- package/dist/emit/java/sdk-record.d.ts +16 -0
- package/dist/emit/java/sdk-record.js +99 -0
- package/dist/emit/java/sdk.d.ts +49 -0
- package/dist/emit/java/sdk.js +216 -0
- package/dist/emit/java/sse.d.ts +35 -0
- package/dist/emit/java/sse.js +57 -0
- package/dist/emit/java/ws.d.ts +27 -0
- package/dist/emit/java/ws.js +31 -0
- package/dist/emit/mcp/annotations.d.ts +15 -0
- package/dist/emit/mcp/annotations.js +15 -0
- package/dist/emit/mcp/files.d.ts +18 -0
- package/dist/emit/mcp/files.js +42 -0
- package/dist/emit/mcp/index.d.ts +3 -0
- package/dist/emit/mcp/index.js +3 -0
- package/dist/emit/mcp/literal.d.ts +2 -0
- package/dist/emit/mcp/literal.js +33 -0
- package/dist/emit/mcp/mounted.d.ts +21 -0
- package/dist/emit/mcp/mounted.js +89 -0
- package/dist/emit/mcp/output-schema.d.ts +18 -0
- package/dist/emit/mcp/output-schema.js +38 -0
- package/dist/emit/mcp/registry.d.ts +23 -0
- package/dist/emit/mcp/registry.js +83 -0
- package/dist/emit/mcp/runtime.d.ts +10 -0
- package/dist/emit/mcp/runtime.js +47 -0
- package/dist/emit/mcp/schema.d.ts +19 -0
- package/dist/emit/mcp/schema.js +88 -0
- package/dist/emit/mcp/server.d.ts +30 -0
- package/dist/emit/mcp/server.js +246 -0
- package/dist/emit/mcp/tools.d.ts +51 -0
- package/dist/emit/mcp/tools.js +153 -0
- package/dist/emit/python/errors.d.ts +8 -0
- package/dist/emit/python/errors.js +68 -0
- package/dist/emit/python/index.d.ts +1 -0
- package/dist/emit/python/index.js +1 -0
- package/dist/emit/python/realtime.d.ts +10 -0
- package/dist/emit/python/realtime.js +33 -0
- package/dist/emit/python/sdk-answer.d.ts +49 -0
- package/dist/emit/python/sdk-answer.js +89 -0
- package/dist/emit/python/sdk-body.d.ts +11 -0
- package/dist/emit/python/sdk-body.js +40 -0
- package/dist/emit/python/sdk-client.d.ts +36 -0
- package/dist/emit/python/sdk-client.js +163 -0
- package/dist/emit/python/sdk-doc.d.ts +9 -0
- package/dist/emit/python/sdk-doc.js +32 -0
- package/dist/emit/python/sdk-imports.d.ts +14 -0
- package/dist/emit/python/sdk-imports.js +38 -0
- package/dist/emit/python/sdk-method.d.ts +29 -0
- package/dist/emit/python/sdk-method.js +183 -0
- package/dist/emit/python/sdk-plan.d.ts +33 -0
- package/dist/emit/python/sdk-plan.js +1 -0
- package/dist/emit/python/sdk-pyproject.d.ts +27 -0
- package/dist/emit/python/sdk-pyproject.js +103 -0
- package/dist/emit/python/sdk.d.ts +22 -0
- package/dist/emit/python/sdk.js +154 -0
- package/dist/emit/python/sse.d.ts +12 -0
- package/dist/emit/python/sse.js +23 -0
- package/dist/emit/python/transport.d.ts +15 -0
- package/dist/emit/python/transport.js +60 -0
- package/dist/emit/python/types-dict.d.ts +31 -0
- package/dist/emit/python/types-dict.js +45 -0
- package/dist/emit/python/types-names.d.ts +16 -0
- package/dist/emit/python/types-names.js +52 -0
- package/dist/emit/python/types-union.d.ts +32 -0
- package/dist/emit/python/types-union.js +46 -0
- package/dist/emit/python/types.d.ts +36 -0
- package/dist/emit/python/types.js +128 -0
- package/dist/emit/python/ws.d.ts +14 -0
- package/dist/emit/python/ws.js +16 -0
- package/dist/emit/rust/errors.d.ts +7 -0
- package/dist/emit/rust/errors.js +107 -0
- package/dist/emit/rust/http.d.ts +13 -0
- package/dist/emit/rust/http.js +67 -0
- package/dist/emit/rust/index.d.ts +1 -0
- package/dist/emit/rust/index.js +1 -0
- package/dist/emit/rust/realtime.d.ts +11 -0
- package/dist/emit/rust/realtime.js +29 -0
- package/dist/emit/rust/sdk-body.d.ts +19 -0
- package/dist/emit/rust/sdk-body.js +53 -0
- package/dist/emit/rust/sdk-cargo.d.ts +43 -0
- package/dist/emit/rust/sdk-cargo.js +178 -0
- package/dist/emit/rust/sdk-client.d.ts +25 -0
- package/dist/emit/rust/sdk-client.js +108 -0
- package/dist/emit/rust/sdk-method.d.ts +15 -0
- package/dist/emit/rust/sdk-method.js +119 -0
- package/dist/emit/rust/sdk-opts.d.ts +58 -0
- package/dist/emit/rust/sdk-opts.js +117 -0
- package/dist/emit/rust/sdk-plan.d.ts +33 -0
- package/dist/emit/rust/sdk-plan.js +1 -0
- package/dist/emit/rust/sdk.d.ts +23 -0
- package/dist/emit/rust/sdk.js +111 -0
- package/dist/emit/rust/sse.d.ts +19 -0
- package/dist/emit/rust/sse.js +20 -0
- package/dist/emit/rust/types-enum.d.ts +13 -0
- package/dist/emit/rust/types-enum.js +62 -0
- package/dist/emit/rust/types-names.d.ts +19 -0
- package/dist/emit/rust/types-names.js +66 -0
- package/dist/emit/rust/types-struct.d.ts +21 -0
- package/dist/emit/rust/types-struct.js +59 -0
- package/dist/emit/rust/types-union.d.ts +24 -0
- package/dist/emit/rust/types-union.js +97 -0
- package/dist/emit/rust/types.d.ts +34 -0
- package/dist/emit/rust/types.js +105 -0
- package/dist/emit/rust/ws.d.ts +21 -0
- package/dist/emit/rust/ws.js +20 -0
- package/dist/emit/shared/escape.d.ts +55 -0
- package/dist/emit/shared/escape.js +144 -0
- package/dist/emit/shared/format.d.ts +24 -0
- package/dist/emit/shared/format.js +23 -0
- package/dist/emit/shared/gofmt.d.ts +3 -0
- package/dist/emit/shared/gofmt.js +26 -0
- package/dist/emit/shared/lang.d.ts +60 -0
- package/dist/emit/shared/lang.js +233 -0
- package/dist/emit/shared/literals.d.ts +4 -0
- package/dist/emit/shared/literals.js +31 -0
- package/dist/emit/shared/metadata.d.ts +106 -0
- package/dist/emit/shared/metadata.js +130 -0
- package/dist/emit/shared/mirror.d.ts +22 -0
- package/dist/emit/shared/mirror.js +26 -0
- package/dist/emit/shared/ruff.d.ts +3 -0
- package/dist/emit/shared/ruff.js +31 -0
- package/dist/emit/shared/rustfmt.d.ts +3 -0
- package/dist/emit/shared/rustfmt.js +32 -0
- package/dist/emit/shared/status-keys.d.ts +7 -0
- package/dist/emit/shared/status-keys.js +67 -0
- package/dist/emit/shared/type-emitter.d.ts +19 -0
- package/dist/emit/shared/type-emitter.js +100 -0
- package/dist/emit/ts/app-client.d.ts +4 -0
- package/dist/emit/ts/app-client.js +68 -0
- package/dist/emit/ts/http.d.ts +20 -0
- package/dist/emit/ts/http.js +74 -0
- package/dist/emit/ts/package.d.ts +36 -0
- package/dist/emit/ts/package.js +126 -0
- package/dist/emit/ts/route-tree.d.ts +68 -0
- package/dist/emit/ts/route-tree.js +240 -0
- package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
- package/dist/emit/ts/sdk-types-preamble.js +123 -0
- package/dist/emit/ts/sdk-types.d.ts +13 -0
- package/dist/emit/ts/sdk-types.js +213 -0
- package/dist/emit/ts/sdk.d.ts +21 -0
- package/dist/emit/ts/sdk.js +173 -0
- package/dist/emit/ts/service-map.d.ts +40 -0
- package/dist/emit/ts/service-map.js +171 -0
- package/dist/emit/ts/tanstack-query.d.ts +12 -0
- package/dist/emit/ts/tanstack-query.js +156 -0
- package/dist/emit/ts/type-gen.d.ts +26 -0
- package/dist/emit/ts/type-gen.js +255 -0
- package/dist/emit/ts/webhooks.d.ts +19 -0
- package/dist/emit/ts/webhooks.js +81 -0
- package/dist/extract/chain.d.ts +34 -0
- package/dist/extract/chain.js +84 -0
- package/dist/extract/extract.d.ts +41 -0
- package/dist/extract/extract.js +191 -0
- package/dist/extract/serialize.d.ts +34 -0
- package/dist/extract/serialize.js +295 -0
- package/dist/extract/walk.d.ts +47 -0
- package/dist/extract/walk.js +109 -0
- package/dist/gen/args.d.ts +28 -0
- package/dist/gen/args.js +133 -0
- package/dist/gen/formatters.d.ts +62 -0
- package/dist/gen/formatters.js +146 -0
- package/dist/gen/process.d.ts +13 -0
- package/dist/gen/process.js +35 -0
- package/dist/gen/shipped.d.ts +17 -0
- package/dist/gen/shipped.js +55 -0
- package/dist/gen/targets.d.ts +93 -0
- package/dist/gen/targets.js +171 -0
- package/dist/gen/write.d.ts +33 -0
- package/dist/gen/write.js +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +15 -0
- package/dist/ir/build.d.ts +37 -0
- package/dist/ir/build.js +152 -0
- package/dist/ir/load.d.ts +11 -0
- package/dist/ir/load.js +112 -0
- package/dist/ir/model.d.ts +206 -0
- package/dist/ir/model.js +5 -0
- package/dist/ir/resolve-refs.d.ts +11 -0
- package/dist/ir/resolve-refs.js +66 -0
- package/dist/ir/resource-tree.d.ts +9 -0
- package/dist/ir/resource-tree.js +53 -0
- package/dist/ir/route-tree-intern.d.ts +18 -0
- package/dist/ir/route-tree-intern.js +174 -0
- package/dist/ir/schema.d.ts +11 -0
- package/dist/ir/schema.js +192 -0
- package/dist/ir/sdk-model.d.ts +86 -0
- package/dist/ir/sdk-model.js +204 -0
- package/dist/ir/slots.d.ts +42 -0
- package/dist/ir/slots.js +245 -0
- package/dist/runtime/cli/body.go +176 -0
- package/dist/runtime/cli/config.go +243 -0
- package/dist/runtime/cli/discovery.go +147 -0
- package/dist/runtime/cli/format.go +174 -0
- package/dist/runtime/cli/log.go +117 -0
- package/dist/runtime/cli/output.go +247 -0
- package/dist/runtime/cli/params.go +197 -0
- package/dist/runtime/cli/run.go +226 -0
- package/dist/runtime/cli/socket.go +60 -0
- package/dist/runtime/cli/stream.go +217 -0
- package/dist/runtime/cli/target.go +117 -0
- package/dist/runtime/csharp/Adapters.cs +183 -0
- package/dist/runtime/csharp/Auth.cs +56 -0
- package/dist/runtime/csharp/Body.cs +135 -0
- package/dist/runtime/csharp/Config.cs +161 -0
- package/dist/runtime/csharp/Envelope.cs +149 -0
- package/dist/runtime/csharp/Errors.cs +194 -0
- package/dist/runtime/csharp/Events.cs +155 -0
- package/dist/runtime/csharp/Exchange.cs +247 -0
- package/dist/runtime/csharp/Handler.cs +103 -0
- package/dist/runtime/csharp/Hooks.cs +128 -0
- package/dist/runtime/csharp/Invalidation.cs +102 -0
- package/dist/runtime/csharp/Json.cs +144 -0
- package/dist/runtime/csharp/Log.cs +48 -0
- package/dist/runtime/csharp/Operation.cs +33 -0
- package/dist/runtime/csharp/Path.cs +65 -0
- package/dist/runtime/csharp/Query.cs +72 -0
- package/dist/runtime/csharp/Realtime.cs +118 -0
- package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
- package/dist/runtime/csharp/Redirect.cs +53 -0
- package/dist/runtime/csharp/Result.cs +57 -0
- package/dist/runtime/csharp/Sse.cs +122 -0
- package/dist/runtime/csharp/Stale.cs +151 -0
- package/dist/runtime/csharp/Transport.cs +143 -0
- package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
- package/dist/runtime/csharp/TransportSse.cs +54 -0
- package/dist/runtime/csharp/TransportWs.cs +40 -0
- package/dist/runtime/csharp/Wire.cs +109 -0
- package/dist/runtime/csharp/Ws.cs +300 -0
- package/dist/runtime/csharp/WsDial.cs +127 -0
- package/dist/runtime/go/auth.go +127 -0
- package/dist/runtime/go/body.go +129 -0
- package/dist/runtime/go/config.go +75 -0
- package/dist/runtime/go/errors.go +185 -0
- package/dist/runtime/go/export.go +37 -0
- package/dist/runtime/go/hooks.go +53 -0
- package/dist/runtime/go/invalidation.go +112 -0
- package/dist/runtime/go/log.go +92 -0
- package/dist/runtime/go/nullable.go +64 -0
- package/dist/runtime/go/options.go +118 -0
- package/dist/runtime/go/path.go +156 -0
- package/dist/runtime/go/query.go +147 -0
- package/dist/runtime/go/realtime.go +239 -0
- package/dist/runtime/go/realtime_loop.go +208 -0
- package/dist/runtime/go/redirect.go +124 -0
- package/dist/runtime/go/request.go +222 -0
- package/dist/runtime/go/result.go +86 -0
- package/dist/runtime/go/sse.go +186 -0
- package/dist/runtime/go/stale.go +229 -0
- package/dist/runtime/go/stream.go +105 -0
- package/dist/runtime/go/transport.go +242 -0
- package/dist/runtime/go/transport_longpoll.go +121 -0
- package/dist/runtime/go/transport_sse.go +175 -0
- package/dist/runtime/go/ws.go +205 -0
- package/dist/runtime/java/Answer.java +107 -0
- package/dist/runtime/java/ApiException.java +110 -0
- package/dist/runtime/java/BinaryBody.java +36 -0
- package/dist/runtime/java/Body.java +105 -0
- package/dist/runtime/java/Call.java +23 -0
- package/dist/runtime/java/CallLog.java +51 -0
- package/dist/runtime/java/ClientConfig.java +233 -0
- package/dist/runtime/java/ConnectionState.java +12 -0
- package/dist/runtime/java/Credential.java +58 -0
- package/dist/runtime/java/Deadline.java +38 -0
- package/dist/runtime/java/Decode.java +181 -0
- package/dist/runtime/java/Envelope.java +141 -0
- package/dist/runtime/java/ErrorEnvelope.java +23 -0
- package/dist/runtime/java/EventStream.java +129 -0
- package/dist/runtime/java/Exchange.java +62 -0
- package/dist/runtime/java/FilePart.java +5 -0
- package/dist/runtime/java/Flight.java +306 -0
- package/dist/runtime/java/HoneyException.java +14 -0
- package/dist/runtime/java/Hooks.java +47 -0
- package/dist/runtime/java/Hops.java +133 -0
- package/dist/runtime/java/InvalidationConfig.java +73 -0
- package/dist/runtime/java/Json.java +23 -0
- package/dist/runtime/java/Keepalive.java +60 -0
- package/dist/runtime/java/LogEntry.java +14 -0
- package/dist/runtime/java/LongPollAdapter.java +68 -0
- package/dist/runtime/java/Operation.java +21 -0
- package/dist/runtime/java/Opt.java +121 -0
- package/dist/runtime/java/Pump.java +160 -0
- package/dist/runtime/java/RawResponse.java +48 -0
- package/dist/runtime/java/Realtime.java +152 -0
- package/dist/runtime/java/RealtimeLoop.java +371 -0
- package/dist/runtime/java/RedirectPolicy.java +13 -0
- package/dist/runtime/java/Redirects.java +126 -0
- package/dist/runtime/java/RequestContext.java +78 -0
- package/dist/runtime/java/RequestHook.java +9 -0
- package/dist/runtime/java/RequestOptions.java +91 -0
- package/dist/runtime/java/ResponseContext.java +70 -0
- package/dist/runtime/java/ResponseHook.java +12 -0
- package/dist/runtime/java/Result.java +32 -0
- package/dist/runtime/java/ResumableConnection.java +165 -0
- package/dist/runtime/java/SdkException.java +11 -0
- package/dist/runtime/java/Socket.java +301 -0
- package/dist/runtime/java/Sse.java +171 -0
- package/dist/runtime/java/SseAdapter.java +61 -0
- package/dist/runtime/java/SseEvent.java +10 -0
- package/dist/runtime/java/StaleMeta.java +16 -0
- package/dist/runtime/java/StaleTracker.java +287 -0
- package/dist/runtime/java/Transport.java +16 -0
- package/dist/runtime/java/TransportAdapter.java +14 -0
- package/dist/runtime/java/TransportConnection.java +15 -0
- package/dist/runtime/java/TransportKind.java +12 -0
- package/dist/runtime/java/TransportMessage.java +9 -0
- package/dist/runtime/java/TransportOptions.java +138 -0
- package/dist/runtime/java/TypedWebSocket.java +83 -0
- package/dist/runtime/java/UrlPath.java +49 -0
- package/dist/runtime/java/UrlQuery.java +99 -0
- package/dist/runtime/java/WsAdapter.java +52 -0
- package/dist/runtime/java/WsClose.java +47 -0
- package/dist/runtime/java/WsDial.java +148 -0
- package/dist/runtime/java/WsMessage.java +18 -0
- package/dist/runtime/mcp/call.ts +167 -0
- package/dist/runtime/mcp/files.ts +183 -0
- package/dist/runtime/mcp/guard.ts +176 -0
- package/dist/runtime/mcp/http.ts +159 -0
- package/dist/runtime/mcp/jsonrpc.ts +50 -0
- package/dist/runtime/mcp/listen.ts +76 -0
- package/dist/runtime/mcp/mount.ts +123 -0
- package/dist/runtime/mcp/protocol.ts +219 -0
- package/dist/runtime/mcp/reader.ts +57 -0
- package/dist/runtime/mcp/result.ts +85 -0
- package/dist/runtime/mcp/stdio.ts +79 -0
- package/dist/runtime/mcp/stream.ts +62 -0
- package/dist/runtime/python/__init__.py +2 -0
- package/dist/runtime/python/auth.py +67 -0
- package/dist/runtime/python/body.py +83 -0
- package/dist/runtime/python/config.py +139 -0
- package/dist/runtime/python/errors.py +213 -0
- package/dist/runtime/python/events.py +152 -0
- package/dist/runtime/python/exchange.py +298 -0
- package/dist/runtime/python/hooks.py +86 -0
- package/dist/runtime/python/invalidation.py +57 -0
- package/dist/runtime/python/log.py +60 -0
- package/dist/runtime/python/operation.py +25 -0
- package/dist/runtime/python/path.py +41 -0
- package/dist/runtime/python/query.py +48 -0
- package/dist/runtime/python/realtime.py +244 -0
- package/dist/runtime/python/redirect.py +93 -0
- package/dist/runtime/python/result.py +58 -0
- package/dist/runtime/python/send_async.py +189 -0
- package/dist/runtime/python/send_sync.py +105 -0
- package/dist/runtime/python/sse.py +81 -0
- package/dist/runtime/python/stale.py +94 -0
- package/dist/runtime/python/transport.py +157 -0
- package/dist/runtime/python/transport_longpoll.py +60 -0
- package/dist/runtime/python/transport_sse.py +60 -0
- package/dist/runtime/python/transport_ws.py +57 -0
- package/dist/runtime/python/ws.py +276 -0
- package/dist/runtime/rust/Cargo.lock +1763 -0
- package/dist/runtime/rust/answer.rs +120 -0
- package/dist/runtime/rust/auth.rs +80 -0
- package/dist/runtime/rust/body.rs +150 -0
- package/dist/runtime/rust/call.rs +200 -0
- package/dist/runtime/rust/config.rs +254 -0
- package/dist/runtime/rust/envelope.rs +84 -0
- package/dist/runtime/rust/errors.rs +235 -0
- package/dist/runtime/rust/events.rs +177 -0
- package/dist/runtime/rust/exchange.rs +287 -0
- package/dist/runtime/rust/hooks.rs +63 -0
- package/dist/runtime/rust/invalidation.rs +84 -0
- package/dist/runtime/rust/log.rs +88 -0
- package/dist/runtime/rust/nullable.rs +13 -0
- package/dist/runtime/rust/path.rs +83 -0
- package/dist/runtime/rust/query.rs +84 -0
- package/dist/runtime/rust/realtime.rs +182 -0
- package/dist/runtime/rust/realtime_loop.rs +177 -0
- package/dist/runtime/rust/redirect.rs +121 -0
- package/dist/runtime/rust/request.rs +178 -0
- package/dist/runtime/rust/result.rs +101 -0
- package/dist/runtime/rust/sse.rs +104 -0
- package/dist/runtime/rust/stale.rs +209 -0
- package/dist/runtime/rust/transport.rs +221 -0
- package/dist/runtime/rust/transport_longpoll.rs +108 -0
- package/dist/runtime/rust/transport_sse.rs +91 -0
- package/dist/runtime/rust/transport_ws.rs +75 -0
- package/dist/runtime/rust/ws.rs +322 -0
- package/dist/runtime/ts/app-types.ts +200 -0
- package/dist/runtime/ts/app.ts +104 -0
- package/dist/runtime/ts/config.ts +124 -0
- package/dist/runtime/ts/defaults.ts +48 -0
- package/dist/runtime/ts/error.ts +113 -0
- package/dist/runtime/ts/hooks.ts +92 -0
- package/dist/runtime/ts/http.ts +228 -0
- package/dist/runtime/ts/media-type.ts +36 -0
- package/dist/runtime/ts/path.ts +152 -0
- package/dist/runtime/ts/realtime-connection.ts +296 -0
- package/dist/runtime/ts/realtime-transports.ts +149 -0
- package/dist/runtime/ts/realtime.ts +293 -0
- package/dist/runtime/ts/redirect-policy.ts +17 -0
- package/dist/runtime/ts/redirects.ts +74 -0
- package/dist/runtime/ts/request.ts +239 -0
- package/dist/runtime/ts/response.ts +219 -0
- package/dist/runtime/ts/sdk-realtime.ts +10 -0
- package/dist/runtime/ts/sdk-sse.ts +55 -0
- package/dist/runtime/ts/sdk-ws.ts +21 -0
- package/dist/runtime/ts/sdk.ts +242 -0
- package/dist/runtime/ts/sse.ts +175 -0
- package/dist/runtime/ts/stale.ts +137 -0
- package/dist/runtime/ts/stream.ts +87 -0
- package/dist/runtime/ts/webhook.ts +116 -0
- package/dist/runtime/ts/ws.ts +155 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
- package/dist/runtime/ts-tanstack-query/query.ts +261 -0
- package/package.json +84 -5
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generated MCP server as files (bit 18): a package an agent's MCP client starts as a command. Its TypeScript under
|
|
3
|
+
* `src/` (the entry, the tools, the vendored runtime joined into one module, the API's own TS SDK under `src/sdk/`), and
|
|
4
|
+
* the same code with its types erased under `dist/`, ES modules, which the package's bin runs: node refuses to strip
|
|
5
|
+
* types under an installed package's folder, so an installed server must ship JavaScript. The erasure is oxc's
|
|
6
|
+
* transform, the one the TS package compiles with (plan 39 8.3), deterministic whichever runtime generates. No
|
|
7
|
+
* dependency, no build step. With an `mcpName`, the MCP registry's server.json beside package.json (registry.ts).
|
|
8
|
+
*/
|
|
9
|
+
import { toIR } from "../../ir/build.js";
|
|
10
|
+
import { binaryNameOf } from "../cli/module.js";
|
|
11
|
+
import { checked, NPM_NAME, packageOn, SEMVER } from "../shared/metadata.js";
|
|
12
|
+
import { tsString } from "../shared/escape.js";
|
|
13
|
+
import { compiled, npmFields } from "../ts/package.js";
|
|
14
|
+
import { generateSdk } from "../ts/sdk.js";
|
|
15
|
+
import { literal } from "./literal.js";
|
|
16
|
+
import { serverJson } from "./registry.js";
|
|
17
|
+
import { mcpRuntimeSource } from "./runtime.js";
|
|
18
|
+
import { toolsOf, untoolable } from "./tools.js";
|
|
19
|
+
/* a name leaves room for the bin's `-mcp`; a prefix is uppercase words joined by `_` */
|
|
20
|
+
const NAME = /^(?=.{1,60}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
21
|
+
const ENV_PREFIX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
22
|
+
/* a server name as the MCP registry's server.json schema (2025-12-11) takes it: a reverse-DNS namespace, `/`, a name */
|
|
23
|
+
const MCP_NAME = /^(?=.{3,200}$)[a-zA-Z0-9.-]+\/[a-zA-Z0-9._-]+$/;
|
|
24
|
+
const MARKER = "// Code generated by honey. DO NOT EDIT.";
|
|
25
|
+
/** The options with their defaults filled, each refused unless it matches its grammar (F2). */
|
|
26
|
+
export function resolved(options, title) {
|
|
27
|
+
const name = options.name ?? binaryNameOf(title);
|
|
28
|
+
if (!NAME.test(name))
|
|
29
|
+
throw new Error(`Invalid name: ${JSON.stringify(name)}`);
|
|
30
|
+
const envPrefix = options.envPrefix ?? name.toUpperCase().replaceAll("-", "_");
|
|
31
|
+
if (!ENV_PREFIX.test(envPrefix))
|
|
32
|
+
throw new Error(`Invalid envPrefix: ${JSON.stringify(envPrefix)}`);
|
|
33
|
+
if (options.version !== undefined && !SEMVER.test(options.version))
|
|
34
|
+
throw new Error(`Invalid version: ${JSON.stringify(options.version)}`);
|
|
35
|
+
return { envPrefix, name };
|
|
36
|
+
}
|
|
37
|
+
/* a cap in bytes from the environment: a whole number, its default when unset */
|
|
38
|
+
const BYTES = `const bytes = (name: string, fallback: string): number => {
|
|
39
|
+
const text = process.env[name] || fallback
|
|
40
|
+
if (/^(?:0|[1-9][0-9]{0,14})$/.test(text)) return Number(text)
|
|
41
|
+
process.stderr.write("Invalid $" + name + ": a whole number of bytes\\n")
|
|
42
|
+
return process.exit(1)
|
|
43
|
+
}`;
|
|
44
|
+
/** A file-taking server's reader, its root and caps from the environment, the root refused at start unless a directory. */
|
|
45
|
+
const filesSource = (prefix) => `const inline = bytes(${tsString(`${prefix}_MAX_INLINE_BYTES`)}, "1048576")
|
|
46
|
+
const read = fileReader(
|
|
47
|
+
process.env[${tsString(`${prefix}_FILE_ROOT`)}] || process.cwd(),
|
|
48
|
+
bytes(${tsString(`${prefix}_MAX_FILE_BYTES`)}, "52428800"),
|
|
49
|
+
)
|
|
50
|
+
if (read === undefined) {
|
|
51
|
+
process.stderr.write(${tsString(`Invalid $${prefix}_FILE_ROOT: not a directory\n`)})
|
|
52
|
+
process.exit(1)
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
/** The entry's note on files, when a tool takes one. */
|
|
56
|
+
const filesNote = (prefix) => `
|
|
57
|
+
// A file argument is inline (the file-uploads extension's FileInput, at most $${prefix}_MAX_INLINE_BYTES decoded in one
|
|
58
|
+
// call, 1 MiB by default) or a path under $${prefix}_FILE_ROOT (the working directory by default), read whole, at most
|
|
59
|
+
// $${prefix}_MAX_FILE_BYTES (50 MiB by default). An upload (a FileInput without data) and a URL are a mounted server's.`;
|
|
60
|
+
/** The entry's note on --http. */
|
|
61
|
+
const httpNote = (prefix) => `//
|
|
62
|
+
// With --http it serves Streamable HTTP at /mcp instead, on --host (127.0.0.1 by default; another needs --expose,
|
|
63
|
+
// which also answers for any Host name) and --port (8000 by default; 0 picks one), and says where on stderr. Every
|
|
64
|
+
// request sends $${prefix}_MCP_TOKEN as \`Authorization: Bearer\`; with no token it refuses to start unless
|
|
65
|
+
// --no-auth, which --expose refuses. The token is never sent to the API. A browser Origin other than the server's own is
|
|
66
|
+
// refused unless listed in $${prefix}_MCP_ORIGINS (comma-separated); a body is read at most
|
|
67
|
+
// $${prefix}_MAX_BODY_BYTES, 4 MiB by default. A file argument over HTTP is inline: no path is read.`;
|
|
68
|
+
/** The command line read, each refusal at start, and $<PREFIX>_MCP_TOKEN: stdio with none, Streamable HTTP with --http. */
|
|
69
|
+
const flagsSource = (prefix) => `const refuse = (message: string): never => {
|
|
70
|
+
process.stderr.write(message + "\\n")
|
|
71
|
+
return process.exit(1)
|
|
72
|
+
}
|
|
73
|
+
/* the command line: nothing for stdio; --http [--port N] [--host H] [--no-auth] [--expose] for Streamable HTTP */
|
|
74
|
+
const flags = new Map<string, string>()
|
|
75
|
+
const args = process.argv.slice(2)
|
|
76
|
+
for (let at = 0; at < args.length; at++) {
|
|
77
|
+
const arg = args[at] as string
|
|
78
|
+
if (!["--http", "--port", "--host", "--no-auth", "--expose"].includes(arg) || flags.has(arg))
|
|
79
|
+
refuse("Unknown argument: " + arg)
|
|
80
|
+
flags.set(arg, arg === "--port" || arg === "--host" ? (args[++at] ?? "") : "")
|
|
81
|
+
}
|
|
82
|
+
const http = flags.has("--http")
|
|
83
|
+
if (flags.size > 0 && !http) refuse("--port, --host, --no-auth and --expose serve HTTP: pass --http")
|
|
84
|
+
const token = process.env[${tsString(`${prefix}_MCP_TOKEN`)}] || undefined
|
|
85
|
+
if (http && token === undefined && !flags.has("--no-auth"))
|
|
86
|
+
refuse(${tsString(`No token: set $${prefix}_MCP_TOKEN, which every request sends as Authorization: Bearer, or pass --no-auth`)})
|
|
87
|
+
if (token !== undefined && flags.has("--no-auth")) refuse(${tsString(`--no-auth, yet $${prefix}_MCP_TOKEN is set: unset one`)})
|
|
88
|
+
const host = flags.get("--host") ?? "127.0.0.1"
|
|
89
|
+
const exposed = flags.has("--expose")
|
|
90
|
+
if (!exposed && !["127.0.0.1", "localhost", "::1"].includes(host))
|
|
91
|
+
refuse("--host " + host + " is no loopback address: pass --expose to serve beyond this machine")
|
|
92
|
+
if (exposed && token === undefined) refuse(${tsString(`--expose needs $${prefix}_MCP_TOKEN`)})
|
|
93
|
+
const port = flags.get("--port") ?? "8000"
|
|
94
|
+
if (!/^(?:0|[1-9][0-9]{0,4})$/.test(port) || Number(port) > 65535) refuse("Invalid --port: 0 to 65535")
|
|
95
|
+
${BYTES}
|
|
96
|
+
`;
|
|
97
|
+
/** The protocol over the bound tools, served over Streamable HTTP with --http, else over stdio. */
|
|
98
|
+
const serveSource = (app) => `const protocol = createProtocol(
|
|
99
|
+
{ name: ${tsString(app.name)}, version: ${tsString(app.version)} },
|
|
100
|
+
bindTools(toolSpecs, client, { opening, secrets: [key, token ?? "", ...Object.values(headers)], timeout: Number(timeout)${app.files ? ", inline" : ""} }),${app.files ? "\n\tfilesCapability(inline)," : ""}
|
|
101
|
+
)
|
|
102
|
+
if (http) {
|
|
103
|
+
const max = bytes(${tsString(`${app.envPrefix}_MAX_BODY_BYTES`)}, "4194304")
|
|
104
|
+
const origins = (process.env[${tsString(`${app.envPrefix}_MCP_ORIGINS`)}] ?? "").split(",").map((each) => each.trim()).filter(Boolean)
|
|
105
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => process.exit(0))
|
|
106
|
+
listenHttp(serveHttp(protocol, { max, origins }), { exposed, host, port: Number(port), token }).then(
|
|
107
|
+
(server) => {
|
|
108
|
+
const { port: bound } = server.address() as { port: number }
|
|
109
|
+
process.stderr.write(${tsString(`${app.name} MCP server on http://`)} + (host.includes(":") ? "[" + host + "]" : host) + ":" + bound + "/mcp\\n")
|
|
110
|
+
},
|
|
111
|
+
(error: Error) => refuse("Cannot listen on " + host + ":" + port + ": " + error.message),
|
|
112
|
+
)
|
|
113
|
+
} else {
|
|
114
|
+
const stop = new AbortController()
|
|
115
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => stop.abort())
|
|
116
|
+
void serveStdio(protocol, undefined, stop.signal${app.files ? ", read" : ""}).then(
|
|
117
|
+
() => stop.signal.aborted && process.stdout.write("", () => process.exit(0)),
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
/** The entry: the tools served over stdio, or Streamable HTTP with --http, under the server's name and version. */
|
|
122
|
+
const entrySource = (app, ir) => `${MARKER}
|
|
123
|
+
|
|
124
|
+
// The ${app.name} MCP server: its tools over stdio, for the MCP client that starts it. The API key is
|
|
125
|
+
// $${app.envPrefix}_API_KEY, sent as the API's scheme says; the API is at $${app.envPrefix}_BASE_URL, else its first server, and
|
|
126
|
+
// with neither it refuses to start. A call waits $${app.envPrefix}_TIMEOUT_MS milliseconds at most, 30 s by default, an
|
|
127
|
+
// event stream's collect too. $${app.envPrefix}_HEADERS, a JSON object of string values, goes on every call, each value
|
|
128
|
+
// scrubbed as the key is; $${app.envPrefix}_REDIRECT is same-origin (the default) or follow. SIGINT and SIGTERM abort
|
|
129
|
+
// every call in flight and exit 0, no later reply written. The API's answer is read at most 1 MiB, past it refused.${app.files ? filesNote(app.envPrefix) : ""}
|
|
130
|
+
${httpNote(app.envPrefix)}
|
|
131
|
+
import { ${app.files ? "BYTES_MAX, bindTools, configHeaders, createProtocol, fileReader, filesCapability, listenHttp, serveHttp, serveStdio" : "BYTES_MAX, bindTools, configHeaders, createProtocol, listenHttp, serveHttp, serveStdio"} } from "./mcp.runtime.js"
|
|
132
|
+
import { Api } from "./sdk/api.index.gen.js"
|
|
133
|
+
import { headerValue } from "./sdk/api.runtime.gen.js"
|
|
134
|
+
import { toolSpecs } from "./tools.gen.js"
|
|
135
|
+
|
|
136
|
+
${flagsSource(app.envPrefix)}
|
|
137
|
+
const key = process.env[${tsString(`${app.envPrefix}_API_KEY`)}] ?? ""
|
|
138
|
+
const timeout = process.env[${tsString(`${app.envPrefix}_TIMEOUT_MS`)}] || "30000"
|
|
139
|
+
if (!/^[1-9][0-9]{0,9}$/.test(timeout) || Number(timeout) > 2147483647) {
|
|
140
|
+
process.stderr.write(${tsString(`Invalid $${app.envPrefix}_TIMEOUT_MS: a whole number of milliseconds, 1 to 2147483647\n`)})
|
|
141
|
+
process.exit(1)
|
|
142
|
+
}
|
|
143
|
+
const baseURL = process.env[${tsString(`${app.envPrefix}_BASE_URL`)}] || ${tsString(ir.servers[0] ?? "")}
|
|
144
|
+
if (baseURL === "") {
|
|
145
|
+
process.stderr.write(${tsString(`No API to call: set $${app.envPrefix}_BASE_URL, since the API names no server\n`)})
|
|
146
|
+
process.exit(1)
|
|
147
|
+
}
|
|
148
|
+
const headers = configHeaders(process.env[${tsString(`${app.envPrefix}_HEADERS`)}], ${tsString(`${app.envPrefix}_HEADERS`)}, headerValue)
|
|
149
|
+
if (typeof headers === "string") {
|
|
150
|
+
process.stderr.write(headers + ${tsString("\n")})
|
|
151
|
+
process.exit(1)
|
|
152
|
+
}
|
|
153
|
+
const redirect = process.env[${tsString(`${app.envPrefix}_REDIRECT`)}] || "same-origin"
|
|
154
|
+
if (redirect !== "same-origin" && redirect !== "follow") {
|
|
155
|
+
process.stderr.write(${tsString(`Invalid $${app.envPrefix}_REDIRECT: same-origin or follow
|
|
156
|
+
`)})
|
|
157
|
+
process.exit(1)
|
|
158
|
+
}
|
|
159
|
+
const config = {
|
|
160
|
+
baseURL,
|
|
161
|
+
headers: key === "" ? headers : { ...headers, ${tsString(ir.auth.headerName)}: ${tsString(ir.auth.prefix)} + key },
|
|
162
|
+
maxResponseBytes: BYTES_MAX,
|
|
163
|
+
redirect: redirect as "follow" | "same-origin",
|
|
164
|
+
timeout: Number(timeout),
|
|
165
|
+
}
|
|
166
|
+
${app.files ? filesSource(app.envPrefix) : ""}const client = new Api(config)
|
|
167
|
+
/* a collect's own client: its answer tells that collect its stream opened */
|
|
168
|
+
const opening = (seen: () => void) => new Api({ ...config, onResponse: [() => void seen()] })
|
|
169
|
+
${serveSource(app)}`;
|
|
170
|
+
/** tools.gen.ts: every tool's spec, as data the runtime binds to the SDK client. */
|
|
171
|
+
const toolsSource = (specs) => `${MARKER}\n\nimport type { ToolSpec } from "./mcp.runtime.js"\n\nexport const toolSpecs: readonly ToolSpec[] = ${literal(specs)}\n`;
|
|
172
|
+
/**
|
|
173
|
+
* The package: its bin the compiled entry, no dependency, its metadata the run's, the description the server's own
|
|
174
|
+
* when the run gives none.
|
|
175
|
+
*/
|
|
176
|
+
const packageJson = (name, version, published, metadata) => `${JSON.stringify({
|
|
177
|
+
name: published.packageName,
|
|
178
|
+
version,
|
|
179
|
+
...(published.mcpName === undefined ? {} : { mcpName: published.mcpName }),
|
|
180
|
+
description: `The ${name} API as MCP tools`,
|
|
181
|
+
...npmFields(metadata),
|
|
182
|
+
type: "module",
|
|
183
|
+
bin: { [`${name}-mcp`]: "dist/server.js" },
|
|
184
|
+
files: ["dist", "src"],
|
|
185
|
+
engines: { node: ">=22" },
|
|
186
|
+
}, null, "\t")}\n`;
|
|
187
|
+
/** `source` with its types erased, as ES module JavaScript; the entry gets the shebang a bin needs. */
|
|
188
|
+
export function erased(path, source) {
|
|
189
|
+
return `${path === "src/server.ts" ? "#!/usr/bin/env node\n" : ""}${compiled(path, source, false).code.trimEnd()}\n`;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* What a publish reads, `app` at the version npm takes: package.json, server.json when it has an `mcpName`, and the
|
|
193
|
+
* package on each registry.
|
|
194
|
+
*/
|
|
195
|
+
function released(app, published, ir, metadata) {
|
|
196
|
+
const { mcpName, packageName } = published;
|
|
197
|
+
const listing = mcpName === undefined ? undefined : { ...app, mcpName, packageName };
|
|
198
|
+
return {
|
|
199
|
+
files: {
|
|
200
|
+
"package.json": packageJson(app.name, app.version, published, metadata),
|
|
201
|
+
...(listing === undefined ? {} : { "server.json": serverJson(listing, ir, metadata) }),
|
|
202
|
+
},
|
|
203
|
+
packages: [
|
|
204
|
+
packageOn("npm", packageName, app.version),
|
|
205
|
+
...(mcpName === undefined ? [] : [packageOn("mcp-registry", mcpName, app.version)]),
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** The MCP server for `document`, as its package's files, its package.json carrying `metadata`. */
|
|
210
|
+
export function generateMcpServer(document, options = {}, metadata = {}) {
|
|
211
|
+
const ir = toIR(document, { deriveOperationIds: true });
|
|
212
|
+
const { envPrefix, name } = resolved(options, ir.info.title);
|
|
213
|
+
const published = {
|
|
214
|
+
mcpName: checked("mcpName", options.mcpName, MCP_NAME),
|
|
215
|
+
packageName: checked("packageName", options.packageName ?? `${name}-mcp`, NPM_NAME),
|
|
216
|
+
};
|
|
217
|
+
const version = options.version ?? ir.info.version ?? "0.0.0";
|
|
218
|
+
/* what npm and the registries take: the version when it is semver, else 0.0.0 */
|
|
219
|
+
const publishable = SEMVER.test(version) ? version : "0.0.0";
|
|
220
|
+
const specs = toolsOf(ir);
|
|
221
|
+
if (specs.length === 0)
|
|
222
|
+
throw new Error(ir.operations.some((op) => op.extensions.mcp === true)
|
|
223
|
+
? "No operation marked x-mcp is one a tool can call yet: nothing to serve"
|
|
224
|
+
: "No operation is marked x-mcp: nothing to serve");
|
|
225
|
+
const files = specs.some((spec) => spec.parts?.some(([, , kind]) => kind !== "text"));
|
|
226
|
+
const sdk = generateSdk(document, { name: "Api", stem: "api" });
|
|
227
|
+
const source = {
|
|
228
|
+
"src/mcp.runtime.ts": mcpRuntimeSource(),
|
|
229
|
+
"src/server.ts": entrySource({ envPrefix, files, name, version }, ir),
|
|
230
|
+
"src/tools.gen.ts": toolsSource(specs),
|
|
231
|
+
...Object.fromEntries(Object.entries(sdk.files).map(([file, text]) => [`src/sdk/${file}`, text])),
|
|
232
|
+
};
|
|
233
|
+
const release = released({ envPrefix, files, name, version: publishable }, published, ir, metadata);
|
|
234
|
+
const compiled = Object.fromEntries(Object.entries(source).map(([path, text]) => [
|
|
235
|
+
path.replace(/^src\//, "dist/").replace(/\.ts$/, ".js"),
|
|
236
|
+
erased(path, text),
|
|
237
|
+
]));
|
|
238
|
+
return {
|
|
239
|
+
files: { ...release.files, ...source, ...compiled },
|
|
240
|
+
packages: release.packages,
|
|
241
|
+
skipped: ir.operations.flatMap((op) => {
|
|
242
|
+
const what = op.extensions.mcp === true ? untoolable(op) : undefined;
|
|
243
|
+
return what === undefined ? [] : [`${op.id} (${what})`];
|
|
244
|
+
}),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP server's tools (bit 18 phases b, d and e): one per operation marked `x-mcp` that a tool call can make, in the IR's
|
|
3
|
+
* order. A tool's name is its operation id in snake case, only `[A-Za-z0-9_-]`, at most 64 characters (the tool-use
|
|
4
|
+
* APIs an MCP client maps a tool onto accept no more), a name taken already suffixed `_2`, `_3`, … after truncating, so
|
|
5
|
+
* it still fits. Its description is the operation's description or summary, controls dropped. Its inputSchema is flat:
|
|
6
|
+
* each path, query and header parameter a property under its own name (one taken already suffixed, as the CLI's flags
|
|
7
|
+
* are), the body under `body`: JSON or a form as its schema, bytes as a base64 string (Q4), text as a string; a
|
|
8
|
+
* credential header is never an argument, the server sending the API key itself. Its outputSchema and annotations are
|
|
9
|
+
* output-schema.ts's and annotations.ts's. An event stream is a bounded collect, taking `max_events` (1 to 100, 20 by
|
|
10
|
+
* default) and `last_event_id` to resume after. Sockets are no tools. A multipart form (bit 21 c, H24) is a tool too,
|
|
11
|
+
* each part its own argument: a text part as its schema, a file part (or a list of them) a file argument, files.ts's
|
|
12
|
+
* schema.
|
|
13
|
+
*/
|
|
14
|
+
import type { IR, IROperation } from "../../ir/model.ts";
|
|
15
|
+
import { type Annotations } from "./annotations.ts";
|
|
16
|
+
import { type JsonSchema } from "./schema.ts";
|
|
17
|
+
/** The SDK input group a parameter goes in, by where it is sent. */
|
|
18
|
+
type Group = "params" | "search" | "headers";
|
|
19
|
+
/** One tool as tools.gen.ts holds it (runtime/mcp/call.ts `ToolSpec`). */
|
|
20
|
+
export type ToolSpec = {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly description?: string;
|
|
23
|
+
readonly inputSchema: JsonSchema;
|
|
24
|
+
readonly member: readonly string[];
|
|
25
|
+
readonly args: readonly (readonly [property: string, group: Group, name: string])[];
|
|
26
|
+
/** the body argument's property, how it is sent, and a raw body's content type, when the operation takes a body */
|
|
27
|
+
readonly body?: readonly [property: string, field: BodyField, contentType?: string];
|
|
28
|
+
readonly outputSchema?: JsonSchema;
|
|
29
|
+
/** whether structuredContent wraps the answer as `{result, headers}` */
|
|
30
|
+
readonly wrap?: true;
|
|
31
|
+
readonly annotations?: Annotations;
|
|
32
|
+
/** an event stream's collect: its `max_events` and `last_event_id` properties */
|
|
33
|
+
readonly collect?: readonly [max: string, lastEventId: string];
|
|
34
|
+
/** a multipart form's parts: each one's property, its name in the form, and whether it is a file or a list of them */
|
|
35
|
+
readonly parts?: readonly Part[];
|
|
36
|
+
};
|
|
37
|
+
/** A multipart form's part as a tool argument: its property, its name in the form, and what it is. */
|
|
38
|
+
type Part = readonly [property: string, name: string, kind: "text" | "file" | "files"];
|
|
39
|
+
/** How a body is sent: JSON, a urlencoded form, base64-decoded bytes, text as it is, or a multipart form's parts. */
|
|
40
|
+
type BodyField = "json" | "form" | "bytes" | "text" | "parts";
|
|
41
|
+
/** The most characters a tool name may have. */
|
|
42
|
+
export declare const NAME_MAX = 64;
|
|
43
|
+
/** What `op` is that no tool serves, or undefined when a tool can: a socket. */
|
|
44
|
+
export declare function untoolable(op: IROperation): string | undefined;
|
|
45
|
+
/** Whether `op` is a tool: marked `x-mcp`, and nothing no tool serves. */
|
|
46
|
+
export declare const isTool: (op: IROperation) => boolean;
|
|
47
|
+
/** The tool name for `id`, not one `taken` holds: snake case, sanitized, truncated, then suffixed. */
|
|
48
|
+
export declare function toolName(id: string, taken: Set<string>): string;
|
|
49
|
+
/** Every tool the IR's operations make, in their order. */
|
|
50
|
+
export declare function toolsOf(ir: IR, file?: JsonSchema): ToolSpec[];
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { irResolver } from "../../ir/schema.js";
|
|
2
|
+
import { isJsonMedia, isTextMedia, mediaEssence, sdkModel } from "../../ir/sdk-model.js";
|
|
3
|
+
import { NameScope, snakeWords } from "../shared/lang.js";
|
|
4
|
+
import { sdkMemberPaths } from "../ts/service-map.js";
|
|
5
|
+
import { annotationsOf } from "./annotations.js";
|
|
6
|
+
import { FILE_SCHEMA } from "./files.js";
|
|
7
|
+
import { outputOf } from "./output-schema.js";
|
|
8
|
+
import { describe, jsonSchemaOf } from "./schema.js";
|
|
9
|
+
/** The most characters a tool name may have. */
|
|
10
|
+
export const NAME_MAX = 64;
|
|
11
|
+
/** Headers that carry a credential: never a tool's argument. */
|
|
12
|
+
const CREDENTIAL_HEADERS = ["authorization", "cookie", "proxy-authorization"];
|
|
13
|
+
/** How `op`'s body is sent: JSON, a urlencoded form, bytes, text, or a multipart form (a file in it or not) by parts. */
|
|
14
|
+
function bodyField(op) {
|
|
15
|
+
const body = op.body;
|
|
16
|
+
if (body === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (body.kind === "stream")
|
|
19
|
+
return "bytes";
|
|
20
|
+
if (isJsonMedia(body.contentType))
|
|
21
|
+
return "json";
|
|
22
|
+
const essence = mediaEssence(body.contentType);
|
|
23
|
+
if (essence === "application/x-www-form-urlencoded")
|
|
24
|
+
return "form";
|
|
25
|
+
if (essence === "multipart/form-data")
|
|
26
|
+
return "parts";
|
|
27
|
+
return isTextMedia(body.contentType) ? "text" : "bytes";
|
|
28
|
+
}
|
|
29
|
+
/** The schema a body argument of `field` takes. */
|
|
30
|
+
function bodySchema(op, field, ir) {
|
|
31
|
+
if (field === "bytes")
|
|
32
|
+
return { type: "string", contentEncoding: "base64" };
|
|
33
|
+
if (field === "text" || op.body?.kind !== "raw")
|
|
34
|
+
return { type: "string" };
|
|
35
|
+
return jsonSchemaOf(op.body.schema, ir.schemas);
|
|
36
|
+
}
|
|
37
|
+
/** What `op` is that no tool serves, or undefined when a tool can: a socket. */
|
|
38
|
+
export function untoolable(op) {
|
|
39
|
+
if (op.extensions.websocket === true)
|
|
40
|
+
return "a WebSocket";
|
|
41
|
+
return op.extensions.realtime === true ? "a realtime channel" : undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Whether `op` is a tool: marked `x-mcp`, and nothing no tool serves. */
|
|
44
|
+
export const isTool = (op) => op.extensions.mcp === true && untoolable(op) === undefined;
|
|
45
|
+
/** The tool name for `id`, not one `taken` holds: snake case, sanitized, truncated, then suffixed. */
|
|
46
|
+
export function toolName(id, taken) {
|
|
47
|
+
/* snakeWords keeps only letters, digits and inner underscores: nothing is left to sanitize */
|
|
48
|
+
const base = (snakeWords(id) || "tool").slice(0, NAME_MAX);
|
|
49
|
+
let name = base;
|
|
50
|
+
for (let n = 2; taken.has(name); n++)
|
|
51
|
+
name = `${base.slice(0, NAME_MAX - `_${n}`.length)}_${n}`;
|
|
52
|
+
taken.add(name);
|
|
53
|
+
return name;
|
|
54
|
+
}
|
|
55
|
+
/** `form`'s fields as arguments into `into`: a text part its schema; a file, or a list of them, files.ts's. */
|
|
56
|
+
function partsOf(form, ir, into) {
|
|
57
|
+
const resolve = irResolver(ir.schemas);
|
|
58
|
+
const object = resolve(form);
|
|
59
|
+
return (object.kind === "object" ? object.fields : []).map((field) => {
|
|
60
|
+
const property = into.scope.claim(field.name);
|
|
61
|
+
const schema = resolve(field.schema);
|
|
62
|
+
const files = schema.kind === "array" && resolve(schema.items).kind === "binary";
|
|
63
|
+
const kind = schema.kind === "binary" ? "file" : files ? "files" : "text";
|
|
64
|
+
const own = kind === "file" ? into.file : jsonSchemaOf(field.schema, ir.schemas);
|
|
65
|
+
into.properties[property] = {
|
|
66
|
+
...own,
|
|
67
|
+
...(kind === "files" && { items: into.file }),
|
|
68
|
+
...describe(field.description),
|
|
69
|
+
};
|
|
70
|
+
if (field.required)
|
|
71
|
+
into.required.push(property);
|
|
72
|
+
return [property, field.name, kind];
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** `op`'s body argument into `into`: its property, how it is sent and a raw body's content type; or its parts. */
|
|
76
|
+
function bodyOf(op, ir, into) {
|
|
77
|
+
const field = bodyField(op);
|
|
78
|
+
if (field === undefined || op.body === undefined)
|
|
79
|
+
return {};
|
|
80
|
+
/* a multipart form is never a stream: it has its schema */
|
|
81
|
+
if (field === "parts")
|
|
82
|
+
return { parts: partsOf(op.body.schema, ir, into) };
|
|
83
|
+
const property = into.scope.claim("body");
|
|
84
|
+
into.properties[property] = bodySchema(op, field, ir);
|
|
85
|
+
if (op.body.required)
|
|
86
|
+
into.required.push(property);
|
|
87
|
+
return { body: field === "bytes" || field === "text" ? [property, field, op.body.contentType] : [property, field] };
|
|
88
|
+
}
|
|
89
|
+
/** `op`'s flat inputSchema and how each property reaches the SDK input. */
|
|
90
|
+
function inputOf(op, ir, file) {
|
|
91
|
+
const scope = new NameScope();
|
|
92
|
+
const credentials = new Set([...CREDENTIAL_HEADERS, ir.auth.headerName.toLowerCase()]);
|
|
93
|
+
/* null-prototype: a parameter named __proto__ is a property, never the object's prototype */
|
|
94
|
+
const properties = Object.create(null);
|
|
95
|
+
const required = [];
|
|
96
|
+
const args = [];
|
|
97
|
+
const groups = [
|
|
98
|
+
["params", op.params.path],
|
|
99
|
+
["search", op.params.query],
|
|
100
|
+
["headers", op.params.header.filter((param) => !credentials.has(param.name.toLowerCase()))],
|
|
101
|
+
];
|
|
102
|
+
for (const [group, params] of groups)
|
|
103
|
+
for (const param of params) {
|
|
104
|
+
const property = scope.claim(param.name);
|
|
105
|
+
properties[property] = { ...jsonSchemaOf(param.schema, ir.schemas), ...describe(param.description) };
|
|
106
|
+
if (group === "params" || param.required === true)
|
|
107
|
+
required.push(property);
|
|
108
|
+
args.push([property, group, param.name]);
|
|
109
|
+
}
|
|
110
|
+
const body = bodyOf(op, ir, { file, properties, required, scope });
|
|
111
|
+
let collect;
|
|
112
|
+
if (op.extensions.sse === true) {
|
|
113
|
+
collect = [scope.claim("max_events"), scope.claim("last_event_id")];
|
|
114
|
+
properties[collect[0]] = {
|
|
115
|
+
type: "integer",
|
|
116
|
+
minimum: 1,
|
|
117
|
+
maximum: 100,
|
|
118
|
+
description: "The most events to collect, 1 to 100; 20 when omitted",
|
|
119
|
+
};
|
|
120
|
+
properties[collect[1]] = { type: "string", description: "Resume after this event id: a collect's last_event_id" };
|
|
121
|
+
}
|
|
122
|
+
const inputSchema = {
|
|
123
|
+
type: "object",
|
|
124
|
+
properties,
|
|
125
|
+
...(required.length > 0 ? { required } : {}),
|
|
126
|
+
additionalProperties: false,
|
|
127
|
+
};
|
|
128
|
+
return { args, body, collect, inputSchema };
|
|
129
|
+
}
|
|
130
|
+
/** Every tool the IR's operations make, in their order. */
|
|
131
|
+
export function toolsOf(ir, file = FILE_SCHEMA) {
|
|
132
|
+
const members = sdkMemberPaths(ir);
|
|
133
|
+
const model = sdkModel(ir);
|
|
134
|
+
const taken = new Set();
|
|
135
|
+
return ir.operations.filter(isTool).map((op) => {
|
|
136
|
+
const { args, body, collect, inputSchema } = inputOf(op, ir, file);
|
|
137
|
+
/* the SDK model holds every operation of the IR */
|
|
138
|
+
const sdkOp = model.opsById.get(op.id);
|
|
139
|
+
const annotations = annotationsOf(sdkOp);
|
|
140
|
+
return {
|
|
141
|
+
name: toolName(op.id, taken),
|
|
142
|
+
...describe(op.description ?? op.summary),
|
|
143
|
+
inputSchema,
|
|
144
|
+
/* sdkMemberPaths holds every operation of the IR */
|
|
145
|
+
member: members.get(op.id),
|
|
146
|
+
args,
|
|
147
|
+
...body,
|
|
148
|
+
...outputOf(sdkOp, ir),
|
|
149
|
+
...(annotations === undefined ? {} : { annotations }),
|
|
150
|
+
...(collect === undefined ? {} : { collect }),
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SdkModel } from "../../ir/sdk-model.ts";
|
|
2
|
+
import { type PyTypeContext } from "./types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The `ErrorKey` block for `model`: its doc comment (a line per key whose body decodes into a type), then the
|
|
5
|
+
* functional StrEnum, a member per key in code-unit order (a colliding name gets `…2`); each `<Key>Data` hoisted
|
|
6
|
+
* into `at.decls`. `null` when the API declares no key: nothing else changes then.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pythonErrorKeys(model: SdkModel, at: PyTypeContext): string | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { irErrorEnvelope, isJsonMedia } from "../../ir/sdk-model.js";
|
|
2
|
+
import { lineComment, pyString } from "../shared/escape.js";
|
|
3
|
+
import { compareCodeUnits, NameScope, pyClassName, pyIdentifier } from "../shared/lang.js";
|
|
4
|
+
import { pyTopLevel } from "./types.js";
|
|
5
|
+
/** The keys an error response's envelope names, over every operation's JSON error statuses (the runtime reads JSON only). */
|
|
6
|
+
function envelopeKeys(model) {
|
|
7
|
+
return model.ops.flatMap((op) => op.errorStatuses.flatMap((status) => {
|
|
8
|
+
/* an error status is a declared response, and a schema comes with the content type it is under */
|
|
9
|
+
const { contentType, schema } = op.ir.responses[String(status)];
|
|
10
|
+
if (schema === undefined || !isJsonMedia(contentType))
|
|
11
|
+
return [];
|
|
12
|
+
return irErrorEnvelope(schema, model.resolve)?.keys ?? [];
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Every declared key in code-unit order with its schema: `x-honey-errors`' (the first operation by id to declare
|
|
17
|
+
* the key, so the document's path order never changes it), then an envelope's keys, which carry none (Rust's rule).
|
|
18
|
+
*/
|
|
19
|
+
function declaredKeys(model) {
|
|
20
|
+
const byId = [...model.ops].sort((a, b) => compareCodeUnits(a.id, b.id));
|
|
21
|
+
const declared = byId.flatMap((op) => Object.entries(op.ir.extensions.errors ?? {}));
|
|
22
|
+
/* a later entry wins: an envelope's key gives way to a declaration, each declaration reversed to its first */
|
|
23
|
+
const keys = new Map([
|
|
24
|
+
...envelopeKeys(model).map((key) => [key, undefined]),
|
|
25
|
+
...declared.toReversed().map(([key, { schema }]) => [key, schema]),
|
|
26
|
+
]);
|
|
27
|
+
return [...keys].sort(([a], [b]) => compareCodeUnits(a, b));
|
|
28
|
+
}
|
|
29
|
+
/** What a body carrying `key` decodes into: its component, a new `<Key>Data`, or nothing to name (no schema, the envelope). */
|
|
30
|
+
function bodyType(key, schema, model, at) {
|
|
31
|
+
if (schema === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (schema.kind === "ref")
|
|
34
|
+
return at.names.ref(schema.name);
|
|
35
|
+
if (irErrorEnvelope(schema, model.resolve) !== null)
|
|
36
|
+
return undefined;
|
|
37
|
+
const name = at.names.claim(`${pyClassName(key)}Data`);
|
|
38
|
+
at.decls.set(name, pyTopLevel(name, schema, at));
|
|
39
|
+
return name;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The `ErrorKey` block for `model`: its doc comment (a line per key whose body decodes into a type), then the
|
|
43
|
+
* functional StrEnum, a member per key in code-unit order (a colliding name gets `…2`); each `<Key>Data` hoisted
|
|
44
|
+
* into `at.decls`. `null` when the API declares no key: nothing else changes then.
|
|
45
|
+
*/
|
|
46
|
+
export function pythonErrorKeys(model, at) {
|
|
47
|
+
const declared = declaredKeys(model);
|
|
48
|
+
if (declared.length === 0)
|
|
49
|
+
return null;
|
|
50
|
+
const members = new NameScope();
|
|
51
|
+
const keys = declared.map(([wire, schema]) => ({
|
|
52
|
+
data: bodyType(wire, schema, model, at),
|
|
53
|
+
/* an UPPER_SNAKE member never meets a keyword, so the keyword guard's `_` goes */
|
|
54
|
+
member: members.claim(pyIdentifier(wire).replace(/_$/, "").toUpperCase()),
|
|
55
|
+
wire,
|
|
56
|
+
}));
|
|
57
|
+
const doc = keys.flatMap(({ data, wire }) => data === undefined ? [] : lineComment(`${wire}: its body decodes into ${data} (APIStatusError.decode_body).`, "#"));
|
|
58
|
+
return [
|
|
59
|
+
"# The error keys the API declares: APIStatusError.key is one of these, else the server's string.",
|
|
60
|
+
...doc,
|
|
61
|
+
"ErrorKey = StrEnum(",
|
|
62
|
+
' "ErrorKey",',
|
|
63
|
+
" {",
|
|
64
|
+
...keys.map(({ member, wire }) => ` ${pyString(member)}: ${pyString(wire)},`),
|
|
65
|
+
" },",
|
|
66
|
+
")",
|
|
67
|
+
].join("\n");
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type GeneratedPythonSdk, generatePythonSdk, type PythonSdkOptions, pythonCallPlans } from "./sdk.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generatePythonSdk, pythonCallPlans } from "./sdk.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A realtime operation's answer (contract 34 §2.0, §2.3; Fd3): `ResumableConnection[E]`, `E` the declared event
|
|
3
|
+
* schema's type (`Any` for a string or absent one), opened by awaiting the method over WebSocket, else SSE, else
|
|
4
|
+
* long-poll. Its five fields are the `TransportOpts` of their names: the resume cursor, the offered subprotocols
|
|
5
|
+
* and the reconnect policy; a declared param on a resume channel is folded in, and one named like a policy field
|
|
6
|
+
* is claimed as `…2` (`sdk-method.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import { type PyStream } from "./sdk-answer.ts";
|
|
9
|
+
/** The realtime operation's answer, its five fields and its docstring's lines. */
|
|
10
|
+
export declare const realtimeStream: PyStream;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A realtime operation's answer (contract 34 §2.0, §2.3; Fd3): `ResumableConnection[E]`, `E` the declared event
|
|
3
|
+
* schema's type (`Any` for a string or absent one), opened by awaiting the method over WebSocket, else SSE, else
|
|
4
|
+
* long-poll. Its five fields are the `TransportOpts` of their names: the resume cursor, the offered subprotocols
|
|
5
|
+
* and the reconnect policy; a declared param on a resume channel is folded in, and one named like a policy field
|
|
6
|
+
* is claimed as `…2` (`sdk-method.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import { eventType } from "./sdk-answer.js";
|
|
9
|
+
import { isLastEventIdHeader, sseStream } from "./sse.js";
|
|
10
|
+
import { pyTypeOf } from "./types.js";
|
|
11
|
+
import { isReconnectToken, PROTOCOLS, RECONNECT_TOKEN } from "./ws.js";
|
|
12
|
+
/** The realtime operation's answer, its five fields and its docstring's lines. */
|
|
13
|
+
export const realtimeStream = {
|
|
14
|
+
answer: (op, env) => {
|
|
15
|
+
const events = eventType(op, env, () => pyTypeOf({ kind: "unknown" }, env.at));
|
|
16
|
+
return { returns: `ResumableConnection[${events}]`, run: "realtime", type: events };
|
|
17
|
+
},
|
|
18
|
+
/* the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID */
|
|
19
|
+
carries: (name, where) => isReconnectToken(name, where) ||
|
|
20
|
+
(where === "query" && name === "last_event_id") ||
|
|
21
|
+
isLastEventIdHeader(name, where),
|
|
22
|
+
doc: [
|
|
23
|
+
"Opens the connection over WebSocket, else SSE, else long-poll; recv() reconnects after a drop and",
|
|
24
|
+
"resumes after the last message it delivered.",
|
|
25
|
+
],
|
|
26
|
+
fields: [
|
|
27
|
+
...sseStream.fields,
|
|
28
|
+
RECONNECT_TOKEN,
|
|
29
|
+
PROTOCOLS,
|
|
30
|
+
"max_reconnect_attempts: int | None = None",
|
|
31
|
+
"reconnect_delay_ms: int | None = None",
|
|
32
|
+
],
|
|
33
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a method takes and answers beyond its params (G3, G4, G5): its body's type by kind, its return type
|
|
3
|
+
* and the transport call it makes, the JSON kind its answer (or a typed stream's event) must
|
|
4
|
+
* have, and its `<Op>Headers` TypedDict, hoisted beside the types, with how the runtime reads each header and
|
|
5
|
+
* whether it must arrive (Fc5). A streaming operation answers as its `PyStream` says (`sse.ts`, `ws.ts`,
|
|
6
|
+
* `realtime.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import type { IRParam } from "../../ir/model.ts";
|
|
9
|
+
import type { SdkOp } from "../../ir/sdk-model.ts";
|
|
10
|
+
import type { MethodEnv } from "./sdk-method.ts";
|
|
11
|
+
/** `schema`'s type at `<Op><field>`, written in the client module. */
|
|
12
|
+
export declare const typeAt: (op: SdkOp, field: string, schema: IRParam["schema"], env: MethodEnv) => string;
|
|
13
|
+
/** The body parameter's type: its schema's for JSON and a form, `<Op>Body` for multipart, `str` for text, bytes or chunks for binary. */
|
|
14
|
+
export declare function bodyType(op: SdkOp, async: boolean, env: MethodEnv): string | null;
|
|
15
|
+
/** What a method answers (its `Operation`'s type and its return type), and the transport call it makes. */
|
|
16
|
+
export type Answer = {
|
|
17
|
+
readonly type: string;
|
|
18
|
+
readonly returns: string;
|
|
19
|
+
readonly run: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* What a streaming operation's method is: whether a declared param is one its own fields carry (Fd3), those
|
|
23
|
+
* fields (`name: type = None`, after the declared params), its answer, and the lines its docstring adds.
|
|
24
|
+
*/
|
|
25
|
+
export type PyStream = {
|
|
26
|
+
readonly carries: (name: string, where: string) => boolean;
|
|
27
|
+
readonly fields: readonly string[];
|
|
28
|
+
answer(op: SdkOp, env: MethodEnv): Answer;
|
|
29
|
+
readonly doc: readonly string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A streamed event's type: the operation's declared event schema, else `fallback`'s, spelled only then, so an
|
|
33
|
+
* undeclared event's `Any` is imported only where it is written (bit 21 i7a: a typed realtime op imported it unused).
|
|
34
|
+
*/
|
|
35
|
+
export declare const eventType: (op: SdkOp, env: MethodEnv, fallback: () => string) => string;
|
|
36
|
+
/** The answer of a plain operation `op`: its decoded success (`client.safe`'s twin wraps it in a `Result`). */
|
|
37
|
+
export declare function answerOf(op: SdkOp, env: MethodEnv): Answer;
|
|
38
|
+
/** The JSON kind a success body, or a typed SSE or realtime event (Fd5), must have, when its schema pins one. */
|
|
39
|
+
export declare function shapeOf(op: SdkOp, env: MethodEnv): string | null;
|
|
40
|
+
/** `<Op>Headers` (total=False) hoisted beside the types, and how `Operation.headers` reads each; null without any. */
|
|
41
|
+
export declare function responseHeaders(op: SdkOp, env: MethodEnv): {
|
|
42
|
+
plan: {
|
|
43
|
+
fields: {
|
|
44
|
+
[k: string]: string;
|
|
45
|
+
};
|
|
46
|
+
type: string;
|
|
47
|
+
};
|
|
48
|
+
read: string[];
|
|
49
|
+
} | null;
|