liminal 0.11.1 → 0.12.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/CHANGELOG.md +12 -0
- package/L.ts +4 -3
- package/{pretty.ts → LPretty.ts} +3 -3
- package/Strand.ts +24 -4
- package/append.ts +1 -1
- package/assistant.ts +3 -1
- package/assistantStream.ts +25 -0
- package/branch.ts +3 -3
- package/clear.ts +1 -1
- package/disable.ts +5 -0
- package/dist/L.d.ts +4 -3
- package/dist/L.js +4 -3
- package/dist/L.js.map +1 -1
- package/dist/LPretty.d.ts +4 -0
- package/dist/{pretty.js → LPretty.js} +4 -4
- package/dist/LPretty.js.map +1 -0
- package/dist/Strand.d.ts +9 -3
- package/dist/Strand.js +11 -1
- package/dist/Strand.js.map +1 -1
- package/dist/append.d.ts +1 -1
- package/dist/append.js +0 -1
- package/dist/append.js.map +1 -1
- package/dist/assistant.js +3 -1
- package/dist/assistant.js.map +1 -1
- package/dist/assistantStream.d.ts +7 -0
- package/dist/assistantStream.js +17 -0
- package/dist/assistantStream.js.map +1 -0
- package/dist/branch.d.ts +1 -1
- package/dist/branch.js +2 -2
- package/dist/branch.js.map +1 -1
- package/dist/clear.d.ts +1 -1
- package/dist/clear.js +0 -1
- package/dist/clear.js.map +1 -1
- package/dist/disable.d.ts +4 -0
- package/dist/disable.js +3 -0
- package/dist/disable.js.map +1 -0
- package/dist/enable.d.ts +5 -0
- package/dist/enable.js +3 -0
- package/dist/enable.js.map +1 -0
- package/dist/events.d.ts +2 -2
- package/dist/events.js +2 -2
- package/dist/events.js.map +1 -1
- package/dist/handle.d.ts +7 -0
- package/dist/handle.js +14 -0
- package/dist/handle.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sequence.d.ts +2 -0
- package/dist/{sequence_.js → sequence.js} +1 -1
- package/dist/sequence.js.map +1 -0
- package/dist/strand_.d.ts +1 -1
- package/dist/strand_.js +3 -13
- package/dist/strand_.js.map +1 -1
- package/dist/system.d.ts +3 -3
- package/dist/system.js +3 -2
- package/dist/system.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/user.d.ts +3 -4
- package/dist/user.js +8 -9
- package/dist/user.js.map +1 -1
- package/dist/user.test.js.map +1 -0
- package/dist/userJson.d.ts +4 -4
- package/dist/userJson.js +2 -4
- package/dist/userJson.js.map +1 -1
- package/dist/{internal → util}/JsonValue.d.ts +2 -0
- package/dist/util/JsonValue.js +82 -0
- package/dist/util/JsonValue.js.map +1 -0
- package/dist/util/Sequence.d.ts +2 -0
- package/dist/util/Sequence.js +2 -0
- package/dist/util/Sequence.js.map +1 -0
- package/dist/util/Taggable.d.ts +6 -0
- package/dist/util/Taggable.js +21 -0
- package/dist/util/Taggable.js.map +1 -0
- package/enable.ts +8 -0
- package/events.ts +5 -4
- package/handle.ts +25 -0
- package/index.ts +1 -1
- package/package.json +4 -4
- package/{sequence_.ts → sequence.ts} +1 -1
- package/strand_.ts +3 -17
- package/system.ts +8 -9
- package/user.test.ts +30 -0
- package/user.ts +15 -11
- package/userJson.ts +7 -7
- package/util/JsonValue.ts +97 -0
- package/util/Sequence.ts +9 -0
- package/util/Taggable.ts +47 -0
- package/Sequence.ts +0 -14
- package/dist/Sequence.d.ts +0 -2
- package/dist/Sequence.js +0 -2
- package/dist/Sequence.js.map +0 -1
- package/dist/internal/JsonValue.js +0 -2
- package/dist/internal/JsonValue.js.map +0 -1
- package/dist/internal/Taggable.d.ts +0 -11
- package/dist/internal/Taggable.js +0 -2
- package/dist/internal/Taggable.js.map +0 -1
- package/dist/pretty.d.ts +0 -2
- package/dist/pretty.js.map +0 -1
- package/dist/reduce.d.ts +0 -4
- package/dist/reduce.js +0 -20
- package/dist/reduce.js.map +0 -1
- package/dist/sequence_.d.ts +0 -2
- package/dist/sequence_.js.map +0 -1
- package/dist/todo.test.js +0 -3
- package/dist/todo.test.js.map +0 -1
- package/internal/JsonValue.ts +0 -5
- package/internal/Taggable.ts +0 -17
- package/reduce.ts +0 -32
- package/todo.test.ts +0 -3
- package/tsconfig.json +0 -18
- /package/dist/{todo.test.d.ts → user.test.d.ts} +0 -0
package/dist/user.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type Taggable } from "./
|
|
3
|
-
import * as Strand from "./Strand.ts";
|
|
1
|
+
import type { Strand } from "./Strand.ts";
|
|
2
|
+
import { type Taggable } from "./util/Taggable.ts";
|
|
4
3
|
/** Append a user message to the conversation. */
|
|
5
|
-
export declare const user: Taggable<
|
|
4
|
+
export declare const user: Taggable<void, never, Strand>;
|
package/dist/user.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { TextPart, UserMessage } from "@effect/ai/AiInput";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import { append } from "./append.js";
|
|
4
|
-
import { normalize } from "./
|
|
5
|
-
import * as Strand from "./Strand.js";
|
|
4
|
+
import { normalize } from "./util/Taggable.js";
|
|
6
5
|
/** Append a user message to the conversation. */
|
|
7
|
-
export const user = (a0, ...aRest) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
text
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export const user = (a0, ...aRest) => normalize(a0, aRest).pipe(Effect.flatMap((text) => text
|
|
7
|
+
? append(UserMessage.make({
|
|
8
|
+
parts: [
|
|
9
|
+
TextPart.make({ text }),
|
|
10
|
+
],
|
|
11
|
+
}))
|
|
12
|
+
: Effect.succeed(undefined)));
|
|
14
13
|
//# sourceMappingURL=user.js.map
|
package/dist/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,SAAS,EAAiB,MAAM,oBAAoB,CAAA;AAE7D,iDAAiD;AACjD,MAAM,CAAC,MAAM,IAAI,GAAkC,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAClE,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CACvB,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACtB,IAAI;IACF,CAAC,CAAC,MAAM,CACN,WAAW,CAAC,IAAI,CAAC;QACf,KAAK,EAAE;YACL,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;SACxB;KACF,CAAC,CACH;IACD,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAC9B,CACF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.test.js","sourceRoot":"","sources":["../user.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,GAAG,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,KAAK,CAAC,CAAC,IAAI,CAAA,GAAG,CAAA;IACd,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAChB,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC;QACpC,WAAW,CAAC,IAAI,CAAC;YACf,KAAK,EAAE;gBACL,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,GAAG;iBACV,CAAC;aACH;SACF,CAAC;QACF,WAAW,CAAC,IAAI,CAAC;YACf,KAAK,EAAE;gBACL,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,GAAG;iBACV,CAAC;aACH;SACF,CAAC;KACH,CAAC,CAAA;AACJ,CAAC,CAAC,CAAC,IAAI,CACL,MAAM,CACP,CAAC,CAAA"}
|
package/dist/userJson.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Schema from "effect/Schema";
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
2
|
+
import type * as Schema from "effect/Schema";
|
|
3
|
+
import type * as Strand from "./Strand.ts";
|
|
4
|
+
import { type JsonValue } from "./util/JsonValue.ts";
|
|
5
5
|
/** Stringify and append some JSON as a user message to the conversation. */
|
|
6
|
-
export declare const userJson: <A, I extends
|
|
6
|
+
export declare const userJson: <A, I extends JsonValue>(value: A, schema?: Schema.Schema<A, I>) => Effect.Effect<void, never, Strand.Strand>;
|
package/dist/userJson.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Schema from "effect/Schema";
|
|
3
|
-
import * as Strand from "./Strand.js";
|
|
4
2
|
import { user } from "./user.js";
|
|
5
|
-
|
|
3
|
+
import { encodeJsonc } from "./util/JsonValue.js";
|
|
6
4
|
/** Stringify and append some JSON as a user message to the conversation. */
|
|
7
|
-
export const userJson = (value) => user `\`\`\`
|
|
5
|
+
export const userJson = (value, schema) => user `\`\`\`json${schema ? "c" : ""}\n${schema ? encodeJsonc(schema)(value) : JSON.stringify(value, null, 2)}\n\`\`\``;
|
|
8
6
|
//# sourceMappingURL=userJson.js.map
|
package/dist/userJson.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userJson.js","sourceRoot":"","sources":["../userJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"userJson.js","sourceRoot":"","sources":["../userJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAA;AAEjE,4EAA4E;AAC5E,MAAM,CAAC,MAAM,QAAQ,GAG4B,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CACjE,IAAI,CAAA,aAAa,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
1
2
|
export type JsonValue = null | boolean | number | string | JsonValueArray | JsonValueObject;
|
|
2
3
|
export type JsonValueArray = Array<JsonValue> | ReadonlyArray<JsonValue>;
|
|
3
4
|
export type JsonValueObject = {
|
|
4
5
|
[key: string]: JsonValue;
|
|
5
6
|
};
|
|
7
|
+
export declare const encodeJsonc: <A, I extends JsonValue>(schema: Schema.Schema<A, I>) => (value: A) => string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
3
|
+
export const encodeJsonc = (schema) => {
|
|
4
|
+
const encoder = encodeAstJsonc(SchemaAST.encodedAST(schema.ast));
|
|
5
|
+
return (value) => encoder(value, new EncodeJsoncContext(0));
|
|
6
|
+
};
|
|
7
|
+
class EncodeJsoncContext {
|
|
8
|
+
depth;
|
|
9
|
+
indentation;
|
|
10
|
+
childIndentation;
|
|
11
|
+
constructor(depth) {
|
|
12
|
+
this.depth = depth;
|
|
13
|
+
this.indentation = " ".repeat(depth * 2);
|
|
14
|
+
this.childIndentation = " ".repeat((depth + 1) * 2);
|
|
15
|
+
}
|
|
16
|
+
next = () => new EncodeJsoncContext(this.depth + 1);
|
|
17
|
+
comment = (type) => {
|
|
18
|
+
const description = extractAnnotation(type)?.trim();
|
|
19
|
+
if (description) {
|
|
20
|
+
return `// ${description}\n${this.childIndentation}`;
|
|
21
|
+
}
|
|
22
|
+
return "";
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const encodeAstJsonc = (ast) => {
|
|
26
|
+
switch (ast._tag) {
|
|
27
|
+
case "TypeLiteral": {
|
|
28
|
+
return (value, ctx) => {
|
|
29
|
+
const props = ast.propertySignatures
|
|
30
|
+
.map(({ name, type }) => {
|
|
31
|
+
if (typeof name === "symbol")
|
|
32
|
+
throw 0;
|
|
33
|
+
const child = encodeAstJsonc(type)(value[name], ctx.next());
|
|
34
|
+
return `${ctx.comment(type)}${name}: ${child}`;
|
|
35
|
+
})
|
|
36
|
+
.join(`,\n${ctx.childIndentation}`);
|
|
37
|
+
return `{\n${ctx.childIndentation}${props}\n${ctx.indentation}}`;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
case "StringKeyword": {
|
|
41
|
+
return (value) => `"${value}"`;
|
|
42
|
+
}
|
|
43
|
+
case "NumberKeyword": {
|
|
44
|
+
return (value) => `${value}`;
|
|
45
|
+
}
|
|
46
|
+
case "Literal": {
|
|
47
|
+
const { literal } = ast;
|
|
48
|
+
if (typeof literal === "string") {
|
|
49
|
+
return () => `"${literal}"`;
|
|
50
|
+
}
|
|
51
|
+
if (typeof literal === "number" || typeof literal === "boolean") {
|
|
52
|
+
return () => String(literal);
|
|
53
|
+
}
|
|
54
|
+
if (literal === null) {
|
|
55
|
+
return () => "null";
|
|
56
|
+
}
|
|
57
|
+
throw 0;
|
|
58
|
+
}
|
|
59
|
+
case "TupleType": {
|
|
60
|
+
const { elements, rest } = ast;
|
|
61
|
+
return (value, ctx) => {
|
|
62
|
+
const e = (elements.length ? elements : rest).map((element, i) => {
|
|
63
|
+
const child = encodeAstJsonc(element.type)(value[i], ctx.next());
|
|
64
|
+
return `${ctx.comment(element.type)}${child}`;
|
|
65
|
+
}).join(`,\n${ctx.childIndentation}`);
|
|
66
|
+
return `[\n${ctx.childIndentation}${e}\n${ctx.indentation}]`;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
console.log(ast._tag);
|
|
71
|
+
throw 0;
|
|
72
|
+
};
|
|
73
|
+
const extractAnnotation = ({ annotations }) => {
|
|
74
|
+
if (SchemaAST.JSONSchemaAnnotationId in annotations) {
|
|
75
|
+
const jsonSchemaAnnotations = annotations[SchemaAST.JSONSchemaAnnotationId];
|
|
76
|
+
if (jsonSchemaAnnotations) {
|
|
77
|
+
return jsonSchemaAnnotations.description;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=JsonValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonValue.js","sourceRoot":"","sources":["../../util/JsonValue.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { Effect } from "effect/Effect";
|
|
2
|
+
export type Sequence<I = never, O = never> = <Arg extends Array<Effect<any, any, any>>>(...steps: Arg) => Effect<Arg extends [] ? void : Arg extends [...infer _0, infer L extends Effect<any, any, any>] ? Effect.Success<L> : never, Effect.Error<Arg[number]>, Exclude<Effect.Context<Arg[number]>, I> | O>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../../util/Sequence.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
/** Append a user message to the conversation. */
|
|
3
|
+
export type Taggable<A, E, R> = <L extends Array<unknown>, E1 = never, R1 = never>(template?: TemplateStringsArray | string | Effect.Effect<string | undefined, E1, R1> | undefined, ...substitutions: L) => Effect.Effect<A, ([ExtractEffect<L>] extends [never] ? never : Effect.Effect.Error<ExtractEffect<L>>) | E | E1, ([ExtractEffect<L>] extends [never] ? never : Effect.Effect.Context<ExtractEffect<L>>) | R | R1>;
|
|
4
|
+
type ExtractEffect<T extends Array<unknown>> = Extract<T[number], Effect.All.EffectAny>;
|
|
5
|
+
export declare const normalize: <A0 extends TemplateStringsArray | string | Effect.Effect<string | undefined, any, any> | undefined, L extends Array<unknown>>(a0: A0, ...aRest: L) => Effect.Effect<string | (undefined extends A0 ? undefined : never)>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
export const normalize = Effect.fnUntraced(function* (a0, ...aRest) {
|
|
3
|
+
let a0_;
|
|
4
|
+
if (Effect.isEffect(a0)) {
|
|
5
|
+
a0_ = yield* a0;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
a0_ = a0;
|
|
9
|
+
}
|
|
10
|
+
if (!a0_)
|
|
11
|
+
return undefined;
|
|
12
|
+
const aRest_ = yield* Effect.all(aRest.map((v) => Effect.isEffect(v) ? v : Effect.succeed(v)));
|
|
13
|
+
if (typeof a0_ === "string") {
|
|
14
|
+
if (aRest_.length === 0) {
|
|
15
|
+
return a0_;
|
|
16
|
+
}
|
|
17
|
+
return [a0_, ...aRest_].join("");
|
|
18
|
+
}
|
|
19
|
+
return String.raw(a0_, ...aRest);
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=Taggable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Taggable.js","sourceRoot":"","sources":["../../util/Taggable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAkBvC,MAAM,CAAC,MAAM,SAAS,GAUoD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,EAAE,EAAE,GAAG,KAAK;IAChH,IAAI,GAA8C,CAAA;IAClD,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QACxB,GAAG,GAAG,KAAK,CAAC,CAAC,EAA8D,CAAA;IAC7E,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,EAAE,CAAA;IACV,CAAC;IACD,IAAI,CAAC,GAAG;QAAE,OAAO,SAAkB,CAAA;IACnC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAC9B,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CACnB,CAAA;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,GAAG,CAAA;QACZ,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAA;AAClC,CAAC,CAAC,CAAA"}
|
package/enable.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as AiTool from "@effect/ai/AiTool"
|
|
2
|
+
import type { AiToolkit } from "@effect/ai/AiToolkit"
|
|
3
|
+
import * as Effect from "effect/Effect"
|
|
4
|
+
import type { Strand } from "./Strand.ts"
|
|
5
|
+
|
|
6
|
+
export declare const enable: <Tools extends AiTool.Any>(
|
|
7
|
+
toolkit: AiToolkit<Tools>,
|
|
8
|
+
) => Effect.Effect<never, never, AiTool.Handler<Tools["name"]> | Strand>
|
package/events.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
2
|
import * as Stream from "effect/Stream"
|
|
3
|
-
import type { LEvent } from "./LEvent"
|
|
3
|
+
import type { LEvent } from "./LEvent.ts"
|
|
4
4
|
import { Strand } from "./Strand.ts"
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
export const events: Stream.Stream<LEvent, never, Strand> =
|
|
8
|
-
Effect.map(
|
|
6
|
+
/** A stream of events from the current strand. */
|
|
7
|
+
export const events: Stream.Stream<LEvent, never, Strand> = Strand.pipe(
|
|
8
|
+
Effect.map(({ events }) => Stream.fromPubSub(events)),
|
|
9
|
+
Stream.unwrap,
|
|
9
10
|
)
|
package/handle.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
import type { RuntimeFiber } from "effect/Fiber"
|
|
3
|
+
import * as Scope from "effect/Scope"
|
|
4
|
+
import * as Stream from "effect/Stream"
|
|
5
|
+
import type { LEvent } from "./LEvent.ts"
|
|
6
|
+
import { Strand } from "./Strand.ts"
|
|
7
|
+
|
|
8
|
+
/** Attach an event handler to process the events of the current strand. */
|
|
9
|
+
export const handle: <A, E, R>(
|
|
10
|
+
f: (event: LEvent) => Effect.Effect<A, E, R>,
|
|
11
|
+
) => Effect.Effect<RuntimeFiber<void, E>, never, Strand | R | Scope.Scope> = Effect.fnUntraced(function*(f) {
|
|
12
|
+
const latch = yield* Effect.makeLatch(false)
|
|
13
|
+
const { events } = yield* Strand
|
|
14
|
+
const dequeue = yield* events.subscribe
|
|
15
|
+
const fiber = yield* latch.open.pipe(
|
|
16
|
+
Effect.zipRight(
|
|
17
|
+
Stream.fromQueue(dequeue).pipe(
|
|
18
|
+
Stream.runForEach(f),
|
|
19
|
+
Effect.fork,
|
|
20
|
+
),
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
yield* latch.await
|
|
24
|
+
return fiber
|
|
25
|
+
})
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"access": "public",
|
|
8
8
|
"provenance": true
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.12.2",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
|
-
"description": "
|
|
19
|
+
"description": "An Effect AI toolkit for LLM integration and conversation state management.",
|
|
20
20
|
"exports": {
|
|
21
21
|
".": "./index.ts",
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@effect/ai": "^0.
|
|
26
|
-
"effect": "^3.17.
|
|
25
|
+
"@effect/ai": "^0.25.0",
|
|
26
|
+
"effect": "^3.17.6"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/strand_.ts
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
2
|
import { flow } from "effect/Function"
|
|
3
|
-
import
|
|
4
|
-
import * as PubSub from "effect/PubSub"
|
|
5
|
-
import type { LEvent } from "./LEvent.ts"
|
|
6
|
-
import { type Sequence } from "./Sequence.ts"
|
|
7
|
-
import { sequence } from "./sequence_.ts"
|
|
3
|
+
import { sequence } from "./sequence.ts"
|
|
8
4
|
import { Strand } from "./Strand.ts"
|
|
5
|
+
import { type Sequence } from "./util/Sequence.ts"
|
|
9
6
|
|
|
10
7
|
/** Isolate the effect with a new strand in context. */
|
|
11
8
|
export const strand: Sequence<Strand> = flow(
|
|
12
9
|
sequence,
|
|
13
|
-
Effect.
|
|
14
|
-
Strand,
|
|
15
|
-
Effect.gen(function*() {
|
|
16
|
-
return Strand.of({
|
|
17
|
-
parent: yield* Effect.serviceOption(Strand),
|
|
18
|
-
events: yield* PubSub.unbounded<LEvent>(),
|
|
19
|
-
system: Option.none(),
|
|
20
|
-
messages: [],
|
|
21
|
-
tools: [],
|
|
22
|
-
})
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
10
|
+
Effect.provide(Strand.layer()),
|
|
25
11
|
)
|
package/system.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
2
|
import * as Option from "effect/Option"
|
|
3
|
-
import { normalize, type TaggableNullable } from "./internal/Taggable.ts"
|
|
4
3
|
import { Strand } from "./Strand.ts"
|
|
4
|
+
import { normalize, type Taggable } from "./util/Taggable.ts"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
6
|
+
/** Set the system instruction for the current strand. */
|
|
7
|
+
export const system: Taggable<Option.Option<string>, never, Strand> = Effect.fnUntraced(function*(a0, ...aRest) {
|
|
8
|
+
const conversation = yield* Strand
|
|
9
|
+
const { system } = conversation
|
|
10
|
+
conversation.system = a0 ? Option.some(yield* normalize(a0, aRest)) : Option.none()
|
|
11
|
+
return system
|
|
12
|
+
})
|
package/user.test.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TextPart, UserMessage } from "@effect/ai/AiInput"
|
|
2
|
+
import { expect, it } from "@effect/vitest"
|
|
3
|
+
import * as Effect from "effect/Effect"
|
|
4
|
+
import { messages } from "./messages.ts"
|
|
5
|
+
import { strand } from "./strand_.ts"
|
|
6
|
+
import { user } from "./user.ts"
|
|
7
|
+
|
|
8
|
+
it.effect("test success", () =>
|
|
9
|
+
Effect.gen(function*() {
|
|
10
|
+
yield* user`A`
|
|
11
|
+
yield* user("B")
|
|
12
|
+
expect(yield* messages).toStrictEqual([
|
|
13
|
+
UserMessage.make({
|
|
14
|
+
parts: [
|
|
15
|
+
TextPart.make({
|
|
16
|
+
text: "A",
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
}),
|
|
20
|
+
UserMessage.make({
|
|
21
|
+
parts: [
|
|
22
|
+
TextPart.make({
|
|
23
|
+
text: "B",
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
])
|
|
28
|
+
}).pipe(
|
|
29
|
+
strand,
|
|
30
|
+
))
|
package/user.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { TextPart, UserMessage } from "@effect/ai/AiInput"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
3
|
import { append } from "./append.ts"
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import type { Strand } from "./Strand.ts"
|
|
5
|
+
import { normalize, type Taggable } from "./util/Taggable.ts"
|
|
6
6
|
|
|
7
7
|
/** Append a user message to the conversation. */
|
|
8
|
-
export const user: Taggable<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
export const user: Taggable<void, never, Strand> = (a0, ...aRest) =>
|
|
9
|
+
normalize(a0, aRest).pipe(
|
|
10
|
+
Effect.flatMap((text) =>
|
|
11
|
+
text
|
|
12
|
+
? append(
|
|
13
|
+
UserMessage.make({
|
|
14
|
+
parts: [
|
|
15
|
+
TextPart.make({ text }),
|
|
16
|
+
],
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
: Effect.succeed(undefined)
|
|
20
|
+
),
|
|
17
21
|
)
|
package/userJson.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
|
-
import * as Schema from "effect/Schema"
|
|
3
|
-
import type
|
|
4
|
-
import * as Strand from "./Strand.ts"
|
|
2
|
+
import type * as Schema from "effect/Schema"
|
|
3
|
+
import type * as Strand from "./Strand.ts"
|
|
5
4
|
import { user } from "./user.ts"
|
|
5
|
+
import { encodeJsonc, type JsonValue } from "./util/JsonValue.ts"
|
|
6
6
|
|
|
7
|
-
// TODO: serialize with comments from schema
|
|
8
7
|
/** Stringify and append some JSON as a user message to the conversation. */
|
|
9
|
-
export const userJson: <A, I extends
|
|
8
|
+
export const userJson: <A, I extends JsonValue>(
|
|
10
9
|
value: A,
|
|
11
|
-
schema?: Schema.Schema<A, I
|
|
12
|
-
) => Effect.Effect<void, never, Strand.Strand> = (value) =>
|
|
10
|
+
schema?: Schema.Schema<A, I>,
|
|
11
|
+
) => Effect.Effect<void, never, Strand.Strand> = (value, schema) =>
|
|
12
|
+
user`\`\`\`json${schema ? "c" : ""}\n${schema ? encodeJsonc(schema)(value) : JSON.stringify(value, null, 2)}\n\`\`\``
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema"
|
|
2
|
+
import * as SchemaAST from "effect/SchemaAST"
|
|
3
|
+
|
|
4
|
+
export type JsonValue = null | boolean | number | string | JsonValueArray | JsonValueObject
|
|
5
|
+
|
|
6
|
+
export type JsonValueArray = Array<JsonValue> | ReadonlyArray<JsonValue>
|
|
7
|
+
|
|
8
|
+
export type JsonValueObject = { [key: string]: JsonValue }
|
|
9
|
+
|
|
10
|
+
export const encodeJsonc: <A, I extends JsonValue>(schema: Schema.Schema<A, I>) => (value: A) => string = (
|
|
11
|
+
schema,
|
|
12
|
+
) => {
|
|
13
|
+
const encoder = encodeAstJsonc(SchemaAST.encodedAST(schema.ast))
|
|
14
|
+
return (value) => encoder(value, new EncodeJsoncContext(0))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class EncodeJsoncContext {
|
|
18
|
+
readonly depth: number
|
|
19
|
+
readonly indentation: string
|
|
20
|
+
readonly childIndentation: string
|
|
21
|
+
constructor(depth: number) {
|
|
22
|
+
this.depth = depth
|
|
23
|
+
this.indentation = " ".repeat(depth * 2)
|
|
24
|
+
this.childIndentation = " ".repeat((depth + 1) * 2)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
next = () => new EncodeJsoncContext(this.depth + 1)
|
|
28
|
+
|
|
29
|
+
comment = (type: SchemaAST.AST): string => {
|
|
30
|
+
const description = extractAnnotation(type)?.trim()
|
|
31
|
+
if (description) {
|
|
32
|
+
return `// ${description}\n${this.childIndentation}`
|
|
33
|
+
}
|
|
34
|
+
return ""
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const encodeAstJsonc: (ast: SchemaAST.AST) => (value: unknown, ctx: EncodeJsoncContext) => string = (ast) => {
|
|
39
|
+
switch (ast._tag) {
|
|
40
|
+
case "TypeLiteral": {
|
|
41
|
+
return (value, ctx) => {
|
|
42
|
+
const props = ast.propertySignatures
|
|
43
|
+
.map(({ name, type }) => {
|
|
44
|
+
if (typeof name === "symbol") throw 0
|
|
45
|
+
|
|
46
|
+
const child = encodeAstJsonc(type)((value as never)[name], ctx.next())
|
|
47
|
+
return `${ctx.comment(type)}${name}: ${child}`
|
|
48
|
+
})
|
|
49
|
+
.join(`,\n${ctx.childIndentation}`)
|
|
50
|
+
return `{\n${ctx.childIndentation}${props}\n${ctx.indentation}}`
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
case "StringKeyword": {
|
|
54
|
+
return (value) => `"${value}"`
|
|
55
|
+
}
|
|
56
|
+
case "NumberKeyword": {
|
|
57
|
+
return (value) => `${value}`
|
|
58
|
+
}
|
|
59
|
+
case "Literal": {
|
|
60
|
+
const { literal } = ast
|
|
61
|
+
if (typeof literal === "string") {
|
|
62
|
+
return () => `"${literal}"`
|
|
63
|
+
}
|
|
64
|
+
if (typeof literal === "number" || typeof literal === "boolean") {
|
|
65
|
+
return () => String(literal)
|
|
66
|
+
}
|
|
67
|
+
if (literal === null) {
|
|
68
|
+
return () => "null"
|
|
69
|
+
}
|
|
70
|
+
throw 0
|
|
71
|
+
}
|
|
72
|
+
case "TupleType": {
|
|
73
|
+
const { elements, rest } = ast
|
|
74
|
+
return (value, ctx) => {
|
|
75
|
+
const e = (elements.length ? elements : rest).map((element, i) => {
|
|
76
|
+
const child = encodeAstJsonc(element.type)((value as never)[i]!, ctx.next())
|
|
77
|
+
return `${ctx.comment(element.type)}${child}`
|
|
78
|
+
}).join(`,\n${ctx.childIndentation}`)
|
|
79
|
+
return `[\n${ctx.childIndentation}${e}\n${ctx.indentation}]`
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
console.log(ast._tag)
|
|
84
|
+
throw 0
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const extractAnnotation = ({ annotations }: SchemaAST.AST): string | undefined => {
|
|
88
|
+
if (SchemaAST.JSONSchemaAnnotationId in annotations) {
|
|
89
|
+
const jsonSchemaAnnotations = annotations[SchemaAST.JSONSchemaAnnotationId] as
|
|
90
|
+
| SchemaAST.Annotations
|
|
91
|
+
| undefined
|
|
92
|
+
if (jsonSchemaAnnotations) {
|
|
93
|
+
return jsonSchemaAnnotations.description as string
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return
|
|
97
|
+
}
|
package/util/Sequence.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Effect } from "effect/Effect"
|
|
2
|
+
|
|
3
|
+
export type Sequence<I = never, O = never> = <Arg extends Array<Effect<any, any, any>>>(
|
|
4
|
+
...steps: Arg
|
|
5
|
+
) => Effect<
|
|
6
|
+
Arg extends [] ? void : Arg extends [...infer _0, infer L extends Effect<any, any, any>] ? Effect.Success<L> : never,
|
|
7
|
+
Effect.Error<Arg[number]>,
|
|
8
|
+
Exclude<Effect.Context<Arg[number]>, I> | O
|
|
9
|
+
>
|
package/util/Taggable.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
|
|
3
|
+
/** Append a user message to the conversation. */
|
|
4
|
+
export type Taggable<A, E, R> = <L extends Array<unknown>, E1 = never, R1 = never>(
|
|
5
|
+
template?:
|
|
6
|
+
| TemplateStringsArray
|
|
7
|
+
| string
|
|
8
|
+
| Effect.Effect<string | undefined, E1, R1>
|
|
9
|
+
| undefined,
|
|
10
|
+
...substitutions: L
|
|
11
|
+
) => Effect.Effect<
|
|
12
|
+
A,
|
|
13
|
+
([ExtractEffect<L>] extends [never] ? never : Effect.Effect.Error<ExtractEffect<L>>) | E | E1,
|
|
14
|
+
([ExtractEffect<L>] extends [never] ? never : Effect.Effect.Context<ExtractEffect<L>>) | R | R1
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
type ExtractEffect<T extends Array<unknown>> = Extract<T[number], Effect.All.EffectAny>
|
|
18
|
+
|
|
19
|
+
export const normalize: <
|
|
20
|
+
A0 extends
|
|
21
|
+
| TemplateStringsArray
|
|
22
|
+
| string
|
|
23
|
+
| Effect.Effect<string | undefined, any, any>
|
|
24
|
+
| undefined,
|
|
25
|
+
L extends Array<unknown>,
|
|
26
|
+
>(
|
|
27
|
+
a0: A0,
|
|
28
|
+
...aRest: L
|
|
29
|
+
) => Effect.Effect<string | (undefined extends A0 ? undefined : never)> = Effect.fnUntraced(function*(a0, ...aRest) {
|
|
30
|
+
let a0_: TemplateStringsArray | string | undefined
|
|
31
|
+
if (Effect.isEffect(a0)) {
|
|
32
|
+
a0_ = yield* a0 as Effect.Effect<TemplateStringsArray | string | undefined>
|
|
33
|
+
} else {
|
|
34
|
+
a0_ = a0
|
|
35
|
+
}
|
|
36
|
+
if (!a0_) return undefined as never
|
|
37
|
+
const aRest_ = yield* Effect.all(
|
|
38
|
+
aRest.map((v) => Effect.isEffect(v) ? v : Effect.succeed(v)),
|
|
39
|
+
) as never as Effect.Effect<Array<unknown>>
|
|
40
|
+
if (typeof a0_ === "string") {
|
|
41
|
+
if (aRest_.length === 0) {
|
|
42
|
+
return a0_
|
|
43
|
+
}
|
|
44
|
+
return [a0_, ...aRest_].join("")
|
|
45
|
+
}
|
|
46
|
+
return String.raw(a0_, ...aRest)
|
|
47
|
+
})
|
package/Sequence.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect"
|
|
2
|
-
|
|
3
|
-
export type Sequence<P = never, R1 = never> = <Arg extends Array<Effect.Effect<any, any, any>>>(
|
|
4
|
-
...steps: Arg
|
|
5
|
-
) => Effect.Effect<
|
|
6
|
-
Arg extends [] ? void
|
|
7
|
-
: [Arg extends [...infer _0, infer L] ? L : never] extends [Effect.Effect<infer A, infer _E, infer _R>] ? A
|
|
8
|
-
: never,
|
|
9
|
-
Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never,
|
|
10
|
-
Exclude<
|
|
11
|
-
Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never,
|
|
12
|
-
P
|
|
13
|
-
> | R1
|
|
14
|
-
>
|
package/dist/Sequence.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
export type Sequence<P = never, R1 = never> = <Arg extends Array<Effect.Effect<any, any, any>>>(...steps: Arg) => Effect.Effect<Arg extends [] ? void : [Arg extends [...infer _0, infer L] ? L : never] extends [Effect.Effect<infer A, infer _E, infer _R>] ? A : never, Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer E, infer _R>] ? E : never, Exclude<Arg[number] extends never ? never : [Arg[number]] extends [Effect.Effect<infer _A, infer _E, infer R>] ? R : never, P> | R1>;
|
package/dist/Sequence.js
DELETED
package/dist/Sequence.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sequence.js","sourceRoot":"","sources":["../Sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA"}
|