(line)
| 703 | // Create content array with text and files |
| 704 | const contentArray = [ |
| 705 | { type: 'text', text: lastUserMsg.content }, |
| 706 | ...multimodalContent |
| 707 | ]; |
| 708 | |
| 709 | // Update the last message with multimodal content |
| 710 | processedMessages = [ |
| 711 | ...messages.slice(0, -1), |
| 712 | { role: lastUserMsg.role, content: contentArray } |
| 713 | ]; |
| 714 | } |
| 715 | } catch (error) { |
| 716 | console.error('Error processing files:', error); |
| 717 | throw new Error(`Failed to process files: ${error.message}`); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | const access = this._requestAccess; |
| 722 | const url = `${access.baseUrl}/chat/completions`; |
| 723 | const headers = access.headers; |
| 724 | let watchdog = null; |
| 725 | let responseBody = null; |
| 726 | let sawTerminal = false; |
| 727 | let sawAnswer = false; |
| 728 | // Set when this request has returned or thrown. A delivery queued |
| 729 | // behind a callback that was still running at that moment must not |
| 730 | // reach the chat afterwards. |
| 731 | let streamSettled = false; |
| 732 | const throwIfStreamAborted = () => { |
| 733 | watchdog?.signal.throwIfAborted(); |
| 734 | if (!abortController?.signal?.aborted) return; |
| 735 | const error = new DOMException('The operation was aborted.', 'AbortError'); |
| 736 | error.isCancelled = true; |
| 737 | throw error; |
| 738 | }; |
| 739 | |
| 740 | let totalTokens = 0; |
| 741 | let promptTokens = 0; |
| 742 | let completionTokens = 0; |
| 743 | let reportedCost = null; |
| 744 | let modelUsed = effectiveModelId; |
| 745 | let modelPricing = this.getModelBudgetMetadata(effectiveModelId)?.pricing |
| 746 | || null; |
| 747 | let accumulatedContent = ''; |
| 748 | let accumulatedReasoning = ''; |
| 749 | // The provider said the model reasoned but kept the words to itself |
| 750 | // (encrypted reasoning_details). There is nothing to show for it. |
| 751 | let reasoningWithheld = false; |
| 752 | let completionFinishReason = null; |
| 753 | let hasReceivedFirstToken = false; |
| 754 | // Which stream the last delta belonged to. When a model interleaves |
| 755 | // (think, answer a line, call a tool, think again, answer), each |
| 756 | // resumed segment starts on a new paragraph, so a heading that |
| 757 | // follows a sentence is still a heading and two thoughts do not run |
| 758 | // together as one. |
| 759 | let lastDeltaKind = null; |
| 760 | let citations = []; // Track citations for web search results |
| 761 | const annotationsMap = new Map(); // Track annotations with deduplication by URL |
| 762 | let estimatedReasoningTokens = 0; // Track reasoning tokens for cumulative display |
nothing calls this directly
no test coverage detected