import type { ThreadHandoffSnapshot } from "@best-agent/protocol";
import type { CoordinatorWorkerHandoff } from "../coordinator-executor.js";

export function buildCoordinatorWorkerHandoff(
  handoff: ThreadHandoffSnapshot,
): CoordinatorWorkerHandoff {
  return {
    ...(handoff.activePaths && handoff.activePaths.length > 0
      ? { activePaths: handoff.activePaths.slice(0, 8) }
      : {}),
    ...(handoff.recentEvidence && handoff.recentEvidence.length > 0
      ? { evidence: handoff.recentEvidence.slice(0, 8) }
      : {}),
    ...(handoff.lastError ? { lastError: handoff.lastError } : {}),
    ...(handoff.latestToolOutcomes && handoff.latestToolOutcomes.length > 0
      ? { latestToolOutcomes: handoff.latestToolOutcomes.slice(0, 6) }
      : {}),
    ...(handoff.latestVerificationState
      ? {
          latestVerification: {
            ...(handoff.latestVerificationState.status
              ? { status: handoff.latestVerificationState.status }
              : {}),
            summary: handoff.latestVerificationState.summary,
          },
        }
      : {}),
  };
}
