@workclaw/openclaw-workclaw 1.0.19 → 1.0.201

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.
@@ -1,15 +1,15 @@
1
- import { getWorkclawWsConnection, clearWorkclawWsConnection, createLogger, setWorkclawLoggerFromContext, registerAccountContext, unregisterAccountContext, getAppKeyByAccountId, getAllDispatchersByAppKey, getDispatcherByAppKeyAndAccountId, getReconnectScheduler, setReconnectScheduler, clearReconnectScheduler, tryStartConnecting, finishConnecting, setWorkclawConnectionConfig, clearWorkclawConnectionConfig, } from "../runtime.js";
2
- import { buildAccountMap, resolveAccountByUserIdAndAgentId } from "../accounts.js";
3
- import { dispatchWorkclawMessage } from "./message-dispatcher.js";
4
- import { parseWorkClawMessage } from "./message-context.js";
5
- import { createReconnectScheduler } from "./reconnect.js";
1
+ import { buildAccountMap, resolveAccountByUserIdAndAgentId } from '../accounts.js';
2
+ import { clearReconnectScheduler, clearWorkclawConnectionConfig, clearWorkclawWsConnection, createLogger, finishConnecting, getAllDispatchersByAppKey, getAppKeyByAccountId, getDispatcherByAppKeyAndAccountId, getReconnectScheduler, getWorkclawWsConnection, registerAccountContext, setReconnectScheduler, setWorkclawConnectionConfig, setWorkclawLoggerFromContext, tryStartConnecting, unregisterAccountContext, } from '../runtime.js';
3
+ import { parseWorkClawMessage } from './message-context.js';
4
+ import { dispatchWorkclawMessage } from './message-dispatcher.js';
5
+ import { createReconnectScheduler } from './reconnect.js';
6
6
  export async function startWorkclawGateway(options) {
7
7
  const { accountId, account, cfg, log } = options;
8
- const logger = createLogger("", log);
8
+ const logger = createLogger('', log);
9
9
  setWorkclawLoggerFromContext(logger);
10
10
  const rawConfig = account.config;
11
- const connectionMode = rawConfig.connectionMode || "websocket";
12
- if (connectionMode !== "websocket") {
11
+ const connectionMode = rawConfig.connectionMode || 'websocket';
12
+ if (connectionMode !== 'websocket') {
13
13
  throw new Error(`Unsupported connectionMode: ${connectionMode}`);
14
14
  }
15
15
  await startSharedWebSocket(options);
@@ -19,7 +19,7 @@ export async function startWorkclawGateway(options) {
19
19
  */
20
20
  async function startSharedWebSocket(options) {
21
21
  const { accountId, account, cfg, log } = options;
22
- const logger = createLogger("", log);
22
+ const logger = createLogger('', log);
23
23
  const rawConfig = account.config;
24
24
  const baseConfig = {
25
25
  baseUrl: rawConfig.baseUrl,
@@ -36,9 +36,9 @@ async function startSharedWebSocket(options) {
36
36
  openConversationId: rawConfig.openConversationId,
37
37
  };
38
38
  const appKey = baseConfig.appKey || accountId;
39
- const appKeyRaw = baseConfig.appKey ?? "";
39
+ const appKeyRaw = baseConfig.appKey ?? '';
40
40
  buildAccountMap(cfg);
41
- logger.info(`Gateway start accountId=${accountId} appKey=${appKeyRaw ? `${appKeyRaw.slice(0, 8)}...` : "missing"} baseUrl=${baseConfig.baseUrl ?? ""} websocketUrl=${baseConfig.websocketUrl ?? ""}`);
41
+ logger.info(`Gateway start accountId=${accountId} appKey=${appKeyRaw ? `${appKeyRaw.slice(0, 8)}...` : 'missing'} baseUrl=${baseConfig.baseUrl ?? ''} websocketUrl=${baseConfig.websocketUrl ?? ''}`);
42
42
  // 注册账号上下文
43
43
  const ctx = {
44
44
  accountId,
@@ -105,8 +105,8 @@ async function startSharedWebSocket(options) {
105
105
  // Cache the connection config to prevent cfg mutation issues during message sends
106
106
  // 每个账户都有自己的配置缓存
107
107
  setWorkclawConnectionConfig(accountId, {
108
- appKey: baseConfig.appKey ?? "",
109
- appSecret: baseConfig.appSecret ?? "",
108
+ appKey: baseConfig.appKey ?? '',
109
+ appSecret: baseConfig.appSecret ?? '',
110
110
  baseUrl: baseConfig.baseUrl,
111
111
  websocketUrl: baseConfig.websocketUrl,
112
112
  localIp: baseConfig.localIp,
@@ -124,33 +124,33 @@ function handleSharedMessage(appKey, data, cfg, logger) {
124
124
  return;
125
125
  }
126
126
  // ping/pong/disconnect 无需路由
127
- if (parsed.type === "ping") {
127
+ if (parsed.type === 'ping') {
128
128
  const ws = getWorkclawWsConnection(appKey);
129
129
  if (ws && ws.readyState === 1) { // OPEN
130
130
  const pongResponse = {
131
131
  code: 200,
132
- message: "pong",
133
- metadata: { contentType: "application/json" },
132
+ message: 'pong',
133
+ metadata: { contentType: 'application/json' },
134
134
  data: JSON.stringify(parsed.pongData),
135
135
  };
136
136
  ws.send(JSON.stringify(pongResponse));
137
137
  }
138
138
  return;
139
139
  }
140
- if (parsed.type === "disconnect") {
140
+ if (parsed.type === 'disconnect') {
141
141
  const ws = getWorkclawWsConnection(appKey);
142
142
  ws?.close();
143
143
  return;
144
144
  }
145
145
  // logger.info?.(`Gateway received message: ${data}`);
146
146
  // 根据消息类型确定 userId 和 agentId
147
- let userId = "";
148
- let agentId = "";
149
- if (parsed.type === "agent_message" && parsed.message) {
150
- userId = String(parsed.message.userId || "");
151
- agentId = String(parsed.message.agentId || "");
147
+ let userId = '';
148
+ let agentId = '';
149
+ if (parsed.type === 'agent_message' && parsed.message) {
150
+ userId = String(parsed.message.userId || '');
151
+ agentId = String(parsed.message.agentId || '');
152
152
  }
153
- else if (parsed.type === "agent_created") {
153
+ else if (parsed.type === 'agent_created') {
154
154
  // agent_created 触发新账号创建
155
155
  const allDispatchers = getAllDispatchersByAppKey(appKey);
156
156
  if (allDispatchers && allDispatchers.size > 0) {
@@ -161,21 +161,21 @@ function handleSharedMessage(appKey, data, cfg, logger) {
161
161
  }
162
162
  return;
163
163
  }
164
- else if (parsed.type === "agent_updated" || parsed.type === "agent_deleted") {
165
- userId = String(parsed.eventData?.futureId || parsed.eventData?.userId || "");
166
- agentId = String(parsed.eventData?.id || parsed.eventData?.agentId || "");
164
+ else if (parsed.type === 'agent_updated' || parsed.type === 'agent_deleted') {
165
+ userId = String(parsed.eventData?.futureId || parsed.eventData?.userId || '');
166
+ agentId = String(parsed.eventData?.id || parsed.eventData?.agentId || '');
167
167
  }
168
- else if (parsed.type === "tools_list" || parsed.type === "skills_list" || parsed.type === "skills_event") {
169
- userId = String(parsed.eventData?.userId || "");
170
- agentId = String(parsed.eventData?.agentId || "");
168
+ else if (parsed.type === 'tools_list' || parsed.type === 'skills_list' || parsed.type === 'skills_event') {
169
+ userId = String(parsed.eventData?.userId || '');
170
+ agentId = String(parsed.eventData?.agentId || '');
171
171
  }
172
- else if (parsed.type === "init_agent") {
173
- userId = String(parsed.eventData?.futureId || parsed.eventData?.userId || "");
174
- agentId = String(parsed.eventData?.id || parsed.eventData?.agentId || "");
172
+ else if (parsed.type === 'init_agent') {
173
+ userId = String(parsed.eventData?.futureId || parsed.eventData?.userId || '');
174
+ agentId = String(parsed.eventData?.id || parsed.eventData?.agentId || '');
175
175
  /**
176
176
  * 在 init_agent 中,配置文件的agentId 为空,所有无法通过 resolveAccountByUserIdAndAgentId 查找账户
177
177
  */
178
- const accountId = "default";
178
+ const accountId = 'default';
179
179
  const dispatcher = getDispatcherByAppKeyAndAccountId(appKey, accountId);
180
180
  if (dispatcher) {
181
181
  dispatchWorkclawMessage(data, dispatcher.ctx).catch((err) => {
@@ -187,6 +187,20 @@ function handleSharedMessage(appKey, data, cfg, logger) {
187
187
  }
188
188
  return;
189
189
  }
190
+ else if (parsed.type === 'cron_task_event') {
191
+ // 任务事件处理,使用默认账户
192
+ const accountId = 'default';
193
+ const dispatcher = getDispatcherByAppKeyAndAccountId(appKey, accountId);
194
+ if (dispatcher) {
195
+ dispatchWorkclawMessage(data, dispatcher.ctx).catch((err) => {
196
+ logger.error?.(`Dispatch error: ${String(err)}`);
197
+ });
198
+ }
199
+ else {
200
+ logger.warn?.(`Gateway (per-appKey) no dispatcher for accountId=${accountId}`);
201
+ }
202
+ return;
203
+ }
190
204
  else {
191
205
  // 未知消息类型,忽略
192
206
  return;
@@ -44,23 +44,23 @@ function getOpenclawWorkclawCronUpdateParamsTool(api) {
44
44
  return {
45
45
  name: 'openclaw-workclaw-cron-update-params',
46
46
  label: '智小途生成修改提醒参数',
47
- description: `【核心工具】生成修改提醒的 cronParams 参数。
48
-
49
- 📋 工作流程(必须按顺序执行):
50
- 1. 调用此工具获取 cronParams 参数
51
- 2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
52
- 3. 必须调用 openclaw-workclaw-cron-update-sync 同步到后端
53
-
54
- ⏰ 时间格式(核心!):
55
- - time 参数支持相对时间(如 "10m"、"1h"、"2d")和 cron 表达式
56
- - 工具会自动将所有时间统一转换为 cron 表达式
57
- - 严禁使用 --at 参数或其他绝对时间格式
58
- - 最终 CLI 命令必须使用 --cron 参数
59
-
60
- 🔒 强制规则:
61
- - schedule.kind 必须是 "cron"
62
- - 必须使用 --cron 参数传递 cron 表达式
63
-
47
+ description: `【核心工具】生成修改提醒的 cronParams 参数。
48
+
49
+ 📋 工作流程(必须按顺序执行):
50
+ 1. 调用此工具获取 cronParams 参数
51
+ 2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
52
+ 3. 必须调用 openclaw-workclaw-cron-update-sync 同步到后端
53
+
54
+ ⏰ 时间格式(核心!):
55
+ - time 参数支持相对时间(如 "10m"、"1h"、"2d")和 cron 表达式
56
+ - 工具会自动将所有时间统一转换为 cron 表达式
57
+ - 严禁使用 --at 参数或其他绝对时间格式
58
+ - 最终 CLI 命令必须使用 --cron 参数
59
+
60
+ 🔒 强制规则:
61
+ - schedule.kind 必须是 "cron"
62
+ - 必须使用 --cron 参数传递 cron 表达式
63
+
64
64
  ⚠️ 必须从 cron 工具返回值中确认更新成功`,
65
65
  parameters: UpdateParamsSchema,
66
66
  execute: async (_toolCallId, params) => {
package/package.json CHANGED
@@ -1,62 +1,53 @@
1
- {
2
- "name": "@workclaw/openclaw-workclaw",
3
- "type": "module",
4
- "version": "1.0.19",
5
- "description": "openclaw-workclaw channel plugin",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "files": [
12
- "dist",
13
- "!dist/tests",
14
- "!dist/**/*.test.js",
15
- "!dist/**/*.test.d.ts",
16
- "!dist/vitest.config.js",
17
- "!dist/vitest.config.d.ts",
18
- "templates",
19
- "skills",
20
- "openclaw.plugin.json"
21
- ],
22
- "scripts": {
23
- "build": "tsc"
24
- },
25
- "peerDependencies": {
26
- "openclaw": "2026.4.14",
27
- "typescript": "^5.6.3"
28
- },
29
- "dependencies": {
30
- "undici": "^7.16.0",
31
- "ws": "^8.19.0",
32
- "zod": "^4.3.6"
33
- },
34
- "openclaw": {
35
- "extensions": [
36
- "./dist/index.js"
37
- ],
38
- "setupEntry": "./dist/setup-entry.js",
39
- "channel": {
40
- "id": "openclaw-workclaw",
41
- "label": "openclaw-workclaw",
42
- "selectionLabel": "智小途",
43
- "docsPath": "/channels/openclaw-workclaw",
44
- "docsLabel": "openclaw-workclaw",
45
- "blurb": "智小途 企业通讯平台集成",
46
- "aliases": [
47
- "openclaw-workclaw"
48
- ],
49
- "order": 35,
50
- "quickstartAllowFrom": true
51
- },
52
- "compat": {
53
- "pluginApi": "2026.4.14",
54
- "minGatewayVersion": "2026.4.14"
55
- },
56
- "install": {
57
- "npmSpec": "@workclaw/openclaw-workclaw",
58
- "localPath": "extensions/openclaw-workclaw",
59
- "defaultChoice": "npm"
60
- }
61
- }
62
- }
1
+ {
2
+ "name": "@workclaw/openclaw-workclaw",
3
+ "type": "module",
4
+ "version": "1.0.201",
5
+ "description": "openclaw-workclaw channel plugin",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "openclaw.plugin.json",
14
+ "skills",
15
+ "templates"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc"
19
+ },
20
+ "dependencies": {
21
+ "undici": "^7.16.0",
22
+ "ws": "^8.19.0",
23
+ "zod": "^4.3.6"
24
+ },
25
+ "openclaw": {
26
+ "extensions": [
27
+ "./dist/index.js"
28
+ ],
29
+ "setupEntry": "./dist/setup-entry.js",
30
+ "channel": {
31
+ "id": "openclaw-workclaw",
32
+ "label": "openclaw-workclaw",
33
+ "selectionLabel": "智小途",
34
+ "docsPath": "/channels/openclaw-workclaw",
35
+ "docsLabel": "openclaw-workclaw",
36
+ "blurb": "智小途 企业通讯平台集成",
37
+ "aliases": [
38
+ "openclaw-workclaw"
39
+ ],
40
+ "order": 35,
41
+ "quickstartAllowFrom": true
42
+ },
43
+ "compat": {
44
+ "pluginApi": "2026.4.14",
45
+ "minGatewayVersion": "2026.4.14"
46
+ },
47
+ "install": {
48
+ "npmSpec": "@workclaw/openclaw-workclaw",
49
+ "localPath": "extensions/openclaw-workclaw",
50
+ "defaultChoice": "npm"
51
+ }
52
+ }
53
+ }