MCPcopy Create free account
hub / github.com/TanStack/ai / computeOverrides

Function computeOverrides

scripts/generate-fal-image-field-map.ts:214–246  ·  view source on GitHub ↗
(
  endpoints: Map<string, EndpointFields>,
)

Source from the content-addressed store, hash-verified

212]
213
214function computeOverrides(
215 endpoints: Map<string, EndpointFields>,
216): Map<string, Partial<Record<RoleKey, string>>> {
217 const overrides = new Map<string, Partial<Record<RoleKey, string>>>()
218
219 for (const [endpointId, { fields, isList, producesVideo }] of endpoints) {
220 const entry: Partial<Record<RoleKey, string>> = {}
221 for (const role of ROLE_ORDER) {
222 if (VIDEO_ONLY_ROLES.has(role) && !producesVideo) continue
223 const chosen = CANDIDATES[role].find((candidate) => fields.has(candidate))
224 if (!chosen) continue
225
226 // Arity sanity check: the runtime mapper decides array-wrapping from
227 // the static LIST_FIELDS set, so the actual type must agree. Run this
228 // for default-selected fields too, otherwise a default field's type
229 // could drift silently.
230 const actualIsList = isList.get(chosen) ?? false
231 const assumedIsList = LIST_FIELDS.has(chosen)
232 if (actualIsList !== assumedIsList) {
233 throw new Error(
234 `Arity mismatch for ${endpointId}.${chosen}: type says ` +
235 `${actualIsList ? 'array' : 'scalar'} but LIST_FIELDS assumes ` +
236 `${assumedIsList ? 'array' : 'scalar'}. Update LIST_FIELDS here ` +
237 `and LIST_FIELDS in image-inputs.ts.`,
238 )
239 }
240 if (chosen === DEFAULTS[role]) continue
241 entry[role] = chosen
242 }
243 if (Object.keys(entry).length > 0) overrides.set(endpointId, entry)
244 }
245 return overrides
246}
247
248// ---------------------------------------------------------------------------
249// Emission

Callers 1

Calls 3

hasMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected