liminal 0.9.0 → 0.10.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/L.ts +8 -81
  3. package/LEvent.ts +17 -0
  4. package/Strand.ts +37 -38
  5. package/Taggable.ts +17 -0
  6. package/append.ts +13 -0
  7. package/assistant.ts +24 -0
  8. package/assistantStruct.ts +33 -0
  9. package/dist/L.d.ts +8 -15
  10. package/dist/L.js +8 -56
  11. package/dist/L.js.map +1 -1
  12. package/dist/LEvent.d.ts +22 -0
  13. package/dist/LEvent.js +13 -0
  14. package/dist/LEvent.js.map +1 -0
  15. package/dist/Strand.d.ts +12 -17
  16. package/dist/Strand.js +19 -17
  17. package/dist/Strand.js.map +1 -1
  18. package/dist/Taggable.d.ts +11 -0
  19. package/dist/Taggable.js +2 -0
  20. package/dist/Taggable.js.map +1 -0
  21. package/dist/append.d.ts +5 -0
  22. package/dist/append.js +11 -0
  23. package/dist/append.js.map +1 -0
  24. package/dist/assistant.d.ts +6 -0
  25. package/dist/assistant.js +21 -0
  26. package/dist/assistant.js.map +1 -0
  27. package/dist/assistantStruct.d.ts +12 -0
  28. package/dist/assistantStruct.js +21 -0
  29. package/dist/assistantStruct.js.map +1 -0
  30. package/dist/events.d.ts +5 -0
  31. package/dist/events.js +6 -0
  32. package/dist/events.js.map +1 -0
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.js +2 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/reduce.d.ts +6 -0
  37. package/dist/reduce.js +39 -0
  38. package/dist/reduce.js.map +1 -0
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/dist/turn.d.ts +7 -0
  41. package/dist/turn.js +21 -0
  42. package/dist/turn.js.map +1 -0
  43. package/dist/unsafeSet.d.ts +5 -0
  44. package/dist/unsafeSet.js +13 -0
  45. package/dist/unsafeSet.js.map +1 -0
  46. package/dist/user.d.ts +5 -0
  47. package/dist/user.js +14 -0
  48. package/dist/user.js.map +1 -0
  49. package/events.ts +9 -0
  50. package/index.ts +2 -1
  51. package/package.json +7 -5
  52. package/reduce.ts +56 -0
  53. package/tsconfig.json +11 -1
  54. package/turn.ts +25 -0
  55. package/unsafeSet.ts +15 -0
  56. package/user.ts +17 -0
  57. package/dist/util/JSONValue.d.ts +0 -5
  58. package/dist/util/JSONValue.js +0 -2
  59. package/dist/util/JSONValue.js.map +0 -1
  60. package/dist/util/fixTemplateStrings.d.ts +0 -11
  61. package/dist/util/fixTemplateStrings.js +0 -83
  62. package/dist/util/fixTemplateStrings.js.map +0 -1
  63. package/dist/util/isTemplateStringsArray.d.ts +0 -1
  64. package/dist/util/isTemplateStringsArray.js +0 -4
  65. package/dist/util/isTemplateStringsArray.js.map +0 -1
  66. package/util/JSONValue.ts +0 -5
  67. package/util/fixTemplateStrings.ts +0 -99
  68. package/util/isTemplateStringsArray.ts +0 -3
