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:
parent
0e383f51ab
commit
8d32a06b5c
1 changed files with 8 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue