{"version":3,"file":"log_to_message.cjs","names":["AIMessage","HumanMessage"],"sources":["../../../src/agents/format_scratchpad/log_to_message.ts"],"sourcesContent":["import type { AgentStep } from \"@langchain/core/agents\";\nimport {\n  type BaseMessage,\n  AIMessage,\n  HumanMessage,\n} from \"@langchain/core/messages\";\nimport { renderTemplate } from \"@langchain/core/prompts\";\n\nexport function formatLogToMessage(\n  intermediateSteps: AgentStep[],\n  templateToolResponse = \"{observation}\"\n): BaseMessage[] {\n  // Get all input variables, if there is more than one, throw an error.\n  const matches = [...templateToolResponse.matchAll(/{([^}]*)}/g)];\n  const stringsInsideBrackets = matches.map((match) => match[1]);\n  if (stringsInsideBrackets.length > 1) {\n    throw new Error(\n      `templateToolResponse must contain one input variable: ${templateToolResponse}`\n    );\n  }\n\n  const thoughts: BaseMessage[] = [];\n\n  for (const step of intermediateSteps) {\n    thoughts.push(new AIMessage(step.action.log));\n    thoughts.push(\n      new HumanMessage(\n        renderTemplate(templateToolResponse, \"f-string\", {\n          [stringsInsideBrackets[0]]: step.observation,\n        })\n      )\n    );\n  }\n  return thoughts;\n}\n"],"mappings":";;;;;;AAQA,SAAgB,mBACd,mBACA,uBAAuB,iBACR;CAGf,MAAM,wBADU,CAAC,GAAG,qBAAqB,SAAS,aAAa,CAAC,CAC1B,KAAK,UAAU,MAAM,GAAG;AAC9D,KAAI,sBAAsB,SAAS,EACjC,OAAM,IAAI,MACR,yDAAyD,uBAC1D;CAGH,MAAM,WAA0B,EAAE;AAElC,MAAK,MAAM,QAAQ,mBAAmB;AACpC,WAAS,KAAK,IAAIA,yBAAAA,UAAU,KAAK,OAAO,IAAI,CAAC;AAC7C,WAAS,KACP,IAAIC,yBAAAA,cAAAA,GAAAA,wBAAAA,gBACa,sBAAsB,YAAY,GAC9C,sBAAsB,KAAK,KAAK,aAClC,CAAC,CACH,CACF;;AAEH,QAAO"}