package/dist/turn.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { AiError } from "@effect/ai/AiError";
2
+ import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
3
+ import * as Effect from "effect/Effect";
4
+ import { Strand } from "./Strand.ts";
5
+ import { type Taggable } from "./Taggable.ts";
6
+ /** Append a user message to the conversation, then infer and append an assistant message to the conversation. */
7
+ export declare const turn: Taggable<Effect.Effect<string, AiError, Strand | AiLanguageModel>>;
package/dist/turn.js ADDED
@@ -0,0 +1,21 @@
1
+ import { AiError } from "@effect/ai/AiError";
2
+ import { TextPart, UserMessage } from "@effect/ai/AiInput";
3
+ import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
4
+ import * as Effect from "effect/Effect";
5
+ import { append } from "./append.js";
6
+ import { assistant } from "./assistant.js";
7
+ import { Strand } from "./Strand.js";
8
+ import { normalize } from "./Taggable.js";
9
+ /** Append a user message to the conversation, then infer and append an assistant message to the conversation. */
10
+ export const turn = Effect
11
+ .fnUntraced(function* (a0, ...aRest) {
12
+ yield* append(UserMessage.make({
13
+ parts: [
14
+ TextPart.make({
15
+ text: normalize(a0, aRest),
16
+ }),
17
+ ],
18
+ }));
19
+ return yield* assistant;
20
+ });
21
+ //# sourceMappingURL=turn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn.js","sourceRoot":"","sources":["../turn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,SAAS,EAAiB,MAAM,eAAe,CAAA;AAExD,iHAAiH;AACjH,MAAM,CAAC,MAAM,IAAI,GAAuE,MAAM;KAC3F,UAAU,CACT,QAAQ,CAAC,EAAC,EAAE,EAAE,GAAG,KAAK;IACpB,KAAK,CAAC,CAAC,MAAM,CACX,WAAW,CAAC,IAAI,CAAC;QACf,KAAK,EAAE;YACL,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC;aAC3B,CAAC;SACH;KACF,CAAC,CACH,CAAA;IACD,OAAO,KAAK,CAAC,CAAC,SAAS,CAAA;AACzB,CAAC,CACF,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { Message } from "@effect/ai/AiInput";
2
+ import * as Effect from "effect/Effect";
3
+ import { Strand } from "./Strand.ts";
4
+ /** Set the list of messages. */
5
+ export declare const unsafeSet: (messages: Iterable<Message>) => Effect.Effect<Array<Message>, never, Strand>;
@@ -0,0 +1,13 @@
1
+ import { Message } from "@effect/ai/AiInput";
2
+ import * as Effect from "effect/Effect";
3
+ import { Strand } from "./Strand.js";
4
+ /** Set the list of messages. */
5
+ export const unsafeSet = Effect.fnUntraced(function* (messages) {
6
+ const strand = yield* Strand;
7
+ const previous = strand.messages;
8
+ Object.assign(strand, {
9
+ messages: [...messages],
10
+ });
11
+ return previous;
12
+ });
13
+ //# sourceMappingURL=unsafeSet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsafeSet.js","sourceRoot":"","sources":["../unsafeSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,gCAAgC;AAChC,MAAM,CAAC,MAAM,SAAS,GAE8B,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,QAAQ;IACtF,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;IAChC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QACpB,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC;KACxB,CAAC,CAAA;IACF,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAC,CAAA"}
package/dist/user.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Strand from "./Strand.ts";
3
+ import { type Taggable } from "./Taggable.ts";
4
+ /** Append a user message to the conversation. */
5
+ export declare const user: Taggable<Effect.Effect<void, never, Strand.Strand>>;
package/dist/user.js ADDED
@@ -0,0 +1,14 @@
1
+ import { TextPart, UserMessage } from "@effect/ai/AiInput";
2
+ import * as Effect from "effect/Effect";
3
+ import { append } from "./append.js";
4
+ import * as Strand from "./Strand.js";
5
+ import { normalize } from "./Taggable.js";
6
+ /** Append a user message to the conversation. */
7
+ export const user = (a0, ...aRest) => append(UserMessage.make({
8
+ parts: [
9
+ TextPart.make({
10
+ text: normalize(a0, aRest),
11
+ }),
12
+ ],
13
+ }));
14
+ //# sourceMappingURL=user.js.map
@@ -0,0 +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;AACpC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,SAAS,EAAiB,MAAM,eAAe,CAAA;AAExD,iDAAiD;AACjD,MAAM,CAAC,MAAM,IAAI,GAAwD,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CACxF,MAAM,CACJ,WAAW,CAAC,IAAI,CAAC;IACf,KAAK,EAAE;QACL,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC;SAC3B,CAAC;KACH;CACF,CAAC,CACH,CAAA"}
package/events.ts ADDED
@@ -0,0 +1,9 @@
1
+ import * as Effect from "effect/Effect"
2
+ import * as Stream from "effect/Stream"
3
+ import type { LEvent } from "./LEvent"
4
+ import { Strand } from "./Strand.ts"
5
+
6
+ /** Event stream underlying the current strand. */
7
+ export const events: Stream.Stream<LEvent, never, Strand> = Stream.unwrap(
8
+ Effect.map(Strand, ({ events }) => Stream.fromPubSub(events)),
9
+ )
package/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * as L from "./L.ts"
2
- export * as Strand from "./Strand.ts"
2
+ export * from "./LEvent.ts"
3
+ export * from "./Strand.ts"
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "liminal",
3
+ "homepage": "https://liminal.land",
3
4
  "publishConfig": {
4
5
  "access": "public"
5
6
  },
