MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / toProviderEntry

Function toProviderEntry

packages/oauth/src/custom-registry.ts:144–175  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

142}
143
144function toProviderEntry(value: unknown): CustomRegistryProviderEntry | undefined {
145 if (!isRecord(value)) return undefined;
146 const id = value['id'];
147 const name = value['name'];
148 const api = value['api'];
149 const type = value['type'];
150 const models = value['models'];
151
152 if (typeof id !== 'string' || id.length === 0) return undefined;
153 if (typeof name !== 'string' || name.length === 0) return undefined;
154 if (typeof api !== 'string' || api.length === 0) return undefined;
155 if (!isAllowedProviderType(type)) return undefined;
156 if (!isRecord(models)) return undefined;
157
158 const parsedModels: Record<string, CustomRegistryModelEntry> = {};
159 for (const [key, raw] of Object.entries(models)) {
160 const modelEntry = toModelEntry(raw);
161 if (modelEntry === undefined) continue;
162 parsedModels[key] = modelEntry;
163 }
164
165 const env = toStringArrayOrUndefined(value['env']);
166
167 return {
168 id,
169 name,
170 api,
171 type,
172 ...(env !== undefined ? { env } : {}),
173 models: parsedModels,
174 };
175}
176
177/**
178 * Fetches and validates an api.json document. The returned record is keyed by

Callers 1

fetchCustomRegistryFunction · 0.85

Calls 4

isRecordFunction · 0.90
isAllowedProviderTypeFunction · 0.85
toModelEntryFunction · 0.85
toStringArrayOrUndefinedFunction · 0.85

Tested by

no test coverage detected