dsh-qwenwork-connect 0.3.0 → 0.3.2

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 CHANGED
@@ -59,8 +59,20 @@ npx dsh-qwenwork-connect login
59
59
  ```
60
60
  POST /plugins/dsh-qwenwork-connect/login/start
61
61
  GET /plugins/dsh-qwenwork-connect/login/status
62
+ POST /plugins/dsh-qwenwork-connect/logout
62
63
  ```
63
64
 
65
+ **退出登录**在同一张卡片的账号行右侧点「退出登录」,确认后删除
66
+ `~/.dsh/qwenwork-desktop.json`,状态立即回到未登录,可随时重新登录。命令行
67
+ 等价操作是:
68
+
69
+ ```bash
70
+ npx dsh-qwenwork-connect logout
71
+ ```
72
+
73
+ 退出只删凭据文件,保留 `~/.dsh/qwenwork-machine-id`——设备标识不变,重新登录
74
+ 不会换设备。三条路由都只接受本机环回请求。
75
+
64
76
  ## 三个坑
65
77
 
66
78
  **machine_id 必须一致。** 签名头里的 `Cosy-MachineId` 要等于登录时用的那个,
@@ -91,8 +103,10 @@ GET /plugins/dsh-qwenwork-connect/login/status
91
103
 
92
104
  ## 已知限制
93
105
 
94
- - 思考链关不掉。网关侧强制思考,`enable_thinking:false`、
95
- `reasoning_effort:"none"` 这类字段都不生效,只会在输出里多出 reasoning 通道。
106
+ - 思考固定开启,没有档位。网关侧强制思考,请求恒发 `parameters.enable_thinking:true`;
107
+ 上游目录的 `thinking_config` 为 `null`,没有声明任何 effort 档位,插件不提供
108
+ 开关,UI 也不显示推理等级。`enable_thinking:false`、`reasoning_effort:"none"`
109
+ 这类字段上游都不认。
96
110
  - 单次请求的图片预算按网关实测收紧到 6 MB / 32 张;超出时交给宿主的
97
111
  `dsh-compaction-image-offload` 把最旧的图片标成已卸载后重试。宿主没启用
98
112
  这个插件时,图片密集的长会话仍会失败。
package/bin/login.mjs CHANGED
@@ -1,28 +1,48 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * `dsh-qwenwork-connect login` —— 在终端里跑一次 device flow。
3
+ * `dsh-qwenwork-connect login` —— 在终端里跑一次 device flow。
4
+ * `dsh-qwenwork-connect logout` —— 删除本机凭据,退出登录。
4
5
  *
5
- * 打印授权链接,等你在浏览器里选完账号和团队,把 token 写到
6
+ * 登录会打印授权链接,等你在浏览器里选完账号和团队,把 token 写到
6
7
  * `~/.dsh/qwenwork-desktop.json`,插件的下一次请求就会用它。
8
+ * 退出只删除凭据文件,保留 `~/.dsh/qwenwork-machine-id`。
7
9
  */
8
10
 
9
- import { startDeviceLogin, DEFAULT_CREDENTIAL_PATH } from '../lib/login-device-flow.js';
11
+ import fs from 'node:fs';
12
+ import { startDeviceLogin, resolveCredentialPath } from '../lib/login-device-flow.js';
10
13
 
11
14
  const args = process.argv.slice(2);
12
15
  const command = args[0] ?? 'login';
13
16
 
14
17
  if (command === '--help' || command === 'help') {
15
- console.log('用法: dsh-qwenwork-connect login [--credential <path>]');
18
+ console.log('用法: dsh-qwenwork-connect <login|logout> [--credential <path>]');
16
19
  process.exit(0);
17
20
  }
18
21
 
