@kimiclaw/cli 1.0.41 → 1.0.44

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 (94) hide show
  1. package/README.md +19 -17
  2. package/bin/dscode.exe +4 -0
  3. package/install.cjs +15 -0
  4. package/package.json +9 -9
  5. package/web/dist/assets/AssistantsView-Y4TXobGE.js +1 -0
  6. package/web/dist/assets/AutomationView-DfAF2L92.js +3 -0
  7. package/web/dist/assets/Button-D-g7PgYh.js +1 -0
  8. package/web/dist/assets/ChannelConfigView-WJ-zUV8p.js +12 -0
  9. package/web/dist/assets/ChartsView-CSAfGqTC.js +1 -0
  10. package/web/dist/assets/ConnectorsView-DaHmxnGE.js +2 -0
  11. package/web/dist/assets/{MessageBubble-CV16DZMG.js → DiffPreview-D8tIj_aF.js} +64 -67
  12. package/web/dist/assets/FileContextMenu-C5WYeBNu.js +1 -0
  13. package/web/dist/assets/FileTreeView-B7IN0KmE.js +1 -0
  14. package/web/dist/assets/HookConfigView-9gqvrRhQ.js +2 -0
  15. package/web/dist/assets/InboxView-BcEfijbj.js +1 -0
  16. package/web/dist/assets/InputArea-D5F91Uwk.js +14 -0
  17. package/web/dist/assets/Install-Cuelo0If.js +2 -0
  18. package/web/dist/assets/MemoryView-BvZSh5-T.js +1 -0
  19. package/web/dist/assets/ModelsView-BgvMN8xv.js +1 -0
  20. package/web/dist/assets/PluginsView-C3d6e8vV.js +1 -0
  21. package/web/dist/assets/ProjectsView-CM7GOsoK.js +1 -0
  22. package/web/dist/assets/SessionGrid-BQSrCDqQ.js +4 -0
  23. package/web/dist/assets/SettingsModal-BvGXq5EE.js +4 -0
  24. package/web/dist/assets/SkillsView-87kGRliE.js +1 -0
  25. package/web/dist/assets/TemplatesTab-8MLwVNwV.js +1 -0
  26. package/web/dist/assets/ToolsView-CjdYiaNz.js +1 -0
  27. package/web/dist/assets/{agentIconSet-Btsb_SC4.js → agentIconSet-CDeMxTHf.js} +1 -1
  28. package/web/dist/assets/api-ZQf0Ys8y.js +1 -0
  29. package/web/dist/assets/channelMeta-BO645sjD.js +1 -0
  30. package/web/dist/assets/common-CPZxdYLs.js +304 -0
  31. package/web/dist/assets/icons-B8Ngx6rM.js +1 -0
  32. package/web/dist/assets/imageUrl-CrQM4gmf.js +74 -0
  33. package/web/dist/assets/index-Bm7r92T3.css +1 -0
  34. package/web/dist/assets/index-STsyoFCk.js +145 -0
  35. package/web/dist/assets/installDiagnosis-ZYUVgJIJ.js +3 -0
  36. package/web/dist/assets/{markdown-DAQZeY5V.js → markdown-Cps-36Z5.js} +1 -1
  37. package/web/dist/assets/{panels-DYiQiVWh.js → panels-DCwx2Pbu.js} +1 -1
  38. package/web/dist/assets/{react-vendor-BlngCquv.js → react-vendor-CXI113IS.js} +1 -1
  39. package/web/dist/assets/sessionKind-CZ1kQQII.js +1 -0
  40. package/web/dist/assets/settingsStore-BSdi9gNd.js +1 -0
  41. package/web/dist/assets/src-BK8SoTFV.js +1 -0
  42. package/web/dist/assets/{state-_ZfNVAsd.js → state-pOTP5BEk.js} +1 -1
  43. package/web/dist/assets/statusAxesRefresh--2evRuAU.js +1 -0
  44. package/web/dist/assets/sttLanguages-BPcOF0nQ.js +2 -0
  45. package/web/dist/assets/{types-JssxRFJn.js → threads-lr33dwqg.js} +1 -1
  46. package/web/dist/assets/useConfirm-CQjBnYuP.js +1 -0
  47. package/web/dist/assets/{useTranslation-BGmCDuQI.js → useTranslation-gGKZZfux.js} +1 -1
  48. package/web/dist/assets/websocket-CeKJTCdp.js +1 -0
  49. package/web/dist/assets/whatsNewStore-C0hbStfc.js +1 -0
  50. package/web/dist/assets/{workspaceSemantics-RaIRer76.js → workspaceSemantics-CW8ytHq2.js} +3 -3
  51. package/web/dist/favicon.svg +31 -14
  52. package/web/dist/icons/icon-1024.png +0 -0
  53. package/web/dist/icons/icon-180.png +0 -0
  54. package/web/dist/icons/icon-192.png +0 -0
  55. package/web/dist/icons/icon-512.png +0 -0
  56. package/web/dist/icons/icon-maskable-512.png +0 -0
  57. package/web/dist/index.html +38 -35
  58. package/web/dist/logo.svg +42 -20
  59. package/web/dist/manifest.webmanifest +2 -2
  60. package/web/dist/vendor/MANIFEST.json +24 -0
  61. package/web/dist/vendor/d3.min.js +2 -0
  62. package/web/dist/vendor/echarts.min.js +45 -0
  63. package/web/dist/assets/AssistantsView-dhdYVIy0.js +0 -1
  64. package/web/dist/assets/AutomationView-D1dU5ZV7.js +0 -1
  65. package/web/dist/assets/ChannelConfigView-CEPVZntU.js +0 -8
  66. package/web/dist/assets/ChartsView-DdN-beHW.js +0 -1
  67. package/web/dist/assets/ConnectorsView-CseCss9C.js +0 -1
  68. package/web/dist/assets/FileTreeView-Dnc3-gRF.js +0 -1
  69. package/web/dist/assets/HookConfigView-DA2h4HdJ.js +0 -1
  70. package/web/dist/assets/InputArea-DAgOOjOc.js +0 -14
  71. package/web/dist/assets/MemoryView-D6OUBi4-.js +0 -1
  72. package/web/dist/assets/ModelsView-BuqD9vWl.js +0 -1
  73. package/web/dist/assets/PluginsView-CIziDHFJ.js +0 -2
  74. package/web/dist/assets/ProjectsView-c6faWy32.js +0 -1
  75. package/web/dist/assets/SessionGrid-BZJHcklh.js +0 -4
  76. package/web/dist/assets/SettingsModal-BqdGEGW-.js +0 -4
  77. package/web/dist/assets/SkillsView-CB6CKkmb.js +0 -1
  78. package/web/dist/assets/TemplatesTab-B8efVwVZ.js +0 -1
  79. package/web/dist/assets/ThreadsView-CDoM0aNb.js +0 -2
  80. package/web/dist/assets/ToolsView-BG-xsWsO.js +0 -1
  81. package/web/dist/assets/api-CCt9DRQm.js +0 -1
  82. package/web/dist/assets/channelMeta-BGQXQxgj.js +0 -1
  83. package/web/dist/assets/cn-rx4uumOJ.js +0 -1
  84. package/web/dist/assets/common-BHXgEvgk.js +0 -192
  85. package/web/dist/assets/icons-BvYhTENi.js +0 -1
  86. package/web/dist/assets/index-BNI6CNsY.css +0 -1
  87. package/web/dist/assets/index-BX-d2OBW.js +0 -130
  88. package/web/dist/assets/settingsStore-RLUAWgIk.js +0 -1
  89. package/web/dist/assets/src-49LUQhkG.js +0 -1
  90. package/web/dist/assets/sttLanguages-aqoVC79g.js +0 -2
  91. package/web/dist/assets/ttsSettings-DHo3OsOq.js +0 -15
  92. package/web/dist/assets/websocket-C9e3h7VU.js +0 -1
  93. package/web/dist/assets/whatsNewStore-Bf_7lW8o.js +0 -1
  94. /package/web/dist/assets/{MessageBubble-CCTRbIMZ.css → DiffPreview-CCTRbIMZ.css} +0 -0
package/README.md CHANGED
@@ -1166,31 +1166,33 @@ reader's own language instead of being translated on the fly.
1166
1166
 
1167
1167
  ## What's New · 更新日志
1168
1168
 
1169
- ### 1.0.41 — 2026-10-23
1169
+ ### 1.0.44 — 2026-11-05
1170
1170
 
1171
- 收藏与日历、品牌标识工作室、key 轮换与技能安全修复
1171
+ 世界与全息产物、通知流水、工具操作凭据与连接器接线
1172
1172
 
1173
- Favorites & calendar, brand-icon studio, provider key rotation and skill hardening
1173
+ Physics worlds and holograms, a persistent notification feed, operation receipts and connectors wired back
1174
1174
 
1175
1175
  **English**
1176
1176
 
1177
- - Favorites and retrieval: sessions and artifacts can be starred into their own view, with sorting and a favorites toolbar in the artifact list; sidebar and panels are unified under a rebuilt app shell with fuller bilingual copy.
1178
- - Automation calendar: scheduled tasks gain a calendar view with a day-agenda sidebar, so you can see at a glance what runs when and what already ran.
1179
- - Brand-icon studio: the app icon can be recolored and relettered from settings, previewed live and persisted.
1180
- - Turn-bound suggestions: a ghost suggestion no longer reappears in a later turn — it renders only for the turn it was produced in.
1181
- - Server and CLI: the daemon starts on login; question_answer is broadcast so answering on one client dismisses the prompt everywhere; the compaction progress line moves to the end of the output area instead of displacing the status line.
1182
- - Provider key rotation: a throttled or dead key rolls over to the next one without breaking the session, plus a profile-append tool and a reviewer actor.
1183
- - Skill hardening: `skill_define` rejects newline injection and its overwrite guard now also checks registered skills; a skill whose frontmatter repeats a top-level key is rejected wholesale instead of silently overwritten.
1177
+ - Two new artifact types you can actually handle: a **world** where dragging a body and releasing applies an impulse (gravity and damping sliders, play/pause/reset) and a **hologram** whose explode slider pulls parts apart along their declared vectors; both stop rendering when nothing moves. The charts wall also ships five ready-made dashboards (runtime, token usage, memory write/recall, memory ledger, orbit world), and an artifact that fails to load offers "let AI fix it" with the path and the original error pre-filled.
1178
+ - A **notification feed** now keeps what used to vanish with the toast: disconnects, finished background jobs and newly delivered inbox messages stay in a bell list with an unread count and one-click clear, so nothing is lost to a 10-second toast.
1179
+ - Mobile and right-panel rework: on portrait phones the horizontal session tabs become a left rail with a status ring and a "waiting on what" badge per session, and the docked project rail is gone — threads and the library are right-panel cards you can collapse, close, pin, rename and reorder, remembered across restarts.
1180
+ - Tools now write an **operation receipt** (`~/.agent/operations/`) before they run: a reconnect replay, a post-restart resume or a retry collision reuses the recorded result for the same callId, so a `git push`, an email or a file deletion that already happened is never repeated.
1181
+ - Chinese recall and mojibake: when recall is untrustworthy (no word tokens, all-zero scores) memories are re-ranked locally over up to 120 candidates, and memories stored as `æ¯`-style mojibake are restored losslessly while plain Western text is never touched. On session restore only the newest reminder of each family (board, plan, fact, context, scene plan) is kept, so a long session stops reloading a dozen contradictory snapshots.
1182
+ - The server reconnects several loose ends: a `/api/inbox` surface (list, ingest, drain, complete, touch, delete), an hourly `/api/memory/metrics` ledger, `DELETE /api/logs` by file name or age (a missing parameter is a 400, never "delete everything"), four IM channel factories registered at startup under `DEEPSEEKCODE_CHANNELS_IM=1` (Telegram, Discord, Slack, WeChat), provider image settings persisted as endpoint / model / key with the key reported only as a boolean, and `clear_history` clearing the screen while keeping the session model.
1183
+ - CLI and tool fixes: pasted prompts carrying zero-width characters no longer swallow Enter (invisible code points are stripped before submit), `read_file` returns a `snippet_id` that narrows `edit_file` to the lines you actually read (and refuses if the file changed since), Bash no longer hangs to the timeout when a grandchild holds the output pipe, and a new read-only `list_sessions` tool answers "what is running" instead of a goal list.
1184
+ - Channels and connectors: DBHub now ships inside the install tree and runs offline when a recent Node is present, falling back to a global install otherwise; ```viz fences are downgraded to readable plain text for text-only IMs like WeChat, Feishu and Telegram instead of raw JSON; and "where does a scheduled run deliver" collapses into one rule that records a reason instead of creating an empty session when there is no peer.
1184
1185
 
1185
1186
  **中文**
1186
1187
 
1187
- - 收藏与检索:会话 / 产物可加星收藏并单独成栏,产物清单支持排序与收藏工具条;侧栏与面板随 App 壳重构统一,界面文案补齐中英对照。
1188
- - 自动化日历:定时任务从列表升级为日历视图,配「当日议程」侧栏,按天看清什么时候会跑、跑过没有。
1189
- - 品牌标识工作室:应用图标可在设置里换色换字形,改动即时预览并落盘。
1190
- - 会话建议按回合判过期:上一轮给出的「幽灵建议」不会在新回合收场后重新冒出来,只在它所属的那一轮显示。
1191
- - 服务端与 CLI:登录即拉起 daemon;question_answer 改为广播,任一客户端作答后其余端同步收起提问;压缩进度行落到输出区尾部,不再顶掉状态行。
1192
- - provider key 轮换:单个 key 被限流或失效时自动切到下一个,不中断会话;新增画像追加工具与评审线程 actor。
1193
- - 技能安全加固:`skill_define` 拒收换行注入,overwrite 守卫也看已注册技能;技能 frontmatter 出现重复顶层 key 时整份拒收,不再静默覆盖。
1188
+ - 视觉产物新增两种可动手的形态:**世界**(拖住小球往一个方向松手就是一次施力,重力与阻尼可调,播放 / 暂停 / 复位)与**全息**(一根拆解滑杆把零件沿各自向量炸开);两者静止时自动停帧,不再空转烧电。图表大屏同时内置五张现成看板(本机运行时 / Token 用量 / 记忆写入与召回 / 内存账本 / 轨道世界),产物读不出来时红字旁直接给「让 AI 解决」,路径与原始报错已预填进新会话。
1189
+ - 新增**通知流水**:右下角铃铛里留下一份不随提示过期的历史 —— 连接断开、后台任务完成、收件箱新消息都记在里面,带未读计数与一键清空。此前 toast 到期即删,回来只看到「刚才好像发生过什么」。
1190
+ - 移动端与右栏重排:竖屏手机的横向会话标签条改成左侧常驻会话轨,每条带状态环与「在等什么」徽标;项目页那道停靠栏撤掉,「线程」和「库」变成右栏卡片,可折叠 / 关闭 / 置顶 / 改名 / 排序,且偏好重启后仍在。
1191
+ - 工具执行前先落**操作凭据**(`~/.agent/operations/`):断线重放、进程重启续跑或恢复与重试撞车时,同一个 callId 直接复用上次结果 —— 已经发生的 `git push`、发信、删文件不会再做一遍。
1192
+ - 中文记忆召回与乱码:召回结果不可信(中文整串切不出词元、命中分数恒为 0)时改用本地分词重排最多 120 条候选;此前被写成 `æ¯` 形态的中文记忆可无损还原,判定保守到不含汉字的西文一律不动。会话恢复时同一族提醒(黑板 / 计划 / 事实 / 上下文 / 场景图)只留最后一条,长会话不会把十几份互相矛盾的旧快照读回上下文。
1193
+ - 服务端把几条断掉的线接回来:`/api/inbox` 一组接口(查询 / 投递 / 抽干 / 回写 / 人物触碰 / 删除)、`/api/memory/metrics` 小时级账本、`DELETE /api/logs` 按文件名或按天清理(缺参数一律 400,绝不当「删全部」);`DEEPSEEKCODE_CHANNELS_IM=1` 启动即注册 Telegram / Discord / Slack / 微信四个 IM 工厂;provider 生图配置的 endpoint / model / apiKey 三态落盘,读回时 key 只回布尔;`clear_history` 擦屏但保留该会话挑的模型。
1194
+ - CLI 与工具几处扎手的:从网页 / Figma 粘进来的提示词带零宽字符时,屏幕上空着却按不动回车 —— 现在提交前统一清洗不可见码位;`read_file` 返回 `snippet_id`,`edit_file` 带上它就只在读过的行区间里找,文件在此期间被改过则直接拒绝并要求重读;命令已退出但后台孙进程还攥着输出管道时,Bash 不再一路挂到超时,而是按真实退出码结账并提示输出可能不完整;新增只读工具 `list_sessions`,「现在在跑什么」问它而不是问目标列表。
1195
+ - 频道与连接器:DBHub 的文件随安装包一起铺进安装树,机器上有够新的 Node 就离线跑副本、没有才退回全局安装;回复里的 ```viz 图在微信 / 飞书 / Telegram 这类纯文本频道中降级成可读的结构化文本而不是一坨 JSON;定时任务结果投到「哪个频道 / 哪个会话」收敛成唯一判据,没对端或频道下没会话时如实记原因、不建空壳会话。
1194
1196
 
1195
1197
  _Earlier releases: see the version list on this package page, or `CHANGELOG.md` in the repository (generated from the same source)._
1196
1198
 
package/bin/dscode.exe CHANGED
@@ -8,5 +8,9 @@ echo "" >&2
8
8
  echo "Run the postinstall manually (adjust path for local vs global install):" >&2
9
9
  echo " node node_modules/@deepseekcode/cli/install.cjs" >&2
10
10
  echo "" >&2
11
+ echo "If npm reported that install scripts were not covered by 'allowScripts'" >&2
12
+ echo "(the default since npm 11), allow this package's postinstall and reinstall:" >&2
13
+ echo " npm install -g --allow-scripts=@deepseekcode/cli @deepseekcode/cli" >&2
14
+ echo "" >&2
11
15
  echo "Or reinstall without --ignore-scripts / --omit=optional." >&2
12
16
  exit 1
package/install.cjs CHANGED
@@ -11,6 +11,12 @@
11
11
  // leaves the placeholder stub in place. cli-wrapper.cjs (same directory) can be
12
12
  // invoked manually as a fallback.
13
13
  //
14
+ // Every one of those paths must exit NON-ZERO. npm hides postinstall output at
15
+ // the default loglevel and treats exit 0 as success, so a silent `return` made
16
+ // `npm i -g` report "changed N packages" while the placeholder stub stayed put —
17
+ // the user saw a successful install and a `dscode` that only printed this
18
+ // script's "not installed" message. Fail loudly instead.
19
+ //
14
20
  // On Windows the stub (a non-PE .exe) surfaces as a native "not a valid Win32
15
21
  // application" error, so its message is best-effort; install.cjs failure output
16
22
  // above is the primary guidance when postinstall does run.
@@ -267,6 +273,7 @@ function main() {
267
273
  `[${WRAPPER_NAME} postinstall] Unsupported platform: ${process.platform} ${arch()}`,
268
274
  )
269
275
  console.error(` Supported: ${Object.keys(PLATFORMS).join(', ')}`)
276
+ process.exitCode = 1
270
277
  return
271
278
  }
272
279
 
@@ -276,6 +283,7 @@ function main() {
276
283
  `[${WRAPPER_NAME} postinstall] Native binaries for ${platformKey} are not available on this release channel.`,
277
284
  )
278
285
  console.error(` Available: ${Object.keys(optionalDeps).map((p) => p.replace(PACKAGE_PREFIX + '-', '')).join(', ')}`)
286
+ process.exitCode = 1
279
287
  return
280
288
  }
281
289
 
@@ -289,11 +297,18 @@ function main() {
289
297
  console.error(' You are running x64 Node under Rosetta 2 on Apple Silicon. npm only')
290
298
  console.error(' installed the darwin-x64 binary. Install arm64 Node and reinstall:')
291
299
  console.error(' arch -arm64 zsh -c "nvm install --lts && npm i -g ' + WRAPPER_NAME + '"')
300
+ process.exitCode = 1
292
301
  return
293
302
  }
294
303
  console.error(' This happens with --omit=optional or when the download failed.')
295
304
  console.error(' The `dscode` command will print instructions when invoked.')
296
305
  console.error(' Fallback: node ' + path.join(__dirname, 'cli-wrapper.cjs'))
306
+ // The platform package is a 100MB optionalDependency — npm skips a failed
307
+ // optional download without a word, which is exactly how this install gets
308
+ // far enough to look successful.
309
+ console.error(` Or install the platform package directly:`)
310
+ console.error(` npm install -g ${info.pkg}`)
311
+ process.exitCode = 1
297
312
  return
298
313
  }
299
314
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimiclaw/cli",
3
- "version": "1.0.41",
3
+ "version": "1.0.44",
4
4
  "description": "DeepSeekCode — local-first AI coding agent for your terminal: one local runtime with a TUI, a web UI and an API, a permission/approval layer, read-only plan mode, and any OpenAI-compatible model.",
5
5
  "keywords": [
6
6
  "deepseekcode",
@@ -36,14 +36,14 @@
36
36
  "xterm": "5.3.0"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@kimiclaw/cli-darwin-arm64": "1.0.41",
40
- "@kimiclaw/cli-darwin-x64": "1.0.41",
41
- "@kimiclaw/cli-linux-x64": "1.0.41",
42
- "@kimiclaw/cli-linux-arm64": "1.0.41",
43
- "@kimiclaw/cli-linux-x64-musl": "1.0.41",
44
- "@kimiclaw/cli-linux-arm64-musl": "1.0.41",
45
- "@kimiclaw/cli-win32-x64": "1.0.41",
46
- "@kimiclaw/cli-win32-arm64": "1.0.41"
39
+ "@kimiclaw/cli-darwin-arm64": "1.0.44",
40
+ "@kimiclaw/cli-darwin-x64": "1.0.44",
41
+ "@kimiclaw/cli-linux-x64": "1.0.44",
42
+ "@kimiclaw/cli-linux-arm64": "1.0.44",
43
+ "@kimiclaw/cli-linux-x64-musl": "1.0.44",
44
+ "@kimiclaw/cli-linux-arm64-musl": "1.0.44",
45
+ "@kimiclaw/cli-win32-x64": "1.0.44",
46
+ "@kimiclaw/cli-win32-arm64": "1.0.44"
47
47
  },
