openclaw-openagent 1.0.1 → 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.
Files changed (187) hide show
  1. package/dist/index.d.ts +25 -0
  2. package/dist/index.js +105 -0
  3. package/dist/src/app/channel-tools.d.ts +28 -0
  4. package/dist/src/app/channel-tools.js +251 -0
  5. package/dist/src/app/discovery-tools.d.ts +35 -0
  6. package/dist/src/app/discovery-tools.js +243 -0
  7. package/dist/src/app/download-file-tool.d.ts +10 -0
  8. package/dist/src/app/download-file-tool.js +104 -0
  9. package/dist/src/app/hooks.d.ts +14 -0
  10. package/dist/src/app/hooks.js +118 -0
  11. package/dist/src/app/index.d.ts +13 -0
  12. package/dist/src/app/index.js +44 -0
  13. package/dist/src/app/messaging-tools.d.ts +11 -0
  14. package/dist/src/app/messaging-tools.js +79 -0
  15. package/dist/src/app/ops-tools.d.ts +21 -0
  16. package/dist/src/app/ops-tools.js +158 -0
  17. package/dist/src/app/remote-agent-tool.d.ts +27 -0
  18. package/dist/src/app/remote-agent-tool.js +461 -0
  19. package/dist/src/app/types.d.ts +61 -0
  20. package/dist/src/app/types.js +11 -0
  21. package/dist/src/app/upload-file-tool.d.ts +16 -0
  22. package/dist/src/app/upload-file-tool.js +353 -0
  23. package/dist/src/app/verbose-preflight.d.ts +2 -0
  24. package/dist/src/app/verbose-preflight.js +145 -0
  25. package/dist/src/auth/config.d.ts +79 -0
  26. package/dist/src/auth/config.js +133 -0
  27. package/dist/src/auth/credential-manager.d.ts +65 -0
  28. package/dist/src/auth/credential-manager.js +122 -0
  29. package/dist/src/auth/index.d.ts +6 -0
  30. package/dist/src/auth/index.js +6 -0
  31. package/dist/src/auth/verify.d.ts +42 -0
  32. package/dist/src/auth/verify.js +60 -0
  33. package/dist/src/channel.d.ts +269 -0
  34. package/dist/src/channel.js +488 -0
  35. package/dist/src/compat.d.ts +37 -0
  36. package/dist/src/compat.js +70 -0
  37. package/dist/src/config/config-schema.d.ts +56 -0
  38. package/dist/src/config/config-schema.js +34 -0
  39. package/dist/src/messaging/aggregator.d.ts +25 -0
  40. package/dist/src/messaging/aggregator.js +90 -0
  41. package/dist/src/messaging/collector.d.ts +27 -0
  42. package/dist/src/messaging/collector.js +76 -0
  43. package/dist/src/messaging/executor.d.ts +14 -0
  44. package/dist/src/messaging/executor.js +59 -0
  45. package/dist/src/messaging/inbound.d.ts +97 -0
  46. package/dist/src/messaging/inbound.js +63 -0
  47. package/dist/src/messaging/index.d.ts +10 -0
  48. package/dist/src/messaging/index.js +9 -0
  49. package/dist/src/messaging/mention-protocol.d.ts +42 -0
  50. package/dist/src/messaging/mention-protocol.js +74 -0
  51. package/dist/src/messaging/process-c2c-request.d.ts +55 -0
  52. package/dist/src/messaging/process-c2c-request.js +445 -0
  53. package/dist/src/messaging/process-message.d.ts +62 -0
  54. package/dist/src/messaging/process-message.js +282 -0
  55. package/dist/src/messaging/scheduler.d.ts +17 -0
  56. package/dist/src/messaging/scheduler.js +47 -0
  57. package/dist/src/messaging/types.d.ts +34 -0
  58. package/dist/src/messaging/types.js +4 -0
  59. package/dist/src/plugin-ui/assets/openagent-override.js +9267 -0
  60. package/dist/src/plugin-ui/index.d.ts +13 -0
  61. package/dist/src/plugin-ui/index.js +16 -0
  62. package/dist/src/plugin-ui/ui-extension-loader/backup.d.ts +23 -0
  63. package/dist/src/plugin-ui/ui-extension-loader/backup.js +82 -0
  64. package/dist/src/plugin-ui/ui-extension-loader/index.d.ts +28 -0
  65. package/dist/src/plugin-ui/ui-extension-loader/index.js +240 -0
  66. package/dist/src/plugin-ui/ui-extension-loader/locator.d.ts +35 -0
  67. package/dist/src/plugin-ui/ui-extension-loader/locator.js +129 -0
  68. package/dist/src/plugin-ui/ui-extension-loader/manifest.d.ts +26 -0
  69. package/dist/src/plugin-ui/ui-extension-loader/manifest.js +45 -0
  70. package/dist/src/plugin-ui/ui-extension-loader/registry-regex.d.ts +9 -0
  71. package/dist/src/plugin-ui/ui-extension-loader/registry-regex.js +701 -0
  72. package/dist/src/plugin-ui/ui-extension-loader/removed-extensions.d.ts +8 -0
  73. package/dist/src/plugin-ui/ui-extension-loader/removed-extensions.js +58 -0
  74. package/dist/src/plugin-ui/ui-extension-loader/types.d.ts +55 -0
  75. package/dist/src/plugin-ui/ui-extension-loader/types.js +23 -0
  76. package/dist/src/proxy/auth-proxy.d.ts +20 -0
  77. package/dist/src/proxy/auth-proxy.js +337 -0
  78. package/dist/src/runtime/account.d.ts +156 -0
  79. package/dist/src/runtime/account.js +491 -0
  80. package/dist/src/runtime/index.d.ts +5 -0
  81. package/dist/src/runtime/index.js +6 -0
  82. package/dist/src/runtime/plugin-runtime.d.ts +40 -0
  83. package/dist/src/runtime/plugin-runtime.js +72 -0
  84. package/dist/src/runtime/registry.d.ts +41 -0
  85. package/dist/src/runtime/registry.js +60 -0
  86. package/dist/src/sdk/CLASS_MAP.md +143 -0
  87. package/dist/src/sdk/index.d.ts +126 -0
  88. package/dist/src/sdk/index.js +23990 -0
  89. package/dist/src/sdk/modules/cloud-search-module.js +1117 -0
  90. package/dist/src/sdk/modules/follow-module.js +1069 -0
  91. package/dist/src/sdk/modules/group-module.js +7397 -0
  92. package/dist/src/sdk/modules/relationship-module.js +2269 -0
  93. package/dist/src/sdk/modules/signaling-module.js +1468 -0
  94. package/dist/src/sdk/modules/tim-upload-plugin.js +730 -0
  95. package/dist/src/sdk/node-env/http-request.js +90 -0
  96. package/dist/src/sdk/node-env/index.js +57 -0
  97. package/dist/src/sdk/node-env/storage.js +114 -0
  98. package/dist/src/sdk/package.json +10 -0
  99. package/dist/src/sdk/sdk/CLASS_MAP.md +143 -0
  100. package/dist/src/sdk/sdk/index.d.ts +126 -0
  101. package/dist/src/sdk/sdk/index.js +23990 -0
  102. package/dist/src/sdk/sdk/modules/cloud-search-module.js +1117 -0
  103. package/dist/src/sdk/sdk/modules/follow-module.js +1069 -0
  104. package/dist/src/sdk/sdk/modules/group-module.js +7397 -0
  105. package/dist/src/sdk/sdk/modules/relationship-module.js +2269 -0
  106. package/dist/src/sdk/sdk/modules/signaling-module.js +1468 -0
  107. package/dist/src/sdk/sdk/modules/tim-upload-plugin.js +730 -0
  108. package/dist/src/sdk/sdk/node-env/http-request.js +90 -0
  109. package/dist/src/sdk/sdk/node-env/index.js +57 -0
  110. package/dist/src/sdk/sdk/node-env/storage.js +114 -0
  111. package/dist/src/sdk/sdk/package.json +10 -0
  112. package/dist/src/sdk/sdk/tsconfig.json +16 -0
  113. package/dist/src/sdk/tsconfig.json +16 -0
  114. package/dist/src/state/pending-invocation-store.d.ts +26 -0
  115. package/dist/src/state/pending-invocation-store.js +39 -0
  116. package/dist/src/state/store.d.ts +165 -0
  117. package/dist/src/state/store.js +535 -0
  118. package/dist/src/tim/c2c.d.ts +83 -0
  119. package/dist/src/tim/c2c.js +318 -0
  120. package/dist/src/tim/channels.d.ts +95 -0
  121. package/dist/src/tim/channels.js +279 -0
  122. package/dist/src/tim/client.d.ts +54 -0
  123. package/dist/src/tim/client.js +268 -0
  124. package/dist/src/tim/index.d.ts +6 -0
  125. package/dist/src/tim/index.js +6 -0
  126. package/dist/src/tim/messages.d.ts +50 -0
  127. package/dist/src/tim/messages.js +104 -0
  128. package/dist/src/tim/sdk-logger-init.d.ts +13 -0
  129. package/dist/src/tim/sdk-logger-init.js +46 -0
  130. package/dist/src/tools.d.ts +9 -0
  131. package/dist/src/tools.js +8 -0
  132. package/dist/src/transport/factory.d.ts +63 -0
  133. package/dist/src/transport/factory.js +54 -0
  134. package/dist/src/transport/oasn/index.d.ts +12 -0
  135. package/dist/src/transport/oasn/index.js +9 -0
  136. package/dist/src/transport/oasn/oasn-agent-card.d.ts +38 -0
  137. package/dist/src/transport/oasn/oasn-agent-card.js +102 -0
  138. package/dist/src/transport/oasn/oasn-discovery.d.ts +33 -0
  139. package/dist/src/transport/oasn/oasn-discovery.js +97 -0
  140. package/dist/src/transport/oasn/oasn-files.d.ts +64 -0
  141. package/dist/src/transport/oasn/oasn-files.js +174 -0
  142. package/dist/src/transport/oasn/oasn-http.d.ts +98 -0
  143. package/dist/src/transport/oasn/oasn-http.js +362 -0
  144. package/dist/src/transport/oasn/oasn-invocation.d.ts +154 -0
  145. package/dist/src/transport/oasn/oasn-invocation.js +432 -0
  146. package/dist/src/transport/oasn/oasn-normalize.d.ts +6 -0
  147. package/dist/src/transport/oasn/oasn-normalize.js +112 -0
  148. package/dist/src/transport/oasn/oasn-register.d.ts +19 -0
  149. package/dist/src/transport/oasn/oasn-register.js +24 -0
  150. package/dist/src/transport/oasn/oasn-transport.d.ts +114 -0
  151. package/dist/src/transport/oasn/oasn-transport.js +230 -0
  152. package/dist/src/transport/oasn/oasn-types.d.ts +331 -0
  153. package/dist/src/transport/oasn/oasn-types.js +44 -0
  154. package/dist/src/transport/tim/index.d.ts +7 -0
  155. package/dist/src/transport/tim/index.js +6 -0
  156. package/dist/src/transport/tim/tim-transport.d.ts +122 -0
  157. package/dist/src/transport/tim/tim-transport.js +402 -0
  158. package/dist/src/transport/types.d.ts +450 -0
  159. package/dist/src/transport/types.js +38 -0
  160. package/dist/src/util/http.d.ts +21 -0
  161. package/dist/src/util/http.js +93 -0
  162. package/dist/src/util/logger.d.ts +20 -0
  163. package/dist/src/util/logger.js +100 -0
  164. package/dist/src/util/url-resolver.d.ts +7 -0
  165. package/dist/src/util/url-resolver.js +20 -0
  166. package/index.ts +11 -0
  167. package/openclaw.plugin.json +9 -0
  168. package/package.json +7 -4
  169. package/src/app/download-file-tool.ts +133 -0
  170. package/src/app/hooks.ts +89 -5
  171. package/src/app/index.ts +6 -0
  172. package/src/app/remote-agent-tool.ts +46 -0
  173. package/src/app/types.ts +1 -0
  174. package/src/app/upload-file-tool.ts +411 -0
  175. package/src/plugin-ui/assets/openagent-override.js +1 -63
  176. package/src/plugin-ui/modules/agent-book/panel/agent-book.js +0 -61
  177. package/src/plugin-ui/modules/agent-book/panel/agent-data.js +0 -1
  178. package/src/plugin-ui/ui-extension-loader/registry-regex.ts +30 -13
  179. package/src/runtime/account.ts +0 -23
  180. package/src/transport/oasn/oasn-files.ts +5 -5
  181. package/src/transport/oasn/oasn-invocation.ts +44 -2
  182. package/src/transport/oasn/oasn-normalize.ts +0 -26
  183. package/src/transport/oasn/oasn-register.ts +8 -81
  184. package/src/transport/oasn/oasn-transport.ts +9 -32
  185. package/src/transport/oasn/oasn-types.ts +53 -6
  186. package/src/transport/types.ts +33 -36
  187. 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,10 @@
1
+ {
2
+ "name": "@tencentcloud/chat",
3
+ "version": "3.6.6-clawlink",
4
+ "description": "Tencent Cloud Chat SDK — prettified JS with Node.js patches",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ }
10
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "moduleResolution": "bundler",
6
+ "strict": false,
7
+ "noImplicitAny": false,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "esModuleInterop": true,
11
+ "allowJs": true,
12
+ "checkJs": false
13
+ },
14
+ "include": ["./*.ts"],
15
+ "exclude": ["./modules/*"]
16
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "moduleResolution": "bundler",
6
+ "strict": false,
7
+ "noImplicitAny": false,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "esModuleInterop": true,
11
+ "allowJs": true,
12
+ "checkJs": false
13
+ },
14
+ "include": ["./*.ts"],
15
+ "exclude": ["./modules/*"]
16
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * StateStore → OasnInvocation.PendingInvocationStore 适配器
3
+ *
4
+ * 设计依据:docs/specs/2026-06-16-oasn-transport-abstraction-design.md §11.1
5
+ *
6
+ * 把 SQLite-backed StateStore 的 pending_invocations CRUD 方法包装成
7
+ * OasnInvocation 模块需要的 PendingInvocationStore 接口形状。
8
+ *
9
+ * 拆出独立适配器的好处:
10
+ * 1. OasnInvocation 不直接依赖 StateStore 类型 —— 子模块测试时可注入纯内存假实现
11
+ * 2. 后续若多账号场景需要切表/前缀,可以在此层做隔离,不污染 StateStore 主接口
12
+ * 3. 启动时续轮询逻辑(扫描 listUnsettledInvocations)放在 AccountRuntime 里调用,
13
+ * 适配器只承担运行时单条 CRUD,职责清晰
14
+ */
15
+ import type { PendingInvocationStore } from '../transport/oasn/index.js';
16
+ import type { StateStore } from './store.js';
17
+ /**
18
+ * 适配 StateStore 暴露 PendingInvocationStore 接口。
19
+ *
20
+ * 用法:
21
+ * const store = new StateStore();
22
+ * await store.init(accountId);
23
+ * const pending = createPendingInvocationStore(store);
24
+ * const transport = createTransport({ ..., pendingStore: pending });
25
+ */
26
+ export declare function createPendingInvocationStore(store: StateStore): PendingInvocationStore;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * StateStore → OasnInvocation.PendingInvocationStore 适配器
3
+ *
4
+ * 设计依据:docs/specs/2026-06-16-oasn-transport-abstraction-design.md §11.1
5
+ *
6
+ * 把 SQLite-backed StateStore 的 pending_invocations CRUD 方法包装成
7
+ * OasnInvocation 模块需要的 PendingInvocationStore 接口形状。
8
+ *
9
+ * 拆出独立适配器的好处:
10
+ * 1. OasnInvocation 不直接依赖 StateStore 类型 —— 子模块测试时可注入纯内存假实现
11
+ * 2. 后续若多账号场景需要切表/前缀,可以在此层做隔离,不污染 StateStore 主接口
12
+ * 3. 启动时续轮询逻辑(扫描 listUnsettledInvocations)放在 AccountRuntime 里调用,
13
+ * 适配器只承担运行时单条 CRUD,职责清晰
14
+ */
15
+ /**
16
+ * 适配 StateStore 暴露 PendingInvocationStore 接口。
17
+ *
18
+ * 用法:
19
+ * const store = new StateStore();
20
+ * await store.init(accountId);
21
+ * const pending = createPendingInvocationStore(store);
22
+ * const transport = createTransport({ ..., pendingStore: pending });
23
+ */
24
+ export function createPendingInvocationStore(store) {
25
+ return {
26
+ getPending(toolCallId) {
27
+ return store.getPendingInvocation(toolCallId);
28
+ },
29
+ upsertPending(record) {
30
+ store.upsertPendingInvocation(record);
31
+ },
32
+ markTerminal(invocationId, status) {
33
+ store.markPendingInvocationTerminal(invocationId, status);
34
+ },
35
+ markAbandoned(invocationId) {
36
+ store.markPendingInvocationAbandoned(invocationId);
37
+ },
38
+ };
39
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * State Store — SQLite persistence via sql.js (pure WASM)
3
+ *
4
+ * Persists channel state and message dedup records.
5
+ * sql.js operates in-memory; explicit persist() writes to disk.
6
+ * No native compilation needed (unlike better-sqlite3).
7
+ *
8
+ * v3: All tables use (account_id, channel_id) composite key.
9
+ * See §0.4 of refactoring-plan.md for field semantics.
10
+ */
11
+ export interface ChannelState {
12
+ account_id: string;
13
+ channel_id: string;
14
+ channel_name: string;
15
+ joined: number;
16
+ last_visit: number;
17
+ last_reply: number;
18
+ last_msg_seq: number;
19
+ created_at: number;
20
+ updated_at: number;
21
+ }
22
+ export interface ChannelStateDisplay {
23
+ id: string;
24
+ name: string;
25
+ lastVisit: string;
26
+ lastReply: string;
27
+ lastMsgSeq: number;
28
+ }
29
+ /**
30
+ * §11.1 OASN invocation 幂等持久化记录。
31
+ *
32
+ * 同一个 tool_call_id 多次重试时必须复用首次生成的 idempotency_key,
33
+ * 否则服务端会创建多个 Invocation(叠加 §11.2 没有 cancel API 的限制,会泄漏调用配额)。
34
+ *
35
+ * 流程:
36
+ * 1. sendTask 前查询 tool_call_id 是否已有未完成记录 → 复用 idempotency_key
37
+ * 2. POST /api/invocations 成功后 → upsert 写入 invocation_id + status
38
+ * 3. 终态 → markTerminal(status);abort → markAbandoned()
39
+ * 4. 进程启动时扫描 status NOT IN (succeeded,failed,timed_out,cancelled,abandoned)
40
+ * → 调 GET /api/invocations/{id} 续轮询
41
+ */
42
+ export interface PendingInvocationRecord {
43
+ /** LLM 工具调用唯一 id(上层传入) */
44
+ tool_call_id: string;
45
+ /** 首次生成的 UUID,重试必须复用 */
46
+ idempotency_key: string;
47
+ /** POST 返回后回填,POST 之前为 null */
48
+ invocation_id: string | null;
49
+ session_id: string | null;
50
+ target_agent_id: string | null;
51
+ /** accepted / queued / running / succeeded / failed / timed_out / cancelled / abandoned */
52
+ status: string;
53
+ created_at: number;
54
+ updated_at: number;
55
+ }
56
+ export declare class StateStore {
57
+ private db;
58
+ private accountId;
59
+ private _seenCount;
60
+ /**
61
+ * Initialize the SQLite database.
62
+ * Must be called before any other methods.
63
+ *
64
+ * @param currentAccountId - The account ID of the currently starting account.
65
+ * Used for schema migration: old data without account_id will be assigned this ID.
66
+ */
67
+ init(currentAccountId: string): Promise<StateStore>;
68
+ private _migrate;
69
+ private _tableHasColumn;
70
+ private _tableExists;
71
+ private _migrateFromV2;
72
+ private _createV3Tables;
73
+ persist(): void;
74
+ /**
75
+ * Get all joined channels for the current account.
76
+ */
77
+ getJoinedChannels(): ChannelState[];
78
+ getJoinedChannelIds(): string[];
79
+ getChannel(channelId: string): ChannelState | null;
80
+ /**
81
+ * Mark a channel as joined.
82
+ * Authoritative writer: openagent_join_channel tool (on success).
83
+ */
84
+ markJoined(channelId: string, channelName: string): void;
85
+ /**
86
+ * Mark a channel as left.
87
+ * Authoritative writer: openagent_leave_channel tool (on success).
88
+ */
89
+ markLeft(channelId: string): void;
90
+ /**
91
+ * Update last_visit timestamp for a channel.
92
+ * Authoritative writer: Collector — on ingest() accepting a message.
93
+ */
94
+ updateLastVisit(channelId: string): void;
95
+ /**
96
+ * Update last_reply timestamp for a channel.
97
+ * Authoritative writer: openagent_send_message tool — on sendMessage() success.
98
+ */
99
+ updateLastReply(channelId: string): void;
100
+ /**
101
+ * Update last_msg_seq for a channel.
102
+ * Authoritative writer: Collector — on ingest() taking msg.sequence.
103
+ */
104
+ updateLastMsgSeq(channelId: string, seq: number): void;
105
+ hasSeen(messageId: string): boolean;
106
+ markSeen(messageId: string, channelId: string): void;
107
+ getSkill(channelId: string): string | null;
108
+ setSkill(channelId: string, skillContent: string): void;
109
+ getAllSkills(): Array<{
110
+ channel_id: string;
111
+ skill_content: string;
112
+ }>;
113
+ getPurpose(channelId: string): string | null;
114
+ setPurpose(channelId: string, purpose: string): void;
115
+ removePurpose(channelId: string): void;
116
+ /**
117
+ * Clean up old dedup records (older than 24h)
118
+ */
119
+ cleanupSeen(): void;
120
+ /**
121
+ * Close the database connection
122
+ */
123
+ close(): void;
124
+ /**
125
+ * 查 tool_call_id 是否有未完成记录。命中 → 复用其 idempotency_key 防止重复创建 Invocation。
126
+ *
127
+ * 仅当 status 为非终态(pending/accepted/queued/running)时返回,避免幂等键被复用到新调用上。
128
+ */
129
+ getPendingInvocation(toolCallId: string): {
130
+ idempotency_key: string;
131
+ invocation_id?: string;
132
+ } | null;
133
+ /**
134
+ * 插入或更新一条 pending 记录。
135
+ *
136
+ * 调用时机:
137
+ * - sendTask 之前(尚无 invocation_id,status='pending')
138
+ * - POST /api/invocations 返回后(回填 invocation_id + status)
139
+ */
140
+ upsertPendingInvocation(record: {
141
+ tool_call_id: string;
142
+ idempotency_key: string;
143
+ invocation_id?: string;
144
+ session_id?: string;
145
+ target_agent_id?: string;
146
+ status: string;
147
+ }): void;
148
+ /**
149
+ * 终态标记。透过 invocation_id 查找(OasnInvocation 在终态回调时只持有 invocation_id)。
150
+ */
151
+ markPendingInvocationTerminal(invocationId: string, status: string): void;
152
+ /**
153
+ * §11.2 abort 标记。
154
+ *
155
+ * 服务端没有 cancel API,本地只能记录"已放弃跟踪",便于排查 / 配额对账。
156
+ */
157
+ markPendingInvocationAbandoned(invocationId: string): void;
158
+ /**
159
+ * 列出非终态记录(启动时续轮询用)。
160
+ *
161
+ * 返回顺序:按 created_at 升序,先创建的先续。
162
+ */
163
+ listUnsettledInvocations(): PendingInvocationRecord[];
164
+ private _isTerminalStatus;
165
+ }