/**
 * Storage schema types for Content Lake documents.
 *
 * All AILF document types include `schemaVersion` for forward-compatible
 * migration. Full trace data goes to blob storage (GCP/local); only
 * sanitized summaries are stored in Content Lake.
 *
 * SECURITY: The `next` dataset is publicly accessible. Never store
 * sensitive data (API keys, full tool call arguments, raw outputs with
 * PII) in Content Lake. Use blob storage + traceDataUri references.
 *
 * @see docs/design-docs/architecture-overhaul/storage-schema.md
 */
// ---------------------------------------------------------------------------
// Schema version
// ---------------------------------------------------------------------------
/** Current schema version for all AILF document types */
export const CURRENT_SCHEMA_VERSION = 1;
// ---------------------------------------------------------------------------
// Type guards
// ---------------------------------------------------------------------------
/** Check if a document is schema-versioned */
export function isSchemaVersioned(doc) {
    return (typeof doc === "object" &&
        doc !== null &&
        "schemaVersion" in doc &&
        typeof doc.schemaVersion === "number");
}
/** Migrate a document to the current schema version (no-op for v1) */
export function migrateDocument(doc) {
    if (doc.schemaVersion > CURRENT_SCHEMA_VERSION) {
        throw new Error(`Document schema version ${doc.schemaVersion} is newer than supported version ${CURRENT_SCHEMA_VERSION}. ` +
            `Please upgrade @sanity/ailf-core.`);
    }
    if (doc.schemaVersion === CURRENT_SCHEMA_VERSION)
        return doc;
    // When version 2 is introduced, add migration transforms here.
    return { ...doc, schemaVersion: CURRENT_SCHEMA_VERSION };
}
