liminal 0.4.0 → 0.5.1
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/Action.ts +29 -0
- package/Actor.ts +20 -0
- package/CHANGELOG.md +14 -0
- package/Exec.ts +63 -0
- package/L.ts +27 -0
- package/LiminalAssertionError.ts +3 -0
- package/LiminalConfig.ts +7 -0
- package/Message.ts +94 -0
- package/Model.ts +20 -0
- package/PathLike.ts +19 -0
- package/Scope.ts +133 -0
- package/Spec.ts +29 -0
- package/Tool.ts +58 -0
- package/_.ts +11 -0
- package/actions/abort.ts +23 -0
- package/actions/actions_common/updateModels.ts +23 -0
- package/actions/actions_derived/__snapshots__/declareModel.test.ts.snap +89 -0
- package/actions/actions_derived/clear.ts +6 -0
- package/actions/actions_derived/declareModel.test.ts +33 -0
- package/actions/actions_derived/declareModel.ts +9 -0
- package/actions/actions_derived/declareModel.type-test.ts +70 -0
- package/actions/actions_derived/getMessages.ts +9 -0
- package/actions/actions_derived/messages.test.ts +88 -0
- package/actions/actions_derived/messages.ts +19 -0
- package/actions/actions_derived/metatype.ts +9 -0
- package/actions/appendMessage.ts +30 -0
- package/actions/await.ts +13 -0
- package/actions/branch.ts +108 -0
- package/actions/catch.ts +42 -0
- package/actions/declareArg.ts +14 -0
- package/actions/disableTool.ts +26 -0
- package/actions/embed.ts +28 -0
- package/actions/emit.ts +21 -0
- package/actions/enableTool.ts +75 -0
- package/actions/enableTool.type-test.ts +118 -0
- package/actions/getScope.ts +11 -0
- package/actions/getSignal.ts +10 -0
- package/actions/getTools.ts +11 -0
- package/actions/infer.ts +37 -0
- package/actions/pushModel.ts +32 -0
- package/actions/removeMessage.ts +22 -0
- package/actions/removeModel.ts +31 -0
- package/actions/setMessages.ts +66 -0
- package/actions/throw.ts +18 -0
- package/cli/WriteHandler.ts +35 -0
- package/cli/cli_common.ts +3 -0
- package/cli/main.ts +19 -0
- package/cli/runExec.ts +68 -0
- package/dist/Action.d.ts +15 -0
- package/dist/Action.js +13 -0
- package/dist/Action.js.map +1 -0
- package/dist/Actor.d.ts +14 -0
- package/dist/Actor.js +2 -0
- package/dist/Actor.js.map +1 -0
- package/dist/Exec.d.ts +27 -0
- package/dist/Exec.js +22 -0
- package/dist/Exec.js.map +1 -0
- package/dist/L.d.ts +26 -0
- package/dist/L.js +27 -0
- package/dist/L.js.map +1 -0
- package/dist/LiminalAssertionError.d.ts +3 -0
- package/dist/LiminalAssertionError.js +4 -0
- package/dist/LiminalAssertionError.js.map +1 -0
- package/dist/LiminalConfig.d.ts +6 -0
- package/dist/LiminalConfig.js +2 -0
- package/dist/LiminalConfig.js.map +1 -0
- package/dist/Message.d.ts +82 -0
- package/dist/Message.js +2 -0
- package/dist/Message.js.map +1 -0
- package/dist/Model.d.ts +16 -0
- package/dist/Model.js +2 -0
- package/dist/Model.js.map +1 -0
- package/dist/PathLike.d.ts +14 -0
- package/dist/PathLike.js +2 -0
- package/dist/PathLike.js.map +1 -0
- package/dist/Scope.d.ts +36 -0
- package/dist/Scope.js +90 -0
- package/dist/Scope.js.map +1 -0
- package/dist/Spec.d.ts +20 -0
- package/dist/Spec.js +2 -0
- package/dist/Spec.js.map +1 -0
- package/dist/Tool.d.ts +21 -0
- package/dist/Tool.js +32 -0
- package/dist/Tool.js.map +1 -0
- package/dist/_.d.ts +5 -0
- package/dist/_.js +7 -0
- package/dist/_.js.map +1 -0
- package/dist/actions/abort.d.ts +9 -0
- package/dist/actions/abort.js +15 -0
- package/dist/actions/abort.js.map +1 -0
- package/dist/actions/actions_common/updateModels.d.ts +3 -0
- package/dist/actions/actions_common/updateModels.js +17 -0
- package/dist/actions/actions_common/updateModels.js.map +1 -0
- package/dist/actions/actions_derived/clear.d.ts +8 -0
- package/dist/actions/actions_derived/clear.js +5 -0
- package/dist/actions/actions_derived/clear.js.map +1 -0
- package/dist/actions/actions_derived/declareModel.d.ts +5 -0
- package/dist/actions/actions_derived/declareModel.js +7 -0
- package/dist/actions/actions_derived/declareModel.js.map +1 -0
- package/dist/actions/actions_derived/declareModel.test.d.ts +1 -0
- package/dist/actions/actions_derived/declareModel.test.js +32 -0
- package/dist/actions/actions_derived/declareModel.test.js.map +1 -0
- package/dist/actions/actions_derived/declareModel.type-test.d.ts +1 -0
- package/dist/actions/actions_derived/declareModel.type-test.js +66 -0
- package/dist/actions/actions_derived/declareModel.type-test.js.map +1 -0
- package/dist/actions/actions_derived/getMessages.d.ts +3 -0
- package/dist/actions/actions_derived/getMessages.js +8 -0
- package/dist/actions/actions_derived/getMessages.js.map +1 -0
- package/dist/actions/actions_derived/messages.d.ts +6 -0
- package/dist/actions/actions_derived/messages.js +15 -0
- package/dist/actions/actions_derived/messages.js.map +1 -0
- package/dist/actions/actions_derived/messages.test.d.ts +1 -0
- package/dist/actions/actions_derived/messages.test.js +72 -0
- package/dist/actions/actions_derived/messages.test.js.map +1 -0
- package/dist/actions/actions_derived/metatype.d.ts +9 -0
- package/dist/actions/actions_derived/metatype.js +7 -0
- package/dist/actions/actions_derived/metatype.js.map +1 -0
- package/dist/actions/appendMessage.d.ts +10 -0
- package/dist/actions/appendMessage.js +20 -0
- package/dist/actions/appendMessage.js.map +1 -0
- package/dist/actions/await.d.ts +5 -0
- package/dist/actions/await.js +10 -0
- package/dist/actions/await.js.map +1 -0
- package/dist/actions/branch.d.ts +35 -0
- package/dist/actions/branch.js +40 -0
- package/dist/actions/branch.js.map +1 -0
- package/dist/actions/catch.d.ts +10 -0
- package/dist/actions/catch.js +27 -0
- package/dist/actions/catch.js.map +1 -0
- package/dist/actions/declareArg.d.ts +8 -0
- package/dist/actions/declareArg.js +10 -0
- package/dist/actions/declareArg.js.map +1 -0
- package/dist/actions/disableTool.d.ts +10 -0
- package/dist/actions/disableTool.js +17 -0
- package/dist/actions/disableTool.js.map +1 -0
- package/dist/actions/embed.d.ts +9 -0
- package/dist/actions/embed.js +23 -0
- package/dist/actions/embed.js.map +1 -0
- package/dist/actions/emit.d.ts +9 -0
- package/dist/actions/emit.js +14 -0
- package/dist/actions/emit.js.map +1 -0
- package/dist/actions/enableTool.d.ts +20 -0
- package/dist/actions/enableTool.js +26 -0
- package/dist/actions/enableTool.js.map +1 -0
- package/dist/actions/enableTool.type-test.d.ts +1 -0
- package/dist/actions/enableTool.type-test.js +30 -0
- package/dist/actions/enableTool.type-test.js.map +1 -0
- package/dist/actions/getScope.d.ts +5 -0
- package/dist/actions/getScope.js +8 -0
- package/dist/actions/getScope.js.map +1 -0
- package/dist/actions/getSignal.d.ts +4 -0
- package/dist/actions/getSignal.js +8 -0
- package/dist/actions/getSignal.js.map +1 -0
- package/dist/actions/getTools.d.ts +5 -0
- package/dist/actions/getTools.js +8 -0
- package/dist/actions/getTools.js.map +1 -0
- package/dist/actions/infer.d.ts +13 -0
- package/dist/actions/infer.js +21 -0
- package/dist/actions/infer.js.map +1 -0
- package/dist/actions/pushModel.d.ts +11 -0
- package/dist/actions/pushModel.js +21 -0
- package/dist/actions/pushModel.js.map +1 -0
- package/dist/actions/removeMessage.d.ts +9 -0
- package/dist/actions/removeMessage.js +17 -0
- package/dist/actions/removeMessage.js.map +1 -0
- package/dist/actions/removeModel.d.ts +10 -0
- package/dist/actions/removeModel.js +20 -0
- package/dist/actions/removeModel.js.map +1 -0
- package/dist/actions/setMessages.d.ts +16 -0
- package/dist/actions/setMessages.js +31 -0
- package/dist/actions/setMessages.js.map +1 -0
- package/dist/actions/throw.d.ts +9 -0
- package/dist/actions/throw.js +13 -0
- package/dist/actions/throw.js.map +1 -0
- package/dist/cli/WriteHandler.d.ts +9 -0
- package/dist/cli/WriteHandler.js +24 -0
- package/dist/cli/WriteHandler.js.map +1 -0
- package/dist/cli/cli_common.d.ts +3 -0
- package/dist/cli/cli_common.js +2 -0
- package/dist/cli/cli_common.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +15 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/runExec.d.ts +2 -0
- package/dist/cli/runExec.js +69 -0
- package/dist/cli/runExec.js.map +1 -0
- package/dist/events/Aborted.d.ts +4 -0
- package/dist/events/Aborted.js +2 -0
- package/dist/events/Aborted.js.map +1 -0
- package/dist/events/Embedded.d.ts +5 -0
- package/dist/events/Embedded.js +2 -0
- package/dist/events/Embedded.js.map +1 -0
- package/dist/events/EmbeddingRequested.d.ts +4 -0
- package/dist/events/EmbeddingRequested.js +2 -0
- package/dist/events/EmbeddingRequested.js.map +1 -0
- package/dist/events/Emitted.d.ts +4 -0
- package/dist/events/Emitted.js +2 -0
- package/dist/events/Emitted.js.map +1 -0
- package/dist/events/EventBase.d.ts +3 -0
- package/dist/events/EventBase.js +2 -0
- package/dist/events/EventBase.js.map +1 -0
- package/dist/events/EventHandler.d.ts +2 -0
- package/dist/events/EventHandler.js +2 -0
- package/dist/events/EventHandler.js.map +1 -0
- package/dist/events/EventResolved.d.ts +19 -0
- package/dist/events/EventResolved.js +2 -0
- package/dist/events/EventResolved.js.map +1 -0
- package/dist/events/Forked.d.ts +3 -0
- package/dist/events/Forked.js +2 -0
- package/dist/events/Forked.js.map +1 -0
- package/dist/events/InferenceRequested.d.ts +3 -0
- package/dist/events/InferenceRequested.js +2 -0
- package/dist/events/InferenceRequested.js.map +1 -0
- package/dist/events/Inferred.d.ts +5 -0
- package/dist/events/Inferred.js +2 -0
- package/dist/events/Inferred.js.map +1 -0
- package/dist/events/LEvent.d.ts +18 -0
- package/dist/events/LEvent.js +2 -0
- package/dist/events/LEvent.js.map +1 -0
- package/dist/events/MessageAppended.d.ts +5 -0
- package/dist/events/MessageAppended.js +2 -0
- package/dist/events/MessageAppended.js.map +1 -0
- package/dist/events/MessageRemoved.d.ts +5 -0
- package/dist/events/MessageRemoved.js +2 -0
- package/dist/events/MessageRemoved.js.map +1 -0
- package/dist/events/MessagesSet.d.ts +5 -0
- package/dist/events/MessagesSet.js +2 -0
- package/dist/events/MessagesSet.js.map +1 -0
- package/dist/events/ModelPushed.d.ts +7 -0
- package/dist/events/ModelPushed.js +2 -0
- package/dist/events/ModelPushed.js.map +1 -0
- package/dist/events/ModelRemoved.d.ts +7 -0
- package/dist/events/ModelRemoved.js +2 -0
- package/dist/events/ModelRemoved.js.map +1 -0
- package/dist/events/Returned.d.ts +4 -0
- package/dist/events/Returned.js +2 -0
- package/dist/events/Returned.js.map +1 -0
- package/dist/events/Threw.d.ts +4 -0
- package/dist/events/Threw.js +2 -0
- package/dist/events/Threw.js.map +1 -0
- package/dist/events/ToolCalled.d.ts +6 -0
- package/dist/events/ToolCalled.js +2 -0
- package/dist/events/ToolCalled.js.map +1 -0
- package/dist/events/ToolDisabled.d.ts +5 -0
- package/dist/events/ToolDisabled.js +2 -0
- package/dist/events/ToolDisabled.js.map +1 -0
- package/dist/events/ToolEnabled.d.ts +7 -0
- package/dist/events/ToolEnabled.js +2 -0
- package/dist/events/ToolEnabled.js.map +1 -0
- package/dist/events/isScopeChildEvent.d.ts +6 -0
- package/dist/events/isScopeChildEvent.js +9 -0
- package/dist/events/isScopeChildEvent.js.map +1 -0
- package/dist/events/isScopeDescendantEvent.d.ts +14 -0
- package/dist/events/isScopeDescendantEvent.js +12 -0
- package/dist/events/isScopeDescendantEvent.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/testing/ActorAssertions.d.ts +9 -0
- package/dist/testing/ActorAssertions.js +6 -0
- package/dist/testing/ActorAssertions.js.map +1 -0
- package/dist/testing/TestEmbeddingModel.d.ts +6 -0
- package/dist/testing/TestEmbeddingModel.js +10 -0
- package/dist/testing/TestEmbeddingModel.js.map +1 -0
- package/dist/testing/TestLanguageModel.d.ts +8 -0
- package/dist/testing/TestLanguageModel.js +21 -0
- package/dist/testing/TestLanguageModel.js.map +1 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/takeFirstAction.d.ts +3 -0
- package/dist/testing/takeFirstAction.js +6 -0
- package/dist/testing/takeFirstAction.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/AssertDiagnostics.d.ts +18 -0
- package/dist/types/AssertDiagnostics.js +152 -0
- package/dist/types/AssertDiagnostics.js.map +1 -0
- package/dist/types/JSONRootType.d.ts +6 -0
- package/dist/types/JSONRootType.js +2 -0
- package/dist/types/JSONRootType.js.map +1 -0
- package/dist/types/JSONType.d.ts +16 -0
- package/dist/types/JSONType.js +2 -0
- package/dist/types/JSONType.js.map +1 -0
- package/dist/types/JSONTypeBase.d.ts +3 -0
- package/dist/types/JSONTypeBase.js +2 -0
- package/dist/types/JSONTypeBase.js.map +1 -0
- package/dist/types/Metatype/MetatypeDescriptor.d.ts +41 -0
- package/dist/types/Metatype/MetatypeDescriptor.js +38 -0
- package/dist/types/Metatype/MetatypeDescriptor.js.map +1 -0
- package/dist/types/Metatype/fromMetatypeDescriptor.d.ts +6 -0
- package/dist/types/Metatype/fromMetatypeDescriptor.js +43 -0
- package/dist/types/Metatype/fromMetatypeDescriptor.js.map +1 -0
- package/dist/types/Type.d.ts +30 -0
- package/dist/types/Type.js +5 -0
- package/dist/types/Type.js.map +1 -0
- package/dist/types/TypeContext.d.ts +7 -0
- package/dist/types/TypeContext.js +17 -0
- package/dist/types/TypeContext.js.map +1 -0
- package/dist/types/TypeLike.d.ts +23 -0
- package/dist/types/TypeLike.js +23 -0
- package/dist/types/TypeLike.js.map +1 -0
- package/dist/types/TypeVisitor.d.ts +14 -0
- package/dist/types/TypeVisitor.js +12 -0
- package/dist/types/TypeVisitor.js.map +1 -0
- package/dist/types/array.d.ts +10 -0
- package/dist/types/array.js +9 -0
- package/dist/types/array.js.map +1 -0
- package/dist/types/boolean.d.ts +6 -0
- package/dist/types/boolean.js +3 -0
- package/dist/types/boolean.js.map +1 -0
- package/dist/types/const.d.ts +8 -0
- package/dist/types/const.js +7 -0
- package/dist/types/const.js.map +1 -0
- package/dist/types/declareType.d.ts +2 -0
- package/dist/types/declareType.js +57 -0
- package/dist/types/declareType.js.map +1 -0
- package/dist/types/enum.d.ts +8 -0
- package/dist/types/enum.js +7 -0
- package/dist/types/enum.js.map +1 -0
- package/dist/types/factories.d.ts +8 -0
- package/dist/types/factories.js +9 -0
- package/dist/types/factories.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/integer.d.ts +6 -0
- package/dist/types/integer.js +3 -0
- package/dist/types/integer.js.map +1 -0
- package/dist/types/intrinsics.d.ts +11 -0
- package/dist/types/intrinsics.js +12 -0
- package/dist/types/intrinsics.js.map +1 -0
- package/dist/types/match.d.ts +3 -0
- package/dist/types/match.js +11 -0
- package/dist/types/match.js.map +1 -0
- package/dist/types/non_factories.d.ts +21 -0
- package/dist/types/non_factories.js +9 -0
- package/dist/types/non_factories.js.map +1 -0
- package/dist/types/null.d.ts +7 -0
- package/dist/types/null.js +4 -0
- package/dist/types/null.js.map +1 -0
- package/dist/types/number.d.ts +6 -0
- package/dist/types/number.js +3 -0
- package/dist/types/number.js.map +1 -0
- package/dist/types/object.d.ts +16 -0
- package/dist/types/object.js +10 -0
- package/dist/types/object.js.map +1 -0
- package/dist/types/ref.d.ts +7 -0
- package/dist/types/ref.js +5 -0
- package/dist/types/ref.js.map +1 -0
- package/dist/types/string.d.ts +6 -0
- package/dist/types/string.js +3 -0
- package/dist/types/string.js.map +1 -0
- package/dist/types/toJSON.d.ts +5 -0
- package/dist/types/toJSON.js +97 -0
- package/dist/types/toJSON.js.map +1 -0
- package/dist/types/type_common.d.ts +10 -0
- package/dist/types/type_common.js +12 -0
- package/dist/types/type_common.js.map +1 -0
- package/dist/types/types_derived/option.d.ts +5 -0
- package/dist/types/types_derived/option.js +6 -0
- package/dist/types/types_derived/option.js.map +1 -0
- package/dist/types/types_derived/taggedUnion.d.ts +19 -0
- package/dist/types/types_derived/taggedUnion.js +8 -0
- package/dist/types/types_derived/taggedUnion.js.map +1 -0
- package/dist/types/types_derived/wrapper.d.ts +8 -0
- package/dist/types/types_derived/wrapper.js +5 -0
- package/dist/types/types_derived/wrapper.js.map +1 -0
- package/dist/types/union.d.ts +9 -0
- package/dist/types/union.js +9 -0
- package/dist/types/union.js.map +1 -0
- package/dist/util/ArrayOfLength.d.ts +1 -0
- package/dist/util/ArrayOfLength.js +2 -0
- package/dist/util/ArrayOfLength.js.map +1 -0
- package/dist/util/DeferredOr.d.ts +1 -0
- package/dist/util/DeferredOr.js +2 -0
- package/dist/util/DeferredOr.js.map +1 -0
- package/dist/util/EnsureNarrow.d.ts +2 -0
- package/dist/util/EnsureNarrow.js +2 -0
- package/dist/util/EnsureNarrow.js.map +1 -0
- package/dist/util/EnsureRecord.d.ts +2 -0
- package/dist/util/EnsureRecord.js +2 -0
- package/dist/util/EnsureRecord.js.map +1 -0
- package/dist/util/Expand.d.ts +3 -0
- package/dist/util/Expand.js +2 -0
- package/dist/util/Expand.js.map +1 -0
- package/dist/util/Falsy.d.ts +1 -0
- package/dist/util/Falsy.js +2 -0
- package/dist/util/Falsy.js.map +1 -0
- package/dist/util/FromEntries.d.ts +3 -0
- package/dist/util/FromEntries.js +2 -0
- package/dist/util/FromEntries.js.map +1 -0
- package/dist/util/IteratorLike.d.ts +1 -0
- package/dist/util/IteratorLike.js +2 -0
- package/dist/util/IteratorLike.js.map +1 -0
- package/dist/util/JSONEntry.d.ts +2 -0
- package/dist/util/JSONEntry.js +2 -0
- package/dist/util/JSONEntry.js.map +1 -0
- package/dist/util/JSONKey.d.ts +1 -0
- package/dist/util/JSONKey.js +2 -0
- package/dist/util/JSONKey.js.map +1 -0
- package/dist/util/JSONObject.d.ts +5 -0
- package/dist/util/JSONObject.js +2 -0
- package/dist/util/JSONObject.js.map +1 -0
- package/dist/util/JSONSchemaMemo.d.ts +2 -0
- package/dist/util/JSONSchemaMemo.js +13 -0
- package/dist/util/JSONSchemaMemo.js.map +1 -0
- package/dist/util/JSONValue.d.ts +2 -0
- package/dist/util/JSONValue.js +2 -0
- package/dist/util/JSONValue.js.map +1 -0
- package/dist/util/PromiseOr.d.ts +1 -0
- package/dist/util/PromiseOr.js +2 -0
- package/dist/util/PromiseOr.js.map +1 -0
- package/dist/util/Result.d.ts +7 -0
- package/dist/util/Result.js +2 -0
- package/dist/util/Result.js.map +1 -0
- package/dist/util/Taggable.d.ts +9 -0
- package/dist/util/Taggable.js +8 -0
- package/dist/util/Taggable.js.map +1 -0
- package/dist/util/TupleToRecord.d.ts +5 -0
- package/dist/util/TupleToRecord.js +2 -0
- package/dist/util/TupleToRecord.js.map +1 -0
- package/dist/util/assert.d.ts +1 -0
- package/dist/util/assert.js +7 -0
- package/dist/util/assert.js.map +1 -0
- package/dist/util/dedent.d.ts +1 -0
- package/dist/util/dedent.js +5 -0
- package/dist/util/dedent.js.map +1 -0
- package/dist/util/fixTemplateStrings.d.ts +11 -0
- package/dist/util/fixTemplateStrings.js +83 -0
- package/dist/util/fixTemplateStrings.js.map +1 -0
- package/dist/util/fixTemplateStrings.test.d.ts +1 -0
- package/dist/util/fixTemplateStrings.test.js +221 -0
- package/dist/util/fixTemplateStrings.test.js.map +1 -0
- package/dist/util/isAsyncIterator.d.ts +1 -0
- package/dist/util/isAsyncIterator.js +7 -0
- package/dist/util/isAsyncIterator.js.map +1 -0
- package/dist/util/isIterator.d.ts +1 -0
- package/dist/util/isIterator.js +7 -0
- package/dist/util/isIterator.js.map +1 -0
- package/dist/util/isJSONValue.d.ts +2 -0
- package/dist/util/isJSONValue.js +16 -0
- package/dist/util/isJSONValue.js.map +1 -0
- package/dist/util/isPropertyKey.d.ts +1 -0
- package/dist/util/isPropertyKey.js +4 -0
- package/dist/util/isPropertyKey.js.map +1 -0
- package/dist/util/isTemplateStringsArray.d.ts +1 -0
- package/dist/util/isTemplateStringsArray.js +4 -0
- package/dist/util/isTemplateStringsArray.js.map +1 -0
- package/dist/util/jsonEquals.d.ts +2 -0
- package/dist/util/jsonEquals.js +33 -0
- package/dist/util/jsonEquals.js.map +1 -0
- package/dist/util/nullaryMemo.d.ts +1 -0
- package/dist/util/nullaryMemo.js +12 -0
- package/dist/util/nullaryMemo.js.map +1 -0
- package/dist/util/unimplemented.d.ts +1 -0
- package/dist/util/unimplemented.js +5 -0
- package/dist/util/unimplemented.js.map +1 -0
- package/dist/util/unreachable.d.ts +1 -0
- package/dist/util/unreachable.js +5 -0
- package/dist/util/unreachable.js.map +1 -0
- package/dist/util/unwrapDeferred.d.ts +2 -0
- package/dist/util/unwrapDeferred.js +4 -0
- package/dist/util/unwrapDeferred.js.map +1 -0
- package/dist/util/util.d.ts +10 -0
- package/dist/util/util.js +11 -0
- package/dist/util/util.js.map +1 -0
- package/events/Aborted.ts +5 -0
- package/events/Embedded.ts +6 -0
- package/events/EmbeddingRequested.ts +5 -0
- package/events/Emitted.ts +5 -0
- package/events/EventBase.ts +3 -0
- package/events/EventHandler.ts +3 -0
- package/events/EventResolved.ts +30 -0
- package/events/Forked.ts +3 -0
- package/events/InferenceRequested.ts +3 -0
- package/events/Inferred.ts +6 -0
- package/events/LEvent.ts +36 -0
- package/events/MessageAppended.ts +6 -0
- package/events/MessageRemoved.ts +6 -0
- package/events/MessagesSet.ts +6 -0
- package/events/ModelPushed.ts +10 -0
- package/events/ModelRemoved.ts +10 -0
- package/events/Returned.ts +5 -0
- package/events/Threw.ts +5 -0
- package/events/ToolCalled.ts +7 -0
- package/events/ToolDisabled.ts +6 -0
- package/events/ToolEnabled.ts +8 -0
- package/events/isScopeChildEvent.ts +15 -0
- package/events/isScopeDescendantEvent.ts +30 -0
- package/index.ts +41 -0
- package/package.json +28 -19
- package/testing/ActorAssertions.ts +19 -0
- package/testing/TestEmbeddingModel.ts +18 -0
- package/testing/TestLanguageModel.ts +32 -0
- package/testing/index.ts +4 -0
- package/testing/takeFirstAction.ts +8 -0
- package/tsconfig.json +4 -8
- package/types/AssertDiagnostics.ts +183 -0
- package/types/JSONRootType.ts +8 -0
- package/types/JSONType.ts +27 -0
- package/types/JSONTypeBase.ts +3 -0
- package/types/Metatype/MetatypeDescriptor.ts +80 -0
- package/types/Metatype/fromMetatypeDescriptor.ts +52 -0
- package/types/Type.ts +46 -0
- package/types/TypeContext.ts +19 -0
- package/types/TypeLike.ts +60 -0
- package/types/TypeVisitor.ts +49 -0
- package/types/array.ts +20 -0
- package/types/boolean.ts +9 -0
- package/types/const.ts +17 -0
- package/types/declareType.ts +71 -0
- package/types/enum.ts +14 -0
- package/types/factories.ts +8 -0
- package/types/index.ts +2 -0
- package/types/integer.ts +9 -0
- package/types/intrinsics.ts +11 -0
- package/types/match.ts +13 -0
- package/types/non_factories.ts +26 -0
- package/types/null.ts +10 -0
- package/types/number.ts +9 -0
- package/types/object.ts +27 -0
- package/types/ref.ts +12 -0
- package/types/string.ts +9 -0
- package/types/toJSON.ts +111 -0
- package/types/type_common.ts +21 -0
- package/types/types_derived/option.ts +10 -0
- package/types/types_derived/taggedUnion.ts +30 -0
- package/types/types_derived/wrapper.ts +10 -0
- package/types/union.ts +19 -0
- package/util/ArrayOfLength.ts +5 -0
- package/util/DeferredOr.ts +1 -0
- package/util/EnsureNarrow.ts +5 -0
- package/util/EnsureRecord.ts +3 -0
- package/util/Expand.ts +1 -0
- package/util/Falsy.ts +1 -0
- package/util/FromEntries.ts +3 -0
- package/util/IteratorLike.ts +1 -0
- package/util/JSONEntry.ts +3 -0
- package/util/JSONKey.ts +1 -0
- package/util/JSONObject.ts +6 -0
- package/util/JSONSchemaMemo.ts +15 -0
- package/util/JSONValue.ts +3 -0
- package/util/PromiseOr.ts +1 -0
- package/util/Result.ts +7 -0
- package/util/Taggable.ts +18 -0
- package/util/TupleToRecord.ts +5 -0
- package/util/assert.ts +7 -0
- package/util/dedent.ts +5 -0
- package/util/fixTemplateStrings.test.ts +250 -0
- package/util/fixTemplateStrings.ts +99 -0
- package/util/isAsyncIterator.ts +6 -0
- package/util/isIterator.ts +6 -0
- package/util/isJSONValue.ts +20 -0
- package/util/isPropertyKey.ts +3 -0
- package/util/isTemplateStringsArray.ts +3 -0
- package/util/jsonEquals.ts +41 -0
- package/util/nullaryMemo.ts +11 -0
- package/util/unimplemented.ts +5 -0
- package/util/unreachable.ts +5 -0
- package/util/unwrapDeferred.ts +5 -0
- package/util/util.ts +10 -0
- package/LICENSE +0 -15
- package/README.md +0 -94
- package/jest.config.js +0 -4
- package/lib/array/array.d.ts +0 -6
- package/lib/array/array.js +0 -21
- package/lib/array/index.d.ts +0 -11
- package/lib/array/index.js +0 -17
- package/lib/composition/composition.d.ts +0 -6
- package/lib/composition/composition.js +0 -37
- package/lib/composition/index.d.ts +0 -9
- package/lib/composition/index.js +0 -13
- package/lib/composition/types.d.ts +0 -2
- package/lib/composition/types.js +0 -2
- package/lib/dispatch/getType.d.ts +0 -2
- package/lib/dispatch/getType.js +0 -15
- package/lib/dispatch/identity.d.ts +0 -2
- package/lib/dispatch/identity.js +0 -4
- package/lib/dispatch/index.d.ts +0 -22
- package/lib/dispatch/index.js +0 -13
- package/lib/dispatch/types.d.ts +0 -14
- package/lib/dispatch/types.js +0 -16
- package/lib/error/error.d.ts +0 -24
- package/lib/error/error.js +0 -25
- package/lib/error/index.d.ts +0 -2
- package/lib/error/index.js +0 -4
- package/lib/index.d.ts +0 -67
- package/lib/index.js +0 -19
- package/lib/multimethod/index.d.ts +0 -7
- package/lib/multimethod/index.js +0 -9
- package/lib/multimethod/multimethod.d.ts +0 -3
- package/lib/multimethod/multimethod.js +0 -101
- package/src/array/array.ts +0 -29
- package/src/array/index.ts +0 -12
- package/src/composition/composition.ts +0 -45
- package/src/composition/index.ts +0 -10
- package/src/composition/types.ts +0 -6
- package/src/dispatch/getType.ts +0 -17
- package/src/dispatch/identity.ts +0 -3
- package/src/dispatch/index.ts +0 -11
- package/src/dispatch/types.ts +0 -15
- package/src/error/error.ts +0 -26
- package/src/error/index.ts +0 -3
- package/src/index.ts +0 -15
- package/src/multimethod/index.ts +0 -8
- package/src/multimethod/multimethod.test.ts +0 -10
- package/src/multimethod/multimethod.ts +0 -148
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Spec } from "../Spec.ts"
|
|
2
|
+
import type { Expand } from "../util/Expand.ts"
|
|
3
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
4
|
+
import type { Forked } from "./Forked.ts"
|
|
5
|
+
import type { LEvent } from "./LEvent.ts"
|
|
6
|
+
import type { Returned } from "./Returned.ts"
|
|
7
|
+
|
|
8
|
+
export type EventResolved<E extends LEvent = LEvent> = E & {
|
|
9
|
+
scope: Array<JSONKey>
|
|
10
|
+
index: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ExtractEventResolved<S extends Spec, P extends Array<JSONKey> = []> =
|
|
14
|
+
| ([S["Event"]] extends [never] ? never
|
|
15
|
+
: Expand<
|
|
16
|
+
{
|
|
17
|
+
scope: P
|
|
18
|
+
index: number
|
|
19
|
+
} & (S["Event"] | (P extends [] ? never : Forked))
|
|
20
|
+
>)
|
|
21
|
+
| ([S["Child"]] extends [infer C extends [JSONKey, Spec]] ? {
|
|
22
|
+
[L in C[0]]: ExtractEventResolved<Extract<C, [L, Spec]>[1], [...P, L]>
|
|
23
|
+
}[C[0]]
|
|
24
|
+
: never)
|
|
25
|
+
| ([S["Value"]] extends [never] ? never : Expand<
|
|
26
|
+
{
|
|
27
|
+
scope: P
|
|
28
|
+
index: number
|
|
29
|
+
} & Returned<S["Value"]>
|
|
30
|
+
>)
|
package/events/Forked.ts
ADDED
package/events/LEvent.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Aborted } from "./Aborted.ts"
|
|
2
|
+
import type { Embedded } from "./Embedded.ts"
|
|
3
|
+
import type { EmbeddingRequested } from "./EmbeddingRequested.ts"
|
|
4
|
+
import type { Emitted } from "./Emitted.ts"
|
|
5
|
+
import type { Forked } from "./Forked.ts"
|
|
6
|
+
import type { InferenceRequested } from "./InferenceRequested.ts"
|
|
7
|
+
import type { Inferred } from "./Inferred.ts"
|
|
8
|
+
import type { MessageAppended } from "./MessageAppended.ts"
|
|
9
|
+
import type { MessageRemoved } from "./MessageRemoved.ts"
|
|
10
|
+
import type { MessagesSet } from "./MessagesSet.ts"
|
|
11
|
+
import type { ModelPushed } from "./ModelPushed.ts"
|
|
12
|
+
import type { ModelRemoved } from "./ModelRemoved.ts"
|
|
13
|
+
import type { Returned } from "./Returned.ts"
|
|
14
|
+
import type { Threw } from "./Threw.ts"
|
|
15
|
+
import type { ToolCalled } from "./ToolCalled.ts"
|
|
16
|
+
import type { ToolDisabled } from "./ToolDisabled.ts"
|
|
17
|
+
import type { ToolEnabled } from "./ToolEnabled.ts"
|
|
18
|
+
|
|
19
|
+
export type LEvent =
|
|
20
|
+
| Embedded
|
|
21
|
+
| EmbeddingRequested
|
|
22
|
+
| Emitted
|
|
23
|
+
| Inferred
|
|
24
|
+
| InferenceRequested
|
|
25
|
+
| MessageAppended
|
|
26
|
+
| MessagesSet
|
|
27
|
+
| Returned
|
|
28
|
+
| Threw
|
|
29
|
+
| ToolCalled
|
|
30
|
+
| ToolDisabled
|
|
31
|
+
| ToolEnabled
|
|
32
|
+
| Aborted
|
|
33
|
+
| MessageRemoved
|
|
34
|
+
| Forked
|
|
35
|
+
| ModelPushed
|
|
36
|
+
| ModelRemoved
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelType } from "../Model.ts"
|
|
2
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
3
|
+
import type { EventBase } from "./EventBase.ts"
|
|
4
|
+
|
|
5
|
+
export interface ModelPushed<K extends JSONKey = JSONKey, M extends ModelType = ModelType>
|
|
6
|
+
extends EventBase<"model_pushed">
|
|
7
|
+
{
|
|
8
|
+
modelKey: K
|
|
9
|
+
modelType: M
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelType } from "../Model.ts"
|
|
2
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
3
|
+
import type { EventBase } from "./EventBase.ts"
|
|
4
|
+
|
|
5
|
+
export interface ModelRemoved<K extends JSONKey = JSONKey, M extends ModelType = ModelType>
|
|
6
|
+
extends EventBase<"model_removed">
|
|
7
|
+
{
|
|
8
|
+
modelKey: K
|
|
9
|
+
modelType: M
|
|
10
|
+
}
|
package/events/Threw.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type _ } from "../_.ts"
|
|
2
|
+
import type { Path, PathLike } from "../PathLike.ts"
|
|
3
|
+
import type { Expand } from "../util/Expand.ts"
|
|
4
|
+
import type { EventResolved } from "./EventResolved.ts"
|
|
5
|
+
import { isScopeDescendantEvent } from "./isScopeDescendantEvent.ts"
|
|
6
|
+
|
|
7
|
+
export function isScopeChildEvent<E extends EventResolved, const P extends PathLike.FromPath<E["scope"]>>(
|
|
8
|
+
event: E,
|
|
9
|
+
path: P,
|
|
10
|
+
): event is Expand<Extract<E, { scope: Path.FromPathLike<P> }>> {
|
|
11
|
+
if (event.scope.length !== path.length) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
return isScopeDescendantEvent(event, path as never)
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type _, is_ } from "../_.ts"
|
|
2
|
+
import type { Path, PathLike } from "../PathLike.ts"
|
|
3
|
+
import type { Expand } from "../util/Expand.ts"
|
|
4
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
5
|
+
import type { EventResolved } from "./EventResolved.ts"
|
|
6
|
+
|
|
7
|
+
export function isScopeDescendantEvent<
|
|
8
|
+
E extends EventResolved,
|
|
9
|
+
const P extends PathLike.FromPath<Subscope<E["scope"]>>,
|
|
10
|
+
>(
|
|
11
|
+
event: E,
|
|
12
|
+
path: P,
|
|
13
|
+
): event is Expand<Extract<E, { scope: Subscope.Select<E["scope"], Path.FromPathLike<P>> }>> {
|
|
14
|
+
for (let i = 0; i < path.length; i++) {
|
|
15
|
+
const currentMatchKey = path[i]!
|
|
16
|
+
const currentActualKey = event.scope[i]!
|
|
17
|
+
if (currentActualKey !== currentMatchKey || !is_(currentMatchKey)) {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Subscope<A extends Array<JSONKey>> = A extends
|
|
25
|
+
[infer E0 extends JSONKey, ...infer ERest extends Array<JSONKey>] ? [E0, ...([] | Subscope<ERest>)]
|
|
26
|
+
: []
|
|
27
|
+
|
|
28
|
+
export declare namespace Subscope {
|
|
29
|
+
export type Select<A extends Array<JSONKey>, S extends Array<JSONKey>> = Extract<A, [...S, ...Array<JSONKey>]>
|
|
30
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export * from "./Action.ts"
|
|
2
|
+
export * from "./actions/appendMessage.ts"
|
|
3
|
+
export * from "./Actor.ts"
|
|
4
|
+
export * from "./events/Aborted.ts"
|
|
5
|
+
export * from "./events/Embedded.ts"
|
|
6
|
+
export * from "./events/EmbeddingRequested.ts"
|
|
7
|
+
export * from "./events/Emitted.ts"
|
|
8
|
+
export * from "./events/EventBase.ts"
|
|
9
|
+
export * from "./events/EventHandler.ts"
|
|
10
|
+
export * from "./events/EventResolved.ts"
|
|
11
|
+
export * from "./events/EventResolved.ts"
|
|
12
|
+
export * from "./events/EventResolved.ts"
|
|
13
|
+
export * from "./events/InferenceRequested.ts"
|
|
14
|
+
export * from "./events/Inferred.ts"
|
|
15
|
+
export * from "./events/isScopeChildEvent.ts"
|
|
16
|
+
export * from "./events/isScopeDescendantEvent.ts"
|
|
17
|
+
export * from "./events/LEvent.ts"
|
|
18
|
+
export * from "./events/MessageAppended.ts"
|
|
19
|
+
export * from "./events/MessageRemoved.ts"
|
|
20
|
+
export * from "./events/MessagesSet.ts"
|
|
21
|
+
export * from "./events/ModelPushed.ts"
|
|
22
|
+
export * from "./events/ModelRemoved.ts"
|
|
23
|
+
export * from "./events/Returned.ts"
|
|
24
|
+
export * from "./events/Threw.ts"
|
|
25
|
+
export * from "./events/ToolCalled.ts"
|
|
26
|
+
export * from "./events/ToolDisabled.ts"
|
|
27
|
+
export * from "./events/ToolEnabled.ts"
|
|
28
|
+
export * from "./Exec.ts"
|
|
29
|
+
export * as L from "./L.ts"
|
|
30
|
+
export * from "./LiminalAssertionError.ts"
|
|
31
|
+
export * from "./LiminalConfig.ts"
|
|
32
|
+
export * from "./Message.ts"
|
|
33
|
+
export * from "./Model.ts"
|
|
34
|
+
export * from "./Scope.ts"
|
|
35
|
+
export * from "./Spec.ts"
|
|
36
|
+
export * from "./Tool.ts"
|
|
37
|
+
export * from "./types/non_factories.ts"
|
|
38
|
+
export * from "./util/JSONKey.ts"
|
|
39
|
+
export * from "./util/JSONObject.ts"
|
|
40
|
+
export * from "./util/JSONValue.ts"
|
|
41
|
+
export * as _util from "./util/util.ts"
|
package/package.json
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liminal",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
"repository": "https://github.com/caderek/liminal",
|
|
6
|
-
"homepage": "https://github.com/caderek/liminal",
|
|
7
|
-
"main": "lib/index.js",
|
|
8
|
-
"license": "ISC",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"start": "nodemon --exec ts-node src/index.ts",
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"test": "jest"
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
13
5
|
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
"version": "0.5.1",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/harrysolovay/liminal.git",
|
|
11
|
+
"directory": "liminal"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"description": "Liminal is a model-agnostic library for conversation state management.",
|
|
15
|
+
"bin": {
|
|
16
|
+
"liminal": "./dist/cli/main.js"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./testing": "./dist/testing/index.js",
|
|
21
|
+
"./types": "./dist/types/index.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"
|
|
24
|
+
"standard-json-schema": "^0.1.1"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@standard-schema/spec": "^1.0.0",
|
|
28
|
+
"conditional-type-checks": "^1.0.6"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"conditional-type-checks": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
35
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IsExact } from "conditional-type-checks"
|
|
2
|
+
import type { Action } from "../Action.ts"
|
|
3
|
+
import type { ActorLike } from "../Actor.ts"
|
|
4
|
+
import type { Spec } from "../Spec.ts"
|
|
5
|
+
import type { Expand } from "../util/Expand.ts"
|
|
6
|
+
|
|
7
|
+
export interface ActorAssertions<S extends Spec> {
|
|
8
|
+
assertSpec<A extends Spec>(
|
|
9
|
+
...[passes]: IsExact<S, Expand<A>> extends true ? [passes?: true] : [passes: false]
|
|
10
|
+
): void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ActorAssertions<Y extends Action, R>(
|
|
14
|
+
_actorLike: ActorLike<Y, R>,
|
|
15
|
+
): ActorAssertions<Y[""]> {
|
|
16
|
+
return {
|
|
17
|
+
assertSpec: () => {},
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EmbeddingModel } from "../Model.ts"
|
|
2
|
+
|
|
3
|
+
export interface TestEmbeddingModelConfig {
|
|
4
|
+
getEmbedding: () => Promise<Array<number>>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const defaultTestingEmbeddingModelConfig: TestEmbeddingModelConfig = {
|
|
8
|
+
getEmbedding: () => Promise.resolve([]),
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function TestEmbeddingModel({
|
|
12
|
+
getEmbedding,
|
|
13
|
+
}: TestEmbeddingModelConfig = defaultTestingEmbeddingModelConfig): EmbeddingModel {
|
|
14
|
+
return {
|
|
15
|
+
type: "embedding",
|
|
16
|
+
embed: getEmbedding,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { assistant } from "../actions/actions_derived/messages.ts"
|
|
2
|
+
import type { LanguageModel } from "../Model.ts"
|
|
3
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
4
|
+
|
|
5
|
+
export interface TestLanguageModelConfig {
|
|
6
|
+
getObject: () => JSONValue
|
|
7
|
+
getText: () => string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const defaultTestLanguageModelConfig: TestLanguageModelConfig = {
|
|
11
|
+
getObject: () => ({}),
|
|
12
|
+
getText: () => "",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function TestLanguageModel({
|
|
16
|
+
getObject,
|
|
17
|
+
getText,
|
|
18
|
+
}: TestLanguageModelConfig = defaultTestLanguageModelConfig): LanguageModel {
|
|
19
|
+
return {
|
|
20
|
+
type: "language",
|
|
21
|
+
async *infer(type) {
|
|
22
|
+
if (type) {
|
|
23
|
+
const object = getObject()
|
|
24
|
+
yield* assistant`${JSON.stringify(object)}`
|
|
25
|
+
return object
|
|
26
|
+
}
|
|
27
|
+
const text = getText()
|
|
28
|
+
yield* assistant`${text}`
|
|
29
|
+
return text
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
package/testing/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Action } from "../Action.ts"
|
|
2
|
+
import type { ActorLike } from "../Actor.ts"
|
|
3
|
+
import { unwrapDeferred } from "../util/unwrapDeferred.ts"
|
|
4
|
+
|
|
5
|
+
export async function takeFirstAction<Y extends Action>(f: ActorLike<Y>): Promise<Y | undefined> {
|
|
6
|
+
const { value } = await unwrapDeferred(f).next()
|
|
7
|
+
return value
|
|
8
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "../tsconfig.base",
|
|
2
3
|
"compilerOptions": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"removeComments": true,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"outDir": "./lib",
|
|
8
|
-
"preserveConstEnums": true
|
|
4
|
+
"noEmit": false,
|
|
5
|
+
"outDir": "dist"
|
|
9
6
|
},
|
|
10
|
-
"include": ["
|
|
11
|
-
"exclude": ["node_modules", "src/**/*.test.ts", "src/**/*.temp.ts"]
|
|
7
|
+
"include": ["."]
|
|
12
8
|
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { assert } from "../util/assert.ts"
|
|
2
|
+
import { isJSONValue } from "../util/isJSONValue.ts"
|
|
3
|
+
import { jsonEquals } from "../util/jsonEquals.ts"
|
|
4
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
5
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
6
|
+
import type { JSONType } from "./JSONType.ts"
|
|
7
|
+
import type { Type } from "./Type.ts"
|
|
8
|
+
import { TypeVisitor } from "./TypeVisitor.ts"
|
|
9
|
+
|
|
10
|
+
export type AssertDiagnostics = Array<Diagnostic>
|
|
11
|
+
|
|
12
|
+
export type Diagnostic = ReturnType<typeof Diagnostic>
|
|
13
|
+
export function Diagnostic(path: AssertPath, type: Type, error: unknown) {
|
|
14
|
+
return {
|
|
15
|
+
path,
|
|
16
|
+
type,
|
|
17
|
+
error,
|
|
18
|
+
message,
|
|
19
|
+
formatPath,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function message() {
|
|
23
|
+
return error instanceof Error ? error.message : JSON.stringify(error)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatPath() {
|
|
27
|
+
let formatted = ""
|
|
28
|
+
for (let i = 0; i < path.length; i++) {
|
|
29
|
+
const key = path[i]!
|
|
30
|
+
if (typeof key === "string") {
|
|
31
|
+
try {
|
|
32
|
+
const int = parseInt(key)
|
|
33
|
+
if (Number.isInteger(int)) {
|
|
34
|
+
formatted += `[${int}]`
|
|
35
|
+
} else {
|
|
36
|
+
formatted += `.${key}`
|
|
37
|
+
}
|
|
38
|
+
} catch (_e: unknown) {
|
|
39
|
+
formatted += `.${key}`
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
formatted += `[${key}]`
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return formatted
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type AssertPath = Array<JSONKey>
|
|
50
|
+
|
|
51
|
+
// Possibly: `nullUnionFieldsAsOptional?: boolean`
|
|
52
|
+
export interface AssertDiagnosticsConfig {}
|
|
53
|
+
|
|
54
|
+
export function AssertDiagnostics<T extends JSONValue, J extends JSONType>(
|
|
55
|
+
config: AssertDiagnosticsConfig,
|
|
56
|
+
type: Type<T, J>,
|
|
57
|
+
value: unknown,
|
|
58
|
+
): Array<Diagnostic> {
|
|
59
|
+
const state = ValueVisitorState()
|
|
60
|
+
visit([config, false], type)(value, state)
|
|
61
|
+
return state.diagnostics
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type ValueVisitorState = ReturnType<typeof ValueVisitorState>
|
|
65
|
+
function ValueVisitorState(
|
|
66
|
+
diagnostics: Array<Diagnostic> = [],
|
|
67
|
+
path: Array<number | string> = [],
|
|
68
|
+
) {
|
|
69
|
+
return {
|
|
70
|
+
diagnostics,
|
|
71
|
+
path,
|
|
72
|
+
next,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function next(key?: JSONKey) {
|
|
76
|
+
return ValueVisitorState(diagnostics, [...path, ...key !== undefined ? [key] : []])
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const visit: TypeVisitor<AssertDiagnosticsConfig, (value: unknown, vState: ValueVisitorState) => void> = TypeVisitor(
|
|
81
|
+
{
|
|
82
|
+
hook(next, tState, type) {
|
|
83
|
+
return (value, vState) => {
|
|
84
|
+
try {
|
|
85
|
+
next(tState, type)(value, vState)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
vState.diagnostics.push(Diagnostic(vState.path, type, error))
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
null() {
|
|
92
|
+
return (value) => {
|
|
93
|
+
assert(value === null)
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
boolean() {
|
|
97
|
+
return (value) => {
|
|
98
|
+
assert(typeof value === "boolean")
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
integer() {
|
|
102
|
+
return (value) => {
|
|
103
|
+
assert(typeof value === "number" && Number.isInteger(value))
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
number() {
|
|
107
|
+
return (value) => {
|
|
108
|
+
assert(typeof value === "number")
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
string() {
|
|
112
|
+
return (value) => {
|
|
113
|
+
assert(typeof value === "string")
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
const(_tState, _type, _valueType, value_) {
|
|
117
|
+
return (value) => {
|
|
118
|
+
assert(isJSONValue(value) && jsonEquals(value_, value))
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
_array(tState, _type, element) {
|
|
122
|
+
const visitElement = visit(tState, element)
|
|
123
|
+
return (value, vState) => {
|
|
124
|
+
assert(Array.isArray(value))
|
|
125
|
+
value.forEach((e, i) => visitElement(e, vState.next(i)))
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
enum(_tState, _type, ...values) {
|
|
129
|
+
return (value) => {
|
|
130
|
+
assert(typeof value == "string")
|
|
131
|
+
assert(values.includes(value))
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
_union(tState, _type, ...members) {
|
|
135
|
+
return (value, vState) => {
|
|
136
|
+
assert(members.some((member) => {
|
|
137
|
+
const memberState = vState.next()
|
|
138
|
+
visit(tState, member)(value, memberState)
|
|
139
|
+
return !memberState.diagnostics.length
|
|
140
|
+
}))
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
_object(tState, _type, fields) {
|
|
144
|
+
return (value, vState) => {
|
|
145
|
+
assert(typeof value === "object" && value !== null)
|
|
146
|
+
if (Array.isArray(fields)) {
|
|
147
|
+
fields.forEach((v, i) => {
|
|
148
|
+
visitField(tState, vState, value, i, v)
|
|
149
|
+
})
|
|
150
|
+
} else {
|
|
151
|
+
Object.entries(fields).forEach(([k, v]) => {
|
|
152
|
+
visitField(tState, vState, value, k, v)
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
ref(tState, _type, getType) {
|
|
158
|
+
return (value, vState) => {
|
|
159
|
+
visit(tState, getType())(value, vState)
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
function visitField(
|
|
166
|
+
tState: AssertDiagnosticsConfig,
|
|
167
|
+
vState: ValueVisitorState,
|
|
168
|
+
value: object,
|
|
169
|
+
key: JSONKey,
|
|
170
|
+
type: Type,
|
|
171
|
+
) {
|
|
172
|
+
assert(key in value)
|
|
173
|
+
const childValue = value[key as never]
|
|
174
|
+
assert(childValue !== undefined)
|
|
175
|
+
visit(tState, type)(childValue, vState.next(key))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// TODO: serialize signature
|
|
179
|
+
export function formatAssertDiagnostics(diagnostics: AssertDiagnostics) {
|
|
180
|
+
return diagnostics
|
|
181
|
+
.map((diagnostic) => `Error "${diagnostic.message()}"; encountered at ${diagnostic.formatPath()}`)
|
|
182
|
+
.join("\n")
|
|
183
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JSONIdentifiedType, JSONType } from "./JSONType.ts"
|
|
2
|
+
|
|
3
|
+
export const JSONSchema$schema = "http://json-schema.org/draft-07/schema#"
|
|
4
|
+
|
|
5
|
+
export type JSONRootType<J extends JSONType> = J & {
|
|
6
|
+
$schema: typeof JSONSchema$schema
|
|
7
|
+
$defs: Record<string, JSONIdentifiedType | undefined>
|
|
8
|
+
}
|