{"version":3,"sources":["../../../../../src/agents/bee/runners/granite/runner.ts"],"names":["GraniteRunner","DefaultRunner","defaultTemplates","system","GraniteBeeSystemPrompt","assistant","GraniteBeeAssistantPrompt","user","GraniteBeeUserPrompt","schemaError","GraniteBeeSchemaErrorPrompt","toolNotFoundError","GraniteBeeToolNotFoundPrompt","toolError","GraniteBeeToolErrorPrompt","toolInputError","GraniteBeeToolInputErrorPrompt","userEmpty","BeeUserEmptyPrompt","toolNoResultError","BeeToolNoResultsPrompt","register","constructor","input","options","run","emitter","on","update","meta","memory","key","add","BaseMessage","of","role","text","value","success","isBlocking","initMemory","isEmpty","tools","index","messages","findIndex","msg","Role","SYSTEM","JSON","stringify","renderers","variables","map","tool","name","description","schema","parse","createParser","parser","parserRegex","RegExp","join","fork","nodes","thought","prefix","tool_name","tool_input","isEnd","next","final_answer","enumerable"],"mappings":";;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAsBM,MAAMA,sBAAsBC,wBAAAA,CAAAA;EApCnC;;;AAqCE,EAAA,IACWC,gBAAmB,GAAA;AAC5B,IAAO,OAAA;MACLC,MAAQC,EAAAA,oCAAAA;MACRC,SAAWC,EAAAA,uCAAAA;MACXC,IAAMC,EAAAA,kCAAAA;MACNC,WAAaC,EAAAA,yCAAAA;MACbC,iBAAmBC,EAAAA,0CAAAA;MACnBC,SAAWC,EAAAA,uCAAAA;MACXC,cAAgBC,EAAAA,4CAAAA;;MAEhBC,SAAWC,EAAAA,8BAAAA;MACXC,iBAAmBC,EAAAA;AACrB,KAAA;AACF;EAEA;AACE,IAAA,IAAA,CAAKC,QAAQ,EAAA;AACf;EAEAC,WAAYC,CAAAA,KAAAA,EAAiBC,SAAwBC,GAA8B,EAAA;AACjF,IAAMF,KAAAA,CAAAA,KAAAA,EAAOC,SAASC,GAAAA,CAAAA;AAEtB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* Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BaseMessage, Role } from \"@/llms/primitives/message.js\";\nimport { isEmpty } from \"remeda\";\nimport type { AnyTool } from \"@/tools/base.js\";\nimport { DefaultRunner } from \"@/agents/bee/runners/default/runner.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport type { BeeParserInput, BeeRunInput, BeeRunOptions } from \"@/agents/bee/types.js\";\nimport { BeeAgent, BeeInput } from \"@/agents/bee/agent.js\";\nimport type { GetRunContext } from \"@/context.js\";\nimport {\n  GraniteBeeAssistantPrompt,\n  GraniteBeeSchemaErrorPrompt,\n  GraniteBeeSystemPrompt,\n  GraniteBeeToolErrorPrompt,\n  GraniteBeeToolInputErrorPrompt,\n  GraniteBeeToolNotFoundPrompt,\n  GraniteBeeUserPrompt,\n} from \"@/agents/bee/runners/granite/prompts.js\";\nimport { BeeToolNoResultsPrompt, BeeUserEmptyPrompt } from \"@/agents/bee/prompts.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\n\nexport class GraniteRunner extends DefaultRunner {\n  @Cache({ enumerable: false })\n  public get defaultTemplates() {\n    return {\n      system: GraniteBeeSystemPrompt,\n      assistant: GraniteBeeAssistantPrompt,\n      user: GraniteBeeUserPrompt,\n      schemaError: GraniteBeeSchemaErrorPrompt,\n      toolNotFoundError: GraniteBeeToolNotFoundPrompt,\n      toolError: GraniteBeeToolErrorPrompt,\n      toolInputError: GraniteBeeToolInputErrorPrompt,\n      // Note: These are from bee\n      userEmpty: BeeUserEmptyPrompt,\n      toolNoResultError: BeeToolNoResultsPrompt,\n    };\n  }\n\n  static {\n    this.register();\n  }\n\n  constructor(input: BeeInput, options: BeeRunOptions, run: GetRunContext<BeeAgent>) {\n    super(input, options, run);\n\n    run.emitter.on(\n      \"update\",\n      async ({ update, meta, memory }) => {\n        if (update.key === \"tool_output\") {\n          await memory.add(\n            BaseMessage.of({\n              role: \"tool_response\",\n              text: update.value,\n              meta: { success: meta.success },\n            }),\n          );\n        }\n      },\n      {\n        isBlocking: true,\n      },\n    );\n  }\n\n  protected async initMemory(input: BeeRunInput): Promise<BaseMemory> {\n    const memory = await super.initMemory(input);\n\n    if (!isEmpty(this.input.tools)) {\n      const index = memory.messages.findIndex((msg) => msg.role === Role.SYSTEM) + 1;\n      await memory.add(\n        BaseMessage.of({\n          role: \"tools\",\n          text: JSON.stringify(\n            (await this.renderers.system.variables.tools()).map((tool) => ({\n              name: tool.name,\n              description: tool.description,\n              schema: JSON.parse(tool.schema),\n            })),\n            null,\n            4,\n          ),\n        }),\n        index,\n      );\n    }\n    return memory;\n  }\n\n  protected createParser(tools: AnyTool[]) {\n    const { parser } = super.createParser(tools);\n\n    return {\n      parserRegex: isEmpty(tools)\n        ? new RegExp(`Thought: .+\\\\nFinal Answer: [\\\\s\\\\S]+`)\n        : new RegExp(\n            `Thought: .+\\\\n(?:Final Answer: [\\\\s\\\\S]+|Tool Name: (${tools.map((tool) => tool.name).join(\"|\")})\\\\nTool Input: \\\\{.*\\\\})`,\n          ),\n      parser: parser.fork<BeeParserInput>((nodes, options) => ({\n        options,\n        nodes: {\n          ...nodes,\n          thought: { ...nodes.thought, prefix: \"Thought:\" },\n          tool_name: { ...nodes.tool_name, prefix: \"Tool Name:\" },\n          tool_input: { ...nodes.tool_input, prefix: \"Tool Input:\", isEnd: true, next: [] },\n          final_answer: { ...nodes.final_answer, prefix: \"Final Answer:\" },\n        },\n      })),\n    };\n  }\n}\n"]}