MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / validated

Function validated

graph-ui/src/browser-ai/agent-preferences.ts:49–65  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

47const within = (value: unknown, min: number, max: number): value is number => Number.isSafeInteger(value) && (value as number) >= min && (value as number) <= max;
48
49function 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
67function decode(raw: string | null): Readonly<AgentPreferences> {
68 try {

Callers 2

decodeFunction · 0.70
setAgentPreferencesFunction · 0.70

Calls 2

recordFunction · 0.70
withinFunction · 0.70

Tested by

no test coverage detected