(messages: Message[], model?: string)
| 178 | } |
| 179 | |
| 180 | private applyContextWindowLimit(messages: Message[], model?: string): Message[] { |
| 181 | if (!model) return messages |
| 182 | |
| 183 | for (const provider of Object.values(PROVIDER_DEFINITIONS)) { |
| 184 | if (provider.contextInformationAvailable === false) continue |
| 185 | |
| 186 | const matchesPattern = provider.modelPatterns?.some((p) => p.test(model)) |
| 187 | const matchesModel = provider.models.some((m) => m.id === model) |
| 188 | |
| 189 | if (matchesPattern || matchesModel) { |
| 190 | const modelDef = provider.models.find((m) => m.id === model) |
| 191 | if (modelDef?.contextWindow) { |
| 192 | const maxTokens = Math.floor(modelDef.contextWindow * MEMORY.CONTEXT_WINDOW_UTILIZATION) |
| 193 | return this.applyTokenWindow(messages, maxTokens, model) |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return messages |
| 199 | } |
| 200 | |
| 201 | private async fetchMemory(workspaceId: string, key: string): Promise<Message[]> { |
| 202 | const result = await db |
no test coverage detected