dsh-github-studio 0.6.6 → 0.7.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 +39 -11
- package/lib/client.js +41 -6
- package/lib/core.js +4 -3
- package/lib/core.mjs +4 -3
- package/lib/credential-store.js +174 -0
- package/lib/credential-store.mjs +174 -0
- package/lib/diagnostics.js +2 -2
- package/lib/diagnostics.mjs +2 -2
- package/lib/dsh-go.js +148 -0
- package/lib/dsh-go.mjs +148 -0
- package/lib/gh.js +104 -12
- package/lib/gh.mjs +104 -12
- package/lib/http.js +2 -1
- package/lib/http.mjs +2 -1
- package/lib/index.js +9 -2
- package/lib/network.js +32 -0
- package/lib/network.mjs +32 -0
- package/lib/oauth-setup.js +2 -0
- package/lib/oauth-setup.mjs +2 -0
- package/package.json +23 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**面向 DeepSeek Harness 的 GitHub 连接与发布插件。** 在聊天中读取项目、准备代码提交,在设置页管理仓库、生成项目介绍并发布程序版本。
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> 面向 Windows 和 macOS 上的 DeepSeek Harness,以及 Android 版 DSH Go 的第三方开源插件。
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
@@ -16,7 +16,7 @@ DeepSeek GitHub Studio 将 GitHub 仓库操作集成到 Harness 的工具调用
|
|
|
16
16
|
|
|
17
17
|
| 模块 | 能力 |
|
|
18
18
|
| --- | --- |
|
|
19
|
-
| GitHub 连接 | OAuth Device Flow
|
|
19
|
+
| GitHub 连接 | OAuth Device Flow 登录和自动续期,使用 Windows DPAPI、macOS 钥匙串或 DSH Go 主机凭据服务 |
|
|
20
20
|
| 仓库浏览 | 浏览已授权仓库、目录和文本文件,查看版本及附件链接 |
|
|
21
21
|
| 聊天工具 | 搜索公开仓库和代码、读取文件、准备建库及提交操作 |
|
|
22
22
|
| 官网搜索 | 仓库/代码分类,高级筛选,直接在浏览器打开 GitHub 原生搜索 |
|
|
@@ -54,7 +54,7 @@ DeepSeek GitHub Studio 将 GitHub 仓库操作集成到 Harness 的工具调用
|
|
|
54
54
|
|
|
55
55
|
### 环境要求
|
|
56
56
|
|
|
57
|
-
- Windows
|
|
57
|
+
- Windows、macOS 或 Android 版 DSH Go 本机引擎。macOS 兼容 Apple Silicon 和 Intel。
|
|
58
58
|
- DeepSeek Harness。开发基线为 `0.2.2-rc.1`,其他版本的插件接口可能存在差异。
|
|
59
59
|
- 网络能访问 GitHub 登录页、`api.github.com` 和 `uploads.github.com`。
|
|
60
60
|
- 使用 AI 介绍时,需在 Harness 中配置可用默认模型。
|
|
@@ -71,7 +71,7 @@ https://github.com/zhaohaix/DeepSeek-GitHub
|
|
|
71
71
|
|
|
72
72
|
### 使用本地源码或安装包
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
也可以克隆项目后,在“添加插件”中输入本地项目目录,或选择构建好的 `.tgz`。Windows 还可在完全退出 Harness 后运行随附安装脚本。macOS 直接通过插件管理器添加安装包。
|
|
75
75
|
|
|
76
76
|
```sh
|
|
77
77
|
git clone https://github.com/zhaohaix/DeepSeek-GitHub.git
|
|
@@ -80,15 +80,29 @@ npm ci
|
|
|
80
80
|
npm run verify
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
+
### Android 版 DSH Go
|
|
84
|
+
|
|
85
|
+
先安装并启动 DSH Go 的本机引擎。将对应版本的 `.tgz` 放到手机的下载目录,在 DSH Go 设置中打开「访问手机文件」,然后在 DSH Go 的本机终端运行:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
dsh plugin --profile web add /sdcard/Download/dsh-github-studio-0.7.1.tgz
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
按提示重启引擎。可以在「全部功能 → 插件 → GitHub」打开原生面板,保存 OAuth App Client ID、获取设备码、打开授权页和查看登录状态。在 DSH Go 的「网页版 → 设置 → GitHub」可浏览仓库、生成介绍、上传附件、发布以及预览和确认写入。两个界面使用同一个登录状态。
|
|
92
|
+
|
|
93
|
+
远程使用时,插件和凭据都在所选的 Harness 主机上。SSH 和中转模式的界面能力取决于 DSH Go 的连接方式。此版适配目标是 Android 的本机引擎。
|
|
94
|
+
|
|
83
95
|
## 配置 GitHub 登录
|
|
84
96
|
|
|
85
97
|
**公开版本没有预置个人 OAuth App Client ID。** 首次登录前需配置自己的 GitHub OAuth App:
|
|
86
98
|
|
|
87
|
-
1.
|
|
88
|
-
2.
|
|
89
|
-
3.
|
|
99
|
+
1. [打开 GitHub OAuth App 注册页](https://github.com/settings/applications/new),登录自己的 GitHub 账号。
|
|
100
|
+
2. 应用名称可填 `DeepSeek GitHub Studio`。主页 URL 和重定向 URI 都填 `https://github.com/zhaohaix/DeepSeek-GitHub`。应用描述可留空,通配符保持关闭。勾选 **启用设备流(Enable Device Flow)**,再注册应用。
|
|
101
|
+
3. 将应用详情里的 **Client ID** 粘贴到插件「设置 → GitHub」并保存。已有启用了设备流的 OAuth App 可直接复用 Client ID。
|
|
90
102
|
4. 点击“登录 GitHub”,打开 GitHub 官方设备授权页,输入显示的设备代码并授权。
|
|
91
103
|
|
|
104
|
+
如果从 Windows 换到 Mac,在 Mac 上授权一次即可建立本机钥匙串凭据。若系统提示无法访问凭据,请在“钥匙串访问”中解锁登录钥匙串后重试。
|
|
105
|
+
|
|
92
106
|
此流程不要求在插件中填写 Client Secret。不要把访问令牌、Client Secret 或本机配置上传到仓库。
|
|
93
107
|
|
|
94
108
|
| 配置状态 | 可使用范围 |
|
|
@@ -125,13 +139,14 @@ npm run verify
|
|
|
125
139
|
|
|
126
140
|
## 隐私与安全边界
|
|
127
141
|
|
|
128
|
-
-
|
|
129
|
-
-
|
|
142
|
+
- 暂存文件、诊断日志和文案工作区默认保存在用户主目录下的 `.dsh/github-connect`。
|
|
143
|
+
- Windows 使用 DPAPI CurrentUser 加密本地令牌,macOS 将令牌保存到系统钥匙串。两种凭据都随系统账户隔离。
|
|
144
|
+
- Android 本机引擎使用 Harness 管理的凭据记录,由 DSH Go 的应用私有环境和文件权限保护。默认的文件型提供方没有钥匙串式加密,和引擎同一账户运行的工具可以访问这一存储。
|
|
130
145
|
- 本地 API 限定宿主浏览器身份及本机访问;本项目面向个人桌面环境,不适合作为公开多租户服务。
|
|
131
146
|
- ZIP 只读取符合限制的文本,不运行其中的程序;会跳过依赖目录、部分构建产物和明显凭据文件。启发式筛选不能保证发现所有敏感信息。
|
|
132
147
|
- AI 将所选文本发送给 Harness 配置的模型服务,生成结果需审阅,不能视为已验证的软件功能或测试结论。
|
|
133
148
|
- 若写入后网络中断,请先核实 GitHub 上的实际结果,再决定是否重新准备操作。
|
|
134
|
-
-
|
|
149
|
+
- 支持加密保存与自动续期刷新令牌;首次使用旧版凭据或授权已撤销时仍需重新登录。
|
|
135
150
|
|
|
136
151
|
## 常见问题
|
|
137
152
|
|
|
@@ -152,10 +167,23 @@ npm ci
|
|
|
152
167
|
npm run verify
|
|
153
168
|
npm run release:check
|
|
154
169
|
npm pack
|
|
155
|
-
npm run release:source
|
|
156
170
|
```
|
|
157
171
|
|
|
172
|
+
Windows 可以另运行 `npm run release:source` 生成源码 ZIP。
|
|
173
|
+
|
|
158
174
|
公开打包检查要求预置 Client ID 为空,并排除个人运行资料、日志、浏览器缓存与凭据。请勿将整个本机开发目录直接上传。欢迎通过 Issue 报告可复现问题;提交截图或日志前请去除个人信息与秘密值。
|
|
159
175
|
|
|
160
176
|
本项目使用 MIT License。第三方依赖遵循各自许可证;不附带或重新分发 DeepSeek Harness 宿主运行时。
|
|
161
177
|
|
|
178
|
+
|
|
179
|
+
## 网络不稳定与 GitHub 加速
|
|
180
|
+
|
|
181
|
+
登录的临时网络错误会自动重试;设备码有效期内轮询失败会保留设备码并退避,界面可取消本次登录。证书错误会立即给出提示,不会通过关闭 HTTPS 校验来绕过。建库、提交、发布和上传不会自动重放。
|
|
182
|
+
|
|
183
|
+
插件网络连接使用 Node 内置 CA、系统信任证书以及启动时配置的额外 CA。使用 Steam++ 等证书接管模式时,配置好系统信任后请彻底退出并重开 Harness。线路不可用时可切换线路或关闭 GitHub 加速。
|
|
184
|
+
|
|
185
|
+
如需明确指定 HTTP/HTTPS 代理,可在启动 Harness 前设置本机环境变量 `DSH_GITHUB_PROXY`(例如 `http://127.0.0.1:7890`,端口以加速器实际配置为准)。也支持 `HTTP_PROXY`、`HTTPS_PROXY`、`NO_PROXY` 及小写形式;插件专用代理优先。暂不支持 SOCKS 地址、Windows PAC 或自动发现系统代理。不要把含账号密码的代理配置提交到仓库。
|
|
186
|
+
|
|
187
|
+
自定义可信 CA 可通过启动时的 `NODE_EXTRA_CA_CERTS` 指向 PEM 文件;仅加入你确认可信的证书。修改上述启动配置后需完全重启 Harness。
|
|
188
|
+
|
|
189
|
+
新授权会申请 `repo offline_access`,在 GitHub 返回刷新令牌时加密保存并提前续期。旧版只保存访问令牌,无法补回刷新令牌,需要重新授权一次。撤销授权、刷新令牌过期或轮换响应丢失时仍可能需要重新登录。诊断日志只记录固定错误类别,不写令牌、设备码、代理地址或正文。
|
package/lib/client.js
CHANGED
|
@@ -139,6 +139,10 @@ function mergeConnectionState(previous3, next) {
|
|
|
139
139
|
return transient && previous3?.user ? { ...next, user: previous3.user } : next;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
// src/oauth-setup.mjs
|
|
143
|
+
var oauthRegistrationUrl = "https://github.com/settings/applications/new";
|
|
144
|
+
var oauthHomepage = "https://github.com/zhaohaix/DeepSeek-GitHub";
|
|
145
|
+
|
|
142
146
|
// src/release-editor.jsx
|
|
143
147
|
var import_react3 = __toESM(require("react"), 1);
|
|
144
148
|
|
|
@@ -13885,7 +13889,7 @@ function ReleaseEditor({ repo, apiCall, onBusyChange }) {
|
|
|
13885
13889
|
}
|
|
13886
13890
|
|
|
13887
13891
|
// src/style.css
|
|
13888
|
-
var style_default = '.dsh-github{font:14px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;color:var(--text-primary,#1f2328);width:100%;padding:2px 0 24px;box-sizing:border-box;--gh-line:#e6e9ef;--gh-soft:#f6f7f9;--gh-muted:#68717f;--gh-blue:#4169e1}\n.dsh-github *{box-sizing:border-box}.dsh-github h2,.dsh-github h3,.dsh-github p{margin:0}.dsh-github h2{font-size:22px;font-weight:600}.dsh-github h3{font-size:15px;font-weight:600;margin:16px 0 10px}.gh-header,.gh-row,.gh-title,.gh-actions,.gh-account,.gh-attachment{display:flex;align-items:center;gap:10px}.gh-header,.gh-row,.gh-attachment{justify-content:space-between}.gh-title{gap:12px}.gh-intro{color:var(--gh-muted);margin:10px 0 22px!important}.dsh-github button,.gh-upload{font:inherit;cursor:pointer;border:1px solid var(--gh-line);background:transparent;color:inherit;border-radius:8px;padding:7px 13px;transition:background .15s}.dsh-github button:hover,.gh-upload:hover{background:var(--gh-soft)}.dsh-github button:disabled,.gh-disabled{opacity:.5;cursor:not-allowed}.dsh-github .gh-primary{background:var(--gh-blue);border-color:var(--gh-blue);color:#fff}.dsh-github .gh-primary:hover{background:#3159cd}.dsh-github button:focus-visible,.dsh-github input:focus-visible,.dsh-github select:focus-visible,.dsh-github textarea:focus-visible,.gh-upload:focus-within{outline:2px solid var(--gh-blue);outline-offset:3px}.dsh-github a{color:var(--gh-blue);text-decoration:none;overflow-wrap:anywhere}.dsh-github a:hover{text-decoration:underline}.gh-account{padding:16px 0 20px;border-bottom:1px solid var(--gh-line)}.gh-account img{width:42px;height:42px;border-radius:50%}.gh-account>div{flex:1}.gh-account strong,.gh-account span{display:block}.gh-account span{color:var(--gh-muted);font-size:12px}.gh-account i{display:inline-block;width:6px;height:6px;border-radius:50%;background:#26834a;margin:0 4px 1px}.gh-connect{background:var(--gh-soft);padding:20px;border-radius:10px;margin-bottom:20px}.gh-connect p{color:var(--gh-muted);margin-top:6px}.gh-device{margin-top:14px;display:flex;flex-direction:column;align-items:flex-start;gap:6px}.gh-device>strong{font:600 22px/1.7 Consolas,monospace;letter-spacing:3px;color:var(--text-primary,#1f2328)}.gh-tabs{display:flex;border-bottom:1px solid var(--gh-line);gap:22px;margin-top:14px}.gh-tabs button{border:0;border-radius:0;color:var(--gh-muted);padding:12px 0;border-bottom:2px solid transparent}.gh-tabs button[aria-current]{color:var(--gh-blue);border-bottom-color:var(--gh-blue)}.gh-tabs button:hover{background:transparent;color:var(--gh-blue)}.gh-pending{width:100%;text-align:left;background:#f0f4ff!important;color:#3255af!important;margin-top:14px}.gh-empty{padding:42px 14px;text-align:center;display:flex;flex-direction:column;align-items:center;gap:10px;color:var(--gh-muted)}.gh-empty strong{color:var(--text-primary,#1f2328);font-weight:500}.gh-empty p{max-width:340px;font-size:13px}.gh-empty svg{opacity:.45;margin-bottom:4px}.gh-section-title{margin:14px 0}.gh-section-title h3{margin:0}.gh-repositories{display:grid;gap:10px}.dsh-github .gh-repo{width:100%;text-align:left;padding:15px 16px}.gh-repo strong{font-weight:600;color:var(--gh-blue)}.gh-repo p{color:var(--gh-muted);margin:5px 0;font-size:13px}.gh-repo small{color:var(--gh-muted)}.gh-badge{border:1px solid var(--gh-line);border-radius:20px;font-size:11px;color:var(--gh-muted);padding:1px 8px;white-space:nowrap}.gh-success{color:#22733e;background:#eef8f0;border-color:#d4e8d9}.gh-failed{color:#b42318;background:#fff3f1;border-color:#f4d8d3}.gh-form{display:grid;gap:13px;padding:16px 0 20px;border-bottom:1px solid var(--gh-line)}.gh-field{display:grid;gap:5px}.gh-field>span{font-size:13px;color:var(--gh-muted)}.dsh-github input:not([type=checkbox]):not([type=file]),.dsh-github select,.dsh-github textarea{font:inherit;width:100%;padding:8px 10px;border:1px solid var(--gh-line);border-radius:7px;background:var(--input-background,transparent);color:inherit}.dsh-github textarea{resize:vertical;min-height:90px}.gh-check{display:flex;align-items:center;gap:7px;font-size:13px}.gh-check input{accent-color:var(--gh-blue)}.gh-form>.gh-primary{justify-self:start}.gh-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.dsh-github .gh-back{border:0;padding:4px 0;margin-bottom:12px;color:var(--gh-muted)}.gh-repo-heading{display:flex;align-items:center;gap:10px}.gh-branch{display:flex;align-items:center;gap:8px;margin:14px 0}.gh-branch label{display:flex;align-items:center;gap:8px;flex:1}.gh-branch input{flex:1;min-width:0}.gh-breadcrumb{display:flex;justify-content:space-between;align-items:center;background:var(--gh-soft);padding:8px 12px;overflow-wrap:anywhere;border-radius:6px}.gh-breadcrumb button{font-size:12px;padding:2px 7px}.gh-files{display:grid;margin-top:7px}.gh-files button{display:flex;align-items:center;text-align:left;gap:10px;border:0;border-bottom:1px solid var(--gh-line);border-radius:0;padding:10px 8px}.gh-files button>span:nth-child(2){flex:1;overflow-wrap:anywhere}.gh-files small{color:var(--gh-muted);font-size:11px}.gh-code,.gh-operation pre{font:12px/1.7 Consolas,"Cascadia Mono",monospace;white-space:pre-wrap;overflow-wrap:anywhere;max-height:440px;overflow:auto;padding:13px;background:var(--gh-soft);border-radius:6px}.gh-operation{padding:17px 0;border-bottom:1px solid var(--gh-line)}.gh-operation .gh-target{font-size:15px;font-weight:500;margin:7px 0;overflow-wrap:anywhere}.gh-operation p{font-size:13px;margin:8px 0;color:var(--gh-muted)}.gh-operation .gh-actions{margin-top:13px}.gh-operation details{margin:9px 0}.gh-operation summary{cursor:pointer;font-size:13px;overflow-wrap:anywhere}.gh-release{padding:14px 0;border-bottom:1px solid var(--gh-line);display:grid;gap:6px}.gh-release>small{color:var(--gh-muted)}.gh-download{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:13px}.gh-asset-publish{display:flex;gap:8px;margin-top:8px}.gh-asset-publish select{min-width:0;flex:1}.gh-asset-publish button{white-space:nowrap}.gh-attachments{margin-top:16px}.gh-upload{font-size:13px;white-space:nowrap}.gh-upload input{display:none}.gh-attachment{border-bottom:1px solid var(--gh-line);padding:12px 0}.gh-attachment>div{min-width:0}.gh-attachment strong{font-size:13px;font-weight:500;overflow-wrap:anywhere}.gh-attachment small{display:block;color:var(--gh-muted);font-size:12px}.gh-muted{color:var(--gh-muted);font-size:12px;margin:10px 0!important}.gh-errorbox{display:flex;justify-content:space-between;align-items:flex-start;color:#b42318;background:#fff3f1;border-radius:8px;padding:10px 12px;margin:12px 0;overflow-wrap:anywhere}.gh-errorbox button{border:0;padding:0 5px;margin-left:8px}.dsh-github .gh-error{color:#b42318}.gh-working{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--gh-blue);margin-top:16px}.gh-working>span{width:10px;height:10px;border:2px solid #c2cef5;border-top-color:var(--gh-blue);border-radius:50%;animation:gh-spin .7s linear infinite}.gh-footer{font-size:11px;color:var(--gh-muted);margin-top:28px;border-top:1px solid var(--gh-line);padding-top:13px}@keyframes gh-spin{to{transform:rotate(360deg)}}@media(prefers-color-scheme:dark){.dsh-github{--gh-line:#3c414b;--gh-soft:#252931;--gh-muted:#a1a8b4;color:var(--text-primary,#e6e8ed)}.gh-empty strong,.gh-device>strong{color:var(--text-primary,#e6e8ed)}.dsh-github select option{background:#252931;color:#e6e8ed}}@media(max-width:520px){.gh-header{flex-wrap:wrap}.gh-grid{grid-template-columns:1fr}.gh-tabs{gap:16px}.gh-account{flex-wrap:wrap}.gh-asset-publish{flex-wrap:wrap}.gh-actions{flex-wrap:wrap}}@media(prefers-reduced-motion:reduce){.dsh-github *{animation:none!important;transition:none!important}}\n\n.gh-tabs .gh-refresh-repos{margin-left:auto;align-self:center;white-space:nowrap;padding:5px 10px;border:1px solid var(--gh-line);border-radius:7px;font-size:12px;line-height:1.5;min-width:68px;margin-bottom:6px;color:var(--gh-muted)}.gh-tabs .gh-refresh-repos:hover{background:var(--gh-soft)}\n.gh-browser-search{margin:18px 0 8px;padding:0 0 12px;border-bottom:1px solid var(--gh-line)}.gh-search-row{display:flex;gap:8px;align-items:center}.gh-search-row>select{width:84px!important;flex:none}.gh-search-row>input{min-width:0;flex:1}.gh-search-row>button{flex:none;white-space:nowrap}.gh-search-advanced>summary,.gh-search-preview>summary{cursor:pointer;color:var(--gh-muted);font-size:12px}.gh-search-fields{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px;margin:12px 0}.gh-search-fields .gh-field{min-width:0}.gh-search-preview{margin-top:8px}.gh-search-preview code{display:block;overflow-wrap:anywhere;white-space:pre-wrap;font-size:12px;background:var(--gh-soft);padding:8px;margin-top:6px}.gh-reset-search{font-size:12px!important}.gh-search-row input{font-size:13px!important}@media(max-width:520px){.gh-search-row{flex-wrap:wrap}.gh-search-row>select{width:72px!important}.gh-search-row>button{margin-left:auto}.gh-search-fields{grid-template-columns:minmax(0,1fr)}}\n\n.dsh-github .gh-delete-repo{margin-left:auto;flex-shrink:0;color:#b42318;border-color:#f0cdca;font-size:12px;white-space:nowrap}.dsh-github .gh-delete-repo:hover{background:#fff3f1}.gh-delete-dialog{box-sizing:border-box;border:1px solid var(--gh-line);border-radius:12px;background:var(--modal-background,#fff);color:inherit;width:min(460px,calc(100vw - 32px));max-height:calc(100vh - 48px);overflow:auto;padding:22px;font:inherit;box-shadow:0 16px 48px #0003}.gh-delete-dialog::backdrop{background:#0006}.gh-delete-dialog h3{margin:0 0 12px!important;font-size:17px!important}.gh-delete-dialog p{margin:10px 0!important;line-height:1.7}.gh-delete-target{font-weight:600;overflow-wrap:anywhere}.gh-delete-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px;flex-wrap:wrap}.dsh-github .gh-delete-continue{background:#b42318;color:white;border-radius:8px;padding:7px 13px;text-decoration:none}.dsh-github .gh-delete-continue:hover{background:#971d14;text-decoration:none}.gh-delete-continue:focus-visible{outline:2px solid #b42318;outline-offset:3px}@media(prefers-color-scheme:dark){.gh-delete-dialog{background:var(--modal-background,#252931)}}\n.gh-imported-files{margin:2px 0 0;border-top:1px solid var(--gh-line)}.gh-ai-label{display:flex;justify-content:space-between;align-items:center;gap:12px;color:var(--gh-muted);font-size:13px}.gh-ai-label button:disabled{color:var(--gh-muted)}.gh-ai-label button:disabled:hover{background:transparent}.gh-ai-label button{font-size:12px;padding:5px 9px;color:var(--gh-blue)}.gh-markdown-toolbar{display:flex;gap:6px;flex-wrap:wrap}.gh-markdown-toolbar button{font-size:12px;padding:4px 8px}.gh-image-insert{display:flex;gap:6px}.gh-image-insert input{min-width:0;flex:1}.gh-image-insert button{white-space:nowrap}.gh-markdown-preview{border:1px solid var(--gh-line);border-radius:8px;padding:14px;max-height:500px;overflow:auto;line-height:1.7}.gh-markdown-preview img{max-width:100%;height:auto}.gh-markdown-preview h1,.gh-markdown-preview h2,.gh-markdown-preview h3{margin:12px 0}.gh-markdown-preview p{margin:8px 0}.gh-markdown-preview blockquote{border-left:3px solid var(--gh-line);margin:8px 0;padding-left:12px;color:var(--gh-muted)}.gh-copy-code{position:relative;margin:10px 0;background:var(--gh-soft);border-radius:7px}.gh-copy-code>button{position:absolute;right:6px;top:6px;font-size:11px;padding:3px 7px}.gh-copy-code pre{padding:36px 12px 12px;white-space:pre-wrap;overflow-wrap:anywhere;overflow:auto;font:12px/1.7 Consolas,monospace}.gh-markdown-preview table{border-collapse:collapse}.gh-markdown-preview td,.gh-markdown-preview th{border:1px solid var(--gh-line);padding:5px 9px}@media(max-width:520px){.gh-ai-label{flex-wrap:wrap}.gh-image-insert{flex-wrap:wrap}}\n.dsh-github .gh-muted{overflow-wrap:anywhere}\n\n';
|
|
13892
|
+
var style_default = '.dsh-github{font:14px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;color:var(--text-primary,#1f2328);width:100%;padding:2px 0 24px;box-sizing:border-box;--gh-line:#e6e9ef;--gh-soft:#f6f7f9;--gh-muted:#68717f;--gh-blue:#4169e1}\n.dsh-github *{box-sizing:border-box}.dsh-github h2,.dsh-github h3,.dsh-github p{margin:0}.dsh-github h2{font-size:22px;font-weight:600}.dsh-github h3{font-size:15px;font-weight:600;margin:16px 0 10px}.gh-header,.gh-row,.gh-title,.gh-actions,.gh-account,.gh-attachment{display:flex;align-items:center;gap:10px}.gh-header,.gh-row,.gh-attachment{justify-content:space-between}.gh-title{gap:12px}.gh-intro{color:var(--gh-muted);margin:10px 0 22px!important}.dsh-github button,.gh-upload{font:inherit;cursor:pointer;border:1px solid var(--gh-line);background:transparent;color:inherit;border-radius:8px;padding:7px 13px;transition:background .15s}.dsh-github button:hover,.gh-upload:hover{background:var(--gh-soft)}.dsh-github button:disabled,.gh-disabled{opacity:.5;cursor:not-allowed}.dsh-github .gh-primary{background:var(--gh-blue);border-color:var(--gh-blue);color:#fff}.dsh-github .gh-primary:hover{background:#3159cd}.dsh-github button:focus-visible,.dsh-github input:focus-visible,.dsh-github select:focus-visible,.dsh-github textarea:focus-visible,.gh-upload:focus-within{outline:2px solid var(--gh-blue);outline-offset:3px}.dsh-github a{color:var(--gh-blue);text-decoration:none;overflow-wrap:anywhere}.dsh-github a:hover{text-decoration:underline}.gh-account{padding:16px 0 20px;border-bottom:1px solid var(--gh-line)}.gh-account img{width:42px;height:42px;border-radius:50%}.gh-account>div{flex:1}.gh-account strong,.gh-account span{display:block}.gh-account span{color:var(--gh-muted);font-size:12px}.gh-account i{display:inline-block;width:6px;height:6px;border-radius:50%;background:#26834a;margin:0 4px 1px}.gh-connect{background:var(--gh-soft);padding:20px;border-radius:10px;margin-bottom:20px}.gh-connect p{color:var(--gh-muted);margin-top:6px}.gh-device{margin-top:14px;display:flex;flex-direction:column;align-items:flex-start;gap:6px}.gh-device>strong{font:600 22px/1.7 Consolas,monospace;letter-spacing:3px;color:var(--text-primary,#1f2328)}.gh-tabs{display:flex;border-bottom:1px solid var(--gh-line);gap:22px;margin-top:14px}.gh-tabs button{border:0;border-radius:0;color:var(--gh-muted);padding:12px 0;border-bottom:2px solid transparent}.gh-tabs button[aria-current]{color:var(--gh-blue);border-bottom-color:var(--gh-blue)}.gh-tabs button:hover{background:transparent;color:var(--gh-blue)}.gh-pending{width:100%;text-align:left;background:#f0f4ff!important;color:#3255af!important;margin-top:14px}.gh-empty{padding:42px 14px;text-align:center;display:flex;flex-direction:column;align-items:center;gap:10px;color:var(--gh-muted)}.gh-empty strong{color:var(--text-primary,#1f2328);font-weight:500}.gh-empty p{max-width:340px;font-size:13px}.gh-empty svg{opacity:.45;margin-bottom:4px}.gh-section-title{margin:14px 0}.gh-section-title h3{margin:0}.gh-repositories{display:grid;gap:10px}.dsh-github .gh-repo{width:100%;text-align:left;padding:15px 16px}.gh-repo strong{font-weight:600;color:var(--gh-blue)}.gh-repo p{color:var(--gh-muted);margin:5px 0;font-size:13px}.gh-repo small{color:var(--gh-muted)}.gh-badge{border:1px solid var(--gh-line);border-radius:20px;font-size:11px;color:var(--gh-muted);padding:1px 8px;white-space:nowrap}.gh-success{color:#22733e;background:#eef8f0;border-color:#d4e8d9}.gh-failed{color:#b42318;background:#fff3f1;border-color:#f4d8d3}.gh-form{display:grid;gap:13px;padding:16px 0 20px;border-bottom:1px solid var(--gh-line)}.gh-field{display:grid;gap:5px}.gh-field>span{font-size:13px;color:var(--gh-muted)}.dsh-github input:not([type=checkbox]):not([type=file]),.dsh-github select,.dsh-github textarea{font:inherit;width:100%;padding:8px 10px;border:1px solid var(--gh-line);border-radius:7px;background:var(--input-background,transparent);color:inherit}.dsh-github textarea{resize:vertical;min-height:90px}.gh-check{display:flex;align-items:center;gap:7px;font-size:13px}.gh-check input{accent-color:var(--gh-blue)}.gh-form>.gh-primary{justify-self:start}.gh-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.dsh-github .gh-back{border:0;padding:4px 0;margin-bottom:12px;color:var(--gh-muted)}.gh-repo-heading{display:flex;align-items:center;gap:10px}.gh-branch{display:flex;align-items:center;gap:8px;margin:14px 0}.gh-branch label{display:flex;align-items:center;gap:8px;flex:1}.gh-branch input{flex:1;min-width:0}.gh-breadcrumb{display:flex;justify-content:space-between;align-items:center;background:var(--gh-soft);padding:8px 12px;overflow-wrap:anywhere;border-radius:6px}.gh-breadcrumb button{font-size:12px;padding:2px 7px}.gh-files{display:grid;margin-top:7px}.gh-files button{display:flex;align-items:center;text-align:left;gap:10px;border:0;border-bottom:1px solid var(--gh-line);border-radius:0;padding:10px 8px}.gh-files button>span:nth-child(2){flex:1;overflow-wrap:anywhere}.gh-files small{color:var(--gh-muted);font-size:11px}.gh-code,.gh-operation pre{font:12px/1.7 Consolas,"Cascadia Mono",monospace;white-space:pre-wrap;overflow-wrap:anywhere;max-height:440px;overflow:auto;padding:13px;background:var(--gh-soft);border-radius:6px}.gh-operation{padding:17px 0;border-bottom:1px solid var(--gh-line)}.gh-operation .gh-target{font-size:15px;font-weight:500;margin:7px 0;overflow-wrap:anywhere}.gh-operation p{font-size:13px;margin:8px 0;color:var(--gh-muted)}.gh-operation .gh-actions{margin-top:13px}.gh-operation details{margin:9px 0}.gh-operation summary{cursor:pointer;font-size:13px;overflow-wrap:anywhere}.gh-release{padding:14px 0;border-bottom:1px solid var(--gh-line);display:grid;gap:6px}.gh-release>small{color:var(--gh-muted)}.gh-download{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:13px}.gh-asset-publish{display:flex;gap:8px;margin-top:8px}.gh-asset-publish select{min-width:0;flex:1}.gh-asset-publish button{white-space:nowrap}.gh-attachments{margin-top:16px}.gh-upload{font-size:13px;white-space:nowrap}.gh-upload input{display:none}.gh-attachment{border-bottom:1px solid var(--gh-line);padding:12px 0}.gh-attachment>div{min-width:0}.gh-attachment strong{font-size:13px;font-weight:500;overflow-wrap:anywhere}.gh-attachment small{display:block;color:var(--gh-muted);font-size:12px}.gh-muted{color:var(--gh-muted);font-size:12px;margin:10px 0!important}.gh-errorbox{display:flex;justify-content:space-between;align-items:flex-start;color:#b42318;background:#fff3f1;border-radius:8px;padding:10px 12px;margin:12px 0;overflow-wrap:anywhere}.gh-errorbox button{border:0;padding:0 5px;margin-left:8px}.dsh-github .gh-error{color:#b42318}.gh-working{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--gh-blue);margin-top:16px}.gh-working>span{width:10px;height:10px;border:2px solid #c2cef5;border-top-color:var(--gh-blue);border-radius:50%;animation:gh-spin .7s linear infinite}.gh-footer{font-size:11px;color:var(--gh-muted);margin-top:28px;border-top:1px solid var(--gh-line);padding-top:13px}@keyframes gh-spin{to{transform:rotate(360deg)}}@media(prefers-color-scheme:dark){.dsh-github{--gh-line:#3c414b;--gh-soft:#252931;--gh-muted:#a1a8b4;color:var(--text-primary,#e6e8ed)}.gh-empty strong,.gh-device>strong{color:var(--text-primary,#e6e8ed)}.dsh-github select option{background:#252931;color:#e6e8ed}}@media(max-width:520px){.gh-header{flex-wrap:wrap}.gh-grid{grid-template-columns:1fr}.gh-tabs{gap:16px}.gh-account{flex-wrap:wrap}.gh-asset-publish{flex-wrap:wrap}.gh-actions{flex-wrap:wrap}}@media(prefers-reduced-motion:reduce){.dsh-github *{animation:none!important;transition:none!important}}\n\n.gh-tabs .gh-refresh-repos{margin-left:auto;align-self:center;white-space:nowrap;padding:5px 10px;border:1px solid var(--gh-line);border-radius:7px;font-size:12px;line-height:1.5;min-width:68px;margin-bottom:6px;color:var(--gh-muted)}.gh-tabs .gh-refresh-repos:hover{background:var(--gh-soft)}\n.gh-browser-search{margin:18px 0 8px;padding:0 0 12px;border-bottom:1px solid var(--gh-line)}.gh-search-row{display:flex;gap:8px;align-items:center}.gh-search-row>select{width:84px!important;flex:none}.gh-search-row>input{min-width:0;flex:1}.gh-search-row>button{flex:none;white-space:nowrap}.gh-search-advanced>summary,.gh-search-preview>summary{cursor:pointer;color:var(--gh-muted);font-size:12px}.gh-search-fields{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px;margin:12px 0}.gh-search-fields .gh-field{min-width:0}.gh-search-preview{margin-top:8px}.gh-search-preview code{display:block;overflow-wrap:anywhere;white-space:pre-wrap;font-size:12px;background:var(--gh-soft);padding:8px;margin-top:6px}.gh-reset-search{font-size:12px!important}.gh-search-row input{font-size:13px!important}@media(max-width:520px){.gh-search-row{flex-wrap:wrap}.gh-search-row>select{width:72px!important}.gh-search-row>button{margin-left:auto}.gh-search-fields{grid-template-columns:minmax(0,1fr)}}\n\n.dsh-github .gh-delete-repo{margin-left:auto;flex-shrink:0;color:#b42318;border-color:#f0cdca;font-size:12px;white-space:nowrap}.dsh-github .gh-delete-repo:hover{background:#fff3f1}.gh-delete-dialog{box-sizing:border-box;border:1px solid var(--gh-line);border-radius:12px;background:var(--modal-background,#fff);color:inherit;width:min(460px,calc(100vw - 32px));max-height:calc(100vh - 48px);overflow:auto;padding:22px;font:inherit;box-shadow:0 16px 48px #0003}.gh-delete-dialog::backdrop{background:#0006}.gh-delete-dialog h3{margin:0 0 12px!important;font-size:17px!important}.gh-delete-dialog p{margin:10px 0!important;line-height:1.7}.gh-delete-target{font-weight:600;overflow-wrap:anywhere}.gh-delete-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px;flex-wrap:wrap}.dsh-github .gh-delete-continue{background:#b42318;color:white;border-radius:8px;padding:7px 13px;text-decoration:none}.dsh-github .gh-delete-continue:hover{background:#971d14;text-decoration:none}.gh-delete-continue:focus-visible{outline:2px solid #b42318;outline-offset:3px}@media(prefers-color-scheme:dark){.gh-delete-dialog{background:var(--modal-background,#252931)}}\n.gh-imported-files{margin:2px 0 0;border-top:1px solid var(--gh-line)}.gh-ai-label{display:flex;justify-content:space-between;align-items:center;gap:12px;color:var(--gh-muted);font-size:13px}.gh-ai-label button:disabled{color:var(--gh-muted)}.gh-ai-label button:disabled:hover{background:transparent}.gh-ai-label button{font-size:12px;padding:5px 9px;color:var(--gh-blue)}.gh-markdown-toolbar{display:flex;gap:6px;flex-wrap:wrap}.gh-markdown-toolbar button{font-size:12px;padding:4px 8px}.gh-image-insert{display:flex;gap:6px}.gh-image-insert input{min-width:0;flex:1}.gh-image-insert button{white-space:nowrap}.gh-markdown-preview{border:1px solid var(--gh-line);border-radius:8px;padding:14px;max-height:500px;overflow:auto;line-height:1.7}.gh-markdown-preview img{max-width:100%;height:auto}.gh-markdown-preview h1,.gh-markdown-preview h2,.gh-markdown-preview h3{margin:12px 0}.gh-markdown-preview p{margin:8px 0}.gh-markdown-preview blockquote{border-left:3px solid var(--gh-line);margin:8px 0;padding-left:12px;color:var(--gh-muted)}.gh-copy-code{position:relative;margin:10px 0;background:var(--gh-soft);border-radius:7px}.gh-copy-code>button{position:absolute;right:6px;top:6px;font-size:11px;padding:3px 7px}.gh-copy-code pre{padding:36px 12px 12px;white-space:pre-wrap;overflow-wrap:anywhere;overflow:auto;font:12px/1.7 Consolas,monospace}.gh-markdown-preview table{border-collapse:collapse}.gh-markdown-preview td,.gh-markdown-preview th{border:1px solid var(--gh-line);padding:5px 9px}@media(max-width:520px){.gh-ai-label{flex-wrap:wrap}.gh-image-insert{flex-wrap:wrap}}\n.dsh-github .gh-muted{overflow-wrap:anywhere}\n.gh-oauth-setup summary { cursor: pointer; font-weight: 600; }\n.gh-oauth-setup > p { margin-top: 10px; }\n.gh-oauth-steps { margin: 12px 0; padding-inline-start: 1.4em; }\n.gh-oauth-steps > li + li { margin-top: 10px; }\n.gh-oauth-steps ul { margin: 6px 0; padding-inline-start: 1.2em; list-style: disc; }\n.gh-oauth-steps ul li + li { margin-top: 4px; }\n.gh-oauth-steps code { overflow-wrap: anywhere; }\n.gh-oauth-value { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 4px 0 8px; }\n.gh-oauth-value code { min-width: 0; user-select: text; }\n.dsh-github .gh-oauth-value button { font-size: 12px; padding: 4px 8px; }\n\n@media (max-width: 520px) {\n .dsh-github { padding: 16px; }\n .dsh-github .gh-tabs { gap: 10px; flex-wrap: wrap; }\n .dsh-github .gh-search-row > input { flex-basis: 140px; }\n .dsh-github .gh-branch { flex-wrap: wrap; }\n .dsh-github .gh-branch label, .dsh-github .gh-asset-publish select { min-width: 0; }\n .dsh-github .gh-repo-heading a { overflow-wrap: anywhere; }\n}\n\n';
|
|
13889
13893
|
|
|
13890
13894
|
// src/browser-search.jsx
|
|
13891
13895
|
var import_react4 = __toESM(require("react"), 1);
|
|
@@ -14138,6 +14142,34 @@ var sizeLabel = (n) => n >= 1024 ** 2 ? (n / 1024 ** 2).toFixed(1) + " MB" : n >
|
|
|
14138
14142
|
function Field({ label, children }) {
|
|
14139
14143
|
return /* @__PURE__ */ import_react8.default.createElement("label", { className: "gh-field" }, /* @__PURE__ */ import_react8.default.createElement("span", null, label), children);
|
|
14140
14144
|
}
|
|
14145
|
+
function OAuthSetup({ clientId, busy, onSave }) {
|
|
14146
|
+
const [copyStatus, setCopyStatus] = (0, import_react8.useState)("");
|
|
14147
|
+
async function copy(label, value) {
|
|
14148
|
+
try {
|
|
14149
|
+
await navigator.clipboard.writeText(value);
|
|
14150
|
+
setCopyStatus(label + "\u5DF2\u590D\u5236");
|
|
14151
|
+
} catch {
|
|
14152
|
+
setCopyStatus("\u81EA\u52A8\u590D\u5236\u5931\u8D25\uFF0C\u8BF7\u957F\u6309\u6216\u9009\u4E2D\u5730\u5740\u624B\u52A8\u590D\u5236\u3002");
|
|
14153
|
+
}
|
|
14154
|
+
}
|
|
14155
|
+
return /* @__PURE__ */ import_react8.default.createElement("details", { open: !clientId, className: "gh-connect gh-oauth-setup" }, /* @__PURE__ */ import_react8.default.createElement("summary", null, clientId ? "GitHub \u767B\u5F55\u914D\u7F6E\uFF08\u5DF2\u914D\u7F6E\uFF09" : "\u9996\u6B21\u767B\u5F55\uFF1F\u914D\u7F6E\u4F60\u7684 GitHub OAuth App"), /* @__PURE__ */ import_react8.default.createElement("p", null, "\u9996\u6B21\u4F7F\u7528\u8BF7\u5728\u81EA\u5DF1\u7684 GitHub \u8D26\u53F7\u4E0B\u6CE8\u518C\u4E00\u6B21\u3002\u5DF2\u7ECF\u6709\u542F\u7528\u4E86\u8BBE\u5907\u6D41\u7684 OAuth App\uFF1F\u76F4\u63A5\u7528\u539F\u6765\u7684 Client ID\uFF0C\u540C\u4E00\u4E2A ID \u53EF\u5728\u7535\u8111\u548C\u624B\u673A\u4E0A\u4F7F\u7528\u3002"), /* @__PURE__ */ import_react8.default.createElement("ol", { className: "gh-oauth-steps" }, /* @__PURE__ */ import_react8.default.createElement("li", null, /* @__PURE__ */ import_react8.default.createElement("a", { href: oauthRegistrationUrl, target: "_blank", rel: "noreferrer" }, "\u6253\u5F00 GitHub OAuth App \u6CE8\u518C\u9875"), "\uFF0C\u767B\u5F55\u4F60\u7684 GitHub \u8D26\u53F7\u3002"), /* @__PURE__ */ import_react8.default.createElement("li", null, "\u6309\u4E0B\u9762\u7684\u793A\u4F8B\u586B\u5199\u8868\u5355\uFF0C\u518D\u70B9\u51FB GitHub \u7684\u300C\u6CE8\u518C\u5E94\u7528\u300D\u3002", /* @__PURE__ */ import_react8.default.createElement("ul", null, /* @__PURE__ */ import_react8.default.createElement("li", null, /* @__PURE__ */ import_react8.default.createElement("strong", null, "\u5E94\u7528\u540D\u79F0"), "\u53EF\u586B ", /* @__PURE__ */ import_react8.default.createElement("code", null, "DeepSeek GitHub Studio"), "\uFF0C\u4E5F\u53EF\u4EE5\u53D6\u81EA\u5DF1\u7684\u540D\u5B57\u3002"), /* @__PURE__ */ import_react8.default.createElement("li", null, /* @__PURE__ */ import_react8.default.createElement("strong", null, "\u4E3B\u9875 URL"), "\u586B\u63D2\u4EF6\u7684\u4ED3\u5E93\u5730\u5740\u3002", /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-oauth-value" }, /* @__PURE__ */ import_react8.default.createElement("code", null, oauthHomepage), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", onClick: () => copy("\u4E3B\u9875 URL", oauthHomepage) }, "\u590D\u5236\u4E3B\u9875 URL"))), /* @__PURE__ */ import_react8.default.createElement("li", null, /* @__PURE__ */ import_react8.default.createElement("strong", null, "\u5E94\u7528\u63CF\u8FF0"), "\u53EF\u7559\u7A7A\u3002"), /* @__PURE__ */ import_react8.default.createElement("li", null, /* @__PURE__ */ import_react8.default.createElement("strong", null, "\u91CD\u5B9A\u5411 URI"), "\u586B\u548C\u4E3B\u9875 URL \u4E00\u6837\u7684\u4ED3\u5E93\u5730\u5740\u3002\u901A\u914D\u7B26\u5339\u914D\u4FDD\u6301\u5173\u95ED\u3002", /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-oauth-value" }, /* @__PURE__ */ import_react8.default.createElement("code", null, oauthHomepage), /* @__PURE__ */ import_react8.default.createElement("button", { type: "button", onClick: () => copy("\u91CD\u5B9A\u5411 URI", oauthHomepage) }, "\u590D\u5236\u91CD\u5B9A\u5411 URI"))), /* @__PURE__ */ import_react8.default.createElement("li", null, "\u52FE\u9009", /* @__PURE__ */ import_react8.default.createElement("strong", null, "\u542F\u7528\u8BBE\u5907\u6D41\uFF08Enable Device Flow\uFF09"), "\u3002"))), /* @__PURE__ */ import_react8.default.createElement("li", null, "\u6CE8\u518C\u540E\uFF0C\u5728 GitHub \u5E94\u7528\u8BE6\u60C5\u91CC\u590D\u5236 ", /* @__PURE__ */ import_react8.default.createElement("strong", null, "Client ID"), "\uFF0C\u7C98\u8D34\u5230\u4E0B\u65B9\u5E76\u4FDD\u5B58\u3002\u518D\u70B9\u300C\u767B\u5F55 GitHub\u300D\uFF0C\u5728 GitHub \u6388\u6743\u9875\u8F93\u5165\u63D2\u4EF6\u663E\u793A\u7684\u8BBE\u5907\u7801\u5E76\u786E\u8BA4\u3002")), copyStatus && /* @__PURE__ */ import_react8.default.createElement("p", { role: "status" }, copyStatus), /* @__PURE__ */ import_react8.default.createElement("p", null, "\u53EA\u9700\u586B\u5199 Client ID\uFF0C\u65E0\u9700\u751F\u6210 Client Secret\u3002"), /* @__PURE__ */ import_react8.default.createElement("form", { className: "gh-form", onSubmit: (event) => {
|
|
14156
|
+
event.preventDefault();
|
|
14157
|
+
const form = new FormData(event.currentTarget);
|
|
14158
|
+
onSave(form.get("clientId").trim());
|
|
14159
|
+
} }, /* @__PURE__ */ import_react8.default.createElement(Field, { label: "OAuth App Client ID" }, /* @__PURE__ */ import_react8.default.createElement(
|
|
14160
|
+
"input",
|
|
14161
|
+
{
|
|
14162
|
+
name: "clientId",
|
|
14163
|
+
required: true,
|
|
14164
|
+
maxLength: 120,
|
|
14165
|
+
defaultValue: clientId ?? "",
|
|
14166
|
+
autoCapitalize: "none",
|
|
14167
|
+
autoComplete: "off",
|
|
14168
|
+
spellCheck: false,
|
|
14169
|
+
placeholder: "\u7C98\u8D34\u4F60\u7684 Client ID"
|
|
14170
|
+
}
|
|
14171
|
+
)), /* @__PURE__ */ import_react8.default.createElement("button", { disabled: busy }, "\u4FDD\u5B58\u5E94\u7528\u914D\u7F6E")));
|
|
14172
|
+
}
|
|
14141
14173
|
function Empty({ title, children }) {
|
|
14142
14174
|
return /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-empty" }, /* @__PURE__ */ import_react8.default.createElement(GitHubIcon, { size: 30 }), /* @__PURE__ */ import_react8.default.createElement("strong", null, title), /* @__PURE__ */ import_react8.default.createElement("p", null, children));
|
|
14143
14175
|
}
|
|
@@ -14233,11 +14265,14 @@ function GitHubSettings() {
|
|
|
14233
14265
|
if (result.status === "failed") throw Error(result.error);
|
|
14234
14266
|
if (selected) await loadReleases();
|
|
14235
14267
|
});
|
|
14236
|
-
return /* @__PURE__ */ import_react8.default.createElement("div", { className: "dsh-github" }, /* @__PURE__ */ import_react8.default.createElement("style", null, style_default), /* @__PURE__ */ import_react8.default.createElement("header", { className: "gh-header" }, /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-title" }, /* @__PURE__ */ import_react8.default.createElement(GitHubIcon, { size: 26 }), /* @__PURE__ */ import_react8.default.createElement("h2", null, "GitHub")), !logged && /* @__PURE__ */ import_react8.default.createElement("button", { className: "gh-primary", disabled: !!busy || ["preparing", "waiting"].includes(login.state), onClick: () => act("\u6B63\u5728\u8FDE\u63A5", () => post2("auth/start")) }, login.state === "preparing" ? "\u6B63\u5728\u51C6\u5907\u767B\u5F55\u2026" : login.state === "waiting" ? "\u7B49\u5F85\u6388\u6743\u2026" : "\u767B\u5F55 GitHub")), /* @__PURE__ */ import_react8.default.createElement("p", { className: "gh-intro" }, "\u8FDE\u63A5\u4F60\u7684\u8D26\u53F7\uFF0C\u5728\u804A\u5929\u4E2D\u6D4F\u89C8\u4ED3\u5E93\u3001\u63D0\u4EA4\u4EE3\u7801\u548C\u53D1\u5E03\u7A0B\u5E8F\u3002"), state && !logged && /* @__PURE__ */ import_react8.default.createElement(
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14268
|
+
return /* @__PURE__ */ import_react8.default.createElement("div", { className: "dsh-github" }, /* @__PURE__ */ import_react8.default.createElement("style", null, style_default), /* @__PURE__ */ import_react8.default.createElement("header", { className: "gh-header" }, /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-title" }, /* @__PURE__ */ import_react8.default.createElement(GitHubIcon, { size: 26 }), /* @__PURE__ */ import_react8.default.createElement("h2", null, "GitHub")), !logged && /* @__PURE__ */ import_react8.default.createElement("button", { className: "gh-primary", disabled: !!busy || ["preparing", "waiting"].includes(login.state), onClick: () => act("\u6B63\u5728\u8FDE\u63A5", () => post2("auth/start")) }, login.state === "preparing" ? "\u6B63\u5728\u51C6\u5907\u767B\u5F55\u2026" : login.state === "waiting" ? "\u7B49\u5F85\u6388\u6743\u2026" : "\u767B\u5F55 GitHub")), /* @__PURE__ */ import_react8.default.createElement("p", { className: "gh-intro" }, "\u8FDE\u63A5\u4F60\u7684\u8D26\u53F7\uFF0C\u5728\u804A\u5929\u4E2D\u6D4F\u89C8\u4ED3\u5E93\u3001\u63D0\u4EA4\u4EE3\u7801\u548C\u53D1\u5E03\u7A0B\u5E8F\u3002"), state && !logged && /* @__PURE__ */ import_react8.default.createElement(
|
|
14269
|
+
OAuthSetup,
|
|
14270
|
+
{
|
|
14271
|
+
clientId: state.clientId,
|
|
14272
|
+
busy: !!busy,
|
|
14273
|
+
onSave: (clientId) => act("\u6B63\u5728\u4FDD\u5B58", () => post2("auth/configure", { clientId }))
|
|
14274
|
+
}
|
|
14275
|
+
), error && /* @__PURE__ */ import_react8.default.createElement("div", { role: "alert", className: "gh-errorbox" }, error, /* @__PURE__ */ import_react8.default.createElement("button", { "aria-label": "\u5173\u95ED\u63D0\u793A", onClick: () => setError("") }, "\xD7")), state?.user && state.errorKind && state.errorKind !== "auth" && /* @__PURE__ */ import_react8.default.createElement("p", { role: "status", className: "gh-muted" }, "GitHub \u6682\u65F6\u4E0D\u53EF\u7528\uFF08", state.error, "\uFF09\uFF0C\u5DF2\u4FDD\u7559\u5F53\u524D\u754C\u9762\u72B6\u6001\u5E76\u81EA\u52A8\u91CD\u8BD5\u3002"), state?.hasCredential && !logged && /* @__PURE__ */ import_react8.default.createElement("button", { disabled: !!busy, onClick: () => act("\u6B63\u5728\u6E05\u9664\u672C\u5730\u8FDE\u63A5", () => post2("auth/logout")) }, "\u6E05\u9664\u672C\u5730\u8FDE\u63A5"), !state && /* @__PURE__ */ import_react8.default.createElement("p", { role: "status", className: "gh-muted" }, "\u6B63\u5728\u68C0\u67E5\u8FDE\u63A5\u2026"), logged ? /* @__PURE__ */ import_react8.default.createElement("section", { className: "gh-account" }, /* @__PURE__ */ import_react8.default.createElement("img", { src: state.user.avatar_url, alt: "" }), /* @__PURE__ */ import_react8.default.createElement("div", null, /* @__PURE__ */ import_react8.default.createElement("strong", null, state.user.name || state.user.login), /* @__PURE__ */ import_react8.default.createElement("span", null, "@", state.user.login, " ", /* @__PURE__ */ import_react8.default.createElement("i", null), " \u5DF2\u8FDE\u63A5")), /* @__PURE__ */ import_react8.default.createElement("button", { disabled: !!busy, onClick: () => act("\u6B63\u5728\u65AD\u5F00", () => post2("auth/logout")) }, "\u65AD\u5F00\u8FDE\u63A5")) : /* @__PURE__ */ import_react8.default.createElement("section", { className: "gh-connect" }, /* @__PURE__ */ import_react8.default.createElement("strong", null, "\u8FDE\u63A5\u4F60\u7684 GitHub \u8D26\u53F7"), /* @__PURE__ */ import_react8.default.createElement("p", null, "\u70B9\u51FB\u53F3\u4E0A\u65B9\u767B\u5F55\uFF0C\u5728 GitHub \u5B98\u65B9\u9875\u9762\u5B8C\u6210\u6388\u6743\u3002\u8BF7\u5728 GitHub \u5B98\u65B9\u6388\u6743\u9875\u8F93\u5165\u8BBE\u5907\u4EE3\u7801\u3002"), login.state === "waiting" && /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-device" }, /* @__PURE__ */ import_react8.default.createElement("span", null, "\u5728\u6388\u6743\u9875\u9762\u8F93\u5165\u8BBE\u5907\u4EE3\u7801"), /* @__PURE__ */ import_react8.default.createElement("strong", null, login.code || "\u6B63\u5728\u83B7\u53D6\u2026"), /* @__PURE__ */ import_react8.default.createElement("a", { href: "https://github.com/login/device", target: "_blank", rel: "noreferrer" }, "\u6253\u5F00 GitHub \u6388\u6743\u9875\u9762")), ["preparing", "waiting"].includes(login.state) && /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, /* @__PURE__ */ import_react8.default.createElement("p", { role: "status", className: "gh-muted" }, login.message || "\u6388\u6743\u6709\u6548\u671F\u5185\u9047\u5230\u77ED\u6682\u7F51\u7EDC\u6545\u969C\u4F1A\u81EA\u52A8\u91CD\u8BD5\u3002"), /* @__PURE__ */ import_react8.default.createElement("button", { disabled: !!busy, onClick: () => act("\u6B63\u5728\u53D6\u6D88\u767B\u5F55", () => post2("auth/cancel")) }, "\u53D6\u6D88\u672C\u6B21\u767B\u5F55")), login.state === "preparing" && /* @__PURE__ */ import_react8.default.createElement("p", { role: "status" }, "\u6B63\u5728\u8BF7\u6C42 GitHub \u8BBE\u5907\u6388\u6743\uFF0C\u8BF7\u7A0D\u5019\u2026"), state?.error && !logged && !["preparing", "waiting", "error"].includes(login.state) && /* @__PURE__ */ import_react8.default.createElement("p", { className: "gh-error" }, state.error), login.state === "error" && /* @__PURE__ */ import_react8.default.createElement("p", { className: "gh-error" }, login.message)), /* @__PURE__ */ import_react8.default.createElement(BrowserSearch, null), pending > 0 && tab2 !== "operations" && /* @__PURE__ */ import_react8.default.createElement("button", { className: "gh-pending", onClick: () => setTab("operations") }, pending, " \u9879\u64CD\u4F5C\u7B49\u5F85\u786E\u8BA4\uFF0C\u70B9\u51FB\u9884\u89C8"), /* @__PURE__ */ import_react8.default.createElement("nav", { className: "gh-tabs", "aria-label": "GitHub \u529F\u80FD" }, [["repos", "\u4ED3\u5E93"], ["releases", "\u7A0B\u5E8F\u53D1\u5E03"], ["operations", `\u64CD\u4F5C\u8BB0\u5F55${pending ? " (" + pending + ")" : ""}`]].map(([id, label]) => /* @__PURE__ */ import_react8.default.createElement("button", { key: id, "aria-current": tab2 === id ? "page" : void 0, onClick: () => {
|
|
14241
14276
|
setTab(id);
|
|
14242
14277
|
if (id === "releases" && selected) act("\u6B63\u5728\u8BFB\u53D6\u7248\u672C", () => loadReleases());
|
|
14243
14278
|
} }, label)), /* @__PURE__ */ import_react8.default.createElement("button", { className: "gh-refresh-repos", disabled: !logged || !!busy, onClick: () => act("\u6B63\u5728\u5237\u65B0\u4ED3\u5E93", () => listRepos(1)) }, busy === "\u6B63\u5728\u5237\u65B0\u4ED3\u5E93" ? "\u5237\u65B0\u4E2D\u2026" : "\u5237\u65B0\u5E93")), tab2 === "repos" && (!logged ? /* @__PURE__ */ import_react8.default.createElement(Empty, { title: "\u767B\u5F55\u540E\u67E5\u770B\u4ED3\u5E93" }, "\u9009\u62E9\u4F60\u7684\u9879\u76EE\uFF0C\u8BA9 DeepSeek \u9605\u8BFB\u548C\u5206\u6790\u4EE3\u7801\u3002") : /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-row gh-section-title" }, /* @__PURE__ */ import_react8.default.createElement("h3", null, selected ? "\u4ED3\u5E93\u6587\u4EF6" : "\u6211\u7684\u4ED3\u5E93"), /* @__PURE__ */ import_react8.default.createElement("div", { className: "gh-actions" }, /* @__PURE__ */ import_react8.default.createElement("button", { disabled: !!busy, onClick: () => act("\u6B63\u5728\u5237\u65B0", () => listRepos()) }, "\u5237\u65B0"), /* @__PURE__ */ import_react8.default.createElement("button", { onClick: () => setCreate(!create2) }, "\u65B0\u5EFA\u4ED3\u5E93"))), create2 && /* @__PURE__ */ import_react8.default.createElement(NewRepositoryForm, { busy: !!busy, apiCall: post2, upload: (file) => call("upload", { method: "POST", body: file, headers: { "x-file-name": encodeURIComponent(file.name), "x-file-purpose": "intro", "Content-Type": "application/octet-stream" } }), onPrepare: (args) => act("\u6B63\u5728\u51C6\u5907\u4ED3\u5E93", () => prepare("create_repository", args)) }), selected ? /* @__PURE__ */ import_react8.default.createElement(import_react8.default.Fragment, null, /* @__PURE__ */ import_react8.default.createElement("button", { className: "gh-back", onClick: () => {
|
package/lib/core.js
CHANGED
|
@@ -14,11 +14,12 @@ const repoPath=a=>`/repos/${enc(segment(a.owner,'账号'))}/${enc(segment(a.repo
|
|
|
14
14
|
const filePath=s=>{if(typeof s!=='string'||s.length>600||s.startsWith('/')||s.includes('\\')||s.split('/').some(p=>!p||p==='.'||p==='..')||/[\x00-\x1f]/.test(s))throw Error('文件路径无效。');return s;};
|
|
15
15
|
export class GitHub {
|
|
16
16
|
constructor({auth,fetchImpl=fetch,base='https://api.github.com',uploadBase='https://uploads.github.com',diagnostics=()=>{}}={}){this.auth=auth;this.fetch=fetchImpl;this.base=base;this.uploadBase=uploadBase;this.diagnostics=diagnostics;}
|
|
17
|
-
async request(route,{method='GET',body,token,signal,raw=false,headers={}}={}){
|
|
17
|
+
async request(route,{method='GET',body,token,signal,raw=false,headers={},reauthenticated=false}={}){
|
|
18
18
|
token??=await this.auth.token();
|
|
19
|
-
let response;try{response=await this.fetch(this.base+route,{method,headers:{Accept:'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28','User-Agent':'dsh-github-connect',Authorization:`Bearer ${token}`,...(body!==undefined?{'Content-Type':'application/json'}:{}),...headers},body:body===undefined?undefined:JSON.stringify(body),signal:signal??AbortSignal.timeout(45000),redirect:'error'});}catch(e){this.diagnostics('api_failure',{category:requestCategory(route),reason:['TimeoutError','AbortError'].includes(e.name)?'timeout':'network_error'});throw e;}
|
|
19
|
+
let response;try{response=await this.fetch(this.base+route,{method,headers:{Accept:'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28','User-Agent':'dsh-github-connect',Authorization:`Bearer ${token}`,...(body!==undefined?{'Content-Type':'application/json'}:{}),...headers},body:body===undefined?undefined:JSON.stringify(body),signal:signal??AbortSignal.timeout(45000),redirect:'error'});}catch(e){this.diagnostics('api_failure',{category:requestCategory(route),reason:e.reason??(['TimeoutError','AbortError'].includes(e.name)?'timeout':'network_error')});throw e;}
|
|
20
20
|
this.diagnostics('api_response',{category:requestCategory(route),status:response.status,reason:response.ok?'ok':response.status===401?'invalid_credentials':response.status===429||response.headers.get('x-ratelimit-remaining')==='0'?'rate_limited':response.status===403?'forbidden':response.status>=500?'server_error':undefined});
|
|
21
|
-
if(!response.
|
|
21
|
+
if(!reauthenticated&&response.status===401&&['GET','HEAD'].includes(method)&&token!==undefined&&this.auth.refreshAfter401){const renewed=await this.auth.refreshAfter401(token);if(renewed&&renewed!==token){await response.body?.cancel();return this.request(route,{method,body,token:renewed,signal,raw,headers,reauthenticated:true});}}
|
|
22
|
+
if(!response.ok){let info={};try{info=await response.json();}catch{}const e=Error(`GitHub 请求失败(${response.status}):${String(info.message??'请检查授权和网络').slice(0,400)}`);e.status=response.status;if(response.status===401)e.message='GitHub 登录凭据已失效(401),请点击登录 GitHub 重新授权。';if(response.status===429||(response.status===403&&(response.headers.get('x-ratelimit-remaining')==='0'||/rate limit/i.test(info.message??'')))){const retry=Number(response.headers.get('retry-after')),reset=Number(response.headers.get('x-ratelimit-reset'));const seconds=retry>0?Math.ceil(retry):reset>0?Math.max(1,Math.ceil(reset-Date.now()/1000)):60;e.message='GitHub 请求频率已受限,请等待约 '+seconds+' 秒后重试,不要连续请求。';}throw e;}
|
|
22
23
|
if(response.status===204)return {};
|
|
23
24
|
if(raw)return response;
|
|
24
25
|
return response.json();
|
package/lib/core.mjs
CHANGED
|
@@ -14,11 +14,12 @@ const repoPath=a=>`/repos/${enc(segment(a.owner,'账号'))}/${enc(segment(a.repo
|
|
|
14
14
|
const filePath=s=>{if(typeof s!=='string'||s.length>600||s.startsWith('/')||s.includes('\\')||s.split('/').some(p=>!p||p==='.'||p==='..')||/[\x00-\x1f]/.test(s))throw Error('文件路径无效。');return s;};
|
|
15
15
|
export class GitHub {
|
|
16
16
|
constructor({auth,fetchImpl=fetch,base='https://api.github.com',uploadBase='https://uploads.github.com',diagnostics=()=>{}}={}){this.auth=auth;this.fetch=fetchImpl;this.base=base;this.uploadBase=uploadBase;this.diagnostics=diagnostics;}
|
|
17
|
-
async request(route,{method='GET',body,token,signal,raw=false,headers={}}={}){
|
|
17
|
+
async request(route,{method='GET',body,token,signal,raw=false,headers={},reauthenticated=false}={}){
|
|
18
18
|
token??=await this.auth.token();
|
|
19
|
-
let response;try{response=await this.fetch(this.base+route,{method,headers:{Accept:'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28','User-Agent':'dsh-github-connect',Authorization:`Bearer ${token}`,...(body!==undefined?{'Content-Type':'application/json'}:{}),...headers},body:body===undefined?undefined:JSON.stringify(body),signal:signal??AbortSignal.timeout(45000),redirect:'error'});}catch(e){this.diagnostics('api_failure',{category:requestCategory(route),reason:['TimeoutError','AbortError'].includes(e.name)?'timeout':'network_error'});throw e;}
|
|
19
|
+
let response;try{response=await this.fetch(this.base+route,{method,headers:{Accept:'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28','User-Agent':'dsh-github-connect',Authorization:`Bearer ${token}`,...(body!==undefined?{'Content-Type':'application/json'}:{}),...headers},body:body===undefined?undefined:JSON.stringify(body),signal:signal??AbortSignal.timeout(45000),redirect:'error'});}catch(e){this.diagnostics('api_failure',{category:requestCategory(route),reason:e.reason??(['TimeoutError','AbortError'].includes(e.name)?'timeout':'network_error')});throw e;}
|
|
20
20
|
this.diagnostics('api_response',{category:requestCategory(route),status:response.status,reason:response.ok?'ok':response.status===401?'invalid_credentials':response.status===429||response.headers.get('x-ratelimit-remaining')==='0'?'rate_limited':response.status===403?'forbidden':response.status>=500?'server_error':undefined});
|
|
21
|
-
if(!response.
|
|
21
|
+
if(!reauthenticated&&response.status===401&&['GET','HEAD'].includes(method)&&token!==undefined&&this.auth.refreshAfter401){const renewed=await this.auth.refreshAfter401(token);if(renewed&&renewed!==token){await response.body?.cancel();return this.request(route,{method,body,token:renewed,signal,raw,headers,reauthenticated:true});}}
|
|
22
|
+
if(!response.ok){let info={};try{info=await response.json();}catch{}const e=Error(`GitHub 请求失败(${response.status}):${String(info.message??'请检查授权和网络').slice(0,400)}`);e.status=response.status;if(response.status===401)e.message='GitHub 登录凭据已失效(401),请点击登录 GitHub 重新授权。';if(response.status===429||(response.status===403&&(response.headers.get('x-ratelimit-remaining')==='0'||/rate limit/i.test(info.message??'')))){const retry=Number(response.headers.get('retry-after')),reset=Number(response.headers.get('x-ratelimit-reset'));const seconds=retry>0?Math.ceil(retry):reset>0?Math.max(1,Math.ceil(reset-Date.now()/1000)):60;e.message='GitHub 请求频率已受限,请等待约 '+seconds+' 秒后重试,不要连续请求。';}throw e;}
|
|
22
23
|
if(response.status===204)return {};
|
|
23
24
|
if(raw)return response;
|
|
24
25
|
return response.json();
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {spawn} from 'node:child_process';
|
|
2
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
3
|
+
import {mkdir,readFile,rename,stat,unlink,writeFile} from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
export function command(executable, args, {input = '', timeout = 30000} = {}) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const child = spawn(executable, args, {windowsHide: true, stdio: ['pipe', 'pipe', 'ignore']});
|
|
9
|
+
let stdout = '';
|
|
10
|
+
child.stdout.setEncoding('utf8');
|
|
11
|
+
child.stdout.on('data', chunk => { stdout += chunk; });
|
|
12
|
+
let timedOut = false;
|
|
13
|
+
const timer = setTimeout(() => {
|
|
14
|
+
timedOut = true;
|
|
15
|
+
child.kill('SIGKILL');
|
|
16
|
+
}, timeout);
|
|
17
|
+
child.on('error', error => { clearTimeout(timer); reject(error); });
|
|
18
|
+
child.on('close', code => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
if (timedOut) reject(Error('凭据操作超时。'));
|
|
21
|
+
else resolve({code, stdout});
|
|
22
|
+
});
|
|
23
|
+
child.stdin.on('error', () => {});
|
|
24
|
+
child.stdin.end(input);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function windowsSeal(action, value) {
|
|
29
|
+
if (process.platform !== 'win32') throw Error('DPAPI 仅在 Windows 上可用。');
|
|
30
|
+
const operation = action === 'protect' ? 'Protect' : 'Unprotect';
|
|
31
|
+
const script = `$ErrorActionPreference='Stop'; Add-Type -AssemblyName System.Security; $b=[Convert]::FromBase64String([Console]::In.ReadToEnd().Trim()); $r=[Security.Cryptography.ProtectedData]::${operation}($b,$null,[Security.Cryptography.DataProtectionScope]::CurrentUser); [Console]::Write([Convert]::ToBase64String($r))`;
|
|
32
|
+
const result = await command('powershell.exe', ['-NoProfile','-NonInteractive','-Command',script], {
|
|
33
|
+
input: action === 'protect' ? Buffer.from(value, 'utf8').toString('base64') : value
|
|
34
|
+
});
|
|
35
|
+
if (result.code !== 0) throw Error('Windows 凭据保护操作失败。');
|
|
36
|
+
return action === 'protect' ? result.stdout.trim() : Buffer.from(result.stdout.trim(), 'base64').toString('utf8');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fileCredentialStore(root, seal = windowsSeal) {
|
|
40
|
+
const filename = path.join(root, 'credential.dpapi');
|
|
41
|
+
return {
|
|
42
|
+
async exists() {
|
|
43
|
+
try { return (await stat(filename)).isFile(); }
|
|
44
|
+
catch (error) { if (error.code === 'ENOENT') return false; throw error; }
|
|
45
|
+
},
|
|
46
|
+
async read() {
|
|
47
|
+
let encrypted;
|
|
48
|
+
try { encrypted = await readFile(filename, 'utf8'); }
|
|
49
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
50
|
+
try { return await seal('unprotect', encrypted); }
|
|
51
|
+
catch {
|
|
52
|
+
throw Object.assign(Error('本机 GitHub 凭据无法解密,请重新连接。'), {
|
|
53
|
+
status: 401, reason: 'decrypt_failed', hasCredential: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
async write(plain, beforeCommit = () => {}) {
|
|
58
|
+
const encrypted = await seal('protect', plain);
|
|
59
|
+
await mkdir(root, {recursive: true});
|
|
60
|
+
const temp = path.join(root, 'credential-' + randomUUID() + '.tmp');
|
|
61
|
+
try {
|
|
62
|
+
await writeFile(temp, encrypted, {mode: 0o600, flag: 'wx'});
|
|
63
|
+
beforeCommit();
|
|
64
|
+
await rename(temp, filename);
|
|
65
|
+
} finally { await unlink(temp).catch(() => {}); }
|
|
66
|
+
},
|
|
67
|
+
async remove() {
|
|
68
|
+
try { await unlink(filename); }
|
|
69
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The security tool returns the low byte of errSecItemNotFound (-25300).
|
|
75
|
+
const itemNotFound = 44;
|
|
76
|
+
const keychainError = () => Object.assign(
|
|
77
|
+
Error('无法访问 macOS 钥匙串。请确认登录钥匙串已解锁,并允许访问 DeepSeek GitHub Studio 的凭据。'),
|
|
78
|
+
{status: 503, reason: 'keychain_unavailable'}
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
export function macCredentialStore(root, {run = command, keychain} = {}) {
|
|
82
|
+
const service = 'DeepSeek GitHub Studio';
|
|
83
|
+
// Different DSH_HOME directories must not share a Keychain item.
|
|
84
|
+
const account = createHash('sha256').update(path.resolve(root)).digest('hex');
|
|
85
|
+
const identity = ['-s', service, '-a', account];
|
|
86
|
+
const keychains = keychain ? [keychain] : [];
|
|
87
|
+
async function security(args, options) {
|
|
88
|
+
try { return await run('/usr/bin/security', args, options); }
|
|
89
|
+
catch { throw keychainError(); }
|
|
90
|
+
}
|
|
91
|
+
async function find(passwordOnly) {
|
|
92
|
+
const flags = passwordOnly ? ['-w'] : [];
|
|
93
|
+
const result = await security(['find-generic-password', ...flags, ...identity, ...keychains]);
|
|
94
|
+
if (result.code === itemNotFound) return null;
|
|
95
|
+
if (result.code !== 0) throw keychainError();
|
|
96
|
+
return result.stdout;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
async exists() { return (await find(false)) !== null; },
|
|
100
|
+
async read() {
|
|
101
|
+
const result = await find(true);
|
|
102
|
+
if (result === null) return null;
|
|
103
|
+
const encoded = result.trim();
|
|
104
|
+
if (!/^v1\.[A-Za-z0-9+/]+={0,2}$/.test(encoded)) {
|
|
105
|
+
throw Object.assign(Error('钥匙串中的 GitHub 凭据格式无效,请重新登录。'), {
|
|
106
|
+
status: 401, reason: 'invalid_local', hasCredential: true
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return Buffer.from(encoded.slice(3), 'base64').toString('utf8');
|
|
110
|
+
},
|
|
111
|
+
async write(plain, beforeCommit = () => {}) {
|
|
112
|
+
// Pass the credential through a pipe, never through the process arguments.
|
|
113
|
+
const encoded = 'v1.' + Buffer.from(plain, 'utf8').toString('base64');
|
|
114
|
+
const args = [...identity, '-U', '-w', encoded, ...keychains];
|
|
115
|
+
if (args.some(arg => /[\r\n\0]/.test(arg))) throw keychainError();
|
|
116
|
+
const quoted = args.map(arg => '"' + arg.replace(/["\\]/g, '\\$&') + '"');
|
|
117
|
+
const input = 'add-generic-password ' + quoted.join(' ') + '\n';
|
|
118
|
+
if (Buffer.byteLength(input) >= 4095) throw Error('GitHub 凭据过长,无法保存到 macOS 钥匙串。');
|
|
119
|
+
beforeCommit();
|
|
120
|
+
const result = await security(['-q', '-i'], {input});
|
|
121
|
+
if (result.code !== 0) throw keychainError();
|
|
122
|
+
},
|
|
123
|
+
async remove() {
|
|
124
|
+
const result = await security(['delete-generic-password', ...identity, ...keychains]);
|
|
125
|
+
if (result.code !== 0 && result.code !== itemNotFound) throw keychainError();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The Android guest runs Linux and exposes Harness's managed credential provider.
|
|
131
|
+
// Keep its record separate from model credentials and desktop credential stores.
|
|
132
|
+
const harnessCredentialKey = 'github-connect/github-oauth';
|
|
133
|
+
|
|
134
|
+
export function harnessCredentialStore(getProvider) {
|
|
135
|
+
function provider() {
|
|
136
|
+
const service = getProvider();
|
|
137
|
+
if (!service || ['describeRecord', 'readRecord', 'modifyRecord', 'deleteRecord'].some(
|
|
138
|
+
method => typeof service[method] !== 'function'
|
|
139
|
+
)) {
|
|
140
|
+
throw Object.assign(Error('Harness 凭据服务不可用,请检查当前主机或重启引擎。'), {status: 503});
|
|
141
|
+
}
|
|
142
|
+
return service;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
async exists() {
|
|
146
|
+
return (await provider().describeRecord(harnessCredentialKey)).configured === true;
|
|
147
|
+
},
|
|
148
|
+
async read() {
|
|
149
|
+
const record = await provider().readRecord(harnessCredentialKey);
|
|
150
|
+
if (record === undefined) return null;
|
|
151
|
+
if (record.kind !== 'grant' || typeof record.payload?.access_token !== 'string') {
|
|
152
|
+
throw Object.assign(Error('GitHub 登录记录无效,请重新授权。'), {
|
|
153
|
+
status: 401, reason: 'invalid_local', hasCredential: true
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return JSON.stringify(record.payload);
|
|
157
|
+
},
|
|
158
|
+
async write(plain, beforeCommit = () => {}) {
|
|
159
|
+
const payload = JSON.parse(plain);
|
|
160
|
+
await provider().modifyRecord(harnessCredentialKey, async () => {
|
|
161
|
+
beforeCommit();
|
|
162
|
+
return {kind: 'grant', payload};
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
async remove() { await provider().deleteRecord(harnessCredentialKey); }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function credentialStore(root, seal) {
|
|
170
|
+
if (seal || process.platform === 'win32') return fileCredentialStore(root, seal);
|
|
171
|
+
if (process.platform === 'darwin') return macCredentialStore(root);
|
|
172
|
+
const unsupported = () => { throw Error('此主机缺少受支持的 GitHub 凭据存储。'); };
|
|
173
|
+
return {exists: async () => false, read: unsupported, write: unsupported, remove: unsupported};
|
|
174
|
+
}
|