effect 4.0.0-beta.100 → 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/MutableList.d.ts.map +1 -1
- package/dist/MutableList.js +4 -0
- package/dist/MutableList.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 +1269 -496
- 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 +3 -2
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/effect.js +119 -53
- 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 +26 -26
- 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/HttpRouter.d.ts +2 -2
- package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
- package/dist/unstable/http/HttpRouter.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/MutableList.ts +4 -0
- 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 +2538 -987
- 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 +4 -3
- package/src/internal/effect.ts +132 -70
- 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/HttpRouter.ts +6 -3
- 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.js";
|
|
14
12
|
import * as JsonSchema from "../../JsonSchema.js";
|
|
15
|
-
import * as Option from "../../Option.js";
|
|
16
|
-
import * as Predicate from "../../Predicate.js";
|
|
17
13
|
import * as Rec from "../../Record.js";
|
|
18
14
|
import * as Schema from "../../Schema.js";
|
|
19
|
-
import * as
|
|
20
|
-
import * as SchemaTransformation from "../../SchemaTransformation.js";
|
|
21
|
-
import * as Tool from "./Tool.js";
|
|
15
|
+
import * as InternalStructuredOutput from "./internal/structured-output.js";
|
|
22
16
|
/**
|
|
23
17
|
* Converts a `Schema.Codec` to OpenAI structured-output JSON Schema and a
|
|
24
18
|
* matching codec for model output.
|
|
@@ -26,35 +20,49 @@ import * as Tool from "./Tool.js";
|
|
|
26
20
|
* **When to use**
|
|
27
21
|
*
|
|
28
22
|
* Use when you send Effect Schema-backed structured output requests to OpenAI
|
|
29
|
-
* and need provider-compatible JSON Schema without losing the
|
|
30
|
-
* application type.
|
|
23
|
+
* standard models and need provider-compatible JSON Schema without losing the
|
|
24
|
+
* decoded application type.
|
|
31
25
|
*
|
|
32
26
|
* **Details**
|
|
33
27
|
*
|
|
34
28
|
* Returns the JSON Schema to include in the request and the codec to use when
|
|
35
|
-
* decoding the model response.
|
|
36
|
-
*
|
|
29
|
+
* decoding the model response. The codec remains authoritative: the provider
|
|
30
|
+
* JSON Schema can be a lossy, less restrictive representation when OpenAI
|
|
31
|
+
* cannot express an Effect Schema constraint. Conversion throws when the
|
|
32
|
+
* resulting root is not an object or contains `anyOf`.
|
|
37
33
|
*
|
|
38
34
|
* **Gotchas**
|
|
39
35
|
*
|
|
40
36
|
* - Some schemas use a provider-safe encoded shape: tuples become objects with
|
|
41
|
-
* numeric string keys,
|
|
42
|
-
* optional properties become required nullable
|
|
37
|
+
* numeric string keys, objects with index signatures become arrays of
|
|
38
|
+
* `[key, value]` pairs, and optional properties become required nullable
|
|
39
|
+
* properties.
|
|
43
40
|
* - `oneOf` unions are emitted as `anyOf` unions.
|
|
44
|
-
* -
|
|
45
|
-
*
|
|
46
|
-
* -
|
|
47
|
-
*
|
|
41
|
+
* - Compatible regex patterns are merged because OpenAI structured output does
|
|
42
|
+
* not support `allOf`.
|
|
43
|
+
* - The root JSON Schema must be an object and cannot use `anyOf`.
|
|
44
|
+
* - Constraints inside `allOf` are retained only when they have an explicit,
|
|
45
|
+
* semantics-preserving normalization rule.
|
|
46
|
+
* - Structural constraints inside `allOf`, such as `properties`, `required`,
|
|
47
|
+
* `additionalProperties`, and `items`, are omitted instead of being merged
|
|
48
|
+
* with a different meaning.
|
|
49
|
+
* - Unsupported constraints are removed from the provider schema and are still
|
|
50
|
+
* checked while decoding with the returned codec.
|
|
51
|
+
* - Compatibility targets standard OpenAI models. Fine-tuned models support a
|
|
52
|
+
* smaller JSON Schema subset.
|
|
48
53
|
*
|
|
49
54
|
* @category Codec Transformation
|
|
50
55
|
* @since 4.0.0
|
|
51
56
|
*/
|
|
52
57
|
export function toCodecOpenAI(schema) {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
const codec = InternalStructuredOutput.toCodec(schema);
|
|
59
|
+
const document = JsonSchema.resolveTopLevel$ref(Schema.toJsonSchemaDocument(codec, {
|
|
60
|
+
generateDescriptions: true
|
|
61
|
+
}));
|
|
57
62
|
const jsonSchema = rewriteOpenAI(document.schema);
|
|
63
|
+
if (jsonSchema.type !== "object" || jsonSchema.anyOf !== undefined) {
|
|
64
|
+
throw new Error(`OpenAiStructuredOutput: Root JSON Schema must have type "object" and must not use "anyOf"`);
|
|
65
|
+
}
|
|
58
66
|
if (Object.keys(document.definitions).length > 0) {
|
|
59
67
|
jsonSchema.$defs = Rec.map(document.definitions, rewriteOpenAI);
|
|
60
68
|
}
|
|
@@ -63,375 +71,183 @@ export function toCodecOpenAI(schema) {
|
|
|
63
71
|
jsonSchema
|
|
64
72
|
};
|
|
65
73
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Post-processes the JSON schema produced by `Schema.toJsonSchemaDocument`,
|
|
68
|
-
* recursively flattening `allOf` arrays by merging each member's keys into
|
|
69
|
-
* the parent object. This is necessary because OpenAI structured output does
|
|
70
|
-
* not support `allOf`.
|
|
71
|
-
*/
|
|
72
74
|
function rewriteOpenAI(schema) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
return InternalStructuredOutput.walkJsonSchema(schema, schema => {
|
|
76
|
+
const normalized = normalizeAllOf(schema);
|
|
77
|
+
const out = {};
|
|
78
|
+
let unsupportedFormat;
|
|
79
|
+
for (const [key, value] of Object.entries(normalized)) {
|
|
80
|
+
if (key === "format") {
|
|
81
|
+
if (typeof value === "string" && formats.has(value) && supportsType(key, normalized.type)) out.format = value;else if (typeof value === "string") unsupportedFormat = value;
|
|
82
|
+
} else if (supportedKeywords.has(key) && supportsType(key, normalized.type)) {
|
|
83
|
+
if (key !== "additionalProperties" || value === false) out[key] = value;
|
|
78
84
|
}
|
|
79
|
-
} else if (Array.isArray(v)) {
|
|
80
|
-
out[k] = v.map(item => typeof item === "object" && item !== null && !Array.isArray(item) ? rewriteOpenAI(item) : item);
|
|
81
|
-
} else if (typeof v === "object" && v !== null) {
|
|
82
|
-
out[k] = rewriteOpenAI(v);
|
|
83
|
-
} else {
|
|
84
|
-
out[k] = v;
|
|
85
85
|
}
|
|
86
|
+
if (unsupportedFormat !== undefined) {
|
|
87
|
+
InternalStructuredOutput.appendDescription(out, `a value with a format of ${unsupportedFormat}`);
|
|
88
|
+
}
|
|
89
|
+
if (out.type === "object" && out.properties === undefined && out.additionalProperties === false) {
|
|
90
|
+
out.properties = {};
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function supportsType(key, type) {
|
|
96
|
+
if (typeof type !== "string") return true;
|
|
97
|
+
switch (key) {
|
|
98
|
+
case "pattern":
|
|
99
|
+
case "format":
|
|
100
|
+
return type === "string";
|
|
101
|
+
case "multipleOf":
|
|
102
|
+
case "minimum":
|
|
103
|
+
case "exclusiveMinimum":
|
|
104
|
+
case "maximum":
|
|
105
|
+
case "exclusiveMaximum":
|
|
106
|
+
return type === "number" || type === "integer";
|
|
107
|
+
case "items":
|
|
108
|
+
case "minItems":
|
|
109
|
+
case "maxItems":
|
|
110
|
+
return type === "array";
|
|
111
|
+
case "properties":
|
|
112
|
+
case "patternProperties":
|
|
113
|
+
case "required":
|
|
114
|
+
case "additionalProperties":
|
|
115
|
+
return type === "object";
|
|
116
|
+
default:
|
|
117
|
+
return true;
|
|
86
118
|
}
|
|
87
|
-
|
|
88
|
-
|
|
119
|
+
}
|
|
120
|
+
function normalizeAllOf(schema) {
|
|
121
|
+
if (!Array.isArray(schema.allOf)) return schema;
|
|
122
|
+
const out = {};
|
|
123
|
+
const patterns = [];
|
|
124
|
+
const baseKeywords = new Set();
|
|
125
|
+
const memberKeywords = new Set();
|
|
126
|
+
const ambiguousKeywords = new Set();
|
|
127
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
128
|
+
if (key === "allOf") continue;
|
|
129
|
+
baseKeywords.add(key);
|
|
130
|
+
if (key === "pattern" && typeof value === "string") patterns.push(value);else out[key] = value;
|
|
131
|
+
}
|
|
132
|
+
for (const member of schema.allOf) {
|
|
133
|
+
if (!InternalStructuredOutput.isJsonSchema(member)) continue;
|
|
134
|
+
for (const [key, value] of Object.entries(member)) {
|
|
135
|
+
mergeAllOfKeyword(out, key, value, patterns, baseKeywords, memberKeywords, ambiguousKeywords);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const uniquePatterns = Array.from(new Set(patterns));
|
|
139
|
+
if (uniquePatterns.length === 1) {
|
|
140
|
+
out.pattern = uniquePatterns[0];
|
|
141
|
+
} else if (uniquePatterns.length > 1) {
|
|
142
|
+
const combined = uniquePatterns.map(source => `(?=[\\s\\S]*?(?:${source}))`).join("");
|
|
143
|
+
out.pattern = `^${combined}`;
|
|
89
144
|
}
|
|
90
145
|
return out;
|
|
91
146
|
}
|
|
92
|
-
function
|
|
93
|
-
switch (
|
|
94
|
-
case "
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
case "
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
case "
|
|
101
|
-
case "
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
case "
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
case "
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const {
|
|
124
|
-
annotations,
|
|
125
|
-
filters
|
|
126
|
-
} = get(ast);
|
|
127
|
-
if (annotations !== undefined || filters !== undefined) {
|
|
128
|
-
return new SchemaAST.Number(annotations, filters);
|
|
129
|
-
}
|
|
130
|
-
return ast;
|
|
131
|
-
}
|
|
132
|
-
case "Boolean":
|
|
133
|
-
return ast;
|
|
134
|
-
case "Literal":
|
|
135
|
-
{
|
|
136
|
-
const literal = ast.literal;
|
|
137
|
-
if (typeof literal === "string" || typeof literal === "number" || typeof literal === "boolean") {
|
|
138
|
-
const {
|
|
139
|
-
annotations,
|
|
140
|
-
filters
|
|
141
|
-
} = get(ast);
|
|
142
|
-
if (annotations !== undefined || filters !== undefined) {
|
|
143
|
-
return new SchemaAST.Literal(ast.literal, annotations, filters);
|
|
144
|
-
}
|
|
145
|
-
return ast;
|
|
146
|
-
}
|
|
147
|
-
throw new Error(`${errorPrefix}: Unsupported literal type ${typeof literal} (value: ${String(literal)}) (supported: string | number | boolean)`);
|
|
148
|
-
}
|
|
149
|
-
case "Union":
|
|
150
|
-
{
|
|
151
|
-
if (ast.mode === "oneOf") {
|
|
152
|
-
return new SchemaAST.Union(ast.types, "anyOf", ast.annotations, ast.checks);
|
|
153
|
-
}
|
|
154
|
-
const types = SchemaAST.mapOrSame(ast.types, recurOpenAI);
|
|
155
|
-
const {
|
|
156
|
-
annotations,
|
|
157
|
-
filters
|
|
158
|
-
} = get(ast);
|
|
159
|
-
if (types !== ast.types || annotations !== undefined || filters !== undefined) {
|
|
160
|
-
return new SchemaAST.Union(types, "anyOf", annotations, filters);
|
|
161
|
-
}
|
|
162
|
-
return ast;
|
|
163
|
-
}
|
|
164
|
-
case "Arrays":
|
|
165
|
-
{
|
|
166
|
-
if (ast.rest.length > 1) {
|
|
167
|
-
throw new Error(`${errorPrefix}: Post-rest elements are not supported for arrays (rest length: ${ast.rest.length})`);
|
|
168
|
-
}
|
|
169
|
-
let {
|
|
170
|
-
annotations,
|
|
171
|
-
filters
|
|
172
|
-
} = get(ast);
|
|
173
|
-
if (ast.elements.length > 0) {
|
|
174
|
-
// tuples are not supported by OpenAI, we translate them to objects with string keys
|
|
175
|
-
if (annotations !== undefined && typeof annotations.description === "string") {
|
|
176
|
-
annotations.description = `${TUPLE_DESCRIPTION}; ${annotations.description}`;
|
|
177
|
-
} else {
|
|
178
|
-
annotations ??= {};
|
|
179
|
-
annotations.description = TUPLE_DESCRIPTION;
|
|
180
|
-
}
|
|
181
|
-
const propertySignatures = ast.elements.map((e, i) => {
|
|
182
|
-
return new SchemaAST.PropertySignature(String(i), e);
|
|
183
|
-
});
|
|
184
|
-
if (ast.rest.length === 1) {
|
|
185
|
-
propertySignatures.push(new SchemaAST.PropertySignature(REST_PROPERTY_NAME, new SchemaAST.Arrays(false, [], ast.rest)));
|
|
186
|
-
}
|
|
187
|
-
return SchemaAST.decodeTo(recurOpenAI(new SchemaAST.Objects(propertySignatures, [], annotations, filters)), ast, SchemaTransformation.transform({
|
|
188
|
-
decode: o => {
|
|
189
|
-
let t = [];
|
|
190
|
-
for (let i = 0; i < ast.elements.length; i++) {
|
|
191
|
-
const k = String(i);
|
|
192
|
-
if (o[k] !== undefined) {
|
|
193
|
-
t.push(o[k]);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (REST_PROPERTY_NAME in o) {
|
|
197
|
-
t = [...t, ...o[REST_PROPERTY_NAME]];
|
|
198
|
-
}
|
|
199
|
-
return t;
|
|
200
|
-
},
|
|
201
|
-
encode: t => {
|
|
202
|
-
const o = {};
|
|
203
|
-
for (let i = 0; i < ast.elements.length; i++) {
|
|
204
|
-
if (t.length >= i) {
|
|
205
|
-
o[String(i)] = t[i];
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (ast.rest.length === 1) {
|
|
209
|
-
o[REST_PROPERTY_NAME] = t.length >= ast.elements.length ? t.slice(ast.elements.length) : [];
|
|
210
|
-
}
|
|
211
|
-
return o;
|
|
212
|
-
}
|
|
213
|
-
}));
|
|
214
|
-
} else {
|
|
215
|
-
const rest = SchemaAST.mapOrSame(ast.rest, recurOpenAI);
|
|
216
|
-
if (rest !== ast.rest || annotations !== undefined || filters !== undefined) {
|
|
217
|
-
return new SchemaAST.Arrays(false, [], rest, annotations, filters);
|
|
218
|
-
}
|
|
219
|
-
return ast;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
case "Objects":
|
|
223
|
-
{
|
|
224
|
-
let {
|
|
225
|
-
annotations,
|
|
226
|
-
filters
|
|
227
|
-
} = get(ast);
|
|
228
|
-
if (ast.indexSignatures.length === 0) {
|
|
229
|
-
const propertySignatures = SchemaAST.mapOrSame(ast.propertySignatures, ps => {
|
|
230
|
-
if (typeof ps.name !== "string") {
|
|
231
|
-
throw new Error(`${errorPrefix}: Property names must be strings (got ${typeof ps.name})`);
|
|
232
|
-
}
|
|
233
|
-
let type = recurOpenAI(ps.type);
|
|
234
|
-
// optional properties are not supported by OpenAI, so we translate them to nullable unions
|
|
235
|
-
if (SchemaAST.isOptional(ps.type)) {
|
|
236
|
-
type = SchemaAST.decodeTo(new SchemaAST.Union([type, SchemaAST.null], "anyOf"), SchemaAST.optionalKey(type), SchemaTransformation.transformOptional({
|
|
237
|
-
decode: Option.filter(Predicate.isNotNull),
|
|
238
|
-
encode: Option.orElseSome(() => null)
|
|
239
|
-
}));
|
|
240
|
-
}
|
|
241
|
-
if (type === ps.type) {
|
|
242
|
-
return ps;
|
|
243
|
-
}
|
|
244
|
-
return new SchemaAST.PropertySignature(ps.name, type);
|
|
245
|
-
});
|
|
246
|
-
if (propertySignatures !== ast.propertySignatures || annotations !== undefined || filters !== undefined) {
|
|
247
|
-
return new SchemaAST.Objects(propertySignatures, [], annotations, filters);
|
|
248
|
-
}
|
|
249
|
-
} else if (ast.indexSignatures.length === 1 && ast.propertySignatures.length === 0) {
|
|
250
|
-
const is = ast.indexSignatures[0];
|
|
251
|
-
if (Tool.isEmptyParamsRecord(is)) {
|
|
252
|
-
return ast;
|
|
253
|
-
}
|
|
254
|
-
// records are not supported by OpenAI, so we translate them to arrays of key-value pairs
|
|
255
|
-
if (annotations !== undefined && typeof annotations.description === "string") {
|
|
256
|
-
annotations.description = `${RECORD_DESCRIPTION}; ${annotations.description}`;
|
|
257
|
-
} else {
|
|
258
|
-
annotations ??= {};
|
|
259
|
-
annotations.description = RECORD_DESCRIPTION;
|
|
260
|
-
}
|
|
261
|
-
return SchemaAST.decodeTo(recurOpenAI(new SchemaAST.Arrays(false, [], [new SchemaAST.Arrays(false, [is.parameter, is.type], [])], annotations)), ast, SchemaTransformation.transform({
|
|
262
|
-
decode: Object.fromEntries,
|
|
263
|
-
encode: Object.entries
|
|
264
|
-
}));
|
|
265
|
-
} else {
|
|
266
|
-
throw new Error(`${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)`);
|
|
267
|
-
}
|
|
268
|
-
return ast;
|
|
269
|
-
}
|
|
270
|
-
case "Suspend":
|
|
271
|
-
{
|
|
272
|
-
const cached = cache.get(ast);
|
|
273
|
-
if (cached) return cached;
|
|
274
|
-
const {
|
|
275
|
-
annotations
|
|
276
|
-
} = get(ast);
|
|
277
|
-
const out = new SchemaAST.Suspend(() => recurOpenAI(ast.thunk()), annotations);
|
|
278
|
-
cache.set(ast, out);
|
|
279
|
-
return out;
|
|
147
|
+
function mergeAllOfKeyword(out, key, value, patterns, baseKeywords, memberKeywords, ambiguousKeywords) {
|
|
148
|
+
switch (key) {
|
|
149
|
+
case "description":
|
|
150
|
+
if (typeof value === "string") InternalStructuredOutput.appendDescription(out, value);
|
|
151
|
+
return;
|
|
152
|
+
case "pattern":
|
|
153
|
+
if (typeof value === "string") patterns.push(value);
|
|
154
|
+
return;
|
|
155
|
+
case "minimum":
|
|
156
|
+
case "exclusiveMinimum":
|
|
157
|
+
mergeLowerBound(out, key, value);
|
|
158
|
+
return;
|
|
159
|
+
case "maximum":
|
|
160
|
+
case "exclusiveMaximum":
|
|
161
|
+
mergeUpperBound(out, key, value);
|
|
162
|
+
return;
|
|
163
|
+
case "minItems":
|
|
164
|
+
mergeMinimum(out, key, value);
|
|
165
|
+
return;
|
|
166
|
+
case "maxItems":
|
|
167
|
+
mergeMaximum(out, key, value);
|
|
168
|
+
return;
|
|
169
|
+
default:
|
|
170
|
+
if (!normalizableAllOfKeywords.has(key) || baseKeywords.has(key) || ambiguousKeywords.has(key)) return;
|
|
171
|
+
if (!memberKeywords.has(key)) {
|
|
172
|
+
out[key] = value;
|
|
173
|
+
memberKeywords.add(key);
|
|
174
|
+
} else if (out[key] !== value) {
|
|
175
|
+
delete out[key];
|
|
176
|
+
memberKeywords.delete(key);
|
|
177
|
+
ambiguousKeywords.add(key);
|
|
280
178
|
}
|
|
179
|
+
return;
|
|
281
180
|
}
|
|
282
181
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const full = `${errorPrefix}: ${base}`;
|
|
288
|
-
throw new Error(details !== undefined ? `${full} (${details})` : full);
|
|
182
|
+
function mergeMinimum(schema, key, value) {
|
|
183
|
+
if (typeof value !== "number") return;
|
|
184
|
+
const current = schema[key];
|
|
185
|
+
if (typeof current !== "number" || value > current) schema[key] = value;
|
|
289
186
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
for (const check of checks) {
|
|
300
|
-
switch (check._tag) {
|
|
301
|
-
case "description":
|
|
302
|
-
{
|
|
303
|
-
if (annotations.description !== undefined) {
|
|
304
|
-
annotations.description += ` and ${check.description}`;
|
|
305
|
-
} else {
|
|
306
|
-
annotations.description = check.description;
|
|
307
|
-
}
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
case "format":
|
|
311
|
-
{
|
|
312
|
-
annotations.format = check.format;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
case "filter":
|
|
316
|
-
{
|
|
317
|
-
filters.push(check.filter);
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
case "regex":
|
|
321
|
-
{
|
|
322
|
-
regexSources.push(check.source);
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
// OpenAI does not support allOf, so we merge multiple regex patterns into a single isPattern filter
|
|
329
|
-
if (regexSources.length === 1) {
|
|
330
|
-
filters.push(SchemaAST.isPattern(new RegExp(regexSources[0])));
|
|
331
|
-
} else if (regexSources.length > 1) {
|
|
332
|
-
const combined = regexSources.map(s => `(?=[\\s\\S]*?(?:${s}))`).join("");
|
|
333
|
-
filters.push(SchemaAST.isPattern(new RegExp(`^${combined}`)));
|
|
187
|
+
function mergeMaximum(schema, key, value) {
|
|
188
|
+
if (typeof value !== "number") return;
|
|
189
|
+
const current = schema[key];
|
|
190
|
+
if (typeof current !== "number" || value < current) schema[key] = value;
|
|
191
|
+
}
|
|
192
|
+
function mergeLowerBound(schema, key, value) {
|
|
193
|
+
if (typeof value !== "number") {
|
|
194
|
+
if (!Object.hasOwn(schema, key)) schema[key] = value;
|
|
195
|
+
return;
|
|
334
196
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
197
|
+
const minimum = typeof schema.minimum === "number" ? schema.minimum : undefined;
|
|
198
|
+
const exclusiveMinimum = typeof schema.exclusiveMinimum === "number" ? schema.exclusiveMinimum : undefined;
|
|
199
|
+
let current;
|
|
200
|
+
if (minimum !== undefined) current = {
|
|
201
|
+
value: minimum,
|
|
202
|
+
exclusive: false
|
|
338
203
|
};
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const description = annotations?.description ?? (annotations.meta?._tag === "isInt" || annotations.meta?._tag === "isFinite" ? undefined : annotations?.expected);
|
|
345
|
-
if (typeof description === "string") {
|
|
346
|
-
out.push({
|
|
347
|
-
_tag: "description",
|
|
348
|
-
description
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
const format = annotations?.format;
|
|
352
|
-
if (typeof format === "string") {
|
|
353
|
-
if (formats.includes(format)) {
|
|
354
|
-
out.push({
|
|
355
|
-
_tag: "format",
|
|
356
|
-
format
|
|
357
|
-
});
|
|
358
|
-
} else {
|
|
359
|
-
out.push({
|
|
360
|
-
_tag: "description",
|
|
361
|
-
description: `a value with a format of ${format}`
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
204
|
+
if (exclusiveMinimum !== undefined && (current === undefined || exclusiveMinimum >= current.value)) {
|
|
205
|
+
current = {
|
|
206
|
+
value: exclusiveMinimum,
|
|
207
|
+
exclusive: true
|
|
208
|
+
};
|
|
365
209
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (meta !== undefined) {
|
|
373
|
-
switch (meta._tag) {
|
|
374
|
-
case "isMinLength":
|
|
375
|
-
case "isMaxLength":
|
|
376
|
-
case "isLengthBetween":
|
|
377
|
-
{
|
|
378
|
-
out = out.concat(annotations);
|
|
379
|
-
if (isArray) {
|
|
380
|
-
out.push({
|
|
381
|
-
_tag: "filter",
|
|
382
|
-
filter: resetFilter(filter)
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
case "isInt":
|
|
388
|
-
case "isFinite":
|
|
389
|
-
case "isGreaterThan":
|
|
390
|
-
case "isGreaterThanOrEqualTo":
|
|
391
|
-
case "isLessThan":
|
|
392
|
-
case "isLessThanOrEqualTo":
|
|
393
|
-
case "isBetween":
|
|
394
|
-
case "isMultipleOf":
|
|
395
|
-
{
|
|
396
|
-
out = out.concat(annotations);
|
|
397
|
-
out.push({
|
|
398
|
-
_tag: "filter",
|
|
399
|
-
filter: resetFilter(filter)
|
|
400
|
-
});
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
default:
|
|
404
|
-
{
|
|
405
|
-
out = out.concat(annotations);
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if ("regExp" in meta && meta.regExp instanceof RegExp) {
|
|
410
|
-
out.push({
|
|
411
|
-
_tag: "regex",
|
|
412
|
-
source: meta.regExp.source
|
|
413
|
-
});
|
|
414
|
-
}
|
|
210
|
+
const candidate = {
|
|
211
|
+
value,
|
|
212
|
+
exclusive: key === "exclusiveMinimum"
|
|
213
|
+
};
|
|
214
|
+
if (current === undefined || candidate.value > current.value || candidate.value === current.value && candidate.exclusive) {
|
|
215
|
+
current = candidate;
|
|
415
216
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return filter.annotate({
|
|
420
|
-
description: undefined,
|
|
421
|
-
expected: undefined,
|
|
422
|
-
title: undefined,
|
|
423
|
-
format: undefined
|
|
424
|
-
});
|
|
217
|
+
delete schema.minimum;
|
|
218
|
+
delete schema.exclusiveMinimum;
|
|
219
|
+
schema[current.exclusive ? "exclusiveMinimum" : "minimum"] = current.value;
|
|
425
220
|
}
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
221
|
+
function mergeUpperBound(schema, key, value) {
|
|
222
|
+
if (typeof value !== "number") {
|
|
223
|
+
if (!Object.hasOwn(schema, key)) schema[key] = value;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const maximum = typeof schema.maximum === "number" ? schema.maximum : undefined;
|
|
227
|
+
const exclusiveMaximum = typeof schema.exclusiveMaximum === "number" ? schema.exclusiveMaximum : undefined;
|
|
228
|
+
let current;
|
|
229
|
+
if (maximum !== undefined) current = {
|
|
230
|
+
value: maximum,
|
|
231
|
+
exclusive: false
|
|
232
|
+
};
|
|
233
|
+
if (exclusiveMaximum !== undefined && (current === undefined || exclusiveMaximum <= current.value)) {
|
|
234
|
+
current = {
|
|
235
|
+
value: exclusiveMaximum,
|
|
236
|
+
exclusive: true
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const candidate = {
|
|
240
|
+
value,
|
|
241
|
+
exclusive: key === "exclusiveMaximum"
|
|
242
|
+
};
|
|
243
|
+
if (current === undefined || candidate.value < current.value || candidate.value === current.value && candidate.exclusive) {
|
|
244
|
+
current = candidate;
|
|
245
|
+
}
|
|
246
|
+
delete schema.maximum;
|
|
247
|
+
delete schema.exclusiveMaximum;
|
|
248
|
+
schema[current.exclusive ? "exclusiveMaximum" : "maximum"] = current.value;
|
|
435
249
|
}
|
|
436
|
-
const
|
|
250
|
+
const supportedKeywords = /*#__PURE__*/new Set(["$ref", "type", "title", "description", "enum", "anyOf", "properties", "required", "additionalProperties", "items", "pattern", "multipleOf", "minimum", "exclusiveMinimum", "maximum", "exclusiveMaximum", "minItems", "maxItems"]);
|
|
251
|
+
const normalizableAllOfKeywords = /*#__PURE__*/new Set(["$ref", "title", "enum", "anyOf", "format", "multipleOf"]);
|
|
252
|
+
const formats = /*#__PURE__*/new Set(["date-time", "time", "date", "duration", "email", "hostname", "ipv4", "ipv6", "uuid"]);
|
|
437
253
|
//# sourceMappingURL=OpenAiStructuredOutput.js.map
|