Skip to content

Function: assembleForkContext()

Makaio Framework


Makaio Framework / services-core / assembleForkContext

assembleForkContext(bus, session, sessionId, originalContext?, isNewTurn?): Promise<{ extractedContext?: unknown; hasCompression?: boolean; hasConnectorSwap?: boolean; hasNewTransforms?: boolean; isFirstTurn?: boolean; messageHistory?: object[]; turnContext?: Record<string, JsonValue>; } | undefined>

Defined in: ../../../packages/services/core/src/session/context/assemble-fork-context.ts:25

Assemble fork context for a session’s first turn.

For fork sessions on their first turn, this:

  1. Detects if this is a fork session (has parentSessionId)
  2. Checks if this is the first turn (via isNewTurn flag + storage query)
  3. Calls getFullConversation() to get projected context with transforms
  4. Converts SessionMessage[] to Message[] format
  5. Returns enriched SessionContext with messageHistory

If not a fork first turn, returns the original sessionContext unchanged.

IMakaioBus

Bus instance for RPC calls

IMakaioSession

Session to check for fork context

string

Session ID

Original sessionContext from payload

unknown = ...

Structured context from compression (if hasCompression=true).

boolean = ...

Whether compression is active (extractedContext present). If true, Agent should use fresh mode with compressed context.

boolean = ...

Whether a connector swap occurred before this message (e.g., cwd/model change). If true, native resume is infeasible and adapters should use fresh mode.

boolean = ...

Whether transforms have been applied since last turn. If true, Agent should use fresh mode (history changed).

boolean = ...

Whether this is the first turn in the session. If true, no native history exists yet.

object[] = ...

Curated message history assembled via getFullConversation(). Only used if Agent decides to inject (fresh mode).

Record<string, JsonValue> = ...

Turn-scoped context assembled by PreUserMessage hooks and the orchestrator. Keys are plugin-defined (e.g., ‘skillCatalog’, ‘skills’, ‘predictedTools’). Adapters consume this to prepend context blocks.

Constrained to JSON-safe types to ensure serialization succeeds.

ADAPTER CONTRACT: Every adapter MUST materialize turnContext into the LLM-facing message using serializeTurnContext().

boolean

Whether this is a new turn (avoids race with just-created turn record)

Promise<{ extractedContext?: unknown; hasCompression?: boolean; hasConnectorSwap?: boolean; hasNewTransforms?: boolean; isFirstTurn?: boolean; messageHistory?: object[]; turnContext?: Record<string, JsonValue>; } | undefined>

Enriched or original SessionContext