6
- "version": "0.9.0",
7
+ "version": "0.10.0",
7
8
  "license": "Apache-2.0",
8
9
  "repository": {
9
10
  "type": "git",
@@ -13,12 +14,13 @@
13
14
  "type": "module",
14
15
  "description": "Primitives for composing conversation trees with language models and TypeScript iterators.",
15
16
  "exports": {
16
- ".": "./dist/index.js",
17
- "./L": "./dist/L.js",
18
- "./Strand": "./dist/Strand.js"
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./index.ts"
20
+ }
19
21
  },
20
22
  "peerDependencies": {
21
23
  "@effect/ai": "^0.18.16",
22
- "effect": "^3.17.2"
24
+ "effect": "^3.17.4"
23
25
  }
24
26
  }
package/reduce.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { Message } from "@effect/ai/AiInput"
2
+ import * as Effect from "effect/Effect"
3
+ import * as Option from "effect/Option"
4
+ import * as PubSub from "effect/PubSub"
5
+ import type { YieldWrap } from "effect/Utils"
6
+ import { append } from "./append.ts"
7
+ import { LEvent, MessagesReduced } from "./LEvent.ts"
8
+ import { Strand } from "./Strand.ts"
9
+ import { unsafeSet } from "./unsafeSet.ts"
10
+
11
+ /** Reduce the current strand's messages. */
12
+ export const reduce: <Y extends YieldWrap<Effect.Effect<any, any, any>>, A, E, R>(
13
+ reducer: () => Generator<Y, Effect.Effect<Option.Option<A>, E, R>, never>,
14
+ ) => Effect.Effect<
15
+ void,
16
+ ([Y] extends [never] ? never : [Y] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never) | E,
17
+ | Strand
18
+ | ([Y] extends [never] ? never : [Y] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never)
19
+ | R
20
+ > = Effect.fnUntraced(function*(reducer) {
21
+ const strand = yield* Strand
22
+ if (!strand.messages.length || strand.messages.length === 1) return
23
+ const [m0, m1, ...mRest] = strand.messages
24
+ let prelude = yield* Effect
25
+ .gen(function*() {
26
+ yield* append(m0!, m1!)
27
+ return yield* Effect.gen(reducer)
28
+ })
29
+ .pipe(
30
+ Effect.provide(Strand.new()),
31
+ )
32
+ while (mRest.length) {
33
+ prelude = yield* Effect
34
+ .gen(function*() {
35
+ yield* prelude
36
+ yield* append(mRest.pop()!)
37
+ return yield* Effect.gen(reducer)
38
+ })
39
+ .pipe(
40
+ Effect.provide(Strand.new()),
41
+ )
42
+ }
43
+ const messages: Array<Message> = []
44
+ yield* prelude.pipe(Effect.provideService(
45
+ Strand,
46
+ Strand.of({
47
+ messages,
48
+ events: yield* PubSub.unbounded<LEvent>(),
49
+ }),
50
+ ))
51
+ const previous = yield* unsafeSet(messages)
52
+ yield* strand.events.publish(
53
+ MessagesReduced.make({ previous, messages }),
54
+ )
55
+ return
56
+ })
package/tsconfig.json CHANGED
@@ -2,7 +2,17 @@
2
2
  "extends": "../tsconfig.base",
3
3
  "compilerOptions": {
4
4
  "noEmit": false,
5
- "outDir": "dist"
5
+ "outDir": "dist",
6
+ "plugins": [
7
+ {
8
+ "name": "@effect/language-service",
9
+ "transform": "@effect/language-service/transform",
10
+ "namespaceImportPackages": ["effect", "@effect/ai"],
11
+ "diagnosticSeverity": {
12
+ "importFromBarrel": "error"
13
+ }
14
+ }
15
+ ]
6
16
  },
7
17
  "include": ["."]
8
18
  }
