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
package/dist/Scope.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function RootScope(
|
|
1
|
+
export function RootScope({ signal, args, handler, default: defaultLanguageModel, }) {
|
|
2
2
|
const controller = new AbortController();
|
|
3
3
|
signal?.addEventListener("abort", () => {
|
|
4
4
|
controller.abort();
|
|
@@ -14,6 +14,7 @@ export function RootScope(defaultLanguageModel, args, handler = () => { }, signa
|
|
|
14
14
|
languageModels: new Set([defaultLanguageModel]),
|
|
15
15
|
embeddingModels: new Set(),
|
|
16
16
|
childForkCounts: {},
|
|
17
|
+
sections: new Set(),
|
|
17
18
|
index: 0,
|
|
18
19
|
reduce,
|
|
19
20
|
fork,
|
|
@@ -21,14 +22,14 @@ export function RootScope(defaultLanguageModel, args, handler = () => { }, signa
|
|
|
21
22
|
event,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
|
-
async function reduce(
|
|
25
|
+
async function reduce(agent) {
|
|
25
26
|
const { signal } = this.controller;
|
|
26
27
|
let scope = { ...this };
|
|
27
28
|
if (signal.aborted)
|
|
28
29
|
return scope;
|
|
29
30
|
let value;
|
|
30
31
|
try {
|
|
31
|
-
let current = await
|
|
32
|
+
let current = await agent.next();
|
|
32
33
|
while (!current.done) {
|
|
33
34
|
const { value } = current;
|
|
34
35
|
if (signal.aborted)
|
|
@@ -36,7 +37,7 @@ async function reduce(actor) {
|
|
|
36
37
|
scope = await value.reducer(scope);
|
|
37
38
|
if (signal.aborted)
|
|
38
39
|
return scope;
|
|
39
|
-
current = await
|
|
40
|
+
current = await agent.next(scope.nextArg);
|
|
40
41
|
}
|
|
41
42
|
value = current.value;
|
|
42
43
|
}
|
|
@@ -49,7 +50,7 @@ async function reduce(actor) {
|
|
|
49
50
|
nextArg: undefined,
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
|
-
function fork(type, subpath) {
|
|
53
|
+
function fork(type, subpath, overrides) {
|
|
53
54
|
const subpathStr = subpath.join(" ");
|
|
54
55
|
let index = this.childForkCounts[subpathStr];
|
|
55
56
|
if (typeof index === "number") {
|
|
@@ -73,9 +74,11 @@ function fork(type, subpath) {
|
|
|
73
74
|
parent: this,
|
|
74
75
|
value: undefined,
|
|
75
76
|
index,
|
|
77
|
+
sections: new Set(this.sections),
|
|
76
78
|
reduce,
|
|
77
79
|
fork,
|
|
78
80
|
event,
|
|
81
|
+
...overrides ?? {},
|
|
79
82
|
};
|
|
80
83
|
f.event({ type: "forked" });
|
|
81
84
|
return f;
|
package/dist/Scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scope.js","sourceRoot":"","sources":["../Scope.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Scope.js","sourceRoot":"","sources":["../Scope.ts"],"names":[],"mappings":"AAoDA,MAAM,UAAU,SAAS,CAAC,EACxB,MAAM,EACN,IAAI,EACJ,OAAO,EACP,OAAO,EAAE,oBAAoB,GAClB;IACX,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;QACrC,UAAU,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC,CAAC,CAAA;IACF,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,IAAI;QACJ,UAAU;QACV,QAAQ,EAAE,IAAI,GAAG,EAAE;QACnB,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,EAAE;QACR,cAAc,EAAE,IAAI,GAAG,CAAC,CAAC,oBAAoB,CAAC,CAAC;QAC/C,eAAe,EAAE,IAAI,GAAG,EAAE;QAC1B,eAAe,EAAE,EAAE;QACnB,QAAQ,EAAE,IAAI,GAAG,EAAE;QACnB,KAAK,EAAE,CAAC;QACR,M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action } from "./Action.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Agent } from "./Agent.ts";
|
|
4
4
|
import type { Scope } from "./Scope.ts";
|
|
5
5
|
import type { JSONKey } from "./util/JSONKey.ts";
|
|
6
6
|
import type { JSONObject } from "./util/JSONObject.ts";
|
|
@@ -16,6 +16,6 @@ export interface Tool<K extends JSONKey = JSONKey> extends ToolConfig<K> {
|
|
|
16
16
|
executor: (scope: Scope) => ToolExecutor;
|
|
17
17
|
}
|
|
18
18
|
export declare function Tool<K extends JSONKey>(config: ToolConfig<K>): Tool<K>;
|
|
19
|
-
export type ToolImplementation = (params: any) =>
|
|
19
|
+
export type ToolImplementation = (params: any) => Agent<Action, ToolResult> | PromiseOr<ToolResult>;
|
|
20
20
|
export type ToolExecutor = (args: any) => Promise<JSONValue>;
|
|
21
21
|
export type ToolResult = JSONValue | void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear.js","sourceRoot":"","sources":["../../../actions/actions_derived/clear.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clear.js","sourceRoot":"","sources":["../../../actions/actions_derived/clear.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,UAAU,KAAK;IACnB,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Models, ModelType } from "../../Model.ts";
|
|
2
2
|
import type { JSONKey } from "../../util/JSONKey.ts";
|
|
3
3
|
import { declareArg } from "../declareArg.ts";
|
|
4
4
|
import { pushModel } from "../pushModel.ts";
|
|
5
|
-
export declare function declareModel<K extends JSONKey>(key: K): Generator<declareArg<K,
|
|
5
|
+
export declare function declareModel<K extends JSONKey, M extends ModelType>(key: K, _modelType: M): Generator<declareArg<K, Models[M]> | pushModel<K, Models[M]["type"]>, Generator<import("../pushModel.ts").removeModel<K, Models[M]["type"]>, void, any>, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { declareArg } from "../declareArg.js";
|
|
2
2
|
import { pushModel } from "../pushModel.js";
|
|
3
|
-
export function* declareModel(key) {
|
|
3
|
+
export function* declareModel(key, _modelType) {
|
|
4
4
|
const model = yield* declareArg(key)();
|
|
5
5
|
return yield* pushModel(key, model);
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declareModel.js","sourceRoot":"","sources":["../../../actions/actions_derived/declareModel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,MAAM,SAAS,CAAC,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"declareModel.js","sourceRoot":"","sources":["../../../actions/actions_derived/declareModel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,MAAM,SAAS,CAAC,CAAC,YAAY,CAAyC,GAAM,EAAE,UAAa;IACzF,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAa,CAAA;IACjD,OAAO,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACrC,CAAC"}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import { exec } from "../../Exec.js";
|
|
3
3
|
import * as L from "../../L.js";
|
|
4
4
|
import { TestEmbeddingModel } from "../../testing/TestEmbeddingModel.js";
|
|
5
5
|
import { TestLanguageModel } from "../../testing/TestLanguageModel.js";
|
|
6
6
|
describe("Model", () => {
|
|
7
7
|
it("generates the expected event sequence", async () => {
|
|
8
8
|
const events = [];
|
|
9
|
-
await
|
|
10
|
-
const a = yield* L.declareModel("secondary");
|
|
9
|
+
await exec(function* () {
|
|
10
|
+
const a = yield* L.declareModel("secondary", "language");
|
|
11
11
|
yield* L.branch("fork-key", function* () {
|
|
12
|
-
const b = yield* L.declareModel("child_a");
|
|
13
|
-
const c = yield* L.declareModel("child_b");
|
|
12
|
+
const b = yield* L.declareModel("child_a", "language");
|
|
13
|
+
const c = yield* L.declareModel("child_b", "embedding");
|
|
14
14
|
yield* b;
|
|
15
15
|
yield* c;
|
|
16
16
|
});
|
|
17
|
-
const c = yield* L.declareModel("tertiary");
|
|
17
|
+
const c = yield* L.declareModel("tertiary", "embedding");
|
|
18
18
|
yield* a;
|
|
19
19
|
yield* c;
|
|
20
20
|
}, {
|
|
@@ -25,7 +25,10 @@ describe("Model", () => {
|
|
|
25
25
|
child_b: TestEmbeddingModel(),
|
|
26
26
|
tertiary: TestEmbeddingModel(),
|
|
27
27
|
},
|
|
28
|
-
|
|
28
|
+
handler(event) {
|
|
29
|
+
events.push(event);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
29
32
|
expect(JSON.stringify(events, null, 2)).toMatchSnapshot();
|
|
30
33
|
});
|
|
31
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declareModel.test.js","sourceRoot":"","sources":["../../../actions/actions_derived/declareModel.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,CAAC,MAAM,YAAY,CAAA;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AAEtE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,uCAAuC,EAAE,KAAK,I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AU,EAAE,WAAW,CAAC,CAAA;YACxD,KAAK,CAAC,CAAC,CAAC,CAAA;YACR,KAAK,CAAC,CAAC,CAAC,CAAA;QACV,CAAC,EAAE;YACD,OAAO,EAAE,iBAAiB,EAAE;YAC5B,IAAI,EAAE;gBACJ,SAAS,EAAE,iBAAiB,EAAE;gBAC9B,OAAO,EAAE,iBAAiB,EAAE;gBAC5B,OAAO,EAAE,kBAAkB,EAAE;gBAC7B,QAAQ,EAAE,kBAAkB,EAAE;aAC/B;YACD,OAAO,CAAC,KAAK;gBACX,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC;SACF,CAAC,CAAA;QACF,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,CAAA;IAC3D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AssistantContent, UserContent } from "../../Message.ts";
|
|
2
2
|
import { type TaggableArgs } from "../../util/Taggable.ts";
|
|
3
3
|
import { appendMessage } from "../appendMessage.ts";
|
|
4
|
-
export declare function user(...args: TaggableArgs<[content: UserContent]>): Generator<appendMessage<import("../../Message.ts").UserMessage>, Generator<import("../
|
|
5
|
-
export declare function system(...args: TaggableArgs<[content: string]>): Generator<appendMessage<import("../../Message.ts").SystemMessage>, Generator<import("../
|
|
6
|
-
export declare function assistant(...args: TaggableArgs<[content: AssistantContent]>): Generator<appendMessage<import("../../Message.ts").AssistantMessage>, Generator<import("../
|
|
4
|
+
export declare function user(...args: TaggableArgs<[content: UserContent]>): Generator<appendMessage<import("../../Message.ts").UserMessage>, Generator<import("../appendMessage.ts").removeMessage, void, any>, any>;
|
|
5
|
+
export declare function system(...args: TaggableArgs<[content: string]>): Generator<appendMessage<import("../../Message.ts").SystemMessage>, Generator<import("../appendMessage.ts").removeMessage, void, any>, any>;
|
|
6
|
+
export declare function assistant(...args: TaggableArgs<[content: AssistantContent]>): Generator<appendMessage<import("../../Message.ts").AssistantMessage>, Generator<import("../appendMessage.ts").removeMessage, void, any>, any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../actions/actions_derived/messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../actions/actions_derived/messages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAqB,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,UAAU,IAAI,CAAC,GAAG,IAA0C;IAChE,MAAM,CAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC,GAAG,IAAI,CAAC,CAAA;IAChD,OAAO,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAG,IAAqC;IAC7D,MAAM,CAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC,GAAG,IAAI,CAAC,CAAA;IAChD,OAAO,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAG,IAA+C;IAC1E,MAAM,CAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC,GAAG,IAAI,CAAC,CAAA;IAChD,OAAO,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const tools: {
|
|
2
|
+
[Symbol.iterator](): Generator<import("../scope.ts").getScope, Set<import("../../Tool.ts").Tool<import("../../index.ts").JSONKey>>, any>;
|
|
3
|
+
};
|
|
4
|
+
export declare const signal: {
|
|
5
|
+
[Symbol.iterator](): Generator<import("../scope.ts").getScope, AbortSignal, any>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { scope } from "../scope.js";
|
|
2
|
+
export const tools = {
|
|
3
|
+
*[Symbol.iterator]() {
|
|
4
|
+
const scope_ = yield* scope;
|
|
5
|
+
return scope_.tools;
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
export const signal = {
|
|
9
|
+
*[Symbol.iterator]() {
|
|
10
|
+
const scope_ = yield* scope;
|
|
11
|
+
return scope_.controller.signal;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=readers_derived.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readers_derived.js","sourceRoot":"","sources":["../../../actions/actions_derived/readers_derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAA;QAC3B,OAAO,MAAM,CAAC,KAAK,CAAA;IACrB,CAAC;CACF,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAA;QAC3B,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAA;IACjC,CAAC;CACF,CAAA"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Action } from "../Action.ts";
|
|
2
2
|
import type { MessageAppended } from "../events/MessageAppended.ts";
|
|
3
|
+
import type { MessageRemoved } from "../events/MessageRemoved.ts";
|
|
3
4
|
import type { Message, MessageContents, MessageRole, Messages } from "../Message.ts";
|
|
4
5
|
import type { Spec } from "../Spec.ts";
|
|
5
|
-
|
|
6
|
-
export interface appendMessage<M extends Message> extends Action<"append_message", Spec.Make<{
|
|
6
|
+
export interface appendMessage<M extends Message = Message> extends Action<"append_message", Spec.Make<{
|
|
7
7
|
Event: MessageAppended<M>;
|
|
8
8
|
}>> {
|
|
9
9
|
}
|
|
10
|
+
export interface removeMessage extends Action<"remove_message", Spec.Make<{
|
|
11
|
+
Event: MessageRemoved;
|
|
12
|
+
}>> {
|
|
13
|
+
}
|
|
10
14
|
export declare function appendMessage<R extends MessageRole>(role: R, content: MessageContents[R]): Generator<appendMessage<Messages[R]>, Generator<removeMessage, void>>;
|
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
import { Action } from "../Action.js";
|
|
2
|
-
import {
|
|
2
|
+
import { peekLast } from "../util/peekLast.js";
|
|
3
3
|
export function* appendMessage(role, content) {
|
|
4
4
|
return yield Action("append_message", (scope) => {
|
|
5
5
|
const message = {
|
|
6
6
|
role,
|
|
7
7
|
content,
|
|
8
8
|
}; // <-- why isn't this inferred?
|
|
9
|
+
const section = peekLast(scope.sections);
|
|
10
|
+
if (section) {
|
|
11
|
+
section.messages.add(message);
|
|
12
|
+
}
|
|
9
13
|
scope.event({
|
|
10
14
|
type: "message_appended",
|
|
11
15
|
message,
|
|
12
16
|
});
|
|
13
17
|
return {
|
|
14
18
|
...scope,
|
|
15
|
-
nextArg:
|
|
19
|
+
nextArg: (function* () {
|
|
20
|
+
return yield Action("remove_message", (scope) => {
|
|
21
|
+
scope.event({
|
|
22
|
+
type: "message_removed",
|
|
23
|
+
message,
|
|
24
|
+
});
|
|
25
|
+
const messages = new Set(scope.messages);
|
|
26
|
+
messages.delete(message);
|
|
27
|
+
if (section) {
|
|
28
|
+
section.messages.delete(message);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
...scope,
|
|
32
|
+
nextArg: message,
|
|
33
|
+
messages,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
})(),
|
|
16
37
|
messages: new Set([...scope.messages, message]),
|
|
17
38
|
};
|
|
18
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appendMessage.js","sourceRoot":"","sources":["../../actions/app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ChB,QAAQ;qBACT,CAAA;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,EAAE;YACJ,QAAQ,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SAChD,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/actions/branch.d.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
import { Action } from "../Action.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentLike, AgentLikeT, AgentLikeY } from "../Agent.ts";
|
|
3
3
|
import type { Spec } from "../Spec.ts";
|
|
4
4
|
import type { JSONKey } from "../util/JSONKey.ts";
|
|
5
|
-
export declare function branch<K extends JSONKey, Y extends Action, T>(key: K,
|
|
5
|
+
export declare function branch<K extends JSONKey, Y extends Action, T>(key: K, agentLike: AgentLike<Y, T>): Generator<Action<"branch", Spec.Make<{
|
|
6
6
|
Child: [Y[""]] extends [never] ? never : [K, Y[""]];
|
|
7
7
|
Entry: Y[""]["Entry"];
|
|
8
8
|
Value: T;
|
|
9
9
|
}>>, T>;
|
|
10
|
-
export declare function branch<K extends JSONKey, const A extends
|
|
10
|
+
export declare function branch<K extends JSONKey, const A extends Array<AgentLike>>(name: K, agentLikes: A): Generator<Action<"branch", Spec.Make<{
|
|
11
11
|
Child: [
|
|
12
12
|
K,
|
|
13
13
|
{
|
|
14
14
|
[L in keyof A]: Spec.Make<{
|
|
15
|
-
Child: [L,
|
|
16
|
-
Entry:
|
|
17
|
-
Value:
|
|
15
|
+
Child: [L, AgentLikeY<A[L]>[""]];
|
|
16
|
+
Entry: AgentLikeY<A[L]>[""]["Entry"];
|
|
17
|
+
Value: AgentLikeT<A[L]>;
|
|
18
18
|
}>;
|
|
19
19
|
}[keyof A]
|
|
20
20
|
];
|
|
21
|
-
Entry:
|
|
22
|
-
}>>,
|
|
23
|
-
export declare function branch<K extends JSONKey, A extends
|
|
21
|
+
Entry: AgentLikeY<A[number]>[""]["Entry"];
|
|
22
|
+
}>>, AgentLikesT<A>>;
|
|
23
|
+
export declare function branch<K extends JSONKey, A extends Record<JSONKey, AgentLike>>(name: K, agentLikes: A): Generator<Action<"branch", Spec.Make<{
|
|
24
24
|
Child: [
|
|
25
25
|
K,
|
|
26
26
|
{
|
|
27
27
|
[L in Exclude<keyof A, symbol>]: Spec.Make<{
|
|
28
|
-
Child: [L,
|
|
29
|
-
Entry:
|
|
30
|
-
Value:
|
|
28
|
+
Child: [L, AgentLikeY<A[L]>[""]];
|
|
29
|
+
Entry: AgentLikeY<A[L]>[""]["Entry"];
|
|
30
|
+
Value: AgentLikeT<A[L]>;
|
|
31
31
|
}>;
|
|
32
32
|
}[Exclude<keyof A, symbol>]
|
|
33
33
|
];
|
|
34
|
-
Entry:
|
|
35
|
-
}>>,
|
|
34
|
+
Entry: AgentLikeY<A[keyof A]>[""]["Entry"];
|
|
35
|
+
}>>, AgentLikesT<A>>;
|
|
36
|
+
export type AgentLikes = Array<AgentLike> | Record<JSONKey, AgentLike>;
|
|
37
|
+
export type AgentLikesT<A extends AgentLikes> = {
|
|
38
|
+
-readonly [K in keyof A]: A[K] extends AgentLike<Action, infer T> ? T : never;
|
|
39
|
+
} & {};
|
package/dist/actions/branch.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Action } from "../Action.js";
|
|
2
2
|
import { unwrapDeferred } from "../util/unwrapDeferred.js";
|
|
3
|
-
export function* branch(key,
|
|
3
|
+
export function* branch(key, a1) {
|
|
4
4
|
return yield Action("branch", async (scope) => {
|
|
5
|
-
if (typeof
|
|
5
|
+
if (typeof a1 === "function") {
|
|
6
6
|
const branchScope = scope.fork("branch", [key]);
|
|
7
|
-
const
|
|
8
|
-
const { value } = await branchScope.reduce(
|
|
7
|
+
const agent = unwrapDeferred(a1);
|
|
8
|
+
const { value } = await branchScope.reduce(agent);
|
|
9
9
|
branchScope.event({
|
|
10
10
|
type: "returned",
|
|
11
11
|
value,
|
|
@@ -15,20 +15,20 @@ export function* branch(key, implementation) {
|
|
|
15
15
|
nextArg: value,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
const armKeys = Array.isArray(
|
|
19
|
-
? Array.from({ length:
|
|
20
|
-
: Reflect.ownKeys(
|
|
18
|
+
const armKeys = Array.isArray(a1)
|
|
19
|
+
? Array.from({ length: a1.length }, (_0, i) => i)
|
|
20
|
+
: Reflect.ownKeys(a1);
|
|
21
21
|
const values = await Promise.all(armKeys.map(async (armKey) => {
|
|
22
22
|
const branchArmScope = scope.fork("branch_arm", [key, armKey]);
|
|
23
|
-
const
|
|
24
|
-
const { value } = await branchArmScope.reduce(
|
|
23
|
+
const agent = unwrapDeferred(a1[armKey]);
|
|
24
|
+
const { value } = await branchArmScope.reduce(agent);
|
|
25
25
|
branchArmScope.event({
|
|
26
26
|
type: "returned",
|
|
27
27
|
value,
|
|
28
28
|
});
|
|
29
29
|
return value;
|
|
30
30
|
}));
|
|
31
|
-
const value = Array.isArray(
|
|
31
|
+
const value = Array.isArray(a1)
|
|
32
32
|
? values
|
|
33
33
|
: Object.fromEntries(armKeys.map((key, i) => [key, values[i]]));
|
|
34
34
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../../actions/branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../../actions/branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AA0D1D,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,GAAY,EAAE,EAA0B;IAC9D,OAAO,MAAM,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAC5C,IAAI,OAAO,EAAE,KAAK,UAAU,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CAAC;YAC7B,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACjE,OAAO;YACL,GAAG,KAAK;YACR,OAAO,EAAE,KAAK;SACf,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/actions/catch.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Action } from "../Action.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentLike } from "../Agent.ts";
|
|
3
3
|
import type { Spec } from "../Spec.ts";
|
|
4
4
|
import type { JSONKey } from "../util/JSONKey.ts";
|
|
5
5
|
import type { Result } from "../util/Result.ts";
|
|
6
6
|
export { catch_ as catch };
|
|
7
|
-
declare function catch_<K extends JSONKey, Y extends Action, T>(key: K,
|
|
7
|
+
declare function catch_<K extends JSONKey, Y extends Action, T>(key: K, agentLike: AgentLike<Y, T>): Generator<Action<"catch", Spec.Make<{
|
|
8
8
|
Child: [K, Y[""]];
|
|
9
9
|
Value: T;
|
|
10
10
|
}>>, Result<T, Y[""]["Throw"]>>;
|
package/dist/actions/catch.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Action } from "../Action.js";
|
|
2
2
|
import { unwrapDeferred } from "../util/unwrapDeferred.js";
|
|
3
3
|
export { catch_ as catch };
|
|
4
|
-
function* catch_(key,
|
|
4
|
+
function* catch_(key, agentLike) {
|
|
5
5
|
return yield Action("catch", async (scope) => {
|
|
6
6
|
const catchScope = scope.fork("catch", [key]);
|
|
7
7
|
try {
|
|
8
|
-
const { value } = await catchScope.reduce(unwrapDeferred(
|
|
8
|
+
const { value } = await catchScope.reduce(unwrapDeferred(agentLike));
|
|
9
9
|
catchScope.event({
|
|
10
10
|
type: "returned",
|
|
11
11
|
value,
|
package/dist/actions/embed.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Action } from "../Action.js";
|
|
2
2
|
import { assert } from "../util/assert.js";
|
|
3
|
+
import { peekLast } from "../util/peekLast.js";
|
|
3
4
|
export function* embed(value) {
|
|
4
5
|
return yield Action("embed", async (scope) => {
|
|
5
|
-
const model = scope.embeddingModels
|
|
6
|
+
const model = peekLast(scope.embeddingModels);
|
|
6
7
|
assert(model);
|
|
7
8
|
scope.event({
|
|
8
9
|
type: "embedding_requested",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../actions/embed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../actions/embed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI9C,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,KAAa;IAClC,OAAO,MAAM,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAC3C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;QAC7C,MAAM,CAAC,KAAK,CAAC,CAAA;QACb,KAAK,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,qBAAqB;YAC3B,KAAK;SACN,CAAC,CAAA;QACF,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC1C,KAAK,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,UAAU;YAChB,KAAK;YACL,SAAS;SACV,CAAC,CAAA;QACF,OAAO;YACL,GAAG,KAAK;YACR,OAAO,EAAE,KAAK,CAAC,KAAK;SACrB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
2
|
import { Action } from "../Action.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Agent } from "../Agent.ts";
|
|
4
4
|
import type { ToolCalled } from "../events/ToolCalled.ts";
|
|
5
5
|
import type { ToolEnabled } from "../events/ToolEnabled.ts";
|
|
6
6
|
import type { Spec } from "../Spec.ts";
|
|
@@ -12,7 +12,7 @@ import { disableTool } from "./disableTool.ts";
|
|
|
12
12
|
export declare function enableTool<K extends JSONKey, A>(key: K, description: string, params: StandardSchemaV1<JSONObject, A>, implementation: (params: A) => PromiseOr<ToolResult>): Generator<Action<"enable_tool", Spec.Make<{
|
|
13
13
|
Event: ToolEnabled<K> | ToolCalled<K, A>;
|
|
14
14
|
}>>, Generator<disableTool<K>, void>>;
|
|
15
|
-
export declare function enableTool<K extends JSONKey, A, Y extends Action, T extends ToolResult>(key: K, description: string, params: StandardSchemaV1<JSONObject, A>, implementation: (params: A) =>
|
|
15
|
+
export declare function enableTool<K extends JSONKey, A, Y extends Action, T extends ToolResult>(key: K, description: string, params: StandardSchemaV1<JSONObject, A>, implementation: (params: A) => Agent<Y, T>): Generator<Action<"enable_tool", Spec.Make<{
|
|
16
16
|
Event: ToolEnabled<K> | ToolCalled<K, A>;
|
|
17
17
|
Child: [K, Y[""]];
|
|
18
18
|
Entry: Y[""]["Entry"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as L from "../L.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AgentAssertions } from "../testing/AgentAssertions.js";
|
|
3
3
|
import { emit } from "./emit.js";
|
|
4
4
|
import { enableTool } from "./enableTool.js";
|
|
5
5
|
const P = L.object({
|
|
@@ -8,16 +8,16 @@ const P = L.object({
|
|
|
8
8
|
});
|
|
9
9
|
const arrowTool = L.enableTool("Tool", "", P, (params) => {
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
AgentAssertions(arrowTool).assertSpec();
|
|
12
12
|
function* _0() {
|
|
13
13
|
const detach = yield* arrowTool;
|
|
14
|
-
|
|
14
|
+
AgentAssertions(detach).assertSpec();
|
|
15
15
|
}
|
|
16
16
|
const genTool = enableTool("tool-key", "", P, function* (params) {
|
|
17
17
|
yield* emit("Test");
|
|
18
18
|
return "";
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
AgentAssertions(genTool).assertSpec();
|
|
21
21
|
function* parent() {
|
|
22
22
|
yield* L.enableTool("parent-tool", "", P, () => { });
|
|
23
23
|
yield* L.branch("fork-key", {
|
|
@@ -26,5 +26,5 @@ function* parent() {
|
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
AgentAssertions(parent).assertSpec();
|
|
30
30
|
//# sourceMappingURL=enableTool.type-test.js.map
|
package/dist/actions/infer.d.ts
CHANGED
|
@@ -10,4 +10,6 @@ interface infer_<_T> extends Action<"infer", Spec.Make<{
|
|
|
10
10
|
Event: InferenceRequested | Inferred;
|
|
11
11
|
}>> {
|
|
12
12
|
}
|
|
13
|
-
declare
|
|
13
|
+
declare const infer_: (<T extends JSONValue>(type: StandardSchemaV1<JSONObject, T>) => Generator<infer_<T>, T>) & {
|
|
14
|
+
[Symbol.iterator](): Iterator<infer_<string>, string>;
|
|
15
|
+
};
|
package/dist/actions/infer.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { Action } from "../Action.js";
|
|
2
|
+
import { peekLast } from "../util/peekLast.js";
|
|
2
3
|
export { infer_ as infer };
|
|
3
|
-
function* infer_(type) {
|
|
4
|
+
const infer_ = Object.assign(function* infer_(type) {
|
|
5
|
+
return yield* impl(type);
|
|
6
|
+
}, {
|
|
7
|
+
*[Symbol.iterator]() {
|
|
8
|
+
return yield* impl();
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(infer_, "name", { value: "infer" });
|
|
12
|
+
function* impl(type) {
|
|
4
13
|
return yield Action("infer", async (scope) => {
|
|
5
14
|
scope.event({
|
|
6
15
|
type: "inference_requested",
|
|
7
16
|
});
|
|
8
|
-
const model = scope.languageModels
|
|
17
|
+
const model = peekLast(scope.languageModels);
|
|
9
18
|
scope = await scope.reduce(model.infer(type));
|
|
10
19
|
scope.event({
|
|
11
20
|
type: "inferred",
|
|
@@ -17,5 +26,4 @@ function* infer_(type) {
|
|
|
17
26
|
};
|
|
18
27
|
});
|
|
19
28
|
}
|
|
20
|
-
Object.defineProperty(infer_, "name", { value: "infer" });
|
|
21
29
|
//# sourceMappingURL=infer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer.js","sourceRoot":"","sources":["../../actions/infer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"infer.js","sourceRoot":"","sources":["../../actions/infer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAMrC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,CAAA;AAW1B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,QAAQ,CAAC,CAAC,MAAM,CAAsB,IAAqC;IACzE,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC,EACD;IACE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,OAAO,KAAK,CAAC,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;CACF,CACF,CAAA;AACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;AAEzD,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAwC;IACrD,OAAO,MAAM,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAC3C,KAAK,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,qBAAqB;SAC5B,CAAC,CAAA;QACF,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAE,CAAA;QAC7C,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;QAC7C,KAAK,CAAC,KAAK,CAAC;YACV,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAA;QACF,OAAO;YACL,GAAG,KAAK;YACR,OAAO,EAAE,KAAK,CAAC,KAAK;SACrB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 type { JSONKey } from "../util/JSONKey.ts";
|
|
7
|
+
import type { PromiseOr } from "../util/PromiseOr.ts";
|
|
8
|
+
import { type getScope } from "./scope.ts";
|
|
9
|
+
interface messages extends Iterable<getScope, Set<Message>> {
|
|
10
|
+
(messages: Array<Message>): Generator<Action<"set_messages", Spec.Make<{
|
|
11
|
+
Event: MessagesSet;
|
|
12
|
+
}>>, Array<Message>>;
|
|
13
|
+
(setter: (messages: Array<Message>) => PromiseOr<Array<Message>>): Generator<Action<"set_messages", Spec.Make<{
|
|
14
|
+
Event: MessagesSet;
|
|
15
|
+
}>>, Array<Message>>;
|
|
16
|
+
<K extends JSONKey, Y extends Action>(key: K, setter: (messages: Array<Message>) => Agent<Y, void>): Generator<Action<"set_messages", Spec.Make<{
|
|
17
|
+
Event: MessagesSet;
|
|
18
|
+
Child: [K, Y[""]];
|
|
19
|
+
Entry: Y[""]["Entry"];
|
|
20
|
+
Value: Array<Message>;
|
|
21
|
+
}>>, Array<Message>>;
|
|
22
|
+
}
|
|
23
|
+
export declare const messages: messages;
|
|
24
|
+
export {};
|