dsh-workbuddy-login-ui 0.0.0-stage → 1.0.0
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 +21 -0
- package/README.md +84 -2
- package/cordis.patch.yml +6 -0
- package/icon.svg +7 -0
- package/lib/client.js +131 -0
- package/lib/index.js +221 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +38 -4
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,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-workbuddy-login-ui
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
- DSH 已安装(提供 `@deepseek-ai/dsh-typert-protocol`)
|
|
72
|
+
- Node.js 18+(用内置 `fetch`)
|
|
73
|
+
- 不需要 Python,不需要 API key
|
|
74
|
+
|
|
75
|
+
## 实现说明
|
|
76
|
+
|
|
77
|
+
Node 原生不支持 TC39 装饰器语法,而 DSH 官方包都是编译产物。本插件继承 `TypertRemoteService`,并用 `markRemote()` 手动写入与 `@Remote` 装饰器等价的 `REMOTE_METHOD_DESCRIPTOR`,因此可以直接以源码形式发布。
|
|
78
|
+
|
|
79
|
+
## 许可证
|
|
80
|
+
|
|
81
|
+
MIT。见 [LICENSE](LICENSE)。
|
|
82
|
+
|
|
83
|
+
## 免责声明
|
|
84
|
+
|
|
85
|
+
本项目非官方,与腾讯、WorkBuddy、CodeBuddy 及其关联公司没有任何关系,未获其授权或认可。登录的是你自己的账号,使用的是你自己的账号额度。**使用风险自负**——包括但不限于账号受限、服务中断等情况。
|
package/cordis.patch.yml
ADDED
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,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkBuddy 登录 UI —— 客户端
|
|
3
|
+
*
|
|
4
|
+
* 在「插件详情页」的 action 区放一个按钮:
|
|
5
|
+
* - 未登录:显示「登录 WorkBuddy」,点击取授权链接并展示
|
|
6
|
+
* - 已登录:显示昵称 + 退出
|
|
7
|
+
* - 等待中:显示授权链接和倒计时
|
|
8
|
+
*/
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-workbuddy-login-ui',
|
|
11
|
+
factory(require) {
|
|
12
|
+
const React = require('react');
|
|
13
|
+
const h = React.createElement;
|
|
14
|
+
const { useState, useEffect, useCallback } = React;
|
|
15
|
+
|
|
16
|
+
const S = {
|
|
17
|
+
wrap: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
|
|
18
|
+
btn: {
|
|
19
|
+
appearance: 'none', border: '1px solid currentColor', borderRadius: 6,
|
|
20
|
+
background: 'transparent', color: 'inherit', cursor: 'pointer',
|
|
21
|
+
font: 'inherit', padding: '4px 12px', lineHeight: 1.5,
|
|
22
|
+
},
|
|
23
|
+
btnPrimary: { background: '#247bbf', borderColor: '#247bbf', color: '#fff' },
|
|
24
|
+
link: {
|
|
25
|
+
fontSize: 12, color: '#247bbf', wordBreak: 'break-all',
|
|
26
|
+
maxWidth: 320, textDecoration: 'underline',
|
|
27
|
+
},
|
|
28
|
+
ok: { fontSize: 12, opacity: 0.8 },
|
|
29
|
+
err: { fontSize: 12, color: '#c0392b' },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** 登录按钮组件。 */
|
|
33
|
+
function LoginAction(props) {
|
|
34
|
+
const [state, setState] = useState(null);
|
|
35
|
+
const [busy, setBusy] = useState(false);
|
|
36
|
+
|
|
37
|
+
// service 由 DSH 注入(Remote 服务名)
|
|
38
|
+
const svc = props?.service;
|
|
39
|
+
|
|
40
|
+
const refresh = useCallback(async () => {
|
|
41
|
+
if (!svc) return;
|
|
42
|
+
try {
|
|
43
|
+
const s = await svc.getState();
|
|
44
|
+
setState(s);
|
|
45
|
+
} catch { /* 服务未就绪 */ }
|
|
46
|
+
}, [svc]);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
refresh();
|
|
50
|
+
const t = setInterval(refresh, 2000);
|
|
51
|
+
return () => clearInterval(t);
|
|
52
|
+
}, [refresh]);
|
|
53
|
+
|
|
54
|
+
const onLogin = async () => {
|
|
55
|
+
if (!svc) return;
|
|
56
|
+
setBusy(true);
|
|
57
|
+
try {
|
|
58
|
+
const r = await svc.startSignIn();
|
|
59
|
+
if (r?.ok && r.url) {
|
|
60
|
+
// 新窗口打开授权页
|
|
61
|
+
window.open(r.url, '_blank', 'noopener,noreferrer');
|
|
62
|
+
}
|
|
63
|
+
await refresh();
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error('signIn failed', e);
|
|
66
|
+
} finally {
|
|
67
|
+
setBusy(false);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (state === null) return null;
|
|
72
|
+
|
|
73
|
+
if (state.loggedIn) {
|
|
74
|
+
return h('div', { style: S.wrap },
|
|
75
|
+
h('span', { style: S.ok }, `已登录:${state.nickname || state.uid || '账号'}`),
|
|
76
|
+
h('button', {
|
|
77
|
+
type: 'button',
|
|
78
|
+
style: S.btn,
|
|
79
|
+
onClick: async () => {
|
|
80
|
+
await svc.cancelSignIn?.();
|
|
81
|
+
await refresh();
|
|
82
|
+
},
|
|
83
|
+
}, '重新登录'),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const waiting = Boolean(state.pendingUrl);
|
|
88
|
+
const mins = Math.max(0, Math.ceil((state.pendingExpiresInMs || 0) / 60000));
|
|
89
|
+
|
|
90
|
+
return h('div', { style: S.wrap },
|
|
91
|
+
h('button', {
|
|
92
|
+
type: 'button',
|
|
93
|
+
style: { ...S.btn, ...S.btnPrimary },
|
|
94
|
+
disabled: busy,
|
|
95
|
+
onClick: onLogin,
|
|
96
|
+
}, busy ? '获取中…' : waiting ? '等待授权…' : '登录 WorkBuddy'),
|
|
97
|
+
waiting
|
|
98
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2 } },
|
|
99
|
+
h('a', {
|
|
100
|
+
href: state.pendingUrl, target: '_blank', rel: 'noopener noreferrer',
|
|
101
|
+
style: S.link,
|
|
102
|
+
}, '点此打开授权页'),
|
|
103
|
+
h('span', { style: S.ok }, `或复制链接 · ${mins} 分钟内有效`),
|
|
104
|
+
)
|
|
105
|
+
: null,
|
|
106
|
+
state.lastError
|
|
107
|
+
? h('span', { style: S.err }, state.lastError)
|
|
108
|
+
: null,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
inject: ['slots'],
|
|
114
|
+
apply(ctx) {
|
|
115
|
+
// 插件详情页的操作区
|
|
116
|
+
ctx.slots.inject('plugins.detail.actions', () => ctx.slots.register({
|
|
117
|
+
name: 'plugins.detail.actions',
|
|
118
|
+
id: 'workbuddy-login',
|
|
119
|
+
order: 10,
|
|
120
|
+
}, (props) => {
|
|
121
|
+
// 只对 WorkBuddy 相关插件显示
|
|
122
|
+
const name = props?.subject?.name || '';
|
|
123
|
+
if (!/workbuddy/i.test(name)) return null;
|
|
124
|
+
// 从 ctx 里取 Remote 服务
|
|
125
|
+
const service = ctx.remote?.workbuddyLogin;
|
|
126
|
+
return h(LoginAction, { service });
|
|
127
|
+
}));
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
});
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbuddy-login-ui",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
+
}
|