export function uniq(items) {
    return [...new Set(items)];
}
export function now() {
    return Date.now();
}
export function updateDomainMetadata(domain, source) {
    return {
        ...domain,
        revision: domain.revision + 1,
        lastUpdatedAt: now(),
        source,
    };
}
export function isTerminalTurnState(state) {
    return state === 'completed' || state === 'failed' || state === 'cancelled';
}
export function canStartNewTurn(domain) {
    return domain.turnState === 'idle' || isTerminalTurnState(domain.turnState);
}
export function isCurrentTurnEvent(domain, turnId) {
    return domain.currentTurnId !== undefined && domain.currentTurnId === turnId;
}
export function formatPartialToolPreview(toolCalls) {
    if (!toolCalls || toolCalls.length === 0)
        return undefined;
    const last = toolCalls[toolCalls.length - 1];
    const name = typeof last.name === 'string' ? last.name : '';
    const args = typeof last.arguments === 'string'
        ? last.arguments
        : last.arguments !== undefined
            ? JSON.stringify(last.arguments)
            : '';
    if (!name)
        return undefined;
    const preview = args.length > 60 ? `${args.slice(0, 57)}...` : args;
    return `${name}(${preview})`;
}
export function resetStreamState() {
    return {
        accumulated: '',
        reasoningAccumulated: '',
        partialToolPreview: undefined,
        deltaCount: 0,
        firstDeltaAt: undefined,
        lastDeltaAt: undefined,
    };
}
