import equal from "fast-deep-equal"; import type { AgentUsage } from "@getpaseo/protocol/agent-types"; interface AgentUpdateValue { updatedAt: Date | string; lastUsage?: AgentUsage; } function timestamp(value: Date | string): number { return value instanceof Date ? value.getTime() : Date.parse(value); } export function acceptAgentDirectoryUpdate( current: T | undefined, incoming: T, ): T { if (!current || timestamp(incoming.updatedAt) >= timestamp(current.updatedAt)) return incoming; if (incoming.lastUsage === undefined) return current; if (equal(incoming.lastUsage, current.lastUsage)) return current; return { ...current, lastUsage: incoming.lastUsage }; }