19
- if (command !== 'login') {
22
+ if (command !== 'login' && command !== 'logout') {
20
23
  console.error('未知命令: ' + command);
21
24
  process.exit(1);
22
25
  }
23
26
 
24
27
  const flagIndex = args.indexOf('--credential');
25
- const credentialPath = flagIndex >= 0 ? args[flagIndex + 1] : DEFAULT_CREDENTIAL_PATH;
28
+ const credentialPath = resolveCredentialPath(
29
+ flagIndex >= 0 ? args[flagIndex + 1] : undefined,
30
+ );
31
+
32
+ if (command === 'logout') {
33
+ try {
34
+ fs.unlinkSync(credentialPath);
35
+ console.log('已退出登录,删除 ' + credentialPath);
36
+ } catch (error) {
37
+ if (/** @type {any} */ (error)?.code === 'ENOENT') {
38
+ console.log('当前未登录(凭据文件不存在)');
39
+ } else {
40
+ console.error('退出登录失败: ' + error.message);
41
+ process.exit(1);
42
+ }
43
+ }
44
+ process.exit(0);
45
+ }
26
46
 
27
47
  console.log('打开下面的链接,用已登录千问办公的浏览器继续:\n');
28
48
  const result = await startDeviceLogin({
package/lib/chat-shim.js CHANGED
@@ -487,8 +487,9 @@ export function resolveModelKey(body) {
487
487
  * 其中 `r` 是上游 catalog 返回的**逐模型**记录。插件不动态拉 catalog,等价物是
488
488
  * models.js 的静态目录(其注释注明取自 App `rawModels` 的 `is_vl` 等实测值):
489
489
  * - `is_vl` ← 目录的 `supportsImages`(App `rawModels.is_vl === true`)
490
- * - `is_reasoning` ← 目录的既有声明:models.js 的 `toPiModel()` 对全部模型
491
- * 置 `reasoning: true`(实测上游确实返回 `reasoning_content`)
490
+ * - `is_reasoning` ← 固定 true:思考始终开启,与 models.js 的 `reasoning:false`
491
+ * 不冲突(后者只是让 DSH 不生成推理等级菜单;pi-ai 仍会
492
+ * 解析上游的 `reasoning_content`,思考块照常显示)
492
493
  *
493
494
  * 目录里查不到的模型按 SDK 的兜底取 `false`——不凭空声明能力。注意
494
495
  * `is_reasoning` 还会被 SDK 按 `thinkingBudget === 0` / `reasoning_effort === "none"`
package/lib/client.js CHANGED
@@ -32,6 +32,7 @@ window.__ModuleLoader__.load({
32
32
  /** 设置卡片上的设备码登录(路由在 lib/login-route.js)。 */
33
33
  const LOGIN_START_PATH = '/plugins/dsh-qwenwork-connect/login/start';
34
34
  const LOGIN_STATUS_PATH = '/plugins/dsh-qwenwork-connect/login/status';
35
+ const LOGOUT_PATH = '/plugins/dsh-qwenwork-connect/logout';
35
36
  const LOGIN_POLL_MS = 2000;
36
37
  const LOGIN_WAIT_MS = 180000;
37
38
  //#endregion
@@ -187,6 +188,14 @@ window.__ModuleLoader__.load({
187
188
  fontSize: 13,
188
189
  cursor: 'pointer',
189
190
  };
191
+ /** 账号行右侧的退出按钮:用错误色标出「这是破坏性操作」,但仍需确认。 */
192
+ const logoutButtonStyle = {
193
+ ...refreshButtonStyle,
194
+ marginLeft: 'auto',
195
+ color: 'var(--dsw-alias-state-error-primary, #d92d20)',
196
+ fontSize: 12,
197
+ padding: '3px 10px',
198
+ };
190
199
  const actionRowStyle = {
191
200
  display: 'flex',
192
201
  alignItems: 'center',
@@ -423,6 +432,11 @@ window.__ModuleLoader__.load({
423
432
  if (state === null) {
424
433
  return react_jsx_runtime.jsx('div', { style: errorStyle, children: t('loading') });
425
434
  }
435
+ // 退出登录后 getAccountContext 会抛 CREDENTIALS_MISSING——这是预期状态,
436
+ // 不是故障:顶部已有「尚未登录 + 登录按钮」,不该再甩一段红色报错。
437
+ if (state.status === 'signed-out' && state.error?.code === 'CREDENTIALS_MISSING') {
438
+ return null;
439
+ }
426
440
  if (state.error !== undefined && state.status !== 'signed-in') {
427
441
  const err = state.error;
428
442
  const text = [err.message, err.recovery].filter(Boolean).join('\n');
@@ -443,6 +457,18 @@ window.__ModuleLoader__.load({
443
457
  react_jsx_runtime.jsx('span', {
444
458
  children: t('signedInAs', { name: state.nickname ?? state.account ?? '—' }),
445
459
  }),
460
+ typeof props.onLogout === 'function'
461
+ ? react_jsx_runtime.jsx('button', {
462
+ type: 'button',
463
+ disabled: props.logoutBusy === true,
464
+ style:
465
+ props.logoutBusy === true
466
+ ? { ...logoutButtonStyle, opacity: 0.6, cursor: 'default' }
467
+ : logoutButtonStyle,
468
+ onClick: props.onLogout,
469
+ children: props.logoutBusy === true ? t('loggingOut') : t('logout'),
470
+ })
471
+ : null,
446
472
  ],
447
473
  },
448
474
  'who',
@@ -635,6 +661,8 @@ window.__ModuleLoader__.load({
635
661
  /** 设备码登录的本地阶段:null | { phase, url?, error? }。 */
636
662
  const [login, setLogin] = react.useState(null);
637
663
  const [loginBusy, setLoginBusy] = react.useState(false);
664
+ const [logoutBusy, setLogoutBusy] = react.useState(false);
665
+ const [logoutError, setLogoutError] = react.useState(null);
638
666
 
639
667
  react.useEffect(() => {
640
668
  let cancelled = false;
@@ -742,6 +770,34 @@ window.__ModuleLoader__.load({
742
770
  }
743
771
  };
744
772
 
773
+ /** 退出登录:确认 → 删除本机凭据 → 立即重拉状态(回到未登录)。 */
774
+ const logout = async () => {
775
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function') {
776
+ if (!window.confirm(t('logoutConfirm'))) return;
777
+ }
778
+ setLogoutBusy(true);
779
+ setLogoutError(null);
780
+ try {
781
+ const response = await fetch(LOGOUT_PATH, {
782
+ method: 'POST',
783
+ headers: { accept: 'application/json' },
784
+ credentials: 'same-origin',
785
+ });
786
+ const body = await response.json().catch(() => null);
787
+ if (!response.ok) {
788
+ throw new Error(body?.error ?? `${t('requestFailed')} (HTTP ${response.status})`);
789
+ }
790
+ setLogin(null);
791
+ setNonce((value) => value + 1);
792
+ } catch (error) {
793
+ setLogoutError(
794
+ `${t('logoutFailed')}: ${error instanceof Error ? error.message : String(error)}`,
795
+ );
796
+ } finally {
797
+ setLogoutBusy(false);
798
+ }
799
+ };
800
+
745
801
  const signedIn = state !== null && state.status === 'signed-in';
746
802
  const subtitle = signedIn
747
803
  ? state.remaining === undefined
@@ -785,7 +841,7 @@ window.__ModuleLoader__.load({
785
841
  children: [
786
842
  react_jsx_runtime.jsx('div', {
787
843
  style: { fontSize: 13, lineHeight: '20px', color: 'var(--dsw-alias-label-secondary)' },
788
- children: signedIn ? t('signedIn') : t('subtitle'),
844
+ children: signedIn ? t('signedIn') : t('notSignedIn'),
789
845
  }),
790
846
  react_jsx_runtime.jsxs('div', {
791
847
  style: actionRowStyle,
@@ -850,7 +906,18 @@ window.__ModuleLoader__.load({
850
906
  : null,
851
907
  ],
852
908
  }),
853
- react_jsx_runtime.jsx(StatusBody, { state, t }),
909
+ logoutError === null
910
+ ? null
911
+ : react_jsx_runtime.jsx('div', {
912
+ style: loginPanelStyle,
913
+ children: logoutError,
914
+ }),
915
+ react_jsx_runtime.jsx(StatusBody, {
916
+ state,
917
+ t,
918
+ onLogout: logout,
919
+ logoutBusy,
920
+ }),
854
921
  ],
855
922
  })
856
923
  : null,
@@ -1001,7 +1068,8 @@ window.__ModuleLoader__.load({
1001
1068
  //#region 文案
1002
1069
  const zh = {
1003
1070
  title: '千问办公',
1004
- subtitle: '复用千问办公桌面 App 登录态',
1071
+ subtitle: '设备码登录,直连千问办公网关',
1072
+ notSignedIn: '未登录',
1005
1073
  signedIn: '已登录',
1006
1074
  signedInAs: '已登录:{name}',
1007
1075
  loading: '正在读取状态…',
@@ -1013,6 +1081,10 @@ window.__ModuleLoader__.load({
1013
1081
  loginWaiting: '已打开授权页,等待你在浏览器里完成授权…',
1014
1082
  loginTimeout: '登录超时,请重试',
1015
1083
  loginFailed: '登录失败',
1084
+ logout: '退出登录',
1085
+ loggingOut: '正在退出…',
1086
+ logoutConfirm: '确定要退出登录吗?本机凭据会被删除,可随时重新登录。',
1087
+ logoutFailed: '退出登录失败',
1016
1088
  accountHeading: '账号',
1017
1089
  quotaHeading: '剩余积分',
1018
1090
  nickname: '账号',
@@ -1059,7 +1131,8 @@ window.__ModuleLoader__.load({
1059
1131
  };
1060
1132
  const en = {
1061
1133
  title: 'QwenWork',
1062
- subtitle: "Reuses the QwenWork desktop app's sign-in",
1134
+ subtitle: "Device-code sign-in, direct to the QwenWork gateway",
1135
+ notSignedIn: 'Not signed in',
1063
1136
  signedIn: 'Signed in',
1064
1137
  signedInAs: 'Signed in: {name}',
1065
1138
  loading: 'Reading status…',
@@ -1071,6 +1144,10 @@ window.__ModuleLoader__.load({
1071
1144
  loginWaiting: 'Authorization page opened; waiting for you to finish in the browser…',
1072
1145
  loginTimeout: 'Sign-in timed out. Please try again.',
1073
1146
  loginFailed: 'Sign-in failed',
1147
+ logout: 'Sign out',
1148
+ loggingOut: 'Signing out…',
1149
+ logoutConfirm: 'Sign out of this device? The local credentials will be removed; you can sign in again anytime.',
1150
+ logoutFailed: 'Sign-out failed',
1074
1151
  accountHeading: 'Account',
1075
1152
  quotaHeading: 'Remaining credits',
1076
1153
  nickname: 'Account',
package/lib/index.js CHANGED
@@ -34,6 +34,7 @@ import { CATALOG_TTL_MS, createCatalogStore } from './catalog.js';
34
34
  import { relaxTlsForVpc, resolveGatewayEndpoint } from './endpoint.js';
35
35
  import { registerQwenWorkStatusRoute } from './web-status.js';
36
36
  import { registerDeviceLoginRoute } from './login-route.js';
37
+ import { registerLogoutRoute } from './logout-route.js';
37
38
  import { perfSummary } from './perf.js';
38
39
  import { installStallGuard } from './stall-guard.js';
39
40
 
@@ -433,12 +434,17 @@ export function apply(ctx, config) {
433
434
  // ---- 设置卡片数据源 ------------------------------------------------
434
435
  // 无论 provider 是否注册成功,卡片都要能显示——它是阶段 B 的主要可见成果。
435
436
  ctx.inject(['webServer'], (webCtx) => {
436
- registerDeviceLoginRoute(webCtx, {
437
+ const loginRoutes = registerDeviceLoginRoute(webCtx, {
437
438
  logger: ctx.logger,
438
439
  onLogin: () => {
439
440
  void refreshCatalog(true);
440
441
  },
441
442
  });
443
+ registerLogoutRoute(webCtx, {
444
+ logger: ctx.logger,
445
+ // 清掉登录页缓存,避免退出后 /login/status 仍回上一次的账号摘要。
446
+ onLogout: () => loginRoutes?.reset?.(),
447
+ });
442
448
  registerQwenWorkStatusRoute(webCtx, {
443
449
  getAccountContext,
444
450
  tokenAvailable: isWired,
@@ -27,6 +27,23 @@ export const DEVICE_BASE = 'https://gateway.qwenwork.cn';
27
27
  export const DEFAULT_CREDENTIAL_PATH = path.join(os.homedir(), '.dsh', 'qwenwork-desktop.json');
28
28
  export const DEFAULT_MACHINE_ID_PATH = path.join(os.homedir(), '.dsh', 'qwenwork-machine-id');
29
29
 
30
+ /**
31
+ * 凭据文件路径的唯一解析口:显式参数 > `QWENWORK_CREDENTIAL_FILE` > 默认路径。
32
+ *
33
+ * `credentials.js` 的读取侧早就支持这个环境变量;写入侧(登录 / CLI)与
34
+ * 删除侧(退出登录)必须走同一套优先级,否则会出现「登录写 A、读取读 B」
35
+ * 或「退出删 A、实际用的是 B」这种自相矛盾的状态。
36
+ *
37
+ * @param {string | undefined} explicit
38
+ * @returns {string}
39
+ */
40
+ export function resolveCredentialPath(explicit) {
41
+ if (typeof explicit === 'string' && explicit !== '') return explicit;
42
+ const fromEnv = process.env.QWENWORK_CREDENTIAL_FILE;
43
+ if (typeof fromEnv === 'string' && fromEnv.trim() !== '') return fromEnv.trim();
44
+ return DEFAULT_CREDENTIAL_PATH;
45
+ }
46
+
30
47
  export function createPkce() {
31
48
  const verifier = crypto.randomBytes(48).toString('base64url');
32
49
  const challenge = crypto.createHash('sha256').update(verifier).digest('base64url');
@@ -134,7 +151,8 @@ function sleep(ms) {
134
151
  * 字段名沿用上游 `normalizeCredentials` 的契约,换实现时不用改契约。
135
152
  */
136
153
  export function writeCredential(payload, options = {}) {
137
- const { machineId, credentialPath = DEFAULT_CREDENTIAL_PATH } = options;
154
+ const { machineId } = options;
155
+ const credentialPath = resolveCredentialPath(options.credentialPath);
138
156
  const claims = decodeJwt(payload.token);
139
157
  const user = {
140
158
  id: payload.user_id ?? claims.user_id ?? claims.sub ?? null,
@@ -162,7 +180,7 @@ export async function startDeviceLogin(options = {}) {
162
180
  const {
163
181
  clientId = DEVICE_CLIENT_ID,
164
182
  base = DEVICE_BASE,
165
- credentialPath = DEFAULT_CREDENTIAL_PATH,
183
+ credentialPath,
166
184
  machineIdPath = DEFAULT_MACHINE_ID_PATH,
167
185
  intervalMs = 2000,
168
186
  timeoutMs = 5 * 60 * 1000,
@@ -13,9 +13,9 @@ import {
13
13
  buildAuthUrl,
14
14
  createPkce,
15
15
  pollDeviceToken,
16
+ resolveCredentialPath,
16
17
  resolveMachineId,
17
18
  writeCredential,
18
- DEFAULT_CREDENTIAL_PATH,
19
19
  } from './login-device-flow.js';
20
20
 
21
21
  export const LOGIN_START_PATH = '/plugins/dsh-qwenwork-connect/login/start';
@@ -36,8 +36,13 @@ function json(res, status, body) {
36
36
  * @param {{ logger?: any, credentialPath?: string, onLogin?: () => void }} [deps]
37
37
  */
38
38
  export function registerDeviceLoginRoute(ctx, deps = {}) {
39
- const credentialPath = deps.credentialPath ?? DEFAULT_CREDENTIAL_PATH;
39
+ const credentialPath = resolveCredentialPath(deps.credentialPath);
40
40
  const state = { phase: 'idle', url: null, error: null, account: null, startedAt: null };
41
+ /**
42
+ * 登录轮询的代际号:退出登录时 +1,让尚在途中的 device flow 结果作废。
43
+ * 只改 `state` 不够——旧轮询拿到 token 后仍会写盘,把刚退出的账号又登回去。
44
+ */
45
+ let epoch = 0;
41
46
 
42
47
  const handle = (req, res) => {
43
48
  if (!loopbackRequest(req)) {
@@ -70,8 +75,13 @@ export function registerDeviceLoginRoute(ctx, deps = {}) {
70
75
  state.account = null;
71
76
  state.startedAt = Date.now();
72
77
 
78
+ const loginEpoch = epoch;
73
79
  void pollDeviceToken({ nonce, verifier })
74
80
  .then((payload) => {
81
+ if (loginEpoch !== epoch) {
82
+ // 等待期间用户已退出登录:丢弃这次授权结果,不写回凭据。
83
+ return;
84
+ }
75
85
  const written = writeCredential(payload, { machineId, credentialPath });
76
86
  state.phase = 'ready';
77
87
  state.account = {
@@ -88,6 +98,7 @@ export function registerDeviceLoginRoute(ctx, deps = {}) {
88
98
  }
89
99
  })
90
100
  .catch((error) => {
101
+ if (loginEpoch !== epoch) return;
91
102
  state.phase = 'failed';
92
103
  state.error = String(error?.message ?? error).slice(0, 300);
93
104
  deps.logger?.warn?.('dsh-qwenwork-connect: device login failed', state.error);
@@ -116,13 +127,24 @@ export function registerDeviceLoginRoute(ctx, deps = {}) {
116
127
  };
117
128
  };
118
129
 
130
+ /** 退出登录时清空登录页状态,并让在途轮询作废。 */
131
+ const reset = () => {
132
+ epoch += 1;
133
+ state.phase = 'idle';
134
+ state.url = null;
135
+ state.error = null;
136
+ state.account = null;
137
+ state.startedAt = null;
138
+ };
139
+
119
140
  if (typeof ctx.effect === 'function') {
120
141
  ctx.effect(() => mount(), 'dsh-qwenwork-connect: device login routes');
121
- return;
142
+ return { reset };
122
143
  }
123
144
  try {
124
145
  mount();
125
146
  } catch (error) {
126
147
  void error;
127
148
  }
149
+ return { reset };
128
150
  }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * 退出登录:设置卡片上点「退出登录」走这里。
3
+ *
4
+ * 只做一件事——删掉本机凭据文件,让下一次请求重新回到「未登录」。
5
+ * 不吊销上游 token(千问办公没有公开的吊销接口),但 token 离开本机后
6
+ * 已经无法再被本插件使用;设备标识 `~/.dsh/qwenwork-machine-id` 刻意保留,
7
+ * 这样重新登录不会换设备。
8
+ *
9
+ * 安全边界与登录 / 状态路由一致:只接受环回请求;错误文本不回显凭据内容。
10
+ *
11
+ * @module dsh-qwenwork-connect/logout-route
12
+ */
13
+
14
+ import fs from 'node:fs';
15
+ import { loopbackRequest } from './loopback.js';
16
+ import { resolveCredentialPath } from './login-device-flow.js';
17
+
18
+ export const LOGOUT_PATH = '/plugins/dsh-qwenwork-connect/logout';
19
+
20
+ function json(res, status, body) {
21
+ const payload = JSON.stringify(body);
22
+ res.writeHead(status, {
23
+ 'Content-Type': 'application/json; charset=utf-8',
24
+ 'Content-Length': Buffer.byteLength(payload),
25
+ 'Cache-Control': 'no-store',
26
+ });
27
+ res.end(payload);
28
+ }
29
+
30
+ /**
31
+ * @param {any} ctx 已注入 webServer 的上下文
32
+ * @param {{ logger?: any, credentialPath?: string, onLogout?: () => void }} [deps]
33
+ */
34
+ export function registerLogoutRoute(ctx, deps = {}) {
35
+ const credentialPath = resolveCredentialPath(deps.credentialPath);
36
+
37
+ const handle = (req, res) => {
38
+ if (!loopbackRequest(req)) {
39
+ json(res, 403, { error: 'loopback only' });
40
+ return;
41
+ }
42
+ if (req.method !== 'POST') {
43
+ json(res, 405, { error: 'POST only' });
44
+ return;
45
+ }
46
+
47
+ try {
48
+ let removed = false;
49
+ try {
50
+ fs.unlinkSync(credentialPath);
51
+ removed = true;
52
+ } catch (error) {
53
+ // 已经退出过 / 从来没登录过:幂等成功,不把「文件不存在」当失败。
54
+ if (/** @type {any} */ (error)?.code !== 'ENOENT') throw error;
55
+ }
56
+
57
+ try {
58
+ deps.onLogout?.();
59
+ } catch {
60
+ // 内存态清理失败不应把「凭据已删除」判成退出失败。
61
+ }
62
+
63
+ deps.logger?.info?.(`dsh-qwenwork-connect: 已退出登录${removed ? '' : '(凭据文件原本不存在)'}`);
64
+ json(res, 200, { ok: true, removed });
65
+ } catch (error) {
66
+ const message = String(/** @type {any} */ (error)?.message ?? error).slice(0, 300);
67
+ deps.logger?.warn?.('dsh-qwenwork-connect: 退出登录失败', message);
68
+ json(res, 500, { error: message });
69
+ }
70
+ };
71
+
72
+ const mount = () => {
73
+ const dispose = ctx.webServer.register({
74
+ kind: 'exact',
75
+ path: LOGOUT_PATH,
76
+ handler: handle,
77
+ });
78
+ return dispose;
79
+ };
80
+
81
+ if (typeof ctx.effect === 'function') {
82
+ ctx.effect(() => mount(), 'dsh-qwenwork-connect: device logout route');
83
+ return;
84
+ }
85
+ try {
86
+ mount();
87
+ } catch (error) {
88
+ void error;
89
+ }
90
+ }
package/lib/models.js CHANGED
@@ -235,14 +235,23 @@ export function toPiModel(info, baseUrl, opts = {}) {
235
235
  baseUrl,
236
236
  input: supportsImages ? ['text', 'image'] : ['text'],
237
237
  /**
238
- * 上游确实返回思维链,置 true 让 pi-ai 把 `reasoning_content` 识别为
239
- * 独立的 thinking 块,而不是混进正文渲染。
238
+ * 上游确实返回思维链(`reasoning_content`),但 pi-ai 把它解析成独立
239
+ * thinking 块**不依赖这个标志**:openai-completions 的解析分支无条件读取
240
+ * `reasoning_content`(实测 reasoning:false 时 thinking 块照常产出)。
240
241
  *
241
- * 实测依据:glm-5.2 在 `choices[0].delta.reasoning_content` 里给出思维链
242
- * (见 research/probe-reasoning-vs-content.mjs)。此前置 false 时,思维链
243
- * 会被当作普通 text 输出,用户会在回答里看到模型的内心独白。
242
+ * 这里置 false 只有一个目的:让 DSH 不生成「推理等级」菜单。
243
+ *
244
+ * 原因:上游模型目录里所有模型的 `thinking_config` 都是 null,没有声明
245
+ * 任何 effort 档位。DSH 对 `reasoning:true` 且没有 `thinkingLevelMap`
246
+ * 的模型会自动补出 off/minimal/low/medium/high,但上游并不认这些档位,
247
+ * 属于假开关。置 false 后 DSH 的 `reasoningInfo` 返回空,UI 不再出现
248
+ * 推理等级;把 `thinkingLevelMap` 全设 null 反而会得到空 efforts,
249
+ * dsh-llm 会直接抛 `INVALID_MODEL_REASONING`。
250
+ *
251
+ * 思考本身固定开启:请求体 `parameters.enable_thinking` 恒为 true
252
+ * (见 signer-session.js 的 buildInferBody),不提供开关、不做回退。
244
253
  */
245
- reasoning: true,
254
+ reasoning: false,
246
255
  /**
247
256
  * 思考开关握手(QwenWork 网关不支持,2026-11-08 实测):
248
257
  *
@@ -256,7 +265,8 @@ export function toPiModel(info, baseUrl, opts = {}) {
256
265
  * probe-flash-thinking.mjs:flash 模型 3 变体):QwenWork 网关对
257
266
  * `enable_thinking:false`、`chat_template_kwargs.enable_thinking:false`、
258
267
  * `reasoning_effort:"none"`、`is_reasoning:false` 全部无视,思考照发。
259
- * 所以这里**刻意不声明** compat.thinkingLevelMap / thinkingFormat:发了
268
+ * 所以这里**刻意不声明** compat.thinkingLevelMap / thinkingFormat,并且把
269
+ * `reasoning` 置 false,避免 DSH 自动补出上游并不支持的通用档位:发了
260
270
  * 也是无效字段,反而让 pi-ai 以为关思考已生效。上游强制思考,
261
271
  * 宿主端的正确姿态是容忍 thinking 通道(pi-hermes-memory 的
262
272
  * thinking-channel recovery 那样从 thinking 块恢复答案)。
@@ -344,11 +344,13 @@ export function buildInferBody(params) {
344
344
  tools: Array.isArray(params.tools) ? params.tools : [],
345
345
  // ── §3.8 parameters ───────────────────────────────────────────────
346
346
  // 确定最小形态是 `{ max_tokens }`;`context_length` 是产品额外声明的窗口。
347
+ // `enable_thinking` 固定 true:千问办公网关强制思考,关不掉(2026-11-08
348
+ // 五变体实测),插件也不提供开关;显式发 true 比依赖上游默认更明确。
347
349
  //
348
350
  // ⚠️ context_length 的计量单位是 **Qwen 的 token**,与 DSH 用的 tokenizer
349
351
  // 不是同一套;不能拿 DSH 的 token 计数直接填。当前策略是固定 1M、按消息
350
352
  // 估算窗口的实现需要额外接 Qwen tokenizer,这里不做。
351
- parameters: { max_tokens: maxOutput, context_length: maxInput },
353
+ parameters: { enable_thinking: true, max_tokens: maxOutput, context_length: maxInput },
352
354
  // ── §3.13 business(**503 根因字段**)─────────────────────────────
353
355
  // SDK 的写法是条件展开 `...void 0!==m?{business:m}:{}`,但服务端要求它存在
354
356
  // 且含 `product`:缺失即 503(§1.1b.1 实测)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qwenwork-connect",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "千问办公(QwenWork)的 DSH 模型提供方:device flow 登录、官方网关、支持工具调用",
5
5
  "license": "MIT",
6
6
  "author": "AaIchhe",