import { randomUUID } from "node:crypto";
import { OMK_CONTRACT_VERSION, OMK_RUNTIME_VERSION, } from "../version.js";
import { getOmkVersionSync } from "./version.js";
export function createOmkJsonEnvelope(options) {
    const ok = options.ok ?? options.status === "passed";
    return {
        ok,
        schemaVersion: OMK_CONTRACT_VERSION,
        command: options.command,
        omkVersion: getOmkVersionSync(),
        runtimeVersion: OMK_RUNTIME_VERSION,
        ...(options.commit ? { commit: options.commit } : {}),
        ...(options.runId ? { runId: options.runId } : {}),
        traceId: options.traceId ?? randomUUID(),
        status: options.status,
        data: options.data,
        warnings: options.warnings ?? [],
        errors: options.errors ?? [],
        metadata: {
            cwd: process.cwd(),
            platform: process.platform,
            nodeVersion: process.version,
            ...(options.provider ? { provider: options.provider } : {}),
            durationMs: options.durationMs,
            timestamp: new Date().toISOString(),
        },
    };
}
