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

Function toModelEntry

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

Source from the content-addressed store, hash-verified

91}
92
93function toModelEntry(value: unknown): CustomRegistryModelEntry | undefined {
94 if (!isRecord(value)) return undefined;
95 const id = value['id'];
96 if (typeof id !== 'string' || id.length === 0) return undefined;
97
98 const entry: {
99 id: string;
100 name?: string;
101 limit?: { context?: number; output?: number };
102 tool_call?: boolean;
103 reasoning?: boolean;
104 modalities?: { input?: readonly string[]; output?: readonly string[] };
105 } = { id };
106
107 const name = value['name'];
108 if (typeof name === 'string' && name.length > 0) entry.name = name;
109
110 const limit = value['limit'];
111 if (isRecord(limit)) {
112 const context = limit['context'];
113 const output = limit['output'];
114 const parsedLimit: { context?: number; output?: number } = {};
115 if (typeof context === 'number' && Number.isFinite(context) && context > 0) {
116 parsedLimit.context = Math.floor(context);
117 }
118 if (typeof output === 'number' && Number.isFinite(output) && output > 0) {
119 parsedLimit.output = Math.floor(output);
120 }
121 if (parsedLimit.context !== undefined || parsedLimit.output !== undefined) {
122 entry.limit = parsedLimit;
123 }
124 }
125
126 if (typeof value['tool_call'] === 'boolean') entry.tool_call = value['tool_call'];
127 if (typeof value['reasoning'] === 'boolean') entry.reasoning = value['reasoning'];
128
129 const modalities = value['modalities'];
130 if (isRecord(modalities)) {
131 const input = toStringArrayOrUndefined(modalities['input']);
132 const output = toStringArrayOrUndefined(modalities['output']);
133 if (input !== undefined || output !== undefined) {
134 entry.modalities = {
135 ...(input !== undefined ? { input } : {}),
136 ...(output !== undefined ? { output } : {}),
137 };
138 }
139 }
140
141 return entry;
142}
143
144function toProviderEntry(value: unknown): CustomRegistryProviderEntry | undefined {
145 if (!isRecord(value)) return undefined;

Callers 1

toProviderEntryFunction · 0.85

Calls 2

isRecordFunction · 0.90
toStringArrayOrUndefinedFunction · 0.85

Tested by

no test coverage detected