(params: {
followUpContent: CompactionFollowUpRequest;
baseOptions: SendMessageOptions;
reason: "on-send" | "mid-stream";
})
| 3250 | } |
| 3251 | |
| 3252 | private buildAutoCompactionRequest(params: { |
| 3253 | followUpContent: CompactionFollowUpRequest; |
| 3254 | baseOptions: SendMessageOptions; |
| 3255 | reason: "on-send" | "mid-stream"; |
| 3256 | }): { |
| 3257 | messageText: string; |
| 3258 | metadata: MuxMessageMetadata; |
| 3259 | sendOptions: SendMessageOptions; |
| 3260 | agentInitiated: boolean; |
| 3261 | } { |
| 3262 | // Callers pass the stream model in baseOptions.model; avoid ambient session state |
| 3263 | // here because the current stream is cleared before compaction and could go stale. |
| 3264 | const compactionModel = this.getPreferredCompactionModel() ?? params.baseOptions.model; |
| 3265 | assert( |
| 3266 | typeof compactionModel === "string" && compactionModel.trim().length > 0, |
| 3267 | "auto-compaction requires a non-empty model" |
| 3268 | ); |
| 3269 | |
| 3270 | const sendOptions: SendMessageOptions = { |
| 3271 | ...params.baseOptions, |
| 3272 | agentId: "compact", |
| 3273 | skipAiSettingsPersistence: true, |
| 3274 | model: compactionModel, |
| 3275 | thinkingLevel: enforceThinkingPolicy( |
| 3276 | compactionModel, |
| 3277 | params.baseOptions.thinkingLevel ?? "off" |
| 3278 | ), |
| 3279 | maxOutputTokens: undefined, |
| 3280 | toolPolicy: [{ regex_match: ".*", action: "disable" }], |
| 3281 | }; |
| 3282 | |
| 3283 | const followUpContent: CompactionFollowUpRequest = |
| 3284 | params.reason === "mid-stream" |
| 3285 | ? { |
| 3286 | ...params.followUpContent, |
| 3287 | dispatchOptions: { |
| 3288 | ...params.followUpContent.dispatchOptions, |
| 3289 | // Mid-stream compaction resumes with a generated "Continue" sentinel; unlike |
| 3290 | // on-send compaction, it is not the user's original prompt completing. |
| 3291 | source: "internal-resume", |
| 3292 | }, |
| 3293 | } |
| 3294 | : params.followUpContent; |
| 3295 | |
| 3296 | const messageText = buildCompactionMessageText({ followUpContent }); |
| 3297 | |
| 3298 | const metadata: MuxMessageMetadata = { |
| 3299 | type: "compaction-request", |
| 3300 | rawCommand: "/compact", |
| 3301 | commandPrefix: "/compact", |
| 3302 | parsed: { |
| 3303 | model: sendOptions.model, |
| 3304 | followUpContent, |
| 3305 | }, |
| 3306 | requestedModel: sendOptions.model, |
| 3307 | source: "auto-compaction", |
| 3308 | displayStatus: { |
| 3309 | emoji: "🔄", |
no test coverage detected