export function withRegistryKey(model) {
    return model.registryKey ? model : { ...model, registryKey: `${model.provider}:${model.id}` };
}
export function splitModelRegistryKey(modelId) {
    if (!modelId.includes(':')) {
        return { providerId: modelId, resolvedModelId: modelId };
    }
    return {
        providerId: modelId.split(':')[0] ?? 'unknown',
        resolvedModelId: modelId.split(':').slice(1).join(':'),
    };
}
export function getBaseModelId(modelId) {
    return modelId.includes(':') ? modelId.split(':').slice(1).join(':') : modelId;
}
/**
 * Key-order-independent JSON serialisation used for model diff comparisons.
 * Recursively sorts object keys so that { a: 1, b: 2 } and { b: 2, a: 1 }
 * produce the same string.
 */
export function stableStringify(value) {
    if (value === null || typeof value !== 'object')
        return JSON.stringify(value);
    if (Array.isArray(value))
        return '[' + value.map(stableStringify).join(',') + ']';
    const sorted = Object.keys(value).sort();
    return '{' + sorted.map((key) => (JSON.stringify(key) + ':' + stableStringify(value[key]))).join(',') + '}';
}
