import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
var identityToolName=name=>name;function splitDeferredTools(context,enabled,normalizeName=identityToolName){let uniqueTools=new Map;for(let tool of context.tools??[])uniqueTools.set(normalizeName(tool.name),tool);if(!enabled)return{immediate:[...uniqueTools.values()],deferred:new Map};let deferredNames=new Set,usedNames=new Set;for(let message of context.messages)if(message.role==="assistant")for(let block of message.content)block.type==="toolCall"&&usedNames.add(normalizeName(block.name));else if(message.role==="toolResult")for(let name of message.addedToolNames??[]){let normalizedName=normalizeName(name);usedNames.has(normalizedName)||deferredNames.add(normalizedName)}let immediate=[],deferred=new Map;for(let[name,tool]of uniqueTools)deferredNames.has(name)?deferred.set(name,tool):immediate.push(tool);return{immediate,deferred}}export{splitDeferredTools};
