import { readRuntimeMetadata } from '../../runtime-metadata.js';
import { logClock } from '../../../servertool/clock/log.js';
import { buildClockStandardToolAppendOperations, buildClockToolAppendOperations } from './chat-process-clock-tool-schemas.js';
import { planChatClockOperationsWithNative } from '../../../router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js';
import { isClientInjectReady } from './client-inject-readiness.js';
function readString(value) {
    return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}
export function buildClockOperations(metadata) {
    if (!isClientInjectReady(metadata)) {
        return [];
    }
    const rt = (readRuntimeMetadata(metadata) ?? {});
    const rawConfig = rt?.clock;
    const plan = planChatClockOperationsWithNative(rt);
    if (!plan.shouldInject) {
        return [];
    }
    const sessionId = readString(metadata.sessionId);
    const hasSessionId = Boolean(sessionId && sessionId.trim());
    logClock('inject_schema', { hasSessionId });
    return buildClockToolAppendOperations(hasSessionId);
}
export function buildClockOperationsWithPlan(metadata, precomputedPlan) {
    if (!isClientInjectReady(metadata)) {
        return [];
    }
    if (!precomputedPlan) {
        return buildClockOperations(metadata);
    }
    if (!precomputedPlan.shouldInject) {
        return [];
    }
    const sessionId = readString(metadata.sessionId);
    const hasSessionId = Boolean(sessionId && sessionId.trim());
    logClock('inject_schema', { hasSessionId });
    return buildClockToolAppendOperations(hasSessionId);
}
export function buildClockStandardToolsOperations() {
    return buildClockStandardToolAppendOperations();
}
