@workclaw/openclaw-workclaw 1.0.23 → 1.0.26

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 (210) hide show
  1. package/dist/api.d.ts +4 -3
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +379 -3
  4. package/dist/channel-DSvR6Irx.js +50017 -0
  5. package/dist/cron-tasks-handler-C-mP3VmV.js +152 -0
  6. package/dist/index.d.ts +5 -4
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2056 -232
  9. package/dist/jiti-4i2h0FGP.js +4814 -0
  10. package/dist/setup-entry.d.ts +2 -1
  11. package/dist/setup-entry.d.ts.map +1 -0
  12. package/dist/setup-entry.js +181 -11
  13. package/dist/src/accounts.d.ts +3 -2
  14. package/dist/src/accounts.d.ts.map +1 -0
  15. package/dist/src/api/accounts-api.d.ts +2 -1
  16. package/dist/src/api/accounts-api.d.ts.map +1 -0
  17. package/dist/src/api/prompts-api.d.ts +2 -1
  18. package/dist/src/api/prompts-api.d.ts.map +1 -0
  19. package/dist/src/api/session-api.d.ts +2 -1
  20. package/dist/src/api/session-api.d.ts.map +1 -0
  21. package/dist/src/api/skills-api.d.ts +2 -1
  22. package/dist/src/api/skills-api.d.ts.map +1 -0
  23. package/dist/src/api/workspace.d.ts +2 -1
  24. package/dist/src/api/workspace.d.ts.map +1 -0
  25. package/dist/src/channel.d.ts +3 -2
  26. package/dist/src/channel.d.ts.map +1 -0
  27. package/dist/src/config-schema.d.ts +1 -6
  28. package/dist/src/config-schema.d.ts.map +1 -0
  29. package/dist/src/connection/workclaw-client.d.ts +6 -4
  30. package/dist/src/connection/workclaw-client.d.ts.map +1 -0
  31. package/dist/src/gateway/agent-handlers.d.ts +3 -2
  32. package/dist/src/gateway/agent-handlers.d.ts.map +1 -0
  33. package/dist/src/gateway/config-writer.d.ts +3 -2
  34. package/dist/src/gateway/config-writer.d.ts.map +1 -0
  35. package/dist/src/gateway/cron-tasks-handler.d.ts +1 -0
  36. package/dist/src/gateway/cron-tasks-handler.d.ts.map +1 -0
  37. package/dist/src/gateway/message-context.d.ts +2 -1
  38. package/dist/src/gateway/message-context.d.ts.map +1 -0
  39. package/dist/src/gateway/message-dispatcher.d.ts +3 -4
  40. package/dist/src/gateway/message-dispatcher.d.ts.map +1 -0
  41. package/dist/src/gateway/reconnect.d.ts +3 -5
  42. package/dist/src/gateway/reconnect.d.ts.map +1 -0
  43. package/dist/src/gateway/skills-handler.d.ts +1 -0
  44. package/dist/src/gateway/skills-handler.d.ts.map +1 -0
  45. package/dist/src/gateway/skills-list-handler.d.ts +1 -0
  46. package/dist/src/gateway/skills-list-handler.d.ts.map +1 -0
  47. package/dist/src/gateway/tools-list-handler.d.ts +1 -0
  48. package/dist/src/gateway/tools-list-handler.d.ts.map +1 -0
  49. package/dist/src/gateway/workclaw-gateway.d.ts +4 -7
  50. package/dist/src/gateway/workclaw-gateway.d.ts.map +1 -0
  51. package/dist/src/media/upload.d.ts +1 -0
  52. package/dist/src/media/upload.d.ts.map +1 -0
  53. package/dist/src/outbound/index.d.ts +9 -6
  54. package/dist/src/outbound/index.d.ts.map +1 -0
  55. package/dist/src/outbound/workclaw-sender.d.ts +6 -4
  56. package/dist/src/outbound/workclaw-sender.d.ts.map +1 -0
  57. package/dist/src/runtime.d.ts +11 -9
  58. package/dist/src/runtime.d.ts.map +1 -0
  59. package/dist/src/secret-contract-api.d.ts +1 -0
  60. package/dist/src/secret-contract-api.d.ts.map +1 -0
  61. package/dist/src/send.d.ts +2 -1
  62. package/dist/src/send.d.ts.map +1 -0
  63. package/dist/src/setup-api.d.ts +4 -3
  64. package/dist/src/setup-api.d.ts.map +1 -0
  65. package/dist/src/setup-core.d.ts +2 -1
  66. package/dist/src/setup-core.d.ts.map +1 -0
  67. package/dist/src/setup-surface.d.ts +3 -2
  68. package/dist/src/setup-surface.d.ts.map +1 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +2 -4
  70. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts.map +1 -0
  71. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +1 -0
  72. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts.map +1 -0
  73. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +2 -4
  74. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts.map +1 -0
  75. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +2 -4
  76. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts.map +1 -0
  77. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +2 -4
  78. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts.map +1 -0
  79. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +2 -4
  80. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts.map +1 -0
  81. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +2 -4
  82. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts.map +1 -0
  83. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +2 -4
  84. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts.map +1 -0
  85. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +2 -6
  86. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts.map +1 -0
  87. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +2 -4
  88. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts.map +1 -0
  89. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +2 -4
  90. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts.map +1 -0
  91. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +2 -4
  92. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts.map +1 -0
  93. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +2 -4
  94. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts.map +1 -0
  95. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +1 -0
  96. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts.map +1 -0
  97. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +1 -0
  98. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts.map +1 -0
  99. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +1 -0
  100. package/dist/src/tools/openclaw-workclaw-system/index.d.ts.map +1 -0
  101. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +2 -4
  102. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts.map +1 -0
  103. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +2 -4
  104. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts.map +1 -0
  105. package/dist/src/types.d.ts +7 -7
  106. package/dist/src/types.d.ts.map +1 -0
  107. package/dist/src/utils/content.d.ts +1 -0
  108. package/dist/src/utils/content.d.ts.map +1 -0
  109. package/openclaw.plugin.json +6 -0
  110. package/package.json +69 -45
  111. package/api.ts +0 -3
  112. package/dist/src/accounts.js +0 -279
  113. package/dist/src/api/accounts-api.js +0 -130
  114. package/dist/src/api/prompts-api.js +0 -103
  115. package/dist/src/api/session-api.js +0 -207
  116. package/dist/src/api/skills-api.js +0 -64
  117. package/dist/src/api/workspace.js +0 -30
  118. package/dist/src/channel.js +0 -199
  119. package/dist/src/config-schema.js +0 -56
  120. package/dist/src/connection/workclaw-client.js +0 -351
  121. package/dist/src/gateway/agent-handlers.js +0 -433
  122. package/dist/src/gateway/config-writer.js +0 -302
  123. package/dist/src/gateway/cron-tasks-handler.js +0 -188
  124. package/dist/src/gateway/message-context.js +0 -509
  125. package/dist/src/gateway/message-dispatcher.js +0 -572
  126. package/dist/src/gateway/reconnect.js +0 -210
  127. package/dist/src/gateway/skills-handler.js +0 -615
  128. package/dist/src/gateway/skills-list-handler.js +0 -233
  129. package/dist/src/gateway/tools-list-handler.js +0 -101
  130. package/dist/src/gateway/workclaw-gateway.js +0 -237
  131. package/dist/src/media/upload.js +0 -125
  132. package/dist/src/outbound/index.js +0 -123
  133. package/dist/src/outbound/workclaw-sender.js +0 -95
  134. package/dist/src/runtime.js +0 -374
  135. package/dist/src/secret-contract-api.js +0 -4
  136. package/dist/src/send.js +0 -1
  137. package/dist/src/setup-api.js +0 -3
  138. package/dist/src/setup-core.js +0 -13
  139. package/dist/src/setup-surface.js +0 -363
  140. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +0 -209
  141. package/dist/src/tools/openclaw-workclaw-cron/index.js +0 -33
  142. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +0 -152
  143. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +0 -162
  144. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +0 -80
  145. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +0 -107
  146. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +0 -80
  147. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +0 -107
  148. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +0 -127
  149. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +0 -87
  150. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +0 -107
  151. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +0 -164
  152. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +0 -135
  153. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +0 -4
  154. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +0 -122
  155. package/dist/src/tools/openclaw-workclaw-system/index.js +0 -15
  156. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +0 -64
  157. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +0 -78
  158. package/dist/src/types.js +0 -1
  159. package/dist/src/utils/content.js +0 -38
  160. package/index.ts +0 -325
  161. package/setup-entry.ts +0 -13
  162. package/src/accounts.ts +0 -360
  163. package/src/api/accounts-api.ts +0 -156
  164. package/src/api/prompts-api.ts +0 -122
  165. package/src/api/session-api.ts +0 -246
  166. package/src/api/skills-api.ts +0 -74
  167. package/src/api/workspace.ts +0 -45
  168. package/src/channel.ts +0 -226
  169. package/src/config-schema.ts +0 -60
  170. package/src/connection/workclaw-client.ts +0 -618
  171. package/src/gateway/agent-handlers.ts +0 -551
  172. package/src/gateway/config-writer.ts +0 -378
  173. package/src/gateway/cron-tasks-handler.ts +0 -230
  174. package/src/gateway/message-context.ts +0 -645
  175. package/src/gateway/message-dispatcher.ts +0 -688
  176. package/src/gateway/reconnect.ts +0 -260
  177. package/src/gateway/skills-handler.ts +0 -805
  178. package/src/gateway/skills-list-handler.ts +0 -332
  179. package/src/gateway/tools-list-handler.ts +0 -161
  180. package/src/gateway/workclaw-gateway.ts +0 -298
  181. package/src/media/upload.ts +0 -168
  182. package/src/outbound/index.ts +0 -191
  183. package/src/outbound/workclaw-sender.ts +0 -161
  184. package/src/runtime.ts +0 -520
  185. package/src/secret-contract-api.ts +0 -4
  186. package/src/send.ts +0 -1
  187. package/src/setup-api.ts +0 -3
  188. package/src/setup-core.ts +0 -25
  189. package/src/setup-surface.ts +0 -498
  190. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  191. package/src/tools/openclaw-workclaw-cron/index.ts +0 -39
  192. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
  193. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  194. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  195. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  196. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  197. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  198. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  199. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  200. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  201. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
  202. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  203. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  204. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  205. package/src/tools/openclaw-workclaw-system/index.ts +0 -17
  206. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  207. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  208. package/src/types.ts +0 -50
  209. package/src/utils/content.ts +0 -40
  210. package/tsconfig.json +0 -34
