feat(cowork-service): prefer canonical audit event ids
This commit is contained in:
parent
69bced0a25
commit
a57b367fe5
@ -164,6 +164,7 @@ describe('agent runtime routes', () => {
|
||||
action: 'approval_granted',
|
||||
timestamp: '2026-04-04T09:00:00.000Z',
|
||||
details: {
|
||||
eventId: 'evt_cowork_approval_1',
|
||||
taskId: 'task-1',
|
||||
sessionId: 'sess-1',
|
||||
tool: 'rm',
|
||||
@ -182,7 +183,7 @@ describe('agent runtime routes', () => {
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = JSON.parse(res.payload);
|
||||
expect(body.approvals[0]).toMatchObject({
|
||||
approvalId: 'audit-1',
|
||||
approvalId: 'evt_cowork_approval_1',
|
||||
sessionId: 'sess-1',
|
||||
runId: 'task-1',
|
||||
status: 'approved',
|
||||
@ -201,6 +202,7 @@ describe('agent runtime routes', () => {
|
||||
category: 'execution',
|
||||
timestamp: '2026-04-04T09:05:00.000Z',
|
||||
details: {
|
||||
eventId: 'evt_cowork_action_1',
|
||||
taskId: 'task-1',
|
||||
sessionId: 'sess-1',
|
||||
correlationId: 'corr-1',
|
||||
@ -215,7 +217,7 @@ describe('agent runtime routes', () => {
|
||||
expect(res.statusCode).toBe(200);
|
||||
const body = JSON.parse(res.payload);
|
||||
expect(body.actions[0]).toMatchObject({
|
||||
actionLogId: 'audit-2',
|
||||
actionLogId: 'evt_cowork_action_1',
|
||||
sessionId: 'sess-1',
|
||||
runId: 'task-1',
|
||||
eventName: 'task_completed',
|
||||
|
||||
@ -168,6 +168,19 @@ function mapResolverSurface(surface: unknown): 'mobile' | 'web' | 'desktop' | nu
|
||||
}
|
||||
}
|
||||
|
||||
function getCanonicalAuditEventId(
|
||||
record: Record<string, unknown>,
|
||||
details: Record<string, unknown>
|
||||
): string | null {
|
||||
if (typeof details.eventId === 'string' && details.eventId.length > 0) {
|
||||
return details.eventId;
|
||||
}
|
||||
if (typeof record.id === 'string' && record.id.length > 0) {
|
||||
return record.id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function toApprovalCheckpoint(
|
||||
record: Record<string, unknown>,
|
||||
fallbackNow: string
|
||||
@ -178,10 +191,10 @@ function toApprovalCheckpoint(
|
||||
: {};
|
||||
const status = mapApprovalStatus(record.action);
|
||||
const requestedAt = asIsoString(record.timestamp ?? record.createdAt, fallbackNow);
|
||||
const canonicalEventId = getCanonicalAuditEventId(record, details);
|
||||
|
||||
return AgentApprovalCheckpointSchema.parse({
|
||||
approvalId:
|
||||
typeof record.id === 'string' && record.id.length > 0 ? record.id : `approval_${fallbackNow}`,
|
||||
approvalId: canonicalEventId ?? `approval_${fallbackNow}`,
|
||||
sessionId:
|
||||
typeof details.sessionId === 'string' && details.sessionId.length > 0
|
||||
? details.sessionId
|
||||
@ -226,6 +239,7 @@ function toActionLog(record: Record<string, unknown>, fallbackNow: string): Agen
|
||||
record.details && typeof record.details === 'object'
|
||||
? (record.details as Record<string, unknown>)
|
||||
: {};
|
||||
const canonicalEventId = getCanonicalAuditEventId(record, details);
|
||||
const sessionId =
|
||||
typeof details.sessionId === 'string' && details.sessionId.length > 0
|
||||
? details.sessionId
|
||||
@ -240,8 +254,7 @@ function toActionLog(record: Record<string, unknown>, fallbackNow: string): Agen
|
||||
: 'unknown-run';
|
||||
|
||||
return AgentActionLogSchema.parse({
|
||||
actionLogId:
|
||||
typeof record.id === 'string' && record.id.length > 0 ? record.id : `action_${fallbackNow}`,
|
||||
actionLogId: canonicalEventId ?? `action_${fallbackNow}`,
|
||||
sessionId,
|
||||
runId,
|
||||
eventName:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user