import runDbClient_default from "../../../data/db/runDbClient.js";
import { getLogger as getLogger$1 } from "../../../logger.js";
import { extractTransferData, isTransferTask } from "./types.js";
import { setActiveAgentForThread } from "@inkeep/agents-core";

//#region src/domains/run/a2a/transfer.ts
const logger = getLogger$1("Transfer");
/**
* Executes a transfer by sending the original message to the target agent
*/
async function executeTransfer({ tenantId, threadId, projectId, agentId, targetSubAgentId, ref }) {
	logger.info({
		targetAgent: targetSubAgentId,
		threadId,
		tenantId,
		projectId
	}, "Executing transfer - calling setActiveAgentForThread");
	try {
		await setActiveAgentForThread(runDbClient_default)({
			scopes: {
				tenantId,
				projectId
			},
			threadId,
			subAgentId: targetSubAgentId,
			agentId,
			ref
		});
		logger.info({
			targetAgent: targetSubAgentId,
			threadId,
			agentId
		}, "Successfully updated active_sub_agent_id in database");
	} catch (error) {
		logger.error({
			error,
			targetAgent: targetSubAgentId,
			threadId,
			agentId
		}, "Failed to update active_sub_agent_id");
		throw error;
	}
	return {
		success: true,
		targetSubAgentId
	};
}

//#endregion
export { executeTransfer, extractTransferData, isTransferTask as isTransferResponse };