( msg: OcMessage, partsByMsg: Map<string, OcPart[]>, assistantData: OpenCodeAssistantData, userTs: number | null, )
| 228 | } |
| 229 | |
| 230 | function buildOpenCodeRequest( |
| 231 | msg: OcMessage, |
| 232 | partsByMsg: Map<string, OcPart[]>, |
| 233 | assistantData: OpenCodeAssistantData, |
| 234 | userTs: number | null, |
| 235 | ): SessionRequest { |
| 236 | const cacheRead = assistantData.tokenSource?.cache?.read ?? 0; |
| 237 | const cacheWrite = assistantData.tokenSource?.cache?.write ?? 0; |
| 238 | const hasTokenData = assistantData.tokenSource != null; |
| 239 | return createRequest({ |
| 240 | requestId: msg.id, |
| 241 | timestamp: userTs, |
| 242 | messageText: getOpenCodeUserText(msg, partsByMsg), |
| 243 | responseText: assistantData.responseText, |
| 244 | agentName: msg.agent || 'OpenCode', |
| 245 | agentMode: msg.agent || 'build', |
| 246 | modelId: assistantData.modelId, |
| 247 | toolsUsed: assistantData.toolsUsed, |
| 248 | editedFiles: [...new Set(assistantData.editedFiles)], |
| 249 | referencedFiles: [...new Set(assistantData.referencedFiles)], |
| 250 | totalElapsed: assistantData.totalElapsed, |
| 251 | // promptTokens = total input context (uncached input + cache read + cache write) |
| 252 | // so that context-window analysis sees the full context. Cached portions |
| 253 | // are tracked separately for billing. |
| 254 | promptTokens: hasTokenData ? (assistantData.tokenSource?.input ?? 0) + cacheRead + cacheWrite : null, |
| 255 | completionTokens: hasTokenData ? (assistantData.tokenSource?.output ?? 0) : null, |
| 256 | cacheReadTokens: cacheRead > 0 ? cacheRead : null, |
| 257 | cacheWriteTokens: cacheWrite > 0 ? cacheWrite : null, |
| 258 | // OpenCode stores reasoning effort as "variant" on user messages |
| 259 | reasoningEffort: canonicalizeReasoningEffort(msg.variant) |
| 260 | ?? extractReasoningEffortFromModelId(assistantData.modelId), |
| 261 | }); |
| 262 | } |
| 263 | |
| 264 | function parseOpenCodeSession(rawSession: OcSession, storageDir: string): Session | null { |
| 265 | if (!rawSession.id) return null; |
no test coverage detected