@arizeai/phoenix-evals 0.4.0 → 0.5.1

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 (47) hide show
  1. package/dist/esm/llm/ClassificationEvaluator.d.ts +3 -3
  2. package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -1
  3. package/dist/esm/llm/ClassificationEvaluator.js.map +1 -1
  4. package/dist/esm/template/applyTemplate.d.ts +3 -3
  5. package/dist/esm/template/applyTemplate.d.ts.map +1 -1
  6. package/dist/esm/template/applyTemplate.js +16 -0
  7. package/dist/esm/template/applyTemplate.js.map +1 -1
  8. package/dist/esm/template/createTemplateVariablesProxy.d.ts +7 -0
  9. package/dist/esm/template/createTemplateVariablesProxy.d.ts.map +1 -0
  10. package/dist/esm/template/createTemplateVariablesProxy.js +61 -0
  11. package/dist/esm/template/createTemplateVariablesProxy.js.map +1 -0
  12. package/dist/esm/template/getTemplateVariables.d.ts +2 -2
  13. package/dist/esm/template/getTemplateVariables.d.ts.map +1 -1
  14. package/dist/esm/template/getTemplateVariables.js +16 -0
  15. package/dist/esm/template/getTemplateVariables.js.map +1 -1
  16. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  17. package/dist/esm/types/evals.d.ts +2 -1
  18. package/dist/esm/types/evals.d.ts.map +1 -1
  19. package/dist/esm/types/templating.d.ts +10 -1
  20. package/dist/esm/types/templating.d.ts.map +1 -1
  21. package/dist/src/llm/ClassificationEvaluator.d.ts +3 -3
  22. package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -1
  23. package/dist/src/llm/ClassificationEvaluator.js.map +1 -1
  24. package/dist/src/template/applyTemplate.d.ts +3 -3
  25. package/dist/src/template/applyTemplate.d.ts.map +1 -1
  26. package/dist/src/template/applyTemplate.js +13 -0
  27. package/dist/src/template/applyTemplate.js.map +1 -1
  28. package/dist/src/template/createTemplateVariablesProxy.d.ts +7 -0
  29. package/dist/src/template/createTemplateVariablesProxy.d.ts.map +1 -0
  30. package/dist/src/template/createTemplateVariablesProxy.js +64 -0
  31. package/dist/src/template/createTemplateVariablesProxy.js.map +1 -0
  32. package/dist/src/template/getTemplateVariables.d.ts +2 -2
  33. package/dist/src/template/getTemplateVariables.d.ts.map +1 -1
  34. package/dist/src/template/getTemplateVariables.js +16 -0
  35. package/dist/src/template/getTemplateVariables.js.map +1 -1
  36. package/dist/src/types/evals.d.ts +2 -1
  37. package/dist/src/types/evals.d.ts.map +1 -1
  38. package/dist/src/types/templating.d.ts +10 -1
  39. package/dist/src/types/templating.d.ts.map +1 -1
  40. package/dist/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +2 -1
  42. package/src/llm/ClassificationEvaluator.ts +7 -5
  43. package/src/template/applyTemplate.ts +24 -3
  44. package/src/template/createTemplateVariablesProxy.ts +69 -0
  45. package/src/template/getTemplateVariables.ts +18 -2
  46. package/src/types/evals.ts +2 -1
  47. package/src/types/templating.ts +12 -1
@@ -1,11 +1,11 @@
1
- import { CreateClassificationEvaluatorArgs, EvaluatorFn, Template } from "../types/index.js";
1
+ import { CreateClassificationEvaluatorArgs, EvaluatorFn, PromptTemplate, WithPromptTemplate } from "../types/index.js";
2
2
  import { LLMEvaluator } from "./LLMEvaluator.js";
3
3
  /**
4
4
  * An LLM evaluator that performs evaluation via classification
5
5
  */
