opencode-plugin-wecom 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 yee94
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # opencode-plugin-wecom
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/opencode-plugin-wecom.svg)](https://www.npmjs.com/package/opencode-plugin-wecom)
4
+ [![CI](https://github.com/yee94/yuri-plugins/actions/workflows/ci.yml/badge.svg)](https://github.com/yee94/yuri-plugins/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ 标准 OpenCode V2 插件(`@opencode/plugin`),为 OpenCode CLI / TUI 与 Yuri 桌面端提供**零客户端依赖**的企业微信(WeCom / 大圆)集成能力。
8
+
9
+ ## 核心特性
10
+
11
+ - **零桌面客户端依赖**:纯 HTTPS 协议实现,**不需要**在电脑上安装 WorkBuddy 客户端或企业微信桌面端,本机与远程 Linux 服务器均可直接运行。
12
+ - **Device Flow 风格扫码登录 + 自动静默续期**:获取官方扫码链接,用手机企业微信扫一次码后,凭据持久化到 OpenCode 原生 `storage`,后续自动在后台刷新并换取企微 `access_token`。
13
+ - **大圆 A2A 只读群聊查询**:基于白名单端点(`qyapi.weixin.qq.com/cgi-bin/a2a/api`)实现查群、读群聊摘要、搜消息摘要,内置:
14
+ - `request_id` 幂等回执与参数指纹冲突检测
15
+ - 终态结果本地缓存与 `401` / 过期错误码自动强制换票重试
16
+ - `input_required` 交互分类:放行纯文本澄清,**强制拦截敏感审批卡片(`approval`)并交由人工处理**
17
+ - **可选 `@wecom/cli` 结构化办公域桥接**:如果本机安装了官方 `@wecom/cli`,可直接查询文档、智能表格、日程、会议、邮件、微盘、通讯录(默认严格只读;未安装完全不影响大圆 A2A)。
18
+ - **Yuri / Desktop GUI 薄壳**:通过 `./gui-experimental` 提供中英文界面、顶栏连接状态 Pill、命令面板一键扫码与独立设置页,状态经 OpenCode RPC 实时同步。
19
+
20
+ ---
21
+
22
+ ## 安装与配置
23
+
24
+ 要求 Node.js `>= 22` 与 OpenCode V2(`@opencode/plugin` `^2.3.x`)。
25
+
26
+ 在 `~/.config/opencode/opencode.jsonc` 中添加插件:
27
+
28
+ ```jsonc
29
+ {
30
+ "plugins": [
31
+ "opencode-plugin-wecom"
32
+ ]
33
+ }
34
+ ```
35
+
36
+ ### 可选插件参数(`options`)
37
+
38
+ ```jsonc
39
+ {
40
+ "plugins": [
41
+ [
42
+ "opencode-plugin-wecom",
43
+ {
44
+ "enableCliTool": true,
45
+ "allowCliWrite": false,
46
+ "cliBinary": "wecom"
47
+ }
48
+ ]
49
+ ]
50
+ }
51
+ ```
52
+
53
+ | 参数 | 类型 | 默认值 | 说明 |
54
+ | --- | --- | --- | --- |
55
+ | `enableCliTool` | `boolean` | `true` | 是否注册可选的 `wecom_cli` 工具 |
56
+ | `allowCliWrite` | `boolean` | `false` | 是否允许 `wecom_cli` 执行写操作子命令(`create`/`update`/`delete`/`send` 等);默认严格只读 |
57
+ | `cliBinary` | `string` | `"wecom"` | 自定义 `@wecom/cli` 可执行文件路径 |
58
+
59
+ ---
60
+
61
+ ## 快速上手(扫码登录)
62
+
63
+ 1. 在 OpenCode 会话中运行 `/wecom-login`(或让 Agent 调用 `wecom_login({ mode: "start" })`;在 Yuri 桌面端也可从设置页或命令面板选择 **「企业微信:扫码登录」**)。
64
+ 2. 在浏览器打开返回的 `authorization_url`,用**手机企业微信**扫码确认。
65
+ 3. 调用 `wecom_login({ mode: "wait", wait_seconds: 60 })`(或在 Yuri 设置页点击 **「确认已扫码」**),插件将轮询登录态并自动换取企业微信 user token。
66
+ 4. 登录成功后,后续所有大圆 A2A 查询均可直接调用并自动后台续期。
67
+
68
+ > **关于首次企业授权(403)**:如果 WorkBuddy 登录成功但换票返回 `WECOM_AUTH_REQUIRED_OPEN_WECOM_LOGIN`,请在浏览器打开 `https://www.workbuddy.cn/login/wecom-auth`(或执行 `wecom_login({ mode: "wecom_auth" })`)完成企业微信应用授权后重试。
69
+
70
+ ---
71
+
72
+ ## 能力清单
73
+
74
+ ### 1. Tools(namespace: `wecom`,`codemode: true`)
75
+
76
+ | 工具名 | 作用 | 主要参数 |
77
+ | --- | --- | --- |
78
+ | `wecom_status` | 零网络请求检查登录态、企微 Token 就绪度、可选 `@wecom/cli` 状态及近期回执 | `include_receipts?: boolean` |
79
+ | `wecom_login` | 扫码登录全生命周期管理 | `mode: "start" \| "finish" \| "wait" \| "wecom_auth" \| "logout"`, `wait_seconds?: number` |
80
+ | `wecom_read_start` | 发起大圆 A2A 只读查询并返回摘要(`is_summary: true`) | `action: "search_groups" \| "read_chat" \| "search_messages"`, `query?`, `chat_name?`, `question?`, `time_range?`, `limit?`, `request_id?`, `wait_seconds?` |
81
+ | `wecom_read_result` | 按 `task_id` 轮询或读取本地缓存的终态结果 | `task_id: string`, `wait_seconds?: number` |
82
+ | `wecom_read_reply` | 对纯文本澄清类 `input_required` 任务回复澄清(审批卡片强制拒绝) | `task_id: string`, `text: string`, `request_id?`, `wait_seconds?` |
83
+ | `wecom_cli` | 可选 `@wecom/cli` 办公域只读桥接(`execFile` 无 Shell 插值) | `domain: "doc" \| "smartsheet" \| "calendar" \| "meeting" \| "mail" \| "wedrive" \| "contact" \| "auth"`, `args: string[]`, `timeout_ms?: number` |
84
+
85
+ ### 2. Slash Commands
86
+
87
+ - `/wecom-login`:生成并在会话中展示手机企业微信扫码链接
88
+ - `/wecom-status`:查看当前登录态、企微凭据状态与近期查询回执数
89
+ - `/wecom-logout`:清除 OpenCode 存储的 WorkBuddy 与企业微信凭据
90
+
91
+ ### 3. 内嵌 Skill
92
+
93
+ - `wecom-dayuan`:自动随插件注册,约束 Agent 遵守摘要边界(`is_summary: true`)、幂等 `request_id` 使用规范、以及遇到审批卡必须停下交由人工确认的护栏。
94
+
95
+ ### 4. RPC 契约(`opencode-plugin-wecom/rpc`)
96
+
97
+ 导出 `WecomRpc`(`id: "opencode-plugin-wecom"`),供 Yuri GUI / TUI 或其他插件调用:
98
+
99
+ - Methods:`status`、`startLogin`、`finishLogin`、`logout`、`recentReceipts`
100
+ - Events:`authChanged`(`{ phase, wecom_configured }`)
101
+
102
+ ---
103
+
104
+ ## 安全护栏与已知限制
105
+
106
+ 1. **只读摘要而非逐字原文**:大圆 A2A 返回的是 AI 总结后的群聊/消息摘要(结果对象固定带 `is_summary: true`),适合总结讨论要点与检索结论,不适合作为逐字原始日志取证。
107
+ 2. **严禁自动代批**:当任务进入 `input_required` 且包含 `wecom_part_type: "approval"` 或 `token_id_list` 时,插件会标记 `interaction_kind: "approval_required"`,并在 `wecom_read_reply` 中直接抛出 `APPROVAL_INTERACTION_BLOCKED`(零网络请求),提醒用户在手机企业微信手动审批。
108
+ 3. **一次性 `refresh_token` 防重放屏障**:发起续期请求前先持久化 `refresh_unknown` 屏障;若发生发送前网络错误(如 DNS 失败)会自动恢复可重试,若发生不确定中断则禁止自动重放,避免打废有效会话。
109
+ 4. **企业权限前提**:需要企业微信企业账号,且所在企业允许授权 WorkBuddy 应用。
110
+
111
+ ---
112
+
113
+ ## 本地开发与校验
114
+
115
+ 在仓库根目录执行:
116
+
117
+ ```sh
118
+ pnpm install
119
+ pnpm --filter opencode-plugin-wecom check
120
+ ```
121
+
122
+ `check` 会依次运行 Biome lint、TypeScript 类型检查(`tsc --noEmit`)、`tsdown` 打包(ESM + CJS GUI bundle)、Vitest 单元测试,以及 `node --check dist/gui-experimental.cjs`。
123
+
124
+ 本地联调时,可直接将绝对路径写入 `~/.config/opencode/opencode.jsonc`:
125
+
126
+ ```jsonc
127
+ {
128
+ "plugins": [
129
+ "/Users/yee.wang/Code/selfs/yuri-plugins/packages/opencode-plugin-wecom"
130
+ ]
131
+ }
132
+ ```
133
+
134
+ ## License
135
+
136
+ [MIT](LICENSE)
@@ -0,0 +1,460 @@
1
+ let __opencode_plugin_gui = require("@opencode/plugin/gui");
2
+ let solid_js = require("solid-js");
3
+ let __opencode_plugin_rpc = require("@opencode/plugin/rpc");
4
+
5
+ //#region src/rpc.ts
6
+ const PLUGIN_ID = "opencode-plugin-wecom";
7
+ const emptyObjectSchema = {
8
+ type: "object",
9
+ properties: {},
10
+ additionalProperties: false
11
+ };
12
+ const anyObjectSchema = {
13
+ type: "object",
14
+ additionalProperties: true
15
+ };
16
+ const WecomRpc = __opencode_plugin_rpc.Rpc.define({
17
+ id: PLUGIN_ID,
18
+ methods: {
19
+ status: {
20
+ input: emptyObjectSchema,
21
+ output: anyObjectSchema
22
+ },
23
+ startLogin: {
24
+ input: emptyObjectSchema,
25
+ output: {
26
+ type: "object",
27
+ properties: {
28
+ phase: { type: "string" },
29
+ authorization_url: { type: "string" }
30
+ },
31
+ required: ["phase", "authorization_url"]
32
+ }
33
+ },
34
+ finishLogin: {
35
+ input: {
36
+ type: "object",
37
+ properties: { wait_seconds: { type: "number" } },
38
+ additionalProperties: false
39
+ },
40
+ output: anyObjectSchema
41
+ },
42
+ logout: {
43
+ input: emptyObjectSchema,
44
+ output: anyObjectSchema
45
+ },
46
+ recentReceipts: {
47
+ input: {
48
+ type: "object",
49
+ properties: { limit: { type: "number" } },
50
+ additionalProperties: false
51
+ },
52
+ output: {
53
+ type: "object",
54
+ properties: { receipts: {
55
+ type: "array",
56
+ items: anyObjectSchema
57
+ } },
58
+ required: ["receipts"]
59
+ }
60
+ }
61
+ },
62
+ events: { authChanged: { schema: {
63
+ type: "object",
64
+ properties: {
65
+ phase: { type: "string" },
66
+ wecom_configured: { type: "boolean" }
67
+ },
68
+ required: ["phase", "wecom_configured"]
69
+ } } }
70
+ });
71
+
72
+ //#endregion
73
+ //#region src/gui.ts
74
+ function activeServer(ctx) {
75
+ const sessionServer = ctx.sessions.current()?.server;
76
+ if (sessionServer?.connected) return sessionServer;
77
+ for (const id of ctx.servers.list()) {
78
+ const ref = ctx.servers.get(id);
79
+ if (ref?.connected) return ref;
80
+ }
81
+ const firstId = ctx.servers.list()[0];
82
+ return firstId ? ctx.servers.get(firstId) : void 0;
83
+ }
84
+ var gui_default = __opencode_plugin_gui.Plugin.define({
85
+ i18n: {
86
+ en: {
87
+ title: "WeCom / Dayuan",
88
+ description: "Desktop-free Enterprise WeChat QR login and read-only Dayuan A2A chat summaries.",
89
+ "cmd.login": "WeCom: Sign in with QR code",
90
+ "cmd.login.desc": "Open WorkBuddy WeCom QR login in your browser (no desktop client needed).",
91
+ "cmd.settings": "WeCom: Open settings",
92
+ "section.connection": "Connection",
93
+ "section.actions": "Actions",
94
+ "section.office": "Optional @wecom/cli",
95
+ "section.receipts": "Recent Dayuan Queries",
96
+ "row.status": "Auth Status",
97
+ "row.login": "QR Code Login",
98
+ "row.login.desc": "Scan with mobile Enterprise WeChat; credentials auto-refresh in the background.",
99
+ "row.wecom_auth": "WeCom App Authorization",
100
+ "row.wecom_auth.desc": "Open secondary WorkBuddy WeCom authorization page if token exchange returns 403.",
101
+ "row.logout": "Sign Out",
102
+ "row.logout.desc": "Remove stored WorkBuddy and WeCom tokens from OpenCode storage.",
103
+ "btn.refresh": "Refresh",
104
+ "btn.login": "Open QR Login",
105
+ "btn.finish": "Verify Scan",
106
+ "btn.open_wecom_auth": "Open WeCom Auth",
107
+ "btn.logout": "Sign Out",
108
+ "toast.login_opened": "Opened WeCom QR login in browser",
109
+ "toast.login_opened_desc": "Scan with mobile Enterprise WeChat, then click Verify Scan.",
110
+ "toast.ready": "WeCom connected",
111
+ "toast.logged_out": "WeCom credentials cleared",
112
+ "toast.no_server": "No connected OpenCode server",
113
+ "state.connected": "Connected (WeCom ready)",
114
+ "state.pending": "Waiting for QR scan...",
115
+ "state.logged_out": "Not signed in",
116
+ "cli.available": "Installed",
117
+ "cli.missing": "Not installed (optional; Dayuan A2A works without it)",
118
+ "receipts.empty": "No recent Dayuan queries yet."
119
+ },
120
+ zh: {
121
+ title: "企业微信 / 大圆",
122
+ description: "零桌面客户端依赖:手机企微扫码登录 + 大圆 A2A 只读群聊摘要。",
123
+ "cmd.login": "企业微信:扫码登录",
124
+ "cmd.login.desc": "在浏览器打开 WorkBuddy 企微扫码页(无需安装任何桌面客户端)。",
125
+ "cmd.settings": "企业微信:打开设置",
126
+ "section.connection": "连接状态",
127
+ "section.actions": "登录与凭据操作",
128
+ "section.office": "可选 @wecom/cli 办公域",
129
+ "section.receipts": "近期大圆查询回执",
130
+ "row.status": "当前状态",
131
+ "row.login": "手机企微扫码登录",
132
+ "row.login.desc": "用手机企业微信扫一次码,后续自动后台续期换票,无需安装桌面端。",
133
+ "row.wecom_auth": "企微应用二次授权",
134
+ "row.wecom_auth.desc": "如果换票提示 403,请点此打开官方 wecom-auth 页面完成企业授权。",
135
+ "row.logout": "退出登录",
136
+ "row.logout.desc": "清除 OpenCode 本地持久化存储的 WorkBuddy / 企微凭据。",
137
+ "btn.refresh": "刷新状态",
138
+ "btn.login": "打开扫码页",
139
+ "btn.finish": "确认已扫码",
140
+ "btn.open_wecom_auth": "打开企微授权页",
141
+ "btn.logout": "清除凭据",
142
+ "toast.login_opened": "已在浏览器打开企微扫码页",
143
+ "toast.login_opened_desc": "请用手机企业微信扫码确认,完成后点击「确认已扫码」。",
144
+ "toast.ready": "企业微信已连接就绪",
145
+ "toast.logged_out": "已清除企业微信登录凭据",
146
+ "toast.no_server": "当前没有已连接的 OpenCode 服务",
147
+ "state.connected": "已连接(企微凭据就绪)",
148
+ "state.pending": "等待手机企微扫码...",
149
+ "state.logged_out": "未登录",
150
+ "cli.available": "已安装",
151
+ "cli.missing": "未安装(可选,不影响大圆 A2A 查群)",
152
+ "receipts.empty": "暂无近期大圆查询记录。"
153
+ }
154
+ },
155
+ setup(ctx) {
156
+ const [snapshot, setSnapshot] = (0, solid_js.createSignal)(void 0);
157
+ const [busy, setBusy] = (0, solid_js.createSignal)(false);
158
+ const [lastAuthUrl, setLastAuthUrl] = (0, solid_js.createSignal)(void 0);
159
+ const getRpc = () => {
160
+ const server = activeServer(ctx);
161
+ return server ? server.client.rpc(WecomRpc) : void 0;
162
+ };
163
+ const refresh = async () => {
164
+ const rpc = getRpc();
165
+ if (!rpc) return;
166
+ setBusy(true);
167
+ try {
168
+ setSnapshot(await rpc.status({}, { signal: ctx.signal }));
169
+ } catch {} finally {
170
+ setBusy(false);
171
+ }
172
+ };
173
+ const startQrLogin = async () => {
174
+ const rpc = getRpc();
175
+ if (!rpc) {
176
+ ctx.toast.show({
177
+ title: ctx.t("toast.no_server"),
178
+ variant: "error"
179
+ });
180
+ return;
181
+ }
182
+ setBusy(true);
183
+ try {
184
+ const started = await rpc.startLogin({}, { signal: ctx.signal });
185
+ setLastAuthUrl(started.authorization_url);
186
+ ctx.system.openExternal(started.authorization_url);
187
+ await ctx.system.copy(started.authorization_url).catch(() => {});
188
+ ctx.toast.show({
189
+ title: ctx.t("toast.login_opened"),
190
+ description: ctx.t("toast.login_opened_desc")
191
+ });
192
+ } catch (err) {
193
+ ctx.toast.show({
194
+ title: err instanceof Error ? err.message : String(err),
195
+ variant: "error"
196
+ });
197
+ } finally {
198
+ setBusy(false);
199
+ }
200
+ };
201
+ const finishQrLogin = async () => {
202
+ const rpc = getRpc();
203
+ if (!rpc) return;
204
+ setBusy(true);
205
+ try {
206
+ const res = await rpc.finishLogin({ wait_seconds: 15 }, { signal: ctx.signal });
207
+ await refresh();
208
+ if (res.auth?.phase === "ready" && res.auth?.wecom_configured) ctx.toast.show({
209
+ title: ctx.t("toast.ready"),
210
+ variant: "success"
211
+ });
212
+ } catch (err) {
213
+ ctx.toast.show({
214
+ title: err instanceof Error ? err.message : String(err),
215
+ variant: "error"
216
+ });
217
+ } finally {
218
+ setBusy(false);
219
+ }
220
+ };
221
+ const logout = async () => {
222
+ const rpc = getRpc();
223
+ if (!rpc) return;
224
+ setBusy(true);
225
+ try {
226
+ await rpc.logout({}, { signal: ctx.signal });
227
+ setLastAuthUrl(void 0);
228
+ await refresh();
229
+ ctx.toast.show({ title: ctx.t("toast.logged_out") });
230
+ } finally {
231
+ setBusy(false);
232
+ }
233
+ };
234
+ refresh();
235
+ const initialRpc = getRpc();
236
+ const unsubAuth = initialRpc ? initialRpc.events.on("authChanged", () => {
237
+ refresh();
238
+ }, { signal: ctx.signal }) : void 0;
239
+ const cleanups = [
240
+ ctx.add(__opencode_plugin_gui.Command, {
241
+ id: "login",
242
+ get title() {
243
+ return ctx.t("cmd.login");
244
+ },
245
+ get description() {
246
+ return ctx.t("cmd.login.desc");
247
+ },
248
+ run: () => startQrLogin()
249
+ }),
250
+ ctx.add(__opencode_plugin_gui.Command, {
251
+ id: "settings",
252
+ get title() {
253
+ return ctx.t("cmd.settings");
254
+ },
255
+ run: () => {
256
+ ctx.layout.settings(ctx.id);
257
+ }
258
+ }),
259
+ ctx.add(__opencode_plugin_gui.TitlebarItem, () => {
260
+ const snap = snapshot();
261
+ const ready = snap?.auth.phase === "ready" && snap?.auth.wecom_configured;
262
+ const pending = snap?.auth.phase === "pending_token" || snap?.auth.phase === "pending_account";
263
+ const icon = ready ? "circle-check" : "bubble-5";
264
+ return {
265
+ id: "wecom-status",
266
+ label: ready ? "WeCom ✓" : pending ? "WeCom …" : "WeCom",
267
+ title: ctx.t("title"),
268
+ icon,
269
+ busy: busy(),
270
+ run: () => {
271
+ ctx.layout.settings(ctx.id);
272
+ }
273
+ };
274
+ }),
275
+ ctx.add(__opencode_plugin_gui.SettingsPage, {
276
+ id: ctx.id,
277
+ get title() {
278
+ return ctx.t("title");
279
+ },
280
+ icon: "bubble-5",
281
+ entries: [{
282
+ id: "wecom.status",
283
+ title: "WeCom Auth Status",
284
+ keywords: "wecom dayuan workbuddy qr"
285
+ }, {
286
+ id: "wecom.login",
287
+ title: "WeCom QR Login",
288
+ keywords: "wecom login scan qr"
289
+ }],
290
+ render() {
291
+ refresh();
292
+ const statusLabel = () => {
293
+ const snap = snapshot();
294
+ if (!snap) return ctx.t("state.logged_out");
295
+ if (snap.auth.phase === "ready" && snap.auth.wecom_configured) return ctx.t("state.connected");
296
+ if (snap.auth.phase === "pending_token" || snap.auth.phase === "pending_account") return ctx.t("state.pending");
297
+ return `${ctx.t("state.logged_out")} (${snap.auth.phase})`;
298
+ };
299
+ const cliLabel = () => {
300
+ const snap = snapshot();
301
+ if (snap?.cli.available) return `${ctx.t("cli.available")} (${snap.cli.version ?? "ok"})`;
302
+ return ctx.t("cli.missing");
303
+ };
304
+ const receiptsDescription = () => {
305
+ const list = snapshot()?.recent_receipts ?? [];
306
+ if (list.length === 0) return ctx.t("receipts.empty");
307
+ return list.slice(0, 5).map((r) => `[${r.status}] ${r.action}${r.summary_preview ? `: ${r.summary_preview}` : ""}`).join(" | ");
308
+ };
309
+ return (0, solid_js.createComponent)(ctx.ui.SettingsLayout, {
310
+ get title() {
311
+ return ctx.t("title");
312
+ },
313
+ get description() {
314
+ return ctx.t("description");
315
+ },
316
+ get actions() {
317
+ return (0, solid_js.createComponent)(ctx.ui.Button, {
318
+ get busy() {
319
+ return busy();
320
+ },
321
+ onClick: () => void refresh(),
322
+ get children() {
323
+ return ctx.t("btn.refresh");
324
+ }
325
+ });
326
+ },
327
+ get children() {
328
+ return [
329
+ (0, solid_js.createComponent)(ctx.ui.SettingsSection, {
330
+ get title() {
331
+ return ctx.t("section.connection");
332
+ },
333
+ get children() {
334
+ return [(0, solid_js.createComponent)(ctx.ui.SettingsRow, {
335
+ id: "wecom.status",
336
+ get title() {
337
+ return ctx.t("row.status");
338
+ },
339
+ get description() {
340
+ return statusLabel();
341
+ }
342
+ }), (0, solid_js.createComponent)(ctx.ui.SettingsRow, {
343
+ id: "wecom.cli",
344
+ get title() {
345
+ return ctx.t("section.office");
346
+ },
347
+ get description() {
348
+ return cliLabel();
349
+ }
350
+ })];
351
+ }
352
+ }),
353
+ (0, solid_js.createComponent)(ctx.ui.SettingsSection, {
354
+ get title() {
355
+ return ctx.t("section.actions");
356
+ },
357
+ get children() {
358
+ return [
359
+ (0, solid_js.createComponent)(ctx.ui.SettingsRow, {
360
+ id: "wecom.login",
361
+ get title() {
362
+ return ctx.t("row.login");
363
+ },
364
+ get description() {
365
+ return lastAuthUrl() ?? ctx.t("row.login.desc");
366
+ },
367
+ get children() {
368
+ return [(0, solid_js.createComponent)(ctx.ui.Button, {
369
+ variant: "contrast",
370
+ get busy() {
371
+ return busy();
372
+ },
373
+ onClick: () => void startQrLogin(),
374
+ get children() {
375
+ return ctx.t("btn.login");
376
+ }
377
+ }), (0, solid_js.createComponent)(ctx.ui.Button, {
378
+ get busy() {
379
+ return busy();
380
+ },
381
+ onClick: () => void finishQrLogin(),
382
+ get children() {
383
+ return ctx.t("btn.finish");
384
+ }
385
+ })];
386
+ }
387
+ }),
388
+ (0, solid_js.createComponent)(ctx.ui.SettingsRow, {
389
+ id: "wecom.auth_page",
390
+ get title() {
391
+ return ctx.t("row.wecom_auth");
392
+ },
393
+ get description() {
394
+ return ctx.t("row.wecom_auth.desc");
395
+ },
396
+ get children() {
397
+ return (0, solid_js.createComponent)(ctx.ui.Button, {
398
+ onClick: () => {
399
+ const url = snapshot()?.wecom_auth_url ?? "https://www.workbuddy.cn/login/wecom-auth";
400
+ ctx.system.openExternal(url);
401
+ },
402
+ get children() {
403
+ return ctx.t("btn.open_wecom_auth");
404
+ }
405
+ });
406
+ }
407
+ }),
408
+ (0, solid_js.createComponent)(ctx.ui.SettingsRow, {
409
+ id: "wecom.logout",
410
+ get title() {
411
+ return ctx.t("row.logout");
412
+ },
413
+ get description() {
414
+ return ctx.t("row.logout.desc");
415
+ },
416
+ get children() {
417
+ return (0, solid_js.createComponent)(ctx.ui.Button, {
418
+ get busy() {
419
+ return busy();
420
+ },
421
+ onClick: () => void logout(),
422
+ get children() {
423
+ return ctx.t("btn.logout");
424
+ }
425
+ });
426
+ }
427
+ })
428
+ ];
429
+ }
430
+ }),
431
+ (0, solid_js.createComponent)(ctx.ui.SettingsSection, {
432
+ get title() {
433
+ return ctx.t("section.receipts");
434
+ },
435
+ get children() {
436
+ return (0, solid_js.createComponent)(ctx.ui.SettingsRow, {
437
+ get title() {
438
+ return ctx.t("section.receipts");
439
+ },
440
+ get description() {
441
+ return receiptsDescription();
442
+ }
443
+ });
444
+ }
445
+ })
446
+ ];
447
+ }
448
+ });
449
+ }
450
+ })
451
+ ];
452
+ return () => {
453
+ unsubAuth?.();
454
+ for (const cleanup of cleanups) cleanup();
455
+ };
456
+ }
457
+ });
458
+
459
+ //#endregion
460
+ module.exports = gui_default;