05f39b859f
Introduce ChatCitationFloat hover UI, session-scoped citation chunk cache, and unified citation markdown handling for main chat and embed views.
36 lines
894 B
TypeScript
36 lines
894 B
TypeScript
export type CitationChunkCacheValue = { content: string; error?: string }
|
|
|
|
const chunkCache = new Map<string, CitationChunkCacheValue>()
|
|
|
|
export function makeCitationCacheKey(scope: string, chunkId: string): string {
|
|
return `${scope}::${chunkId}`
|
|
}
|
|
|
|
export function getCitationChunkCache(
|
|
scope: string,
|
|
chunkId: string,
|
|
): CitationChunkCacheValue | undefined {
|
|
return chunkCache.get(makeCitationCacheKey(scope, chunkId))
|
|
}
|
|
|
|
export function setCitationChunkCache(
|
|
scope: string,
|
|
chunkId: string,
|
|
value: CitationChunkCacheValue,
|
|
): void {
|
|
chunkCache.set(makeCitationCacheKey(scope, chunkId), value)
|
|
}
|
|
|
|
export function clearCitationChunkCache(scope?: string): void {
|
|
if (scope === undefined) {
|
|
chunkCache.clear()
|
|
return
|
|
}
|
|
const prefix = `${scope}::`
|
|
for (const key of chunkCache.keys()) {
|
|
if (key.startsWith(prefix)) {
|
|
chunkCache.delete(key)
|
|
}
|
|
}
|
|
}
|