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,33 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test"
|
|
2
|
+
import type { LEvent } from "../../events/LEvent.ts"
|
|
3
|
+
import { Exec } from "../../Exec.ts"
|
|
4
|
+
import * as L from "../../L.ts"
|
|
5
|
+
import { TestEmbeddingModel } from "../../testing/TestEmbeddingModel.ts"
|
|
6
|
+
import { TestLanguageModel } from "../../testing/TestLanguageModel.ts"
|
|
7
|
+
|
|
8
|
+
describe("Model", () => {
|
|
9
|
+
it("generates the expected event sequence", async () => {
|
|
10
|
+
const events: Array<LEvent> = []
|
|
11
|
+
await Exec(function*() {
|
|
12
|
+
const a = yield* L.declareModel("secondary")
|
|
13
|
+
yield* L.branch("fork-key", function*() {
|
|
14
|
+
const b = yield* L.declareModel("child_a")
|
|
15
|
+
const c = yield* L.declareModel("child_b")
|
|
16
|
+
yield* b
|
|
17
|
+
yield* c
|
|
18
|
+
})
|
|
19
|
+
const c = yield* L.declareModel("tertiary")
|
|
20
|
+
yield* a
|
|
21
|
+
yield* c
|
|
22
|
+
}, {
|
|
23
|
+
default: TestLanguageModel(),
|
|
24
|
+
args: {
|
|
25
|
+
secondary: TestLanguageModel(),
|
|
26
|
+
child_a: TestLanguageModel(),
|
|
27
|
+
child_b: TestEmbeddingModel(),
|
|
28
|
+
tertiary: TestEmbeddingModel(),
|
|
29
|
+
},
|
|
30
|
+
})((event) => events.push(event))
|
|
31
|
+
expect(JSON.stringify(events, null, 2)).toMatchSnapshot()
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Model } from "../../Model.ts"
|
|
2
|
+
import type { JSONKey } from "../../util/JSONKey.ts"
|
|
3
|
+
import { declareArg } from "../declareArg.ts"
|
|
4
|
+
import { pushModel } from "../pushModel.ts"
|
|
5
|
+
|
|
6
|
+
export function* declareModel<K extends JSONKey>(key: K) {
|
|
7
|
+
const model = yield* declareArg(key)<Model>()
|
|
8
|
+
return yield* pushModel(key, model)
|
|
9
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// import type { RunEmbed, RunInfer } from "../../adapters.ts"
|
|
2
|
+
// import type { ChildEvent } from "../../events/ChildEvent.ts"
|
|
3
|
+
// import type { EmbeddingModelSetEvent } from "../../events/EmbeddingModelSetEvent.ts"
|
|
4
|
+
// import type { LanguageModelSetEvent } from "../../events/LanguageModelSetEvent.ts"
|
|
5
|
+
// import * as L from "../../L.ts"
|
|
6
|
+
// import { ActorAssertions } from "../../testing/ActorAssertions.ts"
|
|
7
|
+
// import { declareEmbeddingModel } from "./declareEmbeddingModel.ts"
|
|
8
|
+
// import { declareLanguageModel } from "./declareLanguageModel.ts"
|
|
9
|
+
|
|
10
|
+
// const languageModel = declareLanguageModel("A")
|
|
11
|
+
// ActorAssertions(languageModel).assertSpec<{
|
|
12
|
+
// Entry: ["A", RunInfer]
|
|
13
|
+
// Event: LanguageModelSetEvent<"A">
|
|
14
|
+
// Throw: never
|
|
15
|
+
// Child: never
|
|
16
|
+
// }>()
|
|
17
|
+
|
|
18
|
+
// const embeddingModel = declareEmbeddingModel("B")
|
|
19
|
+
// ActorAssertions(embeddingModel).assertSpec<{
|
|
20
|
+
// Entry: ["B", RunEmbed]
|
|
21
|
+
// Event: EmbeddingModelSetEvent<"B">
|
|
22
|
+
// Throw: never
|
|
23
|
+
// Child: never
|
|
24
|
+
// }>()
|
|
25
|
+
|
|
26
|
+
// function* both() {
|
|
27
|
+
// yield* languageModel
|
|
28
|
+
// yield* embeddingModel
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
// ActorAssertions(both).assertSpec<{
|
|
32
|
+
// Entry: ["A", RunInfer] | ["B", RunEmbed]
|
|
33
|
+
// Event: LanguageModelSetEvent<"A"> | EmbeddingModelSetEvent<"B">
|
|
34
|
+
// Throw: never
|
|
35
|
+
// Child: never
|
|
36
|
+
// }>()
|
|
37
|
+
|
|
38
|
+
// function* parent() {
|
|
39
|
+
// yield* L.branch("fork-key", {
|
|
40
|
+
// *key() {
|
|
41
|
+
// yield* both()
|
|
42
|
+
// },
|
|
43
|
+
// })
|
|
44
|
+
// yield* declareLanguageModel("C")
|
|
45
|
+
// yield* declareEmbeddingModel("D")
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
// ActorAssertions(parent).assertSpec<{
|
|
49
|
+
// Entry:
|
|
50
|
+
// | ["A", RunInfer]
|
|
51
|
+
// | ["B", RunEmbed]
|
|
52
|
+
// | ["C", RunInfer]
|
|
53
|
+
// | ["D", RunEmbed]
|
|
54
|
+
// Event:
|
|
55
|
+
// | ChildEvent<
|
|
56
|
+
// "branch",
|
|
57
|
+
// "fork-key",
|
|
58
|
+
// ChildEvent<
|
|
59
|
+
// "branch_arm",
|
|
60
|
+
// "key",
|
|
61
|
+
// LanguageModelSetEvent<"A"> | EmbeddingModelSetEvent<"B">,
|
|
62
|
+
// void
|
|
63
|
+
// >,
|
|
64
|
+
// { key: void }
|
|
65
|
+
// >
|
|
66
|
+
// | LanguageModelSetEvent<"C">
|
|
67
|
+
// | EmbeddingModelSetEvent<"D">
|
|
68
|
+
// Throw: never
|
|
69
|
+
// Child: never
|
|
70
|
+
// }>()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Action } from "../../Action.ts"
|
|
2
|
+
import type { Message } from "../../Message.ts"
|
|
3
|
+
|
|
4
|
+
export function* getMessages(): Generator<Action<"get_messages">, Array<Message>> {
|
|
5
|
+
return yield Action("get_messages", (scope) => ({
|
|
6
|
+
...scope,
|
|
7
|
+
nextArg: [...scope.messages],
|
|
8
|
+
}))
|
|
9
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// import { describe, expect, test } from "bun:test"
|
|
2
|
+
// import * as L from "../L.ts"
|
|
3
|
+
// import { takeFirstAction } from "../testing/takeFirstAction.ts"
|
|
4
|
+
|
|
5
|
+
// describe("message templates", () => {
|
|
6
|
+
// test("system messages with indentation", async () => {
|
|
7
|
+
// // Create a system message with indented multiline content
|
|
8
|
+
// const messageGenerator = L.system`
|
|
9
|
+
// Hello, I am an AI assistant.
|
|
10
|
+
// I can help with the following:
|
|
11
|
+
// - Code generation
|
|
12
|
+
// - Answering questions
|
|
13
|
+
// - General assistance
|
|
14
|
+
// `
|
|
15
|
+
|
|
16
|
+
// const action = await takeFirstAction(messageGenerator)
|
|
17
|
+
|
|
18
|
+
// expect(action?.message.content).toBe(
|
|
19
|
+
// "Hello, I am an AI assistant.\nI can help with the following:\n - Code generation\n - Answering questions\n - General assistance",
|
|
20
|
+
// )
|
|
21
|
+
// })
|
|
22
|
+
|
|
23
|
+
// test("user messages with substitution", async () => {
|
|
24
|
+
// const name = "John"
|
|
25
|
+
// const messageGenerator = L.user`Hello, my name is ${name}.`
|
|
26
|
+
|
|
27
|
+
// const action = await takeFirstAction(messageGenerator)
|
|
28
|
+
|
|
29
|
+
// expect(action?.message.content).toBe("Hello, my name is John.")
|
|
30
|
+
// })
|
|
31
|
+
|
|
32
|
+
// test("user messages with multiline substitution and indentation", async () => {
|
|
33
|
+
// const codeBlock = "function example() {\n console.log('Hello');\n}"
|
|
34
|
+
|
|
35
|
+
// const messageGenerator = L.user`
|
|
36
|
+
// Here's my code:
|
|
37
|
+
// ${codeBlock}
|
|
38
|
+
// Can you help me understand it?
|
|
39
|
+
// `
|
|
40
|
+
|
|
41
|
+
// const action = await takeFirstAction(messageGenerator)
|
|
42
|
+
|
|
43
|
+
// // The code block should get indentation applied to lines after the first
|
|
44
|
+
// expect(action?.message.content).toBe(
|
|
45
|
+
// "Here's my code:\n function example() {\n console.log('Hello');\n }\nCan you help me understand it?",
|
|
46
|
+
// )
|
|
47
|
+
// })
|
|
48
|
+
|
|
49
|
+
// test("assistant messages with multiline substitution", async () => {
|
|
50
|
+
// const explanation =
|
|
51
|
+
// "1. First, we declare a function\n2. Then we log a message\n3. The function doesn't return anything"
|
|
52
|
+
|
|
53
|
+
// const messageGenerator = L.assistant`
|
|
54
|
+
// Let me explain:
|
|
55
|
+
// ${explanation}
|
|
56
|
+
// Does that help?
|
|
57
|
+
// `
|
|
58
|
+
|
|
59
|
+
// const action = await takeFirstAction(messageGenerator)
|
|
60
|
+
|
|
61
|
+
// // The explanation lines should get indentation
|
|
62
|
+
// expect(action?.message.content).toBe(
|
|
63
|
+
// "Let me explain:\n 1. First, we declare a function\n 2. Then we log a message\n 3. The function doesn't return anything\nDoes that help?",
|
|
64
|
+
// )
|
|
65
|
+
// })
|
|
66
|
+
|
|
67
|
+
// test("preserves code indentation", async () => {
|
|
68
|
+
// const code = `if (condition) {
|
|
69
|
+
// // This is indented once
|
|
70
|
+
// if (nestedCondition) {
|
|
71
|
+
// // This is indented twice
|
|
72
|
+
// }
|
|
73
|
+
// }`
|
|
74
|
+
|
|
75
|
+
// const messageGenerator = L.user`
|
|
76
|
+
// My code:
|
|
77
|
+
// ${code}
|
|
78
|
+
// `
|
|
79
|
+
|
|
80
|
+
// const action = await takeFirstAction(messageGenerator)
|
|
81
|
+
|
|
82
|
+
// // The code's internal indentation structure should be preserved
|
|
83
|
+
// // while getting additional indentation from the template
|
|
84
|
+
// expect(action?.message.content).toBe(
|
|
85
|
+
// "My code:\n if (condition) {\n // This is indented once\n if (nestedCondition) {\n // This is indented twice\n }\n }",
|
|
86
|
+
// )
|
|
87
|
+
// })
|
|
88
|
+
// })
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MessageRemoved } from "../../events/MessageRemoved.ts"
|
|
2
|
+
import type { AssistantContent, UserContent } from "../../Message.ts"
|
|
3
|
+
import { normalizeTaggableArgs, type TaggableArgs } from "../../util/Taggable.ts"
|
|
4
|
+
import { appendMessage } from "../appendMessage.ts"
|
|
5
|
+
|
|
6
|
+
export function user(...args: TaggableArgs<[content: UserContent]>) {
|
|
7
|
+
const [content] = normalizeTaggableArgs(...args)
|
|
8
|
+
return appendMessage("user", content)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function system(...args: TaggableArgs<[content: string]>) {
|
|
12
|
+
const [content] = normalizeTaggableArgs(...args)
|
|
13
|
+
return appendMessage("system", content)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function assistant(...args: TaggableArgs<[content: AssistantContent]>) {
|
|
17
|
+
const [content] = normalizeTaggableArgs(...args)
|
|
18
|
+
return appendMessage("assistant", content)
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { fromMetatypeRootDescriptor } from "../../types/Metatype/fromMetatypeDescriptor.ts"
|
|
2
|
+
import { MetatypeRootDescriptor } from "../../types/Metatype/MetatypeDescriptor.ts"
|
|
3
|
+
import type { Falsy } from "../../util/Falsy.ts"
|
|
4
|
+
import type { TaggableArgs } from "../../util/Taggable.ts"
|
|
5
|
+
|
|
6
|
+
export function* metatype(...args: TaggableArgs<[...description: Array<string | Falsy>]>) {
|
|
7
|
+
const descriptor = yield* MetatypeRootDescriptor(args.map((e) => typeof e === "string").join("\n"))
|
|
8
|
+
return fromMetatypeRootDescriptor(descriptor)
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { MessageAppended } from "../events/MessageAppended.ts"
|
|
3
|
+
import type { Message, MessageContents, MessageRole, Messages } from "../Message.ts"
|
|
4
|
+
import type { Spec } from "../Spec.ts"
|
|
5
|
+
import { removeMessage } from "./removeMessage.ts"
|
|
6
|
+
|
|
7
|
+
export interface appendMessage<M extends Message>
|
|
8
|
+
extends Action<"append_message", Spec.Make<{ Event: MessageAppended<M> }>>
|
|
9
|
+
{}
|
|
10
|
+
|
|
11
|
+
export function* appendMessage<R extends MessageRole>(
|
|
12
|
+
role: R,
|
|
13
|
+
content: MessageContents[R],
|
|
14
|
+
): Generator<appendMessage<Messages[R]>, Generator<removeMessage, void>> {
|
|
15
|
+
return yield Action("append_message", (scope) => {
|
|
16
|
+
const message = {
|
|
17
|
+
role,
|
|
18
|
+
content,
|
|
19
|
+
} as Messages[R] // <-- why isn't this inferred?
|
|
20
|
+
scope.event({
|
|
21
|
+
type: "message_appended",
|
|
22
|
+
message,
|
|
23
|
+
})
|
|
24
|
+
return {
|
|
25
|
+
...scope,
|
|
26
|
+
nextArg: removeMessage(message),
|
|
27
|
+
messages: new Set([...scope.messages, message]),
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
package/actions/await.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
|
|
3
|
+
export interface await_<_T> extends Action<"await", never> {}
|
|
4
|
+
|
|
5
|
+
function* await_<T>(value: T): Generator<await_<Awaited<T>>, Awaited<T>> {
|
|
6
|
+
return yield Action("await", async (scope) => ({
|
|
7
|
+
...scope,
|
|
8
|
+
nextArg: await value,
|
|
9
|
+
}))
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(await_, "name", { value: "await" })
|
|
12
|
+
|
|
13
|
+
export { await_ as await }
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type {
|
|
3
|
+
Actor,
|
|
4
|
+
ActorLike,
|
|
5
|
+
ActorLikeArray,
|
|
6
|
+
ActorLikeRecord,
|
|
7
|
+
ActorLikesT,
|
|
8
|
+
ActorLikeT,
|
|
9
|
+
ActorLikeY,
|
|
10
|
+
} from "../Actor.ts"
|
|
11
|
+
import type { ActorLikes } from "../Actor.ts"
|
|
12
|
+
import type { Spec } from "../Spec.ts"
|
|
13
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
14
|
+
import { unwrapDeferred } from "../util/unwrapDeferred.ts"
|
|
15
|
+
|
|
16
|
+
export function branch<
|
|
17
|
+
K extends JSONKey,
|
|
18
|
+
Y extends Action,
|
|
19
|
+
T,
|
|
20
|
+
>(
|
|
21
|
+
key: K,
|
|
22
|
+
actorLike: ActorLike<Y, T>,
|
|
23
|
+
): Generator<
|
|
24
|
+
Action<
|
|
25
|
+
"branch",
|
|
26
|
+
Spec.Make<{
|
|
27
|
+
Child: [Y[""]] extends [never] ? never : [K, Y[""]]
|
|
28
|
+
Entry: Y[""]["Entry"]
|
|
29
|
+
Value: T
|
|
30
|
+
}>
|
|
31
|
+
>,
|
|
32
|
+
T
|
|
33
|
+
>
|
|
34
|
+
export function branch<K extends JSONKey, const A extends ActorLikeArray>(name: K, actorLikeArray: A): Generator<
|
|
35
|
+
Action<
|
|
36
|
+
"branch",
|
|
37
|
+
Spec.Make<{
|
|
38
|
+
Child: [
|
|
39
|
+
K,
|
|
40
|
+
{
|
|
41
|
+
[L in keyof A]: Spec.Make<{
|
|
42
|
+
Child: [L, ActorLikeY<A[L]>[""]]
|
|
43
|
+
Entry: ActorLikeY<A[L]>[""]["Entry"]
|
|
44
|
+
Value: ActorLikeT<A[L]>
|
|
45
|
+
}>
|
|
46
|
+
}[keyof A],
|
|
47
|
+
]
|
|
48
|
+
Entry: ActorLikeY<A[number]>[""]["Entry"]
|
|
49
|
+
}>
|
|
50
|
+
>,
|
|
51
|
+
ActorLikesT<A>
|
|
52
|
+
>
|
|
53
|
+
export function branch<K extends JSONKey, A extends ActorLikeRecord>(name: K, actorLikeRecord: A): Generator<
|
|
54
|
+
Action<
|
|
55
|
+
"branch",
|
|
56
|
+
Spec.Make<{
|
|
57
|
+
Child: [
|
|
58
|
+
K,
|
|
59
|
+
{
|
|
60
|
+
[L in Exclude<keyof A, symbol>]: Spec.Make<{
|
|
61
|
+
Child: [L, ActorLikeY<A[L]>[""]]
|
|
62
|
+
Entry: ActorLikeY<A[L]>[""]["Entry"]
|
|
63
|
+
Value: ActorLikeT<A[L]>
|
|
64
|
+
}>
|
|
65
|
+
}[Exclude<keyof A, symbol>],
|
|
66
|
+
]
|
|
67
|
+
Entry: ActorLikeY<A[keyof A]>[""]["Entry"]
|
|
68
|
+
}>
|
|
69
|
+
>,
|
|
70
|
+
ActorLikesT<A>
|
|
71
|
+
>
|
|
72
|
+
export function* branch(key: JSONKey, implementation: ActorLike | ActorLikes): Generator<Action<"branch">, any> {
|
|
73
|
+
return yield Action("branch", async (scope) => {
|
|
74
|
+
if (typeof implementation === "function") {
|
|
75
|
+
const branchScope = scope.fork("branch", [key])
|
|
76
|
+
const actor = unwrapDeferred(implementation as ActorLike)
|
|
77
|
+
const { value } = await branchScope.reduce(actor)
|
|
78
|
+
branchScope.event({
|
|
79
|
+
type: "returned",
|
|
80
|
+
value,
|
|
81
|
+
})
|
|
82
|
+
return {
|
|
83
|
+
...scope,
|
|
84
|
+
nextArg: value,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const armKeys = Array.isArray(implementation)
|
|
88
|
+
? Array.from({ length: implementation.length }, (_0, i) => i)
|
|
89
|
+
: Reflect.ownKeys(implementation) as Array<string>
|
|
90
|
+
const values = await Promise.all(armKeys.map(async (armKey) => {
|
|
91
|
+
const branchArmScope = scope.fork("branch_arm", [key, armKey])
|
|
92
|
+
const actor = unwrapDeferred(implementation[armKey as never]) as Actor
|
|
93
|
+
const { value } = await branchArmScope.reduce(actor)
|
|
94
|
+
branchArmScope.event({
|
|
95
|
+
type: "returned",
|
|
96
|
+
value,
|
|
97
|
+
})
|
|
98
|
+
return value
|
|
99
|
+
}))
|
|
100
|
+
const value = Array.isArray(implementation)
|
|
101
|
+
? values
|
|
102
|
+
: Object.fromEntries(armKeys.map((key, i) => [key, values[i]]))
|
|
103
|
+
return {
|
|
104
|
+
...scope,
|
|
105
|
+
nextArg: value,
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
package/actions/catch.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { ActorLike } from "../Actor.ts"
|
|
3
|
+
import type { Spec } from "../Spec.ts"
|
|
4
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
5
|
+
import type { Result } from "../util/Result.ts"
|
|
6
|
+
import { unwrapDeferred } from "../util/unwrapDeferred.ts"
|
|
7
|
+
|
|
8
|
+
export { catch_ as catch }
|
|
9
|
+
function* catch_<K extends JSONKey, Y extends Action, T>(
|
|
10
|
+
key: K,
|
|
11
|
+
actorLike: ActorLike<Y, T>,
|
|
12
|
+
): Generator<
|
|
13
|
+
Action<
|
|
14
|
+
"catch",
|
|
15
|
+
Spec.Make<{
|
|
16
|
+
Child: [K, Y[""]]
|
|
17
|
+
Value: T
|
|
18
|
+
}>
|
|
19
|
+
>,
|
|
20
|
+
Result<T, Y[""]["Throw"]>
|
|
21
|
+
> {
|
|
22
|
+
return yield Action("catch", async (scope) => {
|
|
23
|
+
const catchScope = scope.fork("catch", [key])
|
|
24
|
+
try {
|
|
25
|
+
const { value } = await catchScope.reduce(unwrapDeferred(actorLike))
|
|
26
|
+
catchScope.event({
|
|
27
|
+
type: "returned",
|
|
28
|
+
value,
|
|
29
|
+
})
|
|
30
|
+
return {
|
|
31
|
+
...scope,
|
|
32
|
+
nextArg: { value },
|
|
33
|
+
}
|
|
34
|
+
} catch (thrown: unknown) {
|
|
35
|
+
return {
|
|
36
|
+
...scope,
|
|
37
|
+
nextArg: { thrown },
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
Object.defineProperty(catch_, "name", { value: "catch" })
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Spec } from "../Spec.ts"
|
|
3
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
4
|
+
|
|
5
|
+
export interface declareArg<K extends JSONKey, T> extends Action<"declare_arg", Spec.Make<{ Entry: [K, T] }>> {}
|
|
6
|
+
|
|
7
|
+
export function declareArg<K extends JSONKey>(key: K): <T>() => Generator<declareArg<K, T>, T> {
|
|
8
|
+
return function*() {
|
|
9
|
+
return yield Action("declare_arg", (scope) => ({
|
|
10
|
+
...scope,
|
|
11
|
+
nextArg: scope.args?.[key],
|
|
12
|
+
}))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { ToolDisabled } from "../events/ToolDisabled.ts"
|
|
3
|
+
import type { Spec } from "../Spec.ts"
|
|
4
|
+
import type { Tool } from "../Tool.ts"
|
|
5
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
6
|
+
|
|
7
|
+
export interface disableTool<K extends JSONKey> extends Action<"disable_tool", Spec.Make<{ Event: ToolDisabled<K> }>> {}
|
|
8
|
+
|
|
9
|
+
export function* disableTool<K extends JSONKey>(tool: Tool<K>): Generator<
|
|
10
|
+
disableTool<K>,
|
|
11
|
+
void
|
|
12
|
+
> {
|
|
13
|
+
yield Action("disable_tool", (scope) => {
|
|
14
|
+
scope.event({
|
|
15
|
+
type: "tool_disabled",
|
|
16
|
+
tool: tool.toolKey,
|
|
17
|
+
})
|
|
18
|
+
const tools = new Set(scope.tools)
|
|
19
|
+
tools.delete(tool)
|
|
20
|
+
return {
|
|
21
|
+
...scope,
|
|
22
|
+
tools,
|
|
23
|
+
nextArg: undefined,
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
package/actions/embed.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Embedded } from "../events/Embedded.ts"
|
|
3
|
+
import type { EmbeddingRequested } from "../events/EmbeddingRequested.ts"
|
|
4
|
+
import type { Spec } from "../Spec.ts"
|
|
5
|
+
import { assert } from "../util/assert.ts"
|
|
6
|
+
|
|
7
|
+
export interface embed extends Action<"embed", Spec.Make<{ Event: EmbeddingRequested | Embedded }>> {}
|
|
8
|
+
|
|
9
|
+
export function* embed(value: string): Generator<embed, Array<number>> {
|
|
10
|
+
return yield Action("embed", async (scope) => {
|
|
11
|
+
const model = scope.embeddingModels.values().next().value
|
|
12
|
+
assert(model)
|
|
13
|
+
scope.event({
|
|
14
|
+
type: "embedding_requested",
|
|
15
|
+
value,
|
|
16
|
+
})
|
|
17
|
+
const embedding = await model.embed(value)
|
|
18
|
+
scope.event({
|
|
19
|
+
type: "embedded",
|
|
20
|
+
value,
|
|
21
|
+
embedding,
|
|
22
|
+
})
|
|
23
|
+
return {
|
|
24
|
+
...scope,
|
|
25
|
+
nextArg: scope.value,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
package/actions/emit.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Emitted } from "../events/Emitted.ts"
|
|
3
|
+
import type { Spec } from "../Spec.ts"
|
|
4
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
5
|
+
|
|
6
|
+
export interface emit<V extends JSONValue> extends Action<"emit", Spec.Make<{ Event: Emitted<V> }>> {}
|
|
7
|
+
|
|
8
|
+
export function* emit<V extends JSONValue = never>(
|
|
9
|
+
value: V = undefined as never,
|
|
10
|
+
): Generator<emit<V>, void> {
|
|
11
|
+
return yield Action("emit", (scope) => {
|
|
12
|
+
scope.event({
|
|
13
|
+
type: "emitted",
|
|
14
|
+
value,
|
|
15
|
+
})
|
|
16
|
+
return {
|
|
17
|
+
...scope,
|
|
18
|
+
nextArg: undefined,
|
|
19
|
+
}
|
|
20
|
+
}) as never
|
|
21
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
+
import { Action } from "../Action.ts"
|
|
3
|
+
import type { Actor } from "../Actor.ts"
|
|
4
|
+
import type { ToolCalled } from "../events/ToolCalled.ts"
|
|
5
|
+
import type { ToolEnabled } from "../events/ToolEnabled.ts"
|
|
6
|
+
import type { Spec } from "../Spec.ts"
|
|
7
|
+
import { Tool, type ToolImplementation, type ToolResult } from "../Tool.ts"
|
|
8
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
9
|
+
import type { JSONObject } from "../util/JSONObject.ts"
|
|
10
|
+
import { JSONSchemaMemo } from "../util/JSONSchemaMemo.ts"
|
|
11
|
+
import type { PromiseOr } from "../util/PromiseOr.ts"
|
|
12
|
+
import { disableTool } from "./disableTool.ts"
|
|
13
|
+
|
|
14
|
+
export function enableTool<K extends JSONKey, A>(
|
|
15
|
+
key: K,
|
|
16
|
+
description: string,
|
|
17
|
+
params: StandardSchemaV1<JSONObject, A>,
|
|
18
|
+
implementation: (params: A) => PromiseOr<ToolResult>,
|
|
19
|
+
): Generator<
|
|
20
|
+
Action<
|
|
21
|
+
"enable_tool",
|
|
22
|
+
Spec.Make<{
|
|
23
|
+
Event: ToolEnabled<K> | ToolCalled<K, A>
|
|
24
|
+
}>
|
|
25
|
+
>,
|
|
26
|
+
Generator<disableTool<K>, void>
|
|
27
|
+
>
|
|
28
|
+
export function enableTool<
|
|
29
|
+
K extends JSONKey,
|
|
30
|
+
A,
|
|
31
|
+
Y extends Action,
|
|
32
|
+
T extends ToolResult,
|
|
33
|
+
>(
|
|
34
|
+
key: K,
|
|
35
|
+
description: string,
|
|
36
|
+
params: StandardSchemaV1<JSONObject, A>,
|
|
37
|
+
implementation: (params: A) => Actor<Y, T>,
|
|
38
|
+
): Generator<
|
|
39
|
+
Action<
|
|
40
|
+
"enable_tool",
|
|
41
|
+
Spec.Make<{
|
|
42
|
+
Event: ToolEnabled<K> | ToolCalled<K, A>
|
|
43
|
+
Child: [K, Y[""]]
|
|
44
|
+
Entry: Y[""]["Entry"]
|
|
45
|
+
Value: T
|
|
46
|
+
}>
|
|
47
|
+
>,
|
|
48
|
+
Generator<disableTool<K>, void>
|
|
49
|
+
>
|
|
50
|
+
export function* enableTool(
|
|
51
|
+
key: JSONKey,
|
|
52
|
+
description: string,
|
|
53
|
+
params: StandardSchemaV1<JSONObject, any>,
|
|
54
|
+
implementation: ToolImplementation,
|
|
55
|
+
): Generator<Action<"enable_tool">, Generator<Action<"disable_tool">, void>> {
|
|
56
|
+
return yield Action("enable_tool", async (scope) => {
|
|
57
|
+
scope.event({
|
|
58
|
+
type: "tool_enabled",
|
|
59
|
+
description,
|
|
60
|
+
schema: await JSONSchemaMemo(params),
|
|
61
|
+
tool: key,
|
|
62
|
+
})
|
|
63
|
+
const tool = Tool({
|
|
64
|
+
toolKey: key,
|
|
65
|
+
description,
|
|
66
|
+
params,
|
|
67
|
+
implementation,
|
|
68
|
+
})
|
|
69
|
+
return {
|
|
70
|
+
...scope,
|
|
71
|
+
tools: new Set([...scope.tools, tool]),
|
|
72
|
+
nextArg: disableTool(tool),
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}
|