import { DELEGATE_TOOL_PREFIX, TRANSFER_TOOL_PREFIX } from "@inkeep/agents-core";

//#region src/domains/run/agents/tools/tool-utils.ts
function getRelationshipIdForTool(ctx, toolName, toolType) {
	if (toolType === "mcp") return (ctx.config.tools?.find((tool) => {
		if (tool.config?.type !== "mcp") return false;
		if (tool.availableTools?.some((available) => available.name === toolName)) return true;
		if (tool.config.mcp.activeTools?.includes(toolName)) return true;
		return tool.name === toolName;
	}))?.relationshipId;
	if (toolType === "tool") return ctx.functionToolRelationshipIdByName.get(toolName);
	if (toolType === "delegation") return ctx.config.delegateRelations.find((relation) => `${DELEGATE_TOOL_PREFIX}${relation.config.id.toLowerCase().replace(/\s+/g, "_")}` === toolName)?.config.relationId;
	if (toolType === "transfer") return ctx.config.transferRelations.find((relation) => `${TRANSFER_TOOL_PREFIX}${relation.id.toLowerCase().replace(/\s+/g, "_")}` === toolName)?.relationId;
}

//#endregion
export { getRelationshipIdForTool };