effect 4.0.0-beta.101 → 4.0.0-beta.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +81 -5
- package/dist/Array.js.map +1 -1
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +27 -9
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +6 -5
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.js +7 -7
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +2 -1
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +61 -100
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +66 -39
- package/dist/Effect.js.map +1 -1
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +3 -2
- package/dist/FiberHandle.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +2 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/JsonPatch.d.ts.map +1 -1
- package/dist/JsonPatch.js +4 -3
- package/dist/JsonPatch.js.map +1 -1
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +9 -11
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +3 -2
- package/dist/Logger.js.map +1 -1
- package/dist/ManagedRuntime.d.ts +9 -0
- package/dist/ManagedRuntime.d.ts.map +1 -1
- package/dist/ManagedRuntime.js +3 -0
- package/dist/ManagedRuntime.js.map +1 -1
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +4 -3
- package/dist/Metric.js.map +1 -1
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +5 -4
- package/dist/Optic.js.map +1 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +2 -1
- package/dist/Option.js.map +1 -1
- package/dist/PartitionedSemaphore.d.ts.map +1 -1
- package/dist/PartitionedSemaphore.js +1 -4
- package/dist/PartitionedSemaphore.js.map +1 -1
- package/dist/Record.d.ts +93 -1
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +57 -19
- package/dist/Record.js.map +1 -1
- package/dist/References.d.ts +0 -45
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +0 -45
- package/dist/References.js.map +1 -1
- package/dist/Request.d.ts.map +1 -1
- package/dist/Request.js +9 -6
- package/dist/Request.js.map +1 -1
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js +2 -1
- package/dist/Result.js.map +1 -1
- package/dist/Schema.d.ts +1268 -495
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +2308 -614
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -2
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +189 -130
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.js +1 -1
- package/dist/SchemaError.js.map +1 -1
- package/dist/SchemaGetter.d.ts +13 -11
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +34 -24
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.js +1 -1
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +1 -12
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +403 -1504
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +294 -2852
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.js +3 -3
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/Semaphore.d.ts +5 -3
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js.map +1 -1
- package/dist/Stream.d.ts +15 -9
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +46 -16
- package/dist/Stream.js.map +1 -1
- package/dist/Struct.d.ts.map +1 -1
- package/dist/Struct.js +5 -4
- package/dist/Struct.js.map +1 -1
- package/dist/Types.d.ts +1 -3
- package/dist/Types.d.ts.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/core.js +2 -1
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/effect.js +64 -21
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/matcher.js +1 -1
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/record.d.ts +0 -3
- package/dist/internal/record.d.ts.map +1 -1
- package/dist/internal/record.js +10 -5
- package/dist/internal/record.js.map +1 -1
- package/dist/internal/references.js +0 -4
- package/dist/internal/references.js.map +1 -1
- package/dist/internal/schema/annotations.js +12 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.d.ts +2 -0
- package/dist/internal/schema/fromJsonSchemaDocument.d.ts.map +1 -0
- package/dist/internal/schema/fromJsonSchemaDocument.js +743 -0
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -0
- package/dist/internal/schema/fromRepresentation.d.ts +2 -0
- package/dist/internal/schema/fromRepresentation.d.ts.map +1 -0
- package/dist/internal/schema/fromRepresentation.js +252 -0
- package/dist/internal/schema/fromRepresentation.js.map +1 -0
- package/dist/internal/schema/schema.js +28 -40
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/{arbitrary.d.ts → toArbitrary.d.ts} +1 -1
- package/dist/internal/schema/toArbitrary.d.ts.map +1 -0
- package/dist/internal/schema/{arbitrary.js → toArbitrary.js} +8 -9
- package/dist/internal/schema/toArbitrary.js.map +1 -0
- package/dist/internal/schema/toCodeDocument.d.ts +2 -0
- package/dist/internal/schema/toCodeDocument.d.ts.map +1 -0
- package/dist/internal/schema/toCodeDocument.js +438 -0
- package/dist/internal/schema/toCodeDocument.js.map +1 -0
- package/dist/internal/schema/toEquivalence.d.ts +2 -0
- package/dist/internal/schema/toEquivalence.d.ts.map +1 -0
- package/dist/internal/schema/{equivalence.js → toEquivalence.js} +15 -13
- package/dist/internal/schema/toEquivalence.js.map +1 -0
- package/dist/internal/schema/toJsonSchemaDocument.d.ts +2 -0
- package/dist/internal/schema/toJsonSchemaDocument.d.ts.map +1 -0
- package/dist/internal/schema/toJsonSchemaDocument.js +466 -0
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -0
- package/dist/internal/schema/toRepresentation.d.ts +2 -0
- package/dist/internal/schema/toRepresentation.d.ts.map +1 -0
- package/dist/internal/schema/toRepresentation.js +369 -0
- package/dist/internal/schema/toRepresentation.js.map +1 -0
- package/dist/internal/stackTraceLimit.js +3 -6
- package/dist/internal/stackTraceLimit.js.map +1 -1
- package/dist/testing/TestClock.js +4 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +26 -26
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +5 -4
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +21 -6
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js +86 -316
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/EmbeddingModel.d.ts +1 -1
- package/dist/unstable/ai/EmbeddingModel.js +1 -1
- package/dist/unstable/ai/EmbeddingModel.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +4 -1
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +19 -17
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +197 -197
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +13 -13
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +4 -4
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +116 -49
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +32 -10
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +193 -377
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Response.d.ts +19 -19
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +14 -14
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +4 -0
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +11 -3
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +9 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +14 -10
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +15 -12
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/ai/internal/structured-output.d.ts +2 -0
- package/dist/unstable/ai/internal/structured-output.d.ts.map +1 -0
- package/dist/unstable/ai/internal/structured-output.js +316 -0
- package/dist/unstable/ai/internal/structured-output.js.map +1 -0
- package/dist/unstable/cli/CliError.d.ts +40 -2
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +45 -6
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.js +14 -5
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/Param.js +3 -3
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.js +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +3 -1
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +11 -4
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/config.d.ts +0 -48
- package/dist/unstable/cli/internal/config.d.ts.map +1 -1
- package/dist/unstable/cli/internal/config.js +8 -10
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.js +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/Envelope.d.ts.map +1 -1
- package/dist/unstable/cluster/Envelope.js +2 -1
- package/dist/unstable/cluster/Envelope.js.map +1 -1
- package/dist/unstable/cluster/Reply.js +1 -1
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/Runner.d.ts +1 -1
- package/dist/unstable/cluster/Runner.js +1 -1
- package/dist/unstable/cluster/Runner.js.map +1 -1
- package/dist/unstable/cluster/RunnerAddress.d.ts +1 -1
- package/dist/unstable/cluster/RunnerAddress.js +1 -1
- package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
- package/dist/unstable/cluster/ShardId.js +1 -1
- package/dist/unstable/cluster/ShardId.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +125 -24
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +10 -2
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SingleRunner.d.ts +4 -2
- package/dist/unstable/cluster/SingleRunner.d.ts.map +1 -1
- package/dist/unstable/cluster/SingleRunner.js +2 -1
- package/dist/unstable/cluster/SingleRunner.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts +7 -4
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +55 -24
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +109 -62
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +19 -7
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/shardLock.d.ts +2 -0
- package/dist/unstable/cluster/internal/shardLock.d.ts.map +1 -0
- package/dist/unstable/cluster/internal/shardLock.js +4 -0
- package/dist/unstable/cluster/internal/shardLock.js.map +1 -0
- package/dist/unstable/devtools/DevToolsSchema.d.ts +20 -20
- package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js +8 -5
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.js +1 -1
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLog.js +15 -11
- package/dist/unstable/eventlog/EventLog.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +4 -4
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +8 -3
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.js +2 -2
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +3 -3
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +24 -22
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Headers.js +8 -8
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +44 -0
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +14 -0
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +5 -4
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +17 -15
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/http/Template.js +1 -1
- package/dist/unstable/http/Template.js.map +1 -1
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +17 -14
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +3 -3
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +5 -5
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +37 -24
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +72 -1
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +69 -4
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts +4 -3
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +2 -2
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +7 -3
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.js +5 -2
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts +4 -3
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.js +2 -2
- package/dist/unstable/observability/OtlpTracer.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.js +2 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +2 -2
- package/dist/unstable/persistence/RateLimiter.js +2 -2
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +2 -2
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.js +3 -1
- package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +4 -3
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +83 -0
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +31 -0
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +2 -1
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +1 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +13 -10
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +1 -1
- package/dist/unstable/socket/Socket.js +1 -1
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/sql/SqlError.d.ts +2 -2
- package/dist/unstable/sql/SqlError.js +2 -2
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +7 -6
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +86 -25
- package/src/Channel.ts +32 -14
- package/src/Config.ts +6 -5
- package/src/ConfigProvider.ts +7 -7
- package/src/Data.ts +3 -2
- package/src/Effect.ts +70 -116
- package/src/FiberHandle.ts +3 -2
- package/src/Iterable.ts +2 -1
- package/src/JsonPatch.ts +4 -3
- package/src/JsonSchema.ts +9 -11
- package/src/Logger.ts +3 -2
- package/src/ManagedRuntime.ts +13 -0
- package/src/Metric.ts +4 -3
- package/src/Optic.ts +5 -4
- package/src/Option.ts +2 -1
- package/src/PartitionedSemaphore.ts +1 -4
- package/src/Record.ts +119 -22
- package/src/References.ts +0 -46
- package/src/Request.ts +5 -7
- package/src/Result.ts +2 -1
- package/src/Schema.ts +2537 -986
- package/src/SchemaAST.ts +228 -149
- package/src/SchemaError.ts +1 -1
- package/src/SchemaGetter.ts +36 -29
- package/src/SchemaIssue.ts +1 -1
- package/src/SchemaParser.ts +1 -25
- package/src/SchemaRepresentation.ts +697 -3398
- package/src/SchemaTransformation.ts +3 -3
- package/src/Semaphore.ts +5 -3
- package/src/Stream.ts +63 -19
- package/src/Struct.ts +5 -4
- package/src/Types.ts +1 -3
- package/src/index.ts +0 -5
- package/src/internal/core.ts +3 -2
- package/src/internal/effect.ts +67 -31
- package/src/internal/matcher.ts +1 -1
- package/src/internal/record.ts +11 -7
- package/src/internal/references.ts +0 -5
- package/src/internal/schema/annotations.ts +44 -0
- package/src/internal/schema/fromJsonSchemaDocument.ts +957 -0
- package/src/internal/schema/fromRepresentation.ts +345 -0
- package/src/internal/schema/schema.ts +45 -46
- package/src/internal/schema/{arbitrary.ts → toArbitrary.ts} +8 -10
- package/src/internal/schema/toCodeDocument.ts +572 -0
- package/src/internal/schema/{equivalence.ts → toEquivalence.ts} +12 -7
- package/src/internal/schema/toJsonSchemaDocument.ts +475 -0
- package/src/internal/schema/toRepresentation.ts +401 -0
- package/src/internal/stackTraceLimit.ts +3 -7
- package/src/testing/TestClock.ts +1 -1
- package/src/unstable/ai/AiError.ts +5 -4
- package/src/unstable/ai/AnthropicStructuredOutput.ts +102 -333
- package/src/unstable/ai/EmbeddingModel.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +30 -28
- package/src/unstable/ai/McpSchema.ts +15 -15
- package/src/unstable/ai/McpServer.ts +172 -56
- package/src/unstable/ai/OpenAiStructuredOutput.ts +230 -395
- package/src/unstable/ai/Response.ts +24 -24
- package/src/unstable/ai/Tool.ts +22 -4
- package/src/unstable/ai/Toolkit.ts +19 -7
- package/src/unstable/ai/internal/codec-transformer.ts +13 -7
- package/src/unstable/ai/internal/structured-output.ts +458 -0
- package/src/unstable/cli/CliError.ts +51 -5
- package/src/unstable/cli/Command.ts +4 -4
- package/src/unstable/cli/Param.ts +3 -3
- package/src/unstable/cli/Primitive.ts +1 -1
- package/src/unstable/cli/internal/command.ts +13 -5
- package/src/unstable/cli/internal/config.ts +8 -10
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +3 -3
- package/src/unstable/cluster/Entity.ts +1 -1
- package/src/unstable/cluster/Envelope.ts +2 -1
- package/src/unstable/cluster/Reply.ts +1 -1
- package/src/unstable/cluster/Runner.ts +1 -1
- package/src/unstable/cluster/RunnerAddress.ts +1 -1
- package/src/unstable/cluster/ShardId.ts +1 -1
- package/src/unstable/cluster/Sharding.ts +161 -34
- package/src/unstable/cluster/ShardingConfig.ts +5 -1
- package/src/unstable/cluster/SingleRunner.ts +4 -2
- package/src/unstable/cluster/SqlMessageStorage.ts +83 -35
- package/src/unstable/cluster/SqlRunnerStorage.ts +186 -116
- package/src/unstable/cluster/internal/entityManager.ts +31 -10
- package/src/unstable/cluster/internal/shardLock.ts +9 -0
- package/src/unstable/devtools/DevToolsSchema.ts +10 -5
- package/src/unstable/eventlog/EventJournal.ts +1 -1
- package/src/unstable/eventlog/EventLog.ts +21 -11
- package/src/unstable/eventlog/EventLogEncryption.ts +1 -1
- package/src/unstable/eventlog/EventLogMessage.ts +10 -3
- package/src/unstable/eventlog/SqlEventJournal.ts +2 -2
- package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +1 -1
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +6 -3
- package/src/unstable/http/Cookies.ts +29 -24
- package/src/unstable/http/Headers.ts +8 -8
- package/src/unstable/http/HttpClientRequest.ts +57 -0
- package/src/unstable/http/HttpServerRequest.ts +5 -4
- package/src/unstable/http/Multipart.ts +16 -13
- package/src/unstable/http/Template.ts +1 -1
- package/src/unstable/http/UrlParams.ts +17 -14
- package/src/unstable/httpapi/HttpApi.ts +3 -3
- package/src/unstable/httpapi/HttpApiClient.ts +5 -5
- package/src/unstable/httpapi/HttpApiGroup.ts +1 -1
- package/src/unstable/httpapi/OpenApi.ts +52 -28
- package/src/unstable/observability/OtlpExporter.ts +109 -5
- package/src/unstable/observability/OtlpLogger.ts +5 -5
- package/src/unstable/observability/OtlpMetrics.ts +8 -4
- package/src/unstable/observability/OtlpTracer.ts +8 -4
- package/src/unstable/persistence/Persistable.ts +3 -2
- package/src/unstable/persistence/RateLimiter.ts +2 -2
- package/src/unstable/persistence/Redis.ts +2 -2
- package/src/unstable/process/ChildProcessSpawner.ts +1 -1
- package/src/unstable/reactivity/AsyncResult.ts +4 -3
- package/src/unstable/reactivity/Atom.ts +92 -0
- package/src/unstable/reactivity/AtomRegistry.ts +1 -1
- package/src/unstable/rpc/RpcClient.ts +2 -1
- package/src/unstable/schema/VariantSchema.ts +14 -24
- package/src/unstable/socket/Socket.ts +1 -1
- package/src/unstable/sql/SqlError.ts +2 -2
- package/src/unstable/sql/Statement.ts +7 -6
- package/dist/SchemaUtils.d.ts +0 -28
- package/dist/SchemaUtils.d.ts.map +0 -1
- package/dist/SchemaUtils.js +0 -45
- package/dist/SchemaUtils.js.map +0 -1
- package/dist/internal/schema/arbitrary.d.ts.map +0 -1
- package/dist/internal/schema/arbitrary.js.map +0 -1
- package/dist/internal/schema/equivalence.d.ts +0 -2
- package/dist/internal/schema/equivalence.d.ts.map +0 -1
- package/dist/internal/schema/equivalence.js.map +0 -1
- package/dist/internal/schema/representation.d.ts +0 -2
- package/dist/internal/schema/representation.d.ts.map +0 -1
- package/dist/internal/schema/representation.js +0 -865
- package/dist/internal/schema/representation.js.map +0 -1
- package/src/SchemaUtils.ts +0 -51
- package/src/internal/schema/representation.ts +0 -795
|
@@ -4,21 +4,15 @@
|
|
|
4
4
|
* OpenAI structured output accepts only a subset of JSON Schema. This module
|
|
5
5
|
* converts an Effect `Schema.Codec` into a provider-compatible JSON Schema and
|
|
6
6
|
* a matching codec for decoding the model response back into the original
|
|
7
|
-
* application type.
|
|
8
|
-
*
|
|
9
|
-
* conversion.
|
|
7
|
+
* application type. Unsupported constraints can be omitted from the provider
|
|
8
|
+
* schema and remain enforced by the returned codec.
|
|
10
9
|
*
|
|
11
10
|
* @since 4.0.0
|
|
12
11
|
*/
|
|
13
|
-
import * as Arr from "../../Array.ts"
|
|
14
12
|
import * as JsonSchema from "../../JsonSchema.ts"
|
|
15
|
-
import * as Option from "../../Option.ts"
|
|
16
|
-
import * as Predicate from "../../Predicate.ts"
|
|
17
13
|
import * as Rec from "../../Record.ts"
|
|
18
14
|
import * as Schema from "../../Schema.ts"
|
|
19
|
-
import * as
|
|
20
|
-
import * as SchemaTransformation from "../../SchemaTransformation.ts"
|
|
21
|
-
import * as Tool from "./Tool.ts"
|
|
15
|
+
import * as InternalStructuredOutput from "./internal/structured-output.ts"
|
|
22
16
|
|
|
23
17
|
/**
|
|
24
18
|
* Converts a `Schema.Codec` to OpenAI structured-output JSON Schema and a
|
|
@@ -27,25 +21,36 @@ import * as Tool from "./Tool.ts"
|
|
|
27
21
|
* **When to use**
|
|
28
22
|
*
|
|
29
23
|
* Use when you send Effect Schema-backed structured output requests to OpenAI
|
|
30
|
-
* and need provider-compatible JSON Schema without losing the
|
|
31
|
-
* application type.
|
|
24
|
+
* standard models and need provider-compatible JSON Schema without losing the
|
|
25
|
+
* decoded application type.
|
|
32
26
|
*
|
|
33
27
|
* **Details**
|
|
34
28
|
*
|
|
35
29
|
* Returns the JSON Schema to include in the request and the codec to use when
|
|
36
|
-
* decoding the model response.
|
|
37
|
-
*
|
|
30
|
+
* decoding the model response. The codec remains authoritative: the provider
|
|
31
|
+
* JSON Schema can be a lossy, less restrictive representation when OpenAI
|
|
32
|
+
* cannot express an Effect Schema constraint. Conversion throws when the
|
|
33
|
+
* resulting root is not an object or contains `anyOf`.
|
|
38
34
|
*
|
|
39
35
|
* **Gotchas**
|
|
40
36
|
*
|
|
41
37
|
* - Some schemas use a provider-safe encoded shape: tuples become objects with
|
|
42
|
-
* numeric string keys,
|
|
43
|
-
* optional properties become required nullable
|
|
38
|
+
* numeric string keys, objects with index signatures become arrays of
|
|
39
|
+
* `[key, value]` pairs, and optional properties become required nullable
|
|
40
|
+
* properties.
|
|
44
41
|
* - `oneOf` unions are emitted as `anyOf` unions.
|
|
45
|
-
* -
|
|
46
|
-
*
|
|
47
|
-
* -
|
|
48
|
-
*
|
|
42
|
+
* - Compatible regex patterns are merged because OpenAI structured output does
|
|
43
|
+
* not support `allOf`.
|
|
44
|
+
* - The root JSON Schema must be an object and cannot use `anyOf`.
|
|
45
|
+
* - Constraints inside `allOf` are retained only when they have an explicit,
|
|
46
|
+
* semantics-preserving normalization rule.
|
|
47
|
+
* - Structural constraints inside `allOf`, such as `properties`, `required`,
|
|
48
|
+
* `additionalProperties`, and `items`, are omitted instead of being merged
|
|
49
|
+
* with a different meaning.
|
|
50
|
+
* - Unsupported constraints are removed from the provider schema and are still
|
|
51
|
+
* checked while decoding with the returned codec.
|
|
52
|
+
* - Compatibility targets standard OpenAI models. Fine-tuned models support a
|
|
53
|
+
* smaller JSON Schema subset.
|
|
49
54
|
*
|
|
50
55
|
* @category Codec Transformation
|
|
51
56
|
* @since 4.0.0
|
|
@@ -56,421 +61,251 @@ export function toCodecOpenAI<T, E, RD, RE>(
|
|
|
56
61
|
codec: Schema.ConstraintCodec<T, unknown, RD, RE>
|
|
57
62
|
jsonSchema: JsonSchema.JsonSchema
|
|
58
63
|
} {
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
: Schema.make<typeof schema>(SchemaAST.decodeTo(from, to, SchemaTransformation.passthrough()))
|
|
64
|
-
const document = JsonSchema.resolveTopLevel$ref(Schema.toJsonSchemaDocument(codec))
|
|
64
|
+
const codec = InternalStructuredOutput.toCodec(schema)
|
|
65
|
+
const document = JsonSchema.resolveTopLevel$ref(
|
|
66
|
+
Schema.toJsonSchemaDocument(codec, { generateDescriptions: true })
|
|
67
|
+
)
|
|
65
68
|
const jsonSchema = rewriteOpenAI(document.schema)
|
|
69
|
+
if (jsonSchema.type !== "object" || jsonSchema.anyOf !== undefined) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`OpenAiStructuredOutput: Root JSON Schema must have type "object" and must not use "anyOf"`
|
|
72
|
+
)
|
|
73
|
+
}
|
|
66
74
|
if (Object.keys(document.definitions).length > 0) {
|
|
67
75
|
jsonSchema.$defs = Rec.map(document.definitions, rewriteOpenAI)
|
|
68
76
|
}
|
|
69
77
|
return { codec, jsonSchema }
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
/**
|
|
73
|
-
* Post-processes the JSON schema produced by `Schema.toJsonSchemaDocument`,
|
|
74
|
-
* recursively flattening `allOf` arrays by merging each member's keys into
|
|
75
|
-
* the parent object. This is necessary because OpenAI structured output does
|
|
76
|
-
* not support `allOf`.
|
|
77
|
-
*/
|
|
78
80
|
function rewriteOpenAI(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
return InternalStructuredOutput.walkJsonSchema(schema, (schema) => {
|
|
82
|
+
const normalized = normalizeAllOf(schema)
|
|
83
|
+
const out: JsonSchema.JsonSchema = {}
|
|
84
|
+
let unsupportedFormat: string | undefined
|
|
85
|
+
for (const [key, value] of Object.entries(normalized)) {
|
|
86
|
+
if (key === "format") {
|
|
87
|
+
if (typeof value === "string" && formats.has(value) && supportsType(key, normalized.type)) out.format = value
|
|
88
|
+
else if (typeof value === "string") unsupportedFormat = value
|
|
89
|
+
} else if (supportedKeywords.has(key) && supportsType(key, normalized.type)) {
|
|
90
|
+
if (key !== "additionalProperties" || value === false) out[key] = value
|
|
84
91
|
}
|
|
85
|
-
} else if (Array.isArray(v)) {
|
|
86
|
-
out[k] = v.map((item) =>
|
|
87
|
-
typeof item === "object" && item !== null && !Array.isArray(item)
|
|
88
|
-
? rewriteOpenAI(item as JsonSchema.JsonSchema)
|
|
89
|
-
: item
|
|
90
|
-
)
|
|
91
|
-
} else if (typeof v === "object" && v !== null) {
|
|
92
|
-
out[k] = rewriteOpenAI(v as JsonSchema.JsonSchema)
|
|
93
|
-
} else {
|
|
94
|
-
out[k] = v
|
|
95
92
|
}
|
|
93
|
+
if (unsupportedFormat !== undefined) {
|
|
94
|
+
InternalStructuredOutput.appendDescription(out, `a value with a format of ${unsupportedFormat}`)
|
|
95
|
+
}
|
|
96
|
+
if (out.type === "object" && out.properties === undefined && out.additionalProperties === false) {
|
|
97
|
+
out.properties = {}
|
|
98
|
+
}
|
|
99
|
+
return out
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function supportsType(key: string, type: unknown): boolean {
|
|
104
|
+
if (typeof type !== "string") return true
|
|
105
|
+
switch (key) {
|
|
106
|
+
case "pattern":
|
|
107
|
+
case "format":
|
|
108
|
+
return type === "string"
|
|
109
|
+
case "multipleOf":
|
|
110
|
+
case "minimum":
|
|
111
|
+
case "exclusiveMinimum":
|
|
112
|
+
case "maximum":
|
|
113
|
+
case "exclusiveMaximum":
|
|
114
|
+
return type === "number" || type === "integer"
|
|
115
|
+
case "items":
|
|
116
|
+
case "minItems":
|
|
117
|
+
case "maxItems":
|
|
118
|
+
return type === "array"
|
|
119
|
+
case "properties":
|
|
120
|
+
case "patternProperties":
|
|
121
|
+
case "required":
|
|
122
|
+
case "additionalProperties":
|
|
123
|
+
return type === "object"
|
|
124
|
+
default:
|
|
125
|
+
return true
|
|
96
126
|
}
|
|
97
|
-
|
|
98
|
-
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function normalizeAllOf(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
|
|
130
|
+
if (!Array.isArray(schema.allOf)) return schema
|
|
131
|
+
|
|
132
|
+
const out: JsonSchema.JsonSchema = {}
|
|
133
|
+
const patterns: Array<string> = []
|
|
134
|
+
const baseKeywords = new Set<string>()
|
|
135
|
+
const memberKeywords = new Set<string>()
|
|
136
|
+
const ambiguousKeywords = new Set<string>()
|
|
137
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
138
|
+
if (key === "allOf") continue
|
|
139
|
+
baseKeywords.add(key)
|
|
140
|
+
if (key === "pattern" && typeof value === "string") patterns.push(value)
|
|
141
|
+
else out[key] = value
|
|
142
|
+
}
|
|
143
|
+
for (const member of schema.allOf) {
|
|
144
|
+
if (!InternalStructuredOutput.isJsonSchema(member)) continue
|
|
145
|
+
for (const [key, value] of Object.entries(member)) {
|
|
146
|
+
mergeAllOfKeyword(out, key, value, patterns, baseKeywords, memberKeywords, ambiguousKeywords)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const uniquePatterns = Array.from(new Set(patterns))
|
|
150
|
+
if (uniquePatterns.length === 1) {
|
|
151
|
+
out.pattern = uniquePatterns[0]
|
|
152
|
+
} else if (uniquePatterns.length > 1) {
|
|
153
|
+
const combined = uniquePatterns.map((source) => `(?=[\\s\\S]*?(?:${source}))`).join("")
|
|
154
|
+
out.pattern = `^${combined}`
|
|
99
155
|
}
|
|
100
156
|
return out
|
|
101
157
|
}
|
|
102
158
|
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
case "
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
case "
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return
|
|
127
|
-
case "
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return ast
|
|
143
|
-
case "Literal": {
|
|
144
|
-
const literal = ast.literal
|
|
145
|
-
if (typeof literal === "string" || typeof literal === "number" || typeof literal === "boolean") {
|
|
146
|
-
const { annotations, filters } = get(ast)
|
|
147
|
-
if (annotations !== undefined || filters !== undefined) {
|
|
148
|
-
return new SchemaAST.Literal(ast.literal, annotations, filters)
|
|
149
|
-
}
|
|
150
|
-
return ast
|
|
151
|
-
}
|
|
152
|
-
throw new Error(
|
|
153
|
-
`${errorPrefix}: Unsupported literal type ${typeof literal} (value: ${
|
|
154
|
-
String(literal)
|
|
155
|
-
}) (supported: string | number | boolean)`
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
case "Union": {
|
|
159
|
-
if (ast.mode === "oneOf") {
|
|
160
|
-
return new SchemaAST.Union(ast.types, "anyOf", ast.annotations, ast.checks)
|
|
159
|
+
function mergeAllOfKeyword(
|
|
160
|
+
out: JsonSchema.JsonSchema,
|
|
161
|
+
key: string,
|
|
162
|
+
value: unknown,
|
|
163
|
+
patterns: Array<string>,
|
|
164
|
+
baseKeywords: ReadonlySet<string>,
|
|
165
|
+
memberKeywords: Set<string>,
|
|
166
|
+
ambiguousKeywords: Set<string>
|
|
167
|
+
): void {
|
|
168
|
+
switch (key) {
|
|
169
|
+
case "description":
|
|
170
|
+
if (typeof value === "string") InternalStructuredOutput.appendDescription(out, value)
|
|
171
|
+
return
|
|
172
|
+
case "pattern":
|
|
173
|
+
if (typeof value === "string") patterns.push(value)
|
|
174
|
+
return
|
|
175
|
+
case "minimum":
|
|
176
|
+
case "exclusiveMinimum":
|
|
177
|
+
mergeLowerBound(out, key, value)
|
|
178
|
+
return
|
|
179
|
+
case "maximum":
|
|
180
|
+
case "exclusiveMaximum":
|
|
181
|
+
mergeUpperBound(out, key, value)
|
|
182
|
+
return
|
|
183
|
+
case "minItems":
|
|
184
|
+
mergeMinimum(out, key, value)
|
|
185
|
+
return
|
|
186
|
+
case "maxItems":
|
|
187
|
+
mergeMaximum(out, key, value)
|
|
188
|
+
return
|
|
189
|
+
default:
|
|
190
|
+
if (!normalizableAllOfKeywords.has(key) || baseKeywords.has(key) || ambiguousKeywords.has(key)) return
|
|
191
|
+
if (!memberKeywords.has(key)) {
|
|
192
|
+
out[key] = value
|
|
193
|
+
memberKeywords.add(key)
|
|
194
|
+
} else if (out[key] !== value) {
|
|
195
|
+
delete out[key]
|
|
196
|
+
memberKeywords.delete(key)
|
|
197
|
+
ambiguousKeywords.add(key)
|
|
161
198
|
}
|
|
162
|
-
|
|
163
|
-
const { annotations, filters } = get(ast)
|
|
164
|
-
if (types !== ast.types || annotations !== undefined || filters !== undefined) {
|
|
165
|
-
return new SchemaAST.Union(types, "anyOf", annotations, filters)
|
|
166
|
-
}
|
|
167
|
-
return ast
|
|
168
|
-
}
|
|
169
|
-
case "Arrays": {
|
|
170
|
-
if (ast.rest.length > 1) {
|
|
171
|
-
throw new Error(
|
|
172
|
-
`${errorPrefix}: Post-rest elements are not supported for arrays (rest length: ${ast.rest.length})`
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
let { annotations, filters } = get(ast)
|
|
176
|
-
if (ast.elements.length > 0) {
|
|
177
|
-
// tuples are not supported by OpenAI, we translate them to objects with string keys
|
|
178
|
-
if (annotations !== undefined && typeof annotations.description === "string") {
|
|
179
|
-
annotations.description = `${TUPLE_DESCRIPTION}; ${annotations.description}`
|
|
180
|
-
} else {
|
|
181
|
-
annotations ??= {}
|
|
182
|
-
annotations.description = TUPLE_DESCRIPTION
|
|
183
|
-
}
|
|
184
|
-
const propertySignatures = ast.elements.map((e, i) => {
|
|
185
|
-
return new SchemaAST.PropertySignature(String(i), e)
|
|
186
|
-
})
|
|
187
|
-
if (ast.rest.length === 1) {
|
|
188
|
-
propertySignatures.push(
|
|
189
|
-
new SchemaAST.PropertySignature(REST_PROPERTY_NAME, new SchemaAST.Arrays(false, [], ast.rest))
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
return SchemaAST.decodeTo(
|
|
193
|
-
recurOpenAI(new SchemaAST.Objects(propertySignatures, [], annotations, filters)),
|
|
194
|
-
ast,
|
|
195
|
-
SchemaTransformation.transform({
|
|
196
|
-
decode: (o) => {
|
|
197
|
-
let t: Array<unknown> = []
|
|
198
|
-
for (let i = 0; i < ast.elements.length; i++) {
|
|
199
|
-
const k = String(i)
|
|
200
|
-
if (o[k] !== undefined) {
|
|
201
|
-
t.push(o[k])
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (REST_PROPERTY_NAME in o) {
|
|
205
|
-
t = [...t, ...o[REST_PROPERTY_NAME]]
|
|
206
|
-
}
|
|
207
|
-
return t
|
|
208
|
-
},
|
|
209
|
-
encode: (t) => {
|
|
210
|
-
const o: Record<string, unknown> = {}
|
|
211
|
-
for (let i = 0; i < ast.elements.length; i++) {
|
|
212
|
-
if (t.length >= i) {
|
|
213
|
-
o[String(i)] = t[i]
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (ast.rest.length === 1) {
|
|
217
|
-
o[REST_PROPERTY_NAME] = t.length >= ast.elements.length ? t.slice(ast.elements.length) : []
|
|
218
|
-
}
|
|
219
|
-
return o
|
|
220
|
-
}
|
|
221
|
-
})
|
|
222
|
-
)
|
|
223
|
-
} else {
|
|
224
|
-
const rest = SchemaAST.mapOrSame(ast.rest, recurOpenAI)
|
|
225
|
-
if (rest !== ast.rest || annotations !== undefined || filters !== undefined) {
|
|
226
|
-
return new SchemaAST.Arrays(false, [], rest, annotations, filters)
|
|
227
|
-
}
|
|
228
|
-
return ast
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
case "Objects": {
|
|
232
|
-
let { annotations, filters } = get(ast)
|
|
233
|
-
if (ast.indexSignatures.length === 0) {
|
|
234
|
-
const propertySignatures = SchemaAST.mapOrSame(ast.propertySignatures, (ps) => {
|
|
235
|
-
if (typeof ps.name !== "string") {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`${errorPrefix}: Property names must be strings (got ${typeof ps.name})`
|
|
238
|
-
)
|
|
239
|
-
}
|
|
240
|
-
let type = recurOpenAI(ps.type)
|
|
241
|
-
// optional properties are not supported by OpenAI, so we translate them to nullable unions
|
|
242
|
-
if (SchemaAST.isOptional(ps.type)) {
|
|
243
|
-
type = SchemaAST.decodeTo(
|
|
244
|
-
new SchemaAST.Union([type, SchemaAST.null], "anyOf"),
|
|
245
|
-
SchemaAST.optionalKey(type),
|
|
246
|
-
SchemaTransformation.transformOptional({
|
|
247
|
-
decode: Option.filter(Predicate.isNotNull),
|
|
248
|
-
encode: Option.orElseSome(() => null)
|
|
249
|
-
})
|
|
250
|
-
)
|
|
251
|
-
}
|
|
252
|
-
if (type === ps.type) {
|
|
253
|
-
return ps
|
|
254
|
-
}
|
|
255
|
-
return new SchemaAST.PropertySignature(ps.name, type)
|
|
256
|
-
})
|
|
257
|
-
if (
|
|
258
|
-
propertySignatures !== ast.propertySignatures || annotations !== undefined || filters !== undefined
|
|
259
|
-
) {
|
|
260
|
-
return new SchemaAST.Objects(propertySignatures, [], annotations, filters)
|
|
261
|
-
}
|
|
262
|
-
} else if (ast.indexSignatures.length === 1 && ast.propertySignatures.length === 0) {
|
|
263
|
-
const is = ast.indexSignatures[0]
|
|
264
|
-
if (Tool.isEmptyParamsRecord(is)) {
|
|
265
|
-
return ast
|
|
266
|
-
}
|
|
267
|
-
// records are not supported by OpenAI, so we translate them to arrays of key-value pairs
|
|
268
|
-
if (annotations !== undefined && typeof annotations.description === "string") {
|
|
269
|
-
annotations.description = `${RECORD_DESCRIPTION}; ${annotations.description}`
|
|
270
|
-
} else {
|
|
271
|
-
annotations ??= {}
|
|
272
|
-
annotations.description = RECORD_DESCRIPTION
|
|
273
|
-
}
|
|
274
|
-
return SchemaAST.decodeTo(
|
|
275
|
-
recurOpenAI(
|
|
276
|
-
new SchemaAST.Arrays(false, [], [new SchemaAST.Arrays(false, [is.parameter, is.type], [])], annotations)
|
|
277
|
-
),
|
|
278
|
-
ast,
|
|
279
|
-
SchemaTransformation.transform({
|
|
280
|
-
decode: Object.fromEntries,
|
|
281
|
-
encode: Object.entries
|
|
282
|
-
})
|
|
283
|
-
)
|
|
284
|
-
} else {
|
|
285
|
-
throw new Error(
|
|
286
|
-
`${errorPrefix}: unsupported object schema shape (properties: ${ast.propertySignatures.length}, indexSignatures: ${ast.indexSignatures.length}). Supported: plain objects (properties only) or records (single index signature, no properties)`
|
|
287
|
-
)
|
|
288
|
-
}
|
|
289
|
-
return ast
|
|
290
|
-
}
|
|
291
|
-
case "Suspend": {
|
|
292
|
-
const cached = cache.get(ast)
|
|
293
|
-
if (cached) return cached
|
|
294
|
-
const { annotations } = get(ast)
|
|
295
|
-
const out = new SchemaAST.Suspend(() => recurOpenAI(ast.thunk()), annotations)
|
|
296
|
-
cache.set(ast, out)
|
|
297
|
-
return out
|
|
298
|
-
}
|
|
199
|
+
return
|
|
299
200
|
}
|
|
300
201
|
}
|
|
301
202
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
function unsupportedAst(ast: SchemaAST.AST, details?: string): never {
|
|
307
|
-
const base = `Unsupported AST ${ast._tag}`
|
|
308
|
-
const full = `${errorPrefix}: ${base}`
|
|
309
|
-
throw new Error(details !== undefined ? `${full} (${details})` : full)
|
|
203
|
+
function mergeMinimum(schema: JsonSchema.JsonSchema, key: string, value: unknown): void {
|
|
204
|
+
if (typeof value !== "number") return
|
|
205
|
+
const current = schema[key]
|
|
206
|
+
if (typeof current !== "number" || value > current) schema[key] = value
|
|
310
207
|
}
|
|
311
208
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const TUPLE_DESCRIPTION =
|
|
318
|
-
"Tuple encoded as an object with numeric string keys ('0', '1', ...). If present, '__rest__' contains remaining elements"
|
|
319
|
-
|
|
320
|
-
type Annotation =
|
|
321
|
-
| { readonly _tag: "description"; readonly description: string }
|
|
322
|
-
| { readonly _tag: "format"; readonly format: string }
|
|
323
|
-
|
|
324
|
-
type Filter =
|
|
325
|
-
| Annotation
|
|
326
|
-
| { readonly _tag: "filter"; readonly filter: SchemaAST.Filter<any> }
|
|
327
|
-
| { readonly _tag: "regex"; readonly source: string }
|
|
209
|
+
function mergeMaximum(schema: JsonSchema.JsonSchema, key: string, value: unknown): void {
|
|
210
|
+
if (typeof value !== "number") return
|
|
211
|
+
const current = schema[key]
|
|
212
|
+
if (typeof current !== "number" || value < current) schema[key] = value
|
|
213
|
+
}
|
|
328
214
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const annotations: Record<string, string> = {}
|
|
334
|
-
const filters: Array<SchemaAST.Filter<any>> = []
|
|
335
|
-
const regexSources: Array<string> = []
|
|
336
|
-
const checks = getChecks(ast, SchemaAST.isArrays(ast))
|
|
337
|
-
if (checks.length > 0) {
|
|
338
|
-
for (const check of checks) {
|
|
339
|
-
switch (check._tag) {
|
|
340
|
-
case "description": {
|
|
341
|
-
if (annotations.description !== undefined) {
|
|
342
|
-
annotations.description += ` and ${check.description}`
|
|
343
|
-
} else {
|
|
344
|
-
annotations.description = check.description
|
|
345
|
-
}
|
|
346
|
-
break
|
|
347
|
-
}
|
|
348
|
-
case "format": {
|
|
349
|
-
annotations.format = check.format
|
|
350
|
-
break
|
|
351
|
-
}
|
|
352
|
-
case "filter": {
|
|
353
|
-
filters.push(check.filter)
|
|
354
|
-
break
|
|
355
|
-
}
|
|
356
|
-
case "regex": {
|
|
357
|
-
regexSources.push(check.source)
|
|
358
|
-
break
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
215
|
+
function mergeLowerBound(schema: JsonSchema.JsonSchema, key: string, value: unknown): void {
|
|
216
|
+
if (typeof value !== "number") {
|
|
217
|
+
if (!Object.hasOwn(schema, key)) schema[key] = value
|
|
218
|
+
return
|
|
362
219
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
220
|
+
const minimum = typeof schema.minimum === "number" ? schema.minimum : undefined
|
|
221
|
+
const exclusiveMinimum = typeof schema.exclusiveMinimum === "number" ? schema.exclusiveMinimum : undefined
|
|
222
|
+
let current: { readonly value: number; readonly exclusive: boolean } | undefined
|
|
223
|
+
if (minimum !== undefined) current = { value: minimum, exclusive: false }
|
|
224
|
+
if (
|
|
225
|
+
exclusiveMinimum !== undefined &&
|
|
226
|
+
(current === undefined || exclusiveMinimum >= current.value)
|
|
227
|
+
) {
|
|
228
|
+
current = { value: exclusiveMinimum, exclusive: true }
|
|
369
229
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
230
|
+
const candidate = { value, exclusive: key === "exclusiveMinimum" }
|
|
231
|
+
if (
|
|
232
|
+
current === undefined ||
|
|
233
|
+
candidate.value > current.value ||
|
|
234
|
+
(candidate.value === current.value && candidate.exclusive)
|
|
235
|
+
) {
|
|
236
|
+
current = candidate
|
|
373
237
|
}
|
|
238
|
+
delete schema.minimum
|
|
239
|
+
delete schema.exclusiveMinimum
|
|
240
|
+
schema[current.exclusive ? "exclusiveMinimum" : "minimum"] = current.value
|
|
374
241
|
}
|
|
375
242
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const getAnnotations = (annotations: Schema.Annotations.Filter | undefined): Array<Annotation> => {
|
|
382
|
-
const out: Array<Annotation> = []
|
|
383
|
-
if (annotations !== undefined) {
|
|
384
|
-
const description = annotations?.description
|
|
385
|
-
?? (annotations.meta?._tag === "isInt" || annotations.meta?._tag === "isFinite"
|
|
386
|
-
? undefined
|
|
387
|
-
: annotations?.expected)
|
|
388
|
-
if (typeof description === "string") {
|
|
389
|
-
out.push({ _tag: "description", description })
|
|
390
|
-
}
|
|
391
|
-
const format = annotations?.format
|
|
392
|
-
if (typeof format === "string") {
|
|
393
|
-
if (formats.includes(format)) {
|
|
394
|
-
out.push({ _tag: "format", format })
|
|
395
|
-
} else {
|
|
396
|
-
out.push({ _tag: "description", description: `a value with a format of ${format}` })
|
|
397
|
-
}
|
|
398
|
-
}
|
|
243
|
+
function mergeUpperBound(schema: JsonSchema.JsonSchema, key: string, value: unknown): void {
|
|
244
|
+
if (typeof value !== "number") {
|
|
245
|
+
if (!Object.hasOwn(schema, key)) schema[key] = value
|
|
246
|
+
return
|
|
399
247
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
case "isMinLength":
|
|
410
|
-
case "isMaxLength":
|
|
411
|
-
case "isLengthBetween": {
|
|
412
|
-
out = out.concat(annotations)
|
|
413
|
-
if (isArray) {
|
|
414
|
-
out.push({ _tag: "filter", filter: resetFilter(filter) })
|
|
415
|
-
}
|
|
416
|
-
break
|
|
417
|
-
}
|
|
418
|
-
case "isInt":
|
|
419
|
-
case "isFinite":
|
|
420
|
-
case "isGreaterThan":
|
|
421
|
-
case "isGreaterThanOrEqualTo":
|
|
422
|
-
case "isLessThan":
|
|
423
|
-
case "isLessThanOrEqualTo":
|
|
424
|
-
case "isBetween":
|
|
425
|
-
case "isMultipleOf": {
|
|
426
|
-
out = out.concat(annotations)
|
|
427
|
-
out.push({ _tag: "filter", filter: resetFilter(filter) })
|
|
428
|
-
break
|
|
429
|
-
}
|
|
430
|
-
default: {
|
|
431
|
-
out = out.concat(annotations)
|
|
432
|
-
break
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
if ("regExp" in meta && meta.regExp instanceof RegExp) {
|
|
436
|
-
out.push({ _tag: "regex", source: meta.regExp.source })
|
|
437
|
-
}
|
|
248
|
+
const maximum = typeof schema.maximum === "number" ? schema.maximum : undefined
|
|
249
|
+
const exclusiveMaximum = typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum : undefined
|
|
250
|
+
let current: { readonly value: number; readonly exclusive: boolean } | undefined
|
|
251
|
+
if (maximum !== undefined) current = { value: maximum, exclusive: false }
|
|
252
|
+
if (
|
|
253
|
+
exclusiveMaximum !== undefined &&
|
|
254
|
+
(current === undefined || exclusiveMaximum <= current.value)
|
|
255
|
+
) {
|
|
256
|
+
current = { value: exclusiveMaximum, exclusive: true }
|
|
438
257
|
}
|
|
439
|
-
|
|
258
|
+
const candidate = { value, exclusive: key === "exclusiveMaximum" }
|
|
259
|
+
if (
|
|
260
|
+
current === undefined ||
|
|
261
|
+
candidate.value < current.value ||
|
|
262
|
+
(candidate.value === current.value && candidate.exclusive)
|
|
263
|
+
) {
|
|
264
|
+
current = candidate
|
|
265
|
+
}
|
|
266
|
+
delete schema.maximum
|
|
267
|
+
delete schema.exclusiveMaximum
|
|
268
|
+
schema[current.exclusive ? "exclusiveMaximum" : "maximum"] = current.value
|
|
440
269
|
}
|
|
441
270
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
271
|
+
const supportedKeywords = new Set([
|
|
272
|
+
"$ref",
|
|
273
|
+
"type",
|
|
274
|
+
"title",
|
|
275
|
+
"description",
|
|
276
|
+
"enum",
|
|
277
|
+
"anyOf",
|
|
278
|
+
"properties",
|
|
279
|
+
"required",
|
|
280
|
+
"additionalProperties",
|
|
281
|
+
"items",
|
|
282
|
+
"pattern",
|
|
283
|
+
"multipleOf",
|
|
284
|
+
"minimum",
|
|
285
|
+
"exclusiveMinimum",
|
|
286
|
+
"maximum",
|
|
287
|
+
"exclusiveMaximum",
|
|
288
|
+
"minItems",
|
|
289
|
+
"maxItems"
|
|
290
|
+
])
|
|
450
291
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
case "FilterGroup":
|
|
460
|
-
return getFilters(check.checks, isArray)
|
|
461
|
-
}
|
|
462
|
-
})
|
|
463
|
-
}
|
|
292
|
+
const normalizableAllOfKeywords = new Set([
|
|
293
|
+
"$ref",
|
|
294
|
+
"title",
|
|
295
|
+
"enum",
|
|
296
|
+
"anyOf",
|
|
297
|
+
"format",
|
|
298
|
+
"multipleOf"
|
|
299
|
+
])
|
|
464
300
|
|
|
465
|
-
const formats = [
|
|
301
|
+
const formats = new Set([
|
|
466
302
|
"date-time",
|
|
467
303
|
"time",
|
|
468
304
|
"date",
|
|
469
305
|
"duration",
|
|
470
306
|
"email",
|
|
471
307
|
"hostname",
|
|
472
|
-
"uri",
|
|
473
308
|
"ipv4",
|
|
474
309
|
"ipv6",
|
|
475
310
|
"uuid"
|
|
476
|
-
]
|
|
311
|
+
])
|