()
| 3323 | } |
| 3324 | |
| 3325 | private async interruptForCompaction(): Promise<void> { |
| 3326 | if (this.midStreamCompactionPending || this.disposed) { |
| 3327 | return; |
| 3328 | } |
| 3329 | |
| 3330 | const streamContext = this.activeStreamContext; |
| 3331 | if (!streamContext?.modelString || !streamContext.options) { |
| 3332 | return; |
| 3333 | } |
| 3334 | |
| 3335 | const interruptedUserMessageId = this.activeStreamUserMessageId; |
| 3336 | |
| 3337 | this.midStreamCompactionPending = true; |
| 3338 | try { |
| 3339 | const stopResult = await this.aiService.stopStream(this.workspaceId, { |
| 3340 | abortReason: "system", |
| 3341 | }); |
| 3342 | if (!stopResult.success) { |
| 3343 | log.warn("Failed to stop stream for mid-stream compaction", { |
| 3344 | workspaceId: this.workspaceId, |
| 3345 | error: stopResult.error, |
| 3346 | }); |
| 3347 | return; |
| 3348 | } |
| 3349 | |
| 3350 | await this.waitForIdle(); |
| 3351 | if (this.disposed) { |
| 3352 | return; |
| 3353 | } |
| 3354 | |
| 3355 | const followUpContent = this.buildAutoCompactionFollowUp({ |
| 3356 | // Keep mid-stream auto-compaction on the shared default sentinel so |
| 3357 | // buildCompactionMessageText can hide the internal resume marker. |
| 3358 | messageText: "Continue", |
| 3359 | options: streamContext.options, |
| 3360 | goalKind: streamContext.goalKind, |
| 3361 | modelForStream: streamContext.modelString, |
| 3362 | }); |
| 3363 | const autoCompactionRequest = this.buildAutoCompactionRequest({ |
| 3364 | followUpContent, |
| 3365 | baseOptions: streamContext.options, |
| 3366 | reason: "mid-stream", |
| 3367 | }); |
| 3368 | |
| 3369 | const sendResult = await this.sendMessage( |
| 3370 | autoCompactionRequest.messageText, |
| 3371 | { |
| 3372 | ...autoCompactionRequest.sendOptions, |
| 3373 | muxMetadata: autoCompactionRequest.metadata, |
| 3374 | }, |
| 3375 | { synthetic: true } |
| 3376 | ); |
| 3377 | if (!sendResult.success) { |
| 3378 | log.warn("Failed to dispatch mid-stream compaction request", { |
| 3379 | workspaceId: this.workspaceId, |
| 3380 | error: sendResult.error, |
| 3381 | }); |
| 3382 |
no test coverage detected