mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-24 02:39:42 +02:00
fix(agent): validate API key before calling PiAgentCore.prompt()
getApiKey errors thrown inside PiAgentCore's internal async context result in UnhandledPromiseRejection instead of propagating to the caller. Return a graceful error early so AsyncAgent can emit it through the subscriber mechanism to the UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -364,6 +364,14 @@ export class Agent {
|
||||
await this.ensureInitialized();
|
||||
this.output.state.lastAssistantText = "";
|
||||
|
||||
// Early validation: check API key before calling PiAgentCore.prompt(),
|
||||
// because getApiKey errors thrown inside PiAgentCore's internal async
|
||||
// context result in UnhandledPromiseRejection instead of propagating.
|
||||
if (!this.currentApiKey) {
|
||||
const errorMsg = `No API key configured for provider: ${this.resolvedProvider}. Please configure a provider in Agent Settings.`;
|
||||
return { text: "", error: errorMsg };
|
||||
}
|
||||
|
||||
const canRotate = !this.pinnedProfile && this.profileCandidates.length > 1;
|
||||
let lastError: unknown;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user