| import { |
| clearBetaHeaderLatches, |
| clearSystemPromptSectionState, |
| getSystemPromptSectionCache, |
| setSystemPromptSectionCacheEntry, |
| } from '../bootstrap/state.js' |
|
|
| type ComputeFn = () => string | null | Promise<string | null> |
|
|
| type SystemPromptSection = { |
| name: string |
| compute: ComputeFn |
| cacheBreak: boolean |
| } |
|
|
| |
| |
| |
| |
| export function systemPromptSection( |
| name: string, |
| compute: ComputeFn, |
| ): SystemPromptSection { |
| return { name, compute, cacheBreak: false } |
| } |
|
|
| |
| |
| |
| |
| |
| export function DANGEROUS_uncachedSystemPromptSection( |
| name: string, |
| compute: ComputeFn, |
| _reason: string, |
| ): SystemPromptSection { |
| return { name, compute, cacheBreak: true } |
| } |
|
|
| |
| |
| |
| export async function resolveSystemPromptSections( |
| sections: SystemPromptSection[], |
| ): Promise<(string | null)[]> { |
| const cache = getSystemPromptSectionCache() |
|
|
| return Promise.all( |
| sections.map(async s => { |
| if (!s.cacheBreak && cache.has(s.name)) { |
| return cache.get(s.name) ?? null |
| } |
| const value = await s.compute() |
| setSystemPromptSectionCacheEntry(s.name, value) |
| return value |
| }), |
| ) |
| } |
|
|
| |
| |
| |
| |
| |
| export function clearSystemPromptSections(): void { |
| clearSystemPromptSectionState() |
| clearBetaHeaderLatches() |
| } |
|
|