liminal 0.5.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/Agent.ts +10 -0
- package/CHANGELOG.md +6 -0
- package/Exec.ts +19 -31
- package/L.ts +4 -7
- package/LiminalConfig.ts +1 -1
- package/Model.ts +8 -2
- package/PathLike.ts +8 -10
- package/Scope.ts +33 -14
- package/Tool.ts +3 -3
- package/actions/actions_derived/clear.ts +2 -2
- package/actions/actions_derived/declareModel.test.ts +10 -7
- package/actions/actions_derived/declareModel.ts +3 -3
- package/actions/actions_derived/messages.ts +0 -1
- package/actions/actions_derived/readers_derived.ts +15 -0
- package/actions/appendMessage.ts +27 -3
- package/actions/branch.ts +31 -33
- package/actions/catch.ts +3 -3
- package/actions/embed.ts +2 -1
- package/actions/enableTool.ts +2 -2
- package/actions/enableTool.type-test.ts +7 -7
- package/actions/infer.ts +15 -3
- package/actions/messages.ts +62 -0
- package/actions/pushModel.ts +22 -2
- package/actions/scope.ts +13 -0
- package/actions/section.ts +105 -0
- package/cli/cli_common.ts +1 -0
- package/cli/main.ts +6 -1
- package/cli/runExec.ts +20 -16
- 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 +5 -7
- package/dist/Exec.js +14 -17
- package/dist/Exec.js.map +1 -1
- package/dist/L.d.ts +4 -7
- package/dist/L.js +4 -7
- package/dist/L.js.map +1 -1
- package/dist/LiminalConfig.d.ts +1 -1
- package/dist/Model.d.ts +7 -2
- package/dist/PathLike.d.ts +4 -7
- package/dist/Scope.d.ts +11 -5
- package/dist/Scope.js +8 -5
- package/dist/Scope.js.map +1 -1
- package/dist/Tool.d.ts +2 -2
- package/dist/actions/actions_derived/clear.js +2 -2
- package/dist/actions/actions_derived/clear.js.map +1 -1
- package/dist/actions/actions_derived/declareModel.d.ts +2 -2
- package/dist/actions/actions_derived/declareModel.js +1 -1
- package/dist/actions/actions_derived/declareModel.js.map +1 -1
- package/dist/actions/actions_derived/declareModel.test.js +10 -7
- package/dist/actions/actions_derived/declareModel.test.js.map +1 -1
- package/dist/actions/actions_derived/messages.d.ts +3 -3
- package/dist/actions/actions_derived/messages.js.map +1 -1
- 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 +6 -2
- package/dist/actions/appendMessage.js +23 -2
- package/dist/actions/appendMessage.js.map +1 -1
- package/dist/actions/branch.d.ts +18 -14
- package/dist/actions/branch.js +10 -10
- package/dist/actions/branch.js.map +1 -1
- package/dist/actions/catch.d.ts +2 -2
- package/dist/actions/catch.js +2 -2
- package/dist/actions/embed.js +2 -1
- package/dist/actions/embed.js.map +1 -1
- package/dist/actions/enableTool.d.ts +2 -2
- package/dist/actions/enableTool.type-test.js +5 -5
- package/dist/actions/infer.d.ts +3 -1
- package/dist/actions/infer.js +11 -3
- package/dist/actions/infer.js.map +1 -1
- package/dist/actions/messages.d.ts +24 -0
- package/dist/actions/{setMessages.js → messages.js} +14 -10
- package/dist/actions/messages.js.map +1 -0
- package/dist/actions/pushModel.d.ts +5 -1
- package/dist/actions/pushModel.js +17 -2
- package/dist/actions/pushModel.js.map +1 -1
- package/dist/actions/{getScope.d.ts → scope.d.ts} +3 -1
- 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/cli/cli_common.d.ts +1 -0
- package/dist/cli/main.js +6 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/runExec.js +21 -16
- package/dist/cli/runExec.js.map +1 -1
- package/dist/events/LEvent.d.ts +3 -1
- 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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/testing/{ActorAssertions.d.ts → AgentAssertions.d.ts} +3 -3
- package/dist/testing/AgentAssertions.js +6 -0
- package/dist/testing/AgentAssertions.js.map +1 -0
- package/dist/testing/TestEmbeddingModel.js +1 -0
- package/dist/testing/TestEmbeddingModel.js.map +1 -1
- package/dist/testing/TestLanguageModel.js +1 -0
- package/dist/testing/TestLanguageModel.js.map +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/takeFirstAction.d.ts +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Type.d.ts +1 -0
- package/dist/types/Type.js.map +1 -1
- package/dist/types/array.js +2 -2
- package/dist/types/array.js.map +1 -1
- package/dist/types/boolean.js +2 -2
- package/dist/types/boolean.js.map +1 -1
- package/dist/types/const.js +2 -2
- package/dist/types/const.js.map +1 -1
- package/dist/types/enum.js +2 -2
- package/dist/types/enum.js.map +1 -1
- package/dist/types/integer.js +2 -2
- package/dist/types/integer.js.map +1 -1
- package/dist/types/makeType.d.ts +2 -0
- package/dist/types/{declareType.js → makeType.js} +4 -3
- package/dist/types/makeType.js.map +1 -0
- package/dist/types/null.js +2 -2
- package/dist/types/null.js.map +1 -1
- package/dist/types/number.js +2 -2
- package/dist/types/number.js.map +1 -1
- package/dist/types/object.js +2 -2
- package/dist/types/object.js.map +1 -1
- package/dist/types/ref.js +2 -2
- package/dist/types/ref.js.map +1 -1
- package/dist/types/string.js +2 -2
- package/dist/types/string.js.map +1 -1
- package/dist/types/union.js +2 -2
- package/dist/types/union.js.map +1 -1
- package/dist/util/peekLast.d.ts +1 -0
- package/dist/util/peekLast.js +4 -0
- package/dist/util/peekLast.js.map +1 -0
- package/events/LEvent.ts +4 -0
- package/events/SectionCleared.ts +6 -0
- package/events/Sectioned.ts +6 -0
- package/index.ts +1 -1
- package/package.json +1 -1
- package/testing/{ActorAssertions.ts → AgentAssertions.ts} +3 -5
- package/testing/TestEmbeddingModel.ts +1 -0
- package/testing/TestLanguageModel.ts +1 -0
- package/testing/index.ts +1 -1
- package/testing/takeFirstAction.ts +2 -2
- package/types/Type.ts +1 -0
- package/types/array.ts +2 -2
- package/types/boolean.ts +2 -2
- package/types/const.ts +2 -2
- package/types/enum.ts +2 -2
- package/types/integer.ts +2 -2
- package/types/{declareType.ts → makeType.ts} +3 -2
- package/types/null.ts +2 -2
- package/types/number.ts +2 -2
- package/types/object.ts +2 -2
- package/types/ref.ts +2 -2
- package/types/string.ts +2 -2
- package/types/union.ts +2 -2
- package/util/peekLast.ts +3 -0
- package/Actor.ts +0 -20
- package/actions/actions_derived/getMessages.ts +0 -9
- package/actions/getScope.ts +0 -11
- package/actions/getSignal.ts +0 -10
- package/actions/getTools.ts +0 -11
- package/actions/removeMessage.ts +0 -22
- package/actions/removeModel.ts +0 -31
- package/actions/setMessages.ts +0 -66
- package/dist/Actor.d.ts +0 -14
- package/dist/Actor.js +0 -2
- package/dist/Actor.js.map +0 -1
- package/dist/actions/actions_derived/getMessages.d.ts +0 -3
- package/dist/actions/actions_derived/getMessages.js +0 -8
- package/dist/actions/actions_derived/getMessages.js.map +0 -1
- package/dist/actions/getScope.js +0 -8
- package/dist/actions/getScope.js.map +0 -1
- package/dist/actions/getSignal.d.ts +0 -4
- package/dist/actions/getSignal.js +0 -8
- package/dist/actions/getSignal.js.map +0 -1
- package/dist/actions/getTools.d.ts +0 -5
- package/dist/actions/getTools.js +0 -8
- package/dist/actions/getTools.js.map +0 -1
- package/dist/actions/removeMessage.d.ts +0 -9
- package/dist/actions/removeMessage.js +0 -17
- package/dist/actions/removeMessage.js.map +0 -1
- package/dist/actions/removeModel.d.ts +0 -10
- package/dist/actions/removeModel.js +0 -20
- package/dist/actions/removeModel.js.map +0 -1
- package/dist/actions/setMessages.d.ts +0 -16
- package/dist/actions/setMessages.js.map +0 -1
- package/dist/testing/ActorAssertions.js +0 -6
- package/dist/testing/ActorAssertions.js.map +0 -1
- package/dist/types/declareType.d.ts +0 -2
- package/dist/types/declareType.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { AssertTrue, IsExact } from "conditional-type-checks"
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentLike } from "../Agent.ts"
|
|
3
3
|
import type { Emitted } from "../events/Emitted.ts"
|
|
4
4
|
import type { ToolCalled } from "../events/ToolCalled.ts"
|
|
5
5
|
import type { ToolDisabled } from "../events/ToolDisabled.ts"
|
|
6
6
|
import type { ToolEnabled } from "../events/ToolEnabled.ts"
|
|
7
7
|
import * as L from "../L.ts"
|
|
8
|
-
import {
|
|
8
|
+
import { AgentAssertions } from "../testing/AgentAssertions.ts"
|
|
9
9
|
import { emit } from "./emit.ts"
|
|
10
10
|
import { enableTool } from "./enableTool.ts"
|
|
11
11
|
|
|
@@ -19,7 +19,7 @@ const arrowTool = L.enableTool("Tool", "", P, (params) => {
|
|
|
19
19
|
type _ = [AssertTrue<IsExact<typeof params, P>>]
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
AgentAssertions(arrowTool).assertSpec<{
|
|
23
23
|
Event:
|
|
24
24
|
| ToolEnabled<"Tool">
|
|
25
25
|
| ToolCalled<"Tool", {
|
|
@@ -34,7 +34,7 @@ ActorAssertions(arrowTool).assertSpec<{
|
|
|
34
34
|
|
|
35
35
|
function* _0() {
|
|
36
36
|
const detach = yield* arrowTool
|
|
37
|
-
|
|
37
|
+
AgentAssertions(detach).assertSpec<{
|
|
38
38
|
Event: ToolDisabled<"Tool">
|
|
39
39
|
Child: never
|
|
40
40
|
Throw: never
|
|
@@ -49,7 +49,7 @@ const genTool = enableTool("tool-key", "", P, function*(params) {
|
|
|
49
49
|
return ""
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
AgentAssertions(genTool).assertSpec<{
|
|
53
53
|
Event:
|
|
54
54
|
| ToolEnabled<"tool-key">
|
|
55
55
|
| ToolCalled<"tool-key", {
|
|
@@ -77,9 +77,9 @@ function* parent() {
|
|
|
77
77
|
})
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
type g = typeof parent extends
|
|
80
|
+
type g = typeof parent extends AgentLike<infer Y> ? Y[""] : never
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
AgentAssertions(parent).assertSpec<
|
|
83
83
|
{
|
|
84
84
|
Event:
|
|
85
85
|
| ToolEnabled<"parent-tool">
|
package/actions/infer.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { Inferred } from "../events/Inferred.ts"
|
|
|
5
5
|
import type { Spec } from "../Spec.ts"
|
|
6
6
|
import type { JSONObject } from "../util/JSONObject.ts"
|
|
7
7
|
import type { JSONValue } from "../util/JSONValue.ts"
|
|
8
|
+
import { peekLast } from "../util/peekLast.ts"
|
|
8
9
|
|
|
9
10
|
export { infer_ as infer }
|
|
10
11
|
|
|
@@ -17,12 +18,24 @@ interface infer_<_T> extends
|
|
|
17
18
|
>
|
|
18
19
|
{}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
const infer_ = Object.assign(
|
|
22
|
+
function* infer_<T extends JSONValue>(type: StandardSchemaV1<JSONObject, T>): Generator<infer_<T>, T> {
|
|
23
|
+
return yield* impl(type)
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
*[Symbol.iterator](): Iterator<infer_<string>, string> {
|
|
27
|
+
return yield* impl()
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
)
|
|
31
|
+
Object.defineProperty(infer_, "name", { value: "infer" })
|
|
32
|
+
|
|
33
|
+
function* impl(type?: StandardSchemaV1<JSONObject, any>): Generator<infer_<any>, any> {
|
|
21
34
|
return yield Action("infer", async (scope) => {
|
|
22
35
|
scope.event({
|
|
23
36
|
type: "inference_requested",
|
|
24
37
|
})
|
|
25
|
-
const model = scope.languageModels
|
|
38
|
+
const model = peekLast(scope.languageModels)!
|
|
26
39
|
scope = await scope.reduce(model.infer(type))
|
|
27
40
|
scope.event({
|
|
28
41
|
type: "inferred",
|
|
@@ -34,4 +47,3 @@ function* infer_<T extends JSONValue = string>(type?: StandardSchemaV1<JSONObjec
|
|
|
34
47
|
}
|
|
35
48
|
})
|
|
36
49
|
}
|
|
37
|
-
Object.defineProperty(infer_, "name", { value: "infer" })
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Agent } from "../Agent.ts"
|
|
3
|
+
import type { MessagesSet } from "../events/MessagesSet.ts"
|
|
4
|
+
import type { Message } from "../Message.ts"
|
|
5
|
+
import type { Spec } from "../Spec.ts"
|
|
6
|
+
import { isPropertyKey } from "../util/isPropertyKey.ts"
|
|
7
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
8
|
+
import type { PromiseOr } from "../util/PromiseOr.ts"
|
|
9
|
+
import { type getScope, scope } from "./scope.ts"
|
|
10
|
+
|
|
11
|
+
interface messages extends Iterable<getScope, Set<Message>> {
|
|
12
|
+
(messages: Array<Message>): Generator<Action<"set_messages", Spec.Make<{ Event: MessagesSet }>>, Array<Message>>
|
|
13
|
+
(
|
|
14
|
+
setter: (messages: Array<Message>) => PromiseOr<Array<Message>>,
|
|
15
|
+
): Generator<Action<"set_messages", Spec.Make<{ Event: MessagesSet }>>, Array<Message>>
|
|
16
|
+
<K extends JSONKey, Y extends Action>(
|
|
17
|
+
key: K,
|
|
18
|
+
setter: (messages: Array<Message>) => Agent<Y, void>,
|
|
19
|
+
): Generator<
|
|
20
|
+
Action<
|
|
21
|
+
"set_messages",
|
|
22
|
+
Spec.Make<{ Event: MessagesSet; Child: [K, Y[""]]; Entry: Y[""]["Entry"]; Value: Array<Message> }>
|
|
23
|
+
>,
|
|
24
|
+
Array<Message>
|
|
25
|
+
>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const messages: messages = Object.assign(messages_, {
|
|
29
|
+
*[Symbol.iterator]() {
|
|
30
|
+
const scope_ = yield* scope
|
|
31
|
+
return scope_.messages
|
|
32
|
+
},
|
|
33
|
+
}) as never
|
|
34
|
+
|
|
35
|
+
function* messages_(
|
|
36
|
+
setterOrKey: JSONKey | ((messages: Array<Message>) => PromiseOr<Array<Message>>),
|
|
37
|
+
maybeSetter?: (messages: Array<Message>) => Agent<Action, void>,
|
|
38
|
+
): Generator<Action<"set_messages">, Array<Message>> {
|
|
39
|
+
return yield Action("set_messages", async (scope) => {
|
|
40
|
+
if (isPropertyKey(setterOrKey)) {
|
|
41
|
+
const setterScope = scope.fork("set_messages", [setterOrKey])
|
|
42
|
+
const reduced = await setterScope.reduce(maybeSetter!([...scope.messages]))
|
|
43
|
+
const { messages } = reduced
|
|
44
|
+
setterScope.event({
|
|
45
|
+
type: "messages_set",
|
|
46
|
+
messages: [...messages],
|
|
47
|
+
})
|
|
48
|
+
return {
|
|
49
|
+
...scope,
|
|
50
|
+
messages,
|
|
51
|
+
nextArg: scope.messages,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const messages = new Set(Array.isArray(setterOrKey) ? setterOrKey : await setterOrKey([...scope.messages]))
|
|
55
|
+
return {
|
|
56
|
+
...scope,
|
|
57
|
+
messages,
|
|
58
|
+
nextArg: scope.messages,
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
Object.defineProperty(messages_, "name", { value: "messages" })
|
package/actions/pushModel.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Action } from "../Action.ts"
|
|
2
2
|
import type { ModelPushed } from "../events/ModelPushed.ts"
|
|
3
|
+
import type { ModelRemoved } from "../events/ModelRemoved.ts"
|
|
3
4
|
import type { Model, ModelType } from "../Model.ts"
|
|
4
5
|
import type { Spec } from "../Spec.ts"
|
|
5
6
|
import type { JSONKey } from "../util/JSONKey.ts"
|
|
6
7
|
import { applyToModels } from "./actions_common/updateModels.ts"
|
|
7
|
-
import { removeModel } from "./removeModel.ts"
|
|
8
8
|
|
|
9
9
|
export interface pushModel<K extends JSONKey, M extends ModelType>
|
|
10
10
|
extends Action<"remove_model", Spec.Make<{ Event: ModelPushed<K, M> }>>
|
|
11
11
|
{}
|
|
12
12
|
|
|
13
|
+
export interface removeModel<K extends JSONKey, M extends ModelType>
|
|
14
|
+
extends Action<"remove_model", Spec.Make<{ Event: ModelRemoved<K, M> }>>
|
|
15
|
+
{}
|
|
16
|
+
|
|
13
17
|
export function* pushModel<K extends JSONKey, M extends Model>(
|
|
14
18
|
modelKey: K,
|
|
15
19
|
model: M,
|
|
@@ -26,7 +30,23 @@ export function* pushModel<K extends JSONKey, M extends Model>(
|
|
|
26
30
|
models.add(model)
|
|
27
31
|
return models
|
|
28
32
|
}),
|
|
29
|
-
nextArg: removeModel
|
|
33
|
+
nextArg: (function*(): Generator<removeModel<K, M["type"]>, void> {
|
|
34
|
+
yield Action("remove_model", (scope) => {
|
|
35
|
+
scope.event({
|
|
36
|
+
type: "model_removed",
|
|
37
|
+
modelKey,
|
|
38
|
+
modelType: model.type,
|
|
39
|
+
})
|
|
40
|
+
return {
|
|
41
|
+
...scope,
|
|
42
|
+
...applyToModels(scope, model, (models) => {
|
|
43
|
+
models.delete(model)
|
|
44
|
+
return models
|
|
45
|
+
}),
|
|
46
|
+
nextArg: undefined,
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
})(),
|
|
30
50
|
}
|
|
31
51
|
})
|
|
32
52
|
}
|
package/actions/scope.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Scope } from "../Scope.ts"
|
|
3
|
+
|
|
4
|
+
export interface getScope extends Action<"get_scope", never> {}
|
|
5
|
+
|
|
6
|
+
export const scope = {
|
|
7
|
+
*[Symbol.iterator](): Iterator<getScope, Scope> {
|
|
8
|
+
return yield Action("get_scope", (scope) => ({
|
|
9
|
+
...scope,
|
|
10
|
+
nextArg: scope,
|
|
11
|
+
}))
|
|
12
|
+
},
|
|
13
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Action } from "../Action.ts"
|
|
2
|
+
import type { Agent, AgentLike } from "../Agent.ts"
|
|
3
|
+
import type { SectionCleared } from "../events/SectionCleared.ts"
|
|
4
|
+
import type { Sectioned } from "../events/Sectioned.ts"
|
|
5
|
+
import type { Message } from "../Message.ts"
|
|
6
|
+
import type { Section } from "../Scope.ts"
|
|
7
|
+
import type { Spec } from "../Spec.ts"
|
|
8
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
9
|
+
import { unwrapDeferred } from "../util/unwrapDeferred.ts"
|
|
10
|
+
|
|
11
|
+
export interface section<K extends JSONKey> extends Action<"section", Spec.Make<{ Event: Sectioned<K> }>> {}
|
|
12
|
+
|
|
13
|
+
export interface SectionHandle<K extends JSONKey> {
|
|
14
|
+
clear: Generator<Action<"clear_section", Spec.Make<{ Event: SectionCleared<K> }>>, void>
|
|
15
|
+
getMessages: () => Generator<Action<"get_section_messages", never>, Set<Message>>
|
|
16
|
+
|
|
17
|
+
<L extends JSONKey, Y extends Action, T>(key: L, agentLike: AgentLike<Y, T>): Generator<
|
|
18
|
+
Action<
|
|
19
|
+
"run_section",
|
|
20
|
+
Spec.Make<{
|
|
21
|
+
Child: [L, Y[""]]
|
|
22
|
+
Entry: Y[""]["Entry"]
|
|
23
|
+
Value: T
|
|
24
|
+
}>
|
|
25
|
+
>,
|
|
26
|
+
T
|
|
27
|
+
>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function* section<K extends JSONKey>(sectionKey: K): Generator<section<K>, SectionHandle<K>> {
|
|
31
|
+
return yield Action("section", (scope) => {
|
|
32
|
+
scope.event({
|
|
33
|
+
type: "sectioned",
|
|
34
|
+
sectionKey,
|
|
35
|
+
})
|
|
36
|
+
const section: Section = {
|
|
37
|
+
sectionKey,
|
|
38
|
+
messages: new Set(),
|
|
39
|
+
}
|
|
40
|
+
scope.sections.add(section)
|
|
41
|
+
return {
|
|
42
|
+
...scope,
|
|
43
|
+
nextArg: Object.assign(
|
|
44
|
+
function*<L extends JSONKey, Y extends Action, T>(key: L, agentLike: AgentLike<Y, T>): Generator<
|
|
45
|
+
Action<
|
|
46
|
+
"run_section",
|
|
47
|
+
Spec.Make<{
|
|
48
|
+
Child: [L, Y[""]]
|
|
49
|
+
Entry: Y[""]["Entry"]
|
|
50
|
+
Value: T
|
|
51
|
+
}>
|
|
52
|
+
>,
|
|
53
|
+
T
|
|
54
|
+
> {
|
|
55
|
+
return yield Action("run_section", async (scope) => {
|
|
56
|
+
const sectionScope = scope.fork("run_section", [key], {
|
|
57
|
+
messages: new Set(section.messages),
|
|
58
|
+
})
|
|
59
|
+
const reduced = await sectionScope.reduce(unwrapDeferred(agentLike))
|
|
60
|
+
const { value } = reduced
|
|
61
|
+
sectionScope.event({
|
|
62
|
+
type: "returned",
|
|
63
|
+
value,
|
|
64
|
+
})
|
|
65
|
+
return {
|
|
66
|
+
...scope,
|
|
67
|
+
nextArg: value,
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
getMessages: (function*(): Generator<Action<"get_section_messages", never>, Set<Message>> {
|
|
73
|
+
return yield Action("get_section_messages", (scope) => ({
|
|
74
|
+
...scope,
|
|
75
|
+
nextArg: new Set(section.messages),
|
|
76
|
+
}))
|
|
77
|
+
})(),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
clear:
|
|
81
|
+
(function*(): Generator<Action<"clear_section", Spec.Make<{ Event: SectionCleared<K> }>>, Set<Message>> {
|
|
82
|
+
return yield Action("clear_section", (scope) => {
|
|
83
|
+
const sections = new Set(scope.sections)
|
|
84
|
+
sections.delete(section)
|
|
85
|
+
const messages = new Set(scope.messages)
|
|
86
|
+
section.messages.forEach((message) => {
|
|
87
|
+
messages.delete(message)
|
|
88
|
+
})
|
|
89
|
+
scope.event({
|
|
90
|
+
type: "section_cleared",
|
|
91
|
+
sectionKey,
|
|
92
|
+
})
|
|
93
|
+
return {
|
|
94
|
+
...scope,
|
|
95
|
+
nextArg: messages,
|
|
96
|
+
sections,
|
|
97
|
+
messages,
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
})(),
|
|
101
|
+
},
|
|
102
|
+
),
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
package/cli/cli_common.ts
CHANGED
package/cli/main.ts
CHANGED
|
@@ -9,7 +9,12 @@ const args = process.argv.slice(2)
|
|
|
9
9
|
const command = L.enum("exec").assert(args.shift())
|
|
10
10
|
const ctl = new AbortController()
|
|
11
11
|
|
|
12
|
-
const cliCtx: CliCtx = {
|
|
12
|
+
const cliCtx: CliCtx = {
|
|
13
|
+
ctl,
|
|
14
|
+
error(message) { // TODO
|
|
15
|
+
throw new Error(message)
|
|
16
|
+
},
|
|
17
|
+
}
|
|
13
18
|
|
|
14
19
|
switch (command) {
|
|
15
20
|
case "exec": {
|
package/cli/runExec.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dirname, isAbsolute, parse, resolve } from "node:path"
|
|
2
2
|
import { parseArgs, type ParseArgsConfig } from "node:util"
|
|
3
|
-
import { type
|
|
3
|
+
import { type Agent, type EventResolved, exec, L, type LiminalConfig } from "../index.ts"
|
|
4
4
|
import type { CliCtx } from "./cli_common.ts"
|
|
5
5
|
import { WriteHandler } from "./WriteHandler.ts"
|
|
6
6
|
|
|
@@ -32,18 +32,23 @@ export async function runExec(ctx: CliCtx, args: Array<string>) {
|
|
|
32
32
|
const configPathResolved = resolve(configPath)
|
|
33
33
|
const configDir = dirname(configPathResolved)
|
|
34
34
|
const config = await import(configPathResolved).then(({ default: default_ }) => default_ as LiminalConfig)
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
if (isAbsolute(
|
|
38
|
-
|
|
35
|
+
const agentPathInitial = L.string.assert(positionals[0])
|
|
36
|
+
let agentPathResolved: string
|
|
37
|
+
if (isAbsolute(agentPathInitial)) {
|
|
38
|
+
agentPathResolved = agentPathInitial
|
|
39
39
|
} else {
|
|
40
|
-
|
|
40
|
+
agentPathResolved = resolve(configDir, ...config.agents ? [config.agents] : [], agentPathInitial)
|
|
41
41
|
}
|
|
42
|
-
if (!
|
|
43
|
-
|
|
42
|
+
if (!agentPathResolved.endsWith(".ts")) {
|
|
43
|
+
agentPathResolved = `${agentPathResolved}.ts`
|
|
44
|
+
}
|
|
45
|
+
const parsedPath = parse(agentPathResolved)
|
|
46
|
+
let agentLike: () => Agent
|
|
47
|
+
try {
|
|
48
|
+
agentLike = await import(agentPathResolved).then(({ default: default_ }) => default_ as () => Agent)
|
|
49
|
+
} catch (_e: unknown) {
|
|
50
|
+
ctx.error(`Could not fine agent file at "${agentPathResolved}".`)
|
|
44
51
|
}
|
|
45
|
-
const parsedPath = parse(actorPathResolved)
|
|
46
|
-
const actorLike = await import(actorPathResolved).then(({ default: default_ }) => default_ as () => Actor)
|
|
47
52
|
const startTime = Date.now()
|
|
48
53
|
const writeHandlerOrNoop = config.write
|
|
49
54
|
? await WriteHandler({
|
|
@@ -55,14 +60,13 @@ export async function runExec(ctx: CliCtx, args: Array<string>) {
|
|
|
55
60
|
})
|
|
56
61
|
: undefined
|
|
57
62
|
const printHandlerOrNoop = config.silent ? undefined : (event: EventResolved) => console.log(event)
|
|
58
|
-
|
|
63
|
+
await exec(agentLike, {
|
|
59
64
|
default: config.default,
|
|
60
65
|
args: config.args!,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}, {
|
|
66
|
+
handler(event) {
|
|
67
|
+
printHandlerOrNoop?.(event)
|
|
68
|
+
writeHandlerOrNoop?.(event)
|
|
69
|
+
},
|
|
66
70
|
signal: ctx.ctl.signal,
|
|
67
71
|
})
|
|
68
72
|
}
|
package/dist/Agent.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Action } from "./Action.ts";
|
|
2
|
+
import type { DeferredOr } from "./util/DeferredOr.ts";
|
|
3
|
+
import type { IteratorLike } from "./util/IteratorLike.ts";
|
|
4
|
+
export type Agent<Y extends Action = Action, R = any> = IteratorLike<Y, R>;
|
|
5
|
+
export type AgentLike<Y extends Action = Action, R = any> = DeferredOr<Agent<Y, R>>;
|
|
6
|
+
export type AgentLikeY<A extends AgentLike> = A extends AgentLike<infer Y> ? Y : never;
|
|
7
|
+
export type AgentLikeT<A extends AgentLike> = A extends AgentLike<Action, infer T> ? T : never;
|
package/dist/Agent.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Agent.js","sourceRoot":"","sources":["../Agent.ts"],"names":[],"mappings":""}
|
package/dist/Exec.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import type { Action } from "./Action.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Agent } from "./Agent.ts";
|
|
3
3
|
import type { EventHandler } from "./events/EventHandler.ts";
|
|
4
4
|
import type { EventResolved, ExtractEventResolved } from "./events/EventResolved.ts";
|
|
5
5
|
import type { LanguageModel } from "./Model.ts";
|
|
6
6
|
import type { FromEntries } from "./util/FromEntries.ts";
|
|
7
7
|
import type { JSONKey } from "./util/JSONKey.ts";
|
|
8
|
-
export interface Exec<Y extends Action = Action, T = any> {
|
|
9
|
-
(handler?: EventHandler<Extract<ExtractEventResolved<Y[""]> & {}, EventResolved>>, options?: ExecOptions): Promise<T>;
|
|
10
|
-
}
|
|
11
8
|
export interface ExecConfig {
|
|
12
9
|
default: LanguageModel;
|
|
13
10
|
args?: Record<JSONKey, any>;
|
|
14
|
-
}
|
|
15
|
-
export interface ExecOptions {
|
|
16
11
|
signal?: AbortSignal;
|
|
12
|
+
handler?: EventHandler;
|
|
17
13
|
}
|
|
18
14
|
export type ExtractExecConfig<Y extends Action> = {
|
|
19
15
|
default: LanguageModel;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
handler?: EventHandler<Extract<ExtractEventResolved<Y[""]> & {}, EventResolved>>;
|
|
20
18
|
} & ([
|
|
21
19
|
Y[""]["Entry"]
|
|
22
20
|
] extends [never] ? {
|
|
@@ -24,4 +22,4 @@ export type ExtractExecConfig<Y extends Action> = {
|
|
|
24
22
|
} : {
|
|
25
23
|
args: FromEntries<Y[""]["Entry"]>;
|
|
26
24
|
});
|
|
27
|
-
export declare function
|
|
25
|
+
export declare function exec<Y extends Action, T>(createAgent: () => Agent<Y, T>, config: ExtractExecConfig<Y>): Promise<T>;
|
package/dist/Exec.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { RootScope } from "./Scope.js";
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { signal: { aborted, reason } } = scope.controller;
|
|
8
|
-
if (aborted) {
|
|
9
|
-
scope.event({
|
|
10
|
-
type: "aborted",
|
|
11
|
-
reason,
|
|
12
|
-
});
|
|
13
|
-
throw reason;
|
|
14
|
-
}
|
|
2
|
+
export async function exec(createAgent, config) {
|
|
3
|
+
let scope = RootScope(config);
|
|
4
|
+
scope = await scope.reduce(createAgent());
|
|
5
|
+
const { signal: { aborted, reason } } = scope.controller;
|
|
6
|
+
if (aborted) {
|
|
15
7
|
scope.event({
|
|
16
|
-
type: "
|
|
17
|
-
|
|
8
|
+
type: "aborted",
|
|
9
|
+
reason,
|
|
18
10
|
});
|
|
19
|
-
|
|
20
|
-
}
|
|
11
|
+
throw reason;
|
|
12
|
+
}
|
|
13
|
+
scope.event({
|
|
14
|
+
type: "returned",
|
|
15
|
+
value: scope.value,
|
|
16
|
+
});
|
|
17
|
+
return scope.value;
|
|
21
18
|
}
|
|
22
19
|
//# sourceMappingURL=Exec.js.map
|
package/dist/Exec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Exec.js","sourceRoot":"","sources":["../Exec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAc,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"Exec.js","sourceRoot":"","sources":["../Exec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAc,MAAM,YAAY,CAAA;AA0BlD,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,WAA8B,EAC9B,MAA4B;IAE5B,IAAI,KAAK,GAAU,SAAS,CAAC,MAAe,CAAC,CAAA;IAC7C,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,UAAU,CAAA;IACxD,IAAI,OAAO,EAAE,CAAC;QACZ,KAAK,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,SAAS;YACf,MAAM;SACP,CAAC,CAAA;QACF,MAAM,MAAM,CAAA;IACd,CAAC;IACD,KAAK,CAAC,KAAK,CAAC;QACV,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC,CAAA;IACF,OAAO,KAAK,CAAC,KAAK,CAAA;AACpB,CAAC"}
|
package/dist/L.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ export * from "./_.ts";
|
|
|
2
2
|
export * from "./actions/abort.ts";
|
|
3
3
|
export * from "./actions/actions_derived/clear.ts";
|
|
4
4
|
export * from "./actions/actions_derived/declareModel.ts";
|
|
5
|
-
export * from "./actions/actions_derived/declareModel.ts";
|
|
6
|
-
export * from "./actions/actions_derived/getMessages.ts";
|
|
7
5
|
export * from "./actions/actions_derived/messages.ts";
|
|
6
|
+
export * from "./actions/actions_derived/readers_derived.ts";
|
|
8
7
|
export * from "./actions/appendMessage.ts";
|
|
9
8
|
export * from "./actions/await.ts";
|
|
10
9
|
export * from "./actions/branch.ts";
|
|
@@ -14,13 +13,11 @@ export * from "./actions/disableTool.ts";
|
|
|
14
13
|
export * from "./actions/embed.ts";
|
|
15
14
|
export * from "./actions/emit.ts";
|
|
16
15
|
export * from "./actions/enableTool.ts";
|
|
17
|
-
export * from "./actions/getScope.ts";
|
|
18
|
-
export * from "./actions/getSignal.ts";
|
|
19
|
-
export * from "./actions/getTools.ts";
|
|
20
16
|
export * from "./actions/infer.ts";
|
|
17
|
+
export * from "./actions/messages.ts";
|
|
21
18
|
export * from "./actions/pushModel.ts";
|
|
22
|
-
export * from "./actions/
|
|
23
|
-
export * from "./actions/
|
|
19
|
+
export * from "./actions/scope.ts";
|
|
20
|
+
export * from "./actions/section.ts";
|
|
24
21
|
export * from "./actions/throw.ts";
|
|
25
22
|
export * from "./types/factories.ts";
|
|
26
23
|
export * from "./actions/actions_derived/metatype.ts";
|
package/dist/L.js
CHANGED
|
@@ -2,9 +2,8 @@ export * from "./_.js";
|
|
|
2
2
|
export * from "./actions/abort.js";
|
|
3
3
|
export * from "./actions/actions_derived/clear.js";
|
|
4
4
|
export * from "./actions/actions_derived/declareModel.js";
|
|
5
|
-
export * from "./actions/actions_derived/declareModel.js";
|
|
6
|
-
export * from "./actions/actions_derived/getMessages.js";
|
|
7
5
|
export * from "./actions/actions_derived/messages.js";
|
|
6
|
+
export * from "./actions/actions_derived/readers_derived.js";
|
|
8
7
|
export * from "./actions/appendMessage.js";
|
|
9
8
|
export * from "./actions/await.js";
|
|
10
9
|
export * from "./actions/branch.js";
|
|
@@ -14,13 +13,11 @@ export * from "./actions/disableTool.js";
|
|
|
14
13
|
export * from "./actions/embed.js";
|
|
15
14
|
export * from "./actions/emit.js";
|
|
16
15
|
export * from "./actions/enableTool.js";
|
|
17
|
-
export * from "./actions/getScope.js";
|
|
18
|
-
export * from "./actions/getSignal.js";
|
|
19
|
-
export * from "./actions/getTools.js";
|
|
20
16
|
export * from "./actions/infer.js";
|
|
17
|
+
export * from "./actions/messages.js";
|
|
21
18
|
export * from "./actions/pushModel.js";
|
|
22
|
-
export * from "./actions/
|
|
23
|
-
export * from "./actions/
|
|
19
|
+
export * from "./actions/scope.js";
|
|
20
|
+
export * from "./actions/section.js";
|
|
24
21
|
export * from "./actions/throw.js";
|
|
25
22
|
export * from "./types/factories.js";
|
|
26
23
|
export * from "./actions/actions_derived/metatype.js";
|
package/dist/L.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"L.js","sourceRoot":"","sources":["../L.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,oCAAoC,CAAA;AAClD,cAAc,2CAA2C,CAAA;AACzD,cAAc,
|
|
1
|
+
{"version":3,"file":"L.js","sourceRoot":"","sources":["../L.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,oBAAoB,CAAA;AAClC,cAAc,oCAAoC,CAAA;AAClD,cAAc,2CAA2C,CAAA;AACzD,cAAc,uCAAuC,CAAA;AACrD,cAAc,8CAA8C,CAAA;AAC5D,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,uCAAuC,CAAA"}
|
package/dist/LiminalConfig.d.ts
CHANGED
package/dist/Model.d.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
2
|
import type { Action } from "./Action.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Agent } from "./Agent.ts";
|
|
4
4
|
import type { JSONObject } from "./util/JSONObject.ts";
|
|
5
5
|
export type Model = LanguageModel | EmbeddingModel;
|
|
6
6
|
export interface LanguageModel extends ModelBase<"language"> {
|
|
7
|
-
infer: (type: StandardSchemaV1<JSONObject, any> | undefined) =>
|
|
7
|
+
infer: (type: StandardSchemaV1<JSONObject, any> | undefined) => Agent<Action, any>;
|
|
8
8
|
}
|
|
9
9
|
export interface EmbeddingModel extends ModelBase<"embedding"> {
|
|
10
10
|
embed: (value: string) => Promise<Array<number>>;
|
|
11
11
|
}
|
|
12
12
|
interface ModelBase<K extends ModelType> {
|
|
13
13
|
type: K;
|
|
14
|
+
vendor: string;
|
|
14
15
|
}
|
|
15
16
|
export type ModelType = "language" | "embedding";
|
|
17
|
+
export type Models = {
|
|
18
|
+
language: LanguageModel;
|
|
19
|
+
embedding: EmbeddingModel;
|
|
20
|
+
};
|
|
16
21
|
export {};
|
package/dist/PathLike.d.ts
CHANGED
|
@@ -2,13 +2,10 @@ import type { _ } from "./_.ts";
|
|
|
2
2
|
import type { JSONKey } from "./util/JSONKey.ts";
|
|
3
3
|
export type Path = Array<JSONKey>;
|
|
4
4
|
export declare namespace Path {
|
|
5
|
-
type FromPathLike<P extends PathLike> =
|
|
6
|
-
[K in keyof P]: P[K] extends _ ? JSONKey : P[K];
|
|
7
|
-
}, Path>;
|
|
5
|
+
type FromPathLike<P extends PathLike> = P extends [infer E0 extends KeyLike, ...infer ERest extends PathLike] ? [E0 extends JSONKey ? E0 : JSONKey, ...FromPathLike<ERest>] : [];
|
|
8
6
|
}
|
|
9
|
-
export type
|
|
7
|
+
export type KeyLike = JSONKey | _;
|
|
8
|
+
export type PathLike = Array<KeyLike>;
|
|
10
9
|
export declare namespace PathLike {
|
|
11
|
-
type FromPath<P extends Path> =
|
|
12
|
-
[K in keyof P]: P[K] | _;
|
|
13
|
-
};
|
|
10
|
+
type FromPath<P extends Path> = P extends [infer E0, ...infer ERest extends Path] ? [E0 | _, ...FromPath<ERest>] : [];
|
|
14
11
|
}
|
package/dist/Scope.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Agent } from "./Agent.ts";
|
|
2
2
|
import type { EventHandler } from "./events/EventHandler.ts";
|
|
3
3
|
import type { LEvent } from "./events/LEvent.ts";
|
|
4
|
+
import type { ExecConfig } from "./Exec.ts";
|
|
4
5
|
import type { Message } from "./Message.ts";
|
|
5
6
|
import type { EmbeddingModel, LanguageModel } from "./Model.ts";
|
|
6
7
|
import type { Tool } from "./Tool.ts";
|
|
@@ -12,7 +13,7 @@ export interface ChildScope extends ScopeBase<ChildScopeType> {
|
|
|
12
13
|
readonly parent: Scope;
|
|
13
14
|
}
|
|
14
15
|
export type RootScopeType = "root";
|
|
15
|
-
export type ChildScopeType = "catch" | "tool" | "branch" | "branch_arm" | "set_messages";
|
|
16
|
+
export type ChildScopeType = "catch" | "tool" | "branch" | "branch_arm" | "set_messages" | "run_section";
|
|
16
17
|
export type ScopeType = RootScopeType | ChildScopeType;
|
|
17
18
|
export interface ScopeBase<Type extends ScopeType> {
|
|
18
19
|
readonly type: Type;
|
|
@@ -29,8 +30,13 @@ export interface ScopeBase<Type extends ScopeType> {
|
|
|
29
30
|
readonly handler?: EventHandler;
|
|
30
31
|
readonly childForkCounts: Record<JSONKey, number>;
|
|
31
32
|
readonly index: number;
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
readonly sections: Set<Section>;
|
|
34
|
+
reduce(agent: Agent): Promise<Scope>;
|
|
35
|
+
fork(source: ChildScopeType, subpath: Array<JSONKey>, overrides?: Partial<ChildScope>): Scope;
|
|
34
36
|
event(event: LEvent): void;
|
|
35
37
|
}
|
|
36
|
-
export
|
|
38
|
+
export interface Section {
|
|
39
|
+
sectionKey: JSONKey;
|
|
40
|
+
messages: Set<Message>;
|
|
41
|
+
}
|
|
42
|
+
export declare function RootScope({ signal, args, handler, default: defaultLanguageModel, }: ExecConfig): RootScope;
|