dsh-use-chatgpt 1.0.0 → 1.0.1
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/README.md +3 -1
- package/dist/client.js +80 -56
- package/dist/index.js +107 -57
- package/docs/images/chatgpt-settings.png +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
在 DeepSeek Harness 中使用你的 ChatGPT 套餐额度。当前支持本机 macOS 和 Windows。
|
|
4
4
|
|
|
5
|
+

|
|
6
|
+
|
|
5
7
|
## 开始使用
|
|
6
8
|
|
|
7
9
|
1. 打开侧边栏的「关联ChatGPT」,点击「使用 ChatGPT 登录」,在浏览器中完成授权。
|
|
@@ -11,7 +13,7 @@
|
|
|
11
13
|
|
|
12
14
|
## 常用功能
|
|
13
15
|
|
|
14
|
-
- **账号**
|
|
16
|
+
- **账号** 在账号列表底部添加账号,在对应行切换账号或通过「⋯」退出登录。退出后,该账号的本地连接记录会被删除。再次添加同一账号会建立新连接,模型显示设置需重新配置,绑定旧连接的插件专属对话也无法续接。
|
|
15
17
|
- **模型** 在「可用模型」里关闭不常用的模型,即可从对话页的模型列表中隐藏。每个账号单独保存设置。
|
|
16
18
|
- **对话** 在输入框底部打开「联网」即可搜索网页。支持的模型还可调整推理等级、读取图片和 PDF,或调用会话中已获准的工具。
|
|
17
19
|
|
package/dist/client.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primi
|
|
|
31
31
|
// package.json
|
|
32
32
|
var package_default = {
|
|
33
33
|
name: "dsh-use-chatgpt",
|
|
34
|
-
version: "1.0.
|
|
34
|
+
version: "1.0.1",
|
|
35
35
|
description: "ChatGPT plan model provider for a local DeepSeek Harness desktop instance",
|
|
36
36
|
type: "module",
|
|
37
37
|
engines: { node: "^22.19.0 || >=24.0.0" },
|
|
@@ -45,7 +45,7 @@ var package_default = {
|
|
|
45
45
|
"./client": "./dist/client.js",
|
|
46
46
|
"./package.json": "./package.json"
|
|
47
47
|
},
|
|
48
|
-
files: ["dist", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
48
|
+
files: ["dist", "docs/images/chatgpt-settings.png", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
49
49
|
dsh: {
|
|
50
50
|
bundle: { patch: "./cordis.patch.yml" },
|
|
51
51
|
client: {
|
|
@@ -319,8 +319,8 @@ function ModelCatalog({ t, language, resource, profileId }) {
|
|
|
319
319
|
)
|
|
320
320
|
] }),
|
|
321
321
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "cg-catalog-hint", children: words.hint }),
|
|
322
|
-
error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", className: "dsh-use-chatgpt-error", children: t("modelsFailed") }),
|
|
323
|
-
|
|
322
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", className: "dsh-use-chatgpt-error", children: error || t("modelsFailed") }),
|
|
323
|
+
error === null && !models?.length && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "status", children: t(models ? "modelsEmpty" : "modelsLoading") }),
|
|
324
324
|
models?.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "cg-model-list", "aria-labelledby": heading, children: models.map((model) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
325
325
|
ModelRow,
|
|
326
326
|
{
|
|
@@ -576,7 +576,7 @@ function openPluginDetails(ctx) {
|
|
|
576
576
|
}
|
|
577
577
|
|
|
578
578
|
// client/settings.css
|
|
579
|
-
var settings_default = ".dsh-use-chatgpt-page {\n --cg-surface: var(--dsw-alias-bg-layer-1, #fff);\n --cg-ink: var(--dsw-alias-label-primary, #0d0d0d);\n --cg-muted: var(--dsw-alias-label-secondary, #5d5d5d);\n --cg-line: color-mix(in srgb, var(--cg-ink) 13%, var(--cg-surface));\n --cg-wash: color-mix(in srgb, var(--cg-ink) 5%, var(--cg-surface));\n --cg-accent: var(--cg-ink);\n --cg-allowed: #257250;\n width: 100%; height: 100%; min-width: 0; overflow: auto;\n background: var(--cg-surface); color: var(--cg-ink);\n font-family: inherit; font-size: 14px; line-height: 1.5; container: chatgpt-page / inline-size;\n}\nbody[data-ds-dark-theme] .dsh-use-chatgpt-page { --cg-allowed: #9ad5b0; }\n.dsh-use-chatgpt-page *, .dsh-use-chatgpt-page *::before, .dsh-use-chatgpt-page *::after { box-sizing: border-box; }\n.dsh-use-chatgpt-page [hidden] { display: none !important; }\n.dsh-use-chatgpt-content { width: min(calc(100% - 48px), 728px); margin: 0 auto; padding: 30px 0 58px; }\n.dsh-use-chatgpt-header { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 5px 12px; }\n.dsh-use-chatgpt-header h1 { margin: 0; font-size: 26px; line-height: 1.25; font-weight: 600; letter-spacing: -.045em; }\n.dsh-use-chatgpt-header p { grid-column: 1 / -1; margin: 0; color: var(--cg-muted); font-size: 15px; line-height: 1.55; }\n.cg-header-version { display: grid; justify-items: end; color: var(--cg-muted); text-align: end; }\n.cg-header-links { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 2px 6px; }\n.cg-project-link {\n display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;\n border-radius: 50%; color: var(--cg-muted); text-decoration: none;\n}\n.cg-project-link:is(:hover, :focus-visible) { background: var(--cg-wash); color: var(--cg-ink); }\n.dsh-use-chatgpt-page .dsh-use-chatgpt-actions button {\n display: inline-flex; align-items: center; justify-content: center; gap: 7px;\n min-height: 36px; padding: 6px 14px; border: 1px solid var(--cg-line); border-radius: 999px;\n background: var(--cg-wash); color: var(--cg-ink); cursor: pointer;\n font: inherit; font-size: 14px; line-height: 1.4; white-space: normal;\n}\n.dsh-use-chatgpt-page .dsh-use-chatgpt-actions button:hover:enabled {\n background: color-mix(in srgb, var(--cg-ink) 9%, var(--cg-surface));\n}\n.dsh-use-chatgpt-page :where(button, select, a, summary):focus-visible { outline: 2px solid var(--cg-ink); outline-offset: 3px; }\n.dsh-use-chatgpt-page button:disabled { cursor: default; opacity: .55; }\n.cg-dashboard { display: grid; gap: 34px; margin-top: 41px; }\n.cg-account { min-width: 0; }\n.cg-account-heading { padding-bottom: 12px; border-bottom: 1px solid var(--cg-line); }\n.cg-account-heading h2 { margin: 0; font-size: 16px; line-height: 1.5; font-weight: 600; }\n.cg-profile-list { margin: 0; padding: 0; list-style: none; }\n.cg-profile {\n display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;\n min-height: 76px; padding-block: 14px; border-block-end: 1px solid var(--cg-line);\n}\n.cg-profile-avatar {\n display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; overflow: hidden;\n background: var(--cg-ink); color: var(--cg-surface); font-size: 13px; line-height: 1; font-weight: 550;\n}\n.cg-profile-text { display: grid; gap: 3px; min-width: 0; }\n.cg-profile-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }\n.cg-profile-name strong { min-width: 0; font-size: 15px; font-weight: 550; overflow-wrap: anywhere; }\n.cg-current-account {\n display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px;\n background: color-mix(in srgb, var(--cg-allowed) 13%, var(--cg-surface));\n color: var(--cg-allowed); font-size: 11px; font-weight: 600; white-space: nowrap;\n}\n.cg-profile-meta { display: flex; align-items: center; gap: 3px 12px; flex-wrap: wrap; font-size: 13px; color: var(--cg-muted); overflow-wrap: anywhere; }\n.cg-profile-actions { display: flex; align-items: center; justify-self: end; gap: 6px; }\n.cg-account-action, .cg-account-more, .cg-account-add {\n display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 32px;\n border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--cg-ink);\n font: inherit; font-size: 13px; font-weight: 500; line-height: 1.4; cursor: pointer;\n}\n.cg-account-action, .cg-account-add { border-color: var(--cg-line); padding: 5px 12px; }\n.cg-account-more { width: 32px; padding: 0; color: var(--cg-muted); }\n.cg-account-add { min-height: 36px; margin-block-start: 14px; font-size: 14px; }\n.cg-account-action:hover:enabled, .cg-account-add:hover:enabled,\n.cg-account-more:hover:enabled, .cg-account-more[aria-expanded=true] { color: var(--cg-ink); background: var(--cg-wash); }\n.cg-account-flow { display: grid; gap: 12px; justify-items: start; padding: 16px 0; }\n.cg-account-flow
|
|
579
|
+
var settings_default = ".dsh-use-chatgpt-page {\n --cg-surface: var(--dsw-alias-bg-layer-1, #fff);\n --cg-ink: var(--dsw-alias-label-primary, #0d0d0d);\n --cg-muted: var(--dsw-alias-label-secondary, #5d5d5d);\n --cg-line: color-mix(in srgb, var(--cg-ink) 13%, var(--cg-surface));\n --cg-wash: color-mix(in srgb, var(--cg-ink) 5%, var(--cg-surface));\n --cg-accent: var(--cg-ink);\n --cg-allowed: #257250;\n width: 100%; height: 100%; min-width: 0; overflow: auto;\n background: var(--cg-surface); color: var(--cg-ink);\n font-family: inherit; font-size: 14px; line-height: 1.5; container: chatgpt-page / inline-size;\n}\nbody[data-ds-dark-theme] .dsh-use-chatgpt-page { --cg-allowed: #9ad5b0; }\n.dsh-use-chatgpt-page *, .dsh-use-chatgpt-page *::before, .dsh-use-chatgpt-page *::after { box-sizing: border-box; }\n.dsh-use-chatgpt-page [hidden] { display: none !important; }\n.dsh-use-chatgpt-content { width: min(calc(100% - 48px), 728px); margin: 0 auto; padding: 30px 0 58px; }\n.dsh-use-chatgpt-header { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 5px 12px; }\n.dsh-use-chatgpt-header h1 { margin: 0; font-size: 26px; line-height: 1.25; font-weight: 600; letter-spacing: -.045em; }\n.dsh-use-chatgpt-header p { grid-column: 1 / -1; margin: 0; color: var(--cg-muted); font-size: 15px; line-height: 1.55; }\n.cg-header-version { display: grid; justify-items: end; color: var(--cg-muted); text-align: end; }\n.cg-header-links { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 2px 6px; }\n.cg-project-link {\n display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;\n border-radius: 50%; color: var(--cg-muted); text-decoration: none;\n}\n.cg-project-link:is(:hover, :focus-visible) { background: var(--cg-wash); color: var(--cg-ink); }\n.dsh-use-chatgpt-page .dsh-use-chatgpt-actions button {\n display: inline-flex; align-items: center; justify-content: center; gap: 7px;\n min-height: 36px; padding: 6px 14px; border: 1px solid var(--cg-line); border-radius: 999px;\n background: var(--cg-wash); color: var(--cg-ink); cursor: pointer;\n font: inherit; font-size: 14px; line-height: 1.4; white-space: normal;\n}\n.dsh-use-chatgpt-page .dsh-use-chatgpt-actions button:hover:enabled {\n background: color-mix(in srgb, var(--cg-ink) 9%, var(--cg-surface));\n}\n.dsh-use-chatgpt-page :where(button, select, a, summary):focus-visible { outline: 2px solid var(--cg-ink); outline-offset: 3px; }\n.dsh-use-chatgpt-page button:disabled { cursor: default; opacity: .55; }\n.cg-dashboard { display: grid; gap: 34px; margin-top: 41px; }\n.cg-account { min-width: 0; }\n.cg-account-heading { padding-bottom: 12px; border-bottom: 1px solid var(--cg-line); }\n.cg-account-heading h2 { margin: 0; font-size: 16px; line-height: 1.5; font-weight: 600; }\n.cg-profile-list { margin: 0; padding: 0; list-style: none; }\n.cg-profile {\n display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;\n min-height: 76px; padding-block: 14px; border-block-end: 1px solid var(--cg-line);\n}\n.cg-profile-avatar {\n display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; overflow: hidden;\n background: var(--cg-ink); color: var(--cg-surface); font-size: 13px; line-height: 1; font-weight: 550;\n}\n.cg-profile-text { display: grid; gap: 3px; min-width: 0; }\n.cg-profile-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }\n.cg-profile-name strong { min-width: 0; font-size: 15px; font-weight: 550; overflow-wrap: anywhere; }\n.cg-current-account {\n display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px;\n background: color-mix(in srgb, var(--cg-allowed) 13%, var(--cg-surface));\n color: var(--cg-allowed); font-size: 11px; font-weight: 600; white-space: nowrap;\n}\n.cg-profile-meta { display: flex; align-items: center; gap: 3px 12px; flex-wrap: wrap; font-size: 13px; color: var(--cg-muted); overflow-wrap: anywhere; }\n.cg-profile-actions { display: flex; align-items: center; justify-self: end; gap: 6px; }\n.cg-account-action, .cg-account-more, .cg-account-add {\n display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 32px;\n border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--cg-ink);\n font: inherit; font-size: 13px; font-weight: 500; line-height: 1.4; cursor: pointer;\n}\n.cg-account-action, .cg-account-add { border-color: var(--cg-line); padding: 5px 12px; }\n.cg-account-more { width: 32px; padding: 0; color: var(--cg-muted); }\n.cg-account-add { min-height: 36px; margin-block-start: 14px; font-size: 14px; }\n.cg-account-action:hover:enabled, .cg-account-add:hover:enabled,\n.cg-account-more:hover:enabled, .cg-account-more[aria-expanded=true] { color: var(--cg-ink); background: var(--cg-wash); }\n.cg-account-flow { display: grid; gap: 12px; justify-items: start; padding: 16px 0; }\n.cg-account-flow p { margin: 0; color: var(--cg-muted); }\n.dsh-use-chatgpt-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }\n.dsh-use-chatgpt-actions:empty { display: none; }\n.cg-account > p { margin: 12px 0; font-size: 14px; color: var(--cg-muted); }\n.dsh-use-chatgpt-page .dsh-use-chatgpt-error { color: var(--dsw-alias-state-warn-label, #9a461e); overflow-wrap: anywhere; }\n.cg-login-layout {\n display: grid; grid-template-columns: minmax(0, 1fr);\n grid-template-rows: minmax(min-content, 1fr) auto minmax(min-content, 1fr);\n justify-items: center; gap: 20px;\n min-height: 100%; width: 100%; padding: 20px clamp(16px, 4cqi, 40px);\n}\n.cg-welcome {\n grid-row: 2; display: flex; flex-direction: column; align-items: center;\n width: min(100%, 392px); text-align: center;\n}\n.cg-welcome-heading { display: grid; justify-items: center; gap: 22px; }\n.cg-welcome-heading h1 { margin: 0; font-size: clamp(26px, 4cqi, 34px); font-weight: 600; letter-spacing: -.035em; line-height: 1.18; text-wrap: balance; }\n.cg-welcome > .cg-account-status { margin: 12px 0 0; font-size: 15px; line-height: 1.6; text-wrap: balance; }\n.cg-welcome > .dsh-use-chatgpt-actions:not(:empty) {\n display: grid; width: min(100%, 310px); gap: 8px; margin-top: 26px;\n}\n.cg-welcome > .dsh-use-chatgpt-actions button { width: 100%; min-height: 46px; font-size: 15px; }\n.cg-welcome .dsh-use-chatgpt-actions .cg-primary { background: var(--cg-ink); color: var(--cg-surface); font-weight: 550; }\n.cg-welcome .dsh-use-chatgpt-actions .cg-primary:hover:enabled { background: color-mix(in srgb, var(--cg-ink) 85%, var(--cg-surface)); }\n.cg-login-footer { grid-row: 3; align-self: end; display: grid; justify-items: center; color: var(--cg-muted); text-align: center; }\n.cg-version {\n display: inline-flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px 7px; max-width: 100%;\n min-height: 32px; padding: 4px 0; border: 0; border-radius: 8px;\n background: transparent; color: inherit; font: inherit; font-size: 12px; font-variant-numeric: tabular-nums;\n overflow-wrap: anywhere; cursor: default;\n}\n.cg-login-footer .cg-version { justify-content: center; padding: 6px 10px; }\nbutton.cg-version { padding-inline: 8px; cursor: pointer; }\nbutton.cg-version:hover { color: var(--cg-ink); background: var(--cg-wash); }\n.dsh-use-chatgpt-update-badge {\n display: inline-flex; align-items: center; flex: none; vertical-align: middle;\n padding: 1px 6px; border-radius: 999px; white-space: nowrap;\n background-color: #171717;\n color: #fff;\n font-family: inherit; font-size: 11px; font-weight: 550; line-height: 16px;\n}\nbody[data-ds-dark-theme] .dsh-use-chatgpt-update-badge {\n background-color: #f5f5f5;\n color: #171717;\n}\n.cg-legacy-defaults { font-size: 14px; }\n.cg-legacy-defaults summary { cursor: pointer; }\n.cg-legacy-defaults p { margin: 8px 0; color: var(--cg-muted); }\n@container chatgpt-page (max-width: 510px) {\n .dsh-use-chatgpt-content { width: calc(100% - 36px); padding-block: 22px 36px; }\n .cg-dashboard { margin-top: 28px; }\n .cg-dashboard { gap: 26px; }\n .cg-profile { column-gap: 9px; }\n .cg-profile-meta { gap: 1px 8px; }\n}\n@container chatgpt-page (max-width: 360px) {\n .cg-profile:has(.cg-account-action) { grid-template-columns: auto minmax(0, 1fr); row-gap: 6px; }\n .cg-profile:has(.cg-account-action) .cg-profile-actions { grid-column: 2; justify-self: start; }\n}\n";
|
|
580
580
|
|
|
581
581
|
// client/index.jsx
|
|
582
582
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
@@ -604,9 +604,9 @@ var dictionaries = {
|
|
|
604
604
|
subtitle: "\u5728 DeepSeek Harness \u4E2D\u4F7F\u7528\u4F60\u7684 ChatGPT \u5957\u9910\u989D\u5EA6\u3002",
|
|
605
605
|
browserTitle: "\u5728\u6D4F\u89C8\u5668\u4E2D\u7EE7\u7EED",
|
|
606
606
|
chooseSignedIn: "\u9009\u62E9\u5DF2\u767B\u5F55\u8D26\u53F7",
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
607
|
+
authorizeHint: "\u8BF7\u5728 1 \u5206\u949F\u5185\u5B8C\u6210\u6D4F\u89C8\u5668\u4E2D\u7684\u6388\u6743\u3002\u5B8C\u6210\u540E\u5C06\u5207\u6362\u5230\u8BE5\u8D26\u53F7\u3002",
|
|
608
|
+
authorizationFailed: "\u6388\u6743\u672A\u5B8C\u6210",
|
|
609
|
+
close: "\u5173\u95ED",
|
|
610
610
|
reconnectAccount: "\u91CD\u65B0\u8FDE\u63A5",
|
|
611
611
|
pendingAccount: "\u5F85\u5B8C\u6210\u6388\u6743",
|
|
612
612
|
resumeAccount: "\u7EE7\u7EED\u6388\u6743",
|
|
@@ -657,9 +657,9 @@ var dictionaries = {
|
|
|
657
657
|
subtitle: "Use your ChatGPT plan allowance in DeepSeek Harness.",
|
|
658
658
|
browserTitle: "Continue in your browser",
|
|
659
659
|
chooseSignedIn: "Choose a signed-in account",
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
660
|
+
authorizeHint: "Complete authorization in your browser within 1 minute to switch to this account.",
|
|
661
|
+
authorizationFailed: "Authorization incomplete",
|
|
662
|
+
close: "Close",
|
|
663
663
|
reconnectAccount: "Reconnect",
|
|
664
664
|
pendingAccount: "Authorization pending",
|
|
665
665
|
resumeAccount: "Continue sign-in",
|
|
@@ -721,6 +721,9 @@ async function requestConnection(action, signal, payload) {
|
|
|
721
721
|
function isSignIn(action) {
|
|
722
722
|
return action === "sign-in" || action === "enable" || action === "add-account";
|
|
723
723
|
}
|
|
724
|
+
function isAccountDialogAction(action) {
|
|
725
|
+
return action === "add-account" || action === "cancel-add";
|
|
726
|
+
}
|
|
724
727
|
function useConnection() {
|
|
725
728
|
const [connection, setConnection] = (0, import_react4.useState)(null);
|
|
726
729
|
const [pending, setPending] = (0, import_react4.useState)(null);
|
|
@@ -762,7 +765,7 @@ function useConnection() {
|
|
|
762
765
|
pendingAction.current = null;
|
|
763
766
|
};
|
|
764
767
|
}, [refresh]);
|
|
765
|
-
const polling = connection?.status === "connecting";
|
|
768
|
+
const polling = connection?.status === "connecting" || connection?.addingAccount;
|
|
766
769
|
(0, import_react4.useEffect)(() => {
|
|
767
770
|
if (!polling) return;
|
|
768
771
|
const timer = window.setInterval(() => {
|
|
@@ -790,7 +793,9 @@ function useConnection() {
|
|
|
790
793
|
}
|
|
791
794
|
} catch (failure) {
|
|
792
795
|
failed = true;
|
|
793
|
-
if (!signal.aborted && revision.current === update
|
|
796
|
+
if (!signal.aborted && revision.current === update && !(action === "add-account" && failure.code === "cancelled")) {
|
|
797
|
+
setError({ action, message: failure.message, code: failure.code });
|
|
798
|
+
}
|
|
794
799
|
} finally {
|
|
795
800
|
if (!signal.aborted && revision.current === update) {
|
|
796
801
|
pendingAction.current = null;
|
|
@@ -799,7 +804,7 @@ function useConnection() {
|
|
|
799
804
|
}
|
|
800
805
|
}
|
|
801
806
|
}
|
|
802
|
-
return { connection, pending, error, refresh, run };
|
|
807
|
+
return { connection, pending, error, dismissError: () => setError(null), refresh, run };
|
|
803
808
|
}
|
|
804
809
|
function profileName(profile) {
|
|
805
810
|
return profile.identity?.email || profile.identity?.name || profile.label;
|
|
@@ -947,6 +952,7 @@ function AccountRow({ profile, current, busy, t, run }) {
|
|
|
947
952
|
type: "button",
|
|
948
953
|
className: "cg-account-action",
|
|
949
954
|
disabled: busy,
|
|
955
|
+
"aria-haspopup": "dialog",
|
|
950
956
|
onClick: () => {
|
|
951
957
|
void run("add-account", { profileId: id });
|
|
952
958
|
},
|
|
@@ -955,7 +961,7 @@ function AccountRow({ profile, current, busy, t, run }) {
|
|
|
955
961
|
) })
|
|
956
962
|
] });
|
|
957
963
|
}
|
|
958
|
-
function Account({ t, state
|
|
964
|
+
function Account({ t, state }) {
|
|
959
965
|
const titleId = (0, import_react4.useId)();
|
|
960
966
|
const { connection, pending, error, run } = state;
|
|
961
967
|
const { profileId, profiles = [] } = connection;
|
|
@@ -969,10 +975,10 @@ function Account({ t, state, adding }) {
|
|
|
969
975
|
sharing: connection.sharing
|
|
970
976
|
});
|
|
971
977
|
}
|
|
972
|
-
const waiting =
|
|
973
|
-
const busy = waiting || Boolean(pending);
|
|
978
|
+
const waiting = connection.status === "connecting" || pending === "enable" || pending === "cancel";
|
|
979
|
+
const busy = waiting || Boolean(pending) && !isAccountDialogAction(pending);
|
|
974
980
|
const needsConsent = connection.status === "connected" && !connection.sharing;
|
|
975
|
-
const message = error ? error.message || t("requestFailed") : !waiting && connection.error?.message;
|
|
981
|
+
const message = error ? !isAccountDialogAction(error.action) && (error.message || t("requestFailed")) : !waiting && connection.error?.message;
|
|
976
982
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "cg-account", "aria-labelledby": titleId, children: [
|
|
977
983
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("header", { className: "cg-account-heading", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { id: titleId, children: t("account") }) }),
|
|
978
984
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: "cg-profile-list", children: rows.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -988,20 +994,17 @@ function Account({ t, state, adding }) {
|
|
|
988
994
|
)) }),
|
|
989
995
|
message && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsh-use-chatgpt-error", role: "alert", children: message }),
|
|
990
996
|
waiting ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cg-account-flow", children: [
|
|
991
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
992
|
-
adding && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: t("addTitle") }),
|
|
993
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: t(adding ? "addHint" : "connecting") })
|
|
994
|
-
] }),
|
|
997
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "status", children: t("connecting") }),
|
|
995
998
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-use-chatgpt-actions", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
996
999
|
import_dsh_client_ui_primitives3.Button,
|
|
997
1000
|
{
|
|
998
1001
|
variant: "outline",
|
|
999
1002
|
size: "sm",
|
|
1000
|
-
disabled: pending === "cancel"
|
|
1003
|
+
disabled: pending === "cancel",
|
|
1001
1004
|
onClick: () => {
|
|
1002
|
-
void run(
|
|
1005
|
+
void run("cancel");
|
|
1003
1006
|
},
|
|
1004
|
-
children: t(
|
|
1007
|
+
children: t("cancel")
|
|
1005
1008
|
}
|
|
1006
1009
|
) })
|
|
1007
1010
|
] }) : needsConsent && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cg-account-flow", children: [
|
|
@@ -1016,6 +1019,7 @@ function Account({ t, state, adding }) {
|
|
|
1016
1019
|
type: "button",
|
|
1017
1020
|
className: "cg-account-add",
|
|
1018
1021
|
disabled: busy,
|
|
1022
|
+
"aria-haspopup": "dialog",
|
|
1019
1023
|
onClick: () => {
|
|
1020
1024
|
void run("add-account", { newProfile: true });
|
|
1021
1025
|
},
|
|
@@ -1029,7 +1033,7 @@ function Account({ t, state, adding }) {
|
|
|
1029
1033
|
}
|
|
1030
1034
|
function usePageResource(read) {
|
|
1031
1035
|
const [data, setData] = (0, import_react4.useState)(null);
|
|
1032
|
-
const [error, setError] = (0, import_react4.useState)(
|
|
1036
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
1033
1037
|
const [revision, setRevision] = (0, import_react4.useState)(0);
|
|
1034
1038
|
const [refreshing, setRefreshing] = (0, import_react4.useState)(false);
|
|
1035
1039
|
const refresh = (0, import_react4.useCallback)(() => {
|
|
@@ -1038,7 +1042,7 @@ function usePageResource(read) {
|
|
|
1038
1042
|
(0, import_react4.useEffect)(() => {
|
|
1039
1043
|
if (!read) {
|
|
1040
1044
|
setData(null);
|
|
1041
|
-
setError(
|
|
1045
|
+
setError(null);
|
|
1042
1046
|
return;
|
|
1043
1047
|
}
|
|
1044
1048
|
const controller = new AbortController();
|
|
@@ -1049,10 +1053,10 @@ function usePageResource(read) {
|
|
|
1049
1053
|
const result = await read(signal, revision > 0);
|
|
1050
1054
|
if (!signal.aborted) {
|
|
1051
1055
|
setData(result);
|
|
1052
|
-
setError(
|
|
1056
|
+
setError(null);
|
|
1053
1057
|
}
|
|
1054
|
-
} catch {
|
|
1055
|
-
if (!signal.aborted) setError(
|
|
1058
|
+
} catch (failure) {
|
|
1059
|
+
if (!signal.aborted) setError(typeof failure?.message === "string" ? failure.message : "");
|
|
1056
1060
|
} finally {
|
|
1057
1061
|
if (!signal.aborted) setRefreshing(false);
|
|
1058
1062
|
}
|
|
@@ -1143,14 +1147,14 @@ function PluginVersion({ ctx, t, data, loginFooter = false }) {
|
|
|
1143
1147
|
hasUpdate && fallback && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { role: "status", children: t("pluginDetailsFallback") })
|
|
1144
1148
|
] });
|
|
1145
1149
|
}
|
|
1146
|
-
function WorkspaceBody({ t, language, state
|
|
1150
|
+
function WorkspaceBody({ t, language, state }) {
|
|
1147
1151
|
const { connection, pending, run } = state;
|
|
1148
|
-
const authorized = connection.status === "connected" && connection.sharing
|
|
1152
|
+
const authorized = connection.status === "connected" && connection.sharing;
|
|
1149
1153
|
const profileId = connection?.profileId;
|
|
1150
1154
|
const loadModels = (0, import_react4.useCallback)((signal, force) => readModels(profileId, signal, force), [profileId]);
|
|
1151
1155
|
const models = usePageResource(authorized && profileId ? loadModels : null);
|
|
1152
1156
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cg-dashboard", children: [
|
|
1153
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Account, { t, state
|
|
1157
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Account, { t, state }),
|
|
1154
1158
|
authorized && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1155
1159
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ModelCatalog, { t, language, resource: models, profileId }),
|
|
1156
1160
|
connection.features?.webSearch && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("details", { className: "cg-legacy-defaults", children: [
|
|
@@ -1166,35 +1170,55 @@ function WorkspaceBody({ t, language, state, adding }) {
|
|
|
1166
1170
|
function ChatGPTPage({ ctx, t, updates }) {
|
|
1167
1171
|
const titleId = (0, import_react4.useId)();
|
|
1168
1172
|
const state = useConnection();
|
|
1169
|
-
const { connection, pending } = state;
|
|
1170
|
-
const
|
|
1173
|
+
const { connection, pending, error, run, dismissError } = state;
|
|
1174
|
+
const authorizing = connection?.addingAccount || isAccountDialogAction(pending);
|
|
1175
|
+
const dialogError = isAccountDialogAction(error?.action) ? error : null;
|
|
1176
|
+
const dialogOpen = Boolean(authorizing || dialogError);
|
|
1177
|
+
function closeDialog() {
|
|
1178
|
+
if (authorizing) {
|
|
1179
|
+
if (pending !== "cancel-add") void run("cancel-add");
|
|
1180
|
+
} else dismissError();
|
|
1181
|
+
}
|
|
1171
1182
|
const connectedProfile = connection?.profiles?.some((profile) => profile.id === connection.profileId && profile.status === "connected" && !profile.pending);
|
|
1172
|
-
const signedIn = connection?.available && (connection.status === "connected" ||
|
|
1183
|
+
const signedIn = connection?.available && (connection.status === "connected" || connection.status === "connecting" && connectedProfile);
|
|
1173
1184
|
const version = (0, import_react4.useSyncExternalStore)(updates.subscribe, updates.getSnapshot);
|
|
1174
1185
|
const language = (ctx.locale.getSnapshot?.().active || document.documentElement.lang || "zh").startsWith("en") ? "en" : "zh";
|
|
1175
1186
|
(0, import_react4.useEffect)(updates.refresh, [updates]);
|
|
1176
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.
|
|
1177
|
-
|
|
1178
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
1179
|
-
|
|
1180
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
1181
|
-
|
|
1182
|
-
"
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1187
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "dsh-use-chatgpt-page", "aria-label": signedIn ? void 0 : t("title"), "aria-labelledby": signedIn ? titleId : void 0, children: [
|
|
1188
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: signedIn ? "dsh-use-chatgpt-content" : "cg-login-layout", inert: dialogOpen ? "" : void 0, children: [
|
|
1189
|
+
signedIn && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: "dsh-use-chatgpt-header", children: [
|
|
1190
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { id: titleId, children: t("title") }),
|
|
1191
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cg-header-links", children: [
|
|
1192
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PluginVersion, { ctx, t, data: version }),
|
|
1193
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives3.Tooltip, { label: t("viewProject"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1194
|
+
"a",
|
|
1195
|
+
{
|
|
1196
|
+
className: "cg-project-link",
|
|
1197
|
+
href: "https://github.com/houyanchao/dsh-use-chatgpt",
|
|
1198
|
+
target: "_blank",
|
|
1199
|
+
rel: "noopener noreferrer",
|
|
1200
|
+
"aria-label": t("viewProject"),
|
|
1201
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 16 16", fill: "currentColor", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z" }) })
|
|
1202
|
+
}
|
|
1203
|
+
) })
|
|
1204
|
+
] }),
|
|
1205
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: t("subtitle") })
|
|
1192
1206
|
] }),
|
|
1193
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1207
|
+
signedIn ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(WorkspaceBody, { t, language, state }, connection.profileId) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LoginScreen, { t, state }),
|
|
1208
|
+
!signedIn && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PluginVersion, { ctx, t, data: version, loginFooter: true })
|
|
1194
1209
|
] }),
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1210
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1211
|
+
import_dsh_client_ui_primitives3.Modal,
|
|
1212
|
+
{
|
|
1213
|
+
open: dialogOpen,
|
|
1214
|
+
title: t(dialogError ? "authorizationFailed" : "browserTitle"),
|
|
1215
|
+
description: dialogError ? dialogError.message || t("requestFailed") : t("authorizeHint"),
|
|
1216
|
+
closeLabel: t(authorizing ? "cancel" : "close"),
|
|
1217
|
+
onClose: closeDialog,
|
|
1218
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives3.Button, { variant: "outline", autoFocus: true, disabled: pending === "cancel-add", onClick: closeDialog, children: t(authorizing ? "cancel" : "close") })
|
|
1219
|
+
}
|
|
1220
|
+
)
|
|
1221
|
+
] });
|
|
1198
1222
|
}
|
|
1199
1223
|
function SidebarIcon({ size = 16 }) {
|
|
1200
1224
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChatGPTMark, { size });
|
package/dist/index.js
CHANGED
|
@@ -24561,23 +24561,27 @@ var AccountStore = class {
|
|
|
24561
24561
|
async #load(save) {
|
|
24562
24562
|
const record = await readRecord(join(this.directory, authFile));
|
|
24563
24563
|
if (record === void 0) return newState();
|
|
24564
|
+
let state2 = record;
|
|
24564
24565
|
if (record?.version === 3) {
|
|
24565
24566
|
if (record.provider !== this.encryption.id) throw new ChatGPTError("storage_provider_mismatch", "\u8BF7\u4F7F\u7528\u4FDD\u5B58\u8FD9\u4E9B\u51ED\u636E\u7684\u7CFB\u7EDF\u52A0\u5BC6\u670D\u52A1\u3002");
|
|
24566
24567
|
await this.#requireEncryption();
|
|
24567
24568
|
try {
|
|
24568
24569
|
const bytes = Buffer.from(record.ciphertext, "base64");
|
|
24569
24570
|
if (!bytes.length || bytes.toString("base64") !== record.ciphertext) throw invalid2();
|
|
24570
|
-
|
|
24571
|
+
state2 = checkState(JSON.parse(await this.encryption.decrypt(bytes)));
|
|
24571
24572
|
} catch {
|
|
24572
24573
|
throw new ChatGPTError("storage_decryption_failed", "\u65E0\u6CD5\u89E3\u5BC6\u73B0\u6709\u51ED\u636E\u3002\u8BF7\u68C0\u67E5\u94A5\u5319\u4E32\u6216 Windows \u7528\u6237\u540E\u91CD\u8BD5\u3002", true);
|
|
24573
24574
|
}
|
|
24575
|
+
if (!state2.profiles.some((profile) => profile.status === "disconnected")) return state2;
|
|
24576
|
+
} else {
|
|
24577
|
+
if (record?.version === 1) {
|
|
24578
|
+
const id = randomUUID();
|
|
24579
|
+
state2 = { ...newState(), activeProfileId: id, profiles: [{ ...record, id, label: "Connection 1", requiresNewRegistration: true }] };
|
|
24580
|
+
}
|
|
24581
|
+
checkState(state2);
|
|
24574
24582
|
}
|
|
24575
|
-
|
|
24576
|
-
if (
|
|
24577
|
-
const id = randomUUID();
|
|
24578
|
-
state2 = { ...newState(), activeProfileId: id, profiles: [{ ...record, id, label: "Connection 1", requiresNewRegistration: true }] };
|
|
24579
|
-
}
|
|
24580
|
-
checkState(state2);
|
|
24583
|
+
state2.profiles = state2.profiles.filter((profile) => profile.status !== "disconnected");
|
|
24584
|
+
if (!state2.profiles.some((profile) => profile.id === state2.activeProfileId)) delete state2.activeProfileId;
|
|
24581
24585
|
await save(state2);
|
|
24582
24586
|
return state2;
|
|
24583
24587
|
}
|
|
@@ -24593,6 +24597,9 @@ var cancelled2 = () => new ChatGPTError("cancelled", "\u64CD\u4F5C\u5DF2\u53D6\u
|
|
|
24593
24597
|
var missingAccount = () => new ChatGPTError("profile_not_found", "\u627E\u4E0D\u5230\u9009\u5B9A\u7684\u8D26\u53F7\u3002");
|
|
24594
24598
|
var connected = (profile) => profile?.status === "connected" && Boolean(profile.credentials);
|
|
24595
24599
|
var sharing = (profile) => connected(profile) && profile.scopes.includes(planScope2);
|
|
24600
|
+
function isAddingAccount(session, options) {
|
|
24601
|
+
return session?.status === "connected" && Boolean(session.profileId) && !options.reconsent && (options.newProfile === true || Boolean(options.profileId) && options.profileId !== session.profileId);
|
|
24602
|
+
}
|
|
24596
24603
|
function publicIdentity(identity2) {
|
|
24597
24604
|
if (!identity2) return {};
|
|
24598
24605
|
const fields = {};
|
|
@@ -24613,11 +24620,11 @@ function sessionFor(state2) {
|
|
|
24613
24620
|
...profile.pendingRefresh ? { error: identityVerificationUnavailable().toJSON() } : {}
|
|
24614
24621
|
};
|
|
24615
24622
|
}
|
|
24616
|
-
function
|
|
24623
|
+
function requireNewSignIn(profile) {
|
|
24617
24624
|
delete profile.credentials;
|
|
24618
24625
|
delete profile.profileIdToken;
|
|
24619
24626
|
delete profile.pendingRefresh;
|
|
24620
|
-
Object.assign(profile, { status, scopes: [], savedAt: now() });
|
|
24627
|
+
Object.assign(profile, { status: "reauth_required", scopes: [], savedAt: now() });
|
|
24621
24628
|
}
|
|
24622
24629
|
function availableLabel(state2, requested) {
|
|
24623
24630
|
const labels = new Set([...state2.profiles, ...state2.pendingRegistrations].map((profile) => profile.label));
|
|
@@ -24657,14 +24664,17 @@ function createChatGPT(config) {
|
|
|
24657
24664
|
return structuredClone(session);
|
|
24658
24665
|
}
|
|
24659
24666
|
function idle({ modelRequest = false } = {}) {
|
|
24660
|
-
|
|
24667
|
+
const loginBlocksRequest = login && (!modelRequest || !login.addingAccount);
|
|
24668
|
+
if (updating || loginBlocksRequest || signingOutProfile && !modelRequest) {
|
|
24669
|
+
throw new ChatGPTError("connection_busy", "\u8BF7\u5148\u5B8C\u6210\u5F53\u524D\u7684\u8D26\u53F7\u64CD\u4F5C\u3002");
|
|
24670
|
+
}
|
|
24661
24671
|
}
|
|
24662
24672
|
function invalidate() {
|
|
24663
24673
|
generation.abort();
|
|
24664
24674
|
generation = new AbortController();
|
|
24665
24675
|
}
|
|
24666
24676
|
async function getSession() {
|
|
24667
|
-
if (updating || login) return structuredClone(displayed);
|
|
24677
|
+
if (updating || login && !login.addingAccount) return structuredClone(displayed);
|
|
24668
24678
|
const beforeRead = generation;
|
|
24669
24679
|
try {
|
|
24670
24680
|
const latest = await store.transaction(({ state: state2 }) => sessionFor(state2));
|
|
@@ -24698,7 +24708,7 @@ function createChatGPT(config) {
|
|
|
24698
24708
|
} catch (error) {
|
|
24699
24709
|
const typed = asError(error);
|
|
24700
24710
|
if (requiresReauthentication(typed) || ["invalid_id_token", "invalid_token_response", "account_mismatch"].includes(typed.code)) {
|
|
24701
|
-
|
|
24711
|
+
requireNewSignIn(profile);
|
|
24702
24712
|
await save();
|
|
24703
24713
|
}
|
|
24704
24714
|
throw typed;
|
|
@@ -24724,13 +24734,18 @@ function createChatGPT(config) {
|
|
|
24724
24734
|
async function signIn(options = {}) {
|
|
24725
24735
|
idle();
|
|
24726
24736
|
if (options.newProfile && options.profileId) throw new ChatGPTError("invalid_profile", "\u8BF7\u6307\u5B9A\u4E00\u4E2A\u767B\u5F55\u65B9\u5F0F\u3002");
|
|
24727
|
-
|
|
24728
|
-
const
|
|
24737
|
+
const addingAccount = isAddingAccount(displayed, options);
|
|
24738
|
+
const sourceProfileId = displayed.profileId;
|
|
24739
|
+
const attempt = { controller: new AbortController(), addingAccount };
|
|
24729
24740
|
login = attempt;
|
|
24730
|
-
const
|
|
24741
|
+
const timeout = AbortSignal.timeout(6e4);
|
|
24742
|
+
const signals = [attempt.controller.signal, timeout];
|
|
24731
24743
|
if (options.signal) signals.push(options.signal);
|
|
24732
24744
|
const signal = AbortSignal.any(signals);
|
|
24733
|
-
|
|
24745
|
+
if (!addingAccount) {
|
|
24746
|
+
invalidate();
|
|
24747
|
+
publish({ ...displayed, status: "connecting", sharing: false, error: void 0 });
|
|
24748
|
+
}
|
|
24734
24749
|
try {
|
|
24735
24750
|
let inspect = function(state2) {
|
|
24736
24751
|
signal.throwIfAborted();
|
|
@@ -24744,6 +24759,7 @@ function createChatGPT(config) {
|
|
|
24744
24759
|
const pending = state2.pendingRegistrations.find((item) => item.id === id);
|
|
24745
24760
|
if (options.profileId && !profile && !pending) throw missingAccount();
|
|
24746
24761
|
if (profile?.requiresNewRegistration) throw new ChatGPTError("registration_upgrade_required", "\u8BF7\u6DFB\u52A0\u8D26\u53F7\u4EE5\u5B8C\u6210\u65B0\u7248\u672C\u6388\u6743\u3002");
|
|
24762
|
+
if (addingAccount && state2.activeProfileId !== sourceProfileId) throw changed();
|
|
24747
24763
|
return { id, profile, pending, activeId: state2.activeProfileId, host: await hostId() };
|
|
24748
24764
|
}, signal);
|
|
24749
24765
|
let previous = original.profile ?? original.pending;
|
|
@@ -24769,7 +24785,7 @@ function createChatGPT(config) {
|
|
|
24769
24785
|
previous ??= { clientId: registeredClientId };
|
|
24770
24786
|
verified = await interact();
|
|
24771
24787
|
}
|
|
24772
|
-
|
|
24788
|
+
return await store.transaction(async ({ state: state2, save }) => {
|
|
24773
24789
|
const { profile, pending } = inspect(state2);
|
|
24774
24790
|
if ((profile ?? pending)?.clientId !== verified.clientId) throw changed();
|
|
24775
24791
|
const completed = { ...verified, id: original.id, label: (profile ?? pending).label };
|
|
@@ -24778,14 +24794,18 @@ function createChatGPT(config) {
|
|
|
24778
24794
|
state2.pendingRegistrations = state2.pendingRegistrations.filter((item) => item.id !== original.id);
|
|
24779
24795
|
state2.activeProfileId = original.id;
|
|
24780
24796
|
await save();
|
|
24781
|
-
|
|
24797
|
+
if (addingAccount) invalidate();
|
|
24798
|
+
return publish(sessionFor(state2));
|
|
24782
24799
|
}, signal);
|
|
24783
|
-
signal.throwIfAborted();
|
|
24784
|
-
return publish(session);
|
|
24785
24800
|
} catch (error) {
|
|
24786
|
-
|
|
24801
|
+
let failure = asError(error);
|
|
24802
|
+
if (signal.aborted) {
|
|
24803
|
+
failure = timeout.aborted && signal.reason === timeout.reason ? new ChatGPTError("authorization_timeout", "\u6388\u6743\u5DF2\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5\u3002", true) : cancelled2();
|
|
24804
|
+
}
|
|
24787
24805
|
const restored = await store.transaction(({ state: state2 }) => sessionFor(state2)).catch(() => disconnected());
|
|
24788
|
-
if (login === attempt && !updating)
|
|
24806
|
+
if (login === attempt && !updating) {
|
|
24807
|
+
publish(addingAccount || failure.code === "cancelled" ? restored : { ...restored, error: failure.toJSON() });
|
|
24808
|
+
}
|
|
24789
24809
|
throw failure;
|
|
24790
24810
|
} finally {
|
|
24791
24811
|
if (login === attempt) login = void 0;
|
|
@@ -24812,7 +24832,7 @@ function createChatGPT(config) {
|
|
|
24812
24832
|
signingOutProfile = profileId;
|
|
24813
24833
|
updating = !profileId || profileId === displayed.profileId;
|
|
24814
24834
|
if (updating) invalidate();
|
|
24815
|
-
if (!profileId) login?.abort();
|
|
24835
|
+
if (!profileId) login?.controller.abort();
|
|
24816
24836
|
try {
|
|
24817
24837
|
const { session, revocation } = await store.transaction(async ({ state: state2, save }) => {
|
|
24818
24838
|
const profile = profileId ? state2.profiles.find((item) => item.id === profileId) : active(state2);
|
|
@@ -24832,10 +24852,10 @@ function createChatGPT(config) {
|
|
|
24832
24852
|
revocation2 = new ChatGPTError("revocation_failed", "\u672C\u673A\u5DF2\u9000\u51FA\uFF0C\u672A\u786E\u8BA4\u8FDC\u7AEF\u64A4\u9500\u3002\u53EF\u524D\u5F80 ChatGPT \u8BBE\u7F6E\u65AD\u5F00\u6B64\u5E94\u7528\u3002", true);
|
|
24833
24853
|
}
|
|
24834
24854
|
}
|
|
24835
|
-
|
|
24836
|
-
if (
|
|
24837
|
-
const next = state2.profiles.find(sharing) ?? state2.profiles.find(connected);
|
|
24838
|
-
|
|
24855
|
+
state2.profiles = state2.profiles.filter((item) => item.id !== profile.id);
|
|
24856
|
+
if (profile.id === state2.activeProfileId) {
|
|
24857
|
+
const next = chooseNext ? state2.profiles.find(sharing) ?? state2.profiles.find(connected) : void 0;
|
|
24858
|
+
state2.activeProfileId = next?.id;
|
|
24839
24859
|
}
|
|
24840
24860
|
await save();
|
|
24841
24861
|
}
|
|
@@ -24860,7 +24880,7 @@ function createChatGPT(config) {
|
|
|
24860
24880
|
await endConnection({ profileId });
|
|
24861
24881
|
},
|
|
24862
24882
|
cancelSignIn() {
|
|
24863
|
-
login?.abort();
|
|
24883
|
+
login?.controller.abort();
|
|
24864
24884
|
},
|
|
24865
24885
|
listProfiles() {
|
|
24866
24886
|
return store.transaction(({ state: state2 }) => [
|
|
@@ -25427,6 +25447,13 @@ function createProvider(client, getSession, lifetime, {
|
|
|
25427
25447
|
const entries = await loadModels(session, false);
|
|
25428
25448
|
return entries.find((entry) => entry.id === model) ?? modelInfo(model);
|
|
25429
25449
|
}
|
|
25450
|
+
async function listVisibleModels(session) {
|
|
25451
|
+
const models = await loadModels(session, false);
|
|
25452
|
+
session.accountSignal?.throwIfAborted();
|
|
25453
|
+
if (!session.profileId || models.length === 0) return models;
|
|
25454
|
+
const hidden = getHiddenModels(session.profileId);
|
|
25455
|
+
return models.filter((model) => !hidden.has(model.id));
|
|
25456
|
+
}
|
|
25430
25457
|
return {
|
|
25431
25458
|
providerInfo: (id) => ({ id, name: "ChatGPT \u5957\u9910" }),
|
|
25432
25459
|
providerRetryPolicy: () => void 0,
|
|
@@ -25438,11 +25465,17 @@ function createProvider(client, getSession, lifetime, {
|
|
|
25438
25465
|
}),
|
|
25439
25466
|
async listModels() {
|
|
25440
25467
|
const session = await getSession();
|
|
25441
|
-
|
|
25442
|
-
|
|
25443
|
-
|
|
25444
|
-
|
|
25445
|
-
|
|
25468
|
+
try {
|
|
25469
|
+
return await listVisibleModels(session);
|
|
25470
|
+
} catch (error) {
|
|
25471
|
+
if (error?.code !== "network_error") throw error;
|
|
25472
|
+
lifetime.throwIfAborted();
|
|
25473
|
+
session.accountSignal?.throwIfAborted();
|
|
25474
|
+
return [];
|
|
25475
|
+
}
|
|
25476
|
+
},
|
|
25477
|
+
async listSelectableModels() {
|
|
25478
|
+
return listVisibleModels(await getSession());
|
|
25446
25479
|
},
|
|
25447
25480
|
async listPlanModels(force = false) {
|
|
25448
25481
|
return loadModels(await getSession(), force);
|
|
@@ -25660,7 +25693,8 @@ async function modelCatalog({ adapter, getSession, usageStore, onCatalogChange }
|
|
|
25660
25693
|
if (writing && (!body || typeof body !== "object" || Array.isArray(body) || Object.keys(body).some((key) => !["profileId", "model", "enabled"].includes(key)) || typeof body.profileId !== "string" || typeof body.model !== "string" || !body.model.length || typeof body.enabled !== "boolean")) return fail("\u65E0\u6548\u7684\u6A21\u578B\u663E\u793A\u8BBE\u7F6E\u3002", 400);
|
|
25661
25694
|
const expected = writing ? body.profileId : params.get("profileId");
|
|
25662
25695
|
if (expected !== null && expected !== profileId) return fail("\u5F53\u524D ChatGPT \u8D26\u53F7\u5DF2\u66F4\u6539\uFF0C\u8BF7\u5237\u65B0\u91CD\u8BD5\u3002", 409);
|
|
25663
|
-
const
|
|
25696
|
+
const refreshing = !writing && params.get("refresh") === "1";
|
|
25697
|
+
const models = await adapter.listPlanModels(refreshing);
|
|
25664
25698
|
const current = await getSession();
|
|
25665
25699
|
request.signal?.throwIfAborted();
|
|
25666
25700
|
accountSignal?.throwIfAborted();
|
|
@@ -25674,6 +25708,7 @@ async function modelCatalog({ adapter, getSession, usageStore, onCatalogChange }
|
|
|
25674
25708
|
return json({ model: body.model, enabled: body.enabled });
|
|
25675
25709
|
}
|
|
25676
25710
|
const hidden = usageStore.hiddenModels(profileId);
|
|
25711
|
+
if (refreshing) onCatalogChange();
|
|
25677
25712
|
return json({ models: models.map((model) => ({ ...model, enabled: !hidden.has(model.id) })) });
|
|
25678
25713
|
}
|
|
25679
25714
|
async function selectChatModel(ctx, { adapter, getSession, usageStore }, request, session) {
|
|
@@ -25689,7 +25724,7 @@ async function selectChatModel(ctx, { adapter, getSession, usageStore }, request
|
|
|
25689
25724
|
const agents = ctx.get?.("agents");
|
|
25690
25725
|
const agent = agents?.get(sessionId);
|
|
25691
25726
|
if (!agent) return fail("DSH \u4F1A\u8BDD\u672A\u6253\u5F00\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u4F1A\u8BDD\u3002", 409);
|
|
25692
|
-
const available = (await adapter.
|
|
25727
|
+
const available = (await adapter.listSelectableModels()).find((entry) => entry.id === model);
|
|
25693
25728
|
signal.throwIfAborted();
|
|
25694
25729
|
if (!available || reasoningEffort !== void 0 && !available.reasoning?.efforts.some((effort) => effort.id === reasoningEffort)) {
|
|
25695
25730
|
return fail("\u5F53\u524D ChatGPT \u8D26\u53F7\u4E0D\u652F\u6301\u6B64\u6A21\u578B\u6216\u63A8\u7406\u5F3A\u5EA6\u3002", 400);
|
|
@@ -26158,7 +26193,7 @@ function createPreferences(storageDir) {
|
|
|
26158
26193
|
// package.json
|
|
26159
26194
|
var package_default = {
|
|
26160
26195
|
name: "dsh-use-chatgpt",
|
|
26161
|
-
version: "1.0.
|
|
26196
|
+
version: "1.0.1",
|
|
26162
26197
|
description: "ChatGPT plan model provider for a local DeepSeek Harness desktop instance",
|
|
26163
26198
|
type: "module",
|
|
26164
26199
|
engines: { node: "^22.19.0 || >=24.0.0" },
|
|
@@ -26172,7 +26207,7 @@ var package_default = {
|
|
|
26172
26207
|
"./client": "./dist/client.js",
|
|
26173
26208
|
"./package.json": "./package.json"
|
|
26174
26209
|
},
|
|
26175
|
-
files: ["dist", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
26210
|
+
files: ["dist", "docs/images/chatgpt-settings.png", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
26176
26211
|
dsh: {
|
|
26177
26212
|
bundle: { patch: "./cordis.patch.yml" },
|
|
26178
26213
|
client: {
|
|
@@ -26360,16 +26395,23 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26360
26395
|
function locallySignedOut(profileId) {
|
|
26361
26396
|
return signedOutUnknownProfile || signedOutProfiles.has(profileId);
|
|
26362
26397
|
}
|
|
26398
|
+
function accountBlocked() {
|
|
26399
|
+
return transition && !transition.preparing && !transition.addingAccount;
|
|
26400
|
+
}
|
|
26401
|
+
function invalidateAccount() {
|
|
26402
|
+
account.abort();
|
|
26403
|
+
account = new AbortController();
|
|
26404
|
+
}
|
|
26363
26405
|
function visibleSession(current) {
|
|
26364
26406
|
if (!available || disposed) return disconnected2;
|
|
26365
26407
|
if (transition?.kind === "disconnect") return { ...current, ...disconnected2 };
|
|
26366
|
-
if (
|
|
26408
|
+
if (accountBlocked()) return { ...current, status: "connecting", sharing: false, error: void 0 };
|
|
26367
26409
|
if (locallySignedOut(current.profileId)) return { ...current, ...disconnected2 };
|
|
26368
26410
|
return current;
|
|
26369
26411
|
}
|
|
26370
26412
|
async function getSession() {
|
|
26371
26413
|
const { signal: accountSignal } = account;
|
|
26372
|
-
if (available && !disposed && !
|
|
26414
|
+
if (available && !disposed && !accountBlocked()) {
|
|
26373
26415
|
const current = await client.getSession();
|
|
26374
26416
|
if (accountSignal.aborted) return { ...disconnected2, accountSignal };
|
|
26375
26417
|
session = current;
|
|
@@ -26398,6 +26440,9 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26398
26440
|
registration.replace(next === void 0 ? [] : [providerId]);
|
|
26399
26441
|
}
|
|
26400
26442
|
const unsubscribe = client.subscribe((current) => {
|
|
26443
|
+
if (transition?.addingAccount && session.profileId !== current.profileId) {
|
|
26444
|
+
invalidateAccount();
|
|
26445
|
+
}
|
|
26401
26446
|
session = current;
|
|
26402
26447
|
refreshCatalog(current);
|
|
26403
26448
|
});
|
|
@@ -26414,9 +26459,8 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26414
26459
|
if (signingOutProfile || previous && !(kind === "disconnect" && previous.kind === "sign-in")) {
|
|
26415
26460
|
throw pluginError("connection_busy", "\u8BF7\u5148\u5B8C\u6210\u6216\u53D6\u6D88\u5F53\u524D\u8D26\u53F7\u64CD\u4F5C\u3002");
|
|
26416
26461
|
}
|
|
26417
|
-
transition = { kind };
|
|
26418
|
-
|
|
26419
|
-
account = new AbortController();
|
|
26462
|
+
transition = { kind, preparing: kind === "sign-in" };
|
|
26463
|
+
if (accountBlocked()) invalidateAccount();
|
|
26420
26464
|
refreshCatalog(session);
|
|
26421
26465
|
return { current: transition, previous };
|
|
26422
26466
|
}
|
|
@@ -26426,17 +26470,26 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26426
26470
|
refreshCatalog(session);
|
|
26427
26471
|
}
|
|
26428
26472
|
async function signIn(request, reconsent) {
|
|
26429
|
-
|
|
26430
|
-
const source = !reconsent && (options.newProfile || options.profileId) ? await getSession() : void 0;
|
|
26431
|
-
if (source?.accountSignal.aborted) throw pluginError("connection_busy", "\u8D26\u53F7\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
26473
|
+
request.signal.throwIfAborted();
|
|
26432
26474
|
const { current: attempt } = beginTransition("sign-in");
|
|
26433
|
-
if (source?.status === "connected" && source.profileId && source.profileId !== options.profileId) {
|
|
26434
|
-
attempt.addingFrom = source;
|
|
26435
|
-
}
|
|
26436
26475
|
const controller = new AbortController();
|
|
26437
|
-
const signal = AbortSignal.any([controller.signal, request.signal, lifetime.signal]);
|
|
26438
26476
|
attempt.controller = controller;
|
|
26439
26477
|
attempt.promise = (async () => {
|
|
26478
|
+
const options = await profileInput(request, { allowNew: !reconsent });
|
|
26479
|
+
controller.signal.throwIfAborted();
|
|
26480
|
+
const source = !reconsent && (options.newProfile || options.profileId) ? await getSession() : void 0;
|
|
26481
|
+
controller.signal.throwIfAborted();
|
|
26482
|
+
if (source?.accountSignal.aborted) throw pluginError("connection_busy", "\u8D26\u53F7\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u8BD5\u3002");
|
|
26483
|
+
attempt.addingAccount = isAddingAccount(source, options);
|
|
26484
|
+
attempt.preparing = false;
|
|
26485
|
+
if (!attempt.addingAccount) {
|
|
26486
|
+
invalidateAccount();
|
|
26487
|
+
refreshCatalog(session);
|
|
26488
|
+
}
|
|
26489
|
+
const signals = [controller.signal, lifetime.signal];
|
|
26490
|
+
if (!attempt.addingAccount) signals.push(request.signal);
|
|
26491
|
+
const signal = AbortSignal.any(signals);
|
|
26492
|
+
signal.throwIfAborted();
|
|
26440
26493
|
if (!await credentialEncryption.isAvailable()) {
|
|
26441
26494
|
throw pluginError("storage_encryption_unavailable", "\u65E0\u6CD5\u8BBF\u95EE\u7CFB\u7EDF\u51ED\u636E\u5B58\u50A8\uFF0C\u8BF7\u68C0\u67E5\u5F53\u524D\u7CFB\u7EDF\u8D26\u53F7\u540E\u91CD\u8BD5\u3002");
|
|
26442
26495
|
}
|
|
@@ -26444,7 +26497,6 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26444
26497
|
session = await client.signIn({ ...options, signal, reconsent });
|
|
26445
26498
|
signedOutUnknownProfile = false;
|
|
26446
26499
|
signedOutProfiles.delete(session.profileId);
|
|
26447
|
-
signal.throwIfAborted();
|
|
26448
26500
|
})();
|
|
26449
26501
|
try {
|
|
26450
26502
|
await attempt.promise;
|
|
@@ -26455,7 +26507,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26455
26507
|
async function cancel() {
|
|
26456
26508
|
const attempt = transition;
|
|
26457
26509
|
if (attempt?.kind === "sign-in") {
|
|
26458
|
-
attempt.controller.abort();
|
|
26510
|
+
attempt.controller.abort(pluginError("cancelled", "\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
|
|
26459
26511
|
await attempt.promise.catch(() => void 0);
|
|
26460
26512
|
}
|
|
26461
26513
|
}
|
|
@@ -26475,7 +26527,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26475
26527
|
const { current, previous } = beginTransition("disconnect");
|
|
26476
26528
|
try {
|
|
26477
26529
|
if (previous) {
|
|
26478
|
-
previous.controller.abort();
|
|
26530
|
+
previous.controller.abort(pluginError("cancelled", "\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
|
|
26479
26531
|
await previous.promise.catch(() => void 0);
|
|
26480
26532
|
}
|
|
26481
26533
|
await client.disconnect({ expectedProfileId: profileId });
|
|
@@ -26499,8 +26551,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26499
26551
|
const alreadySignedOut = signedOutProfiles.has(profileId);
|
|
26500
26552
|
signedOutProfiles.add(profileId);
|
|
26501
26553
|
if (session.profileId === profileId) {
|
|
26502
|
-
|
|
26503
|
-
account = new AbortController();
|
|
26554
|
+
invalidateAccount();
|
|
26504
26555
|
refreshCatalog(session);
|
|
26505
26556
|
}
|
|
26506
26557
|
try {
|
|
@@ -26530,8 +26581,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26530
26581
|
const current = await getSession();
|
|
26531
26582
|
const saved = available && !disposed ? await client.listProfiles().catch(() => []) : [];
|
|
26532
26583
|
if (!disposed && (current.accountSignal.aborted || pending !== transition)) continue;
|
|
26533
|
-
const { status, sharing: sharing2, error } = current;
|
|
26534
|
-
const { identity: identity2, profileId, profileLabel } = pending?.addingFrom ?? current;
|
|
26584
|
+
const { status, sharing: sharing2, error, identity: identity2, profileId, profileLabel } = current;
|
|
26535
26585
|
const profiles = saved.map((profile) => {
|
|
26536
26586
|
const signedOut = locallySignedOut(profile.id);
|
|
26537
26587
|
return {
|
|
@@ -26544,7 +26594,7 @@ function mountChatGPT(ctx, { client, available, credentialEncryption, preference
|
|
|
26544
26594
|
requiresNewRegistration: profile.requiresNewRegistration
|
|
26545
26595
|
};
|
|
26546
26596
|
});
|
|
26547
|
-
return { status, sharing: sharing2, available, addingAccount: Boolean(pending?.
|
|
26597
|
+
return { status, sharing: sharing2, available, addingAccount: Boolean(pending?.addingAccount), identity: publicIdentity2(identity2), profileId, profileLabel, profiles, features, error: error ? publicError(error) : void 0 };
|
|
26548
26598
|
}
|
|
26549
26599
|
}
|
|
26550
26600
|
const actions = {
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-use-chatgpt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "ChatGPT plan model provider for a local DeepSeek Harness desktop instance",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": { "node": "^22.19.0 || >=24.0.0" },
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"./client": "./dist/client.js",
|
|
15
15
|
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
|
-
"files": ["dist", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
17
|
+
"files": ["dist", "docs/images/chatgpt-settings.png", "native/credential-key", "native/credential-key-universal", "cordis.patch.yml"],
|
|
18
18
|
"dsh": {
|
|
19
19
|
"bundle": { "patch": "./cordis.patch.yml" },
|
|
20
20
|
"client": {
|