fix(core): read data tool API key from credentials.json5

Use credentialManager.getToolConfig("data") as the primary source for
the Financial Datasets API key, with FINANCIAL_DATASETS_API_KEY env var
as fallback. Also add data tool entry to the credentials template.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jiayuan Zhang
2026-02-11 16:45:46 +08:00
parent 6e28513ec5
commit d80e97648c
2 changed files with 15 additions and 9 deletions

View File

@@ -44,7 +44,8 @@ function buildCoreTemplate(): string {
},
tools: {
// brave: { apiKey: "brv-..." },
// perplexity: { apiKey: "pplx-...", baseUrl: "https://api.perplexity.ai", model: "perplexity/sonar-pro" }
// perplexity: { apiKey: "pplx-...", baseUrl: "https://api.perplexity.ai", model: "perplexity/sonar-pro" },
// data: { apiKey: "your-financial-datasets-api-key" }
}
}
`;

View File

@@ -12,14 +12,19 @@ const BASE_URL = "https://api.financialdatasets.ai";
const TIMEOUT_MS = 30_000;
function getApiKey(): string {
const key = credentialManager.getEnv("FINANCIAL_DATASETS_API_KEY");
if (!key) {
throw new Error(
"FINANCIAL_DATASETS_API_KEY not configured. " +
"Set it in ~/.super-multica/skills.env.json5 under env, or as an environment variable.",
);
}
return key;
// 1. credentials.json5 → tools.data.apiKey (preferred)
const toolConfig = credentialManager.getToolConfig("data");
if (toolConfig?.apiKey) return toolConfig.apiKey;
// 2. Fallback: env var (skills.env.json5 or process.env)
const envKey = credentialManager.getEnv("FINANCIAL_DATASETS_API_KEY");
if (envKey) return envKey;
throw new Error(
"Financial Datasets API key not configured. " +
'Set it in ~/.super-multica/credentials.json5 under tools.data.apiKey, ' +
"or set FINANCIAL_DATASETS_API_KEY in ~/.super-multica/skills.env.json5.",
);
}
/**