opencode-plugin-wecom 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -7
- package/dist/gui-experimental.cjs +40 -4
- package/dist/index.d.ts +20 -7
- package/dist/index.js +1135 -856
- package/dist/{rpc-D5Bs48Ma.d.ts → rpc-BI3X82Bx.d.ts} +11 -0
- package/dist/{rpc-CDRXKJwO.js → rpc-D5y1uowA.js} +4 -0
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
- **零桌面客户端依赖**:纯 HTTPS 协议实现,**不需要**在电脑上安装 WorkBuddy 客户端或企业微信桌面端,本机与远程 Linux 服务器均可直接运行。
|
|
12
12
|
- **Device Flow 风格扫码登录 + 自动静默续期**:获取官方扫码链接,用手机企业微信扫一次码后,凭据持久化到 OpenCode 原生 `storage`,后续自动在后台刷新并换取企微 `access_token`。
|
|
13
|
-
- **大圆 A2A
|
|
13
|
+
- **大圆 A2A 只读聊天查询**:按当前企业账号发现大圆并换取专用票据,支持查群、读会话摘要、搜消息摘要,内置:
|
|
14
14
|
- `request_id` 幂等回执与参数指纹冲突检测
|
|
15
15
|
- 终态结果本地缓存与 `401` / 过期错误码自动强制换票重试
|
|
16
|
-
|
|
16
|
+
- 追加授权返回官方入口;仅允许回复纯文本澄清,审批卡交给本人处理
|
|
17
17
|
- **可选 `@wecom/cli` 结构化办公域桥接**:如果本机安装了官方 `@wecom/cli`,可直接查询文档、智能表格、日程、会议、邮件、微盘、通讯录(默认严格只读;未安装完全不影响大圆 A2A)。
|
|
18
18
|
- **Yuri / Desktop GUI 薄壳**:通过 `./gui-experimental` 提供中英文界面、顶栏连接状态 Pill、命令面板一键扫码与独立设置页,状态经 OpenCode RPC 实时同步。
|
|
19
19
|
|
|
@@ -58,14 +58,28 @@
|
|
|
58
58
|
|
|
59
59
|
---
|
|
60
60
|
|
|
61
|
-
##
|
|
61
|
+
## 快速上手:用 OpenCode 查企业微信
|
|
62
|
+
|
|
63
|
+
安装插件后,在 OpenCode 里直接提问即可,不必手动调用工具。插件内置 `wecom-dayuan` Skill,Agent 会按需要查消息、引导授权或恢复原任务。支持企业微信内部单聊和群聊,不是个人微信,也不提供聊天原文。
|
|
64
|
+
|
|
65
|
+
- 「根据最近 7 天我发出的消息和提到我的消息,看看我最近在跟进什么,注明会话和日期。」
|
|
66
|
+
- 「总结『项目群』近 3 天的结论和待办。」
|
|
67
|
+
- 「在企业微信里找一下与『联调』相关的讨论。」
|
|
68
|
+
|
|
69
|
+
### 首次登录
|
|
62
70
|
|
|
63
71
|
1. 在 OpenCode 会话中运行 `/wecom-login`(或让 Agent 调用 `wecom_login({ mode: "start" })`;在 Yuri 桌面端也可从设置页或命令面板选择 **「企业微信:扫码登录」**)。
|
|
64
72
|
2. 在浏览器打开返回的 `authorization_url`,用**手机企业微信**扫码确认。
|
|
65
73
|
3. 调用 `wecom_login({ mode: "wait", wait_seconds: 60 })`(或在 Yuri 设置页点击 **「确认已扫码」**),插件将轮询登录态并自动换取企业微信 user token。
|
|
66
|
-
4.
|
|
74
|
+
4. 首次查询时,插件通过当前账号的 Agent Card 发现大圆并换取专用 Agent Ticket;仅在有票据后提交只读查询。企业微信用户 Token 不用于提交大圆任务。
|
|
75
|
+
|
|
76
|
+
### 查询要求追加授权时
|
|
77
|
+
|
|
78
|
+
1. 工具返回 `interaction_kind: "authorization_required"`,并在正文和 `authorization_url` 字段提供官方授权地址。Agent 应把链接写到**每个受阻事项的回复正文**里,不要只说「请先授权」。
|
|
79
|
+
2. 用同一企业账号打开链接确认。确认后,Agent 调用 `wecom_login({ mode: "verify_wecom" })`;Yuri 也可以点「确认已授权」。验证只换票,不提交查询。
|
|
80
|
+
3. 如果已拿到 `task_id`,用 `wecom_read_result` 继续查同一个任务;如果明确尚未提交才重试原查询。原任务仍待授权时,到官方界面查看该任务;若企业未开通权限,找管理员处理。
|
|
67
81
|
|
|
68
|
-
|
|
82
|
+
任务审批卡是另一条流程。WorkBuddy 可用 `wxwork://` 唤起企业微信确认当前任务;本插件不生成或转发含审批票据的 deep link,也不代批。请在企业微信官方界面处理原审批卡,再查询原任务。
|
|
69
83
|
|
|
70
84
|
---
|
|
71
85
|
|
|
@@ -76,7 +90,7 @@
|
|
|
76
90
|
| 工具名 | 作用 | 主要参数 |
|
|
77
91
|
| --- | --- | --- |
|
|
78
92
|
| `wecom_status` | 零网络请求检查登录态、企微 Token 就绪度、可选 `@wecom/cli` 状态及近期回执 | `include_receipts?: boolean` |
|
|
79
|
-
| `wecom_login` |
|
|
93
|
+
| `wecom_login` | 扫码登录、追加授权与换票验证 | `mode: "start" \| "finish" \| "wait" \| "wecom_auth" \| "verify_wecom" \| "logout"`, `wait_seconds?: number` |
|
|
80
94
|
| `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
95
|
| `wecom_read_result` | 按 `task_id` 轮询或读取本地缓存的终态结果 | `task_id: string`, `wait_seconds?: number` |
|
|
82
96
|
| `wecom_read_reply` | 对纯文本澄清类 `input_required` 任务回复澄清(审批卡片强制拒绝) | `task_id: string`, `text: string`, `request_id?`, `wait_seconds?` |
|
|
@@ -96,7 +110,7 @@
|
|
|
96
110
|
|
|
97
111
|
导出 `WecomRpc`(`id: "opencode-plugin-wecom"`),供 Yuri GUI / TUI 或其他插件调用:
|
|
98
112
|
|
|
99
|
-
- Methods:`status`、`startLogin`、`finishLogin`、`logout`、`recentReceipts`
|
|
113
|
+
- Methods:`status`、`startLogin`、`finishLogin`、`verifyWecom`、`logout`、`recentReceipts`
|
|
100
114
|
- Events:`authChanged`(`{ phase, wecom_configured }`)
|
|
101
115
|
|
|
102
116
|
---
|
|
@@ -39,6 +39,10 @@ const WecomRpc = __opencode_plugin_rpc.Rpc.define({
|
|
|
39
39
|
},
|
|
40
40
|
output: anyObjectSchema
|
|
41
41
|
},
|
|
42
|
+
verifyWecom: {
|
|
43
|
+
input: emptyObjectSchema,
|
|
44
|
+
output: anyObjectSchema
|
|
45
|
+
},
|
|
42
46
|
logout: {
|
|
43
47
|
input: emptyObjectSchema,
|
|
44
48
|
output: anyObjectSchema
|
|
@@ -97,13 +101,15 @@ var gui_default = __opencode_plugin_gui.Plugin.define({
|
|
|
97
101
|
"row.login": "QR Code Login",
|
|
98
102
|
"row.login.desc": "Scan with mobile Enterprise WeChat; credentials auto-refresh in the background.",
|
|
99
103
|
"row.wecom_auth": "WeCom App Authorization",
|
|
100
|
-
"row.wecom_auth.desc": "Open
|
|
104
|
+
"row.wecom_auth.desc": "Open the official authorization page. After granting access, verify the WeCom and Dayuan credentials.",
|
|
101
105
|
"row.logout": "Sign Out",
|
|
102
106
|
"row.logout.desc": "Remove stored WorkBuddy and WeCom tokens from OpenCode storage.",
|
|
103
107
|
"btn.refresh": "Refresh",
|
|
104
108
|
"btn.login": "Open QR Login",
|
|
105
109
|
"btn.finish": "Verify Scan",
|
|
106
110
|
"btn.open_wecom_auth": "Open WeCom Auth",
|
|
111
|
+
"btn.verify_wecom_auth": "Verify Authorization",
|
|
112
|
+
"toast.auth_verified": "WeCom authorization and Dayuan ticket verified",
|
|
107
113
|
"btn.logout": "Sign Out",
|
|
108
114
|
"toast.login_opened": "Opened WeCom QR login in browser",
|
|
109
115
|
"toast.login_opened_desc": "Scan with mobile Enterprise WeChat, then click Verify Scan.",
|
|
@@ -131,13 +137,15 @@ var gui_default = __opencode_plugin_gui.Plugin.define({
|
|
|
131
137
|
"row.login": "手机企微扫码登录",
|
|
132
138
|
"row.login.desc": "用手机企业微信扫一次码,后续自动后台续期换票,无需安装桌面端。",
|
|
133
139
|
"row.wecom_auth": "企微应用二次授权",
|
|
134
|
-
"row.wecom_auth.desc": "
|
|
140
|
+
"row.wecom_auth.desc": "需要追加授权或授权失效时,打开官方页面确认,再验证企业微信和大圆凭据。",
|
|
135
141
|
"row.logout": "退出登录",
|
|
136
142
|
"row.logout.desc": "清除 OpenCode 本地持久化存储的 WorkBuddy / 企微凭据。",
|
|
137
143
|
"btn.refresh": "刷新状态",
|
|
138
144
|
"btn.login": "打开扫码页",
|
|
139
145
|
"btn.finish": "确认已扫码",
|
|
140
146
|
"btn.open_wecom_auth": "打开企微授权页",
|
|
147
|
+
"btn.verify_wecom_auth": "确认已授权",
|
|
148
|
+
"toast.auth_verified": "企业微信授权和大圆票据已验证",
|
|
141
149
|
"btn.logout": "清除凭据",
|
|
142
150
|
"toast.login_opened": "已在浏览器打开企微扫码页",
|
|
143
151
|
"toast.login_opened_desc": "请用手机企业微信扫码确认,完成后点击「确认已扫码」。",
|
|
@@ -218,6 +226,26 @@ var gui_default = __opencode_plugin_gui.Plugin.define({
|
|
|
218
226
|
setBusy(false);
|
|
219
227
|
}
|
|
220
228
|
};
|
|
229
|
+
const verifyWecom = async () => {
|
|
230
|
+
const rpc = getRpc();
|
|
231
|
+
if (!rpc) return;
|
|
232
|
+
setBusy(true);
|
|
233
|
+
try {
|
|
234
|
+
await rpc.verifyWecom({}, { signal: ctx.signal });
|
|
235
|
+
await refresh();
|
|
236
|
+
ctx.toast.show({
|
|
237
|
+
title: ctx.t("toast.auth_verified"),
|
|
238
|
+
variant: "success"
|
|
239
|
+
});
|
|
240
|
+
} catch (err) {
|
|
241
|
+
ctx.toast.show({
|
|
242
|
+
title: err instanceof Error ? err.message : String(err),
|
|
243
|
+
variant: "error"
|
|
244
|
+
});
|
|
245
|
+
} finally {
|
|
246
|
+
setBusy(false);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
221
249
|
const logout = async () => {
|
|
222
250
|
const rpc = getRpc();
|
|
223
251
|
if (!rpc) return;
|
|
@@ -394,7 +422,7 @@ var gui_default = __opencode_plugin_gui.Plugin.define({
|
|
|
394
422
|
return ctx.t("row.wecom_auth.desc");
|
|
395
423
|
},
|
|
396
424
|
get children() {
|
|
397
|
-
return (0, solid_js.createComponent)(ctx.ui.Button, {
|
|
425
|
+
return [(0, solid_js.createComponent)(ctx.ui.Button, {
|
|
398
426
|
onClick: () => {
|
|
399
427
|
const url = snapshot()?.wecom_auth_url ?? "https://www.workbuddy.cn/login/wecom-auth";
|
|
400
428
|
ctx.system.openExternal(url);
|
|
@@ -402,7 +430,15 @@ var gui_default = __opencode_plugin_gui.Plugin.define({
|
|
|
402
430
|
get children() {
|
|
403
431
|
return ctx.t("btn.open_wecom_auth");
|
|
404
432
|
}
|
|
405
|
-
})
|
|
433
|
+
}), (0, solid_js.createComponent)(ctx.ui.Button, {
|
|
434
|
+
get busy() {
|
|
435
|
+
return busy();
|
|
436
|
+
},
|
|
437
|
+
onClick: () => void verifyWecom(),
|
|
438
|
+
get children() {
|
|
439
|
+
return ctx.t("btn.verify_wecom_auth");
|
|
440
|
+
}
|
|
441
|
+
})];
|
|
406
442
|
}
|
|
407
443
|
}),
|
|
408
444
|
(0, solid_js.createComponent)(ctx.ui.SettingsRow, {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as WecomRpc, t as PLUGIN_ID } from "./rpc-
|
|
1
|
+
import { n as WecomRpc, t as PLUGIN_ID } from "./rpc-BI3X82Bx.js";
|
|
2
2
|
import { Plugin } from "@opencode/plugin";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
@@ -100,6 +100,13 @@ interface WecomCredential {
|
|
|
100
100
|
expires_at_ms: number;
|
|
101
101
|
source: 'workbuddy_cloud';
|
|
102
102
|
}
|
|
103
|
+
interface DayuanCredential {
|
|
104
|
+
access_token: string;
|
|
105
|
+
identity: string;
|
|
106
|
+
endpoint: string;
|
|
107
|
+
headers: Record<string, string>;
|
|
108
|
+
expires_at_ms: number;
|
|
109
|
+
}
|
|
103
110
|
interface WorkBuddyStatus {
|
|
104
111
|
phase: AuthPhase;
|
|
105
112
|
desktop_required: false;
|
|
@@ -109,6 +116,7 @@ interface WorkBuddyStatus {
|
|
|
109
116
|
refresh_credential_present: boolean;
|
|
110
117
|
wecom_expires_at_ms: number | null;
|
|
111
118
|
wecom_configured: boolean;
|
|
119
|
+
dayuan_ticket_ready?: boolean;
|
|
112
120
|
authorization_verified: boolean;
|
|
113
121
|
}
|
|
114
122
|
interface StartLoginResult {
|
|
@@ -137,6 +145,7 @@ declare class WorkBuddyAuth {
|
|
|
137
145
|
private readonly clock;
|
|
138
146
|
private readonly onAuthChange?;
|
|
139
147
|
private readonly lock;
|
|
148
|
+
private dayuan?;
|
|
140
149
|
constructor(options: WorkBuddyAuthOptions);
|
|
141
150
|
private load;
|
|
142
151
|
private save;
|
|
@@ -165,13 +174,18 @@ declare class WorkBuddyAuth {
|
|
|
165
174
|
deadlineMonoMs?: number;
|
|
166
175
|
signal?: AbortSignal;
|
|
167
176
|
}): Promise<WecomCredential>;
|
|
177
|
+
verifyWecom(signal?: AbortSignal): Promise<WorkBuddyStatus>;
|
|
178
|
+
ensureDayuan(options?: {
|
|
179
|
+
force?: boolean;
|
|
180
|
+
signal?: AbortSignal;
|
|
181
|
+
}): Promise<DayuanCredential>;
|
|
168
182
|
logout(): Promise<WorkBuddyStatus>;
|
|
169
183
|
}
|
|
170
184
|
//#endregion
|
|
171
185
|
//#region src/a2a/client.d.ts
|
|
172
186
|
type DayuanAction = 'search_groups' | 'read_chat' | 'search_messages';
|
|
173
|
-
type A2ATaskState = 'submitted' | 'working' | 'input_required' | 'completed' | 'failed' | 'canceled' | 'rejected' | 'unknown';
|
|
174
|
-
type InteractionKind = 'none' | 'text_clarification' | 'approval_required' | 'unsupported';
|
|
187
|
+
type A2ATaskState = 'submitted' | 'working' | 'input_required' | 'auth_required' | 'completed' | 'failed' | 'canceled' | 'rejected' | 'unknown';
|
|
188
|
+
type InteractionKind = 'none' | 'text_clarification' | 'approval_required' | 'authorization_required' | 'unsupported';
|
|
175
189
|
interface SearchGroupsInput {
|
|
176
190
|
readonly action: 'search_groups';
|
|
177
191
|
readonly query: string;
|
|
@@ -227,6 +241,7 @@ interface DayuanTaskResult {
|
|
|
227
241
|
readonly interaction_kind: InteractionKind;
|
|
228
242
|
readonly can_reply_in_text: boolean;
|
|
229
243
|
readonly human_action_required: boolean;
|
|
244
|
+
readonly authorization_url?: string;
|
|
230
245
|
readonly guidance?: string;
|
|
231
246
|
readonly from_cache: boolean;
|
|
232
247
|
readonly updated_at_ms: number;
|
|
@@ -240,12 +255,10 @@ interface DayuanReceiptSummary {
|
|
|
240
255
|
readonly updated_at_ms: number;
|
|
241
256
|
}
|
|
242
257
|
interface WecomCredentialProvider {
|
|
243
|
-
|
|
258
|
+
ensureDayuan(options?: {
|
|
244
259
|
force?: boolean;
|
|
245
|
-
refreshAccount?: boolean;
|
|
246
|
-
deadlineMonoMs?: number;
|
|
247
260
|
signal?: AbortSignal;
|
|
248
|
-
}): Promise<
|
|
261
|
+
}): Promise<DayuanCredential>;
|
|
249
262
|
}
|
|
250
263
|
interface DayuanA2AClientOptions {
|
|
251
264
|
readonly auth: WecomCredentialProvider;
|