Files
AgentCompany/src/main/worker/observability/run-event-recorder.ts
T
ZacharyZhang-NY a69fbb053b Codemod db pass-through calls: messages + runs + approvals + company (C1 part 2/3)
Rewrite ~376 call sites for messages, runs, approvalsMod, and company
domains and delete the corresponding pass-through methods on
AppDatabase / AppDatabaseBase. Structural type references
(ReturnType<HandlerDeps["db"]["getRun"]>) and SweepStaleReviewsDeps-style
mocks are updated to route through the owning sub-module.
2026-04-20 13:20:15 -04:00

34 lines
855 B
TypeScript

import type { AppDatabase } from "../../database";
interface PersistInput {
companyId: string;
runId: string;
agentId: string;
eventType: string;
stream?: "stdout" | "stderr" | null;
level?: string | null;
message?: string | null;
payload?: Record<string, unknown> | null;
}
/**
* Best-effort `run_events` row writer used by the worker message handler.
* Failures are logged and swallowed because the run lifecycle must not be
* gated on audit-log writes.
*/
export function persistRunEvent(
db: AppDatabase,
logger: { warn: (...args: unknown[]) => void },
input: PersistInput,
) {
try {
db.runs.appendRunEvent(input);
} catch (error) {
logger.warn(
`[run-events] Failed to append ${input.eventType} for ${input.runId}: ${
error instanceof Error ? error.message : String(error)
}`,
);
}
}