* Send a user message and stream back normalized events. The caller * (desktop main) is expected to forward the events to the renderer over * the IPC bridge. * * Runtime v2 bridge: SessionManager remains the public facade; RuntimeKernel * owns AgentRun/AiSdkFlow/RuntimeRunner orchestr
(
sessionId: string,
input: UserMessageInput,
options: TurnStartOptions = {},
)
| 2037 | * owns AgentRun/AiSdkFlow/RuntimeRunner orchestration and ledger recording. |
| 2038 | */ |
| 2039 | async *sendMessage( |
| 2040 | sessionId: string, |
| 2041 | input: UserMessageInput, |
| 2042 | options: TurnStartOptions = {}, |
| 2043 | ): AsyncIterable<SessionEvent> { |
| 2044 | if (input.origin?.kind === 'legacy_automation') { |
| 2045 | throw new Error('Live Turn cannot use removed Automation authority'); |
| 2046 | } |
| 2047 | const repair = input.agentId ? undefined : this.runtimeLedgerRepair; |
| 2048 | const admitTurn = repair |
| 2049 | ? async () => { |
| 2050 | await this.ensureTranscriptLedger(sessionId, repair, 'compatibility'); |
| 2051 | return (await options.admitTurn?.()) ?? 'admitted'; |
| 2052 | } |
| 2053 | : options.admitTurn; |
| 2054 | const sourceText = sessionTitleSource(input); |
| 2055 | const onRunStarted = this.deps.generateSessionTitle |
| 2056 | ? async (runId: string, header: SessionHeader) => { |
| 2057 | await options.onRunStarted?.(runId, header); |
| 2058 | if ( |
| 2059 | !header.connectionLocked && |
| 2060 | !header.titleIsManual && |
| 2061 | header.name === DEFAULT_SESSION_NAME && |
| 2062 | sourceText |
| 2063 | ) { |
| 2064 | void this.generateTitleInBackground(sessionId, header, sourceText); |
| 2065 | } |
| 2066 | } |
| 2067 | : options.onRunStarted; |
| 2068 | yield* this.runtimeKernel.startTurn(sessionId, input, { ...options, admitTurn, onRunStarted }); |
| 2069 | } |
| 2070 | |
| 2071 | private async generateTitleInBackground( |
| 2072 | sessionId: string, |
no test coverage detected