openclaw-openagent 1.0.0 → 1.0.2
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/dist/index.d.ts +25 -0
- package/dist/index.js +105 -0
- package/dist/src/app/channel-tools.d.ts +28 -0
- package/dist/src/app/channel-tools.js +251 -0
- package/dist/src/app/discovery-tools.d.ts +35 -0
- package/dist/src/app/discovery-tools.js +243 -0
- package/dist/src/app/download-file-tool.d.ts +10 -0
- package/dist/src/app/download-file-tool.js +104 -0
- package/dist/src/app/hooks.d.ts +14 -0
- package/dist/src/app/hooks.js +118 -0
- package/dist/src/app/index.d.ts +13 -0
- package/dist/src/app/index.js +44 -0
- package/dist/src/app/messaging-tools.d.ts +11 -0
- package/dist/src/app/messaging-tools.js +79 -0
- package/dist/src/app/ops-tools.d.ts +21 -0
- package/dist/src/app/ops-tools.js +158 -0
- package/dist/src/app/remote-agent-tool.d.ts +27 -0
- package/dist/src/app/remote-agent-tool.js +461 -0
- package/dist/src/app/types.d.ts +61 -0
- package/dist/src/app/types.js +11 -0
- package/dist/src/app/upload-file-tool.d.ts +16 -0
- package/dist/src/app/upload-file-tool.js +353 -0
- package/dist/src/app/verbose-preflight.d.ts +2 -0
- package/dist/src/app/verbose-preflight.js +145 -0
- package/dist/src/auth/config.d.ts +79 -0
- package/dist/src/auth/config.js +133 -0
- package/dist/src/auth/credential-manager.d.ts +65 -0
- package/dist/src/auth/credential-manager.js +122 -0
- package/dist/src/auth/index.d.ts +6 -0
- package/dist/src/auth/index.js +6 -0
- package/dist/src/auth/verify.d.ts +42 -0
- package/dist/src/auth/verify.js +60 -0
- package/dist/src/channel.d.ts +269 -0
- package/dist/src/channel.js +488 -0
- package/dist/src/compat.d.ts +37 -0
- package/dist/src/compat.js +70 -0
- package/dist/src/config/config-schema.d.ts +56 -0
- package/dist/src/config/config-schema.js +34 -0
- package/dist/src/messaging/aggregator.d.ts +25 -0
- package/dist/src/messaging/aggregator.js +90 -0
- package/dist/src/messaging/collector.d.ts +27 -0
- package/dist/src/messaging/collector.js +76 -0
- package/dist/src/messaging/executor.d.ts +14 -0
- package/dist/src/messaging/executor.js +59 -0
- package/dist/src/messaging/inbound.d.ts +97 -0
- package/dist/src/messaging/inbound.js +63 -0
- package/dist/src/messaging/index.d.ts +10 -0
- package/dist/src/messaging/index.js +9 -0
- package/dist/src/messaging/mention-protocol.d.ts +42 -0
- package/dist/src/messaging/mention-protocol.js +74 -0
- package/dist/src/messaging/process-c2c-request.d.ts +55 -0
- package/dist/src/messaging/process-c2c-request.js +445 -0
- package/dist/src/messaging/process-message.d.ts +62 -0
- package/dist/src/messaging/process-message.js +282 -0
- package/dist/src/messaging/scheduler.d.ts +17 -0
- package/dist/src/messaging/scheduler.js +47 -0
- package/dist/src/messaging/types.d.ts +34 -0
- package/dist/src/messaging/types.js +4 -0
- package/dist/src/plugin-ui/assets/openagent-override.js +9267 -0
- package/dist/src/plugin-ui/index.d.ts +13 -0
- package/dist/src/plugin-ui/index.js +16 -0
- package/dist/src/plugin-ui/ui-extension-loader/backup.d.ts +23 -0
- package/dist/src/plugin-ui/ui-extension-loader/backup.js +82 -0
- package/dist/src/plugin-ui/ui-extension-loader/index.d.ts +28 -0
- package/dist/src/plugin-ui/ui-extension-loader/index.js +240 -0
- package/dist/src/plugin-ui/ui-extension-loader/locator.d.ts +35 -0
- package/dist/src/plugin-ui/ui-extension-loader/locator.js +129 -0
- package/dist/src/plugin-ui/ui-extension-loader/manifest.d.ts +26 -0
- package/dist/src/plugin-ui/ui-extension-loader/manifest.js +45 -0
- package/dist/src/plugin-ui/ui-extension-loader/registry-regex.d.ts +9 -0
- package/dist/src/plugin-ui/ui-extension-loader/registry-regex.js +701 -0
- package/dist/src/plugin-ui/ui-extension-loader/removed-extensions.d.ts +8 -0
- package/dist/src/plugin-ui/ui-extension-loader/removed-extensions.js +58 -0
- package/dist/src/plugin-ui/ui-extension-loader/types.d.ts +55 -0
- package/dist/src/plugin-ui/ui-extension-loader/types.js +23 -0
- package/dist/src/proxy/auth-proxy.d.ts +20 -0
- package/dist/src/proxy/auth-proxy.js +337 -0
- package/dist/src/runtime/account.d.ts +156 -0
- package/dist/src/runtime/account.js +491 -0
- package/dist/src/runtime/index.d.ts +5 -0
- package/dist/src/runtime/index.js +6 -0
- package/dist/src/runtime/plugin-runtime.d.ts +40 -0
- package/dist/src/runtime/plugin-runtime.js +72 -0
- package/dist/src/runtime/registry.d.ts +41 -0
- package/dist/src/runtime/registry.js +60 -0
- package/dist/src/sdk/CLASS_MAP.md +143 -0
- package/dist/src/sdk/index.d.ts +126 -0
- package/dist/src/sdk/index.js +23990 -0
- package/dist/src/sdk/modules/cloud-search-module.js +1117 -0
- package/dist/src/sdk/modules/follow-module.js +1069 -0
- package/dist/src/sdk/modules/group-module.js +7397 -0
- package/dist/src/sdk/modules/relationship-module.js +2269 -0
- package/dist/src/sdk/modules/signaling-module.js +1468 -0
- package/dist/src/sdk/modules/tim-upload-plugin.js +730 -0
- package/dist/src/sdk/node-env/http-request.js +90 -0
- package/dist/src/sdk/node-env/index.js +57 -0
- package/dist/src/sdk/node-env/storage.js +114 -0
- package/dist/src/sdk/package.json +10 -0
- package/dist/src/sdk/sdk/CLASS_MAP.md +143 -0
- package/dist/src/sdk/sdk/index.d.ts +126 -0
- package/dist/src/sdk/sdk/index.js +23990 -0
- package/dist/src/sdk/sdk/modules/cloud-search-module.js +1117 -0
- package/dist/src/sdk/sdk/modules/follow-module.js +1069 -0
- package/dist/src/sdk/sdk/modules/group-module.js +7397 -0
- package/dist/src/sdk/sdk/modules/relationship-module.js +2269 -0
- package/dist/src/sdk/sdk/modules/signaling-module.js +1468 -0
- package/dist/src/sdk/sdk/modules/tim-upload-plugin.js +730 -0
- package/dist/src/sdk/sdk/node-env/http-request.js +90 -0
- package/dist/src/sdk/sdk/node-env/index.js +57 -0
- package/dist/src/sdk/sdk/node-env/storage.js +114 -0
- package/dist/src/sdk/sdk/package.json +10 -0
- package/dist/src/sdk/sdk/tsconfig.json +16 -0
- package/dist/src/sdk/tsconfig.json +16 -0
- package/dist/src/state/pending-invocation-store.d.ts +26 -0
- package/dist/src/state/pending-invocation-store.js +39 -0
- package/dist/src/state/store.d.ts +165 -0
- package/dist/src/state/store.js +535 -0
- package/dist/src/tim/c2c.d.ts +83 -0
- package/dist/src/tim/c2c.js +318 -0
- package/dist/src/tim/channels.d.ts +95 -0
- package/dist/src/tim/channels.js +279 -0
- package/dist/src/tim/client.d.ts +54 -0
- package/dist/src/tim/client.js +268 -0
- package/dist/src/tim/index.d.ts +6 -0
- package/dist/src/tim/index.js +6 -0
- package/dist/src/tim/messages.d.ts +50 -0
- package/dist/src/tim/messages.js +104 -0
- package/dist/src/tim/sdk-logger-init.d.ts +13 -0
- package/dist/src/tim/sdk-logger-init.js +46 -0
- package/dist/src/tools.d.ts +9 -0
- package/dist/src/tools.js +8 -0
- package/dist/src/transport/factory.d.ts +63 -0
- package/dist/src/transport/factory.js +54 -0
- package/dist/src/transport/oasn/index.d.ts +12 -0
- package/dist/src/transport/oasn/index.js +9 -0
- package/dist/src/transport/oasn/oasn-agent-card.d.ts +38 -0
- package/dist/src/transport/oasn/oasn-agent-card.js +102 -0
- package/dist/src/transport/oasn/oasn-discovery.d.ts +33 -0
- package/dist/src/transport/oasn/oasn-discovery.js +97 -0
- package/dist/src/transport/oasn/oasn-files.d.ts +64 -0
- package/dist/src/transport/oasn/oasn-files.js +174 -0
- package/dist/src/transport/oasn/oasn-http.d.ts +98 -0
- package/dist/src/transport/oasn/oasn-http.js +362 -0
- package/dist/src/transport/oasn/oasn-invocation.d.ts +154 -0
- package/dist/src/transport/oasn/oasn-invocation.js +432 -0
- package/dist/src/transport/oasn/oasn-normalize.d.ts +6 -0
- package/dist/src/transport/oasn/oasn-normalize.js +112 -0
- package/dist/src/transport/oasn/oasn-register.d.ts +19 -0
- package/dist/src/transport/oasn/oasn-register.js +24 -0
- package/dist/src/transport/oasn/oasn-transport.d.ts +114 -0
- package/dist/src/transport/oasn/oasn-transport.js +230 -0
- package/dist/src/transport/oasn/oasn-types.d.ts +331 -0
- package/dist/src/transport/oasn/oasn-types.js +44 -0
- package/dist/src/transport/tim/index.d.ts +7 -0
- package/dist/src/transport/tim/index.js +6 -0
- package/dist/src/transport/tim/tim-transport.d.ts +122 -0
- package/dist/src/transport/tim/tim-transport.js +402 -0
- package/dist/src/transport/types.d.ts +450 -0
- package/dist/src/transport/types.js +38 -0
- package/dist/src/util/http.d.ts +21 -0
- package/dist/src/util/http.js +93 -0
- package/dist/src/util/logger.d.ts +20 -0
- package/dist/src/util/logger.js +100 -0
- package/dist/src/util/url-resolver.d.ts +7 -0
- package/dist/src/util/url-resolver.js +20 -0
- package/index.ts +11 -0
- package/openclaw.plugin.json +9 -0
- package/package.json +7 -4
- package/src/app/download-file-tool.ts +133 -0
- package/src/app/hooks.ts +89 -5
- package/src/app/index.ts +6 -0
- package/src/app/remote-agent-tool.ts +46 -0
- package/src/app/types.ts +1 -0
- package/src/app/upload-file-tool.ts +411 -0
- package/src/plugin-ui/assets/openagent-override.js +1 -63
- package/src/plugin-ui/modules/agent-book/panel/agent-book.js +0 -61
- package/src/plugin-ui/modules/agent-book/panel/agent-data.js +0 -1
- package/src/plugin-ui/ui-extension-loader/registry-regex.ts +30 -13
- package/src/runtime/account.ts +0 -23
- package/src/transport/oasn/oasn-files.ts +5 -5
- package/src/transport/oasn/oasn-invocation.ts +44 -2
- package/src/transport/oasn/oasn-normalize.ts +0 -26
- package/src/transport/oasn/oasn-register.ts +8 -81
- package/src/transport/oasn/oasn-transport.ts +9 -32
- package/src/transport/oasn/oasn-types.ts +53 -6
- package/src/transport/types.ts +33 -36
- package/src/util/url-resolver.ts +17 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-env/http-request.js
|
|
3
|
+
*
|
|
4
|
+
* 替代 XMLHttpRequest,用 Node.js 内置 fetch() 实现。
|
|
5
|
+
* SDK 中两处使用 XMLHttpRequest:
|
|
6
|
+
* 1. Io 函数(网络诊断 getconninfo)— index.js L15844
|
|
7
|
+
* 2. ErrMsgModule._fetchErrCode(错误码表拉取)— index.js L21296
|
|
8
|
+
*
|
|
9
|
+
* 本模块导出两个函数,分别对应这两种用法。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 替代 Io 函数中的 XMLHttpRequest 用法。
|
|
14
|
+
* 功能:发送 HTTP 请求,3秒超时,返回 Promise。
|
|
15
|
+
*
|
|
16
|
+
* @param {string} method - HTTP 方法 (GET/POST)
|
|
17
|
+
* @param {string} url - 请求 URL
|
|
18
|
+
* @param {string} [body] - 请求体(POST 时)
|
|
19
|
+
* @param {Function} resolve - Promise resolve
|
|
20
|
+
* @param {Function} reject - Promise reject
|
|
21
|
+
* @param {Function} createError - 创建 SDK 错误对象的工厂函数 (code) => Error
|
|
22
|
+
* @param {object} errorCodes - { NETWORK_ERROR, NETWORK_TIMEOUT }
|
|
23
|
+
* @param {object} logger - SDK 日志对象 { l, w, e }
|
|
24
|
+
*/
|
|
25
|
+
export function httpDiagnose(method, url, body, resolve, reject, createError, errorCodes, logger) {
|
|
26
|
+
const controller = new AbortController();
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
controller.abort();
|
|
29
|
+
reject(createError(errorCodes.NETWORK_TIMEOUT));
|
|
30
|
+
}, 3000);
|
|
31
|
+
|
|
32
|
+
fetch(url, {
|
|
33
|
+
method,
|
|
34
|
+
headers: { "Content-type": "application/x-www-form-urlencoded;charset=UTF-8" },
|
|
35
|
+
body: body || undefined,
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
})
|
|
38
|
+
.then((res) => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
if (res.ok || res.status === 304) {
|
|
41
|
+
return res.text().then((text) => {
|
|
42
|
+
if (text && text.indexOf("NetCheckInfo") > -1) {
|
|
43
|
+
logger.l("getconninfo ok in node. ret:", JSON.parse(text));
|
|
44
|
+
}
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
reject(createError(errorCodes.NETWORK_ERROR));
|
|
49
|
+
})
|
|
50
|
+
.catch(() => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
reject(createError(errorCodes.NETWORK_TIMEOUT));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 替代 ErrMsgModule._fetchErrCode 中的 XMLHttpRequest 用法。
|
|
58
|
+
* 功能:GET 请求拉取错误码 JSON,3秒超时。
|
|
59
|
+
*
|
|
60
|
+
* @param {string} url - 错误码表 URL
|
|
61
|
+
* @param {string} contentType - Content-Type header
|
|
62
|
+
* @param {Function} resolve - Promise resolve,传入响应文本
|
|
63
|
+
* @param {Function} reject - Promise reject
|
|
64
|
+
* @param {object} logger - SDK 日志对象
|
|
65
|
+
*/
|
|
66
|
+
export function httpFetchText(url, contentType, resolve, reject, logger) {
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
const timer = setTimeout(() => {
|
|
69
|
+
controller.abort();
|
|
70
|
+
}, 3000);
|
|
71
|
+
|
|
72
|
+
fetch(url, {
|
|
73
|
+
method: "GET",
|
|
74
|
+
headers: { "Content-type": contentType },
|
|
75
|
+
signal: controller.signal,
|
|
76
|
+
})
|
|
77
|
+
.then((res) => {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
if (res.ok || res.status === 304) {
|
|
80
|
+
return res.text().then((text) => {
|
|
81
|
+
resolve(text);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
reject(res.status);
|
|
85
|
+
})
|
|
86
|
+
.catch((err) => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
reject(err);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-env/index.js
|
|
3
|
+
*
|
|
4
|
+
* SDK 的 Node.js 环境适配层。
|
|
5
|
+
* 在 import SDK 之前先 import 此文件,自动注入浏览器 API 的 Node.js 替代实现。
|
|
6
|
+
*
|
|
7
|
+
* 使用方式:
|
|
8
|
+
* import './node-env/index.js'; // 必须在 SDK import 之前
|
|
9
|
+
* import SDK from './index.js'; // SDK 正常使用
|
|
10
|
+
*
|
|
11
|
+
* 提供的替代能力:
|
|
12
|
+
* - localStorage → 内存 Map(支持 for...in 遍历)
|
|
13
|
+
* - navigator.cookieEnabled → true
|
|
14
|
+
* - httpDiagnose / httpFetchText → 通过 SDK 源码内引用
|
|
15
|
+
*
|
|
16
|
+
* 不在这里处理的(需要改 SDK 源码):
|
|
17
|
+
* - XMLHttpRequest → 在 index.js 中直接引用 http-request.js
|
|
18
|
+
* - unhandled rejection → 在 index.js send() 方法中加 .catch
|
|
19
|
+
* - OPENAGENT logger → 已有 globalThis.__OPENAGENT_SDK_LOGGER 机制
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import WS from "ws";
|
|
23
|
+
import { installStorage } from "./storage.js";
|
|
24
|
+
|
|
25
|
+
// ─── 替换 WebSocket(禁用 permessage-deflate)──────────────
|
|
26
|
+
// 根因:Node.js v22 内置 WebSocket 自动协商 permessage-deflate 扩展,
|
|
27
|
+
// 导致某些 WebSocket 帧(特别是 million_group_open_http_svc 社区群协议)
|
|
28
|
+
// 的响应数据被损坏或丢失。浏览器 WebSocket 不支持此扩展,SDK 设计时
|
|
29
|
+
// 假设接收的是未经传输层压缩的原始数据。
|
|
30
|
+
// 解决方案:用 ws npm 包替代内置 WebSocket,显式关闭 perMessageDeflate。
|
|
31
|
+
globalThis.WebSocket = class OpenAgentWebSocket extends WS {
|
|
32
|
+
constructor(url, protocols) {
|
|
33
|
+
super(url, protocols, { perMessageDeflate: false });
|
|
34
|
+
this.binaryType = "arraybuffer";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// ─── 安装 localStorage ────────────────────────────────────
|
|
39
|
+
installStorage();
|
|
40
|
+
|
|
41
|
+
// ─── unhandledRejection 安全网 ────────────────────────────
|
|
42
|
+
// 即使 SDK 内部的 send() 已加 p.catch(),仍需全局兜底
|
|
43
|
+
// 以防其他代码路径产生 unhandled rejection
|
|
44
|
+
if (!globalThis.__OPENAGENT_REJECTION_HANDLER_INSTALLED) {
|
|
45
|
+
process.on("unhandledRejection", (reason) => {
|
|
46
|
+
const code = reason?.code || "UNKNOWN";
|
|
47
|
+
const msg = reason?.message || "";
|
|
48
|
+
// 用 OPENAGENT logger(如果已注入)或 stderr
|
|
49
|
+
const logger = globalThis.__OPENAGENT_SDK_LOGGER;
|
|
50
|
+
if (logger) {
|
|
51
|
+
logger.warn(`[SDK] unhandled rejection: code=${code} ${msg}`);
|
|
52
|
+
} else {
|
|
53
|
+
console.error(`[SDK] unhandled rejection: code=${code} ${msg}`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
globalThis.__OPENAGENT_REJECTION_HANDLER_INSTALLED = true;
|
|
57
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-env/storage.js
|
|
3
|
+
*
|
|
4
|
+
* 替代浏览器 localStorage,用内存 Map 实现。
|
|
5
|
+
* SDK 通过 StorageModule(index.js L11400区)使用 localStorage。
|
|
6
|
+
*
|
|
7
|
+
* 原始 SDK 通过 _canIUseCookies() 检测:
|
|
8
|
+
* typeof window !== "undefined" && navigator.cookieEnabled && localStorage
|
|
9
|
+
* 在 Node.js 下返回 false → 所有存储操作被跳过。
|
|
10
|
+
*
|
|
11
|
+
* 本模块提供一个 localStorage 兼容对象。
|
|
12
|
+
* 使用方式:在 SDK import 前设置 globalThis.localStorage。
|
|
13
|
+
* 同时需要设置 globalThis.navigator.cookieEnabled = true。
|
|
14
|
+
*
|
|
15
|
+
* 注意:这是内存实现,进程退出后数据丢失。
|
|
16
|
+
* 对 Agent 场景足够——不需要跨进程持久化。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const _store = new Map();
|
|
20
|
+
|
|
21
|
+
const memoryStorage = {
|
|
22
|
+
getItem(key) {
|
|
23
|
+
return _store.has(key) ? _store.get(key) : null;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
setItem(key, value) {
|
|
27
|
+
_store.set(key, String(value));
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
removeItem(key) {
|
|
31
|
+
_store.delete(key);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
clear() {
|
|
35
|
+
_store.clear();
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
get length() {
|
|
39
|
+
return _store.size;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
key(index) {
|
|
43
|
+
const keys = [..._store.keys()];
|
|
44
|
+
return index < keys.length ? keys[index] : null;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 支持 for...in 遍历(SDK L11445: for (let e in localStorage))
|
|
49
|
+
* 通过 Proxy 在 install() 时实现
|
|
50
|
+
*/
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 安装 localStorage polyfill 到 globalThis。
|
|
55
|
+
* 使用 Proxy 支持 for...in 遍历和 hasOwnProperty 调用。
|
|
56
|
+
*
|
|
57
|
+
* 必须在 SDK import 之前调用。
|
|
58
|
+
*/
|
|
59
|
+
export function installStorage() {
|
|
60
|
+
// Proxy 让 for...in 和 hasOwnProperty 工作
|
|
61
|
+
const storageProxy = new Proxy(memoryStorage, {
|
|
62
|
+
ownKeys() {
|
|
63
|
+
return [..._store.keys()];
|
|
64
|
+
},
|
|
65
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
66
|
+
if (_store.has(prop)) {
|
|
67
|
+
return {
|
|
68
|
+
configurable: true,
|
|
69
|
+
enumerable: true,
|
|
70
|
+
value: _store.get(prop),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (prop in target) {
|
|
74
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
},
|
|
78
|
+
has(target, prop) {
|
|
79
|
+
return _store.has(prop) || prop in target;
|
|
80
|
+
},
|
|
81
|
+
get(target, prop) {
|
|
82
|
+
if (prop === "hasOwnProperty") {
|
|
83
|
+
return (key) => _store.has(key);
|
|
84
|
+
}
|
|
85
|
+
if (prop in target) {
|
|
86
|
+
const val = target[prop];
|
|
87
|
+
return typeof val === "function" ? val.bind(target) : val;
|
|
88
|
+
}
|
|
89
|
+
return _store.get(prop);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
globalThis.localStorage = storageProxy;
|
|
94
|
+
|
|
95
|
+
// navigator.cookieEnabled 让 _canIUseCookies() 返回 true
|
|
96
|
+
if (typeof globalThis.navigator === "undefined") {
|
|
97
|
+
globalThis.navigator = {};
|
|
98
|
+
}
|
|
99
|
+
globalThis.navigator.cookieEnabled = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 获取内部 store 的大小(调试用)
|
|
104
|
+
*/
|
|
105
|
+
export function getStorageSize() {
|
|
106
|
+
return _store.size;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 导出内存 store 的快照(调试用)
|
|
111
|
+
*/
|
|
112
|
+
export function getStorageSnapshot() {
|
|
113
|
+
return Object.fromEntries(_store);
|
|
114
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @tencentcloud/chat SDK v3.6.6 — Code Structure Map
|
|
2
|
+
|
|
3
|
+
> Annotated and formatted for readability. Logic 100% preserved from ESM distribution.
|
|
4
|
+
|
|
5
|
+
## Quick Navigation
|
|
6
|
+
|
|
7
|
+
### Core Infrastructure
|
|
8
|
+
|
|
9
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
10
|
+
|-------|-------------|-------|------|---------|
|
|
11
|
+
| `s` | — | L157-181 | 25 | Middleware chain |
|
|
12
|
+
| `i` | — | L182-202 | 21 | Uint64 implementation |
|
|
13
|
+
| `ni` | — (extends Error) | L3227-3243 | 17 | SDK custom error |
|
|
14
|
+
| `ui` | — | L3381-3460 | 80 | **Module base class** (all `extends ui` inherit this) |
|
|
15
|
+
| `Mo` | **SocketHandler** | L18135-18685 | **551** | WebSocket connection, reconnection, heartbeat |
|
|
16
|
+
| `To` | **PHandler** | L18964-22460 | **3497** | Protocol handler — frame serialize/deserialize |
|
|
17
|
+
| `vo` | **MsgDispatcher** | L22462-22797 | 336 | Routes incoming WS messages to modules |
|
|
18
|
+
| `Pr` | **ModuleManager** | L27279-27690 | 412 | Central registry — instantiates all modules |
|
|
19
|
+
| `Gr` | — | L27770-28854 | 1085 | **Main SDK class** (TencentCloudChat instance) |
|
|
20
|
+
|
|
21
|
+
### Messaging
|
|
22
|
+
|
|
23
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
24
|
+
|-------|-------------|-------|------|---------|
|
|
25
|
+
| `Qi` | **C2CModule** | L5031-5896 | 866 | One-to-one private chat |
|
|
26
|
+
| `tn` | **MsgListHandler** | L5904-6342 | 439 | Message list storage & pagination |
|
|
27
|
+
| `Xn` | **MessageModule** | L15343-16350 | **1008** | Core message create/send/receive |
|
|
28
|
+
| `Yn` | MergerMessageHandler | L15076-15312 | 237 | Combined message handling |
|
|
29
|
+
| `Zn` | MsgExtModule | L16351-16752 | 402 | Message extensions |
|
|
30
|
+
| `Qn` | MsgReactionModule | L16753-17172 | 420 | Message reactions (emoji) |
|
|
31
|
+
| `eo` | ComboMsgModule | L17173-17370 | 198 | Combo message handling |
|
|
32
|
+
| `so` | SyncUnreadMsgModule | L17392-17499 | 108 | Unread message sync |
|
|
33
|
+
|
|
34
|
+
### Conversations
|
|
35
|
+
|
|
36
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
37
|
+
|-------|-------------|-------|------|---------|
|
|
38
|
+
| `fn` | MsgRemindHandler | L6873-7134 | 262 | Message notification settings |
|
|
39
|
+
| `Mn` | **ConvGroupHandler** | L7135-8124 | 990 | Conversation group (folder) management |
|
|
40
|
+
| `In` | **ConvModule** | L8125-10961 | **2837** | Conversation list, unread counts |
|
|
41
|
+
|
|
42
|
+
### Groups & Topics
|
|
43
|
+
|
|
44
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
45
|
+
|-------|-------------|-------|------|---------|
|
|
46
|
+
| `vn` | TopicModule | L11067-11768 | 702 | Community topic (sub-channel) |
|
|
47
|
+
| `Co` | ChannelModule | L18745-18963 | 219 | Channel/Room messaging |
|
|
48
|
+
|
|
49
|
+
### User & Profile
|
|
50
|
+
|
|
51
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
52
|
+
|-------|-------------|-------|------|---------|
|
|
53
|
+
| `Sn` | ProfileHandler | L11769-12222 | 454 | User profile management |
|
|
54
|
+
| `Dn` | BlacklistHandler | L12231-12384 | 154 | Blocklist |
|
|
55
|
+
| `Ln` | UserStatusHandler | L12400-12669 | 270 | Online/offline status |
|
|
56
|
+
| `An` | UserModule | L12670-12798 | 129 | User operations |
|
|
57
|
+
|
|
58
|
+
### Auth & Session
|
|
59
|
+
|
|
60
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
61
|
+
|-------|-------------|-------|------|---------|
|
|
62
|
+
| `Pn` | SignModule | L13042-13354 | 313 | Authentication signing |
|
|
63
|
+
| `Lo` | **SessionModule** | L22904-23260 | 357 | Login/logout lifecycle |
|
|
64
|
+
|
|
65
|
+
### Upload & Media
|
|
66
|
+
|
|
67
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
68
|
+
|-------|-------------|-------|------|---------|
|
|
69
|
+
| `Wn` | **UploadModule** | L14043-15075 | 1033 | File/image/video upload to COS |
|
|
70
|
+
|
|
71
|
+
### Quality & Monitoring
|
|
72
|
+
|
|
73
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
74
|
+
|-------|-------------|-------|------|---------|
|
|
75
|
+
| `Di` | SSOLogData | L3666-3812 | 147 | SSO log entry |
|
|
76
|
+
| `bn` | EventStatModule | L13576-13703 | 128 | Event statistics |
|
|
77
|
+
| `qn` | NetMonitorModule | L13706-13823 | 118 | Network monitoring |
|
|
78
|
+
| `No` | AvgE2EDelay | L23620-23707 | 88 | End-to-end delay metric |
|
|
79
|
+
| `Po` | AvgRTT | L23708-23774 | 67 | Round-trip time metric |
|
|
80
|
+
| `ko` | QualityStatModule | L24015-24226 | 212 | Quality statistics |
|
|
81
|
+
| `wo` | WorkerTimerModule | L24227-24298 | 72 | Web Worker timer |
|
|
82
|
+
|
|
83
|
+
### Plugins & Extensions
|
|
84
|
+
|
|
85
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
86
|
+
|-------|-------------|-------|------|---------|
|
|
87
|
+
| `to` | PluginModule | L17371-17391 | 21 | Plugin registration |
|
|
88
|
+
| `bo` | PurchasedFeatureHandler | L24299-24401 | 103 | Feature gating |
|
|
89
|
+
| `Fo` | CommercialConfigModule | L24402-24500 | 99 | Commercial config |
|
|
90
|
+
| `qo` | TIMPushModule | L24767-25114 | 348 | Push notifications |
|
|
91
|
+
| `xo` | ProfanityFilterModule | L25115-25321 | 207 | Content moderation |
|
|
92
|
+
| `Ao` | CloudControlModule | L23261-23383 | 123 | Cloud config |
|
|
93
|
+
| `Gn` | StorageModule | L13358-13531 | 174 | Local storage |
|
|
94
|
+
|
|
95
|
+
### Other
|
|
96
|
+
|
|
97
|
+
| Class | Module Name | Lines | Size | Purpose |
|
|
98
|
+
|-------|-------------|-------|------|---------|
|
|
99
|
+
| `Oo` | RecoverMsgModule | L23384-23619 | 236 | Message recovery |
|
|
100
|
+
| `Vo` | TransCmdModule | L25322-25398 | 77 | Translation commands |
|
|
101
|
+
| `Bo` | ErrMsgModule | L25399-25568 | 170 | Error message mapping |
|
|
102
|
+
| `Nr` | InflateModule | L27240-27278 | 39 | Data decompression |
|
|
103
|
+
| `Ur` | SafetyCallback | L27691-27769 | 79 | Safe callback wrapper |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Key Top-Level Variables
|
|
108
|
+
|
|
109
|
+
| Variable | Lines | Size | Purpose |
|
|
110
|
+
|----------|-------|------|---------|
|
|
111
|
+
| `e` | L1-39 | 39 | **EVENT** enum — all SDK event names |
|
|
112
|
+
| `t` | L40-156 | 117 | **TYPES** enum — message/group/conversation types |
|
|
113
|
+
| `n` | L203-317 | 115 | WebSocket server addresses by region |
|
|
114
|
+
| `o` | L318-333 | 16 | Platform IDs |
|
|
115
|
+
| `r` | L334 | 1 | SDK version: `"1.7.3"` |
|
|
116
|
+
| `a` | L335 | 1 | Build number: `537048168` |
|
|
117
|
+
| `f` | L345-392 | 48 | Server host config (current host, service names) |
|
|
118
|
+
| `M` | L393-412 | 20 | Feature capability bitfields |
|
|
119
|
+
| `Ee` | L563-643 | 81 | **Logger** (d/l/i/w/e methods, level control) |
|
|
120
|
+
| `Ts` | L1453-3035 | **1583** | **API command definitions** (wslogin, sendmsg, etc.) |
|
|
121
|
+
| `ys` | L3036-3186 | 151 | **Error codes** (NO_SDKAPPID, NETWORK_TIMEOUT, etc.) |
|
|
122
|
+
| `dr` | L26129-26948 | 820 | **SDK factory** — creates TencentCloudChat instances |
|
|
123
|
+
|
|
124
|
+
## Key Patch Points
|
|
125
|
+
|
|
126
|
+
| Line | Content | Clawlink Usage |
|
|
127
|
+
|------|---------|----------------|
|
|
128
|
+
| L514 | `globalThis.__CLAWLINK_SDK_LOGGER` | Logger injection — redirects SDK logs to file |
|
|
129
|
+
| L18135 | `class Mo` (SocketHandler) | WebSocket timeout/reconnect behavior |
|
|
130
|
+
| L18148 | `MAX_RECONNECT_COUNT = 3` | Max reconnection attempts |
|
|
131
|
+
| L5031 | `class Qi` (C2CModule) | Private messaging logic |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## External Modules (in `modules/` directory)
|
|
136
|
+
|
|
137
|
+
| File | Formatted Lines | Classes | Purpose |
|
|
138
|
+
|------|-----------------|---------|---------|
|
|
139
|
+
| `group-module.js` | 6,078 | 28 | Group create/join/quit/update + member mgmt |
|
|
140
|
+
| `relationship-module.js` | 1,981 | 11 | Friend add/delete/check + friend groups |
|
|
141
|
+
| `signaling-module.js` | 1,272 | 7 | Invite/accept/reject signaling |
|
|
142
|
+
| `cloud-search-module.js` | 999 | 5 | Cloud message/group/user search |
|
|
143
|
+
| `follow-module.js` | 935 | 4 | Follow/unfollow user relationships |
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for the bundled TIM SDK (src/sdk/index.js)
|
|
3
|
+
*
|
|
4
|
+
* The SDK is a modified copy of @tencentcloud/chat without TS declarations.
|
|
5
|
+
* This file provides the minimal type surface used by openagent.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface ChatInstance {
|
|
9
|
+
setLogLevel(level: number): void;
|
|
10
|
+
login(options: { userID: string; userSig: string }): Promise<void>;
|
|
11
|
+
logout(): Promise<void>;
|
|
12
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
13
|
+
off(event: string, handler: (...args: unknown[]) => void): void;
|
|
14
|
+
|
|
15
|
+
// Messaging
|
|
16
|
+
createTextMessage(options: {
|
|
17
|
+
to: string;
|
|
18
|
+
conversationType: string;
|
|
19
|
+
payload: { text: string };
|
|
20
|
+
}): unknown;
|
|
21
|
+
createTextAtMessage(options: {
|
|
22
|
+
to: string;
|
|
23
|
+
conversationType: string;
|
|
24
|
+
payload: { text: string; atUserList: string[] };
|
|
25
|
+
}): unknown;
|
|
26
|
+
createCustomMessage(options: {
|
|
27
|
+
to: string;
|
|
28
|
+
conversationType: string;
|
|
29
|
+
payload: { data: string; description: string; extension: string };
|
|
30
|
+
}): unknown;
|
|
31
|
+
// T4: File message for C2C file transfer
|
|
32
|
+
createFileMessage(options: {
|
|
33
|
+
to: string;
|
|
34
|
+
conversationType: string;
|
|
35
|
+
payload: { file: File };
|
|
36
|
+
onProgress?: (event: { percent: number }) => void;
|
|
37
|
+
}): unknown;
|
|
38
|
+
sendMessage(message: unknown): Promise<{ data?: { message?: { ID?: string } } }>;
|
|
39
|
+
getMessageList(options: {
|
|
40
|
+
conversationID: string;
|
|
41
|
+
count: number;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
data?: {
|
|
44
|
+
messageList?: Array<{
|
|
45
|
+
ID?: string;
|
|
46
|
+
from?: string;
|
|
47
|
+
type?: string;
|
|
48
|
+
payload?: { text?: string };
|
|
49
|
+
time?: number;
|
|
50
|
+
sequence?: number;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
|
|
55
|
+
// Groups
|
|
56
|
+
getGroupList(): Promise<{
|
|
57
|
+
data?: {
|
|
58
|
+
groupList?: Array<{
|
|
59
|
+
groupID: string;
|
|
60
|
+
name: string;
|
|
61
|
+
introduction?: string;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
}>;
|
|
65
|
+
joinGroup(options: { groupID: string }): Promise<void>;
|
|
66
|
+
quitGroup(groupID: string): Promise<void>;
|
|
67
|
+
getGroupMemberList(options: {
|
|
68
|
+
groupID: string;
|
|
69
|
+
count: number;
|
|
70
|
+
offset: number;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
data?: {
|
|
73
|
+
memberList?: Array<{
|
|
74
|
+
userID: string;
|
|
75
|
+
nick?: string;
|
|
76
|
+
role?: string;
|
|
77
|
+
avatar?: string;
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
80
|
+
}>;
|
|
81
|
+
createGroup(options: {
|
|
82
|
+
type: string;
|
|
83
|
+
name: string;
|
|
84
|
+
groupID?: string;
|
|
85
|
+
introduction?: string;
|
|
86
|
+
notification?: string;
|
|
87
|
+
joinOption?: string;
|
|
88
|
+
isSupportTopic?: boolean;
|
|
89
|
+
}): Promise<{ data?: { group?: { groupID?: string } } }>;
|
|
90
|
+
getGroupProfile(options: {
|
|
91
|
+
groupID: string;
|
|
92
|
+
groupCustomFieldFilter?: string[];
|
|
93
|
+
}): Promise<{
|
|
94
|
+
data?: { group?: { notification?: string } };
|
|
95
|
+
}>;
|
|
96
|
+
updateGroupProfile(options: {
|
|
97
|
+
groupID: string;
|
|
98
|
+
notification?: string;
|
|
99
|
+
}): Promise<void>;
|
|
100
|
+
getConversationProfile(conversationID: string): Promise<unknown>;
|
|
101
|
+
// T4: Plugin registration for tim-upload-plugin
|
|
102
|
+
registerPlugin(plugins: Record<string, unknown>): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface TencentCloudChatStatic {
|
|
106
|
+
create(options: { SDKAppID: number; modules?: Record<string, unknown> }): ChatInstance;
|
|
107
|
+
EVENT: {
|
|
108
|
+
SDK_READY: string;
|
|
109
|
+
SDK_NOT_READY: string;
|
|
110
|
+
KICKED_OUT: string;
|
|
111
|
+
MESSAGE_RECEIVED: string;
|
|
112
|
+
};
|
|
113
|
+
TYPES: {
|
|
114
|
+
CONV_GROUP: string;
|
|
115
|
+
CONV_C2C: string;
|
|
116
|
+
MSG_TEXT: string;
|
|
117
|
+
MSG_AT_ALL: string;
|
|
118
|
+
MSG_FILE: string;
|
|
119
|
+
GRP_PUBLIC: string;
|
|
120
|
+
GRP_COMMUNITY: string;
|
|
121
|
+
JOIN_OPTIONS_FREE_ACCESS: string;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare const TencentCloudChat: TencentCloudChatStatic;
|
|
126
|
+
export default TencentCloudChat;
|