import { randomUUID } from "node:crypto"; import type { BaseEvent, PrivacyProfile, UltraConfig } from "../types.js"; export type UltraEventType = | "agent.cancelled" | "agent.completed" | "agent.failed" | "agent.signal.failed" | "agent.spawn.proposed" | "agent.spawn.rejected" | "agent.spawned" | "agent.steer.rejected" | "agent.steered" | "attribution.created" | "blackboard.event" | "budget.accounting_incomplete" | "budget.allocated" | "budget.hard_limit" | "budget.soft_limit" | "budget.updated" | "config.changed" | "context.threshold" | "coverage.evaluated" | "decomposition.validated" | "destructive.command.completed" | "envelope.measured" | "escalation.triggered" | "experiment.assigned" | "experiment.evaluated" | "experiment.started" | "experiment.stopped" | "export.created" | "failure.fingerprinted" | "feedback.explicit" | "feedback.implicit" | "governance.violation" | "handoff.received" | "handoff.sent" | "model.call.completed" | "model.call.failed" | "model.call.started" | "model.changed" | "model.rotated" | "model.rotation.blocked" | "preflight.completed" | "provider.health.changed" | "recommendation.accepted" | "recommendation.rejected" | "recovery.created" | "recovery.failed" | "recovery.stopped" | "repair.attempted" | "repair.failed" | "repair.started" | "request.classified" | "request.received" | "request.sanitized" | "result.completed" | "review.completed" | "review.failed" | "root.selection.completed" | "route.changed" | "route.proposed" | "route.validated" | "safety.incident" | "session.compacted" | "session.ended" | "session.started" | "specialist.requested" | "task.context.measured" | "tool.completed" | "tool.failed" | "tool.started" | "user.feedback" | "verification.completed" | "verification.started" | "warroom.converged" | "workflow.completed" | "workflow.failed" | "workflow.node.completed" | "workflow.node.started" | "workflow.started" | "worktree.cleanup.failed" | "worktree.created" | "worktree.integrated" | "worktree.integration.failed" | "worktree.removed"; export interface EventIdentity { sessionId: string; taskId: string; runId: string; spanId?: string; parentSpanId?: string; experimentId?: string } export function event(config: UltraConfig, profile: PrivacyProfile, identity: EventIdentity, eventType: UltraEventType, fields: Record = {}, now = new Date()): BaseEvent { return { schemaVersion: 1, eventId: randomUUID(), timestamp: now.toISOString(), sessionId: identity.sessionId, taskId: identity.taskId, runId: identity.runId, spanId: identity.spanId ?? randomUUID(), ...(identity.parentSpanId ? { parentSpanId: identity.parentSpanId } : {}), configVersion: config.configVersion, policyVersion: config.policyVersion, ...(identity.experimentId ? { experimentId: identity.experimentId } : {}), profile, eventType, ...fields }; }