@michengai/dsh-im-connect 0.1.26 → 0.1.28

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/CHANGELOG.zh-CN.md +16 -0
  3. package/README.en.md +0 -1
  4. package/README.md +0 -1
  5. package/client.js +509 -60
  6. package/lib/channels/factory.d.ts +2 -0
  7. package/lib/channels/factory.d.ts.map +1 -1
  8. package/lib/channels/factory.js +22 -7
  9. package/lib/channels/factory.js.map +1 -1
  10. package/lib/channels/meta.js +3 -3
  11. package/lib/channels/meta.js.map +1 -1
  12. package/lib/client.js +509 -60
  13. package/lib/engine/approval.d.ts +4 -1
  14. package/lib/engine/approval.d.ts.map +1 -1
  15. package/lib/engine/approval.js +38 -11
  16. package/lib/engine/approval.js.map +1 -1
  17. package/lib/engine/gateway.d.ts +32 -1
  18. package/lib/engine/gateway.d.ts.map +1 -1
  19. package/lib/engine/gateway.js +417 -17
  20. package/lib/engine/gateway.js.map +1 -1
  21. package/lib/engine/question.d.ts +56 -0
  22. package/lib/engine/question.d.ts.map +1 -0
  23. package/lib/engine/question.js +196 -0
  24. package/lib/engine/question.js.map +1 -0
  25. package/lib/engine/router.d.ts +10 -7
  26. package/lib/engine/router.d.ts.map +1 -1
  27. package/lib/engine/router.js +47 -27
  28. package/lib/engine/router.js.map +1 -1
  29. package/lib/engine/session-id.d.ts +6 -4
  30. package/lib/engine/session-id.d.ts.map +1 -1
  31. package/lib/engine/session-id.js +4 -2
  32. package/lib/engine/session-id.js.map +1 -1
  33. package/lib/index.d.ts.map +1 -1
  34. package/lib/index.js +9 -1
  35. package/lib/index.js.map +1 -1
  36. package/lib/manager.d.ts +51 -6
  37. package/lib/manager.d.ts.map +1 -1
  38. package/lib/manager.js +311 -66
  39. package/lib/manager.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/channels/factory.ts +15 -9
  42. package/src/channels/meta.ts +3 -3
  43. package/src/engine/approval.ts +40 -13
  44. package/src/engine/gateway.ts +451 -21
  45. package/src/engine/question.ts +228 -0
  46. package/src/engine/router.ts +53 -33
  47. package/src/engine/session-id.ts +10 -6
  48. package/src/index.ts +9 -2
  49. package/src/manager.ts +332 -75
