(
inputPrompt: string | AsyncIterable<string>,
options: {
sdkUrl: string | undefined
replayUserMessages?: boolean
},
)
| 5435 | } |
| 5436 | |
| 5437 | function getStructuredIO( |
| 5438 | inputPrompt: string | AsyncIterable<string>, |
| 5439 | options: { |
| 5440 | sdkUrl: string | undefined |
| 5441 | replayUserMessages?: boolean |
| 5442 | }, |
| 5443 | ): StructuredIO { |
| 5444 | let inputStream: AsyncIterable<string> |
| 5445 | if (typeof inputPrompt === 'string') { |
| 5446 | if (inputPrompt.trim() !== '') { |
| 5447 | // Normalize to a streaming input. |
| 5448 | inputStream = fromArray([ |
| 5449 | jsonStringify({ |
| 5450 | type: 'user', |
| 5451 | content: inputPrompt, |
| 5452 | uuid: '', |
| 5453 | session_id: '', |
| 5454 | message: { |
| 5455 | role: 'user', |
| 5456 | content: inputPrompt, |
| 5457 | }, |
| 5458 | parent_tool_use_id: null, |
| 5459 | } satisfies SDKUserMessage), |
| 5460 | ]) |
| 5461 | } else { |
| 5462 | // Empty string - create empty stream |
| 5463 | inputStream = fromArray([]) |
| 5464 | } |
| 5465 | } else { |
| 5466 | inputStream = inputPrompt |
| 5467 | } |
| 5468 | |
| 5469 | // Use RemoteIO if sdkUrl is provided, otherwise use regular StructuredIO |
| 5470 | return options.sdkUrl |
| 5471 | ? new RemoteIO(options.sdkUrl, inputStream, options.replayUserMessages) |
| 5472 | : new StructuredIO(inputStream, options.replayUserMessages) |
| 5473 | } |
| 5474 | |
| 5475 | /** |
| 5476 | * Handles unexpected permission responses by looking up the unresolved tool |
no test coverage detected