Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): carry auth failure reason and map it for mobile

Chris4f9caa8fcc02
diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.ts
index 61b846ee31..5d729a9250 100644
--- a/packages/maker-core/src/agents/pi/index.ts
+++ b/packages/maker-core/src/agents/pi/index.ts
@@ -457,7 +457,15 @@ export class PiAgent extends BaseAgent {
resolveAgentCredentialMode({ agentKind: 'pi', providerId: authProviderId, model: opts.model }) ??
'gateway-key';
const authState = await this.deps.auth.getState({ credentialMode, providerId: authProviderId });
- if (!authState.authenticated) throw new AgentNotAuthenticatedError('pi');
+ // 携带具体 reason(与 claude-code / codex 同模板 `<agent> not authenticated: <reason>`),
+ // 否则默认构造只产生 `agent-not-authenticated:pi`,跨端映射(describeAgentAuthError)
+ // 识别不了,手机端只能直出内部错误串、无法按 reason 引导修复(codex review)。
+ if (!authState.authenticated) {
+ throw new AgentNotAuthenticatedError(
+ 'pi',
+ `pi not authenticated: ${authState.errorReason ?? 'no_key'}`,
+ );
+ }
const authEnv = await this.deps.auth.getAuthEnv({ credentialMode, providerId: authProviderId });
const agentHome = this.resolveAgentHome();
diff --git a/packages/maker-shared/src/__tests__/deviceLinkContract.test.ts b/packages/maker-shared/src/__tests__/deviceLinkContract.test.ts
index 02f7e302a4..9dd4f8f3ec 100644
--- a/packages/maker-shared/src/__tests__/deviceLinkContract.test.ts
+++ b/packages/maker-shared/src/__tests__/deviceLinkContract.test.ts
@@ -91,6 +91,9 @@ describe('device-link shared contract', () => {
expect(describeAgentAuthError('claude-code not authenticated: no_key')).toContain('Claude');
expect(describeAgentAuthError('codex not authenticated: no_credentials'))
.toContain('尚未登录 Codex');
+ // Pi 也走同一模板与映射(codex review):按 reason 引导,标签显示 Pi。
+ expect(describeAgentAuthError('pi not authenticated: no_key')).toContain('API Key');
+ expect(describeAgentAuthError('pi not authenticated: no_key')).toContain('Pi');
expect(describeAgentAuthError('claude-code not authenticated: no_oauth')).toContain('账号授权');
expect(describeAgentAuthError('claude-code not authenticated: no_encryption')).toContain('安全存储');
expect(describeAgentAuthError('claude-code not authenticated: proxy_not_ready')).toContain('稍候重试');
diff --git a/packages/maker-shared/src/deviceLinkContract.ts b/packages/maker-shared/src/deviceLinkContract.ts
index 0e5c47c93a..5b91eeb210 100644
--- a/packages/maker-shared/src/deviceLinkContract.ts
+++ b/packages/maker-shared/src/deviceLinkContract.ts
@@ -483,7 +483,7 @@ export function connectionIssueHint(kind: DeviceLinkConnectionIssueKind): string
* 要给出可读提示只能按模板识别。formatRemoteError / throwIpcError 会给部分链路的
* message 加 `[CODE] ` 头,识别时一并容忍。
*/
-const AGENT_NOT_AUTHENTICATED_RE = /^(?:\[[A-Z_]+\] )?(claude-code|codex) not authenticated: ?(.*)$/;
+const AGENT_NOT_AUTHENTICATED_RE = /^(?:\[[A-Z_]+\] )?(claude-code|codex|pi) not authenticated: ?(.*)$/;
/**
* agent 未鉴权错误 → 手机端直出文案(桌面端走 i18n,不用这组)。
@@ -496,7 +496,7 @@ export function describeAgentAuthError(error: string | null | undefined): string
if (!error) return null;
const matched = AGENT_NOT_AUTHENTICATED_RE.exec(error.trim());
if (!matched) return null;
- const agentLabel = matched[1] === 'claude-code' ? 'Claude' : 'Codex';
+ const agentLabel = matched[1] === 'claude-code' ? 'Claude' : matched[1] === 'pi' ? 'Pi' : 'Codex';
const goSettings = `请在电脑端 ${BRAND_NAME} 的「设置 → 模型供应商」`;
switch (matched[2]) {
case 'no_key':