@workclaw/openclaw-workclaw 1.0.23 → 1.0.25
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/package.json +1 -1
- package/src/gateway/workclaw-gateway.ts +8 -2
- package/dist/api.d.ts +0 -3
- package/dist/api.js +0 -3
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -264
- package/dist/setup-entry.d.ts +0 -2
- package/dist/setup-entry.js +0 -12
- package/dist/src/accounts.d.ts +0 -66
- package/dist/src/accounts.js +0 -279
- package/dist/src/api/accounts-api.d.ts +0 -2
- package/dist/src/api/accounts-api.js +0 -130
- package/dist/src/api/prompts-api.d.ts +0 -2
- package/dist/src/api/prompts-api.js +0 -103
- package/dist/src/api/session-api.d.ts +0 -2
- package/dist/src/api/session-api.js +0 -207
- package/dist/src/api/skills-api.d.ts +0 -2
- package/dist/src/api/skills-api.js +0 -64
- package/dist/src/api/workspace.d.ts +0 -3
- package/dist/src/api/workspace.js +0 -30
- package/dist/src/channel.d.ts +0 -11
- package/dist/src/channel.js +0 -199
- package/dist/src/config-schema.d.ts +0 -93
- package/dist/src/config-schema.js +0 -56
- package/dist/src/connection/workclaw-client.d.ts +0 -147
- package/dist/src/connection/workclaw-client.js +0 -351
- package/dist/src/gateway/agent-handlers.d.ts +0 -12
- package/dist/src/gateway/agent-handlers.js +0 -433
- package/dist/src/gateway/config-writer.d.ts +0 -71
- package/dist/src/gateway/config-writer.js +0 -302
- package/dist/src/gateway/cron-tasks-handler.d.ts +0 -19
- package/dist/src/gateway/cron-tasks-handler.js +0 -188
- package/dist/src/gateway/message-context.d.ts +0 -80
- package/dist/src/gateway/message-context.js +0 -509
- package/dist/src/gateway/message-dispatcher.d.ts +0 -18
- package/dist/src/gateway/message-dispatcher.js +0 -572
- package/dist/src/gateway/reconnect.d.ts +0 -27
- package/dist/src/gateway/reconnect.js +0 -210
- package/dist/src/gateway/skills-handler.d.ts +0 -29
- package/dist/src/gateway/skills-handler.js +0 -615
- package/dist/src/gateway/skills-list-handler.d.ts +0 -27
- package/dist/src/gateway/skills-list-handler.js +0 -233
- package/dist/src/gateway/tools-list-handler.d.ts +0 -30
- package/dist/src/gateway/tools-list-handler.js +0 -101
- package/dist/src/gateway/workclaw-gateway.d.ts +0 -14
- package/dist/src/gateway/workclaw-gateway.js +0 -237
- package/dist/src/media/upload.d.ts +0 -13
- package/dist/src/media/upload.js +0 -125
- package/dist/src/outbound/index.d.ts +0 -36
- package/dist/src/outbound/index.js +0 -123
- package/dist/src/outbound/workclaw-sender.d.ts +0 -36
- package/dist/src/outbound/workclaw-sender.js +0 -95
- package/dist/src/runtime.d.ts +0 -116
- package/dist/src/runtime.js +0 -374
- package/dist/src/secret-contract-api.d.ts +0 -4
- package/dist/src/secret-contract-api.js +0 -4
- package/dist/src/send.d.ts +0 -1
- package/dist/src/send.js +0 -1
- package/dist/src/setup-api.d.ts +0 -3
- package/dist/src/setup-api.js +0 -3
- package/dist/src/setup-core.d.ts +0 -3
- package/dist/src/setup-core.js +0 -13
- package/dist/src/setup-surface.d.ts +0 -7
- package/dist/src/setup-surface.js +0 -363
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +0 -93
- package/dist/src/tools/openclaw-workclaw-cron/api/index.js +0 -209
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +0 -10
- package/dist/src/tools/openclaw-workclaw-cron/index.js +0 -33
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +0 -16
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +0 -152
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +0 -18
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +0 -162
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +0 -14
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +0 -80
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +0 -14
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +0 -107
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +0 -14
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +0 -80
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +0 -14
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +0 -107
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +0 -17
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +0 -127
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +0 -14
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +0 -87
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +0 -14
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +0 -107
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +0 -17
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +0 -164
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +0 -18
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +0 -135
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +0 -52
- package/dist/src/tools/openclaw-workclaw-cron/types/index.js +0 -4
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +0 -40
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +0 -122
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts +0 -10
- package/dist/src/tools/openclaw-workclaw-system/index.js +0 -15
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +0 -8
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +0 -64
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +0 -8
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +0 -78
- package/dist/src/types.d.ts +0 -39
- package/dist/src/types.js +0 -1
- package/dist/src/utils/content.d.ts +0 -15
- package/dist/src/utils/content.js +0 -38
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reconnect Scheduler - manages WebSocket reconnection with exponential backoff
|
|
3
|
-
*/
|
|
4
|
-
import { clearWorkclawTokenCache } from "../connection/workclaw-client.js";
|
|
5
|
-
import { openWorkclawConnection } from "../connection/workclaw-client.js";
|
|
6
|
-
import { Agent, WebSocket } from "undici";
|
|
7
|
-
import { setWorkclawWsConnection, clearWorkclawWsConnection } from "../runtime.js";
|
|
8
|
-
export function createReconnectScheduler(options) {
|
|
9
|
-
const { key, config, log, onMessage, onReconnectSuccess, onClose, onConnectingStarted } = options;
|
|
10
|
-
let reconnectBackoff = 5000;
|
|
11
|
-
let shouldStopReconnect = false;
|
|
12
|
-
let pendingReconnectTimer = null;
|
|
13
|
-
/** 正在进行的 doConnect() 的 promise,所有 caller 共享同一个结果 */
|
|
14
|
-
let pendingDoConnectPromise = null;
|
|
15
|
-
/**
|
|
16
|
-
* 核心建连逻辑,首次连接和重连复用同一套代码
|
|
17
|
-
* 返回 Promise,连接建立后 resolve,失败后决定是否重连
|
|
18
|
-
* 关键:重试时复用 pendingDoConnectPromise,所有 caller 共享同一个结果
|
|
19
|
-
* - 失败时:不删除 promise,让后续 connect() 调用者等待重试结果
|
|
20
|
-
* - 重试定时器触发时:复用同一 promise,不创建新的
|
|
21
|
-
*/
|
|
22
|
-
async function doConnect() {
|
|
23
|
-
// 如果已有进行中的 doConnect(失败后重试期间),复用同一 promise
|
|
24
|
-
if (pendingDoConnectPromise !== null) {
|
|
25
|
-
return pendingDoConnectPromise;
|
|
26
|
-
}
|
|
27
|
-
let resolveThis;
|
|
28
|
-
let rejectThis;
|
|
29
|
-
const p = new Promise((resolve, reject) => {
|
|
30
|
-
resolveThis = resolve;
|
|
31
|
-
rejectThis = reject;
|
|
32
|
-
});
|
|
33
|
-
// 设置后再调用 connection,后续 connect() 调用能立即看到它
|
|
34
|
-
pendingDoConnectPromise = p;
|
|
35
|
-
const tokenCacheKey = config.appKey || key;
|
|
36
|
-
clearWorkclawTokenCache(tokenCacheKey);
|
|
37
|
-
const connConfig = {
|
|
38
|
-
baseUrl: config.baseUrl || "",
|
|
39
|
-
websocketUrl: config.websocketUrl,
|
|
40
|
-
appKey: config.appKey,
|
|
41
|
-
appSecret: config.appSecret,
|
|
42
|
-
localIp: config.localIp,
|
|
43
|
-
allowInsecureTls: config.allowInsecureTls,
|
|
44
|
-
requestTimeout: config.requestTimeout,
|
|
45
|
-
};
|
|
46
|
-
let endpoint;
|
|
47
|
-
let ticket;
|
|
48
|
-
try {
|
|
49
|
-
const result = await openWorkclawConnection(tokenCacheKey, connConfig);
|
|
50
|
-
endpoint = result.endpoint;
|
|
51
|
-
ticket = result.ticket;
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
// openWorkclawConnection 失败时(如 AbortError),由 handleConnectError 决定是否重试
|
|
55
|
-
// 如果不重试则 reject promise;如果重试则保持 pending(后续 timer 会触发重试)
|
|
56
|
-
const willRetry = handleConnectError(String(err));
|
|
57
|
-
if (!willRetry) {
|
|
58
|
-
pendingDoConnectPromise = null;
|
|
59
|
-
rejectThis(err);
|
|
60
|
-
}
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
const url = `${endpoint}?ticket=${encodeURIComponent(ticket)}`;
|
|
64
|
-
const dispatcher = connConfig.allowInsecureTls
|
|
65
|
-
? new Agent({ connect: { rejectUnauthorized: false } })
|
|
66
|
-
: undefined;
|
|
67
|
-
const wsOptions = dispatcher ? { dispatcher } : undefined;
|
|
68
|
-
const ws = new WebSocket(url, wsOptions);
|
|
69
|
-
setWorkclawWsConnection(key, ws);
|
|
70
|
-
// 在 onopen 之前调用,让 waitForConnect() 释放锁
|
|
71
|
-
onConnectingStarted?.(ws);
|
|
72
|
-
// 统一用 resolveThis/rejectThis,ws.onopen 调用 resolveThis 让 await Promise 完成
|
|
73
|
-
ws.onopen = () => {
|
|
74
|
-
log?.info?.(`Gateway WebSocket connected endpoint=${endpoint}`);
|
|
75
|
-
reconnectBackoff = 5000;
|
|
76
|
-
onReconnectSuccess?.();
|
|
77
|
-
resolveThis();
|
|
78
|
-
};
|
|
79
|
-
ws.onerror = (event) => {
|
|
80
|
-
log?.error?.(`Gateway WebSocket error: ${String(event?.message ?? event)}`);
|
|
81
|
-
rejectThis(new Error(String(event?.message ?? event)));
|
|
82
|
-
};
|
|
83
|
-
ws.onclose = (event) => {
|
|
84
|
-
const code = String(event?.code ?? "");
|
|
85
|
-
const reason = String(event?.reason ?? "");
|
|
86
|
-
log?.warn?.(`Gateway WebSocket closed code=${code} reason=${reason}`);
|
|
87
|
-
clearWorkclawWsConnection(key);
|
|
88
|
-
if (onClose) {
|
|
89
|
-
onClose();
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
scheduleReconnect();
|
|
93
|
-
}
|
|
94
|
-
rejectThis(new Error(`WebSocket closed code=${code} reason=${reason}`));
|
|
95
|
-
};
|
|
96
|
-
ws.onmessage = (event) => {
|
|
97
|
-
const data = typeof event.data === "string" ? event.data : String(event.data ?? "");
|
|
98
|
-
log?.info?.(`Gateway WebSocket message received bytes=${data.length}`);
|
|
99
|
-
onMessage(data);
|
|
100
|
-
};
|
|
101
|
-
// 等待 ws.onopen 完成(resolveThis)或 ws.onerror/ws.onclose 失败(rejectThis)
|
|
102
|
-
await new Promise((resolve, reject) => {
|
|
103
|
-
const timeout = setTimeout(() => reject(new Error("websocket connection timeout")), 30000);
|
|
104
|
-
ws.addEventListener("open", () => { clearTimeout(timeout); resolve(); }, { once: true });
|
|
105
|
-
ws.addEventListener("error", (event) => { clearTimeout(timeout); reject(new Error(String(event?.message ?? event))); }, { once: true });
|
|
106
|
-
ws.addEventListener("close", (event) => { clearTimeout(timeout); reject(new Error(`websocket closed before ready code=${event?.code ?? ""} reason=${event?.reason ?? ""}`)); }, { once: true });
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const scheduleReconnect = () => {
|
|
110
|
-
if (shouldStopReconnect) {
|
|
111
|
-
log?.info?.(`Reconnect: Stopped due to previous auth failure`);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (pendingReconnectTimer !== null) {
|
|
115
|
-
log?.info?.(`Reconnect: Already scheduled, skipping duplicate`);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const jitter = Math.floor(Math.random() * 3000);
|
|
119
|
-
const delayMs = reconnectBackoff + jitter;
|
|
120
|
-
log?.info?.(`Reconnect: Scheduling in ${delayMs}ms (base=${reconnectBackoff} + jitter=${jitter}) key=${key}`);
|
|
121
|
-
pendingReconnectTimer = setTimeout(async () => {
|
|
122
|
-
pendingReconnectTimer = null;
|
|
123
|
-
// 清除旧的 pendingDoConnectPromise,确保 doConnect() 真正建立新连接
|
|
124
|
-
// 否则 doConnect() 会直接返回已 resolved 的旧 promise(第一次失败后 promise 没被清除)
|
|
125
|
-
pendingDoConnectPromise = null;
|
|
126
|
-
try {
|
|
127
|
-
log?.info?.(`Reconnect: Attempting... key=${key}`);
|
|
128
|
-
await doConnect();
|
|
129
|
-
log?.info?.(`Reconnect: Success`);
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
const errorStr = String(err);
|
|
133
|
-
log?.error?.(`Reconnect: Failed: ${errorStr}`);
|
|
134
|
-
const willRetry = handleConnectError(errorStr);
|
|
135
|
-
if (!willRetry) {
|
|
136
|
-
// 永久失败,清除 pending promise
|
|
137
|
-
pendingDoConnectPromise = null;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
// 错误不代表永久失败,调度下一次重连
|
|
141
|
-
scheduleReconnect();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}, delayMs);
|
|
145
|
-
};
|
|
146
|
-
/** 返回 true=会重试(promise 保持 pending),false=不重试(promise 应被 reject) */
|
|
147
|
-
function handleConnectError(errorStr) {
|
|
148
|
-
if (errorStr.includes("访问过于频繁")) {
|
|
149
|
-
log?.warn?.(`Reconnect: Rate limited, retrying with minimal backoff`);
|
|
150
|
-
if (pendingReconnectTimer !== null) {
|
|
151
|
-
clearTimeout(pendingReconnectTimer);
|
|
152
|
-
pendingReconnectTimer = null;
|
|
153
|
-
}
|
|
154
|
-
reconnectBackoff = 1000;
|
|
155
|
-
scheduleReconnect();
|
|
156
|
-
return true; // 会重试
|
|
157
|
-
}
|
|
158
|
-
const isAuthError = errorStr.includes('"errCode":2001') ||
|
|
159
|
-
errorStr.includes('"code":2001') ||
|
|
160
|
-
errorStr.includes("鉴权失败") ||
|
|
161
|
-
errorStr.includes("invalid credentials") ||
|
|
162
|
-
errorStr.includes("unauthorized");
|
|
163
|
-
if (isAuthError) {
|
|
164
|
-
log?.error?.(`Reconnect: Authentication failed, stopping`);
|
|
165
|
-
shouldStopReconnect = true;
|
|
166
|
-
if (pendingReconnectTimer !== null) {
|
|
167
|
-
clearTimeout(pendingReconnectTimer);
|
|
168
|
-
pendingReconnectTimer = null;
|
|
169
|
-
}
|
|
170
|
-
return false; // 不重试
|
|
171
|
-
}
|
|
172
|
-
// 其他错误:重试
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* 首次连接或重连:调用 doConnect(),返回其 promise
|
|
177
|
-
* 如果 doConnect() 因失败正在重试(promise 仍 pending),返回同一 promise
|
|
178
|
-
* 调用方 await 此方法,连接建立后 resolve,失败且不重试时 reject
|
|
179
|
-
*/
|
|
180
|
-
async function connect() {
|
|
181
|
-
// 如果 doConnect() 正在进行中(失败后重试期间),返回同一 promise 让 caller 等待
|
|
182
|
-
if (pendingDoConnectPromise !== null) {
|
|
183
|
-
return pendingDoConnectPromise;
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
return await doConnect();
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
189
|
-
const errorStr = String(err);
|
|
190
|
-
log?.error?.(`Gateway connect failed: ${errorStr}`);
|
|
191
|
-
const willRetry = handleConnectError(errorStr);
|
|
192
|
-
if (!willRetry) {
|
|
193
|
-
// 不重试时,清除 pending promise,后续 connect() 可创建新的
|
|
194
|
-
pendingDoConnectPromise = null;
|
|
195
|
-
throw err;
|
|
196
|
-
}
|
|
197
|
-
// handleConnectError 返回 true 时,安排后续重试
|
|
198
|
-
// 注意:pendingDoConnectPromise 仍 pending,下次定时器触发时会清除它再真正重连
|
|
199
|
-
scheduleReconnect();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const stopReconnect = () => {
|
|
203
|
-
shouldStopReconnect = true;
|
|
204
|
-
if (pendingReconnectTimer !== null) {
|
|
205
|
-
clearTimeout(pendingReconnectTimer);
|
|
206
|
-
pendingReconnectTimer = null;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
return { connect, scheduleReconnect, stopReconnect };
|
|
210
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skills 事件处理器
|
|
3
|
-
* 处理云端下发的 skills 相关 EVENT 消息
|
|
4
|
-
* 通过 HTTP 回调返回结果
|
|
5
|
-
*/
|
|
6
|
-
export interface SkillsEventData {
|
|
7
|
-
topic: string;
|
|
8
|
-
requestId: string;
|
|
9
|
-
callbackUrl: string;
|
|
10
|
-
authToken?: string;
|
|
11
|
-
data: any;
|
|
12
|
-
}
|
|
13
|
-
export interface CallbackResponse {
|
|
14
|
-
userId?: string;
|
|
15
|
-
agentId?: string;
|
|
16
|
-
agentIds?: string[];
|
|
17
|
-
appKey?: string;
|
|
18
|
-
dotype?: string;
|
|
19
|
-
doStatus?: boolean;
|
|
20
|
-
doErrorMsg?: string;
|
|
21
|
-
dataList?: any[];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 处理 skills 事件
|
|
25
|
-
*/
|
|
26
|
-
export declare function handleSkillsEvent(eventData: SkillsEventData, token: string, baseUrl: string, appKey: string, log?: {
|
|
27
|
-
info?: (msg: string) => void;
|
|
28
|
-
error?: (msg: string) => void;
|
|
29
|
-
}): Promise<void>;
|