liminal 0.4.1 → 0.5.2
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/Agent.ts +10 -0
- package/CHANGELOG.md +20 -0
- package/Exec.ts +51 -0
- package/L.ts +24 -0
- package/LiminalAssertionError.ts +3 -0
- package/LiminalConfig.ts +7 -0
- package/Message.ts +94 -0
- package/Model.ts +26 -0
- package/PathLike.ts +17 -0
- package/Scope.ts +152 -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 +36 -0
- package/actions/actions_derived/declareModel.ts +9 -0
- package/actions/actions_derived/declareModel.type-test.ts +70 -0
- package/actions/actions_derived/messages.test.ts +88 -0
- package/actions/actions_derived/messages.ts +18 -0
- package/actions/actions_derived/metatype.ts +9 -0
- package/actions/actions_derived/readers_derived.ts +15 -0
- package/actions/appendMessage.ts +54 -0
- package/actions/await.ts +13 -0
- package/actions/branch.ts +106 -0
- package/actions/catch.ts +42 -0
- package/actions/declareArg.ts +14 -0
- package/actions/disableTool.ts +26 -0
- package/actions/embed.ts +29 -0
- package/actions/emit.ts +21 -0
- package/actions/enableTool.ts +75 -0
- package/actions/enableTool.type-test.ts +118 -0
- package/actions/infer.ts +49 -0
- package/actions/messages.ts +62 -0
- package/actions/pushModel.ts +52 -0
- package/actions/scope.ts +13 -0
- package/actions/section.ts +105 -0
- package/actions/throw.ts +18 -0
- package/cli/WriteHandler.ts +35 -0
- package/cli/cli_common.ts +4 -0
- package/cli/main.ts +24 -0
- package/cli/runExec.ts +72 -0
- package/dist/Action.d.ts +15 -0
- package/dist/Action.js +13 -0
- package/dist/Action.js.map +1 -0
- package/dist/Agent.d.ts +7 -0
- package/dist/Agent.js +2 -0
- package/dist/Agent.js.map +1 -0
- package/dist/Exec.d.ts +25 -0
- package/dist/Exec.js +19 -0
- package/dist/Exec.js.map +1 -0
- package/dist/L.d.ts +23 -0
- package/dist/L.js +24 -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 +21 -0
- package/dist/Model.js +2 -0
- package/dist/Model.js.map +1 -0
- package/dist/PathLike.d.ts +11 -0
- package/dist/PathLike.js +2 -0
- package/dist/PathLike.js.map +1 -0
- package/dist/Scope.d.ts +42 -0
- package/dist/Scope.js +93 -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 +35 -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/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/actions_derived/readers_derived.d.ts +6 -0
- package/dist/actions/actions_derived/readers_derived.js +14 -0
- package/dist/actions/actions_derived/readers_derived.js.map +1 -0
- package/dist/actions/appendMessage.d.ts +14 -0
- package/dist/actions/appendMessage.js +41 -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 +39 -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 +24 -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/infer.d.ts +15 -0
- package/dist/actions/infer.js +29 -0
- package/dist/actions/infer.js.map +1 -0
- package/dist/actions/messages.d.ts +24 -0
- package/dist/actions/messages.js +35 -0
- package/dist/actions/messages.js.map +1 -0
- package/dist/actions/pushModel.d.ts +15 -0
- package/dist/actions/pushModel.js +36 -0
- package/dist/actions/pushModel.js.map +1 -0
- package/dist/actions/scope.d.ts +7 -0
- package/dist/actions/scope.js +10 -0
- package/dist/actions/scope.js.map +1 -0
- package/dist/actions/section.d.ts +23 -0
- package/dist/actions/section.js +64 -0
- package/dist/actions/section.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 +4 -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 +20 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/runExec.d.ts +2 -0
- package/dist/cli/runExec.js +74 -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 +20 -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/SectionCleared.d.ts +5 -0
- package/dist/events/SectionCleared.js +2 -0
- package/dist/events/SectionCleared.js.map +1 -0
- package/dist/events/Sectioned.d.ts +5 -0
- package/dist/events/Sectioned.js +2 -0
- package/dist/events/Sectioned.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/AgentAssertions.d.ts +9 -0
- package/dist/testing/AgentAssertions.js +6 -0
- package/dist/testing/AgentAssertions.js.map +1 -0
- package/dist/testing/TestEmbeddingModel.d.ts +6 -0
- package/dist/testing/TestEmbeddingModel.js +11 -0
- package/dist/testing/TestEmbeddingModel.js.map +1 -0
- package/dist/testing/TestLanguageModel.d.ts +8 -0
- package/dist/testing/TestLanguageModel.js +22 -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 +31 -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/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/makeType.d.ts +2 -0
- package/dist/types/makeType.js +58 -0
- package/dist/types/makeType.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/peekLast.d.ts +1 -0
- package/dist/util/peekLast.js +4 -0
- package/dist/util/peekLast.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 +40 -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/SectionCleared.ts +6 -0
- package/events/Sectioned.ts +6 -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 +32 -9
- package/testing/AgentAssertions.ts +17 -0
- package/testing/TestEmbeddingModel.ts +19 -0
- package/testing/TestLanguageModel.ts +33 -0
- package/testing/index.ts +4 -0
- package/testing/takeFirstAction.ts +8 -0
- package/tsconfig.json +8 -0
- 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 +47 -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/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/makeType.ts +72 -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/peekLast.ts +3 -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/lib/index.js +0 -1
package/Action.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Scope } from "./Scope.ts"
|
|
2
|
+
import type { Spec } from "./Spec.ts"
|
|
3
|
+
import type { PromiseOr } from "./util/PromiseOr.ts"
|
|
4
|
+
|
|
5
|
+
export interface Action<K extends string = string, S extends Spec = Spec> {
|
|
6
|
+
"": S
|
|
7
|
+
type: K
|
|
8
|
+
[ActionKey]: true
|
|
9
|
+
trace: string
|
|
10
|
+
reducer(this: this, scope: Scope): PromiseOr<Scope>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ActionReducer<K extends string, S extends Spec> = (this: Action<K, S>, scope: Scope) => PromiseOr<Scope>
|
|
14
|
+
|
|
15
|
+
export function Action<K extends string, S extends Spec>(type: K, reducer: ActionReducer<K, S>): Action<K, S> {
|
|
16
|
+
return ({
|
|
17
|
+
type,
|
|
18
|
+
[ActionKey]: true,
|
|
19
|
+
trace: new Error().stack!,
|
|
20
|
+
reducer,
|
|
21
|
+
} satisfies Omit<Action<K, S>, "">) as never
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ActionKey = typeof ActionKey
|
|
25
|
+
export const ActionKey = Symbol("Liminal/Action")
|
|
26
|
+
|
|
27
|
+
export function isAction(value: unknown): value is Action {
|
|
28
|
+
return typeof value === "object" && value !== null && ActionKey in value
|
|
29
|
+
}
|
package/Agent.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Action } from "./Action.ts"
|
|
2
|
+
import type { DeferredOr } from "./util/DeferredOr.ts"
|
|
3
|
+
import type { IteratorLike } from "./util/IteratorLike.ts"
|
|
4
|
+
|
|
5
|
+
export type Agent<Y extends Action = Action, R = any> = IteratorLike<Y, R>
|
|
6
|
+
|
|
7
|
+
export type AgentLike<Y extends Action = Action, R = any> = DeferredOr<Agent<Y, R>>
|
|
8
|
+
|
|
9
|
+
export type AgentLikeY<A extends AgentLike> = A extends AgentLike<infer Y> ? Y : never
|
|
10
|
+
export type AgentLikeT<A extends AgentLike> = A extends AgentLike<Action, infer T> ? T : never
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# liminal
|
|
2
|
+
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- de74823: Various API changes, such as infer as a callable object (the object of which implements Symbol.iterator and yields the actual action). Introduced initial "section" action. Also created an adapter for Ollama.
|
|
8
|
+
|
|
9
|
+
## 0.5.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 96339de: Fixing continuous publishing. No other changes contained in this release.
|
|
14
|
+
|
|
15
|
+
## 0.1.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 171acfe: Initial publish of Liminal and the Vercel AI adapter library. Still heavily WIP.
|
|
20
|
+
More publishes to come!
|
package/Exec.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Action } from "./Action.ts"
|
|
2
|
+
import type { Agent } from "./Agent.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 { RootScope, type Scope } from "./Scope.ts"
|
|
7
|
+
import type { FromEntries } from "./util/FromEntries.ts"
|
|
8
|
+
import type { JSONKey } from "./util/JSONKey.ts"
|
|
9
|
+
|
|
10
|
+
export interface ExecConfig {
|
|
11
|
+
default: LanguageModel
|
|
12
|
+
args?: Record<JSONKey, any>
|
|
13
|
+
signal?: AbortSignal
|
|
14
|
+
handler?: EventHandler
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ExtractExecConfig<Y extends Action> =
|
|
18
|
+
& {
|
|
19
|
+
default: LanguageModel
|
|
20
|
+
signal?: AbortSignal
|
|
21
|
+
handler?: EventHandler<Extract<ExtractEventResolved<Y[""]> & {}, EventResolved>>
|
|
22
|
+
}
|
|
23
|
+
& (
|
|
24
|
+
[Y[""]["Entry"]] extends [never] ? {
|
|
25
|
+
args?: undefined
|
|
26
|
+
}
|
|
27
|
+
: {
|
|
28
|
+
args: FromEntries<Y[""]["Entry"]>
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
export async function exec<Y extends Action, T>(
|
|
33
|
+
createAgent: () => Agent<Y, T>,
|
|
34
|
+
config: ExtractExecConfig<Y>,
|
|
35
|
+
): Promise<T> {
|
|
36
|
+
let scope: Scope = RootScope(config as never)
|
|
37
|
+
scope = await scope.reduce(createAgent())
|
|
38
|
+
const { signal: { aborted, reason } } = scope.controller
|
|
39
|
+
if (aborted) {
|
|
40
|
+
scope.event({
|
|
41
|
+
type: "aborted",
|
|
42
|
+
reason,
|
|
43
|
+
})
|
|
44
|
+
throw reason
|
|
45
|
+
}
|
|
46
|
+
scope.event({
|
|
47
|
+
type: "returned",
|
|
48
|
+
value: scope.value,
|
|
49
|
+
})
|
|
50
|
+
return scope.value
|
|
51
|
+
}
|
package/L.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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/messages.ts"
|
|
6
|
+
export * from "./actions/actions_derived/readers_derived.ts"
|
|
7
|
+
export * from "./actions/appendMessage.ts"
|
|
8
|
+
export * from "./actions/await.ts"
|
|
9
|
+
export * from "./actions/branch.ts"
|
|
10
|
+
export * from "./actions/catch.ts"
|
|
11
|
+
export * from "./actions/declareArg.ts"
|
|
12
|
+
export * from "./actions/disableTool.ts"
|
|
13
|
+
export * from "./actions/embed.ts"
|
|
14
|
+
export * from "./actions/emit.ts"
|
|
15
|
+
export * from "./actions/enableTool.ts"
|
|
16
|
+
export * from "./actions/infer.ts"
|
|
17
|
+
export * from "./actions/messages.ts"
|
|
18
|
+
export * from "./actions/pushModel.ts"
|
|
19
|
+
export * from "./actions/scope.ts"
|
|
20
|
+
export * from "./actions/section.ts"
|
|
21
|
+
export * from "./actions/throw.ts"
|
|
22
|
+
export * from "./types/factories.ts"
|
|
23
|
+
|
|
24
|
+
export * from "./actions/actions_derived/metatype.ts"
|
package/LiminalConfig.ts
ADDED
package/Message.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export type Message = Messages[keyof Messages]
|
|
2
|
+
export type Messages = {
|
|
3
|
+
system: SystemMessage
|
|
4
|
+
user: UserMessage
|
|
5
|
+
assistant: AssistantMessage
|
|
6
|
+
tool: ToolMessage
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SystemMessage extends MessageBase<"system"> {}
|
|
10
|
+
export interface UserMessage extends MessageBase<"user"> {}
|
|
11
|
+
export interface AssistantMessage extends MessageBase<"assistant"> {}
|
|
12
|
+
export interface ToolMessage extends MessageBase<"tool"> {}
|
|
13
|
+
|
|
14
|
+
interface MessageBase<R extends MessageRole> {
|
|
15
|
+
readonly role: R
|
|
16
|
+
readonly content: MessageContents[R]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type MessageRole = "system" | "user" | "assistant" | "tool"
|
|
20
|
+
|
|
21
|
+
export type MessageContents = {
|
|
22
|
+
system: string
|
|
23
|
+
user: UserContent
|
|
24
|
+
assistant: AssistantContent
|
|
25
|
+
tool: ToolContent
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type AssistantContent =
|
|
29
|
+
| string
|
|
30
|
+
| ReadonlyArray<TextPart | FilePart | ReasoningPart | RedactedReasoningPart | ToolCallPart>
|
|
31
|
+
|
|
32
|
+
export type UserContent = string | Array<TextPart | ImagePart | FilePart>
|
|
33
|
+
|
|
34
|
+
export type ToolContent = Array<ToolContentPart>
|
|
35
|
+
export interface ToolContentPart {
|
|
36
|
+
readonly type: "tool-result"
|
|
37
|
+
readonly toolCallId: string
|
|
38
|
+
readonly toolName: string
|
|
39
|
+
readonly result: unknown
|
|
40
|
+
readonly isError?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TextPart {
|
|
44
|
+
readonly type: "text"
|
|
45
|
+
readonly text: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// TODO: URL?
|
|
49
|
+
export type DataContent = string | Uint8Array | ArrayBuffer | Buffer
|
|
50
|
+
|
|
51
|
+
export interface FilePart {
|
|
52
|
+
type: "file"
|
|
53
|
+
/**
|
|
54
|
+
* File data. Can either be:
|
|
55
|
+
*
|
|
56
|
+
* - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
|
57
|
+
* - URL: a URL that points to the image
|
|
58
|
+
*/
|
|
59
|
+
readonly data: DataContent | URL
|
|
60
|
+
/** Optional filename of the file. */
|
|
61
|
+
readonly filename?: string
|
|
62
|
+
/** Mime type of the file. */
|
|
63
|
+
readonly mimeType: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ReasoningPart {
|
|
67
|
+
readonly type: "reasoning"
|
|
68
|
+
/** The reasoning text. */
|
|
69
|
+
readonly text: string
|
|
70
|
+
/** An optional signature for verifying that the reasoning originated from the model. */
|
|
71
|
+
readonly signature?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface RedactedReasoningPart {
|
|
75
|
+
readonly type: "redacted-reasoning"
|
|
76
|
+
/** Redacted reasoning data. */
|
|
77
|
+
readonly data: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ToolCallPart {
|
|
81
|
+
readonly type: "tool-call"
|
|
82
|
+
/** ID of the tool call. This ID is used to match the tool call with the tool result. */
|
|
83
|
+
readonly toolCallId: string
|
|
84
|
+
/** Name of the tool that is being called. */
|
|
85
|
+
readonly toolName: string
|
|
86
|
+
/** Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. */
|
|
87
|
+
readonly args: unknown
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ImagePart {
|
|
91
|
+
readonly type: "image"
|
|
92
|
+
readonly image: DataContent | URL
|
|
93
|
+
readonly mimeType?: string
|
|
94
|
+
}
|
package/Model.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
+
import type { Action } from "./Action.ts"
|
|
3
|
+
import type { Agent } from "./Agent.ts"
|
|
4
|
+
import type { JSONObject } from "./util/JSONObject.ts"
|
|
5
|
+
|
|
6
|
+
export type Model = LanguageModel | EmbeddingModel
|
|
7
|
+
|
|
8
|
+
export interface LanguageModel extends ModelBase<"language"> {
|
|
9
|
+
infer: (type: StandardSchemaV1<JSONObject, any> | undefined) => Agent<Action, any>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface EmbeddingModel extends ModelBase<"embedding"> {
|
|
13
|
+
embed: (value: string) => Promise<Array<number>>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ModelBase<K extends ModelType> {
|
|
17
|
+
type: K
|
|
18
|
+
vendor: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ModelType = "language" | "embedding"
|
|
22
|
+
|
|
23
|
+
export type Models = {
|
|
24
|
+
language: LanguageModel
|
|
25
|
+
embedding: EmbeddingModel
|
|
26
|
+
}
|
package/PathLike.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { _ } from "./_.ts"
|
|
2
|
+
import type { JSONKey } from "./util/JSONKey.ts"
|
|
3
|
+
|
|
4
|
+
export type Path = Array<JSONKey>
|
|
5
|
+
export declare namespace Path {
|
|
6
|
+
export type FromPathLike<P extends PathLike> = P extends [infer E0 extends KeyLike, ...infer ERest extends PathLike]
|
|
7
|
+
? [E0 extends JSONKey ? E0 : JSONKey, ...FromPathLike<ERest>]
|
|
8
|
+
: []
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type KeyLike = JSONKey | _
|
|
12
|
+
export type PathLike = Array<KeyLike>
|
|
13
|
+
export declare namespace PathLike {
|
|
14
|
+
export type FromPath<P extends Path> = P extends [infer E0, ...infer ERest extends Path]
|
|
15
|
+
? [E0 | _, ...FromPath<ERest>]
|
|
16
|
+
: []
|
|
17
|
+
}
|
package/Scope.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { Action } from "./Action.ts"
|
|
2
|
+
import type { Agent } from "./Agent.ts"
|
|
3
|
+
import type { EventHandler } from "./events/EventHandler.ts"
|
|
4
|
+
import type { LEvent } from "./events/LEvent.ts"
|
|
5
|
+
import type { ExecConfig } from "./Exec.ts"
|
|
6
|
+
import type { Message } from "./Message.ts"
|
|
7
|
+
import type { EmbeddingModel, LanguageModel } from "./Model.ts"
|
|
8
|
+
import type { Tool } from "./Tool.ts"
|
|
9
|
+
import type { JSONKey } from "./util/JSONKey.ts"
|
|
10
|
+
|
|
11
|
+
export type Scope = RootScope | ChildScope
|
|
12
|
+
|
|
13
|
+
export interface RootScope extends ScopeBase<RootScopeType> {}
|
|
14
|
+
export interface ChildScope extends ScopeBase<ChildScopeType> {
|
|
15
|
+
readonly parent: Scope
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type RootScopeType = "root"
|
|
19
|
+
export type ChildScopeType = "catch" | "tool" | "branch" | "branch_arm" | "set_messages" | "run_section"
|
|
20
|
+
export type ScopeType = RootScopeType | ChildScopeType
|
|
21
|
+
|
|
22
|
+
export interface ScopeBase<Type extends ScopeType> {
|
|
23
|
+
readonly type: Type
|
|
24
|
+
readonly path: Array<JSONKey>
|
|
25
|
+
readonly args?: Record<JSONKey, any>
|
|
26
|
+
readonly controller: AbortController
|
|
27
|
+
readonly messages: Set<Message>
|
|
28
|
+
readonly tools: Set<Tool>
|
|
29
|
+
readonly nextArg?: any
|
|
30
|
+
readonly value: any
|
|
31
|
+
readonly thrown?: any
|
|
32
|
+
readonly languageModels: Set<LanguageModel>
|
|
33
|
+
readonly embeddingModels: Set<EmbeddingModel>
|
|
34
|
+
readonly handler?: EventHandler
|
|
35
|
+
readonly childForkCounts: Record<JSONKey, number>
|
|
36
|
+
readonly index: number
|
|
37
|
+
readonly sections: Set<Section>
|
|
38
|
+
|
|
39
|
+
reduce(agent: Agent): Promise<Scope>
|
|
40
|
+
fork(
|
|
41
|
+
source: ChildScopeType,
|
|
42
|
+
subpath: Array<JSONKey>,
|
|
43
|
+
overrides?: Partial<ChildScope>,
|
|
44
|
+
): Scope
|
|
45
|
+
event(event: LEvent): void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Section {
|
|
49
|
+
sectionKey: JSONKey
|
|
50
|
+
messages: Set<Message>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function RootScope({
|
|
54
|
+
signal,
|
|
55
|
+
args,
|
|
56
|
+
handler,
|
|
57
|
+
default: defaultLanguageModel,
|
|
58
|
+
}: ExecConfig): RootScope {
|
|
59
|
+
const controller = new AbortController()
|
|
60
|
+
signal?.addEventListener("abort", () => {
|
|
61
|
+
controller.abort()
|
|
62
|
+
})
|
|
63
|
+
return {
|
|
64
|
+
type: "root",
|
|
65
|
+
args,
|
|
66
|
+
controller,
|
|
67
|
+
messages: new Set(),
|
|
68
|
+
tools: new Set(),
|
|
69
|
+
value: undefined,
|
|
70
|
+
path: [],
|
|
71
|
+
languageModels: new Set([defaultLanguageModel]),
|
|
72
|
+
embeddingModels: new Set(),
|
|
73
|
+
childForkCounts: {},
|
|
74
|
+
sections: new Set(),
|
|
75
|
+
index: 0,
|
|
76
|
+
reduce,
|
|
77
|
+
fork,
|
|
78
|
+
handler,
|
|
79
|
+
event,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function reduce(this: Scope, agent: Agent): Promise<Scope> {
|
|
84
|
+
const { signal } = this.controller
|
|
85
|
+
let scope = { ...this }
|
|
86
|
+
if (signal.aborted) return scope
|
|
87
|
+
let value: unknown
|
|
88
|
+
try {
|
|
89
|
+
let current = await agent.next()
|
|
90
|
+
while (!current.done) {
|
|
91
|
+
const { value } = current
|
|
92
|
+
if (signal.aborted) return scope
|
|
93
|
+
scope = await (value as Action).reducer(scope)
|
|
94
|
+
if (signal.aborted) return scope
|
|
95
|
+
current = await agent.next(scope.nextArg)
|
|
96
|
+
}
|
|
97
|
+
value = current.value
|
|
98
|
+
} catch (thrown: unknown) {
|
|
99
|
+
scope.controller.abort(thrown)
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...scope,
|
|
103
|
+
value,
|
|
104
|
+
nextArg: undefined,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function fork(
|
|
109
|
+
this: Scope,
|
|
110
|
+
type: ChildScopeType,
|
|
111
|
+
subpath: Array<JSONKey>,
|
|
112
|
+
overrides?: Partial<ChildScope>,
|
|
113
|
+
): ChildScope {
|
|
114
|
+
const subpathStr = subpath.join(" ")
|
|
115
|
+
let index = this.childForkCounts[subpathStr]
|
|
116
|
+
if (typeof index === "number") {
|
|
117
|
+
this.childForkCounts[subpathStr]! += 1
|
|
118
|
+
} else {
|
|
119
|
+
index = 0
|
|
120
|
+
this.childForkCounts[subpathStr] = 1
|
|
121
|
+
}
|
|
122
|
+
const f: ChildScope = {
|
|
123
|
+
type,
|
|
124
|
+
controller: this.controller,
|
|
125
|
+
args: this.args,
|
|
126
|
+
messages: new Set(this.messages),
|
|
127
|
+
tools: new Set(),
|
|
128
|
+
languageModels: new Set(this.languageModels),
|
|
129
|
+
embeddingModels: new Set(this.embeddingModels),
|
|
130
|
+
childForkCounts: {},
|
|
131
|
+
handler: this.handler,
|
|
132
|
+
path: [...this.path, ...subpath],
|
|
133
|
+
parent: this,
|
|
134
|
+
value: undefined,
|
|
135
|
+
index,
|
|
136
|
+
sections: new Set(this.sections),
|
|
137
|
+
reduce,
|
|
138
|
+
fork,
|
|
139
|
+
event,
|
|
140
|
+
...overrides ?? {},
|
|
141
|
+
}
|
|
142
|
+
f.event({ type: "forked" })
|
|
143
|
+
return f
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function event(this: ChildScope, event: LEvent): void {
|
|
147
|
+
this.handler?.({
|
|
148
|
+
scope: this.path,
|
|
149
|
+
index: this.index,
|
|
150
|
+
...event,
|
|
151
|
+
})
|
|
152
|
+
}
|
package/Spec.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { LEvent } from "./events/LEvent.ts"
|
|
2
|
+
import type { Expand } from "./util/Expand.ts"
|
|
3
|
+
import type { JSONEntry } from "./util/JSONEntry.ts"
|
|
4
|
+
import type { JSONKey } from "./util/JSONKey.ts"
|
|
5
|
+
|
|
6
|
+
export interface Spec<
|
|
7
|
+
Key extends JSONKey = JSONKey,
|
|
8
|
+
Event extends LEvent = LEvent,
|
|
9
|
+
Spec_ extends Spec = any,
|
|
10
|
+
Entry_ extends JSONEntry = JSONEntry,
|
|
11
|
+
Throw = any,
|
|
12
|
+
Value = any,
|
|
13
|
+
> {
|
|
14
|
+
Event: Event
|
|
15
|
+
Child: [Key, Spec_]
|
|
16
|
+
Entry: Entry_
|
|
17
|
+
Throw: Throw
|
|
18
|
+
Value: Value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export declare namespace Spec {
|
|
22
|
+
export type Make<P extends Partial<Spec>> = Expand<{
|
|
23
|
+
Event: [unknown] extends [P["Event"]] ? never : P["Event"]
|
|
24
|
+
Child: [unknown] extends [P["Child"]] ? never : P["Child"]
|
|
25
|
+
Throw: [unknown] extends [P["Throw"]] ? never : P["Throw"]
|
|
26
|
+
Entry: [unknown] extends [P["Entry"]] ? never : P["Entry"]
|
|
27
|
+
Value: [unknown] extends [P["Value"]] ? never : P["Value"]
|
|
28
|
+
}>
|
|
29
|
+
}
|
package/Tool.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
+
import type { Action } from "./Action.ts"
|
|
3
|
+
import type { Agent } from "./Agent.ts"
|
|
4
|
+
import type { Scope } from "./Scope.ts"
|
|
5
|
+
import { assert } from "./util/assert.ts"
|
|
6
|
+
import { isJSONValue } from "./util/isJSONValue.ts"
|
|
7
|
+
import type { JSONKey } from "./util/JSONKey.ts"
|
|
8
|
+
import type { JSONObject } from "./util/JSONObject.ts"
|
|
9
|
+
import type { JSONValue } from "./util/JSONValue.ts"
|
|
10
|
+
import type { PromiseOr } from "./util/PromiseOr.ts"
|
|
11
|
+
|
|
12
|
+
export interface ToolConfig<K extends JSONKey = JSONKey> {
|
|
13
|
+
toolKey: K
|
|
14
|
+
description: string
|
|
15
|
+
params: StandardSchemaV1<JSONObject, any>
|
|
16
|
+
implementation: ToolImplementation
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Tool<K extends JSONKey = JSONKey> extends ToolConfig<K> {
|
|
20
|
+
executor: (scope: Scope) => ToolExecutor
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Tool<K extends JSONKey>(config: ToolConfig<K>): Tool<K> {
|
|
24
|
+
return {
|
|
25
|
+
...config,
|
|
26
|
+
executor,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ToolImplementation = (params: any) => Agent<Action, ToolResult> | PromiseOr<ToolResult>
|
|
31
|
+
|
|
32
|
+
export type ToolExecutor = (args: any) => Promise<JSONValue>
|
|
33
|
+
|
|
34
|
+
export type ToolResult = JSONValue | void
|
|
35
|
+
|
|
36
|
+
function executor(this: Tool, scope: Scope): ToolExecutor {
|
|
37
|
+
return async (args) => {
|
|
38
|
+
scope.event({
|
|
39
|
+
type: "tool_called",
|
|
40
|
+
args,
|
|
41
|
+
tool: this.toolKey,
|
|
42
|
+
})
|
|
43
|
+
const parsed = await this.params["~standard"].validate(args)
|
|
44
|
+
assert(!parsed.issues)
|
|
45
|
+
const { value: transformed } = parsed
|
|
46
|
+
const initial = await this.implementation(transformed)
|
|
47
|
+
if (isJSONValue(initial)) {
|
|
48
|
+
return { value: initial }
|
|
49
|
+
}
|
|
50
|
+
const fork = scope.fork("tool", [this.toolKey])
|
|
51
|
+
const { value } = await fork.reduce(initial as Agent)
|
|
52
|
+
fork.event({
|
|
53
|
+
type: "returned",
|
|
54
|
+
value,
|
|
55
|
+
})
|
|
56
|
+
return { value }
|
|
57
|
+
}
|
|
58
|
+
}
|
package/_.ts
ADDED
package/actions/abort.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Aborted } from "../events/Aborted.ts"
|
|
3
|
+
import type { Spec } from "../Spec.ts"
|
|
4
|
+
import type { EnsureNarrow } from "../util/EnsureNarrow.ts"
|
|
5
|
+
|
|
6
|
+
export interface abort<V> extends Action<"abort", Spec.Make<{ Event: Aborted<V> }>> {}
|
|
7
|
+
|
|
8
|
+
export function* abort<V>(reason: V, ...[_error]: EnsureNarrow<V>): Generator<
|
|
9
|
+
abort<V>,
|
|
10
|
+
never
|
|
11
|
+
> {
|
|
12
|
+
return (yield (Action("abort", (scope) => {
|
|
13
|
+
scope.event({
|
|
14
|
+
type: "aborted",
|
|
15
|
+
reason,
|
|
16
|
+
})
|
|
17
|
+
scope.controller.abort(reason)
|
|
18
|
+
return {
|
|
19
|
+
...scope,
|
|
20
|
+
nextArg: undefined,
|
|
21
|
+
}
|
|
22
|
+
}))) as never
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EmbeddingModel, LanguageModel, Model } from "../../Model.ts"
|
|
2
|
+
import type { Scope } from "../../Scope.ts"
|
|
3
|
+
import { unreachable } from "../../util/unreachable.ts"
|
|
4
|
+
|
|
5
|
+
export function applyToModels<M extends Model>(
|
|
6
|
+
scope: Scope,
|
|
7
|
+
model: M,
|
|
8
|
+
f: (initial: Set<M>) => Set<M>,
|
|
9
|
+
): Pick<Scope, "languageModels" | "embeddingModels"> {
|
|
10
|
+
const initial: Set<M> = (model.type === "language" ? scope.languageModels : scope.embeddingModels) as never
|
|
11
|
+
const models = f(new Set(initial))
|
|
12
|
+
return model.type === "language"
|
|
13
|
+
? {
|
|
14
|
+
languageModels: models as Set<LanguageModel>,
|
|
15
|
+
embeddingModels: scope.embeddingModels,
|
|
16
|
+
}
|
|
17
|
+
: model.type === "embedding"
|
|
18
|
+
? {
|
|
19
|
+
languageModels: scope.languageModels,
|
|
20
|
+
embeddingModels: models as Set<EmbeddingModel>,
|
|
21
|
+
}
|
|
22
|
+
: unreachable()
|
|
23
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Model generates the expected event sequence 1`] = `
|
|
4
|
+
"[
|
|
5
|
+
{
|
|
6
|
+
"scope": [],
|
|
7
|
+
"index": 0,
|
|
8
|
+
"type": "model_pushed",
|
|
9
|
+
"modelKey": "secondary",
|
|
10
|
+
"modelType": "language"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"scope": [
|
|
14
|
+
"fork-key"
|
|
15
|
+
],
|
|
16
|
+
"index": 0,
|
|
17
|
+
"type": "forked"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"scope": [
|
|
21
|
+
"fork-key"
|
|
22
|
+
],
|
|
23
|
+
"index": 0,
|
|
24
|
+
"type": "model_pushed",
|
|
25
|
+
"modelKey": "child_a",
|
|
26
|
+
"modelType": "language"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"scope": [
|
|
30
|
+
"fork-key"
|
|
31
|
+
],
|
|
32
|
+
"index": 0,
|
|
33
|
+
"type": "model_pushed",
|
|
34
|
+
"modelKey": "child_b",
|
|
35
|
+
"modelType": "embedding"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"scope": [
|
|
39
|
+
"fork-key"
|
|
40
|
+
],
|
|
41
|
+
"index": 0,
|
|
42
|
+
"type": "model_removed",
|
|
43
|
+
"modelKey": "child_a",
|
|
44
|
+
"modelType": "language"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"scope": [
|
|
48
|
+
"fork-key"
|
|
49
|
+
],
|
|
50
|
+
"index": 0,
|
|
51
|
+
"type": "model_removed",
|
|
52
|
+
"modelKey": "child_b",
|
|
53
|
+
"modelType": "embedding"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"scope": [
|
|
57
|
+
"fork-key"
|
|
58
|
+
],
|
|
59
|
+
"index": 0,
|
|
60
|
+
"type": "returned"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"scope": [],
|
|
64
|
+
"index": 0,
|
|
65
|
+
"type": "model_pushed",
|
|
66
|
+
"modelKey": "tertiary",
|
|
67
|
+
"modelType": "embedding"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"scope": [],
|
|
71
|
+
"index": 0,
|
|
72
|
+
"type": "model_removed",
|
|
73
|
+
"modelKey": "secondary",
|
|
74
|
+
"modelType": "language"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"scope": [],
|
|
78
|
+
"index": 0,
|
|
79
|
+
"type": "model_removed",
|
|
80
|
+
"modelKey": "tertiary",
|
|
81
|
+
"modelType": "embedding"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"scope": [],
|
|
85
|
+
"index": 0,
|
|
86
|
+
"type": "returned"
|
|
87
|
+
}
|
|
88
|
+
]"
|
|
89
|
+
`;
|