package/turn.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { AiError } from "@effect/ai/AiError"
2
+ import { TextPart, UserMessage } from "@effect/ai/AiInput"
3
+ import { AiLanguageModel } from "@effect/ai/AiLanguageModel"
4
+ import * as Effect from "effect/Effect"
5
+ import { append } from "./append.ts"
6
+ import { assistant } from "./assistant.ts"
7
+ import { Strand } from "./Strand.ts"
8
+ import { normalize, type Taggable } from "./Taggable.ts"
9
+
10
+ /** Append a user message to the conversation, then infer and append an assistant message to the conversation. */
11
+ export const turn: Taggable<Effect.Effect<string, AiError, Strand | AiLanguageModel>> = Effect
12
+ .fnUntraced(
13
+ function*(a0, ...aRest) {
14
+ yield* append(
15
+ UserMessage.make({
16
+ parts: [
17
+ TextPart.make({
18
+ text: normalize(a0, aRest),
19
+ }),
20
+ ],
21
+ }),
22
+ )
23
+ return yield* assistant
24
+ },
25
+ )
package/unsafeSet.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Message } from "@effect/ai/AiInput"
2
+ import * as Effect from "effect/Effect"
3
+ import { Strand } from "./Strand.ts"
4
+
5
+ /** Set the list of messages. */
6
+ export const unsafeSet: (
7
+ messages: Iterable<Message>,
8
+ ) => Effect.Effect<Array<Message>, never, Strand> = Effect.fnUntraced(function*(messages) {
9
+ const strand = yield* Strand
10
+ const previous = strand.messages
11
+ Object.assign(strand, {
12
+ messages: [...messages],
13
+ })
14
+ return previous
15
+ })
package/user.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { TextPart, UserMessage } from "@effect/ai/AiInput"
2
+ import * as Effect from "effect/Effect"
3
+ import { append } from "./append.ts"
4
+ import * as Strand from "./Strand.ts"
5
+ import { normalize, type Taggable } from "./Taggable.ts"
6
+
7
+ /** Append a user message to the conversation. */
8
+ export const user: Taggable<Effect.Effect<void, never, Strand.Strand>> = (a0, ...aRest) =>
9
+ append(
10
+ UserMessage.make({
11
+ parts: [
12
+ TextPart.make({
13
+ text: normalize(a0, aRest),
14
+ }),
15
+ ],
16
+ }),
17
+ )
@@ -1,5 +0,0 @@
1
- export type JSONValue = null | boolean | number | string | JSONValueArray | JSONValueObject;
2
- export type JSONValueArray = Array<JSONValue>;
3
- export type JSONValueObject = {
4
- [key: string]: JSONValue;
5
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=JSONValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JSONValue.js","sourceRoot":"","sources":["../../util/JSONValue.ts"],"names":[],"mappings":""}
@@ -1,11 +0,0 @@
1
- export declare function fixTemplateStrings(template: TemplateStringsArray): {
2
- readonly raw: readonly string[];
3
- };
4
- /**
5
- * Applies template string indentation to substituted values with line breaks
6
- *
7
- * @param strings - The template strings array (processed through fixTemplateStrings)
8
- * @param values - The substitution values
9
- * @returns - The formatted string with properly indented substitutions
10
- */
11
- export declare function applyTemplateWithIndentation(strings: TemplateStringsArray, ...values: any[]): string;
@@ -1,83 +0,0 @@
1
- const INDENTATION_RE = /^\n([ \t]+)/;
2
- const ESCAPE_SEQ_RE = /\\([`${\\]|\n)/g;
3
- const LAST_INDENTATION_RE = /\n[ \t]+$/;
4
- export function fixTemplateStrings(template) {
5
- const firstSegment = template.raw[0];
6
- const leadingIndentMatch = INDENTATION_RE.exec(firstSegment);
7
- const indentation = leadingIndentMatch?.[1];
8
- const rawLength = template.raw.length;
9
- const result = new Array(rawLength);
10
- for (let i = 0; i < rawLength; i++) {
11
- let str = template.raw[i];
12
- // Only perform common indentation replacements if needed
13
- if (indentation) {
14
- // Remove leading newline and indentation in the first segment
15
- if (i === 0) {
16
- str = str.slice(indentation.length + 1);
17
- }
18
- // Use a simple string replacement with a regular expression for better performance
19
- str = str.replaceAll(`\n${indentation}`, "\n");
20
- }
21
- // Replace common escape sequences in a single pass
22
- str = str.replace(ESCAPE_SEQ_RE, (_match, char) => {
23
- // Keep the escaped newline replacement separate for clarity
24
- return char === "\n" ? "" : char;
25
- });
26
- // Handle trailing spaces only for the last segment
27
- if (indentation && i === rawLength - 1) {
28
- str = str.replace(LAST_INDENTATION_RE, "");
29
- }
30
- result[i] = str;
31
- }
32
- return { raw: result };
33
- }
34
- const LEADING_SPACE_RE = /^([ \t]*)/;
35
- /**
36
- * Applies template string indentation to substituted values with line breaks
37
- *
38
- * @param strings - The template strings array (processed through fixTemplateStrings)
39
- * @param values - The substitution values
40
- * @returns - The formatted string with properly indented substitutions
41
- */
42
- export function applyTemplateWithIndentation(strings, ...values) {
43
- const fixedStrings = fixTemplateStrings(strings);
44
- const rawArr = fixedStrings.raw;
45
- const valuesLength = values.length;
46
- const resultParts = new Array(Math.max(1, rawArr.length * 2 - 1));
47
- let resultIndex = 0;
48
- for (let i = 0; i < rawArr.length; i++) {
49
- const str = rawArr[i] || "";
50
- resultParts[resultIndex++] = str;
51
- // Only process values for non-final segments
52
- if (i < valuesLength) {
53
- const value = String(values[i]);
54
- // If value has line breaks, we should indent it
55
- if (value.includes("\n")) {
56
- const lastNewlineIndex = str.lastIndexOf("\n");
57
- if (lastNewlineIndex !== -1) {
58
- // Extract the indentation after the last newline
59
- const textAfterLastNewline = str.substring(lastNewlineIndex + 1);
60
- const leadingSpaceMatch = LEADING_SPACE_RE.exec(textAfterLastNewline);
61
- const indentationToApply = leadingSpaceMatch && leadingSpaceMatch[1] ? leadingSpaceMatch[1] : "";
62
- if (indentationToApply) {
63
- // Split the value into lines once
64
- const lines = value.split("\n");
65
- const linesLength = lines.length;
66
- // First line doesn't need indentation
67
- resultParts[resultIndex++] = lines[0];
68
- // Apply indentation to subsequent lines
69
- for (let j = 1; j < linesLength; j++) {
70
- resultParts[resultIndex++] = "\n" + indentationToApply + lines[j];
71
- }
72
- continue;
73
- }
74
- }
75
- }
76
- // For simple values or when no indentation is needed
77
- resultParts[resultIndex++] = value;
78
- }
79
- }
80
- // Combine all parts at once
81
- return resultParts.slice(0, resultIndex).join("");
82
- }
83
- //# sourceMappingURL=fixTemplateStrings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fixTemplateStrings.js","sourceRoot":"","sources":["../../util/fixTemplateStrings.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,aAAa,CAAA;AACpC,MAAM,aAAa,GAAG,iBAAiB,CAAA;AACvC,MAAM,mBAAmB,GAAG,WAAW,CAAA;AAEvC,MAAM,UAAU,kBAAkB,CAAC,QAA8B;IAC/D,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAE,CAAA;IACrC,MAAM,kBAAkB,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAC5D,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAA;IAE3C,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAA;IACrC,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC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AAK,CAAC,MAAM,CAAA;wBAEhC,sCAAsC;wBACtC,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;wBAErC,wCAAwC;wBACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;4BACrC,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,IAAI,GAAG,kBAAkB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;wBACnE,CAAC;wBACD,SAAQ;oBACV,CAAC;gBACH,CAAC;YACH,CAAC;YACD,qDAAqD;YACrD,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAA;QACpC,CAAC;IACH,CAAC;IAED,4BAA4B;IAC5B,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACnD,CAAC"}
@@ -1 +0,0 @@
1
- export declare function isTemplateStringsArray(value: unknown): value is TemplateStringsArray;
@@ -1,4 +0,0 @@
1
- export function isTemplateStringsArray(value) {
2
- return Array.isArray(value) && "raw" in value && Array.isArray(value.raw);
3
- }
4
- //# sourceMappingURL=isTemplateStringsArray.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isTemplateStringsArray.js","sourceRoot":"","sources":["../../util/isTemplateStringsArray.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAC3E,CAAC"}
package/util/JSONValue.ts DELETED
@@ -1,5 +0,0 @@
1
- export type JSONValue = null | boolean | number | string | JSONValueArray | JSONValueObject
2
-
3
- export type JSONValueArray = Array<JSONValue>
4
-
5
- export type JSONValueObject = { [key: string]: JSONValue }
@@ -1,99 +0,0 @@
1
- const INDENTATION_RE = /^\n([ \t]+)/
2
- const ESCAPE_SEQ_RE = /\\([`${\\]|\n)/g
3
- const LAST_INDENTATION_RE = /\n[ \t]+$/
4
-
5
- export function fixTemplateStrings(template: TemplateStringsArray): { readonly raw: readonly string[] } {
6
- const firstSegment = template.raw[0]!
7
- const leadingIndentMatch = INDENTATION_RE.exec(firstSegment)
8
- const indentation = leadingIndentMatch?.[1]
9
-
10
- const rawLength = template.raw.length
11
- const result = new Array(rawLength)
12
-
13
- for (let i = 0; i < rawLength; i++) {
14
- let str = template.raw[i]!
15
- // Only perform common indentation replacements if needed
16
- if (indentation) {
17
- // Remove leading newline and indentation in the first segment
18
- if (i === 0) {
19
- str = str.slice(indentation.length + 1)
20
- }
21
- // Use a simple string replacement with a regular expression for better performance
22
- str = str.replaceAll(`\n${indentation}`, "\n")
23
- }
24
-
25
- // Replace common escape sequences in a single pass
26
- str = str.replace(ESCAPE_SEQ_RE, (_match, char) => {
27
- // Keep the escaped newline replacement separate for clarity
28
- return char === "\n" ? "" : char
29
- })
30
-
31
- // Handle trailing spaces only for the last segment
32
- if (indentation && i === rawLength - 1) {
33
- str = str.replace(LAST_INDENTATION_RE, "")
34
- }
35
-
36
- result[i] = str
37
- }
38
-
39
- return { raw: result }
40
- }
41
-
42
- const LEADING_SPACE_RE = /^([ \t]*)/
43
- /**
44
- * Applies template string indentation to substituted values with line breaks
45
- *
46
- * @param strings - The template strings array (processed through fixTemplateStrings)
47
- * @param values - The substitution values
48
- * @returns - The formatted string with properly indented substitutions
49
- */
50
- export function applyTemplateWithIndentation(strings: TemplateStringsArray, ...values: any[]): string {
51
- const fixedStrings = fixTemplateStrings(strings)
52
- const rawArr = fixedStrings.raw
53
- const valuesLength = values.length
54
-
55
- const resultParts = new Array(Math.max(1, rawArr.length * 2 - 1))
56
- let resultIndex = 0
57
-
58
- for (let i = 0; i < rawArr.length; i++) {
59
- const str = rawArr[i] || ""
60
- resultParts[resultIndex++] = str
61
-
62
- // Only process values for non-final segments
63
- if (i < valuesLength) {
64
- const value = String(values[i])
65
-
66
- // If value has line breaks, we should indent it
67
- if (value.includes("\n")) {
68
- const lastNewlineIndex = str.lastIndexOf("\n")
69
-
70
- if (lastNewlineIndex !== -1) {
71
- // Extract the indentation after the last newline
72
- const textAfterLastNewline = str.substring(lastNewlineIndex + 1)
73
- const leadingSpaceMatch = LEADING_SPACE_RE.exec(textAfterLastNewline)
74
- const indentationToApply = leadingSpaceMatch && leadingSpaceMatch[1] ? leadingSpaceMatch[1] : ""
75
-
76
- if (indentationToApply) {
77
- // Split the value into lines once
78
- const lines = value.split("\n")
79
- const linesLength = lines.length
80
-
81
- // First line doesn't need indentation
82
- resultParts[resultIndex++] = lines[0]
83
-
84
- // Apply indentation to subsequent lines
85
- for (let j = 1; j < linesLength; j++) {
86
- resultParts[resultIndex++] = "\n" + indentationToApply + lines[j]
87
- }
88
- continue
89
- }
90
- }
91
- }
92
- // For simple values or when no indentation is needed
93
- resultParts[resultIndex++] = value
94
- }
95
- }
96
-
97
- // Combine all parts at once
98
- return resultParts.slice(0, resultIndex).join("")
99
- }
@@ -1,3 +0,0 @@
1
- export function isTemplateStringsArray(value: unknown): value is TemplateStringsArray {
2
- return Array.isArray(value) && "raw" in value && Array.isArray(value.raw)
3
- }