MCPcopy Create free account
hub / github.com/apache/maka / normalizeRelayModelProfile

Function normalizeRelayModelProfile

packages/core/src/model-thinking.ts:132–170  ·  view source on GitHub ↗
(entry: unknown)

Source from the content-addressed store, hash-verified

130}
131
132function normalizeRelayModelProfile(entry: unknown): RelayModelProfile | undefined {
133 if (!isRecord(entry)) return undefined;
134 const declared: {
135 thinkingLevels?: readonly ThinkingLevel[];
136 vision?: boolean;
137 contextWindow?: number;
138 } = {};
139 if (Array.isArray(entry.thinkingLevels)) {
140 // Declared levels are filtered to the declarable vocabulary, not merely
141 // the level vocabulary: `off` is a disable-wire encoding no generic
142 // relay is presumed to speak, and a declaration table has no business
143 // carrying it. The codec rejects it in persisted documents for the same
144 // reason; normalize silently drops it because it also sanitizes input
145 // that never passed a validator (settings drafts, hand-edited tables).
146 const declaredSet = new Set(
147 entry.thinkingLevels.filter(
148 (level): level is ThinkingLevel =>
149 isThinkingLevel(level) &&
150 (DECLARABLE_RELAY_THINKING_LEVELS as readonly ThinkingLevel[]).includes(level),
151 ),
152 );
153 if (declaredSet.size > 0) {
154 declared.thinkingLevels = DECLARABLE_RELAY_THINKING_LEVELS.filter((level) =>
155 declaredSet.has(level),
156 );
157 }
158 }
159 if (typeof entry.vision === 'boolean') declared.vision = entry.vision;
160 // Safe-integer, matching the store codec's 1..MAX_SAFE_INTEGER bound: a
161 // value that normalizes here must never be rejected by the write it feeds.
162 if (
163 typeof entry.contextWindow === 'number' &&
164 Number.isSafeInteger(entry.contextWindow) &&
165 entry.contextWindow > 0
166 ) {
167 declared.contextWindow = entry.contextWindow;
168 }
169 return Object.keys(declared).length > 0 ? (declared as RelayModelProfile) : undefined;
170}
171
172/**
173 * Write-side sanitation for a whole profiles table (settings drafts, config

Callers 2

relayModelProfileFunction · 0.85

Calls 4

isThinkingLevelFunction · 0.85
keysMethod · 0.80
isRecordFunction · 0.70
hasMethod · 0.65

Tested by

no test coverage detected