@workclaw/openclaw-workclaw 1.0.18 → 1.0.20

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 (145) hide show
  1. package/README.md +30 -11
  2. package/dist/api.d.ts +3 -0
  3. package/dist/api.js +3 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.js +264 -0
  6. package/dist/setup-entry.d.ts +2 -0
  7. package/dist/setup-entry.js +12 -0
  8. package/dist/src/accounts.d.ts +66 -0
  9. package/dist/src/accounts.js +279 -0
  10. package/dist/src/api/accounts-api.d.ts +2 -0
  11. package/dist/src/api/accounts-api.js +130 -0
  12. package/dist/src/api/prompts-api.d.ts +2 -0
  13. package/dist/src/api/prompts-api.js +103 -0
  14. package/dist/src/api/session-api.d.ts +2 -0
  15. package/dist/src/api/session-api.js +207 -0
  16. package/dist/src/api/skills-api.d.ts +2 -0
  17. package/dist/src/api/skills-api.js +64 -0
  18. package/dist/src/api/workspace.d.ts +3 -0
  19. package/dist/src/api/workspace.js +30 -0
  20. package/dist/src/channel.d.ts +11 -0
  21. package/{src/channel.ts → dist/src/channel.js} +199 -225
  22. package/dist/src/config-schema.d.ts +93 -0
  23. package/dist/src/config-schema.js +56 -0
  24. package/dist/src/connection/workclaw-client.d.ts +147 -0
  25. package/dist/src/connection/workclaw-client.js +351 -0
  26. package/dist/src/gateway/agent-handlers.d.ts +12 -0
  27. package/{src/gateway/agent-handlers.ts → dist/src/gateway/agent-handlers.js} +372 -462
  28. package/dist/src/gateway/config-writer.d.ts +71 -0
  29. package/dist/src/gateway/config-writer.js +302 -0
  30. package/dist/src/gateway/cron-tasks-handler.d.ts +19 -0
  31. package/dist/src/gateway/cron-tasks-handler.js +188 -0
  32. package/dist/src/gateway/message-context.d.ts +80 -0
  33. package/{src/gateway/message-context.ts → dist/src/gateway/message-context.js} +509 -594
  34. package/dist/src/gateway/message-dispatcher.d.ts +18 -0
  35. package/dist/src/gateway/message-dispatcher.js +572 -0
  36. package/dist/src/gateway/reconnect.d.ts +27 -0
  37. package/{src/gateway/reconnect.ts → dist/src/gateway/reconnect.js} +210 -253
  38. package/dist/src/gateway/skills-handler.d.ts +29 -0
  39. package/dist/src/gateway/skills-handler.js +615 -0
  40. package/dist/src/gateway/skills-list-handler.d.ts +27 -0
  41. package/dist/src/gateway/skills-list-handler.js +233 -0
  42. package/dist/src/gateway/tools-list-handler.d.ts +30 -0
  43. package/dist/src/gateway/tools-list-handler.js +101 -0
  44. package/dist/src/gateway/workclaw-gateway.d.ts +14 -0
  45. package/dist/src/gateway/workclaw-gateway.js +237 -0
  46. package/dist/src/media/upload.d.ts +13 -0
  47. package/dist/src/media/upload.js +125 -0
  48. package/dist/src/outbound/index.d.ts +36 -0
  49. package/dist/src/outbound/index.js +123 -0
  50. package/dist/src/outbound/workclaw-sender.d.ts +36 -0
  51. package/{src/outbound/workclaw-sender.ts → dist/src/outbound/workclaw-sender.js} +95 -158
  52. package/dist/src/runtime.d.ts +116 -0
  53. package/dist/src/runtime.js +374 -0
  54. package/dist/src/secret-contract-api.d.ts +4 -0
  55. package/dist/src/secret-contract-api.js +4 -0
  56. package/{src/send.ts → dist/src/send.d.ts} +1 -1
  57. package/dist/src/send.js +1 -0
  58. package/dist/src/setup-api.d.ts +3 -0
  59. package/dist/src/setup-api.js +3 -0
  60. package/dist/src/setup-core.d.ts +3 -0
  61. package/dist/src/setup-core.js +13 -0
  62. package/dist/src/setup-surface.d.ts +7 -0
  63. package/dist/src/setup-surface.js +363 -0
  64. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +93 -0
  65. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +209 -0
  66. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +10 -0
  67. package/{src/tools/openclaw-workclaw-cron/index.ts → dist/src/tools/openclaw-workclaw-cron/index.js} +33 -39
  68. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +16 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +152 -0
  70. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +18 -0
  71. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +162 -0
  72. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +14 -0
  73. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +80 -0
  74. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +14 -0
  75. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +107 -0
  76. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +14 -0
  77. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +80 -0
  78. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +14 -0
  79. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +107 -0
  80. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +17 -0
  81. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +127 -0
  82. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +14 -0
  83. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +87 -0
  84. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +14 -0
  85. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +107 -0
  86. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +17 -0
  87. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +164 -0
  88. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +18 -0
  89. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +135 -0
  90. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +52 -0
  91. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +4 -0
  92. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +40 -0
  93. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +122 -0
  94. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +10 -0
  95. package/{src/tools/openclaw-workclaw-system/index.ts → dist/src/tools/openclaw-workclaw-system/index.js} +15 -17
  96. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +8 -0
  97. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +64 -0
  98. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +8 -0
  99. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +78 -0
  100. package/{src/types.ts → dist/src/types.d.ts} +39 -58
  101. package/dist/src/types.js +1 -0
  102. package/dist/src/utils/content.d.ts +15 -0
  103. package/{src/utils/content.ts → dist/src/utils/content.js} +38 -35
  104. package/package.json +13 -9
  105. package/index.ts +0 -302
  106. package/setup-entry.ts +0 -6
  107. package/src/accounts.ts +0 -312
  108. package/src/api/accounts-api.ts +0 -156
  109. package/src/api/prompts-api.ts +0 -116
  110. package/src/api/session-api.ts +0 -238
  111. package/src/api/skills-api.ts +0 -72
  112. package/src/api/workspace.ts +0 -41
  113. package/src/config-schema.ts +0 -110
  114. package/src/connection/workclaw-client.ts +0 -643
  115. package/src/gateway/config-writer.ts +0 -296
  116. package/src/gateway/message-dispatcher.ts +0 -641
  117. package/src/gateway/skills-handler.ts +0 -741
  118. package/src/gateway/skills-list-handler.ts +0 -332
  119. package/src/gateway/tools-list-handler.ts +0 -160
  120. package/src/gateway/workclaw-gateway.ts +0 -367
  121. package/src/media/upload.ts +0 -157
  122. package/src/outbound/index.ts +0 -185
  123. package/src/runtime.ts +0 -497
  124. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  125. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
  126. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  127. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  128. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  129. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  130. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  131. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  132. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  133. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  134. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
  135. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  136. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  137. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  138. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  139. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  140. package/tests/accounts.test.ts +0 -285
  141. package/tests/message-context.test.ts +0 -313
  142. package/tests/reconnect.test.ts +0 -257
  143. package/tests/workclaw-client.test.ts +0 -112
  144. package/tsconfig.json +0 -14
  145. package/vitest.config.ts +0 -8
