MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / parseAgentCredentials

Function parseAgentCredentials

src/workspaces/template-registry.ts:314–332  ·  view source on GitHub ↗

* Parse the optional `agentCredentials` map from a template.json. Shape: * { " ": { "credentialSlug": "openai-1", "model": "gpt-5.5", * "authMode"?: "x-api-key"|"bearer", "wireApi"?: "chat"|"responses" } } * Entries missing a string `credentialSlug` are dropped. Retur

(raw: unknown)

Source from the content-addressed store, hash-verified

312 * nothing valid is present (so the field stays absent on the meta).
313 */
314function parseAgentCredentials(raw: unknown): Record<string, AgentCredentialDecl> | undefined {
315 if (typeof raw !== 'object' || raw === null) return undefined;
316 const out: Record<string, AgentCredentialDecl> = {};
317 for (const [agentId, value] of Object.entries(raw as Record<string, unknown>)) {
318 if (typeof value !== 'object' || value === null) continue;
319 const v = value as Record<string, unknown>;
320 if (typeof v['credentialSlug'] !== 'string' || v['credentialSlug'].length === 0) continue;
321 const decl: AgentCredentialDecl = { credentialSlug: v['credentialSlug'] };
322 if (typeof v['model'] === 'string') (decl as { model?: string }).model = v['model'];
323 if (v['authMode'] === 'x-api-key' || v['authMode'] === 'bearer') {
324 (decl as { authMode?: 'x-api-key' | 'bearer' }).authMode = v['authMode'];
325 }
326 if (v['wireApi'] === 'chat' || v['wireApi'] === 'responses') {
327 (decl as { wireApi?: 'chat' | 'responses' }).wireApi = v['wireApi'];
328 }
329 out[agentId] = decl;
330 }
331 return Object.keys(out).length > 0 ? out : undefined;
332}
333

Callers 1

readTemplateMetaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected