(
workspaceId: WorkspaceId,
streamInfo: WorkspaceStreamInfo,
options?: { preserveParts?: boolean; preserveUsage?: boolean; workspaceLog?: Logger }
)
| 3280 | } |
| 3281 | |
| 3282 | private async resetStreamStateForRetry( |
| 3283 | workspaceId: WorkspaceId, |
| 3284 | streamInfo: WorkspaceStreamInfo, |
| 3285 | options?: { preserveParts?: boolean; preserveUsage?: boolean; workspaceLog?: Logger } |
| 3286 | ): Promise<void> { |
| 3287 | const preserveParts = options?.preserveParts ?? false; |
| 3288 | const preserveUsage = options?.preserveUsage ?? false; |
| 3289 | |
| 3290 | if (streamInfo.partialWriteTimer) { |
| 3291 | clearTimeout(streamInfo.partialWriteTimer); |
| 3292 | streamInfo.partialWriteTimer = undefined; |
| 3293 | } |
| 3294 | |
| 3295 | await this.awaitPendingPartialWrite(streamInfo); |
| 3296 | streamInfo.partialWritePromise = undefined; |
| 3297 | |
| 3298 | if (!preserveParts) { |
| 3299 | streamInfo.parts = []; |
| 3300 | } |
| 3301 | if (!preserveParts) { |
| 3302 | streamInfo.reasoningBackfillStartIndex = undefined; |
| 3303 | } |
| 3304 | streamInfo.receivedTerminalEvent = false; |
| 3305 | streamInfo.terminalFinishReason = undefined; |
| 3306 | streamInfo.terminalRawFinishReason = undefined; |
| 3307 | streamInfo.lastPartialWriteTime = 0; |
| 3308 | |
| 3309 | if (!preserveUsage) { |
| 3310 | streamInfo.cumulativeUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 }; |
| 3311 | streamInfo.cumulativeProviderMetadata = undefined; |
| 3312 | streamInfo.terminalRefusalUsage = undefined; |
| 3313 | streamInfo.terminalRefusalProviderMetadata = undefined; |
| 3314 | streamInfo.lastStepUsage = undefined; |
| 3315 | streamInfo.lastStepProviderMetadata = undefined; |
| 3316 | } |
| 3317 | |
| 3318 | if (!preserveParts) { |
| 3319 | try { |
| 3320 | await this.historyService.deletePartial(workspaceId as string); |
| 3321 | } catch (deleteError) { |
| 3322 | const logger = options?.workspaceLog ?? this.getWorkspaceLogger(workspaceId, streamInfo); |
| 3323 | logger.warn("Failed to clear partial state before retry", { error: deleteError }); |
| 3324 | } |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | private async retryStreamWithoutPreviousResponseId( |
| 3329 | workspaceId: WorkspaceId, |
no test coverage detected