* Write an internal worker event via POST /sessions/{id}/worker/internal-events. * These events are NOT visible to frontend clients — they store worker-internal * state (transcript messages, compaction markers) needed for session resume.
(
eventType: string,
payload: Record<string, unknown>,
{
isCompaction = false,
agentId,
}: {
isCompaction?: boolean
agentId?: string
} = {},
)
| 791 | * state (transcript messages, compaction markers) needed for session resume. |
| 792 | */ |
| 793 | async writeInternalEvent( |
| 794 | eventType: string, |
| 795 | payload: Record<string, unknown>, |
| 796 | { |
| 797 | isCompaction = false, |
| 798 | agentId, |
| 799 | }: { |
| 800 | isCompaction?: boolean |
| 801 | agentId?: string |
| 802 | } = {}, |
| 803 | ): Promise<void> { |
| 804 | const event: WorkerEvent = { |
| 805 | payload: { |
| 806 | type: eventType, |
| 807 | ...payload, |
| 808 | uuid: typeof payload.uuid === 'string' ? payload.uuid : randomUUID(), |
| 809 | } as EventPayload, |
| 810 | ...(isCompaction && { is_compaction: true }), |
| 811 | ...(agentId && { agent_id: agentId }), |
| 812 | } |
| 813 | await this.internalEventUploader.enqueue(event) |
| 814 | } |
| 815 | |
| 816 | /** |
| 817 | * Flush pending internal events. Call between turns and on shutdown |