2026-03-03 08:45:26 -06:00
|
|
|
import type { Db } from "@paperclipai/db";
|
|
|
|
|
import { activityLog } from "@paperclipai/db";
|
2026-02-17 12:24:43 -06:00
|
|
|
import { publishLiveEvent } from "./live-events.js";
|
2026-02-19 15:43:52 -06:00
|
|
|
import { sanitizeRecord } from "../redaction.js";
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
|
|
|
|
|
export interface LogActivityInput {
|
|
|
|
|
companyId: string;
|
|
|
|
|
actorType: "agent" | "user" | "system";
|
|
|
|
|
actorId: string;
|
|
|
|
|
action: string;
|
|
|
|
|
entityType: string;
|
|
|
|
|
entityId: string;
|
|
|
|
|
agentId?: string | null;
|
2026-02-19 09:09:40 -06:00
|
|
|
runId?: string | null;
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
details?: Record<string, unknown> | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function logActivity(db: Db, input: LogActivityInput) {
|
2026-02-19 15:43:52 -06:00
|
|
|
const sanitizedDetails = input.details ? sanitizeRecord(input.details) : null;
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
await db.insert(activityLog).values({
|
|
|
|
|
companyId: input.companyId,
|
|
|
|
|
actorType: input.actorType,
|
|
|
|
|
actorId: input.actorId,
|
|
|
|
|
action: input.action,
|
|
|
|
|
entityType: input.entityType,
|
|
|
|
|
entityId: input.entityId,
|
|
|
|
|
agentId: input.agentId ?? null,
|
2026-02-19 09:09:40 -06:00
|
|
|
runId: input.runId ?? null,
|
2026-02-19 15:43:52 -06:00
|
|
|
details: sanitizedDetails,
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
});
|
2026-02-17 12:24:43 -06:00
|
|
|
|
|
|
|
|
publishLiveEvent({
|
|
|
|
|
companyId: input.companyId,
|
|
|
|
|
type: "activity.logged",
|
|
|
|
|
payload: {
|
|
|
|
|
actorType: input.actorType,
|
|
|
|
|
actorId: input.actorId,
|
|
|
|
|
action: input.action,
|
|
|
|
|
entityType: input.entityType,
|
|
|
|
|
entityId: input.entityId,
|
|
|
|
|
agentId: input.agentId ?? null,
|
2026-02-19 09:09:40 -06:00
|
|
|
runId: input.runId ?? null,
|
2026-02-19 15:43:52 -06:00
|
|
|
details: sanitizedDetails,
|
2026-02-17 12:24:43 -06:00
|
|
|
},
|
|
|
|
|
});
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
}
|