(cancelReason?: ClineApiReqCancelReason, streamingFailedMessage?: string)
| 2634 | // of prices in tasks from history (it's worth removing a few months |
| 2635 | // from now). |
| 2636 | const updateApiReqMsg = (cancelReason?: ClineApiReqCancelReason, streamingFailedMessage?: string) => { |
| 2637 | if (lastApiReqIndex < 0 || !this.clineMessages[lastApiReqIndex]) { |
| 2638 | return |
| 2639 | } |
| 2640 | |
| 2641 | const existingData = JSON.parse(this.clineMessages[lastApiReqIndex].text || "{}") |
| 2642 | |
| 2643 | // Calculate total tokens and cost using provider-aware function |
| 2644 | const modelId = getModelId(this.apiConfiguration) |
| 2645 | const apiProvider = this.apiConfiguration.apiProvider |
| 2646 | const apiProtocol = getApiProtocol( |
| 2647 | apiProvider && !isRetiredProvider(apiProvider) ? apiProvider : undefined, |
| 2648 | modelId, |
| 2649 | ) |
| 2650 | |
| 2651 | const costResult = |
| 2652 | apiProtocol === "anthropic" |
| 2653 | ? calculateApiCostAnthropic( |
| 2654 | streamModelInfo, |
| 2655 | inputTokens, |
| 2656 | outputTokens, |
| 2657 | cacheWriteTokens, |
| 2658 | cacheReadTokens, |
| 2659 | ) |
| 2660 | : calculateApiCostOpenAI( |
| 2661 | streamModelInfo, |
| 2662 | inputTokens, |
| 2663 | outputTokens, |
| 2664 | cacheWriteTokens, |
| 2665 | cacheReadTokens, |
| 2666 | ) |
| 2667 | |
| 2668 | this.clineMessages[lastApiReqIndex].text = JSON.stringify({ |
| 2669 | ...existingData, |
| 2670 | tokensIn: costResult.totalInputTokens, |
| 2671 | tokensOut: costResult.totalOutputTokens, |
| 2672 | cacheWrites: cacheWriteTokens, |
| 2673 | cacheReads: cacheReadTokens, |
| 2674 | cost: totalCost ?? costResult.totalCost, |
| 2675 | cancelReason, |
| 2676 | streamingFailedMessage, |
| 2677 | } satisfies ClineApiReqInfo) |
| 2678 | } |
| 2679 | |
| 2680 | const abortStream = async (cancelReason: ClineApiReqCancelReason, streamingFailedMessage?: string) => { |
| 2681 | if (this.diffViewProvider.isEditing) { |
nothing calls this directly
no test coverage detected