fix(edge): meter and size-cap knowledge embeddings in embed-chunks and search-knowledge

This commit is contained in:
Yun Chan 2026-09-28 00:53:48 +09:00
parent b35676c75c
commit 1afaea7214
12 changed files with 1111 additions and 270 deletions

View file

@ -0,0 +1,25 @@
// Test double for EmbeddingUsageStore (not a test file itself).
import { EMBEDDING_QUOTA_FEATURE, type EmbeddingUsageStore } from './embedding-quota.ts'
import type { PlanQuotaTier } from './core-contract.generated.ts'
/** In-memory daily_usage keyed by date; `today` is the date increments land on. */
export class MemoryUsageStore implements EmbeddingUsageStore {
rows = new Map<string, number>()
failIncrement = false
constructor(public tier: PlanQuotaTier, public today: string) {}
readTier(): Promise<PlanQuotaTier> {
return Promise.resolve(this.tier)
}
increment(_userId: string, feature: string, amount: number): Promise<number> {
if (this.failIncrement) return Promise.reject(new Error('down'))
if (feature !== EMBEDDING_QUOTA_FEATURE) return Promise.reject(new Error(`unexpected feature ${feature}`))
const next = (this.rows.get(this.today) ?? 0) + amount
this.rows.set(this.today, next)
return Promise.resolve(next)
}
sumBetween(_userId: string, _feature: string, fromDate: string, beforeDate: string): Promise<number> {
let sum = 0
for (const [date, count] of this.rows) if (date >= fromDate && date < beforeDate) sum += count
return Promise.resolve(sum)
}
}