48
48
  "files": [
49
49
  "bin/",
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{$ as t,It as n,Tt as r,V as i,_t as a,at as o,d as s,dt as c,f as l,it as u,kr as d,n as f,ni as p,v as m,z as h,zr as g}from"./icons-B8Ngx6rM.js";import{t as _}from"./useTranslation-gGKZZfux.js";import{t as v}from"./Button-D-g7PgYh.js";import"./src-BK8SoTFV.js";import{n as y}from"./sessionKind-CZ1kQQII.js";import{t as b}from"./api-ZQf0Ys8y.js";import{I as x}from"./markdown-Cps-36Z5.js";import{t as S}from"./useConfirm-CQjBnYuP.js";import{f as C,r as w}from"./common-CPZxdYLs.js";import{n as T,t as E}from"./channelMeta-BO645sjD.js";import{r as D}from"./index-STsyoFCk.js";var O=e(p(),1),k=x(),A=(0,O.memo)(function({selectedSessionId:e,onSelectionChange:t,onOpenSession:n,onNavigate:i,onCollapse:a,onDeleted:o}){let{t:s}=_(),[l,d]=(0,O.useState)([]),[f,p]=(0,O.useState)(!0),[m,h]=(0,O.useState)(null),[v,y]=(0,O.useState)(null),[x,w]=(0,O.useState)(null),[T,E]=(0,O.useState)(!1),[D,A]=(0,O.useState)(null),[j,N]=(0,O.useState)(null),P=(0,O.useCallback)(async()=>{try{let e=await b.assistants.list();e.success&&Array.isArray(e.data)?(d(e.data),h(null)):h(e.error||s(`assistants.loadFailed`))}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},[s]);(0,O.useEffect)(()=>{P();let e=window.setInterval(()=>{P()},8e3);return()=>window.clearInterval(e)},[P]);let F=(0,O.useCallback)(async(e,t)=>{(await b.assistants.update(e,t)).success&&P()},[P]),I=(0,O.useCallback)(async()=>{E(!0),N(null);try{let e=await b.assistants.create({title:s(`assistants.newAssistantTitle`)});e.success&&e.data?(await P(),t(e.data),w(e.data.sessionId)):N(e.error||s(`assistants.createFailed`))}catch(e){N(e instanceof Error?e.message:String(e))}finally{E(!1)}},[P,t,s]),L=(0,O.useCallback)(async(e,t)=>{N(null);try{let n=await b.assistants.rename(e,t);n.success?(w(null),await P()):N(n.error||s(`assistants.renameFailed`))}catch(e){N(e instanceof Error?e.message:String(e))}},[P,s]),[R,z]=S(),B=(0,O.useCallback)(async(t,n)=>{if(await z({message:s(`assistants.deleteConfirm`,{title:n}),variant:`danger`})){N(null),A(t);try{let n=await b.assistants.remove(t);n.success?(x===t&&w(null),e===t&&o?.(t),await P()):N(n.error||s(`assistants.deleteFailed`))}catch(e){N(e instanceof Error?e.message:String(e))}finally{A(null)}}},[x,e,o,P,z,s]);return(0,O.useEffect)(()=>{if(!e)return;let n=l.find(t=>t.sessionId===e);n&&t(n)},[l,e,t]),(0,k.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[R,(0,k.jsxs)(`div`,{className:`flex items-center justify-between border-b border-dark-border px-4 py-2.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(g,{size:16,className:`text-accent-blue`,"aria-hidden":`true`}),(0,k.jsx)(`h2`,{className:`text-sm font-semibold text-dark-text`,children:s(`assistants.title`)}),!f&&(0,k.jsx)(`span`,{className:`rounded-full bg-dark-hover px-1.5 py-0.5 text-badge text-dark-muted`,children:l.length})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>void I(),disabled:T,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-accent-blue hover:bg-dark-hover disabled:opacity-50`,title:s(`assistants.newAssistantHint`),"data-testid":`assistants-create`,children:[(0,k.jsx)(c,{size:12,"aria-hidden":`true`}),s(`assistants.newAssistant`)]}),(0,k.jsxs)(`button`,{type:`button`,onClick:()=>void P(),className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text`,title:s(`common.refresh`),children:[(0,k.jsx)(u,{size:12,className:f?`animate-spin`:``,"aria-hidden":`true`}),s(`common.refresh`)]}),a&&(0,k.jsx)(`button`,{type:`button`,onClick:a,className:`rounded p-1 text-dark-muted hover:bg-dark-hover hover:text-dark-text`,title:s(`assistants.collapseList`),"aria-label":s(`assistants.collapseList`),"aria-expanded":!0,"data-testid":`assistants-list-collapse`,children:(0,k.jsx)(r,{size:13,"aria-hidden":`true`})})]})]}),j&&(0,k.jsx)(`div`,{className:`border-b border-dark-border px-4 py-1.5 text-meta text-accent-red`,role:`alert`,children:j}),(0,k.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-2`,children:f&&l.length===0?(0,k.jsx)(`div`,{className:`py-2`,role:`status`,"aria-label":s(`assistants.loading`),children:(0,k.jsx)(C,{count:4})}):m&&l.length===0?(0,k.jsx)(`div`,{className:`py-8 text-center text-xs text-accent-red`,children:m}):l.length===0?(0,k.jsxs)(`div`,{className:`py-10 text-center text-xs text-dark-muted`,children:[(0,k.jsx)(g,{size:24,className:`mx-auto mb-2 text-dark-muted`,"aria-hidden":`true`}),(0,k.jsx)(`p`,{children:s(`assistants.empty`)}),(0,k.jsx)(`p`,{className:`mt-1 text-meta`,children:s(`assistants.emptyHint`)}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>i(`channels`),className:`mt-3 rounded border border-dark-border px-2.5 py-1 text-meta text-dark-text hover:bg-dark-hover`,children:s(`assistants.goChannels`)})]}):(0,k.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(r=>(0,k.jsx)(M,{assistant:r,selected:e===r.sessionId,onSelect:()=>t(r),expanded:v===r.sessionId,onToggleExpand:()=>y(v===r.sessionId?null:r.sessionId),onOpen:()=>n(r.sessionId,r.title),onUpdate:e=>void F(r.sessionId,e),editing:x===r.sessionId,onStartRename:()=>w(r.sessionId),onCancelRename:()=>w(null),onRename:e=>void L(r.sessionId,e),deleting:D===r.sessionId,onDelete:()=>void B(r.sessionId,r.title)},r.sessionId))})})]})});function j(e){if(e===`running`)return`running`;if(e===`paused`)return`waiting`;if(e===`error`)return`failed`}var M=(0,O.memo)(function({assistant:e,selected:t,onSelect:r,expanded:c,onToggleExpand:u,onOpen:d,onUpdate:f,editing:p,onStartRename:v,onCancelRename:b,onRename:x,deleting:S,onDelete:C}){let{t:O}=_(),A=e.channel?.peerKind===`group`,M=e.channel?.peerId===y,I=e.kind===`home`;return(0,k.jsxs)(`div`,{className:`rounded-lg border bg-dark-surface transition-colors ${t?`border-accent-blue/60 ring-1 ring-accent-blue/30`:`border-dark-border`}`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:r,"aria-current":t?`true`:void 0,className:`flex w-full items-center gap-2 rounded-t-lg px-3 py-2 text-start focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60 ${t?`bg-accent-blue/5`:`hover:bg-dark-hover/40`}`,children:[(0,k.jsx)(w,{sessionId:e.sessionId,status:j(e.status),signal:e.status===`paused`?`paused`:void 0,size:40}),(0,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[e.channel?(0,k.jsx)(`span`,{className:`text-base leading-none`,"aria-hidden":`true`,children:E(e.channel.type)}):(0,k.jsx)(g,{size:14,className:`shrink-0 text-dark-muted`,"aria-hidden":`true`}),(0,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-dark-text`,title:e.title,children:e.title}),(0,k.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${D(e.status)}`,title:O(`assistants.status.${e.status}`,{defaultValue:e.status})}),e.channel&&(M?(0,k.jsx)(o,{size:11,className:`shrink-0 text-dark-muted`,"aria-label":O(`assistants.channelLevelLabel`)}):A?(0,k.jsx)(s,{size:11,className:`shrink-0 text-dark-muted`,"aria-label":O(`assistants.group`)}):(0,k.jsx)(l,{size:11,className:`shrink-0 text-dark-muted`,"aria-label":O(`assistants.dm`)}))]}),(0,k.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-badge text-dark-muted`,children:[(0,k.jsx)(`span`,{className:`shrink-0`,children:e.channel?T(e.channel.type):O(I?`assistants.homeLabel`:`assistants.localLabel`)}),(0,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.channel?.peerId,children:e.channel?M?O(`assistants.channelLevelHint`):e.channel.peerId:O(I?`assistants.homeHint`:`assistants.localHint`)}),e.stats.unread>0&&(0,k.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent-red/15 px-1.5 text-avatar font-medium text-accent-fg`,children:e.stats.unread})]}),e.preview&&(0,k.jsx)(`p`,{className:`mt-1 line-clamp-2 text-meta leading-snug text-dark-muted`,title:e.preview,children:e.preview})]}),(0,k.jsx)(P,{mode:e.mode}),e.trust.level===`owner`?(0,k.jsx)(h,{size:12,className:`shrink-0 text-accent-green`,"aria-label":O(`assistants.trust.owner`)}):e.trust.level===`public`?(0,k.jsx)(i,{size:12,className:`shrink-0 text-accent-yellow`,"aria-label":O(`assistants.trust.public`)}):(0,k.jsx)(h,{size:12,className:`shrink-0 text-accent-blue`,"aria-label":O(`assistants.trust.team`)})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-dark-border px-3 py-1.5`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:d,className:`flex items-center gap-1 rounded px-2 py-0.5 text-meta text-accent-blue hover:bg-dark-hover`,children:[(0,k.jsx)(n,{size:11,"aria-hidden":`true`}),O(`assistants.openSession`)]}),(0,k.jsx)(`button`,{type:`button`,onClick:u,className:`flex items-center gap-1 rounded px-2 py-0.5 text-meta text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:O(`assistants.policy`)}),!I&&(0,k.jsx)(`button`,{type:`button`,onClick:p?b:v,className:`flex items-center gap-1 rounded px-2 py-0.5 text-meta text-dark-muted hover:bg-dark-hover hover:text-dark-text`,title:O(`assistants.rename`),"aria-label":O(`assistants.rename`),"aria-pressed":p,"data-testid":`assistant-rename-${e.sessionId}`,children:(0,k.jsx)(a,{size:11,"aria-hidden":`true`})}),!I&&(0,k.jsx)(`button`,{type:`button`,onClick:C,disabled:S,className:`flex items-center gap-1 rounded px-2 py-0.5 text-meta text-dark-muted hover:bg-accent-red/10 hover:text-accent-red disabled:opacity-50`,title:O(`assistants.deleteHint`),"aria-label":O(`assistants.delete`),"data-testid":`assistant-delete-${e.sessionId}`,children:(0,k.jsx)(m,{size:11,"aria-hidden":`true`})}),(0,k.jsx)(`span`,{className:`flex-1`}),(0,k.jsx)(`span`,{className:`text-badge text-dark-muted`,children:O(`assistants.groupPolicy`,{mention:String(A?e.policy.mentionRequired:!1)})})]}),c&&(0,k.jsx)(F,{assistant:e,isGroup:A,onUpdate:f}),p&&(0,k.jsx)(N,{initial:e.title,onSubmit:x,onCancel:b})]})});function N({initial:e,onSubmit:t,onCancel:n}){let{t:r}=_(),[i,a]=(0,O.useState)(e),o=()=>{let r=i.trim();!r||r===e?n():t(r)};return(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-dark-border px-3 py-1.5`,children:[(0,k.jsx)(`input`,{autoFocus:!0,type:`text`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),o()):e.key===`Escape`&&(e.preventDefault(),n())},"aria-label":r(`assistants.renameLabel`),"data-testid":`assistant-rename-input`,className:`min-w-0 flex-1 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-meta text-dark-text`}),(0,k.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-accent-blue hover:bg-dark-hover`,title:r(`common.save`),"aria-label":r(`common.save`),"data-testid":`assistant-rename-save`,children:(0,k.jsx)(d,{size:12,"aria-hidden":`true`})}),(0,k.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-dark-muted hover:bg-dark-hover hover:text-dark-text`,title:r(`common.cancel`),"aria-label":r(`common.cancel`),children:(0,k.jsx)(f,{size:12,"aria-hidden":`true`})})]})}function P({mode:e}){let{t}=_();return(0,k.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0.5 text-avatar font-medium ${e===`delegate`?`bg-accent-blue/15 text-accent-blue`:`bg-dark-hover text-dark-muted`}`,children:t(`assistants.mode.${e}`)})}function F({assistant:e,isGroup:n,onUpdate:r}){let{t:i}=_(),[a,o]=(0,O.useState)(e.mode),[s,c]=(0,O.useState)(e.policy.mentionRequired),[l,u]=(0,O.useState)(String(e.policy.cooldownSeconds)),[d,f]=(0,O.useState)((e.policy.keywords??[]).join(`, `)),[p,m]=(0,O.useState)(!1);return(0,k.jsxs)(`div`,{className:`border-t border-dark-border px-3 py-2.5 text-meta`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,k.jsxs)(`label`,{className:`flex items-center gap-1.5 text-dark-muted`,children:[i(`assistants.mode.label`),(0,k.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text`,children:[(0,k.jsx)(`option`,{value:`delegate`,children:i(`assistants.mode.delegate`)}),(0,k.jsx)(`option`,{value:`direct`,children:i(`assistants.mode.direct`)})]})]}),n&&(0,k.jsxs)(`label`,{className:`flex items-center gap-1.5 text-dark-muted`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),i(`assistants.mentionRequired`)]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-1.5 text-dark-muted`,children:[i(`assistants.cooldown`),(0,k.jsx)(`input`,{type:`number`,min:0,value:l,onChange:e=>u(e.target.value),className:`w-14 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text`}),`s`]})]}),(0,k.jsxs)(`label`,{className:`mt-2 flex items-center gap-1.5 text-dark-muted`,children:[i(`assistants.keywords`),(0,k.jsx)(`input`,{type:`text`,value:d,placeholder:i(`assistants.keywordsPlaceholder`)??``,onChange:e=>f(e.target.value),className:`min-w-0 flex-1 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text`})]}),(0,k.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,k.jsx)(v,{size:`sm`,variant:`accent`,onClick:()=>{m(!0),r({mode:a,policy:{mentionRequired:n?s:!1,cooldownSeconds:Math.max(0,Number(l)||0),...d.trim()?{keywords:d.split(/[,,]/).map(e=>e.trim()).filter(Boolean)}:{}}}),window.setTimeout(()=>m(!1),600)},loading:p,leftIcon:(0,k.jsx)(t,{size:11,"aria-hidden":`true`}),children:i(`common.save`)})})]})}export{A as AssistantsView};
@@ -0,0 +1,3 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,Dr as n,Er as r,Fr as i,Kr as a,Kt as o,Nr as s,Pr as c,Qn as l,S as u,Wr as d,_t as f,c as p,dn as m,dt as h,ft as g,g as _,i as v,it as y,lt as b,n as x,ni as S,pt as ee,qt as C,sr as te,v as ne,vr as re,wn as ie,xn as ae,xt as oe,z as se}from"./icons-B8Ngx6rM.js";import{r as ce}from"./react-vendor-CXI113IS.js";import{t as w}from"./useTranslation-gGKZZfux.js";import{i as T,n as le,t as ue}from"./Button-D-g7PgYh.js";import{t as E}from"./api-ZQf0Ys8y.js";import{I as de}from"./markdown-Cps-36Z5.js";import{t as fe}from"./useConfirm-CQjBnYuP.js";import"./common-CPZxdYLs.js";import{ct as D,dt as O,lt as k,ot as A,st as j,u as pe,ut as M}from"./index-STsyoFCk.js";function N(e,t,n){let r=M(e,n?.in);return isNaN(t)?O(n?.in||e,NaN):(t&&r.setDate(r.getDate()+t),r)}function me(e,t,n){let r=M(e,n?.in);if(isNaN(t))return O(n?.in||e,NaN);if(!t)return r;let i=r.getDate(),a=O(n?.in||e,r.getTime());return a.setMonth(r.getMonth()+t+1,0),i>=a.getDate()?a:(r.setFullYear(a.getFullYear(),a.getMonth(),i),r)}function he(e,t,n){return N(e,t*7,n)}function ge(e){return O(e,Date.now())}function P(e,t,n){let[r,i]=D(n?.in,e,t);return+j(r)==+j(i)}function F(e,t){let n=M(e,t?.in);return n.setHours(23,59,59,999),n}function I(e,t){let[n,r]=D(e,t.start,t.end);return{start:n,end:r}}function _e(e,t){let{start:n,end:r}=I(t?.in,e),i=+n>+r,a=i?+n:+r,o=i?r:n;o.setHours(0,0,0,0);let s=t?.step??1;if(!s)return[];s<0&&(s=-s,i=!i);let c=[];for(;+o<=a;)c.push(O(n,o)),o.setDate(o.getDate()+s),o.setHours(0,0,0,0);return i?c.reverse():c}function ve(e,t){let n=M(e,t?.in);return n.setDate(1),n.setHours(0,0,0,0),n}function ye(e,t,n){let[r,i]=D(n?.in,e,t);return+k(r,n)==+k(i,n)}function be(e,t,n){let[r,i]=D(n?.in,e,t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()}function L(e,t){return P(O(t?.in||e,e),ge(t?.in||e))}var R=e(S(),1),xe=ce(),Se=2e3;function Ce(e){return`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}`}function z(e,t,n){return Number.isInteger(e)&&e>=t&&e<=n}function B(e,t,n){let r=e.trim();if(!r)return null;let i=new Set;for(let e of r.split(`,`)){let r=e.trim();if(!r)return null;if(r===`*`||r===`?`){for(let e=t;e<=n;e++)i.add(e);continue}let a=r.match(/^(\*|\d+|\d+-\d+)\/(\d+)$/);if(a){let e=parseInt(a[2]??``,10);if(!z(e,1,n))return null;let r=a[1]??``,o,s;if(r===`*`)o=t,s=n;else if(r.includes(`-`)){let[e,t]=r.split(`-`).map(Number);o=e??NaN,s=t??NaN}else o=Number(r),s=n;if(!z(o,t,n)||!z(s,t,n)||o>s)return null;for(let t=o;t<=s;t+=e)i.add(t);continue}let o=r.match(/^(\d+)-(\d+)$/);if(o){let e=parseInt(o[1]??``,10),r=parseInt(o[2]??``,10);if(!z(e,t,n)||!z(r,t,n)||e>r)return null;for(let t=e;t<=r;t++)i.add(t);continue}let s=Number(r);if(!z(s,t,n))return null;i.add(s)}return i.size>0?[...i].sort((e,t)=>e-t):null}function we(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let n=B(t[0]??``,0,59),r=B(t[1]??``,0,23),i=B(t[2]??``,1,31),a=B(t[3]??``,1,12),o=B(t[4]??``,0,7);return!n||!r||!i||!a||!o?null:{minutes:n,hours:r,daysOfMonth:i,months:a,daysOfWeek:[...new Set(o.map(e=>e===7?0:e))].sort((e,t)=>e-t)}}function Te(e,t){return e.months.includes(t.getMonth()+1)&&e.daysOfMonth.includes(t.getDate())&&e.daysOfWeek.includes(t.getDay())}function Ee(e,t){if(e.kind===`once`){if(!e.fireAt)return[];let n=new Date(e.fireAt);return Number.isNaN(n.getTime())?[]:P(n,t)?[n]:[]}let n=we(e.cron??``);if(!n||!Te(n,t))return[];let r=[];for(let e of n.hours)for(let i of n.minutes)r.push(new Date(t.getFullYear(),t.getMonth(),t.getDate(),e,i,0,0));return r}function De(e,t,n){let r=j(t),i=F(n);if(r.getTime()>i.getTime())return[];let a=[],o=_e({start:r,end:i});for(let t of e){let e=0;for(let n of o){if(e>=Se)break;for(let o of Ee(t.schedule,n))if(!(o.getTime()<r.getTime()||o.getTime()>i.getTime())&&(a.push({key:`${t.id}@${o.toISOString()}`,automationId:t.id,at:o,automation:t}),e+=1,e>=Se))break}}return a.sort((e,t)=>e.at.getTime()-t.at.getTime()||e.automation.name.localeCompare(t.automation.name)),a}var V=e=>e===`*`||e===`?`;function Oe(e,t){let n=e.schedule;if(n.kind===`once`){let e=n.fireAt?new Date(n.fireAt):null;if(!e||Number.isNaN(e.getTime()))return{ok:!1,reason:`unparsable`};if(P(e,t))return{ok:!1,reason:`noop-day`};let r=new Date(t.getFullYear(),t.getMonth(),t.getDate(),e.getHours(),e.getMinutes(),0,0);return{ok:!0,schedule:{...n,kind:`once`,fireAt:r.toISOString()}}}let r=(n.cron??``).trim().split(/\s+/);if(r.length!==5)return{ok:!1,reason:`unparsable`};let i=r[2]??``,a=r[3]??``,o=r[4]??``;if(!V(i)||!V(a))return{ok:!1,reason:`locked-cron`};let s=t.getDay();if(!V(o)){if(/^\d+$/.test(o)){if(Number(o)%7===s)return{ok:!1,reason:`noop-day`}}else if(o===`1-5`){if(s>=1&&s<=5)return{ok:!1,reason:`noop-day`}}else return{ok:!1,reason:`locked-cron`}}let c=[...r];return c[4]=String(s),{ok:!0,schedule:{...n,kind:`cron`,cron:c.join(` `)}}}function ke(e){return Ce(e)}function Ae(e){let t=new Map;for(let n of e){let e=Ce(n.at),r=t.get(e);r?r.push(n):t.set(e,[n])}return t}var H=[`automation.dow.monday`,`automation.dow.tuesday`,`automation.dow.wednesday`,`automation.dow.thursday`,`automation.dow.friday`,`automation.dow.saturday`,`automation.dow.sunday`],je=e=>(e.getDay()+6)%7;function Me(e){let t=ve(e),n=k(t,{weekStartsOn:1});return Array.from({length:42},(e,t)=>N(n,t))}function Ne(e){let t=k(e,{weekStartsOn:1});return Array.from({length:7},(e,n)=>N(t,n))}var U=de(),W=3,G=e=>A(e,`HH:mm`),K=e=>`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()}`;function Pe(e){return e.status===`enabled`?e.schedule.kind===`once`?`once`:`enabled`:`disabled`}var Fe={enabled:`border-accent-blue bg-accent-blue/10 text-dark-text`,once:`border-accent-yellow bg-accent-yellow/10 text-dark-text`,disabled:`border-dark-border bg-dark-hover text-dark-muted`};function q({occurrence:e,onSelectDay:t,extra:n,onUnpack:r,onDragStart:i,onDragEnd:a}){let{t:o}=w(),s=n=>{n.stopPropagation(),r?r():t(e.at)},c=!!i,l=c?o(`automation.dragHint`):r?o(`automation.unpackHint`):``;return(0,U.jsxs)(`button`,{type:`button`,onClick:s,draggable:c,onDragStart:t=>{i&&(t.stopPropagation(),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(`text/plain`,e.key)),i(e))},onDragEnd:()=>a?.(),title:`${G(e.at)} ${e.automation.name}${l?` · ${l}`:``}`,className:`flex w-full items-center gap-1 truncate rounded border-s-2 px-1.5 py-[3px] text-start text-badge hover:brightness-110 ${Fe[Pe(e.automation)]} ${c?`cursor-grab active:cursor-grabbing`:``}`,children:[(0,U.jsx)(`span`,{className:`shrink-0 tabular-nums opacity-70`,children:G(e.at)}),(0,U.jsx)(`span`,{className:`truncate`,children:e.automation.name}),n!==void 0&&n>0&&(0,U.jsx)(`span`,{className:`shrink-0 opacity-70`,children:o(`automation.moreCount`,{count:n})})]})}function Ie({anchor:e,selectedDay:t,byDay:n,onSelectDay:r,onFocusSlot:i,onMoveOccurrence:a}){let{t:o}=w(),s=(0,R.useMemo)(()=>Me(e),[e]),[c,l]=(0,R.useState)(null),[u,d]=(0,R.useState)(null),f=()=>{l(null),d(null)};return(0,U.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-dark-border bg-dark-surface max-md:overflow-x-auto`,children:[(0,U.jsx)(`div`,{className:`grid grid-cols-7 border-b border-dark-border bg-dark-hover/40 max-md:min-w-[42rem]`,children:H.map(e=>(0,U.jsx)(`div`,{className:`px-2 py-2 text-center text-meta font-medium text-dark-muted`,children:o(e)},e))}),(0,U.jsx)(`div`,{className:`grid grid-cols-7 max-md:min-w-[42rem]`,children:s.map((s,p)=>{let m=K(s),h=n.get(m)??[],g=J(h),_=g.slice(0,W),v=g.slice(W).reduce((e,t)=>e+t.items.length,0),y=be(s,e),b=P(s,t),x=L(s),S=u===m;return(0,U.jsxs)(`div`,{"data-day":m,role:`button`,tabIndex:0,onClick:()=>r(s),onDragOver:e=>{c&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),d(m))},onDragLeave:()=>d(e=>e===m?null:e),onDrop:e=>{if(!c)return;e.preventDefault();let t=c;f(),a?.(t,s)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r(s))},className:[`flex min-h-28 cursor-pointer flex-col gap-1 border-b border-e border-dark-border p-1.5`,p%7==6?`border-e-0`:``,p>=35?`border-b-0`:``,y?`bg-dark-surface`:`bg-dark-bg/50`,S?`bg-accent-blue/10 ring-2 ring-inset ring-accent-blue/70`:b?`ring-1 ring-inset ring-accent-blue/50`:`hover:bg-dark-hover/40`].join(` `),children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,U.jsx)(`span`,{className:[`flex h-5 w-5 items-center justify-center rounded-full text-meta tabular-nums`,x?`bg-accent-blue font-semibold text-accent-fg`:y?`text-dark-text`:`text-dark-muted/60`].join(` `),children:s.getDate()}),h.length>0&&(0,U.jsx)(`span`,{className:`text-badge tabular-nums text-dark-muted/50`,children:h.length})]}),(0,U.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[_.map(e=>{let t=e.items[0],n=e.items.length>1;return(0,U.jsx)(q,{occurrence:t,onSelectDay:r,extra:e.items.length-1,onDragStart:a&&!n?l:void 0,onDragEnd:f,onUnpack:n&&i?()=>i(s,G(e.at)):void 0},`${m}-${G(e.at)}`)}),v>0&&(0,U.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r(s)},className:`px-1 text-start text-badge text-dark-muted hover:text-accent-blue`,children:o(`automation.moreCount`,{count:v})})]})]},s.toISOString())})})]})}function J(e){let t=new Map;for(let n of e){let e=G(n.at),r=t.get(e);r?r.items.push(n):t.set(e,{at:n.at,items:[n]})}return[...t.values()].sort((e,t)=>e.at.getTime()-t.at.getTime())}function Le({anchor:e,selectedDay:t,byDay:n,onSelectDay:r,onFocusSlot:i,onMoveOccurrence:a}){let{t:o}=w(),s=(0,R.useMemo)(()=>Ne(e),[e]),c=(0,R.useMemo)(()=>Array.from({length:24},(e,t)=>t),[]),[l,u]=(0,R.useState)(null),[d,f]=(0,R.useState)(null),p=()=>{u(null),f(null)};return(0,U.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-dark-border bg-dark-surface`,children:[(0,U.jsxs)(`div`,{className:`grid grid-cols-[3rem_repeat(7,minmax(0,1fr))] border-b border-dark-border bg-dark-hover/40`,children:[(0,U.jsx)(`div`,{}),s.map(e=>{let n=L(e),i=P(e,t);return(0,U.jsxs)(`button`,{type:`button`,onClick:()=>r(e),className:[`border-s border-dark-border px-1 py-1.5 text-center`,i?`bg-accent-blue/10`:`hover:bg-dark-hover/60`].join(` `),children:[(0,U.jsx)(`div`,{className:`text-meta text-dark-muted`,children:o(H[je(e)]??``)}),(0,U.jsx)(`div`,{className:[`mx-auto mt-0.5 flex h-5 w-5 items-center justify-center rounded-full text-meta tabular-nums`,n?`bg-accent-blue font-semibold text-accent-fg`:`text-dark-text`].join(` `),children:e.getDate()})]},e.toISOString())})]}),(0,U.jsxs)(`div`,{className:`custom-scrollbar grid max-h-[62vh] grid-cols-[3rem_repeat(7,minmax(0,1fr))] overflow-y-auto`,children:[(0,U.jsx)(`div`,{className:`relative`,style:{height:`72rem`},children:c.map(e=>(0,U.jsx)(`div`,{className:`absolute end-1 -translate-y-1/2 text-badge tabular-nums text-dark-muted`,style:{top:`${e/24*100}%`},children:e===0?``:`${String(e).padStart(2,`0`)}:00`},e))}),s.map(e=>{let o=K(e),s=J(n.get(o)??[]),m=P(e,t);return(0,U.jsxs)(`div`,{"data-day":o,onDragOver:e=>{l&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),f(o))},onDragLeave:()=>f(e=>e===o?null:e),onDrop:t=>{if(!l)return;t.preventDefault();let n=l;p(),a?.(n,e)},className:[`relative border-s border-dark-border`,d===o?`bg-accent-blue/15 ring-2 ring-inset ring-accent-blue/70`:m?`bg-accent-blue/5`:``].join(` `),style:{height:`72rem`},children:[c.map(e=>(0,U.jsx)(`div`,{className:`absolute inset-x-0 border-t ${e===0?`border-transparent`:`border-dark-border/60`}`,style:{top:`${e/24*100}%`}},e)),s.map(t=>{let n=t.items[0],o=t.at.getHours()*60+t.at.getMinutes();return(0,U.jsx)(`div`,{className:`absolute inset-x-0.5 z-10`,style:{top:`${o/1440*100}%`},children:(0,U.jsx)(q,{occurrence:n,onSelectDay:r,extra:t.items.length-1,onDragStart:a&&t.items.length===1?u:void 0,onDragEnd:p,onUnpack:i&&t.items.length>1?()=>i(e,G(t.at)):void 0})},`${e.toISOString()}-${G(t.at)}`)})]},e.toISOString())})]})]})}var Y=e=>A(e,`HH:mm`);function Re({day:e,occurrences:t,focusSlot:n,onClearFocus:r,onEdit:a,onRun:o,onToggle:s,onDelete:c,onCreate:l}){let{t:u}=w(),d=n??null,p=d?t.filter(e=>Y(e.at)===d).length:0,m=d?t.findIndex(e=>Y(e.at)===d):-1,g=(0,R.useRef)(null);return(0,R.useEffect)(()=>{d&&g.current?.scrollIntoView?.({block:`nearest`})},[d]),(0,U.jsxs)(`aside`,{className:`flex w-full shrink-0 flex-col overflow-hidden rounded-xl border border-dark-border bg-dark-surface lg:w-72`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-2 border-b border-dark-border px-3 py-2.5`,children:[(0,U.jsxs)(`div`,{className:`min-w-0`,children:[(0,U.jsxs)(`div`,{className:`truncate text-sm font-semibold`,children:[u(H[je(e)]??``),` · `,A(e,`yyyy-MM-dd`)]}),(0,U.jsxs)(`div`,{className:`text-meta text-dark-muted`,children:[u(`automation.tasksCount`,{count:t.length}),L(e)?` · ${u(`automation.today`)}`:``]})]}),(0,U.jsx)(`button`,{type:`button`,onClick:l,title:u(`automation.new`),className:`rounded-lg p-1.5 text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:(0,U.jsx)(h,{size:15})})]}),d&&(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-dark-border bg-accent-blue/10 px-3 py-1.5 text-meta`,children:[(0,U.jsx)(`span`,{className:`shrink-0 font-medium tabular-nums`,children:d}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-dark-muted`,children:u(`automation.slotFocus`,{count:p})}),r&&(0,U.jsx)(`button`,{type:`button`,onClick:r,title:u(`automation.clearFocus`),className:`rounded p-0.5 text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:(0,U.jsx)(x,{size:12})})]}),(0,U.jsx)(`div`,{className:`custom-scrollbar flex-1 overflow-y-auto p-2.5`,children:t.length===0?(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-1 px-2 py-8 text-center`,children:[(0,U.jsx)(i,{size:22,className:`text-dark-muted`}),(0,U.jsx)(`p`,{className:`text-xs text-dark-muted`,children:u(`automation.dayEmpty`)}),(0,U.jsx)(`p`,{className:`text-meta text-dark-muted/70`,children:u(`automation.dayEmptyHint`)})]}):(0,U.jsx)(`div`,{className:`space-y-2`,children:t.map((e,t)=>{let n=e.automation,r=n.status===`enabled`,i=d!==null&&Y(e.at)===d;return(0,U.jsxs)(`div`,{ref:t===m?g:void 0,"data-focus-slot":i?d:void 0,className:[`rounded-lg border bg-dark-bg/50 px-2.5 py-2`,i?`border-accent-blue/60 ring-1 ring-inset ring-accent-blue/50`:`border-dark-border`].join(` `),children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`shrink-0 text-meta font-medium tabular-nums text-dark-muted`,children:Y(e.at)}),(0,U.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium`,title:n.name,children:n.name}),(0,U.jsx)(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-badge ${r?`bg-accent-green/20 text-accent-green`:`bg-dark-hover text-dark-muted`}`,children:u(r?`automation.enabled`:`automation.disabled`)})]}),(0,U.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[n.nextRunAt&&(0,U.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-badge tabular-nums text-dark-muted`,children:[u(`automation.nextRun`),` `,A(new Date(n.nextRunAt),`MM-dd HH:mm`)]}),(0,U.jsxs)(`div`,{className:`ms-auto flex shrink-0 items-center gap-1`,children:[(0,U.jsx)(`button`,{type:`button`,onClick:()=>a(n),title:u(`automation.edit`),className:`rounded p-1.5 text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:(0,U.jsx)(f,{size:14})}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>s(n),title:u(r?`automation.disable`:`automation.enable`),className:`rounded p-1.5 text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:(0,U.jsx)(b,{size:14})}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>o(n.id),title:u(`automation.runNow`),className:`rounded p-1.5 text-accent-green hover:bg-dark-hover`,children:(0,U.jsx)(ee,{size:14})}),c&&(0,U.jsx)(`button`,{type:`button`,onClick:()=>c(n),title:u(`automation.delete`),className:`rounded p-1.5 text-dark-muted hover:bg-accent-red/10 hover:text-accent-red`,children:(0,U.jsx)(ne,{size:14})})]})]})]},e.key)})})})]})}var X={name:``,instructions:``,jobKind:`agent`,workflowTemplate:``,freq:`daily`,time:`09:00`,dow:`1`,onceAt:``,cron:`0 9 * * *`,modelRef:``,connectorIds:[],channelIds:[],workspaceDir:``,readAutoAllow:!0,runSessionMode:`home`,runSessionId:``,budgetUsd:``};function ze(e){let t=e.trim();if(!t)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:String(Math.round(n*100))}var Be=`.agent/automation-attachments`,Ve=`workflow:`;function He(e){return/^[a-z0-9][a-z0-9_-]*$/.test(e)}function Ue(e){let t=e??``;if(!t.startsWith(Ve))return``;let n=t.slice(9).trim();return He(n)?n:``}var Z=`deepseekcode:automation-view`,We=[{id:`month`,key:`automation.viewMonth`,Icon:c},{id:`week`,key:`automation.viewWeek`,Icon:s},{id:`list`,key:`automation.viewList`,Icon:C}];function Ge(){try{let e=localStorage.getItem(Z);if(e===`month`||e===`week`||e===`list`)return e}catch{}return`month`}function Ke(e){try{localStorage.setItem(Z,e)}catch{}}var Q=e=>String(e).padStart(2,`0`);function qe(e){let t=e.schedule,n=Ue(e.name),r={modelRef:e.modelRef??``,connectorIds:Array.isArray(e.connectorIds)?[...e.connectorIds]:[],channelIds:Array.isArray(e.notificationChannelIds)?[...e.notificationChannelIds]:[],workspaceDir:e.workspaceDir??``,readAutoAllow:e.readAutoAllow,runSessionMode:e.runSessionMode??`home`,runSessionId:e.runSessionId??``,budgetUsd:e.budgetCents?String(Number(e.budgetCents)/100):``,workflowTemplate:n,jobKind:n?`workflow`:`agent`};if(t.kind===`once`&&t.fireAt){let n=new Date(t.fireAt);return{...X,name:e.name,instructions:e.instructions,freq:`once`,time:`${Q(n.getHours())}:${Q(n.getMinutes())}`,onceAt:`${n.getFullYear()}-${Q(n.getMonth()+1)}-${Q(n.getDate())}T${Q(n.getHours())}:${Q(n.getMinutes())}`,...r}}let i=(t.cron||``).trim().split(/\s+/),a={...X,name:e.name,instructions:e.instructions,...r};if(i.length===5){let e=i[0]??``,t=i[1]??``,n=i[4]??``,r=`${Q(parseInt(t,10)||0)}:${Q(parseInt(e,10)||0)}`;if(n===`*`)return{...a,freq:`daily`,time:r};if(n===`1-5`)return{...a,freq:`weekdays`,time:r};if(/^\d+$/.test(n))return{...a,freq:`weekly`,time:r,dow:n}}return{...a,freq:`custom`,cron:t.cron||``}}function Je(e){let[t,n]=e.time.split(`:`),r=parseInt(t??``,10),i=parseInt(n??``,10);switch(e.freq){case`daily`:return Number.isInteger(r)&&Number.isInteger(i)?{kind:`cron`,cron:`${i} ${r} * * *`}:null;case`weekdays`:return Number.isInteger(r)&&Number.isInteger(i)?{kind:`cron`,cron:`${i} ${r} * * 1-5`}:null;case`weekly`:return Number.isInteger(r)&&Number.isInteger(i)?{kind:`cron`,cron:`${i} ${r} * * ${e.dow}`}:null;case`once`:return e.onceAt?{kind:`once`,fireAt:new Date(e.onceAt).toISOString()}:null;case`custom`:return e.cron.trim()?{kind:`cron`,cron:e.cron.trim()}:null}}function Ye(e,t){if(e.kind===`once`&&e.fireAt){let n=new Date(e.fireAt);return`${t(`automation.badgeOnce`)} ${n.toLocaleString()}`}let n=(e.cron||``).trim().split(/\s+/);if(n.length!==5)return e.cron||``;let r=n[0]??``,i=n[1]??``,a=n[4]??``,o=`${Q(parseInt(i,10)||0)}:${Q(parseInt(r,10)||0)}`;return a===`*`?t(`automation.badgeDaily`,{time:o}):a===`1-5`?t(`automation.badgeWeekdays`,{time:o}):/^\d+$/.test(a)?t(`automation.badgeWeekly`,{day:t(`automation.dow.${[`sunday`,`monday`,`tuesday`,`wednesday`,`thursday`,`friday`,`saturday`][parseInt(a,10)%7]}`),time:o}):e.cron||``}var Xe=[{value:`1`,key:`automation.dow.monday`},{value:`2`,key:`automation.dow.tuesday`},{value:`3`,key:`automation.dow.wednesday`},{value:`4`,key:`automation.dow.thursday`},{value:`5`,key:`automation.dow.friday`},{value:`6`,key:`automation.dow.saturday`},{value:`0`,key:`automation.dow.sunday`}];function Ze(e){let t=e.replace(/[\\/]+$/,``),n=Math.max(t.lastIndexOf(`\\`),t.lastIndexOf(`/`));return n===-1?t:t.slice(n+1)}function Qe({isOpen:e,initial:t,onClose:n,onConfirm:r}){let{t:i}=w(),{visible:s,phase:c}=le(e),[l,u]=(0,R.useState)(t),[d,f]=(0,R.useState)(null),[p,h]=(0,R.useState)([]),[g,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(``),[b,S]=(0,R.useState)(t),ee=(0,R.useRef)(null),C=async e=>{_(!0),y(``);try{let t=await E.dirs.list(e);if(!t.success||!t.data){y(t.error||`加载目录失败`);return}u(t.data.path),f(t.data.parent),h(t.data.dirs||[]),S(t.data.path)}catch(e){y(e instanceof Error?e.message:`加载目录失败`)}finally{_(!1)}};return(0,R.useEffect)(()=>{e&&C(t)},[e,t]),(0,R.useEffect)(()=>{ee.current?.focus()},[]),(0,R.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n())};return document.addEventListener(`keydown`,t),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,t),document.body.style.overflow=``}},[e,n]),s?(0,U.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center overflow-hidden p-4 max-md:p-0`,role:`dialog`,"aria-modal":`true`,children:[(0,U.jsx)(`div`,{className:`absolute inset-0 ui-scrim ui-overlay-backdrop`,"data-phase":c,onClick:n}),(0,U.jsxs)(`div`,{className:`relative w-full max-w-lg mx-4 bg-dark-overlay ui-surface-overlay border border-dark-border rounded-xl shadow-pop flex flex-col max-h-[70vh] ui-overlay-panel max-md:mx-0 max-md:max-w-none max-md:rounded-none max-md:max-h-[85vh]`,"data-phase":c,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-b border-dark-border shrink-0`,children:[(0,U.jsxs)(`span`,{className:`flex items-center gap-2 text-compact font-semibold text-dark-text`,children:[(0,U.jsx)(ie,{size:15,className:`text-accent-blue`}),i(`automation.workspacePick`)]}),(0,U.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-dark-muted hover:bg-dark-hover`,children:(0,U.jsx)(x,{size:15})})]}),(0,U.jsxs)(`div`,{className:`p-4 flex flex-col gap-3 min-h-0 flex-1`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,U.jsxs)(`div`,{className:`relative flex-1`,children:[(0,U.jsx)(m,{size:13,className:`absolute start-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60`}),(0,U.jsx)(`input`,{ref:ee,value:b,onChange:e=>S(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(b.trim())},spellCheck:!1,className:`w-full rounded-lg border border-dark-border bg-dark-surface ps-8 pe-2.5 py-1.5 text-xs font-mono focus:outline-none focus:border-accent-blue/50`})]}),(0,U.jsx)(`button`,{type:`button`,onClick:()=>void C(b.trim()),disabled:g||!b.trim(),className:`shrink-0 rounded-lg border border-dark-border px-2.5 py-1.5 text-xs text-dark-muted hover:bg-dark-hover disabled:opacity-40`,children:i(`chat.dirPickerGo`)})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`flex-1 truncate font-mono text-meta text-dark-muted bg-dark-surface rounded-md px-2 py-1 border border-dark-border`,title:l,children:l||`—`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>d&&void C(d),disabled:g||!d,className:`shrink-0 flex items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-meta text-dark-muted hover:bg-dark-hover disabled:opacity-40`,children:[(0,U.jsx)(a,{size:12}),i(`chat.dirPickerUp`)]})]}),(0,U.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto rounded-lg border border-dark-border bg-dark-surface divide-y divide-dark-border/60`,children:g?(0,U.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-6 text-xs text-dark-muted`,children:[(0,U.jsx)(o,{size:14,className:`animate-spin`}),i(`chat.loading`)]}):v?(0,U.jsx)(`div`,{className:`px-3 py-4 text-xs text-accent-red`,children:v}):p.length===0?(0,U.jsx)(`div`,{className:`px-3 py-4 text-xs text-dark-muted/60 text-center`,children:`—`}):p.map(e=>{let t=l.includes(`\\`)?`\\`:`/`,n=l.endsWith(t)?l+e:l+t+e;return(0,U.jsxs)(`button`,{type:`button`,onClick:()=>void C(n),className:`w-full flex items-center gap-2 px-3 py-1.5 text-start text-xs text-dark-text hover:bg-dark-hover`,children:[(0,U.jsx)(ae,{size:13,className:`shrink-0 text-accent-yellow/80`}),(0,U.jsx)(`span`,{className:`truncate`,children:e})]},e)})}),(0,U.jsx)(ue,{variant:`accent`,className:`w-full`,onClick:()=>r(l),disabled:!l,loading:g,children:i(`chat.dirPickerConfirm`)})]})]})]}):null}function $e(){let{t:e}=w(),{automations:a,runsByAutomation:s,fetchAutomations:c,createAutomation:S,updateAutomation:C,deleteAutomation:ae,toggleAutomation:ce,runAutomation:de,fetchRuns:D,error:O}=pe(),[k,j]=(0,R.useState)(!1),{visible:M,phase:N}=le(k),[ge,P]=(0,R.useState)(null),[F,I]=(0,R.useState)(X),[_e,ve]=(0,R.useState)(null),[L,Se]=(0,R.useState)(``),[Ce,z]=(0,R.useState)(!1),[B,we]=fe(),Te=async t=>{await we({message:e(`automation.deleteConfirm`,{name:t.name}),variant:`danger`})&&await ae(t.id)},[Ee,V]=(0,R.useState)(!1),[H,je]=(0,R.useState)(Ge),[W,G]=(0,R.useState)(()=>new Date),[K,Pe]=(0,R.useState)(()=>new Date),[Fe,q]=(0,R.useState)(null),J=e=>{Pe(e),q(null)};(0,R.useEffect)(()=>{Ke(H)},[H]);let Y=(0,R.useMemo)(()=>{if(H===`month`){let e=Me(W);return{from:e[0],to:e[e.length-1]}}if(H===`week`){let e=Ne(W);return{from:e[0],to:e[e.length-1]}}return null},[H,W]),He=(0,R.useMemo)(()=>Y?De(a,Y.from,Y.to):[],[a,Y]),Z=(0,R.useMemo)(()=>Ae(He),[He]),Q=(0,R.useMemo)(()=>Z.get(ke(K))??[],[Z,K]),$e=e=>{let t=H===`week`?he(W,e):me(W,e);G(t),(H===`week`?ye(K,t,{weekStartsOn:1}):be(K,t))||J(t)},et=()=>{let e=new Date;G(e),J(e)},tt=async(t,n)=>{let r=Oe(t.automation,n);if(!r.ok){r.reason===`noop-day`?T.info(e(`automation.dragNoop`)):T.warning(e(`automation.dragLocked`));return}let i=Ye(t.automation.schedule,e);await C(t.automation.id,{schedule:r.schedule})&&(J(n),T.success(e(`automation.dragMoved`,{name:t.automation.name,from:i,to:Ye(r.schedule,e)})))},nt=(0,R.useMemo)(()=>{if(H===`week`){let e=Ne(W);return`${A(e[0],`yyyy-MM-dd`)} → ${A(e[e.length-1],`MM-dd`)}`}return A(W,`yyyy-MM`)},[H,W]),[rt,it]=(0,R.useState)([]),[at,ot]=(0,R.useState)([]),[st,ct]=(0,R.useState)([]),[lt,ut]=(0,R.useState)([]),[dt,ft]=(0,R.useState)(!1),[pt,mt]=(0,R.useState)([]),[ht,gt]=(0,R.useState)(!1),[_t,vt]=(0,R.useState)(!1),yt=async()=>{if(ht)return;gt(!0);let e=await E.sessions.list().catch(()=>({success:!1,data:void 0}));e.success&&Array.isArray(e.data)&&mt(e.data.filter(e=>!e.id.startsWith(`__automation_run__`)))},[bt,$]=(0,R.useState)([]),xt=(0,R.useRef)(null);(0,R.useEffect)(()=>{c()},[c]);let St=async e=>{P(null),I(e?{...e.form}:{...X}),$([]),j(!0),await Tt()},Ct=async e=>{P(e.id),I(qe(e)),$((e.attachments??[]).map((e,t)=>({id:`existing-${t}-${e}`,name:Ze(e),file:null,uploading:!1,path:e}))),j(!0),await Tt(),e.runSessionMode===`fixed`&&yt()},wt=()=>{j(!1),P(null),I(X),$([]),V(!1)},Tt=async()=>{vt(!0);try{let e=E.templates?.list?E.templates.list().catch(()=>({success:!1,data:void 0})):Promise.resolve({success:!1,data:void 0}),[t,n,r,i]=await Promise.all([E.models.list().catch(()=>({success:!1,data:void 0})),E.connectors.list().catch(()=>({success:!1,data:void 0})),E.channels.list().catch(()=>({success:!1,data:void 0})),e]);t.success&&t.data?.models?it(t.data.models.filter(e=>e.enabled!==!1)):it([]),n.success&&n.data?.connectors?ot(n.data.connectors.filter(e=>e.installed)):ot([]),r.success&&Array.isArray(r.data)?ct(r.data):ct([]),i.success&&Array.isArray(i.data)?ut(i.data):ut([]),ft(!0)}finally{vt(!1)}},Et=e=>{I(t=>{if(t.jobKind===e)return t;let n=e===`agent`&&!Ue(t.name);return{...t,jobKind:e,workflowTemplate:``,instructions:``,name:n?t.name:``}})},Dt=()=>{let e=lt.find(e=>e.id===F.workflowTemplate),t={};for(let n of e?.inputs??[])t[n.name]=n.default===void 0?``:n.default;I(e=>({...e,instructions:JSON.stringify(t,null,2)}))},Ot=async()=>{let t=Je(F);if(!t)return;let n=F.jobKind===`workflow`;if(n&&!F.workflowTemplate)return;if(n){let t=F.instructions.trim();if(t){let n;try{n=JSON.parse(t)}catch{T.warning(e(`automation.workflowJsonInvalid`));return}if(!n||typeof n!=`object`||Array.isArray(n)){T.warning(e(`automation.workflowJsonNotObject`));return}}}else if(!F.name.trim()||!F.instructions.trim())return;if(bt.some(e=>e.uploading)){T.warning(`附件上传中,请稍候…`);return}let r=bt.filter(e=>e.error).map(e=>e.name);if(r.length>0){T.warning(`附件上传失败:${r.join(`, `)}`);return}z(!0);let i={name:n?`${Ve}${F.workflowTemplate}`:F.name.trim(),instructions:F.instructions.trim(),schedule:t,workspaceDir:F.workspaceDir.trim(),readAutoAllow:F.readAutoAllow,modelRef:F.modelRef.trim()||null,attachments:bt.map(e=>e.path).filter(e=>!!e),connectorIds:[...F.connectorIds],notificationChannelIds:[...F.channelIds],runSessionMode:F.runSessionMode,runSessionId:F.runSessionMode===`fixed`&&F.runSessionId.trim()||null,budgetCents:ze(F.budgetUsd)},a=ge?await C(ge,i):await S(i)!==null;z(!1),a&&wt()},kt=async e=>{let t=L.trim();if(!t)return;let[n,...r]=t.split(/\s+/),i=r.join(` `);n&&i&&(await fetch(`/api/automations/${encodeURIComponent(e)}/permissions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({tool:n,target:i})})).ok&&(Se(``),await c())},At=async(e,t)=>{(await fetch(`/api/automations/${encodeURIComponent(e)}/permissions`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify({entry:t})})).ok&&await c()},jt=async e=>{let t=_e===e?null:e;ve(t),t&&await D(e)},Mt=async e=>{if(!e||e.length===0)return;let t=Array.from(e).map(e=>({id:`f-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,name:e.name,file:e,uploading:!0}));$(e=>[...e,...t]);for(let e of t){let t=`${Be}/${e.name}`;try{let n=await E.files.upload(e.file,t);if(n.success&&n.data?.path){let t=n.data.path.replace(/\\/g,`/`);$(n=>n.map(n=>n.id===e.id?{...n,uploading:!1,path:t}:n))}else $(t=>t.map(t=>t.id===e.id?{...t,uploading:!1,error:n.error||`upload failed`}:t))}catch(t){let n=t instanceof Error?t.message:`upload failed`;$(t=>t.map(t=>t.id===e.id?{...t,uploading:!1,error:n}:t))}}},Nt=e=>{$(t=>t.filter(t=>t.id!==e))},Pt=[{id:`movie`,nameKey:`automation.tplMovieName`,descKey:`automation.tplMovieDesc`,form:{...X,name:e(`automation.tplMovieName`),instructions:e(`automation.tplMovieInstr`),freq:`daily`,time:`20:00`}},{id:`health`,nameKey:`automation.tplHealthName`,descKey:`automation.tplHealthDesc`,form:{...X,name:e(`automation.tplHealthName`),instructions:e(`automation.tplHealthInstr`),freq:`daily`,time:`14:00`}},{id:`why`,nameKey:`automation.tplWhyName`,descKey:`automation.tplWhyDesc`,form:{...X,name:e(`automation.tplWhyName`),instructions:e(`automation.tplWhyInstr`),freq:`daily`,time:`16:00`}},{id:`git`,nameKey:`automation.tplGitName`,descKey:`automation.tplGitDesc`,form:{...X,name:e(`automation.tplGitName`),instructions:e(`automation.tplGitInstr`),freq:`weekdays`,time:`09:00`}}],Ft=lt.find(e=>e.id===F.workflowTemplate),It=(F.jobKind===`workflow`?!!F.workflowTemplate:!!(F.name.trim()&&F.instructions.trim()))&&(F.freq===`custom`?!!F.cron.trim():F.freq!==`once`||!!F.onceAt);return(0,U.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-y-auto p-6 max-md:p-3`,children:[B,(0,U.jsxs)(`div`,{className:`max-w-7xl w-full mx-auto`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between mb-1`,children:[(0,U.jsxs)(`h2`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,U.jsx)(te,{size:20,className:`text-accent-blue`}),e(`automation.title`)]}),(0,U.jsx)(`button`,{onClick:()=>void c(),className:`p-2 rounded-lg hover:bg-dark-hover text-dark-muted`,title:e(`automation.refresh`),children:(0,U.jsx)(y,{size:16})})]}),(0,U.jsx)(`p`,{className:`text-sm text-dark-muted mb-4`,children:e(`automation.subtitle`)}),(0,U.jsx)(`div`,{className:`mb-4`,children:a.length===0?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,U.jsx)(t,{size:15,className:`text-accent-yellow`}),(0,U.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`automation.recommendedTitle`)})]}),(0,U.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:Pt.map(t=>(0,U.jsxs)(`button`,{onClick:()=>void St(t),className:`flex flex-col gap-1 rounded-xl border border-dark-border bg-dark-surface p-2.5 text-start transition-colors hover:border-accent-blue/60 hover:bg-dark-hover/50`,children:[(0,U.jsx)(`span`,{className:`text-xs font-semibold`,children:e(t.nameKey)}),(0,U.jsx)(`span`,{className:`text-meta leading-relaxed text-dark-muted line-clamp-1`,children:e(t.descKey)}),(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 self-start rounded bg-dark-hover px-1.5 py-0.5 text-badge text-dark-muted`,children:[(0,U.jsx)(te,{size:11}),` `,Ye(Je(t.form),e)]})]},t.id))})]}):(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 pe-1 text-meta font-medium text-dark-muted`,children:[(0,U.jsx)(t,{size:13,className:`text-accent-yellow`}),e(`automation.recommendedTitle`)]}),Pt.map(t=>(0,U.jsxs)(`button`,{onClick:()=>void St(t),title:e(t.descKey),className:`flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-2 py-1 text-meta text-dark-muted transition-colors hover:border-accent-blue/60 hover:text-dark-text`,children:[(0,U.jsx)(h,{size:11}),e(t.nameKey),(0,U.jsx)(`span`,{className:`text-badge tabular-nums opacity-60`,children:Ye(Je(t.form),e)})]},t.id))]})}),O&&(0,U.jsxs)(`div`,{className:`mb-4 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2`,children:[(0,U.jsx)(_,{size:16}),` `,O]}),(0,U.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`flex items-center rounded-lg border border-dark-border bg-dark-surface p-0.5`,children:We.map(({id:t,key:n,Icon:r})=>(0,U.jsxs)(`button`,{onClick:()=>je(t),"aria-pressed":H===t,className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${H===t?`bg-accent-blue/15 text-accent-blue font-medium`:`text-dark-muted hover:text-dark-text`}`,children:[(0,U.jsx)(r,{size:13}),` `,e(n)]},t))}),H!==`list`&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,U.jsx)(`button`,{onClick:()=>$e(-1),title:e(`automation.prevPeriod`),className:`rounded-lg border border-dark-border bg-dark-surface p-1.5 text-dark-muted hover:text-dark-text`,children:(0,U.jsx)(n,{size:14})}),(0,U.jsx)(`button`,{onClick:et,className:`rounded-lg border border-dark-border bg-dark-surface px-2 py-1.5 text-xs text-dark-muted hover:text-dark-text`,children:e(`automation.today`)}),(0,U.jsx)(`button`,{onClick:()=>$e(1),title:e(`automation.nextPeriod`),className:`rounded-lg border border-dark-border bg-dark-surface p-1.5 text-dark-muted hover:text-dark-text`,children:(0,U.jsx)(r,{size:14})})]}),(0,U.jsx)(`span`,{className:`text-sm font-medium tabular-nums`,children:nt})]}),(0,U.jsxs)(`div`,{className:`ms-auto flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`text-xs text-dark-muted`,children:e(`automation.tasksCount`,{count:a.length})}),(0,U.jsxs)(`button`,{onClick:()=>void St(),className:`flex items-center gap-1 rounded-lg bg-accent-blue px-3 py-1.5 text-xs font-medium text-accent-fg hover:brightness-110`,children:[(0,U.jsx)(h,{size:14}),` `,e(`automation.new`)]})]})]}),H!==`list`&&(0,U.jsxs)(`div`,{className:`mb-6 flex flex-col gap-4 lg:flex-row lg:items-start`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[H===`month`?(0,U.jsx)(Ie,{anchor:W,selectedDay:K,byDay:Z,onSelectDay:J,onFocusSlot:(e,t)=>{Pe(e),q(t)},onMoveOccurrence:(e,t)=>void tt(e,t)}):(0,U.jsx)(Le,{anchor:W,selectedDay:K,byDay:Z,onSelectDay:J,onFocusSlot:(e,t)=>{Pe(e),q(t)},onMoveOccurrence:(e,t)=>void tt(e,t)}),a.length===0&&(0,U.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 rounded-lg border border-dashed border-dark-border px-3 py-2 text-xs text-dark-muted`,children:[(0,U.jsx)(i,{size:14}),e(`automation.emptyTitle`),` · `,e(`automation.emptyDesc`)]})]}),(0,U.jsx)(Re,{day:K,occurrences:Q,focusSlot:Fe,onClearFocus:()=>q(null),onEdit:e=>void Ct(e),onRun:e=>void de(e),onToggle:e=>void ce(e.id,e.status!==`enabled`),onDelete:e=>void Te(e),onCreate:()=>void St()})]}),H===`list`&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,U.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`automation.mineTitle`)}),(0,U.jsx)(`span`,{className:`text-xs text-dark-muted`,children:a.length})]}),a.length===0?(0,U.jsxs)(`div`,{className:`rounded-xl border border-dashed border-dark-border py-12 flex flex-col items-center gap-2 text-center`,children:[(0,U.jsx)(i,{size:32,className:`text-dark-muted`}),(0,U.jsx)(`p`,{className:`text-sm font-medium`,children:e(`automation.emptyTitle`)}),(0,U.jsx)(`p`,{className:`text-xs text-dark-muted`,children:e(`automation.emptyDesc`)}),(0,U.jsxs)(`button`,{onClick:()=>void St(),className:`mt-2 flex items-center gap-1 px-4 py-1.5 rounded-lg border border-dark-border bg-dark-surface hover:bg-dark-hover text-sm font-medium`,children:[(0,U.jsx)(h,{size:15}),` `,e(`automation.new`)]})]}):(0,U.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,U.jsxs)(`div`,{className:`rounded-xl border border-dark-border bg-dark-surface`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between p-3`,children:[(0,U.jsxs)(`button`,{onClick:()=>void jt(t.id),className:`flex items-center gap-2 min-w-0 text-start`,children:[(0,U.jsx)(te,{size:16,className:`text-accent-blue shrink-0`}),(0,U.jsx)(`span`,{className:`font-medium text-sm truncate`,children:t.name}),(0,U.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded shrink-0 ${t.status===`enabled`?`bg-accent-green/20 text-accent-green`:`bg-dark-hover text-dark-muted`}`,children:t.status===`enabled`?e(`automation.enabled`):e(`automation.disabled`)}),(0,U.jsx)(`span`,{className:`text-xs text-dark-muted shrink-0 hidden md:inline`,children:Ye(t.schedule,e)})]}),(0,U.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[t.nextRunAt&&(0,U.jsxs)(`span`,{className:`text-xs text-dark-muted hidden lg:inline me-1`,children:[e(`automation.nextRun`),`: `,new Date(t.nextRunAt).toLocaleString()]}),(0,U.jsx)(`button`,{onClick:()=>void Ct(t),className:`p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted`,title:e(`automation.edit`),children:(0,U.jsx)(f,{size:15})}),(0,U.jsx)(`button`,{onClick:()=>void ce(t.id,t.status!==`enabled`),className:`p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted`,title:t.status===`enabled`?e(`automation.disable`):e(`automation.enable`),children:(0,U.jsx)(b,{size:15})}),(0,U.jsx)(`button`,{onClick:()=>void de(t.id),className:`p-1.5 rounded-lg hover:bg-dark-hover text-accent-green`,title:e(`automation.runNow`),children:(0,U.jsx)(ee,{size:15})}),(0,U.jsx)(`button`,{onClick:()=>void Te(t),className:`p-1.5 rounded-lg hover:bg-dark-hover text-accent-red`,title:e(`automation.delete`),children:(0,U.jsx)(ne,{size:15})})]})]}),_e===t.id&&(0,U.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t border-dark-border pt-3`,children:[Ue(t.name)?(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsxs)(`p`,{className:`text-xs text-dark-muted flex items-center gap-1.5`,children:[(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-accent-blue/10 text-accent-blue`,children:[(0,U.jsx)(v,{size:11}),` `,e(`automation.jobKindWorkflow`)]}),(0,U.jsx)(`code`,{children:Ue(t.name)})]}),t.instructions.trim()&&(0,U.jsx)(`pre`,{className:`text-badge text-dark-muted whitespace-pre-wrap font-mono`,children:t.instructions})]}):(0,U.jsx)(`p`,{className:`text-xs text-dark-muted whitespace-pre-wrap`,children:t.instructions}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`h4`,{className:`text-xs font-semibold text-dark-muted mb-1 flex items-center gap-1`,children:[(0,U.jsx)(u,{size:12}),` `,e(`automation.historyTitle`)]}),(s[t.id]||[]).length===0&&(0,U.jsx)(`p`,{className:`text-xs text-dark-muted`,children:e(`automation.noRuns`)}),(s[t.id]||[]).slice(0,10).map(e=>(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-xs py-1`,children:[(0,U.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded flex items-center gap-1 ${e.status===`ok`?`bg-accent-green/20 text-accent-green`:e.status===`error`?`bg-accent-red/20 text-accent-red`:`bg-accent-yellow/20 text-accent-yellow`}`,children:[e.status===`ok`&&(0,U.jsx)(re,{size:11}),e.status]}),(0,U.jsx)(`span`,{className:`text-dark-muted`,children:new Date(e.startedAt).toLocaleString()}),(0,U.jsxs)(`span`,{className:`text-dark-muted truncate flex-1`,children:[`#`,e.id.slice(0,8),` · `,e.trigger]})]},e.id))]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`text-xs font-semibold text-dark-muted mb-1`,children:e(`automation.permissionsTitle`)}),t.permissions.length===0&&(0,U.jsx)(`p`,{className:`text-xs text-dark-muted`,children:e(`automation.permissionsEmpty`)}),(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-1`,children:t.permissions.map(e=>(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded bg-accent-blue/10 text-accent-blue text-xs`,children:[e,(0,U.jsx)(`button`,{onClick:()=>void At(t.id,e),className:`hover:text-accent-red`,children:(0,U.jsx)(x,{size:12})})]},e))}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(`input`,{value:L,onChange:e=>Se(e.target.value),placeholder:e(`automation.permissionPlaceholder`),className:`flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue`}),(0,U.jsx)(`button`,{onClick:()=>void kt(t.id),className:`px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs`,children:e(`automation.add`)})]})]})]})]},t.id))})]})]}),M&&(0,U.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 max-md:p-0`,onClick:wt,children:[(0,U.jsx)(`div`,{className:`absolute inset-0 ui-scrim ui-overlay-backdrop`,"data-phase":N,"aria-hidden":`true`}),(0,U.jsxs)(`div`,{className:`relative w-full max-w-2xl rounded-xl border border-dark-border bg-dark-overlay ui-surface-overlay p-5 space-y-4 shadow-pop max-h-[90vh] overflow-y-auto custom-scrollbar ui-overlay-panel max-md:max-w-none max-md:rounded-none max-md:p-4`,"data-phase":N,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h3`,{className:`text-base font-semibold`,children:e(ge?`automation.editTitle`:`automation.createTitle`)}),(0,U.jsx)(`p`,{className:`text-xs text-dark-muted mt-0.5`,children:e(`automation.subtitle`)})]}),(0,U.jsx)(`button`,{onClick:wt,className:`p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted`,children:(0,U.jsx)(x,{size:16})})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`label`,{className:`block text-xs font-medium text-dark-muted mb-1.5`,children:e(`automation.jobKindLabel`)}),(0,U.jsx)(`div`,{className:`flex gap-1.5`,children:[{id:`agent`,label:e(`automation.jobKindAgent`),hint:e(`automation.jobKindAgentHint`)},{id:`workflow`,label:e(`automation.jobKindWorkflow`),hint:e(`automation.jobKindWorkflowHint`)}].map(e=>{let n=F.jobKind===e.id;return(0,U.jsxs)(`button`,{type:`button`,title:e.hint,onClick:()=>Et(e.id),className:`flex-1 px-3 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 ${n?`border-accent-blue bg-accent-blue/10 text-accent-blue`:`border-dark-border bg-dark-surface text-dark-muted hover:bg-dark-hover`}`,children:[e.id===`workflow`?(0,U.jsx)(v,{size:13}):(0,U.jsx)(t,{size:13}),e.label]},e.id)})})]}),F.jobKind===`workflow`&&(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`label`,{className:`block text-xs font-medium text-dark-muted mb-1.5`,children:e(`automation.workflowTemplateLabel`)}),(0,U.jsxs)(`select`,{value:F.workflowTemplate,onChange:e=>{let t=e.target.value;I(e=>({...e,workflowTemplate:t,name:t?`${Ve}${t}`:``}))},className:`w-full px-3 py-2 rounded-lg bg-dark-surface border border-dark-border text-sm focus:outline-none focus:border-accent-blue`,children:[(0,U.jsx)(`option`,{value:``,children:e(`automation.workflowTemplateNone`)}),lt.map(e=>(0,U.jsx)(`option`,{value:e.id,children:(e.nameOverride||e.name||e.id)+(e.category?` · ${e.category}`:``)},e.id))]}),dt&&lt.length===0&&(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mt-1`,children:e(`automation.workflowTemplateEmpty`)})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`label`,{className:`block text-xs font-medium text-dark-muted mb-1.5`,children:e(`automation.nameLabel`)}),(0,U.jsx)(`input`,{autoFocus:F.jobKind===`agent`,value:F.name,onChange:e=>I(t=>({...t,name:e.target.value})),placeholder:e(`automation.namePlaceholder`),disabled:F.jobKind===`workflow`,className:`w-full px-3 py-2 rounded-lg bg-dark-surface border border-dark-border text-sm focus:outline-none focus:border-accent-blue disabled:opacity-60`}),F.jobKind===`workflow`&&(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mt-1`,children:e(`automation.workflowNameHint`)})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`label`,{className:`block text-xs font-medium text-dark-muted mb-1.5`,children:e(`automation.scheduleLabel`)}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsxs)(`select`,{value:F.freq,onChange:e=>I(t=>({...t,freq:e.target.value})),className:`px-2.5 py-2 rounded-lg bg-dark-surface border border-dark-border text-sm focus:outline-none focus:border-accent-blue`,children:[(0,U.jsx)(`option`,{value:`daily`,children:e(`automation.freqDaily`)}),(0,U.jsx)(`option`,{value:`weekly`,children:e(`automation.freqWeekly`)}),(0,U.jsx)(`option`,{value:`weekdays`,children:e(`automation.freqWeekdays`)}),(0,U.jsx)(`option`,{value:`once`,children:e(`automation.freqOnce`)}),(0,U.jsx)(`option`,{value:`custom`,children:e(`automation.freqCustom`)})]}),F.freq===`weekly`&&(0,U.jsx)(`select`,{value:F.dow,onChange:e=>I(t=>({...t,dow:e.target.value})),className:`px-2.5 py-2 rounded-lg bg-dark-surface border border-dark-border text-sm focus:outline-none focus:border-accent-blue`,children:Xe.map(t=>(0,U.jsx)(`option`,{value:t.value,children:e(t.key)},t.value))}),(F.freq===`daily`||F.freq===`weekly`||F.freq===`weekdays`)&&(0,U.jsx)(`input`,{type:`time`,value:F.time,onChange:e=>I(t=>({...t,time:e.target.value})),className:`flex-1 px-3 py-2 rounded-lg bg-dark-surface border border-dark-border text-sm focus:outline-none focus:border-accent-blue`}),F.freq===`once`&&(0,U.jsx)(`input`,{type:`datetime-local`,value:F.onceAt,onChange:e=>I(t=>({...t,onceAt:e.target.value})),className:`flex-1 px-3 py-2 rounded-lg bg-dark-surface border border-dark-border text-sm focus:outline-none focus:border-accent-blue`}),F.freq===`custom`&&(0,U.jsx)(`input`,{value:F.cron,onChange:e=>I(t=>({...t,cron:e.target.value})),placeholder:`*/30 * * * *`,className:`flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm font-mono focus:outline-none focus:border-accent-blue`})]})]}),F.jobKind===`agent`?(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`label`,{className:`block text-xs font-medium text-dark-muted mb-1.5`,children:e(`automation.instructionLabel`)}),(0,U.jsx)(`textarea`,{value:F.instructions,onChange:e=>I(t=>({...t,instructions:e.target.value})),placeholder:e(`automation.instructionsPlaceholder`),rows:4,className:`w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue resize-none`})]}):(0,U.jsxs)(`div`,{className:`rounded-lg border border-dark-border bg-dark-surface/40 p-3 space-y-2`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,U.jsx)(`label`,{className:`text-xs font-medium text-dark-muted`,children:e(`automation.workflowInputsLabel`)}),(Ft?.inputs.length??0)>0&&(0,U.jsx)(`button`,{type:`button`,onClick:Dt,className:`text-badge text-accent-blue hover:underline`,children:e(`automation.workflowInputsFillDefaults`)})]}),Ft&&Ft.inputs.length>0?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`ul`,{className:`space-y-0.5`,children:Ft.inputs.map(e=>(0,U.jsxs)(`li`,{className:`text-badge text-dark-muted`,children:[(0,U.jsx)(`code`,{className:`text-accent-blue`,children:e.name}),e.label&&(0,U.jsx)(`span`,{className:`ms-1`,children:e.label}),e.required&&(0,U.jsx)(`span`,{className:`ms-1 text-accent-red`,children:`*`}),e.description&&(0,U.jsxs)(`span`,{className:`ms-1 text-dark-muted/60`,children:[`— `,e.description]})]},e.name))}),(0,U.jsx)(`textarea`,{value:F.instructions,onChange:e=>I(t=>({...t,instructions:e.target.value})),placeholder:`{
2
+ "key": "value"
3
+ }`,rows:4,className:`w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-xs font-mono focus:outline-none focus:border-accent-blue resize-none`}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70`,children:e(`automation.workflowInputsHint`)})]}):(0,U.jsx)(`p`,{className:`text-xs text-dark-muted/70`,children:e(`automation.workflowNoInputs`)})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(oe,{size:12}),` `,e(`automation.attachmentsLabel`)]}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mb-1.5`,children:e(`automation.attachmentsHint`)}),bt.length===0?(0,U.jsx)(`div`,{className:`text-xs text-dark-muted/60 italic`,children:e(`automation.attachmentsEmpty`)}):(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:bt.map(e=>(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs ${e.error?`bg-accent-red/10 text-accent-red`:e.uploading?`bg-dark-hover text-dark-muted`:`bg-accent-blue/10 text-accent-blue`}`,title:e.path??e.error,children:[(0,U.jsx)(oe,{size:11}),(0,U.jsx)(`span`,{className:`truncate max-w-[180px]`,children:e.name}),e.uploading&&(0,U.jsx)(o,{size:11,className:`animate-spin`}),e.error&&(0,U.jsx)(_,{size:11}),(0,U.jsx)(`button`,{onClick:()=>Nt(e.id),className:`hover:text-accent-red ms-0.5`,children:(0,U.jsx)(x,{size:11})})]},e.id))}),(0,U.jsx)(`input`,{ref:xt,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{Mt(e.target.files),e.target.value=``}}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>xt.current?.click(),className:`inline-flex items-center gap-1 px-2.5 py-1 rounded-lg border border-dashed border-dark-border text-xs text-dark-muted hover:border-accent-blue/60 hover:text-accent-blue`,children:[(0,U.jsx)(h,{size:12}),` `,e(`automation.attachmentsAdd`)]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(l,{size:12}),` `,e(`automation.modelLabel`)]}),(0,U.jsxs)(`select`,{value:F.modelRef,onChange:e=>I(t=>({...t,modelRef:e.target.value})),className:`w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue disabled:opacity-50 disabled:cursor-not-allowed`,disabled:_t||F.runSessionMode!==`new`,children:[(0,U.jsx)(`option`,{value:``,children:e(`automation.modelAuto`)}),rt.map(e=>(0,U.jsxs)(`option`,{value:`${e.provider}:${e.id}`,children:[e.name,` · `,e.provider]},`${e.provider}:${e.id}`))]}),F.runSessionMode!==`new`&&(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mt-1`,children:e(`automation.modelFollowsSession`)}),!_t&&rt.length===0&&(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mt-1`,children:e(`automation.modelNoModels`)})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(m,{size:12}),` `,e(`automation.runSessionLabel`)]}),(0,U.jsxs)(`select`,{value:F.runSessionMode,onChange:e=>{let t=e.target.value;I(e=>({...e,runSessionMode:t})),t===`fixed`&&yt()},className:`w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue`,children:[(0,U.jsx)(`option`,{value:`home`,children:e(`automation.runSessionHome`)}),(0,U.jsx)(`option`,{value:`new`,children:e(`automation.runSessionNew`)}),(0,U.jsx)(`option`,{value:`fixed`,children:e(`automation.runSessionFixed`)})]}),F.runSessionMode===`fixed`&&(0,U.jsxs)(`select`,{value:F.runSessionId,onChange:e=>I(t=>({...t,runSessionId:e.target.value})),className:`mt-2 w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue`,disabled:_t,children:[(0,U.jsx)(`option`,{value:``,children:e(`automation.runSessionPick`)}),pt.map(e=>(0,U.jsx)(`option`,{value:e.id,children:e.title||e.id},e.id))]}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mt-1`,children:e(`automation.runSessionHint`)})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(p,{size:12}),` `,e(`automation.budgetLabel`)]}),(0,U.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:F.budgetUsd,onChange:e=>I(t=>({...t,budgetUsd:e.target.value})),placeholder:e(`automation.budgetPlaceholder`),className:`w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue`}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mt-1`,children:e(`automation.budgetHint`)})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(g,{size:12}),` `,e(`automation.connectorsLabel`)]}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mb-1.5`,children:e(`automation.connectorsHint`)}),(0,U.jsx)(`p`,{className:`text-badge text-accent-yellow/90 mb-1.5`,children:e(`automation.connectorsUnwired`)}),at.length===0?(0,U.jsx)(`div`,{className:`text-xs text-dark-muted/60 italic`,children:e(`automation.connectorsEmpty`)}):(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5 opacity-50`,children:at.map(t=>{let n=F.connectorIds.includes(t.id);return(0,U.jsxs)(`button`,{type:`button`,disabled:!0,"aria-disabled":!0,title:e(`automation.connectorsUnwired`),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs border cursor-not-allowed ${n?`bg-accent-blue/15 text-accent-blue border-accent-blue/40`:`bg-dark-bg text-dark-muted border-dark-border`}`,children:[(0,U.jsx)(g,{size:11}),t.name]},t.id)})})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(d,{size:12}),` `,e(`automation.channelsLabel`)]}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mb-1.5`,children:e(`automation.channelsHint`)}),st.length===0?(0,U.jsx)(`div`,{className:`text-xs text-dark-muted/60 italic`,children:e(`automation.channelsEmpty`)}):(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:st.map(e=>{let t=F.channelIds.includes(e.id);return(0,U.jsxs)(`button`,{type:`button`,disabled:!e.enabled,onClick:()=>I(n=>({...n,channelIds:t?n.channelIds.filter(t=>t!==e.id):[...n.channelIds,e.id]})),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors ${t?`bg-accent-blue/15 text-accent-blue border border-accent-blue/40`:e.enabled?`bg-dark-bg text-dark-muted border border-dark-border hover:border-accent-blue/40 hover:text-accent-blue`:`bg-dark-bg text-dark-muted/50 border border-dark-border opacity-60 cursor-not-allowed`}`,children:[(0,U.jsx)(d,{size:11}),e.name,!e.enabled&&(0,U.jsx)(`span`,{className:`text-avatar`,children:`·off`})]},e.id)})})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(ie,{size:12}),` `,e(`automation.workspaceLabel`)]}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/70 mb-1.5`,children:e(`automation.workspaceHint`)}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(`input`,{value:F.workspaceDir,onChange:e=>I(t=>({...t,workspaceDir:e.target.value})),placeholder:`留空使用当前工作目录`,className:`flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm font-mono focus:outline-none focus:border-accent-blue`}),(0,U.jsxs)(`button`,{type:`button`,onClick:()=>V(!0),className:`shrink-0 inline-flex items-center gap-1 px-3 py-2 rounded-lg border border-dark-border text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text`,children:[(0,U.jsx)(ie,{size:12}),` `,e(`automation.workspacePick`)]}),F.workspaceDir&&(0,U.jsx)(`button`,{type:`button`,onClick:()=>I(e=>({...e,workspaceDir:``})),className:`shrink-0 inline-flex items-center gap-1 px-2 py-2 rounded-lg border border-dark-border text-xs text-dark-muted hover:bg-dark-hover hover:text-accent-red`,title:e(`automation.workspaceClear`),children:(0,U.jsx)(x,{size:12})})]})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs font-medium text-dark-muted mb-1.5`,children:[(0,U.jsx)(se,{size:12}),` `,e(`automation.permissionAccess`)]}),(0,U.jsxs)(`div`,{className:`flex items-start gap-2 p-2.5 rounded-lg border border-dark-border bg-dark-bg`,children:[(0,U.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":F.readAutoAllow,onClick:()=>I(e=>({...e,readAutoAllow:!e.readAutoAllow})),className:`relative shrink-0 mt-0.5 inline-flex h-5 w-9 items-center rounded-full transition-colors ${F.readAutoAllow?`bg-accent-blue`:`bg-dark-hover`}`,children:(0,U.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${F.readAutoAllow?`translate-x-4`:`translate-x-0.5`}`})}),(0,U.jsxs)(`div`,{className:`flex-1`,children:[(0,U.jsx)(`div`,{className:`text-xs font-medium text-dark-text`,children:e(`automation.fullAccessLabel`)}),(0,U.jsx)(`p`,{className:`text-badge text-dark-muted/80 mt-0.5`,children:e(`automation.fullAccessHint`)})]})]})]}),(0,U.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,U.jsx)(`button`,{onClick:wt,className:`px-4 py-2 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-sm`,children:e(`automation.cancel`)}),(0,U.jsx)(ue,{variant:`accent`,onClick:()=>void Ot(),disabled:!It,loading:Ce,children:e(`automation.save`)})]})]})]}),(0,xe.createPortal)((0,U.jsx)(Qe,{isOpen:Ee&&k,initial:F.workspaceDir||``,onClose:()=>V(!1),onConfirm:e=>{I(t=>({...t,workspaceDir:e})),V(!1)}}),document.body)]})}export{$e as AutomationView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{Kt as t,ni as n}from"./icons-B8Ngx6rM.js";import{n as r}from"./state-pOTP5BEk.js";import{I as i}from"./markdown-Cps-36Z5.js";var a=4e3,o=new Map;function s(e,t){let n=o.get(e);n&&clearTimeout(n),!(t<=0)&&o.set(e,setTimeout(()=>{o.delete(e),c.setState(t=>({toasts:t.toasts.filter(t=>t.id!==e)}))},t))}var c=r(e=>({toasts:[],addToast:(t,n,r,i,o)=>{let c=r??a,l=e=>e.dedupeKey??`${e.type}\u0000${e.message}`,u=o??`${t}\u0000${n}`;e(e=>{let r=e.toasts.find(e=>l(e)===u);if(r)return s(r.id,c),{toasts:e.toasts.map(e=>e.id===r.id?{...e,count:e.count+1,createdAt:Date.now(),action:i??e.action}:e)};let a=`toast-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;s(a,c);let d={id:a,type:t,message:n,duration:c,createdAt:Date.now(),count:1,action:i,...o?{dedupeKey:o}:{}};return{toasts:[...e.toasts,d].slice(-10)}})},dismissToast:t=>{let n=o.get(t);n&&(clearTimeout(n),o.delete(t)),e(e=>({toasts:e.toasts.filter(e=>e.id!==t)}))},clearAll:()=>{for(let e of o.values())clearTimeout(e);o.clear(),e({toasts:[]})}})),l={info:(e,t)=>c.getState().addToast(`info`,e,t),success:(e,t)=>c.getState().addToast(`success`,e,t),warning:(e,t)=>c.getState().addToast(`warning`,e,t),error:(e,t)=>c.getState().addToast(`error`,e,t??6e3),infoWithAction:(e,t,n,r)=>c.getState().addToast(`info`,e,n,t,r)},u=e(n(),1);function d(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=d(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function f(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=d(e))&&(r&&(r+=` `),r+=t);return r}function p(...e){return f(e)}var m=20;function h(){if(typeof window>`u`||typeof getComputedStyle!=`function`)return 220;let e=getComputedStyle(document.documentElement).getPropertyValue(`--dur-base`).trim(),t=Number.parseFloat(e);return!Number.isFinite(t)||t<=0?220:(e.endsWith(`ms`)?t:t*1e3)+m}function g(e){let[t,n]=(0,u.useState)(e),[r,i]=(0,u.useState)(!1),a=(0,u.useRef)(e);return a.current!==e&&(a.current=e,e?(n(!0),i(!1)):t&&i(!0)),(0,u.useEffect)(()=>{if(!r)return;let e=window.setTimeout(()=>{i(!1),n(!1)},h());return()=>window.clearTimeout(e)},[r]),{visible:t,phase:r?`exit`:`enter`}}var _=i(),v={primary:`btn-primary`,accent:`btn-accent`,secondary:`btn-secondary`,ghost:`btn-ghost`,danger:`btn-danger`},y={sm:`btn-sm`,lg:`btn-lg`},b={sm:13,md:15,lg:17};function x({variant:e=`secondary`,size:n=`md`,shape:r=`default`,loading:i=!1,leftIcon:a,rightIcon:o,type:s=`button`,disabled:c,className:l,children:u,ref:d,...f}){return(0,_.jsxs)(`button`,{ref:d,type:s,disabled:c||i,"aria-busy":i||void 0,className:p(`btn`,v[e],n!==`md`&&y[n],r===`pill`&&`btn-pill`,l),...f,children:[i?(0,_.jsx)(t,{size:b[n],className:`shrink-0 animate-spin`,"aria-hidden":`true`}):a,u,!i&&o]})}export{c as a,l as i,g as n,p as r,x as t};
@@ -0,0 +1,12 @@
1
+ import{i as e,t}from"./rolldown-runtime-COiEfhsA.js";import{$ as n,A as r,Dn as i,a,dt as o,ft as s,g as c,it as l,ni as u,o as d,st as f,ti as p,v as m,zr as h}from"./icons-B8Ngx6rM.js";import{t as g}from"./useTranslation-gGKZZfux.js";import{i as _,t as v}from"./Button-D-g7PgYh.js";import{t as y}from"./api-ZQf0Ys8y.js";import{I as b}from"./markdown-Cps-36Z5.js";import{r as x,t as S}from"./useConfirm-CQjBnYuP.js";import"./common-CPZxdYLs.js";import{n as C,r as w,t as T}from"./channelMeta-BO645sjD.js";import{ft as E,v as D}from"./index-STsyoFCk.js";import{n as O}from"./installDiagnosis-ZYUVgJIJ.js";var k=e(u(),1),A=b(),j=[{labelKey:`im`,types:[`wechat`,`weixin-im`,`feishu`,`dingtalk`]},{labelKey:`international`,types:[`telegram`,`telegram-im`,`discord`,`discord-im`,`slack`,`slack-im`,`signal`,`whatsapp`]},{labelKey:`eastAsia`,types:[`line`,`qqbot`]},{labelKey:`collaboration`,types:[`matrix`,`mattermost`,`msteams`,`googlechat`]},{labelKey:`classic`,types:[`irc`,`imessage`,`sms`]},{labelKey:`other`,types:[`nextcloud-talk`,`nostr`,`synology-chat`,`tlon`,`twitch`,`zalo`,`zalouser`]},{labelKey:`builtin`,types:[`clickclack`,`raft`,`qa-channel`]}];function M(){let{t:e}=g(),{channels:t,availableTypes:n,typesLoaded:r,selectedType:i,selectType:a,loadTypes:o}=D();(0,k.useEffect)(()=>{o()},[o]);let s=(0,k.useMemo)(()=>{if(n.length===0)return[];let e=new Set(n),t=j.map(t=>({...t,types:t.types.filter(t=>e.has(t))})).filter(e=>e.types.length>0),r=new Set(j.flatMap(e=>e.types)),i=n.filter(e=>!r.has(e));return i.length>0?[...t,{labelKey:`plugins`,types:i}]:t},[n]),c=(0,k.useMemo)(()=>{let e=new Map;for(let n of t){let t=e.get(n.type)??{count:0,connected:0};e.set(n.type,{count:t.count+1,connected:t.connected+ +!!n.connected})}return e},[t]),l=n.length>0,u=(0,k.useMemo)(()=>l?t.filter(e=>n.includes(e.type)):[],[l,t,n]);return(0,A.jsxs)(`div`,{className:`flex flex-col h-full min-h-0 border-e border-dark-border bg-dark-surface`,children:[(0,A.jsxs)(`div`,{className:`shrink-0 px-4 py-3 border-b border-dark-border`,children:[(0,A.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-dark-muted`,children:e(`channels.sidebar.title`)}),(0,A.jsx)(`p`,{className:`text-meta text-dark-muted mt-0.5`,children:u.length>0?e(`channels.sidebar.configuredCount`,{n:u.length}):e(l?`channels.sidebar.clickToConfigure`:`channels.sidebar.emptyHint`)})]}),(0,A.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar`,children:[r&&!l&&(0,A.jsxs)(`div`,{className:`px-4 py-10 text-center`,children:[(0,A.jsx)(`p`,{className:`text-xs text-dark-muted`,children:e(`channels.sidebar.empty`)}),(0,A.jsx)(`p`,{className:`text-meta text-dark-muted/70 mt-1.5 leading-relaxed`,children:e(`channels.sidebar.emptyHint`)})]}),s.map(t=>{let n=t.types.filter(e=>c.has(e));return n.length===0?null:(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:`sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-badge font-semibold uppercase tracking-wider text-dark-muted/60`,children:e(`channels.categories.${t.labelKey}`)}),n.map(e=>{let t=c.get(e);return(0,A.jsx)(N,{label:C(e),icon:T(e),isSelected:i===e,experimental:w(e),info:t,onClick:()=>a(e)},e)})]},t.labelKey)}),(()=>{let t=s.flatMap(e=>e.types).filter(e=>!c.has(e));return t.length===0?null:(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:`sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-badge font-semibold uppercase tracking-wider text-dark-muted/60`,children:e(`channels.sidebar.unconfigured`)}),t.map(e=>(0,A.jsx)(N,{label:C(e),icon:T(e),isSelected:i===e,experimental:w(e),onClick:()=>a(e)},e))]})})()]})]})}function N({label:e,icon:t,isSelected:n,experimental:r,info:o,onClick:s}){let{t:c}=g();return(0,A.jsxs)(`button`,{onClick:s,className:`w-full flex items-center gap-2.5 px-4 py-2.5 text-start transition-colors hover:bg-dark-hover ${n?`bg-accent-blue/10 border-s-2 border-accent-blue`:`border-s-2 border-transparent`}`,children:[(0,A.jsx)(`span`,{className:`text-lg shrink-0 w-7 h-7 flex items-center justify-center rounded-md bg-dark-bg`,children:t}),(0,A.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,A.jsx)(`span`,{className:`text-sm font-medium text-dark-text truncate`,children:e}),r&&(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-avatar text-accent-yellow bg-accent-yellow/15 px-1 py-0.5 rounded shrink-0`,title:c(`channels.experimentalTip`),children:[(0,A.jsx)(i,{className:`w-2.5 h-2.5`}),` `,c(`channels.experimentalShort`)]}),o&&(0,A.jsx)(`span`,{className:`text-badge text-dark-muted bg-dark-hover px-1.5 py-0.5 rounded shrink-0`,children:o.count})]}),(0,A.jsx)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:o?o.connected>0?(0,A.jsxs)(`span`,{className:`flex items-center gap-1 text-meta text-accent-green`,children:[(0,A.jsx)(a,{className:`w-3 h-3`}),o.connected===o.count?c(`channels.status.connected`):c(`channels.sidebar.partialConnected`,{connected:o.connected,count:o.count})]}):(0,A.jsxs)(`span`,{className:`flex items-center gap-1 text-meta text-dark-muted`,children:[(0,A.jsx)(d,{className:`w-3 h-3`}),c(`channels.status.disconnected`)]}):(0,A.jsx)(`span`,{className:`text-meta text-dark-muted`,children:c(`channels.sidebar.unconfigured`)})})]})]})}function P({result:e}){let{t}=g(),[n,r]=(0,k.useState)(!1),i=e.logs?.length?e.logs:[...e.message?[e.message]:[],...typeof e.probed==`boolean`?[`probed=${e.probed}`]:[],`connected=${e.connected}`,...typeof e.latencyMs==`number`?[`latencyMs=${e.latencyMs}`]:[]];return i.length===0?null:(0,A.jsxs)(`details`,{open:!e.ok,className:`mt-1`,children:[(0,A.jsxs)(`summary`,{className:`cursor-pointer select-none text-meta text-dark-muted hover:text-dark-text`,children:[t(`channels.actions.debugLogs`),` · `,i.length]}),(0,A.jsxs)(`div`,{className:`mt-1 rounded-md border border-dark-border bg-dark-bg`,children:[(0,A.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap break-all p-2 font-mono text-meta leading-relaxed text-dark-muted`,children:i.join(`
2
+ `)}),(0,A.jsx)(`div`,{className:`flex justify-end border-t border-dark-border px-2 py-1`,children:(0,A.jsx)(`button`,{onClick:async()=>{try{await navigator.clipboard.writeText(i.join(`
3
+ `)),r(!0),window.setTimeout(()=>r(!1),1500)}catch{}},className:`text-meta text-accent-blue hover:underline`,children:t(n?`channels.actions.copied`:`channels.actions.copyLog`)})})]})]})}var F={IMPLEMENTED:`IMPLEMENTED(收发双向)`,OUTBOUND_ONLY:`OUTBOUND_ONLY(只能发出,收不到入站消息)`,TEMPLATE:`TEMPLATE(骨架实现,功能未完成)`},I=60;function L({channel:e,result:t,pluginMissing:n,typeLabel:r}){let i=r?`${e.type}(${r})`:e.type,a=t.detail||t.message||`(服务端没有给出错误信息)`,o=[`频道测试连接失败了,帮我定位并修好。`,``,`- 频道:${e.name}`,`- 类型:${i}`,`- AppID:${e.appId||`(没配)`}`,`- 启用:${e.enabled?`是`:`否`}`];return e.implementationStatus&&o.push(`- 能力档位:${F[e.implementationStatus]??e.implementationStatus}`),n&&o.push(`- 插件:该类型的适配器**没有注册**(插件未安装或未激活)`),o.push(``),o.push(`【测试结论】`),o.push(`- ok=${t.ok},connected=${t.connected}`),o.push(t.probed?`- probed=true:服务端真的拿凭据敲了平台,上面的结论可信`:`- probed=false:适配器没有 probe 实现,服务端只看了本地状态,**没有真的验证凭据**`),typeof t.latencyMs==`number`&&o.push(`- 耗时:${t.latencyMs}ms`),o.push(`- 错误:${a}`),o.push(``),t.logs&&t.logs.length>0&&o.push(`【最近 ${Math.min(t.logs.length,I)} 行诊断日志】`,O(t.logs),``),o.push(`请先判断属于哪一类:凭据不匹配(AppID / AppSecret / token / EncodingAESKey 填错或过期) / 适配器没有 probe 实现(probed=false,结论不可信) / 频道插件未安装或未激活 / 适配器没启动、入站回调地址没配置 / 平台侧权限或 IP 白名单 / 网络不通。`,`然后给出最小修复动作:能改配置的,说清改哪一项、去哪里改;要改代码的,指出文件与函数。`,`最后说明改完之后该怎么重测。`,``,`需要读代码时:判定逻辑在 packages/server/src/channelTestDiagnostics.ts,适配器实现在 packages/plugins/channels/${e.type}/。`),o.join(`
4
+ `)}var R={slack:{entry:`https://api.slack.com/apps(打开后停住等我在浏览器里登录,然后进应用 → OAuth & Permissions)`,credentials:[`token:Bot User OAuth Token(xoxb- 开头,OAuth & Permissions 页;收发消息都靠它)`,`extra.app_token:App-Level Token(xapp- 开头,收消息才需要;Basic settings → App-Level Tokens)`]},telegram:{entry:`Telegram 的凭据不走浏览器:找 @BotFather 发 /mybots → API Token 获取(你把话术准备好,我复制 token 给你)`,credentials:[`token:bot token(形如 123456789:AAEx…)`]},discord:{entry:`https://discord.com/developers/applications(停在登录页等我登录)`,credentials:[`token:Developer Portal → 应用 → Bot → Reset Token(只在生成时显示一次,当场复制)`]},line:{entry:`https://developers.line.biz/console/(停在登录页等我登录)`,credentials:[`token:Messaging API 频道 → Messaging API 设定 → Channel access token 点 Issue`]},whatsapp:{entry:`https://developers.facebook.com/(停在登录页等我登录)`,credentials:[`token:应用 → WhatsApp → API Setup 页的 access_token(临时 token 24h 过期)`,`extra.phone_number_id:同页的 Phone number ID`]},dingtalk:{entry:`https://open-dev.dingtalk.com/(停在登录页等我登录)`,credentials:[`appId:AppKey`,`appSecret:AppSecret(应用详情 → 凭据与基础信息)`]},feishu:{entry:`https://open.feishu.cn/app(停在登录页等我登录)`,credentials:[`appId / appSecret:开发者后台 → 应用 → 凭据与基础信息`]},mattermost:{entry:`用频道配置里 extra.server 的站点地址登录(停在登录页等我输入)`,credentials:[`token:个人访问令牌(账户设置 → 安全 → 个人访问令牌)`]},msteams:{entry:`Teams 网页版/客户端里操作:频道名 → ⋯ → 连接 → Incoming Webhook → 创建`,credentials:[`extra.webhook_url:创建后生成的完整地址`]},matrix:{entry:`用家服务器的 Web 客户端(如 Element)登录(停在登录页等我输入)`,credentials:[`token:access_token(Element → 所有设置 → 帮助与关于 → 高级)`,`extra.homeserver:家服务器地址`,`extra.user_id:完整用户 ID(@user:server)`]},qqbot:{entry:`https://q.qq.com/(停在登录页等我登录)`,credentials:[`appId / token / appSecret:机器人管理台 → 开发设置`]},wechat:{entry:`微信不需要浏览器:走本应用频道面板上的「扫码绑定」入口`,credentials:[`无固定凭据:扫码即完成绑定`]}};function z(e,t){let n=t?`${e.type}(${t})`:e.type,r=R[e.type]??{entry:`(该平台没有固定的后台入口,按平台文档定位凭据页面)`,credentials:[`按平台文档确认需要哪些凭据`]},i=[`- appId:${e.appId?`已填`:`未填`}`,`- appSecret:${e.appSecret?`已填`:`未填`}`,`- token:${e.token?`已填`:`未填`}`],a=Object.keys(e.extra??{});i.push(`- extra:${a.length?a.join(`、`):`空`}`);let o=[`帮我自动配置频道「${e.name}」(${n})。用「人机接力」的方式:`,`你负责打开页面、导航、定位和填表;**账号密码和验证码由我在浏览器里亲手输入**——`,`你不要读取、记录或代填任何密码;登录页出现时停下来等我。`,``,`【流程】`,`1. 打开平台后台:${r.entry}`,`2. 我登录完成后,你定位并复制下面的凭据。`,`3. 把凭据写回本应用:频道配置存在本机 channels.json(凭据是 enc: 密文落盘的),`,` **不要直接改文件**——调本地 server 的 HTTP 接口 PUT /api/channels/:id,`,` body 传明文,服务端会自己加密;本仓库就是 server 源码,server 在本机运行。`,` ⚠️ 拿到的 token 不要在回复里明文回显,写进配置即可。`,`4. 保存后适配器会自动重启。然后 POST /api/channels/:id/test 跑一次测试连接,`,` 把 ok / probed / detail / 诊断日志原样带回来给我。`,`5. 测试失败就按 packages/server/src/channelTestDiagnostics.ts 的分类定位,`,` 先区分「凭据没配置」和「凭据无效」,别一上来就让我换 token。`,``,`【该平台需要哪些凭据、去哪拿】`,...r.credentials.map(e=>`- ${e}`),``,`【已知现场(只报有无,不含值)】`,`- 频道:${e.name}`,`- 类型:${n}`,`- 启用:${e.enabled?`是`:`否`}`,...i];return e.implementationStatus&&o.push(`- 能力档位:${F[e.implementationStatus]??e.implementationStatus}`),o.join(`
5
+ `)}var B={name:``,type:`wechat`,appId:``,appSecret:``,token:``,encodingAESKey:``,enabled:!0};function V(){let{t:e}=g(),[t,n]=S(),{channels:r,selectedType:a,availableTypes:l,create:u,update:d,remove:p,toggle:m,error:h,clearError:_,openQr:y,load:b,test:x,testResult:E,testing:O}=D(),j=(0,k.useMemo)(()=>l.length>0&&!!a&&!l.includes(a),[l,a]),M=(0,k.useMemo)(()=>a?r.filter(e=>e.type===a):[],[r,a]),[N,P]=(0,k.useState)(``),[F,I]=(0,k.useState)(B),[L,R]=(0,k.useState)(!1),z=N===`__new__`,V=(0,k.useMemo)(()=>z?null:M.find(e=>e.id===N)??null,[M,N,z]);(0,k.useEffect)(()=>{P(``),I(B),R(!1),_()},[a]),(0,k.useEffect)(()=>{a===`wechat`&&M.length===0&&!j&&y(null)},[a,M.length,j,y]),(0,k.useEffect)(()=>{V?I({name:V.name,type:V.type,appId:V.appId||``,appSecret:``,token:``,encodingAESKey:V.encodingAESKey||``,enabled:V.enabled}):z&&I(e=>({...e,type:a}))},[N]);let H=(e,t)=>{_(),I(n=>({...n,[e]:t}))},U=e=>{P(e),_()},W=()=>{P(`__new__`),I({...B,type:a}),_()},G=()=>{P(``),I(B),_()},K=async()=>{if(!F.name.trim())return;R(!0);let e=V?await d(V.id,F):await u(F);R(!1),e&&(P(``),I(B))},q=async t=>{await n({message:e(`channels.actions.deleteConfirmShort`),variant:`danger`})&&await p(t)&&N===t&&(P(``),I(B))},J=(e,t)=>{m(e,t)};return a?(0,A.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-hidden`,children:[t,(0,A.jsx)(`div`,{className:`shrink-0 px-6 py-4 border-b border-dark-border`,children:(0,A.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,A.jsx)(`span`,{className:`text-2xl`,children:T(a)}),(0,A.jsxs)(`div`,{children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`h2`,{className:`font-semibold text-base text-dark-text`,children:C(a)}),w(a)&&(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-badge text-accent-yellow bg-accent-yellow/15 px-1.5 py-0.5 rounded`,title:e(`channels.experimentalTip`),children:[(0,A.jsx)(i,{className:`w-3 h-3`}),` `,e(`channels.experimentalLabel`)]})]}),(0,A.jsx)(`p`,{className:`text-xs text-dark-muted mt-0.5`,children:M.length>0?e(`channels.instancesCount`,{n:M.length}):e(`channels.notConfiguredYet`)}),w(a)&&(0,A.jsx)(`p`,{className:`text-badge text-accent-yellow mt-1`,children:e(`channels.experimentalDesc`)})]})]}),(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`button`,{onClick:()=>b(),className:`text-xs px-3 py-1.5 rounded-lg border border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors`,children:e(`channels.actions.refresh`)}),(0,A.jsx)(v,{size:`sm`,variant:`accent`,onClick:W,leftIcon:(0,A.jsx)(o,{className:`w-3.5 h-3.5`}),children:e(`channels.createInstance`)})]})]})}),h&&(0,A.jsxs)(`div`,{className:`shrink-0 mx-6 mt-3 bg-accent-red/15 border border-accent-red text-accent-red px-3 py-2 rounded-lg text-sm flex justify-between items-center`,children:[(0,A.jsx)(`span`,{children:h}),(0,A.jsx)(`button`,{onClick:_,className:`text-accent-red hover:text-accent-red`,children:(0,A.jsx)(`span`,{className:`w-4 h-4 inline-flex items-center justify-center`,children:`×`})})]}),j&&(0,A.jsxs)(`div`,{className:`shrink-0 mx-6 mt-3 flex items-start gap-2 bg-accent-yellow/15 border border-accent-yellow text-accent-yellow px-3 py-2 rounded-lg text-xs`,children:[(0,A.jsx)(c,{className:`w-3.5 h-3.5 mt-0.5 shrink-0`}),(0,A.jsx)(`span`,{children:e(`channels.pluginMissingWarning`,{name:a===`wechat`?` WeChat Channel`:` ${C(a)}`})})]}),(0,A.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto custom-scrollbar p-6`,children:[M.length>1&&!z&&(0,A.jsxs)(`div`,{className:`mb-4`,children:[(0,A.jsx)(`label`,{className:`block text-xs text-dark-muted mb-1.5`,children:e(`channels.selectInstance`)}),(0,A.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[M.map(e=>(0,A.jsxs)(`button`,{onClick:()=>U(e.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border transition-colors ${N===e.id?`bg-accent-blue/10 border-accent-blue/40 text-accent-blue`:`border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover`}`,children:[(0,A.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${e.connected?`bg-accent-green`:`bg-dark-muted`}`}),e.name]},e.id)),(0,A.jsxs)(`button`,{onClick:W,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border border-dashed border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors`,children:[(0,A.jsx)(o,{className:`w-3 h-3`}),` `,e(`channels.createShort`)]})]})]}),M.length===0&&N===``&&(0,A.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,A.jsx)(`div`,{className:`text-4xl mb-3`,children:T(a)}),(0,A.jsx)(`p`,{className:`text-dark-text font-medium`,children:e(`channels.emptyWithType`,{type:C(a)})}),(0,A.jsx)(`p`,{className:`text-sm text-dark-muted mt-1 mb-4`,children:e(a===`wechat`?`channels.wechatBindHint`:`channels.startWithCreate`)}),a===`wechat`&&(0,A.jsxs)(`button`,{onClick:()=>y(null),className:`flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-accent-green/15 hover:bg-accent-green/15 text-accent-green border border-accent-green transition-colors mb-3`,children:[(0,A.jsx)(f,{className:`w-4 h-4`}),` `,e(`channels.scanToBind`)]}),(0,A.jsx)(v,{variant:`accent`,onClick:W,leftIcon:(0,A.jsx)(o,{className:`w-4 h-4`}),children:e(`channels.createInstance`)})]}),M.length===1&&N===``&&M[0]&&(0,A.jsx)(ee,{channel:M[0],onEdit:()=>U(M[0].id),onDelete:()=>q(M[0].id),onToggle:e=>J(M[0].id,e),onQr:()=>y(M[0]),onTest:()=>x(M[0].id),testResult:E[M[0].id],testing:O===M[0].id,pluginMissing:j}),M.length>1&&N===``&&(0,A.jsx)(`div`,{className:`space-y-3`,children:M.map(e=>(0,A.jsx)(ee,{channel:e,onEdit:()=>U(e.id),onDelete:()=>q(e.id),onToggle:t=>J(e.id,t),onQr:()=>y(e),onTest:()=>x(e.id),testResult:E[e.id],testing:O===e.id,pluginMissing:j},e.id))}),N!==``&&(z||V)&&(0,A.jsx)(te,{form:F,upd:H,saving:L,editing:!!V,channel:V??void 0,onSave:K,onCancel:G,onDelete:V?()=>q(V.id):void 0,onQr:V?()=>y(V):void 0})]})]}):(0,A.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,A.jsxs)(`div`,{className:`text-center`,children:[(0,A.jsx)(s,{className:`w-12 h-12 mx-auto mb-3 text-dark-muted/40`}),(0,A.jsx)(`p`,{className:`text-dark-muted text-sm`,children:e(`channels.selectTypeHint`)})]})})}function ee({channel:e,onEdit:t,onDelete:n,onToggle:i,onQr:o,onTest:s,testResult:l,testing:u,pluginMissing:_}){let{t:v}=g();return(0,A.jsxs)(`div`,{className:`border border-dark-border rounded-lg bg-dark-surface overflow-hidden`,children:[(0,A.jsx)(`div`,{className:`p-5`,children:(0,A.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h3`,{className:`font-medium text-dark-text`,children:e.name}),(0,A.jsxs)(`div`,{className:`flex items-center gap-3 mt-2`,children:[(0,A.jsx)(`span`,{className:`flex items-center gap-1 text-xs ${e.connected?`text-accent-green`:`text-dark-muted`}`,children:e.connected?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(a,{className:`w-3 h-3`}),` `,v(`channels.status.connected`)]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(d,{className:`w-3 h-3`}),` `,v(`channels.status.disconnected`)]})}),(0,A.jsxs)(`span`,{className:`text-xs text-dark-muted`,children:[`AppID: `,e.appId||`—`]}),e.implementationStatus===`OUTBOUND_ONLY`&&(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-badge text-accent-yellow bg-accent-yellow/15 px-1.5 py-0.5 rounded`,title:v(`channels.outboundOnlyTip`),children:[(0,A.jsx)(c,{className:`w-3 h-3`}),` `,v(`channels.outboundOnlyLabel`)]})]}),l&&(0,A.jsxs)(`div`,{className:`mt-1.5`,children:[(0,A.jsxs)(`p`,{className:`text-xs ${l.ok?`text-accent-green`:`text-accent-red`}`,children:[l.detail??(l.ok?v(`channels.actions.testPassed`):l.message??v(`channels.actions.testFailed`)),typeof l.latencyMs==`number`&&l.ok?` · ${l.latencyMs}ms`:``]}),(0,A.jsx)(P,{result:l}),!l.ok&&(0,A.jsxs)(`button`,{type:`button`,"data-testid":`channel-ask-ai`,onClick:()=>E(L({channel:e,result:l,pluginMissing:_,typeLabel:C(e.type)})),className:`mt-1 inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-accent-blue/40 bg-accent-blue/10 text-meta text-accent-blue hover:bg-accent-blue/20 transition-colors`,children:[(0,A.jsx)(r,{className:`w-3 h-3`}),` `,v(`channels.actions.askAiFix`)]})]})]}),(0,A.jsx)(`button`,{onClick:()=>i(!e.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${e.enabled?`bg-accent-green`:`bg-dark-muted`}`,children:(0,A.jsx)(`span`,{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${e.enabled?`start-[18px]`:`start-0.5`}`})})]})}),(0,A.jsxs)(`div`,{className:`flex items-center gap-1 px-5 py-2.5 bg-dark-bg/50 border-t border-dark-border`,children:[e.type===`wechat`&&(0,A.jsxs)(`button`,{onClick:o,className:`flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-green hover:bg-accent-green/15 transition-colors`,children:[(0,A.jsx)(f,{className:`w-3.5 h-3.5`}),` `,v(`channels.actions.qrLogin`)]}),(0,A.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-blue hover:bg-accent-blue/10 transition-colors`,children:[(0,A.jsx)(`span`,{className:`w-3.5 h-3.5 inline-flex items-center justify-center`,children:`✎`}),` `,v(`channels.actions.edit`)]}),e.enabled&&s&&(0,A.jsxs)(`button`,{onClick:s,disabled:u,className:`flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-blue hover:bg-accent-blue/10 transition-colors disabled:opacity-50`,children:[(0,A.jsx)(p,{className:`w-3.5 h-3.5`}),` `,v(`channels.actions.test`)]}),(0,A.jsxs)(`button`,{type:`button`,"data-testid":`channel-ask-ai-setup`,onClick:()=>E(z(e,C(e.type))),className:`flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-blue hover:bg-accent-blue/10 transition-colors`,children:[(0,A.jsx)(h,{className:`w-3.5 h-3.5`}),` `,v(`channels.actions.askAiSetup`)]}),(0,A.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-red hover:bg-accent-red/15 transition-colors ms-auto`,children:[(0,A.jsx)(m,{className:`w-3.5 h-3.5`}),` `,v(`channels.actions.delete`)]})]})]})}function te({form:e,upd:t,saving:r,editing:i,channel:a,onSave:o,onCancel:s,onDelete:c,onQr:l}){let{t:u}=g(),d=e.type===`slack`,p=d?`xapp-… · ${u(`channels.form.optionalShort`)}`:u(i?`channels.form.leaveBlankUnchanged`:`channels.form.appSecretValue`),h=d?i?`xoxb-… · ${u(`channels.form.leaveBlankUnchanged`)}`:`xoxb-…`:u(i?`channels.form.leaveBlankUnchanged`:`channels.form.tokenCallback`);return(0,A.jsxs)(`div`,{className:`border border-dark-border rounded-lg bg-dark-surface overflow-hidden`,children:[(0,A.jsx)(`div`,{className:`px-5 py-4 border-b border-dark-border`,children:(0,A.jsx)(`h3`,{className:`font-medium text-dark-text`,children:u(i?`channels.editConfig`:`channels.createConfig`)})}),(0,A.jsxs)(`div`,{className:`p-5 space-y-4`,children:[(0,A.jsx)(H,{label:u(`channels.form.name`),required:!0,children:(0,A.jsx)(`input`,{value:e.name,onChange:e=>t(`name`,e.target.value),placeholder:u(`channels.form.namePlaceholderDev`),className:U})}),(0,A.jsxs)(H,{label:u(`channels.form.credentials`),children:[(0,A.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{className:`block text-badge text-dark-muted mb-1`,children:u(`channels.form.appId`)}),(0,A.jsx)(`input`,{value:e.appId,onChange:e=>t(`appId`,e.target.value),placeholder:`AppID`,className:U})]}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{className:`block text-badge text-dark-muted mb-1`,children:`AppSecret`}),(0,A.jsx)(`input`,{type:`password`,value:e.appSecret,onChange:e=>t(`appSecret`,e.target.value),placeholder:p,className:U})]}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{className:`block text-badge text-dark-muted mb-1`,children:`Token`}),(0,A.jsx)(`input`,{value:e.token,onChange:e=>t(`token`,e.target.value),placeholder:h,className:U})]}),e.type===`wechat`&&(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`label`,{className:`block text-badge text-dark-muted mb-1`,children:`EncodingAESKey`}),(0,A.jsx)(`input`,{value:e.encodingAESKey,onChange:e=>t(`encodingAESKey`,e.target.value),placeholder:u(`channels.form.optionalShort`),className:U})]})]}),e.type===`wechat`&&(0,A.jsx)(`p`,{className:`text-xs text-dark-muted mt-2`,children:u(`channels.form.wechatIlinkHint`)})]}),(0,A.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-dark-border px-3 py-2.5`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`p`,{className:`text-sm text-dark-text`,children:u(`channels.form.enabled`)}),(0,A.jsx)(`p`,{className:`text-xs text-dark-muted`,children:u(`channels.form.enabledOffHint`)})]}),(0,A.jsx)(`button`,{onClick:()=>t(`enabled`,!e.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${e.enabled?`bg-accent-green`:`bg-dark-muted`}`,children:(0,A.jsx)(`span`,{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${e.enabled?`start-[18px]`:`start-0.5`}`})})]}),i&&a?.type===`wechat`&&l&&(0,A.jsxs)(`button`,{onClick:l,className:`w-full flex items-center justify-center gap-2 text-sm bg-accent-green/15 hover:bg-accent-green/15 text-accent-green border border-accent-green px-3 py-2.5 rounded-lg transition-colors`,children:[(0,A.jsx)(f,{className:`w-4 h-4`}),` `,u(`channels.qrLoginReauth`)]})]}),(0,A.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 bg-dark-bg/50 border-t border-dark-border`,children:[(0,A.jsx)(`div`,{children:i&&c&&(0,A.jsxs)(`button`,{onClick:c,className:`flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-red hover:bg-accent-red/15 transition-colors`,children:[(0,A.jsx)(m,{className:`w-3.5 h-3.5`}),` `,u(`channels.actions.delete`)]})}),(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm text-dark-muted hover:text-dark-text transition-colors`,children:u(`channels.actions.cancel`)}),(0,A.jsx)(v,{variant:`accent`,onClick:o,loading:r,disabled:!e.name.trim(),leftIcon:(0,A.jsx)(n,{className:`w-3.5 h-3.5`}),children:u(`channels.save`)})]})]})]})}function H({label:e,required:t,children:n}){return(0,A.jsxs)(`div`,{children:[(0,A.jsxs)(`label`,{className:`block text-xs text-dark-muted mb-1.5`,children:[e,t&&(0,A.jsx)(`span`,{className:`text-accent-red ms-0.5`,children:`*`})]}),n]})}var U=`w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue transition-colors`,W=t(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),G=t((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),K=t((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),q=t(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),J=t(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),ne=t((e=>{var t=G().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),re=t((e=>{var t=G().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),ie=t((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),Y=t((e=>{var t=K(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),ae=t((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),oe=t((e=>{var t=ae();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),se=t(((e,t)=>{var n=oe();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),X=t((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),Z=t((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
6
+ ]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^[0-9]+$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),Q=t((e=>{var t=X(),n=Z();e.NUMERIC={id:`Numeric`,bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:`Alphanumeric`,bit:2,ccBits:[9,11,13]},e.BYTE={id:`Byte`,bit:4,ccBits:[8,16,16]},e.KANJI={id:`Kanji`,bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw Error(`Invalid mode: `+e);if(!t.isValid(n))throw Error(`Invalid version: `+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw Error(`Invalid mode`)},e.isValid=function(e){return e&&e.bit&&e.ccBits};function r(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`numeric`:return e.NUMERIC;case`alphanumeric`:return e.ALPHANUMERIC;case`kanji`:return e.KANJI;case`byte`:return e.BYTE;default:throw Error(`Unknown mode: `+t)}}e.from=function(t,n){if(e.isValid(t))return t;try{return r(t)}catch{return n}}})),ce=t((e=>{var t=G(),n=Y(),r=K(),i=Q(),a=X(),o=7973,s=t.getBCHDigit(o);function c(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}function l(e,t){return i.getCharCountIndicator(e,t)+4}function u(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}function d(t,n){for(let r=1;r<=40;r++)if(u(t,r)<=e.getCapacity(r,n,i.MIXED))return r}e.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,o){if(!a.isValid(e))throw Error(`Invalid QR Code version`);o===void 0&&(o=i.BYTE);let s=(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r))*8;if(o===i.MIXED)return s;let c=s-l(o,e);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(e,t){let n,i=r.from(t,r.M);if(Array.isArray(e)){if(e.length>1)return d(e,i);if(e.length===0)return 1;n=e[0]}else n=e;return c(n.mode,n.getLength(),i)},e.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error(`Invalid QR Code version`);let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=o<<t.getBCHDigit(n)-s;return e<<12|n}})),le=t((e=>{var t=G(),n=1335,r=21522,i=t.getBCHDigit(n);e.getEncodedBits=function(e,a){let o=e.bit<<3|a,s=o<<10;for(;t.getBCHDigit(s)-i>=0;)s^=n<<t.getBCHDigit(s)-i;return(o<<10|s)^r}})),ue=t(((e,t)=>{var n=Q();function r(e){this.mode=n.NUMERIC,this.data=e.toString()}r.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);let i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,i*3+1))},t.exports=r})),de=t(((e,t)=>{var n=Q(),r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function i(e){this.mode=n.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t=0;for(;t+2<=this.data.length;t+=2){let n=r.indexOf(this.data[t])*45;n+=r.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(r.indexOf(this.data[t]),6)},t.exports=i})),fe=t(((e,t)=>{var n=Q();function r(e){this.mode=n.BYTE,this.data=typeof e==`string`?new TextEncoder().encode(e):new Uint8Array(e)}r.getBitsLength=function(e){return e*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},t.exports=r})),pe=t(((e,t)=>{var n=Q(),r=G();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t=0;for(;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
7
+ Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),me=t(((e,t)=>{var n={single_source_shortest_paths:function(e,t,r){var i={},a={};a[t]=0;var o=n.PriorityQueue.make();o.push(t,0);for(var s,c,l,u,d,f,p,m,h;!o.empty();)for(l in s=o.pop(),c=s.value,u=s.cost,d=e[c]||{},d)d.hasOwnProperty(l)&&(f=d[l],p=u+f,m=a[l],h=a[l]===void 0,(h||m>p)&&(a[l]=p,o.push(l,p),i[l]=c));if(r!==void 0&&a[r]===void 0){var g=[`Could not find a path from `,t,` to `,r,`.`].join(``);throw Error(g)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,r){var i=n.single_source_shortest_paths(e,t,r);return n.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var t=n.PriorityQueue,r={},i;for(i in e||={},t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r.queue=[],r.sorter=e.sorter||t.default_sorter,r},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t!==void 0&&(t.exports=n)})),he=t((e=>{var t=Q(),n=ue(),r=de(),i=fe(),a=pe(),o=Z(),s=G(),c=me();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
8
+ Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),ge=t((e=>{var t=G(),n=K(),r=q(),i=J(),a=ne(),o=re(),s=ie(),c=Y(),l=se(),u=ce(),d=le(),f=Q(),p=he();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function _(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function v(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function y(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function b(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return x(a,e,n)}function x(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function S(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
9
+ The chosen QR Code version cannot contain this amount of data.
10
+ Minimum version required to store current data is: `+c+`.
11
+ `);let l=b(n,r,o),d=new i(t.getSymbolSize(n));return m(d,n),h(d),g(d,n),v(d,r,0),n>=7&&_(d,n),y(d,l),isNaN(a)&&(a=s.getBestMask(d,v.bind(null,d,r))),s.applyMask(a,d),v(d,r,a),{modules:d,version:n,errorCorrectionLevel:r,maskPattern:a,segments:o}}e.create=function(e,r){if(e===void 0||e===``)throw Error(`No input text`);let i=n.M,a,o;return r!==void 0&&(i=n.from(r.errorCorrectionLevel,n.M),a=u.from(r.version),o=s.from(r.maskPattern),r.toSJISFunc&&t.setToSJISFunction(r.toSJISFunc)),S(e,a,i,o)}})),$=t((e=>{function t(e){if(typeof e==`number`&&(e=e.toString()),typeof e!=`string`)throw Error(`Color should be defined as hex string`);let t=e.slice().replace(`#`,``).split(``);if(t.length<3||t.length===5||t.length>8)throw Error(`Invalid hex color: `+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),t.length===6&&t.push(`F`,`F`);let n=parseInt(t.join(``),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:`#`+t.slice(0,6).join(``)}}e.getOptions=function(e){e||={},e.color||(e.color={});let n=e.margin===void 0||e.margin===null||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:t(e.color.dark||`#000000ff`),light:t(e.color.light||`#ffffffff`)},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+t.margin*2?t.width/(e+t.margin*2):t.scale},e.getImageWidth=function(t,n){let r=e.getScale(t,n);return Math.floor((t+n.margin*2)*r)},e.qrToImageData=function(t,n,r){let i=n.modules.size,a=n.modules.data,o=e.getScale(i,r),s=Math.floor((i+r.margin*2)*o),c=r.margin*o,l=[r.color.light,r.color.dark];for(let e=0;e<s;e++)for(let n=0;n<s;n++){let u=(e*s+n)*4,d=r.color.light;if(e>=c&&n>=c&&e<s-c&&n<s-c){let t=Math.floor((e-c)/o),r=Math.floor((n-c)/o);d=l[+!!a[t*i+r]]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}})),_e=t((e=>{var t=$();function n(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||={},t.height=n,t.width=n,t.style.height=n+`px`,t.style.width=n+`px`}function r(){try{return document.createElement(`canvas`)}catch{throw Error(`You need to specify a canvas element`)}}e.render=function(e,i,a){let o=a,s=i;o!==void 0||i&&i.getContext||(o=i,i=void 0),i||(s=r()),o=t.getOptions(o);let c=t.getImageWidth(e.modules.size,o),l=s.getContext(`2d`),u=l.createImageData(c,c);return t.qrToImageData(u.data,e,o),n(l,s,c),l.putImageData(u,0,0),s},e.renderToDataURL=function(t,n,r){let i=r;i!==void 0||n&&n.getContext||(i=n,n=void 0),i||={};let a=e.render(t,n,i),o=i.type||`image/png`,s=i.rendererOpts||{};return a.toDataURL(o,s.quality)}})),ve=t((e=>{var t=$();function n(e,t){let n=e.a/255,r=t+`="`+e.hex+`"`;return n<1?r+` `+t+`-opacity="`+n.toFixed(2).slice(1)+`"`:r}function r(e,t,n){let r=e+t;return n!==void 0&&(r+=` `+n),r}function i(e,t,n){let i=``,a=0,o=!1,s=0;for(let c=0;c<e.length;c++){let l=Math.floor(c%t),u=Math.floor(c/t);!l&&!o&&(o=!0),e[c]?(s++,c>0&&l>0&&e[c-1]||(i+=o?r(`M`,l+n,.5+u+n):r(`m`,a,0),a=0,o=!1),l+1<t&&e[c+1]||(i+=r(`h`,s),s=0)):a++}return i}e.render=function(e,r,a){let o=t.getOptions(r),s=e.modules.size,c=e.modules.data,l=s+o.margin*2,u=o.color.light.a?`<path `+n(o.color.light,`fill`)+` d="M0 0h`+l+`v`+l+`H0z"/>`:``,d=`<path `+n(o.color.dark,`stroke`)+` d="`+i(c,s,o.margin)+`"/>`,f=`viewBox="0 0 `+l+` `+l+`"`,p=`<svg xmlns="http://www.w3.org/2000/svg" `+(o.width?`width="`+o.width+`" height="`+o.width+`" `:``)+f+` shape-rendering="crispEdges">`+u+d+`</svg>
12
+ `;return typeof a==`function`&&a(null,p),p}})),ye=e(t((e=>{var t=W(),n=ge(),r=_e(),i=ve();function a(e,r,i,a,o){let s=[].slice.call(arguments,1),c=s.length,l=typeof s[c-1]==`function`;if(!l&&!t())throw Error(`Callback required as last argument`);if(l){if(c<2)throw Error(`Too few arguments provided`);c===2?(o=i,i=r,r=a=void 0):c===3&&(r.getContext&&o===void 0?(o=a,a=void 0):(o=a,a=i,i=r,r=void 0))}else{if(c<1)throw Error(`Too few arguments provided`);return c===1?(i=r,r=a=void 0):c===2&&!r.getContext&&(a=i,i=r,r=void 0),new Promise(function(t,o){try{t(e(n.create(i,a),r,a))}catch(e){o(e)}})}try{let t=n.create(i,a);o(null,e(t,r,a))}catch(e){o(e)}}e.create=n.create,e.toCanvas=a.bind(null,r.render),e.toDataURL=a.bind(null,r.renderToDataURL),e.toString=a.bind(null,function(e,t,n){return i.render(e,n)})}))(),1),be=2e3,xe=5;function Se({channel:e,onClose:t}){let{t:n}=g(),[r,i]=(0,k.useState)(`loading`),[a,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(null),[l,u]=(0,k.useState)(``),d=(0,k.useRef)(null),f=(0,k.useRef)(0),p=(0,k.useRef)(null),m=(0,k.useRef)(!1),h=()=>{p.current&&=(clearTimeout(p.current),null),m.current=!0},v=async e=>{if(d.current)try{await ye.toCanvas(d.current,e,{width:240,margin:2,color:{dark:`#000000ff`,light:`#ffffffff`}})}catch(e){console.warn(`[WechatQr] Canvas QR generation failed, falling back to URL:`,e)}},b=async()=>{if(!m.current&&s)try{let r=await y.channels.weixin.bindStatus(s),a=r?.data??r,o=a?.status??``;if(f.current=0,o===`confirmed`){if(!a?.channel_id){i(`error`),u(n(`channels.bindNoInstance`)),_.error(n(`channels.bindNoInstance`));return}i(`confirmed`),_.success(e?n(`channels.toastReauthSuccess`,{name:e.name}):n(`channels.toastBindSuccess`)),setTimeout(t,2400);return}if(o===`scaned`)i(`scanned`);else if(o===`expired`){i(`expired`);return}m.current||(p.current=setTimeout(b,be))}catch(e){if(f.current++,console.warn(`[WechatQr] poll error (`+f.current+`/5)`,e),f.current>=xe)i(`error`),u(n(`channels.pollFailedRefresh`)),_.error(n(`channels.pollFailedToast`));else if(!m.current){let e=Math.min(1e3*2**f.current,1e4);p.current=setTimeout(b,e)}}},S=()=>{h(),m.current=!1,f.current=0,p.current=setTimeout(b,1e3)},C=async()=>{i(`loading`),o(null),c(null),u(``),f.current=0;try{let e=await y.channels.weixin.bind(),t=e?.data??e,r=t?.qrcode_img_content??``,a=t?.qrcode??``;if(!r||!a){i(`error`),u(n(`channels.qrDataMissing`,{data:JSON.stringify(t)}));return}o(r),c(a),await v(r),i(`waiting`)}catch(e){i(`error`);let t=String(e?.message??e);u(t),_.error(n(`channels.fetchWechatQrFailed`,{error:t}))}},w=()=>{C()};return(0,k.useEffect)(()=>(C(),h),[]),(0,k.useEffect)(()=>(s&&S(),h),[s]),(0,A.jsx)(x,{isOpen:!0,onClose:t,title:n(`channels.bindTitle`,{name:e?.name??n(`channels.typeLabels.wechat`)}),size:`sm`,children:(0,A.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-2`,children:[(0,A.jsxs)(`div`,{className:`relative w-60 h-60 rounded-lg bg-white flex items-center justify-center overflow-hidden`,children:[r===`loading`&&(0,A.jsx)(`span`,{className:`text-dark-muted text-sm`,children:n(`channels.qr.generating`)}),r!==`error`&&r!==`expired`&&(0,A.jsx)(`canvas`,{ref:d,width:240,height:240,className:`w-full h-full object-contain ${r===`waiting`?``:`opacity-30`}`}),r===`scanned`&&(0,A.jsxs)(`div`,{className:`absolute inset-0 bg-black/70 flex flex-col items-center justify-center text-overlay-fg gap-1`,children:[(0,A.jsx)(`span`,{className:`text-2xl`,children:`✓`}),(0,A.jsx)(`span`,{className:`text-sm`,children:n(`channels.qr.scanned`)})]}),r===`confirmed`&&(0,A.jsxs)(`div`,{className:`absolute inset-0 bg-accent-green/15 flex flex-col items-center justify-center text-accent-fg gap-2 px-4 text-center`,children:[(0,A.jsx)(`span`,{className:`text-2xl`,children:`🎉`}),(0,A.jsx)(`span`,{className:`text-sm font-medium`,children:n(`channels.bindSuccess`)}),(0,A.jsx)(`span`,{className:`text-xs opacity-90`,children:e?n(`channels.connectedReady`,{name:e.name}):n(`channels.createdConnectedReady`)}),(0,A.jsx)(`button`,{onClick:t,className:`mt-1 text-xs bg-white/20 hover:bg-white/30 px-3 py-1.5 rounded-md transition-colors`,children:n(`channels.startUsing`)})]}),r===`expired`&&(0,A.jsxs)(`div`,{className:`absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-overlay-fg gap-2`,children:[(0,A.jsx)(`span`,{className:`text-sm`,children:n(`channels.qr.expired`)}),(0,A.jsx)(`button`,{onClick:w,className:`text-xs bg-accent-green hover:bg-accent-green px-3 py-1 rounded`,children:n(`channels.clickToRefresh`)})]}),r===`error`&&(0,A.jsxs)(`div`,{className:`absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-accent-red gap-2 px-4 text-center`,children:[(0,A.jsx)(`span`,{className:`text-xs`,children:l||n(`channels.unknownError`)}),(0,A.jsx)(`button`,{onClick:w,className:`text-xs bg-accent-blue hover:bg-accent-blue px-3 py-1 rounded text-accent-fg`,children:n(`channels.retry`)})]})]}),(0,A.jsxs)(`p`,{className:`text-sm text-dark-muted text-center`,children:[r===`waiting`&&n(`channels.waitingAuthorize`),r===`scanned`&&n(`channels.scannedConfirming`),r===`confirmed`&&n(`channels.confirmedClosing`),r===`loading`&&n(`channels.connectingIlink`),(r===`expired`||r===`error`)&&(r===`expired`?n(`channels.qr.expired`):``)]}),a&&r===`waiting`&&(0,A.jsxs)(`button`,{onClick:()=>window.open(a,`_blank`,`width=480,height=600,noopener`),className:`w-full flex items-center justify-center gap-2 text-sm bg-accent-green/15 hover:bg-accent-green/15 text-accent-green border border-accent-green px-3 py-2.5 rounded-lg transition-colors`,children:[(0,A.jsx)(`span`,{children:`🔔`}),` `,n(`channels.openInNewTabFallback`)]})]})})}function Ce(){let{t:e}=g(),{load:t,loading:n,qrOpen:r,qrChannel:i,closeQr:a}=D();return(0,k.useEffect)(()=>{t()},[]),(0,A.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-dark-bg text-dark-text`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-dark-border shrink-0`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h2`,{className:`font-semibold text-base`,children:e(`channels.title`)}),(0,A.jsx)(`p`,{className:`text-xs text-dark-muted mt-0.5`,children:e(`channels.viewSubtitle`)})]}),(0,A.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,A.jsx)(`button`,{onClick:()=>t(),title:e(`channels.actions.refresh`),className:`p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors`,children:(0,A.jsx)(l,{className:`w-4 h-4 ${n?`animate-spin`:``}`})})})]}),(0,A.jsxs)(`div`,{className:`flex-1 flex min-h-0 overflow-hidden max-md:flex-col`,children:[(0,A.jsx)(`div`,{className:`w-[260px] shrink-0 max-md:w-full max-md:max-h-[30vh] max-md:overflow-y-auto custom-scrollbar`,children:(0,A.jsx)(M,{})}),(0,A.jsx)(`div`,{className:`flex-1 min-w-0 max-md:min-h-0`,children:(0,A.jsx)(V,{})})]}),r&&(0,A.jsx)(Se,{channel:i,onClose:a})]})}export{Ce as ChannelConfigView};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,Ar as n,Er as r,Kt as i,Nt as a,Or as o,Vt as s,g as c,gn as l,it as u,kr as d,n as f,ni as p,v as ee}from"./icons-B8Ngx6rM.js";import{t as m}from"./useTranslation-gGKZZfux.js";import{i as h,r as g}from"./Button-D-g7PgYh.js";import{l as te}from"./DiffPreview-D8tIj_aF.js";import{t as _}from"./api-ZQf0Ys8y.js";import{I as v}from"./markdown-Cps-36Z5.js";import{$ as y,Q as b,X as x,Z as S,et as C,ft as w,ht as ne,it as T,mt as re,nt as E,pt as ie,rt as ae,tt as D,wt as oe,xt as O}from"./index-STsyoFCk.js";var k=e(p(),1),A=v(),j=[];function M(e){let t=[];return e.query?t.push(e.query):e.connector&&t.push(e.connector),e.detail&&t.push(e.detail),t.join(` — `)}function se({onApproved:e,refreshToken:t=0}){let{t:n}=m(),[a,s]=(0,k.useState)(j),[l,u]=(0,k.useState)(!0),[p,ee]=(0,k.useState)(!0),[h,v]=(0,k.useState)(null),[y,b]=(0,k.useState)(null),x=(0,k.useCallback)(async()=>{u(!0);try{let e=await _.pendingArtifacts.list(`pending`);if(!e?.success)throw Error(e?.error||n(`charts.pending.loadFailed`));s(e.data?.items??j),b(null)}catch(e){b(e instanceof Error?e.message:String(e))}finally{u(!1)}},[n]);(0,k.useEffect)(()=>{x()},[x,t]);let S=(0,k.useCallback)(async(t,r)=>{v(t),b(null);try{let i=r===`approve`?await _.pendingArtifacts.approve(t):await _.pendingArtifacts.reject(t);if(!i?.success)throw Error(i?.error||n(`charts.pending.decideFailed`));s(e=>e.filter(e=>e.id!==t)),r===`approve`&&e?.(),x()}catch(e){b(e instanceof Error?e.message:String(e))}finally{v(null)}},[e,x,n]);return l&&a.length===0||a.length===0&&!y?null:(0,A.jsxs)(`div`,{"data-testid":`pending-artifacts`,className:`mx-4 mt-3 shrink-0 rounded-lg border border-accent-yellow/40 bg-accent-yellow/5`,children:[(0,A.jsxs)(`button`,{type:`button`,"data-testid":`pending-artifacts-toggle`,onClick:()=>ee(e=>!e),"aria-expanded":p,className:`flex w-full items-center gap-2 px-3 py-2 text-start`,children:[(0,A.jsx)(p?o:r,{size:13,className:`shrink-0 text-accent-yellow`}),(0,A.jsx)(`span`,{className:`shrink-0 text-xs font-medium text-accent-yellow`,children:n(`charts.pending.title`,{n:a.length})}),(0,A.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-badge text-dark-muted`,children:n(`charts.pending.subtitle`)}),l&&(0,A.jsx)(i,{size:12,className:`animate-spin text-dark-muted`})]}),p&&(0,A.jsxs)(`div`,{className:`border-t border-accent-yellow/20`,children:[y&&(0,A.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-2 text-xs text-accent-red`,children:[(0,A.jsx)(c,{size:13,className:`mt-0.5 shrink-0`}),(0,A.jsx)(`span`,{className:`min-w-0 break-words`,children:y})]}),a.map(e=>{let t=h===e.id;return(0,A.jsxs)(`div`,{"data-testid":`pending-artifact-item`,className:`flex items-start gap-2.5 border-b border-accent-yellow/15 px-3 py-2 last:border-b-0`,children:[(0,A.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,A.jsx)(`p`,{className:`text-xs leading-relaxed text-dark-text`,children:e.summary}),(0,A.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-badge text-dark-muted/80`,children:[(0,A.jsx)(`span`,{className:`truncate font-mono`,children:e.targetPath}),(0,A.jsx)(`span`,{className:`shrink-0 rounded bg-dark-hover px-1 py-px`,children:e.artifactType}),(0,A.jsx)(`span`,{className:`shrink-0`,children:te(e.createdAt,Date.now(),n)})]}),e.sources.length>0?(0,A.jsx)(`ul`,{className:`mt-1 space-y-0.5`,"data-testid":`pending-artifact-sources`,children:e.sources.map((t,n)=>(0,A.jsx)(`li`,{className:`truncate font-mono text-badge text-dark-muted/70`,title:M(t),children:M(t)},`${e.id}-src-${n}`))}):(0,A.jsx)(`p`,{className:`mt-1 text-badge text-accent-yellow/80`,children:n(`charts.pending.noSources`)})]}),(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,A.jsxs)(`button`,{type:`button`,"data-testid":`pending-artifact-approve`,disabled:t,onClick:()=>void S(e.id,`approve`),title:n(`charts.pending.approveHint`),className:g(`flex items-center gap-1 rounded-md border border-accent-green/40 bg-accent-green/10 px-2 py-1 text-badge text-accent-green transition-colors hover:bg-accent-green/20`,t&&`opacity-60`),children:[t?(0,A.jsx)(i,{size:11,className:`animate-spin`}):(0,A.jsx)(d,{size:11}),n(`charts.pending.approve`)]}),(0,A.jsxs)(`button`,{type:`button`,"data-testid":`pending-artifact-reject`,disabled:t,onClick:()=>void S(e.id,`reject`),title:n(`charts.pending.rejectHint`),className:g(`flex items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-badge text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,t&&`opacity-60`),children:[(0,A.jsx)(f,{size:11}),n(`charts.pending.reject`)]})]})]},e.id)})]})]})}var N=`dsc.charts.artifactOrder`,P=1;function ce(){try{let e=localStorage.getItem(N);if(!e)return[];let t=JSON.parse(e);if(typeof t!=`object`||!t)return[];let n=t;return n.v!==P||!Array.isArray(n.order)?[]:n.order.filter(e=>typeof e==`string`&&e!==``)}catch{return[]}}function F(e){try{localStorage.setItem(N,JSON.stringify({v:P,order:e}))}catch{}}function le(e,t,n){if(t.length===0)return[...e];let r=new Map(e.map(e=>[n(e),e])),i=[];for(let e of t){let t=r.get(e);t!==void 0&&(i.push(t),r.delete(e))}for(let t of e)r.has(n(t))&&i.push(t);return i}function ue(e,t,n,r){return T(e,t,n,r)}function de(e,t){let n=e.filter(e=>t.has(e));return F(n),n}function I(e,t){return e.version===t.version?e.createdAt>t.createdAt:e.version>t.version}function fe(e){let t=new Map;for(let n of e){let e=n.locator?.path;if(!e)continue;let r=O({type:n.type,workspaceDir:n.workspaceDir,path:e})||n.logicalId,i=t.get(r);(!i||I(n,i))&&t.set(r,n)}return[...t.values()].sort((e,t)=>e.createdAt===t.createdAt?0:e.createdAt<t.createdAt?1:-1)}var pe=[`list`,`tabs`],L=`dsc.charts.displayMode`;function me(){try{return localStorage.getItem(L)===`tabs`?`tabs`:`list`}catch{return`list`}}function he(e){try{localStorage.setItem(L,e)}catch{}}var R=[],ge=[{command:`dashboard`,hintKey:`chat.visualArtifactsEmptyHint_dashboard`},{command:`analysis`,hintKey:`chat.visualArtifactsEmptyHint_analysis`},{command:`motion`,hintKey:`chat.visualArtifactsEmptyHint_motion`}];function z({text:e,path:n}){let{t:r}=m(),i=(0,k.useCallback)(()=>{w(r(`charts.askAiPrompt`,{path:n||`—`,error:e})),h.info(r(`charts.askAiHint`))},[n,r,e]);return(0,A.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-accent-red/30 bg-accent-red/5 px-3 py-2.5 text-xs text-accent-red`,children:[(0,A.jsx)(c,{size:14,className:`mt-0.5 shrink-0`}),(0,A.jsx)(`span`,{className:`min-w-0 break-words`,children:e}),(0,A.jsxs)(`button`,{type:`button`,"data-testid":`charts-error-ask-ai`,onClick:i,title:r(`charts.askAi`),className:`ml-auto flex shrink-0 items-center gap-1 rounded-md border border-accent-red/40 px-2 py-0.5 text-[11px] font-medium text-accent-red transition-colors hover:bg-accent-red/10`,children:[(0,A.jsx)(t,{size:11,"aria-hidden":`true`}),r(`charts.askAi`)]})]})}function B({path:e,content:t,readError:n,freshness:r}){let{t:i}=m();if(n)return(0,A.jsx)(z,{text:n,path:e});let a=C(e);return a===`motion`?(0,A.jsx)(b,{path:e,content:t}):a===`dashboard`?(0,A.jsx)(E,{path:e,content:t,freshness:r}):a===`analysis`?(0,A.jsx)(D,{path:e,content:t}):a===`world`?(0,A.jsx)(y,{path:e,content:t}):a===`holo`?(0,A.jsx)(S,{path:e,content:t}):(0,A.jsxs)(`div`,{"data-testid":`charts-no-renderer`,className:`px-1 py-2 text-xs leading-relaxed text-dark-muted`,children:[i(`charts.noRenderer`),(0,A.jsx)(`span`,{className:`mt-1 block truncate font-mono text-badge text-dark-muted/70`,children:e})]})}function _e({records:e,activePath:t,onSelect:n,nameOf:r}){return(0,A.jsx)(`div`,{"data-testid":`charts-tabs`,role:`tablist`,className:`flex shrink-0 items-center gap-1 overflow-x-auto rounded-lg border border-dark-border bg-dark-surface p-1`,children:e.map(e=>{let i=e.locator.path,a=i===t;return(0,A.jsxs)(`button`,{type:`button`,role:`tab`,"data-testid":`charts-tab`,"aria-selected":a,"aria-current":a,title:`${i}\n${e.producer.sessionId}`,onClick:()=>n(i),className:g(`flex max-w-[14rem] shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs transition-colors`,a?`bg-accent-blue/15 text-accent-blue`:`text-dark-muted hover:bg-dark-hover hover:text-dark-text`),children:[(0,A.jsx)(x,{kind:C(i),size:13}),(0,A.jsx)(`span`,{className:`min-w-0 truncate`,children:r(e)}),(0,A.jsxs)(`span`,{className:`shrink-0 text-badge opacity-60`,children:[`v`,e.version]})]},e.logicalId)})})}function V(){let{t:e}=m(),[r,o]=(0,k.useState)(R),[c,d]=(0,k.useState)(!0),[f,p]=(0,k.useState)(null),[h,v]=(0,k.useState)(0),[y,b]=(0,k.useState)([]),[S,T]=(0,k.useState)(null),[E,D]=(0,k.useState)(null),[O,j]=(0,k.useState)(!1),[M,N]=(0,k.useState)(null),[P,F]=(0,k.useState)(null),[I,L]=(0,k.useState)(()=>ce()),[V,H]=(0,k.useState)(null),[U,ve]=(0,k.useState)(()=>me()),ye=(0,k.useCallback)(e=>{e!==U&&(ve(e),he(e),H(null),W(null))},[U]),[be,W]=(0,k.useState)(null),[xe,Se]=(0,k.useState)(!1),Ce=oe(e=>e.publishedSeq),G=(0,k.useCallback)(async t=>{t?.silent||d(!0),p(null);try{let t=await _.visualArtifacts.list();if(!t?.success)throw Error(t?.error||e(`charts.loadFailed`));o(fe(t.data?.items??R))}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}},[e]),K=(0,k.useCallback)(async()=>{try{let e=await _.visualArtifacts.builtins();if(!e?.success)return;b((e.data?.items??[]).filter(e=>!e.installed).map(e=>({id:e.id,kind:e.kind,title:e.title})))}catch{}},[]),we=(0,k.useCallback)(async e=>{T(e);try{let t=await _.visualArtifacts.installBuiltin(e);if(!t?.success)throw Error(t?.error||`install failed`);await Promise.all([K(),G({silent:!0})])}catch(e){p(e instanceof Error?e.message:String(e))}finally{T(null)}},[G,K]);(0,k.useEffect)(()=>{K()},[K]),(0,k.useEffect)(()=>{G()},[G]),(0,k.useEffect)(()=>{Ce!==0&&G({silent:!0})},[Ce,G]);let q=(0,k.useMemo)(()=>le(r,I,e=>e.logicalId),[r,I]),Te=(0,k.useMemo)(()=>new Set(r.map(e=>e.logicalId)),[r]),J=(0,k.useCallback)(e=>{L(de(e,Te))},[Te]),Ee=(0,k.useCallback)(async t=>{Se(!0),W(null);try{let n=await _.visualArtifacts.remove(t);if(!n?.success)throw Error(n?.error||e(`charts.removeFailed`));o(e=>e.filter(e=>e.logicalId!==t)),J(I.filter(e=>e!==t)),H(null)}catch(e){W(e instanceof Error?e.message:String(e))}finally{Se(!1)}},[J,I,e]),De=(0,k.useCallback)((e,t)=>{let n=q.map(e=>e.logicalId),r=ue(n,e,t.id,t.side);r.join()!==n.join()&&J(r)},[J,q]),Y=ae(De,{vertical:!0}),Oe=(0,k.useCallback)((e,t)=>{let n=q.map(e=>e.logicalId),r=n.indexOf(e);if(r<0)return;let i=n[r+t];i&&J(ue(n,e,i,t<0?`before`:`after`))},[J,q]),X=(0,k.useMemo)(()=>E&&r.some(e=>e.locator.path===E)?E:q[0]?.locator.path??null,[q,r,E]),Z=(0,k.useMemo)(()=>r.find(e=>e.locator.path===X)??null,[r,X]),ke=Z?.exists===!1;(0,k.useEffect)(()=>{if(!X){N(null),F(null);return}if(ke){N(null),F(e(`charts.fileMissing`));return}let t=!1;return N(null),F(null),(async()=>{try{let n=await _.visualArtifacts.content(X);if(t)return;n.success&&n.data!==void 0&&n.data!==null?N(String(n.data)):F(n.error||e(`charts.readFailed`))}catch(e){t||F(e instanceof Error?e.message:String(e))}})(),()=>{t=!0}},[X,ke,e]),(0,k.useEffect)(()=>{if(!O)return;let e=e=>{e.key===`Escape`&&j(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O]);let Ae=(0,k.useMemo)(()=>r.map(e=>({path:e.locator.path??``,metadata:e.metadata,version:e.version})),[r]),je=ie(Ae),Q=e=>e.locator.path?je(e.locator.path):``,Me=Z?Q(Z):null,$=Y.draggingId?r.find(e=>e.logicalId===Y.draggingId)??null:null,Ne=Z?.locator.path===void 0?null:(0,A.jsx)(B,{path:Z.locator.path,content:M,readError:P,freshness:Z.freshness});return(0,A.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,A.jsxs)(`div`,{className:`flex shrink-0 items-start gap-3 px-4 pt-3`,children:[(0,A.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,A.jsxs)(`h1`,{className:`flex items-center gap-1.5 text-lg font-semibold text-dark-text`,children:[(0,A.jsx)(n,{size:16,className:`shrink-0 text-accent-blue`}),e(`charts.title`)]}),(0,A.jsx)(`p`,{className:`mt-0.5 text-xs leading-relaxed text-dark-muted`,children:e(`charts.subtitle`)})]}),(0,A.jsxs)(`div`,{className:`mt-0.5 flex shrink-0 items-center gap-2`,children:[(0,A.jsxs)(`button`,{type:`button`,"data-testid":`charts-create-with-ai`,onClick:()=>w(e(`charts.createWithAiPrompt`)),className:`flex shrink-0 items-center gap-1 rounded-md border border-accent-blue/40 bg-accent-blue/10 px-2 py-1 text-xs font-medium text-accent-blue transition-colors hover:bg-accent-blue/20`,title:e(`charts.createWithAiHint`),children:[(0,A.jsx)(t,{size:12}),e(`charts.createWithAi`)]}),r.length>0&&(0,A.jsx)(`div`,{"data-testid":`charts-display-switch`,role:`group`,"aria-label":e(`charts.displayMode`),className:`flex items-center gap-0.5 rounded-md border border-dark-border p-0.5`,children:pe.map(t=>(0,A.jsx)(`button`,{type:`button`,"data-testid":`charts-display-${t}`,"aria-pressed":U===t,onClick:()=>ye(t),className:g(`rounded px-2 py-0.5 text-badge transition-colors`,U===t?`bg-accent-blue/15 text-accent-blue`:`text-dark-muted hover:bg-dark-hover hover:text-dark-text`),children:e(t===`list`?`charts.viewList`:`charts.viewTabs`)},t))}),(0,A.jsxs)(`button`,{type:`button`,"data-testid":`charts-refresh`,onClick:()=>{G(),v(e=>e+1)},className:`flex shrink-0 items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-xs text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:e(`charts.refresh`),children:[c?(0,A.jsx)(i,{size:12,className:`animate-spin`}):(0,A.jsx)(u,{size:12}),e(`charts.refresh`)]})]})]}),f&&(0,A.jsx)(`div`,{className:`shrink-0 px-4 pt-2`,children:(0,A.jsx)(z,{text:f})}),(0,A.jsx)(se,{refreshToken:h,onApproved:()=>void G()}),(0,A.jsx)(`div`,{className:g(`flex min-h-0 flex-1 gap-3 p-4`,U===`tabs`?`flex-col`:``),children:r.length===0?(0,A.jsx)(`div`,{"data-testid":`charts-empty`,className:`flex min-h-0 flex-1 items-center justify-center rounded-lg border border-dashed border-dark-border px-6`,children:c?(0,A.jsx)(i,{size:18,className:`animate-spin text-accent-blue`}):(0,A.jsxs)(`div`,{className:`max-w-md space-y-2`,children:[(0,A.jsx)(`p`,{className:`text-xs leading-relaxed text-dark-muted`,children:e(`charts.empty`)}),(0,A.jsx)(`ul`,{className:`space-y-1`,children:ge.map(({command:t,hintKey:n})=>(0,A.jsxs)(`li`,{className:`flex items-baseline gap-1.5 text-badge text-dark-muted/80`,children:[(0,A.jsxs)(`code`,{className:`shrink-0 rounded bg-dark-hover px-1 py-px font-mono text-accent-blue`,children:[`/`,t]}),(0,A.jsx)(`span`,{className:`min-w-0`,children:e(n)})]},t))}),y.length>0&&(0,A.jsx)(`div`,{className:`flex flex-wrap gap-1.5 pt-1`,"data-testid":`charts-builtin-cards`,children:y.map(n=>(0,A.jsxs)(`button`,{type:`button`,disabled:S!==null,onClick:()=>void we(n.id),className:`inline-flex items-center gap-1 rounded border border-dark-border px-2 py-1 text-badge text-dark-muted transition-colors hover:border-accent-blue hover:text-accent-blue disabled:opacity-50`,children:[(0,A.jsx)(t,{size:11}),e(`charts.builtin.${n.id}.title`,{defaultValue:n.title})]},n.id))})]})}):(0,A.jsxs)(A.Fragment,{children:[U===`tabs`?(0,A.jsx)(_e,{records:q,activePath:X,onSelect:D,nameOf:Q}):(0,A.jsxs)(`aside`,{"data-testid":`charts-list`,className:`flex w-64 shrink-0 flex-col overflow-y-auto rounded-lg border border-dark-border bg-dark-surface`,children:[be&&(0,A.jsx)(`div`,{className:`border-b border-dark-border/60 p-1.5`,children:(0,A.jsx)(z,{text:`${e(`charts.removeFailed`)} — ${be}`})}),q.map(t=>{let n=t.locator.path,r=n===X,i=ne(t.type),a=i?e(i):t.type,o=Y.draggingId===t.logicalId,s=Y.dropTarget?.id===t.logicalId?Y.dropTarget.side:null,c=V===t.logicalId;return(0,A.jsxs)(`div`,{"data-panel-id":t.logicalId,"data-testid":`charts-item-row`,"data-dragging":o?`true`:`false`,"data-drop-side":s??void 0,onPointerDown:e=>Y.startFromCard(e,t.logicalId),onPointerMove:Y.onPointerMove,onPointerUp:Y.onPointerUp,onPointerCancel:Y.onPointerCancel,className:g(`flex items-stretch border-b border-dark-border/60 transition-colors`,r?`bg-accent-blue/10`:`hover:bg-dark-hover`,o&&`opacity-40`,s===`before`&&`shadow-[inset_0_2px_0_0_theme(colors.accent-blue)]`,s===`after`&&`shadow-[inset_0_-2px_0_0_theme(colors.accent-blue)]`),children:[(0,A.jsx)(`button`,{type:`button`,"data-testid":`charts-item-grab`,"aria-label":e(`charts.dragHandle`),title:e(`charts.dragHandle`),onPointerDown:e=>Y.startFromGrip(e,t.logicalId),onKeyDown:e=>{let n=e.key===`ArrowUp`,r=e.key===`ArrowDown`;(n||r)&&(e.preventDefault(),Oe(t.logicalId,n?-1:1))},style:{touchAction:`none`},className:`flex shrink-0 cursor-grab items-center px-1 text-dark-tertiary transition-colors hover:text-dark-text active:cursor-grabbing`,children:(0,A.jsx)(l,{size:12})}),c?(0,A.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5 py-2 pe-2`,children:[(0,A.jsx)(`span`,{className:`min-w-0 flex-1 text-badge leading-snug text-amber-300`,children:e(`charts.removeConfirm`)}),(0,A.jsx)(`button`,{type:`button`,"data-testid":`charts-item-remove-confirm`,disabled:xe,onClick:()=>void Ee(t.logicalId),className:`shrink-0 rounded border border-accent-red/40 px-1.5 py-0.5 text-badge text-accent-red transition-colors hover:bg-accent-red/10 disabled:opacity-50`,children:e(`charts.remove`)}),(0,A.jsx)(`button`,{type:`button`,"data-testid":`charts-item-remove-cancel`,onClick:()=>H(null),className:`shrink-0 rounded border border-dark-border px-1.5 py-0.5 text-badge text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,children:e(`common.cancel`)})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`button`,{type:`button`,"data-testid":`charts-item`,"aria-current":r,onClick:()=>D(n),title:`${n}\n${t.producer.sessionId}`,className:`flex min-w-0 flex-1 items-center gap-2 py-2 pe-1 text-start`,children:[(0,A.jsx)(x,{kind:C(n),size:14}),(0,A.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,A.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,A.jsx)(`span`,{"data-testid":`charts-item-name`,className:g(`truncate text-xs`,r?`text-accent-blue`:`text-dark-text`),children:Q(t)}),(0,A.jsxs)(`span`,{className:`shrink-0 rounded bg-dark-hover px-1 py-px text-badge text-dark-muted`,children:[a,` v`,t.version]})]}),(0,A.jsxs)(`span`,{className:`mt-0.5 block truncate font-mono text-badge text-dark-muted/70`,children:[re(n),` · `,te(t.createdAt,Date.now(),e)]})]})]}),(0,A.jsx)(`button`,{type:`button`,"data-testid":`charts-item-remove`,onClick:()=>{W(null),H(t.logicalId)},title:e(`charts.removeHint`),"aria-label":e(`charts.removeHint`),className:`flex shrink-0 items-center px-1.5 text-dark-tertiary transition-colors hover:text-accent-red`,children:(0,A.jsx)(ee,{size:12})})]})]},t.logicalId)})]}),(0,A.jsxs)(`section`,{"data-testid":`charts-canvas`,className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-lg border border-dark-border bg-dark-surface`,children:[(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-dark-border px-3 py-1.5`,children:[(0,A.jsx)(`span`,{"data-testid":`charts-canvas-name`,className:`min-w-0 flex-1 truncate text-xs text-dark-text`,title:X??``,children:Me??X??``}),(0,A.jsx)(`button`,{type:`button`,"data-testid":`charts-fullscreen-toggle`,onClick:()=>j(!0),className:`shrink-0 rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:e(`charts.fullscreen`),"aria-label":e(`charts.fullscreen`),children:(0,A.jsx)(s,{size:13})})]}),(0,A.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:Ne})]})]})}),$&&(0,A.jsx)(`div`,{ref:Y.ghost.setElement,"data-testid":`charts-drag-ghost`,"aria-hidden":!0,className:`pointer-events-none fixed left-0 top-0 z-50 w-56 will-change-transform`,children:(0,A.jsxs)(`div`,{className:g(`flex w-full rotate-1 items-center gap-2 overflow-hidden rounded-lg border bg-dark-surface/95 px-2 py-1.5 shadow-pop`,Y.dropTarget?`border-accent-blue/70 ring-1 ring-accent-blue/30`:`border-dark-border`),children:[(0,A.jsx)(l,{size:12,className:`shrink-0 text-dark-muted`}),(0,A.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-dark-text`,children:Q($)})]})}),O&&Z?.locator.path!==void 0&&(0,A.jsxs)(`div`,{"data-testid":`charts-fullscreen`,className:`fixed inset-0 z-50 flex flex-col bg-dark-bg`,children:[(0,A.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-dark-border px-4 py-2`,children:[(0,A.jsx)(n,{size:14,className:`shrink-0 text-accent-blue`}),(0,A.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-dark-text`,title:Z.locator.path,children:Me??Z.locator.path}),(0,A.jsxs)(`button`,{type:`button`,onClick:()=>j(!1),className:`flex shrink-0 items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-xs text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text`,title:e(`charts.exitFullscreen`),children:[(0,A.jsx)(a,{size:12}),e(`charts.exitFullscreen`)]})]}),(0,A.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:(0,A.jsx)(B,{path:Z.locator.path,content:M,readError:P,freshness:Z.freshness})})]})]})}function H(){return(0,A.jsx)(`div`,{className:`flex h-full min-h-0 flex-col`,children:(0,A.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,A.jsx)(V,{})})})}export{H as ChartsView};