(
config: PluginConfig,
state: SessionState,
messages: WithParts[],
)
| 18 | export type CompressionPriorityMap = Map<string, CompressionPriorityEntry> |
| 19 | |
| 20 | export function buildPriorityMap( |
| 21 | config: PluginConfig, |
| 22 | state: SessionState, |
| 23 | messages: WithParts[], |
| 24 | ): CompressionPriorityMap { |
| 25 | if (config.compress.mode !== "message") { |
| 26 | return new Map() |
| 27 | } |
| 28 | const priorities: CompressionPriorityMap = new Map() |
| 29 | |
| 30 | for (const message of messages) { |
| 31 | if (isIgnoredUserMessage(message)) { |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | if (isProtectedUserMessage(config, message)) { |
| 36 | continue |
| 37 | } |
| 38 | |
| 39 | if (isMessageCompacted(state, message)) { |
| 40 | continue |
| 41 | } |
| 42 | |
| 43 | const rawMessageId = message.info.id |
| 44 | if (typeof rawMessageId !== "string" || rawMessageId.length === 0) { |
| 45 | continue |
| 46 | } |
| 47 | |
| 48 | const ref = state.messageIds.byRawId.get(rawMessageId) |
| 49 | if (!ref) { |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | const tokenCount = countAllMessageTokens(message) |
| 54 | priorities.set(rawMessageId, { |
| 55 | ref, |
| 56 | tokenCount, |
| 57 | priority: messageHasCompress(message) ? "high" : classifyMessagePriority(tokenCount), |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | return priorities |
| 62 | } |
| 63 | |
| 64 | export function classifyMessagePriority(tokenCount: number): MessagePriority { |
| 65 | if (tokenCount >= HIGH_PRIORITY_MIN_TOKENS) { |
no test coverage detected