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,118 @@
|
|
|
1
|
+
import type { AssertTrue, IsExact } from "conditional-type-checks"
|
|
2
|
+
import type { ActorLike } from "../Actor.ts"
|
|
3
|
+
import type { Emitted } from "../events/Emitted.ts"
|
|
4
|
+
import type { ToolCalled } from "../events/ToolCalled.ts"
|
|
5
|
+
import type { ToolDisabled } from "../events/ToolDisabled.ts"
|
|
6
|
+
import type { ToolEnabled } from "../events/ToolEnabled.ts"
|
|
7
|
+
import * as L from "../L.ts"
|
|
8
|
+
import { ActorAssertions } from "../testing/ActorAssertions.ts"
|
|
9
|
+
import { emit } from "./emit.ts"
|
|
10
|
+
import { enableTool } from "./enableTool.ts"
|
|
11
|
+
|
|
12
|
+
type P = typeof P["T"]
|
|
13
|
+
const P = L.object({
|
|
14
|
+
a: L.string,
|
|
15
|
+
b: L.string,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const arrowTool = L.enableTool("Tool", "", P, (params) => {
|
|
19
|
+
type _ = [AssertTrue<IsExact<typeof params, P>>]
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
ActorAssertions(arrowTool).assertSpec<{
|
|
23
|
+
Event:
|
|
24
|
+
| ToolEnabled<"Tool">
|
|
25
|
+
| ToolCalled<"Tool", {
|
|
26
|
+
a: string
|
|
27
|
+
b: string
|
|
28
|
+
}>
|
|
29
|
+
Child: never
|
|
30
|
+
Throw: never
|
|
31
|
+
Entry: never
|
|
32
|
+
Value: never
|
|
33
|
+
}>()
|
|
34
|
+
|
|
35
|
+
function* _0() {
|
|
36
|
+
const detach = yield* arrowTool
|
|
37
|
+
ActorAssertions(detach).assertSpec<{
|
|
38
|
+
Event: ToolDisabled<"Tool">
|
|
39
|
+
Child: never
|
|
40
|
+
Throw: never
|
|
41
|
+
Entry: never
|
|
42
|
+
Value: never
|
|
43
|
+
}>()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const genTool = enableTool("tool-key", "", P, function*(params) {
|
|
47
|
+
type _ = [AssertTrue<IsExact<typeof params, P>>]
|
|
48
|
+
yield* emit("Test")
|
|
49
|
+
return ""
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
ActorAssertions(genTool).assertSpec<{
|
|
53
|
+
Event:
|
|
54
|
+
| ToolEnabled<"tool-key">
|
|
55
|
+
| ToolCalled<"tool-key", {
|
|
56
|
+
a: string
|
|
57
|
+
b: string
|
|
58
|
+
}>
|
|
59
|
+
Child: ["tool-key", {
|
|
60
|
+
Event: Emitted<"Test">
|
|
61
|
+
Child: never
|
|
62
|
+
Throw: never
|
|
63
|
+
Entry: never
|
|
64
|
+
Value: never
|
|
65
|
+
}]
|
|
66
|
+
Throw: never
|
|
67
|
+
Entry: never
|
|
68
|
+
Value: string
|
|
69
|
+
}>()
|
|
70
|
+
|
|
71
|
+
function* parent() {
|
|
72
|
+
yield* L.enableTool("parent-tool", "", P, () => {})
|
|
73
|
+
yield* L.branch("fork-key", {
|
|
74
|
+
*"arm-key"() {
|
|
75
|
+
yield* arrowTool
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type g = typeof parent extends ActorLike<infer Y> ? Y[""] : never
|
|
81
|
+
|
|
82
|
+
ActorAssertions(parent).assertSpec<
|
|
83
|
+
{
|
|
84
|
+
Event:
|
|
85
|
+
| ToolEnabled<"parent-tool">
|
|
86
|
+
| ToolCalled<"parent-tool", {
|
|
87
|
+
a: string
|
|
88
|
+
b: string
|
|
89
|
+
}>
|
|
90
|
+
Child: never
|
|
91
|
+
Throw: never
|
|
92
|
+
Entry: never
|
|
93
|
+
Value: never
|
|
94
|
+
} | {
|
|
95
|
+
Event: never
|
|
96
|
+
Child: ["fork-key", {
|
|
97
|
+
Event: never
|
|
98
|
+
Child: ["arm-key", {
|
|
99
|
+
Event:
|
|
100
|
+
| ToolEnabled<"Tool">
|
|
101
|
+
| ToolCalled<"Tool", {
|
|
102
|
+
a: string
|
|
103
|
+
b: string
|
|
104
|
+
}>
|
|
105
|
+
Child: never
|
|
106
|
+
Throw: never
|
|
107
|
+
Entry: never
|
|
108
|
+
Value: never
|
|
109
|
+
}]
|
|
110
|
+
Throw: never
|
|
111
|
+
Entry: never
|
|
112
|
+
Value: void
|
|
113
|
+
}]
|
|
114
|
+
Throw: never
|
|
115
|
+
Entry: never
|
|
116
|
+
Value: never
|
|
117
|
+
}
|
|
118
|
+
>()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Scope } from "../Scope.ts"
|
|
3
|
+
|
|
4
|
+
export interface getScope extends Action<"get_scope", never> {}
|
|
5
|
+
|
|
6
|
+
export function* getScope(): Generator<getScope, Scope> {
|
|
7
|
+
return yield Action("get_scope", (scope) => ({
|
|
8
|
+
...scope,
|
|
9
|
+
nextArg: scope,
|
|
10
|
+
}))
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
|
|
3
|
+
export interface getSignal extends Action<"get_signal", never> {}
|
|
4
|
+
|
|
5
|
+
export function* getSignal(): Generator<getSignal, AbortSignal> {
|
|
6
|
+
return yield (Action("get_signal", (scope) => ({
|
|
7
|
+
...scope,
|
|
8
|
+
nextArg: scope.controller.signal,
|
|
9
|
+
})))
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Tool } from "../Tool.ts"
|
|
3
|
+
|
|
4
|
+
export interface getTools extends Action<"get_tools", never> {}
|
|
5
|
+
|
|
6
|
+
export function* getTools(): Generator<getTools, Set<Tool>> {
|
|
7
|
+
return yield Action("get_tools", (scope) => ({
|
|
8
|
+
...scope,
|
|
9
|
+
nextArg: scope.tools,
|
|
10
|
+
}))
|
|
11
|
+
}
|
package/actions/infer.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
+
import { Action } from "../Action.ts"
|
|
3
|
+
import type { InferenceRequested } from "../events/InferenceRequested.ts"
|
|
4
|
+
import type { Inferred } from "../events/Inferred.ts"
|
|
5
|
+
import type { Spec } from "../Spec.ts"
|
|
6
|
+
import type { JSONObject } from "../util/JSONObject.ts"
|
|
7
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
8
|
+
|
|
9
|
+
export { infer_ as infer }
|
|
10
|
+
|
|
11
|
+
interface infer_<_T> extends
|
|
12
|
+
Action<
|
|
13
|
+
"infer",
|
|
14
|
+
Spec.Make<{
|
|
15
|
+
Event: InferenceRequested | Inferred
|
|
16
|
+
}>
|
|
17
|
+
>
|
|
18
|
+
{}
|
|
19
|
+
|
|
20
|
+
function* infer_<T extends JSONValue = string>(type?: StandardSchemaV1<JSONObject, T>): Generator<infer_<T>, T> {
|
|
21
|
+
return yield Action("infer", async (scope) => {
|
|
22
|
+
scope.event({
|
|
23
|
+
type: "inference_requested",
|
|
24
|
+
})
|
|
25
|
+
const model = scope.languageModels.values().next().value!
|
|
26
|
+
scope = await scope.reduce(model.infer(type))
|
|
27
|
+
scope.event({
|
|
28
|
+
type: "inferred",
|
|
29
|
+
value: scope.value,
|
|
30
|
+
})
|
|
31
|
+
return {
|
|
32
|
+
...scope,
|
|
33
|
+
nextArg: scope.value,
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(infer_, "name", { value: "infer" })
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { ModelPushed } from "../events/ModelPushed.ts"
|
|
3
|
+
import type { Model, ModelType } from "../Model.ts"
|
|
4
|
+
import type { Spec } from "../Spec.ts"
|
|
5
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
6
|
+
import { applyToModels } from "./actions_common/updateModels.ts"
|
|
7
|
+
import { removeModel } from "./removeModel.ts"
|
|
8
|
+
|
|
9
|
+
export interface pushModel<K extends JSONKey, M extends ModelType>
|
|
10
|
+
extends Action<"remove_model", Spec.Make<{ Event: ModelPushed<K, M> }>>
|
|
11
|
+
{}
|
|
12
|
+
|
|
13
|
+
export function* pushModel<K extends JSONKey, M extends Model>(
|
|
14
|
+
modelKey: K,
|
|
15
|
+
model: M,
|
|
16
|
+
): Generator<pushModel<K, M["type"]>, Generator<removeModel<K, M["type"]>, void>> {
|
|
17
|
+
return yield Action("remove_model", (scope) => {
|
|
18
|
+
scope.event({
|
|
19
|
+
type: "model_pushed",
|
|
20
|
+
modelKey,
|
|
21
|
+
modelType: model.type,
|
|
22
|
+
})
|
|
23
|
+
return {
|
|
24
|
+
...scope,
|
|
25
|
+
...applyToModels(scope, model, (models) => {
|
|
26
|
+
models.add(model)
|
|
27
|
+
return models
|
|
28
|
+
}),
|
|
29
|
+
nextArg: removeModel(modelKey, model),
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { MessageRemoved } from "../events/MessageRemoved.ts"
|
|
3
|
+
import type { Message } from "../Message.ts"
|
|
4
|
+
import type { Spec } from "../Spec.ts"
|
|
5
|
+
|
|
6
|
+
export interface removeMessage extends Action<"remove_message", Spec.Make<{ Event: MessageRemoved }>> {}
|
|
7
|
+
|
|
8
|
+
export function* removeMessage(message: Message): Generator<removeMessage, void> {
|
|
9
|
+
yield Action("remove_message", (scope) => {
|
|
10
|
+
scope.event({
|
|
11
|
+
type: "message_removed",
|
|
12
|
+
message,
|
|
13
|
+
})
|
|
14
|
+
const messages = new Set(scope.messages)
|
|
15
|
+
messages.delete(message)
|
|
16
|
+
return {
|
|
17
|
+
...scope,
|
|
18
|
+
nextArg: message,
|
|
19
|
+
messages,
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { ModelRemoved } from "../events/ModelRemoved.ts"
|
|
3
|
+
import type { Model, ModelType } from "../Model.ts"
|
|
4
|
+
import type { Spec } from "../Spec.ts"
|
|
5
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
6
|
+
import { applyToModels } from "./actions_common/updateModels.ts"
|
|
7
|
+
|
|
8
|
+
export interface removeModel<K extends JSONKey, M extends ModelType>
|
|
9
|
+
extends Action<"remove_model", Spec.Make<{ Event: ModelRemoved<K, M> }>>
|
|
10
|
+
{}
|
|
11
|
+
|
|
12
|
+
export function* removeModel<K extends JSONKey, M extends Model>(
|
|
13
|
+
modelKey: K,
|
|
14
|
+
model: M,
|
|
15
|
+
): Generator<removeModel<K, M["type"]>, void> {
|
|
16
|
+
yield Action("remove_model", (scope) => {
|
|
17
|
+
scope.event({
|
|
18
|
+
type: "model_removed",
|
|
19
|
+
modelKey,
|
|
20
|
+
modelType: model.type,
|
|
21
|
+
})
|
|
22
|
+
return {
|
|
23
|
+
...scope,
|
|
24
|
+
...applyToModels(scope, model, (models) => {
|
|
25
|
+
models.delete(model)
|
|
26
|
+
return models
|
|
27
|
+
}),
|
|
28
|
+
nextArg: undefined,
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Actor } from "../Actor.ts"
|
|
3
|
+
import type { MessagesSet } from "../events/MessagesSet.ts"
|
|
4
|
+
import type { Message } from "../Message.ts"
|
|
5
|
+
import type { Spec } from "../Spec.ts"
|
|
6
|
+
import { isPropertyKey } from "../util/isPropertyKey.ts"
|
|
7
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
8
|
+
import type { PromiseOr } from "../util/PromiseOr.ts"
|
|
9
|
+
|
|
10
|
+
export function setMessages(
|
|
11
|
+
setter: (messages: Array<Message>) => PromiseOr<Array<Message>>,
|
|
12
|
+
): Generator<
|
|
13
|
+
Action<
|
|
14
|
+
"set_messages",
|
|
15
|
+
Spec.Make<{
|
|
16
|
+
Event: MessagesSet
|
|
17
|
+
}>
|
|
18
|
+
>,
|
|
19
|
+
Array<Message>
|
|
20
|
+
>
|
|
21
|
+
export function setMessages<K extends JSONKey, Y extends Action>(
|
|
22
|
+
key: K,
|
|
23
|
+
setter: (messages: Array<Message>) => Actor<Y, Array<Message>>,
|
|
24
|
+
): Generator<
|
|
25
|
+
Action<
|
|
26
|
+
"set_messages",
|
|
27
|
+
Spec.Make<{
|
|
28
|
+
Event: MessagesSet
|
|
29
|
+
Child: [K, Y[""]]
|
|
30
|
+
Entry: Y[""]["Entry"]
|
|
31
|
+
Value: Array<Message>
|
|
32
|
+
}>
|
|
33
|
+
>,
|
|
34
|
+
Array<Message>
|
|
35
|
+
>
|
|
36
|
+
export function* setMessages(
|
|
37
|
+
setterOrKey: JSONKey | ((messages: Array<Message>) => PromiseOr<Array<Message>>),
|
|
38
|
+
maybeSetter?: (messages: Array<Message>) => Actor<Action, Array<Message>>,
|
|
39
|
+
): Generator<Action<"set_messages">, Array<Message>> {
|
|
40
|
+
return yield Action("set_messages", async (scope) => {
|
|
41
|
+
if (isPropertyKey(setterOrKey)) {
|
|
42
|
+
const setterScope = scope.fork("set_messages", [setterOrKey])
|
|
43
|
+
const reduced = await setterScope.reduce(maybeSetter!([...scope.messages]))
|
|
44
|
+
const { value } = reduced
|
|
45
|
+
setterScope.event({
|
|
46
|
+
type: "returned",
|
|
47
|
+
value,
|
|
48
|
+
})
|
|
49
|
+
setterScope.event({
|
|
50
|
+
type: "messages_set",
|
|
51
|
+
messages: value,
|
|
52
|
+
})
|
|
53
|
+
return {
|
|
54
|
+
...scope,
|
|
55
|
+
messages: value,
|
|
56
|
+
nextArg: scope.messages,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const messages = await setterOrKey([...scope.messages])
|
|
60
|
+
return {
|
|
61
|
+
...scope,
|
|
62
|
+
messages,
|
|
63
|
+
nextArg: scope.messages,
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
package/actions/throw.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Spec } from "../Spec.ts"
|
|
3
|
+
import type { EnsureNarrow } from "../util/EnsureNarrow.ts"
|
|
4
|
+
|
|
5
|
+
export { throw_ as throw }
|
|
6
|
+
|
|
7
|
+
interface throw_<V> extends Action<"throw", Spec.Make<{ Throw: V }>> {}
|
|
8
|
+
|
|
9
|
+
function* throw_<V>(value: V, ...[_error]: EnsureNarrow<V>): Generator<throw_<V>, never> {
|
|
10
|
+
return (yield Action("throw", (scope) => {
|
|
11
|
+
return {
|
|
12
|
+
...scope,
|
|
13
|
+
thrown: value,
|
|
14
|
+
nextArg: undefined,
|
|
15
|
+
}
|
|
16
|
+
})) as never
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(throw_, "name", { value: "throw" })
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises"
|
|
2
|
+
import { type ParsedPath, relative, resolve } from "node:path"
|
|
3
|
+
import type { EventResolved } from "../events/EventResolved.ts"
|
|
4
|
+
|
|
5
|
+
export async function WriteHandler({
|
|
6
|
+
stateDir,
|
|
7
|
+
parsedPath,
|
|
8
|
+
configDir,
|
|
9
|
+
startTime,
|
|
10
|
+
}: {
|
|
11
|
+
stateDir: string
|
|
12
|
+
execId: string | undefined
|
|
13
|
+
parsedPath: ParsedPath
|
|
14
|
+
startTime: number
|
|
15
|
+
configDir: string
|
|
16
|
+
}): Promise<(event: EventResolved) => Promise<void>> {
|
|
17
|
+
const destDir = resolve(stateDir, relative(configDir, parsedPath.dir), parsedPath.name, startTime.toString())
|
|
18
|
+
let ensureDir: undefined | PromiseWithResolvers<void>
|
|
19
|
+
let i = 0
|
|
20
|
+
return async (event) => {
|
|
21
|
+
if (!ensureDir) {
|
|
22
|
+
ensureDir = Promise.withResolvers()
|
|
23
|
+
;(async () => {
|
|
24
|
+
try {
|
|
25
|
+
await mkdir(destDir, { recursive: true })
|
|
26
|
+
} catch (_e: unknown) {}
|
|
27
|
+
ensureDir.resolve()
|
|
28
|
+
})()
|
|
29
|
+
}
|
|
30
|
+
await ensureDir.promise
|
|
31
|
+
const key = `${i++}__${event.scope.join("__")}__${event.type}.json`
|
|
32
|
+
const destPath = resolve(destDir, key)
|
|
33
|
+
await writeFile(destPath, JSON.stringify(event, null, 2), "utf-8")
|
|
34
|
+
}
|
|
35
|
+
}
|
package/cli/main.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import process from "node:process"
|
|
4
|
+
import { L } from "../index.ts"
|
|
5
|
+
import type { CliCtx } from "./cli_common.ts"
|
|
6
|
+
import { runExec } from "./runExec.ts"
|
|
7
|
+
|
|
8
|
+
const args = process.argv.slice(2)
|
|
9
|
+
const command = L.enum("exec").assert(args.shift())
|
|
10
|
+
const ctl = new AbortController()
|
|
11
|
+
|
|
12
|
+
const cliCtx: CliCtx = { ctl }
|
|
13
|
+
|
|
14
|
+
switch (command) {
|
|
15
|
+
case "exec": {
|
|
16
|
+
await runExec(cliCtx, args)
|
|
17
|
+
break
|
|
18
|
+
}
|
|
19
|
+
}
|
package/cli/runExec.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { dirname, isAbsolute, parse, resolve } from "node:path"
|
|
2
|
+
import { parseArgs, type ParseArgsConfig } from "node:util"
|
|
3
|
+
import { type Actor, type EventResolved, Exec, L, type LEvent, type LiminalConfig } from "../index.ts"
|
|
4
|
+
import type { CliCtx } from "./cli_common.ts"
|
|
5
|
+
import { WriteHandler } from "./WriteHandler.ts"
|
|
6
|
+
|
|
7
|
+
const options = {
|
|
8
|
+
config: {
|
|
9
|
+
type: "string",
|
|
10
|
+
default: "liminal.ts",
|
|
11
|
+
short: "c",
|
|
12
|
+
},
|
|
13
|
+
execId: {
|
|
14
|
+
type: "string",
|
|
15
|
+
short: "i",
|
|
16
|
+
},
|
|
17
|
+
} satisfies ParseArgsConfig["options"]
|
|
18
|
+
|
|
19
|
+
export async function runExec(ctx: CliCtx, args: Array<string>) {
|
|
20
|
+
let {
|
|
21
|
+
values: {
|
|
22
|
+
config: configPath,
|
|
23
|
+
execId,
|
|
24
|
+
},
|
|
25
|
+
positionals,
|
|
26
|
+
} = parseArgs({
|
|
27
|
+
args,
|
|
28
|
+
strict: true,
|
|
29
|
+
allowPositionals: true,
|
|
30
|
+
options,
|
|
31
|
+
})
|
|
32
|
+
const configPathResolved = resolve(configPath)
|
|
33
|
+
const configDir = dirname(configPathResolved)
|
|
34
|
+
const config = await import(configPathResolved).then(({ default: default_ }) => default_ as LiminalConfig)
|
|
35
|
+
const actorPathInitial = L.string.assert(positionals[0])
|
|
36
|
+
let actorPathResolved: string
|
|
37
|
+
if (isAbsolute(actorPathInitial)) {
|
|
38
|
+
actorPathResolved = actorPathInitial
|
|
39
|
+
} else {
|
|
40
|
+
actorPathResolved = resolve(configDir, ...config.actors ? [config.actors] : [], actorPathInitial)
|
|
41
|
+
}
|
|
42
|
+
if (!actorPathResolved.endsWith(".ts")) {
|
|
43
|
+
actorPathResolved = `${actorPathResolved}.ts`
|
|
44
|
+
}
|
|
45
|
+
const parsedPath = parse(actorPathResolved)
|
|
46
|
+
const actorLike = await import(actorPathResolved).then(({ default: default_ }) => default_ as () => Actor)
|
|
47
|
+
const startTime = Date.now()
|
|
48
|
+
const writeHandlerOrNoop = config.write
|
|
49
|
+
? await WriteHandler({
|
|
50
|
+
configDir,
|
|
51
|
+
parsedPath,
|
|
52
|
+
execId,
|
|
53
|
+
startTime,
|
|
54
|
+
stateDir: typeof config.write === "string" ? config.write : ".liminal",
|
|
55
|
+
})
|
|
56
|
+
: undefined
|
|
57
|
+
const printHandlerOrNoop = config.silent ? undefined : (event: EventResolved) => console.log(event)
|
|
58
|
+
const exec = Exec(actorLike, {
|
|
59
|
+
default: config.default,
|
|
60
|
+
args: config.args!,
|
|
61
|
+
})
|
|
62
|
+
await exec((event) => {
|
|
63
|
+
printHandlerOrNoop?.(event)
|
|
64
|
+
writeHandlerOrNoop?.(event)
|
|
65
|
+
}, {
|
|
66
|
+
signal: ctx.ctl.signal,
|
|
67
|
+
})
|
|
68
|
+
}
|
package/dist/Action.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Scope } from "./Scope.ts";
|
|
2
|
+
import type { Spec } from "./Spec.ts";
|
|
3
|
+
import type { PromiseOr } from "./util/PromiseOr.ts";
|
|
4
|
+
export interface Action<K extends string = string, S extends Spec = Spec> {
|
|
5
|
+
"": S;
|
|
6
|
+
type: K;
|
|
7
|
+
[ActionKey]: true;
|
|
8
|
+
trace: string;
|
|
9
|
+
reducer(this: this, scope: Scope): PromiseOr<Scope>;
|
|
10
|
+
}
|
|
11
|
+
export type ActionReducer<K extends string, S extends Spec> = (this: Action<K, S>, scope: Scope) => PromiseOr<Scope>;
|
|
12
|
+
export declare function Action<K extends string, S extends Spec>(type: K, reducer: ActionReducer<K, S>): Action<K, S>;
|
|
13
|
+
export type ActionKey = typeof ActionKey;
|
|
14
|
+
export declare const ActionKey: unique symbol;
|
|
15
|
+
export declare function isAction(value: unknown): value is Action;
|
package/dist/Action.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function Action(type, reducer) {
|
|
2
|
+
return {
|
|
3
|
+
type,
|
|
4
|
+
[ActionKey]: true,
|
|
5
|
+
trace: new Error().stack,
|
|
6
|
+
reducer,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export const ActionKey = Symbol("Liminal/Action");
|
|
10
|
+
export function isAction(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && ActionKey in value;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.js","sourceRoot":"","sources":["../Action.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,MAAM,CAAmC,IAAO,EAAE,OAA4B;IAC5F,OAAQ;QACN,IAAI;QACJ,CAAC,SAAS,CAAC,EAAE,IAAI;QACjB,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC,KAAM;QACzB,OAAO;KACmC,CAAA;AAC9C,CAAC;AAGD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAEjD,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK,CAAA;AAC1E,CAAC"}
|
package/dist/Actor.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Action } from "./Action.ts";
|
|
2
|
+
import type { DeferredOr } from "./util/DeferredOr.ts";
|
|
3
|
+
import type { IteratorLike } from "./util/IteratorLike.ts";
|
|
4
|
+
import type { JSONKey } from "./util/JSONKey.ts";
|
|
5
|
+
export type Actor<Y extends Action = Action, R = any> = IteratorLike<Y, R>;
|
|
6
|
+
export type ActorLike<Y extends Action = Action, R = any> = DeferredOr<Actor<Y, R>>;
|
|
7
|
+
export type ActorLikeY<A extends ActorLike> = A extends ActorLike<infer Y> ? Y : never;
|
|
8
|
+
export type ActorLikeT<A extends ActorLike> = A extends ActorLike<Action, infer T> ? T : never;
|
|
9
|
+
export type ActorLikes = ActorLikeArray | ActorLikeRecord;
|
|
10
|
+
export type ActorLikeArray = Array<ActorLike>;
|
|
11
|
+
export type ActorLikeRecord = Record<JSONKey, ActorLike>;
|
|
12
|
+
export type ActorLikesT<A extends ActorLikes> = {
|
|
13
|
+
-readonly [K in keyof A]: A[K] extends ActorLike<Action, infer T> ? T : never;
|
|
14
|
+
} & {};
|
package/dist/Actor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Actor.js","sourceRoot":"","sources":["../Actor.ts"],"names":[],"mappings":""}
|
package/dist/Exec.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Action } from "./Action.ts";
|
|
2
|
+
import type { Actor } from "./Actor.ts";
|
|
3
|
+
import type { EventHandler } from "./events/EventHandler.ts";
|
|
4
|
+
import type { EventResolved, ExtractEventResolved } from "./events/EventResolved.ts";
|
|
5
|
+
import type { LanguageModel } from "./Model.ts";
|
|
6
|
+
import type { FromEntries } from "./util/FromEntries.ts";
|
|
7
|
+
import type { JSONKey } from "./util/JSONKey.ts";
|
|
8
|
+
export interface Exec<Y extends Action = Action, T = any> {
|
|
9
|
+
(handler?: EventHandler<Extract<ExtractEventResolved<Y[""]> & {}, EventResolved>>, options?: ExecOptions): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
export interface ExecConfig {
|
|
12
|
+
default: LanguageModel;
|
|
13
|
+
args?: Record<JSONKey, any>;
|
|
14
|
+
}
|
|
15
|
+
export interface ExecOptions {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
export type ExtractExecConfig<Y extends Action> = {
|
|
19
|
+
default: LanguageModel;
|
|
20
|
+
} & ([
|
|
21
|
+
Y[""]["Entry"]
|
|
22
|
+
] extends [never] ? {
|
|
23
|
+
args?: undefined;
|
|
24
|
+
} : {
|
|
25
|
+
args: FromEntries<Y[""]["Entry"]>;
|
|
26
|
+
});
|
|
27
|
+
export declare function Exec<Y extends Action, T>(createActor: () => Actor<Y, T>, config: ExtractExecConfig<Y>): Exec<Y, T>;
|
package/dist/Exec.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RootScope } from "./Scope.js";
|
|
2
|
+
export function Exec(createActor, config) {
|
|
3
|
+
// TODO: consider `Result` type.
|
|
4
|
+
return async (handler, options) => {
|
|
5
|
+
let scope = RootScope(config.default, config.args, handler, options?.signal);
|
|
6
|
+
scope = await scope.reduce(createActor());
|
|
7
|
+
const { signal: { aborted, reason } } = scope.controller;
|
|
8
|
+
if (aborted) {
|
|
9
|
+
scope.event({
|
|
10
|
+
type: "aborted",
|
|
11
|
+
reason,
|
|
12
|
+
});
|
|
13
|
+
throw reason;
|
|
14
|
+
}
|
|
15
|
+
scope.event({
|
|
16
|
+
type: "returned",
|
|
17
|
+
value: scope.value,
|
|
18
|
+
});
|
|
19
|
+
return scope.value;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=Exec.js.map
|
package/dist/Exec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Exec.js","sourceRoot":"","sources":["../Exec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAc,MAAM,YAAY,CAAA;AAmClD,MAAM,UAAU,IAAI,CAClB,WAA8B,EAC9B,MAA4B;IAE5B,gCAAgC;IAChC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QAChC,IAAI,KAAK,GAAU,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,OAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QAC5F,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QACzC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,UAAU,CAAA;QACxD,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,CAAC,KAAK,CAAC;gBACV,IAAI,EAAE,SAAS;gBACf,MAAM;aACP,CAAC,CAAA;YACF,MAAM,MAAM,CAAA;QACd,CAAC;QACD,KAAK,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAA;QACF,OAAO,KAAK,CAAC,KAAK,CAAA;IACpB,CAAC,CAAA;AACH,CAAC"}
|
package/dist/L.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./_.ts";
|
|
2
|
+
export * from "./actions/abort.ts";
|
|
3
|
+
export * from "./actions/actions_derived/clear.ts";
|
|
4
|
+
export * from "./actions/actions_derived/declareModel.ts";
|
|
5
|
+
export * from "./actions/actions_derived/declareModel.ts";
|
|
6
|
+
export * from "./actions/actions_derived/getMessages.ts";
|
|
7
|
+
export * from "./actions/actions_derived/messages.ts";
|
|
8
|
+
export * from "./actions/appendMessage.ts";
|
|
9
|
+
export * from "./actions/await.ts";
|
|
10
|
+
export * from "./actions/branch.ts";
|
|
11
|
+
export * from "./actions/catch.ts";
|
|
12
|
+
export * from "./actions/declareArg.ts";
|
|
13
|
+
export * from "./actions/disableTool.ts";
|
|
14
|
+
export * from "./actions/embed.ts";
|
|
15
|
+
export * from "./actions/emit.ts";
|
|
16
|
+
export * from "./actions/enableTool.ts";
|
|
17
|
+
export * from "./actions/getScope.ts";
|
|
18
|
+
export * from "./actions/getSignal.ts";
|
|
19
|
+
export * from "./actions/getTools.ts";
|
|
20
|
+
export * from "./actions/infer.ts";
|
|
21
|
+
export * from "./actions/pushModel.ts";
|
|
22
|
+
export * from "./actions/removeModel.ts";
|
|
23
|
+
export * from "./actions/setMessages.ts";
|
|
24
|
+
export * from "./actions/throw.ts";
|
|
25
|
+
export * from "./types/factories.ts";
|
|
26
|
+
export * from "./actions/actions_derived/metatype.ts";
|
package/dist/L.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from "./_.js";
|
|
2
|
+
export * from "./actions/abort.js";
|
|
3
|
+
export * from "./actions/actions_derived/clear.js";
|
|
4
|
+
export * from "./actions/actions_derived/declareModel.js";
|
|
5
|
+
export * from "./actions/actions_derived/declareModel.js";
|
|
6
|
+
export * from "./actions/actions_derived/getMessages.js";
|
|
7
|
+
export * from "./actions/actions_derived/messages.js";
|
|
8
|
+
export * from "./actions/appendMessage.js";
|
|
9
|
+
export * from "./actions/await.js";
|
|
10
|
+
export * from "./actions/branch.js";
|
|
11
|
+
export * from "./actions/catch.js";
|
|
12
|
+
export * from "./actions/declareArg.js";
|
|
13
|
+
export * from "./actions/disableTool.js";
|
|
14
|
+
export * from "./actions/embed.js";
|
|
15
|
+
export * from "./actions/emit.js";
|
|
16
|
+
export * from "./actions/enableTool.js";
|
|
17
|
+
export * from "./actions/getScope.js";
|
|
18
|
+
export * from "./actions/getSignal.js";
|
|
19
|
+
export * from "./actions/getTools.js";
|
|
20
|
+
export * from "./actions/infer.js";
|
|
21
|
+
export * from "./actions/pushModel.js";
|
|
22
|
+
export * from "./actions/removeModel.js";
|
|
23
|
+
export * from "./actions/setMessages.js";
|
|
24
|
+
export * from "./actions/throw.js";
|
|
25
|
+
export * from "./types/factories.js";
|
|
26
|
+
export * from "./actions/actions_derived/metatype.js";
|
|
27
|
+
//# sourceMappingURL=L.js.map
|
package/dist/L.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"L.js","sourceRoot":"","sources":["../L.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,oCAAoC,CAAA;AAClD,cAAc,2CAA2C,CAAA;AACzD,cAAc,2CAA2C,CAAA;AACzD,cAAc,0CAA0C,CAAA;AACxD,cAAc,uCAAuC,CAAA;AACrD,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,uCAAuC,CAAA"}
|