package/client.js CHANGED
@@ -14,14 +14,15 @@ window.__ModuleLoader__.load({
14
14
  const inject = ["slots", "sessions", "workspaces", "locale"];
15
15
  const API_BASE = "/dsh-im-connect/api";
16
16
  const TAB_KEY = "dsh-im-connect.sidebar-tab";
17
+ const ACCOUNT_SELECTION_KEY = "dsh-im-connect.settings.selected-account";
17
18
  const IM_LOCALE_NS = "im-connect";
18
19
  const IM_LOCALES = {
19
20
  zh: {
20
21
  "settings.label": "IM助理", "settings.title": "IM 频道", "settings.description": "配置 IM 频道,让本机助手接收来自钉钉、飞书等平台的消息。频道配置仅保存在本机。",
21
- "settings.aria": "IM助理", "pending.notice": "有访问请求。批准后该用户才能驱动本机助手。", "action.approve": "批准", "action.deny": "拒绝", "loading": "加载中…",
22
+ "settings.aria": "IM助理", "settings.selectAccountTitle": "选择一个账号", "settings.selectAccountDescription": "从左侧选择账号,查看并修改工作区、模型和权限配置。", "settings.noAccountsTitle": "还没有接入账号", "settings.noAccountsDescription": "请在左侧选择对应渠道,然后点击“添加账号”。", "settings.publicChatNotice": "未批准用户可以发起聊天,但不能批准工具调用。", "pending.notice": "有访问请求。批准后该用户才能驱动本机助手。", "action.approve": "批准", "action.deny": "拒绝", "loading": "加载中…",
22
23
  "channel.dingtalk": "钉钉", "channel.feishu": "飞书", "channel.lark": "Lark", "channel.weixin": "微信", "channel.wecom": "企业微信", "channel.qq": "QQ", "channel.telegram": "Telegram",
23
24
  "field.dingtalk.clientId": "Client ID(原 AppKey)", "field.dingtalk.clientSecret": "Client Secret(原 AppSecret)",
24
- "bind.title": "配置 {channel}", "bind.close": "关闭", "bind.quick": "快捷绑定(推荐)", "bind.manual": "手动配置", "bind.success": "绑定成功,频道已连接", "bind.qrAlt": "{channel} 绑定二维码", "bind.generating": "正在生成…", "bind.waiting": "等待二维码", "bind.expire": "二维码 {time} 后过期", "bind.scanned": "已扫码,请在手机上确认", "bind.retry": "请重新生成二维码", "bind.refresh": "重新生成二维码", "action.saving": "保存中…", "action.confirm": "确认",
25
+ "bind.title": "配置 {channel}", "bind.close": "关闭", "bind.quick": "快捷绑定(推荐)", "bind.manual": "手动配置", "bind.success": "绑定成功,频道已连接", "bind.newIdentity": "检测到新的账号身份,已创建新账号", "bind.qrAlt": "{channel} 绑定二维码", "bind.generating": "正在生成…", "bind.expire": "二维码 {time} 后过期", "bind.scanned": "已扫码,请在手机上确认", "bind.retry": "请重新生成二维码", "bind.refresh": "重新生成二维码", "action.saving": "保存中…", "action.confirm": "确认",
25
26
  "qr.weixin": "请使用微信扫描二维码完成绑定", "qr.feishu": "请使用飞书扫描二维码,将自动创建机器人", "qr.lark": "请使用 Lark 扫描二维码完成配对", "qr.wecom": "请使用企业微信扫描二维码,快捷绑定机器人", "qr.dingtalk": "请使用钉钉扫描二维码,自动创建机器人", "qr.qq": "请使用手机 QQ 扫描二维码,创建开放平台机器人", "qr.default": "请使用对应 App 扫描二维码",
26
27
  "status.unconfigured": "未配置", "status.connected": "已连接", "status.connecting": "接入中…", "action.configure": "配置", "action.more": "{channel} 更多", "action.reconnect": "重新接入", "action.disconnect": "断开", "action.removeConfig": "删除配置", "action.receive": "接收消息",
27
28
  "error.loadAssistant": "无法加载全局配置", "error.noModels": "当前 Host 还没有可用模型,请先在网页里配置提供商", "error.save": "保存失败", "error.chooseWorkspace": "请选择工作区目录", "error.workspaceUnavailable": "当前 Host 无法新增工作区", "error.addWorkspace": "新增工作区失败", "error.load": "加载失败", "error.connection": "无法连接本机 IM 助理接口", "error.request": "请求失败", "error.action": "操作失败", "error.qr": "无法生成二维码", "error.detailsInLog": "操作失败,请查看服务器日志。",
@@ -34,10 +35,10 @@ window.__ModuleLoader__.load({
34
35
  },
35
36
  en: {
36
37
  "settings.label": "IM Assistant", "settings.title": "IM Channels", "settings.description": "Connect IM channels so your local assistant can receive messages from DingTalk, Feishu, and more. Channel settings are stored only on this machine.",
37
- "settings.aria": "IM Assistant", "pending.notice": "There are access requests. Approve a user before they can control the local assistant.", "action.approve": "Approve", "action.deny": "Deny", "loading": "Loading…",
38
+ "settings.aria": "IM Assistant", "settings.selectAccountTitle": "Select an account", "settings.selectAccountDescription": "Choose an account on the left to view and edit its workspace, model, and permissions.", "settings.noAccountsTitle": "No accounts connected", "settings.noAccountsDescription": "Choose a channel on the left, then select Add account.", "settings.publicChatNotice": "Unapproved users can start chats, but they cannot approve tool calls.", "pending.notice": "There are access requests. Approve a user before they can control the local assistant.", "action.approve": "Approve", "action.deny": "Deny", "loading": "Loading…",
38
39
  "channel.dingtalk": "DingTalk", "channel.feishu": "Feishu", "channel.lark": "Lark", "channel.weixin": "WeChat", "channel.wecom": "WeCom", "channel.qq": "QQ", "channel.telegram": "Telegram",
39
40
  "field.dingtalk.clientId": "Client ID (formerly AppKey)", "field.dingtalk.clientSecret": "Client Secret (formerly AppSecret)",
40
- "bind.title": "Set up {channel}", "bind.close": "Close", "bind.quick": "Quick setup (recommended)", "bind.manual": "Manual setup", "bind.success": "Connected successfully", "bind.qrAlt": "{channel} setup QR code", "bind.generating": "Generating…", "bind.waiting": "Waiting for QR code", "bind.expire": "QR code expires in {time}", "bind.scanned": "Scanned. Confirm on your phone.", "bind.retry": "Generate a new QR code", "bind.refresh": "Generate a new QR code", "action.saving": "Saving…", "action.confirm": "Confirm",
41
+ "bind.title": "Set up {channel}", "bind.close": "Close", "bind.quick": "Quick setup (recommended)", "bind.manual": "Manual setup", "bind.success": "Connected successfully", "bind.newIdentity": "A new account identity was detected and a new account was created", "bind.qrAlt": "{channel} setup QR code", "bind.generating": "Generating…", "bind.expire": "QR code expires in {time}", "bind.scanned": "Scanned. Confirm on your phone.", "bind.retry": "Generate a new QR code", "bind.refresh": "Generate a new QR code", "action.saving": "Saving…", "action.confirm": "Confirm",
41
42
  "qr.weixin": "Scan the QR code with WeChat to connect", "qr.feishu": "Scan with Feishu; a bot will be created automatically", "qr.lark": "Scan with Lark to pair", "qr.wecom": "Scan with WeCom to quickly connect a bot", "qr.dingtalk": "Scan with DingTalk; a bot will be created automatically", "qr.qq": "Scan with mobile QQ to create an Open Platform bot", "qr.default": "Scan the QR code with the corresponding app",
42
43
  "status.unconfigured": "Not configured", "status.connected": "Connected", "status.connecting": "Connecting…", "action.configure": "Configure", "action.more": "More options for {channel}", "action.reconnect": "Reconnect", "action.disconnect": "Disconnect", "action.removeConfig": "Remove configuration", "action.receive": "Receive messages",
43
44
  "error.loadAssistant": "Could not load global settings", "error.noModels": "No models are available in the Host. Configure a provider in the web app first.", "error.save": "Could not save", "error.chooseWorkspace": "Choose a workspace directory", "error.workspaceUnavailable": "This Host cannot create workspaces", "error.addWorkspace": "Could not add workspace", "error.load": "Could not load", "error.connection": "Could not connect to the local IM Assistant API", "error.request": "Request failed", "error.action": "Action failed", "error.qr": "Could not generate a QR code", "error.detailsInLog": "The operation failed. Check the server logs for details.",
@@ -53,7 +54,7 @@ window.__ModuleLoader__.load({
53
54
  const h = React.createElement;
54
55
 
55
56
  const CSS = `
56
- .ima-page{--ima-text:var(--dsw-alias-label-primary,var(--dsh-text,#e6edf3));--ima-muted:var(--dsw-alias-label-tertiary,var(--dsh-text-muted,#8b949e));--ima-line:var(--dsw-alias-border-l2,var(--dsh-border,rgba(255,255,255,.1)));--ima-card:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));--ima-card-hover:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06));--ima-ok:var(--dsw-alias-state-success-primary,#3fb950);--ima-danger:var(--dsw-alias-state-error-primary,#f85149);--ima-accent:var(--dsw-alias-brand-primary,#4b7cff);box-sizing:border-box;max-width:760px;width:100%;margin:0 auto;padding:0 0 32px;color:var(--ima-text)}
57
+ .ima-page{--ima-text:var(--dsw-alias-label-primary,var(--dsh-text,#e6edf3));--ima-muted:var(--dsw-alias-label-tertiary,var(--dsh-text-muted,#8b949e));--ima-line:var(--dsw-alias-border-l2,var(--dsh-border,rgba(255,255,255,.1)));--ima-card:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));--ima-card-hover:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06));--ima-ok:var(--dsw-alias-state-success-primary,#3fb950);--ima-warning:var(--dsw-alias-state-warning-primary,#d29922);--ima-danger:var(--dsw-alias-state-error-primary,#f85149);--ima-accent:var(--dsw-alias-brand-primary,#4b7cff);box-sizing:border-box;max-width:760px;width:100%;margin:0 auto;padding:0 0 32px;color:var(--ima-text)}
57
58
  .ima-deco{display:flex;justify-content:center;align-items:flex-end;gap:10px;min-height:56px;margin:8px 0 14px}
58
59
  .ima-bubble{font-size:12px;line-height:1.4;padding:6px 10px;border-radius:12px;max-width:220px;border:1px solid var(--ima-line)}
59
60
  .ima-bubble.left{background:rgba(46,160,67,.14);color:#7ee787}
@@ -164,8 +165,8 @@ window.__ModuleLoader__.load({
164
165
  .ima-seg button{flex:1;border:0;background:transparent;padding:10px 0;font-size:13px;color:var(--ima-muted);cursor:pointer}
165
166
  .ima-seg button.on{color:var(--ima-accent);box-shadow:inset 0 -2px 0 var(--ima-accent);font-weight:600}
166
167
  .ima-qrbox{display:flex;flex-direction:column;align-items:center;gap:10px;padding:8px 0 4px}
167
- .ima-qrbox img,.ima-qrph{width:200px;height:200px;background:#fff;border:1px solid var(--ima-line);border-radius:12px;object-fit:contain}
168
- .ima-qrph{display:grid;place-items:center;color:var(--ima-muted);font-size:13px}
168
+ .ima-qrbox img{width:200px;height:200px;background:#fff;border:1px solid var(--ima-line);border-radius:12px;object-fit:contain}
169
+ .ima-bind-ready{display:flex;flex-direction:column;align-items:center;gap:14px;padding:12px 0 4px}.ima-bind-ready .ima-btn{min-width:136px}.ima-bind-status{min-height:40px;display:grid;place-items:center;color:var(--ima-muted);font-size:13px;text-align:center}
169
170
  .ima-hint{margin:0;color:var(--ima-muted);font-size:13px;text-align:center;line-height:1.6}
170
171
  .ima-link{border:0;background:transparent;color:var(--ima-accent);cursor:pointer;font-size:13px;min-height:32px}
171
172
  .ima-field{display:flex;flex-direction:column;gap:6px;margin-bottom:12px;font-size:13px}
@@ -175,6 +176,27 @@ window.__ModuleLoader__.load({
175
176
  .ima-radio small{display:block;color:var(--ima-muted);margin-top:2px}
176
177
  .ima-ok{color:var(--ima-ok);font-size:14px;text-align:center;padding:24px 0}
177
178
  .ima-modal .ima-error{color:var(--ima-danger)}
179
+ .ima-page.ima-account-page{max-width:1120px;padding-bottom:40px}
180
+ .ima-account-shell{display:grid;grid-template-columns:minmax(330px,390px) minmax(360px,1fr);min-height:650px;border:1px solid var(--ima-line);border-radius:16px;overflow:hidden;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.018))}
181
+ .ima-platforms{padding:0;border-right:1px solid var(--ima-line);background:var(--dsw-alias-bg-base,transparent)}
182
+ .ima-platform{border:0;border-bottom:1px solid var(--ima-line);border-radius:0;margin:0;overflow:visible;background:transparent}.ima-platform:last-child{border-bottom:0}.ima-platform.open{background:transparent}
183
+ .ima-platform-head{display:flex;align-items:center;gap:10px;width:100%;min-height:64px;padding:10px 18px;border:0;border-radius:0;background:transparent;color:inherit;text-align:left;cursor:pointer}
184
+ .ima-platform:not(.open):not(.empty) .ima-platform-head:hover{background:var(--ima-card-hover)}.ima-platform.empty .ima-platform-head{cursor:default}.ima-platform-title{min-width:0;flex:1;font-size:14px;font-weight:650}.ima-platform-count{color:var(--ima-muted);font-size:12px;white-space:nowrap}.ima-platform-count.online{color:var(--ima-ok)}.ima-platform-count.offline,.ima-platform-count.partial{color:var(--ima-warning)}
185
+ .ima-platform-add{min-height:34px;padding:0 10px;border:1px solid var(--ima-line);border-radius:8px;background:transparent;color:var(--ima-text);font-size:12px;font-weight:600;cursor:pointer;white-space:nowrap}.ima-platform-add:hover{background:var(--ima-card-hover)}
186
+ .ima-platform-caret{display:grid;width:18px;height:18px;margin:0 1px;place-items:center;color:var(--ima-muted);transition:transform .15s ease}.ima-platform-caret.empty{visibility:hidden}.ima-platform.open .ima-platform-caret{transform:rotate(90deg)}
187
+ .ima-account-list{display:flex;flex-direction:column;gap:8px;padding:0 14px 14px}.ima-account-row{display:flex;align-items:center;gap:10px;width:100%;min-height:72px;padding:10px 12px;border:1px solid var(--ima-line);border-radius:9px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.025));color:inherit;text-align:left;cursor:pointer}.ima-account-row:hover{background:var(--ima-card-hover);border-color:color-mix(in srgb,var(--ima-text) 22%,var(--ima-line))}.ima-account-row.on{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06));border-color:color-mix(in srgb,var(--ima-text) 18%,var(--ima-line))}
188
+ .ima-platform-head:focus-visible,.ima-platform-add:focus-visible,.ima-account-row:focus-visible{outline:2px solid var(--ima-accent);outline-offset:2px}
189
+ .ima-account-row .ima-logo,.ima-account-row .ima-logo svg{width:38px;height:38px}.ima-account-row .ima-logo{border-radius:9px}.ima-account-copy{min-width:0;flex:1}.ima-account-name{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;font-weight:600}.ima-account-id{display:block;margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ima-muted);font-size:11px}.ima-account-state{font-size:12px;white-space:nowrap;color:var(--ima-muted)}.ima-account-state.online{color:var(--ima-ok)}.ima-account-state.offline{color:var(--ima-warning)}.ima-account-next{display:grid;width:16px;height:16px;place-items:center;color:var(--ima-text);opacity:.8}.ima-dot{width:7px;height:7px;border-radius:50%;background:var(--ima-warning);flex:none}.ima-dot.on{background:var(--ima-ok);box-shadow:0 0 0 3px color-mix(in srgb,var(--ima-ok) 15%,transparent)}
190
+ .ima-inspector{padding:22px 24px 26px;min-width:0}.ima-inspector-empty{display:grid;min-height:580px;padding:32px;place-items:center;text-align:center}.ima-inspector-empty-copy{max-width:300px}.ima-inspector-empty-title{margin:0;color:var(--ima-text);font-size:16px;font-weight:650;line-height:24px}.ima-inspector-empty-description{margin:8px 0 0;color:var(--ima-muted);font-size:13px;line-height:20px}.ima-inspector-head{display:flex;align-items:flex-start;gap:12px;padding-bottom:18px;border-bottom:1px solid var(--ima-line)}.ima-inspector-head-copy{min-width:0;flex:1}.ima-inspector-title{margin:1px 0 3px;font-size:17px;line-height:24px}.ima-inspector-status{color:var(--ima-muted);font-size:12px}.ima-inspector-status.ok{color:var(--ima-ok)}
191
+ .ima-form{display:flex;flex-direction:column;gap:16px;padding-top:20px}.ima-control{display:flex;flex-direction:column;gap:7px}.ima-control>span{color:var(--ima-muted);font-size:12px;font-weight:550}.ima-control input,.ima-control select{box-sizing:border-box;width:100%;min-height:44px;padding:0 12px;border:1px solid var(--ima-line);border-radius:9px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));color:var(--ima-text);font:13px inherit;outline:none}.ima-control input:focus,.ima-control select:focus{border-color:var(--ima-accent);box-shadow:0 0 0 2px color-mix(in srgb,var(--ima-accent) 18%,transparent)}.ima-control option{background:#202124;color:#f2f3f5}
192
+ .ima-switch-row{display:flex;align-items:center;justify-content:space-between;min-height:48px;padding:0 2px}.ima-switch-copy strong{display:block;font-size:13px}.ima-switch-copy small{display:block;margin-top:2px;color:var(--ima-muted);font-size:11px}
193
+ .ima-inspector-actions{display:flex;align-items:center;gap:8px;margin-top:6px;padding-top:18px;border-top:1px solid var(--ima-line)}.ima-inspector-actions .ima-btn{min-height:36px}.ima-inspector-actions .danger{margin-left:auto;color:var(--ima-danger);border-color:color-mix(in srgb,var(--ima-danger) 35%,transparent)}
194
+ .ima-save-note{min-height:18px;color:var(--ima-muted);font-size:11px}.ima-save-note.ok{color:var(--ima-ok)}
195
+ .ima-modal.ima-account-modal{width:min(560px,100%);max-height:min(760px,calc(100vh - 48px));overflow:auto}.ima-setup-section{margin:4px 0 14px;padding-bottom:14px;border-bottom:1px solid var(--ima-line)}
196
+ .ima-account-settings{display:grid;grid-template-columns:1fr 1fr;gap:12px}.ima-account-settings.compact{grid-template-columns:1fr}.ima-picker-field{display:flex;min-width:0;flex-direction:column;gap:7px}.ima-picker-field.wide{grid-column:1/-1}.ima-picker-label{color:var(--ima-muted);font-size:12px;font-weight:550}.ima-account-picker{width:100%}.ima-account-picker .ima-chip-btn{width:100%;height:auto;min-height:44px;justify-content:flex-start;padding:8px 12px;border:1px solid var(--ima-line);border-radius:9px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));color:var(--ima-text);font-size:13px;text-align:left}.ima-account-picker .ima-chip-btn:hover,.ima-account-picker.is-open .ima-chip-btn{border-color:var(--ima-accent);background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.04));box-shadow:0 0 0 2px color-mix(in srgb,var(--ima-accent) 18%,transparent)}.ima-account-picker .ima-chip-label{flex:1}.ima-account-picker .ima-chip-btn em{margin-left:auto}.ima-account-picker .ima-chip-menu{width:100%;min-width:100%;max-height:min(320px,calc(100vh - 120px))}.ima-account-picker.ima-model-select .ima-chip-btn{border-radius:9px}.ima-account-picker.ima-model-select .ima-chip-menu{width:max(100%,320px);min-width:100%}.ima-account-settings .ima-chip-dialog{grid-column:1/-1;margin-top:0}.ima-picker-note{grid-column:1/-1;color:var(--ima-muted);font-size:11px;line-height:1.5}.ima-picker-note.warning{color:var(--ima-warning)}
197
+ @media(max-width:1280px){[role="dialog"][aria-labelledby]:has(.ima-account-page){width:min(920px,calc(100vw - 48px));max-width:min(920px,calc(100vw - 48px))}.ima-account-shell{grid-template-columns:minmax(300px,340px) minmax(320px,1fr)}}
198
+ @media(max-width:850px){[role="dialog"][aria-labelledby]:has(.ima-account-page){width:calc(100vw - 32px);max-width:calc(100vw - 32px)}.ima-account-shell{grid-template-columns:1fr}.ima-platforms{border-right:0;border-bottom:1px solid var(--ima-line)}.ima-inspector{padding:18px}}
199
+ @media(max-width:620px){.ima-account-settings{grid-template-columns:1fr}.ima-picker-field.wide{grid-column:auto}.ima-account-picker.ima-model-select .ima-chip-menu{width:100%}}
178
200
  @media (prefers-reduced-motion:reduce){.ima-switch i{transition:none}}
179
201
  `;
180
202
 
@@ -190,12 +212,24 @@ window.__ModuleLoader__.load({
190
212
  const request = Object.assign({}, opts || {});
191
213
  const method = String(request.method || "GET").toUpperCase();
192
214
  if (method !== "GET" && method !== "HEAD") {
193
- request.headers = Object.assign({}, request.headers || {}, { "x-dsh-im-connect-client": "1" });
215
+ request.headers = Object.assign({ "content-type": "application/json" }, request.headers || {}, { "x-dsh-im-connect-client": "1" });
216
+ if (request.body === undefined) request.body = "{}";
194
217
  }
195
218
  return fetch(API_BASE + path, request).then((r) => r.json());
196
219
  };
197
220
 
198
- function BrandMark({ id }) {
221
+ const storedAccountSelection = () => {
222
+ try { return window.localStorage.getItem(ACCOUNT_SELECTION_KEY) || ""; }
223
+ catch { return ""; }
224
+ };
225
+ const rememberAccountSelection = (id) => {
226
+ try {
227
+ if (id) window.localStorage.setItem(ACCOUNT_SELECTION_KEY, id);
228
+ else window.localStorage.removeItem(ACCOUNT_SELECTION_KEY);
229
+ } catch { /* Local storage can be unavailable in restricted browser contexts. */ }
230
+ };
231
+
232
+ function BrandMark({ id, compact }) {
199
233
  const svg = (viewBox, children) => h("svg", {
200
234
  viewBox,
201
235
  xmlns: "http://www.w3.org/2000/svg",
@@ -226,8 +260,8 @@ window.__ModuleLoader__.load({
226
260
  }
227
261
 
228
262
  if (id === "wecom") {
229
- return svg("0 0 46 46", [
230
- h("path", { key: "bg", d: "M39.743 0H6.257A6.257 6.257 0 0 0 0 6.257v33.487A6.257 6.257 0 0 0 6.257 46h33.487A6.257 6.257 0 0 0 46 39.743V6.257A6.257 6.257 0 0 0 39.743 0", fill: "#fff" }),
263
+ return svg(compact ? "4 6 39 34" : "0 0 46 46", [
264
+ !compact && h("path", { key: "bg", d: "M39.743 0H6.257A6.257 6.257 0 0 0 0 6.257v33.487A6.257 6.257 0 0 0 6.257 46h33.487A6.257 6.257 0 0 0 46 39.743V6.257A6.257 6.257 0 0 0 39.743 0", fill: "#fff" }),
231
265
  h("path", { key: "orange", d: "M28.856 31.647a.483.483 0 0 0 .06.738 6.2 6.2 0 0 1 1.911 3.725 2.02 2.02 0 1 0 2.16-2.54 6.2 6.2 0 0 1-3.448-1.922.483.483 0 0 0-.683-.001", fill: "#fb6500" }),
232
266
  h("path", { key: "blueDot", d: "M37.057 28.448a2 2 0 0 0-.58 1.215 6.2 6.2 0 0 1-1.918 3.454.484.484 0 1 0 .738.616 6.2 6.2 0 0 1 3.725-1.91 2.02 2.02 0 1 0-1.96-3.376z", fill: "#0082ef" }),
233
267
  h("path", { key: "green", d: "M31.366 22.75a2.02 2.02 0 0 0 1.215 3.435 6.2 6.2 0 0 1 3.454 1.918.483.483 0 0 0 .829-.27.48.48 0 0 0-.212-.468 6.2 6.2 0 0 1-1.911-3.726 2.02 2.02 0 0 0-3.375-.889", fill: "#2dbc00" }),
@@ -254,7 +288,7 @@ window.__ModuleLoader__.load({
254
288
  }
255
289
 
256
290
  function Logo({ id, small }) {
257
- return h("div", { className: small ? "ima-logo sm" : "ima-logo", "data-brand": id, "aria-hidden": "true" }, h(BrandMark, { id }));
291
+ return h("div", { className: small ? "ima-logo sm" : "ima-logo", "data-brand": id, "aria-hidden": "true" }, h(BrandMark, { id, compact: small }));
258
292
  }
259
293
 
260
294
  function isRasterQr(value) {
@@ -330,35 +364,46 @@ window.__ModuleLoader__.load({
330
364
  };
331
365
  let channelSkin = "native";
332
366
 
333
- function BindModal({ ch, onClose, onConnected, t = fallbackT }) {
367
+ function BindModal({ ch, onClose, onConnected, catalog, permissions, workspaces, defaults, createWorkspace, pickDirectory, modelT, permissionT, t = fallbackT }) {
334
368
  const hasQr = ch.kind === "qr" || ch.kind === "qr-or-credentials";
335
369
  const hasManual = ch.kind === "credentials" || ch.kind === "qr-or-credentials";
336
370
  const [tab, setTab] = useState(hasQr ? "qr" : "manual");
337
371
  const [pairing, setPairing] = useState(null);
372
+ const [qrStarted, setQrStarted] = useState(false);
338
373
  const [draft, setDraft] = useState({});
339
374
  const [busy, setBusy] = useState(false);
340
375
  const [error, setError] = useState("");
376
+ const [success, setSuccess] = useState("");
377
+ const [settings, setSettings] = useState(() => ({
378
+ cwd: defaults && defaults.cwd || "",
379
+ provider: defaults && defaults.assistant && defaults.assistant.provider || "",
380
+ model: defaults && defaults.assistant && defaults.assistant.model || "",
381
+ reasoningEffort: defaults && defaults.assistant && defaults.assistant.reasoningEffort || "",
382
+ permission: defaults && defaults.permission || "",
383
+ privateAccess: "approved",
384
+ }));
341
385
  const alive = useRef(true);
342
386
 
343
387
  const startQr = useCallback((refresh) => {
344
388
  if (!hasQr) return;
389
+ setQrStarted(true);
345
390
  setBusy(true);
346
391
  setError("");
392
+ setSuccess("");
347
393
  api(`/channels/${ch.id}/qr/${refresh ? "refresh" : "start"}`, {
348
394
  method: "POST",
349
395
  headers: { "content-type": "application/json" },
350
- body: JSON.stringify({}),
396
+ body: JSON.stringify({ settings }),
351
397
  }).then((data) => {
352
398
  if (!alive.current) return;
353
399
  if (!data.ok && !data.pairing) setError(serverText(data.error, t) || t("error.qr"));
354
400
  setPairing(data.pairing || null);
355
401
  }).catch(() => { if (alive.current) setError(t("error.qr")); })
356
402
  .finally(() => { if (alive.current) setBusy(false); });
357
- }, [ch.id, hasQr]);
403
+ }, [ch.id, hasQr, settings]);
358
404
 
359
405
  useEffect(() => {
360
406
  alive.current = true;
361
- if (tab === "qr") startQr(false);
362
407
  return () => { alive.current = false; };
363
408
  }, []);
364
409
 
@@ -373,7 +418,7 @@ window.__ModuleLoader__.load({
373
418
  };
374
419
 
375
420
  useEffect(() => {
376
- if (tab !== "qr") return undefined;
421
+ if (tab !== "qr" || !qrStarted) return undefined;
377
422
  const timer = setInterval(() => {
378
423
  api(`/channels/${ch.id}/qr/status`).then((data) => {
379
424
  if (finished.current || !alive.current || !data.ok) return;
@@ -382,7 +427,7 @@ window.__ModuleLoader__.load({
382
427
  }).catch(() => undefined);
383
428
  }, 2000);
384
429
  return () => clearInterval(timer);
385
- }, [tab, ch.id]);
430
+ }, [tab, ch.id, qrStarted]);
386
431
 
387
432
  const close = () => {
388
433
  if (finished.current) return;
@@ -410,29 +455,37 @@ window.__ModuleLoader__.load({
410
455
  const config = { ...draft };
411
456
  setBusy(true);
412
457
  setError("");
458
+ setSuccess("");
413
459
  api(`/channels/${ch.id}/connect`, {
414
460
  method: "POST",
415
461
  headers: { "content-type": "application/json" },
416
- body: JSON.stringify({ config }),
462
+ body: JSON.stringify({ config, settings }),
417
463
  }).then((data) => {
418
464
  if (!data.ok) setError(serverText(data.error, t) || t("error.save"));
419
- else finish(400);
465
+ else {
466
+ setSuccess(data.newIdentity ? t("bind.newIdentity") : t("bind.success"));
467
+ finish(data.newIdentity ? 1400 : 500);
468
+ }
420
469
  }).catch(() => setError(t("error.save"))).finally(() => setBusy(false));
421
470
  };
422
471
 
423
472
  const switchTab = (next) => {
424
473
  setTab(next);
425
474
  setError("");
426
- if (next === "qr") startQr(false);
427
- else api(`/channels/${ch.id}/qr/cancel`, { method: "POST" }).catch(() => undefined);
475
+ setSuccess("");
476
+ if (next !== "qr") {
477
+ setQrStarted(false);
478
+ setPairing(null);
479
+ api(`/channels/${ch.id}/qr/cancel`, { method: "POST" }).catch(() => undefined);
480
+ }
428
481
  };
429
482
 
430
- const status = pairing && pairing.status;
431
- const src = qrSrc(pairing);
432
- const remain = pairing && pairing.remainingSeconds;
483
+ const status = qrStarted && pairing && pairing.status;
484
+ const src = qrStarted ? qrSrc(pairing) : "";
485
+ const remain = qrStarted && pairing && pairing.remainingSeconds;
433
486
 
434
487
  return h("div", { className: "ima-mask", role: "presentation", onMouseDown: (event) => event.stopPropagation(), onClick: (event) => { event.stopPropagation(); close(); }, onKeyDown: (event) => { if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); close(); } } },
435
- h("div", { className: "ima-modal", onClick: (e) => e.stopPropagation() },
488
+ h("div", { className: "ima-modal ima-account-modal", onClick: (e) => e.stopPropagation() },
436
489
  h("div", { className: "ima-modal-h" },
437
490
  h("h2", null, t("bind.title", { channel: channelLabel(ch, t) })),
438
491
  h("button", { className: "ima-x", onClick: close, "aria-label": t("bind.close") }, "×"),
@@ -442,19 +495,40 @@ window.__ModuleLoader__.load({
442
495
  h("button", { className: tab === "manual" ? "on" : "", onClick: () => switchTab("manual") }, t("bind.manual")),
443
496
  ),
444
497
  error && h("div", { className: "ima-error" }, error),
498
+ success && h("div", { className: "ima-ok" }, success),
499
+ h("div", { className: "ima-setup-section" },
500
+ h(AccountSettingsPicker, {
501
+ value: settings,
502
+ onChange: (patch) => setSettings((current) => ({ ...current, ...patch })),
503
+ catalog,
504
+ permissions,
505
+ workspaces,
506
+ createWorkspace,
507
+ pickDirectory,
508
+ modelT,
509
+ permissionT,
510
+ showAutoNameNote: true,
511
+ t,
512
+ }),
513
+ ),
445
514
  tab === "qr" && hasQr && (
446
515
  status === "success"
447
516
  ? h("div", { className: "ima-ok" }, t("bind.success"))
448
- : h("div", { className: "ima-qrbox" },
517
+ : src
518
+ ? h("div", { className: "ima-qrbox" },
449
519
  h("p", { className: "ima-hint" }, hintOf(ch, t)),
450
- src
451
- ? h("img", { src, alt: t("bind.qrAlt", { channel: channelLabel(ch, t) }) })
452
- : h("div", { className: "ima-qrph" }, busy || status === "starting" ? t("bind.generating") : serverText(pairing && pairing.error, t) || t("bind.waiting")),
520
+ h("img", { src, alt: t("bind.qrAlt", { channel: channelLabel(ch, t) }) }),
453
521
  remain > 0 && h("p", { className: "ima-hint" }, t("bind.expire", { time: Math.floor(remain / 60) + ":" + String(remain % 60).padStart(2, "0") })),
454
522
  status === "scanned" && h("p", { className: "ima-hint" }, t("bind.scanned")),
455
523
  (status === "expired" || status === "failed") && h("p", { className: "ima-error" }, serverText(pairing && pairing.error, t) || t("bind.retry")),
456
- h("button", { className: "ima-link", disabled: busy, onClick: () => startQr(true) }, t("bind.refresh")),
524
+ h("button", { className: "ima-btn", disabled: busy, onClick: () => startQr(true) }, t("bind.refresh")),
457
525
  )
526
+ : h("div", { className: "ima-bind-ready" },
527
+ h("p", { className: "ima-hint" }, hintOf(ch, t)),
528
+ (busy || status === "starting") && h("div", { className: "ima-bind-status" }, t("bind.generating")),
529
+ (status === "expired" || status === "failed") && h("div", { className: "ima-error" }, serverText(pairing && pairing.error, t) || t("bind.retry")),
530
+ h("button", { className: "ima-btn primary", disabled: busy || !settings.cwd || !settings.provider || !settings.model || !settings.permission, onClick: () => startQr(qrStarted) }, busy ? t("bind.generating") : qrStarted ? t("bind.refresh") : "生成二维码"),
531
+ )
458
532
  ),
459
533
  tab === "manual" && hasManual && h("div", null,
460
534
  ...ch.fields.map((f) => h("label", { key: f.key, className: "ima-field" },
@@ -575,6 +649,7 @@ window.__ModuleLoader__.load({
575
649
  h("button", {
576
650
  type: "button",
577
651
  className: "ima-chip-btn",
652
+ title: props.title || undefined,
578
653
  "aria-label": props.ariaLabel,
579
654
  "aria-expanded": Boolean(props.open),
580
655
  onMouseDown: (event) => event.stopPropagation(),
@@ -624,6 +699,221 @@ window.__ModuleLoader__.load({
624
699
  );
625
700
  }
626
701
 
702
+ function AccountSettingsPicker(props) {
703
+ const t = props.t || fallbackT;
704
+ const modelT = props.modelT || ((key) => key);
705
+ const permissionT = props.permissionT || ((key) => key);
706
+ const value = props.value || {};
707
+ const [open, setOpen] = useState("");
708
+ const [modelPane, setModelPane] = useState("root");
709
+ const [adding, setAdding] = useState(false);
710
+ const [addPath, setAddPath] = useState("");
711
+ const [addBusy, setAddBusy] = useState(false);
712
+ const [hint, setHint] = useState("");
713
+ const [confirmingFullAccess, setConfirmingFullAccess] = useState(false);
714
+ const [fullAccessAcknowledged, setFullAccessAcknowledged] = useState(false);
715
+ const items = props.workspaces || [];
716
+ const providers = props.catalog || [];
717
+ const permissions = props.permissions || [];
718
+ const provider = value.provider || (value.assistant && value.assistant.provider) || "";
719
+ const model = value.model || (value.assistant && value.assistant.model) || "";
720
+ const effort = value.reasoningEffort || (value.assistant && value.assistant.reasoningEffort) || "";
721
+ const cwd = value.cwd || "";
722
+ const permission = value.permission || "";
723
+ const privateAccess = value.privateAccess === "all" ? "all" : "approved";
724
+ const workspace = items.find((item) => item.path === cwd);
725
+ const modelGroups = providers.map((item) => ({
726
+ id: item.id,
727
+ name: item.name || item.id,
728
+ models: (item.models || []).map((entry) => ({
729
+ value: item.id + "::" + entry.id,
730
+ provider: item.id,
731
+ providerName: item.name || item.id,
732
+ model: entry.id,
733
+ label: entry.name || entry.id,
734
+ description: entry.description,
735
+ reasoning: entry.reasoning,
736
+ })),
737
+ })).filter((item) => item.models.length > 0);
738
+ const models = modelGroups.flatMap((item) => item.models);
739
+ const currentModel = models.find((item) => item.provider === provider && item.model === model);
740
+ const reasoning = currentModel && currentModel.reasoning;
741
+ const effectiveEffort = effort || (reasoning && reasoning.defaultEffort) || "";
742
+ const efforts = reasoning
743
+ ? [
744
+ ...(reasoning.defaultEffort ? [] : [{ id: "", name: modelT("effort.providerDefault") }]),
745
+ ...((reasoning.efforts || []).map((item) => ({ id: item.id, name: item.name || item.id, description: item.description }))),
746
+ ]
747
+ : [];
748
+ const effortLabel = reasoning
749
+ ? ((efforts.find((item) => item.id === effectiveEffort) || {}).name || effectiveEffort || modelT("effort.providerDefault"))
750
+ : "";
751
+ const permissionOptions = permissions.map((item) => ({ ...item, label: permissionLabel(item, t) }));
752
+ const currentPermission = permissionOptions.find((item) => item.value === permission);
753
+ const update = (patch) => {
754
+ setHint("");
755
+ if (typeof props.onChange === "function") props.onChange(patch);
756
+ };
757
+
758
+ const addWorkspace = (path) => {
759
+ const next = (path || "").trim();
760
+ if (!next) { setHint(t("error.chooseWorkspace")); return Promise.resolve(); }
761
+ if (typeof props.createWorkspace !== "function") { setHint(t("error.workspaceUnavailable")); return Promise.resolve(); }
762
+ setAddBusy(true);
763
+ return Promise.resolve(props.createWorkspace({ path: next })).then((created) => {
764
+ const cwdPath = (created && (created.path || created.cwd)) || next;
765
+ update({ cwd: cwdPath });
766
+ setAdding(false);
767
+ setAddPath("");
768
+ setOpen("");
769
+ }).catch((error) => setHint((error && error.message) || t("error.addWorkspace")))
770
+ .finally(() => setAddBusy(false));
771
+ };
772
+ const onAddWorkspace = () => {
773
+ setOpen("");
774
+ if (typeof props.pickDirectory === "function") {
775
+ Promise.resolve(props.pickDirectory()).then((picked) => picked && addWorkspace(picked)).catch(() => {
776
+ setAdding(true);
777
+ setAddPath("");
778
+ });
779
+ return;
780
+ }
781
+ setAdding(true);
782
+ setAddPath("");
783
+ };
784
+ const selectPermission = (next) => {
785
+ setOpen("");
786
+ if (next === permission) return;
787
+ if (next === "danger-full-access") {
788
+ setFullAccessAcknowledged(false);
789
+ setConfirmingFullAccess(true);
790
+ return;
791
+ }
792
+ update({ permission: next });
793
+ };
794
+ const field = (key, label, picker, wide) => h("div", { key, className: "ima-picker-field" + (wide ? " wide" : "") },
795
+ h("span", { className: "ima-picker-label" }, label),
796
+ picker,
797
+ );
798
+
799
+ return h("div", { className: "ima-account-settings" + (props.compact ? " compact" : "") },
800
+ field("workspace", props.workspaceLabel || "工作区", h(ChipMenu, {
801
+ open: open === "workspace",
802
+ onToggle: (next) => setOpen(next ? "workspace" : ""),
803
+ icon: h(FolderIcon),
804
+ label: (workspace && (workspace.title || workspace.path)) || cwd || "请选择工作区",
805
+ ariaLabel: props.workspaceLabel || "工作区",
806
+ className: "ima-account-picker",
807
+ },
808
+ items.length === 0 && h("div", { className: "ima-chip-empty" }, t("composer.noWorkspaces")),
809
+ ...items.map((item) => h(ChipRow, {
810
+ key: item.path,
811
+ icon: h(FolderIcon),
812
+ label: item.title || item.path,
813
+ hint: item.title ? item.path : "",
814
+ active: item.path === cwd,
815
+ onClick: () => { update({ cwd: item.path }); setOpen(""); },
816
+ })),
817
+ h("div", { className: "ima-chip-split" }),
818
+ h(ChipRow, { icon: h(PlusIcon), label: t("composer.addWorkspace"), onClick: onAddWorkspace }),
819
+ ), true),
820
+ field("model", "模型", h(ChipMenu, {
821
+ open: open === "model",
822
+ onToggle: (next) => { setOpen(next ? "model" : ""); if (next) setModelPane("root"); },
823
+ icon: null,
824
+ label: (currentModel && currentModel.label) || "请选择模型",
825
+ title: currentModel && currentModel.label,
826
+ suffix: effortLabel,
827
+ ariaLabel: modelT("trigger.selectAria"),
828
+ menuAria: modelT("menu.aria"),
829
+ className: "ima-account-picker ima-model-select",
830
+ menuClassName: "ima-model-menu",
831
+ },
832
+ modelPane === "root" && [
833
+ h(ChipRow, { key: "model", kv: true, label: modelT("menu.model"), hint: (currentModel && currentModel.label) || "请选择模型", chevron: true, onClick: () => setModelPane("model") }),
834
+ reasoning && h(ChipRow, { key: "effort", kv: true, label: modelT("menu.effort"), hint: effortLabel || modelT("effort.providerDefault"), chevron: true, onClick: () => setModelPane("effort") }),
835
+ ],
836
+ modelPane === "model" && (models.length === 0
837
+ ? h("div", { className: "ima-chip-empty" }, modelT("empty.models"))
838
+ : modelGroups.map((group) => h("section", { key: group.id, className: "ima-model-group", role: "group", "aria-label": group.name },
839
+ h("div", { className: "ima-model-group-title" }, group.name),
840
+ ...group.models.map((item) => h(ModelChoiceRow, {
841
+ key: item.value,
842
+ label: item.label,
843
+ description: item.description,
844
+ active: item.provider === provider && item.model === model,
845
+ onClick: () => {
846
+ const nextEffort = (item.reasoning && item.reasoning.defaultEffort) || "";
847
+ update({ provider: item.provider, model: item.model, reasoningEffort: nextEffort });
848
+ setOpen("");
849
+ },
850
+ })),
851
+ ))),
852
+ modelPane === "effort" && efforts.map((item) => h(ModelChoiceRow, {
853
+ key: item.id,
854
+ label: item.name,
855
+ description: item.description,
856
+ active: item.id === effectiveEffort,
857
+ onClick: () => { update({ provider, model, reasoningEffort: item.id }); setOpen(""); },
858
+ })),
859
+ )),
860
+ field("permission", "权限", h(ChipMenu, {
861
+ open: open === "permission",
862
+ onToggle: (next) => setOpen(next ? "permission" : ""),
863
+ icon: h(ShieldIcon),
864
+ label: (currentPermission && currentPermission.label) || "请选择权限",
865
+ ariaLabel: t("composer.permission"),
866
+ className: "ima-account-picker",
867
+ },
868
+ ...permissionOptions.map((item) => h(ChipRow, {
869
+ key: item.value,
870
+ icon: h(ShieldIcon),
871
+ label: item.label,
872
+ active: item.value === permission,
873
+ onClick: () => selectPermission(item.value),
874
+ })),
875
+ )),
876
+ field("private", "私聊准入", h(ChipMenu, {
877
+ open: open === "private",
878
+ onToggle: (next) => setOpen(next ? "private" : ""),
879
+ icon: h(ShieldIcon),
880
+ label: privateAccess === "all" ? "允许所有私聊用户" : "仅已批准用户",
881
+ ariaLabel: "私聊准入",
882
+ className: "ima-account-picker",
883
+ },
884
+ h(ChipRow, { icon: h(ShieldIcon), label: "仅已批准用户", active: privateAccess === "approved", onClick: () => { update({ privateAccess: "approved" }); setOpen(""); } }),
885
+ h(ChipRow, { icon: h(ShieldIcon), label: "允许所有私聊用户", active: privateAccess === "all", onClick: () => { update({ privateAccess: "all" }); setOpen(""); } }),
886
+ ), true),
887
+ privateAccess === "all" && h("div", { className: "ima-picker-note warning" }, t("settings.publicChatNotice")),
888
+ adding && h("div", { className: "ima-chip-dialog" },
889
+ h("strong", null, t("composer.addWorkspace")),
890
+ h("input", { value: addPath, placeholder: t("composer.workspacePath"), "aria-label": t("composer.workspacePath"), onChange: (event) => setAddPath(event.target.value) }),
891
+ h("div", { className: "ima-chip-dialog-actions" },
892
+ h("button", { className: "ima-btn", onClick: () => { setAdding(false); setAddPath(""); } }, t("action.cancel")),
893
+ h("button", { className: "ima-btn primary", disabled: addBusy || !addPath.trim(), onClick: () => addWorkspace(addPath) }, addBusy ? t("action.adding") : t("action.confirm")),
894
+ ),
895
+ ),
896
+ hint && h("div", { className: "ima-picker-note" }, hint),
897
+ props.showAutoNameNote && h("div", { className: "ima-picker-note" }, "绑定成功后会自动生成账号名,无需手动填写。"),
898
+ h(RiskConfirmation, {
899
+ open: confirmingFullAccess,
900
+ title: permissionT("confirm.title"),
901
+ description: permissionT("confirm.description"),
902
+ acknowledgeLabel: permissionT("confirm.acknowledge"),
903
+ cancelLabel: permissionT("confirm.cancel"),
904
+ confirmLabel: permissionT("confirm.enable"),
905
+ acknowledged: fullAccessAcknowledged,
906
+ onAcknowledgedChange: setFullAccessAcknowledged,
907
+ onCancel: () => { setFullAccessAcknowledged(false); setConfirmingFullAccess(false); },
908
+ onConfirm: () => {
909
+ update({ permission: "danger-full-access" });
910
+ setFullAccessAcknowledged(false);
911
+ setConfirmingFullAccess(false);
912
+ },
913
+ }),
914
+ );
915
+ }
916
+
627
917
  function ComposerBar(props) {
628
918
  const t = props.t || fallbackT;
629
919
  const items = typeof props.useWorkspaces === "function"
@@ -902,6 +1192,82 @@ window.__ModuleLoader__.load({
902
1192
  );
903
1193
  }
904
1194
 
1195
+ function AccountInspector({ account, catalog, permissions, workspaces, createWorkspace, pickDirectory, modelT, permissionT, t, onAction, onSave }) {
1196
+ const [draft, setDraft] = useState(account);
1197
+ const [note, setNote] = useState("");
1198
+ const saveSeq = useRef(0);
1199
+ useEffect(() => {
1200
+ saveSeq.current += 1;
1201
+ setDraft(account);
1202
+ setNote("");
1203
+ }, [account.id, account.cwd, account.permission, account.privateAccess, account.receiveEnabled, account.assistant && account.assistant.provider, account.assistant && account.assistant.model, account.assistant && account.assistant.reasoningEffort]);
1204
+ const save = (patch) => {
1205
+ const seq = ++saveSeq.current;
1206
+ const next = { ...draft, ...patch };
1207
+ setDraft(next);
1208
+ setNote("保存中…");
1209
+ return onSave(account.id, {
1210
+ name: next.name,
1211
+ cwd: next.cwd,
1212
+ provider: next.assistant.provider,
1213
+ model: next.assistant.model,
1214
+ reasoningEffort: next.assistant.reasoningEffort || null,
1215
+ permission: next.permission,
1216
+ privateAccess: next.privateAccess,
1217
+ }).then((ok) => {
1218
+ if (seq === saveSeq.current) setNote(ok ? "已保存" : "保存失败");
1219
+ return ok;
1220
+ });
1221
+ };
1222
+ const applySettings = (patch) => {
1223
+ const hasAssistant = Object.prototype.hasOwnProperty.call(patch, "provider") || Object.prototype.hasOwnProperty.call(patch, "model") || Object.prototype.hasOwnProperty.call(patch, "reasoningEffort");
1224
+ if (!hasAssistant) return save(patch);
1225
+ const assistant = {
1226
+ ...(draft.assistant || {}),
1227
+ ...(Object.prototype.hasOwnProperty.call(patch, "provider") ? { provider: patch.provider } : {}),
1228
+ ...(Object.prototype.hasOwnProperty.call(patch, "model") ? { model: patch.model } : {}),
1229
+ ...(Object.prototype.hasOwnProperty.call(patch, "reasoningEffort") ? { reasoningEffort: patch.reasoningEffort || undefined } : {}),
1230
+ };
1231
+ return save({ assistant });
1232
+ };
1233
+ return h("div", { className: "ima-inspector" },
1234
+ h("div", { className: "ima-inspector-head" },
1235
+ h(Logo, { id: account.platform }),
1236
+ h("div", { className: "ima-inspector-head-copy" },
1237
+ h("h3", { className: "ima-inspector-title" }, account.name),
1238
+ h("div", { className: account.connected ? "ima-inspector-status ok" : "ima-inspector-status" }, account.connected ? "● 运行正常" : "● " + (account.status || "未连接")),
1239
+ h("div", { className: "ima-account-id" }, account.id),
1240
+ ),
1241
+ ),
1242
+ h("div", { className: "ima-form" },
1243
+ h(AccountSettingsPicker, {
1244
+ value: draft,
1245
+ onChange: applySettings,
1246
+ catalog,
1247
+ permissions,
1248
+ workspaces,
1249
+ createWorkspace,
1250
+ pickDirectory,
1251
+ modelT,
1252
+ permissionT,
1253
+ compact: true,
1254
+ workspaceLabel: "当前工作区",
1255
+ t,
1256
+ }),
1257
+ h("div", { className: "ima-switch-row" },
1258
+ h("div", { className: "ima-switch-copy" }, h("strong", null, "接收消息"), h("small", null, "关闭后保留账号配置,但不接收新消息")),
1259
+ h("button", { type: "button", className: draft.receiveEnabled ? "ima-switch" : "ima-switch off", role: "switch", "aria-checked": Boolean(draft.receiveEnabled), "aria-label": "接收消息", onClick: () => onAction(account.id, "receive", { receiveEnabled: !draft.receiveEnabled }) }, h("i")),
1260
+ ),
1261
+ h("div", { className: note === "已保存" ? "ima-save-note ok" : "ima-save-note" }, note),
1262
+ h("div", { className: "ima-inspector-actions" },
1263
+ h("button", { className: "ima-btn", onClick: () => onAction(account.id, "check") }, "检查连接"),
1264
+ h("button", { className: "ima-btn", onClick: () => onAction(account.id, "reconnect") }, "重新连接"),
1265
+ h("button", { className: "ima-btn danger", onClick: () => { if (window.confirm("确定移除这个账号?本机保存的配置和凭据将一并删除。")) onAction(account.id, "remove"); } }, "移除接入"),
1266
+ ),
1267
+ ),
1268
+ );
1269
+ }
1270
+
905
1271
  function SettingsPage(props) {
906
1272
  const t = props.t || fallbackT;
907
1273
  const [channels, setChannels] = useState(null);
@@ -909,77 +1275,160 @@ window.__ModuleLoader__.load({
909
1275
  const [error, setError] = useState("");
910
1276
  const [busy, setBusy] = useState({});
911
1277
  const [editing, setEditing] = useState(null);
912
- // 请求序号守卫:快速连续操作时丢弃旧 GET 响应,避免旧状态覆盖新状态
1278
+ const [selected, setSelected] = useState(storedAccountSelection);
1279
+ const [expanded, setExpanded] = useState({ weixin: true });
1280
+ const [catalog, setCatalog] = useState({ providers: [], permissions: [], assistant: null, cwd: "", permission: "" });
1281
+ const workspaces = props.useWorkspaces ? (props.useWorkspaces((state) => state && state.items || []) || []) : [];
913
1282
  const refreshSeq = useRef(0);
1283
+ const selectAccount = useCallback((id) => {
1284
+ const next = id || "";
1285
+ setSelected(next);
1286
+ rememberAccountSelection(next);
1287
+ }, []);
914
1288
 
915
1289
  const refresh = useCallback(() => {
916
1290
  const seq = ++refreshSeq.current;
917
1291
  api("/channels").then((data) => {
918
1292
  if (seq !== refreshSeq.current) return;
919
- if (data.ok) { setChannels(data.channels); setPending(data.pending || []); setError(""); }
920
- else setError(serverText(data.error, t) || t("error.load"));
1293
+ if (data.ok) {
1294
+ setChannels(data.channels);
1295
+ setPending(data.pending || []);
1296
+ setError("");
1297
+ const all = (data.channels || []).flatMap((channel) => channel.accounts || []);
1298
+ setSelected((current) => {
1299
+ const next = all.some((item) => item.id === current) ? current : "";
1300
+ if (next !== current) rememberAccountSelection(next);
1301
+ return next;
1302
+ });
1303
+ } else setError(serverText(data.error, t) || t("error.load"));
921
1304
  }).catch(() => { if (seq === refreshSeq.current) setError(t("error.connection")); });
922
1305
  }, []);
923
1306
 
924
- useEffect(() => { ensureStyle(); refresh(); }, [refresh]);
925
1307
  useEffect(() => {
926
- const timer = setInterval(refresh, 4000);
927
- return () => clearInterval(timer);
1308
+ ensureStyle();
1309
+ refresh();
1310
+ api("/assistant").then((data) => {
1311
+ if (data.ok) setCatalog({ providers: data.providers || [], permissions: data.permissions || [], assistant: data.assistant || null, cwd: data.cwd || "", permission: data.permission || "" });
1312
+ }).catch(() => undefined);
928
1313
  }, [refresh]);
1314
+ useEffect(() => { const timer = setInterval(refresh, 4000); return () => clearInterval(timer); }, [refresh]);
929
1315
 
930
1316
  const onAction = (id, action, body) => {
1317
+ const removalFallback = action === "remove"
1318
+ ? (() => {
1319
+ const owner = (channels || []).find((channel) => (channel.accounts || []).some((account) => account.id === id));
1320
+ const ownerAccounts = owner && owner.accounts || [];
1321
+ const removedIndex = ownerAccounts.findIndex((account) => account.id === id);
1322
+ const adjacent = ownerAccounts[removedIndex + 1] || ownerAccounts[removedIndex - 1];
1323
+ if (adjacent) return adjacent.id;
1324
+ return (channels || []).flatMap((channel) => channel.accounts || []).find((account) => account.id !== id)?.id || "";
1325
+ })()
1326
+ : "";
931
1327
  setBusy((prev) => ({ ...prev, [id]: true }));
932
- api(`/channels/${id}/${action}`, {
1328
+ return api("/accounts/" + id + "/" + action, {
933
1329
  method: "POST",
934
1330
  headers: { "content-type": "application/json" },
935
1331
  body: JSON.stringify(body || {}),
936
1332
  }).then((data) => {
937
- if (!data.ok) setError(serverText(data.error, t) || t("error.action"));
938
- else setError("");
1333
+ if (!data.ok) { setError(serverText(data.error, t) || t("error.action")); return false; }
1334
+ setError("");
1335
+ if (action === "remove" && selected === id) selectAccount(removalFallback);
939
1336
  refresh();
940
- }).catch(() => setError(t("error.request"))).finally(() => {
941
- setBusy((prev) => ({ ...prev, [id]: false }));
942
- });
1337
+ return true;
1338
+ }).catch(() => { setError(t("error.request")); return false; }).finally(() => setBusy((prev) => ({ ...prev, [id]: false })));
943
1339
  };
1340
+ const saveAccount = (id, body) => onAction(id, "settings", body);
1341
+ const allAccounts = (channels || []).flatMap((channel) => channel.accounts || []);
1342
+ const selectedAccount = allAccounts.find((item) => item.id === selected);
944
1343
 
945
- return h("section", { className: "ima-page", "aria-label": t("settings.aria") },
1344
+ return h("section", { className: "ima-page ima-account-page", "aria-label": t("settings.aria") },
946
1345
  h("header", { className: "ima-head" },
947
1346
  h("div", null,
948
- h("h2", { className: "ima-title" }, t("settings.title")),
949
- h("p", { className: "ima-sub" }, t("settings.description")),
1347
+ h("h2", { className: "ima-title" }, "IM机器人"),
1348
+ h("p", { className: "ima-sub" }, "管理各渠道账号。每个账号独立选择工作区、模型和权限,配置仅保存在本机。"),
950
1349
  ),
951
1350
  ),
952
- h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory, permissionT: props.permissionT, modelT: props.modelT, t }),
953
1351
  error && h("div", { className: "ima-error" }, error),
954
- pending && pending.length > 0 && h("div", { className: "ima-pending" },
1352
+ pending.length > 0 && h("div", { className: "ima-pending" },
955
1353
  h("div", null, t("pending.notice")),
956
1354
  ...pending.map((p) => h("div", { key: p.channelId + p.userId, className: "ima-pending-row" },
957
- h("span", { style: { flex: 1 } }, (p.username || p.userId) + " · " + channelLabel({ id: p.channelId, label: p.channelId }, t)),
1355
+ h("span", { style: { flex: 1 } }, (p.username || p.userId) + " · " + (allAccounts.find((item) => item.id === p.channelId)?.name || p.channelId)),
958
1356
  h("button", { className: "ima-btn", onClick: () => onAction(p.channelId, "approve", { userId: p.userId }) }, t("action.approve")),
959
1357
  h("button", { className: "ima-btn", onClick: () => onAction(p.channelId, "deny", { userId: p.userId }) }, t("action.deny")),
960
1358
  )),
961
1359
  ),
962
1360
  channels == null
963
1361
  ? h("div", { className: "ima-empty" }, t("loading"))
964
- : h("div", { className: "ima-list" },
965
- ...channels.map((ch) => h(ChannelCard, {
966
- key: ch.id,
967
- ch,
968
- busy: busy[ch.id],
969
- onAction,
970
- onConfigure: () => setEditing(ch.id),
971
- t,
972
- })),
1362
+ : h("div", { className: "ima-account-shell" },
1363
+ h("div", { className: "ima-platforms" },
1364
+ ...channels.map((ch) => {
1365
+ const canExpand = (ch.accounts || []).length > 0;
1366
+ const open = canExpand && Boolean(expanded[ch.id]);
1367
+ const toggleExpanded = canExpand ? () => setExpanded({ ...expanded, [ch.id]: !open }) : undefined;
1368
+ const channelStatus = ch.total === 0
1369
+ ? { label: "0 个账号", tone: "muted" }
1370
+ : ch.online === ch.total
1371
+ ? { label: ch.online + " / " + ch.total + " 在线", tone: "online" }
1372
+ : ch.online === 0
1373
+ ? { label: ch.total + " / " + ch.total + " 离线", tone: "offline" }
1374
+ : { label: ch.online + " / " + ch.total + " 在线", tone: "partial" };
1375
+ return h("div", { key: ch.id, className: "ima-platform" + (open ? " open" : "") + (canExpand ? "" : " empty") },
1376
+ h("div", { className: "ima-platform-head", role: canExpand ? "button" : undefined, tabIndex: canExpand ? 0 : undefined, "aria-expanded": canExpand ? open : undefined, onClick: toggleExpanded, onKeyDown: canExpand ? (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggleExpanded(); } } : undefined },
1377
+ h(Logo, { id: ch.id }),
1378
+ h("span", { className: "ima-platform-title" }, channelLabel(ch, t)),
1379
+ h("span", { className: "ima-platform-count " + channelStatus.tone }, channelStatus.label),
1380
+ h("button", { className: "ima-platform-add", type: "button", onClick: (e) => { e.stopPropagation(); setEditing(ch.id); } }, "+ 添加账号"),
1381
+ h("span", { className: canExpand ? "ima-platform-caret" : "ima-platform-caret empty", "aria-hidden": "true" }, canExpand && h(IconChevron)),
1382
+ ),
1383
+ open && h("div", { className: "ima-account-list" },
1384
+ ...(ch.accounts || []).map((account) => h("button", { key: account.id, type: "button", className: account.id === selected ? "ima-account-row on" : "ima-account-row", onClick: () => selectAccount(account.id) },
1385
+ h("span", { className: account.connected ? "ima-dot on" : "ima-dot" }),
1386
+ h(Logo, { id: ch.id }),
1387
+ h("span", { className: "ima-account-copy" }, h("span", { className: "ima-account-name" }, account.name), h("span", { className: "ima-account-id" }, account.id)),
1388
+ h("span", { className: busy[account.id] ? "ima-account-state" : account.connected ? "ima-account-state online" : "ima-account-state offline" }, busy[account.id] ? "处理中…" : account.connected ? "在线" : "离线"),
1389
+ h("span", { className: "ima-account-next", "aria-hidden": "true" }, h(IconChevron)),
1390
+ )),
1391
+ ),
1392
+ );
1393
+ }),
1394
+ ),
1395
+ selectedAccount
1396
+ ? h(AccountInspector, {
1397
+ account: selectedAccount,
1398
+ catalog: catalog.providers,
1399
+ permissions: catalog.permissions,
1400
+ workspaces,
1401
+ createWorkspace: props.createWorkspace,
1402
+ pickDirectory: props.pickDirectory,
1403
+ modelT: props.modelT,
1404
+ permissionT: props.permissionT,
1405
+ t,
1406
+ onAction,
1407
+ onSave: saveAccount,
1408
+ })
1409
+ : h("div", { className: "ima-inspector-empty", role: "status" },
1410
+ h("div", { className: "ima-inspector-empty-copy" },
1411
+ h("h3", { className: "ima-inspector-empty-title" }, allAccounts.length ? t("settings.selectAccountTitle") : t("settings.noAccountsTitle")),
1412
+ h("p", { className: "ima-inspector-empty-description" }, allAccounts.length ? t("settings.selectAccountDescription") : t("settings.noAccountsDescription")),
1413
+ ),
1414
+ ),
973
1415
  ),
974
1416
  editing && h(BindModal, {
975
1417
  ch: (channels || []).find((item) => item.id === editing) || { id: editing, label: editing, kind: "qr", fields: [] },
1418
+ catalog: catalog.providers,
1419
+ permissions: catalog.permissions,
1420
+ workspaces,
1421
+ createWorkspace: props.createWorkspace,
1422
+ pickDirectory: props.pickDirectory,
1423
+ modelT: props.modelT,
1424
+ permissionT: props.permissionT,
1425
+ defaults: catalog,
976
1426
  onClose: () => setEditing(null),
977
- onConnected: () => { setEditing(null); refresh(); },
1427
+ onConnected: () => { setEditing(null); setExpanded((prev) => ({ ...prev, [editing]: true })); refresh(); },
978
1428
  t,
979
1429
  }),
980
1430
  );
981
1431
  }
982
-
983
1432
  const WB_CSS = `.dcu-wb,.ima-native{display:flex;flex:1;min-height:0;flex-direction:column;padding:0;padding-right:var(--dsh-sidebar-inline-padding,12px);box-sizing:border-box;color:var(--dsw-alias-label-primary,var(--ima-text));font:14px/20px inherit}.ima-n-toolbar{box-sizing:border-box;flex:none;height:36px;margin:2px -4px 4px 0;padding-left:4px;display:flex;justify-content:flex-end;align-items:center;gap:4px;overflow:visible;position:relative;z-index:2;color:var(--dsw-alias-label-tertiary,#81858C);border-radius:12px}.ima-n-head-label{white-space:nowrap;min-width:0;max-width:45%;flex:none;line-height:20px;font-size:14px;overflow:hidden;transition:max-width .18s var(--ds-ease-in-out,ease),margin-right .18s var(--ds-ease-in-out,ease),opacity .12s var(--ds-ease-in-out,ease),transform .18s var(--ds-ease-in-out,ease),visibility 0s linear}.ima-n-toolbar.is-search .ima-n-head-label{opacity:0;visibility:hidden;max-width:0;margin-right:-4px;transform:translate(-4px);transition-delay:0s,0s,0s,0s,.18s}.ima-n-search-slot{box-sizing:border-box;min-width:28px;max-width:28px;transition:max-width .18s var(--ds-ease-in-out,ease);flex:none;align-items:center;margin-left:auto;display:flex;position:relative;z-index:2}.ima-n-toolbar.is-search .ima-n-search-slot{flex:1;min-width:0;max-width:100%}.ima-n-search{box-sizing:border-box;cursor:text;width:100%;height:28px;color:var(--dsw-alias-label-secondary);transition:width .18s var(--ds-ease-in-out,ease),padding .18s var(--ds-ease-in-out,ease),border-color .18s var(--ds-ease-in-out,ease);background:transparent;border:none;border-radius:50%;flex:none;align-items:center;margin:0;padding:0;display:flex;overflow:hidden}.ima-n-toolbar.is-search .ima-n-search{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.10));width:calc(100% + 4px);height:30px;border-radius:10px;margin-inline:-2px;padding:0 4px 0 0}.ima-n-search-btn,.ima-n-head-btn{cursor:pointer;width:28px;height:28px;min-width:28px;min-height:28px;position:relative;z-index:1;color:var(--dsw-alias-label-secondary);background:transparent;border:none;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.ima-n-toolbar.is-search .ima-n-search-btn{width:28px;height:30px}.ima-n-search-btn:hover,.ima-n-head-btn:hover,.ima-n-head-btn.on{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06));color:var(--dsw-alias-label-primary,var(--ima-text))}.ima-n-toolbar.is-search .ima-n-search-btn:hover{background:transparent}.ima-n-head-acts{opacity:1;visibility:visible;max-width:32px;transition:max-width .18s var(--ds-ease-in-out,ease),opacity .12s var(--ds-ease-in-out,ease),transform .18s var(--ds-ease-in-out,ease),visibility 0s linear;flex:none;align-items:center;gap:4px;display:flex;overflow:visible;position:relative}.ima-n-toolbar.is-search .ima-n-head-acts{opacity:0;visibility:hidden;pointer-events:none;max-width:0;transform:translate(4px);transition-delay:0s,0s,0s,.18s}.ima-n-head-filter{position:relative}.ima-n-search-input{display:none;opacity:0;pointer-events:none;width:0;min-width:0;flex:none;color:var(--dsw-alias-label-primary,var(--ima-text));transition:opacity .12s var(--ds-ease-in-out,ease);background:transparent;border:none;outline:none;flex:1;font-size:13px;line-height:18px}.ima-n-toolbar.is-search .ima-n-search-input{display:block;opacity:1;pointer-events:auto;margin-left:-2px;width:auto;flex:1;min-width:0}.ima-n-search-input::placeholder{color:var(--dsw-alias-label-tertiary,#81858C)}.ima-n-search-clear{cursor:pointer;width:24px;height:24px;color:var(--dsw-alias-label-secondary);background:transparent;border:none;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.ima-n-search-clear:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}@media (prefers-reduced-motion:reduce){.ima-n-head-label,.ima-n-search-slot,.ima-n-search,.ima-n-head-acts,.ima-n-search-input{transition:none}}.ima-n-filter-menu{position:absolute;right:0;top:calc(100% + 6px);z-index:30;min-width:196px;padding:8px 6px;border:1px solid var(--dsw-alias-border-inverted,rgba(255,255,255,.12));border-radius:12px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2,#1c2128));box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.36))}.ima-n-filter-label{padding:6px 10px 4px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#81858C)}.ima-n-filter-split{height:1px;margin:6px 8px;background:var(--dsw-alias-border-l2,rgba(255,255,255,.1))}.ima-n-filter-menu button{display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;min-height:36px;padding:6px 10px;border:0;border-radius:8px;background:transparent;color:inherit;font:14px/20px inherit;cursor:pointer;text-align:left}.ima-n-filter-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}.ima-n-filter-tick{width:16px;height:16px;flex:none}.ima-native-tree,.dcu-wb-tree{padding:0 0 16px;scrollbar-gutter:stable}.ima-native-project+.ima-native-project,.dcu-wb-project+.dcu-wb-project{margin-top:4px}.ima-native-project>*+*,.dcu-wb-project>*+*{margin-top:2px}
984
1433
  .dcu-wb *,.ima-native *{box-sizing:border-box}
985
1434
  .dcu-wb-tree,.ima-native-tree{flex:1;min-height:0;overflow-y:auto;padding-bottom:16px;user-select:none}