feat(09-01): define granular event types, IPC channels, entity getters, and Zustand patch methods
- Add 5 granular event interfaces (TaskUpdated, RunUpdated, ApprovalUpdated, AgentUpdated, BudgetChanged) to DesktopEvent union - Add 4 entity getter IPC channels (getTask, getAgent, getRun, getApproval) with Zod validation and company ownership checks - Add getRun method to AppDatabase following existing getTask pattern - Add 4 preload bridge methods for entity getters - Add 8 patch/remove methods and refreshBadges to CompanySlice - Add selective-ipc.test.ts with exhaustive union type tests - Extend store.test.ts with 14 patch method tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c1de05a7f1
commit
920a764856
8 files changed
+631
-5
No files matched your search
@@ -1159,6 +1159,17 @@ export class AppDatabase {
|
||||
return row ? { ...row, isPrimary: toBoolean(row.isPrimary) } : null;
|
||||
}
|
||||
|
||||
getRun(id: string): RunRecord {
|
||||
const row = this.db
|
||||
.prepare(
|
||||
"select id, company_id as companyId, task_id as taskId, agent_id as agentId, workspace_id as workspaceId, connector_id as connectorId, status, summary, error_message as errorMessage, exit_code as exitCode, signal, model, session_display_id as sessionDisplayId, cost_usd as costUsd, unattributed_cost as unattributedCost, started_at as startedAt, finished_at as finishedAt, log_path as logPath, created_at as createdAt, updated_at as updatedAt from runs where id = ?",
|
||||
)
|
||||
.get(id) as RunRecord | undefined;
|
||||
if (!row) throw new Error(`Run not found: ${id}`);
|
||||
row.unattributedCost = Boolean(row.unattributedCost);
|
||||
return row;
|
||||
}
|
||||
|
||||
getRunAuthState(runId: string): { id: string; companyId: string; agentId: string; status: RunRecord["status"] } | null {
|
||||
const row = this.db
|
||||
.prepare("select id, company_id as companyId, agent_id as agentId, status from runs where id = ?")
|
||||
|
||||
@@ -4,6 +4,7 @@ import { z } from "zod";
|
||||
import {
|
||||
IPC_CHANNELS,
|
||||
connectorInputSchema,
|
||||
entityGetterSchema,
|
||||
metricsQuerySchema,
|
||||
settingsSchema,
|
||||
} from "@shared/contracts";
|
||||
@@ -142,4 +143,58 @@ export function registerCoreReadHandlers({
|
||||
if (err) return err;
|
||||
return ok(db.getStandupReport(companyId));
|
||||
});
|
||||
|
||||
// --- Entity getters for granular IPC updates ---
|
||||
|
||||
registerHandle(IPC_CHANNELS.getTask, (_event, payload) => {
|
||||
const parsed = entityGetterSchema.parse(payload);
|
||||
const companyError = ensureCompanyExists(parsed.companyId);
|
||||
if (companyError) return companyError;
|
||||
try {
|
||||
const task = db.getTask(parsed.id);
|
||||
if (task.companyId !== parsed.companyId) return fail("TASK_NOT_FOUND", "Task not found in current company.");
|
||||
return ok(task);
|
||||
} catch {
|
||||
return fail("TASK_NOT_FOUND", "Task not found.");
|
||||
}
|
||||
});
|
||||
|
||||
registerHandle(IPC_CHANNELS.getAgent, (_event, payload) => {
|
||||
const parsed = entityGetterSchema.parse(payload);
|
||||
const companyError = ensureCompanyExists(parsed.companyId);
|
||||
if (companyError) return companyError;
|
||||
try {
|
||||
const agent = db.getAgent(parsed.id);
|
||||
if (agent.companyId !== parsed.companyId) return fail("AGENT_NOT_FOUND", "Agent not found in current company.");
|
||||
return ok(agent);
|
||||
} catch {
|
||||
return fail("AGENT_NOT_FOUND", "Agent not found.");
|
||||
}
|
||||
});
|
||||
|
||||
registerHandle(IPC_CHANNELS.getRun, (_event, payload) => {
|
||||
const parsed = entityGetterSchema.parse(payload);
|
||||
const companyError = ensureCompanyExists(parsed.companyId);
|
||||
if (companyError) return companyError;
|
||||
try {
|
||||
const run = db.getRun(parsed.id);
|
||||
if (run.companyId !== parsed.companyId) return fail("RUN_NOT_FOUND", "Run not found in current company.");
|
||||
return ok(run);
|
||||
} catch {
|
||||
return fail("RUN_NOT_FOUND", "Run not found.");
|
||||
}
|
||||
});
|
||||
|
||||
registerHandle(IPC_CHANNELS.getApproval, (_event, payload) => {
|
||||
const parsed = entityGetterSchema.parse(payload);
|
||||
const companyError = ensureCompanyExists(parsed.companyId);
|
||||
if (companyError) return companyError;
|
||||
try {
|
||||
const approval = db.getApprovalRecord(parsed.id);
|
||||
if (approval.companyId !== parsed.companyId) return fail("APPROVAL_NOT_FOUND", "Approval not found in current company.");
|
||||
return ok(approval);
|
||||
} catch {
|
||||
return fail("APPROVAL_NOT_FOUND", "Approval not found.");
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user