export const DEFAULT_MODEL_OPTION = {
    id: 'default',
    label: 'Default (CLI config)',
};
// Daemon's /api/chat needs to validate the user's model pick against the
// list we last surfaced to the UI. We keep a per-agent cache of the most
// recent live list (refreshed every detectAgents() call) and additionally
// trust any value present in the static fallback. A model that's neither
// gets rejected so a stale or hostile value can't smuggle arbitrary flags.
const liveModelCache = new Map();
export function rememberLiveModels(agentId, models) {
    if (!Array.isArray(models))
        return;
    liveModelCache.set(agentId, new Set(models.map((m) => m && m.id).filter((id) => typeof id === 'string')));
}
export function isKnownModel(def, modelId) {
    if (!modelId)
        return false;
    const live = liveModelCache.get(def.id);
    if (live && live.has(modelId))
        return true;
    if (Array.isArray(def.fallbackModels)) {
        return def.fallbackModels.some((m) => m.id === modelId);
    }
    return false;
}
// Permit user-typed model ids that didn't appear in either the live
// listing or the static fallback (e.g. the user is on a brand-new model
// the CLI's `models` command hasn't surfaced yet). The CLI gets the value
// as a child-process arg — not a shell string — so injection isn't a
// concern, but we still reject anything that could be misread as a flag
// by a downstream CLI or that contains whitespace / control chars.
export function sanitizeCustomModel(id) {
    if (typeof id !== 'string')
        return null;
    const trimmed = id.trim();
    if (trimmed.length === 0 || trimmed.length > 200)
        return null;
    if (!/^[A-Za-z0-9][A-Za-z0-9._/:@-]*$/.test(trimmed))
        return null;
    return trimmed;
}
//# sourceMappingURL=models.js.map