(
inputPrompt: string | AsyncIterable<string>,
options: {
sdkUrl: string | undefined
replayUserMessages?: boolean
sessionId?: string
},
)
| 5231 | } |
| 5232 | |
| 5233 | function getStructuredIO( |
| 5234 | inputPrompt: string | AsyncIterable<string>, |
| 5235 | options: { |
| 5236 | sdkUrl: string | undefined |
| 5237 | replayUserMessages?: boolean |
| 5238 | sessionId?: string |
| 5239 | }, |
| 5240 | ): StructuredIO { |
| 5241 | let inputStream: AsyncIterable<string> |
| 5242 | if (typeof inputPrompt === 'string') { |
| 5243 | if (inputPrompt.trim() !== '') { |
| 5244 | // Normalize to a streaming input. |
| 5245 | inputStream = fromArray([ |
| 5246 | jsonStringify({ |
| 5247 | type: 'user', |
| 5248 | session_id: '', |
| 5249 | message: { |
| 5250 | role: 'user', |
| 5251 | content: inputPrompt, |
| 5252 | }, |
| 5253 | parent_tool_use_id: null, |
| 5254 | } satisfies SDKUserMessage), |
| 5255 | ]) |
| 5256 | } else { |
| 5257 | // Empty string - create empty stream |
| 5258 | inputStream = fromArray([]) |
| 5259 | } |
| 5260 | } else { |
| 5261 | inputStream = inputPrompt |
| 5262 | } |
| 5263 | |
| 5264 | // Use RemoteIO if sdkUrl is provided, otherwise use regular StructuredIO |
| 5265 | return options.sdkUrl |
| 5266 | ? new RemoteIO( |
| 5267 | options.sdkUrl, |
| 5268 | inputStream, |
| 5269 | options.replayUserMessages, |
| 5270 | options.sessionId, |
| 5271 | ) |
| 5272 | : new StructuredIO(inputStream, options.replayUserMessages) |
| 5273 | } |
| 5274 | |
| 5275 | /** |
| 5276 | * Handles unexpected permission responses by looking up the unresolved tool |
no test coverage detected