feat(models): capability toggles for custom models with upsert and live caps refresh
- AddCustomModelModal lets users pick vision/reasoning caps when adding a model - POST /api/models/custom whitelists caps to booleans - aliasRepo.addCustomModel upserts — re-adding updates caps/name in place - /api/models includes custom llm models with stored caps overriding the heuristic - useModelCaps refetches on customModelChanged instead of trusting a stale cache Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -29,15 +29,21 @@ export async function getCustomModels() {
|
||||
return Object.values(all);
|
||||
}
|
||||
|
||||
// Atomic check-then-insert inside transaction to prevent duplicate races
|
||||
export async function addCustomModel({ providerAlias, id, type = "llm", name }) {
|
||||
// Atomic upsert inside transaction to prevent duplicate races.
|
||||
// Re-adding an existing model updates caps/name without resetting omitted fields.
|
||||
export async function addCustomModel({ providerAlias, id, type = "llm", name, caps }) {
|
||||
const k = customKey(providerAlias, id, type);
|
||||
const db = await getAdapter();
|
||||
let added = false;
|
||||
db.transaction(() => {
|
||||
const row = db.get(`SELECT 1 FROM kv WHERE scope = 'customModels' AND key = ?`, [k]);
|
||||
if (row) return;
|
||||
const value = stringifyJson({ providerAlias, id, type, name: name || id });
|
||||
const row = db.get(`SELECT value FROM kv WHERE scope = 'customModels' AND key = ?`, [k]);
|
||||
if (row) {
|
||||
const prev = parseJson(row.value) || {};
|
||||
const next = { ...prev, ...(name ? { name } : {}), ...(caps ? { caps } : {}) };
|
||||
db.run(`UPDATE kv SET value = ? WHERE scope = 'customModels' AND key = ?`, [stringifyJson(next), k]);
|
||||
return;
|
||||
}
|
||||
const value = stringifyJson({ providerAlias, id, type, name: name || id, ...(caps ? { caps } : {}) });
|
||||
db.run(`INSERT INTO kv(scope, key, value) VALUES('customModels', ?, ?)`, [k, value]);
|
||||
added = true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user