refactor(db): add findAgent/findConnector; wrap linkManyTasksToApproval in tx; collapse saveAgent IIFEs (P1-28, P1-29)

This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 23:02:13 -04:00
1 parent a05885c0ff
commit 821855931d
5 files changed
+38 -30

No files matched your search

+14 -3
View File
@@ -79,7 +79,7 @@ export function buildConnectorMethods(
.run(input.status, input.authState, input.version, nowIso(), input.lastError, nowIso(), input.id);
},
getConnector(id: ConnectorId): ConnectorRecord {
findConnector(id: ConnectorId): ConnectorRecord | null {
const row = getDb()
.prepare(
"select id, label, description, status, command, version, auth_state, last_checked_at, last_error, model, env_binding_text, notes from connectors where id = ?",
@@ -100,8 +100,13 @@ export function buildConnectorMethods(
notes: string;
}
| undefined;
if (!row) throw new Error(`Connector not found: ${id}`);
const definition = getConnectorDefinition(row.id as ConnectorId);
if (!row) return null;
let definition;
try {
definition = getConnectorDefinition(row.id as ConnectorId);
} catch {
return null;
}
return {
id: row.id as ConnectorId,
label: row.label,
@@ -120,6 +125,12 @@ export function buildConnectorMethods(
};
},
getConnector(id: ConnectorId): ConnectorRecord {
const result = this.findConnector(id);
if (!result) throw new Error(`Connector not found: ${id}`);
return result;
},
seedConnectors() {
getDb().prepare("delete from connectors where id not in ('codex_local', 'claude_local', 'gemini_local') and id not like 'claude_compat%'").run();
const currentRows = readAll<Partial<ConnectorRecord>>(