(
initialPrompt: AsyncIterable<string> | undefined,
refreshHeaders: () => Record<string, string>,
)
| 295 | } |
| 296 | |
| 297 | private async initializeInput( |
| 298 | initialPrompt: AsyncIterable<string> | undefined, |
| 299 | refreshHeaders: () => Record<string, string>, |
| 300 | ): Promise<void> { |
| 301 | if (this.shouldReplayHistoricalSessionEvents) { |
| 302 | await this.hydrateHistoricalSessionEvents(refreshHeaders) |
| 303 | } |
| 304 | |
| 305 | if (initialPrompt) { |
| 306 | // Convert the initial prompt to the input stream format. |
| 307 | // Chunks from stdin may already contain trailing newlines, so strip |
| 308 | // them before appending our own to avoid double-newline issues that |
| 309 | // cause structuredIO to parse empty lines. String() handles both |
| 310 | // string chunks and Buffer objects from process.stdin. |
| 311 | const stream = this.inputStream |
| 312 | void (async () => { |
| 313 | for await (const chunk of initialPrompt) { |
| 314 | stream.write(String(chunk).replace(/\n$/, '') + '\n') |
| 315 | } |
| 316 | })() |
| 317 | } else if (!this.shouldReplayHistoricalSessionEvents) { |
| 318 | await this.hydrateHistoricalSessionEvents(refreshHeaders) |
| 319 | } |
| 320 | |
| 321 | // Start connection only after all callbacks are wired (setOnData above, |
| 322 | // setOnEvent inside new CCRClient() when CCR v2 is enabled). |
| 323 | void this.transport.connect() |
| 324 | } |
| 325 | |
| 326 | private async hydrateHistoricalSessionEvents( |
| 327 | refreshHeaders: () => Record<string, string>, |
no test coverage detected