dsh-auth-remote 0.1.7 → 0.1.9

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/CHANGELOG.zh-CN.md +12 -1
  3. package/CONTRIBUTING.md +1 -1
  4. package/CONTRIBUTING.zh-CN.md +1 -1
  5. package/README.md +30 -12
  6. package/README.zh-CN.md +30 -12
  7. package/dist/cli.js +50 -0
  8. package/dist/cli.js.map +2 -2
  9. package/dist/client.js +457 -1
  10. package/dist/client.js.map +4 -4
  11. package/dist/index.js +366 -26
  12. package/dist/index.js.map +3 -3
  13. package/dist/login.js +50 -0
  14. package/dist/login.js.map +2 -2
  15. package/dist/types/adapters/dsh/account-callback.d.ts +12 -0
  16. package/dist/types/adapters/dsh/account-callback.d.ts.map +1 -0
  17. package/dist/types/adapters/dsh/browser-capability.d.ts +1 -1
  18. package/dist/types/adapters/dsh/browser-capability.d.ts.map +1 -1
  19. package/dist/types/adapters/dsh/webserver.d.ts +3 -0
  20. package/dist/types/adapters/dsh/webserver.d.ts.map +1 -1
  21. package/dist/types/http/account-login.d.ts +43 -0
  22. package/dist/types/http/account-login.d.ts.map +1 -0
  23. package/dist/types/http/gate.d.ts.map +1 -1
  24. package/dist/types/http/origin-policy.d.ts.map +1 -1
  25. package/dist/types/http/public-assets.d.ts +3 -0
  26. package/dist/types/http/public-assets.d.ts.map +1 -0
  27. package/dist/types/http/routes.d.ts +16 -1
  28. package/dist/types/http/routes.d.ts.map +1 -1
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/shared/account-login.d.ts +21 -0
  31. package/dist/types/shared/account-login.d.ts.map +1 -0
  32. package/dist/types/shared/i18n.d.ts +50 -0
  33. package/dist/types/shared/i18n.d.ts.map +1 -1
  34. package/dist/types/shared/locales/en.d.ts +25 -0
  35. package/dist/types/shared/locales/en.d.ts.map +1 -1
  36. package/dist/types/shared/locales/zh.d.ts +25 -0
  37. package/dist/types/shared/locales/zh.d.ts.map +1 -1
  38. package/docs/deployment.md +21 -15
  39. package/docs/deployment.zh-CN.md +21 -15
  40. package/docs/development.md +16 -6
  41. package/docs/development.zh-CN.md +16 -6
  42. package/docs/legacy-compatibility.md +170 -117
  43. package/docs/legacy-compatibility.zh-CN.md +170 -0
  44. package/docs/releasing.md +6 -6
  45. package/docs/releasing.zh-CN.md +6 -6
  46. package/docs/reverse-proxy.md +2 -2
  47. package/docs/reverse-proxy.zh-CN.md +2 -2
  48. package/package.json +25 -11
