{"version":3,"sources":["../../../../../src/agents/bee/runners/deep-think/runner.ts"],"names":["DeepThinkRunner","DefaultRunner","defaultTemplates","system","DeepThinkBeeSystemPrompt","assistant","DeepThinkBeeAssistantPrompt","user","DeepThinkBeeUserPrompt","schemaError","DeepThinkBeeSchemaErrorPrompt","toolNotFoundError","DeepThinkBeeToolNotFoundPrompt","toolError","DeepThinkBeeToolErrorPrompt","toolInputError","DeepThinkBeeToolInputErrorPrompt","userEmpty","BeeUserEmptyPrompt","toolNoResultError","BeeToolNoResultsPrompt","register","constructor","input","options","run","emitter","on","update","meta","memory","key","add","BaseMessage","of","role","text","value","success","isBlocking","createParser","tools","parser","parserRegex","isEmpty","RegExp","map","tool","name","join","fork","nodes","silentNodes","thought","prefix","next","isStart","field","ZodParserField","z","string","min","dummy_thought_end","isDummy","transform","_","tool_name","tool_input","isEnd","tool_output","final_answer","enumerable"],"mappings":";;;;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAuBM,MAAMA,wBAAwBC,wBAAAA,CAAAA;EArCrC;;;AAsCE,EAAA,IACWC,gBAAmB,GAAA;AAC5B,IAAO,OAAA;MACLC,MAAQC,EAAAA,sCAAAA;MACRC,SAAWC,EAAAA,yCAAAA;MACXC,IAAMC,EAAAA,oCAAAA;MACNC,WAAaC,EAAAA,2CAAAA;MACbC,iBAAmBC,EAAAA,4CAAAA;MACnBC,SAAWC,EAAAA,yCAAAA;MACXC,cAAgBC,EAAAA,8CAAAA;;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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A;YACTC,MAAQ,EAAA,SAAA;;YAERC,IAAM,EAAA;AAAC,cAAA;;YACPC,OAAS,EAAA,IAAA;AACTC,YAAAA,KAAAA,EAAO,IAAIC,wBAAeC,CAAAA,KAAAA,CAAEC,QAASC,CAAAA,GAAAA,CAAI,CAAA,CAAA;AAC3C,WAAA;UACAC,iBAAmB,EAAA;YACjBR,MAAQ,EAAA,UAAA;YACRS,OAAS,EAAA,IAAA;YACTR,IAAM,EAAA;AAAC,cAAA,WAAA;AAAa,cAAA;;YACpBE,KAAO,EAAA,IAAIC,yBAAeC,KAAEC,CAAAA,MAAAA,GAASI,SAAU,CAAA,CAACC,CAAM,KAAA,EAAA,CAAA;AACxD,WAAA;UACAC,SAAW,EAAA;AAAE,YAAA,GAAGf,KAAMe,CAAAA,SAAAA;YAAWZ,MAAQ,EAAA;AAAa,WAAA;UACtDa,UAAY,EAAA;AACV,YAAA,GAAGhB,KAAMgB,CAAAA,UAAAA;YACTb,MAAQ,EAAA,aAAA;YACRc,KAAO,EAAA,IAAA;AACPb,YAAAA,IAAAA,EAAM;AACR,WAAA;UACAc,WAAa,EAAA;AAAE,YAAA,GAAGlB,KAAMe,CAAAA,SAAAA;YAAWZ,MAAQ,EAAA;AAAe,WAAA;UAC1DgB,YAAc,EAAA;AAAE,YAAA,GAAGnB,KAAMmB,CAAAA,YAAAA;YAAchB,MAAQ,EAAA;AAAY;AAC7D;OACF,CAAA;AACF,KAAA;AACF;AACF;;;IAxFWiB,UAAY,EAAA","file":"runner.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * 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 { isEmpty } from \"remeda\";\nimport type { AnyTool } from \"@/tools/base.js\";\nimport { DefaultRunner } from \"@/agents/bee/runners/default/runner.js\";\nimport {\n  DeepThinkBeeAssistantPrompt,\n  DeepThinkBeeSchemaErrorPrompt,\n  DeepThinkBeeSystemPrompt,\n  DeepThinkBeeToolErrorPrompt,\n  DeepThinkBeeToolInputErrorPrompt,\n  DeepThinkBeeToolNotFoundPrompt,\n  DeepThinkBeeUserPrompt,\n} from \"@/agents/bee/runners/deep-think/prompts.js\";\nimport { BeeToolNoResultsPrompt, BeeUserEmptyPrompt } from \"@/agents/bee/prompts.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\nimport { ZodParserField } from \"@/agents/parsers/field.js\";\nimport { z } from \"zod\";\nimport { BeeInput, BeeAgent } from \"@/agents/bee/agent.js\";\nimport { BeeRunOptions } from \"@/agents/bee/types.js\";\nimport { BaseMessage } from \"@/llms/primitives/message.js\";\nimport { GetRunContext } from \"@/context.js\";\n\nexport class DeepThinkRunner extends DefaultRunner {\n  @Cache({ enumerable: false })\n  public get defaultTemplates() {\n    return {\n      system: DeepThinkBeeSystemPrompt,\n      assistant: DeepThinkBeeAssistantPrompt,\n      user: DeepThinkBeeUserPrompt,\n      schemaError: DeepThinkBeeSchemaErrorPrompt,\n      toolNotFoundError: DeepThinkBeeToolNotFoundPrompt,\n      toolError: DeepThinkBeeToolErrorPrompt,\n      toolInputError: DeepThinkBeeToolInputErrorPrompt,\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: \"user\",\n              text: update.value,\n              meta: { success: meta.success },\n            }),\n          );\n        }\n      },\n      {\n        isBlocking: true,\n      },\n    );\n  }\n\n  protected createParser(tools: AnyTool[]) {\n    const { parser } = super.createParser(tools);\n\n    const parserRegex = isEmpty(tools)\n      ? new RegExp(`<think>.+?</think>\\\\n\\\\nFinal Answer: [\\\\s\\\\S]+`)\n      : new RegExp(\n          `<think>.+?</think>\\\\n\\\\n(?:Final Answer: [\\\\s\\\\S]+|Tool Name: (${tools.map((tool) => tool.name).join(\"|\")})\\\\nTool Input: \\\\{.*\\\\})`,\n        );\n\n    return {\n      parserRegex,\n      parser: parser.fork((nodes, options) => ({\n        options: {\n          ...options,\n          // @ts-expect-error\n          silentNodes: [...(options?.silentNodes ?? []), \"dummy_thought_end\"],\n        },\n        nodes: {\n          ...nodes,\n          thought: {\n            ...nodes.thought,\n            prefix: \"<think>\",\n            // @ts-expect-error\n            next: [\"dummy_thought_end\"] as const,\n            isStart: true,\n            field: new ZodParserField(z.string().min(1)),\n          },\n          dummy_thought_end: {\n            prefix: \"</think>\",\n            isDummy: true,\n            next: [\"tool_name\", \"final_answer\"],\n            field: new ZodParserField(z.string().transform((_) => \"\")),\n          },\n          tool_name: { ...nodes.tool_name, prefix: \"Tool Name:\" },\n          tool_input: {\n            ...nodes.tool_input,\n            prefix: \"Tool Input:\",\n            isEnd: true,\n            next: [],\n          },\n          tool_output: { ...nodes.tool_name, prefix: \"Tool Output:\" },\n          final_answer: { ...nodes.final_answer, prefix: \"Response:\" },\n        },\n      })),\n    } as const;\n  }\n}\n"]}