Skip to content

Class: ProceduralConnectorTurn<TState, TBus, TSubject>

Makaio Framework


Makaio Framework / ai-adapters-core / ProceduralConnectorTurn

Class: ProceduralConnectorTurn<TState, TBus, TSubject>

Section titled “Class: ProceduralConnectorTurn<TState, TBus, TSubject>”

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:60

Base turn implementation for procedural adapters (Gemini, OpenAI, Copilot).

These adapters share an abort+restart pattern rather than true pause/resume. This class extracts the common state machine, lifecycle methods, and message handle delegation that was duplicated across all three.

Subclasses only need to add adapter-specific behavior:

  • Gemini: AbortController for SDK cancellation
  • OpenAI: AbortController for SDK cancellation
  • Copilot: SDK event handling (handleSdkEvent)

TState extends string = ProceduralTurnState

Turn state type (defaults to ProceduralTurnState)

TBus extends ScopedBus<string> = ScopedBus<string>

Scoped bus type for the adapter

TSubject extends ScopedSubjectDefinition = ScopedSubjectDefinition

Subject definition type for emit calls

new ProceduralConnectorTurn<TState, TBus, TSubject>(config, initialState): ProceduralConnectorTurn<TState, TBus, TSubject>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:71

ProceduralTurnConfig<TBus, TSubject>

TState

ProceduralConnectorTurn<TState, TBus, TSubject>

BaseConnectorTurn.constructor

protected aborted: boolean = false

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:69


protected activeMessageHandle: MessageHandle

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:65

Active message handle for this turn. Subclasses must provide this handle for message lifecycle management.

BaseConnectorTurn.activeMessageHandle


protected readonly adapterId: string

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:31

BaseConnectorTurn.adapterId


protected readonly adapterName: string

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:32

BaseConnectorTurn.adapterName


protected readonly agentId: string

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:67


protected readonly bus: ScopedBus<string>

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:30

BaseConnectorTurn.bus


protected readonly connectorBus: TBus

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:66


protected state: TState

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:29

BaseConnectorTurn.state


protected optional stateChangedCallback?: (oldState, newState) => void | Promise<void>

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:33

TState

TState

void | Promise<void>

BaseConnectorTurn.stateChangedCallback


protected readonly turnSubjects: TurnSubjects<TSubject>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:68

canAcceptImmediate(): boolean

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:192

Check if turn can accept immediate message. True if turn is active (not finished, not aborted).

boolean

True if turn can accept an immediate message


protected emitStateChange(oldState, newState): Promise<void>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:84

Emit state change using adapter-provided turn subjects.

TState

Previous state before transition

TState

New state after transition

Promise<void>

BaseConnectorTurn.emitStateChange


getMessageHandle(): MessageHandle

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:111

Get the message handle for this turn.

MessageHandle

The message handle for this turn

BaseConnectorTurn.getMessageHandle


getState(): TState

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:103

Get current turn state.

TState

Current turn state

BaseConnectorTurn.getState


isCompleted(): boolean

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:183

Check if turn is completed.

boolean

True if turn has finished


isPaused(): boolean

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:175

Check if turn was aborted.

boolean

True if turn was aborted

BaseConnectorTurn.isPaused


markAcknowledged(): void

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:118

Mark message handle as acknowledged.

void

BaseConnectorTurn.markAcknowledged


markCompleted(result): void

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:126

Mark message handle as completed.

The completion result with outcome and optional result/error

unknown

string

unknown

void

BaseConnectorTurn.markCompleted


markStepFinished(): Promise<void>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:132

Transition to step_finished (called after content block completes).

Promise<void>


markStepStarted(): Promise<void>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:123

Transition to step_started (called when first content arrives). Allows turn_started to step_started AND step_finished to step_started (for tool recursion).

Promise<void>


markTurnFinished(): Promise<void>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:141

Mark turn as finished.

Promise<void>


onStateChanged(cb): void

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:69

Register callback for state changes.

(oldState, newState) => void | Promise<void>

Callback to invoke on state transitions

void

BaseConnectorTurn.onStateChanged


pause(): Promise<PauseResult<TState>>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:151

Pause (abort) at next opportunity. Procedural adapters don’t support true pause - caller creates a new turn with merged content instead.

Promise<PauseResult<TState>>

Pause result indicating turn state

BaseConnectorTurn.pause


resume(_message?): Promise<void>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:167

Resume is not supported for procedural adapters - caller creates new turn.

unknown

Unused

Promise<void>

Error always

BaseConnectorTurn.resume


start(): Promise<void>

Defined in: ../../../adapters/core/src/connector/procedural-connector-turn.ts:114

Start the turn.

Promise<void>


protected transitionTo(newState): Promise<void>

Defined in: ../../../adapters/core/src/connector/base-connector-turn.ts:81

Transition to new state and notify listeners. Template method for shared state transition pattern.

NOTE: Subclasses should use their typed namespace subjects for emission. This is a template - concrete implementation in adapter-specific Turn classes.

TState

New state to transition to

Promise<void>

BaseConnectorTurn.transitionTo