liminal 0.11.1 → 0.13.0
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 +18 -0
- package/L.ts +5 -4
- package/{pretty.ts → LPretty.ts} +3 -3
- package/Strand.ts +24 -4
- package/append.ts +1 -1
- package/assistant.ts +3 -1
- package/assistantSchema.ts +60 -0
- 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 +5 -4
- package/dist/L.js +5 -4
- 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/{assistantStruct.d.ts → assistantSchema.d.ts} +3 -2
- package/dist/assistantSchema.js +44 -0
- package/dist/assistantSchema.js.map +1 -0
- 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 +5 -4
- package/dist/userJson.js.map +1 -1
- package/dist/{internal → util}/JsonValue.d.ts +3 -0
- package/dist/util/JsonValue.js +109 -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 +24 -0
- package/dist/util/Taggable.js.map +1 -0
- package/dist/util/fixRaw.d.ts +4 -0
- package/dist/util/fixRaw.js +75 -0
- package/dist/util/fixRaw.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 +9 -7
- package/util/JsonValue.ts +144 -0
- package/util/Sequence.ts +9 -0
- package/util/Taggable.ts +52 -0
- package/util/fixRaw.ts +93 -0
- package/Sequence.ts +0 -14
- package/assistantStruct.ts +0 -34
- package/dist/Sequence.d.ts +0 -2
- package/dist/Sequence.js +0 -2
- package/dist/Sequence.js.map +0 -1
- package/dist/assistantStruct.js +0 -22
- package/dist/assistantStruct.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,9 @@
|
|
|
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 = (
|
|
5
|
+
export const userJson = Effect.fnUntraced(function* (value, schema) {
|
|
6
|
+
const encoded = schema ? encodeJsonc(schema)(value) : JSON.stringify(value, null, 2);
|
|
7
|
+
return yield* user `\`\`\`json${schema ? "c" : ""}${"\n"}${encoded}${"\n"}\`\`\``;
|
|
8
|
+
});
|
|
8
9
|
//# 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,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,KAAK,EAAE,MAAM;IACxF,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACpF,OAAO,KAAK,CAAC,CAAC,IAAI,CAAA,aAAa,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,QAAQ,CAAA;AAClF,CAAC,CAAC,CAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
1
3
|
export type JsonValue = null | boolean | number | string | JsonValueArray | JsonValueObject;
|
|
2
4
|
export type JsonValueArray = Array<JsonValue> | ReadonlyArray<JsonValue>;
|
|
3
5
|
export type JsonValueObject = {
|
|
4
6
|
[key: string]: JsonValue;
|
|
5
7
|
};
|
|
8
|
+
export declare const encodeJsonc: <A, I extends JsonValue>(schema: Schema.Schema<A, I>) => (value: A) => Effect.Effect<string>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { pipe } from "effect/Function";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
6
|
+
export const encodeJsonc = (schema) => {
|
|
7
|
+
const encoder = encodeAst(SchemaAST.encodedBoundAST(schema.ast));
|
|
8
|
+
return (value) => encoder(value, new EncodeJsoncContext(0));
|
|
9
|
+
};
|
|
10
|
+
class EncodeJsoncContext {
|
|
11
|
+
depth;
|
|
12
|
+
indentation;
|
|
13
|
+
childIndentation;
|
|
14
|
+
constructor(depth) {
|
|
15
|
+
this.depth = depth;
|
|
16
|
+
this.indentation = " ".repeat(depth * 2);
|
|
17
|
+
this.childIndentation = " ".repeat((depth + 1) * 2);
|
|
18
|
+
}
|
|
19
|
+
next = () => new EncodeJsoncContext(this.depth + 1);
|
|
20
|
+
comment = (type) => Option.match(SchemaAST.getDescriptionAnnotation(type), {
|
|
21
|
+
onSome: (v) => {
|
|
22
|
+
v = v.trim();
|
|
23
|
+
if (v) {
|
|
24
|
+
return `// ${v}\n${this.childIndentation}`;
|
|
25
|
+
}
|
|
26
|
+
return "";
|
|
27
|
+
},
|
|
28
|
+
onNone: () => "",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const encodeAst = (ast, refinement) => {
|
|
32
|
+
switch (ast._tag) {
|
|
33
|
+
case "TypeLiteral": {
|
|
34
|
+
return Effect.fnUntraced(function* (value, ctx) {
|
|
35
|
+
const props = yield* Effect.all(ast.propertySignatures.map(Effect.fnUntraced(function* ({ name, type }) {
|
|
36
|
+
if (typeof name === "symbol")
|
|
37
|
+
throw 0;
|
|
38
|
+
const child = yield* encodeAst(type)(value[name], ctx.next());
|
|
39
|
+
return `${ctx.comment(refinement ?? type)}${name}: ${child}`;
|
|
40
|
+
}))).pipe(Effect.map((v) => v.join(`,\n${ctx.childIndentation}`)));
|
|
41
|
+
return `{\n${ctx.childIndentation}${props}\n${ctx.indentation}}`;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
case "StringKeyword": {
|
|
45
|
+
return (value) => Effect.succeed(`"${value}"`);
|
|
46
|
+
}
|
|
47
|
+
case "BooleanKeyword":
|
|
48
|
+
case "NumberKeyword": {
|
|
49
|
+
return (value) => Effect.succeed(String(value));
|
|
50
|
+
}
|
|
51
|
+
case "Refinement": {
|
|
52
|
+
return encodeAst(ast.from, refinement ?? ast);
|
|
53
|
+
}
|
|
54
|
+
case "UnknownKeyword":
|
|
55
|
+
case "AnyKeyword": {
|
|
56
|
+
return (value, ctx) => Effect.succeed(JSON
|
|
57
|
+
.stringify(value, null, 2)
|
|
58
|
+
.split("\n")
|
|
59
|
+
.map((line, i) => i ? ctx.indentation.concat(line) : line)
|
|
60
|
+
.join("\n"));
|
|
61
|
+
}
|
|
62
|
+
case "Union": {
|
|
63
|
+
const { types } = ast;
|
|
64
|
+
const guards = types.map((ast) => pipe(ast, Schema.make, Schema.is));
|
|
65
|
+
return (value, ctx) => {
|
|
66
|
+
for (let i = 0; i < types.length; i++) {
|
|
67
|
+
const guard = guards[i];
|
|
68
|
+
if (guard(value)) {
|
|
69
|
+
return encodeAst(types[i])(value, ctx);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw 0;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
case "Literal": {
|
|
76
|
+
const { literal } = ast;
|
|
77
|
+
const v = (() => {
|
|
78
|
+
switch (typeof literal) {
|
|
79
|
+
case "boolean":
|
|
80
|
+
case "number": {
|
|
81
|
+
return String(literal);
|
|
82
|
+
}
|
|
83
|
+
case "string": {
|
|
84
|
+
return `"${literal}"`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (literal === null) {
|
|
88
|
+
return "null";
|
|
89
|
+
}
|
|
90
|
+
console.log({ literal });
|
|
91
|
+
throw 0;
|
|
92
|
+
})();
|
|
93
|
+
return () => Effect.succeed(v);
|
|
94
|
+
}
|
|
95
|
+
case "TupleType": {
|
|
96
|
+
const { elements, rest } = ast;
|
|
97
|
+
return (value, ctx) => Effect.all((elements.length ? elements : rest).map(Effect.fnUntraced(function* (element, i) {
|
|
98
|
+
const child = yield* encodeAst(element.type)(value[i], ctx.next());
|
|
99
|
+
return `${ctx.comment(refinement ?? element.type)}${child}`;
|
|
100
|
+
}))).pipe(Effect.map((v) => `[\n${ctx.childIndentation}${v.join(`,\n${ctx.childIndentation}`)}\n${ctx.indentation}]`));
|
|
101
|
+
}
|
|
102
|
+
case "Suspend": {
|
|
103
|
+
return encodeAst(ast.f());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
console.log({ ast });
|
|
107
|
+
throw 0;
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=JsonValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonValue.js","sourceRoot":"","sources":["../../util/JsonValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAA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AAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;gBAC9E,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,CAAA;YAC7D,CAAC,CAAC,CACH,CAAC,CAAC,IAAI,CACL,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,gBAAgB,EAAE,CAAC,KAAK,GAAG,CAAC,WAAW,GAAG,CAAC,CAC5G,CAAA;QACL,CAAC;QACD,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAA;QAC3B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IACpB,MAAM,CAAC,CAAA;AACT,CAAC,CAAA"}
|
|
@@ -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,24 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { fixRaw } from "./fixRaw.js";
|
|
3
|
+
export const normalize = Effect.fnUntraced(function* (a0, aRest) {
|
|
4
|
+
let a0_;
|
|
5
|
+
if (Effect.isEffect(a0)) {
|
|
6
|
+
a0_ = yield* a0;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
a0_ = a0;
|
|
10
|
+
}
|
|
11
|
+
if (!a0_)
|
|
12
|
+
return undefined;
|
|
13
|
+
const aRest_ = yield* Effect.all(aRest.map((v) => Effect.isEffect(v)
|
|
14
|
+
? v
|
|
15
|
+
: Effect.succeed(v)));
|
|
16
|
+
if (typeof a0_ === "string") {
|
|
17
|
+
if (aRest_.length === 0) {
|
|
18
|
+
return a0_;
|
|
19
|
+
}
|
|
20
|
+
return [a0_, ...aRest_].join("");
|
|
21
|
+
}
|
|
22
|
+
return fixRaw(a0_, aRest_);
|
|
23
|
+
});
|
|
24
|
+
//# 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;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAkBpC,MAAM,CAAC,MAAM,SAAS,GAUoD,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,EAAE,EAAE,KAAK;IAC7G,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,CACd,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CACtB,CACwC,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,EAAE,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const LEADING_SPACE_RE = /^([ \t]*)/;
|
|
2
|
+
const INDENTATION_RE = /^\n([ \t]+)/;
|
|
3
|
+
const ESCAPE_SEQ_RE = /\\([`${\\]|\n)/g;
|
|
4
|
+
const LAST_INDENTATION_RE = /\n[ \t]+$/;
|
|
5
|
+
export const fixRaw = (strings, values) => {
|
|
6
|
+
const fixedStrings = fixTemplateStrings(strings);
|
|
7
|
+
const rawArr = fixedStrings.raw;
|
|
8
|
+
const valuesLength = values.length;
|
|
9
|
+
const resultParts = new Array(Math.max(1, rawArr.length * 2 - 1));
|
|
10
|
+
let resultIndex = 0;
|
|
11
|
+
for (let i = 0; i < rawArr.length; i++) {
|
|
12
|
+
const str = rawArr[i] || "";
|
|
13
|
+
resultParts[resultIndex++] = str;
|
|
14
|
+
// Only process values for non-final segments.
|
|
15
|
+
if (i < valuesLength) {
|
|
16
|
+
const value = String(values[i]);
|
|
17
|
+
// If value has line breaks, we should indent it.
|
|
18
|
+
if (value.includes("\n")) {
|
|
19
|
+
const lastNewlineIndex = str.lastIndexOf("\n");
|
|
20
|
+
if (lastNewlineIndex !== -1) {
|
|
21
|
+
// Extract the indentation after the last newline.
|
|
22
|
+
const textAfterLastNewline = str.substring(lastNewlineIndex + 1);
|
|
23
|
+
const leadingSpaceMatch = LEADING_SPACE_RE.exec(textAfterLastNewline);
|
|
24
|
+
const indentationToApply = leadingSpaceMatch && leadingSpaceMatch[1] ? leadingSpaceMatch[1] : "";
|
|
25
|
+
if (indentationToApply) {
|
|
26
|
+
// Split the value into lines once.
|
|
27
|
+
const lines = value.split("\n");
|
|
28
|
+
const linesLength = lines.length;
|
|
29
|
+
// First line doesn't need indentation.
|
|
30
|
+
resultParts[resultIndex++] = lines[0];
|
|
31
|
+
// Apply indentation to subsequent lines.
|
|
32
|
+
for (let j = 1; j < linesLength; j++) {
|
|
33
|
+
resultParts[resultIndex++] = "\n" + indentationToApply + lines[j];
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// For simple values or when no indentation is needed.
|
|
40
|
+
resultParts[resultIndex++] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Combine all parts at once
|
|
44
|
+
return resultParts.slice(0, resultIndex).join("");
|
|
45
|
+
};
|
|
46
|
+
export const fixTemplateStrings = (template) => {
|
|
47
|
+
const leadingIndentMatch = INDENTATION_RE.exec(template.raw[0]);
|
|
48
|
+
const indentation = leadingIndentMatch?.[1];
|
|
49
|
+
const rawLength = template.raw.length;
|
|
50
|
+
const raw = new Array(rawLength);
|
|
51
|
+
for (let i = 0; i < rawLength; i++) {
|
|
52
|
+
let str = template.raw[i];
|
|
53
|
+
// Only perform common indentation replacements if needed.
|
|
54
|
+
if (indentation) {
|
|
55
|
+
// Remove leading newline and indentation in the first segment.
|
|
56
|
+
if (i === 0) {
|
|
57
|
+
str = str.slice(indentation.length + 1);
|
|
58
|
+
}
|
|
59
|
+
// Use a simple string replacement with a regular expression for better performance.
|
|
60
|
+
str = str.replaceAll(`\n${indentation}`, "\n");
|
|
61
|
+
}
|
|
62
|
+
// Replace common escape sequences in a single pass.
|
|
63
|
+
str = str.replace(ESCAPE_SEQ_RE, (_match, char) => {
|
|
64
|
+
// Keep the escaped newline replacement separate for clarity.
|
|
65
|
+
return char === "\n" ? "" : char;
|
|
66
|
+
});
|
|
67
|
+
// Handle trailing spaces only for the last segment.
|
|
68
|
+
if (indentation && i === rawLength - 1) {
|
|
69
|
+
str = str.replace(LAST_INDENTATION_RE, "");
|
|
70
|
+
}
|
|
71
|
+
raw[i] = str;
|
|
72
|
+
}
|
|
73
|
+
return { raw };
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=fixRaw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixRaw.js","sourceRoot":"","sources":["../../util/fixRaw.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,WAAW,CAAA;AACpC,MAAM,cAAc,GAAG,aAAa,CAAA;AACpC,MAAM,aAAa,GAAG,iBAAiB,CAAA;AACvC,MAAM,mBAAmB,GAAG,WAAW,CAAA;AAEvC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAA6B,EAAE,MAAsB,EAAU,EAAE;IACtF,MAAM,YAAY,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAChD,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAA;IAC/B,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAA;IAElC,MAAM,WAAW,GAAG,IA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;YACzC,CAAC;YACD,oFAAoF;YACpF,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,KAAK,WAAW,EAAE,EAAE,IAAI,CAAC,CAAA;QAChD,CAAC;QAED,oDAAoD;QACpD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YAChD,6DAA6D;YAC7D,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QAClC,CAAC,CAAC,CAAA;QAEF,oDAAoD;QACpD,IAAI,WAAW,IAAI,CAAC,KAAK,SAAS,GAAG,CAAC,EAAE,CAAC;YACvC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAA;QAC5C,CAAC;QAED,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;IACd,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,CAAA;AAChB,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 listen: <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.13.0",
|
|
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,14 @@
|
|
|
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> =
|
|
10
|
+
schema?: Schema.Schema<A, I>,
|
|
11
|
+
) => Effect.Effect<void, never, Strand.Strand> = Effect.fnUntraced(function*(value, schema) {
|
|
12
|
+
const encoded = schema ? encodeJsonc(schema)(value) : JSON.stringify(value, null, 2)
|
|
13
|
+
return yield* user`\`\`\`json${schema ? "c" : ""}${"\n"}${encoded}${"\n"}\`\`\``
|
|
14
|
+
})
|