6
- export declare class ClassificationEvaluator<RecordType extends Record<string, unknown>> extends LLMEvaluator<RecordType> {
6
+ export declare class ClassificationEvaluator<RecordType extends Record<string, unknown>> extends LLMEvaluator<RecordType> implements WithPromptTemplate {
7
7
  readonly evaluatorFn: EvaluatorFn<RecordType>;
8
- readonly promptTemplate: Template;
8
+ readonly promptTemplate: PromptTemplate;
9
9
  private _promptTemplateVariables;
10
10
  constructor(args: CreateClassificationEvaluatorArgs);
11
11
  evaluate: (example: RecordType) => Promise<import("../types/index.js").EvaluationResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"ClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iCAAiC,EACjC,WAAW,EACX,QAAQ,EACT,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,qBAAa,uBAAuB,CAClC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC1C,SAAQ,YAAY,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAC9C,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC;IAClC,OAAO,CAAC,wBAAwB,CAAuB;gBAC3C,IAAI,EAAE,iCAAiC;IAKnD,QAAQ,GAAI,SAAS,UAAU,kDAE7B;IACF;;OAEG;IACH,IAAI,uBAAuB,IAAI,MAAM,EAAE,CAStC;CACF"}
1
+ {"version":3,"file":"ClassificationEvaluator.d.ts","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iCAAiC,EACjC,WAAW,EACX,cAAc,EACd,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,qBAAa,uBAAuB,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC7E,SAAQ,YAAY,CAAC,UAAU,CAC/B,YAAW,kBAAkB;IAE7B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAC9C,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,OAAO,CAAC,wBAAwB,CAAuB;gBAC3C,IAAI,EAAE,iCAAiC;IAKnD,QAAQ,GAAI,SAAS,UAAU,kDAE7B;IACF;;OAEG;IACH,IAAI,uBAAuB,IAAI,MAAM,EAAE,CAStC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAOnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,uBAEX,SAAQ,YAAwB;IACvB,WAAW,CAA0B;IACrC,cAAc,CAAW;IAC1B,wBAAwB,CAAuB;IACvD,YAAY,IAAuC;QACjD,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,kBAAkB,CAAa,IAAI,CAAC,CAAC;IAC1D,CAAC;IACD,QAAQ,GAAG,CAAC,OAAmB,EAAE,EAAE;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC;IACF;;OAEG;IACH,IAAI,uBAAuB;QACzB,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,wBAAwB,GAAG,oBAAoB,CAAC;gBACnD,QAAQ,EAAE,IAAI,CAAC,cAAc;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,+BAA+B;QAC/B,OAAO,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;CACF"}
1
+ {"version":3,"file":"ClassificationEvaluator.js","sourceRoot":"","sources":["../../../src/llm/ClassificationEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,uBACX,SAAQ,YAAwB;IAGvB,WAAW,CAA0B;IACrC,cAAc,CAAiB;IAChC,wBAAwB,CAAuB;IACvD,YAAY,IAAuC;QACjD,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,kBAAkB,CAAa,IAAI,CAAC,CAAC;IAC1D,CAAC;IACD,QAAQ,GAAG,CAAC,OAAmB,EAAE,EAAE;QACjC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC;IACF;;OAEG;IACH,IAAI,uBAAuB;QACzB,0DAA0D;QAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,wBAAwB,GAAG,oBAAoB,CAAC;gBACnD,QAAQ,EAAE,IAAI,CAAC,cAAc;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,+BAA+B;QAC/B,OAAO,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -1,10 +1,10 @@
1
- import { Template } from "../types/templating.js";
1
+ import { PromptTemplate, RenderedPrompt } from "../types/templating.js";
2
2
  /**
3
3
  * A function that applies a set of variables to a template (e.g. a prompt)
4
4
  * Uses the Mustache library to apply the variables to the template
5
5
  */
6
6
  export declare function formatTemplate(args: {
7
- template: Template;
7
+ template: PromptTemplate;
8
8
  variables: Record<string, unknown>;
9
- }): string;
9
+ }): RenderedPrompt;
10
10
  //# sourceMappingURL=applyTemplate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"applyTemplate.d.ts","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,UAIA"}
1
+ {"version":3,"file":"applyTemplate.d.ts","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAMrE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,cAAc,CAejB"}
@@ -1,3 +1,4 @@
1
+ import { createTemplateVariablesProxy } from "./createTemplateVariablesProxy.js";
1
2
  import Mustache from "mustache";
2
3
  /**
3
4
  * A function that applies a set of variables to a template (e.g. a prompt)
@@ -5,6 +6,21 @@ import Mustache from "mustache";
5
6
  */
6
7
  export function formatTemplate(args) {
7
8
  const { template, variables } = args;
9
+ const variablesProxy = createTemplateVariablesProxy(variables);
10
+ if (typeof template === "string") {
11
+ return renderTemplateString(template, variablesProxy);
12
+ }
13
+ return template.map((message) => {
14
+ if (message.content !== undefined && typeof message.content === "string") {
15
+ return {
16
+ ...message,
17
+ content: renderTemplateString(message.content, variablesProxy),
18
+ };
19
+ }
20
+ return message;
21
+ });
22
+ }
23
+ function renderTemplateString(template, variables) {
8
24
  // Disable HTML escaping by providing a custom escape function that returns text as-is
9
25
  return Mustache.render(template, variables, {}, { escape: (text) => text });
10
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"applyTemplate.js","sourceRoot":"","sources":["../../../src/template/applyTemplate.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAG9B;IACC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACrC,sF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a Proxy that wraps an object to stringify nested object values when accessed directly.
3
+ * This allows Mustache to access properties of objects (e.g., {{user.name}}) while
4
+ * stringifying objects that are accessed as leaf values (e.g., {{user.profile}}).
5
+ */
6
+ export declare function createTemplateVariablesProxy<T>(obj: T): T;
7
+ //# sourceMappingURL=createTemplateVariablesProxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTemplateVariablesProxy.d.ts","sourceRoot":"","sources":["../../../src/template/createTemplateVariablesProxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CA+DzD"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Creates a Proxy that wraps an object to stringify nested object values when accessed directly.
3
+ * This allows Mustache to access properties of objects (e.g., {{user.name}}) while
4
+ * stringifying objects that are accessed as leaf values (e.g., {{user.profile}}).
5
+ */
6
+ export function createTemplateVariablesProxy(obj) {
7
+ if (obj === null || obj === undefined) {
8
+ return obj;
9
+ }
10
+ if (Array.isArray(obj)) {
11
+ return obj.map(createTemplateVariablesProxy);
12
+ }
13
+ if (typeof obj === "object") {
14
+ return new Proxy(obj, {
15
+ get(target, prop) {
16
+ // Handle toString and valueOf to stringify the object when accessed directly
17
+ if (prop === "toString") {
18
+ return () => JSON.stringify(target);
19
+ }
20
+ if (prop === "valueOf") {
21
+ return () => JSON.stringify(target);
22
+ }
23
+ if (typeof prop !== "string") {
24
+ return Reflect.get(target, prop);
25
+ }
26
+ const value = Reflect.get(target, prop);
27
+ // If the value is an object (not array, not null), wrap it in a proxy
28
+ // so it can be stringified if accessed directly, or have its properties accessed
29
+ if (value !== null &&
30
+ typeof value === "object" &&
31
+ !Array.isArray(value)) {
32
+ return createTemplateVariablesProxy(value);
33
+ }
34
+ return value;
35
+ },
36
+ // Override valueOf and toString to stringify the object when Mustache tries to render it directly
37
+ // Mustache will call toString() when it needs to render an object as a string
38
+ has(target, prop) {
39
+ if (prop === "toString" || prop === "valueOf") {
40
+ return true;
41
+ }
42
+ return Reflect.has(target, prop);
43
+ },
44
+ ownKeys(target) {
45
+ return Reflect.ownKeys(target);
46
+ },
47
+ getOwnPropertyDescriptor(target, prop) {
48
+ if (prop === "toString") {
49
+ return {
50
+ enumerable: false,
51
+ configurable: true,
52
+ value: () => JSON.stringify(target),
53
+ };
54
+ }
55
+ return Reflect.getOwnPropertyDescriptor(target, prop);
56
+ },
57
+ });
58
+ }
59
+ return obj;
60
+ }
61
+ //# sourceMappingURL=createTemplateVariablesProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTemplateVariablesProxy.js","sourceRoot":"","sources":["../../../src/template/createTemplateVariablesProxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAI,GAAM;IACpD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,4BAA4B,CAAM,CAAC;IACpD,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAI,KAAK,CAAC,GAAG,EAAE;YACpB,GAAG,CAAC,MAAM,EAAE,IAAqB;gBAC/B,6EAA6E;gBAC7E,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;oBACxB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACtC,CAAC;gBACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACtC,CAAC;gBAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;oBAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBACnC,CAAC;gBAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAExC,sEAAsE;gBACtE,iFAAiF;gBACjF,IACE,KAAK,KAAK,IAAI;oBACd,OAAO,KAAK,KAAK,QAAQ;oBACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACrB,CAAC;oBACD,OAAO,4BAA4B,CAAC,KAAK,CAAC,CAAC;gBAC7C,CAAC;gBAED,OAAO,KAAK,CAAC;YACf,CAAC;YACD,kGAAkG;YAClG,8EAA8E;YAC9E,GAAG,CAAC,MAAM,EAAE,IAAI;gBACd,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9C,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,CAAC,MAAM;gBACZ,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACjC,CAAC;YACD,wBAAwB,CAAC,MAAM,EAAE,IAAI;gBACnC,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;oBACxB,OAAO;wBACL,UAAU,EAAE,KAAK;wBACjB,YAAY,EAAE,IAAI;wBAClB,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;qBACpC,CAAC;gBACJ,CAAC;gBACD,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,6 +1,6 @@
1
- import { Template } from "../types/templating.js";
1
+ import { PromptTemplate } from "../types/templating.js";
2
2
  type GetTemplateVariableArgs = {
3
- template: Template;
3
+ template: PromptTemplate;
4
4
  };
5
5
  /**
6
6
  * Parse out the template variables of a prompt
@@ -1 +1 @@
1
- {"version":3,"file":"getTemplateVariables.d.ts","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AACF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,EAAE,CAU5E"}
1
+ {"version":3,"file":"getTemplateVariables.d.ts","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AACF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,EAAE,CAW5E"}
@@ -6,6 +6,22 @@ import Mustache from "mustache";
6
6
  */
7
7
  export function getTemplateVariables(args) {
8
8
  const { template } = args;
9
+ if (typeof template === "string") {
10
+ return getTemplateVariablesFromString(template);
11
+ }
12
+ return template.reduce((acc, message) => {
13
+ if (message.content !== undefined && typeof message.content === "string") {
14
+ return [...acc, ...getTemplateVariablesFromString(message.content)];
15
+ }
16
+ return acc;
17
+ }, []);
18
+ }
19
+ /**
20
+ * Parse out the template variables of a string template
21
+ * @param template - The template to get the variables from
22
+ * @returns {string[]} a list of prompt template variables
23
+ */
24
+ function getTemplateVariablesFromString(template) {
9
25
  const templateSpans = Mustache.parse(template);
10
26
  return templateSpans.reduce((acc, templateSpan) => {
11
27
  const [spanType, value] = templateSpan;
@@ -1 +1 @@
1
- {"version":3,"file":"getTemplateVariables.js","sourceRoot":"","sources":["../../../src/template/getTemplateVariables.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,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