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
|
@@ -3,24 +3,18 @@
|
|
|
3
3
|
* structured output.
|
|
4
4
|
*
|
|
5
5
|
* The main entry point returns the JSON Schema to send to Anthropic and a codec
|
|
6
|
-
* for decoding the model response back into the original application type.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `oneOf` unions. Schema kinds that cannot be represented throw during
|
|
10
|
-
* conversion instead of producing a lossy schema.
|
|
6
|
+
* for decoding the model response back into the original application type.
|
|
7
|
+
* Unsupported constraints can be omitted from the provider schema and remain
|
|
8
|
+
* enforced by the returned codec.
|
|
11
9
|
*
|
|
12
10
|
* @since 4.0.0
|
|
13
11
|
*/
|
|
14
|
-
import * as Arr from "../../Array.ts"
|
|
15
12
|
import * as JsonSchema from "../../JsonSchema.ts"
|
|
16
|
-
import * as
|
|
17
|
-
import * as Predicate from "../../Predicate.ts"
|
|
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"
|
|
15
|
+
import * as InternalStructuredOutput from "./internal/structured-output.ts"
|
|
21
16
|
import * as LanguageModel from "./LanguageModel.ts"
|
|
22
17
|
import * as OpenAiStructuredOutput from "./OpenAiStructuredOutput.ts"
|
|
23
|
-
import * as Tool from "./Tool.ts"
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
20
|
* Converts a `Schema.Codec` to Anthropic structured-output JSON Schema and a
|
|
@@ -35,17 +29,21 @@ import * as Tool from "./Tool.ts"
|
|
|
35
29
|
* **Details**
|
|
36
30
|
*
|
|
37
31
|
* Returns the JSON Schema to include in the request and the codec to use when
|
|
38
|
-
* decoding the model response.
|
|
39
|
-
*
|
|
32
|
+
* decoding the model response. The codec remains authoritative: the provider
|
|
33
|
+
* JSON Schema can be a lossy, less restrictive representation when Anthropic
|
|
34
|
+
* cannot express an Effect Schema constraint.
|
|
40
35
|
*
|
|
41
36
|
* **Gotchas**
|
|
42
37
|
*
|
|
43
38
|
* - Some schemas use a provider-safe encoded shape: tuples become objects with
|
|
44
|
-
* numeric string keys,
|
|
45
|
-
* optional properties become required nullable
|
|
39
|
+
* numeric string keys, objects with index signatures become arrays of
|
|
40
|
+
* `[key, value]` pairs, and optional properties become required nullable
|
|
41
|
+
* properties.
|
|
46
42
|
* - `oneOf` unions are emitted as `anyOf` unions.
|
|
47
|
-
* - Unsupported
|
|
48
|
-
*
|
|
43
|
+
* - Unsupported constraints are removed from the provider schema and are still
|
|
44
|
+
* checked while decoding with the returned codec.
|
|
45
|
+
* - Recursive schemas throw during conversion because Anthropic structured
|
|
46
|
+
* output does not support recursive references.
|
|
49
47
|
*
|
|
50
48
|
* @see {@link LanguageModel.CodecTransformer} for the structured-output transformer contract
|
|
51
49
|
* @see {@link OpenAiStructuredOutput.toCodecOpenAI} for the OpenAI-specific transformer
|
|
@@ -59,349 +57,120 @@ export function toCodecAnthropic<T, E, RD, RE>(
|
|
|
59
57
|
readonly codec: Schema.ConstraintCodec<T, unknown, RD, RE>
|
|
60
58
|
readonly jsonSchema: JsonSchema.JsonSchema
|
|
61
59
|
} {
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const document = JsonSchema.resolveTopLevel$ref(
|
|
68
|
-
const jsonSchema =
|
|
60
|
+
const codec = InternalStructuredOutput.toCodec(schema)
|
|
61
|
+
const unresolvedDocument = Schema.toJsonSchemaDocument(codec, { generateDescriptions: true })
|
|
62
|
+
if (hasReferenceCycle(unresolvedDocument.schema, unresolvedDocument.definitions)) {
|
|
63
|
+
throw new Error("AnthropicStructuredOutput: Recursive schemas are not supported")
|
|
64
|
+
}
|
|
65
|
+
const document = JsonSchema.resolveTopLevel$ref(unresolvedDocument)
|
|
66
|
+
const jsonSchema = rewriteAnthropic(document.schema)
|
|
69
67
|
if (Object.keys(document.definitions).length > 0) {
|
|
70
|
-
jsonSchema.$defs = document.definitions
|
|
68
|
+
jsonSchema.$defs = Rec.map(document.definitions, rewriteAnthropic)
|
|
71
69
|
}
|
|
72
70
|
return { codec, jsonSchema }
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
93
|
-
case "Undefined":
|
|
94
|
-
return unsupportedAst(
|
|
95
|
-
ast,
|
|
96
|
-
"Anthropic structured output does not support undefined; consider transforming the schema or using a different provider; if using `Schema.optional`, consider using `Schema.optionalKey` instead"
|
|
97
|
-
)
|
|
98
|
-
case "Null":
|
|
99
|
-
return ast
|
|
100
|
-
case "String": {
|
|
101
|
-
const { annotations, filters } = get(ast)
|
|
102
|
-
if (annotations !== undefined || filters !== undefined) {
|
|
103
|
-
return new SchemaAST.String(annotations, filters)
|
|
104
|
-
}
|
|
105
|
-
return ast
|
|
106
|
-
}
|
|
107
|
-
case "Number": {
|
|
108
|
-
const { annotations, filters } = get(ast)
|
|
109
|
-
if (annotations !== undefined || filters !== undefined) {
|
|
110
|
-
return new SchemaAST.Number(annotations, filters)
|
|
111
|
-
}
|
|
112
|
-
return ast
|
|
113
|
-
}
|
|
114
|
-
case "Boolean":
|
|
115
|
-
return ast
|
|
116
|
-
case "Literal": {
|
|
117
|
-
const literal = ast.literal
|
|
118
|
-
if (typeof literal === "string" || typeof literal === "number" || typeof literal === "boolean") {
|
|
119
|
-
const { annotations, filters } = get(ast)
|
|
120
|
-
if (annotations !== undefined || filters !== undefined) {
|
|
121
|
-
return new SchemaAST.Literal(ast.literal, annotations, filters)
|
|
122
|
-
}
|
|
123
|
-
return ast
|
|
124
|
-
}
|
|
125
|
-
throw new Error(
|
|
126
|
-
`${errorPrefix}: Unsupported literal type ${typeof literal} (value: ${
|
|
127
|
-
String(literal)
|
|
128
|
-
}) (supported: string | number | boolean)`
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
case "Union": {
|
|
132
|
-
if (ast.mode === "oneOf") {
|
|
133
|
-
return new SchemaAST.Union(ast.types, "anyOf", ast.annotations, ast.checks)
|
|
134
|
-
}
|
|
135
|
-
const types = SchemaAST.mapOrSame(ast.types, recur)
|
|
136
|
-
const { annotations, filters } = get(ast)
|
|
137
|
-
if (types !== ast.types || annotations !== undefined || filters !== undefined) {
|
|
138
|
-
return new SchemaAST.Union(types, "anyOf", annotations, filters)
|
|
139
|
-
}
|
|
140
|
-
return ast
|
|
141
|
-
}
|
|
142
|
-
case "Arrays": {
|
|
143
|
-
if (ast.rest.length > 1) {
|
|
144
|
-
throw new Error(
|
|
145
|
-
`${errorPrefix}: Post-rest elements are not supported for arrays (rest length: ${ast.rest.length})`
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
let { annotations, filters } = get(ast)
|
|
149
|
-
if (ast.elements.length > 0) {
|
|
150
|
-
// tuples are not supported by Anthropic, we translate them to objects with string keys
|
|
151
|
-
if (annotations !== undefined && typeof annotations.description === "string") {
|
|
152
|
-
annotations.description = `${TUPLE_DESCRIPTION}; ${annotations.description}`
|
|
153
|
-
} else {
|
|
154
|
-
annotations ??= {}
|
|
155
|
-
annotations.description = TUPLE_DESCRIPTION
|
|
156
|
-
}
|
|
157
|
-
const propertySignatures = ast.elements.map((e, i) => {
|
|
158
|
-
return new SchemaAST.PropertySignature(String(i), e)
|
|
159
|
-
})
|
|
160
|
-
if (ast.rest.length === 1) {
|
|
161
|
-
propertySignatures.push(
|
|
162
|
-
new SchemaAST.PropertySignature(REST_PROPERTY_NAME, new SchemaAST.Arrays(false, [], ast.rest))
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
return SchemaAST.decodeTo(
|
|
166
|
-
recur(new SchemaAST.Objects(propertySignatures, [], annotations, filters)),
|
|
167
|
-
ast,
|
|
168
|
-
SchemaTransformation.transform({
|
|
169
|
-
decode: (o) => {
|
|
170
|
-
let t: Array<unknown> = []
|
|
171
|
-
for (let i = 0; i < ast.elements.length; i++) {
|
|
172
|
-
const k = String(i)
|
|
173
|
-
if (o[k] !== undefined) {
|
|
174
|
-
t.push(o[k])
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (REST_PROPERTY_NAME in o) {
|
|
178
|
-
t = [...t, ...o[REST_PROPERTY_NAME]]
|
|
179
|
-
}
|
|
180
|
-
return t
|
|
181
|
-
},
|
|
182
|
-
encode: (t) => {
|
|
183
|
-
const o: Record<string, unknown> = {}
|
|
184
|
-
for (let i = 0; i < ast.elements.length; i++) {
|
|
185
|
-
if (t.length >= i) {
|
|
186
|
-
o[String(i)] = t[i]
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (ast.rest.length === 1) {
|
|
190
|
-
o[REST_PROPERTY_NAME] = t.length >= ast.elements.length ? t.slice(ast.elements.length) : []
|
|
191
|
-
}
|
|
192
|
-
return o
|
|
193
|
-
}
|
|
194
|
-
})
|
|
195
|
-
)
|
|
196
|
-
} else {
|
|
197
|
-
const rest = SchemaAST.mapOrSame(ast.rest, recur)
|
|
198
|
-
if (rest !== ast.rest || annotations !== undefined || filters !== undefined) {
|
|
199
|
-
return new SchemaAST.Arrays(false, [], rest, annotations, filters)
|
|
200
|
-
}
|
|
201
|
-
return ast
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
case "Objects": {
|
|
205
|
-
let { annotations, filters } = get(ast)
|
|
206
|
-
if (ast.indexSignatures.length === 0) {
|
|
207
|
-
const propertySignatures = SchemaAST.mapOrSame(ast.propertySignatures, (ps) => {
|
|
208
|
-
if (typeof ps.name !== "string") {
|
|
209
|
-
throw new Error(
|
|
210
|
-
`${errorPrefix}: Property names must be strings (got ${typeof ps.name})`
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
let type = recur(ps.type)
|
|
214
|
-
// opttional properties are not supported by Anthropic, so we translate them to nullable unions
|
|
215
|
-
if (SchemaAST.isOptional(ps.type)) {
|
|
216
|
-
type = SchemaAST.decodeTo(
|
|
217
|
-
new SchemaAST.Union([type, SchemaAST.null], "anyOf"),
|
|
218
|
-
SchemaAST.optionalKey(type),
|
|
219
|
-
SchemaTransformation.transformOptional({
|
|
220
|
-
decode: Option.filter(Predicate.isNotNull),
|
|
221
|
-
encode: Option.orElseSome(() => null)
|
|
222
|
-
})
|
|
223
|
-
)
|
|
224
|
-
}
|
|
225
|
-
if (type === ps.type) {
|
|
226
|
-
return ps
|
|
227
|
-
}
|
|
228
|
-
return new SchemaAST.PropertySignature(ps.name, type)
|
|
229
|
-
})
|
|
230
|
-
if (
|
|
231
|
-
propertySignatures !== ast.propertySignatures || annotations !== undefined || filters !== undefined
|
|
232
|
-
) {
|
|
233
|
-
return new SchemaAST.Objects(propertySignatures, [], annotations, filters)
|
|
234
|
-
}
|
|
235
|
-
} else if (ast.indexSignatures.length === 1 && ast.propertySignatures.length === 0) {
|
|
236
|
-
const is = ast.indexSignatures[0]
|
|
237
|
-
if (Tool.isEmptyParamsRecord(is)) {
|
|
238
|
-
return ast
|
|
239
|
-
}
|
|
240
|
-
// records are not supported by Anthropic, so we translate them to arrays of key-value pairs
|
|
241
|
-
if (annotations !== undefined && typeof annotations.description === "string") {
|
|
242
|
-
annotations.description = `${RECORD_DESCRIPTION}; ${annotations.description}`
|
|
243
|
-
} else {
|
|
244
|
-
annotations ??= {}
|
|
245
|
-
annotations.description = RECORD_DESCRIPTION
|
|
246
|
-
}
|
|
247
|
-
return SchemaAST.decodeTo(
|
|
248
|
-
recur(
|
|
249
|
-
new SchemaAST.Arrays(false, [], [new SchemaAST.Arrays(false, [is.parameter, is.type], [])], annotations)
|
|
250
|
-
),
|
|
251
|
-
ast,
|
|
252
|
-
SchemaTransformation.transform({
|
|
253
|
-
decode: Object.fromEntries,
|
|
254
|
-
encode: Object.entries
|
|
255
|
-
})
|
|
256
|
-
)
|
|
257
|
-
} else {
|
|
258
|
-
throw new Error(
|
|
259
|
-
`${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)`
|
|
260
|
-
)
|
|
73
|
+
function hasReferenceCycle(
|
|
74
|
+
root: JsonSchema.JsonSchema,
|
|
75
|
+
definitions: JsonSchema.Definitions
|
|
76
|
+
): boolean {
|
|
77
|
+
const visiting = new Set<JsonSchema.JsonSchema>()
|
|
78
|
+
const visited = new Set<JsonSchema.JsonSchema>()
|
|
79
|
+
|
|
80
|
+
function visit(schema: JsonSchema.JsonSchema): boolean {
|
|
81
|
+
if (visiting.has(schema)) return true
|
|
82
|
+
if (visited.has(schema)) return false
|
|
83
|
+
|
|
84
|
+
visiting.add(schema)
|
|
85
|
+
let cycle = false
|
|
86
|
+
InternalStructuredOutput.walkJsonSchema(schema, (node) => {
|
|
87
|
+
if (!cycle && typeof node.$ref === "string") {
|
|
88
|
+
const target = node.$ref === "#" ? root : JsonSchema.resolve$ref(node.$ref, definitions)
|
|
89
|
+
if (target !== undefined && visit(target)) cycle = true
|
|
261
90
|
}
|
|
262
|
-
return
|
|
263
|
-
}
|
|
91
|
+
return node
|
|
92
|
+
})
|
|
93
|
+
visiting.delete(schema)
|
|
94
|
+
visited.add(schema)
|
|
95
|
+
return cycle
|
|
264
96
|
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const errorPrefix = "AnthropicStructuredOutput"
|
|
268
97
|
|
|
269
|
-
|
|
270
|
-
const base = `Unsupported AST ${ast._tag}`
|
|
271
|
-
const full = `${errorPrefix}: ${base}`
|
|
272
|
-
throw new Error(details !== undefined ? `${full} (${details})` : full)
|
|
98
|
+
return visit(root)
|
|
273
99
|
}
|
|
274
100
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const get = (ast: SchemaAST.AST): {
|
|
292
|
-
annotations: Record<string, string> | undefined
|
|
293
|
-
filters: [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]] | undefined
|
|
294
|
-
} => {
|
|
295
|
-
const annotations: Record<string, string> = {}
|
|
296
|
-
const filters: Array<SchemaAST.Filter<any>> = []
|
|
297
|
-
const checks = getChecks(ast)
|
|
298
|
-
if (checks.length > 0) {
|
|
299
|
-
for (const check of checks) {
|
|
300
|
-
switch (check._tag) {
|
|
301
|
-
case "description": {
|
|
302
|
-
if (annotations.description !== undefined) {
|
|
303
|
-
annotations.description += ` and ${check.description}`
|
|
304
|
-
} else {
|
|
305
|
-
annotations.description = check.description
|
|
306
|
-
}
|
|
307
|
-
break
|
|
308
|
-
}
|
|
309
|
-
case "format": {
|
|
310
|
-
annotations.format = check.format
|
|
311
|
-
break
|
|
312
|
-
}
|
|
313
|
-
case "filter": {
|
|
314
|
-
filters.push(check.filter)
|
|
315
|
-
break
|
|
316
|
-
}
|
|
101
|
+
function rewriteAnthropic(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
|
|
102
|
+
return InternalStructuredOutput.walkJsonSchema(schema, (schema) => {
|
|
103
|
+
const normalized = hoistAllOfDescriptions(schema)
|
|
104
|
+
const out: JsonSchema.JsonSchema = {}
|
|
105
|
+
let unsupportedFormat: string | undefined
|
|
106
|
+
for (const [key, value] of Object.entries(normalized)) {
|
|
107
|
+
if (key === "format") {
|
|
108
|
+
if (
|
|
109
|
+
typeof value === "string" && formats.has(value) &&
|
|
110
|
+
(normalized.type === undefined || normalized.type === "string")
|
|
111
|
+
) {
|
|
112
|
+
out.format = value
|
|
113
|
+
} else if (typeof value === "string") unsupportedFormat = value
|
|
114
|
+
} else if (supportedKeywords.has(key)) {
|
|
115
|
+
if (key !== "additionalProperties" || value === false) out[key] = value
|
|
317
116
|
}
|
|
318
117
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
118
|
+
if (unsupportedFormat !== undefined) {
|
|
119
|
+
InternalStructuredOutput.appendDescription(out, `a value with a format of ${unsupportedFormat}`)
|
|
120
|
+
}
|
|
121
|
+
return out
|
|
122
|
+
})
|
|
324
123
|
}
|
|
325
124
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
...getAnnotations(ast.annotations)
|
|
329
|
-
]
|
|
125
|
+
function hoistAllOfDescriptions(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
|
|
126
|
+
if (!Array.isArray(schema.allOf)) return schema
|
|
330
127
|
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
const description = annotations?.description
|
|
335
|
-
?? (annotations.meta?._tag === "isInt" || annotations.meta?._tag === "isFinite"
|
|
336
|
-
? undefined
|
|
337
|
-
: annotations?.expected)
|
|
338
|
-
if (typeof description === "string") {
|
|
339
|
-
out.push({ _tag: "description", description })
|
|
340
|
-
}
|
|
341
|
-
const format = annotations?.format
|
|
342
|
-
if (typeof format === "string") {
|
|
343
|
-
if (formats.includes(format)) {
|
|
344
|
-
out.push({ _tag: "format", format })
|
|
345
|
-
} else {
|
|
346
|
-
out.push({ _tag: "description", description: `a value with a format of ${format}` })
|
|
347
|
-
}
|
|
348
|
-
}
|
|
128
|
+
const out: JsonSchema.JsonSchema = {}
|
|
129
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
130
|
+
if (key !== "allOf") out[key] = value
|
|
349
131
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
switch (meta._tag) {
|
|
359
|
-
case "isInt":
|
|
360
|
-
case "isFinite": {
|
|
361
|
-
out = out.concat(annotations)
|
|
362
|
-
out.push({ _tag: "filter", filter: resetFilter(filter) })
|
|
363
|
-
break
|
|
364
|
-
}
|
|
365
|
-
default: {
|
|
366
|
-
out = out.concat(annotations)
|
|
367
|
-
break
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
if ("regExp" in meta && meta.regExp instanceof RegExp) {
|
|
371
|
-
out.push({ _tag: "filter", filter: resetFilter(filter) })
|
|
132
|
+
const members: Array<JsonSchema.JsonSchema> = []
|
|
133
|
+
for (const member of schema.allOf) {
|
|
134
|
+
if (!InternalStructuredOutput.isJsonSchema(member)) continue
|
|
135
|
+
const { description, format, title, ...memberRest } = member
|
|
136
|
+
const rest = { ...memberRest }
|
|
137
|
+
if (schema.type !== undefined && schema.type !== "string") delete rest.pattern
|
|
138
|
+
if (typeof description === "string") {
|
|
139
|
+
InternalStructuredOutput.appendDescription(out, description)
|
|
372
140
|
}
|
|
141
|
+
if (out.format === undefined && typeof format === "string") out.format = format
|
|
142
|
+
if (out.title === undefined && typeof title === "string") out.title = title
|
|
143
|
+
if (Object.keys(rest).length > 0) members.push(rest)
|
|
373
144
|
}
|
|
145
|
+
if (members.length > 0) out.allOf = members
|
|
374
146
|
return out
|
|
375
147
|
}
|
|
376
148
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
})
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const formats = [
|
|
149
|
+
const supportedKeywords = new Set([
|
|
150
|
+
"$ref",
|
|
151
|
+
"type",
|
|
152
|
+
"title",
|
|
153
|
+
"description",
|
|
154
|
+
"enum",
|
|
155
|
+
"const",
|
|
156
|
+
"anyOf",
|
|
157
|
+
"allOf",
|
|
158
|
+
"properties",
|
|
159
|
+
"required",
|
|
160
|
+
"additionalProperties",
|
|
161
|
+
"items",
|
|
162
|
+
"pattern"
|
|
163
|
+
])
|
|
164
|
+
|
|
165
|
+
const formats = new Set([
|
|
398
166
|
"date-time",
|
|
399
167
|
"time",
|
|
400
168
|
"date",
|
|
401
169
|
"duration",
|
|
402
170
|
"email",
|
|
403
171
|
"hostname",
|
|
172
|
+
"uri",
|
|
404
173
|
"ipv4",
|
|
405
174
|
"ipv6",
|
|
406
175
|
"uuid"
|
|
407
|
-
]
|
|
176
|
+
])
|
|
@@ -69,7 +69,7 @@ export class Dimensions extends Context.Service<Dimensions, number>()(
|
|
|
69
69
|
export class EmbeddingUsage extends Schema.Class<EmbeddingUsage>(
|
|
70
70
|
"effect/ai/EmbeddingModel/EmbeddingUsage"
|
|
71
71
|
)({
|
|
72
|
-
inputTokens: Schema.
|
|
72
|
+
inputTokens: Schema.optional(Schema.Finite)
|
|
73
73
|
}) {}
|
|
74
74
|
|
|
75
75
|
/**
|