effect 4.0.3 → 4.0.5
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/AGENTS.md +24 -0
- package/CLAUDE.md +24 -0
- package/ai-docs/package.json +2 -2
- package/ai-docs/src/52_graphql/10_basics.ts +117 -0
- package/ai-docs/src/52_graphql/20_testing.ts +45 -0
- package/ai-docs/src/52_graphql/30_batching.ts +118 -0
- package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
- package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
- package/ai-docs/src/52_graphql/index.md +6 -0
- package/dist/Array.d.ts +90 -6
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +4 -2
- package/dist/Array.js.map +1 -1
- package/dist/Channel.d.ts +6 -1
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +17 -3
- package/dist/Channel.js.map +1 -1
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +33 -32
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +9 -0
- package/dist/Context.js.map +1 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +2 -5
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +61 -19
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +58 -39
- package/dist/Effect.js.map +1 -1
- package/dist/FileSystem.d.ts +23 -9
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js.map +1 -1
- package/dist/Match.d.ts +20 -6
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js +2 -2
- package/dist/Match.js.map +1 -1
- package/dist/Path.d.ts +37 -5
- package/dist/Path.d.ts.map +1 -1
- package/dist/Path.js +36 -5
- package/dist/Path.js.map +1 -1
- package/dist/RequestResolver.d.ts.map +1 -1
- package/dist/RequestResolver.js +4 -10
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Scheduler.d.ts +9 -0
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +9 -0
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +15 -2
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +16 -2
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaGetter.d.ts +4 -0
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +52 -33
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +38 -17
- package/dist/Sink.js.map +1 -1
- package/dist/Stream.d.ts +11 -0
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +16 -1
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +12 -0
- package/dist/String.d.ts.map +1 -1
- package/dist/String.js +17 -4
- package/dist/String.js.map +1 -1
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +3 -2
- package/dist/TxRef.js.map +1 -1
- package/dist/Utils.js +8 -3
- package/dist/Utils.js.map +1 -1
- package/dist/ai/AiError.d.ts +10 -10
- package/dist/ai/AiError.d.ts.map +1 -1
- package/dist/ai/AiError.js +1 -1
- package/dist/ai/AiError.js.map +1 -1
- package/dist/ai/AnthropicStructuredOutput.js +0 -2
- package/dist/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/ai/Chat.d.ts +2 -2
- package/dist/ai/Chat.d.ts.map +1 -1
- package/dist/ai/Decision.d.ts +70 -19
- package/dist/ai/Decision.d.ts.map +1 -1
- package/dist/ai/Decision.js +37 -3
- package/dist/ai/Decision.js.map +1 -1
- package/dist/ai/DecisionModel.js +1 -1
- package/dist/ai/DecisionModel.js.map +1 -1
- package/dist/ai/LanguageModel.d.ts +38 -7
- package/dist/ai/LanguageModel.d.ts.map +1 -1
- package/dist/ai/LanguageModel.js +70 -40
- package/dist/ai/LanguageModel.js.map +1 -1
- package/dist/ai/McpServer.d.ts +61 -52
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +134 -50
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js +28 -5
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Response.d.ts +5 -4
- package/dist/ai/Response.d.ts.map +1 -1
- package/dist/ai/Response.js.map +1 -1
- package/dist/cli/Completions.d.ts +5 -0
- package/dist/cli/Completions.d.ts.map +1 -1
- package/dist/cli/Completions.js.map +1 -1
- package/dist/cli/Flag.d.ts +100 -0
- package/dist/cli/Flag.d.ts.map +1 -1
- package/dist/cli/Flag.js +33 -0
- package/dist/cli/Flag.js.map +1 -1
- package/dist/cli/Param.d.ts +87 -0
- package/dist/cli/Param.d.ts.map +1 -1
- package/dist/cli/Param.js +30 -0
- package/dist/cli/Param.js.map +1 -1
- package/dist/cli/internal/command.d.ts.map +1 -1
- package/dist/cli/internal/command.js +2 -1
- package/dist/cli/internal/command.js.map +1 -1
- package/dist/cli/internal/completions/bash.js +4 -3
- package/dist/cli/internal/completions/bash.js.map +1 -1
- package/dist/cli/internal/completions/descriptor.js +8 -1
- package/dist/cli/internal/completions/descriptor.js.map +1 -1
- package/dist/cli/internal/completions/fish.js +4 -4
- package/dist/cli/internal/completions/fish.js.map +1 -1
- package/dist/cli/internal/completions/powershell.js +3 -2
- package/dist/cli/internal/completions/powershell.js.map +1 -1
- package/dist/cli/internal/completions/zsh.js +7 -3
- package/dist/cli/internal/completions/zsh.js.map +1 -1
- package/dist/cli/internal/parser.js +11 -3
- package/dist/cli/internal/parser.js.map +1 -1
- package/dist/cli/internal/wizard.d.ts.map +1 -1
- package/dist/cli/internal/wizard.js +2 -1
- package/dist/cli/internal/wizard.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts +1 -0
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +113 -21
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +20 -12
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/Runners.d.ts.map +1 -1
- package/dist/cluster/Runners.js +54 -34
- package/dist/cluster/Runners.js.map +1 -1
- package/dist/cluster/Sharding.d.ts.map +1 -1
- package/dist/cluster/Sharding.js +6 -4
- package/dist/cluster/Sharding.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +1 -1
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/encoding/Sse.d.ts +6 -0
- package/dist/encoding/Sse.d.ts.map +1 -1
- package/dist/encoding/Sse.js +63 -71
- package/dist/encoding/Sse.js.map +1 -1
- package/dist/graphql/GraphQL.d.ts +349 -0
- package/dist/graphql/GraphQL.d.ts.map +1 -0
- package/dist/graphql/GraphQL.js +207 -0
- package/dist/graphql/GraphQL.js.map +1 -0
- package/dist/graphql/GraphQLClient.d.ts +562 -0
- package/dist/graphql/GraphQLClient.d.ts.map +1 -0
- package/dist/graphql/GraphQLClient.js +505 -0
- package/dist/graphql/GraphQLClient.js.map +1 -0
- package/dist/graphql/GraphQLClientError.d.ts +445 -0
- package/dist/graphql/GraphQLClientError.d.ts.map +1 -0
- package/dist/graphql/GraphQLClientError.js +479 -0
- package/dist/graphql/GraphQLClientError.js.map +1 -0
- package/dist/graphql/GraphQLGroup.d.ts +118 -0
- package/dist/graphql/GraphQLGroup.d.ts.map +1 -0
- package/dist/graphql/GraphQLGroup.js +109 -0
- package/dist/graphql/GraphQLGroup.js.map +1 -0
- package/dist/graphql/GraphQLMiddleware.d.ts +249 -0
- package/dist/graphql/GraphQLMiddleware.d.ts.map +1 -0
- package/dist/graphql/GraphQLMiddleware.js +130 -0
- package/dist/graphql/GraphQLMiddleware.js.map +1 -0
- package/dist/graphql/GraphQLProtocol.d.ts +969 -0
- package/dist/graphql/GraphQLProtocol.d.ts.map +1 -0
- package/dist/graphql/GraphQLProtocol.js +809 -0
- package/dist/graphql/GraphQLProtocol.js.map +1 -0
- package/dist/graphql/GraphQLResolver.d.ts +453 -0
- package/dist/graphql/GraphQLResolver.d.ts.map +1 -0
- package/dist/graphql/GraphQLResolver.js +582 -0
- package/dist/graphql/GraphQLResolver.js.map +1 -0
- package/dist/graphql/index.d.ts +40 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +41 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/http/FetchHttpClient.d.ts +6 -3
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +6 -3
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/FindMyWay/internal/router.js +2 -1
- package/dist/http/FindMyWay/internal/router.js.map +1 -1
- package/dist/http/Headers.d.ts +3 -3
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +6 -5
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts +27 -0
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +38 -11
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +8 -6
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +147 -4
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +47 -1
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpEffect.d.ts.map +1 -1
- package/dist/http/HttpEffect.js +14 -7
- package/dist/http/HttpEffect.js.map +1 -1
- package/dist/http/HttpMiddleware.d.ts +60 -0
- package/dist/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/http/HttpMiddleware.js +93 -32
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpRouter.d.ts +35 -0
- package/dist/http/HttpRouter.d.ts.map +1 -1
- package/dist/http/HttpRouter.js +87 -13
- package/dist/http/HttpRouter.js.map +1 -1
- package/dist/http/HttpServerError.d.ts.map +1 -1
- package/dist/http/HttpServerError.js +6 -4
- package/dist/http/HttpServerError.js.map +1 -1
- package/dist/http/HttpServerRequest.js +2 -2
- package/dist/http/HttpServerRequest.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts +8 -6
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +27 -16
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/HttpStaticServer.d.ts.map +1 -1
- package/dist/http/HttpStaticServer.js +4 -10
- package/dist/http/HttpStaticServer.js.map +1 -1
- package/dist/http/HttpTraceContext.js +1 -1
- package/dist/http/HttpTraceContext.js.map +1 -1
- package/dist/http/Multipart.d.ts.map +1 -1
- package/dist/http/Multipart.js +15 -1
- package/dist/http/Multipart.js.map +1 -1
- package/dist/http/Url.d.ts.map +1 -1
- package/dist/http/Url.js +2 -1
- package/dist/http/Url.js.map +1 -1
- package/dist/http/UrlParams.d.ts +112 -8
- package/dist/http/UrlParams.d.ts.map +1 -1
- package/dist/http/UrlParams.js +141 -14
- package/dist/http/UrlParams.js.map +1 -1
- package/dist/http/internal/compression.d.ts +1 -1
- package/dist/http/internal/compression.d.ts.map +1 -1
- package/dist/http/internal/compression.js +2 -10
- package/dist/http/internal/compression.js.map +1 -1
- package/dist/http/internal/compressionBody.d.ts +2 -0
- package/dist/http/internal/compressionBody.d.ts.map +1 -0
- package/dist/http/internal/compressionBody.js +36 -0
- package/dist/http/internal/compressionBody.js.map +1 -0
- package/dist/http/internal/decompression.d.ts +2 -0
- package/dist/http/internal/decompression.d.ts.map +1 -0
- package/dist/http/internal/decompression.js +162 -0
- package/dist/http/internal/decompression.js.map +1 -0
- package/dist/http/internal/tracing.js +14 -4
- package/dist/http/internal/tracing.js.map +1 -1
- package/dist/http/internal/urlParams.d.ts +2 -0
- package/dist/http/internal/urlParams.d.ts.map +1 -0
- package/dist/http/internal/urlParams.js +4 -0
- package/dist/http/internal/urlParams.js.map +1 -0
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +2 -1
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/HttpApiScalar.d.ts +5 -0
- package/dist/http-api/HttpApiScalar.d.ts.map +1 -1
- package/dist/http-api/HttpApiScalar.js.map +1 -1
- package/dist/internal/core.js +17 -1
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +40 -35
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +13 -6
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/graphql.d.ts +2 -0
- package/dist/internal/graphql.d.ts.map +1 -0
- package/dist/internal/graphql.js +205 -0
- package/dist/internal/graphql.js.map +1 -0
- package/dist/internal/graphqlHeaders.d.ts +4 -0
- package/dist/internal/graphqlHeaders.d.ts.map +1 -0
- package/dist/internal/graphqlHeaders.js +11 -0
- package/dist/internal/graphqlHeaders.js.map +1 -0
- package/dist/internal/request.js +20 -1
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +4 -1
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/schema/toJsonSchemaDocument.js +29 -5
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/net/Host.d.ts +49 -0
- package/dist/net/Host.d.ts.map +1 -1
- package/dist/net/Host.js +55 -0
- package/dist/net/Host.js.map +1 -1
- package/dist/net/NetAddress.d.ts +8 -0
- package/dist/net/NetAddress.d.ts.map +1 -1
- package/dist/net/NetAddress.js +8 -0
- package/dist/net/NetAddress.js.map +1 -1
- package/dist/observability/Otlp.d.ts +15 -0
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +3 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpExporter.d.ts +8 -0
- package/dist/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/observability/OtlpExporter.js +10 -1
- package/dist/observability/OtlpExporter.js.map +1 -1
- package/dist/observability/OtlpLogger.d.ts +17 -0
- package/dist/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/observability/OtlpLogger.js +14 -1
- package/dist/observability/OtlpLogger.js.map +1 -1
- package/dist/observability/OtlpMetrics.d.ts +17 -0
- package/dist/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/observability/OtlpMetrics.js +13 -0
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.d.ts +17 -0
- package/dist/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/observability/OtlpTracer.js +15 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/reactivity/AsyncResult.d.ts +6 -0
- package/dist/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/reactivity/AsyncResult.js +27 -0
- package/dist/reactivity/AsyncResult.js.map +1 -1
- package/dist/reactivity/AtomRegistry.js +3 -1
- package/dist/reactivity/AtomRegistry.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +6 -1
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcServer.d.ts.map +1 -1
- package/dist/rpc/RpcServer.js +36 -9
- package/dist/rpc/RpcServer.js.map +1 -1
- package/dist/socket/Socket.d.ts +6 -0
- package/dist/socket/Socket.d.ts.map +1 -1
- package/dist/socket/Socket.js.map +1 -1
- package/dist/sql/SqlClient.d.ts +8 -7
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +8 -7
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/testing/TestClock.d.ts +16 -3
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +112 -22
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/workflow/Activity.js +1 -0
- package/dist/workflow/Activity.js.map +1 -1
- package/dist/workflow/DurableDeferred.d.ts.map +1 -1
- package/dist/workflow/DurableDeferred.js +32 -3
- package/dist/workflow/DurableDeferred.js.map +1 -1
- package/dist/workflow/Workflow.d.ts +22 -0
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +15 -3
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts +44 -3
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +45 -22
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +6 -3
- package/src/Array.ts +95 -6
- package/src/Channel.ts +24 -3
- package/src/ConfigProvider.ts +40 -44
- package/src/Context.ts +9 -0
- package/src/Duration.ts +4 -5
- package/src/Effect.ts +140 -53
- package/src/FileSystem.ts +23 -9
- package/src/Match.ts +65 -12
- package/src/Path.ts +52 -7
- package/src/RequestResolver.ts +4 -10
- package/src/Scheduler.ts +9 -0
- package/src/Schema.ts +25 -4
- package/src/SchemaGetter.ts +47 -35
- package/src/Sink.ts +45 -18
- package/src/Stream.ts +33 -4
- package/src/String.ts +17 -4
- package/src/TxRef.ts +4 -2
- package/src/Utils.ts +8 -5
- package/src/ai/AiError.ts +3 -1
- package/src/ai/AnthropicStructuredOutput.ts +2 -2
- package/src/ai/Chat.ts +2 -2
- package/src/ai/Decision.ts +70 -21
- package/src/ai/DecisionModel.ts +1 -1
- package/src/ai/LanguageModel.ts +141 -63
- package/src/ai/McpServer.ts +259 -145
- package/src/ai/Prompt.ts +24 -10
- package/src/ai/Response.ts +6 -3
- package/src/cli/Completions.ts +5 -0
- package/src/cli/Flag.ts +101 -0
- package/src/cli/Param.ts +96 -0
- package/src/cli/internal/command.ts +2 -1
- package/src/cli/internal/completions/bash.ts +4 -3
- package/src/cli/internal/completions/descriptor.ts +10 -1
- package/src/cli/internal/completions/fish.ts +4 -4
- package/src/cli/internal/completions/powershell.ts +5 -2
- package/src/cli/internal/completions/zsh.ts +7 -3
- package/src/cli/internal/parser.ts +12 -3
- package/src/cli/internal/wizard.ts +2 -1
- package/src/cluster/ClusterWorkflowEngine.ts +143 -36
- package/src/cluster/MessageStorage.ts +14 -3
- package/src/cluster/Runners.ts +88 -66
- package/src/cluster/Sharding.ts +12 -9
- package/src/cluster/internal/entityManager.ts +1 -1
- package/src/encoding/Sse.ts +70 -80
- package/src/graphql/GraphQL.ts +494 -0
- package/src/graphql/GraphQLClient.ts +924 -0
- package/src/graphql/GraphQLClientError.ts +542 -0
- package/src/graphql/GraphQLGroup.ts +167 -0
- package/src/graphql/GraphQLMiddleware.ts +253 -0
- package/src/graphql/GraphQLProtocol.ts +1540 -0
- package/src/graphql/GraphQLResolver.ts +1038 -0
- package/src/graphql/index.ts +48 -0
- package/src/http/FetchHttpClient.ts +6 -3
- package/src/http/FindMyWay/internal/router.ts +2 -1
- package/src/http/Headers.ts +6 -9
- package/src/http/HttpClient.ts +72 -11
- package/src/http/HttpClientError.ts +10 -6
- package/src/http/HttpClientRequest.ts +173 -7
- package/src/http/HttpEffect.ts +11 -5
- package/src/http/HttpMiddleware.ts +113 -34
- package/src/http/HttpRouter.ts +95 -13
- package/src/http/HttpServerError.ts +8 -4
- package/src/http/HttpServerRequest.ts +2 -2
- package/src/http/HttpServerResponse.ts +28 -16
- package/src/http/HttpStaticServer.ts +4 -10
- package/src/http/HttpTraceContext.ts +1 -1
- package/src/http/Multipart.ts +17 -1
- package/src/http/Url.ts +2 -1
- package/src/http/UrlParams.ts +225 -26
- package/src/http/internal/compression.ts +3 -17
- package/src/http/internal/compressionBody.ts +56 -0
- package/src/http/internal/decompression.ts +226 -0
- package/src/http/internal/tracing.ts +21 -4
- package/src/http/internal/urlParams.ts +5 -0
- package/src/http-api/HttpApiClient.ts +2 -1
- package/src/http-api/HttpApiScalar.ts +5 -0
- package/src/internal/core.ts +21 -1
- package/src/internal/dateTime.ts +13 -10
- package/src/internal/effect.ts +13 -7
- package/src/internal/graphql.ts +286 -0
- package/src/internal/graphqlHeaders.ts +11 -0
- package/src/internal/request.ts +31 -3
- package/src/internal/schema/toCodeDocument.ts +7 -1
- package/src/internal/schema/toJsonSchemaDocument.ts +34 -2
- package/src/internal/version.ts +1 -1
- package/src/net/Host.ts +72 -0
- package/src/net/NetAddress.ts +9 -0
- package/src/observability/Otlp.ts +18 -0
- package/src/observability/OtlpExporter.ts +14 -3
- package/src/observability/OtlpLogger.ts +31 -2
- package/src/observability/OtlpMetrics.ts +30 -1
- package/src/observability/OtlpTracer.ts +32 -3
- package/src/reactivity/AsyncResult.ts +31 -0
- package/src/reactivity/AtomRegistry.ts +3 -1
- package/src/rpc/RpcClient.ts +6 -1
- package/src/rpc/RpcServer.ts +55 -15
- package/src/socket/Socket.ts +6 -0
- package/src/sql/SqlClient.ts +9 -7
- package/src/testing/TestClock.ts +144 -29
- package/src/workflow/Activity.ts +1 -0
- package/src/workflow/DurableDeferred.ts +43 -5
- package/src/workflow/Workflow.ts +31 -5
- package/src/workflow/WorkflowEngine.ts +107 -25
package/src/ai/LanguageModel.ts
CHANGED
|
@@ -122,7 +122,7 @@ export interface LanguageModel {
|
|
|
122
122
|
<Options extends NoExcessProperties<GenerateTextOptionsWithoutToolkit, Options>>(
|
|
123
123
|
options: Options & GenerateTextOptionsWithoutToolkit
|
|
124
124
|
): Effect.Effect<
|
|
125
|
-
GenerateTextResponse<{}
|
|
125
|
+
GenerateTextResponse<{}, ExtractToolParametersModeWithoutToolkit<Options>>,
|
|
126
126
|
ExtractError<Options>,
|
|
127
127
|
ExtractServices<Options>
|
|
128
128
|
>
|
|
@@ -181,7 +181,7 @@ export interface LanguageModel {
|
|
|
181
181
|
<Options extends NoExcessProperties<GenerateTextOptionsWithoutToolkit, Options>>(
|
|
182
182
|
options: Options & GenerateTextOptionsWithoutToolkit
|
|
183
183
|
): Stream.Stream<
|
|
184
|
-
Response.StreamPart<{}
|
|
184
|
+
Response.StreamPart<{}, ExtractToolParametersModeWithoutToolkit<Options>>,
|
|
185
185
|
ExtractError<Options>,
|
|
186
186
|
ExtractServices<Options>
|
|
187
187
|
>
|
|
@@ -312,6 +312,22 @@ export interface GenerateTextOptions<Tools extends Record<string, Tool.Any>> {
|
|
|
312
312
|
* resolver execution yourself.
|
|
313
313
|
*/
|
|
314
314
|
readonly disableToolCallResolution?: boolean | undefined
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Controls tool call validation when `disableToolCallResolution` is `true`.
|
|
318
|
+
* Defaults to `"strict"`, which validates tool names and encoded parameters.
|
|
319
|
+
*
|
|
320
|
+
* **Details**
|
|
321
|
+
*
|
|
322
|
+
* `"deferred"` returns model-generated calls with `unknown` parameters for
|
|
323
|
+
* the caller to validate, including undeclared names and calls without a
|
|
324
|
+
* toolkit. Provider-executed calls and other response parts remain validated.
|
|
325
|
+
* Providers must support this option to return undeclared tool calls.
|
|
326
|
+
*
|
|
327
|
+
* Has no effect when resolution is enabled; `Toolkit` validates parameters
|
|
328
|
+
* according to each tool's `failureMode`.
|
|
329
|
+
*/
|
|
330
|
+
readonly toolCallValidation?: "strict" | "deferred" | undefined
|
|
315
331
|
}
|
|
316
332
|
|
|
317
333
|
type GenerateTextOptionsWithoutToolkit = Omit<GenerateTextOptions<{}>, "toolkit"> & {
|
|
@@ -589,18 +605,32 @@ export type ExtractTools<Options> = Options extends {
|
|
|
589
605
|
: {}
|
|
590
606
|
|
|
591
607
|
/**
|
|
592
|
-
* Resolves to `"
|
|
593
|
-
*
|
|
608
|
+
* Resolves to `"deferred"` when tool call resolution may be disabled with
|
|
609
|
+
* deferred tool call validation. Otherwise resolves to `"encoded"` when tool
|
|
610
|
+
* call resolution is disabled and `"opaque"` when it may be enabled.
|
|
594
611
|
*
|
|
595
612
|
* @stability unstable
|
|
596
613
|
* @category utility types
|
|
597
614
|
* @since 4.0.0
|
|
598
615
|
*/
|
|
599
|
-
export type ExtractToolParametersMode<Options> =
|
|
600
|
-
|
|
601
|
-
} ? "encoded"
|
|
616
|
+
export type ExtractToolParametersMode<Options> = "deferred" extends Options["toolCallValidation" & keyof Options] ?
|
|
617
|
+
true extends Options["disableToolCallResolution" & keyof Options] ? "deferred" : "opaque"
|
|
618
|
+
: Options extends { readonly disableToolCallResolution: true } ? "encoded"
|
|
602
619
|
: "opaque"
|
|
603
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Resolves the tool parameters mode for requests without a toolkit:
|
|
623
|
+
* `"deferred"` when tool call validation may be deferred, otherwise
|
|
624
|
+
* `"decoded"`.
|
|
625
|
+
*
|
|
626
|
+
* @stability unstable
|
|
627
|
+
* @category utility types
|
|
628
|
+
* @since 4.0.4
|
|
629
|
+
*/
|
|
630
|
+
export type ExtractToolParametersModeWithoutToolkit<Options> = "deferred" extends ExtractToolParametersMode<Options>
|
|
631
|
+
? "deferred"
|
|
632
|
+
: "decoded"
|
|
633
|
+
|
|
604
634
|
type ExtractErrorFromToolkitOption<ToolkitValue, DisableToolCallResolution extends boolean> = ToolkitValue extends
|
|
605
635
|
Toolkit.WithHandler<infer Tools> ?
|
|
606
636
|
| AiError.AiError
|
|
@@ -785,6 +815,12 @@ export interface ProviderOptions {
|
|
|
785
815
|
* prompt after the provider rejected the incremental request.
|
|
786
816
|
*/
|
|
787
817
|
readonly incrementalFallback?: boolean | undefined
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Defaults to `"strict"`. With `"deferred"`, return calls to tools absent
|
|
821
|
+
* from `tools` with unchanged parameters instead of `ToolNotFoundError`.
|
|
822
|
+
*/
|
|
823
|
+
readonly toolCallValidation?: "strict" | "deferred" | undefined
|
|
788
824
|
}
|
|
789
825
|
|
|
790
826
|
/**
|
|
@@ -857,13 +893,20 @@ export const make: (params: {
|
|
|
857
893
|
Effect.map(Option.getOrElse(() => defaultIdGenerator))
|
|
858
894
|
)
|
|
859
895
|
|
|
896
|
+
const contentDecoderFor = makeResponseDecoder((toolkit, deferred) =>
|
|
897
|
+
Schema.decodeEffect(Schema.mutable(Schema.Array(withUndeclaredToolCalls(Response.Part(toolkit), deferred))))
|
|
898
|
+
)
|
|
899
|
+
const streamDecoderFor = makeResponseDecoder((toolkit, deferred) =>
|
|
900
|
+
Schema.decodeEffect(Schema.NonEmptyArray(withUndeclaredToolCalls(Response.StreamPart(toolkit), deferred)))
|
|
901
|
+
)
|
|
902
|
+
|
|
860
903
|
const generateText = <
|
|
861
904
|
Options extends NoExcessProperties<GenerateTextOptions<any>, Options>,
|
|
862
905
|
Tools extends Record<string, Tool.Any> = {}
|
|
863
906
|
>(
|
|
864
907
|
options: Options & GenerateTextOptions<Tools>
|
|
865
908
|
): Effect.Effect<
|
|
866
|
-
GenerateTextResponse<Tools>,
|
|
909
|
+
GenerateTextResponse<Tools, Response.ToolParametersMode>,
|
|
867
910
|
ExtractError<Options>,
|
|
868
911
|
ExtractServices<Options>
|
|
869
912
|
> =>
|
|
@@ -1071,6 +1114,10 @@ export const make: (params: {
|
|
|
1071
1114
|
const toolChoice = options.toolChoice ?? "auto"
|
|
1072
1115
|
const concurrency = options.concurrency ?? "unbounded"
|
|
1073
1116
|
annotateRequestOptions(providerOptions, toolChoice, concurrency)
|
|
1117
|
+
const deferToolCallValidation = isToolCallValidationDeferred(options)
|
|
1118
|
+
if (deferToolCallValidation) {
|
|
1119
|
+
providerOptions.toolCallValidation = "deferred"
|
|
1120
|
+
}
|
|
1074
1121
|
|
|
1075
1122
|
const generateWithNonIncrementalFallback = () => {
|
|
1076
1123
|
const requestOptions: ProviderOptions = {
|
|
@@ -1092,10 +1139,8 @@ export const make: (params: {
|
|
|
1092
1139
|
}
|
|
1093
1140
|
|
|
1094
1141
|
// Check for pending approvals that need resolution
|
|
1095
|
-
const { approved, denied } =
|
|
1096
|
-
providerOptions.prompt.content
|
|
1097
|
-
{ excludeResolved: true }
|
|
1098
|
-
)
|
|
1142
|
+
const { approved: allResolved, denied: allDenied, pendingApproved: approved, pendingDenied: denied } =
|
|
1143
|
+
collectToolApprovals(providerOptions.prompt.content)
|
|
1099
1144
|
const hasPendingApprovals = approved.length > 0 || denied.length > 0
|
|
1100
1145
|
|
|
1101
1146
|
// If there is no toolkit, the generated content can be returned immediately
|
|
@@ -1120,7 +1165,7 @@ export const make: (params: {
|
|
|
1120
1165
|
}
|
|
1121
1166
|
}
|
|
1122
1167
|
const ResponseSchema = Schema.mutable(
|
|
1123
|
-
Schema.Array(Response.Part(Toolkit.empty))
|
|
1168
|
+
Schema.Array(withUndeclaredToolCalls(Response.Part(Toolkit.empty), deferToolCallValidation))
|
|
1124
1169
|
)
|
|
1125
1170
|
const rawContent = yield* generateWithNonIncrementalFallback()
|
|
1126
1171
|
const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
|
|
@@ -1158,7 +1203,7 @@ export const make: (params: {
|
|
|
1158
1203
|
}
|
|
1159
1204
|
}
|
|
1160
1205
|
const ResponseSchema = Schema.mutable(
|
|
1161
|
-
Schema.Array(Response.Part(Toolkit.empty))
|
|
1206
|
+
Schema.Array(withUndeclaredToolCalls(Response.Part(Toolkit.empty), deferToolCallValidation))
|
|
1162
1207
|
)
|
|
1163
1208
|
const rawContent = yield* generateWithNonIncrementalFallback()
|
|
1164
1209
|
const content = yield* Schema.decodeEffect(ResponseSchema)(rawContent)
|
|
@@ -1205,17 +1250,12 @@ export const make: (params: {
|
|
|
1205
1250
|
|
|
1206
1251
|
// Strip all resolved approval artifacts (both current and from previous
|
|
1207
1252
|
// rounds) in a single pass before sending to the provider.
|
|
1208
|
-
{
|
|
1209
|
-
|
|
1210
|
-
providerOptions.prompt
|
|
1253
|
+
if (allResolved.length > 0 || allDenied.length > 0) {
|
|
1254
|
+
providerOptions.prompt = stripResolvedApprovals(
|
|
1255
|
+
providerOptions.prompt,
|
|
1256
|
+
allResolved,
|
|
1257
|
+
allDenied
|
|
1211
1258
|
)
|
|
1212
|
-
if (allResolved.length > 0 || allDenied.length > 0) {
|
|
1213
|
-
providerOptions.prompt = stripResolvedApprovals(
|
|
1214
|
-
providerOptions.prompt,
|
|
1215
|
-
allResolved,
|
|
1216
|
-
allDenied
|
|
1217
|
-
)
|
|
1218
|
-
}
|
|
1219
1259
|
}
|
|
1220
1260
|
|
|
1221
1261
|
const tools = typeof toolChoice === "object" && "oneOf" in toolChoice
|
|
@@ -1232,17 +1272,20 @@ export const make: (params: {
|
|
|
1232
1272
|
}
|
|
1233
1273
|
}
|
|
1234
1274
|
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
)
|
|
1275
|
+
const decodeContent = contentDecoderFor(
|
|
1276
|
+
toolkit,
|
|
1277
|
+
options.disableToolCallResolution === true && !deferToolCallValidation,
|
|
1278
|
+
deferToolCallValidation
|
|
1279
|
+
)
|
|
1240
1280
|
|
|
1241
1281
|
// If tool call resolution is disabled, return the response without
|
|
1242
1282
|
// resolving the tool calls that were generated
|
|
1243
1283
|
if (options.disableToolCallResolution === true) {
|
|
1244
1284
|
const rawContent = yield* generateWithNonIncrementalFallback()
|
|
1245
|
-
const content = yield*
|
|
1285
|
+
const content = yield* decodeContent(rawContent)
|
|
1286
|
+
if (deferToolCallValidation) {
|
|
1287
|
+
yield* validateProviderExecutedToolCalls(makeToolkitWithEncodedParameters(toolkit), rawContent)
|
|
1288
|
+
}
|
|
1246
1289
|
if (tracker) {
|
|
1247
1290
|
const responseMetadata = content.find((part) => part.type === "response-metadata")
|
|
1248
1291
|
if (Predicate.isNotUndefined(responseMetadata) && Predicate.isNotUndefined(responseMetadata.id)) {
|
|
@@ -1255,7 +1298,7 @@ export const make: (params: {
|
|
|
1255
1298
|
const rawContent = yield* generateWithNonIncrementalFallback()
|
|
1256
1299
|
|
|
1257
1300
|
// Validate before running tool handlers.
|
|
1258
|
-
const content = yield*
|
|
1301
|
+
const content = yield* decodeContent(rawContent)
|
|
1259
1302
|
yield* validateProviderExecutedToolCalls(toolkit, rawContent)
|
|
1260
1303
|
|
|
1261
1304
|
// Resolve the generated tool calls. When the finish reason indicates an
|
|
@@ -1324,6 +1367,10 @@ export const make: (params: {
|
|
|
1324
1367
|
const toolChoice = options.toolChoice ?? "auto"
|
|
1325
1368
|
const concurrency = options.concurrency ?? "unbounded"
|
|
1326
1369
|
annotateRequestOptions(providerOptions, toolChoice, concurrency)
|
|
1370
|
+
const deferToolCallValidation = isToolCallValidationDeferred(options)
|
|
1371
|
+
if (deferToolCallValidation) {
|
|
1372
|
+
providerOptions.toolCallValidation = "deferred"
|
|
1373
|
+
}
|
|
1327
1374
|
|
|
1328
1375
|
const streamWithNonIncrementalFallback = () => {
|
|
1329
1376
|
const requestOptions: ProviderOptions = {
|
|
@@ -1357,9 +1404,9 @@ export const make: (params: {
|
|
|
1357
1404
|
}
|
|
1358
1405
|
|
|
1359
1406
|
// Check for pending approvals that need resolution
|
|
1360
|
-
const { approved:
|
|
1361
|
-
|
|
1362
|
-
|
|
1407
|
+
const { approved: allResolved, denied: allDenied, pendingApproved, pendingDenied } = collectToolApprovals(
|
|
1408
|
+
providerOptions.prompt.content
|
|
1409
|
+
)
|
|
1363
1410
|
const hasPendingApprovals = pendingApproved.length > 0 || pendingDenied.length > 0
|
|
1364
1411
|
|
|
1365
1412
|
// If there is no toolkit, return immediately
|
|
@@ -1383,7 +1430,9 @@ export const make: (params: {
|
|
|
1383
1430
|
providerOptions.incrementalPrompt = prepared.value.prompt
|
|
1384
1431
|
}
|
|
1385
1432
|
}
|
|
1386
|
-
const schema = Schema.NonEmptyArray(
|
|
1433
|
+
const schema = Schema.NonEmptyArray(
|
|
1434
|
+
withUndeclaredToolCalls(Response.StreamPart(Toolkit.empty), deferToolCallValidation)
|
|
1435
|
+
)
|
|
1387
1436
|
const decodeParts = Schema.decodeEffect(schema)
|
|
1388
1437
|
return pipe(
|
|
1389
1438
|
streamWithNonIncrementalFallback(),
|
|
@@ -1432,7 +1481,9 @@ export const make: (params: {
|
|
|
1432
1481
|
providerOptions.incrementalPrompt = prepared.value.prompt
|
|
1433
1482
|
}
|
|
1434
1483
|
}
|
|
1435
|
-
const schema = Schema.NonEmptyArray(
|
|
1484
|
+
const schema = Schema.NonEmptyArray(
|
|
1485
|
+
withUndeclaredToolCalls(Response.StreamPart(Toolkit.empty), deferToolCallValidation)
|
|
1486
|
+
)
|
|
1436
1487
|
const decodeParts = Schema.decodeEffect(schema)
|
|
1437
1488
|
return pipe(
|
|
1438
1489
|
streamWithNonIncrementalFallback(),
|
|
@@ -1510,9 +1561,6 @@ export const make: (params: {
|
|
|
1510
1561
|
|
|
1511
1562
|
// Strip all resolved approval artifacts (both current and from previous
|
|
1512
1563
|
// rounds) in a single pass before sending to the provider.
|
|
1513
|
-
const { approved: allResolved, denied: allDenied } = collectToolApprovals(
|
|
1514
|
-
providerOptions.prompt.content
|
|
1515
|
-
)
|
|
1516
1564
|
if (allResolved.length > 0 || allDenied.length > 0) {
|
|
1517
1565
|
providerOptions.prompt = stripResolvedApprovals(
|
|
1518
1566
|
providerOptions.prompt,
|
|
@@ -1535,19 +1583,22 @@ export const make: (params: {
|
|
|
1535
1583
|
}
|
|
1536
1584
|
}
|
|
1537
1585
|
|
|
1538
|
-
const
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
)
|
|
1543
|
-
const decodeParts = Schema.decodeEffect(ResponseSchema)
|
|
1586
|
+
const decodeParts = streamDecoderFor(
|
|
1587
|
+
toolkit,
|
|
1588
|
+
options.disableToolCallResolution === true && !deferToolCallValidation,
|
|
1589
|
+
deferToolCallValidation
|
|
1590
|
+
)
|
|
1544
1591
|
|
|
1545
1592
|
// If tool call resolution is disabled, return the response without
|
|
1546
1593
|
// resolving the tool calls that were generated
|
|
1547
1594
|
if (options.disableToolCallResolution === true) {
|
|
1595
|
+
const encodedToolkit = deferToolCallValidation ? makeToolkitWithEncodedParameters(toolkit) : undefined
|
|
1548
1596
|
return streamWithNonIncrementalFallback().pipe(
|
|
1549
1597
|
Stream.mapArrayEffect((parts) =>
|
|
1550
1598
|
decodeParts(parts).pipe(
|
|
1599
|
+
encodedToolkit
|
|
1600
|
+
? Effect.tap(() => validateProviderExecutedToolCalls(encodedToolkit, parts))
|
|
1601
|
+
: identity,
|
|
1551
1602
|
tracker ?
|
|
1552
1603
|
Effect.tap((decodedParts) => {
|
|
1553
1604
|
for (const part of decodedParts) {
|
|
@@ -1577,8 +1628,7 @@ export const make: (params: {
|
|
|
1577
1628
|
const deferredFinishParts: Array<Response.StreamPart<Tools>> = []
|
|
1578
1629
|
|
|
1579
1630
|
// Emit pre-resolved tool results so Chat.streamText persists them to
|
|
1580
|
-
// history
|
|
1581
|
-
// find the corresponding tool-results on future rounds.
|
|
1631
|
+
// history, where collectToolApprovals finds them on future rounds.
|
|
1582
1632
|
if (preResolvedStreamParts.length > 0) {
|
|
1583
1633
|
yield* Queue.offerAll(queue, preResolvedStreamParts)
|
|
1584
1634
|
}
|
|
@@ -1812,7 +1862,7 @@ export const generateText: {
|
|
|
1812
1862
|
>(
|
|
1813
1863
|
options: Options & GenerateTextOptionsWithoutToolkit
|
|
1814
1864
|
): Effect.Effect<
|
|
1815
|
-
GenerateTextResponse<{}
|
|
1865
|
+
GenerateTextResponse<{}, ExtractToolParametersModeWithoutToolkit<Options>>,
|
|
1816
1866
|
ExtractError<Options>,
|
|
1817
1867
|
LanguageModel | ExtractServices<Options>
|
|
1818
1868
|
>
|
|
@@ -1962,7 +2012,7 @@ export const streamText: {
|
|
|
1962
2012
|
>(
|
|
1963
2013
|
options: Options & GenerateTextOptionsWithoutToolkit
|
|
1964
2014
|
): Stream.Stream<
|
|
1965
|
-
Response.StreamPart<{}
|
|
2015
|
+
Response.StreamPart<{}, ExtractToolParametersModeWithoutToolkit<Options>>,
|
|
1966
2016
|
ExtractError<Options>,
|
|
1967
2017
|
ExtractServices<Options> | LanguageModel
|
|
1968
2018
|
>
|
|
@@ -2011,16 +2061,13 @@ interface ApprovalResult {
|
|
|
2011
2061
|
readonly toolCall?: Prompt.ToolCallPart | undefined
|
|
2012
2062
|
}
|
|
2013
2063
|
|
|
2014
|
-
interface CollectToolApprovalsOptions {
|
|
2015
|
-
readonly excludeResolved?: boolean
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
2064
|
const collectToolApprovals = (
|
|
2019
|
-
messages: ReadonlyArray<Prompt.Message
|
|
2020
|
-
options?: CollectToolApprovalsOptions
|
|
2065
|
+
messages: ReadonlyArray<Prompt.Message>
|
|
2021
2066
|
): {
|
|
2022
2067
|
readonly approved: Array<ApprovalResult>
|
|
2023
2068
|
readonly denied: Array<ApprovalResult>
|
|
2069
|
+
readonly pendingApproved: Array<ApprovalResult>
|
|
2070
|
+
readonly pendingDenied: Array<ApprovalResult>
|
|
2024
2071
|
} => {
|
|
2025
2072
|
const requests = new Map<
|
|
2026
2073
|
string,
|
|
@@ -2063,15 +2110,12 @@ const collectToolApprovals = (
|
|
|
2063
2110
|
|
|
2064
2111
|
const approved: Array<ApprovalResult> = []
|
|
2065
2112
|
const denied: Array<ApprovalResult> = []
|
|
2113
|
+
const pendingApproved: Array<ApprovalResult> = []
|
|
2114
|
+
const pendingDenied: Array<ApprovalResult> = []
|
|
2066
2115
|
|
|
2067
2116
|
for (const response of responses) {
|
|
2068
2117
|
const request = requests.get(response.approvalId)
|
|
2069
2118
|
if (Predicate.isNotUndefined(request)) {
|
|
2070
|
-
// Skip if already resolved
|
|
2071
|
-
if (options?.excludeResolved && toolResultIds.has(request.toolCallId)) {
|
|
2072
|
-
continue
|
|
2073
|
-
}
|
|
2074
|
-
|
|
2075
2119
|
const result: ApprovalResult = {
|
|
2076
2120
|
...response,
|
|
2077
2121
|
toolCallId: request.toolCallId,
|
|
@@ -2080,13 +2124,15 @@ const collectToolApprovals = (
|
|
|
2080
2124
|
|
|
2081
2125
|
if (response.approved) {
|
|
2082
2126
|
approved.push(result)
|
|
2127
|
+
if (!toolResultIds.has(request.toolCallId)) pendingApproved.push(result)
|
|
2083
2128
|
} else {
|
|
2084
2129
|
denied.push(result)
|
|
2130
|
+
if (!toolResultIds.has(request.toolCallId)) pendingDenied.push(result)
|
|
2085
2131
|
}
|
|
2086
2132
|
}
|
|
2087
2133
|
}
|
|
2088
2134
|
|
|
2089
|
-
return { approved, denied }
|
|
2135
|
+
return { approved, denied, pendingApproved, pendingDenied }
|
|
2090
2136
|
}
|
|
2091
2137
|
|
|
2092
2138
|
/**
|
|
@@ -2415,6 +2461,27 @@ const resolveToolCalls = <Tools extends Record<string, Tool.Any>>(
|
|
|
2415
2461
|
// Utilities
|
|
2416
2462
|
// =============================================================================
|
|
2417
2463
|
|
|
2464
|
+
// Cache one decoder per model and response kind, keyed by validation mode
|
|
2465
|
+
// and tool names and schema identities in insertion order.
|
|
2466
|
+
const makeResponseDecoder = <Decode>(make: (toolkit: Toolkit.Any, deferred: boolean) => Decode) => {
|
|
2467
|
+
let cached: { readonly key: ReadonlyArray<unknown>; readonly decode: Decode } | undefined
|
|
2468
|
+
return (toolkit: Toolkit.WithHandler<any>, encoded: boolean, deferred: boolean): Decode => {
|
|
2469
|
+
const key: Array<unknown> = [encoded, deferred]
|
|
2470
|
+
for (const tool of Object.values(toolkit.tools as Record<string, Tool.Any>)) {
|
|
2471
|
+
key.push(tool.name, tool.parametersSchema, tool.successSchema, tool.failureSchema)
|
|
2472
|
+
}
|
|
2473
|
+
if (cached !== undefined && cached.key.length === key.length && cached.key.every((part, i) => part === key[i])) {
|
|
2474
|
+
return cached.decode
|
|
2475
|
+
}
|
|
2476
|
+
const decode = make(
|
|
2477
|
+
encoded ? makeToolkitWithEncodedParameters(toolkit) : makeToolkitWithOpaqueParameters(toolkit),
|
|
2478
|
+
deferred
|
|
2479
|
+
)
|
|
2480
|
+
cached = { key, decode }
|
|
2481
|
+
return decode
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2418
2485
|
// Stable parameter-mode copies let Response reuse each tool's part schemas.
|
|
2419
2486
|
const parameterModeTools = new WeakMap<Tool.Any, { encoded?: Tool.Any; opaque?: Tool.Any }>()
|
|
2420
2487
|
|
|
@@ -2443,9 +2510,20 @@ const makeToolkitWithOpaqueParameters = <Tools extends Record<string, Tool.Any>>
|
|
|
2443
2510
|
...Object.values(toolkit.tools).map((tool) => withParameterMode(tool, "opaque"))
|
|
2444
2511
|
)
|
|
2445
2512
|
|
|
2513
|
+
const isToolCallValidationDeferred = (options: GenerateTextOptions<any>): boolean =>
|
|
2514
|
+
options.disableToolCallResolution === true && options.toolCallValidation === "deferred"
|
|
2515
|
+
|
|
2516
|
+
const UndeclaredToolCallPart = Response.ToolCallPart("", Schema.Unknown).mapFields((fields) => ({
|
|
2517
|
+
...fields,
|
|
2518
|
+
name: Schema.String
|
|
2519
|
+
}))
|
|
2520
|
+
|
|
2521
|
+
const withUndeclaredToolCalls = <S extends Schema.Top>(partSchema: S, deferToolCallValidation: boolean): S =>
|
|
2522
|
+
deferToolCallValidation ? Schema.Union([partSchema, UndeclaredToolCallPart]) as any : partSchema
|
|
2523
|
+
|
|
2446
2524
|
// Provider-executed tools bypass Toolkit, so validate their parameters here.
|
|
2447
|
-
const validateProviderExecutedToolCalls =
|
|
2448
|
-
toolkit:
|
|
2525
|
+
const validateProviderExecutedToolCalls = (
|
|
2526
|
+
toolkit: { readonly tools: Record<string, Tool.Any> },
|
|
2449
2527
|
parts: ReadonlyArray<Response.PartEncoded | Response.StreamPartEncoded>
|
|
2450
2528
|
): Effect.Effect<void, Schema.SchemaError> =>
|
|
2451
2529
|
Effect.forEach(
|