(value: unknown)
| 47 | const within = (value: unknown, min: number, max: number): value is number => Number.isSafeInteger(value) && (value as number) >= min && (value as number) <= max; |
| 48 | |
| 49 | function validated(value: unknown): Readonly<AgentPreferences> { |
| 50 | const row = record(value) ?? {}; |
| 51 | const limits: Record<string, TokenLimits> = {}; |
| 52 | for (const model of BROWSER_MODELS) { |
| 53 | const stored = record(record(row.limits)?.[model.id]); |
| 54 | if (!stored || !within(stored.outputTokens, MIN_OUTPUT_TOKENS, model.maxOutputTokens)) continue; |
| 55 | if (within(stored.inputTokens, MIN_INPUT_TOKENS, model.contextTokens - stored.outputTokens)) { |
| 56 | limits[model.id] = Object.freeze({ inputTokens: stored.inputTokens, outputTokens: stored.outputTokens }); |
| 57 | } |
| 58 | } |
| 59 | return Object.freeze({ |
| 60 | modelId: BROWSER_MODELS.some(model => model.id === row.modelId) ? row.modelId as string : DEFAULT_AGENT_PREFERENCES.modelId, |
| 61 | automatic: typeof row.automatic === 'boolean' ? row.automatic : DEFAULT_AGENT_PREFERENCES.automatic, |
| 62 | autoLoad: typeof row.autoLoad === 'boolean' ? row.autoLoad : DEFAULT_AGENT_PREFERENCES.autoLoad, |
| 63 | limits: Object.freeze(limits), |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | function decode(raw: string | null): Readonly<AgentPreferences> { |
| 68 | try { |
no test coverage detected