effect 4.1.4 → 4.1.6
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/THIRD_PARTY_NOTICES.md +88 -0
- package/ai-docs/package.json +2 -2
- package/dist/Arbitrary.d.ts +44 -2
- package/dist/Arbitrary.d.ts.map +1 -1
- package/dist/Arbitrary.js +9 -1
- package/dist/Arbitrary.js.map +1 -1
- package/dist/BigInt.d.ts +200 -1
- package/dist/BigInt.d.ts.map +1 -1
- package/dist/BigInt.js +105 -9
- package/dist/BigInt.js.map +1 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +4 -2
- package/dist/Cache.js.map +1 -1
- package/dist/Cause.d.ts +3 -3
- package/dist/Cause.js +1 -1
- package/dist/Channel.d.ts +104 -7
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +73 -4
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +5 -0
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +7 -2
- package/dist/Chunk.js.map +1 -1
- package/dist/Clock.d.ts +5 -2
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +2 -1
- package/dist/Clock.js.map +1 -1
- package/dist/Codegen.d.ts +300 -0
- package/dist/Codegen.d.ts.map +1 -0
- package/dist/Codegen.js +526 -0
- package/dist/Codegen.js.map +1 -0
- package/dist/Config.d.ts +31 -2
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +12 -1
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +11 -1
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +17 -6
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Effect.d.ts +1008 -127
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +410 -49
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +4 -4
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +78 -65
- package/dist/Equal.js.map +1 -1
- package/dist/Equivalence.d.ts +11 -9
- package/dist/Equivalence.d.ts.map +1 -1
- package/dist/Equivalence.js +15 -12
- package/dist/Equivalence.js.map +1 -1
- package/dist/Fiber.d.ts +58 -8
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js +28 -4
- package/dist/Fiber.js.map +1 -1
- package/dist/FiberHandle.d.ts +81 -10
- package/dist/FiberHandle.d.ts.map +1 -1
- package/dist/FiberHandle.js +40 -8
- package/dist/FiberHandle.js.map +1 -1
- package/dist/FiberMap.d.ts +80 -10
- package/dist/FiberMap.d.ts.map +1 -1
- package/dist/FiberMap.js +37 -6
- package/dist/FiberMap.js.map +1 -1
- package/dist/FiberSet.d.ts +93 -8
- package/dist/FiberSet.d.ts.map +1 -1
- package/dist/FiberSet.js +46 -4
- package/dist/FiberSet.js.map +1 -1
- package/dist/Formatter.d.ts +2 -0
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +2 -0
- package/dist/Formatter.js.map +1 -1
- package/dist/Hash.d.ts.map +1 -1
- package/dist/Hash.js +24 -17
- package/dist/Hash.js.map +1 -1
- package/dist/LayerMap.d.ts +12 -3
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +12 -2
- package/dist/LayerMap.js.map +1 -1
- package/dist/LayerRef.d.ts +3 -3
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +3 -3
- package/dist/LayerRef.js.map +1 -1
- package/dist/Logger.d.ts +37 -13
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +39 -10
- package/dist/Logger.js.map +1 -1
- package/dist/Match.d.ts +35 -23
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js +16 -0
- package/dist/Match.js.map +1 -1
- package/dist/Metric.js +1 -1
- package/dist/Metric.js.map +1 -1
- package/dist/Option.d.ts +4 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +6 -2
- package/dist/Option.js.map +1 -1
- package/dist/Order.d.ts +7 -5
- package/dist/Order.d.ts.map +1 -1
- package/dist/Order.js +8 -3
- package/dist/Order.js.map +1 -1
- package/dist/Pool.d.ts +4 -3
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +21 -18
- package/dist/Pool.js.map +1 -1
- package/dist/Predicate.d.ts +4 -1
- package/dist/Predicate.d.ts.map +1 -1
- package/dist/Predicate.js +5 -1
- package/dist/Predicate.js.map +1 -1
- package/dist/Queue.d.ts +69 -22
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +40 -18
- package/dist/Queue.js.map +1 -1
- package/dist/Rational.d.ts +179 -0
- package/dist/Rational.d.ts.map +1 -1
- package/dist/Rational.js +63 -0
- package/dist/Rational.js.map +1 -1
- package/dist/Request.d.ts +20 -0
- package/dist/Request.d.ts.map +1 -1
- package/dist/Request.js +20 -0
- package/dist/Request.js.map +1 -1
- package/dist/Result.d.ts +3 -1
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js +5 -2
- package/dist/Result.js.map +1 -1
- package/dist/Schema.d.ts +90 -19
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +92 -414
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +11 -7
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +5 -6
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +14 -10
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +19 -64
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +1 -28
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +11 -10
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +12 -11
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/Scope.d.ts +12 -6
- package/dist/Scope.d.ts.map +1 -1
- package/dist/Scope.js +12 -6
- package/dist/Scope.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +8 -5
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js +18 -4
- package/dist/Semaphore.js.map +1 -1
- package/dist/Stream.d.ts +128 -5
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +179 -43
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +57 -3
- package/dist/String.d.ts.map +1 -1
- package/dist/String.js +63 -5
- package/dist/String.js.map +1 -1
- package/dist/Struct.d.ts +135 -1
- package/dist/Struct.d.ts.map +1 -1
- package/dist/Struct.js +64 -5
- package/dist/Struct.js.map +1 -1
- package/dist/TextDiff.d.ts +105 -0
- package/dist/TextDiff.d.ts.map +1 -1
- package/dist/TextDiff.js +137 -24
- package/dist/TextDiff.js.map +1 -1
- package/dist/Tracer.d.ts +10 -0
- package/dist/Tracer.d.ts.map +1 -1
- package/dist/Tracer.js +2 -0
- package/dist/Tracer.js.map +1 -1
- package/dist/TxPriorityQueue.js +2 -2
- package/dist/TxPriorityQueue.js.map +1 -1
- package/dist/ai/LanguageModel.d.ts.map +1 -1
- package/dist/ai/LanguageModel.js +1 -1
- package/dist/ai/LanguageModel.js.map +1 -1
- package/dist/ai/McpServer.d.ts +199 -4
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +143 -18
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Prompt.d.ts +3 -1
- package/dist/ai/Prompt.d.ts.map +1 -1
- package/dist/ai/Prompt.js +17 -3
- package/dist/ai/Prompt.js.map +1 -1
- package/dist/ai/Skill.d.ts +172 -0
- package/dist/ai/Skill.d.ts.map +1 -0
- package/dist/ai/Skill.js +209 -0
- package/dist/ai/Skill.js.map +1 -0
- package/dist/ai/Tool.d.ts +3 -2
- package/dist/ai/Tool.d.ts.map +1 -1
- package/dist/ai/Tool.js +3 -2
- package/dist/ai/Tool.js.map +1 -1
- package/dist/ai/Toolkit.d.ts.map +1 -1
- package/dist/ai/Toolkit.js +5 -1
- package/dist/ai/Toolkit.js.map +1 -1
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/chat/Chat.d.ts +90 -0
- package/dist/chat/Chat.d.ts.map +1 -0
- package/dist/chat/Chat.js +127 -0
- package/dist/chat/Chat.js.map +1 -0
- package/dist/chat/ChatAdapter.d.ts +386 -0
- package/dist/chat/ChatAdapter.d.ts.map +1 -0
- package/dist/chat/ChatAdapter.js +110 -0
- package/dist/chat/ChatAdapter.js.map +1 -0
- package/dist/chat/ChatError.d.ts +500 -0
- package/dist/chat/ChatError.d.ts.map +1 -0
- package/dist/chat/ChatError.js +521 -0
- package/dist/chat/ChatError.js.map +1 -0
- package/dist/chat/ChatEvent.d.ts +321 -0
- package/dist/chat/ChatEvent.d.ts.map +1 -0
- package/dist/chat/ChatEvent.js +163 -0
- package/dist/chat/ChatEvent.js.map +1 -0
- package/dist/chat/ChatHandler.d.ts +81 -0
- package/dist/chat/ChatHandler.d.ts.map +1 -0
- package/dist/chat/ChatHandler.js +85 -0
- package/dist/chat/ChatHandler.js.map +1 -0
- package/dist/chat/ChatInteraction.d.ts +1519 -0
- package/dist/chat/ChatInteraction.d.ts.map +1 -0
- package/dist/chat/ChatInteraction.js +1052 -0
- package/dist/chat/ChatInteraction.js.map +1 -0
- package/dist/chat/ChatMarkdown.d.ts +280 -0
- package/dist/chat/ChatMarkdown.d.ts.map +1 -0
- package/dist/chat/ChatMarkdown.js +1172 -0
- package/dist/chat/ChatMarkdown.js.map +1 -0
- package/dist/chat/ChatMessage.d.ts +224 -0
- package/dist/chat/ChatMessage.d.ts.map +1 -0
- package/dist/chat/ChatMessage.js +172 -0
- package/dist/chat/ChatMessage.js.map +1 -0
- package/dist/chat/ChatTest.d.ts +407 -0
- package/dist/chat/ChatTest.d.ts.map +1 -0
- package/dist/chat/ChatTest.js +2145 -0
- package/dist/chat/ChatTest.js.map +1 -0
- package/dist/chat/ChatThread.d.ts +92 -0
- package/dist/chat/ChatThread.d.ts.map +1 -0
- package/dist/chat/ChatThread.js +116 -0
- package/dist/chat/ChatThread.js.map +1 -0
- package/dist/chat/ChatUi.d.ts +362 -0
- package/dist/chat/ChatUi.d.ts.map +1 -0
- package/dist/chat/ChatUi.js +209 -0
- package/dist/chat/ChatUi.js.map +1 -0
- package/dist/chat/index.d.ts +60 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +61 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/internal/retries.d.ts +2 -0
- package/dist/chat/internal/retries.d.ts.map +1 -0
- package/dist/chat/internal/retries.js +7 -0
- package/dist/chat/internal/retries.js.map +1 -0
- package/dist/cli/CliOutput.d.ts.map +1 -1
- package/dist/cli/CliOutput.js +6 -7
- package/dist/cli/CliOutput.js.map +1 -1
- package/dist/cli/Command.d.ts +20 -2
- package/dist/cli/Command.d.ts.map +1 -1
- package/dist/cli/Command.js +4 -0
- package/dist/cli/Command.js.map +1 -1
- package/dist/cli/Prompt.d.ts +5 -6
- package/dist/cli/Prompt.d.ts.map +1 -1
- package/dist/cli/Prompt.js +9 -4
- package/dist/cli/Prompt.js.map +1 -1
- package/dist/cli/internal/command.d.ts +1 -1
- package/dist/cli/internal/command.d.ts.map +1 -1
- package/dist/cli/internal/config.d.ts +1 -1
- package/dist/cli/internal/config.d.ts.map +1 -1
- package/dist/cli/internal/config.js +3 -3
- package/dist/cli/internal/config.js.map +1 -1
- package/dist/cluster/ClusterCron.d.ts +21 -1
- package/dist/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/cluster/ClusterCron.js +24 -6
- package/dist/cluster/ClusterCron.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +183 -103
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +56 -0
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +18 -2
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/Sharding.d.ts.map +1 -1
- package/dist/cluster/Sharding.js +15 -3
- package/dist/cluster/Sharding.js.map +1 -1
- package/dist/cluster/ShardingConfig.d.ts +6 -0
- package/dist/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/cluster/ShardingConfig.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +58 -37
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/cluster/SqlRunnerStorage.js +18 -8
- package/dist/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/cluster/internal/entityActivation.js +2 -0
- package/dist/cluster/internal/entityActivation.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +20 -13
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/cluster/internal/entityReaper.js +1 -1
- package/dist/cluster/internal/entityReaper.js.map +1 -1
- package/dist/crypto/Kdf.d.ts +2 -1
- package/dist/crypto/Kdf.d.ts.map +1 -1
- package/dist/crypto/Kdf.js +2 -1
- package/dist/crypto/Kdf.js.map +1 -1
- package/dist/crypto/Password.d.ts +162 -0
- package/dist/crypto/Password.d.ts.map +1 -0
- package/dist/crypto/Password.js +217 -0
- package/dist/crypto/Password.js.map +1 -0
- package/dist/crypto/index.d.ts +5 -0
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +5 -0
- package/dist/crypto/index.js.map +1 -1
- package/dist/encoding/Base64.d.ts +63 -0
- package/dist/encoding/Base64.d.ts.map +1 -1
- package/dist/encoding/Base64.js +82 -1
- package/dist/encoding/Base64.js.map +1 -1
- package/dist/encoding/Base64Url.d.ts +1 -0
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +7 -1
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Csv.d.ts.map +1 -1
- package/dist/encoding/Csv.js +44 -16
- package/dist/encoding/Csv.js.map +1 -1
- package/dist/encoding/Hex.d.ts +5 -0
- package/dist/encoding/Hex.d.ts.map +1 -1
- package/dist/encoding/Hex.js +5 -0
- package/dist/encoding/Hex.js.map +1 -1
- package/dist/encoding/SchemaBinary.d.ts.map +1 -1
- package/dist/encoding/SchemaBinary.js +13 -124
- package/dist/encoding/SchemaBinary.js.map +1 -1
- package/dist/encoding/Sse.d.ts +1 -0
- package/dist/encoding/Sse.d.ts.map +1 -1
- package/dist/encoding/Sse.js +7 -5
- package/dist/encoding/Sse.js.map +1 -1
- package/dist/encoding/Xml.d.ts +153 -18
- package/dist/encoding/Xml.d.ts.map +1 -1
- package/dist/encoding/Xml.js +379 -57
- package/dist/encoding/Xml.js.map +1 -1
- package/dist/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/eventlog/EventJournal.js +3 -8
- package/dist/eventlog/EventJournal.js.map +1 -1
- package/dist/eventlog/SqlEventLogServerEncrypted.js +6 -8
- package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +2 -1
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +14 -10
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/FindMyWay/internal/router.js +163 -116
- package/dist/http/FindMyWay/internal/router.js.map +1 -1
- package/dist/http/FindMyWay.d.ts +99 -0
- package/dist/http/FindMyWay.d.ts.map +1 -1
- package/dist/http/FindMyWay.js +39 -0
- package/dist/http/FindMyWay.js.map +1 -1
- package/dist/http/Headers.d.ts +201 -3
- package/dist/http/Headers.d.ts.map +1 -1
- package/dist/http/Headers.js +205 -3
- package/dist/http/Headers.js.map +1 -1
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +12 -8
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientError.d.ts +1 -0
- package/dist/http/HttpClientError.d.ts.map +1 -1
- package/dist/http/HttpClientError.js +32 -9
- package/dist/http/HttpClientError.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +46 -0
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +15 -0
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts +132 -0
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +83 -0
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/http/HttpMiddleware.js +16 -9
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpRouter.d.ts +49 -1
- package/dist/http/HttpRouter.d.ts.map +1 -1
- package/dist/http/HttpRouter.js +70 -20
- package/dist/http/HttpRouter.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts +118 -0
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +67 -58
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/Mime.d.ts.map +1 -1
- package/dist/http/Mime.js +3 -2
- package/dist/http/Mime.js.map +1 -1
- package/dist/http/Multipart.d.ts.map +1 -1
- package/dist/http/Multipart.js +0 -5
- package/dist/http/Multipart.js.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
- package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
- package/dist/http/MultipartParser/internal/contentType.js +1 -1
- package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
- package/dist/http/internal/clientPath.d.ts +2 -0
- package/dist/http/internal/clientPath.d.ts.map +1 -0
- package/dist/http/internal/clientPath.js +24 -0
- package/dist/http/internal/clientPath.js.map +1 -0
- package/dist/http/internal/compression.d.ts.map +1 -1
- package/dist/http/internal/compression.js +2 -2
- package/dist/http/internal/compression.js.map +1 -1
- package/dist/http/internal/mediaType.d.ts.map +1 -0
- package/dist/{http-api → http}/internal/mediaType.js +4 -0
- package/dist/{http-api → http}/internal/mediaType.js.map +1 -1
- package/dist/http/internal/redactedPath.d.ts +2 -0
- package/dist/http/internal/redactedPath.d.ts.map +1 -0
- package/dist/http/internal/redactedPath.js +140 -0
- package/dist/http/internal/redactedPath.js.map +1 -0
- package/dist/http/internal/requestState.js +1 -0
- package/dist/http/internal/requestState.js.map +1 -1
- package/dist/http/internal/tracing.js +5 -3
- package/dist/http/internal/tracing.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +13 -2
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +43 -6
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +7 -3
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +29 -12
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/http-api/HttpApiEndpoint.js +1 -1
- package/dist/http-api/HttpApiEndpoint.js.map +1 -1
- package/dist/http-api/HttpApiScalar.d.ts +4 -0
- package/dist/http-api/HttpApiScalar.d.ts.map +1 -1
- package/dist/http-api/HttpApiScalar.js +10 -1
- package/dist/http-api/HttpApiScalar.js.map +1 -1
- package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
- package/dist/http-api/HttpApiSchema.js +1 -1
- package/dist/http-api/HttpApiSchema.js.map +1 -1
- package/dist/http-api/OpenApi.d.ts +2 -0
- package/dist/http-api/OpenApi.d.ts.map +1 -1
- package/dist/http-api/internal/httpApiScalar.js +5 -2
- package/dist/http-api/internal/httpApiScalar.js.map +1 -1
- package/dist/http-api/internal/redactedKeys.d.ts +2 -0
- package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
- package/dist/http-api/internal/redactedKeys.js +37 -0
- package/dist/http-api/internal/redactedKeys.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/arbitrary/model.js +0 -5
- package/dist/internal/arbitrary/model.js.map +1 -1
- package/dist/internal/arbitrary/regexp.js +2 -1
- package/dist/internal/arbitrary/regexp.js.map +1 -1
- package/dist/internal/arbitrary/runner.d.ts.map +1 -1
- package/dist/internal/arbitrary/runner.js +21 -16
- package/dist/internal/arbitrary/runner.js.map +1 -1
- package/dist/internal/arbitrary/schema.js +140 -23
- package/dist/internal/arbitrary/schema.js.map +1 -1
- package/dist/internal/base64.js +34 -2
- package/dist/internal/base64.js.map +1 -1
- package/dist/internal/codegen.d.ts +2 -0
- package/dist/internal/codegen.d.ts.map +1 -0
- package/dist/internal/codegen.js +59 -0
- package/dist/internal/codegen.js.map +1 -0
- package/dist/internal/core.js +3 -3
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +61 -29
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +30 -8
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/equal.js +14 -13
- package/dist/internal/equal.js.map +1 -1
- package/dist/internal/hash.js +4 -1
- package/dist/internal/hash.js.map +1 -1
- package/dist/internal/hashMap.js +7 -7
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/matcher.js +19 -18
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/record.js +18 -4
- package/dist/internal/record.js.map +1 -1
- package/dist/internal/result.js +1 -1
- package/dist/internal/result.js.map +1 -1
- package/dist/internal/schema/codeExpression.d.ts +4 -0
- package/dist/internal/schema/codeExpression.d.ts.map +1 -0
- package/dist/internal/schema/codeExpression.js +179 -0
- package/dist/internal/schema/codeExpression.js.map +1 -0
- package/dist/internal/schema/codeImports.d.ts +8 -0
- package/dist/internal/schema/codeImports.d.ts.map +1 -0
- package/dist/internal/schema/codeImports.js +135 -0
- package/dist/internal/schema/codeImports.js.map +1 -0
- package/dist/internal/schema/codeTokens.d.ts +8 -0
- package/dist/internal/schema/codeTokens.d.ts.map +1 -0
- package/dist/internal/schema/codeTokens.js +17 -0
- package/dist/internal/schema/codeTokens.js.map +1 -0
- package/dist/internal/schema/passthrough.d.ts +2 -0
- package/dist/internal/schema/passthrough.d.ts.map +1 -0
- package/dist/internal/schema/passthrough.js +8 -0
- package/dist/internal/schema/passthrough.js.map +1 -0
- package/dist/internal/schema/schemaCodegen.d.ts +2 -0
- package/dist/internal/schema/schemaCodegen.d.ts.map +1 -0
- package/dist/internal/schema/schemaCodegen.js +378 -0
- package/dist/internal/schema/schemaCodegen.js.map +1 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
- package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
- package/dist/internal/schema/toEquivalence.js +3 -4
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/schema/toJsonSchemaDocument.js +11 -4
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
- package/dist/internal/trie.js +51 -64
- package/dist/internal/trie.js.map +1 -1
- package/dist/internal/utf8.d.ts +2 -0
- package/dist/internal/utf8.d.ts.map +1 -0
- package/dist/internal/utf8.js +151 -0
- package/dist/internal/utf8.js.map +1 -0
- package/dist/internal/version.js +1 -1
- package/dist/jose/JoseError.d.ts +51 -1
- package/dist/jose/JoseError.d.ts.map +1 -1
- package/dist/jose/JoseError.js +25 -18
- package/dist/jose/JoseError.js.map +1 -1
- package/dist/jose/Jwks.d.ts +13 -0
- package/dist/jose/Jwks.d.ts.map +1 -1
- package/dist/jose/Jwks.js +10 -2
- package/dist/jose/Jwks.js.map +1 -1
- package/dist/jose/internal/compact.js +10 -5
- package/dist/jose/internal/compact.js.map +1 -1
- package/dist/observability/Otlp.d.ts +19 -0
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpExporter.d.ts +49 -13
- package/dist/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/observability/OtlpExporter.js +133 -50
- package/dist/observability/OtlpExporter.js.map +1 -1
- package/dist/observability/OtlpLogger.d.ts +14 -0
- package/dist/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/observability/OtlpLogger.js +15 -5
- package/dist/observability/OtlpLogger.js.map +1 -1
- package/dist/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/observability/OtlpMetrics.js +2 -0
- package/dist/observability/OtlpMetrics.js.map +1 -1
- package/dist/observability/OtlpTracer.d.ts +14 -0
- package/dist/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/observability/OtlpTracer.js +10 -2
- package/dist/observability/OtlpTracer.js.map +1 -1
- package/dist/observability/internal/otlpProtobuf.d.ts +4 -2
- package/dist/observability/internal/otlpProtobuf.d.ts.map +1 -1
- package/dist/observability/internal/otlpProtobuf.js +238 -156
- package/dist/observability/internal/otlpProtobuf.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +6 -4
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/persistence/PersistedQueue.js +20 -3
- package/dist/persistence/PersistedQueue.js.map +1 -1
- package/dist/protobuf/ProtobufDescriptor.d.ts +377 -0
- package/dist/protobuf/ProtobufDescriptor.d.ts.map +1 -0
- package/dist/protobuf/ProtobufDescriptor.js +135 -0
- package/dist/protobuf/ProtobufDescriptor.js.map +1 -0
- package/dist/protobuf/ProtobufDescriptorProto.d.ts +2083 -0
- package/dist/protobuf/ProtobufDescriptorProto.d.ts.map +1 -0
- package/dist/protobuf/ProtobufDescriptorProto.js +2674 -0
- package/dist/protobuf/ProtobufDescriptorProto.js.map +1 -0
- package/dist/protobuf/ProtobufMessage.d.ts +183 -0
- package/dist/protobuf/ProtobufMessage.d.ts.map +1 -0
- package/dist/protobuf/ProtobufMessage.js +232 -0
- package/dist/protobuf/ProtobufMessage.js.map +1 -0
- package/dist/protobuf/ProtobufReader.d.ts +350 -0
- package/dist/protobuf/ProtobufReader.d.ts.map +1 -0
- package/dist/protobuf/ProtobufReader.js +698 -0
- package/dist/protobuf/ProtobufReader.js.map +1 -0
- package/dist/protobuf/ProtobufWriter.d.ts +224 -0
- package/dist/protobuf/ProtobufWriter.d.ts.map +1 -0
- package/dist/protobuf/ProtobufWriter.js +483 -0
- package/dist/protobuf/ProtobufWriter.js.map +1 -0
- package/dist/protobuf/index.d.ts +30 -0
- package/dist/protobuf/index.d.ts.map +1 -0
- package/dist/protobuf/index.js +31 -0
- package/dist/protobuf/index.js.map +1 -0
- package/dist/protobuf/internal/binary.d.ts +2 -0
- package/dist/protobuf/internal/binary.d.ts.map +1 -0
- package/dist/protobuf/internal/binary.js +966 -0
- package/dist/protobuf/internal/binary.js.map +1 -0
- package/dist/protobuf/internal/resolve.d.ts +2 -0
- package/dist/protobuf/internal/resolve.d.ts.map +1 -0
- package/dist/protobuf/internal/resolve.js +463 -0
- package/dist/protobuf/internal/resolve.js.map +1 -0
- package/dist/protobuf/internal/wireType.d.ts +2 -0
- package/dist/protobuf/internal/wireType.d.ts.map +1 -0
- package/dist/protobuf/internal/wireType.js +10 -0
- package/dist/protobuf/internal/wireType.js.map +1 -0
- package/dist/reactivity/AsyncResult.d.ts +3 -0
- package/dist/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/reactivity/AsyncResult.js +4 -1
- package/dist/reactivity/AsyncResult.js.map +1 -1
- package/dist/reactivity/Atom.d.ts +10 -4
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +48 -22
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/reactivity/AtomHttpApi.d.ts +5 -0
- package/dist/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/reactivity/AtomHttpApi.js +5 -1
- package/dist/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/reactivity/AtomRegistry.js +13 -0
- package/dist/reactivity/AtomRegistry.js.map +1 -1
- package/dist/reactivity/AtomRpc.d.ts +5 -0
- package/dist/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/reactivity/AtomRpc.js +6 -1
- package/dist/reactivity/AtomRpc.js.map +1 -1
- package/dist/rpc/Rpc.d.ts +25 -0
- package/dist/rpc/Rpc.d.ts.map +1 -1
- package/dist/rpc/Rpc.js +18 -0
- package/dist/rpc/Rpc.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +70 -22
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcGroup.d.ts +6 -1
- package/dist/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/rpc/RpcGroup.js +4 -0
- package/dist/rpc/RpcGroup.js.map +1 -1
- package/dist/rpc/RpcMiddleware.d.ts +9 -0
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js.map +1 -1
- package/dist/rpc/RpcSerialization.d.ts +7 -1
- package/dist/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/rpc/RpcSerialization.js +22 -5
- package/dist/rpc/RpcSerialization.js.map +1 -1
- package/dist/rpc/RpcServer.d.ts.map +1 -1
- package/dist/rpc/RpcServer.js +33 -18
- package/dist/rpc/RpcServer.js.map +1 -1
- package/dist/schema/SchemaCompiler/runtime.js +2 -1
- package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
- package/dist/schema/VariantSchema.d.ts +10 -2
- package/dist/schema/VariantSchema.d.ts.map +1 -1
- package/dist/schema/VariantSchema.js +7 -1
- package/dist/schema/VariantSchema.js.map +1 -1
- package/dist/socket/Socket.d.ts +24 -10
- package/dist/socket/Socket.d.ts.map +1 -1
- package/dist/socket/Socket.js +52 -17
- package/dist/socket/Socket.js.map +1 -1
- package/dist/sql/Migrator.d.ts +3 -0
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +12 -6
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -1
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/sql/SqlModel.d.ts.map +1 -1
- package/dist/sql/SqlModel.js +1 -0
- package/dist/sql/SqlModel.js.map +1 -1
- package/dist/testing/TestConsole.d.ts +96 -0
- package/dist/testing/TestConsole.d.ts.map +1 -1
- package/dist/testing/TestConsole.js +78 -6
- package/dist/testing/TestConsole.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +5 -1
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +7 -2
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/workers/SharedMemory.d.ts +115 -0
- package/dist/workers/SharedMemory.d.ts.map +1 -0
- package/dist/workers/SharedMemory.js +149 -0
- package/dist/workers/SharedMemory.js.map +1 -0
- package/dist/workers/Transferable.d.ts.map +1 -1
- package/dist/workers/Transferable.js +1 -4
- package/dist/workers/Transferable.js.map +1 -1
- package/dist/workers/index.d.ts +5 -0
- package/dist/workers/index.d.ts.map +1 -1
- package/dist/workers/index.js +5 -0
- package/dist/workers/index.js.map +1 -1
- package/dist/workflow/Activity.d.ts +18 -0
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/Activity.js +13 -4
- package/dist/workflow/Activity.js.map +1 -1
- package/dist/workflow/Workflow.d.ts +10 -9
- package/dist/workflow/Workflow.d.ts.map +1 -1
- package/dist/workflow/Workflow.js +33 -22
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +28 -12
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/dist/workflow/internal/retry.d.ts +2 -0
- package/dist/workflow/internal/retry.d.ts.map +1 -0
- package/dist/workflow/internal/retry.js +11 -0
- package/dist/workflow/internal/retry.js.map +1 -0
- package/dist/workflow/internal/scope.d.ts +2 -0
- package/dist/workflow/internal/scope.d.ts.map +1 -0
- package/dist/workflow/internal/scope.js +26 -0
- package/dist/workflow/internal/scope.js.map +1 -0
- package/package.json +8 -5
- package/src/Arbitrary.ts +60 -3
- package/src/BigInt.ts +247 -9
- package/src/Cache.ts +4 -2
- package/src/Cause.ts +3 -3
- package/src/Channel.ts +105 -8
- package/src/Chunk.ts +7 -3
- package/src/Clock.ts +5 -2
- package/src/Codegen.ts +746 -0
- package/src/Config.ts +35 -4
- package/src/ConfigProvider.ts +24 -7
- package/src/Effect.ts +1095 -157
- package/src/Equal.ts +85 -79
- package/src/Equivalence.ts +16 -13
- package/src/Fiber.ts +58 -8
- package/src/FiberHandle.ts +86 -12
- package/src/FiberMap.ts +83 -10
- package/src/FiberSet.ts +96 -8
- package/src/Formatter.ts +2 -0
- package/src/Hash.ts +30 -22
- package/src/LayerMap.ts +14 -4
- package/src/LayerRef.ts +8 -6
- package/src/Logger.ts +68 -25
- package/src/Match.ts +94 -50
- package/src/Metric.ts +1 -1
- package/src/Option.ts +9 -5
- package/src/Order.ts +10 -5
- package/src/Pool.ts +22 -17
- package/src/Predicate.ts +7 -3
- package/src/Queue.ts +84 -31
- package/src/Rational.ts +198 -0
- package/src/Request.ts +20 -0
- package/src/Result.ts +9 -6
- package/src/Schema.ts +145 -325
- package/src/SchemaAST.ts +15 -5
- package/src/SchemaGetter.ts +17 -10
- package/src/SchemaRepresentation.ts +19 -74
- package/src/SchemaTransformation.ts +12 -11
- package/src/Scope.ts +12 -6
- package/src/ScopedCache.ts +8 -5
- package/src/Semaphore.ts +18 -4
- package/src/Stream.ts +233 -53
- package/src/String.ts +84 -7
- package/src/Struct.ts +138 -5
- package/src/TextDiff.ts +186 -30
- package/src/Tracer.ts +10 -0
- package/src/TxPriorityQueue.ts +2 -2
- package/src/ai/LanguageModel.ts +2 -1
- package/src/ai/McpServer.ts +306 -26
- package/src/ai/Prompt.ts +20 -3
- package/src/ai/Skill.ts +236 -0
- package/src/ai/Tool.ts +3 -2
- package/src/ai/Toolkit.ts +3 -1
- package/src/ai/index.ts +6 -0
- package/src/chat/Chat.ts +164 -0
- package/src/chat/ChatAdapter.ts +444 -0
- package/src/chat/ChatError.ts +684 -0
- package/src/chat/ChatEvent.ts +221 -0
- package/src/chat/ChatHandler.ts +102 -0
- package/src/chat/ChatInteraction.ts +1979 -0
- package/src/chat/ChatMarkdown.ts +1406 -0
- package/src/chat/ChatMessage.ts +213 -0
- package/src/chat/ChatTest.ts +2606 -0
- package/src/chat/ChatThread.ts +132 -0
- package/src/chat/ChatUi.ts +320 -0
- package/src/chat/index.ts +72 -0
- package/src/chat/internal/retries.ts +7 -0
- package/src/cli/CliOutput.ts +4 -5
- package/src/cli/Command.ts +20 -2
- package/src/cli/Prompt.ts +15 -9
- package/src/cli/internal/config.ts +8 -8
- package/src/cluster/ClusterCron.ts +33 -10
- package/src/cluster/ClusterWorkflowEngine.ts +214 -119
- package/src/cluster/MessageStorage.ts +51 -2
- package/src/cluster/Sharding.ts +17 -3
- package/src/cluster/ShardingConfig.ts +3 -0
- package/src/cluster/SqlMessageStorage.ts +97 -54
- package/src/cluster/SqlRunnerStorage.ts +21 -8
- package/src/cluster/internal/entityActivation.ts +6 -0
- package/src/cluster/internal/entityManager.ts +27 -14
- package/src/cluster/internal/entityReaper.ts +1 -1
- package/src/crypto/Kdf.ts +2 -1
- package/src/crypto/Password.ts +258 -0
- package/src/crypto/index.ts +6 -0
- package/src/encoding/Base64.ts +84 -1
- package/src/encoding/Base64Url.ts +7 -1
- package/src/encoding/Csv.ts +47 -20
- package/src/encoding/Hex.ts +5 -0
- package/src/encoding/SchemaBinary.ts +13 -79
- package/src/encoding/Sse.ts +7 -5
- package/src/encoding/Xml.ts +485 -68
- package/src/eventlog/EventJournal.ts +3 -8
- package/src/eventlog/SqlEventLogServerEncrypted.ts +9 -9
- package/src/http/FetchHttpClient.ts +8 -5
- package/src/http/FindMyWay/internal/router.ts +181 -129
- package/src/http/FindMyWay.ts +106 -0
- package/src/http/Headers.ts +309 -3
- package/src/http/HttpClient.ts +21 -8
- package/src/http/HttpClientError.ts +42 -9
- package/src/http/HttpClientRequest.ts +51 -0
- package/src/http/HttpClientResponse.ts +156 -0
- package/src/http/HttpMiddleware.ts +23 -10
- package/src/http/HttpRouter.ts +84 -20
- package/src/http/HttpServerResponse.ts +159 -61
- package/src/http/Mime.ts +3 -2
- package/src/http/Multipart.ts +0 -5
- package/src/http/MultipartParser/internal/contentType.ts +1 -1
- package/src/http/internal/clientPath.ts +39 -0
- package/src/http/internal/compression.ts +2 -2
- package/src/{http-api → http}/internal/mediaType.ts +4 -0
- package/src/http/internal/redactedPath.ts +148 -0
- package/src/http/internal/requestState.ts +2 -0
- package/src/http/internal/tracing.ts +6 -3
- package/src/http-api/HttpApi.ts +50 -6
- package/src/http-api/HttpApiBuilder.ts +11 -3
- package/src/http-api/HttpApiClient.ts +40 -13
- package/src/http-api/HttpApiEndpoint.ts +1 -1
- package/src/http-api/HttpApiScalar.ts +9 -1
- package/src/http-api/HttpApiSchema.ts +1 -1
- package/src/http-api/OpenApi.ts +2 -0
- package/src/http-api/internal/httpApiScalar.ts +5 -1
- package/src/http-api/internal/redactedKeys.ts +40 -0
- package/src/index.ts +6 -0
- package/src/internal/arbitrary/model.ts +3 -9
- package/src/internal/arbitrary/regexp.ts +3 -1
- package/src/internal/arbitrary/runner.ts +28 -14
- package/src/internal/arbitrary/schema.ts +140 -35
- package/src/internal/base64.ts +57 -2
- package/src/internal/codegen.ts +53 -0
- package/src/internal/core.ts +3 -3
- package/src/internal/dateTime.ts +73 -37
- package/src/internal/effect.ts +56 -111
- package/src/internal/equal.ts +37 -17
- package/src/internal/hash.ts +5 -1
- package/src/internal/hashMap.ts +8 -7
- package/src/internal/matcher.ts +36 -114
- package/src/internal/record.ts +19 -4
- package/src/internal/result.ts +1 -1
- package/src/internal/schema/codeExpression.ts +179 -0
- package/src/internal/schema/codeImports.ts +142 -0
- package/src/internal/schema/codeTokens.ts +39 -0
- package/src/internal/schema/passthrough.ts +8 -0
- package/src/internal/schema/schemaCodegen.ts +544 -0
- package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
- package/src/internal/schema/toEquivalence.ts +3 -5
- package/src/internal/schema/toJsonSchemaDocument.ts +13 -4
- package/src/internal/trie.ts +46 -60
- package/src/internal/utf8.ts +106 -0
- package/src/internal/version.ts +1 -1
- package/src/jose/JoseError.ts +34 -0
- package/src/jose/Jwks.ts +23 -4
- package/src/jose/internal/compact.ts +14 -5
- package/src/observability/Otlp.ts +29 -0
- package/src/observability/OtlpExporter.ts +209 -76
- package/src/observability/OtlpLogger.ts +29 -5
- package/src/observability/OtlpMetrics.ts +2 -0
- package/src/observability/OtlpTracer.ts +24 -3
- package/src/observability/internal/otlpProtobuf.ts +386 -457
- package/src/persistence/KeyValueStore.ts +17 -14
- package/src/persistence/PersistedQueue.ts +21 -4
- package/src/protobuf/ProtobufDescriptor.ts +503 -0
- package/src/protobuf/ProtobufDescriptorProto.ts +3611 -0
- package/src/protobuf/ProtobufMessage.ts +277 -0
- package/src/protobuf/ProtobufReader.ts +756 -0
- package/src/protobuf/ProtobufWriter.ts +530 -0
- package/src/protobuf/index.ts +36 -0
- package/src/protobuf/internal/binary.ts +1215 -0
- package/src/protobuf/internal/resolve.ts +533 -0
- package/src/protobuf/internal/wireType.ts +9 -0
- package/src/reactivity/AsyncResult.ts +6 -1
- package/src/reactivity/Atom.ts +67 -34
- package/src/reactivity/AtomHttpApi.ts +10 -1
- package/src/reactivity/AtomRegistry.ts +16 -0
- package/src/reactivity/AtomRpc.ts +11 -1
- package/src/rpc/Rpc.ts +31 -0
- package/src/rpc/RpcClient.ts +56 -22
- package/src/rpc/RpcGroup.ts +9 -1
- package/src/rpc/RpcMiddleware.ts +9 -0
- package/src/rpc/RpcSerialization.ts +26 -6
- package/src/rpc/RpcServer.ts +33 -20
- package/src/schema/SchemaCompiler/runtime.ts +2 -3
- package/src/schema/VariantSchema.ts +12 -4
- package/src/socket/Socket.ts +67 -20
- package/src/sql/Migrator.ts +10 -12
- package/src/sql/SqlClient.ts +14 -8
- package/src/sql/SqlModel.ts +4 -0
- package/src/testing/TestConsole.ts +119 -9
- package/src/testing/TestSchema.ts +8 -3
- package/src/workers/SharedMemory.ts +227 -0
- package/src/workers/Transferable.ts +1 -5
- package/src/workers/index.ts +6 -0
- package/src/workflow/Activity.ts +28 -4
- package/src/workflow/Workflow.ts +68 -44
- package/src/workflow/WorkflowEngine.ts +41 -16
- package/src/workflow/internal/retry.ts +12 -0
- package/src/workflow/internal/scope.ts +36 -0
- package/dist/http-api/internal/mediaType.d.ts.map +0 -1
- package/dist/internal/schema/toCodeDocument.d.ts +0 -2
- package/dist/internal/schema/toCodeDocument.d.ts.map +0 -1
- package/dist/internal/schema/toCodeDocument.js +0 -447
- package/dist/internal/schema/toCodeDocument.js.map +0 -1
- package/dist/observability/internal/protobuf.d.ts +0 -2
- package/dist/observability/internal/protobuf.d.ts.map +0 -1
- package/dist/observability/internal/protobuf.js +0 -169
- package/dist/observability/internal/protobuf.js.map +0 -1
- package/src/internal/schema/toCodeDocument.ts +0 -578
- package/src/observability/internal/protobuf.ts +0 -225
- /package/dist/{http-api → http}/internal/mediaType.d.ts +0 -0
|
@@ -0,0 +1,2145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing tools for chat adapters and their consumers.
|
|
3
|
+
*
|
|
4
|
+
* `layer` builds a whole chat in memory: `Chat`, its registry and one fake
|
|
5
|
+
* adapter with configurable capabilities and fault injection. `conformance`
|
|
6
|
+
* is the suite of rules every adapter obeys, as plain Effects keyed by rule
|
|
7
|
+
* name. `checkMessage`, `checkEvent` and `checkInteraction` assert the
|
|
8
|
+
* invariants every message, event and interaction holds, for fixture tests
|
|
9
|
+
* and live runs.
|
|
10
|
+
*
|
|
11
|
+
* **Details**
|
|
12
|
+
*
|
|
13
|
+
* The fake adapter's mention syntax is `<@id>` for a user, `<@&id>` for a
|
|
14
|
+
* role, `<#id>` for a channel and `<!id>` for a broadcast.
|
|
15
|
+
*
|
|
16
|
+
* @stability unstable
|
|
17
|
+
* @since 4.1.5
|
|
18
|
+
*/
|
|
19
|
+
import * as Bytes from "../Bytes.js";
|
|
20
|
+
import * as Clock from "../Clock.js";
|
|
21
|
+
import * as Context from "../Context.js";
|
|
22
|
+
import * as DateTime from "../DateTime.js";
|
|
23
|
+
import * as Duration from "../Duration.js";
|
|
24
|
+
import * as Effect from "../Effect.js";
|
|
25
|
+
import * as Exit from "../Exit.js";
|
|
26
|
+
import * as Layer from "../Layer.js";
|
|
27
|
+
import * as Option from "../Option.js";
|
|
28
|
+
import * as Predicate from "../Predicate.js";
|
|
29
|
+
import * as Schema from "../Schema.js";
|
|
30
|
+
import * as Stream from "../Stream.js";
|
|
31
|
+
import * as Str from "../String.js";
|
|
32
|
+
import * as Chat from "./Chat.js";
|
|
33
|
+
import { checkMessageLength, Registry, retrySafe } from "./ChatAdapter.js";
|
|
34
|
+
import { Capability, ChatError, fileRefused, Forbidden, interactionExpired, InvalidRequest, isChatError, NotFound, RateLimited, TooLarge, Transport, Unsupported } from "./ChatError.js";
|
|
35
|
+
import * as ChatEvent from "./ChatEvent.js";
|
|
36
|
+
import { ChatHandler } from "./ChatHandler.js";
|
|
37
|
+
import * as ChatInteraction from "./ChatInteraction.js";
|
|
38
|
+
import * as ChatMessage from "./ChatMessage.js";
|
|
39
|
+
import * as ChatThread from "./ChatThread.js";
|
|
40
|
+
/**
|
|
41
|
+
* Error for a click on an element the message does not carry, or on a
|
|
42
|
+
* message that is gone.
|
|
43
|
+
*
|
|
44
|
+
* @stability unstable
|
|
45
|
+
* @category errors
|
|
46
|
+
* @since 4.1.5
|
|
47
|
+
*/
|
|
48
|
+
export class NoSuchElement extends /*#__PURE__*/Schema.TaggedError("effect/chat/ChatTest/NoSuchElement")("NoSuchElement", {
|
|
49
|
+
messageId: Schema.String,
|
|
50
|
+
id: Schema.String
|
|
51
|
+
}) {}
|
|
52
|
+
/**
|
|
53
|
+
* Service that controls the fake adapter built by `layer`.
|
|
54
|
+
*
|
|
55
|
+
* **Details**
|
|
56
|
+
*
|
|
57
|
+
* - `makeThread` creates a fresh address: a channel by default, a direct
|
|
58
|
+
* conversation, or a thread under a user's message in a fresh channel.
|
|
59
|
+
* - `userPosts` puts another identity's message in a thread and returns its
|
|
60
|
+
* event without delivering it. `deliver` delivers an event the way an
|
|
61
|
+
* adapter does, by calling the `ChatHandler` service.
|
|
62
|
+
* - `messages` is what a thread shows now, oldest first, and `calls` is every
|
|
63
|
+
* call the adapter received.
|
|
64
|
+
* - `failNext` makes the next `times` calls of `op` fail with `reason`.
|
|
65
|
+
* `landed` makes the write happen anyway, which is what `uncertain` means.
|
|
66
|
+
* The native stream's ops are `nativeStream.start`, `nativeStream.append`
|
|
67
|
+
* and `nativeStream.stop`.
|
|
68
|
+
* - `refuseFiles` makes the next `times` posts with files fail `denied` with
|
|
69
|
+
* detail `file_refused`, storing nothing. Text-only posts do not consume it.
|
|
70
|
+
* - `clickStop` is a user clicking stop on a native stream. It closes
|
|
71
|
+
* nothing, as on Slack: the stream keeps taking text, and
|
|
72
|
+
* `NativeStream.stop` then reports `stopped: true`.
|
|
73
|
+
* - `closeStream` closes a native stream from outside, so the next append
|
|
74
|
+
* gives `closed`, or `stopped` after a click.
|
|
75
|
+
* - `click` builds the click on element `id` of a message from what the
|
|
76
|
+
* fake stored at `post` or `edit`, without delivering it. For a select,
|
|
77
|
+
* `option` is the encoded value of the option to choose, the first by
|
|
78
|
+
* default. It fails `NoSuchElement` when the message has no such element,
|
|
79
|
+
* or no such option, or is gone.
|
|
80
|
+
* - `command` builds a command typed at `thread`, without delivering it.
|
|
81
|
+
* `text` defaults to the empty string. The fake has no registration, so
|
|
82
|
+
* any id can be typed.
|
|
83
|
+
* - `submit` builds the submit of a modal. It takes the click or the command
|
|
84
|
+
* that opened it, because an `OpenModal` reply does not say where it was
|
|
85
|
+
* opened from and a `ModalSubmitted` has to. A command gives a submit
|
|
86
|
+
* with no `messageId`. `values` are by field id, still encoded, and an
|
|
87
|
+
* empty one is left out, as for an optional field left empty.
|
|
88
|
+
* - `interact` delivers an interaction the way an adapter does: through
|
|
89
|
+
* `ChatInteraction.handle` with the layer's `interactionDeadline`, then
|
|
90
|
+
* the fake's own checks on an `OpenModal` (the `modals` capability,
|
|
91
|
+
* `limits.modalMetadataLength` against the modal's id plus its encoded
|
|
92
|
+
* metadata, and `limits.modalFields`), calling `Handler.refused` when one
|
|
93
|
+
* fails. It succeeds with the handler's reply as it returned it, or
|
|
94
|
+
* `Late`. An `OpenModal` shows in `calls` as op `openModal`.
|
|
95
|
+
* - For a command, `interact` runs the checks of `post` on a `Respond`
|
|
96
|
+
* (the element capabilities, `limits.messageLength` and the element
|
|
97
|
+
* limits), and refuses a private `Respond` or `Defer` without
|
|
98
|
+
* `ephemeral`. A `Respond` shows in `calls` as op `respond`, and a
|
|
99
|
+
* `followUp` as op `followUp`, each with the command's thread and the
|
|
100
|
+
* Markdown. Neither is stored as a message.
|
|
101
|
+
* - The fake's `followUp` succeeds once for a `Defer` that `interact`
|
|
102
|
+
* returned, inside `limits.followUpAge` on `Clock`. Later, a second time,
|
|
103
|
+
* or for a deferral the fake never saw, it fails `NotFound` with detail
|
|
104
|
+
* `interaction_expired`. Failing the second call is stricter than either
|
|
105
|
+
* platform, to catch a handler that relies on more than one: Slack posts
|
|
106
|
+
* another message and Discord replaces the first.
|
|
107
|
+
*
|
|
108
|
+
* @stability unstable
|
|
109
|
+
* @category services
|
|
110
|
+
* @since 4.1.5
|
|
111
|
+
*/
|
|
112
|
+
export class ChatTest extends /*#__PURE__*/Context.Service()("effect/chat/ChatTest") {}
|
|
113
|
+
// -----------------------------------------------------------------------------
|
|
114
|
+
// fake adapter
|
|
115
|
+
// -----------------------------------------------------------------------------
|
|
116
|
+
const allCapabilities = Capability.literals;
|
|
117
|
+
/** Counts code points. */
|
|
118
|
+
const codePoints = markdown => {
|
|
119
|
+
let count = 0;
|
|
120
|
+
for (const _ of markdown) count++;
|
|
121
|
+
return count;
|
|
122
|
+
};
|
|
123
|
+
/** An append holds back an unclosed `<` tail, as Slack does, up to this many characters. */
|
|
124
|
+
const heldBound = 100;
|
|
125
|
+
const mentionPattern = /<(@&|@|#|!)([^<>\s]+)>/g;
|
|
126
|
+
const mentionKinds = {
|
|
127
|
+
"@": "user",
|
|
128
|
+
"@&": "role",
|
|
129
|
+
"#": "channel",
|
|
130
|
+
"!": "broadcast"
|
|
131
|
+
};
|
|
132
|
+
const parseMentions = (text, selfId) => Array.from(text.matchAll(mentionPattern), match => {
|
|
133
|
+
const kind = mentionKinds[match[1]];
|
|
134
|
+
return {
|
|
135
|
+
kind,
|
|
136
|
+
id: match[2],
|
|
137
|
+
start: match.index,
|
|
138
|
+
end: match.index + match[0].length,
|
|
139
|
+
isSelf: kind === "user" && match[2] === selfId
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
const downloadChunkSize = 1024;
|
|
143
|
+
const makeFake = options => {
|
|
144
|
+
const {
|
|
145
|
+
platform,
|
|
146
|
+
selfId
|
|
147
|
+
} = options;
|
|
148
|
+
const capabilities = new Set(options.capabilities);
|
|
149
|
+
const messageLength = options.limits.messageLength ?? 4000;
|
|
150
|
+
const hasActions = capabilities.has("buttons") || capabilities.has("selects");
|
|
151
|
+
const descriptor = {
|
|
152
|
+
platform,
|
|
153
|
+
capabilities,
|
|
154
|
+
measure: options.measure,
|
|
155
|
+
limits: {
|
|
156
|
+
messageLength,
|
|
157
|
+
filesPerMessage: 10,
|
|
158
|
+
uploadBytes: 10 * 1024 * 1024,
|
|
159
|
+
minWriteInterval: Duration.zero,
|
|
160
|
+
...(capabilities.has("nativeStream") ? {
|
|
161
|
+
streamLength: messageLength,
|
|
162
|
+
streamAge: Duration.minutes(10)
|
|
163
|
+
} : {}),
|
|
164
|
+
...(hasActions ? {
|
|
165
|
+
actionsPerMessage: 25,
|
|
166
|
+
actionDataLength: 100
|
|
167
|
+
} : {}),
|
|
168
|
+
...(capabilities.has("modals") ? {
|
|
169
|
+
modalMetadataLength: 100,
|
|
170
|
+
modalFields: 5
|
|
171
|
+
} : {}),
|
|
172
|
+
...(capabilities.has("commands") ? {
|
|
173
|
+
followUpAge: Duration.minutes(15)
|
|
174
|
+
} : {}),
|
|
175
|
+
...options.limits
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const streams = new Map();
|
|
179
|
+
const threads = new Map();
|
|
180
|
+
const messages = new Map();
|
|
181
|
+
const order = [];
|
|
182
|
+
const threadUnder = new Map();
|
|
183
|
+
const users = new Map([[selfId, {
|
|
184
|
+
isBot: true
|
|
185
|
+
}]]);
|
|
186
|
+
const calls = [];
|
|
187
|
+
/** Deferrals `interact` returned, by the command's raw id, with when they were made. */
|
|
188
|
+
const deferrals = new Map();
|
|
189
|
+
let refusedFiles = 0;
|
|
190
|
+
const faults = new Map();
|
|
191
|
+
let counter = 0;
|
|
192
|
+
const nextId = prefix => prefix + String(++counter);
|
|
193
|
+
const chatError = (op, reason) => new ChatError({
|
|
194
|
+
platform,
|
|
195
|
+
op,
|
|
196
|
+
reason
|
|
197
|
+
});
|
|
198
|
+
const fail = (op, reason) => Effect.fail(chatError(op, reason));
|
|
199
|
+
const toMessage = message => ({
|
|
200
|
+
id: message.id,
|
|
201
|
+
thread: message.thread,
|
|
202
|
+
author: {
|
|
203
|
+
id: message.authorId,
|
|
204
|
+
name: message.isSelf ? "test-bot" : message.authorId,
|
|
205
|
+
isBot: message.isBot,
|
|
206
|
+
isSelf: message.isSelf
|
|
207
|
+
},
|
|
208
|
+
text: message.text,
|
|
209
|
+
mentions: message.mentions,
|
|
210
|
+
...(message.replyTo === undefined ? {} : {
|
|
211
|
+
replyTo: message.replyTo.authorId === undefined ? message.replyTo : {
|
|
212
|
+
...message.replyTo,
|
|
213
|
+
isSelf: message.replyTo.authorId === selfId
|
|
214
|
+
}
|
|
215
|
+
}),
|
|
216
|
+
attachments: message.attachments.map(stored => stored.attachment),
|
|
217
|
+
timestamp: message.timestamp,
|
|
218
|
+
raw: {
|
|
219
|
+
type: "message",
|
|
220
|
+
id: message.id,
|
|
221
|
+
channel: message.thread.id,
|
|
222
|
+
user: message.authorId,
|
|
223
|
+
text: message.text
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
const findThread = (op, thread) => Effect.suspend(() => {
|
|
227
|
+
const stored = threads.get(thread.id);
|
|
228
|
+
return stored === undefined ? fail(op, new NotFound({
|
|
229
|
+
detail: "thread_not_found"
|
|
230
|
+
})) : Effect.succeed(stored);
|
|
231
|
+
});
|
|
232
|
+
const listMessages = stored => {
|
|
233
|
+
const list = [];
|
|
234
|
+
if (stored.openerId !== undefined) {
|
|
235
|
+
const opener = messages.get(stored.openerId);
|
|
236
|
+
if (opener !== undefined) list.push(opener);
|
|
237
|
+
}
|
|
238
|
+
for (const id of order) {
|
|
239
|
+
const message = messages.get(id);
|
|
240
|
+
if (message !== undefined && ChatThread.equals(message.thread, stored.thread)) list.push(message);
|
|
241
|
+
}
|
|
242
|
+
return list;
|
|
243
|
+
};
|
|
244
|
+
const findMessage = (op, thread, messageId) => Effect.flatMap(findThread(op, thread), stored => {
|
|
245
|
+
const message = listMessages(stored).find(message => message.id === messageId);
|
|
246
|
+
return message === undefined ? fail(op, new NotFound({
|
|
247
|
+
detail: "message_not_found"
|
|
248
|
+
})) : Effect.succeed(message);
|
|
249
|
+
});
|
|
250
|
+
const store = message => Effect.map(DateTime.now, timestamp => {
|
|
251
|
+
const stored = {
|
|
252
|
+
...message,
|
|
253
|
+
id: nextId("m"),
|
|
254
|
+
timestamp
|
|
255
|
+
};
|
|
256
|
+
messages.set(stored.id, stored);
|
|
257
|
+
order.push(stored.id);
|
|
258
|
+
return stored;
|
|
259
|
+
});
|
|
260
|
+
const storeFiles = files => (files ?? []).map(file => ({
|
|
261
|
+
attachment: {
|
|
262
|
+
id: nextId("f"),
|
|
263
|
+
name: file.name,
|
|
264
|
+
contentType: file.contentType,
|
|
265
|
+
size: file.content.length
|
|
266
|
+
},
|
|
267
|
+
content: file.content
|
|
268
|
+
}));
|
|
269
|
+
/** Stores a message from the bot. The author `replyTo` names is read from the stored target. */
|
|
270
|
+
const postOwn = Effect.fnUntraced(function* (op, thread, message) {
|
|
271
|
+
const target = message.replyTo === undefined ? undefined : yield* findMessage(op, thread, message.replyTo.messageId);
|
|
272
|
+
const stored = yield* store({
|
|
273
|
+
...message,
|
|
274
|
+
thread,
|
|
275
|
+
authorId: selfId,
|
|
276
|
+
isBot: true,
|
|
277
|
+
isSelf: true,
|
|
278
|
+
mentions: [],
|
|
279
|
+
replyTo: target === undefined ? undefined : {
|
|
280
|
+
messageId: target.id,
|
|
281
|
+
authorId: target.authorId
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return {
|
|
285
|
+
id: stored.id,
|
|
286
|
+
thread,
|
|
287
|
+
timestamp: stored.timestamp
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
const createThread = (op, thread, messageId, name) => Effect.flatMap(findMessage(op, thread, messageId), message => {
|
|
291
|
+
const existing = threadUnder.get(message.id);
|
|
292
|
+
if (existing !== undefined) return Effect.succeed(existing);
|
|
293
|
+
const parent = threads.get(message.thread.id);
|
|
294
|
+
if (parent.kind === "thread" || !ChatThread.equals(message.thread, thread)) {
|
|
295
|
+
return fail(op, new InvalidRequest({
|
|
296
|
+
detail: "cannot_thread_reply"
|
|
297
|
+
}));
|
|
298
|
+
}
|
|
299
|
+
return Effect.map(DateTime.now, createdAt => {
|
|
300
|
+
const created = ChatThread.make(platform, thread.id + "/" + message.id);
|
|
301
|
+
threads.set(created.id, {
|
|
302
|
+
thread: created,
|
|
303
|
+
kind: "thread",
|
|
304
|
+
name,
|
|
305
|
+
parent: thread,
|
|
306
|
+
openerId: message.id,
|
|
307
|
+
createdAt
|
|
308
|
+
});
|
|
309
|
+
threadUnder.set(message.id, created);
|
|
310
|
+
return created;
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
/** The capabilities a message's elements need. */
|
|
314
|
+
const actionNeeds = actions => {
|
|
315
|
+
const needs = [];
|
|
316
|
+
if (actions?.some(action => action._tag !== "Select")) needs.push("buttons");
|
|
317
|
+
if (actions?.some(action => action._tag === "Select")) needs.push("selects");
|
|
318
|
+
return needs;
|
|
319
|
+
};
|
|
320
|
+
/** The element limits, counted in code points, as both adapters count them. */
|
|
321
|
+
const checkActions = (op, actions) => Effect.suspend(() => {
|
|
322
|
+
const {
|
|
323
|
+
actionDataLength,
|
|
324
|
+
actionsPerMessage
|
|
325
|
+
} = descriptor.limits;
|
|
326
|
+
if (actionsPerMessage !== undefined && actions.length > actionsPerMessage) {
|
|
327
|
+
return fail(op, new TooLarge({
|
|
328
|
+
detail: "too_many_actions"
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
const data = actions.flatMap(action => action._tag === "Button" ? [codePoints(action.id) + codePoints(action.value ?? "")] : action._tag === "Select" ? action.options.map(option => codePoints(action.id) + codePoints(option.value)) : []);
|
|
332
|
+
if (actionDataLength !== undefined && data.some(length => length > actionDataLength)) {
|
|
333
|
+
return fail(op, new TooLarge({
|
|
334
|
+
detail: "action_data_too_long"
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
return Effect.void;
|
|
338
|
+
});
|
|
339
|
+
/** Why a modal would not open, if it would not. */
|
|
340
|
+
const modalRefusal = modal => {
|
|
341
|
+
const {
|
|
342
|
+
modalFields,
|
|
343
|
+
modalMetadataLength
|
|
344
|
+
} = descriptor.limits;
|
|
345
|
+
if (!capabilities.has("modals")) return chatError("openModal", new Unsupported({
|
|
346
|
+
capability: "modals"
|
|
347
|
+
}));
|
|
348
|
+
if (modalMetadataLength !== undefined && codePoints(modal.id) + codePoints(modal.metadata ?? "") > modalMetadataLength) {
|
|
349
|
+
return chatError("openModal", new TooLarge({
|
|
350
|
+
detail: "modal_metadata_too_long"
|
|
351
|
+
}));
|
|
352
|
+
}
|
|
353
|
+
if (modalFields !== undefined && modal.elements.length > modalFields) {
|
|
354
|
+
return chatError("openModal", new TooLarge({
|
|
355
|
+
detail: "too_many_fields"
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
return undefined;
|
|
359
|
+
};
|
|
360
|
+
/** The capabilities a command's answer needs. */
|
|
361
|
+
const answerNeeds = (visibility, actions) => [...(visibility === "ephemeral" ? ["ephemeral"] : []), ...actionNeeds(actions)];
|
|
362
|
+
/** The id the fake gave a command it built, which keys its deferral. */
|
|
363
|
+
const commandKey = ({
|
|
364
|
+
raw
|
|
365
|
+
}) => Predicate.hasProperty(raw, "id") && typeof raw.id === "string" ? raw.id : undefined;
|
|
366
|
+
const takeFault = op => {
|
|
367
|
+
const queue = faults.get(op);
|
|
368
|
+
const fault = queue?.[0];
|
|
369
|
+
if (fault === undefined) return undefined;
|
|
370
|
+
fault.remaining--;
|
|
371
|
+
if (fault.remaining <= 0) queue.shift();
|
|
372
|
+
return fault;
|
|
373
|
+
};
|
|
374
|
+
const attempt = (call, needs, body, retries = true) => (retries ? retrySafe : effect => effect)(Effect.suspend(() => {
|
|
375
|
+
const record = outcome => calls.push({
|
|
376
|
+
...call,
|
|
377
|
+
outcome
|
|
378
|
+
});
|
|
379
|
+
const missing = needs.find(capability => !descriptor.capabilities.has(capability));
|
|
380
|
+
if (missing !== undefined) {
|
|
381
|
+
record("Unsupported");
|
|
382
|
+
return fail(call.op, new Unsupported({
|
|
383
|
+
capability: missing
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
if (call.op === "post" && (call.files?.length ?? 0) > 0 && refusedFiles > 0) {
|
|
387
|
+
refusedFiles--;
|
|
388
|
+
record("Forbidden");
|
|
389
|
+
return fail(call.op, new Forbidden({
|
|
390
|
+
detail: fileRefused
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
const fault = takeFault(call.op);
|
|
394
|
+
if (fault !== undefined) {
|
|
395
|
+
record(fault.reason._tag);
|
|
396
|
+
const failure = fail(call.op, fault.reason);
|
|
397
|
+
return fault.landed ? Effect.flatMap(Effect.exit(body), () => failure) : failure;
|
|
398
|
+
}
|
|
399
|
+
return body.pipe(Effect.tap(() => Effect.sync(() => record("ok"))), Effect.tapError(error => Effect.sync(() => record(error.reason._tag))));
|
|
400
|
+
}));
|
|
401
|
+
/** Whether a native stream is open on the message, closing it once it is past `limits.streamAge`. */
|
|
402
|
+
const isOpen = messageId => Effect.map(Clock.currentTimeMillis, now => {
|
|
403
|
+
const stream = streams.get(messageId);
|
|
404
|
+
if (stream === undefined || !stream.open) return false;
|
|
405
|
+
const age = descriptor.limits.streamAge;
|
|
406
|
+
if (age !== undefined && now - stream.startedAt >= Duration.toMillis(age)) stream.open = false;
|
|
407
|
+
return stream.open;
|
|
408
|
+
});
|
|
409
|
+
const streamLength = () => descriptor.limits.streamLength ?? descriptor.limits.messageLength;
|
|
410
|
+
const nativeStream = {
|
|
411
|
+
start: (thread, content) => attempt({
|
|
412
|
+
op: "nativeStream.start",
|
|
413
|
+
thread,
|
|
414
|
+
markdown: content.markdown
|
|
415
|
+
}, content.replyTo === undefined ? ["nativeStream"] : ["nativeStream", "replyTo"], Effect.gen(function* () {
|
|
416
|
+
yield* findThread("nativeStream.start", thread);
|
|
417
|
+
yield* checkMessageLength(descriptor, "nativeStream.start", content.markdown);
|
|
418
|
+
if (descriptor.measure(content.markdown) > streamLength()) {
|
|
419
|
+
return yield* fail("nativeStream.start", new TooLarge({
|
|
420
|
+
subject: "text",
|
|
421
|
+
detail: "msg_too_long"
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
424
|
+
const posted = yield* postOwn("nativeStream.start", thread, {
|
|
425
|
+
text: Str.toWellFormed(content.markdown),
|
|
426
|
+
replyTo: content.replyTo,
|
|
427
|
+
attachments: [],
|
|
428
|
+
actions: []
|
|
429
|
+
});
|
|
430
|
+
streams.set(posted.id, {
|
|
431
|
+
startedAt: yield* Clock.currentTimeMillis,
|
|
432
|
+
open: true,
|
|
433
|
+
clicked: false
|
|
434
|
+
});
|
|
435
|
+
return posted;
|
|
436
|
+
})),
|
|
437
|
+
append: (thread, messageId, markdown, appendOptions) => attempt({
|
|
438
|
+
op: "nativeStream.append",
|
|
439
|
+
thread,
|
|
440
|
+
messageId,
|
|
441
|
+
markdown
|
|
442
|
+
}, ["nativeStream"], Effect.gen(function* () {
|
|
443
|
+
const message = yield* findMessage("nativeStream.append", thread, messageId);
|
|
444
|
+
const stream = streams.get(message.id);
|
|
445
|
+
if (stream === undefined || !(yield* isOpen(message.id))) {
|
|
446
|
+
return {
|
|
447
|
+
state: stream?.clicked === true ? "stopped" : "closed",
|
|
448
|
+
held: 0
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
let held = 0;
|
|
452
|
+
const flush = appendOptions?.flush === true;
|
|
453
|
+
const open = markdown.lastIndexOf("<");
|
|
454
|
+
if (!flush && open !== -1 && !markdown.includes(">", open)) {
|
|
455
|
+
held = markdown.length - open;
|
|
456
|
+
if (held > heldBound) held = 0;
|
|
457
|
+
}
|
|
458
|
+
// A trailing high surrogate waits for its other half.
|
|
459
|
+
if (!flush && held === 0 && /[\ud800-\udbff]$/.test(markdown)) held = 1;
|
|
460
|
+
const sent = Str.toWellFormed(markdown.slice(0, markdown.length - held));
|
|
461
|
+
if (descriptor.measure(message.text + sent) > streamLength()) {
|
|
462
|
+
return yield* fail("nativeStream.append", new TooLarge({
|
|
463
|
+
subject: "text",
|
|
464
|
+
detail: "msg_too_long"
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
message.text += sent;
|
|
468
|
+
return {
|
|
469
|
+
state: "open",
|
|
470
|
+
held
|
|
471
|
+
};
|
|
472
|
+
}), false),
|
|
473
|
+
stop: (thread, messageId) => attempt({
|
|
474
|
+
op: "nativeStream.stop",
|
|
475
|
+
thread,
|
|
476
|
+
messageId
|
|
477
|
+
}, ["nativeStream"], Effect.gen(function* () {
|
|
478
|
+
const message = yield* findMessage("nativeStream.stop", thread, messageId);
|
|
479
|
+
const stream = streams.get(message.id);
|
|
480
|
+
if (stream === undefined || !(yield* isOpen(message.id))) return {
|
|
481
|
+
stopped: false
|
|
482
|
+
};
|
|
483
|
+
stream.open = false;
|
|
484
|
+
return {
|
|
485
|
+
stopped: stream.clicked
|
|
486
|
+
};
|
|
487
|
+
}))
|
|
488
|
+
};
|
|
489
|
+
const streamFor = (op, messageId) => Effect.suspend(() => {
|
|
490
|
+
const stream = streams.get(messageId);
|
|
491
|
+
return stream === undefined ? Effect.die(new Error("ChatTest." + op + ": no native stream " + messageId)) : Effect.succeed(stream);
|
|
492
|
+
});
|
|
493
|
+
const adapter = {
|
|
494
|
+
descriptor,
|
|
495
|
+
...(capabilities.has("nativeStream") ? {
|
|
496
|
+
nativeStream
|
|
497
|
+
} : {}),
|
|
498
|
+
post: (thread, content) => {
|
|
499
|
+
const files = content.files ?? [];
|
|
500
|
+
const needs = [];
|
|
501
|
+
if (files.length > 0) needs.push("files");
|
|
502
|
+
if (content.replyTo !== undefined) needs.push("replyTo");
|
|
503
|
+
needs.push(...actionNeeds(content.actions));
|
|
504
|
+
return attempt({
|
|
505
|
+
op: "post",
|
|
506
|
+
thread,
|
|
507
|
+
markdown: content.markdown,
|
|
508
|
+
files: content.files
|
|
509
|
+
}, needs, Effect.gen(function* () {
|
|
510
|
+
yield* findThread("post", thread);
|
|
511
|
+
yield* checkMessageLength(descriptor, "post", content.markdown, content.actions);
|
|
512
|
+
yield* checkActions("post", content.actions ?? []);
|
|
513
|
+
if (files.length > descriptor.limits.filesPerMessage || files.some(file => file.content.length > descriptor.limits.uploadBytes)) {
|
|
514
|
+
return yield* fail("post", new TooLarge({
|
|
515
|
+
subject: "files",
|
|
516
|
+
detail: fileRefused
|
|
517
|
+
}));
|
|
518
|
+
}
|
|
519
|
+
return yield* postOwn("post", thread, {
|
|
520
|
+
text: content.markdown,
|
|
521
|
+
replyTo: content.replyTo,
|
|
522
|
+
attachments: storeFiles(files),
|
|
523
|
+
actions: content.actions ?? []
|
|
524
|
+
});
|
|
525
|
+
}));
|
|
526
|
+
},
|
|
527
|
+
edit: (thread, messageId, content) => attempt({
|
|
528
|
+
op: "edit",
|
|
529
|
+
thread,
|
|
530
|
+
messageId,
|
|
531
|
+
markdown: content.markdown
|
|
532
|
+
}, ["edit", ...actionNeeds(content.actions)], Effect.gen(function* () {
|
|
533
|
+
const message = yield* findMessage("edit", thread, messageId);
|
|
534
|
+
if (!message.isSelf) return yield* fail("edit", new Forbidden({
|
|
535
|
+
detail: "cant_update_message"
|
|
536
|
+
}));
|
|
537
|
+
if (yield* isOpen(message.id)) {
|
|
538
|
+
return yield* fail("edit", new InvalidRequest({
|
|
539
|
+
detail: "streaming_state_conflict"
|
|
540
|
+
}));
|
|
541
|
+
}
|
|
542
|
+
yield* checkMessageLength(descriptor, "edit", content.markdown, content.actions);
|
|
543
|
+
yield* checkActions("edit", content.actions ?? []);
|
|
544
|
+
message.text = content.markdown;
|
|
545
|
+
message.mentions = [];
|
|
546
|
+
message.actions = content.actions ?? [];
|
|
547
|
+
})),
|
|
548
|
+
delete: (thread, messageId) => attempt({
|
|
549
|
+
op: "delete",
|
|
550
|
+
thread,
|
|
551
|
+
messageId
|
|
552
|
+
}, ["delete"], Effect.gen(function* () {
|
|
553
|
+
const message = yield* findMessage("delete", thread, messageId);
|
|
554
|
+
if (!message.isSelf) return yield* fail("delete", new Forbidden({
|
|
555
|
+
detail: "cant_delete_message"
|
|
556
|
+
}));
|
|
557
|
+
if (yield* isOpen(message.id)) {
|
|
558
|
+
return yield* fail("delete", new InvalidRequest({
|
|
559
|
+
detail: "cant_delete_message"
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
messages.delete(message.id);
|
|
563
|
+
})),
|
|
564
|
+
fetchMessage: (thread, messageId) => attempt({
|
|
565
|
+
op: "fetchMessage",
|
|
566
|
+
thread,
|
|
567
|
+
messageId
|
|
568
|
+
}, ["fetchMessage"], Effect.map(findMessage("fetchMessage", thread, messageId), toMessage)),
|
|
569
|
+
history: (thread, options) => Stream.unwrap(attempt({
|
|
570
|
+
op: "history",
|
|
571
|
+
thread,
|
|
572
|
+
messageId: options.from
|
|
573
|
+
}, ["history"], Effect.gen(function* () {
|
|
574
|
+
const stored = yield* findThread("history", thread);
|
|
575
|
+
const list = listMessages(stored).map(toMessage);
|
|
576
|
+
if (options.direction === "backward") list.reverse();
|
|
577
|
+
if (options.from === undefined) return Stream.fromIterable(list);
|
|
578
|
+
const index = list.findIndex(message => message.id === options.from);
|
|
579
|
+
if (index === -1) return yield* fail("history", new NotFound({
|
|
580
|
+
detail: "message_not_found"
|
|
581
|
+
}));
|
|
582
|
+
return Stream.fromIterable(list.slice(index + 1));
|
|
583
|
+
}))),
|
|
584
|
+
download: (thread, attachment, options) => Stream.unwrap(attempt({
|
|
585
|
+
op: "download",
|
|
586
|
+
thread
|
|
587
|
+
}, ["download"], Effect.suspend(() => {
|
|
588
|
+
let content;
|
|
589
|
+
for (const message of messages.values()) {
|
|
590
|
+
const found = message.attachments.find(stored => stored.attachment.id === attachment.id);
|
|
591
|
+
if (found !== undefined) content = found.content;
|
|
592
|
+
}
|
|
593
|
+
if (content === undefined) return fail("download", new NotFound({
|
|
594
|
+
detail: "file_not_found"
|
|
595
|
+
}));
|
|
596
|
+
const chunks = [];
|
|
597
|
+
for (let offset = 0; offset < content.length && offset < options.maxBytes; offset += downloadChunkSize) {
|
|
598
|
+
const end = Math.min(offset + downloadChunkSize, content.length);
|
|
599
|
+
if (end > options.maxBytes) break;
|
|
600
|
+
chunks.push(content.slice(offset, end));
|
|
601
|
+
}
|
|
602
|
+
const tooLarge = content.length > options.maxBytes ? Stream.fail(chatError("download", new TooLarge({
|
|
603
|
+
detail: "max_bytes"
|
|
604
|
+
}))) : Stream.empty;
|
|
605
|
+
return Effect.succeed(Stream.concat(Stream.fromIterable(chunks), tooLarge));
|
|
606
|
+
}))),
|
|
607
|
+
startThread: (thread, messageId, startOptions) => attempt({
|
|
608
|
+
op: "startThread",
|
|
609
|
+
thread,
|
|
610
|
+
messageId
|
|
611
|
+
}, ["startThread"], createThread("startThread", thread, messageId, startOptions?.name)),
|
|
612
|
+
getThread: thread => attempt({
|
|
613
|
+
op: "getThread",
|
|
614
|
+
thread
|
|
615
|
+
}, ["getThread"], Effect.map(findThread("getThread", thread), stored => ({
|
|
616
|
+
thread: stored.thread,
|
|
617
|
+
kind: stored.kind,
|
|
618
|
+
name: stored.name,
|
|
619
|
+
parent: stored.parent,
|
|
620
|
+
createdAt: stored.createdAt,
|
|
621
|
+
raw: {
|
|
622
|
+
id: stored.thread.id,
|
|
623
|
+
kind: stored.kind
|
|
624
|
+
}
|
|
625
|
+
}))),
|
|
626
|
+
opener: thread => attempt({
|
|
627
|
+
op: "opener",
|
|
628
|
+
thread
|
|
629
|
+
}, ["opener"], Effect.map(findThread("opener", thread), stored => {
|
|
630
|
+
const opener = stored.openerId === undefined ? undefined : messages.get(stored.openerId);
|
|
631
|
+
return opener === undefined ? Option.none() : Option.some(toMessage(opener));
|
|
632
|
+
})),
|
|
633
|
+
getUser: (id, userOptions) => attempt({
|
|
634
|
+
op: "getUser",
|
|
635
|
+
thread: userOptions?.in ?? ChatThread.make(platform, "")
|
|
636
|
+
}, ["getUser"], Effect.suspend(() => {
|
|
637
|
+
const user = users.get(id);
|
|
638
|
+
return user === undefined ? fail("getUser", new NotFound({
|
|
639
|
+
detail: "user_not_found"
|
|
640
|
+
})) : Effect.succeed({
|
|
641
|
+
id,
|
|
642
|
+
name: id === selfId ? "test-bot" : id,
|
|
643
|
+
isBot: user.isBot,
|
|
644
|
+
isSelf: id === selfId,
|
|
645
|
+
raw: {
|
|
646
|
+
id
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
})),
|
|
650
|
+
followUp: (deferred, content) => attempt({
|
|
651
|
+
op: "followUp",
|
|
652
|
+
thread: deferred.command.thread,
|
|
653
|
+
markdown: content.markdown
|
|
654
|
+
}, ["commands", ...answerNeeds(deferred.visibility, content.actions)], Effect.gen(function* () {
|
|
655
|
+
const key = commandKey(deferred.command);
|
|
656
|
+
const stored = key === undefined ? undefined : deferrals.get(key);
|
|
657
|
+
const age = descriptor.limits.followUpAge;
|
|
658
|
+
const now = yield* Clock.currentTimeMillis;
|
|
659
|
+
if (stored === undefined || stored.used || age !== undefined && now - stored.at >= Duration.toMillis(age)) {
|
|
660
|
+
return yield* fail("followUp", new NotFound({
|
|
661
|
+
detail: interactionExpired
|
|
662
|
+
}));
|
|
663
|
+
}
|
|
664
|
+
yield* checkMessageLength(descriptor, "followUp", content.markdown, content.actions);
|
|
665
|
+
yield* checkActions("followUp", content.actions ?? []);
|
|
666
|
+
stored.used = true;
|
|
667
|
+
}), false)
|
|
668
|
+
};
|
|
669
|
+
const addThread = kind => Effect.map(DateTime.now, createdAt => {
|
|
670
|
+
const thread = ChatThread.make(platform, nextId(kind === "channel" ? "c" : "d"));
|
|
671
|
+
threads.set(thread.id, {
|
|
672
|
+
thread,
|
|
673
|
+
kind,
|
|
674
|
+
createdAt
|
|
675
|
+
});
|
|
676
|
+
return thread;
|
|
677
|
+
});
|
|
678
|
+
const userPosts = Effect.fnUntraced(function* (thread, message) {
|
|
679
|
+
const stored = threads.get(thread.id);
|
|
680
|
+
if (stored === undefined) return yield* Effect.die(new Error("ChatTest.userPosts: unknown thread"));
|
|
681
|
+
const authorId = message.authorId ?? "user";
|
|
682
|
+
const isBot = message.isBot ?? false;
|
|
683
|
+
users.set(authorId, {
|
|
684
|
+
isBot
|
|
685
|
+
});
|
|
686
|
+
const text = message.mentionsSelf === true ? "<@" + selfId + "> " + message.text : message.text;
|
|
687
|
+
const replyTarget = message.replyTo === undefined ? undefined : messages.get(message.replyTo.messageId);
|
|
688
|
+
const created = yield* store({
|
|
689
|
+
thread,
|
|
690
|
+
authorId,
|
|
691
|
+
isBot,
|
|
692
|
+
isSelf: false,
|
|
693
|
+
text,
|
|
694
|
+
mentions: parseMentions(text, selfId),
|
|
695
|
+
// The author is read from the stored message, as a platform does, not from the caller.
|
|
696
|
+
replyTo: message.replyTo === undefined ? undefined : {
|
|
697
|
+
messageId: message.replyTo.messageId,
|
|
698
|
+
...(replyTarget === undefined ? {} : {
|
|
699
|
+
authorId: replyTarget.authorId
|
|
700
|
+
})
|
|
701
|
+
},
|
|
702
|
+
attachments: storeFiles(message.files),
|
|
703
|
+
actions: []
|
|
704
|
+
});
|
|
705
|
+
return ChatEvent.MessageCreated.make({
|
|
706
|
+
thread,
|
|
707
|
+
kind: stored.kind,
|
|
708
|
+
message: toMessage(created),
|
|
709
|
+
raw: {
|
|
710
|
+
type: "event_callback",
|
|
711
|
+
event_id: nextId("e")
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
const service = ChatTest.of({
|
|
716
|
+
platform,
|
|
717
|
+
selfId,
|
|
718
|
+
makeThread: (kind = "channel") => {
|
|
719
|
+
if (kind !== "thread") return addThread(kind);
|
|
720
|
+
return Effect.gen(function* () {
|
|
721
|
+
const channel = yield* addThread("channel");
|
|
722
|
+
const event = yield* userPosts(channel, {
|
|
723
|
+
text: "thread opener"
|
|
724
|
+
});
|
|
725
|
+
const message = event.message;
|
|
726
|
+
return yield* Effect.orDie(createThread("makeThread", channel, message.id, undefined));
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
userPosts,
|
|
730
|
+
deliver: event => Effect.flatMap(ChatHandler, handler => handler.handle(event)),
|
|
731
|
+
messages: thread => Effect.sync(() => {
|
|
732
|
+
const stored = threads.get(thread.id);
|
|
733
|
+
return stored === undefined ? [] : listMessages(stored).map(toMessage);
|
|
734
|
+
}),
|
|
735
|
+
calls: Effect.sync(() => calls.slice()),
|
|
736
|
+
refuseFiles: options => Effect.sync(() => {
|
|
737
|
+
refusedFiles += options?.times ?? 1;
|
|
738
|
+
}),
|
|
739
|
+
failNext: (op, reason, failOptions) => Effect.sync(() => {
|
|
740
|
+
if (failOptions?.times === 0) return;
|
|
741
|
+
const queue = faults.get(op) ?? [];
|
|
742
|
+
queue.push({
|
|
743
|
+
reason,
|
|
744
|
+
remaining: failOptions?.times ?? 1,
|
|
745
|
+
landed: failOptions?.landed ?? false
|
|
746
|
+
});
|
|
747
|
+
faults.set(op, queue);
|
|
748
|
+
}),
|
|
749
|
+
clickStop: messageId => Effect.map(streamFor("clickStop", messageId), stream => void (stream.clicked = true)),
|
|
750
|
+
closeStream: messageId => Effect.map(streamFor("closeStream", messageId), stream => void (stream.open = false)),
|
|
751
|
+
click: (messageId, id, clickOptions) => Effect.suspend(() => {
|
|
752
|
+
const message = messages.get(messageId);
|
|
753
|
+
const element = message?.actions.find(action => action._tag !== "LinkButton" && action.id === id);
|
|
754
|
+
if (message === undefined || element === undefined || element._tag === "LinkButton") {
|
|
755
|
+
return Effect.fail(new NoSuchElement({
|
|
756
|
+
messageId,
|
|
757
|
+
id
|
|
758
|
+
}));
|
|
759
|
+
}
|
|
760
|
+
const origin = {
|
|
761
|
+
id,
|
|
762
|
+
thread: message.thread,
|
|
763
|
+
messageId,
|
|
764
|
+
userId: clickOptions?.userId ?? "user",
|
|
765
|
+
raw: {
|
|
766
|
+
type: "interaction",
|
|
767
|
+
id: nextId("i"),
|
|
768
|
+
message: messageId,
|
|
769
|
+
element: id
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
if (element._tag === "Button") {
|
|
773
|
+
return Effect.succeed(ChatInteraction.ButtonClicked.make({
|
|
774
|
+
...origin,
|
|
775
|
+
...(element.value === undefined ? {} : {
|
|
776
|
+
value: element.value
|
|
777
|
+
})
|
|
778
|
+
}));
|
|
779
|
+
}
|
|
780
|
+
const option = clickOptions?.option === undefined ? element.options[0] : element.options.find(option => option.value === clickOptions.option);
|
|
781
|
+
return option === undefined ? Effect.fail(new NoSuchElement({
|
|
782
|
+
messageId,
|
|
783
|
+
id
|
|
784
|
+
})) : Effect.succeed(ChatInteraction.SelectChanged.make({
|
|
785
|
+
...origin,
|
|
786
|
+
value: option.value
|
|
787
|
+
}));
|
|
788
|
+
}),
|
|
789
|
+
command: (thread, id, commandOptions) => Effect.sync(() => {
|
|
790
|
+
const text = commandOptions?.text ?? "";
|
|
791
|
+
return ChatInteraction.CommandInvoked.make({
|
|
792
|
+
id,
|
|
793
|
+
text,
|
|
794
|
+
thread,
|
|
795
|
+
userId: commandOptions?.userId ?? "user",
|
|
796
|
+
raw: {
|
|
797
|
+
type: "command",
|
|
798
|
+
id: nextId("i"),
|
|
799
|
+
command: id,
|
|
800
|
+
text
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
}),
|
|
804
|
+
submit: (from, opened, values, submitOptions) => Effect.sync(() => ChatInteraction.ModalSubmitted.make({
|
|
805
|
+
id: opened.modal.id,
|
|
806
|
+
...(opened.modal.metadata === undefined ? {} : {
|
|
807
|
+
metadata: opened.modal.metadata
|
|
808
|
+
}),
|
|
809
|
+
values: Object.fromEntries(Object.entries(values).filter(([, value]) => value !== "")),
|
|
810
|
+
thread: from.thread,
|
|
811
|
+
...(from._tag === "CommandInvoked" ? {} : {
|
|
812
|
+
messageId: from.messageId
|
|
813
|
+
}),
|
|
814
|
+
userId: submitOptions?.userId ?? from.userId,
|
|
815
|
+
raw: {
|
|
816
|
+
type: "submission",
|
|
817
|
+
id: nextId("i"),
|
|
818
|
+
modal: opened.modal.id
|
|
819
|
+
}
|
|
820
|
+
})),
|
|
821
|
+
interact: event => Effect.gen(function* () {
|
|
822
|
+
const reply = yield* ChatInteraction.handle(event, options.interactionDeadline);
|
|
823
|
+
if (event._tag === "ModalSubmitted") return reply;
|
|
824
|
+
let refusal;
|
|
825
|
+
switch (reply._tag) {
|
|
826
|
+
case "OpenModal":
|
|
827
|
+
{
|
|
828
|
+
refusal = modalRefusal(reply.modal);
|
|
829
|
+
calls.push({
|
|
830
|
+
op: "openModal",
|
|
831
|
+
thread: event.thread,
|
|
832
|
+
...(event._tag === "CommandInvoked" ? {} : {
|
|
833
|
+
messageId: event.messageId
|
|
834
|
+
}),
|
|
835
|
+
outcome: refusal === undefined ? "ok" : refusal.reason._tag
|
|
836
|
+
});
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
case "Respond":
|
|
840
|
+
{
|
|
841
|
+
const exit = yield* Effect.exit(attempt({
|
|
842
|
+
op: "respond",
|
|
843
|
+
thread: event.thread,
|
|
844
|
+
markdown: reply.markdown
|
|
845
|
+
}, answerNeeds(reply.visibility, reply.actions), Effect.andThen(checkMessageLength(descriptor, "respond", reply.markdown, reply.actions), checkActions("respond", reply.actions ?? [])), false));
|
|
846
|
+
refusal = Option.getOrUndefined(Exit.findErrorOption(exit));
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
case "Defer":
|
|
850
|
+
{
|
|
851
|
+
const missing = answerNeeds(reply.visibility).find(capability => !capabilities.has(capability));
|
|
852
|
+
if (missing !== undefined) {
|
|
853
|
+
refusal = chatError("defer", new Unsupported({
|
|
854
|
+
capability: missing
|
|
855
|
+
}));
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
const key = event._tag === "CommandInvoked" ? commandKey(event) : undefined;
|
|
859
|
+
if (key !== undefined) deferrals.set(key, {
|
|
860
|
+
at: yield* Clock.currentTimeMillis,
|
|
861
|
+
used: false
|
|
862
|
+
});
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
if (refusal !== undefined) {
|
|
867
|
+
const handler = yield* ChatInteraction.Handler;
|
|
868
|
+
yield* handler.refused(event, refusal);
|
|
869
|
+
}
|
|
870
|
+
return reply;
|
|
871
|
+
})
|
|
872
|
+
});
|
|
873
|
+
return {
|
|
874
|
+
adapter,
|
|
875
|
+
service
|
|
876
|
+
};
|
|
877
|
+
};
|
|
878
|
+
/**
|
|
879
|
+
* Creates a whole chat in memory: `Chat`, its registry and one fake adapter.
|
|
880
|
+
*
|
|
881
|
+
* **When to use**
|
|
882
|
+
*
|
|
883
|
+
* Use to test code that posts and reads through `Chat`, and to run the
|
|
884
|
+
* conformance suite against the fake adapter.
|
|
885
|
+
*
|
|
886
|
+
* **Details**
|
|
887
|
+
*
|
|
888
|
+
* - The platform defaults to `test` and the bot's user id to `bot`.
|
|
889
|
+
* - Every capability is on by default.
|
|
890
|
+
* - `measure` defaults to a count of code points, and the fake checks every
|
|
891
|
+
* length with it.
|
|
892
|
+
* - The default limits are 4000 per message, 10 files of up to 10 MiB, and no
|
|
893
|
+
* write interval. With `nativeStream` on, a stream takes up to
|
|
894
|
+
* `messageLength` and lasts 10 minutes.
|
|
895
|
+
* - The native stream behaves the way Slack's was found to. An append past
|
|
896
|
+
* `limits.streamLength` fails with `TooLarge` and adds nothing. A stream
|
|
897
|
+
* past `limits.streamAge`, on `Clock`, is closed. An append without
|
|
898
|
+
* `flush` holds back an unclosed `<` tail of up to 100 characters, or a
|
|
899
|
+
* trailing high surrogate. Any other lone surrogate is stored as U+FFFD.
|
|
900
|
+
* An open stream refuses `edit` and `delete`.
|
|
901
|
+
* - With `buttons` or `selects` on, a message takes 25 elements, and an
|
|
902
|
+
* element's id plus encoded value 100 code points. With `modals` on, a
|
|
903
|
+
* modal's id plus encoded metadata takes 100 code points, and a modal 5
|
|
904
|
+
* fields. Each limit is there only with its capability.
|
|
905
|
+
* - `interact` gives a handler 3 seconds by default, on `Clock`.
|
|
906
|
+
* - With `commands` on, `limits.followUpAge` is 15 minutes.
|
|
907
|
+
* - Two layers merged with different platforms share one `Chat`, so routing
|
|
908
|
+
* can be tested. The `ChatTest` service in context is the last one merged.
|
|
909
|
+
*
|
|
910
|
+
* @stability unstable
|
|
911
|
+
* @category layers
|
|
912
|
+
* @since 4.1.5
|
|
913
|
+
*/
|
|
914
|
+
export const layer = options => Layer.effect(ChatTest, Effect.gen(function* () {
|
|
915
|
+
const registry = yield* Registry;
|
|
916
|
+
const {
|
|
917
|
+
adapter,
|
|
918
|
+
service
|
|
919
|
+
} = makeFake({
|
|
920
|
+
platform: options?.platform ?? "test",
|
|
921
|
+
selfId: options?.selfId ?? "bot",
|
|
922
|
+
capabilities: options?.capabilities ?? allCapabilities,
|
|
923
|
+
limits: options?.limits ?? {},
|
|
924
|
+
measure: options?.measure ?? codePoints,
|
|
925
|
+
interactionDeadline: options?.interactionDeadline ?? Duration.seconds(3)
|
|
926
|
+
});
|
|
927
|
+
yield* registry.register(adapter);
|
|
928
|
+
return service;
|
|
929
|
+
})).pipe(Layer.provideMerge(Chat.layer));
|
|
930
|
+
// -----------------------------------------------------------------------------
|
|
931
|
+
// invariants
|
|
932
|
+
// -----------------------------------------------------------------------------
|
|
933
|
+
/**
|
|
934
|
+
* Error for a conformance rule or invariant that did not hold.
|
|
935
|
+
*
|
|
936
|
+
* **Details**
|
|
937
|
+
*
|
|
938
|
+
* `rule` names what failed, and `expected` and `actual` say how. A platform
|
|
939
|
+
* error behind the failure is in `cause`.
|
|
940
|
+
*
|
|
941
|
+
* @stability unstable
|
|
942
|
+
* @category errors
|
|
943
|
+
* @since 4.1.5
|
|
944
|
+
*/
|
|
945
|
+
export class ConformanceFailure extends /*#__PURE__*/Schema.TaggedError("effect/chat/ChatTest/ConformanceFailure")("ConformanceFailure", {
|
|
946
|
+
rule: Schema.String,
|
|
947
|
+
expected: Schema.String,
|
|
948
|
+
actual: Schema.String,
|
|
949
|
+
cause: /*#__PURE__*/Schema.optionalKey(/*#__PURE__*/Schema.Defect())
|
|
950
|
+
}) {
|
|
951
|
+
get message() {
|
|
952
|
+
return this.rule + ": expected " + this.expected + ", got " + this.actual;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
const sameMentions = (a, b) => a.length === b.length && a.every((mention, i) => {
|
|
956
|
+
const other = b[i];
|
|
957
|
+
return mention.kind === other.kind && mention.id === other.id && mention.start === other.start && mention.end === other.end && mention.isSelf === other.isSelf;
|
|
958
|
+
});
|
|
959
|
+
const sameReplyTo = (a, b) => a === undefined || b === undefined ? a === b : a.messageId === b.messageId && a.authorId === b.authorId && a.isSelf === b.isSelf;
|
|
960
|
+
/**
|
|
961
|
+
* Returns whether two reads of a message are the same message.
|
|
962
|
+
*
|
|
963
|
+
* **Details**
|
|
964
|
+
*
|
|
965
|
+
* It compares `id`, `thread`, `author.id`, `author.isBot`, `author.isSelf`,
|
|
966
|
+
* `text`, `mentions`, `replyTo`, `timestamp` and the attachment ids in order.
|
|
967
|
+
* `raw`, `author.name` and the optional attachment fields are left out.
|
|
968
|
+
*
|
|
969
|
+
* @stability unstable
|
|
970
|
+
* @category comparisons
|
|
971
|
+
* @since 4.1.5
|
|
972
|
+
*/
|
|
973
|
+
export const sameMessage = (a, b) => a.id === b.id && ChatThread.equals(a.thread, b.thread) && a.author.id === b.author.id && a.author.isBot === b.author.isBot && a.author.isSelf === b.author.isSelf && a.text === b.text && sameMentions(a.mentions, b.mentions) && sameReplyTo(a.replyTo, b.replyTo) && DateTime.Equivalence(a.timestamp, b.timestamp) && a.attachments.length === b.attachments.length && a.attachments.every((attachment, i) => attachment.id === b.attachments[i].id);
|
|
974
|
+
const canonicalJson = value => JSON.stringify(value, (_, v) => Predicate.isObject(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : v);
|
|
975
|
+
const failure = (rule, expected, actual, cause) => new ConformanceFailure({
|
|
976
|
+
rule,
|
|
977
|
+
expected,
|
|
978
|
+
actual,
|
|
979
|
+
...(cause === undefined ? {} : {
|
|
980
|
+
cause
|
|
981
|
+
})
|
|
982
|
+
});
|
|
983
|
+
const check = (rule, condition, expected, actual) => condition ? Effect.void : Effect.fail(failure(rule, expected, actual()));
|
|
984
|
+
const MessageJson = /*#__PURE__*/Schema.toCodecJson(ChatMessage.ChatMessage);
|
|
985
|
+
const EventJson = /*#__PURE__*/Schema.toCodecJson(ChatEvent.ChatEvent);
|
|
986
|
+
const roundTrip = (rule, codec, value) => Effect.gen(function* () {
|
|
987
|
+
const encoded = yield* Schema.encodeEffect(codec)(value);
|
|
988
|
+
const decoded = yield* Schema.decodeEffect(codec)(encoded);
|
|
989
|
+
const again = yield* Schema.encodeEffect(codec)(decoded);
|
|
990
|
+
yield* check(rule, canonicalJson(encoded) === canonicalJson(again), "an unchanged value after encoding and decoding", () => canonicalJson(again));
|
|
991
|
+
return decoded;
|
|
992
|
+
}).pipe(Effect.catchTag("SchemaError", error => Effect.fail(failure(rule, "a value that encodes and decodes", "SchemaError", error))));
|
|
993
|
+
const checkThread = /*#__PURE__*/Effect.fnUntraced(function* (rule, thread, platform) {
|
|
994
|
+
yield* check(rule, thread.platform === platform, "platform " + platform, () => "platform " + thread.platform);
|
|
995
|
+
const decoded = ChatThread.fromString(ChatThread.toString(thread));
|
|
996
|
+
yield* check(rule, Option.isSome(decoded) && ChatThread.equals(decoded.value, thread), "a thread that survives its string codec", () => ChatThread.toString(thread));
|
|
997
|
+
});
|
|
998
|
+
const checkMessageWith = /*#__PURE__*/Effect.fnUntraced(function* (rule, message, options) {
|
|
999
|
+
yield* checkThread(rule, message.thread, options.platform);
|
|
1000
|
+
const mentions = [...message.mentions].sort((a, b) => a.start - b.start);
|
|
1001
|
+
let end = 0;
|
|
1002
|
+
for (const mention of mentions) {
|
|
1003
|
+
yield* check(rule, mention.start >= end && mention.start < mention.end && mention.end <= message.text.length, "mentions inside text without overlap", () => "mention at " + mention.start + "-" + mention.end);
|
|
1004
|
+
end = mention.end;
|
|
1005
|
+
const parsed = options.parseMention(message.text.slice(mention.start, mention.end));
|
|
1006
|
+
yield* check(rule, Option.isSome(parsed) && parsed.value.kind === mention.kind && parsed.value.id === mention.id, "a " + mention.kind + " mention token at " + mention.start + "-" + mention.end, () => Option.isSome(parsed) ? "a " + parsed.value.kind + " token" : "no mention token");
|
|
1007
|
+
}
|
|
1008
|
+
for (const attachment of message.attachments) {
|
|
1009
|
+
yield* check(rule, attachment.id.length > 0 && !("url" in attachment) && !/^[a-z]+:\/\//i.test(attachment.id), "an attachment with an id and no URL", () => "attachment " + (attachment.id.length > 0 ? "with a URL" : "without an id"));
|
|
1010
|
+
}
|
|
1011
|
+
if (message.replyTo !== undefined) {
|
|
1012
|
+
const {
|
|
1013
|
+
authorId,
|
|
1014
|
+
isSelf
|
|
1015
|
+
} = message.replyTo;
|
|
1016
|
+
yield* check(rule, authorId === undefined === (isSelf === undefined), "replyTo.isSelf set exactly when replyTo.authorId is", () => "authorId " + authorId + ", isSelf " + isSelf);
|
|
1017
|
+
}
|
|
1018
|
+
const decoded = yield* roundTrip(rule, MessageJson, message);
|
|
1019
|
+
yield* check(rule, sameMessage(message, decoded), "the same message after decoding", () => "a different message");
|
|
1020
|
+
});
|
|
1021
|
+
/**
|
|
1022
|
+
* Checks the invariants every message holds, for fixture tests and live runs.
|
|
1023
|
+
*
|
|
1024
|
+
* **Details**
|
|
1025
|
+
*
|
|
1026
|
+
* - Every mention sits inside `text`, mentions do not overlap, and each slice
|
|
1027
|
+
* parses with `parseMention` as a token of the mention's kind and id.
|
|
1028
|
+
* - `thread.platform` is the platform, and the thread survives its string
|
|
1029
|
+
* codec.
|
|
1030
|
+
* - The message encodes and decodes through its Schema unchanged, `raw`
|
|
1031
|
+
* included.
|
|
1032
|
+
* - Every attachment has an id and no URL.
|
|
1033
|
+
* - `replyTo.isSelf` is set exactly when `replyTo.authorId` is.
|
|
1034
|
+
*
|
|
1035
|
+
* @stability unstable
|
|
1036
|
+
* @category testing
|
|
1037
|
+
* @since 4.1.5
|
|
1038
|
+
*/
|
|
1039
|
+
export const checkMessage = (message, options) => checkMessageWith("checkMessage", message, options);
|
|
1040
|
+
/**
|
|
1041
|
+
* Checks the invariants every event holds, for fixture tests and live runs.
|
|
1042
|
+
*
|
|
1043
|
+
* **Details**
|
|
1044
|
+
*
|
|
1045
|
+
* - A message event's message passes `checkMessage`, and the event's thread is
|
|
1046
|
+
* the message's.
|
|
1047
|
+
* - `thread.platform` is the platform, and the thread survives its string
|
|
1048
|
+
* codec.
|
|
1049
|
+
* - The event encodes and decodes through its Schema unchanged, `raw`
|
|
1050
|
+
* included, and two decodes have the same `dedupeKey`.
|
|
1051
|
+
* - A reaction's `dedupeKey` differs between added and removed.
|
|
1052
|
+
*
|
|
1053
|
+
* @stability unstable
|
|
1054
|
+
* @category testing
|
|
1055
|
+
* @since 4.1.5
|
|
1056
|
+
*/
|
|
1057
|
+
export const checkEvent = (event, options) => Effect.gen(function* () {
|
|
1058
|
+
const rule = "checkEvent";
|
|
1059
|
+
yield* checkThread(rule, event.thread, options.platform);
|
|
1060
|
+
if (event._tag === "MessageCreated") {
|
|
1061
|
+
yield* checkMessageWith(rule, event.message, options);
|
|
1062
|
+
yield* check(rule, ChatThread.equals(event.thread, event.message.thread), "the event's thread equal to the message's", () => ChatThread.toString(event.thread));
|
|
1063
|
+
} else if (event._tag !== "StopRequested") {
|
|
1064
|
+
const {
|
|
1065
|
+
_tag,
|
|
1066
|
+
...fields
|
|
1067
|
+
} = event;
|
|
1068
|
+
const flipped = _tag === "ReactionAdded" ? ChatEvent.ReactionRemoved.make(fields) : ChatEvent.ReactionAdded.make(fields);
|
|
1069
|
+
yield* check(rule, ChatEvent.dedupeKey(flipped) !== ChatEvent.dedupeKey(event), "different keys for an added and a removed reaction", () => ChatEvent.dedupeKey(event));
|
|
1070
|
+
}
|
|
1071
|
+
const first = yield* roundTrip(rule, EventJson, event);
|
|
1072
|
+
const second = yield* roundTrip(rule, EventJson, event);
|
|
1073
|
+
const key = ChatEvent.dedupeKey(event);
|
|
1074
|
+
yield* check(rule, ChatEvent.dedupeKey(first) === key && ChatEvent.dedupeKey(second) === key, "the same dedupeKey for every decode", () => ChatEvent.dedupeKey(first) + " and " + ChatEvent.dedupeKey(second));
|
|
1075
|
+
});
|
|
1076
|
+
const InteractionJson = /*#__PURE__*/Schema.toCodecJson(ChatInteraction.Interaction);
|
|
1077
|
+
/**
|
|
1078
|
+
* Checks the invariants every interaction holds, for a click, a submit or a
|
|
1079
|
+
* command from a fixture.
|
|
1080
|
+
*
|
|
1081
|
+
* **Details**
|
|
1082
|
+
*
|
|
1083
|
+
* - `thread.platform` is the platform, and the thread survives its string
|
|
1084
|
+
* codec.
|
|
1085
|
+
* - The interaction encodes and decodes through its Schema unchanged, `raw`
|
|
1086
|
+
* included.
|
|
1087
|
+
* - A `ModalSubmitted`'s `messageId` is non-empty when it is there. A modal
|
|
1088
|
+
* a command opened has none.
|
|
1089
|
+
* - A `CommandInvoked` has a non-empty `id`.
|
|
1090
|
+
*
|
|
1091
|
+
* It takes no `parseMention` and checks no dedupe key, since an interaction
|
|
1092
|
+
* carries neither.
|
|
1093
|
+
*
|
|
1094
|
+
* @stability unstable
|
|
1095
|
+
* @category testing
|
|
1096
|
+
* @since 4.1.5
|
|
1097
|
+
*/
|
|
1098
|
+
export const checkInteraction = (interaction, options) => Effect.gen(function* () {
|
|
1099
|
+
const rule = "checkInteraction";
|
|
1100
|
+
yield* checkThread(rule, interaction.thread, options.platform);
|
|
1101
|
+
if (interaction._tag === "ModalSubmitted") {
|
|
1102
|
+
yield* check(rule, interaction.messageId !== "", "a submit with no messageId or a non-empty one", () => "an empty messageId");
|
|
1103
|
+
}
|
|
1104
|
+
if (interaction._tag === "CommandInvoked") {
|
|
1105
|
+
yield* check(rule, interaction.id !== "", "a command with a non-empty id", () => "an empty id");
|
|
1106
|
+
}
|
|
1107
|
+
yield* roundTrip(rule, InteractionJson, interaction);
|
|
1108
|
+
});
|
|
1109
|
+
/** What the suite's own `ChatInteraction.Handler` received, and how it answers. */
|
|
1110
|
+
class Recording {
|
|
1111
|
+
clicks = [];
|
|
1112
|
+
submits = [];
|
|
1113
|
+
commands = [];
|
|
1114
|
+
commandReplies = [];
|
|
1115
|
+
refused = [];
|
|
1116
|
+
onClick = () => ChatInteraction.ack;
|
|
1117
|
+
onSubmit = () => ChatInteraction.close;
|
|
1118
|
+
onCommand = event => ChatInteraction.respond({
|
|
1119
|
+
markdown: conformanceText(event.id),
|
|
1120
|
+
visibility: "public"
|
|
1121
|
+
});
|
|
1122
|
+
handler = /*#__PURE__*/ChatInteraction.Handler.of({
|
|
1123
|
+
click: event => Effect.sync(() => {
|
|
1124
|
+
this.clicks.push(event);
|
|
1125
|
+
return this.onClick(event);
|
|
1126
|
+
}),
|
|
1127
|
+
submit: event => Effect.sync(() => {
|
|
1128
|
+
this.submits.push(event);
|
|
1129
|
+
return this.onSubmit(event);
|
|
1130
|
+
}),
|
|
1131
|
+
command: event => Effect.sync(() => {
|
|
1132
|
+
this.commands.push(event);
|
|
1133
|
+
const reply = this.onCommand(event);
|
|
1134
|
+
this.commandReplies.push(reply);
|
|
1135
|
+
return reply;
|
|
1136
|
+
}),
|
|
1137
|
+
refused: (_, error) => Effect.sync(() => void this.refused.push(error))
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
const conformanceButton = rule => ({
|
|
1141
|
+
_tag: "Button",
|
|
1142
|
+
id: "conformance",
|
|
1143
|
+
label: rule
|
|
1144
|
+
});
|
|
1145
|
+
const conformanceSelect = rule => ({
|
|
1146
|
+
_tag: "Select",
|
|
1147
|
+
id: "conformance",
|
|
1148
|
+
placeholder: rule,
|
|
1149
|
+
options: [{
|
|
1150
|
+
label: "a",
|
|
1151
|
+
value: "a"
|
|
1152
|
+
}, {
|
|
1153
|
+
label: "b",
|
|
1154
|
+
value: "b"
|
|
1155
|
+
}]
|
|
1156
|
+
});
|
|
1157
|
+
const describeExit = exit => {
|
|
1158
|
+
if (Exit.isSuccess(exit)) return "success";
|
|
1159
|
+
const error = Exit.findErrorOption(exit);
|
|
1160
|
+
if (Option.isNone(error)) return "a defect or interruption";
|
|
1161
|
+
return describeError(error.value);
|
|
1162
|
+
};
|
|
1163
|
+
const describeError = error => {
|
|
1164
|
+
if (!isChatError(error)) return String(error);
|
|
1165
|
+
return error.reason._tag === "Unsupported" ? "Unsupported(" + error.reason.capability + ")" : error.reason._tag;
|
|
1166
|
+
};
|
|
1167
|
+
const conformanceText = rule => "conformance " + rule;
|
|
1168
|
+
class Tester {
|
|
1169
|
+
created = [];
|
|
1170
|
+
rule;
|
|
1171
|
+
chat;
|
|
1172
|
+
descriptor;
|
|
1173
|
+
options;
|
|
1174
|
+
constructor(rule, chat, descriptor, options) {
|
|
1175
|
+
this.rule = rule;
|
|
1176
|
+
this.chat = chat;
|
|
1177
|
+
this.descriptor = descriptor;
|
|
1178
|
+
this.options = options;
|
|
1179
|
+
}
|
|
1180
|
+
get thread() {
|
|
1181
|
+
return this.options.thread;
|
|
1182
|
+
}
|
|
1183
|
+
recording = /*#__PURE__*/new Recording();
|
|
1184
|
+
/** Runs an interaction hook with the suite's recording handler. */
|
|
1185
|
+
recorded(effect) {
|
|
1186
|
+
return Effect.provideService(effect, ChatInteraction.Handler, this.recording.handler);
|
|
1187
|
+
}
|
|
1188
|
+
/** Clicks through the hook, with the suite's recording handler. */
|
|
1189
|
+
clickExit(messageId, id, options) {
|
|
1190
|
+
return Effect.exit(this.recorded(this.options.interactions.click(messageId, id, options)));
|
|
1191
|
+
}
|
|
1192
|
+
click(messageId, id, options) {
|
|
1193
|
+
return Effect.flatMap(this.clickExit(messageId, id, options), exit => Exit.isSuccess(exit) ? Effect.void : Effect.fail(failure(this.rule, "a click on element " + id + " of message " + messageId, describeExit(exit), Option.getOrUndefined(Exit.findErrorOption(exit)))));
|
|
1194
|
+
}
|
|
1195
|
+
/** Sends a command through the hook, with the suite's recording handler. */
|
|
1196
|
+
command(id, options) {
|
|
1197
|
+
return this.recorded(this.options.interactions.command(this.thread, id, options));
|
|
1198
|
+
}
|
|
1199
|
+
submit(values) {
|
|
1200
|
+
return this.recorded(this.options.interactions.submit(values));
|
|
1201
|
+
}
|
|
1202
|
+
/** Checks a received interaction with `checkInteraction`, under this rule's name. */
|
|
1203
|
+
checkInteraction(interaction) {
|
|
1204
|
+
return Effect.mapError(checkInteraction(interaction, {
|
|
1205
|
+
platform: this.options.platform
|
|
1206
|
+
}), error => failure(this.rule, error.expected, error.actual, error.cause));
|
|
1207
|
+
}
|
|
1208
|
+
/** A click whose handler answers with `modal`, and what the adapter did with it. */
|
|
1209
|
+
openModal(modal) {
|
|
1210
|
+
return Effect.gen({
|
|
1211
|
+
self: this
|
|
1212
|
+
}, function* () {
|
|
1213
|
+
// A modal opens from a click, on a select when there are no buttons.
|
|
1214
|
+
const element = this.has("buttons") || !this.has("selects") ? conformanceButton(this.rule) : conformanceSelect(this.rule);
|
|
1215
|
+
const posted = yield* this.post({
|
|
1216
|
+
actions: [element]
|
|
1217
|
+
});
|
|
1218
|
+
this.recording.onClick = () => modal;
|
|
1219
|
+
yield* this.click(posted.id, "conformance");
|
|
1220
|
+
return posted;
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
has(capability) {
|
|
1224
|
+
return this.descriptor.capabilities.has(capability);
|
|
1225
|
+
}
|
|
1226
|
+
call(effect) {
|
|
1227
|
+
return Effect.mapError(effect, error => {
|
|
1228
|
+
const listed = error.reason._tag === "Unsupported" && this.has(error.reason.capability);
|
|
1229
|
+
return failure(this.rule, "success", describeError(error) + (listed ? " for a listed capability" : ""), error);
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
collect(stream) {
|
|
1233
|
+
return this.call(Stream.runCollect(stream));
|
|
1234
|
+
}
|
|
1235
|
+
check(condition, expected, actual) {
|
|
1236
|
+
return check(this.rule, condition, expected, actual);
|
|
1237
|
+
}
|
|
1238
|
+
/** Marks a message the rule posted in its thread for cleanup. */
|
|
1239
|
+
track(posted) {
|
|
1240
|
+
this.created.push({
|
|
1241
|
+
thread: this.thread,
|
|
1242
|
+
id: posted.id
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
post(content, thread = this.thread) {
|
|
1246
|
+
return Effect.tap(this.call(this.chat.post(thread, {
|
|
1247
|
+
markdown: conformanceText(this.rule),
|
|
1248
|
+
...content
|
|
1249
|
+
})), posted => Effect.sync(() => this.created.push({
|
|
1250
|
+
thread,
|
|
1251
|
+
id: posted.id
|
|
1252
|
+
})));
|
|
1253
|
+
}
|
|
1254
|
+
userPosts(thread = this.thread) {
|
|
1255
|
+
return Effect.flatMap(this.options.userPosts(thread, conformanceText(this.rule)), event => event._tag === "MessageCreated" ? Effect.succeed(event) : Effect.fail(failure(this.rule, "a MessageCreated event from userPosts", event._tag)));
|
|
1256
|
+
}
|
|
1257
|
+
expectReason(tag, effect, onSuccess, refine) {
|
|
1258
|
+
return Effect.flatMap(Effect.exit(effect), exit => {
|
|
1259
|
+
if (Exit.isSuccess(exit)) onSuccess?.(exit.value);
|
|
1260
|
+
const error = Exit.findErrorOption(exit);
|
|
1261
|
+
const matches = Option.isSome(error) && isChatError(error.value) && error.value.reason._tag === tag && (refine === undefined || refine.test(error.value.reason));
|
|
1262
|
+
return matches ? Effect.void : Effect.fail(failure(this.rule, refine === undefined ? tag : refine.expected, describeExit(exit), Option.getOrUndefined(error)));
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Calls the op behind `capability`. When the descriptor lacks it, the op
|
|
1267
|
+
* must fail with `Unsupported` naming it. When it is listed, the op must
|
|
1268
|
+
* not fail with `Unsupported` at all, whichever capability that names, so a
|
|
1269
|
+
* descriptor that lies in either direction fails.
|
|
1270
|
+
*/
|
|
1271
|
+
probe(capability) {
|
|
1272
|
+
const listed = this.has(capability);
|
|
1273
|
+
const expected = listed ? "no Unsupported for listed " + capability : "Unsupported(" + capability + ")";
|
|
1274
|
+
const expect = (effect, onSuccess) => Effect.flatMap(Effect.exit(effect), exit => {
|
|
1275
|
+
if (Exit.isSuccess(exit)) onSuccess?.(exit.value);
|
|
1276
|
+
const error = Exit.findErrorOption(exit);
|
|
1277
|
+
const reason = Option.isSome(error) && isChatError(error.value) ? error.value.reason : undefined;
|
|
1278
|
+
const holds = listed ? Exit.isSuccess(exit) || reason !== undefined && reason._tag !== "Unsupported" : reason?._tag === "Unsupported" && reason.capability === capability;
|
|
1279
|
+
return holds ? Effect.void : Effect.fail(failure(this.rule, expected, describeExit(exit), Option.getOrUndefined(error)));
|
|
1280
|
+
});
|
|
1281
|
+
const track = posted => this.track(posted);
|
|
1282
|
+
/** Whether the suite's handler was refused `Unsupported` exactly when the capability is not listed. */
|
|
1283
|
+
const checkRefusal = Effect.suspend(() => {
|
|
1284
|
+
const {
|
|
1285
|
+
refused
|
|
1286
|
+
} = this.recording;
|
|
1287
|
+
const refusal = refused.find(error => error.reason._tag === "Unsupported");
|
|
1288
|
+
return this.check(listed ? refusal === undefined : refusal?.reason._tag === "Unsupported" && refusal.reason.capability === capability, listed ? "no refusal Unsupported for listed " + capability : "a refusal Unsupported(" + capability + ")", () => refused.length === 0 ? "no refusal" : refused.map(describeError).join(", "));
|
|
1289
|
+
});
|
|
1290
|
+
const {
|
|
1291
|
+
chat,
|
|
1292
|
+
thread
|
|
1293
|
+
} = this;
|
|
1294
|
+
const text = conformanceText(this.rule);
|
|
1295
|
+
switch (capability) {
|
|
1296
|
+
case "edit":
|
|
1297
|
+
return Effect.flatMap(this.post({}), posted => expect(chat.edit(thread, posted.id, {
|
|
1298
|
+
markdown: text
|
|
1299
|
+
})));
|
|
1300
|
+
case "delete":
|
|
1301
|
+
return Effect.flatMap(this.post({}), posted => expect(chat.delete(thread, posted.id)));
|
|
1302
|
+
case "fetchMessage":
|
|
1303
|
+
return Effect.flatMap(this.post({}), posted => expect(chat.fetchMessage(thread, posted.id)));
|
|
1304
|
+
case "history":
|
|
1305
|
+
return expect(Stream.runDrain(Stream.take(chat.history(thread, {
|
|
1306
|
+
direction: "backward"
|
|
1307
|
+
}), 1)));
|
|
1308
|
+
case "download":
|
|
1309
|
+
return expect(Stream.runDrain(chat.download(thread, {
|
|
1310
|
+
id: "conformance-missing"
|
|
1311
|
+
}, {
|
|
1312
|
+
maxBytes: 1
|
|
1313
|
+
})));
|
|
1314
|
+
case "files":
|
|
1315
|
+
return expect(chat.post(thread, {
|
|
1316
|
+
markdown: text,
|
|
1317
|
+
files: [conformanceFile(this.rule)]
|
|
1318
|
+
}), track);
|
|
1319
|
+
case "replyTo":
|
|
1320
|
+
return Effect.flatMap(this.post({}), target => expect(chat.post(thread, {
|
|
1321
|
+
markdown: text,
|
|
1322
|
+
replyTo: {
|
|
1323
|
+
messageId: target.id
|
|
1324
|
+
}
|
|
1325
|
+
}), track));
|
|
1326
|
+
case "startThread":
|
|
1327
|
+
return Effect.flatMap(this.post({}), posted => expect(chat.startThread(thread, posted.id)));
|
|
1328
|
+
case "getThread":
|
|
1329
|
+
return expect(chat.getThread(thread));
|
|
1330
|
+
case "opener":
|
|
1331
|
+
return expect(chat.opener(thread));
|
|
1332
|
+
case "getUser":
|
|
1333
|
+
return Effect.flatMap(this.userPosts(), event => expect(chat.getUser(this.options.platform, event.message.author.id)));
|
|
1334
|
+
case "buttons":
|
|
1335
|
+
return expect(chat.post(thread, {
|
|
1336
|
+
markdown: text,
|
|
1337
|
+
actions: [conformanceButton(this.rule)]
|
|
1338
|
+
}), track);
|
|
1339
|
+
case "selects":
|
|
1340
|
+
return expect(chat.post(thread, {
|
|
1341
|
+
markdown: text,
|
|
1342
|
+
actions: [conformanceSelect(this.rule)]
|
|
1343
|
+
}), track);
|
|
1344
|
+
case "modals":
|
|
1345
|
+
// Probing a modal requires the interaction hook and a clickable element.
|
|
1346
|
+
return this.options.interactions === undefined || !(this.has("buttons") || this.has("selects")) ? Effect.void : Effect.andThen(this.openModal(probeModal.open()), checkRefusal);
|
|
1347
|
+
case "modalErrors":
|
|
1348
|
+
// Its absence means a degraded answer, not a refusal, so it has no inverse.
|
|
1349
|
+
return Effect.void;
|
|
1350
|
+
case "commands":
|
|
1351
|
+
// A deferral built by hand, which no adapter can follow up: it must fail, and not with Unsupported when listed.
|
|
1352
|
+
return expect(chat.followUp(ChatInteraction.defer(ChatInteraction.CommandInvoked.make({
|
|
1353
|
+
id: "conformance",
|
|
1354
|
+
text: "",
|
|
1355
|
+
thread,
|
|
1356
|
+
userId: "conformance",
|
|
1357
|
+
raw: {}
|
|
1358
|
+
}), {
|
|
1359
|
+
visibility: "public"
|
|
1360
|
+
}), {
|
|
1361
|
+
markdown: text
|
|
1362
|
+
}));
|
|
1363
|
+
case "ephemeral":
|
|
1364
|
+
// Probing a private answer requires the command hook.
|
|
1365
|
+
return this.options.interactions?.command === undefined ? Effect.void : Effect.suspend(() => {
|
|
1366
|
+
this.recording.onCommand = () => ChatInteraction.respond({
|
|
1367
|
+
markdown: text
|
|
1368
|
+
});
|
|
1369
|
+
return Effect.andThen(this.command("conformance"), checkRefusal);
|
|
1370
|
+
});
|
|
1371
|
+
case "nativeStream":
|
|
1372
|
+
return Effect.flatMap(Registry, registry => Effect.flatMap(this.call(registry.get(this.options.platform)), adapter => this.check(adapter.nativeStream !== undefined === listed, listed ? "a nativeStream, as the descriptor lists it" : "no nativeStream, as the descriptor lacks it", () => adapter.nativeStream === undefined ? "no nativeStream" : "a nativeStream")));
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
get cleanup() {
|
|
1376
|
+
return Effect.suspend(() => {
|
|
1377
|
+
if (!this.has("delete")) return Effect.void;
|
|
1378
|
+
const created = this.created.splice(0).reverse();
|
|
1379
|
+
return Effect.forEach(created, ({
|
|
1380
|
+
id,
|
|
1381
|
+
thread
|
|
1382
|
+
}) => Effect.ignore(this.chat.delete(thread, id)), {
|
|
1383
|
+
discard: true
|
|
1384
|
+
});
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
const conformanceFile = rule => ({
|
|
1389
|
+
name: "conformance.txt",
|
|
1390
|
+
contentType: "text/plain",
|
|
1391
|
+
content: new TextEncoder().encode(conformanceText(rule) + " " + "x".repeat(64))
|
|
1392
|
+
});
|
|
1393
|
+
const findIn = (messages, id) => messages.find(message => message.id === id);
|
|
1394
|
+
/** A refusal of the text must not blame the files, or `ChatMarkdown` would post again without them. */
|
|
1395
|
+
const textTooLarge = {
|
|
1396
|
+
expected: "TooLarge without subject files or detail file_refused",
|
|
1397
|
+
test: reason => reason._tag === "TooLarge" && reason.subject !== "files" && reason.detail !== fileRefused
|
|
1398
|
+
};
|
|
1399
|
+
const mentionLike = "@everyone @here <@U0000> <!here> <!channel> <@&1> <#C0000>";
|
|
1400
|
+
/** Text a platform takes in any quantity: no emoji, which Slack limits separately. */
|
|
1401
|
+
const measureFitsBlock = "a < b & c > d\n\n```ts\nconst x = 1 < 2\n```\n\n\u{1D400}\u{1D401} caf\u00e9\n\n";
|
|
1402
|
+
const measureSamples = ["", "x", "hello world", "<", "a < b", "<@U0000>", "& > &", "```\ncode < 1\n```\n", "```", "\u{1D400}\u{1D401}", "\u{1F600}\u{1F44D}\u{1F3FD}", ":grinning:", "caf\u00e9"];
|
|
1403
|
+
const probeModal = /*#__PURE__*/ChatInteraction.modal("conformance-modal", {
|
|
1404
|
+
title: "Conformance",
|
|
1405
|
+
fields: {
|
|
1406
|
+
answer: /*#__PURE__*/ChatInteraction.textInput({
|
|
1407
|
+
label: "Answer"
|
|
1408
|
+
})
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
/** The fixed schemas of `actions/valueRoundTrips`, each with the value posted. */
|
|
1412
|
+
const valueCases = [{
|
|
1413
|
+
schema: Schema.String,
|
|
1414
|
+
value: "v1.4.2"
|
|
1415
|
+
}, {
|
|
1416
|
+
schema: /*#__PURE__*/Schema.Struct({
|
|
1417
|
+
version: Schema.String,
|
|
1418
|
+
attempt: Schema.Number
|
|
1419
|
+
}),
|
|
1420
|
+
value: {
|
|
1421
|
+
version: "v1",
|
|
1422
|
+
attempt: 2
|
|
1423
|
+
}
|
|
1424
|
+
}, {
|
|
1425
|
+
schema: /*#__PURE__*/Schema.Union([Schema.String, Schema.Number]),
|
|
1426
|
+
value: 123
|
|
1427
|
+
}, {
|
|
1428
|
+
schema: /*#__PURE__*/Schema.Union([Schema.String, Schema.Number]),
|
|
1429
|
+
value: "123"
|
|
1430
|
+
}, {
|
|
1431
|
+
schema: Schema.String,
|
|
1432
|
+
value: "a < b & \"c\" \u{1D400}"
|
|
1433
|
+
}];
|
|
1434
|
+
const sameValue = (a, b) => typeof a === typeof b && canonicalJson(a) === canonicalJson(b);
|
|
1435
|
+
/** The largest `n` in `[0, limit]` that `fits`, for a `fits` that holds up to some `n` and fails past it. */
|
|
1436
|
+
const largestFitting = (limit, fits) => {
|
|
1437
|
+
let low = 0;
|
|
1438
|
+
let high = limit;
|
|
1439
|
+
while (low < high) {
|
|
1440
|
+
const middle = Math.ceil((low + high) / 2);
|
|
1441
|
+
if (fits(middle)) low = middle;else high = middle - 1;
|
|
1442
|
+
}
|
|
1443
|
+
return low;
|
|
1444
|
+
};
|
|
1445
|
+
/**
|
|
1446
|
+
* Creates the conformance suite, as plain Effects keyed by rule name, so any
|
|
1447
|
+
* test runner can run them.
|
|
1448
|
+
*
|
|
1449
|
+
* **Details**
|
|
1450
|
+
*
|
|
1451
|
+
* - Each rule needs the adapter under test registered in `Chat` and a way to
|
|
1452
|
+
* make another identity's message appear in `thread`, which must be a
|
|
1453
|
+
* channel the suite may write to.
|
|
1454
|
+
* - A rule is never skipped. When the descriptor lacks a capability a rule
|
|
1455
|
+
* needs, the rule becomes its inverse: the op fails with `Unsupported`.
|
|
1456
|
+
* There is an `unsupported/{capability}` rule for every capability. When
|
|
1457
|
+
* the capability is listed, it calls the op and fails if the op fails with
|
|
1458
|
+
* `Unsupported`, so a descriptor that lies in either direction fails.
|
|
1459
|
+
* - A listed capability never fails with `Unsupported`, which every rule
|
|
1460
|
+
* checks as it goes.
|
|
1461
|
+
* - The three `retries/*` rules exist only when `failNext` is given.
|
|
1462
|
+
* `post/refusedFile` exists only when `refuseFiles` is given.
|
|
1463
|
+
* - The rules that need a click exist only when `interactions` is given,
|
|
1464
|
+
* since neither platform has an API that clicks. A live run leaves it out
|
|
1465
|
+
* and runs only the outbound rules. The suite provides its own recording
|
|
1466
|
+
* `ChatInteraction.Handler` to the hook, so the rules still need only
|
|
1467
|
+
* `Chat` and `Registry`.
|
|
1468
|
+
* - `modalErrors` has no inverse rule: without it an `errors` reply is a
|
|
1469
|
+
* degraded answer, not a refusal.
|
|
1470
|
+
* - The `command/*` rules and `unsupported/ephemeral` exist only when
|
|
1471
|
+
* `interactions.command` is given. `unsupported/commands` always runs: it
|
|
1472
|
+
* calls `followUp` with a deferral the suite builds by hand, which must
|
|
1473
|
+
* fail `Unsupported` without `commands`, and fail some other way with it.
|
|
1474
|
+
* - Every rule deletes what it posted when it ends, pass or fail, when the
|
|
1475
|
+
* platform can delete.
|
|
1476
|
+
*
|
|
1477
|
+
* **Gotchas**
|
|
1478
|
+
*
|
|
1479
|
+
* Rule names are stable, an existing rule is never tightened, and a new rule
|
|
1480
|
+
* arrives only behind a new capability or with a changeset saying third-party
|
|
1481
|
+
* adapters may start failing. `unsupported/buttons` and
|
|
1482
|
+
* `unsupported/selects` are such rules: an adapter that ignores `actions`
|
|
1483
|
+
* and posts anyway fails them. So is `unsupported/commands`: an adapter whose
|
|
1484
|
+
* `followUp` does anything but fail `Unsupported` fails it. The `retries/retrySafe` rule waits for real
|
|
1485
|
+
* time, so run the suite on a live `Clock`.
|
|
1486
|
+
*
|
|
1487
|
+
* @stability unstable
|
|
1488
|
+
* @category testing
|
|
1489
|
+
* @since 4.1.5
|
|
1490
|
+
*/
|
|
1491
|
+
export const conformance = options => {
|
|
1492
|
+
const rules = {};
|
|
1493
|
+
const {
|
|
1494
|
+
parseMention,
|
|
1495
|
+
platform
|
|
1496
|
+
} = options;
|
|
1497
|
+
const rule = (name, needs, body) => {
|
|
1498
|
+
rules[name] = Effect.gen(function* () {
|
|
1499
|
+
const chat = yield* Chat.Chat;
|
|
1500
|
+
const descriptor = yield* Effect.mapError(chat.descriptor(platform), error => failure(name, "a registered adapter", describeError(error), error));
|
|
1501
|
+
const t = new Tester(name, chat, descriptor, options);
|
|
1502
|
+
const missing = needs.find(capability => !t.has(capability));
|
|
1503
|
+
return yield* (missing === undefined ? body(t) : t.probe(missing)).pipe(Effect.ensuring(t.cleanup));
|
|
1504
|
+
});
|
|
1505
|
+
};
|
|
1506
|
+
rule("post/fetchable", ["fetchMessage"], t => Effect.gen(function* () {
|
|
1507
|
+
const posted = yield* t.post({});
|
|
1508
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1509
|
+
yield* t.check(posted.id === message.id && ChatThread.equals(posted.thread, t.thread) && ChatThread.equals(message.thread, t.thread), "the posted message, addressed to " + ChatThread.toString(t.thread), () => "message " + message.id + " in " + ChatThread.toString(message.thread));
|
|
1510
|
+
}));
|
|
1511
|
+
rule("post/authorIsSelf", ["fetchMessage"], t => Effect.gen(function* () {
|
|
1512
|
+
const posted = yield* t.post({});
|
|
1513
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1514
|
+
yield* t.check(message.author.isSelf && message.author.isBot, "author.isSelf and author.isBot", () => "isSelf " + message.author.isSelf + ", isBot " + message.author.isBot);
|
|
1515
|
+
}));
|
|
1516
|
+
rule("post/replyTo", ["replyTo", "fetchMessage"], t => Effect.gen(function* () {
|
|
1517
|
+
const target = yield* t.post({});
|
|
1518
|
+
const reply = yield* t.post({
|
|
1519
|
+
replyTo: {
|
|
1520
|
+
messageId: target.id
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, reply.id));
|
|
1524
|
+
yield* t.check(message.replyTo?.messageId === target.id, "replyTo " + target.id, () => "replyTo " + message.replyTo?.messageId);
|
|
1525
|
+
}));
|
|
1526
|
+
rule("post/files", ["files", "download", "fetchMessage"], t => Effect.gen(function* () {
|
|
1527
|
+
const file = conformanceFile(t.rule);
|
|
1528
|
+
const posted = yield* t.post({
|
|
1529
|
+
files: [file]
|
|
1530
|
+
});
|
|
1531
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1532
|
+
yield* t.check(message.attachments.length === 1, "one attachment", () => message.attachments.length + "");
|
|
1533
|
+
const chunks = yield* t.collect(t.chat.download(t.thread, message.attachments[0], {
|
|
1534
|
+
maxBytes: file.content.length
|
|
1535
|
+
}));
|
|
1536
|
+
const bytes = Bytes.concat(chunks);
|
|
1537
|
+
yield* t.check(Bytes.Equivalence(bytes, file.content), "the uploaded bytes", () => bytes.length + " different bytes");
|
|
1538
|
+
}));
|
|
1539
|
+
const refuseFiles = options.refuseFiles;
|
|
1540
|
+
if (refuseFiles !== undefined) {
|
|
1541
|
+
rule("post/refusedFile", ["files", "history"], t => Effect.gen(function* () {
|
|
1542
|
+
const before = yield* t.collect(t.chat.history(t.thread, {
|
|
1543
|
+
direction: "forward"
|
|
1544
|
+
}));
|
|
1545
|
+
yield* refuseFiles();
|
|
1546
|
+
const exit = yield* Effect.exit(t.chat.post(t.thread, {
|
|
1547
|
+
markdown: conformanceText(t.rule),
|
|
1548
|
+
files: [conformanceFile(t.rule)]
|
|
1549
|
+
}));
|
|
1550
|
+
if (Exit.isSuccess(exit)) t.track(exit.value);
|
|
1551
|
+
const after = yield* t.collect(t.chat.history(t.thread, {
|
|
1552
|
+
direction: "forward"
|
|
1553
|
+
}));
|
|
1554
|
+
const beforeIds = new Set(before.map(message => message.id));
|
|
1555
|
+
for (const message of after) {
|
|
1556
|
+
if (message.author.isSelf && !beforeIds.has(message.id) && !t.created.some(({
|
|
1557
|
+
id
|
|
1558
|
+
}) => id === message.id)) {
|
|
1559
|
+
t.created.push({
|
|
1560
|
+
thread: message.thread,
|
|
1561
|
+
id: message.id
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
const error = Exit.findErrorOption(exit);
|
|
1566
|
+
const reason = Option.isSome(error) ? error.value.reason : undefined;
|
|
1567
|
+
const listed = reason?._tag === "Unsupported" && t.has(reason.capability);
|
|
1568
|
+
yield* t.check(!listed && reason?.retry === "denied" && reason.detail === fileRefused, "denied with detail file_refused, not Unsupported for a listed capability", () => describeExit(exit) + (listed ? " for a listed capability" : ""));
|
|
1569
|
+
yield* t.check(after.length === before.length && after.every((message, i) => message.id === before[i].id), "no new message", () => after.length + " messages after, " + before.length + " before");
|
|
1570
|
+
}));
|
|
1571
|
+
}
|
|
1572
|
+
rule("post/tooLarge", [], t => t.expectReason("TooLarge", t.chat.post(t.thread, {
|
|
1573
|
+
markdown: "x".repeat(t.descriptor.limits.messageLength + 1)
|
|
1574
|
+
}), posted => t.track(posted), textTooLarge));
|
|
1575
|
+
rule("descriptor/measureFits", [], t => Effect.gen(function* () {
|
|
1576
|
+
const {
|
|
1577
|
+
measure
|
|
1578
|
+
} = t.descriptor;
|
|
1579
|
+
const limit = t.descriptor.limits.messageLength;
|
|
1580
|
+
const largest = make => make(largestFitting(limit, n => measure(make(n)) <= limit));
|
|
1581
|
+
const blocks = largest(n => measureFitsBlock.repeat(n));
|
|
1582
|
+
const markdown = largest(n => blocks + "x".repeat(n));
|
|
1583
|
+
yield* t.post({
|
|
1584
|
+
markdown
|
|
1585
|
+
});
|
|
1586
|
+
}));
|
|
1587
|
+
rule("descriptor/measureAdds", [], t => Effect.gen(function* () {
|
|
1588
|
+
const {
|
|
1589
|
+
measure
|
|
1590
|
+
} = t.descriptor;
|
|
1591
|
+
for (const a of measureSamples) {
|
|
1592
|
+
for (const b of measureSamples) {
|
|
1593
|
+
yield* t.check(measure(a + b) <= measure(a) + measure(b), "measure(a + b) <= measure(a) + measure(b)", () => JSON.stringify(a) + " + " + JSON.stringify(b) + " measures " + measure(a + b));
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
1597
|
+
yield* t.check(measure(letters) === letters.length, "ASCII letters measured at one each", () => letters.length + " letters measure " + measure(letters));
|
|
1598
|
+
}));
|
|
1599
|
+
rule("post/noMentions", ["fetchMessage"], t => Effect.gen(function* () {
|
|
1600
|
+
const posted = yield* t.post({
|
|
1601
|
+
markdown: mentionLike
|
|
1602
|
+
});
|
|
1603
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1604
|
+
yield* t.check(message.mentions.length === 0, "no mentions", () => message.mentions.length + " mentions");
|
|
1605
|
+
}));
|
|
1606
|
+
const goneId = Effect.fnUntraced(function* (t) {
|
|
1607
|
+
const posted = yield* t.post({});
|
|
1608
|
+
if (!t.has("delete")) return posted.id + "0";
|
|
1609
|
+
yield* t.call(t.chat.delete(t.thread, posted.id));
|
|
1610
|
+
return posted.id;
|
|
1611
|
+
});
|
|
1612
|
+
rule("edit/keepsId", ["edit", "fetchMessage"], t => Effect.gen(function* () {
|
|
1613
|
+
const posted = yield* t.post({
|
|
1614
|
+
markdown: conformanceText(t.rule) + " before"
|
|
1615
|
+
});
|
|
1616
|
+
const before = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1617
|
+
yield* t.call(t.chat.edit(t.thread, posted.id, {
|
|
1618
|
+
markdown: conformanceText(t.rule) + " after"
|
|
1619
|
+
}));
|
|
1620
|
+
const after = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1621
|
+
yield* t.check(after.id === posted.id && after.text !== before.text, "the same id with new text", () => "id " + after.id + (after.text === before.text ? " with the old text" : ""));
|
|
1622
|
+
}));
|
|
1623
|
+
rule("edit/unknownId", ["edit"], t => Effect.flatMap(goneId(t), id => t.expectReason("NotFound", t.chat.edit(t.thread, id, {
|
|
1624
|
+
markdown: conformanceText(t.rule)
|
|
1625
|
+
}))));
|
|
1626
|
+
rule("edit/tooLarge", ["edit"], t => Effect.flatMap(t.post({}), posted => t.expectReason("TooLarge", t.chat.edit(t.thread, posted.id, {
|
|
1627
|
+
markdown: "x".repeat(t.descriptor.limits.messageLength + 1)
|
|
1628
|
+
}), undefined, textTooLarge)));
|
|
1629
|
+
rule("delete/gone", ["delete", "fetchMessage"], t => Effect.gen(function* () {
|
|
1630
|
+
const posted = yield* t.post({});
|
|
1631
|
+
yield* t.call(t.chat.delete(t.thread, posted.id));
|
|
1632
|
+
yield* t.expectReason("NotFound", t.chat.fetchMessage(t.thread, posted.id));
|
|
1633
|
+
}));
|
|
1634
|
+
rule("delete/unknownId", ["delete"], t => Effect.flatMap(goneId(t), id => t.expectReason("NotFound", t.chat.delete(t.thread, id))));
|
|
1635
|
+
rule("history/order", ["history"], t => Effect.gen(function* () {
|
|
1636
|
+
const a = yield* t.post({
|
|
1637
|
+
markdown: conformanceText(t.rule) + " a"
|
|
1638
|
+
});
|
|
1639
|
+
const b = yield* t.post({
|
|
1640
|
+
markdown: conformanceText(t.rule) + " b"
|
|
1641
|
+
});
|
|
1642
|
+
const c = yield* t.post({
|
|
1643
|
+
markdown: conformanceText(t.rule) + " c"
|
|
1644
|
+
});
|
|
1645
|
+
const backward = yield* t.collect(Stream.take(t.chat.history(t.thread, {
|
|
1646
|
+
direction: "backward"
|
|
1647
|
+
}), 3));
|
|
1648
|
+
const forward = yield* t.collect(Stream.take(t.chat.history(t.thread, {
|
|
1649
|
+
direction: "forward",
|
|
1650
|
+
from: a.id
|
|
1651
|
+
}), 2));
|
|
1652
|
+
const ids = messages => messages.map(m => m.id).join(",");
|
|
1653
|
+
yield* t.check(ids(backward) === [c.id, b.id, a.id].join(","), "backward " + [c.id, b.id, a.id], () => "backward " + ids(backward));
|
|
1654
|
+
yield* t.check(ids(forward) === [b.id, c.id].join(","), "forward " + [b.id, c.id], () => "forward " + ids(forward));
|
|
1655
|
+
}));
|
|
1656
|
+
rule("history/fromExclusive", ["history"], t => Effect.gen(function* () {
|
|
1657
|
+
const a = yield* t.post({
|
|
1658
|
+
markdown: conformanceText(t.rule) + " a"
|
|
1659
|
+
});
|
|
1660
|
+
const b = yield* t.post({
|
|
1661
|
+
markdown: conformanceText(t.rule) + " b"
|
|
1662
|
+
});
|
|
1663
|
+
const before = yield* t.collect(Stream.take(t.chat.history(t.thread, {
|
|
1664
|
+
direction: "backward",
|
|
1665
|
+
from: b.id
|
|
1666
|
+
}), 1));
|
|
1667
|
+
const after = yield* t.collect(Stream.take(t.chat.history(t.thread, {
|
|
1668
|
+
direction: "forward",
|
|
1669
|
+
from: a.id
|
|
1670
|
+
}), 1));
|
|
1671
|
+
yield* t.check(before[0]?.id === a.id && after[0]?.id === b.id, "the message next to from, not from itself", () => "backward " + before[0]?.id + ", forward " + after[0]?.id);
|
|
1672
|
+
}));
|
|
1673
|
+
rule("history/sameAsInbound", ["history"], t => Effect.gen(function* () {
|
|
1674
|
+
const event = yield* t.userPosts();
|
|
1675
|
+
const history = yield* t.collect(Stream.take(t.chat.history(t.thread, {
|
|
1676
|
+
direction: "backward"
|
|
1677
|
+
}), 20));
|
|
1678
|
+
const read = findIn(history, event.message.id);
|
|
1679
|
+
yield* t.check(read !== undefined && sameMessage(event.message, read), "the inbound message in history", () => read === undefined ? "no such message" : "a different message");
|
|
1680
|
+
}));
|
|
1681
|
+
rule("history/startsWithOpener", ["history", "startThread"], t => Effect.gen(function* () {
|
|
1682
|
+
const opener = yield* t.post({
|
|
1683
|
+
markdown: conformanceText(t.rule) + " opener"
|
|
1684
|
+
});
|
|
1685
|
+
const thread = yield* t.call(t.chat.startThread(t.thread, opener.id, {
|
|
1686
|
+
name: conformanceText(t.rule)
|
|
1687
|
+
}));
|
|
1688
|
+
yield* t.post({
|
|
1689
|
+
markdown: conformanceText(t.rule) + " reply"
|
|
1690
|
+
}, thread);
|
|
1691
|
+
const first = yield* t.collect(Stream.take(t.chat.history(thread, {
|
|
1692
|
+
direction: "forward"
|
|
1693
|
+
}), 1));
|
|
1694
|
+
yield* t.check(first[0]?.id === opener.id && ChatThread.equals(first[0].thread, t.thread), "the opener first, addressed to " + ChatThread.toString(t.thread), () => first[0] === undefined ? "an empty history" : "message " + first[0].id + " in " + ChatThread.toString(first[0].thread));
|
|
1695
|
+
}));
|
|
1696
|
+
rule("message/threadStable", ["fetchMessage", "history", "startThread"], t => Effect.gen(function* () {
|
|
1697
|
+
const event = yield* t.userPosts();
|
|
1698
|
+
const id = event.message.id;
|
|
1699
|
+
const read = Effect.gen(function* () {
|
|
1700
|
+
const fetched = yield* t.call(t.chat.fetchMessage(t.thread, id));
|
|
1701
|
+
const history = yield* t.collect(Stream.take(t.chat.history(t.thread, {
|
|
1702
|
+
direction: "backward"
|
|
1703
|
+
}), 20));
|
|
1704
|
+
return [fetched, findIn(history, id)];
|
|
1705
|
+
});
|
|
1706
|
+
const before = yield* read;
|
|
1707
|
+
const thread = yield* t.call(t.chat.startThread(t.thread, id, {
|
|
1708
|
+
name: conformanceText(t.rule)
|
|
1709
|
+
}));
|
|
1710
|
+
yield* t.post({
|
|
1711
|
+
markdown: conformanceText(t.rule) + " reply"
|
|
1712
|
+
}, thread);
|
|
1713
|
+
const after = yield* read;
|
|
1714
|
+
const reads = [event.message, ...before, ...after];
|
|
1715
|
+
yield* t.check(reads.every(message => message !== undefined && ChatThread.equals(message.thread, t.thread)), "every read addressed to " + ChatThread.toString(t.thread), () => reads.map(message => message === undefined ? "missing" : ChatThread.toString(message.thread)).join(", "));
|
|
1716
|
+
}));
|
|
1717
|
+
rule("inbound/fetchable", ["fetchMessage"], t => Effect.gen(function* () {
|
|
1718
|
+
const event = yield* t.userPosts();
|
|
1719
|
+
const message = yield* t.call(t.chat.fetchMessage(event.thread, event.message.id));
|
|
1720
|
+
yield* t.check(sameMessage(event.message, message), "the inbound message", () => "a different message");
|
|
1721
|
+
}));
|
|
1722
|
+
rule("inbound/notSelf", [], t => Effect.gen(function* () {
|
|
1723
|
+
const event = yield* t.userPosts();
|
|
1724
|
+
yield* t.check(!event.message.author.isSelf, "author.isSelf false", () => "author.isSelf true");
|
|
1725
|
+
yield* checkEvent(event, {
|
|
1726
|
+
platform,
|
|
1727
|
+
parseMention
|
|
1728
|
+
}).pipe(Effect.mapError(error => failure(t.rule, error.expected, error.actual, error.cause)));
|
|
1729
|
+
}));
|
|
1730
|
+
rule("download/maxBytes", ["files", "download", "fetchMessage"], t => Effect.gen(function* () {
|
|
1731
|
+
const file = conformanceFile(t.rule);
|
|
1732
|
+
const posted = yield* t.post({
|
|
1733
|
+
files: [file]
|
|
1734
|
+
});
|
|
1735
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1736
|
+
yield* t.check(message.attachments.length === 1, "one attachment", () => message.attachments.length + "");
|
|
1737
|
+
yield* t.expectReason("TooLarge", Stream.runDrain(t.chat.download(t.thread, message.attachments[0], {
|
|
1738
|
+
maxBytes: 8
|
|
1739
|
+
})));
|
|
1740
|
+
}));
|
|
1741
|
+
rule("startThread/idempotent", ["startThread"], t => Effect.gen(function* () {
|
|
1742
|
+
const posted = yield* t.post({});
|
|
1743
|
+
const first = yield* t.call(t.chat.startThread(t.thread, posted.id, {
|
|
1744
|
+
name: conformanceText(t.rule)
|
|
1745
|
+
}));
|
|
1746
|
+
const second = yield* t.call(t.chat.startThread(t.thread, posted.id));
|
|
1747
|
+
yield* t.check(ChatThread.equals(first, second), ChatThread.toString(first), () => ChatThread.toString(second));
|
|
1748
|
+
}));
|
|
1749
|
+
rule("opener/noneOutsideThread", ["opener"], t => Effect.flatMap(t.call(t.chat.opener(t.thread)), opener => t.check(Option.isNone(opener), "no opener", () => "an opener")));
|
|
1750
|
+
rule("descriptor/streamFitsMessage", ["nativeStream"], t => {
|
|
1751
|
+
const {
|
|
1752
|
+
messageLength,
|
|
1753
|
+
streamLength
|
|
1754
|
+
} = t.descriptor.limits;
|
|
1755
|
+
return t.check(streamLength !== undefined && streamLength <= messageLength, "limits.streamLength at most " + messageLength, () => "limits.streamLength " + streamLength);
|
|
1756
|
+
});
|
|
1757
|
+
const openStream = Effect.fnUntraced(function* (t, markdown) {
|
|
1758
|
+
const registry = yield* Registry;
|
|
1759
|
+
const adapter = yield* t.call(registry.get(platform));
|
|
1760
|
+
const native = adapter.nativeStream;
|
|
1761
|
+
const event = yield* t.userPosts();
|
|
1762
|
+
const posted = yield* t.call(native.start(t.thread, {
|
|
1763
|
+
markdown,
|
|
1764
|
+
recipient: event.message.author.id
|
|
1765
|
+
}));
|
|
1766
|
+
t.track(posted);
|
|
1767
|
+
return {
|
|
1768
|
+
native,
|
|
1769
|
+
posted
|
|
1770
|
+
};
|
|
1771
|
+
});
|
|
1772
|
+
rule("nativeStream/concatenates", ["nativeStream", "fetchMessage"], t => Effect.gen(function* () {
|
|
1773
|
+
const first = conformanceText(t.rule) + " one";
|
|
1774
|
+
const {
|
|
1775
|
+
native,
|
|
1776
|
+
posted
|
|
1777
|
+
} = yield* openStream(t, first);
|
|
1778
|
+
const appended = yield* t.call(native.append(t.thread, posted.id, " two", {
|
|
1779
|
+
flush: true
|
|
1780
|
+
})).pipe(Effect.ensuring(Effect.ignore(native.stop(t.thread, posted.id, {
|
|
1781
|
+
end: "done"
|
|
1782
|
+
}))));
|
|
1783
|
+
yield* t.check(appended.state === "open" && appended.held === 0, "an open append holding nothing", () => appended.state + " holding " + appended.held);
|
|
1784
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1785
|
+
yield* t.check(message.text === first + " two", JSON.stringify(first + " two"), () => JSON.stringify(message.text));
|
|
1786
|
+
}));
|
|
1787
|
+
rule("nativeStream/appendAfterStop", ["nativeStream", "fetchMessage"], t => Effect.gen(function* () {
|
|
1788
|
+
const first = conformanceText(t.rule);
|
|
1789
|
+
const {
|
|
1790
|
+
native,
|
|
1791
|
+
posted
|
|
1792
|
+
} = yield* openStream(t, first);
|
|
1793
|
+
yield* t.call(native.stop(t.thread, posted.id, {
|
|
1794
|
+
end: "done"
|
|
1795
|
+
}));
|
|
1796
|
+
const appended = yield* t.call(native.append(t.thread, posted.id, " after", {
|
|
1797
|
+
flush: true
|
|
1798
|
+
}));
|
|
1799
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1800
|
+
yield* t.check(appended.state === "closed" && message.text === first, "closed, with the text unchanged", () => appended.state + " with " + JSON.stringify(message.text));
|
|
1801
|
+
}));
|
|
1802
|
+
// --- buttons and modals ----------------------------------------------------
|
|
1803
|
+
const limit = (t, name) => Effect.flatMap(t.check(t.descriptor.limits[name] !== undefined, "limits." + name + " on a descriptor with its capability", () => "no limits." + name), () => Effect.succeed(t.descriptor.limits[name]));
|
|
1804
|
+
rule("actions/posts", ["buttons"], t => Effect.gen(function* () {
|
|
1805
|
+
const posted = yield* t.post({
|
|
1806
|
+
actions: [conformanceButton(t.rule)]
|
|
1807
|
+
});
|
|
1808
|
+
if (!t.has("fetchMessage")) return;
|
|
1809
|
+
const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id));
|
|
1810
|
+
yield* t.check(message.id === posted.id, "the posted message " + posted.id, () => "message " + message.id);
|
|
1811
|
+
}));
|
|
1812
|
+
rule("actions/tooMany", ["buttons"], t => Effect.gen(function* () {
|
|
1813
|
+
const most = yield* limit(t, "actionsPerMessage");
|
|
1814
|
+
const actions = Array.from({
|
|
1815
|
+
length: most + 1
|
|
1816
|
+
}, (_, i) => ({
|
|
1817
|
+
_tag: "Button",
|
|
1818
|
+
id: "c" + i,
|
|
1819
|
+
label: "c" + i
|
|
1820
|
+
}));
|
|
1821
|
+
yield* t.expectReason("TooLarge", t.chat.post(t.thread, {
|
|
1822
|
+
markdown: conformanceText(t.rule),
|
|
1823
|
+
actions
|
|
1824
|
+
}), posted => t.track(posted));
|
|
1825
|
+
}));
|
|
1826
|
+
rule("actions/dataTooLarge", ["buttons"], t => Effect.gen(function* () {
|
|
1827
|
+
const most = yield* limit(t, "actionDataLength");
|
|
1828
|
+
const id = most >= "conformance".length ? "conformance" : "c".repeat(most + 1);
|
|
1829
|
+
const value = "x".repeat(most + 1 - id.length);
|
|
1830
|
+
const button = {
|
|
1831
|
+
_tag: "Button",
|
|
1832
|
+
id,
|
|
1833
|
+
label: "c",
|
|
1834
|
+
...(value === "" ? {} : {
|
|
1835
|
+
value
|
|
1836
|
+
})
|
|
1837
|
+
};
|
|
1838
|
+
yield* t.expectReason("TooLarge", t.chat.post(t.thread, {
|
|
1839
|
+
markdown: conformanceText(t.rule),
|
|
1840
|
+
actions: [button]
|
|
1841
|
+
}), posted => t.track(posted));
|
|
1842
|
+
}));
|
|
1843
|
+
rule("descriptor/measureAddsActions", ["buttons"], t => Effect.gen(function* () {
|
|
1844
|
+
const {
|
|
1845
|
+
measure
|
|
1846
|
+
} = t.descriptor;
|
|
1847
|
+
const button = conformanceButton(t.rule);
|
|
1848
|
+
const sets = [[button], [{
|
|
1849
|
+
...button,
|
|
1850
|
+
value: "a < b & \u{1D400}"
|
|
1851
|
+
}], [button, {
|
|
1852
|
+
_tag: "LinkButton",
|
|
1853
|
+
label: "Link",
|
|
1854
|
+
url: "https://example.com/?a=1&b=<2>"
|
|
1855
|
+
}], [conformanceSelect(t.rule)]];
|
|
1856
|
+
for (const markdown of measureSamples) {
|
|
1857
|
+
yield* t.check(measure(markdown, []) === measure(markdown), "measure(md, []) equal to measure(md)", () => JSON.stringify(markdown) + " measures " + measure(markdown, []) + " and " + measure(markdown));
|
|
1858
|
+
for (const actions of sets) {
|
|
1859
|
+
const both = measure(markdown, actions);
|
|
1860
|
+
yield* t.check(both <= measure(markdown) + measure("", actions) && both >= measure(markdown), "measure(md) <= measure(md, actions) <= measure(md) + measure(\"\", actions)", () => JSON.stringify(markdown) + " with " + actions.map(action => action._tag) + " measures " + both);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}));
|
|
1864
|
+
rule("descriptor/measureFitsActions", ["buttons"], t => Effect.gen(function* () {
|
|
1865
|
+
const {
|
|
1866
|
+
measure
|
|
1867
|
+
} = t.descriptor;
|
|
1868
|
+
const most = t.descriptor.limits.messageLength;
|
|
1869
|
+
// A short label, so a platform whose labels are short still takes the button.
|
|
1870
|
+
const actions = [{
|
|
1871
|
+
...conformanceButton(t.rule),
|
|
1872
|
+
label: "fits",
|
|
1873
|
+
value: "x"
|
|
1874
|
+
}];
|
|
1875
|
+
const length = largestFitting(most, n => measure("x".repeat(n), actions) <= most);
|
|
1876
|
+
yield* t.post({
|
|
1877
|
+
markdown: "x".repeat(length),
|
|
1878
|
+
actions
|
|
1879
|
+
});
|
|
1880
|
+
}));
|
|
1881
|
+
const interactions = options.interactions;
|
|
1882
|
+
if (interactions !== undefined) {
|
|
1883
|
+
rule("actions/valueRoundTrips", ["buttons"], t => Effect.gen(function* () {
|
|
1884
|
+
const buttons = valueCases.map(({
|
|
1885
|
+
schema
|
|
1886
|
+
}, i) => ChatInteraction.button("v" + i, {
|
|
1887
|
+
label: "v" + i,
|
|
1888
|
+
value: schema
|
|
1889
|
+
}));
|
|
1890
|
+
const posted = yield* t.post({
|
|
1891
|
+
actions: buttons.map((button, i) => button.of(valueCases[i].value))
|
|
1892
|
+
});
|
|
1893
|
+
for (const [i, {
|
|
1894
|
+
schema,
|
|
1895
|
+
value
|
|
1896
|
+
}] of valueCases.entries()) {
|
|
1897
|
+
yield* t.click(posted.id, "v" + i);
|
|
1898
|
+
const click = t.recording.clicks[i];
|
|
1899
|
+
const decoded = click?._tag === "ButtonClicked" && click.value !== undefined ? ChatInteraction.decodeValue(schema, click.value) : Option.none();
|
|
1900
|
+
yield* t.check(Option.isSome(decoded) && sameValue(decoded.value, value), "a value that decodes to " + canonicalJson(value), () => click === undefined ? "no click" : "value " + JSON.stringify(click.value));
|
|
1901
|
+
}
|
|
1902
|
+
}));
|
|
1903
|
+
rule("actions/absentValue", ["buttons"], t => Effect.gen(function* () {
|
|
1904
|
+
const posted = yield* t.post({
|
|
1905
|
+
actions: [conformanceButton(t.rule)]
|
|
1906
|
+
});
|
|
1907
|
+
yield* t.click(posted.id, "conformance");
|
|
1908
|
+
const click = t.recording.clicks[0];
|
|
1909
|
+
yield* t.check(click?._tag === "ButtonClicked" && !("value" in click), "a click with no value key", () => click === undefined ? "no click" : "value " + JSON.stringify(click.value));
|
|
1910
|
+
}));
|
|
1911
|
+
rule("actions/origin", ["buttons"], t => Effect.gen(function* () {
|
|
1912
|
+
const posted = yield* t.post({
|
|
1913
|
+
actions: [conformanceButton(t.rule)]
|
|
1914
|
+
});
|
|
1915
|
+
yield* t.click(posted.id, "conformance");
|
|
1916
|
+
const click = t.recording.clicks[0];
|
|
1917
|
+
yield* t.check(click !== undefined && click.messageId === posted.id && ChatThread.equals(click.thread, posted.thread), "a click on " + posted.id + " in " + ChatThread.toString(posted.thread), () => click === undefined ? "no click" : click.messageId + " in " + ChatThread.toString(click.thread));
|
|
1918
|
+
yield* t.checkInteraction(click);
|
|
1919
|
+
}));
|
|
1920
|
+
rule("actions/selectValue", ["selects"], t => Effect.gen(function* () {
|
|
1921
|
+
const posted = yield* t.post({
|
|
1922
|
+
actions: [conformanceSelect(t.rule)]
|
|
1923
|
+
});
|
|
1924
|
+
yield* t.click(posted.id, "conformance", {
|
|
1925
|
+
option: "b"
|
|
1926
|
+
});
|
|
1927
|
+
const event = t.recording.clicks[0];
|
|
1928
|
+
yield* t.check(event?._tag === "SelectChanged" && event.value === "b", "SelectChanged with value b", () => event === undefined ? "no click" : event._tag + " with value " + JSON.stringify(event.value));
|
|
1929
|
+
yield* t.checkInteraction(event);
|
|
1930
|
+
}));
|
|
1931
|
+
rule("edit/removesActions", ["buttons", "edit"], t => Effect.gen(function* () {
|
|
1932
|
+
const posted = yield* t.post({
|
|
1933
|
+
actions: [conformanceButton(t.rule)]
|
|
1934
|
+
});
|
|
1935
|
+
yield* t.call(t.chat.edit(t.thread, posted.id, {
|
|
1936
|
+
markdown: conformanceText(t.rule) + " edited"
|
|
1937
|
+
}));
|
|
1938
|
+
const exit = yield* t.clickExit(posted.id, "conformance");
|
|
1939
|
+
const error = Exit.findErrorOption(exit);
|
|
1940
|
+
yield* t.check(Option.isSome(error) && error.value._tag === "NoSuchElement", "NoSuchElement", () => describeExit(exit));
|
|
1941
|
+
}));
|
|
1942
|
+
rule("edit/addsActions", ["buttons", "edit"], t => Effect.gen(function* () {
|
|
1943
|
+
const posted = yield* t.post({});
|
|
1944
|
+
yield* t.call(t.chat.edit(t.thread, posted.id, {
|
|
1945
|
+
markdown: conformanceText(t.rule) + " edited",
|
|
1946
|
+
actions: [conformanceButton(t.rule)]
|
|
1947
|
+
}));
|
|
1948
|
+
yield* t.click(posted.id, "conformance");
|
|
1949
|
+
yield* t.check(t.recording.clicks.length === 1, "one click", () => t.recording.clicks.length + " clicks");
|
|
1950
|
+
}));
|
|
1951
|
+
rule("modal/origin", ["modals"], t => Effect.gen(function* () {
|
|
1952
|
+
const posted = yield* t.openModal(probeModal.open());
|
|
1953
|
+
yield* t.submit({
|
|
1954
|
+
answer: "conformance"
|
|
1955
|
+
});
|
|
1956
|
+
const submit = t.recording.submits[0];
|
|
1957
|
+
yield* t.check(submit !== undefined && submit.messageId === posted.id && ChatThread.equals(submit.thread, posted.thread), "a submit from " + posted.id + " in " + ChatThread.toString(posted.thread), () => submit === undefined ? "no submit" : submit.messageId + " in " + ChatThread.toString(submit.thread));
|
|
1958
|
+
yield* t.checkInteraction(submit);
|
|
1959
|
+
}));
|
|
1960
|
+
rule("modal/metadataRoundTrips", ["modals"], t => Effect.gen(function* () {
|
|
1961
|
+
const Metadata = Schema.Struct({
|
|
1962
|
+
version: Schema.String
|
|
1963
|
+
});
|
|
1964
|
+
const withMetadata = ChatInteraction.modal("conformance-meta", {
|
|
1965
|
+
title: "Conformance",
|
|
1966
|
+
metadata: Metadata,
|
|
1967
|
+
fields: {
|
|
1968
|
+
answer: ChatInteraction.textInput({
|
|
1969
|
+
label: "Answer"
|
|
1970
|
+
})
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1973
|
+
const value = {
|
|
1974
|
+
version: "v1 < \u{1D400}"
|
|
1975
|
+
};
|
|
1976
|
+
yield* t.openModal(withMetadata.open({
|
|
1977
|
+
metadata: value
|
|
1978
|
+
}));
|
|
1979
|
+
yield* t.submit({
|
|
1980
|
+
answer: "conformance"
|
|
1981
|
+
});
|
|
1982
|
+
yield* t.openModal(probeModal.open());
|
|
1983
|
+
yield* t.submit({
|
|
1984
|
+
answer: "conformance"
|
|
1985
|
+
});
|
|
1986
|
+
const [first, second] = t.recording.submits;
|
|
1987
|
+
const decoded = first?.metadata === undefined ? Option.none() : ChatInteraction.decodeValue(Metadata, first.metadata);
|
|
1988
|
+
yield* t.check(Option.isSome(decoded) && sameValue(decoded.value, value), "metadata that decodes to " + canonicalJson(value), () => first === undefined ? "no submit" : "metadata " + JSON.stringify(first.metadata));
|
|
1989
|
+
yield* t.check(second !== undefined && !("metadata" in second), "a submit with no metadata key", () => second === undefined ? "no submit" : "metadata " + JSON.stringify(second.metadata));
|
|
1990
|
+
}));
|
|
1991
|
+
const refusedTooLarge = Effect.fnUntraced(function* (t) {
|
|
1992
|
+
yield* t.submit({});
|
|
1993
|
+
const refusal = t.recording.refused[0];
|
|
1994
|
+
yield* t.check(refusal?.reason._tag === "TooLarge" && t.recording.submits.length === 0, "a refusal TooLarge and no modal", () => (refusal === undefined ? "no refusal" : "a refusal " + describeError(refusal)) + (t.recording.submits.length === 0 ? "" : " and a submit"));
|
|
1995
|
+
});
|
|
1996
|
+
rule("modal/metadataTooLarge", ["modals"], t => Effect.gen(function* () {
|
|
1997
|
+
const most = yield* limit(t, "modalMetadataLength");
|
|
1998
|
+
const id = "conformance-big";
|
|
1999
|
+
const big = ChatInteraction.modal(id, {
|
|
2000
|
+
title: "Conformance",
|
|
2001
|
+
metadata: Schema.String,
|
|
2002
|
+
fields: {
|
|
2003
|
+
answer: ChatInteraction.textInput({
|
|
2004
|
+
label: "Answer"
|
|
2005
|
+
})
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
yield* t.openModal(big.open({
|
|
2009
|
+
metadata: "x".repeat(Math.max(0, most + 1 - id.length))
|
|
2010
|
+
}));
|
|
2011
|
+
yield* refusedTooLarge(t);
|
|
2012
|
+
}));
|
|
2013
|
+
rule("modal/tooManyFields", ["modals"], t => Effect.gen(function* () {
|
|
2014
|
+
const most = yield* limit(t, "modalFields");
|
|
2015
|
+
const fields = {};
|
|
2016
|
+
for (let i = 0; i <= most; i++) fields["f" + i] = ChatInteraction.textInput({
|
|
2017
|
+
label: "F" + i
|
|
2018
|
+
});
|
|
2019
|
+
yield* t.openModal(ChatInteraction.modal("conformance-many", {
|
|
2020
|
+
title: "Conformance",
|
|
2021
|
+
fields
|
|
2022
|
+
}).open());
|
|
2023
|
+
yield* refusedTooLarge(t);
|
|
2024
|
+
}));
|
|
2025
|
+
// `modalErrors` means nothing without `modals`, so the rule needs both.
|
|
2026
|
+
rule("modal/errorsKeepOpen", ["modals", "modalErrors"], t => Effect.gen(function* () {
|
|
2027
|
+
t.recording.onSubmit = () => t.recording.submits.length === 1 ? ChatInteraction.errors({
|
|
2028
|
+
answer: "Again."
|
|
2029
|
+
}) : ChatInteraction.close;
|
|
2030
|
+
yield* t.openModal(probeModal.open());
|
|
2031
|
+
yield* t.submit({
|
|
2032
|
+
answer: "first"
|
|
2033
|
+
});
|
|
2034
|
+
yield* t.submit({
|
|
2035
|
+
answer: "second"
|
|
2036
|
+
});
|
|
2037
|
+
const second = t.recording.submits[1];
|
|
2038
|
+
yield* t.check(second !== undefined && second.id === "conformance-modal", "a second submit of the same modal", () => t.recording.submits.length + " submits");
|
|
2039
|
+
}));
|
|
2040
|
+
rule("unsupported/modals", ["buttons"], t => t.probe("modals"));
|
|
2041
|
+
}
|
|
2042
|
+
if (interactions?.command !== undefined) {
|
|
2043
|
+
const commandId = "conformance-command";
|
|
2044
|
+
rule("command/arrives", ["commands"], t => Effect.gen(function* () {
|
|
2045
|
+
const text = "deploy v1 < \u{1D400}";
|
|
2046
|
+
yield* t.command(commandId, {
|
|
2047
|
+
text
|
|
2048
|
+
});
|
|
2049
|
+
const command = t.recording.commands[0];
|
|
2050
|
+
yield* t.check(command !== undefined && command.id === commandId && command.text === text && ChatThread.equals(command.thread, t.thread), "command " + commandId + " with text " + JSON.stringify(text) + " in " + ChatThread.toString(t.thread), () => command === undefined ? "no command" : "command " + command.id + " with text " + JSON.stringify(command.text) + " in " + ChatThread.toString(command.thread));
|
|
2051
|
+
yield* t.checkInteraction(command);
|
|
2052
|
+
}));
|
|
2053
|
+
rule("command/emptyText", ["commands"], t => Effect.gen(function* () {
|
|
2054
|
+
yield* t.command(commandId);
|
|
2055
|
+
const command = t.recording.commands[0];
|
|
2056
|
+
yield* t.check(command !== undefined && command.text === "", "a command with text \"\"", () => command === undefined ? "no command" : "text " + JSON.stringify(command.text));
|
|
2057
|
+
}));
|
|
2058
|
+
const noRefusal = t => t.check(t.recording.commands.length === 1 && t.recording.refused.length === 0, "one command and no refusal", () => t.recording.commands.length + " commands and refusals " + (t.recording.refused.length === 0 ? "none" : t.recording.refused.map(describeError).join(", ")));
|
|
2059
|
+
rule("command/responds", ["commands"], t => Effect.gen(function* () {
|
|
2060
|
+
t.recording.onCommand = () => ChatInteraction.respond({
|
|
2061
|
+
markdown: conformanceText(t.rule),
|
|
2062
|
+
visibility: "public"
|
|
2063
|
+
});
|
|
2064
|
+
yield* t.command(commandId);
|
|
2065
|
+
yield* noRefusal(t);
|
|
2066
|
+
}));
|
|
2067
|
+
rule("command/respondsPrivately", ["commands", "ephemeral"], t => Effect.gen(function* () {
|
|
2068
|
+
t.recording.onCommand = () => ChatInteraction.respond({
|
|
2069
|
+
markdown: conformanceText(t.rule)
|
|
2070
|
+
});
|
|
2071
|
+
yield* t.command(commandId);
|
|
2072
|
+
yield* noRefusal(t);
|
|
2073
|
+
}));
|
|
2074
|
+
rule("command/respondTooLarge", ["commands"], t => Effect.gen(function* () {
|
|
2075
|
+
const markdown = "x".repeat(t.descriptor.limits.messageLength + 1);
|
|
2076
|
+
t.recording.onCommand = () => ChatInteraction.respond({
|
|
2077
|
+
markdown,
|
|
2078
|
+
visibility: "public"
|
|
2079
|
+
});
|
|
2080
|
+
yield* t.command(commandId);
|
|
2081
|
+
const refusal = t.recording.refused[0];
|
|
2082
|
+
yield* t.check(refusal !== undefined && textTooLarge.test(refusal.reason), "a refusal " + textTooLarge.expected, () => refusal === undefined ? "no refusal" : "a refusal " + describeError(refusal));
|
|
2083
|
+
}));
|
|
2084
|
+
rule("command/followUp", ["commands"], t => Effect.gen(function* () {
|
|
2085
|
+
t.recording.onCommand = command => ChatInteraction.defer(command, {
|
|
2086
|
+
visibility: "public"
|
|
2087
|
+
});
|
|
2088
|
+
yield* t.command(commandId);
|
|
2089
|
+
const deferred = t.recording.commandReplies[0];
|
|
2090
|
+
if (deferred?._tag !== "Defer") {
|
|
2091
|
+
return yield* Effect.fail(failure(t.rule, "a Defer reply", deferred === undefined ? "no command" : deferred._tag));
|
|
2092
|
+
}
|
|
2093
|
+
yield* noRefusal(t);
|
|
2094
|
+
yield* t.call(t.chat.followUp(deferred, {
|
|
2095
|
+
markdown: conformanceText(t.rule)
|
|
2096
|
+
}));
|
|
2097
|
+
}));
|
|
2098
|
+
rule("command/modalOrigin", ["commands", "modals"], t => Effect.gen(function* () {
|
|
2099
|
+
t.recording.onCommand = () => probeModal.open();
|
|
2100
|
+
yield* t.command(commandId);
|
|
2101
|
+
yield* t.submit({
|
|
2102
|
+
answer: "conformance"
|
|
2103
|
+
});
|
|
2104
|
+
const submit = t.recording.submits[0];
|
|
2105
|
+
yield* t.check(submit !== undefined && submit.messageId === undefined && ChatThread.equals(submit.thread, t.thread), "a submit in " + ChatThread.toString(t.thread) + " with no messageId", () => submit === undefined ? "no submit" : "a submit in " + ChatThread.toString(submit.thread) + " with messageId " + submit.messageId);
|
|
2106
|
+
yield* t.checkInteraction(submit);
|
|
2107
|
+
}));
|
|
2108
|
+
rule("unsupported/ephemeral", ["commands"], t => t.probe("ephemeral"));
|
|
2109
|
+
}
|
|
2110
|
+
for (const capability of allCapabilities) {
|
|
2111
|
+
if (capability === "modals" || capability === "modalErrors" || capability === "ephemeral") continue;
|
|
2112
|
+
rule("unsupported/" + capability, [], t => t.probe(capability));
|
|
2113
|
+
}
|
|
2114
|
+
const failNext = options.failNext;
|
|
2115
|
+
if (failNext !== undefined) {
|
|
2116
|
+
rule("retries/noneWithoutRetries", [], t => Effect.gen(function* () {
|
|
2117
|
+
yield* failNext("post", new RateLimited({}));
|
|
2118
|
+
yield* t.expectReason("RateLimited", Chat.withoutRetries(t.chat.post(t.thread, {
|
|
2119
|
+
markdown: conformanceText(t.rule)
|
|
2120
|
+
})), posted => t.track(posted));
|
|
2121
|
+
}));
|
|
2122
|
+
rule("retries/retrySafe", [], t => Effect.gen(function* () {
|
|
2123
|
+
const retryAfter = Duration.millis(100);
|
|
2124
|
+
yield* failNext("post", new RateLimited({
|
|
2125
|
+
retryAfter
|
|
2126
|
+
}));
|
|
2127
|
+
const start = yield* DateTime.now;
|
|
2128
|
+
yield* t.post({});
|
|
2129
|
+
const elapsed = DateTime.distance(start, yield* DateTime.now);
|
|
2130
|
+
yield* t.check(
|
|
2131
|
+
// One millisecond of slack: a timer and the clock round to whole milliseconds apart.
|
|
2132
|
+
Duration.toMillis(elapsed) + 1 >= Duration.toMillis(retryAfter), "a retry after " + Duration.format(retryAfter), () => "a retry after " + Duration.format(elapsed));
|
|
2133
|
+
}));
|
|
2134
|
+
rule("retries/neverUncertain", [], t => Effect.gen(function* () {
|
|
2135
|
+
yield* failNext("post", new Transport({
|
|
2136
|
+
retry: "uncertain"
|
|
2137
|
+
}));
|
|
2138
|
+
yield* t.expectReason("Transport", t.chat.post(t.thread, {
|
|
2139
|
+
markdown: conformanceText(t.rule)
|
|
2140
|
+
}), posted => t.track(posted));
|
|
2141
|
+
}));
|
|
2142
|
+
}
|
|
2143
|
+
return rules;
|
|
2144
|
+
};
|
|
2145
|
+
//# sourceMappingURL=ChatTest.js.map
|