Function: isKnownSessionEvent()
Makaio Framework / contracts / isKnownSessionEvent
Function: isKnownSessionEvent()
Section titled “Function: 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.
Parameters
Section titled “Parameters”{ 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
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ adapterId: string; adapterName: string; adapterSessionId: string; agentId: string; cwd?: string; model?: string; role?: "lead" | "member"; sessionId: string; } = ...
payload.adapterId
Section titled “payload.adapterId”string = ...
payload.adapterName
Section titled “payload.adapterName”string = ...
payload.adapterSessionId
Section titled “payload.adapterSessionId”string = ...
payload.agentId
Section titled “payload.agentId”string = ...
payload.cwd?
Section titled “payload.cwd?”string = ...
payload.model?
Section titled “payload.model?”string = ...
payload.role?
Section titled “payload.role?”"lead" | "member" = ...
payload.sessionId
Section titled “payload.sessionId”string = ...
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"agent.added" = ...
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “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; } = ...
payload.agentIds
Section titled “payload.agentIds”string[] = ...
Targeted agent IDs
payload.content
Section titled “payload.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"; } = MessageInputSchema
Message content
payload.messageId
Section titled “payload.messageId”string = ...
User message identifier
payload.origin?
Section titled “payload.origin?”"text" | "voice" | "compact" = ...
Message origin (for example, voice input pipeline)
payload.sessionId
Section titled “payload.sessionId”string = ...
Makaio session ID
payload.source?
Section titled “payload.source?”"user" | "extension" | "system" = ...
Request source provenance from session.sendMessage payload
payload.turnId
Section titled “payload.turnId”string = ...
Turn identifier (UUID)
payload.turnNumber
Section titled “payload.turnNumber”number = ...
Monotonic per-session ordinal (1-based).
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"user_message.sent" = ...
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ agentId: string; messageId: string; sessionId: string; turnId: string; turnNumber: number; } = ...
payload.agentId
Section titled “payload.agentId”string = ...
Agent that acknowledged
payload.messageId
Section titled “payload.messageId”string = ...
User message identifier
payload.sessionId
Section titled “payload.sessionId”string = ...
Makaio session ID
payload.turnId
Section titled “payload.turnId”string = ...
Turn identifier (UUID)
payload.turnNumber
Section titled “payload.turnNumber”number = ...
Monotonic per-session ordinal (1-based).
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"user_message.acknowledged" = ...
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ agentId: string; error?: string; mergedInto?: string; messageId: string; outcome: "error" | "completed" | "superseded" | "merged" | "cancelled" | "rejected"; sessionId: string; supersededBy?: string; turnId: string; turnNumber: number; } = ...
payload.agentId
Section titled “payload.agentId”string = ...
Agent that completed processing
payload.error?
Section titled “payload.error?”string = ...
Error message when outcome=‘error’
payload.mergedInto?
Section titled “payload.mergedInto?”string = ...
Present when outcome=‘merged’: the messageId this was folded into
payload.messageId
Section titled “payload.messageId”string = ...
User message identifier
payload.outcome
Section titled “payload.outcome”"error" | "completed" | "superseded" | "merged" | "cancelled" | "rejected" = MessageOutcomeSchema
Processing outcome
payload.sessionId
Section titled “payload.sessionId”string = ...
Makaio session ID
payload.supersededBy?
Section titled “payload.supersededBy?”string = ...
Present when outcome=‘superseded’: the messageId that replaced this one
payload.turnId
Section titled “payload.turnId”string = ...
Turn identifier (UUID)
payload.turnNumber
Section titled “payload.turnNumber”number = ...
Monotonic per-session ordinal (1-based).
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"user_message.completed" = ...
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ agentIds: string[]; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; messageId: string; sessionId: string; turnId: string; turnNumber: number; } = ...
payload.agentIds
Section titled “payload.agentIds”string[] = ...
Agents targeted for this turn
payload.initiator?
Section titled “payload.initiator?”{ source: "user" | "extension" | "system"; sourceId?: string; } = ...
Origin of the turn (for loop prevention and audit)
payload.initiator.source
Section titled “payload.initiator.source”"user" | "extension" | "system" = ...
Origin category
payload.initiator.sourceId?
Section titled “payload.initiator.sourceId?”string = ...
Identifier for the specific origin.
Examples: 'routine:validation', 'loop', 'subagent:xyz'.
payload.messageId
Section titled “payload.messageId”string = ...
First message that initiated this turn
payload.sessionId
Section titled “payload.sessionId”string = ...
Makaio session ID
payload.turnId
Section titled “payload.turnId”string = ...
Turn identifier (UUID)
payload.turnNumber
Section titled “payload.turnNumber”number = ...
Monotonic per-session ordinal (1-based).
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"turn.started" = ...
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ error?: string; initiator?: { source: "user" | "extension" | "system"; sourceId?: string; }; sessionId: string; success: boolean; turnId: string; turnNumber: number; } = ...
payload.error?
Section titled “payload.error?”string = ...
Error message if any agent failed
payload.initiator?
Section titled “payload.initiator?”{ source: "user" | "extension" | "system"; sourceId?: string; } = ...
Origin of the turn (for loop prevention and audit)
payload.initiator.source
Section titled “payload.initiator.source”"user" | "extension" | "system" = ...
Origin category
payload.initiator.sourceId?
Section titled “payload.initiator.sourceId?”string = ...
Identifier for the specific origin.
Examples: 'routine:validation', 'loop', 'subagent:xyz'.
payload.sessionId
Section titled “payload.sessionId”string = ...
Makaio session ID
payload.success
Section titled “payload.success”boolean = ...
Whether all agents completed successfully
payload.turnId
Section titled “payload.turnId”string = ...
Turn identifier (UUID)
payload.turnNumber
Section titled “payload.turnNumber”number = ...
Monotonic per-session ordinal (1-based).
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"turn.completed" = ...
Type Literal
Section titled “Type Literal”{ eventId: string; payload: { messageId: string; role: "user" | "assistant"; turnId: string | null; }; sessionId: string; timestamp: number; type: "message"; }
Any Zod-validated session event
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ messageId: string; role: "user" | "assistant"; turnId: string | null; } = ...
payload.messageId
Section titled “payload.messageId”string = ...
payload.role
Section titled “payload.role”"user" | "assistant" = ...
payload.turnId
Section titled “payload.turnId”string | null = ...
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"message" = ...
Type Literal
Section titled “Type Literal”{ 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
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ childSessionId: string; forkPointMessageId?: string; kind: "fork" | "branch" | "aside" | "subagent" | "compress" | "rewrite" | "coordinator"; parentSessionId: string; } = ...
payload.childSessionId
Section titled “payload.childSessionId”string = ...
The session that was created
payload.forkPointMessageId?
Section titled “payload.forkPointMessageId?”string = ...
Message ID where the branch diverged (last shared message)
payload.kind
Section titled “payload.kind”"fork" | "branch" | "aside" | "subagent" | "compress" | "rewrite" | "coordinator" = BranchKindSchema
Type of branch
payload.parentSessionId
Section titled “payload.parentSessionId”string = ...
The parent session it branched from
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"branch.created" = ...
Type Literal
Section titled “Type Literal”{ eventId: string; payload: { childSessionId: string; parentSessionId: string; resultJson?: string; resultMessageId?: string; }; sessionId: string; timestamp: number; type: "branch.merged"; }
Any Zod-validated session event
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ childSessionId: string; parentSessionId: string; resultJson?: string; resultMessageId?: string; } = ...
payload.childSessionId
Section titled “payload.childSessionId”string = ...
The branch session that was merged
payload.parentSessionId
Section titled “payload.parentSessionId”string = ...
The parent session it merged into
payload.resultJson?
Section titled “payload.resultJson?”string = ...
Summary/result injected into parent (JSON string)
payload.resultMessageId?
Section titled “payload.resultMessageId?”string = ...
Message ID of the injected summary in parent session
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"branch.merged" = ...
Type Literal
Section titled “Type Literal”{ eventId: string; payload: { compressedMessageIds?: string[]; summaryJson: string; tokensAfter?: number; tokensBefore?: number; }; sessionId: string; timestamp: number; type: "squash"; }
Any Zod-validated session event
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”{ compressedMessageIds?: string[]; summaryJson: string; tokensAfter?: number; tokensBefore?: number; } = ...
payload.compressedMessageIds?
Section titled “payload.compressedMessageIds?”string[] = ...
Message IDs that were compressed (for audit)
payload.summaryJson
Section titled “payload.summaryJson”string = ...
Structured summary JSON that replaces prior context
payload.tokensAfter?
Section titled “payload.tokensAfter?”number = ...
Token count after compression
payload.tokensBefore?
Section titled “payload.tokensBefore?”number = ...
Token count before compression
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
"squash" = ...
Type Literal
Section titled “Type Literal”{ eventId: string; payload: Record<string, unknown>; sessionId: string; timestamp: number; type: string; }
Any Zod-validated session event
eventId
Section titled “eventId”string = ...
Stable unique identifier for this event row.
payload
Section titled “payload”Record<string, unknown> = ...
sessionId
Section titled “sessionId”string = ...
Session the event belongs to.
timestamp
Section titled “timestamp”number = ...
Unix epoch milliseconds when the event was recorded.
string = ...
Returns
Section titled “Returns”event is KnownSessionEvent
true when event.type is a known core session event type