import type { AgentType } from './agent-status-types' import type { SessionOptionValue } from './native-chat/input/native-chat-session-options' import { cloneNativeChatSessionOptionRecord, createNativeChatSessionOptionRecord, type NativeChatSessionOptionRecord, type TrackedNativeChatSessionOption } from './native-chat/input/native-chat-session-option-state' import { setBoundedScopeCacheEntry } from './native-chat/native-chat-scope-cache' const sessionOptionCache = new Map() export function readNativeChatSessionOptionCache( scopeKey: string, fallbackScopeKey?: string ): NativeChatSessionOptionRecord | null { const record = sessionOptionCache.get(scopeKey) ?? sessionOptionCache.get(fallbackScopeKey ?? '') return record ? cloneNativeChatSessionOptionRecord(record) : null } export function writeNativeChatSessionOptionCache( scopeKey: string, record: NativeChatSessionOptionRecord ): void { setBoundedScopeCacheEntry( sessionOptionCache, scopeKey, cloneNativeChatSessionOptionRecord(record) ) } export function seedNativeChatAppliedSessionOptions( scopeKey: string, agent: AgentType, values: Record | null | undefined ): void { const modelId = typeof values?.model === 'string' ? values.model : null if (!modelId) { return } const record = createNativeChatSessionOptionRecord(agent) record.model = { value: modelId, source: 'applied' } const modelValues: Record = {} for (const [id, value] of Object.entries(values ?? {})) { if (id !== 'model') { modelValues[id] = { value, source: 'applied' } } } record.valuesByModel[modelId] = modelValues writeNativeChatSessionOptionCache(scopeKey, record) } export function clearNativeChatSessionOptionCacheForTests(): void { sessionOptionCache.clear() }