Skip to content

Function: isKnownSessionEvent()

Makaio Framework


Makaio Framework / contracts / isKnownSessionEvent

isKnownSessionEvent(event): event is KnownSessionEvent

Defined in: ../../../packages/contracts/src/session/types.ts:121

Type guard that narrows a MakaioSessionEvent to KnownSessionEvent.

Safe at Zod parse boundaries because MakaioSessionEventSchema validates core event types via z.discriminatedUnion. The catch-all PluginSessionEventSchema is excluded by its own refine (rejects core types), so any event whose type matches a core literal is guaranteed to have the matching payload shape.

Note: this guard checks the core SESSION_EVENT_TYPES list only. Plugin event types are not included — they pass through the catch-all branch and will return false here. If runtime registration of plugin event types is needed, a separate registry mechanism should be introduced.

{ eventId: string; payload: { adapterId: string; adapterName: string; adapterSessionId: string; agentId: string; cwd?: string; model?: string; role?: "lead" | "member"; sessionId: string; }; sessionId: string; timestamp: number; type: "agent.added"; } | { eventId: string; payload: { agentIds: string[]; content: string | { blocks: { content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; } | ({ content: string; type: "text"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "image"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "attachment"; } | { content: string; metadata?: Record<…, …>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; })[]; role?: "user" | "assistant" | "system"; }; messageId: string; origin?: "text" | "voice" | "compact"; sessionId: string; source?: "user" | "extension" | "system"; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "user_message.sent"; } | { eventId: string; payload: { agentId: string; messageId: string; sessionId: string; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "user_message.acknowledged"; } | { eventId: string; payload: { agentId: string; error?: string; mergedInto?: string; messageId: string; outcome: "error" | "completed" | "superseded" | "merged" | "cancelled" | "rejected"; sessionId: string; supersededBy?: string; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "user_message.completed"; } | { eventId: string; payload: { agentIds: string[]; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; messageId: string; sessionId: string; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "turn.started"; } | { eventId: string; payload: { error?: string; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; sessionId: string; success: boolean; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "turn.completed"; } | { eventId: string; payload: { messageId: string; role: "user" | "assistant"; turnId: string | null; }; sessionId: string; timestamp: number; type: "message"; } | { eventId: string; payload: { childSessionId: string; forkPointMessageId?: string; kind: "fork" | "branch" | "aside" | "subagent" | "compress" | "rewrite" | "coordinator"; parentSessionId: string; }; sessionId: string; timestamp: number; type: "branch.created"; } | { eventId: string; payload: { childSessionId: string; parentSessionId: string; resultJson?: string; resultMessageId?: string; }; sessionId: string; timestamp: number; type: "branch.merged"; } | { eventId: string; payload: { compressedMessageIds?: string[]; summaryJson: string; tokensAfter?: number; tokensBefore?: number; }; sessionId: string; timestamp: number; type: "squash"; } | { eventId: string; payload: Record<string, unknown>; sessionId: string; timestamp: number; type: string; }

Any Zod-validated session event

{ eventId: string; payload: { adapterId: string; adapterName: string; adapterSessionId: string; agentId: string; cwd?: string; model?: string; role?: "lead" | "member"; sessionId: string; }; sessionId: string; timestamp: number; type: "agent.added"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ adapterId: string; adapterName: string; adapterSessionId: string; agentId: string; cwd?: string; model?: string; role?: "lead" | "member"; sessionId: string; } = ...

string = ...

string = ...

string = ...

string = ...

string = ...

string = ...

"lead" | "member" = ...

string = ...

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"agent.added" = ...


{ eventId: string; payload: { agentIds: string[]; content: string | { blocks: { content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; } | ({ content: string; type: "text"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "image"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "attachment"; } | { content: string; metadata?: Record<…, …>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; })[]; role?: "user" | "assistant" | "system"; }; messageId: string; origin?: "text" | "voice" | "compact"; sessionId: string; source?: "user" | "extension" | "system"; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "user_message.sent"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ agentIds: string[]; content: string | { blocks: { content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; } | ({ content: string; type: "text"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "image"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "attachment"; } | { content: string; metadata?: Record<…, …>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; })[]; role?: "user" | "assistant" | "system"; }; messageId: string; origin?: "text" | "voice" | "compact"; sessionId: string; source?: "user" | "extension" | "system"; turnId: string; turnNumber: number; } = ...

string[] = ...

Targeted agent IDs

string | { blocks: { content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; } | ({ content: string; type: "text"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "image"; } | { source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: …; mimeType: …; type: …; } | { mimeType?: …; type: …; url: …; }; type: "attachment"; } | { content: string; metadata?: Record<…, …>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; })[]; role?: "user" | "assistant" | "system"; } = MessageInputSchema

Message content

string = ...

User message identifier

"text" | "voice" | "compact" = ...

Message origin (for example, voice input pipeline)

string = ...

Makaio session ID

"user" | "extension" | "system" = ...

Request source provenance from session.sendMessage payload

string = ...

Turn identifier (UUID)

number = ...

Monotonic per-session ordinal (1-based).

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"user_message.sent" = ...


{ eventId: string; payload: { agentId: string; messageId: string; sessionId: string; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "user_message.acknowledged"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ agentId: string; messageId: string; sessionId: string; turnId: string; turnNumber: number; } = ...

string = ...

Agent that acknowledged

string = ...

User message identifier

string = ...

Makaio session ID

string = ...

Turn identifier (UUID)

number = ...

Monotonic per-session ordinal (1-based).

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"user_message.acknowledged" = ...


{ eventId: string; payload: { agentId: string; error?: string; mergedInto?: string; messageId: string; outcome: "error" | "completed" | "superseded" | "merged" | "cancelled" | "rejected"; sessionId: string; supersededBy?: string; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "user_message.completed"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ agentId: string; error?: string; mergedInto?: string; messageId: string; outcome: "error" | "completed" | "superseded" | "merged" | "cancelled" | "rejected"; sessionId: string; supersededBy?: string; turnId: string; turnNumber: number; } = ...

string = ...

Agent that completed processing

string = ...

Error message when outcome=‘error’

string = ...

Present when outcome=‘merged’: the messageId this was folded into

string = ...

User message identifier

"error" | "completed" | "superseded" | "merged" | "cancelled" | "rejected" = MessageOutcomeSchema

Processing outcome

string = ...

Makaio session ID

string = ...

Present when outcome=‘superseded’: the messageId that replaced this one

string = ...

Turn identifier (UUID)

number = ...

Monotonic per-session ordinal (1-based).

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"user_message.completed" = ...


{ eventId: string; payload: { agentIds: string[]; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; messageId: string; sessionId: string; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "turn.started"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ agentIds: string[]; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; messageId: string; sessionId: string; turnId: string; turnNumber: number; } = ...

string[] = ...

Agents targeted for this turn

{ source: "user" | "extension" | "system"; sourceId?: string; } = ...

Origin of the turn (for loop prevention and audit)

"user" | "extension" | "system" = ...

Origin category

string = ...

Identifier for the specific origin.

Examples: 'routine:validation', 'loop', 'subagent:xyz'.

string = ...

First message that initiated this turn

string = ...

Makaio session ID

string = ...

Turn identifier (UUID)

number = ...

Monotonic per-session ordinal (1-based).

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"turn.started" = ...


{ eventId: string; payload: { error?: string; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; sessionId: string; success: boolean; turnId: string; turnNumber: number; }; sessionId: string; timestamp: number; type: "turn.completed"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ error?: string; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; sessionId: string; success: boolean; turnId: string; turnNumber: number; } = ...

string = ...

Error message if any agent failed

{ source: "user" | "extension" | "system"; sourceId?: string; } = ...

Origin of the turn (for loop prevention and audit)

"user" | "extension" | "system" = ...

Origin category

string = ...

Identifier for the specific origin.

Examples: 'routine:validation', 'loop', 'subagent:xyz'.

string = ...

Makaio session ID

boolean = ...

Whether all agents completed successfully

string = ...

Turn identifier (UUID)

number = ...

Monotonic per-session ordinal (1-based).

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"turn.completed" = ...


{ eventId: string; payload: { messageId: string; role: "user" | "assistant"; turnId: string | null; }; sessionId: string; timestamp: number; type: "message"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ messageId: string; role: "user" | "assistant"; turnId: string | null; } = ...

string = ...

"user" | "assistant" = ...

string | null = ...

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"message" = ...


{ eventId: string; payload: { childSessionId: string; forkPointMessageId?: string; kind: "fork" | "branch" | "aside" | "subagent" | "compress" | "rewrite" | "coordinator"; parentSessionId: string; }; sessionId: string; timestamp: number; type: "branch.created"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ childSessionId: string; forkPointMessageId?: string; kind: "fork" | "branch" | "aside" | "subagent" | "compress" | "rewrite" | "coordinator"; parentSessionId: string; } = ...

string = ...

The session that was created

string = ...

Message ID where the branch diverged (last shared message)

"fork" | "branch" | "aside" | "subagent" | "compress" | "rewrite" | "coordinator" = BranchKindSchema

Type of branch

string = ...

The parent session it branched from

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"branch.created" = ...


{ eventId: string; payload: { childSessionId: string; parentSessionId: string; resultJson?: string; resultMessageId?: string; }; sessionId: string; timestamp: number; type: "branch.merged"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ childSessionId: string; parentSessionId: string; resultJson?: string; resultMessageId?: string; } = ...

string = ...

The branch session that was merged

string = ...

The parent session it merged into

string = ...

Summary/result injected into parent (JSON string)

string = ...

Message ID of the injected summary in parent session

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"branch.merged" = ...


{ eventId: string; payload: { compressedMessageIds?: string[]; summaryJson: string; tokensAfter?: number; tokensBefore?: number; }; sessionId: string; timestamp: number; type: "squash"; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

{ compressedMessageIds?: string[]; summaryJson: string; tokensAfter?: number; tokensBefore?: number; } = ...

string[] = ...

Message IDs that were compressed (for audit)

string = ...

Structured summary JSON that replaces prior context

number = ...

Token count after compression

number = ...

Token count before compression

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

"squash" = ...


{ eventId: string; payload: Record<string, unknown>; sessionId: string; timestamp: number; type: string; }

Any Zod-validated session event

string = ...

Stable unique identifier for this event row.

Record<string, unknown> = ...

string = ...

Session the event belongs to.

number = ...

Unix epoch milliseconds when the event was recorded.

string = ...

event is KnownSessionEvent

true when event.type is a known core session event type