liminal 0.12.2 → 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 +6 -0
- package/L.ts +1 -1
- package/assistantSchema.ts +60 -0
- package/dist/L.d.ts +1 -1
- package/dist/L.js +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/handle.d.ts +1 -1
- package/dist/handle.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/userJson.js +4 -1
- package/dist/userJson.js.map +1 -1
- package/dist/util/JsonValue.d.ts +2 -1
- package/dist/util/JsonValue.js +73 -46
- package/dist/util/JsonValue.js.map +1 -1
- package/dist/util/Taggable.d.ts +1 -1
- package/dist/util/Taggable.js +6 -3
- package/dist/util/Taggable.js.map +1 -1
- package/dist/util/fixRaw.d.ts +4 -0
- package/dist/util/fixRaw.js +75 -0
- package/dist/util/fixRaw.js.map +1 -0
- package/handle.ts +1 -1
- package/package.json +1 -1
- package/userJson.ts +4 -2
- package/util/JsonValue.ts +101 -54
- package/util/Taggable.ts +9 -4
- package/util/fixRaw.ts +93 -0
- package/assistantStruct.ts +0 -34
- package/dist/assistantStruct.js +0 -22
- package/dist/assistantStruct.js.map +0 -1
package/dist/userJson.js
CHANGED
|
@@ -2,5 +2,8 @@ import * as Effect from "effect/Effect";
|
|
|
2
2
|
import { user } from "./user.js";
|
|
3
3
|
import { encodeJsonc } from "./util/JsonValue.js";
|
|
4
4
|
/** Stringify and append some JSON as a user message to the conversation. */
|
|
5
|
-
export const userJson = (value, schema)
|
|
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
|
+
});
|
|
6
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;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,
|
|
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"}
|
package/dist/util/JsonValue.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
1
2
|
import * as Schema from "effect/Schema";
|
|
2
3
|
export type JsonValue = null | boolean | number | string | JsonValueArray | JsonValueObject;
|
|
3
4
|
export type JsonValueArray = Array<JsonValue> | ReadonlyArray<JsonValue>;
|
|
4
5
|
export type JsonValueObject = {
|
|
5
6
|
[key: string]: JsonValue;
|
|
6
7
|
};
|
|
7
|
-
export declare const encodeJsonc: <A, I extends JsonValue>(schema: Schema.Schema<A, I>) => (value: A) => string
|
|
8
|
+
export declare const encodeJsonc: <A, I extends JsonValue>(schema: Schema.Schema<A, I>) => (value: A) => Effect.Effect<string>;
|
package/dist/util/JsonValue.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import { pipe } from "effect/Function";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
1
4
|
import * as Schema from "effect/Schema";
|
|
2
5
|
import * as SchemaAST from "effect/SchemaAST";
|
|
3
6
|
export const encodeJsonc = (schema) => {
|
|
4
|
-
const encoder =
|
|
7
|
+
const encoder = encodeAst(SchemaAST.encodedBoundAST(schema.ast));
|
|
5
8
|
return (value) => encoder(value, new EncodeJsoncContext(0));
|
|
6
9
|
};
|
|
7
10
|
class EncodeJsoncContext {
|
|
@@ -14,69 +17,93 @@ class EncodeJsoncContext {
|
|
|
14
17
|
this.childIndentation = " ".repeat((depth + 1) * 2);
|
|
15
18
|
}
|
|
16
19
|
next = () => new EncodeJsoncContext(this.depth + 1);
|
|
17
|
-
comment = (type) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
});
|
|
24
30
|
}
|
|
25
|
-
const
|
|
31
|
+
const encodeAst = (ast, refinement) => {
|
|
26
32
|
switch (ast._tag) {
|
|
27
33
|
case "TypeLiteral": {
|
|
28
|
-
return (value, ctx)
|
|
29
|
-
const props = ast.propertySignatures
|
|
30
|
-
.map(({ name, type }) => {
|
|
34
|
+
return Effect.fnUntraced(function* (value, ctx) {
|
|
35
|
+
const props = yield* Effect.all(ast.propertySignatures.map(Effect.fnUntraced(function* ({ name, type }) {
|
|
31
36
|
if (typeof name === "symbol")
|
|
32
37
|
throw 0;
|
|
33
|
-
const child =
|
|
34
|
-
return `${ctx.comment(type)}${name}: ${child}`;
|
|
35
|
-
})
|
|
36
|
-
.join(`,\n${ctx.childIndentation}`);
|
|
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}`)));
|
|
37
41
|
return `{\n${ctx.childIndentation}${props}\n${ctx.indentation}}`;
|
|
38
|
-
};
|
|
42
|
+
});
|
|
39
43
|
}
|
|
40
44
|
case "StringKeyword": {
|
|
41
|
-
return (value) => `"${value}"
|
|
45
|
+
return (value) => Effect.succeed(`"${value}"`);
|
|
42
46
|
}
|
|
47
|
+
case "BooleanKeyword":
|
|
43
48
|
case "NumberKeyword": {
|
|
44
|
-
return (value) =>
|
|
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
|
+
};
|
|
45
74
|
}
|
|
46
75
|
case "Literal": {
|
|
47
76
|
const { literal } = ast;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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);
|
|
58
94
|
}
|
|
59
95
|
case "TupleType": {
|
|
60
96
|
const { elements, rest } = ast;
|
|
61
|
-
return (value, ctx) => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}).join(`,\n${ctx.childIndentation}`);
|
|
66
|
-
return `[\n${ctx.childIndentation}${e}\n${ctx.indentation}]`;
|
|
67
|
-
};
|
|
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}]`));
|
|
68
101
|
}
|
|
69
|
-
|
|
70
|
-
|
|
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;
|
|
102
|
+
case "Suspend": {
|
|
103
|
+
return encodeAst(ast.f());
|
|
78
104
|
}
|
|
79
105
|
}
|
|
80
|
-
|
|
106
|
+
console.log({ ast });
|
|
107
|
+
throw 0;
|
|
81
108
|
};
|
|
82
109
|
//# sourceMappingURL=JsonValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonValue.js","sourceRoot":"","sources":["../../util/JsonValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAQ7C,MAAM,CAAC,MAAM,WAAW,
|
|
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,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAQ7C,MAAM,CAAC,MAAM,WAAW,GAEmB,CAAC,MAAM,EAAE,EAAE;IACpD,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAChE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAA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5G,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"}
|
package/dist/util/Taggable.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import * as Effect from "effect/Effect";
|
|
|
2
2
|
/** Append a user message to the conversation. */
|
|
3
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
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,
|
|
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
6
|
export {};
|
package/dist/util/Taggable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
|
|
2
|
+
import { fixRaw } from "./fixRaw.js";
|
|
3
|
+
export const normalize = Effect.fnUntraced(function* (a0, aRest) {
|
|
3
4
|
let a0_;
|
|
4
5
|
if (Effect.isEffect(a0)) {
|
|
5
6
|
a0_ = yield* a0;
|
|
@@ -9,13 +10,15 @@ export const normalize = Effect.fnUntraced(function* (a0, ...aRest) {
|
|
|
9
10
|
}
|
|
10
11
|
if (!a0_)
|
|
11
12
|
return undefined;
|
|
12
|
-
const aRest_ = yield* Effect.all(aRest.map((v) => Effect.isEffect(v)
|
|
13
|
+
const aRest_ = yield* Effect.all(aRest.map((v) => Effect.isEffect(v)
|
|
14
|
+
? v
|
|
15
|
+
: Effect.succeed(v)));
|
|
13
16
|
if (typeof a0_ === "string") {
|
|
14
17
|
if (aRest_.length === 0) {
|
|
15
18
|
return a0_;
|
|
16
19
|
}
|
|
17
20
|
return [a0_, ...aRest_].join("");
|
|
18
21
|
}
|
|
19
|
-
return
|
|
22
|
+
return fixRaw(a0_, aRest_);
|
|
20
23
|
});
|
|
21
24
|
//# sourceMappingURL=Taggable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Taggable.js","sourceRoot":"","sources":["../../util/Taggable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
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,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACjE,IAAI,WAAW,GAAG,CAAC,CAAA;IAEnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAC3B,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,GAAG,CAAA;QAEhC,8CAA8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I,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/handle.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { LEvent } from "./LEvent.ts"
|
|
|
6
6
|
import { Strand } from "./Strand.ts"
|
|
7
7
|
|
|
8
8
|
/** Attach an event handler to process the events of the current strand. */
|
|
9
|
-
export const
|
|
9
|
+
export const listen: <A, E, R>(
|
|
10
10
|
f: (event: LEvent) => Effect.Effect<A, E, R>,
|
|
11
11
|
) => Effect.Effect<RuntimeFiber<void, E>, never, Strand | R | Scope.Scope> = Effect.fnUntraced(function*(f) {
|
|
12
12
|
const latch = yield* Effect.makeLatch(false)
|
package/package.json
CHANGED
package/userJson.ts
CHANGED
|
@@ -8,5 +8,7 @@ import { encodeJsonc, type JsonValue } from "./util/JsonValue.ts"
|
|
|
8
8
|
export const userJson: <A, I extends JsonValue>(
|
|
9
9
|
value: A,
|
|
10
10
|
schema?: Schema.Schema<A, I>,
|
|
11
|
-
) => Effect.Effect<void, never, Strand.Strand> = (value, schema)
|
|
12
|
-
|
|
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
|
+
})
|
package/util/JsonValue.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect"
|
|
2
|
+
import { pipe } from "effect/Function"
|
|
3
|
+
import * as Option from "effect/Option"
|
|
1
4
|
import * as Schema from "effect/Schema"
|
|
2
5
|
import * as SchemaAST from "effect/SchemaAST"
|
|
3
6
|
|
|
@@ -7,10 +10,10 @@ export type JsonValueArray = Array<JsonValue> | ReadonlyArray<JsonValue>
|
|
|
7
10
|
|
|
8
11
|
export type JsonValueObject = { [key: string]: JsonValue }
|
|
9
12
|
|
|
10
|
-
export const encodeJsonc: <A, I extends JsonValue>(
|
|
11
|
-
schema,
|
|
12
|
-
) => {
|
|
13
|
-
const encoder =
|
|
13
|
+
export const encodeJsonc: <A, I extends JsonValue>(
|
|
14
|
+
schema: Schema.Schema<A, I>,
|
|
15
|
+
) => (value: A) => Effect.Effect<string> = (schema) => {
|
|
16
|
+
const encoder = encodeAst(SchemaAST.encodedBoundAST(schema.ast))
|
|
14
17
|
return (value) => encoder(value, new EncodeJsoncContext(0))
|
|
15
18
|
}
|
|
16
19
|
|
|
@@ -26,72 +29,116 @@ class EncodeJsoncContext {
|
|
|
26
29
|
|
|
27
30
|
next = () => new EncodeJsoncContext(this.depth + 1)
|
|
28
31
|
|
|
29
|
-
comment = (type: SchemaAST.AST): string =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
comment = (type: SchemaAST.AST): string =>
|
|
33
|
+
Option.match(SchemaAST.getDescriptionAnnotation(type), {
|
|
34
|
+
onSome: (v) => {
|
|
35
|
+
v = v.trim()
|
|
36
|
+
if (v) {
|
|
37
|
+
return `// ${v}\n${this.childIndentation}`
|
|
38
|
+
}
|
|
39
|
+
return ""
|
|
40
|
+
},
|
|
41
|
+
onNone: () => "",
|
|
42
|
+
})
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
const
|
|
45
|
+
const encodeAst: (
|
|
46
|
+
ast: SchemaAST.AST,
|
|
47
|
+
refinement?: SchemaAST.Refinement,
|
|
48
|
+
) => (value: unknown, ctx: EncodeJsoncContext) => Effect.Effect<string> = (ast, refinement) => {
|
|
39
49
|
switch (ast._tag) {
|
|
40
50
|
case "TypeLiteral": {
|
|
41
|
-
return (value, ctx)
|
|
42
|
-
const props =
|
|
43
|
-
.map(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
return Effect.fnUntraced(function*(value, ctx) {
|
|
52
|
+
const props = yield* Effect.all(
|
|
53
|
+
ast.propertySignatures.map(
|
|
54
|
+
Effect.fnUntraced(function*({ name, type }) {
|
|
55
|
+
if (typeof name === "symbol") throw 0
|
|
56
|
+
const child = yield* encodeAst(type)((value as never)[name], ctx.next())
|
|
57
|
+
return `${ctx.comment(refinement ?? type)}${name}: ${child}`
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
).pipe(
|
|
61
|
+
Effect.map((v) => v.join(`,\n${ctx.childIndentation}`)),
|
|
62
|
+
)
|
|
50
63
|
return `{\n${ctx.childIndentation}${props}\n${ctx.indentation}}`
|
|
51
|
-
}
|
|
64
|
+
})
|
|
52
65
|
}
|
|
53
66
|
case "StringKeyword": {
|
|
54
|
-
return (value) => `"${value}"`
|
|
67
|
+
return (value) => Effect.succeed(`"${value}"`)
|
|
55
68
|
}
|
|
69
|
+
case "BooleanKeyword":
|
|
56
70
|
case "NumberKeyword": {
|
|
57
|
-
return (value) =>
|
|
71
|
+
return (value) => Effect.succeed(String(value))
|
|
72
|
+
}
|
|
73
|
+
case "Refinement": {
|
|
74
|
+
return encodeAst(ast.from, refinement ?? ast)
|
|
75
|
+
}
|
|
76
|
+
case "UnknownKeyword":
|
|
77
|
+
case "AnyKeyword": {
|
|
78
|
+
return (value, ctx) =>
|
|
79
|
+
Effect.succeed(
|
|
80
|
+
JSON
|
|
81
|
+
.stringify(value, null, 2)
|
|
82
|
+
.split("\n")
|
|
83
|
+
.map((line, i) => i ? ctx.indentation.concat(line) : line)
|
|
84
|
+
.join("\n"),
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
case "Union": {
|
|
88
|
+
const { types } = ast
|
|
89
|
+
const guards = types.map((ast) =>
|
|
90
|
+
pipe(
|
|
91
|
+
ast,
|
|
92
|
+
Schema.make,
|
|
93
|
+
Schema.is,
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
return (value, ctx) => {
|
|
97
|
+
for (let i = 0; i < types.length; i++) {
|
|
98
|
+
const guard = guards[i]!
|
|
99
|
+
if (guard(value)) {
|
|
100
|
+
return encodeAst(types[i]!)(value, ctx)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw 0
|
|
104
|
+
}
|
|
58
105
|
}
|
|
59
106
|
case "Literal": {
|
|
60
107
|
const { literal } = ast
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
const v = (() => {
|
|
109
|
+
switch (typeof literal) {
|
|
110
|
+
case "boolean":
|
|
111
|
+
case "number": {
|
|
112
|
+
return String(literal)
|
|
113
|
+
}
|
|
114
|
+
case "string": {
|
|
115
|
+
return `"${literal}"`
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (literal === null) {
|
|
119
|
+
return "null"
|
|
120
|
+
}
|
|
121
|
+
console.log({ literal })
|
|
122
|
+
throw 0
|
|
123
|
+
})()
|
|
124
|
+
return () => Effect.succeed(v)
|
|
71
125
|
}
|
|
72
126
|
case "TupleType": {
|
|
73
127
|
const { elements, rest } = ast
|
|
74
|
-
return (value, ctx) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
128
|
+
return (value, ctx) =>
|
|
129
|
+
Effect.all((elements.length ? elements : rest).map(
|
|
130
|
+
Effect.fnUntraced(function*(element, i) {
|
|
131
|
+
const child = yield* encodeAst(element.type)((value as never)[i]!, ctx.next())
|
|
132
|
+
return `${ctx.comment(refinement ?? element.type)}${child}`
|
|
133
|
+
}),
|
|
134
|
+
)).pipe(
|
|
135
|
+
Effect.map((v) => `[\n${ctx.childIndentation}${v.join(`,\n${ctx.childIndentation}`)}\n${ctx.indentation}]`),
|
|
136
|
+
)
|
|
81
137
|
}
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
138
|
+
case "Suspend": {
|
|
139
|
+
return encodeAst(ast.f())
|
|
94
140
|
}
|
|
95
141
|
}
|
|
96
|
-
|
|
142
|
+
console.log({ ast })
|
|
143
|
+
throw 0
|
|
97
144
|
}
|
package/util/Taggable.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
|
+
import { fixRaw } from "./fixRaw.ts"
|
|
2
3
|
|
|
3
4
|
/** Append a user message to the conversation. */
|
|
4
5
|
export type Taggable<A, E, R> = <L extends Array<unknown>, E1 = never, R1 = never>(
|
|
@@ -25,8 +26,8 @@ export const normalize: <
|
|
|
25
26
|
L extends Array<unknown>,
|
|
26
27
|
>(
|
|
27
28
|
a0: A0,
|
|
28
|
-
|
|
29
|
-
) => Effect.Effect<string | (undefined extends A0 ? undefined : never)> = Effect.fnUntraced(function*(a0,
|
|
29
|
+
aRest: L,
|
|
30
|
+
) => Effect.Effect<string | (undefined extends A0 ? undefined : never)> = Effect.fnUntraced(function*(a0, aRest) {
|
|
30
31
|
let a0_: TemplateStringsArray | string | undefined
|
|
31
32
|
if (Effect.isEffect(a0)) {
|
|
32
33
|
a0_ = yield* a0 as Effect.Effect<TemplateStringsArray | string | undefined>
|
|
@@ -35,7 +36,11 @@ export const normalize: <
|
|
|
35
36
|
}
|
|
36
37
|
if (!a0_) return undefined as never
|
|
37
38
|
const aRest_ = yield* Effect.all(
|
|
38
|
-
aRest.map((v) =>
|
|
39
|
+
aRest.map((v) =>
|
|
40
|
+
Effect.isEffect(v)
|
|
41
|
+
? v
|
|
42
|
+
: Effect.succeed(v)
|
|
43
|
+
),
|
|
39
44
|
) as never as Effect.Effect<Array<unknown>>
|
|
40
45
|
if (typeof a0_ === "string") {
|
|
41
46
|
if (aRest_.length === 0) {
|
|
@@ -43,5 +48,5 @@ export const normalize: <
|
|
|
43
48
|
}
|
|
44
49
|
return [a0_, ...aRest_].join("")
|
|
45
50
|
}
|
|
46
|
-
return
|
|
51
|
+
return fixRaw(a0_, aRest_)
|
|
47
52
|
})
|