Interface: PreUserMessageContext
Makaio Framework / hooks / PreUserMessageContext
Interface: PreUserMessageContext
Section titled “Interface: PreUserMessageContext”Defined in: ../../../packages/hooks/src/types/hook-context.ts:121
PreUserMessage context with enriched session data.
Intercepts: AgentSubjects.sendMessage RPC via request middleware
When sessionId is present in SendMessageRequest, the context builder queries the bus to populate session, recentHistory, and project fields. Without sessionId, these fields remain undefined/empty (hooks may fire before a session is established).
Extends
Section titled “Extends”RequestHookContext<PreUserMessagePayload>.SessionHookContext
Indexable
Section titled “Indexable”[
key:string]:unknown
Properties
Section titled “Properties”
readonlybus:IMakaioBus
Defined in: ../../../packages/hooks/src/types/hook-context.ts:76
Bus instance for making requests
Inherited from
Section titled “Inherited from”contextExtensions
Section titled “contextExtensions”
readonlycontextExtensions:Record<string,unknown>
Defined in: ../../../packages/hooks/src/types/hook-context.ts:82
Arbitrary context extensions contributed by the host-registered
SessionSubjects.enrichContext handler. Framework spreads these onto
the context object at hook-call time. Empty object in OSS mode.
Inherited from
Section titled “Inherited from”SessionHookContext.contextExtensions
correlationId?
Section titled “correlationId?”
readonlyoptionalcorrelationId?:string
Defined in: ../../../packages/hooks/src/types/hook-context.ts:41
Correlation identifier for tracing (optional)
Inherited from
Section titled “Inherited from”RequestHookContext.correlationId
hookEvent
Section titled “hookEvent”
readonlyhookEvent:"PreUserMessage"
Defined in: ../../../packages/hooks/src/types/hook-context.ts:122
messageId?
Section titled “messageId?”
readonlyoptionalmessageId?:string
Defined in: ../../../packages/hooks/src/types/hook-context.ts:39
Message identifier (optional - may not be present if not provided by caller)
Inherited from
Section titled “Inherited from”RequestHookContext.messageId
payload
Section titled “payload”
readonlypayload:PreUserMessagePayload
Defined in: ../../../packages/hooks/src/types/hook-context.ts:37
The request payload (readonly via getter, mutable via replacePayload)
Inherited from
Section titled “Inherited from”RequestHookContext.payload
recentHistory
Section titled “recentHistory”
readonlyrecentHistory:object[]
Defined in: ../../../packages/hooks/src/types/hook-context.ts:74
Recent turn history, oldest first (up to 10 turns)
completedAt?
Section titled “completedAt?”
optionalcompletedAt?:number
Turn completion timestamp (Unix ms)
error?
Section titled “error?”
optionalerror?:string
Error message if status is ‘error’
sessionId
Section titled “sessionId”sessionId:
string
Session this turn belongs to
startedAt
Section titled “startedAt”startedAt:
number
Turn start timestamp (Unix ms)
status
Section titled “status”status:
"error"|"completed"|"active"=TurnStatusSchema
Turn status
turnId
Section titled “turnId”turnId:
string
Unique turn identifier
turnNumber
Section titled “turnNumber”turnNumber:
number
Monotonic per-session ordinal (1-based), assigned by turn storage at creation.
usage?
Section titled “usage?”
optionalusage?:object
Aggregated usage/cost for this turn. Populated on turn completion.
usage.byAgent?
Section titled “usage.byAgent?”
optionalbyAgent?:Record<string, {cost?:number;inputTokens:number;outputTokens:number; }>
Optional per-agent breakdown (for multi-agent turns)
usage.total
Section titled “usage.total”total:
object=UsageMetricsSchema
Total aggregated usage across all agents
usage.total.cost?
Section titled “usage.total.cost?”
optionalcost?:number
Computed cost in USD (optional, requires pricing data)
usage.total.inputTokens
Section titled “usage.total.inputTokens”inputTokens:
number
Input tokens consumed
usage.total.outputTokens
Section titled “usage.total.outputTokens”outputTokens:
number
Output tokens generated
Inherited from
Section titled “Inherited from”SessionHookContext.recentHistory
session?
Section titled “session?”
readonlyoptionalsession?:IMakaioSession
Defined in: ../../../packages/hooks/src/types/hook-context.ts:72
Session object (populated when sessionId is available)
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”abort()
Section titled “abort()”abort(
reason?):never
Defined in: ../../../packages/hooks/src/types/hook-context.ts:139
Abort message processing. Throws HookAbortError.
Parameters
Section titled “Parameters”reason?
Section titled “reason?”string
Returns
Section titled “Returns”never
getTurnContext()
Section titled “getTurnContext()”getTurnContext():
Record<string,JsonValue>
Defined in: ../../../packages/hooks/src/types/hook-context.ts:137
Get turn context set by THIS hook instance. Returns only context set via setTurnContext() in this handler. Context from earlier hooks is merged separately after handler completes.
Returns
Section titled “Returns”Record<string, JsonValue>
Turn context values set by this hook instance only
next()
Section titled “next()”next():
Promise<void>
Defined in: ../../../packages/hooks/src/types/hook-context.ts:54
Continue to the next handler in the middleware chain.
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”RequestHookContext.next
replacePayload()
Section titled “replacePayload()”replacePayload(
newPayload):void
Defined in: ../../../packages/hooks/src/types/hook-context.ts:50
Replace the payload with a new value. Subsequent handlers in the middleware chain will receive the new payload.
Note: Only message and sessionContext can be replaced. Routing fields
(agentId, adapterId, sessionId, messageId, deliveryMode) are
intentionally immutable to preserve message routing integrity.
Parameters
Section titled “Parameters”newPayload
Section titled “newPayload”Partial<P>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”RequestHookContext.replacePayload
setTurnContext()
Section titled “setTurnContext()”setTurnContext(
key,value):void
Defined in: ../../../packages/hooks/src/types/hook-context.ts:130
Set turn context for downstream consumers. Uses replacePayload() to add context to sessionContext.turnContext. Value must be JSON-serializable.
Parameters
Section titled “Parameters”string
Turn context key to write (e.g. ‘guides’, ‘cwdChange’)
JSON-serializable value to store under the key
Returns
Section titled “Returns”void