(client, request3, options)
| 44638 | var components = __importStar(require_components()); |
| 44639 | var errors = __importStar(require_errors2()); |
| 44640 | async function chatStream(client, request3, options) { |
| 44641 | const parsed = (0, schemas_js_1.safeParse)(request3, (value) => components.ChatCompletionStreamRequest$outboundSchema.parse(value), "Input validation failed"); |
| 44642 | if (!parsed.ok) { |
| 44643 | return parsed; |
| 44644 | } |
| 44645 | const payload = parsed.value; |
| 44646 | const body = (0, encodings_js_1.encodeJSON)("body", payload, { explode: true }); |
| 44647 | const path5 = (0, url_js_1.pathToFunc)("/v1/chat/completions#stream")(); |
| 44648 | const headers = new Headers({ |
| 44649 | "Content-Type": "application/json", |
| 44650 | Accept: "text/event-stream" |
| 44651 | }); |
| 44652 | const secConfig = await (0, security_js_1.extractSecurity)(client._options.apiKey); |
| 44653 | const securityInput = secConfig == null ? {} : { apiKey: secConfig }; |
| 44654 | const requestSecurity = (0, security_js_1.resolveGlobalSecurity)(securityInput); |
| 44655 | const context = { |
| 44656 | operationID: "stream_chat", |
| 44657 | oAuth2Scopes: [], |
| 44658 | resolvedSecurity: requestSecurity, |
| 44659 | securitySource: client._options.apiKey, |
| 44660 | retryConfig: (options === null || options === void 0 ? void 0 : options.retries) || client._options.retryConfig || { strategy: "none" }, |
| 44661 | retryCodes: (options === null || options === void 0 ? void 0 : options.retryCodes) || ["429", "500", "502", "503", "504"] |
| 44662 | }; |
| 44663 | const requestRes = client._createRequest(context, { |
| 44664 | security: requestSecurity, |
| 44665 | method: "POST", |
| 44666 | path: path5, |
| 44667 | headers, |
| 44668 | body, |
| 44669 | timeoutMs: (options === null || options === void 0 ? void 0 : options.timeoutMs) || client._options.timeoutMs || -1 |
| 44670 | }, options); |
| 44671 | if (!requestRes.ok) { |
| 44672 | return requestRes; |
| 44673 | } |
| 44674 | const req = requestRes.value; |
| 44675 | const doResult = await client._do(req, { |
| 44676 | context, |
| 44677 | errorCodes: ["422", "4XX", "5XX"], |
| 44678 | retryConfig: context.retryConfig, |
| 44679 | retryCodes: context.retryCodes |
| 44680 | }); |
| 44681 | if (!doResult.ok) { |
| 44682 | return doResult; |
| 44683 | } |
| 44684 | const response = doResult.value; |
| 44685 | const responseFields = { |
| 44686 | HttpMeta: { Response: response, Request: req } |
| 44687 | }; |
| 44688 | const [result] = await M5.match(M5.sse(200, z6.instanceof(ReadableStream).transform((stream4) => { |
| 44689 | return new event_streams_js_1.EventStream({ |
| 44690 | stream: stream4, |
| 44691 | decoder(rawEvent) { |
| 44692 | const schema = components.CompletionEvent$inboundSchema; |
| 44693 | return schema.parse(rawEvent); |
| 44694 | } |
| 44695 | }); |
| 44696 | }), { sseSentinel: "[DONE]" }), M5.jsonErr(422, errors.HTTPValidationError$inboundSchema), M5.fail(["4XX", "5XX"]))(response, { extraFields: responseFields }); |
| 44697 | if (!result.ok) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…