dsh-workbuddy-login-ui 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-workbuddy-bridge contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Temporary Holding Version
1
+ # dsh-workbuddy-login-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 在 [DeepSeek Harness](https://github.com/deepseek-ai)(DSH)的**插件详情页**直接登录 WorkBuddy 账号。
4
+
5
+ ## 它解决什么问题
6
+
7
+ WorkBuddy 账号桥(`dsh-workbuddy-bridge-mobile`)登录本来是「对助手说一句话」触发 `wb_login` 工具。但如果你的默认模型正指向 WorkBuddy,就会卡死:
8
+
9
+ ```
10
+ 要登录 WorkBuddy → 得先发一条消息
11
+ ↓
12
+ 但默认模型是 WorkBuddy
13
+ ↓
14
+ 没登录 = 没额度 = 发不出去
15
+ ↓
16
+ 永远登录不了
17
+ ```
18
+
19
+ 这个插件把登录搬到**插件详情页的按钮**上,走 OAuth device flow,**完全不经过模型**,所以没有这个死锁。
20
+
21
+ ## 安装
22
+
23
+ 在 DSH 插件页填入包名即可:
24
+
25
+ ```
26
+ dsh-workbuddy-login-ui
27
+ ```
28
+
29
+ 装完重启一次 DSH。
30
+
31
+ ## 使用
32
+
33
+ 1. 打开 **插件** 页
34
+ 2. 找到 **WorkBuddy 登录**,点进详情
35
+ 3. 点 **「登录 WorkBuddy」** 按钮
36
+ 4. 页面给出授权链接(也会自动尝试打开新窗口)
37
+ 5. 在浏览器登录 WorkBuddy 账号并确认授权
38
+ 6. 插件在后台每 3 秒轮询一次,拿到 token 后自动写入
39
+ 7. 状态变为「已登录:<昵称>」
40
+
41
+ 拿到 token 后,回到 WorkBuddy 账号桥执行一次模型同步,模型选择器里就会出现 `workbuddy` 提供商。
42
+
43
+ ## 已经登录过会怎样
44
+
45
+ 插件读的是同一个 token 文件(`~/.wb-bridge/auth.json`),所以账号桥登录过的话,这里会直接显示已登录,不会重复登录。
46
+
47
+ ## 配置
48
+
49
+ 插件行的 `config`:
50
+
51
+ ```yaml
52
+ - id: workbuddy-login
53
+ name: dsh-workbuddy-login-ui
54
+ config:
55
+ realm: cn # cn = workbuddy.cn / codebuddy.cn;global = workbuddy.ai
56
+ timeoutMs: 900000 # 等待授权的最长时间(毫秒)
57
+ ```
58
+
59
+ ## 提供的接口
60
+
61
+ Host 侧暴露三个方法给界面(Cordis 服务键 `workbuddyLogin`):
62
+
63
+ | 方法 | 作用 |
64
+ |---|---|
65
+ | `startSignIn()` | 取授权链接并开始后台轮询,返回 `{ ok, url, state, expiresInMs }` |
66
+ | `getState()` | 返回 `{ loggedIn, nickname, uid, pendingUrl, pendingExpiresInMs, lastError }` |
67
+ | `cancelSignIn()` | 取消等待 |
68
+
69
+ ## 变更记录
70
+
71
+ ### 1.0.1
72
+
73
+ - 修正:按钮在插件详情页不显示。`plugins.detail.actions` 的 `subject` 结构是 `{ kind: 'item', id }`,没有 `name` 字段;改为按 `subject.id` 匹配。
74
+ - 修正:客户端 `inject` 补上 `remote` 和 `remote.workbuddyLogin`,否则取不到 Host 服务。
75
+ - 改为用 slot 的 `inject: () => ({ service })` 标准方式传服务,不再依赖闭包。
76
+
77
+ ### 1.0.0
78
+
79
+ - 首个版本。
80
+
81
+ ## 依赖
82
+
83
+ - DSH 已安装(提供 `@deepseek-ai/dsh-typert-protocol`)
84
+ - Node.js 18+(用内置 `fetch`)
85
+ - 不需要 Python,不需要 API key
86
+
87
+ ## 实现说明
88
+
89
+ Node 原生不支持 TC39 装饰器语法,而 DSH 官方包都是编译产物。本插件继承 `TypertRemoteService`,并用 `markRemote()` 手动写入与 `@Remote` 装饰器等价的 `REMOTE_METHOD_DESCRIPTOR`,因此可以直接以源码形式发布。
90
+
91
+ ## 许可证
92
+
93
+ MIT。见 [LICENSE](LICENSE)。
94
+
95
+ ## 免责声明
96
+
97
+ 本项目非官方,与腾讯、WorkBuddy、CodeBuddy 及其关联公司没有任何关系,未获其授权或认可。登录的是你自己的账号,使用的是你自己的账号额度。**使用风险自负**——包括但不限于账号受限、服务中断等情况。
@@ -0,0 +1,6 @@
1
+ - insert:
2
+ - id: workbuddy-login
3
+ name: dsh-workbuddy-login-ui
4
+ config:
5
+ realm: cn
6
+ timeoutMs: 900000
package/icon.svg ADDED
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="WorkBuddy login">
2
+ <rect width="64" height="64" rx="14" fill="#247bbf"/>
3
+ <circle cx="32" cy="26" r="9" fill="#fff" opacity="0.95"/>
4
+ <path d="M16 50c0-8.8 7.2-14 16-14s16 5.2 16 14" fill="#fff" opacity="0.95"/>
5
+ <circle cx="46" cy="46" r="10" fill="#33c07a"/>
6
+ <path d="M41.5 46.2l3.2 3.2 6-6.4" fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/>
7
+ </svg>
package/lib/client.js ADDED
@@ -0,0 +1,132 @@
1
+ /**
2
+ * WorkBuddy 登录 UI —— 客户端
3
+ *
4
+ * 在「插件详情页」的 actions 区放登录按钮。
5
+ * 走 OAuth device flow,不经过模型 —— 所以没有「没登录就没模型可用」的死锁。
6
+ */
7
+ window.__ModuleLoader__.load({
8
+ id: 'dsh-workbuddy-login-ui',
9
+ factory(require) {
10
+ const React = require('react');
11
+ const h = React.createElement;
12
+ const { useState, useEffect, useCallback } = React;
13
+
14
+ const S = {
15
+ wrap: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
16
+ btn: {
17
+ appearance: 'none', border: '1px solid currentColor', borderRadius: 6,
18
+ background: 'transparent', color: 'inherit', cursor: 'pointer',
19
+ font: 'inherit', fontSize: 13, padding: '4px 12px', lineHeight: 1.5,
20
+ },
21
+ btnPrimary: { background: '#247bbf', borderColor: '#247bbf', color: '#fff' },
22
+ link: {
23
+ fontSize: 12, color: '#247bbf', wordBreak: 'break-all',
24
+ textDecoration: 'underline',
25
+ },
26
+ ok: { fontSize: 12, opacity: 0.75 },
27
+ err: { fontSize: 12, color: '#c0392b' },
28
+ };
29
+
30
+ /** 登录按钮。service 由 slot 的 inject 注入。 */
31
+ function LoginAction(props) {
32
+ const svc = props?.service;
33
+ const [state, setState] = useState(null);
34
+ const [busy, setBusy] = useState(false);
35
+ const [localErr, setLocalErr] = useState('');
36
+
37
+ const refresh = useCallback(async () => {
38
+ if (!svc?.getState) return;
39
+ try {
40
+ const s = await svc.getState();
41
+ setState(s);
42
+ } catch (e) {
43
+ setLocalErr(String(e?.message ?? e));
44
+ }
45
+ }, [svc]);
46
+
47
+ useEffect(() => {
48
+ if (!svc) return undefined;
49
+ refresh();
50
+ const t = setInterval(refresh, 2000);
51
+ return () => clearInterval(t);
52
+ }, [svc, refresh]);
53
+
54
+ if (!svc) {
55
+ return h('div', { style: S.wrap },
56
+ h('span', { style: S.err }, '登录服务未就绪(请重启 DSH)'));
57
+ }
58
+
59
+ const onLogin = async () => {
60
+ setBusy(true);
61
+ setLocalErr('');
62
+ try {
63
+ const r = await svc.startSignIn();
64
+ if (r?.ok && r.url) {
65
+ window.open(r.url, '_blank', 'noopener,noreferrer');
66
+ } else if (r?.error) {
67
+ setLocalErr(r.error);
68
+ }
69
+ await refresh();
70
+ } catch (e) {
71
+ setLocalErr(String(e?.message ?? e));
72
+ } finally {
73
+ setBusy(false);
74
+ }
75
+ };
76
+
77
+ const err = localErr || state?.lastError || '';
78
+
79
+ if (state?.loggedIn) {
80
+ return h('div', { style: S.wrap },
81
+ h('span', { style: S.ok }, `已登录:${state.nickname || state.uid || 'WorkBuddy 账号'}`),
82
+ h('button', {
83
+ type: 'button', style: S.btn,
84
+ onClick: async () => {
85
+ try { await svc.cancelSignIn?.(); } catch { /* 忽略 */ }
86
+ await onLogin();
87
+ },
88
+ }, '重新登录'),
89
+ );
90
+ }
91
+
92
+ const waiting = Boolean(state?.pendingUrl);
93
+ const mins = Math.max(0, Math.ceil((state?.pendingExpiresInMs || 0) / 60000));
94
+
95
+ return h('div', { style: S.wrap },
96
+ h('button', {
97
+ type: 'button',
98
+ style: { ...S.btn, ...S.btnPrimary },
99
+ disabled: busy,
100
+ onClick: onLogin,
101
+ }, busy ? '获取中…' : waiting ? '等待授权…' : '登录 WorkBuddy'),
102
+ waiting
103
+ ? h('a', {
104
+ href: state.pendingUrl, target: '_blank', rel: 'noopener noreferrer',
105
+ style: S.link,
106
+ }, '点此打开授权页')
107
+ : null,
108
+ waiting && mins
109
+ ? h('span', { style: S.ok }, `${mins} 分钟内有效`)
110
+ : null,
111
+ err ? h('span', { style: S.err }, err) : null,
112
+ );
113
+ }
114
+
115
+ return {
116
+ inject: ['slots', 'remote', 'remote.workbuddyLogin'],
117
+ apply(ctx) {
118
+ ctx.slots.inject('plugins.detail.actions', () => ctx.slots.register({
119
+ name: 'plugins.detail.actions',
120
+ id: 'workbuddy-login',
121
+ order: 10,
122
+ inject: () => ({ service: ctx.remote?.workbuddyLogin }),
123
+ }, (props) => {
124
+ // subject 是 { kind: 'item', id },没有 name
125
+ const id = String(props?.subject?.id ?? '');
126
+ if (!/workbuddy/i.test(id)) return null;
127
+ return h(LoginAction, props);
128
+ }));
129
+ },
130
+ };
131
+ },
132
+ });
package/lib/index.js ADDED
@@ -0,0 +1,221 @@
1
+ /**
2
+ * WorkBuddy 登录 UI —— Host 侧服务
3
+ *
4
+ * 提供三个方法给客户端(插件详情页)直接调用:
5
+ * startSignIn() 取授权链接,并在后台轮询 token
6
+ * getState() 登录状态
7
+ * cancelSignIn() 取消等待
8
+ *
9
+ * 流程是 OAuth device flow(与 wb_bridge.py 的 login 一致):
10
+ * POST /v2/plugin/auth/state?platform=CLI -> state + authUrl
11
+ * 用户在浏览器授权
12
+ * GET /v2/plugin/auth/token?state=xxx -> accessToken
13
+ *
14
+ * 这条链路**完全不经过模型**,所以不存在「要先能对话才能登录」的死锁。
15
+ *
16
+ * 实现说明:Node 原生不支持 TC39 装饰器语法,DSH 自己的包都是编译产物。
17
+ * 这里继承 TypertRemoteService 并用 markRemote() 手动写入与 @Remote 等价的
18
+ * 方法描述符(REMOTE_METHOD_DESCRIPTOR)。
19
+ */
20
+ import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
21
+ import { homedir } from "node:os";
22
+ import { join } from "node:path";
23
+ import { mkdirSync, readFileSync, writeFileSync, chmodSync } from "node:fs";
24
+
25
+ const DESCRIPTOR_KEY = "@deepseek-ai/dsh-typert-protocol/remote-methods";
26
+
27
+ const STATE_DIR = join(homedir(), ".wb-bridge");
28
+ const AUTH_FILE = join(STATE_DIR, "auth.json");
29
+
30
+ const BASES = {
31
+ cn: "https://copilot.tencent.com",
32
+ global: "https://www.workbuddy.ai",
33
+ };
34
+
35
+ const UA =
36
+ "Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36";
37
+
38
+ function hdrs(realm) {
39
+ const origin = BASES[realm] || BASES.cn;
40
+ return {
41
+ Accept: "application/json",
42
+ "Content-Type": "application/json",
43
+ "User-Agent": UA,
44
+ Origin: origin,
45
+ Referer: `${origin}/`,
46
+ };
47
+ }
48
+
49
+ function saveAuth(auth) {
50
+ mkdirSync(STATE_DIR, { recursive: true, mode: 0o700 });
51
+ writeFileSync(AUTH_FILE, JSON.stringify(auth, null, 1), { mode: 0o600 });
52
+ try { chmodSync(AUTH_FILE, 0o600); } catch { /* 已限制 */ }
53
+ }
54
+
55
+ function loadAuth() {
56
+ try {
57
+ const d = JSON.parse(readFileSync(AUTH_FILE, "utf-8"));
58
+ return d?.access_token ? d : null;
59
+ } catch {
60
+ return null;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * 把 prototype 上的方法标记为 Remote,等价于 @Remote 装饰器。
66
+ * 结构须与 dsh-typert-protocol 的 mark() 写入的一致。
67
+ */
68
+ function markRemote(prototype, method) {
69
+ const existing = Object.getOwnPropertyDescriptor(prototype, DESCRIPTOR_KEY);
70
+ const methods = existing ? [...existing.value.methods] : [];
71
+ if (methods.some((m) => m.method === method)) return;
72
+ methods.push(Object.freeze({ method, invocation: Object.freeze({ kind: "direct" }) }));
73
+ Object.defineProperty(prototype, DESCRIPTOR_KEY, {
74
+ configurable: true,
75
+ value: Object.freeze({
76
+ version: 1,
77
+ methods: Object.freeze(methods),
78
+ }),
79
+ });
80
+ }
81
+
82
+ /** 登录服务。客户端通过 ctx.remote.<serviceKey> 调用。 */
83
+ export class WorkBuddyLogin extends TypertRemoteService {
84
+ constructor(ctx, config = {}) {
85
+ super(ctx, "workbuddyLogin", {});
86
+ this.realm = config?.realm === "global" ? "global" : "cn";
87
+ this.timeoutMs = Number(config?.timeoutMs) || 900_000;
88
+ this.pending = null; // { state, url, deadline }
89
+ this.timer = null;
90
+ this.lastError = "";
91
+ }
92
+
93
+ // ---------------------------------------------------------- Remote 方法
94
+
95
+ async startSignIn() {
96
+ const base = BASES[this.realm] || BASES.cn;
97
+ const h = hdrs(this.realm);
98
+ let env = {};
99
+ let status = 0;
100
+ try {
101
+ const res = await fetch(`${base}/v2/plugin/auth/state?platform=CLI`, {
102
+ method: "POST",
103
+ headers: h,
104
+ body: "{}",
105
+ });
106
+ status = res.status;
107
+ env = await res.json().catch(() => ({}));
108
+ } catch (e) {
109
+ this.lastError = `网络错误: ${String(e?.message ?? e)}`;
110
+ return { ok: false, error: this.lastError };
111
+ }
112
+
113
+ const data = env?.data || {};
114
+ const state = data.state;
115
+ const url = data.authUrl;
116
+ if (!state || !url) {
117
+ this.lastError = `取授权链接失败: HTTP ${status}`;
118
+ return { ok: false, error: this.lastError };
119
+ }
120
+
121
+ this.pending = { state, url, deadline: Date.now() + this.timeoutMs };
122
+ this.lastError = "";
123
+ this.#startPolling();
124
+ return { ok: true, url, state, expiresInMs: this.timeoutMs };
125
+ }
126
+
127
+ async getState() {
128
+ const auth = loadAuth();
129
+ const p = this.pending;
130
+ return {
131
+ loggedIn: Boolean(auth?.access_token),
132
+ nickname: auth?.nickname || "",
133
+ uid: auth?.uid || "",
134
+ realm: auth?.realm || this.realm,
135
+ expiresAt: auth?.expires_at || 0,
136
+ pendingUrl: p ? p.url : "",
137
+ pendingState: p ? p.state : "",
138
+ pendingExpiresInMs: p ? Math.max(0, p.deadline - Date.now()) : 0,
139
+ lastError: this.lastError,
140
+ };
141
+ }
142
+
143
+ async cancelSignIn() {
144
+ this.#stopPolling();
145
+ this.pending = null;
146
+ return { ok: true };
147
+ }
148
+
149
+ // ---------------------------------------------------------- 轮询
150
+
151
+ #startPolling() {
152
+ this.#stopPolling();
153
+ const tick = async () => {
154
+ const p = this.pending;
155
+ if (!p) return;
156
+ if (Date.now() > p.deadline) {
157
+ this.lastError = "等待授权超时";
158
+ this.pending = null;
159
+ this.#stopPolling();
160
+ return;
161
+ }
162
+ const base = BASES[this.realm] || BASES.cn;
163
+ const h = hdrs(this.realm);
164
+ try {
165
+ const res = await fetch(
166
+ `${base}/v2/plugin/auth/token?state=${encodeURIComponent(p.state)}`,
167
+ { headers: h },
168
+ );
169
+ const env = await res.json().catch(() => ({}));
170
+ const d = env?.data || {};
171
+ if (env?.code === 0 && d.accessToken) {
172
+ const auth = {
173
+ realm: this.realm,
174
+ uid: "",
175
+ nickname: "",
176
+ access_token: d.accessToken,
177
+ refresh_token: d.refreshToken || "",
178
+ expires_at: Math.floor(Date.now() / 1000) + Number(d.expiresIn || 0),
179
+ domain: d.domain || "",
180
+ state: p.state,
181
+ };
182
+ try {
183
+ const r2 = await fetch(
184
+ `${base}/v2/plugin/login/account?state=${encodeURIComponent(p.state)}`,
185
+ { headers: { ...h, Authorization: `Bearer ${d.accessToken}` } },
186
+ );
187
+ const e2 = await r2.json().catch(() => ({}));
188
+ const acct = e2?.data || {};
189
+ auth.uid = acct.uid || acct.userId || "";
190
+ auth.nickname = acct.nickname || acct.name || "";
191
+ if (acct.enterpriseId) auth.enterprise_id = acct.enterpriseId;
192
+ } catch { /* 账号信息可选 */ }
193
+
194
+ saveAuth(auth);
195
+ this.pending = null;
196
+ this.#stopPolling();
197
+ return;
198
+ }
199
+ } catch (e) {
200
+ this.lastError = String(e?.message ?? e);
201
+ }
202
+ this.timer = setTimeout(tick, 3000);
203
+ };
204
+ this.timer = setTimeout(tick, 2000);
205
+ }
206
+
207
+ #stopPolling() {
208
+ if (this.timer) {
209
+ clearTimeout(this.timer);
210
+ this.timer = null;
211
+ }
212
+ }
213
+ }
214
+
215
+ // 标记三个对外方法(等价于 @Remote)
216
+ for (const m of ["startSignIn", "getState", "cancelSignIn"]) {
217
+ markRemote(WorkBuddyLogin.prototype, m);
218
+ }
219
+
220
+ export default WorkBuddyLogin;
221
+ export { markRemote };
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "WorkBuddy login",
4
+ "description": "Sign in to WorkBuddy from the plugin details page. Shows an authorization link and polls for the token in the background, so no working chat model is required first. After signing in, the WorkBuddy model provider fills in on the next model sync."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "WorkBuddy 登录",
4
+ "description": "在插件详情页直接登录 WorkBuddy。点击按钮会取得授权链接并在后台轮询 token,无需先拥有可用的对话模型。登录成功后,同步模型即可在模型选择器里看到 WorkBuddy 的提供商。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "dsh-workbuddy-login-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "type": "module",
5
+ "description": "WorkBuddy 登录界面:在插件详情页直接授权登录,走 OAuth device flow,不需要先有可用的对话模型。",
6
+ "keywords": [
7
+ "dsh",
8
+ "dsh-plugin",
9
+ "workbuddy",
10
+ "codebuddy",
11
+ "login",
12
+ "oauth"
13
+ ],
14
+ "license": "MIT",
15
+ "exports": {
16
+ ".": "./lib/index.js",
17
+ "./client": "./lib/client.js",
18
+ "./locale/*.json": "./locale/*.json",
19
+ "./icon": "./icon.svg"
20
+ },
21
+ "files": [
22
+ "lib/index.js",
23
+ "lib/client.js",
24
+ "cordis.patch.yml",
25
+ "locale/*.json",
26
+ "icon.svg"
27
+ ],
28
+ "dsh": {
29
+ "bundle": {
30
+ "patch": "./cordis.patch.yml"
31
+ },
32
+ "client": {
33
+ "platform": "web",
34
+ "immediately": true,
35
+ "inject": [
36
+ "@deepseek-ai/dsh-client-ui-plugin-manager"
37
+ ]
38
+ }
39
+ }
40
+ }