(
params: ParamsOf<PromptAiSdkStreamFn> & {
skipChatGptOAuth?: boolean
chatGptOAuthRetried?: boolean
},
)
| 284 | } |
| 285 | |
| 286 | export async function* promptAiSdkStream( |
| 287 | params: ParamsOf<PromptAiSdkStreamFn> & { |
| 288 | skipChatGptOAuth?: boolean |
| 289 | chatGptOAuthRetried?: boolean |
| 290 | }, |
| 291 | ): ReturnType<PromptAiSdkStreamFn> { |
| 292 | const { providerOptions: originalProviderOptions, ...streamParams } = params |
| 293 | |
| 294 | const { |
| 295 | logger, |
| 296 | trackEvent, |
| 297 | userId, |
| 298 | userInputId, |
| 299 | model: requestedModel, |
| 300 | } = params |
| 301 | const agentChunkMetadata = |
| 302 | params.agentId != null ? { agentId: params.agentId } : undefined |
| 303 | |
| 304 | if (params.signal.aborted) { |
| 305 | logger.info( |
| 306 | { |
| 307 | userId: params.userId, |
| 308 | userInputId: params.userInputId, |
| 309 | }, |
| 310 | 'Skipping stream due to canceled user input', |
| 311 | ) |
| 312 | return promptAborted('User cancelled input') |
| 313 | } |
| 314 | |
| 315 | const modelParams: ModelRequestParams = { |
| 316 | apiKey: params.apiKey, |
| 317 | model: params.model, |
| 318 | skipChatGptOAuth: params.skipChatGptOAuth, |
| 319 | costMode: params.costMode, |
| 320 | } |
| 321 | const { model: aiSDKModel, isChatGptOAuth } = |
| 322 | await getModelForRequest(modelParams) |
| 323 | |
| 324 | if (isChatGptOAuth) { |
| 325 | trackEvent({ |
| 326 | event: AnalyticsEvent.CHATGPT_OAUTH_REQUEST, |
| 327 | userId: userId ?? '', |
| 328 | properties: { |
| 329 | model: requestedModel, |
| 330 | userInputId, |
| 331 | }, |
| 332 | logger, |
| 333 | }) |
| 334 | } |
| 335 | |
| 336 | const response = streamText({ |
| 337 | ...streamParams, |
| 338 | prompt: undefined, |
| 339 | model: aiSDKModel, |
| 340 | messages: convertCbToModelMessages(params), |
| 341 | ...(isChatGptOAuth && { maxRetries: 0 }), |
| 342 | // For ChatGPT OAuth direct, don't send codebuff metadata/provider options to OpenAI |
| 343 | ...(isChatGptOAuth |
no test coverage detected