@@ -1,207 +0,0 @@
1
- import { getWorkclawRuntime } from "../runtime.js";
2
- function sendJson(res, statusCode, payload) {
3
- res.statusCode = statusCode;
4
- res.setHeader("Content-Type", "application/json");
5
- res.end(JSON.stringify(payload));
6
- }
7
- async function readRequestBody(req) {
8
- const chunks = [];
9
- await new Promise((resolve, reject) => {
10
- req.on("data", (chunk) => {
11
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
12
- });
13
- req.on("end", () => resolve());
14
- req.on("error", (err) => reject(err));
15
- });
16
- return Buffer.concat(chunks).toString("utf-8");
17
- }
18
- /**
19
- * 构建会话 key
20
- * 格式: openclaw-workclaw:{accountId}:{userId}
21
- */
22
- function buildSessionKey(accountId, userId) {
23
- return `openclaw-workclaw:${accountId}:${userId}`;
24
- }
25
- /**
26
- * 解析会话 key
27
- */
28
- function parseSessionKey(sessionKey) {
29
- const parts = sessionKey.split(":");
30
- if (parts.length !== 3 || parts[0] !== "openclaw-workclaw") {
31
- return null;
32
- }
33
- return {
34
- channel: parts[0],
35
- accountId: parts[1],
36
- userId: parts[2],
37
- };
38
- }
39
- /**
40
- * 重置/开启新会话
41
- * 通过发送系统事件 /new 到指定会话
42
- */
43
- async function resetSession(sessionKey, log) {
44
- try {
45
- const runtime = getWorkclawRuntime();
46
- // 使用 system.enqueueSystemEvent 发送 /new 命令
47
- runtime.system.enqueueSystemEvent("/new", {
48
- sessionKey,
49
- contextKey: null,
50
- });
51
- log?.info?.(`[SessionAPI] Sent /new command to session: ${sessionKey}`);
52
- return {
53
- success: true,
54
- message: `Session reset command sent to ${sessionKey}`,
55
- };
56
- }
57
- catch (err) {
58
- const errorMsg = `Failed to reset session: ${String(err)}`;
59
- log?.error?.(`[SessionAPI] ${errorMsg}`);
60
- return { success: false, message: errorMsg };
61
- }
62
- }
63
- /**
64
- * 获取会话存储路径
65
- */
66
- function getSessionStorePath(agentId, log) {
67
- try {
68
- const runtime = getWorkclawRuntime();
69
- const storePath = runtime.channel.session.resolveStorePath(undefined, {
70
- agentId,
71
- });
72
- return storePath;
73
- }
74
- catch (err) {
75
- log?.error?.(`[SessionAPI] Failed to resolve store path: ${String(err)}`);
76
- return null;
77
- }
78
- }
79
- /**
80
- * 读取会话最后更新时间
81
- */
82
- async function getSessionLastUpdated(sessionKey, log) {
83
- try {
84
- const runtime = getWorkclawRuntime();
85
- const storePath = runtime.channel.session.resolveStorePath();
86
- const updatedAt = runtime.channel.session.readSessionUpdatedAt({
87
- storePath,
88
- sessionKey,
89
- });
90
- return updatedAt ?? null;
91
- }
92
- catch (err) {
93
- log?.error?.(`[SessionAPI] Failed to read session updated at: ${String(err)}`);
94
- return null;
95
- }
96
- }
97
- export function createSessionApiHandler(api) {
98
- return async (req, res) => {
99
- const method = String(req.method ?? "GET").toUpperCase();
100
- const url = new URL(req.url ?? "", "http://localhost");
101
- // 移除尾部斜杠并获取路径部分
102
- const fullPath = url.pathname.replace(/\/+$/, "");
103
- // 提取子路径(去掉 /openclaw-workclaw/sessions 前缀)
104
- const subPath = fullPath.replace(/^\/openclaw-workclaw\/sessions/, "").replace(/^\//, "") || "/";
105
- const log = {
106
- info: (msg) => api.logger?.info?.(`[SessionAPI] ${msg}`),
107
- error: (msg) => api.logger?.error?.(`[SessionAPI] ${msg}`),
108
- };
109
- log?.info?.(`[SessionAPI] ${method} ${fullPath} (subPath: ${subPath})`);
110
- // GET /sessions 或 /sessions/ - 列出会话信息
111
- if (method === "GET" && (subPath === "/" || subPath === "")) {
112
- const sessionKey = url.searchParams.get("sessionKey");
113
- if (sessionKey) {
114
- // 获取特定会话信息
115
- const parsed = parseSessionKey(sessionKey);
116
- const updatedAt = await getSessionLastUpdated(sessionKey, log);
117
- sendJson(res, 200, {
118
- ok: true,
119
- session: {
120
- sessionKey,
121
- parsed,
122
- lastUpdatedAt: updatedAt,
123
- lastUpdatedAtFormatted: updatedAt
124
- ? new Date(updatedAt).toISOString()
125
- : null,
126
- },
127
- });
128
- return;
129
- }
130
- // 返回 API 信息
131
- sendJson(res, 200, {
132
- ok: true,
133
- message: "Session Management API",
134
- endpoints: {
135
- "GET /sessions": "获取会话信息 (可选参数: sessionKey)",
136
- "POST /sessions/reset": "重置/开启新会话 (参数: accountId + userId 或直接提供 sessionKey)",
137
- "GET /sessions/store-path": "获取会话存储路径 (可选参数: agentId)",
138
- },
139
- });
140
- return;
141
- }
142
- // POST /sessions/reset - 重置会话
143
- if (method === "POST" && subPath === "reset") {
144
- const raw = await readRequestBody(req);
145
- let input = {};
146
- try {
147
- input = raw ? JSON.parse(raw) : {};
148
- }
149
- catch {
150
- sendJson(res, 400, { ok: false, error: "Invalid JSON" });
151
- return;
152
- }
153
- const { accountId, userId, sessionKey: directSessionKey } = input;
154
- let sessionKey;
155
- if (directSessionKey) {
156
- sessionKey = directSessionKey;
157
- }
158
- else if (accountId && userId) {
159
- sessionKey = buildSessionKey(accountId, userId);
160
- }
161
- else {
162
- sendJson(res, 400, {
163
- ok: false,
164
- error: "Missing required fields: either provide 'sessionKey' or both 'accountId' and 'userId'",
165
- });
166
- return;
167
- }
168
- const result = await resetSession(sessionKey, log);
169
- if (result.success) {
170
- sendJson(res, 200, {
171
- ok: true,
172
- message: result.message,
173
- sessionKey,
174
- });
175
- }
176
- else {
177
- sendJson(res, 500, {
178
- ok: false,
179
- error: result.message,
180
- sessionKey,
181
- });
182
- }
183
- return;
184
- }
185
- // GET /sessions/store-path - 获取会话存储路径
186
- if (method === "GET" && subPath === "store-path") {
187
- const agentId = url.searchParams.get("agentId") ?? undefined;
188
- const storePath = getSessionStorePath(agentId, log);
189
- if (storePath) {
190
- sendJson(res, 200, {
191
- ok: true,
192
- storePath,
193
- agentId: agentId ?? "default",
194
- });
195
- }
196
- else {
197
- sendJson(res, 500, {
198
- ok: false,
199
- error: "Failed to resolve session store path",
200
- });
201
- }
202
- return;
203
- }
204
- // 404
205
- sendJson(res, 404, { ok: false, error: "Not Found" });
206
- };
207
- }
@@ -1,64 +0,0 @@
1
- import { exec } from "node:child_process";
2
- import { promisify } from "node:util";
3
- const execAsync = promisify(exec);
4
- function sendJson(res, statusCode, payload) {
5
- res.statusCode = statusCode;
6
- res.setHeader("Content-Type", "application/json");
7
- res.end(JSON.stringify(payload));
8
- }
9
- export function createSkillsApiHandler(api) {
10
- return async (req, res) => {
11
- const method = String(req.method ?? "GET").toUpperCase();
12
- if (method === "GET") {
13
- try {
14
- // 调用 openclaw skills list 命令
15
- const { stdout, stderr } = await execAsync("openclaw skills list --json", {
16
- timeout: 10000, // 10秒超时
17
- });
18
- if (stderr && !stdout) {
19
- api.logger.error(`Skills list error: ${stderr}`);
20
- sendJson(res, 500, { ok: false, error: "Failed to list skills" });
21
- return;
22
- }
23
- // 尝试解析JSON输出
24
- let skillsData;
25
- try {
26
- skillsData = JSON.parse(stdout);
27
- }
28
- catch {
29
- // 如果不支持--json输出,尝试解析文本输出
30
- const lines = stdout.split('\n');
31
- const skills = lines
32
- .filter((line) => line.trim() && !line.includes('Skills'))
33
- .map((line) => {
34
- const parts = line.split(/\s{2,}/).map((p) => p.trim());
35
- if (parts.length >= 3) {
36
- return {
37
- status: parts[0]?.includes('✓') ? 'ready' : 'missing',
38
- name: parts[1],
39
- description: parts[2],
40
- source: parts[3] || 'openclaw-bundled'
41
- };
42
- }
43
- return null;
44
- })
45
- .filter((s) => s !== null);
46
- skillsData = {
47
- total: skills.length,
48
- ready: skills.filter((s) => s.status === 'ready').length,
49
- missing: skills.filter((s) => s.status === 'missing').length,
50
- skills
51
- };
52
- }
53
- sendJson(res, 200, { ok: true, ...skillsData });
54
- return;
55
- }
56
- catch (error) {
57
- api.logger.error(`Skills API error: ${error.message}`);
58
- sendJson(res, 500, { ok: false, error: error.message });
59
- return;
60
- }
61
- }
62
- sendJson(res, 405, { ok: false, error: "Method Not Allowed" });
63
- };
64
- }
@@ -1,30 +0,0 @@
1
- import os from "node:os";
2
- import path from "node:path";
3
- import { getWorkclawLogger } from "../runtime.js";
4
- export function resolveWorkspaceDir(api) {
5
- const agents = api.config.agents?.list ?? [];
6
- const defaultAgent = agents.find((agent) => agent?.default === true) ??
7
- agents.find((agent) => String(agent?.id ?? "").toLowerCase() === "main");
8
- const workspaceRaw = (typeof defaultAgent?.workspace === "string" && defaultAgent.workspace.trim()) ||
9
- (typeof api.config.agents?.defaults?.workspace === "string" &&
10
- api.config.agents.defaults.workspace.trim());
11
- getWorkclawLogger().info(`workspaceRaw: ${workspaceRaw}`);
12
- if (workspaceRaw) {
13
- return api.resolvePath(workspaceRaw);
14
- }
15
- const profile = process.env.OPENCLAW_PROFILE?.trim();
16
- const suffix = profile && profile.toLowerCase() !== "default" ? `workspace-${profile}` : "workspace";
17
- return path.join(os.homedir(), ".openclaw", suffix);
18
- }
19
- export function isDefaultWorkspace(api) {
20
- const agents = api.config.agents?.list ?? [];
21
- const defaultAgent = agents.find((agent) => agent?.default === true) ??
22
- agents.find((agent) => String(agent?.id ?? "").toLowerCase() === "main");
23
- const workspaceRaw = (typeof defaultAgent?.workspace === "string" && defaultAgent.workspace.trim()) ||
24
- (typeof api.config.agents?.defaults?.workspace === "string" &&
25
- api.config.agents.defaults.workspace.trim());
26
- if (workspaceRaw)
27
- return false;
28
- const profile = process.env.OPENCLAW_PROFILE?.trim();
29
- return !profile || profile.toLowerCase() === "default";
30
- }
@@ -1,199 +0,0 @@
1
- import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
2
- import { formatPairingApproveHint } from "openclaw/plugin-sdk/core";
3
- import { buildChannelConfigSchema } from "openclaw/plugin-sdk/channel-config-schema";
4
- import { isWorkclawAccountConfigured, listWorkclawAccountIds, resolveWorkclawAccount, } from "./accounts.js";
5
- import { WorkclawConfigSchema } from "./config-schema.js";
6
- import { sendMessageWorkclaw } from "./outbound/index.js";
7
- import { getWorkclawRuntime, getWorkclawWsConnection, getLastInboundAt, getLastOutboundAt } from "./runtime.js";
8
- import { startWorkclawGateway, stopWorkclawGateway } from "./gateway/workclaw-gateway.js";
9
- import { appendFileSync } from "fs";
10
- import { join } from "path";
11
- import { homedir } from "os";
12
- const meta = {
13
- id: "openclaw-workclaw",
14
- label: "智小途",
15
- selectionLabel: "智小途",
16
- docsPath: "/channels/openclaw-workclaw",
17
- docsLabel: "智小途",
18
- blurb: "智小途 OpenClaw通道",
19
- aliases: [],
20
- order: 90,
21
- };
22
- /**
23
- * 写入文件日志到磁盘
24
- * @param message 日志消息
25
- */
26
- function writeFileLog(message) {
27
- const timestamp = new Date().toISOString();
28
- const logLine = `[${timestamp}] ${message}\n`;
29
- const logDir = join(homedir(), ".openclaw", "logs");
30
- const logFile = join(logDir, "sendtext-outbound.log");
31
- try {
32
- appendFileSync(logFile, logLine);
33
- }
34
- catch (err) {
35
- console.error(`[writeFileLog] Failed to write log: ${err}`);
36
- }
37
- }
38
- export const workclawDock = {
39
- id: "openclaw-workclaw",
40
- capabilities: {
41
- chatTypes: ["direct", "group"],
42
- media: true,
43
- blockStreaming: true,
44
- },
45
- };
46
- export const workclawPlugin = {
47
- id: "openclaw-workclaw",
48
- meta,
49
- capabilities: {
50
- chatTypes: ["direct", "group"],
51
- media: true,
52
- reactions: false,
53
- threads: false,
54
- polls: false,
55
- nativeCommands: false,
56
- blockStreaming: true,
57
- },
58
- reload: { configPrefixes: ["channels.openclaw-workclaw"] },
59
- configSchema: buildChannelConfigSchema(WorkclawConfigSchema),
60
- config: {
61
- listAccountIds: (cfg) => listWorkclawAccountIds(cfg),
62
- resolveAccount: (cfg, accountId) => resolveWorkclawAccount({ cfg: cfg, accountId }),
63
- isConfigured: (account) => isWorkclawAccountConfigured(account.config),
64
- describeAccount: (account) => ({
65
- accountId: account.accountId,
66
- name: account.name,
67
- enabled: account.enabled,
68
- configured: isWorkclawAccountConfigured(account.config),
69
- }),
70
- },
71
- outbound: {
72
- deliveryMode: "direct",
73
- chunker: (text, _limit) => [text],
74
- textChunkLimit: 4096,
75
- sendText: async ({ to, text, accountId, cfg, replyToId }) => {
76
- writeFileLog(`outbound sendText called: replyToId=${replyToId}, accountId=${accountId}, to=${to}, text=${text.substring(0, 100)}`);
77
- const result = await sendMessageWorkclaw({
78
- accountId: accountId ?? undefined,
79
- cfg: cfg,
80
- to,
81
- text,
82
- ...(replyToId ? { replyToMessageId: replyToId } : {}),
83
- });
84
- return {
85
- channel: "openclaw-workclaw",
86
- ok: true,
87
- messageId: result.messageId,
88
- };
89
- },
90
- sendMedia: async ({ to, text, mediaUrl, accountId, cfg }) => {
91
- if (!mediaUrl && !text.trim()) {
92
- throw new Error("mediaUrl is required for outbound media");
93
- }
94
- const log = getWorkclawRuntime().log ?? console.log;
95
- if (typeof log === "function") {
96
- log(`outbound sendMedia called for ${to} with text ${text} and mediaUrl ${mediaUrl}`);
97
- }
98
- else if (log?.info) {
99
- log.info(`outbound sendMedia called for ${to} with text ${text} and mediaUrl ${mediaUrl}`);
100
- }
101
- const messageText = text.trim() ? text : mediaUrl ?? "";
102
- const result = await sendMessageWorkclaw({
103
- accountId: accountId ?? undefined,
104
- cfg: cfg,
105
- to,
106
- text: messageText,
107
- mediaUrl: mediaUrl ?? undefined,
108
- });
109
- return {
110
- channel: "openclaw-workclaw",
111
- ok: true,
112
- messageId: result.messageId,
113
- };
114
- },
115
- },
116
- security: {
117
- resolveDmPolicy: ({ cfg, accountId, account }) => {
118
- const resolvedAccountId = accountId ?? account.accountId ?? DEFAULT_ACCOUNT_ID;
119
- const channelConfig = cfg.channels?.["openclaw-workclaw"];
120
- const useAccountPath = Boolean(channelConfig?.accounts?.[resolvedAccountId]);
121
- const basePath = useAccountPath
122
- ? `channels.openclaw-workclaw.accounts.${resolvedAccountId}.`
123
- : "channels.openclaw-workclaw.";
124
- return {
125
- policy: account.config.dmPolicy ?? "open",
126
- allowFrom: account.config.allowFrom ?? ["*"],
127
- policyPath: `${basePath}dmPolicy`,
128
- allowFromPath: `${basePath}allowFrom`,
129
- approveHint: formatPairingApproveHint("openclaw-workclaw"),
130
- normalizeEntry: (raw) => raw.replace(/^openclaw-workclaw:/i, ""),
131
- };
132
- },
133
- },
134
- status: {
135
- buildAccountSnapshot: async ({ account, cfg }) => {
136
- // WebSocket 用 appKey 存储
137
- const wsKey = account.config.appKey;
138
- const ws = wsKey ? getWorkclawWsConnection(wsKey) : undefined;
139
- const isConnected = ws && ws.readyState === 1; // WebSocket.OPEN = 1
140
- const lastInboundAt = account.accountId ? getLastInboundAt(account.accountId) : undefined;
141
- const lastOutboundAt = account.accountId ? getLastOutboundAt(account.accountId) : undefined;
142
- return {
143
- accountId: account.accountId,
144
- name: account.name,
145
- enabled: account.enabled,
146
- configured: account.configured,
147
- connected: isConnected,
148
- running: account.enabled && account.configured,
149
- lastInboundAt: lastInboundAt ?? null,
150
- lastOutboundAt: lastOutboundAt ?? null,
151
- };
152
- },
153
- },
154
- gateway: {
155
- startAccount: async (ctx) => {
156
- const { setStatus, getStatus, account, accountId, cfg, log } = ctx;
157
- log?.info?.(`startAccount called for ${accountId}`);
158
- await startWorkclawGateway({
159
- accountId,
160
- account,
161
- cfg,
162
- log,
163
- });
164
- setStatus({
165
- ...getStatus(),
166
- running: true,
167
- lastStartAt: Date.now(),
168
- lastError: null,
169
- });
170
- log?.info?.(`startAccount completed for ${accountId}, keeping pending until abort`);
171
- // 保持 pending 状态直到 abortSignal 触发(防止 OpenClaw 3.8 认为启动立即退出)
172
- await new Promise((resolve) => {
173
- if (ctx.abortSignal.aborted) {
174
- resolve();
175
- return;
176
- }
177
- ctx.abortSignal.addEventListener("abort", () => resolve(), { once: true });
178
- });
179
- // abort 触发后,清理资源
180
- log?.info?.(`startAccount abort signal received for ${accountId}`);
181
- stopWorkclawGateway(accountId);
182
- setStatus({
183
- ...getStatus(),
184
- running: false,
185
- lastStopAt: Date.now(),
186
- });
187
- },
188
- stopAccount: async (ctx) => {
189
- const { setStatus, getStatus, accountId, account } = ctx;
190
- // Stop WorkClaw gateway
191
- stopWorkclawGateway(accountId);
192
- setStatus({
193
- ...getStatus(),
194
- running: false,
195
- lastStopAt: Date.now(),
196
- });
197
- },
198
- },
199
- };
@@ -1,56 +0,0 @@
1
- import { z } from 'zod';
2
- export { z };
3
- const DmPolicySchema = z.enum(["open"]);
4
- const WorkclawConnectionModeSchema = z.enum(["websocket"]);
5
- export const workclawAccountConfigSchema = z
6
- .object({
7
- enabled: z.boolean().optional(),
8
- name: z.string().optional(),
9
- agentId: z.union([z.string(), z.number()]).optional(),
10
- userId: z.union([z.string(), z.number()]).optional(),
11
- openConversationId: z.string().optional(),
12
- dmPolicy: DmPolicySchema.optional(),
13
- allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
14
- mediaMaxMb: z.number().positive().optional(),
15
- allowInsecureTls: z.boolean().optional(),
16
- })
17
- .strict();
18
- export const WorkclawConfigSchema = z
19
- .object({
20
- enabled: z.boolean().optional(),
21
- connectionMode: WorkclawConnectionModeSchema.optional().default("websocket"),
22
- baseUrl: z.string().url().optional(),
23
- websocketUrl: z.string().url().optional(),
24
- appKey: z.string().optional(),
25
- appSecret: z.string().optional(),
26
- agentId: z.union([z.string(), z.number()]).optional(),
27
- localIp: z.string().optional(),
28
- userId: z.union([z.string(), z.number()]).optional(),
29
- requestTimeout: z.number().int().positive().optional(),
30
- allowInsecureTls: z.boolean().optional(),
31
- allowRawJsonPayload: z.boolean().optional(),
32
- uploadUrl: z.string().url().optional(),
33
- uploadFieldName: z.string().optional(),
34
- uploadHeaders: z.record(z.string(), z.string()).optional(),
35
- uploadFormFields: z
36
- .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
37
- .optional(),
38
- uploadResponseUrlPath: z.string().optional(),
39
- dmPolicy: DmPolicySchema.optional().default('open'),
40
- allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
41
- mediaMaxMb: z.number().positive().optional(),
42
- accounts: z.record(z.string(), workclawAccountConfigSchema.optional()).optional(),
43
- })
44
- .strict()
45
- .superRefine((value, ctx) => {
46
- const allowFrom = value.allowFrom ?? [];
47
- const hasWildcard = allowFrom.some(entry => String(entry).trim() === '*');
48
- if (!hasWildcard) {
49
- ctx.addIssue({
50
- code: z.ZodIssueCode.custom,
51
- path: ['allowFrom'],
52
- message: 'channels.openclaw-workclaw.allowFrom must include "*"',
53
- });
54
- }
55
- });
56
- export const workclawConfigSchema = WorkclawConfigSchema;