@huaqiu/dsh-auth 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +6 -31
- package/lib/client.js.map +1 -1
- package/lib/index.d.mts +31 -1
- package/lib/index.mjs +20 -1
- package/package.json +2 -2
- package/src/client/i18n.ts +0 -4
- package/src/client/ui/turn-error-cta.tsx +11 -44
- package/src/index.ts +73 -1
package/lib/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PluginLogger } from "@huaqiu/dsh-plugin-log";
|
|
1
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
2
3
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
3
4
|
//#region src/host.d.ts
|
|
@@ -350,5 +351,34 @@ declare module '@deepseek-ai/cordis' {
|
|
|
350
351
|
* without a supervisor (spec §6.4).
|
|
351
352
|
*/
|
|
352
353
|
declare function apply(ctx: Context, config?: Partial<HuaqiuAuthConfig>): void;
|
|
354
|
+
/**
|
|
355
|
+
* Narrow structural view of the harness `agent/request-error` waterfall. Only
|
|
356
|
+
* the fields this plugin reads are modelled; the real payload also carries
|
|
357
|
+
* `agent`, `turn`, `step`, `retryPolicy` and a required `signal`.
|
|
358
|
+
*/
|
|
359
|
+
interface RequestErrorPayloadView {
|
|
360
|
+
readonly provider: string;
|
|
361
|
+
readonly failure: {
|
|
362
|
+
readonly code: string;
|
|
363
|
+
};
|
|
364
|
+
readonly signal?: AbortSignal;
|
|
365
|
+
}
|
|
366
|
+
type RequestErrorActionView = {
|
|
367
|
+
readonly kind: 'retry';
|
|
368
|
+
} | undefined;
|
|
369
|
+
type RequestErrorListenerView = (payload: RequestErrorPayloadView, next: () => Promise<RequestErrorActionView>) => Promise<RequestErrorActionView>;
|
|
370
|
+
/** The slice of `HuaqiuAuthService` the automatic-login hook depends on. */
|
|
371
|
+
interface AutoLoginAuthView {
|
|
372
|
+
readonly hostMode: boolean;
|
|
373
|
+
readonly auth: {
|
|
374
|
+
login(): Promise<void>;
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Build the live-failure login hook. One instance per running DSH process, so
|
|
379
|
+
* `loginInFlight` coalesces simultaneous failures and is cleared once login
|
|
380
|
+
* settles — successfully or otherwise — without ever retrying the model turn.
|
|
381
|
+
*/
|
|
382
|
+
declare function createHuaqiuMissingCredentialLoginListener(service: AutoLoginAuthView, warn?: PluginLogger['warn']): RequestErrorListenerView;
|
|
353
383
|
//#endregion
|
|
354
|
-
export { AUTH_ROUTE_PREFIX, type AuthHandler, type CredentialStore, DEFAULT_HUAQIU_API_KEY_SYNC_MS, HUAQIU_API_KEY_REF, HuaqiuApiKeySync, type HuaqiuAuthApi, type HuaqiuAuthConfig, type HuaqiuAuthService, type HuaqiuUserInfo, InMemoryHuaqiuAuthService, apply, createAuthHandler, inject, name };
|
|
384
|
+
export { AUTH_ROUTE_PREFIX, type AuthHandler, AutoLoginAuthView, type CredentialStore, DEFAULT_HUAQIU_API_KEY_SYNC_MS, HUAQIU_API_KEY_REF, HuaqiuApiKeySync, type HuaqiuAuthApi, type HuaqiuAuthConfig, type HuaqiuAuthService, type HuaqiuUserInfo, InMemoryHuaqiuAuthService, RequestErrorActionView, RequestErrorListenerView, RequestErrorPayloadView, apply, createAuthHandler, createHuaqiuMissingCredentialLoginListener, inject, name };
|
package/lib/index.mjs
CHANGED
|
@@ -1103,6 +1103,25 @@ function apply(ctx, config) {
|
|
|
1103
1103
|
routes: AUTH_ROUTE_PREFIX,
|
|
1104
1104
|
hostMode: service.hostMode
|
|
1105
1105
|
});
|
|
1106
|
+
ctx.on("agent/request-error", createHuaqiuMissingCredentialLoginListener(service));
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Build the live-failure login hook. One instance per running DSH process, so
|
|
1110
|
+
* `loginInFlight` coalesces simultaneous failures and is cleared once login
|
|
1111
|
+
* settles — successfully or otherwise — without ever retrying the model turn.
|
|
1112
|
+
*/
|
|
1113
|
+
function createHuaqiuMissingCredentialLoginListener(service, warn = (message, fields) => log.warn(message, fields)) {
|
|
1114
|
+
let loginInFlight;
|
|
1115
|
+
return async (payload, next) => {
|
|
1116
|
+
const action = await next();
|
|
1117
|
+
if (action?.kind === "retry") return action;
|
|
1118
|
+
if (service.hostMode && payload.provider === "huaqiu" && payload.failure.code === "MISSING_CREDENTIAL" && payload.signal?.aborted !== true && loginInFlight === void 0) loginInFlight = service.auth.login().catch((error) => {
|
|
1119
|
+
warn("automatic Huaqiu login failed", { error: String(error) });
|
|
1120
|
+
}).finally(() => {
|
|
1121
|
+
loginInFlight = void 0;
|
|
1122
|
+
});
|
|
1123
|
+
return action;
|
|
1124
|
+
};
|
|
1106
1125
|
}
|
|
1107
1126
|
//#endregion
|
|
1108
|
-
export { AUTH_ROUTE_PREFIX, DEFAULT_HUAQIU_API_KEY_SYNC_MS, HUAQIU_API_KEY_REF, HuaqiuApiKeySync, InMemoryHuaqiuAuthService, apply, createAuthHandler, inject, name };
|
|
1127
|
+
export { AUTH_ROUTE_PREFIX, DEFAULT_HUAQIU_API_KEY_SYNC_MS, HUAQIU_API_KEY_REF, HuaqiuApiKeySync, InMemoryHuaqiuAuthService, apply, createAuthHandler, createHuaqiuMissingCredentialLoginListener, inject, name };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/dsh-auth",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.mjs",
|
|
6
6
|
"types": "./lib/index.d.mts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@deepseek-ai/dsh-home-paths": "^0.1.0-rc.0",
|
|
36
|
-
"@huaqiu/dsh-plugin-log": "0.7.
|
|
36
|
+
"@huaqiu/dsh-plugin-log": "0.7.6"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"lib",
|
package/src/client/i18n.ts
CHANGED
|
@@ -55,9 +55,6 @@ const zh = {
|
|
|
55
55
|
'turnError.aiQuotaCta': '升级获取更多 AI 额度',
|
|
56
56
|
'turnError.aiQuotaSignIn': '登录后升级',
|
|
57
57
|
'turnError.aiQuotaOpenFailed': '无法打开订阅页面,请稍后重试。',
|
|
58
|
-
// Turn-error sign-in CTA for a huaqiu MISSING_CREDENTIAL failure: the host
|
|
59
|
-
// session may be valid while the DSH child's mirrored API key is absent.
|
|
60
|
-
'turnError.aiCredentialSignIn': '登录以恢复 AI 服务',
|
|
61
58
|
|
|
62
59
|
'card.title': '华秋 EDA AI(eda.cn)登录',
|
|
63
60
|
'card.desc': '工具「{tool}」需要登录华秋 EDA AI 账号才能继续。请在下方的登录框完成登录(或点击左侧「华秋EDA AI登录」按钮);登录完成后,回复助手「已登录,请重试」,助手会自动重新调用该工具。',
|
|
@@ -113,7 +110,6 @@ const en: Record<AuthCopyKey, string> = {
|
|
|
113
110
|
'turnError.aiQuotaCta': 'Upgrade for more AI tokens',
|
|
114
111
|
'turnError.aiQuotaSignIn': 'Sign in to upgrade',
|
|
115
112
|
'turnError.aiQuotaOpenFailed': 'Could not open the subscription page. Please try again later.',
|
|
116
|
-
'turnError.aiCredentialSignIn': 'Sign in to restore AI access',
|
|
117
113
|
|
|
118
114
|
'card.title': 'Huaqiu EDA AI (eda.cn) login',
|
|
119
115
|
// The reply phrase used to be hardcoded to the Chinese "已登录,请重试" even
|
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
* auth client (`openSubscriptionDialog`), which is the same path the sidebar
|
|
12
12
|
* upgrade entry uses.
|
|
13
13
|
*
|
|
14
|
-
* A
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* (never the subscription dialog), even when the host session is authenticated.
|
|
14
|
+
* A `huaqiu` `MISSING_CREDENTIAL` failure is handled on the backend by the
|
|
15
|
+
* `agent/request-error` hook (which opens the native login dialog for a live
|
|
16
|
+
* failure), so this entry deliberately renders nothing for it — a historical
|
|
17
|
+
* error card must not reopen the dialog.
|
|
19
18
|
*
|
|
20
19
|
* Fallbacks stay inside the card: no host dialog service → the existing
|
|
21
20
|
* "host provides no dialog service" copy; transport failure → retry copy; no
|
|
@@ -39,8 +38,6 @@ export interface TurnErrorCtaNode {
|
|
|
39
38
|
const QUOTA_PROVIDER = 'huaqiu'
|
|
40
39
|
/** The gateway's own code for a token balance that can be topped up. */
|
|
41
40
|
const HUAQIU_QUOTA_SIGNATURE = 'insufficient_user_quota'
|
|
42
|
-
/** The harness code for a provider whose credential reference did not resolve. */
|
|
43
|
-
const HUAQIU_MISSING_CREDENTIAL = 'MISSING_CREDENTIAL'
|
|
44
41
|
|
|
45
42
|
/**
|
|
46
43
|
* Whether a durable failure is the huaqiu gateway's exhausted token balance.
|
|
@@ -62,24 +59,6 @@ export function isHuaqiuQuotaFailure(node: TurnErrorCtaNode | null | undefined):
|
|
|
62
59
|
return node.provider === QUOTA_PROVIDER && node.code === 'QUOTA'
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
/**
|
|
66
|
-
* Whether a durable failure is huaqiu's unresolved API credential.
|
|
67
|
-
*
|
|
68
|
-
* `MISSING_CREDENTIAL` is a generic harness code (DeepSeek and other providers
|
|
69
|
-
* raise it too), so the provider must match exactly. On this path the failure
|
|
70
|
-
* carries no `providerErrorCode` and the message text is explicitly ignored —
|
|
71
|
-
* gating on either would misroute other providers' credential failures.
|
|
72
|
-
* @param node - durable turn-error node, possibly absent at runtime boundaries.
|
|
73
|
-
* @returns true only for the huaqiu missing-credential signature.
|
|
74
|
-
*/
|
|
75
|
-
export function isHuaqiuMissingCredentialFailure(node: TurnErrorCtaNode | null | undefined): boolean {
|
|
76
|
-
return (
|
|
77
|
-
node != null &&
|
|
78
|
-
node.code === HUAQIU_MISSING_CREDENTIAL &&
|
|
79
|
-
node.provider === QUOTA_PROVIDER
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
62
|
const ctaStyle: CSSProperties = {
|
|
84
63
|
display: 'block',
|
|
85
64
|
width: 'fit-content',
|
|
@@ -124,7 +103,6 @@ export const HuaqiuTurnErrorSubscribeAction = memo(function HuaqiuTurnErrorSubsc
|
|
|
124
103
|
const nodeKey = node.message
|
|
125
104
|
const visibleNotice = notice !== null && notice.key === nodeKey ? notice.text : null
|
|
126
105
|
const isQuotaFailure = isHuaqiuQuotaFailure(node)
|
|
127
|
-
const isMissingCredential = isHuaqiuMissingCredentialFailure(node)
|
|
128
106
|
|
|
129
107
|
const open = useCallback(() => {
|
|
130
108
|
if (busy) return
|
|
@@ -144,15 +122,6 @@ export const HuaqiuTurnErrorSubscribeAction = memo(function HuaqiuTurnErrorSubsc
|
|
|
144
122
|
fail()
|
|
145
123
|
}
|
|
146
124
|
}
|
|
147
|
-
// A huaqiu missing credential is diagnosed in the DSH child, not the host
|
|
148
|
-
// session: the two diverge because the key mirrors asynchronously. Sign in
|
|
149
|
-
// unconditionally, before any authenticated check, and never offer a
|
|
150
|
-
// subscription for this failure.
|
|
151
|
-
if (isMissingCredential) {
|
|
152
|
-
setNotice(null)
|
|
153
|
-
requestLogin()
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
125
|
if (!authState.authenticated) {
|
|
157
126
|
requestLogin()
|
|
158
127
|
return
|
|
@@ -169,17 +138,15 @@ export const HuaqiuTurnErrorSubscribeAction = memo(function HuaqiuTurnErrorSubsc
|
|
|
169
138
|
})
|
|
170
139
|
.catch(fail)
|
|
171
140
|
.finally(() => setBusy(false))
|
|
172
|
-
}, [auth, authState.authenticated, busy, dark,
|
|
141
|
+
}, [auth, authState.authenticated, busy, dark, locale, nodeKey, t])
|
|
173
142
|
|
|
174
|
-
if (!isQuotaFailure
|
|
143
|
+
if (!isQuotaFailure) return null
|
|
175
144
|
|
|
176
|
-
const label =
|
|
177
|
-
? t('
|
|
178
|
-
:
|
|
179
|
-
? t('
|
|
180
|
-
:
|
|
181
|
-
? t('turnError.aiQuotaCta')
|
|
182
|
-
: t('turnError.aiQuotaSignIn')
|
|
145
|
+
const label = busy
|
|
146
|
+
? t('subscription.subscribing')
|
|
147
|
+
: authState.authenticated
|
|
148
|
+
? t('turnError.aiQuotaCta')
|
|
149
|
+
: t('turnError.aiQuotaSignIn')
|
|
183
150
|
|
|
184
151
|
return (
|
|
185
152
|
<>
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { Context } from '@deepseek-ai/cordis'
|
|
8
8
|
import type { CredentialProvider, CredentialRef } from '@deepseek-ai/dsh-credentials'
|
|
9
9
|
import type {} from '@deepseek-ai/dsh-host-webserver'
|
|
10
|
-
import { getLogger } from '@huaqiu/dsh-plugin-log'
|
|
10
|
+
import { getLogger, type PluginLogger } from '@huaqiu/dsh-plugin-log'
|
|
11
11
|
import {
|
|
12
12
|
DEFAULT_HOST_AUTH_PATH,
|
|
13
13
|
resolveHostConfig,
|
|
@@ -124,4 +124,76 @@ export function apply(ctx: Context, config?: Partial<HuaqiuAuthConfig>): void {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
log.info('dsh-auth node half ready', { routes: AUTH_ROUTE_PREFIX, hostMode: service.hostMode })
|
|
127
|
+
|
|
128
|
+
// React to a LIVE failed Huaqiu request, not to the durable turn/end node:
|
|
129
|
+
// Cordis events are in-memory and are not replayed when a session is restored,
|
|
130
|
+
// so reopening DSH can never pop the native login dialog for an old failure.
|
|
131
|
+
// The harness owns the `agent/request-error` event typings and dsh-auth does
|
|
132
|
+
// not depend on them, so register through the narrow structural view below.
|
|
133
|
+
;(ctx as unknown as {
|
|
134
|
+
on(event: 'agent/request-error', listener: RequestErrorListenerView): unknown
|
|
135
|
+
}).on('agent/request-error', createHuaqiuMissingCredentialLoginListener(service))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Narrow structural view of the harness `agent/request-error` waterfall. Only
|
|
140
|
+
* the fields this plugin reads are modelled; the real payload also carries
|
|
141
|
+
* `agent`, `turn`, `step`, `retryPolicy` and a required `signal`.
|
|
142
|
+
*/
|
|
143
|
+
export interface RequestErrorPayloadView {
|
|
144
|
+
readonly provider: string
|
|
145
|
+
readonly failure: { readonly code: string }
|
|
146
|
+
readonly signal?: AbortSignal
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type RequestErrorActionView = { readonly kind: 'retry' } | undefined
|
|
150
|
+
|
|
151
|
+
export type RequestErrorListenerView = (
|
|
152
|
+
payload: RequestErrorPayloadView,
|
|
153
|
+
next: () => Promise<RequestErrorActionView>,
|
|
154
|
+
) => Promise<RequestErrorActionView>
|
|
155
|
+
|
|
156
|
+
/** The slice of `HuaqiuAuthService` the automatic-login hook depends on. */
|
|
157
|
+
export interface AutoLoginAuthView {
|
|
158
|
+
readonly hostMode: boolean
|
|
159
|
+
readonly auth: { login(): Promise<void> }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Build the live-failure login hook. One instance per running DSH process, so
|
|
164
|
+
* `loginInFlight` coalesces simultaneous failures and is cleared once login
|
|
165
|
+
* settles — successfully or otherwise — without ever retrying the model turn.
|
|
166
|
+
*/
|
|
167
|
+
export function createHuaqiuMissingCredentialLoginListener(
|
|
168
|
+
service: AutoLoginAuthView,
|
|
169
|
+
warn: PluginLogger['warn'] = (message, fields) => log.warn(message, fields),
|
|
170
|
+
): RequestErrorListenerView {
|
|
171
|
+
let loginInFlight: Promise<void> | undefined
|
|
172
|
+
|
|
173
|
+
return async (payload, next) => {
|
|
174
|
+
// Delegate first: an inner retry policy may own this failure, in which
|
|
175
|
+
// case the dialog must not open and the original action is preserved.
|
|
176
|
+
const action = await next()
|
|
177
|
+
if (action?.kind === 'retry') return action
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
service.hostMode &&
|
|
181
|
+
payload.provider === 'huaqiu' &&
|
|
182
|
+
payload.failure.code === 'MISSING_CREDENTIAL' &&
|
|
183
|
+
payload.signal?.aborted !== true &&
|
|
184
|
+
loginInFlight === undefined
|
|
185
|
+
) {
|
|
186
|
+
// Fire and forget: the host login route can block for minutes, while the
|
|
187
|
+
// failed turn must close immediately. Catching here keeps a login error
|
|
188
|
+
// from replacing the original LLM failure in the waterfall.
|
|
189
|
+
loginInFlight = service.auth.login()
|
|
190
|
+
.catch((error: unknown) => {
|
|
191
|
+
warn('automatic Huaqiu login failed', { error: String(error) })
|
|
192
|
+
})
|
|
193
|
+
.finally(() => {
|
|
194
|
+
loginInFlight = undefined
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
return action
|
|
198
|
+
}
|
|
127
199
|
}
|