{"version":3,"file":"outputs.cjs","names":[],"sources":["../src/outputs.ts"],"sourcesContent":["import { type BaseMessage, type BaseMessageChunk } from \"./messages/base.js\";\n\nexport const RUN_KEY = \"__run\";\n\n/**\n * Output of a single generation.\n */\nexport interface Generation {\n  /**\n   * Generated text output\n   */\n  text: string;\n  /**\n   * Raw generation info response from the provider.\n   * May include things like reason for finishing (e.g. in {@link OpenAI})\n   */\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  generationInfo?: Record<string, any>;\n}\n\nexport type GenerationChunkFields = {\n  text: string;\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  generationInfo?: Record<string, any>;\n};\n\n/**\n * Chunk of a single generation. Used for streaming.\n */\nexport class GenerationChunk implements Generation {\n  public text: string;\n\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  public generationInfo?: Record<string, any>;\n\n  constructor(fields: GenerationChunkFields) {\n    this.text = fields.text;\n    this.generationInfo = fields.generationInfo;\n  }\n\n  concat(chunk: GenerationChunk): GenerationChunk {\n    return new GenerationChunk({\n      text: this.text + chunk.text,\n      generationInfo: {\n        ...this.generationInfo,\n        ...chunk.generationInfo,\n      },\n    });\n  }\n}\n\n/**\n * Contains all relevant information returned by an LLM.\n */\nexport type LLMResult = {\n  /**\n   * List of the things generated. Each input could have multiple {@link Generation | generations}, hence this is a list of lists.\n   */\n  generations: Generation[][];\n  /**\n   * Dictionary of arbitrary LLM-provider specific output.\n   */\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  llmOutput?: Record<string, any>;\n  /**\n   * Dictionary of run metadata\n   */\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  [RUN_KEY]?: Record<string, any>;\n};\n\nexport interface ChatGeneration extends Generation {\n  message: BaseMessage;\n}\n\nexport type ChatGenerationChunkFields = GenerationChunkFields & {\n  message: BaseMessageChunk;\n};\n\nexport class ChatGenerationChunk\n  extends GenerationChunk\n  implements ChatGeneration\n{\n  public message: BaseMessageChunk;\n\n  constructor(fields: ChatGenerationChunkFields) {\n    super(fields);\n    this.message = fields.message;\n  }\n\n  concat(chunk: ChatGenerationChunk) {\n    return new ChatGenerationChunk({\n      text: this.text + chunk.text,\n      generationInfo: {\n        ...this.generationInfo,\n        ...chunk.generationInfo,\n      },\n      message: this.message.concat(chunk.message),\n    });\n  }\n}\n\nexport interface ChatResult {\n  generations: ChatGeneration[];\n\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  llmOutput?: Record<string, any>;\n}\n"],"mappings":";;;;;;;AAEA,MAAa,UAAU;;;;AA2BvB,IAAa,kBAAb,MAAa,gBAAsC;CACjD;CAGA;CAEA,YAAY,QAA+B;AACzC,OAAK,OAAO,OAAO;AACnB,OAAK,iBAAiB,OAAO;;CAG/B,OAAO,OAAyC;AAC9C,SAAO,IAAI,gBAAgB;GACzB,MAAM,KAAK,OAAO,MAAM;GACxB,gBAAgB;IACd,GAAG,KAAK;IACR,GAAG,MAAM;IACV;GACF,CAAC;;;AAgCN,IAAa,sBAAb,MAAa,4BACH,gBAEV;CACE;CAEA,YAAY,QAAmC;AAC7C,QAAM,OAAO;AACb,OAAK,UAAU,OAAO;;CAGxB,OAAO,OAA4B;AACjC,SAAO,IAAI,oBAAoB;GAC7B,MAAM,KAAK,OAAO,MAAM;GACxB,gBAAgB;IACd,GAAG,KAAK;IACR,GAAG,MAAM;IACV;GACD,SAAS,KAAK,QAAQ,OAAO,MAAM,QAAQ;GAC5C,CAAC"}