{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,GAAG,SAAS,CAoBrG;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,eAAe,GAAG,SAAS,EAAE,CAE3G","sourcesContent":["/**\n * Tool wrappers for extension-registered tools.\n *\n * These wrappers only adapt tool execution so extension tools receive the runner context.\n * Tool call and tool result interception is handled by AgentSession via agent-core hooks.\n */\n\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { wrapToolDefinition } from \"../tools/tool-definition-wrapper.ts\";\nimport type { ExtensionRunner } from \"./runner.ts\";\nimport type { RegisteredTool } from \"./types.ts\";\n\n/**\n * Wrap a RegisteredTool into an AgentTool.\n * Uses the runner's createContext() for consistent context across tools and event handlers.\n */\nexport function wrapRegisteredTool(registeredTool: RegisteredTool, runner: ExtensionRunner): AgentTool {\n\tconst tool = wrapToolDefinition(registeredTool.definition, () => runner.createContext());\n\tconst execute = tool.execute;\n\treturn {\n\t\t...tool,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => {\n\t\t\tconst activeBefore = runner.getActiveTools();\n\t\t\tconst result = await execute(toolCallId, params, signal, onUpdate);\n\t\t\tconst activeAfter = runner.getActiveTools();\n\t\t\tif (!activeBefore.every((name) => activeAfter.includes(name))) return result;\n\n\t\t\tconst beforeNames = new Set(activeBefore);\n\t\t\tconst addedToolNames = activeAfter.filter((name) => !beforeNames.has(name));\n\t\t\tif (addedToolNames.length === 0) return result;\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\taddedToolNames: [...new Set([...(result.addedToolNames ?? []), ...addedToolNames])],\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * Wrap all registered tools into AgentTools.\n * Uses the runner's createContext() for consistent context across tools and event handlers.\n */\nexport function wrapRegisteredTools(registeredTools: RegisteredTool[], runner: ExtensionRunner): AgentTool[] {\n\treturn registeredTools.map((tool) => wrapRegisteredTool(tool, runner));\n}\n"]}