854
*/
855
private _beginSteeringTurn(steering: PendingMessage): string {
857
>
if (previousTurnId) {
858
>
const previousDuration = this._currentTurn?.duration ?? 0;
859
>
this._emitAction({
860
>
type: ActionType.ChatTurnComplete,
861
>
turnId: previousTurnId,
862
>
duration: previousDuration,
863
>
});
864
>
}
865
>
const newTurnId = generateUuid();
866
>
this._emitAction({
867
>
type: ActionType.ChatTurnStarted,
868
>
turnId: newTurnId,
869
>
startedAt: new Date().toISOString(),
870
>
message: steering.message,
871
>
queuedMessageId: steering.id,
872
>
});
873
>
// Mirror `resetTurnState` so per-turn counters/mappings (usage total,
874
>
// streaming part ids) don't bleed from the preempted turn into the new
875
>
// steering turn. The steering turn is created mid-loop in response to an
876
>
// SDK `user.message` event, so the SDK is already actively producing its
877
>
// response: mark it `running` immediately rather than leaving it
878
>
// `pending`, otherwise an abort during the steering turn would treat it
879
>
// as a not-yet-started queued turn and leave it open.
880
>
this.resetTurnState(newTurnId);
881
>
this._currentTurn?.markRunning();
882
>
return newTurnId;
883
>
}
884
885
/**