package/dist/client.js CHANGED
@@ -2780,6 +2780,31 @@ var en = {
2780
2780
  errorUnauthorized: "Your session has expired. Sign in again.",
2781
2781
  errorServiceUnavailable: "The service is temporarily unavailable. Try again later.",
2782
2782
  errorGeneric: "The operation could not be completed. Try again.",
2783
+ accountLoginTitle: "Sign in to your DeepSeek account",
2784
+ accountLoginDescription: "Complete authorization in a new tab, then return here to finish signing in.",
2785
+ accountLoginStepOpen: "Click \u201COpen DeepSeek sign-in\u201D below and sign in on the official page.",
2786
+ accountLoginStepCopy: "After authorization, the new tab may show a connection error or 404. Copy its full address from the address bar.",
2787
+ accountLoginStepSubmit: "Return to this dialog, paste the address below and click \u201CConfirm sign-in\u201D.",
2788
+ accountLoginCallbackLabel: "Full callback address",
2789
+ accountLoginCallbackHint: "Include both code and state. The page does not need to load. Submit before this authorization expires.",
2790
+ accountLoginOpen: "Open DeepSeek sign-in",
2791
+ accountLoginConfirm: "Confirm sign-in",
2792
+ accountLoginCancel: "Cancel",
2793
+ accountLoginUseApiKey: "Use API key",
2794
+ accountLoginClose: "Close",
2795
+ accountLoginRetry: "Start again",
2796
+ accountLoginReopen: "Reopen authorization page",
2797
+ accountLoginPopupBlocked: "The new tab was blocked.",
2798
+ accountLoginInitializing: "Preparing authorization\u2026",
2799
+ accountLoginWaiting: "Waiting for the callback address. This authorization lasts at most 10 minutes.",
2800
+ accountLoginExchanging: "Completing sign-in\u2026",
2801
+ accountLoginInvalidCallback: "This callback address does not match the current authorization. Copy the full address, including code and state, from the latest authorization tab.",
2802
+ accountLoginExpired: "This authorization has expired. Start again.",
2803
+ accountLoginMismatch: "This authorization is no longer available in this session. Close this dialog and start again.",
2804
+ accountLoginBusy: "Another authorization is in progress. Finish or cancel it before starting again.",
2805
+ accountLoginUnavailable: "This DSH version does not provide compatible account sign-in.",
2806
+ accountLoginFailed: "Authorization could not be completed. Start again and submit the address from the new tab.",
2807
+ accountLoginNoResponse: "The DeepSeek platform did not respond. Check the DSH server\u2019s network connection and start again.",
2783
2808
  loginInitialTitle: "Sign in to DSH",
2784
2809
  loginInitialLoading: "Checking sign-in status\u2026",
2785
2810
  loginLanguageLabel: "Language",
@@ -2949,6 +2974,31 @@ var zh = {
2949
2974
  errorUnauthorized: "\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002",
2950
2975
  errorServiceUnavailable: "\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
2951
2976
  errorGeneric: "\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5\u3002",
2977
+ accountLoginTitle: "\u767B\u5F55 DeepSeek \u5B98\u65B9\u8D26\u53F7",
2978
+ accountLoginDescription: "\u5728\u65B0\u6807\u7B7E\u9875\u5B8C\u6210\u5B98\u65B9\u6388\u6743\u540E\uFF0C\u8FD4\u56DE\u6B64\u5904\u7EE7\u7EED\u767B\u5F55\u3002",
2979
+ accountLoginStepOpen: "\u70B9\u51FB\u4E0B\u65B9\u201C\u6253\u5F00 DeepSeek \u767B\u5F55\u9875\u201D\uFF0C\u5728\u5B98\u65B9\u9875\u9762\u767B\u5F55\u8D26\u53F7\u3002",
2980
+ accountLoginStepCopy: "\u6388\u6743\u540E\uFF0C\u65B0\u6807\u7B7E\u9875\u53EF\u80FD\u663E\u793A\u8FDE\u63A5\u5931\u8D25\u6216 404\u3002\u8BF7\u590D\u5236\u8BE5\u6807\u7B7E\u9875\u5730\u5740\u680F\u4E2D\u7684\u5B8C\u6574\u5730\u5740\u3002",
2981
+ accountLoginStepSubmit: "\u8FD4\u56DE\u6B64\u5F39\u7A97\uFF0C\u5C06\u5730\u5740\u7C98\u8D34\u5230\u4E0B\u65B9\u8F93\u5165\u6846\uFF0C\u518D\u70B9\u51FB\u201C\u786E\u8BA4\u767B\u5F55\u201D\u3002",
2982
+ accountLoginCallbackLabel: "\u5B8C\u6574\u56DE\u8C03\u5730\u5740",
2983
+ accountLoginCallbackHint: "\u5730\u5740\u987B\u5305\u542B code \u548C state\uFF1B\u8BE5\u9875\u9762\u65E0\u9700\u80FD\u6B63\u5E38\u6253\u5F00\u3002\u8BF7\u5728\u672C\u6B21\u6388\u6743\u5230\u671F\u524D\u63D0\u4EA4\u3002",
2984
+ accountLoginOpen: "\u6253\u5F00 DeepSeek \u767B\u5F55\u9875",
2985
+ accountLoginConfirm: "\u786E\u8BA4\u767B\u5F55",
2986
+ accountLoginCancel: "\u53D6\u6D88",
2987
+ accountLoginUseApiKey: "\u4F7F\u7528 API Key",
2988
+ accountLoginClose: "\u5173\u95ED",
2989
+ accountLoginRetry: "\u91CD\u65B0\u5F00\u59CB",
2990
+ accountLoginReopen: "\u91CD\u65B0\u6253\u5F00\u6388\u6743\u9875",
2991
+ accountLoginPopupBlocked: "\u65B0\u6807\u7B7E\u9875\u88AB\u6D4F\u89C8\u5668\u62E6\u622A\u3002",
2992
+ accountLoginInitializing: "\u6B63\u5728\u51C6\u5907\u6388\u6743\u2026",
2993
+ accountLoginWaiting: "\u7B49\u5F85\u586B\u5199\u56DE\u8C03\u5730\u5740\u3002\u672C\u6B21\u6388\u6743\u6700\u957F\u6709\u6548\u671F\u4E3A 10 \u5206\u949F\u3002",
2994
+ accountLoginExchanging: "\u6B63\u5728\u5B8C\u6210\u767B\u5F55\u2026",
2995
+ accountLoginInvalidCallback: "\u56DE\u8C03\u5730\u5740\u4E0E\u5F53\u524D\u6388\u6743\u4E0D\u5339\u914D\uFF0C\u8BF7\u4ECE\u6700\u8FD1\u4E00\u6B21\u6388\u6743\u6807\u7B7E\u9875\u590D\u5236\u5305\u542B code \u548C state \u7684\u5B8C\u6574\u5730\u5740\u3002",
2996
+ accountLoginExpired: "\u672C\u6B21\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5F00\u59CB\u3002",
2997
+ accountLoginMismatch: "\u5F53\u524D\u4F1A\u8BDD\u5DF2\u65E0\u6CD5\u7EE7\u7EED\u6B64\u6388\u6743\uFF0C\u8BF7\u5173\u95ED\u5F39\u7A97\u540E\u91CD\u65B0\u5F00\u59CB\u3002",
2998
+ accountLoginBusy: "\u5DF2\u6709\u6388\u6743\u6B63\u5728\u8FDB\u884C\uFF0C\u8BF7\u5148\u5B8C\u6210\u6216\u53D6\u6D88\u540E\u518D\u5F00\u59CB\u3002",
2999
+ accountLoginUnavailable: "\u5F53\u524D DSH \u7248\u672C\u672A\u63D0\u4F9B\u517C\u5BB9\u7684\u8D26\u53F7\u767B\u5F55\u529F\u80FD\u3002",
3000
+ accountLoginFailed: "\u672A\u80FD\u5B8C\u6210\u6388\u6743\uFF0C\u8BF7\u91CD\u65B0\u5F00\u59CB\uFF0C\u5E76\u63D0\u4EA4\u65B0\u6807\u7B7E\u9875\u4E2D\u7684\u56DE\u8C03\u5730\u5740\u3002",
3001
+ accountLoginNoResponse: "DeepSeek \u5E73\u53F0\u672A\u54CD\u5E94\uFF0C\u8BF7\u68C0\u67E5 DSH \u670D\u52A1\u5668\u7684\u7F51\u7EDC\u8FDE\u63A5\u540E\u91CD\u65B0\u5F00\u59CB\u3002",
2952
3002
  loginInitialTitle: "\u767B\u5F55 DSH",
2953
3003
  loginInitialLoading: "\u6B63\u5728\u68C0\u67E5\u767B\u5F55\u72B6\u6001\u2026",
2954
3004
  loginLanguageLabel: "\u8BED\u8A00",
@@ -3113,6 +3163,411 @@ var zh = {
3113
3163
  // src/client/settings/style.css
3114
3164
  var style_default = "/* Inherit the host's live DSH theme. Scope every rule to this settings section.\n * Radius fallbacks match 0.1.7, before DSH published the shared radius tokens. */\n.auth-remote-security {\n min-width: 0;\n color: var(--dsw-alias-label-primary);\n font-family: var(--dsw-font-family);\n font-size: 14px;\n line-height: 22px;\n}\n\n.auth-remote-security h2 {\n margin: 0 0 8px;\n font-size: 16px;\n font-weight: 500;\n line-height: 24px;\n}\n\n.auth-remote-security h3 {\n margin: 0 0 8px;\n font-size: 14px;\n font-weight: 500;\n line-height: 22px;\n}\n\n.auth-remote-security p {\n margin: 0 0 16px;\n color: var(--dsw-alias-label-secondary);\n font-size: 13px;\n line-height: 20px;\n}\n\n.auth-remote-actions {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n padding: 4px 0 20px;\n}\n\n.auth-remote-security form {\n margin: 0;\n padding: 20px 0;\n border-top: 0.5px solid var(--dsw-alias-border-l2);\n}\n\n.auth-remote-field {\n display: flex;\n flex-direction: column;\n gap: 6px;\n margin-bottom: 16px;\n font-size: 13px;\n line-height: 20px;\n}\n\n.auth-remote-field input {\n box-sizing: border-box;\n width: 100%;\n max-width: 420px;\n min-width: 0;\n height: 32px;\n padding: 0 10px;\n border: 0.5px solid var(--dsw-alias-border-l4);\n border-radius: var(--dsw-radius-md, 8px);\n background: var(--dsw-alias-bg-layer-1);\n color: var(--dsw-alias-label-primary);\n font: inherit;\n font-size: 14px;\n line-height: 22px;\n}\n\n.auth-remote-field input:focus {\n outline: none;\n border-color: var(--dsw-alias-state-business-primary);\n}\n\n.auth-remote-button {\n box-sizing: border-box;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-height: 36px;\n max-width: 100%;\n padding: 6px 14px;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md, 18px);\n background: transparent;\n color: var(--dsw-alias-label-primary);\n font: inherit;\n font-size: 14px;\n line-height: 22px;\n cursor: pointer;\n}\n\n.auth-remote-button:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.auth-remote-button[aria-pressed='true'] {\n background: var(--dsw-alias-bg-module-platform);\n border-color: var(--dsw-static-neutral-bluish-400);\n}\n\n.auth-remote-primary {\n border-color: transparent;\n background: var(--dsw-alias-button-primary-fill);\n color: var(--dsw-alias-label-primary-foreground);\n}\n\n.auth-remote-primary:hover:not(:disabled) {\n background: var(--dsw-alias-button-primary-hover);\n}\n\n.auth-remote-button:disabled {\n opacity: 0.4;\n cursor: not-allowed;\n}\n\n.auth-remote-button:focus-visible {\n outline: 2px solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));\n outline-offset: 2px;\n}\n\n.auth-remote-restart {\n margin-left: 8px;\n}\n\n.auth-remote-security img {\n display: block;\n max-width: 100%;\n height: auto;\n margin: 16px 0;\n border-radius: var(--dsw-radius-md, 8px);\n}\n\n.auth-remote-security code,\n.auth-remote-backup-codes {\n font-family: var(--ds-font-family-code);\n overflow-wrap: anywhere;\n user-select: all;\n}\n\n.auth-remote-backup-codes {\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 8px 24px;\n margin: 20px 0;\n padding: 16px 16px 16px 40px;\n border-radius: var(--dsw-radius-lg, 16px);\n background: var(--dsw-alias-bg-module-platform);\n}\n\n.auth-remote-security .auth-remote-error {\n margin: 12px 0 0;\n color: var(--dsw-alias-state-error-primary);\n}\n\n.auth-remote-error:empty {\n display: none;\n}\n";
3115
3165
 
3166
+ // src/client/account/style.css
3167
+ var style_default2 = "/* Match DSH's account modal typography and shared control/surface tokens. */\n.auth-remote-account-dialog {\n box-sizing: border-box;\n width: min(520px, calc(100vw - 48px));\n max-height: calc(100dvh - 48px);\n padding: 0;\n overflow: hidden;\n border: 0;\n border-radius: var(--dsw-radius-panel);\n background: var(--dsw-alias-bg-layer-2);\n color: var(--dsw-alias-label-primary);\n font: var(--dsw-font-s-14);\n box-shadow: var(--dsw-elevation-prominent);\n}\n.auth-remote-account-dialog::backdrop {\n background: var(--dsw-alias-bg-mask-1);\n}\n.auth-remote-account-dialog form {\n display: flex;\n flex-direction: column;\n max-height: inherit;\n margin: 0;\n}\n.auth-remote-account-header {\n display: flex;\n flex: none;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n padding: 22px 24px 12px;\n}\n.auth-remote-account-header h2 {\n margin: 0;\n font: var(--dsw-font-base-strong-16);\n}\n.auth-remote-account-dialog button {\n font: inherit;\n cursor: pointer;\n}\n.auth-remote-account-dialog .auth-remote-account-close {\n box-sizing: border-box;\n display: inline-flex;\n flex: none;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n padding: 0;\n border: 0;\n border-radius: var(--dsw-radius-sm);\n background: transparent;\n color: var(--dsw-alias-label-secondary);\n font-size: 20px;\n line-height: 20px;\n}\n.auth-remote-account-close:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n.auth-remote-account-body {\n display: flex;\n flex-direction: column;\n gap: 16px;\n min-height: 0;\n padding: 0 24px;\n overflow-y: auto;\n}\n.auth-remote-account-description,\n.auth-remote-account-steps,\n.auth-remote-account-hint,\n.auth-remote-account-reopen,\n.auth-remote-account-status,\n.auth-remote-account-error {\n margin: 0;\n font: inherit;\n}\n.auth-remote-account-description,\n.auth-remote-account-hint,\n.auth-remote-account-status {\n color: var(--dsw-alias-label-secondary);\n}\n.auth-remote-account-steps {\n padding-left: 20px;\n}\n.auth-remote-account-steps li + li {\n margin-top: 6px;\n}\n.auth-remote-account-callback,\n.auth-remote-account-field {\n display: flex;\n flex-direction: column;\n gap: 6px;\n}\n.auth-remote-account-field textarea {\n box-sizing: border-box;\n width: 100%;\n min-height: 80px;\n resize: vertical;\n padding: 8px 10px;\n border: 0.5px solid var(--dsw-alias-border-l4);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-1);\n color: inherit;\n font: inherit;\n overflow-wrap: anywhere;\n}\n.auth-remote-account-field textarea::placeholder {\n color: var(--dsw-alias-label-dimmed);\n opacity: 1;\n}\n.auth-remote-account-field textarea:focus {\n border-color: var(--dsw-alias-state-business-primary);\n}\n.auth-remote-account-hint {\n font: var(--dsw-font-xxs-12);\n}\n.auth-remote-account-dialog a {\n color: var(--dsw-alias-link);\n font-weight: 500;\n text-decoration: none;\n}\n.auth-remote-account-dialog a:hover,\n.auth-remote-account-dialog a:focus-visible {\n text-decoration: underline dotted;\n text-underline-offset: 3px;\n}\n.auth-remote-account-error {\n color: var(--dsw-alias-state-error-primary);\n}\n.auth-remote-account-status:empty,\n.auth-remote-account-error:empty {\n display: none;\n}\n.auth-remote-account-actions {\n display: flex;\n flex: none;\n justify-content: flex-end;\n align-items: center;\n gap: 8px;\n padding: 20px 24px 24px;\n}\n.auth-remote-account-actions button {\n box-sizing: border-box;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n min-width: 72px;\n height: 36px;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md);\n padding: 0 14px;\n background: transparent;\n color: inherit;\n}\n.auth-remote-account-actions button:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n.auth-remote-account-actions .auth-remote-account-primary {\n padding: 0 16px;\n background: var(--dsw-alias-button-primary-fill);\n border-color: transparent;\n color: var(--dsw-alias-label-primary-foreground);\n font-weight: 500;\n}\n.auth-remote-account-actions .auth-remote-account-primary:hover:not(:disabled) {\n background: var(--dsw-alias-button-primary-hover);\n}\n.auth-remote-account-dialog :disabled {\n opacity: 0.4;\n cursor: not-allowed;\n}\n.auth-remote-account-dialog :focus-visible {\n outline: 2px solid var(--dsw-focus-ring-color);\n outline-offset: 2px;\n}\n@media (max-width: 480px) {\n .auth-remote-account-header {\n padding: 20px 20px 12px;\n }\n .auth-remote-account-body {\n padding: 0 20px;\n }\n .auth-remote-account-actions {\n flex-wrap: wrap;\n padding: 20px;\n }\n .auth-remote-account-actions button {\n flex: 1;\n min-width: max-content;\n padding: 0 12px;\n white-space: nowrap;\n }\n}\n";
3168
+
3169
+ // src/client/account/index.tsx
3170
+ var import_react3 = require("react");
3171
+
3172
+ // src/client/account/dialog.tsx
3173
+ var import_react2 = require("react");
3174
+
3175
+ // src/shared/account-login.ts
3176
+ var ACCOUNT_LOGIN_BASE = "/auth-remote/account";
3177
+ var ACCOUNT_LOGIN_CAPABILITY = "__DSH_AUTH_REMOTE_MANUAL_ACCOUNT_LOGIN__";
3178
+ function isActiveAccountLogin(phase) {
3179
+ return ["initializing", "waiting-browser", "exchanging", "committing"].includes(phase);
3180
+ }
3181
+
3182
+ // src/client/account/dialog.tsx
3183
+ var import_jsx_runtime2 = require("react/jsx-runtime");
3184
+ function failureMessage(error) {
3185
+ if (!(error instanceof SettingsFailure)) return "errorNetwork";
3186
+ switch (error.code) {
3187
+ case "account_invalid_callback":
3188
+ return "accountLoginInvalidCallback";
3189
+ case "account_attempt_expired":
3190
+ return "accountLoginExpired";
3191
+ case "account_attempt_mismatch":
3192
+ return "accountLoginMismatch";
3193
+ case "account_busy":
3194
+ return "accountLoginBusy";
3195
+ case "account_unavailable":
3196
+ return "accountLoginUnavailable";
3197
+ case "account_exchange_failed":
3198
+ return "accountLoginFailed";
3199
+ default:
3200
+ return "errorServiceUnavailable";
3201
+ }
3202
+ }
3203
+ function ManualSignInDialog({
3204
+ t,
3205
+ locale,
3206
+ close,
3207
+ useApiKey
3208
+ }) {
3209
+ const dialog = (0, import_react2.useRef)(null);
3210
+ const popup = (0, import_react2.useRef)(null);
3211
+ const navigated = (0, import_react2.useRef)();
3212
+ const latest = (0, import_react2.useRef)();
3213
+ const live = (0, import_react2.useRef)(true);
3214
+ const revision = (0, import_react2.useRef)(0);
3215
+ const onClose = (0, import_react2.useRef)(close);
3216
+ onClose.current = close;
3217
+ const [state, setState] = (0, import_react2.useState)();
3218
+ const [callbackUrl, setCallbackUrl] = (0, import_react2.useState)("");
3219
+ const [busy, setBusy] = (0, import_react2.useState)(false);
3220
+ const [message, setMessage] = (0, import_react2.useState)();
3221
+ const [blocked, setBlocked] = (0, import_react2.useState)(false);
3222
+ const accept = (value) => {
3223
+ latest.current = value;
3224
+ if (!live.current) return;
3225
+ setState(value);
3226
+ if (value.status === "credential-stored") {
3227
+ setCallbackUrl("");
3228
+ onClose.current();
3229
+ return;
3230
+ }
3231
+ const attempt2 = value.attempt;
3232
+ if (attempt2?.authorizeUrl && navigated.current !== attempt2.id && popup.current && !popup.current.closed) {
3233
+ const target = new URL(attempt2.authorizeUrl);
3234
+ target.searchParams.set(
3235
+ "theme",
3236
+ document.body.hasAttribute("data-ds-dark-theme") ? "dark" : "light"
3237
+ );
3238
+ popup.current.location.replace(target.href);
3239
+ navigated.current = attempt2.id;
3240
+ }
3241
+ };
3242
+ (0, import_react2.useEffect)(() => {
3243
+ live.current = true;
3244
+ dialog.current?.showModal();
3245
+ let timer;
3246
+ const poll = async () => {
3247
+ const generation = revision.current;
3248
+ try {
3249
+ const value = await authRequest(`${ACCOUNT_LOGIN_BASE}/state`);
3250
+ if (generation === revision.current) accept(value);
3251
+ } catch (error) {
3252
+ if (isUnauthorized(error)) goToLogin();
3253
+ else if (live.current) setMessage(failureMessage(error));
3254
+ }
3255
+ if (live.current) timer = setTimeout(() => void poll(), 1e3);
3256
+ };
3257
+ void poll();
3258
+ return () => {
3259
+ live.current = false;
3260
+ clearTimeout(timer);
3261
+ popup.current?.close();
3262
+ const attempt2 = latest.current?.attempt;
3263
+ if (attempt2 && isActiveAccountLogin(attempt2.phase))
3264
+ void authRequest(`${ACCOUNT_LOGIN_BASE}/cancel`, { id: attempt2.id }).catch(() => {
3265
+ });
3266
+ };
3267
+ }, []);
3268
+ const attempt = state?.attempt;
3269
+ const phase = attempt?.phase;
3270
+ const waiting = phase === "waiting-browser";
3271
+ const pending = phase === "initializing" || phase === "exchanging" || phase === "committing";
3272
+ const active = attempt && isActiveAccountLogin(attempt.phase);
3273
+ const statusMessage = phase === "expired" ? "accountLoginExpired" : phase === "failed" ? attempt?.errorCode === "no-response" ? "accountLoginNoResponse" : "accountLoginFailed" : void 0;
3274
+ async function run(operation) {
3275
+ if (busy) return;
3276
+ setBusy(true);
3277
+ revision.current++;
3278
+ setMessage(void 0);
3279
+ try {
3280
+ await operation();
3281
+ } catch (error) {
3282
+ if (isUnauthorized(error)) goToLogin();
3283
+ else if (live.current) setMessage(failureMessage(error));
3284
+ } finally {
3285
+ if (live.current) setBusy(false);
3286
+ }
3287
+ }
3288
+ function start() {
3289
+ popup.current?.close();
3290
+ popup.current = window.open("about:blank", "_blank");
3291
+ if (popup.current) popup.current.opener = null;
3292
+ setBlocked(popup.current === null);
3293
+ navigated.current = void 0;
3294
+ setCallbackUrl("");
3295
+ void run(async () => {
3296
+ try {
3297
+ accept(
3298
+ await authRequest(`${ACCOUNT_LOGIN_BASE}/start`, {
3299
+ locale: locale(),
3300
+ timezoneOffsetSeconds: -(/* @__PURE__ */ new Date()).getTimezoneOffset() * 60
3301
+ })
3302
+ );
3303
+ } catch (error) {
3304
+ popup.current?.close();
3305
+ throw error;
3306
+ }
3307
+ });
3308
+ }
3309
+ function dismiss() {
3310
+ if (busy || phase === "committing") return;
3311
+ void run(async () => {
3312
+ if (active) await authRequest(`${ACCOUNT_LOGIN_BASE}/cancel`, { id: attempt.id });
3313
+ setCallbackUrl("");
3314
+ onClose.current();
3315
+ });
3316
+ }
3317
+ function submit(event) {
3318
+ event.preventDefault();
3319
+ if (!waiting || !attempt) return;
3320
+ void run(async () => {
3321
+ accept(
3322
+ await authRequest(`${ACCOUNT_LOGIN_BASE}/submit`, {
3323
+ id: attempt.id,
3324
+ callbackUrl
3325
+ })
3326
+ );
3327
+ });
3328
+ }
3329
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3330
+ "dialog",
3331
+ {
3332
+ ref: dialog,
3333
+ className: "auth-remote-account-dialog",
3334
+ "aria-labelledby": "auth-remote-account-title",
3335
+ onCancel: (event) => {
3336
+ event.preventDefault();
3337
+ dismiss();
3338
+ },
3339
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { onSubmit: submit, children: [
3340
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "auth-remote-account-header", children: [
3341
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { id: "auth-remote-account-title", children: t("accountLoginTitle") }),
3342
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3343
+ "button",
3344
+ {
3345
+ type: "button",
3346
+ className: "auth-remote-account-close",
3347
+ "aria-label": t("accountLoginClose"),
3348
+ disabled: busy || phase === "committing",
3349
+ onClick: dismiss,
3350
+ children: "\xD7"
3351
+ }
3352
+ )
3353
+ ] }),
3354
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "auth-remote-account-body", children: [
3355
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "auth-remote-account-description", children: t("accountLoginDescription") }),
3356
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("ol", { className: "auth-remote-account-steps", children: [
3357
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { children: t("accountLoginStepOpen") }),
3358
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { children: t("accountLoginStepCopy") }),
3359
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { children: t("accountLoginStepSubmit") })
3360
+ ] }),
3361
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "auth-remote-account-callback", children: [
3362
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "auth-remote-account-field", children: [
3363
+ t("accountLoginCallbackLabel"),
3364
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3365
+ "textarea",
3366
+ {
3367
+ rows: 3,
3368
+ value: callbackUrl,
3369
+ onChange: (event) => setCallbackUrl(event.currentTarget.value),
3370
+ placeholder: "http://127.0.0.1:49183/oauth/callback?code=\u2026&state=\u2026",
3371
+ autoComplete: "off",
3372
+ autoCapitalize: "none",
3373
+ spellCheck: false,
3374
+ maxLength: 8192,
3375
+ disabled: !waiting || busy,
3376
+ required: true,
3377
+ "aria-describedby": "auth-remote-account-hint"
3378
+ }
3379
+ )
3380
+ ] }),
3381
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { id: "auth-remote-account-hint", className: "auth-remote-account-hint", children: t("accountLoginCallbackHint") })
3382
+ ] }),
3383
+ attempt?.authorizeUrl && waiting && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "auth-remote-account-reopen", children: [
3384
+ blocked && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
3385
+ t("accountLoginPopupBlocked"),
3386
+ " "
3387
+ ] }),
3388
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: attempt.authorizeUrl, target: "_blank", rel: "noopener noreferrer", children: t("accountLoginReopen") })
3389
+ ] }),
3390
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "auth-remote-account-status", role: "status", "aria-live": "polite", children: pending ? t(phase === "initializing" ? "accountLoginInitializing" : "accountLoginExchanging") : waiting ? t("accountLoginWaiting") : "" }),
3391
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "auth-remote-account-error", role: "alert", children: state?.supported === false ? t("accountLoginUnavailable") : message || statusMessage ? t(message ?? statusMessage) : "" })
3392
+ ] }),
3393
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "auth-remote-account-actions", children: [
3394
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3395
+ "button",
3396
+ {
3397
+ type: "button",
3398
+ disabled: busy || phase === "committing",
3399
+ onClick: active || !useApiKey ? dismiss : useApiKey,
3400
+ children: t(active || !useApiKey ? "accountLoginCancel" : "accountLoginUseApiKey")
3401
+ }
3402
+ ),
3403
+ active ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3404
+ "button",
3405
+ {
3406
+ type: "submit",
3407
+ className: "auth-remote-account-primary",
3408
+ disabled: busy || !waiting || !callbackUrl.trim(),
3409
+ children: t(
3410
+ busy || phase === "exchanging" || phase === "committing" ? "accountLoginExchanging" : "accountLoginConfirm"
3411
+ )
3412
+ }
3413
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3414
+ "button",
3415
+ {
3416
+ type: "button",
3417
+ className: "auth-remote-account-primary",
3418
+ onClick: start,
3419
+ disabled: busy || !state?.supported,
3420
+ children: t(attempt ? "accountLoginRetry" : "accountLoginOpen")
3421
+ }
3422
+ )
3423
+ ] })
3424
+ ] })
3425
+ }
3426
+ );
3427
+ }
3428
+
3429
+ // src/client/account/index.tsx
3430
+ var import_jsx_runtime3 = require("react/jsx-runtime");
3431
+ function installManualAccountLogin(ctx) {
3432
+ if (globalThis[ACCOUNT_LOGIN_CAPABILITY] !== true) return;
3433
+ const slots = ctx.get("slots");
3434
+ if (typeof slots.entries !== "function" || typeof slots.subscribe !== "function") return;
3435
+ const t = ctx.locale.bind("auth-remote");
3436
+ const locale = () => ctx.locale.getSnapshot().active;
3437
+ let dialog;
3438
+ const listeners = /* @__PURE__ */ new Set();
3439
+ const completions = /* @__PURE__ */ new Set();
3440
+ const notify = () => {
3441
+ for (const listener of listeners) listener();
3442
+ };
3443
+ const show = (owner = {}) => {
3444
+ if (owner.complete) completions.add(owner.complete);
3445
+ dialog = owner;
3446
+ notify();
3447
+ };
3448
+ const close = () => {
3449
+ dialog = void 0;
3450
+ const pending = [...completions];
3451
+ completions.clear();
3452
+ notify();
3453
+ for (const complete of pending) complete();
3454
+ };
3455
+ const useApiKey = () => {
3456
+ const action = dialog?.useApiKey;
3457
+ if (!action) return;
3458
+ dialog = void 0;
3459
+ completions.clear();
3460
+ notify();
3461
+ action();
3462
+ };
3463
+ const subscribe = (listener) => {
3464
+ listeners.add(listener);
3465
+ return () => {
3466
+ listeners.delete(listener);
3467
+ };
3468
+ };
3469
+ function AccountOverlay() {
3470
+ const owner = (0, import_react3.useSyncExternalStore)(subscribe, () => dialog);
3471
+ return owner ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3472
+ ManualSignInDialog,
3473
+ {
3474
+ t,
3475
+ locale,
3476
+ close,
3477
+ ...owner.useApiKey ? { useApiKey } : {}
3478
+ }
3479
+ ) : null;
3480
+ }
3481
+ slots.inject(
3482
+ "shell.overlay",
3483
+ () => slots.register(
3484
+ {
3485
+ name: "shell.overlay",
3486
+ id: "auth-remote.account-sign-in",
3487
+ locale: "auth-remote"
3488
+ },
3489
+ AccountOverlay
3490
+ )
3491
+ );
3492
+ const wrappers = /* @__PURE__ */ new WeakSet();
3493
+ for (const name2 of ["settings.launcher", "settings.models.sign-in"]) {
3494
+ slots.inject(name2, () => {
3495
+ let current;
3496
+ let unregister;
3497
+ const update = () => {
3498
+ const native = slots.entries(name2).find(
3499
+ (entry) => entry.locale === "settings.account" && entry.inject !== void 0 && !wrappers.has(entry.component)
3500
+ );
3501
+ if (native === current) return;
3502
+ current = native;
3503
+ unregister?.();
3504
+ unregister = void 0;
3505
+ if (!native) return;
3506
+ const Native = native.component;
3507
+ function ManualAccountEntry(props) {
3508
+ const latest = (0, import_react3.useRef)(props);
3509
+ latest.current = props;
3510
+ (0, import_react3.useEffect)(() => {
3511
+ if (name2 !== "settings.launcher") {
3512
+ const complete = () => {
3513
+ latest.current.showLogin?.(false);
3514
+ latest.current.complete?.();
3515
+ };
3516
+ const owner = {
3517
+ complete,
3518
+ ...latest.current.useApiKey ? {
3519
+ useApiKey: () => {
3520
+ latest.current.showLogin?.(false);
3521
+ latest.current.useApiKey?.();
3522
+ }
3523
+ } : {}
3524
+ };
3525
+ show(owner);
3526
+ return () => {
3527
+ completions.delete(complete);
3528
+ if (dialog === owner && owner.useApiKey) {
3529
+ dialog = {};
3530
+ notify();
3531
+ }
3532
+ };
3533
+ }
3534
+ }, []);
3535
+ return name2 === "settings.launcher" ? (0, import_react3.createElement)(Native, {
3536
+ ...props,
3537
+ start: async () => {
3538
+ show(
3539
+ latest.current.openOnboarding ? {
3540
+ useApiKey: () => {
3541
+ latest.current.showLogin?.(false);
3542
+ latest.current.openOnboarding?.("deepseek-official");
3543
+ }
3544
+ } : {}
3545
+ );
3546
+ }
3547
+ }) : null;
3548
+ }
3549
+ wrappers.add(ManualAccountEntry);
3550
+ unregister = slots.register(
3551
+ {
3552
+ name: name2,
3553
+ priority: (native.options.priority ?? 0) - 100,
3554
+ // Framework still binds the native menu's translations and Hooks.
3555
+ ...native.locale ? { locale: native.locale } : {},
3556
+ inject: native.inject
3557
+ },
3558
+ ManualAccountEntry
3559
+ );
3560
+ };
3561
+ const stop = slots.subscribe(name2, update);
3562
+ update();
3563
+ return () => {
3564
+ stop();
3565
+ unregister?.();
3566
+ };
3567
+ });
3568
+ }
3569
+ }
3570
+
3116
3571
  // src/client/index.ts
3117
3572
  var name = "auth-remote";
3118
3573
  var inject = ["connection", "slots", "locale"];
@@ -3121,13 +3576,14 @@ function apply(ctx) {
3121
3576
  ctx.effect(() => {
3122
3577
  const tag = document.createElement("style");
3123
3578
  tag.dataset.plugin = "dsh-auth-remote";
3124
- tag.textContent = style_default;
3579
+ tag.textContent = style_default + style_default2;
3125
3580
  document.head.appendChild(tag);
3126
3581
  return () => tag.remove();
3127
3582
  }, "auth-remote: settings styles");
3128
3583
  monitorSession(ctx);
3129
3584
  ctx.effect(() => ctx.locale.register("auth-remote", { en, zh }), "auth-remote: dictionaries");
3130
3585
  const t = ctx.locale.bind("auth-remote");
3586
+ installManualAccountLogin(ctx);
3131
3587
  const slots = ctx.get("slots");
3132
3588
  slots.inject(
3133
3589
  "settings.section",