( sessionId: string, )
| 85 | * Use this to read costs BEFORE overwriting the config with saveCurrentSessionCosts(). |
| 86 | */ |
| 87 | export function getStoredSessionCosts( |
| 88 | sessionId: string, |
| 89 | ): StoredCostState | undefined { |
| 90 | const projectConfig = getCurrentProjectConfig() |
| 91 | |
| 92 | // Only return costs if this is the same session that was last saved |
| 93 | if (projectConfig.lastSessionId !== sessionId) { |
| 94 | return undefined |
| 95 | } |
| 96 | |
| 97 | // Build model usage with context windows |
| 98 | let modelUsage: { [modelName: string]: ModelUsage } | undefined |
| 99 | if (projectConfig.lastModelUsage) { |
| 100 | modelUsage = Object.fromEntries( |
| 101 | Object.entries(projectConfig.lastModelUsage).map(([model, usage]) => [ |
| 102 | model, |
| 103 | { |
| 104 | ...usage, |
| 105 | contextWindow: getContextWindowForModel(model, getSdkBetas()), |
| 106 | maxOutputTokens: getModelMaxOutputTokens(model).default, |
| 107 | }, |
| 108 | ]), |
| 109 | ) |
| 110 | } |
| 111 | |
| 112 | return { |
| 113 | totalCostUSD: projectConfig.lastCost ?? 0, |
| 114 | totalAPIDuration: projectConfig.lastAPIDuration ?? 0, |
| 115 | totalAPIDurationWithoutRetries: |
| 116 | projectConfig.lastAPIDurationWithoutRetries ?? 0, |
| 117 | totalToolDuration: projectConfig.lastToolDuration ?? 0, |
| 118 | totalLinesAdded: projectConfig.lastLinesAdded ?? 0, |
| 119 | totalLinesRemoved: projectConfig.lastLinesRemoved ?? 0, |
| 120 | lastDuration: projectConfig.lastDuration, |
| 121 | modelUsage, |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Restores cost state from project config when resuming a session. |
no test coverage detected