@workerstack/clients 1.0.0-rc.29 → 1.0.0-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +548 -35
- package/assets/installers/examples/github.config.ts +17 -19
- package/assets/installers/examples/goreleaser.config.ts +16 -18
- package/assets/installers/examples/raw.config.ts +13 -15
- package/bin/clients.js +88 -68
- package/bin/installgen.js +18 -13
- package/dist/cli.d.ts +4 -4
- package/dist/cli.js +20 -12
- package/dist/emit/cli/channels.d.ts +2 -2
- package/dist/emit/cli/channels.js +18 -13
- package/dist/emit/cli/commands.d.ts +1 -1
- package/dist/emit/cli/commands.js +14 -8
- package/dist/emit/cli/discovery.d.ts +0 -6
- package/dist/emit/cli/discovery.js +9 -7
- package/dist/emit/cli/flags.d.ts +1 -3
- package/dist/emit/cli/flags.js +11 -5
- package/dist/emit/cli/install.d.ts +0 -8
- package/dist/emit/cli/install.js +3 -3
- package/dist/emit/cli/layout.d.ts +1 -1
- package/dist/emit/cli/layout.js +13 -10
- package/dist/emit/cli/module.d.ts +6 -6
- package/dist/emit/cli/module.js +10 -10
- package/dist/emit/cli/release.d.ts +0 -11
- package/dist/emit/cli/release.js +4 -4
- package/dist/emit/cli/skills.js +3 -3
- package/dist/emit/csharp/errors.js +4 -4
- package/dist/emit/csharp/json.js +8 -8
- package/dist/emit/csharp/realtime.js +3 -3
- package/dist/emit/csharp/sdk-answer.js +4 -4
- package/dist/emit/csharp/sdk-body.js +8 -6
- package/dist/emit/csharp/sdk-client.d.ts +3 -3
- package/dist/emit/csharp/sdk-client.js +2 -2
- package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
- package/dist/emit/csharp/sdk-csproj.js +10 -10
- package/dist/emit/csharp/sdk-doc.js +1 -1
- package/dist/emit/csharp/sdk-method.d.ts +18 -2
- package/dist/emit/csharp/sdk-method.js +24 -9
- package/dist/emit/csharp/sdk-plan.js +0 -1
- package/dist/emit/csharp/sdk.js +7 -4
- package/dist/emit/csharp/sse.d.ts +0 -2
- package/dist/emit/csharp/sse.js +7 -7
- package/dist/emit/csharp/transport.js +7 -7
- package/dist/emit/csharp/types-enum.js +3 -1
- package/dist/emit/csharp/types-messages.js +3 -3
- package/dist/emit/csharp/types-names.js +10 -12
- package/dist/emit/csharp/types-record.js +3 -3
- package/dist/emit/csharp/types-union.d.ts +1 -1
- package/dist/emit/csharp/types.d.ts +0 -1
- package/dist/emit/csharp/types.js +3 -3
- package/dist/emit/csharp/ws.js +2 -2
- package/dist/emit/go/errors.js +1 -1
- package/dist/emit/go/http.js +2 -2
- package/dist/emit/go/module-path.js +2 -2
- package/dist/emit/go/sdk-answer.js +1 -1
- package/dist/emit/go/sdk-body.js +11 -7
- package/dist/emit/go/sdk-client.js +1 -1
- package/dist/emit/go/sdk-method.d.ts +9 -0
- package/dist/emit/go/sdk-method.js +12 -3
- package/dist/emit/go/sdk-mirror.js +2 -2
- package/dist/emit/go/sdk-opts.d.ts +0 -2
- package/dist/emit/go/sdk-opts.js +3 -3
- package/dist/emit/go/sdk.d.ts +1 -1
- package/dist/emit/go/sdk.js +12 -11
- package/dist/emit/go/sse.js +1 -1
- package/dist/emit/go/types-names.js +5 -0
- package/dist/emit/go/types-struct.d.ts +2 -1
- package/dist/emit/go/types-struct.js +1 -1
- package/dist/emit/go/types.js +9 -9
- package/dist/emit/go/ws.js +6 -6
- package/dist/emit/java/gradle.d.ts +7 -9
- package/dist/emit/java/gradle.js +8 -8
- package/dist/emit/java/json.js +1 -1
- package/dist/emit/java/layout-ast.js +1 -1
- package/dist/emit/java/layout-decl.js +5 -4
- package/dist/emit/java/layout-doc.js +13 -7
- package/dist/emit/java/layout-dot.js +1 -1
- package/dist/emit/java/layout-strings.js +4 -5
- package/dist/emit/java/layout-types.js +7 -5
- package/dist/emit/java/layout-visitor.js +4 -3
- package/dist/emit/java/layout.js +5 -4
- package/dist/emit/java/models-names.js +5 -4
- package/dist/emit/java/models-record.d.ts +0 -1
- package/dist/emit/java/models-record.js +3 -3
- package/dist/emit/java/models-union.d.ts +1 -1
- package/dist/emit/java/models-union.js +1 -1
- package/dist/emit/java/models.d.ts +1 -2
- package/dist/emit/java/models.js +25 -16
- package/dist/emit/java/realtime.d.ts +5 -17
- package/dist/emit/java/realtime.js +1 -1
- package/dist/emit/java/sdk-client.d.ts +6 -6
- package/dist/emit/java/sdk-client.js +2 -1
- package/dist/emit/java/sdk-decl.js +2 -2
- package/dist/emit/java/sdk-errors.js +1 -1
- package/dist/emit/java/sdk-headers.js +2 -2
- package/dist/emit/java/sdk-mirror.js +2 -2
- package/dist/emit/java/sdk-models.d.ts +1 -1
- package/dist/emit/java/sdk-models.js +7 -7
- package/dist/emit/java/sdk-op.d.ts +7 -11
- package/dist/emit/java/sdk-op.js +22 -10
- package/dist/emit/java/sdk-params.d.ts +5 -5
- package/dist/emit/java/sdk-params.js +3 -2
- package/dist/emit/java/sdk-plan.js +0 -1
- package/dist/emit/java/sdk.d.ts +1 -1
- package/dist/emit/java/sdk.js +21 -14
- package/dist/emit/java/sse.d.ts +2 -4
- package/dist/emit/java/sse.js +6 -6
- package/dist/emit/java/ws.d.ts +2 -2
- package/dist/emit/java/ws.js +3 -4
- package/dist/emit/mcp/annotations.js +8 -4
- package/dist/emit/mcp/files.js +9 -9
- package/dist/emit/mcp/mounted.js +2 -2
- package/dist/emit/mcp/output-schema.js +3 -3
- package/dist/emit/mcp/registry.d.ts +0 -2
- package/dist/emit/mcp/registry.js +5 -4
- package/dist/emit/mcp/runtime.js +2 -2
- package/dist/emit/mcp/schema.js +22 -11
- package/dist/emit/mcp/server.d.ts +7 -7
- package/dist/emit/mcp/server.js +7 -6
- package/dist/emit/mcp/tools.js +7 -6
- package/dist/emit/python/errors.js +3 -3
- package/dist/emit/python/realtime.js +2 -2
- package/dist/emit/python/sdk-answer.d.ts +3 -7
- package/dist/emit/python/sdk-answer.js +2 -2
- package/dist/emit/python/sdk-body.js +4 -5
- package/dist/emit/python/sdk-client.js +5 -5
- package/dist/emit/python/sdk-doc.js +2 -2
- package/dist/emit/python/sdk-method.d.ts +11 -0
- package/dist/emit/python/sdk-method.js +20 -5
- package/dist/emit/python/sdk-plan.js +0 -1
- package/dist/emit/python/sdk-pyproject.d.ts +0 -2
- package/dist/emit/python/sdk-pyproject.js +8 -8
- package/dist/emit/python/sdk.d.ts +1 -1
- package/dist/emit/python/sdk.js +12 -8
- package/dist/emit/python/sse.d.ts +0 -2
- package/dist/emit/python/sse.js +2 -2
- package/dist/emit/python/transport.js +4 -4
- package/dist/emit/python/types-dict.d.ts +2 -2
- package/dist/emit/python/types-dict.js +1 -1
- package/dist/emit/python/types-names.js +2 -2
- package/dist/emit/python/types-union.js +1 -1
- package/dist/emit/python/types.js +3 -3
- package/dist/emit/python/ws.d.ts +2 -5
- package/dist/emit/python/ws.js +4 -4
- package/dist/emit/rust/errors.js +3 -3
- package/dist/emit/rust/http.js +4 -4
- package/dist/emit/rust/realtime.js +2 -2
- package/dist/emit/rust/sdk-body.js +8 -5
- package/dist/emit/rust/sdk-cargo.d.ts +16 -18
- package/dist/emit/rust/sdk-cargo.js +12 -12
- package/dist/emit/rust/sdk-client.d.ts +1 -1
- package/dist/emit/rust/sdk-client.js +3 -3
- package/dist/emit/rust/sdk-method.d.ts +12 -1
- package/dist/emit/rust/sdk-method.js +12 -4
- package/dist/emit/rust/sdk-opts.d.ts +2 -1
- package/dist/emit/rust/sdk-opts.js +2 -2
- package/dist/emit/rust/sdk-plan.js +0 -1
- package/dist/emit/rust/sdk.d.ts +1 -1
- package/dist/emit/rust/sdk.js +9 -6
- package/dist/emit/rust/sse.d.ts +0 -5
- package/dist/emit/rust/sse.js +2 -2
- package/dist/emit/rust/types-names.js +3 -3
- package/dist/emit/rust/types-struct.js +1 -1
- package/dist/emit/rust/types-union.d.ts +1 -1
- package/dist/emit/rust/types.js +7 -5
- package/dist/emit/rust/ws.d.ts +0 -11
- package/dist/emit/rust/ws.js +5 -5
- package/dist/emit/shared/escape.js +17 -17
- package/dist/emit/shared/format.js +1 -1
- package/dist/emit/shared/gofmt.js +1 -1
- package/dist/emit/shared/lang.js +10 -10
- package/dist/emit/shared/literals.d.ts +5 -0
- package/dist/emit/shared/literals.js +8 -0
- package/dist/emit/shared/metadata.d.ts +0 -6
- package/dist/emit/shared/metadata.js +8 -7
- package/dist/emit/shared/ruff.js +1 -1
- package/dist/emit/shared/rustfmt.js +1 -1
- package/dist/emit/shared/type-emitter.js +37 -20
- package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
- package/dist/emit/shared/unknown-type.constants.js +2 -0
- package/dist/emit/ts/http.d.ts +8 -2
- package/dist/emit/ts/http.js +51 -6
- package/dist/emit/ts/package.d.ts +14 -12
- package/dist/emit/ts/package.js +10 -8
- package/dist/emit/ts/route-tree.js +2 -2
- package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
- package/dist/emit/ts/sdk-types-preamble.js +12 -4
- package/dist/emit/ts/sdk-types.d.ts +0 -5
- package/dist/emit/ts/sdk-types.js +63 -19
- package/dist/emit/ts/sdk.d.ts +3 -1
- package/dist/emit/ts/sdk.js +44 -12
- package/dist/emit/ts/service-map.d.ts +7 -1
- package/dist/emit/ts/service-map.js +10 -1
- package/dist/emit/ts/single-flight-text.d.ts +3 -0
- package/dist/emit/ts/single-flight-text.js +38 -0
- package/dist/emit/ts/tanstack-query.d.ts +3 -2
- package/dist/emit/ts/tanstack-query.js +60 -35
- package/dist/emit/ts/type-gen.js +31 -18
- package/dist/emit/ts/webhooks.d.ts +0 -2
- package/dist/emit/ts/webhooks.js +3 -3
- package/dist/extract/chain.js +5 -4
- package/dist/extract/extract.js +5 -5
- package/dist/extract/serialize.d.ts +0 -2
- package/dist/extract/serialize.js +14 -15
- package/dist/extract/walk.js +15 -12
- package/dist/gen/args.js +9 -5
- package/dist/gen/formatters.js +5 -3
- package/dist/gen/process.js +2 -1
- package/dist/gen/shipped.js +2 -2
- package/dist/gen/switch-on.constants.d.ts +2 -0
- package/dist/gen/switch-on.constants.js +2 -0
- package/dist/gen/targets.d.ts +6 -7
- package/dist/gen/targets.js +11 -6
- package/dist/gen/write.js +4 -2
- package/dist/index.js +2 -2
- package/dist/installers/cli.d.ts +4 -4
- package/dist/installers/cli.js +24 -24
- package/dist/installers/commands/build.d.ts +4 -4
- package/dist/installers/commands/build.js +2 -3
- package/dist/installers/commands/check.d.ts +2 -2
- package/dist/installers/commands/check.js +11 -10
- package/dist/installers/commands/init.d.ts +2 -2
- package/dist/installers/commands/init.js +1 -2
- package/dist/installers/config/define-config.d.ts +16 -16
- package/dist/installers/config/define-config.js +1 -1
- package/dist/installers/config/hooks/bun.d.ts +6 -6
- package/dist/installers/config/hooks/node.js +1 -1
- package/dist/installers/config/load.d.ts +6 -8
- package/dist/installers/config/load.js +7 -8
- package/dist/installers/config/resolve.d.ts +1 -2
- package/dist/installers/config/resolve.js +28 -33
- package/dist/installers/config/types.d.ts +6 -6
- package/dist/installers/config/types.js +0 -1
- package/dist/installers/render/quote.js +3 -5
- package/dist/installers/render/render.d.ts +6 -6
- package/dist/installers/render/render.js +26 -26
- package/dist/installers/ui.d.ts +4 -4
- package/dist/installers/ui.js +3 -3
- package/dist/ir/build.d.ts +3 -3
- package/dist/ir/build.js +8 -5
- package/dist/ir/invalidate-reads.d.ts +17 -0
- package/dist/ir/invalidate-reads.js +104 -0
- package/dist/ir/load.d.ts +10 -0
- package/dist/ir/load.js +65 -18
- package/dist/ir/model.d.ts +2 -1
- package/dist/ir/model.js +0 -1
- package/dist/ir/read-method.constants.d.ts +2 -0
- package/dist/ir/read-method.constants.js +2 -0
- package/dist/ir/resolve-refs.js +2 -2
- package/dist/ir/resource-tree.js +2 -1
- package/dist/ir/route-tree-intern.js +1 -1
- package/dist/ir/schema.js +3 -3
- package/dist/ir/sdk-model.js +3 -3
- package/dist/ir/slots.js +13 -8
- package/dist/ir/streams.js +1 -1
- package/dist/release/bootstrap.d.ts +3 -3
- package/dist/release/bootstrap.js +7 -7
- package/dist/release/bump-args.js +4 -4
- package/dist/release/bump-command.d.ts +1 -1
- package/dist/release/bump-command.js +9 -10
- package/dist/release/bump.d.ts +5 -4
- package/dist/release/bump.js +2 -2
- package/dist/release/cli.d.ts +4 -4
- package/dist/release/cli.js +4 -4
- package/dist/release/codegen.js +1 -1
- package/dist/release/digest.js +5 -7
- package/dist/release/git.js +5 -8
- package/dist/release/load.js +4 -4
- package/dist/release/manifest.js +9 -10
- package/dist/release/oasdiff.d.ts +10 -15
- package/dist/release/oasdiff.js +5 -6
- package/dist/release/registries.d.ts +0 -11
- package/dist/release/registries.js +17 -17
- package/dist/release/release-state.d.ts +16 -13
- package/dist/release/release-workflow.js +5 -7
- package/dist/release/repo-settings.d.ts +2 -1
- package/dist/release/spec-gate.d.ts +0 -2
- package/dist/release/spec-gate.js +6 -10
- package/dist/release/sync-command.d.ts +2 -2
- package/dist/release/sync-command.js +1 -1
- package/dist/release/sync-tree.js +9 -13
- package/dist/release/sync.d.ts +6 -6
- package/dist/release/sync.js +12 -13
- package/dist/release/types.d.ts +22 -22
- package/dist/release/types.js +0 -1
- package/dist/release/version-files.d.ts +3 -4
- package/dist/release/version-files.js +4 -5
- package/dist/runtime/.oxfmtrc.jsonc +8 -0
- package/dist/runtime/csharp/Config.cs +9 -1
- package/dist/runtime/csharp/Exchange.cs +56 -4
- package/dist/runtime/csharp/Hooks.cs +9 -0
- package/dist/runtime/csharp/Operation.cs +6 -1
- package/dist/runtime/csharp/WsDial.cs +3 -1
- package/dist/runtime/go/config.go +5 -0
- package/dist/runtime/go/hooks.go +70 -0
- package/dist/runtime/go/request.go +6 -2
- package/dist/runtime/go/stream.go +4 -1
- package/dist/runtime/go/ws.go +3 -1
- package/dist/runtime/java/ClientConfig.java +11 -0
- package/dist/runtime/java/Flight.java +2 -12
- package/dist/runtime/java/Hooks.java +45 -0
- package/dist/runtime/java/InvalidateEvent.java +10 -0
- package/dist/runtime/java/InvalidateHook.java +12 -0
- package/dist/runtime/java/InvalidateTarget.java +7 -0
- package/dist/runtime/java/Operation.java +23 -3
- package/dist/runtime/java/Realtime.java +3 -1
- package/dist/runtime/java/WsDial.java +3 -0
- package/dist/runtime/mcp/files.ts +1 -1
- package/dist/runtime/mcp/http.ts +6 -2
- package/dist/runtime/mcp/listen.ts +1 -1
- package/dist/runtime/mcp/mount.ts +2 -2
- package/dist/runtime/mcp/protocol.ts +1 -1
- package/dist/runtime/python/config.py +8 -2
- package/dist/runtime/python/exchange.py +3 -1
- package/dist/runtime/python/hooks.py +110 -5
- package/dist/runtime/python/operation.py +2 -0
- package/dist/runtime/python/send_async.py +14 -2
- package/dist/runtime/python/send_sync.py +4 -2
- package/dist/runtime/python/ws.py +5 -1
- package/dist/runtime/rust/config.rs +6 -1
- package/dist/runtime/rust/exchange.rs +15 -3
- package/dist/runtime/rust/hooks.rs +127 -2
- package/dist/runtime/rust/log.rs +11 -3
- package/dist/runtime/rust/request.rs +17 -0
- package/dist/runtime/rust/ws.rs +9 -1
- package/dist/runtime/ts/config.ts +69 -0
- package/dist/runtime/ts/http.ts +12 -10
- package/dist/runtime/ts/request.ts +2 -0
- package/dist/runtime/ts/response.ts +7 -0
- package/dist/runtime/ts/sdk-invalidate.ts +82 -0
- package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
- package/dist/runtime/ts/sdk-single-flight.ts +203 -0
- package/dist/runtime/ts/sdk-sse.ts +5 -1
- package/dist/runtime/ts/sdk-ws.ts +9 -3
- package/dist/runtime/ts/sdk.ts +55 -31
- package/dist/runtime/ts/single-flight-batch.ts +184 -0
- package/dist/runtime/ts/single-flight-body.ts +59 -0
- package/dist/runtime/ts/single-flight-run.ts +160 -0
- package/dist/runtime/ts/single-flight.constants.ts +31 -0
- package/dist/runtime/ts/single-flight.ts +158 -0
- package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
- package/dist/runtime/ts-tanstack-query/query.ts +140 -170
- package/package.json +12 -17
- package/references/INDEX.md +31 -0
- package/references/cli.md +33 -0
- package/references/configuring.md +29 -0
- package/references/documentation.md +15 -0
- package/references/errors.md +23 -0
- package/references/flags.md +104 -0
- package/references/gates.md +46 -0
- package/references/generate.md +29 -0
- package/references/install-scripts.md +28 -0
- package/references/install.md +38 -0
- package/references/license.md +8 -0
- package/references/mcp.md +76 -0
- package/references/output.md +45 -0
- package/references/overview.md +14 -0
- package/references/release-tooling.md +34 -0
- package/references/release.md +305 -0
- package/references/sdks.md +393 -0
- package/references/start.md +22 -0
- package/references/tdd.md +16 -0
- package/dist/emit/cli/index.d.ts +0 -1
- package/dist/emit/cli/index.js +0 -1
- package/dist/emit/csharp/index.d.ts +0 -1
- package/dist/emit/csharp/index.js +0 -1
- package/dist/emit/go/index.d.ts +0 -1
- package/dist/emit/go/index.js +0 -1
- package/dist/emit/java/index.d.ts +0 -2
- package/dist/emit/java/index.js +0 -2
- package/dist/emit/mcp/index.d.ts +0 -3
- package/dist/emit/mcp/index.js +0 -3
- package/dist/emit/python/index.d.ts +0 -1
- package/dist/emit/python/index.js +0 -1
- package/dist/emit/rust/index.d.ts +0 -1
- package/dist/emit/rust/index.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { compareCodeUnits, javaIdentifier, javaTypeName, NameScope } from "../shared/lang.js";
|
|
2
2
|
import { javaTypeOf } from "./models.js";
|
|
3
|
-
import { CURSOR, isLastEventIdHeader, LAST_EVENT_ID } from "./sse.js";
|
|
4
3
|
import { carriesRealtime, REALTIME_FIELDS } from "./realtime.js";
|
|
4
|
+
import { CURSOR, isLastEventIdHeader, LAST_EVENT_ID } from "./sse.js";
|
|
5
5
|
import { isReconnectTokenQuery, PROTOCOLS, RECONNECT_TOKEN, TOKEN } from "./ws.js";
|
|
6
6
|
/** The record's own members, which a component may not take (`builder()` is static). */
|
|
7
7
|
const RECORD_RESERVED = ["builder", "equals", "hashCode", "toString"];
|
|
@@ -88,7 +88,7 @@ export function fieldsOf(op, ctx) {
|
|
|
88
88
|
function streamFields(op) {
|
|
89
89
|
if (op.stream === "sse")
|
|
90
90
|
return [{ field: CURSOR, name: LAST_EVENT_ID, required: false, type: "String", where: "cursor" }];
|
|
91
|
-
if (op.stream === "realtime")
|
|
91
|
+
if (op.stream === "realtime") {
|
|
92
92
|
return REALTIME_FIELDS.map((f) => ({
|
|
93
93
|
field: f.field,
|
|
94
94
|
name: f.field,
|
|
@@ -96,6 +96,7 @@ function streamFields(op) {
|
|
|
96
96
|
type: f.type,
|
|
97
97
|
where: "realtime",
|
|
98
98
|
}));
|
|
99
|
+
}
|
|
99
100
|
if (op.stream !== "ws")
|
|
100
101
|
return [];
|
|
101
102
|
return [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/emit/java/sdk.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type PackageIdentity } from "../shared/metadata.ts";
|
|
1
2
|
import { type JavaPomMetadata } from "./gradle.ts";
|
|
2
3
|
import { type JavaCallPlan } from "./sdk-plan.ts";
|
|
3
|
-
import { type PackageIdentity } from "../shared/metadata.ts";
|
|
4
4
|
/** The package's options, each defaulted and validated. */
|
|
5
5
|
export type JavaSdkOptions = {
|
|
6
6
|
/** the Maven group id; `com.example` by default, the reserved example domain as the Go SDK's `example.com/sdk`: Maven
|
package/dist/emit/java/sdk.js
CHANGED
|
@@ -5,23 +5,25 @@
|
|
|
5
5
|
* no `HttpClient.close`). The emitted Java is google-java-format's canonical form by construction (format.test.ts).
|
|
6
6
|
*/
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
|
+
import { toIR } from "../../ir/build.js";
|
|
9
|
+
import { invalidateReads } from "../../ir/invalidate-reads.js";
|
|
10
|
+
import { sdkModel } from "../../ir/sdk-model.js";
|
|
8
11
|
import { compareCodeUnits } from "../shared/lang.js";
|
|
12
|
+
import { packageOn } from "../shared/metadata.js";
|
|
13
|
+
import { renameNotice } from "../shared/mirror.js";
|
|
9
14
|
import { buildGradle, pomOf, settingsGradle, validateArtifactId, validateClientName, validateGroupId, validatePackageName, validateVersion, } from "./gradle.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
15
|
+
import { javaTypeContext } from "./models.js";
|
|
16
|
+
import { REALTIME_FILES } from "./realtime.js";
|
|
12
17
|
import { surfaceOf } from "./sdk-client.js";
|
|
18
|
+
import { errorClassFiles, errorKeyFiles } from "./sdk-errors.js";
|
|
13
19
|
import { mirrorOf } from "./sdk-mirror.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { javaTypeContext } from "./models.js";
|
|
20
|
+
import { componentDecls, modelFiles, putFile } from "./sdk-models.js";
|
|
21
|
+
import {} from "./sdk-plan.js";
|
|
17
22
|
import { SSE_FILES } from "./sse.js";
|
|
18
|
-
import { REALTIME_FILES } from "./realtime.js";
|
|
19
23
|
import { WS_FILES } from "./ws.js";
|
|
20
|
-
import { sdkModel } from "../../ir/sdk-model.js";
|
|
21
|
-
import { toIR } from "../../ir/build.js";
|
|
22
24
|
/** The marker on line 1 of every emitted file. */
|
|
23
25
|
const MARKER = "// @generated by clients. DO NOT EDIT.";
|
|
24
|
-
|
|
26
|
+
// the package line of every vendored runtime file
|
|
25
27
|
const RUNTIME_PACKAGE = /^package http\.runtime;$/m;
|
|
26
28
|
/** The validated package for `options`. */
|
|
27
29
|
function packageOf(options) {
|
|
@@ -96,6 +98,9 @@ const OPERATION_FILES = [
|
|
|
96
98
|
"HttpException",
|
|
97
99
|
"Hops",
|
|
98
100
|
"Hooks",
|
|
101
|
+
"InvalidateEvent",
|
|
102
|
+
"InvalidateHook",
|
|
103
|
+
"InvalidateTarget",
|
|
99
104
|
"LogEntry",
|
|
100
105
|
"Operation",
|
|
101
106
|
"RawResponse",
|
|
@@ -114,8 +119,8 @@ const OPERATION_FILES = [
|
|
|
114
119
|
/** The vendored runtime's files by class name, read from disk on every call, in `packageName`; every file by default. */
|
|
115
120
|
export function runtimeFiles(packageName, features = {
|
|
116
121
|
json: true,
|
|
117
|
-
opt: true,
|
|
118
122
|
operations: true,
|
|
123
|
+
opt: true,
|
|
119
124
|
realtime: true,
|
|
120
125
|
transport: true,
|
|
121
126
|
ws: true,
|
|
@@ -164,13 +169,14 @@ function featuresOf(ops, decls) {
|
|
|
164
169
|
function emitJava(document, options) {
|
|
165
170
|
const pkg = packageOf(options);
|
|
166
171
|
const dir = `src/main/java/${pkg.packageName.replaceAll(".", "/")}`;
|
|
167
|
-
|
|
172
|
+
// an operation without an operationId is named by the IR's derivation, as every sibling emitter asks
|
|
168
173
|
const ir = toIR(document, { deriveOperationIds: true });
|
|
169
174
|
const pom = pomOf(options, ir.info);
|
|
170
175
|
const model = sdkModel(ir);
|
|
171
176
|
const ctx = javaTypeContext(ir, [pkg.clientName]);
|
|
172
177
|
const isArray = (schema) => model.resolve(schema).kind === "array";
|
|
173
178
|
const operations = model.ops.length > 0;
|
|
179
|
+
const { reads, warnings } = invalidateReads(ir);
|
|
174
180
|
const env = {
|
|
175
181
|
client: pkg.clientName,
|
|
176
182
|
ctx,
|
|
@@ -179,6 +185,7 @@ function emitJava(document, options) {
|
|
|
179
185
|
notices: [],
|
|
180
186
|
ops: model.opsById,
|
|
181
187
|
packageName: pkg.packageName,
|
|
188
|
+
reads,
|
|
182
189
|
};
|
|
183
190
|
const surface = operations ? surfaceOf(ir, env) : { files: {}, plans: [] };
|
|
184
191
|
const errors = operations
|
|
@@ -188,7 +195,7 @@ function emitJava(document, options) {
|
|
|
188
195
|
}
|
|
189
196
|
: {};
|
|
190
197
|
const decls = componentDecls(ir, ctx);
|
|
191
|
-
|
|
198
|
+
// the mirror's names are claimed last, after every normal one (the components' own hoists included)
|
|
192
199
|
const mirror = operations ? mirrorOf(ir, env) : {};
|
|
193
200
|
const runtime = Object.entries(runtimeFiles(pkg.packageName, featuresOf(model.ops, decls))).map(([name, text]) => [`${dir}/${name}.java`, text]);
|
|
194
201
|
const client = operations ? mirror[`${pkg.clientName}.java`] : `${MARKER}\n${clientJava(pkg)}`;
|
|
@@ -203,14 +210,14 @@ function emitJava(document, options) {
|
|
|
203
210
|
.filter(([name]) => name !== `${pkg.clientName}.java`)
|
|
204
211
|
.map(([name, text]) => [`${dir}/${name}`, text]),
|
|
205
212
|
];
|
|
206
|
-
|
|
213
|
+
// one declaration per file: a second claim of a path throws, never overwrites
|
|
207
214
|
const files = {};
|
|
208
215
|
for (const [path, text] of entries)
|
|
209
216
|
putFile(files, path, text);
|
|
210
217
|
const renamed = ctx.names.renamed.map((rename) => renameNotice("java", rename));
|
|
211
218
|
return {
|
|
212
219
|
files: Object.fromEntries(Object.entries(files).sort(([a], [b]) => compareCodeUnits(a, b))),
|
|
213
|
-
notices: [...new Set([...env.notices, ...renamed])],
|
|
220
|
+
notices: [...new Set([...env.notices, ...renamed, ...warnings.map((warning) => `java: ${warning}`)])],
|
|
214
221
|
plans: surface.plans,
|
|
215
222
|
};
|
|
216
223
|
}
|
package/dist/emit/java/sse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SdkOp } from "../../ir/sdk-model.ts";
|
|
2
|
-
import { type JavaTypeContext } from "./models.ts";
|
|
3
2
|
import { type Expr } from "./layout.ts";
|
|
3
|
+
import { type JavaTypeContext } from "./models.ts";
|
|
4
4
|
import type { JavaHeaders } from "./sdk-headers.ts";
|
|
5
5
|
/** The header an SSE open resumes an event stream with. */
|
|
6
6
|
export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
@@ -8,10 +8,8 @@ export declare const LAST_EVENT_ID = "Last-Event-ID";
|
|
|
8
8
|
export declare const CURSOR = "lastEventId";
|
|
9
9
|
/** Whether a declared header param is Last-Event-ID (any casing), the resume channel the cursor field carries. */
|
|
10
10
|
export declare const isLastEventIdHeader: (name: string) => boolean;
|
|
11
|
-
/** F1's doc obligation: how a stream lets its connection go. */
|
|
12
|
-
export declare const RELEASE = "Open it in try-with-resources: a for-each break without one keeps the connection.";
|
|
13
11
|
/** The SSE runtime's files: the stream, its event, the parser and the body's pump; core, with every exchange. */
|
|
14
|
-
export declare const SSE_FILES: string[];
|
|
12
|
+
export declare const SSE_FILES: readonly string[];
|
|
15
13
|
/**
|
|
16
14
|
* What an SSE op's stream yields and the decode the method hands the runtime: a named-event op's `<Op>Event` through
|
|
17
15
|
* its `of`; else `SseEvent<T>` through `EventStream.typed`, `T` the declared event schema's type, or `SseEvent<String>`
|
package/dist/emit/java/sse.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isJsonEventData, sseEvents } from "../../ir/sdk-model.js";
|
|
2
2
|
import { javaString } from "../shared/escape.js";
|
|
3
3
|
import { javaTypeName, NameScope } from "../shared/lang.js";
|
|
4
|
-
import { javaTypeOf } from "./models.js";
|
|
5
4
|
import { bin, call as callOf, cond, id, lambda, lit, local, methodHeader, param, newOf, ref, returnStmt, rule, statement, typeHeader, } from "./layout.js";
|
|
5
|
+
import { javaTypeOf } from "./models.js";
|
|
6
6
|
import { docOf } from "./sdk-decl.js";
|
|
7
7
|
/** The header an SSE open resumes an event stream with. */
|
|
8
8
|
export const LAST_EVENT_ID = "Last-Event-ID";
|
|
@@ -11,10 +11,10 @@ export const CURSOR = "lastEventId";
|
|
|
11
11
|
/** Whether a declared header param is Last-Event-ID (any casing), the resume channel the cursor field carries. */
|
|
12
12
|
export const isLastEventIdHeader = (name) => name.toLowerCase() === LAST_EVENT_ID.toLowerCase();
|
|
13
13
|
/** F1's doc obligation: how a stream lets its connection go. */
|
|
14
|
-
|
|
14
|
+
const RELEASE = "Open it in try-with-resources: a for-each break without one keeps the connection.";
|
|
15
15
|
/** The SSE runtime's files: the stream, its event, the parser and the body's pump; core, with every exchange. */
|
|
16
16
|
export const SSE_FILES = ["EventStream", "Pump", "Sse", "SseEvent"];
|
|
17
|
-
|
|
17
|
+
// the names a nested record never takes besides the models scope's: the types its declaration spells
|
|
18
18
|
const SPELLED = ["Duration", "EventStream", "Object", "SseEvent", "String", "TypeReference"];
|
|
19
19
|
/** A nested record's header: its data, then the event's name, id and retry. */
|
|
20
20
|
const recordLines = (record, data, name) => typeHeader(2, {
|
|
@@ -51,7 +51,7 @@ function nestedOf(op, events, name, ctx) {
|
|
|
51
51
|
const type = json ? javaTypeOf(data, { ...ctx, fieldName: event, parentName: op.id, path: "" }) : "String";
|
|
52
52
|
return { data: type, event, json };
|
|
53
53
|
});
|
|
54
|
-
|
|
54
|
+
// a type a record's data spells would be shadowed by a nested record of its name
|
|
55
55
|
const spelled = typed.flatMap(({ data }) => data.split(/\W+/).filter((word) => word !== ""));
|
|
56
56
|
const reserved = new Set([...SPELLED, ...spelled, name, "Unknown"]);
|
|
57
57
|
const scope = new NameScope(reserved);
|
|
@@ -76,11 +76,11 @@ function namedEvents(op, events, ctx) {
|
|
|
76
76
|
const name = ctx.names.hoist(`${op.id}.events`, `${javaTypeName(op.id)}Event`);
|
|
77
77
|
if (ctx.decls.has(name))
|
|
78
78
|
return name;
|
|
79
|
-
|
|
79
|
+
// claimed before its body: what the data types hoist comes after it
|
|
80
80
|
ctx.decls.set(name, "");
|
|
81
81
|
const nested = nestedOf(op, events, name, ctx);
|
|
82
82
|
const records = nested.map(({ record }) => record).join(", ");
|
|
83
|
-
|
|
83
|
+
// the nested records are its permits
|
|
84
84
|
const header = typeHeader(0, { end: "{", kind: "interface", modifiers: ["public", "sealed"], name, permits: [] });
|
|
85
85
|
ctx.decls.set(name, [
|
|
86
86
|
docOf(`One event of ${op.id}: ${records}, or Unknown for a name the operation does not declare, its data as sent. An instanceof match reads the event's data.`, ""),
|
package/dist/emit/java/ws.d.ts
CHANGED
|
@@ -23,9 +23,9 @@ export declare const RECONNECT_TOKEN = "reconnect_token";
|
|
|
23
23
|
export declare const PROTOCOLS = "protocols";
|
|
24
24
|
export declare const TOKEN = "reconnectToken";
|
|
25
25
|
/** Whether a declared query param is reconnect_token, the resume channel the token field carries. */
|
|
26
|
-
export declare const isReconnectTokenQuery: (name: string) =>
|
|
26
|
+
export declare const isReconnectTokenQuery: (name: string) => boolean;
|
|
27
27
|
/** The WebSocket runtime's files: the socket and its parts; only an SDK with a WebSocket operation ships them. */
|
|
28
|
-
export declare const WS_FILES: string[];
|
|
28
|
+
export declare const WS_FILES: readonly string[];
|
|
29
29
|
/**
|
|
30
30
|
* What a generated reader extends: its base class, the handlers the base has (a member whose `on<Value>` one of them
|
|
31
31
|
* names gets none), what its docs call it, and the suffix its name takes after the read type's.
|
package/dist/emit/java/ws.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NameScope } from "../shared/lang.js";
|
|
2
2
|
import { bin, call as callOf, exprStmt, id, ifOpen, lambda, lit, methodHeader, newOf, param, returnStmt, statement, typeHeader, } from "./layout.js";
|
|
3
|
-
import { declaredTypeOf, keyedArms } from "./models.js";
|
|
4
3
|
import { JSON_NODE } from "./models-names.js";
|
|
4
|
+
import { declaredTypeOf, keyedArms } from "./models.js";
|
|
5
5
|
import { docOf } from "./sdk-decl.js";
|
|
6
6
|
/** The query param the token travels in. */
|
|
7
7
|
export const RECONNECT_TOKEN = "reconnect_token";
|
|
@@ -42,7 +42,7 @@ const handlerLines = (reader, sub, name, { payload, wrapper }) => [
|
|
|
42
42
|
];
|
|
43
43
|
/** The arms of `arms` that get an `on<Value>`: each but one whose handler `reader` has already. */
|
|
44
44
|
export const handledArms = (reader, arms) => arms.filter((arm) => !reader.handlers.includes(handlerName(arm)));
|
|
45
|
-
|
|
45
|
+
// the handler an arm's first value spells
|
|
46
46
|
const handlerName = (arm) => `on${arm.spelled}`;
|
|
47
47
|
/**
|
|
48
48
|
* `<read><Suffix>`, hoisted into `ctx.decls` once per read type and reader with an `on<Value>` per arm of `arms` but
|
|
@@ -82,9 +82,8 @@ export function wsSocketOf(op, ctx) {
|
|
|
82
82
|
const messages = op.ir.messages;
|
|
83
83
|
const at = (fieldName) => ({ ...ctx, fieldName, parentName: op.id, path: "" });
|
|
84
84
|
const write = messages?.receive === undefined ? JSON_NODE : declaredTypeOf(messages.receive, at("Receive"));
|
|
85
|
-
if (messages?.send === undefined)
|
|
85
|
+
if (messages?.send === undefined)
|
|
86
86
|
return { read: asSent(), type: `TypedWebSocket<WsMessage, ${write}>`, wrap: AS_DIALED };
|
|
87
|
-
}
|
|
88
87
|
const read = declaredTypeOf(messages.send, at("Send"));
|
|
89
88
|
const decode = callOf("TypedWebSocket", "json", [newOf(`TypeReference<${read}>`, [], true)]);
|
|
90
89
|
const arms = keyedArms(read, messages.send, ctx);
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
export function annotationsOf(op) {
|
|
3
3
|
switch (op.method.toUpperCase()) {
|
|
4
4
|
case "GET":
|
|
5
|
-
case "HEAD":
|
|
5
|
+
case "HEAD": {
|
|
6
6
|
return { readOnlyHint: true };
|
|
7
|
-
|
|
7
|
+
}
|
|
8
|
+
case "POST": {
|
|
8
9
|
return op.idempotent ? { destructiveHint: false, idempotentHint: true } : { destructiveHint: false };
|
|
10
|
+
}
|
|
9
11
|
case "PUT":
|
|
10
|
-
case "DELETE":
|
|
12
|
+
case "DELETE": {
|
|
11
13
|
return { idempotentHint: true };
|
|
12
|
-
|
|
14
|
+
}
|
|
15
|
+
default: {
|
|
13
16
|
return undefined;
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
}
|
package/dist/emit/mcp/files.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
const STRING = { type: "string" };
|
|
2
2
|
/** The extension's FileInput, marked: the members it requires, the digest's algorithm SHA-256. */
|
|
3
3
|
const FILE_INPUT = {
|
|
4
|
-
type: "object",
|
|
5
|
-
"x-mcp-file": {},
|
|
6
4
|
properties: {
|
|
7
5
|
digest: {
|
|
8
|
-
type: "object",
|
|
9
6
|
properties: { algorithm: { const: "sha-256" }, value: STRING },
|
|
10
7
|
required: ["algorithm", "value"],
|
|
8
|
+
type: "object",
|
|
11
9
|
},
|
|
12
10
|
},
|
|
13
11
|
required: ["id", "mimeType", "size", "digest"],
|
|
12
|
+
type: "object",
|
|
13
|
+
"x-mcp-file": {},
|
|
14
14
|
};
|
|
15
15
|
/** A file argument's schema: the extension's FileInput, or a path the server reads. */
|
|
16
16
|
export const FILE_SCHEMA = {
|
|
17
17
|
anyOf: [
|
|
18
18
|
FILE_INPUT,
|
|
19
19
|
{
|
|
20
|
-
type: "object",
|
|
21
|
-
properties: { path: { type: "string", description: "A file under the server's file root" } },
|
|
22
|
-
required: ["path"],
|
|
23
20
|
additionalProperties: false,
|
|
21
|
+
properties: { path: { description: "A file under the server's file root", type: "string" } },
|
|
22
|
+
required: ["path"],
|
|
23
|
+
type: "object",
|
|
24
24
|
},
|
|
25
25
|
],
|
|
26
26
|
};
|
|
@@ -33,10 +33,10 @@ export const MOUNTED_FILE_SCHEMA = {
|
|
|
33
33
|
anyOf: [
|
|
34
34
|
FILE_INPUT,
|
|
35
35
|
{
|
|
36
|
-
type: "object",
|
|
37
|
-
properties: { url: { type: "string", description: "An https URL the server fetches" } },
|
|
38
|
-
required: ["url"],
|
|
39
36
|
additionalProperties: false,
|
|
37
|
+
properties: { url: { description: "An https URL the server fetches", type: "string" } },
|
|
38
|
+
required: ["url"],
|
|
39
|
+
type: "object",
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
42
|
};
|
package/dist/emit/mcp/mounted.js
CHANGED
|
@@ -16,11 +16,11 @@ import { MCP_PORTABLE, mcpRuntimeSource } from "./runtime.js";
|
|
|
16
16
|
import { resolved } from "./server.js";
|
|
17
17
|
import { isTool, toolsOf, untoolable } from "./tools.js";
|
|
18
18
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
19
|
-
|
|
19
|
+
// a directory name a relative import names
|
|
20
20
|
const DIR = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/;
|
|
21
21
|
/** `op`'s security requirements: its own, else the document's. */
|
|
22
22
|
function requirementsOf(spec, op) {
|
|
23
|
-
|
|
23
|
+
// a tool's operation is the document's own, at its path and method
|
|
24
24
|
const paths = spec.paths;
|
|
25
25
|
const own = paths[op.path][op.method.toLowerCase()];
|
|
26
26
|
return own.security ?? spec.security ?? [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sseEvents } from "../../ir/sdk-model.js";
|
|
2
1
|
import { irResolver } from "../../ir/schema.js";
|
|
2
|
+
import { sseEvents } from "../../ir/sdk-model.js";
|
|
3
3
|
import { jsonSchemaOf } from "./schema.js";
|
|
4
4
|
const STRING = { type: "string" };
|
|
5
5
|
/** An event of a stream that does not name its events: its data as `data` says, its name and id when it has them. */
|
|
@@ -66,14 +66,14 @@ export function outputOf(op, ir) {
|
|
|
66
66
|
outputSchema: collectedOf(unnamedOf(op.events === undefined ? STRING : jsonSchemaOf(op.events, ir.schemas))),
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
// the SDK model gives a success its schema only when it is JSON
|
|
70
70
|
if (op.success.schema === undefined)
|
|
71
71
|
return undefined;
|
|
72
72
|
const result = jsonSchemaOf(op.success.schema, ir.schemas);
|
|
73
73
|
const names = [...new Set((op.ir.responses[op.success.status]?.headers ?? []).map(({ name }) => name.toLowerCase()))];
|
|
74
74
|
if (result.type === "object" && names.length === 0)
|
|
75
75
|
return { outputSchema: result };
|
|
76
|
-
|
|
76
|
+
// null-prototype: a header named __proto__ is a property, never the object's prototype
|
|
77
77
|
const headers = Object.create(null);
|
|
78
78
|
for (const name of names.sort())
|
|
79
79
|
headers[name] = { type: "string" };
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { IR } from "../../ir/model.ts";
|
|
10
10
|
import type { Metadata } from "../shared/metadata.ts";
|
|
11
|
-
/** The schema the file names, the registry's latest dated one. */
|
|
12
|
-
export declare const SERVER_SCHEMA = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
|
|
13
11
|
/** The server as the registry lists it: its names, the version npm publishes, and what its environment holds. */
|
|
14
12
|
export type Listing = {
|
|
15
13
|
readonly name: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** The schema the file names, the registry's latest dated one. */
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const SERVER_SCHEMA = "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json";
|
|
3
|
+
// the registry's cap on a description, in characters
|
|
4
4
|
const DESCRIPTION_MAX = 100;
|
|
5
|
-
|
|
5
|
+
// the forges the registry knows by host: the `source` it validates a repository through
|
|
6
6
|
const SOURCES = { "github.com": "github", "gitlab.com": "gitlab" };
|
|
7
7
|
/** Every variable the server reads over stdio, as its entry reads them; the HTTP transport's are not the package's. */
|
|
8
8
|
function variablesOf(listing, ir) {
|
|
@@ -50,8 +50,9 @@ function variablesOf(listing, ir) {
|
|
|
50
50
|
/** The description the registry shows: the run's, else the package's own, refused past the registry's cap. */
|
|
51
51
|
function descriptionOf(listing, metadata) {
|
|
52
52
|
const text = metadata.description ?? `The ${listing.name} API as MCP tools`;
|
|
53
|
-
if ([...text].length > DESCRIPTION_MAX)
|
|
53
|
+
if ([...text].length > DESCRIPTION_MAX) {
|
|
54
54
|
throw new Error(`Invalid metadata.description: ${JSON.stringify(text)}: the MCP registry takes ${DESCRIPTION_MAX} characters at most`);
|
|
55
|
+
}
|
|
55
56
|
return text;
|
|
56
57
|
}
|
|
57
58
|
/** The repository as the registry links it, for a forge it knows; none for another host. */
|
package/dist/emit/mcp/runtime.js
CHANGED
|
@@ -35,13 +35,13 @@ export const MCP_STANDALONE = [
|
|
|
35
35
|
"reader",
|
|
36
36
|
"listen",
|
|
37
37
|
];
|
|
38
|
-
|
|
38
|
+
// an import of a sibling runtime module, on one line or several
|
|
39
39
|
const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
|
|
40
40
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
41
41
|
/** The vendored runtime as one module: `names` (the standalone package's by default) in order, sibling imports dropped. */
|
|
42
42
|
export function mcpRuntimeSource(names = MCP_STANDALONE) {
|
|
43
43
|
const modules = names.map((name) => readFileSync(new URL(`../../runtime/mcp/${name}.ts`, import.meta.url), "utf8")
|
|
44
|
-
.
|
|
44
|
+
.replaceAll(SIBLING_IMPORT, "")
|
|
45
45
|
.trim());
|
|
46
46
|
return `${MARKER}\n\n${modules.join("\n\n")}\n`;
|
|
47
47
|
}
|
package/dist/emit/mcp/schema.js
CHANGED
|
@@ -53,33 +53,44 @@ function convert(schema, walk) {
|
|
|
53
53
|
if (++walk.nodes.count > walk.budget)
|
|
54
54
|
throw new Error(`a schema inlines past ${walk.budget} nodes`);
|
|
55
55
|
switch (schema.kind) {
|
|
56
|
-
case "scalar":
|
|
56
|
+
case "scalar": {
|
|
57
57
|
return scalarOf(schema);
|
|
58
|
-
|
|
58
|
+
}
|
|
59
|
+
case "const": {
|
|
59
60
|
return { const: schema.value };
|
|
60
|
-
|
|
61
|
+
}
|
|
62
|
+
case "object": {
|
|
61
63
|
return objectOf(schema.fields, schema.additional, walk);
|
|
62
|
-
|
|
64
|
+
}
|
|
65
|
+
case "array": {
|
|
63
66
|
return {
|
|
64
67
|
type: "array",
|
|
65
68
|
items: convert(schema.items, walk),
|
|
66
69
|
...(schema.minItems === undefined ? {} : { minItems: schema.minItems }),
|
|
67
70
|
...(schema.maxItems === undefined ? {} : { maxItems: schema.maxItems }),
|
|
68
71
|
};
|
|
69
|
-
|
|
72
|
+
}
|
|
73
|
+
case "tuple": {
|
|
70
74
|
return tupleOf(schema, walk);
|
|
71
|
-
|
|
75
|
+
}
|
|
76
|
+
case "union": {
|
|
72
77
|
return { anyOf: schema.variants.map((variant) => convert(variant, walk)) };
|
|
73
|
-
|
|
78
|
+
}
|
|
79
|
+
case "allOf": {
|
|
74
80
|
return { allOf: schema.parts.map((part) => convert(part, walk)) };
|
|
75
|
-
|
|
81
|
+
}
|
|
82
|
+
case "ref": {
|
|
76
83
|
return inlineRef(schema.name, walk);
|
|
77
|
-
|
|
84
|
+
}
|
|
85
|
+
case "nullable": {
|
|
78
86
|
return { anyOf: [convert(schema.inner, walk), { type: "null" }] };
|
|
79
|
-
|
|
87
|
+
}
|
|
88
|
+
case "binary": {
|
|
80
89
|
return { type: "string", contentEncoding: "base64" };
|
|
81
|
-
|
|
90
|
+
}
|
|
91
|
+
case "unknown": {
|
|
82
92
|
return {};
|
|
93
|
+
}
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
96
|
/** `schema` as a self-contained JSON Schema, every ref into `schemas` inlined, refused past `budget` nodes. */
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type Metadata, type PackageIdentity } from "../shared/metadata.ts";
|
|
2
2
|
export type McpServerOptions = {
|
|
3
3
|
/** the server's name: lowercase words joined by `-`, at most 60 characters; by default the document title's */
|
|
4
|
-
readonly name?: string;
|
|
4
|
+
readonly name?: string | undefined;
|
|
5
5
|
/** the prefix of its environment variables; by default the name's words, uppercased, joined by `_` */
|
|
6
|
-
readonly envPrefix?: string;
|
|
6
|
+
readonly envPrefix?: string | undefined;
|
|
7
7
|
/** the version its server info and package.json carry, one npm accepts; by default the document's */
|
|
8
|
-
readonly version?: string;
|
|
8
|
+
readonly version?: string | undefined;
|
|
9
9
|
/** the npm name it publishes under; `<name>-mcp` by default, the bin's name either way */
|
|
10
|
-
readonly packageName?: string;
|
|
10
|
+
readonly packageName?: string | undefined;
|
|
11
11
|
/** the MCP registry's name for it, `namespace/name` (`io.github.acme/shop`): package.json's `mcpName`, which the
|
|
12
12
|
* registry checks the npm package by; none by default */
|
|
13
|
-
readonly mcpName?: string;
|
|
13
|
+
readonly mcpName?: string | undefined;
|
|
14
14
|
};
|
|
15
15
|
export type GeneratedMcpServer = {
|
|
16
16
|
readonly files: Readonly<Record<string, string>>;
|
|
@@ -21,8 +21,8 @@ export type GeneratedMcpServer = {
|
|
|
21
21
|
};
|
|
22
22
|
/** The options with their defaults filled, each refused unless it matches its grammar (F2). */
|
|
23
23
|
export declare function resolved(options: McpServerOptions, title: string | undefined): {
|
|
24
|
-
envPrefix: string;
|
|
25
|
-
name: string;
|
|
24
|
+
readonly envPrefix: string;
|
|
25
|
+
readonly name: string;
|
|
26
26
|
};
|
|
27
27
|
/** `source` with its types erased, as ES module JavaScript; the entry gets the shebang a bin needs. */
|
|
28
28
|
export declare function erased(path: string, source: string): string;
|
package/dist/emit/mcp/server.js
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { toIR } from "../../ir/build.js";
|
|
10
10
|
import { binaryNameOf } from "../cli/module.js";
|
|
11
|
-
import { checked, NPM_NAME, packageOn, SEMVER } from "../shared/metadata.js";
|
|
12
11
|
import { tsString } from "../shared/escape.js";
|
|
12
|
+
import { checked, NPM_NAME, packageOn, SEMVER } from "../shared/metadata.js";
|
|
13
13
|
import { compiled, npmFields } from "../ts/package.js";
|
|
14
14
|
import { generateSdk } from "../ts/sdk.js";
|
|
15
15
|
import { literal } from "./literal.js";
|
|
16
16
|
import { serverJson } from "./registry.js";
|
|
17
17
|
import { mcpRuntimeSource } from "./runtime.js";
|
|
18
18
|
import { toolsOf, untoolable } from "./tools.js";
|
|
19
|
-
|
|
19
|
+
// a name leaves room for the bin's `-mcp`; a prefix is uppercase words joined by `_`
|
|
20
20
|
const NAME = /^(?=.{1,60}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
21
21
|
const ENV_PREFIX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
22
|
-
|
|
22
|
+
// a server name as the MCP registry's server.json schema (2025-12-11) takes it: a reverse-DNS namespace, `/`, a name
|
|
23
23
|
const MCP_NAME = /^(?=.{3,200}$)[a-zA-Z0-9.-]+\/[a-zA-Z0-9._-]+$/;
|
|
24
24
|
const MARKER = "// Code generated by clients. DO NOT EDIT.";
|
|
25
25
|
/** The options with their defaults filled, each refused unless it matches its grammar (F2). */
|
|
@@ -34,7 +34,7 @@ export function resolved(options, title) {
|
|
|
34
34
|
throw new Error(`Invalid version: ${JSON.stringify(options.version)}`);
|
|
35
35
|
return { envPrefix, name };
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
// a cap in bytes from the environment: a whole number, its default when unset
|
|
38
38
|
const BYTES = `const bytes = (name: string, fallback: string): number => {
|
|
39
39
|
const text = process.env[name] || fallback
|
|
40
40
|
if (/^(?:0|[1-9][0-9]{0,14})$/.test(text)) return Number(text)
|
|
@@ -215,13 +215,14 @@ export function generateMcpServer(document, options = {}, metadata = {}) {
|
|
|
215
215
|
packageName: checked("packageName", options.packageName ?? `${name}-mcp`, NPM_NAME),
|
|
216
216
|
};
|
|
217
217
|
const version = options.version ?? ir.info.version ?? "0.0.0";
|
|
218
|
-
|
|
218
|
+
// what npm and the registries take: the version when it is semver, else 0.0.0
|
|
219
219
|
const publishable = SEMVER.test(version) ? version : "0.0.0";
|
|
220
220
|
const specs = toolsOf(ir);
|
|
221
|
-
if (specs.length === 0)
|
|
221
|
+
if (specs.length === 0) {
|
|
222
222
|
throw new Error(ir.operations.some((op) => op.extensions.mcp === true)
|
|
223
223
|
? "No operation marked x-mcp is one a tool can call yet: nothing to serve"
|
|
224
224
|
: "No operation is marked x-mcp: nothing to serve");
|
|
225
|
+
}
|
|
225
226
|
const files = specs.some((spec) => spec.parts?.some(([, , kind]) => kind !== "text"));
|
|
226
227
|
const sdk = generateSdk(document, { name: "Api", stem: "api" });
|
|
227
228
|
const source = {
|
package/dist/emit/mcp/tools.js
CHANGED
|
@@ -44,7 +44,7 @@ export function untoolable(op) {
|
|
|
44
44
|
export const isTool = (op) => op.extensions.mcp === true && untoolable(op) === undefined;
|
|
45
45
|
/** The tool name for `id`, not one `taken` holds: snake case, sanitized, truncated, then suffixed. */
|
|
46
46
|
export function toolName(id, taken) {
|
|
47
|
-
|
|
47
|
+
// snakeWords keeps only letters, digits and inner underscores: nothing is left to sanitize
|
|
48
48
|
const base = (snakeWords(id) || "tool").slice(0, NAME_MAX);
|
|
49
49
|
let name = base;
|
|
50
50
|
for (let n = 2; taken.has(name); n++)
|
|
@@ -77,7 +77,7 @@ function bodyOf(op, ir, into) {
|
|
|
77
77
|
const field = bodyField(op);
|
|
78
78
|
if (field === undefined || op.body === undefined)
|
|
79
79
|
return {};
|
|
80
|
-
|
|
80
|
+
// a multipart form is never a stream: it has its schema
|
|
81
81
|
if (field === "parts")
|
|
82
82
|
return { parts: partsOf(op.body.schema, ir, into) };
|
|
83
83
|
const property = into.scope.claim("body");
|
|
@@ -90,7 +90,7 @@ function bodyOf(op, ir, into) {
|
|
|
90
90
|
function inputOf(op, ir, file) {
|
|
91
91
|
const scope = new NameScope();
|
|
92
92
|
const credentials = new Set([...CREDENTIAL_HEADERS, ir.auth.headerName.toLowerCase()]);
|
|
93
|
-
|
|
93
|
+
// null-prototype: a parameter named __proto__ is a property, never the object's prototype
|
|
94
94
|
const properties = Object.create(null);
|
|
95
95
|
const required = [];
|
|
96
96
|
const args = [];
|
|
@@ -99,7 +99,7 @@ function inputOf(op, ir, file) {
|
|
|
99
99
|
["search", op.params.query],
|
|
100
100
|
["headers", op.params.header.filter((param) => !credentials.has(param.name.toLowerCase()))],
|
|
101
101
|
];
|
|
102
|
-
for (const [group, params] of groups)
|
|
102
|
+
for (const [group, params] of groups) {
|
|
103
103
|
for (const param of params) {
|
|
104
104
|
const property = scope.claim(param.name);
|
|
105
105
|
properties[property] = { ...jsonSchemaOf(param.schema, ir.schemas), ...describe(param.description) };
|
|
@@ -107,6 +107,7 @@ function inputOf(op, ir, file) {
|
|
|
107
107
|
required.push(property);
|
|
108
108
|
args.push([property, group, param.name]);
|
|
109
109
|
}
|
|
110
|
+
}
|
|
110
111
|
const body = bodyOf(op, ir, { file, properties, required, scope });
|
|
111
112
|
let collect;
|
|
112
113
|
if (op.extensions.sse === true) {
|
|
@@ -134,14 +135,14 @@ export function toolsOf(ir, file = FILE_SCHEMA) {
|
|
|
134
135
|
const taken = new Set();
|
|
135
136
|
return ir.operations.filter(isTool).map((op) => {
|
|
136
137
|
const { args, body, collect, inputSchema } = inputOf(op, ir, file);
|
|
137
|
-
|
|
138
|
+
// the SDK model holds every operation of the IR
|
|
138
139
|
const sdkOp = model.opsById.get(op.id);
|
|
139
140
|
const annotations = annotationsOf(sdkOp);
|
|
140
141
|
return {
|
|
141
142
|
name: toolName(op.id, taken),
|
|
142
143
|
...describe(op.description ?? op.summary),
|
|
143
144
|
inputSchema,
|
|
144
|
-
|
|
145
|
+
// sdkMemberPaths holds every operation of the IR
|
|
145
146
|
member: members.get(op.id),
|
|
146
147
|
args,
|
|
147
148
|
...body,
|
|
@@ -5,7 +5,7 @@ import { pyTopLevel } from "./types.js";
|
|
|
5
5
|
/** The keys an error response's envelope names, over every operation's JSON error statuses (the runtime reads JSON only). */
|
|
6
6
|
function envelopeKeys(model) {
|
|
7
7
|
return model.ops.flatMap((op) => op.errorStatuses.flatMap((status) => {
|
|
8
|
-
|
|
8
|
+
// an error status is a declared response, and a schema comes with the content type it is under
|
|
9
9
|
const { contentType, schema } = op.ir.responses[String(status)];
|
|
10
10
|
if (schema === undefined || !isJsonMedia(contentType))
|
|
11
11
|
return [];
|
|
@@ -19,7 +19,7 @@ function envelopeKeys(model) {
|
|
|
19
19
|
function declaredKeys(model) {
|
|
20
20
|
const byId = [...model.ops].sort((a, b) => compareCodeUnits(a.id, b.id));
|
|
21
21
|
const declared = byId.flatMap((op) => Object.entries(op.ir.extensions.errors ?? {}));
|
|
22
|
-
|
|
22
|
+
// a later entry wins: an envelope's key gives way to a declaration, each declaration reversed to its first
|
|
23
23
|
const keys = new Map([
|
|
24
24
|
...envelopeKeys(model).map((key) => [key, undefined]),
|
|
25
25
|
...declared.toReversed().map(([key, { schema }]) => [key, schema]),
|
|
@@ -50,7 +50,7 @@ export function pythonErrorKeys(model, at) {
|
|
|
50
50
|
const members = new NameScope();
|
|
51
51
|
const keys = declared.map(([wire, schema]) => ({
|
|
52
52
|
data: bodyType(wire, schema, model, at),
|
|
53
|
-
|
|
53
|
+
// an UPPER_SNAKE member never meets a keyword, so the keyword guard's `_` goes
|
|
54
54
|
member: members.claim(pyIdentifier(wire).replace(/_$/, "").toUpperCase()),
|
|
55
55
|
wire,
|
|
56
56
|
}));
|