{"version":3,"file":"_createLlmEvaluation.mjs","names":[],"sources":["../../src/internal/_createLlmEvaluation.ts"],"sourcesContent":["import { ILlmEvaluation, IValidation } from \"@typia/interface\";\n\nimport { _accessExpressionAsString } from \"./_accessExpressionAsString\";\n\n/**\n * Compile-time plan of `typia.llm.evaluation<T>()`, one entry per decision leaf\n * of `T`.\n *\n * @internal\n */\nexport type _ILlmEvaluationPlan =\n  | _ILlmEvaluationPlan.IBoolean\n  | _ILlmEvaluationPlan.IChoice\n  | _ILlmEvaluationPlan.IScore\n  | _ILlmEvaluationPlan.ISet;\n\n/** @internal */\nexport namespace _ILlmEvaluationPlan {\n  interface IBase {\n    /** Property names from the root of `T` to the leaf. */\n    path: string[];\n    instructions: string;\n  }\n  export interface IBoolean extends IBase {\n    kind: \"boolean\";\n    threshold: number;\n  }\n  export interface IChoice extends IBase {\n    kind: \"choice\";\n    options: IMember<string>[];\n  }\n  export interface IScore extends IBase {\n    kind: \"score\";\n    /** Sorted in ascending value order; level `i` is `levels[i]`. */\n    levels: IMember<number>[];\n  }\n  export interface ISet extends IBase {\n    kind: \"set\";\n    members: ISetMember[];\n  }\n  export interface IMember<Value extends string | number> {\n    value: Value;\n    description?: string;\n    /** Acceptance minimum of the member, when it has one. */\n    minimum?: number;\n  }\n  export interface ISetMember {\n    value: string;\n    description?: string;\n    threshold: number;\n  }\n}\n\n/**\n * Creates the `ILlmEvaluation` of `typia.llm.evaluation<T>()` from its plan.\n *\n * Both the question map and the decoder derive their keys from here, so the\n * readable path encoding has a single owner.\n *\n * @internal\n */\nexport const _createLlmEvaluation = <T>(\n  plan: _ILlmEvaluationPlan[],\n  decimals: number = 2,\n): ILlmEvaluation<T> => {\n  const questions: Record<string, ILlmEvaluation.IQuestion> = {};\n  for (const leaf of plan) {\n    if (leaf.kind === \"set\")\n      for (const member of leaf.members)\n        assign(questions, key([...leaf.path, member.value]), {\n          type: \"boolean\",\n          instructions: setInstructions(leaf, member),\n        });\n    else assign(questions, key(leaf.path), question(leaf));\n  }\n  return {\n    questions,\n    config: { decimals },\n    decode: (answers: unknown): IValidation<T> =>\n      decode(plan, answers, decimals),\n  };\n};\n\n/* -----------------------------------------------------------\n  QUESTIONS\n----------------------------------------------------------- */\n/**\n * Encodes a property path as a question key, like `refund.requested`.\n *\n * Every segment after the first uses typia's accessor notation, so the key is\n * the validation path without its `$input` root. The first segment is quoted\n * when it is not an identifier, and always when it is `__proto__`, so no key\n * can collide with another or reach an object's prototype.\n */\nconst key = (path: string[]): string => {\n  const head: string = path[0]!;\n  const postfix: string = _accessExpressionAsString(head);\n  const first: string =\n    head === \"__proto__\"\n      ? `[${JSON.stringify(head)}]`\n      : postfix.startsWith(\".\")\n        ? head\n        : postfix;\n  return first + path.slice(1).map(_accessExpressionAsString).join(\"\");\n};\n\nconst question = (\n  leaf:\n    | _ILlmEvaluationPlan.IBoolean\n    | _ILlmEvaluationPlan.IChoice\n    | _ILlmEvaluationPlan.IScore,\n): ILlmEvaluation.IQuestion => {\n  if (leaf.kind === \"boolean\")\n    return { type: \"boolean\", instructions: leaf.instructions };\n  else if (leaf.kind === \"choice\") {\n    const criteria: Record<string, string | null> = {};\n    for (const option of leaf.options)\n      assign(criteria, option.value, option.description ?? null);\n    return { type: \"choice\", instructions: leaf.instructions, criteria };\n  }\n  return {\n    type: \"score\",\n    instructions: leaf.instructions,\n    // the transform rejects fewer than two levels\n    criteria: leaf.levels.map(\n      (level) => level.description ?? String(level.value),\n    ) as [string, string, ...string[]],\n  };\n};\n\nconst setInstructions = (\n  leaf: _ILlmEvaluationPlan.ISet,\n  member: _ILlmEvaluationPlan.ISetMember,\n): string =>\n  [\n    leaf.instructions,\n    \"\",\n    `Does the option ${JSON.stringify(member.value)} apply?`,\n    ...(member.description !== undefined ? [member.description] : []),\n  ].join(\"\\n\");\n\n/* -----------------------------------------------------------\n  VALIDATION\n----------------------------------------------------------- */\nconst decode = <T>(\n  plan: _ILlmEvaluationPlan[],\n  answers: unknown,\n  decimals: number,\n): IValidation<T> => {\n  // half a unit in the last decimal place per rounded value\n  const precision: IPrecision = {\n    probability: 0.5 * 10 ** -decimals,\n    score: 0.5 * 10 ** -decimals,\n  };\n  const map: Record<string, unknown> | null = object(answers);\n  if (map === null)\n    return {\n      success: false,\n      data: answers,\n      errors: [\n        {\n          path: \"$input\",\n          expected: \"Record<string, ILlmEvaluation answer>\",\n          value: answers,\n        },\n      ],\n    };\n\n  const errors: IValidation.IError[] = [];\n  const expected: Set<string> = new Set();\n  const output: Record<string, unknown> = {};\n  const read = (id: string): unknown => {\n    expected.add(id);\n    try {\n      return Object.prototype.hasOwnProperty.call(map, id)\n        ? map[id]\n        : undefined;\n    } catch {\n      // The decision reader reports the inaccessible answer on its own path.\n      return undefined;\n    }\n  };\n\n  for (const leaf of plan) {\n    const path: string = accessor(leaf.path);\n    if (leaf.kind === \"set\") {\n      const values: string[] = [];\n      for (const member of leaf.members) {\n        const memberPath: string = [\n          path,\n          _accessExpressionAsString(member.value),\n        ].join(\"\");\n        const answer: unknown = read(key([...leaf.path, member.value]));\n        const probability: number | null = inspect(\n          memberPath,\n          answer,\n          errors,\n          () => booleanProbability(answer, memberPath, errors),\n        );\n        if (probability !== null && probability >= member.threshold)\n          values.push(member.value);\n      }\n      place(output, leaf.path, values);\n      continue;\n    }\n    const answer: unknown = read(key(leaf.path));\n    if (leaf.kind === \"boolean\") {\n      const probability: number | null = inspect(path, answer, errors, () =>\n        booleanProbability(answer, path, errors),\n      );\n      if (probability !== null)\n        place(output, leaf.path, probability >= leaf.threshold);\n    } else if (leaf.kind === \"choice\") {\n      const value: string | null = inspect(path, answer, errors, () =>\n        choice(leaf, answer, path, errors, precision),\n      );\n      if (value !== null) place(output, leaf.path, value);\n    } else {\n      const value: number | null = inspect(path, answer, errors, () =>\n        score(leaf, answer, path, errors, precision),\n      );\n      if (value !== null) place(output, leaf.path, value);\n    }\n  }\n  let received: string[];\n  try {\n    received = Object.keys(map);\n  } catch {\n    errors.push({\n      path: \"$input\",\n      expected: \"readable evaluation answer map\",\n      value: answers,\n      description: \"Evaluation answer keys could not be inspected.\",\n    });\n    received = [];\n  }\n  for (const id of received)\n    if (expected.has(id) === false)\n      try {\n        errors.push({\n          path: `$input${_accessExpressionAsString(id)}`,\n          expected: \"undefined\",\n          value: map[id],\n          description: \"The answer does not belong to any question.\",\n        });\n      } catch {\n        errors.push({\n          path: `$input${_accessExpressionAsString(id)}`,\n          expected: \"readable evaluation answer\",\n          value: undefined,\n          description: \"The extra answer could not be inspected.\",\n        });\n      }\n  return errors.length === 0\n    ? { success: true, data: output as T }\n    : { success: false, data: answers, errors };\n};\n\n/** Contain exceptions from getters and proxies at the decision path. */\nconst inspect = <T>(\n  path: string,\n  answer: unknown,\n  errors: IValidation.IError[],\n  read: () => T,\n): T | null => {\n  try {\n    return read();\n  } catch {\n    errors.push({\n      path,\n      expected: \"readable evaluation answer\",\n      value: answer,\n      description: \"The answer could not be inspected.\",\n    });\n    return null;\n  }\n};\n\nconst booleanProbability = (\n  answer: unknown,\n  path: string,\n  errors: IValidation.IError[],\n): number | null => {\n  const record: Record<string, unknown> | null = object(answer);\n  const type: unknown = record?.type;\n  const probability: unknown =\n    record === null\n      ? undefined\n      : type === \"boolean\"\n        ? record.probability\n        : type === \"noul\"\n          ? record.noul\n          : undefined;\n  if (isProbability(probability)) return probability;\n  errors.push({\n    path,\n    expected:\n      '{ type: \"boolean\"; probability: number } | { type: \"noul\"; noul: number }',\n    value: answer,\n    description:\n      record === null\n        ? \"Missing boolean answer.\"\n        : type !== \"boolean\" && type !== \"noul\"\n          ? `Answer type must be \"boolean\" or \"noul\", but got ${label(type)}.`\n          : \"Boolean answer needs a probability in [0, 1].\",\n  });\n  return null;\n};\n\nconst choice = (\n  leaf: _ILlmEvaluationPlan.IChoice,\n  answer: unknown,\n  path: string,\n  errors: IValidation.IError[],\n  precision: IPrecision,\n): string | null => {\n  const expected: string = `{ type: \"choice\"; choice: ${leaf.options\n    .map((option) => JSON.stringify(option.value))\n    .join(\" | \")}; probabilities?: Record<string, number> }`;\n  const record: Record<string, unknown> | null = object(answer);\n  const type: unknown = record?.type;\n  const selected: unknown = type === \"choice\" ? record?.choice : undefined;\n  const option: _ILlmEvaluationPlan.IMember<string> | undefined =\n    record !== null && type === \"choice\"\n      ? leaf.options.find((o) => o.value === selected)\n      : undefined;\n  if (record === null || option === undefined) {\n    errors.push({\n      path,\n      expected,\n      value: answer,\n      description:\n        record === null\n          ? \"Missing choice answer.\"\n          : type !== \"choice\"\n            ? `Answer type must be \"choice\", but got ${label(type)}.`\n            : \"Choice answer must select one of the declared options.\",\n    });\n    return null;\n  }\n  const probabilities: Record<string, number> | null | undefined = distribution(\n    record.probabilities,\n    leaf.options.map((o) => o.value),\n    precision.probability,\n  );\n  if (probabilities === null) {\n    errors.push({\n      path,\n      expected,\n      value: answer,\n      description:\n        \"Choice probabilities must contain every declared option exactly once, use numbers in [0, 1], and sum to 1.\",\n    });\n    return null;\n  }\n  if (probabilities !== undefined) {\n    const selected: number = own(probabilities, option.value)!;\n    if (\n      Object.values(probabilities).some(\n        (probability) => probability > selected + PROBABILITY_TOLERANCE,\n      )\n    ) {\n      errors.push({\n        path,\n        expected,\n        value: answer,\n        description:\n          \"Choice answer must select an option with maximum probability.\",\n      });\n      return null;\n    }\n  }\n  return accept(\n    option,\n    option.value,\n    own(probabilities, option.value),\n    path,\n    answer,\n    expected,\n    errors,\n  )\n    ? option.value\n    : null;\n};\n\nconst score = (\n  leaf: _ILlmEvaluationPlan.IScore,\n  answer: unknown,\n  path: string,\n  errors: IValidation.IError[],\n  precision: IPrecision,\n): number | null => {\n  const last: number = leaf.levels.length - 1;\n  const expected: string = `{ type: \"score\"; score: number; probabilities?: Record<string, number> }`;\n  const record: Record<string, unknown> | null = object(answer);\n  const type: unknown = record?.type;\n  const scored: unknown = type === \"score\" ? record?.score : undefined;\n  if (\n    record === null ||\n    type !== \"score\" ||\n    typeof scored !== \"number\" ||\n    Number.isFinite(scored) === false ||\n    scored < 0 ||\n    scored > last\n  ) {\n    errors.push({\n      path,\n      expected,\n      value: answer,\n      description:\n        record === null\n          ? \"Missing score answer.\"\n          : type !== \"score\"\n            ? `Answer type must be \"score\", but got ${label(type)}.`\n            : `Score answer needs a score in [0, ${last}].`,\n    });\n    return null;\n  }\n  const probabilities: Record<string, number> | null | undefined = distribution(\n    record.probabilities,\n    leaf.levels.map((_, i) => String(i)),\n    precision.probability,\n  );\n  if (probabilities === null) {\n    errors.push({\n      path,\n      expected,\n      value: answer,\n      description:\n        \"Score probabilities must contain every level index exactly once, use numbers in [0, 1], and sum to 1.\",\n    });\n    return null;\n  }\n  if (probabilities !== undefined) {\n    const mean: number = leaf.levels.reduce(\n      (total, _, index) => total + index * own(probabilities, String(index))!,\n      0,\n    );\n    const meanRoundingError: number = leaf.levels.reduce(\n      (total, _, index) => total + index * precision.probability,\n      0,\n    );\n    if (\n      Math.abs(mean - scored) >\n      PROBABILITY_TOLERANCE + meanRoundingError + precision.score\n    ) {\n      errors.push({\n        path,\n        expected,\n        value: answer,\n        description:\n          \"Score must equal the probability-weighted mean of its distribution.\",\n      });\n      return null;\n    }\n  }\n\n  // the most probable level when a distribution exists, where a tie resolves\n  // to the lower level; otherwise the level nearest to the fractional score,\n  // where a half rounds up\n  let index: number = Math.round(scored);\n  if (probabilities !== undefined && Object.keys(probabilities).length !== 0) {\n    index = -1;\n    leaf.levels.forEach((_, i) => {\n      const p: number | undefined = own(probabilities, String(i));\n      if (\n        p !== undefined &&\n        (index === -1 || p > own(probabilities, String(index))!)\n      )\n        index = i;\n    });\n  }\n  const level: _ILlmEvaluationPlan.IMember<number> = leaf.levels[index]!;\n  return accept(\n    level,\n    level.value,\n    own(probabilities, String(index)),\n    path,\n    answer,\n    expected,\n    errors,\n  )\n    ? level.value\n    : null;\n};\n\n/** Enforces the acceptance minimum of the selected member, if any. */\nconst accept = (\n  member: { minimum?: number },\n  value: string | number,\n  probability: number | undefined,\n  path: string,\n  answer: unknown,\n  expected: string,\n  errors: IValidation.IError[],\n): boolean => {\n  if (member.minimum === undefined) return true;\n  if (probability === undefined) {\n    errors.push({\n      path,\n      expected,\n      value: answer,\n      description: `${JSON.stringify(value)} requires probability >= ${member.minimum}, but the answer has no probability for it.`,\n    });\n    return false;\n  }\n  if (probability < member.minimum) {\n    errors.push({\n      path,\n      expected,\n      value: answer,\n      description: `${JSON.stringify(value)} has probability ${probability} < ${member.minimum}.`,\n    });\n    return false;\n  }\n  return true;\n};\n\n/**\n * Reads optional `probabilities`: `undefined` when absent, `null` when\n * malformed.\n */\nconst distribution = (\n  input: unknown,\n  keys: string[],\n  roundingError: number,\n): Record<string, number> | null | undefined => {\n  if (input === undefined) return undefined;\n  const record: Record<string, unknown> | null = object(input);\n  if (record === null) return null;\n  if (Object.keys(record).length !== keys.length) return null;\n  const output: Record<string, number> = {};\n  for (const key of keys) {\n    if (Object.prototype.hasOwnProperty.call(record, key) === false)\n      return null;\n    const probability: unknown = record[key];\n    if (isProbability(probability) === false) return null;\n    assign(output, key, probability);\n  }\n  if (\n    Math.abs(\n      Object.values(output).reduce((sum, probability) => sum + probability, 0) -\n        1,\n    ) >\n    PROBABILITY_TOLERANCE + keys.length * roundingError\n  )\n    return null;\n  return output;\n};\n\n/** AI SDK's absolute tolerance for probability sums and derived values. */\nconst PROBABILITY_TOLERANCE = 1e-6;\n\ninterface IPrecision {\n  probability: number;\n  score: number;\n}\n\n/* -----------------------------------------------------------\n  HELPERS\n----------------------------------------------------------- */\n/**\n * Renders an untrusted answer `type` for a message; unlike `JSON.stringify`, it\n * never throws on a bigint or circular value.\n */\nconst label = (value: unknown): string =>\n  typeof value === \"string\" ? JSON.stringify(value) : typeof value;\n\nconst accessor = (path: string[]): string =>\n  \"$input\" + path.map(_accessExpressionAsString).join(\"\");\n\n/** Match AI SDK's JSON-record boundary, including null-prototype dictionaries. */\nconst object = (input: unknown): Record<string, unknown> | null => {\n  if (typeof input !== \"object\" || input === null) return null;\n  try {\n    if (Array.isArray(input)) return null;\n    const prototype: object | null = Object.getPrototypeOf(input);\n    return prototype === Object.prototype || prototype === null\n      ? (input as Record<string, unknown>)\n      : null;\n  } catch {\n    // A revoked or trapping proxy is not a usable answer record.\n    return null;\n  }\n};\n\n/**\n * Reads an own probability, so an option named like an `Object.prototype`\n * member (`constructor`, `toString`, ...) never inherits a value.\n */\nconst own = (\n  probabilities: Record<string, number> | undefined,\n  key: string,\n): number | undefined =>\n  probabilities !== undefined &&\n  Object.prototype.hasOwnProperty.call(probabilities, key)\n    ? probabilities[key]\n    : undefined;\n\nconst isProbability = (value: unknown): value is number =>\n  typeof value === \"number\" &&\n  Number.isFinite(value) &&\n  value >= 0 &&\n  value <= 1;\n\n/** Writes the leaf value, creating the intermediate objects of its path. */\nconst place = (\n  output: Record<string, unknown>,\n  path: string[],\n  value: unknown,\n): void => {\n  let target: Record<string, unknown> = output;\n  path.slice(0, -1).forEach((name) => {\n    if (Object.prototype.hasOwnProperty.call(target, name) === false)\n      assign(target, name, {});\n    target = target[name] as Record<string, unknown>;\n  });\n  assign(target, path[path.length - 1]!, value);\n};\n\n/** Own-property assignment that cannot reach the prototype via `__proto__`. */\nconst assign = (\n  target: Record<string, unknown>,\n  name: string,\n  value: unknown,\n): void => {\n  if (name === \"__proto__\")\n    Object.defineProperty(target, name, {\n      value,\n      enumerable: true,\n      writable: true,\n      configurable: true,\n    });\n  else target[name] = value;\n};\n"],"mappings":";;;;;;;;;;AA6DA,MAAa,wBACX,MACA,WAAmB,MACG;CACtB,MAAM,YAAsD,CAAC;CAC7D,KAAK,MAAM,QAAQ,MACjB,IAAI,KAAK,SAAS,OAChB,KAAK,MAAM,UAAU,KAAK,SACxB,OAAO,WAAW,IAAI,CAAC,GAAG,KAAK,MAAM,OAAO,KAAK,CAAC,GAAG;EACnD,MAAM;EACN,cAAc,gBAAgB,MAAM,MAAM;CAC5C,CAAC;MACA,OAAO,WAAW,IAAI,KAAK,IAAI,GAAG,SAAS,IAAI,CAAC;CAEvD,OAAO;EACL;EACA,QAAQ,EAAE,SAAS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