@@ -1,238 +0,0 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- import { getWorkclawRuntime } from "../runtime.js";
3
-
4
- function sendJson(res: any, statusCode: number, payload: unknown) {
5
- res.statusCode = statusCode;
6
- res.setHeader("Content-Type", "application/json");
7
- res.end(JSON.stringify(payload));
8
- }
9
-
10
- async function readRequestBody(req: any): Promise<string> {
11
- const chunks: Buffer[] = [];
12
- await new Promise<void>((resolve, reject) => {
13
- req.on("data", (chunk: any) => {
14
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
15
- });
16
- req.on("end", () => resolve());
17
- req.on("error", (err: unknown) => reject(err));
18
- });
19
- return Buffer.concat(chunks).toString("utf-8");
20
- }
21
-
22
- /**
23
- * 构建会话 key
24
- * 格式: openclaw-workclaw:{accountId}:{userId}
25
- */
26
- function buildSessionKey(accountId: string, userId: string): string {
27
- return `openclaw-workclaw:${accountId}:${userId}`;
28
- }
29
-
30
- /**
31
- * 解析会话 key
32
- */
33
- function parseSessionKey(sessionKey: string): {
34
- channel: string;
35
- accountId: string;
36
- userId: string;
37
- } | null {
38
- const parts = sessionKey.split(":");
39
- if (parts.length !== 3 || parts[0] !== "openclaw-workclaw") {
40
- return null;
41
- }
42
- return {
43
- channel: parts[0],
44
- accountId: parts[1],
45
- userId: parts[2],
46
- };
47
- }
48
-
49
- /**
50
- * 重置/开启新会话
51
- * 通过发送系统事件 /new 到指定会话
52
- */
53
- async function resetSession(
54
- sessionKey: string,
55
- log?: { info?: (msg: string) => void; error?: (msg: string) => void }
56
- ): Promise<{ success: boolean; message: string }> {
57
- try {
58
- const runtime = getWorkclawRuntime();
59
-
60
- // 使用 system.enqueueSystemEvent 发送 /new 命令
61
- runtime.system.enqueueSystemEvent("/new", {
62
- sessionKey,
63
- contextKey: null,
64
- });
65
-
66
- log?.info?.(`[SessionAPI] Sent /new command to session: ${sessionKey}`);
67
-
68
- return {
69
- success: true,
70
- message: `Session reset command sent to ${sessionKey}`,
71
- };
72
- } catch (err) {
73
- const errorMsg = `Failed to reset session: ${String(err)}`;
74
- log?.error?.(`[SessionAPI] ${errorMsg}`);
75
- return { success: false, message: errorMsg };
76
- }
77
- }
78
-
79
- /**
80
- * 获取会话存储路径
81
- */
82
- function getSessionStorePath(
83
- agentId?: string,
84
- log?: { info?: (msg: string) => void; error?: (msg: string) => void }
85
- ): string | null {
86
- try {
87
- const runtime = getWorkclawRuntime();
88
- const storePath = runtime.channel.session.resolveStorePath(undefined, {
89
- agentId,
90
- });
91
- return storePath;
92
- } catch (err) {
93
- log?.error?.(`[SessionAPI] Failed to resolve store path: ${String(err)}`);
94
- return null;
95
- }
96
- }
97
-
98
- /**
99
- * 读取会话最后更新时间
100
- */
101
- async function getSessionLastUpdated(
102
- sessionKey: string,
103
- log?: { info?: (msg: string) => void; error?: (msg: string) => void }
104
- ): Promise<number | null> {
105
- try {
106
- const runtime = getWorkclawRuntime();
107
- const storePath = runtime.channel.session.resolveStorePath();
108
- const updatedAt = runtime.channel.session.readSessionUpdatedAt({
109
- storePath,
110
- sessionKey,
111
- });
112
- return updatedAt ?? null;
113
- } catch (err) {
114
- log?.error?.(`[SessionAPI] Failed to read session updated at: ${String(err)}`);
115
- return null;
116
- }
117
- }
118
-
119
- export function createSessionApiHandler(api: OpenClawPluginApi) {
120
- return async (req: any, res: any) => {
121
- const method = String(req.method ?? "GET").toUpperCase();
122
- const url = new URL(req.url ?? "", "http://localhost");
123
- // 移除尾部斜杠并获取路径部分
124
- const fullPath = url.pathname.replace(/\/+$/, "");
125
- // 提取子路径(去掉 /openclaw-workclaw/sessions 前缀)
126
- const subPath = fullPath.replace(/^\/openclaw-workclaw\/sessions/, "").replace(/^\//, "") || "/";
127
-
128
- const log = {
129
- info: (msg: string) => api.logger?.info?.(`[SessionAPI] ${msg}`),
130
- error: (msg: string) => api.logger?.error?.(`[SessionAPI] ${msg}`),
131
- };
132
-
133
- log?.info?.(`[SessionAPI] ${method} ${fullPath} (subPath: ${subPath})`);
134
-
135
- // GET /sessions 或 /sessions/ - 列出会话信息
136
- if (method === "GET" && (subPath === "/" || subPath === "")) {
137
- const sessionKey = url.searchParams.get("sessionKey");
138
-
139
- if (sessionKey) {
140
- // 获取特定会话信息
141
- const parsed = parseSessionKey(sessionKey);
142
- const updatedAt = await getSessionLastUpdated(sessionKey, log);
143
-
144
- sendJson(res, 200, {
145
- ok: true,
146
- session: {
147
- sessionKey,
148
- parsed,
149
- lastUpdatedAt: updatedAt,
150
- lastUpdatedAtFormatted: updatedAt
151
- ? new Date(updatedAt).toISOString()
152
- : null,
153
- },
154
- });
155
- return;
156
- }
157
-
158
- // 返回 API 信息
159
- sendJson(res, 200, {
160
- ok: true,
161
- message: "Session Management API",
162
- endpoints: {
163
- "GET /sessions": "获取会话信息 (可选参数: sessionKey)",
164
- "POST /sessions/reset": "重置/开启新会话 (参数: accountId + userId 或直接提供 sessionKey)",
165
- "GET /sessions/store-path": "获取会话存储路径 (可选参数: agentId)",
166
- },
167
- });
168
- return;
169
- }
170
-
171
- // POST /sessions/reset - 重置会话
172
- if (method === "POST" && subPath === "reset") {
173
- const raw = await readRequestBody(req);
174
- let input: any = {};
175
- try {
176
- input = raw ? JSON.parse(raw) : {};
177
- } catch {
178
- sendJson(res, 400, { ok: false, error: "Invalid JSON" });
179
- return;
180
- }
181
-
182
- const { accountId, userId, sessionKey: directSessionKey } = input;
183
-
184
- let sessionKey: string;
185
- if (directSessionKey) {
186
- sessionKey = directSessionKey;
187
- } else if (accountId && userId) {
188
- sessionKey = buildSessionKey(accountId, userId);
189
- } else {
190
- sendJson(res, 400, {
191
- ok: false,
192
- error: "Missing required fields: either provide 'sessionKey' or both 'accountId' and 'userId'",
193
- });
194
- return;
195
- }
196
-
197
- const result = await resetSession(sessionKey, log);
198
-
199
- if (result.success) {
200
- sendJson(res, 200, {
201
- ok: true,
202
- message: result.message,
203
- sessionKey,
204
- });
205
- } else {
206
- sendJson(res, 500, {
207
- ok: false,
208
- error: result.message,
209
- sessionKey,
210
- });
211
- }
212
- return;
213
- }
214
-
215
- // GET /sessions/store-path - 获取会话存储路径
216
- if (method === "GET" && subPath === "store-path") {
217
- const agentId = url.searchParams.get("agentId") ?? undefined;
218
- const storePath = getSessionStorePath(agentId, log);
219
-
220
- if (storePath) {
221
- sendJson(res, 200, {
222
- ok: true,
223
- storePath,
224
- agentId: agentId ?? "default",
225
- });
226
- } else {
227
- sendJson(res, 500, {
228
- ok: false,
229
- error: "Failed to resolve session store path",
230
- });
231
- }
232
- return;
233
- }
234
-
235
- // 404
236
- sendJson(res, 404, { ok: false, error: "Not Found" });
237
- };
238
- }
@@ -1,72 +0,0 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- import { exec } from "node:child_process";
3
- import { promisify } from "node:util";
4
-
5
- const execAsync = promisify(exec);
6
-
7
- function sendJson(res: any, statusCode: number, payload: unknown) {
8
- res.statusCode = statusCode;
9
- res.setHeader("Content-Type", "application/json");
10
- res.end(JSON.stringify(payload));
11
- }
12
-
13
- export function createSkillsApiHandler(api: OpenClawPluginApi) {
14
- return async (req: any, res: any) => {
15
- const method = String(req.method ?? "GET").toUpperCase();
16
-
17
- if (method === "GET") {
18
- try {
19
- // 调用 openclaw skills list 命令
20
- const { stdout, stderr } = await execAsync("openclaw skills list --json", {
21
- timeout: 10000, // 10秒超时
22
- });
23
-
24
- if (stderr && !stdout) {
25
- api.logger.error(`Skills list error: ${stderr}`);
26
- sendJson(res, 500, { ok: false, error: "Failed to list skills" });
27
- return;
28
- }
29
-
30
- // 尝试解析JSON输出
31
- let skillsData: any;
32
- try {
33
- skillsData = JSON.parse(stdout);
34
- } catch {
35
- // 如果不支持--json输出,尝试解析文本输出
36
- const lines = stdout.split('\n');
37
- const skills = lines
38
- .filter((line: string) => line.trim() && !line.includes('Skills'))
39
- .map((line: string) => {
40
- const parts = line.split(/\s{2,}/).map((p: string) => p.trim());
41
- if (parts.length >= 3) {
42
- return {
43
- status: parts[0]?.includes('✓') ? 'ready' : 'missing',
44
- name: parts[1],
45
- description: parts[2],
46
- source: parts[3] || 'openclaw-bundled'
47
- };
48
- }
49
- return null;
50
- })
51
- .filter((s: any) => s !== null);
52
-
53
- skillsData = {
54
- total: skills.length,
55
- ready: skills.filter((s: any) => s.status === 'ready').length,
56
- missing: skills.filter((s: any) => s.status === 'missing').length,
57
- skills
58
- };
59
- }
60
-
61
- sendJson(res, 200, { ok: true, ...skillsData });
62
- return;
63
- } catch (error: any) {
64
- api.logger.error(`Skills API error: ${error.message}`);
65
- sendJson(res, 500, { ok: false, error: error.message });
66
- return;
67
- }
68
- }
69
-
70
- sendJson(res, 405, { ok: false, error: "Method Not Allowed" });
71
- };
72
- }
@@ -1,41 +0,0 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- import os from "node:os";
3
- import path from "node:path";
4
-
5
- export function resolveWorkspaceDir(api: OpenClawPluginApi): string {
6
- const agents = api.config.agents?.list ?? [];
7
- const defaultAgent =
8
- agents.find((agent) => agent?.default === true) ??
9
- agents.find((agent) => String(agent?.id ?? "").toLowerCase() === "main");
10
-
11
- const workspaceRaw =
12
- (typeof defaultAgent?.workspace === "string" && defaultAgent.workspace.trim()) ||
13
- (typeof api.config.agents?.defaults?.workspace === "string" &&
14
- api.config.agents.defaults.workspace.trim());
15
-
16
- if (workspaceRaw) {
17
- return api.resolvePath(workspaceRaw);
18
- }
19
-
20
- const profile = process.env.OPENCLAW_PROFILE?.trim();
21
- const suffix =
22
- profile && profile.toLowerCase() !== "default" ? `workspace-${profile}` : "workspace";
23
- return path.join(os.homedir(), ".openclaw", suffix);
24
- }
25
-
26
- export function isDefaultWorkspace(api: OpenClawPluginApi): boolean {
27
- const agents = api.config.agents?.list ?? [];
28
- const defaultAgent =
29
- agents.find((agent) => agent?.default === true) ??
30
- agents.find((agent) => String(agent?.id ?? "").toLowerCase() === "main");
31
-
32
- const workspaceRaw =
33
- (typeof defaultAgent?.workspace === "string" && defaultAgent.workspace.trim()) ||
34
- (typeof api.config.agents?.defaults?.workspace === "string" &&
35
- api.config.agents.defaults.workspace.trim());
36
-
37
- if (workspaceRaw) return false;
38
-
39
- const profile = process.env.OPENCLAW_PROFILE?.trim();
40
- return !profile || profile.toLowerCase() === "default";
41
- }
@@ -1,110 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- export { z }
4
-
5
- const DmPolicySchema = z.enum(["open", "pairing", "allowlist"]);
6
- const WorkclawConnectionModeSchema = z.enum(["websocket"]);
7
- const WsConnectionStrategySchema = z.enum(["per-account", "per-appKey"]);
8
-
9
- const DmConfigSchema = z
10
- .object({
11
- enabled: z.boolean().optional(),
12
- systemPrompt: z.string().optional(),
13
- })
14
- .strict()
15
- .optional()
16
-
17
- // Message render mode: auto (default) = detect markdown, raw = plain text, card = always card
18
- const RenderModeSchema = z.enum(['auto', 'raw', 'card']).optional()
19
- const ChannelHeartbeatVisibilitySchema = z
20
- .object({
21
- visibility: z.enum(['visible', 'hidden']).optional(),
22
- intervalMs: z.number().int().positive().optional(),
23
- })
24
- .strict()
25
- .optional()
26
-
27
- /**
28
- * Per-account config schema
29
- * Only fields that make sense to configure per-account.
30
- */
31
- export const workclawAccountConfigSchema = z
32
- .object({
33
- enabled: z.boolean().optional(),
34
- name: z.string().optional(),
35
- agentId: z.union([z.string(), z.number()]).optional(),
36
- userId: z.union([z.string(), z.number()]).optional(),
37
- openConversationId: z.string().optional(),
38
- replyEndpoint: z.string().optional(),
39
- pushEndpoint: z.string().optional(),
40
- dmPolicy: DmPolicySchema.optional(),
41
- allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
42
- requireMention: z.boolean().optional(),
43
- historyLimit: z.number().int().min(0).optional(),
44
- dmHistoryLimit: z.number().int().min(0).optional(),
45
- dms: z.record(z.string(), DmConfigSchema).optional(),
46
- textChunkLimit: z.number().int().positive().optional(),
47
- chunkMode: z.enum(['length', 'newline']).optional(),
48
- mediaMaxMb: z.number().positive().optional(),
49
- heartbeat: ChannelHeartbeatVisibilitySchema,
50
- renderMode: RenderModeSchema,
51
- })
52
- .strict()
53
-
54
- /**
55
- * Top-level plugin config schema
56
- */
57
- export const WorkclawConfigSchema = z
58
- .object({
59
- enabled: z.boolean().optional(),
60
- connectionMode: WorkclawConnectionModeSchema.optional().default("websocket"),
61
- wsConnectionStrategy: WsConnectionStrategySchema.optional().default("per-account"),
62
- baseUrl: z.string().url().optional(),
63
- websocketUrl: z.string().url().optional(),
64
- appKey: z.string().optional(),
65
- appSecret: z.string().optional(),
66
- agentId: z.union([z.string(), z.number()]).optional(),
67
- localIp: z.string().optional(),
68
- userId: z.union([z.string(), z.number()]).optional(),
69
- replyEndpoint: z.string().optional(),
70
- pushEndpoint: z.string().optional(),
71
- requestTimeout: z.number().int().positive().optional(),
72
- allowInsecureTls: z.boolean().optional(),
73
- allowRawJsonPayload: z.boolean().optional(),
74
- capabilities: z.array(z.string()).optional(),
75
- uploadUrl: z.string().url().optional(),
76
- uploadFieldName: z.string().optional(),
77
- uploadHeaders: z.record(z.string(), z.string()).optional(),
78
- uploadFormFields: z
79
- .record(z.string(), z.union([z.string(), z.number(), z.boolean()]))
80
- .optional(),
81
- uploadResponseUrlPath: z.string().optional(),
82
- dmPolicy: DmPolicySchema.optional().default('pairing'),
83
- allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
84
- historyLimit: z.number().int().min(0).optional(),
85
- dmHistoryLimit: z.number().int().min(0).optional(),
86
- dms: z.record(z.string(), DmConfigSchema).optional(),
87
- textChunkLimit: z.number().int().positive().optional(),
88
- chunkMode: z.enum(['length', 'newline']).optional(),
89
- mediaMaxMb: z.number().positive().optional(),
90
- heartbeat: ChannelHeartbeatVisibilitySchema,
91
- renderMode: RenderModeSchema,
92
- accounts: z.record(z.string(), workclawAccountConfigSchema.optional()).optional(),
93
- })
94
- .strict()
95
- .superRefine((value, ctx) => {
96
- if (value.dmPolicy === 'open') {
97
- const allowFrom = value.allowFrom ?? []
98
- const hasWildcard = allowFrom.some(entry => String(entry).trim() === '*')
99
- if (!hasWildcard) {
100
- ctx.addIssue({
101
- code: z.ZodIssueCode.custom,
102
- path: ['allowFrom'],
103
- message:
104
- 'channels.openclaw-workclaw.dmPolicy="open" requires channels.openclaw-workclaw.allowFrom to include "*"',
105
- })
106
- }
107
- }
108
- })
109
-
110
- export const workclawConfigSchema = WorkclawConfigSchema;