(messages: SessionV1.WithParts[])
| 60 | } |
| 61 | |
| 62 | function completedCompactions(messages: SessionV1.WithParts[]) { |
| 63 | const users = new Map<MessageID, number>() |
| 64 | for (let i = 0; i < messages.length; i++) { |
| 65 | const msg = messages[i] |
| 66 | if (msg.info.role !== "user") continue |
| 67 | if (!msg.parts.some((part) => part.type === "compaction")) continue |
| 68 | users.set(msg.info.id, i) |
| 69 | } |
| 70 | |
| 71 | return messages.flatMap((msg, assistantIndex): CompletedCompaction[] => { |
| 72 | if (msg.info.role !== "assistant") return [] |
| 73 | if (!msg.info.summary || !msg.info.finish || msg.info.error) return [] |
| 74 | const userIndex = users.get(msg.info.parentID) |
| 75 | if (userIndex === undefined) return [] |
| 76 | return [{ userIndex, assistantIndex, summary: summaryText(msg) }] |
| 77 | }) |
| 78 | } |
| 79 | |
| 80 | function preserveRecentBudget(input: { cfg: ConfigV1.Info; model: Provider.Model }) { |
| 81 | return ( |
no test coverage detected