import { createHash } from "node:crypto";
export function openAiRuntimeCredentialScopeKey(workspaceId, credentialVersion) {
    return `openai_api_key:${workspaceId}:${credentialVersion}`;
}
export function openAiRuntimeCredentialScopeFingerprint(workspaceId, credentialVersion) {
    return createHash("sha256")
        .update(`patchtrail-runtime-credential-scope:v1:openai:openai_api_key:${workspaceId}:${credentialVersion}`)
        .digest("hex")
        .slice(0, 32);
}
export function credentialScopeVersionFromStatus(status) {
    return status.credentialVersion ?? status.updatedAt ?? "legacy-unknown";
}
export function openAiRuntimeCredentialScopeMetadata(input) {
    return {
        provider: "openai",
        kind: "openai_api_key",
        workspaceId: input.workspaceId,
        fingerprint: openAiRuntimeCredentialScopeFingerprint(input.workspaceId, input.credentialVersion),
        activatedAt: input.activatedAt ?? new Date().toISOString(),
    };
}
