lightclawbot 1.1.2 → 1.2.0-beta.1
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/README.md +0 -1
- package/dist/index.js +38 -31
- package/dist/setup-entry.js +32 -0
- package/dist/src/channel.js +166 -253
- package/dist/src/channel.setup.js +16 -0
- package/dist/src/config.js +31 -124
- package/dist/src/dedup.js +0 -1
- package/dist/src/download-tool.js +0 -1
- package/dist/src/file-storage.js +2 -2
- package/dist/src/gateway.js +224 -178
- package/dist/src/history/cron-utils.js +0 -1
- package/dist/src/history/index.js +0 -1
- package/dist/src/history/message-parser.js +0 -1
- package/dist/src/history/session-reader.js +3 -1
- package/dist/src/history/session-store.js +0 -1
- package/dist/src/history/text-processing.js +0 -1
- package/dist/src/history/types.js +0 -1
- package/dist/src/inbound.js +165 -234
- package/dist/src/media.js +0 -1
- package/dist/src/messaging.js +65 -0
- package/dist/src/outbound.js +129 -45
- package/dist/src/runtime.js +9 -11
- package/dist/src/setup-core.js +27 -0
- package/dist/src/shared.js +141 -0
- package/dist/src/socket/handlers.js +72 -49
- package/dist/src/socket/index.js +0 -1
- package/dist/src/socket/native-socket.js +385 -0
- package/dist/src/socket/registry.js +0 -1
- package/dist/src/socket/reliable-emitter.js +188 -50
- package/dist/src/streaming/delta-tracker.js +140 -0
- package/dist/src/streaming/index.js +12 -0
- package/dist/src/streaming/stream-reply-sink.js +387 -0
- package/dist/src/streaming/types.js +4 -0
- package/dist/src/tools.js +13 -0
- package/dist/src/types.js +22 -2
- package/dist/src/upload-tool.js +0 -1
- package/dist/src/utils/account.js +73 -0
- package/dist/src/utils/common.js +48 -0
- package/dist/src/utils/index.js +2 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/constants.js +1 -0
- package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/permessage-deflate.js +6 -6
- package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/websocket-server.js +10 -6
- package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/websocket.js +19 -14
- package/node_modules/{engine.io-client/node_modules/ws → ws}/package.json +4 -3
- package/node_modules/ws/wrapper.mjs +21 -0
- package/openclaw.plugin.json +0 -7
- package/package.json +8 -5
- package/dist/index.d.ts +0 -24
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/public/data/scripts/manifest.json +0 -11
- package/dist/public/data/scripts/preflight.9af62b39.sh +0 -191
- package/dist/public/data/scripts/preflight.sh +0 -191
- package/dist/src/channel.d.ts +0 -11
- package/dist/src/channel.d.ts.map +0 -1
- package/dist/src/channel.js.map +0 -1
- package/dist/src/config.d.ts +0 -129
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js.map +0 -1
- package/dist/src/dedup.d.ts +0 -12
- package/dist/src/dedup.d.ts.map +0 -1
- package/dist/src/dedup.js.map +0 -1
- package/dist/src/download-tool.d.ts +0 -32
- package/dist/src/download-tool.d.ts.map +0 -1
- package/dist/src/download-tool.js.map +0 -1
- package/dist/src/file-storage.d.ts +0 -74
- package/dist/src/file-storage.d.ts.map +0 -1
- package/dist/src/file-storage.js.map +0 -1
- package/dist/src/format-urls.d.ts +0 -26
- package/dist/src/format-urls.d.ts.map +0 -1
- package/dist/src/format-urls.js +0 -53
- package/dist/src/format-urls.js.map +0 -1
- package/dist/src/gateway.d.ts +0 -16
- package/dist/src/gateway.d.ts.map +0 -1
- package/dist/src/gateway.js.map +0 -1
- package/dist/src/history/cron-utils.d.ts +0 -76
- package/dist/src/history/cron-utils.d.ts.map +0 -1
- package/dist/src/history/cron-utils.js.map +0 -1
- package/dist/src/history/index.d.ts +0 -20
- package/dist/src/history/index.d.ts.map +0 -1
- package/dist/src/history/index.js.map +0 -1
- package/dist/src/history/message-parser.d.ts +0 -52
- package/dist/src/history/message-parser.d.ts.map +0 -1
- package/dist/src/history/message-parser.js.map +0 -1
- package/dist/src/history/session-reader.d.ts +0 -58
- package/dist/src/history/session-reader.d.ts.map +0 -1
- package/dist/src/history/session-reader.js.map +0 -1
- package/dist/src/history/session-store.d.ts +0 -42
- package/dist/src/history/session-store.d.ts.map +0 -1
- package/dist/src/history/session-store.js.map +0 -1
- package/dist/src/history/text-processing.d.ts +0 -41
- package/dist/src/history/text-processing.d.ts.map +0 -1
- package/dist/src/history/text-processing.js.map +0 -1
- package/dist/src/history/types.d.ts +0 -134
- package/dist/src/history/types.d.ts.map +0 -1
- package/dist/src/history/types.js.map +0 -1
- package/dist/src/inbound.d.ts +0 -18
- package/dist/src/inbound.d.ts.map +0 -1
- package/dist/src/inbound.js.map +0 -1
- package/dist/src/media.d.ts +0 -12
- package/dist/src/media.d.ts.map +0 -1
- package/dist/src/media.js.map +0 -1
- package/dist/src/outbound.d.ts +0 -28
- package/dist/src/outbound.d.ts.map +0 -1
- package/dist/src/outbound.js.map +0 -1
- package/dist/src/runtime.d.ts +0 -4
- package/dist/src/runtime.d.ts.map +0 -1
- package/dist/src/runtime.js.map +0 -1
- package/dist/src/socket/handlers.d.ts +0 -26
- package/dist/src/socket/handlers.d.ts.map +0 -1
- package/dist/src/socket/handlers.js.map +0 -1
- package/dist/src/socket/index.d.ts +0 -11
- package/dist/src/socket/index.d.ts.map +0 -1
- package/dist/src/socket/index.js.map +0 -1
- package/dist/src/socket/registry.d.ts +0 -59
- package/dist/src/socket/registry.d.ts.map +0 -1
- package/dist/src/socket/registry.js.map +0 -1
- package/dist/src/socket/reliable-emitter.d.ts +0 -79
- package/dist/src/socket/reliable-emitter.d.ts.map +0 -1
- package/dist/src/socket/reliable-emitter.js.map +0 -1
- package/dist/src/types.d.ts +0 -112
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js.map +0 -1
- package/dist/src/upload-tool.d.ts +0 -27
- package/dist/src/upload-tool.d.ts.map +0 -1
- package/dist/src/upload-tool.js.map +0 -1
- package/node_modules/@socket.io/component-emitter/LICENSE +0 -24
- package/node_modules/@socket.io/component-emitter/Readme.md +0 -79
- package/node_modules/@socket.io/component-emitter/lib/cjs/index.d.ts +0 -179
- package/node_modules/@socket.io/component-emitter/lib/cjs/index.js +0 -176
- package/node_modules/@socket.io/component-emitter/lib/cjs/package.json +0 -4
- package/node_modules/@socket.io/component-emitter/lib/esm/index.d.ts +0 -179
- package/node_modules/@socket.io/component-emitter/lib/esm/index.js +0 -169
- package/node_modules/@socket.io/component-emitter/lib/esm/package.json +0 -4
- package/node_modules/@socket.io/component-emitter/package.json +0 -28
- package/node_modules/debug/LICENSE +0 -20
- package/node_modules/debug/README.md +0 -481
- package/node_modules/debug/package.json +0 -64
- package/node_modules/debug/src/browser.js +0 -272
- package/node_modules/debug/src/common.js +0 -292
- package/node_modules/debug/src/index.js +0 -10
- package/node_modules/debug/src/node.js +0 -263
- package/node_modules/engine.io-client/LICENSE +0 -22
- package/node_modules/engine.io-client/README.md +0 -331
- package/node_modules/engine.io-client/build/cjs/browser-entrypoint.d.ts +0 -3
- package/node_modules/engine.io-client/build/cjs/browser-entrypoint.js +0 -4
- package/node_modules/engine.io-client/build/cjs/contrib/has-cors.d.ts +0 -1
- package/node_modules/engine.io-client/build/cjs/contrib/has-cors.js +0 -14
- package/node_modules/engine.io-client/build/cjs/contrib/parseqs.d.ts +0 -15
- package/node_modules/engine.io-client/build/cjs/contrib/parseqs.js +0 -38
- package/node_modules/engine.io-client/build/cjs/contrib/parseuri.d.ts +0 -1
- package/node_modules/engine.io-client/build/cjs/contrib/parseuri.js +0 -67
- package/node_modules/engine.io-client/build/cjs/globals.d.ts +0 -4
- package/node_modules/engine.io-client/build/cjs/globals.js +0 -26
- package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +0 -21
- package/node_modules/engine.io-client/build/cjs/globals.node.js +0 -97
- package/node_modules/engine.io-client/build/cjs/index.d.ts +0 -15
- package/node_modules/engine.io-client/build/cjs/index.js +0 -32
- package/node_modules/engine.io-client/build/cjs/package.json +0 -10
- package/node_modules/engine.io-client/build/cjs/socket.d.ts +0 -482
- package/node_modules/engine.io-client/build/cjs/socket.js +0 -765
- package/node_modules/engine.io-client/build/cjs/transport.d.ts +0 -106
- package/node_modules/engine.io-client/build/cjs/transport.js +0 -153
- package/node_modules/engine.io-client/build/cjs/transports/index.d.ts +0 -8
- package/node_modules/engine.io-client/build/cjs/transports/index.js +0 -11
- package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.d.ts +0 -15
- package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.js +0 -60
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +0 -108
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +0 -285
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.d.ts +0 -11
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +0 -44
- package/node_modules/engine.io-client/build/cjs/transports/polling.d.ts +0 -52
- package/node_modules/engine.io-client/build/cjs/transports/polling.js +0 -165
- package/node_modules/engine.io-client/build/cjs/transports/websocket.d.ts +0 -36
- package/node_modules/engine.io-client/build/cjs/transports/websocket.js +0 -136
- package/node_modules/engine.io-client/build/cjs/transports/websocket.node.d.ts +0 -14
- package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +0 -68
- package/node_modules/engine.io-client/build/cjs/transports/webtransport.d.ts +0 -18
- package/node_modules/engine.io-client/build/cjs/transports/webtransport.js +0 -94
- package/node_modules/engine.io-client/build/cjs/util.d.ts +0 -7
- package/node_modules/engine.io-client/build/cjs/util.js +0 -65
- package/node_modules/engine.io-client/build/esm/browser-entrypoint.d.ts +0 -3
- package/node_modules/engine.io-client/build/esm/browser-entrypoint.js +0 -2
- package/node_modules/engine.io-client/build/esm/contrib/has-cors.d.ts +0 -1
- package/node_modules/engine.io-client/build/esm/contrib/has-cors.js +0 -11
- package/node_modules/engine.io-client/build/esm/contrib/parseqs.d.ts +0 -15
- package/node_modules/engine.io-client/build/esm/contrib/parseqs.js +0 -34
- package/node_modules/engine.io-client/build/esm/contrib/parseuri.d.ts +0 -1
- package/node_modules/engine.io-client/build/esm/contrib/parseuri.js +0 -64
- package/node_modules/engine.io-client/build/esm/globals.d.ts +0 -4
- package/node_modules/engine.io-client/build/esm/globals.js +0 -22
- package/node_modules/engine.io-client/build/esm/globals.node.d.ts +0 -21
- package/node_modules/engine.io-client/build/esm/globals.node.js +0 -91
- package/node_modules/engine.io-client/build/esm/index.d.ts +0 -15
- package/node_modules/engine.io-client/build/esm/index.js +0 -15
- package/node_modules/engine.io-client/build/esm/package.json +0 -10
- package/node_modules/engine.io-client/build/esm/socket.d.ts +0 -482
- package/node_modules/engine.io-client/build/esm/socket.js +0 -727
- package/node_modules/engine.io-client/build/esm/transport.d.ts +0 -106
- package/node_modules/engine.io-client/build/esm/transport.js +0 -142
- package/node_modules/engine.io-client/build/esm/transports/index.d.ts +0 -8
- package/node_modules/engine.io-client/build/esm/transports/index.js +0 -8
- package/node_modules/engine.io-client/build/esm/transports/polling-fetch.d.ts +0 -15
- package/node_modules/engine.io-client/build/esm/transports/polling-fetch.js +0 -56
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +0 -108
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +0 -271
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.d.ts +0 -11
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.js +0 -17
- package/node_modules/engine.io-client/build/esm/transports/polling.d.ts +0 -52
- package/node_modules/engine.io-client/build/esm/transports/polling.js +0 -145
- package/node_modules/engine.io-client/build/esm/transports/websocket.d.ts +0 -36
- package/node_modules/engine.io-client/build/esm/transports/websocket.js +0 -125
- package/node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts +0 -14
- package/node_modules/engine.io-client/build/esm/transports/websocket.node.js +0 -41
- package/node_modules/engine.io-client/build/esm/transports/webtransport.d.ts +0 -18
- package/node_modules/engine.io-client/build/esm/transports/webtransport.js +0 -80
- package/node_modules/engine.io-client/build/esm/util.d.ts +0 -7
- package/node_modules/engine.io-client/build/esm/util.js +0 -59
- package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.d.ts +0 -3
- package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.js +0 -2
- package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.d.ts +0 -1
- package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.js +0 -11
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.d.ts +0 -15
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js +0 -34
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.d.ts +0 -1
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.js +0 -64
- package/node_modules/engine.io-client/build/esm-debug/globals.d.ts +0 -4
- package/node_modules/engine.io-client/build/esm-debug/globals.js +0 -22
- package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +0 -21
- package/node_modules/engine.io-client/build/esm-debug/globals.node.js +0 -91
- package/node_modules/engine.io-client/build/esm-debug/index.d.ts +0 -15
- package/node_modules/engine.io-client/build/esm-debug/index.js +0 -15
- package/node_modules/engine.io-client/build/esm-debug/package.json +0 -10
- package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +0 -482
- package/node_modules/engine.io-client/build/esm-debug/socket.js +0 -756
- package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +0 -106
- package/node_modules/engine.io-client/build/esm-debug/transport.js +0 -145
- package/node_modules/engine.io-client/build/esm-debug/transports/index.d.ts +0 -8
- package/node_modules/engine.io-client/build/esm-debug/transports/index.js +0 -8
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.d.ts +0 -15
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.js +0 -56
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +0 -108
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +0 -276
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.d.ts +0 -11
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js +0 -17
- package/node_modules/engine.io-client/build/esm-debug/transports/polling.d.ts +0 -52
- package/node_modules/engine.io-client/build/esm-debug/transports/polling.js +0 -158
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.d.ts +0 -36
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.js +0 -128
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.d.ts +0 -14
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.js +0 -41
- package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.d.ts +0 -18
- package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.js +0 -87
- package/node_modules/engine.io-client/build/esm-debug/util.d.ts +0 -7
- package/node_modules/engine.io-client/build/esm-debug/util.js +0 -59
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js +0 -7
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +0 -1
- package/node_modules/engine.io-client/dist/engine.io.js +0 -3064
- package/node_modules/engine.io-client/dist/engine.io.js.map +0 -1
- package/node_modules/engine.io-client/dist/engine.io.min.js +0 -7
- package/node_modules/engine.io-client/dist/engine.io.min.js.map +0 -1
- package/node_modules/engine.io-client/node_modules/ws/index.js +0 -13
- package/node_modules/engine.io-client/node_modules/ws/wrapper.mjs +0 -8
- package/node_modules/engine.io-client/package.json +0 -95
- package/node_modules/engine.io-parser/LICENSE +0 -22
- package/node_modules/engine.io-parser/Readme.md +0 -158
- package/node_modules/engine.io-parser/build/cjs/commons.d.ts +0 -14
- package/node_modules/engine.io-parser/build/cjs/commons.js +0 -19
- package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.d.ts +0 -2
- package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.js +0 -48
- package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.d.ts +0 -2
- package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.js +0 -66
- package/node_modules/engine.io-parser/build/cjs/decodePacket.d.ts +0 -2
- package/node_modules/engine.io-parser/build/cjs/decodePacket.js +0 -59
- package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.d.ts +0 -4
- package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.js +0 -72
- package/node_modules/engine.io-parser/build/cjs/encodePacket.d.ts +0 -3
- package/node_modules/engine.io-parser/build/cjs/encodePacket.js +0 -38
- package/node_modules/engine.io-parser/build/cjs/index.d.ts +0 -9
- package/node_modules/engine.io-parser/build/cjs/index.js +0 -164
- package/node_modules/engine.io-parser/build/cjs/package.json +0 -8
- package/node_modules/engine.io-parser/build/esm/commons.d.ts +0 -14
- package/node_modules/engine.io-parser/build/esm/commons.js +0 -14
- package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.d.ts +0 -2
- package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js +0 -43
- package/node_modules/engine.io-parser/build/esm/decodePacket.browser.d.ts +0 -2
- package/node_modules/engine.io-parser/build/esm/decodePacket.browser.js +0 -62
- package/node_modules/engine.io-parser/build/esm/decodePacket.d.ts +0 -2
- package/node_modules/engine.io-parser/build/esm/decodePacket.js +0 -55
- package/node_modules/engine.io-parser/build/esm/encodePacket.browser.d.ts +0 -4
- package/node_modules/engine.io-parser/build/esm/encodePacket.browser.js +0 -68
- package/node_modules/engine.io-parser/build/esm/encodePacket.d.ts +0 -3
- package/node_modules/engine.io-parser/build/esm/encodePacket.js +0 -33
- package/node_modules/engine.io-parser/build/esm/index.d.ts +0 -9
- package/node_modules/engine.io-parser/build/esm/index.js +0 -156
- package/node_modules/engine.io-parser/build/esm/package.json +0 -8
- package/node_modules/engine.io-parser/package.json +0 -46
- package/node_modules/ms/index.js +0 -162
- package/node_modules/ms/license.md +0 -21
- package/node_modules/ms/package.json +0 -38
- package/node_modules/ms/readme.md +0 -59
- package/node_modules/socket.io-client/LICENSE +0 -21
- package/node_modules/socket.io-client/README.md +0 -29
- package/node_modules/socket.io-client/build/cjs/browser-entrypoint.d.ts +0 -2
- package/node_modules/socket.io-client/build/cjs/browser-entrypoint.js +0 -4
- package/node_modules/socket.io-client/build/cjs/contrib/backo2.d.ts +0 -12
- package/node_modules/socket.io-client/build/cjs/contrib/backo2.js +0 -69
- package/node_modules/socket.io-client/build/cjs/index.d.ts +0 -29
- package/node_modules/socket.io-client/build/cjs/index.js +0 -76
- package/node_modules/socket.io-client/build/cjs/manager.d.ts +0 -295
- package/node_modules/socket.io-client/build/cjs/manager.js +0 -416
- package/node_modules/socket.io-client/build/cjs/on.d.ts +0 -2
- package/node_modules/socket.io-client/build/cjs/on.js +0 -9
- package/node_modules/socket.io-client/build/cjs/socket.d.ts +0 -593
- package/node_modules/socket.io-client/build/cjs/socket.js +0 -909
- package/node_modules/socket.io-client/build/cjs/url.d.ts +0 -33
- package/node_modules/socket.io-client/build/cjs/url.js +0 -69
- package/node_modules/socket.io-client/build/esm/browser-entrypoint.d.ts +0 -2
- package/node_modules/socket.io-client/build/esm/browser-entrypoint.js +0 -2
- package/node_modules/socket.io-client/build/esm/contrib/backo2.d.ts +0 -12
- package/node_modules/socket.io-client/build/esm/contrib/backo2.js +0 -66
- package/node_modules/socket.io-client/build/esm/index.d.ts +0 -29
- package/node_modules/socket.io-client/build/esm/index.js +0 -58
- package/node_modules/socket.io-client/build/esm/manager.d.ts +0 -295
- package/node_modules/socket.io-client/build/esm/manager.js +0 -367
- package/node_modules/socket.io-client/build/esm/on.d.ts +0 -2
- package/node_modules/socket.io-client/build/esm/on.js +0 -6
- package/node_modules/socket.io-client/build/esm/package.json +0 -5
- package/node_modules/socket.io-client/build/esm/socket.d.ts +0 -593
- package/node_modules/socket.io-client/build/esm/socket.js +0 -880
- package/node_modules/socket.io-client/build/esm/url.d.ts +0 -33
- package/node_modules/socket.io-client/build/esm/url.js +0 -59
- package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.d.ts +0 -2
- package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.js +0 -2
- package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.d.ts +0 -12
- package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.js +0 -66
- package/node_modules/socket.io-client/build/esm-debug/index.d.ts +0 -29
- package/node_modules/socket.io-client/build/esm-debug/index.js +0 -62
- package/node_modules/socket.io-client/build/esm-debug/manager.d.ts +0 -295
- package/node_modules/socket.io-client/build/esm-debug/manager.js +0 -386
- package/node_modules/socket.io-client/build/esm-debug/on.d.ts +0 -2
- package/node_modules/socket.io-client/build/esm-debug/on.js +0 -6
- package/node_modules/socket.io-client/build/esm-debug/package.json +0 -5
- package/node_modules/socket.io-client/build/esm-debug/socket.d.ts +0 -593
- package/node_modules/socket.io-client/build/esm-debug/socket.js +0 -902
- package/node_modules/socket.io-client/build/esm-debug/url.d.ts +0 -33
- package/node_modules/socket.io-client/build/esm-debug/url.js +0 -63
- package/node_modules/socket.io-client/dist/socket.io.esm.min.js +0 -7
- package/node_modules/socket.io-client/dist/socket.io.esm.min.js.map +0 -1
- package/node_modules/socket.io-client/dist/socket.io.js +0 -4955
- package/node_modules/socket.io-client/dist/socket.io.js.map +0 -1
- package/node_modules/socket.io-client/dist/socket.io.min.js +0 -7
- package/node_modules/socket.io-client/dist/socket.io.min.js.map +0 -1
- package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js +0 -7
- package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js.map +0 -1
- package/node_modules/socket.io-client/package.json +0 -101
- package/node_modules/socket.io-parser/LICENSE +0 -20
- package/node_modules/socket.io-parser/Readme.md +0 -81
- package/node_modules/socket.io-parser/build/cjs/binary.d.ts +0 -20
- package/node_modules/socket.io-parser/build/cjs/binary.js +0 -87
- package/node_modules/socket.io-parser/build/cjs/index.d.ts +0 -101
- package/node_modules/socket.io-parser/build/cjs/index.js +0 -367
- package/node_modules/socket.io-parser/build/cjs/is-binary.d.ts +0 -7
- package/node_modules/socket.io-parser/build/cjs/is-binary.js +0 -54
- package/node_modules/socket.io-parser/build/cjs/package.json +0 -3
- package/node_modules/socket.io-parser/build/esm/binary.d.ts +0 -20
- package/node_modules/socket.io-parser/build/esm/binary.js +0 -83
- package/node_modules/socket.io-parser/build/esm/index.d.ts +0 -101
- package/node_modules/socket.io-parser/build/esm/index.js +0 -356
- package/node_modules/socket.io-parser/build/esm/is-binary.d.ts +0 -7
- package/node_modules/socket.io-parser/build/esm/is-binary.js +0 -50
- package/node_modules/socket.io-parser/build/esm/package.json +0 -3
- package/node_modules/socket.io-parser/build/esm-debug/binary.d.ts +0 -20
- package/node_modules/socket.io-parser/build/esm-debug/binary.js +0 -83
- package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +0 -101
- package/node_modules/socket.io-parser/build/esm-debug/index.js +0 -361
- package/node_modules/socket.io-parser/build/esm-debug/is-binary.d.ts +0 -7
- package/node_modules/socket.io-parser/build/esm-debug/is-binary.js +0 -50
- package/node_modules/socket.io-parser/build/esm-debug/package.json +0 -3
- package/node_modules/socket.io-parser/package.json +0 -44
- package/node_modules/xmlhttprequest-ssl/LICENSE +0 -22
- package/node_modules/xmlhttprequest-ssl/README.md +0 -67
- package/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js +0 -689
- package/node_modules/xmlhttprequest-ssl/package.json +0 -40
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/LICENSE +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/README.md +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/browser.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/buffer-util.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/event-target.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/extension.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/limiter.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/receiver.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/sender.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/stream.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/subprotocol.js +0 -0
- /package/node_modules/{engine.io-client/node_modules/ws → ws}/lib/validation.js +0 -0
package/dist/src/gateway.js
CHANGED
|
@@ -1,144 +1,155 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LightClaw —
|
|
2
|
+
* LightClaw — WebSocket Gateway
|
|
3
3
|
*
|
|
4
4
|
* 连接编排层:
|
|
5
5
|
* 1. 管理 Socket.IO 连接生命周期(连接/断开/重连/防重入)
|
|
6
|
-
* 2.
|
|
6
|
+
* 2. 分发入站消息(fire-and-forget),并发/abort 由 openclaw 自己处理
|
|
7
7
|
* 3. 提供 socket emit 抽象供子模块使用
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* 子模块分工:
|
|
10
|
+
* 消息处理逻辑 → inbound.ts
|
|
11
|
+
* 事件监听绑定 → socket-handlers.ts
|
|
12
|
+
* 去重/节流/ID → dedup.ts
|
|
13
|
+
* 媒体文件处理 → media.ts
|
|
13
14
|
*/
|
|
14
|
-
import {
|
|
15
|
-
import { CHANNEL_KEY, WS_URL, API_BASE_URL, SOCKET_PATH,
|
|
16
|
-
import { generateMsgId } from
|
|
17
|
-
import { createInboundHandler } from
|
|
18
|
-
import { bindSocketHandlers, registerSocket, unregisterSocket, flushPendingMessages } from
|
|
19
|
-
import { ReliableEmitter } from
|
|
20
|
-
import {
|
|
15
|
+
import { NativeSocketClient } from './socket/native-socket.js';
|
|
16
|
+
import { CHANNEL_KEY, WS_URL, API_BASE_URL, SOCKET_PATH, API_PATH_USER_CURRENT, EVENT_MESSAGE_PRIVATE, HEALTH_HEARTBEAT_INTERVAL, setApiKeyMap, } from './config.js';
|
|
17
|
+
import { generateMsgId } from './dedup.js';
|
|
18
|
+
import { createInboundHandler } from './inbound.js';
|
|
19
|
+
import { bindSocketHandlers, registerSocket, unregisterSocket, flushPendingMessages } from './socket/index.js';
|
|
20
|
+
import { ReliableEmitter } from './socket/reliable-emitter.js';
|
|
21
|
+
import { buildAuthHeaders } from './utils/index.js';
|
|
21
22
|
// ============================================================
|
|
22
23
|
// Gateway 实例追踪(防止同一 accountId 创建多个连接)
|
|
23
24
|
// ============================================================
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* 全局 Gateway 实例注册表。
|
|
27
|
+
* key = accountId
|
|
28
|
+
* value = cleanup 函数(销毁 socket、定时器、可靠发送器等所有资源)
|
|
29
|
+
*
|
|
30
|
+
* 在 startGateway 入口处检查此 Map,若已存在则先销毁旧实例,
|
|
31
|
+
* 避免同一账号同时持有多个 WebSocket 连接。
|
|
32
|
+
*/
|
|
25
33
|
const activeGateways = new Map();
|
|
26
34
|
/**
|
|
27
|
-
*
|
|
35
|
+
* 通过 /user/current 接口解析 botClientId。
|
|
28
36
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
37
|
+
* 新配置格式下,accountId 即为 uin,apiKey 与 uin 一一对应,
|
|
38
|
+
* 无需并发请求多个 key,只需用当前账户的 apiKey 请求一次即可获取 botClientId。
|
|
31
39
|
*
|
|
32
|
-
*
|
|
40
|
+
* @param apiKey - 当前账户的 apiKey
|
|
41
|
+
* @param log - 可选的日志对象
|
|
42
|
+
* @returns - Bot 的 clientId
|
|
43
|
+
* @throws - 若无法解析出 botClientId,则抛出错误
|
|
33
44
|
*/
|
|
34
|
-
async function
|
|
45
|
+
async function resolveBotClientId(apiKey, log) {
|
|
35
46
|
const url = `${API_BASE_URL}${API_PATH_USER_CURRENT}`;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < results.length; i++) {
|
|
56
|
-
const key = allApiKeys[i];
|
|
57
|
-
const settled = results[i];
|
|
58
|
-
if (settled.status === "rejected") {
|
|
59
|
-
log?.warn(`[${CHANNEL_KEY}] Failed to resolve uin for apiKey ***${key.slice(-4)}: ${settled.reason}`);
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const { result } = settled.value;
|
|
63
|
-
// 提取 uin
|
|
64
|
-
const uin = result.data?.id;
|
|
65
|
-
if (!uin) {
|
|
66
|
-
log?.warn(`[${CHANNEL_KEY}] Missing data.id for apiKey ***${key.slice(-4)}`);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
// 提取 botId(只需从第一个成功的 key 中获取一次)
|
|
70
|
-
if (!botClientId) {
|
|
71
|
-
const extra = result.data?.client?.extra;
|
|
72
|
-
if (!extra) {
|
|
73
|
-
log?.warn(`[${CHANNEL_KEY}] Missing data.client.extra for apiKey ***${key.slice(-4)}`);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
let parsed;
|
|
77
|
-
try {
|
|
78
|
-
parsed = JSON.parse(extra);
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
log?.warn(`[${CHANNEL_KEY}] data.client.extra is not valid JSON for apiKey ***${key.slice(-4)}: ${extra}`);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (!parsed.botId) {
|
|
85
|
-
log?.warn(`[${CHANNEL_KEY}] Missing botId in data.client.extra for apiKey ***${key.slice(-4)}: ${extra}`);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
botClientId = parsed.botId;
|
|
89
|
-
}
|
|
90
|
-
// uin 和 botClientId 都成功获取后,才加入映射
|
|
91
|
-
apiKeyMap.set(uin, key);
|
|
92
|
-
log?.info(`[${CHANNEL_KEY}] Mapped uin=${uin} → apiKey=***${key.slice(-4)}`);
|
|
47
|
+
const resp = await fetch(url, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: buildAuthHeaders(apiKey),
|
|
50
|
+
});
|
|
51
|
+
if (!resp.ok) {
|
|
52
|
+
const body = await resp.text().catch(() => '');
|
|
53
|
+
throw new Error(`[${CHANNEL_KEY}] ${API_PATH_USER_CURRENT} HTTP ${resp.status} ${resp.statusText}${body ? ` — ${body}` : ''}`);
|
|
54
|
+
}
|
|
55
|
+
const result = (await resp.json());
|
|
56
|
+
if (result.code !== 0) {
|
|
57
|
+
throw new Error(`[${CHANNEL_KEY}] ${API_PATH_USER_CURRENT} code=${result.code}, message=${result.message ?? 'unknown'}`);
|
|
58
|
+
}
|
|
59
|
+
const extra = result.data?.client?.extra;
|
|
60
|
+
if (!extra) {
|
|
61
|
+
throw new Error(`[${CHANNEL_KEY}] Missing data.client.extra in ${API_PATH_USER_CURRENT} response`);
|
|
62
|
+
}
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(extra);
|
|
93
66
|
}
|
|
94
|
-
|
|
95
|
-
throw new Error(`[${CHANNEL_KEY}]
|
|
67
|
+
catch {
|
|
68
|
+
throw new Error(`[${CHANNEL_KEY}] data.client.extra is not valid JSON: ${extra}`);
|
|
96
69
|
}
|
|
97
|
-
|
|
70
|
+
if (!parsed.botId) {
|
|
71
|
+
throw new Error(`[${CHANNEL_KEY}] Missing botId in data.client.extra: ${extra}`);
|
|
72
|
+
}
|
|
73
|
+
log?.info(`[${CHANNEL_KEY}] Resolved botClientId: ${parsed.botId}`);
|
|
74
|
+
return {
|
|
75
|
+
botClientId: parsed.botId,
|
|
76
|
+
ticket: result?.data?.ticket || '',
|
|
77
|
+
};
|
|
98
78
|
}
|
|
99
79
|
// ============================================================
|
|
100
80
|
// 核心:启动 Gateway
|
|
101
81
|
// ============================================================
|
|
82
|
+
/**
|
|
83
|
+
* 启动并维持一个 WebSocket Gateway 实例。
|
|
84
|
+
*
|
|
85
|
+
* 整体流程:
|
|
86
|
+
* 1. 防重入检查:若同一 accountId 已有活跃 gateway,先销毁旧实例
|
|
87
|
+
* 2. 调用 /user/current 解析 botClientId 和 uin→apiKey 映射
|
|
88
|
+
* 3. 创建 ReliableEmitter(可靠发送器)和 SocketEmitter 抽象
|
|
89
|
+
* 4. 创建入站消息处理器和串行消息队列
|
|
90
|
+
* 5. 建立 WebSocket 连接,绑定生命周期事件和业务事件
|
|
91
|
+
* 6. 返回一个永不 resolve 的 Promise,直到 abortSignal 触发才退出
|
|
92
|
+
* (框架约定:Promise resolve = gateway 已退出,会触发 auto-restart)
|
|
93
|
+
*
|
|
94
|
+
* @param ctx - Gateway 上下文,包含账户配置、abort 信号和生命周期回调
|
|
95
|
+
*/
|
|
102
96
|
export async function startGateway(ctx) {
|
|
103
97
|
const { account, abortSignal, onReady, onDisconnect, onEvent, log } = ctx;
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
// 判断是否存在有效的apikey
|
|
99
|
+
if (!account.apiKey) {
|
|
100
|
+
log?.error(`[${CHANNEL_KEY}:${account.accountId}] apiKey is not exist`);
|
|
101
|
+
throw new Error(`[${CHANNEL_KEY}] Missing apiKey in config`);
|
|
106
102
|
}
|
|
107
|
-
//
|
|
103
|
+
// 判断 accountId 在缓存中是否存在,避免同一账号同时持有多个 WebSocket 连接
|
|
104
|
+
// 防重入:如果同一 accountId 已有活跃 gateway,先销毁旧实例再创建新实例
|
|
108
105
|
const existingCleanup = activeGateways.get(account.accountId);
|
|
109
106
|
if (existingCleanup) {
|
|
110
|
-
log?.warn(`[${CHANNEL_KEY}] Destroying existing gateway for account ${account.accountId} before creating new one`);
|
|
107
|
+
log?.warn(`[${CHANNEL_KEY}:${account.accountId}] Destroying existing gateway for account ${account.accountId} before creating new one`);
|
|
111
108
|
existingCleanup();
|
|
112
109
|
}
|
|
113
|
-
// 通过 HTTP 接口获取 Bot
|
|
114
|
-
|
|
115
|
-
log?.info(`[${CHANNEL_KEY}] Resolving
|
|
116
|
-
const { botClientId,
|
|
117
|
-
|
|
110
|
+
// 通过 HTTP 接口获取 Bot 的 clientId(botClientId)
|
|
111
|
+
// 新配置格式:accountId 即为 uin,apiKey 与 uin 一一对应,直接构建映射表
|
|
112
|
+
log?.info(`[${CHANNEL_KEY}: ${account.accountId}] Resolving botClientId for account ${account.accountId}...`);
|
|
113
|
+
const { botClientId, ticket } = await resolveBotClientId(account.apiKey, log);
|
|
114
|
+
// 构建 uin→apiKey 映射表(新格式下每个 account 只有一条记录)
|
|
115
|
+
const apiKeyMap = new Map([[account.accountId, account.apiKey]]);
|
|
116
|
+
log?.info(`[${CHANNEL_KEY}] Bot clientId: ${botClientId}, uin=${account.accountId} → apiKey=***${account.apiKey.slice(-4)}`);
|
|
117
|
+
// 将映射表写入全局 config 模块,供 inbound 处理时按 uin 查找对应 apiKey
|
|
118
118
|
setApiKeyMap(apiKeyMap, account.apiKey);
|
|
119
|
+
/** Gateway 是否已被 abort(用于终止消息处理循环) */
|
|
119
120
|
let isAborted = false;
|
|
121
|
+
/** 当前活跃的 WebSocket 实例(断线时为 null) */
|
|
120
122
|
let currentSocket = null;
|
|
123
|
+
/** health-monitor 心跳定时器(连接时启动,断线时清除) */
|
|
121
124
|
let healthHeartbeatTimer = null;
|
|
122
125
|
// ---- 可靠发送器(所有出站 emit 都通过此实例) ----
|
|
126
|
+
// ReliableEmitter 负责:断线时缓冲消息、重连后 flush、ACK 超时重试
|
|
123
127
|
const reliableEmitter = new ReliableEmitter(() => currentSocket, log);
|
|
124
|
-
// ----
|
|
128
|
+
// ---- WebSocket 发送抽象 ----
|
|
129
|
+
/**
|
|
130
|
+
* 底层 emit:将 PrivateMessageData 通过 ReliableEmitter 发送给客户端。
|
|
131
|
+
* - 统一对 content 字段执行 formatCosUrls(将内部 COS 路径转换为公网 URL)
|
|
132
|
+
* - 所有消息都走可靠发送队列,入队即视为"发送成功",实际 ACK 由 ReliableEmitter 保证
|
|
133
|
+
*/
|
|
125
134
|
const emit = (data) => {
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
log?.info(`[${CHANNEL_KEY}] emit: ${JSON.stringify(outgoing)}`);
|
|
131
|
-
// 所有消息都走可靠发送(入队即视为"发送成功")
|
|
132
|
-
reliableEmitter.emitWithAck(EVENT_MESSAGE_PRIVATE, outgoing, outgoing.msgId)
|
|
133
|
-
.then(ok => {
|
|
134
|
-
if (!ok) {
|
|
135
|
-
log?.error(`[${CHANNEL_KEY}] Message delivery failed after retries: msgId=${outgoing.msgId}`);
|
|
136
|
-
}
|
|
135
|
+
// 完整发送日志由 ReliableEmitter 打印(含 idempotencyKey)
|
|
136
|
+
reliableEmitter.emitWithAck(EVENT_MESSAGE_PRIVATE, data, data.msgId).then((ok) => {
|
|
137
|
+
if (!ok)
|
|
138
|
+
log?.error(`[${CHANNEL_KEY}] Message delivery failed after retries: msgId=${data.msgId}`);
|
|
137
139
|
});
|
|
138
140
|
return true;
|
|
139
141
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
/**
|
|
143
|
+
* 发送文本回复消息。
|
|
144
|
+
* 自动生成 msgId 和 timestamp,封装为 PrivateMessageData 后调用 emit。
|
|
145
|
+
*
|
|
146
|
+
* @param targetId - 接收方用户 ID
|
|
147
|
+
* @param text - 回复文本内容
|
|
148
|
+
* @param replyToMsgId - 可选,回复对应的原始消息 ID(用于前端展示引用关系)
|
|
149
|
+
* @param agentId - 可选,目标 Agent ID
|
|
150
|
+
*/
|
|
151
|
+
const sendReply = (targetId, text, replyToMsgId, agentId) => {
|
|
152
|
+
log?.info(`[${CHANNEL_KEY}] sendReply: ${text} to ${targetId} (replyTo: ${replyToMsgId || 'none'})`);
|
|
142
153
|
return emit({
|
|
143
154
|
msgId: generateMsgId(),
|
|
144
155
|
from: botClientId,
|
|
@@ -146,9 +157,20 @@ export async function startGateway(ctx) {
|
|
|
146
157
|
content: text,
|
|
147
158
|
timestamp: Date.now(),
|
|
148
159
|
replyToMsgId,
|
|
160
|
+
agentId,
|
|
149
161
|
});
|
|
150
162
|
};
|
|
151
|
-
|
|
163
|
+
/**
|
|
164
|
+
* 发送带文件附件的消息。
|
|
165
|
+
* 自动生成 msgId 和 timestamp,封装为 PrivateMessageData 后调用 emit。
|
|
166
|
+
*
|
|
167
|
+
* @param targetId - 接收方用户 ID
|
|
168
|
+
* @param text - 消息文本(可为空字符串)
|
|
169
|
+
* @param files - 文件附件列表({name, mimeType, bytes} 格式)
|
|
170
|
+
* @param replyToMsgId - 可选,回复对应的原始消息 ID
|
|
171
|
+
* @param agentId - 可选,目标 Agent ID
|
|
172
|
+
*/
|
|
173
|
+
const sendFiles = (targetId, text, files, replyToMsgId, agentId) => {
|
|
152
174
|
return emit({
|
|
153
175
|
msgId: generateMsgId(),
|
|
154
176
|
from: botClientId,
|
|
@@ -157,61 +179,55 @@ export async function startGateway(ctx) {
|
|
|
157
179
|
timestamp: Date.now(),
|
|
158
180
|
files,
|
|
159
181
|
replyToMsgId,
|
|
182
|
+
agentId,
|
|
160
183
|
});
|
|
161
184
|
};
|
|
185
|
+
/** SocketEmitter 抽象:将 emit / sendReply / sendFiles 和 botClientId 打包传给 inbound 处理器 */
|
|
162
186
|
const emitter = { emit, sendReply, sendFiles, botClientId };
|
|
163
187
|
// ---- 入站消息处理器 ----
|
|
188
|
+
// createInboundHandler 返回一个异步函数,负责处理单条用户消息(文件处理、路由、AI 分发、回复)
|
|
164
189
|
const handleInboundMessage = createInboundHandler(account, emitter, log);
|
|
165
|
-
// ----
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (messageQueue.length >= MESSAGE_QUEUE_SIZE) {
|
|
171
|
-
const dropped = messageQueue.shift();
|
|
172
|
-
log?.error(`[${CHANNEL_KEY}] Queue full, dropped message from ${dropped?.senderId}`);
|
|
173
|
-
}
|
|
174
|
-
if (messageQueue.length >= MESSAGE_QUEUE_WARN_THRESHOLD) {
|
|
175
|
-
log?.warn(`[${CHANNEL_KEY}] Queue size: ${messageQueue.length}/${MESSAGE_QUEUE_SIZE}`);
|
|
176
|
-
}
|
|
177
|
-
messageQueue.push(msg);
|
|
178
|
-
// 唤醒处理器
|
|
179
|
-
queueNotify?.();
|
|
180
|
-
};
|
|
181
|
-
/** 等待队列中有新消息,或超时后返回 */
|
|
182
|
-
const waitForMessage = () => {
|
|
183
|
-
if (messageQueue.length > 0)
|
|
184
|
-
return Promise.resolve();
|
|
185
|
-
return new Promise((resolve) => {
|
|
186
|
-
const timer = setTimeout(() => { queueNotify = null; resolve(); }, QUEUE_POLL_INTERVAL);
|
|
187
|
-
queueNotify = () => { clearTimeout(timer); queueNotify = null; resolve(); };
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
const startMessageProcessor = () => {
|
|
191
|
-
if (messageProcessorRunning)
|
|
190
|
+
// ---- 消息处理(fire-and-forget) ----
|
|
191
|
+
// 不做串行队列:并发/abort 由 openclaw 的 session 写锁 + followup queue 负责。
|
|
192
|
+
// 这里仅兜底 inbound 自身未捕获的异常。
|
|
193
|
+
const handleMessage = (msg) => {
|
|
194
|
+
if (isAborted)
|
|
192
195
|
return;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
void (async () => {
|
|
197
|
+
try {
|
|
198
|
+
await handleInboundMessage(msg);
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
log?.error(`[${CHANNEL_KEY}] Message handler error: ${err}`);
|
|
202
|
+
try {
|
|
203
|
+
emitter.sendReply(msg.senderId, "消息处理异常,请稍后重试。", msg.messageId);
|
|
204
|
+
emitter.emit({
|
|
205
|
+
msgId: generateMsgId(),
|
|
206
|
+
from: emitter.botClientId,
|
|
207
|
+
to: msg.senderId,
|
|
208
|
+
content: "",
|
|
209
|
+
timestamp: Date.now(),
|
|
210
|
+
kind: "typing_stop",
|
|
211
|
+
replyToMsgId: msg.messageId,
|
|
212
|
+
agentId: msg.agentId,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
catch (notifyErr) {
|
|
216
|
+
log?.error(`[${CHANNEL_KEY}] Failed to notify user about handler error: ${notifyErr}`);
|
|
205
217
|
}
|
|
206
218
|
}
|
|
207
|
-
|
|
208
|
-
};
|
|
209
|
-
loop().catch((err) => {
|
|
210
|
-
log?.error(`[${CHANNEL_KEY}] Message processor crashed: ${err}`);
|
|
211
|
-
messageProcessorRunning = false;
|
|
212
|
-
});
|
|
219
|
+
})();
|
|
213
220
|
};
|
|
214
221
|
// ---- 生命周期 ----
|
|
222
|
+
/**
|
|
223
|
+
* 销毁当前 Gateway 实例,释放所有资源:
|
|
224
|
+
* - 设置 isAborted 标志,终止消息处理循环
|
|
225
|
+
* - 销毁 ReliableEmitter(清空发送队列、取消重试)
|
|
226
|
+
* - 清除 health-monitor 心跳定时器
|
|
227
|
+
* - 从 socket 注册表中注销(unregisterSocket)
|
|
228
|
+
* - 从 activeGateways 中移除自身
|
|
229
|
+
* - 断开并销毁 WebSocket 连接
|
|
230
|
+
*/
|
|
215
231
|
const cleanup = () => {
|
|
216
232
|
isAborted = true;
|
|
217
233
|
reliableEmitter.destroy();
|
|
@@ -228,32 +244,46 @@ export async function startGateway(ctx) {
|
|
|
228
244
|
}
|
|
229
245
|
log?.info(`[${CHANNEL_KEY}] Gateway cleaned up`);
|
|
230
246
|
};
|
|
247
|
+
// 将 cleanup 注册到全局 Map,供防重入检查和外部销毁使用
|
|
231
248
|
activeGateways.set(account.accountId, cleanup);
|
|
232
|
-
// ----
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
// ---- WebSocket 连接 ----
|
|
250
|
+
// 采用 ticket 作为 query 参数进行认证,不再使用 header 方式
|
|
251
|
+
// 为兼容已有的 path 选项,仍通过 options.path 传入 /claw-socket
|
|
252
|
+
const ticketQuery = ticket ? `?ticket=${encodeURIComponent(ticket)}` : '';
|
|
253
|
+
log?.info(`[${CHANNEL_KEY}] Connecting to ${WS_URL}${SOCKET_PATH}${ticketQuery}`);
|
|
254
|
+
// 使用原生 WebSocket 封装层建立连接
|
|
255
|
+
const socket = new NativeSocketClient(WS_URL, {
|
|
256
|
+
// 认证:ticket 作为 URL query 参数,替代 Authorization header
|
|
257
|
+
path: `${SOCKET_PATH}${ticketQuery}&enableMultiLogin=false`,
|
|
258
|
+
// 注入日志对象,便于 NativeSocketClient 内部打印连接/重连/错误等诊断信息
|
|
259
|
+
log,
|
|
260
|
+
logPrefix: `[${CHANNEL_KEY}:${account.accountId}:NativeSocket]`,
|
|
244
261
|
});
|
|
245
262
|
currentSocket = socket;
|
|
246
|
-
|
|
247
|
-
|
|
263
|
+
/**
|
|
264
|
+
* 连接成功事件处理。
|
|
265
|
+
* 触发时机:首次连接成功 或 断线重连成功。
|
|
266
|
+
* 职责:
|
|
267
|
+
* 1. 注册 socket 到全局注册表(供 outbound 模块查找)
|
|
268
|
+
* 2. 恢复 ReliableEmitter 的发送能力(resume)
|
|
269
|
+
* 3. 启动消息处理循环(首次连接时启动,重连时幂等)
|
|
270
|
+
* 4. Flush 断线期间缓冲的 outbound 消息
|
|
271
|
+
* 5. 启动 health-monitor 心跳定时器
|
|
272
|
+
* 6. 通知框架 gateway 已就绪(onReady)
|
|
273
|
+
*/
|
|
274
|
+
socket.on('connect', () => {
|
|
275
|
+
log?.info(`[${CHANNEL_KEY}] Connected (accountId=${account.accountId}, id=${socket.id}, botClientId=${botClientId})`);
|
|
276
|
+
// 注册到全局 socket 注册表,供 outbound.ts 查找 socket 实例
|
|
248
277
|
registerSocket(account.accountId, socket, botClientId, reliableEmitter);
|
|
278
|
+
// 恢复可靠发送器(断线时已 pause,重连后需要 resume 才能继续发送)
|
|
249
279
|
reliableEmitter.resume();
|
|
250
|
-
|
|
251
|
-
// 重连后 flush 断线期间缓冲的 outbound 消息
|
|
280
|
+
// 重连后 flush 断线期间缓冲的 outbound 消息(主动发送场景)
|
|
252
281
|
const { sent, failed } = flushPendingMessages(account.accountId, log);
|
|
253
282
|
if (sent > 0 || failed > 0) {
|
|
254
283
|
log?.info(`[${CHANNEL_KEY}] Flushed buffered outbound messages: sent=${sent}, failed=${failed}`);
|
|
255
284
|
}
|
|
256
|
-
// 启动 health-monitor 心跳:定期刷新 lastEventAt
|
|
285
|
+
// 启动 health-monitor 心跳:定期刷新 lastEventAt,防止空闲期被框架误判销毁
|
|
286
|
+
// 重连时先清除旧定时器,再重新创建
|
|
257
287
|
if (healthHeartbeatTimer)
|
|
258
288
|
clearInterval(healthHeartbeatTimer);
|
|
259
289
|
healthHeartbeatTimer = setInterval(() => {
|
|
@@ -264,44 +294,60 @@ export async function startGateway(ctx) {
|
|
|
264
294
|
}, HEALTH_HEARTBEAT_INTERVAL);
|
|
265
295
|
onReady?.();
|
|
266
296
|
});
|
|
267
|
-
//
|
|
297
|
+
// 绑定业务事件处理器(message:private 等),委托给 socket-handlers.ts
|
|
268
298
|
bindSocketHandlers(socket, {
|
|
269
299
|
account,
|
|
270
300
|
botClientId,
|
|
271
301
|
log,
|
|
272
|
-
|
|
302
|
+
handleMessage,
|
|
273
303
|
onEvent,
|
|
274
304
|
reliableEmitter,
|
|
275
305
|
});
|
|
276
|
-
|
|
277
|
-
|
|
306
|
+
/**
|
|
307
|
+
* 连接错误事件处理。
|
|
308
|
+
* 触发时机:WebSocket 握手或认证失败时。
|
|
309
|
+
* 注意:NativeSocketClient 会自动重试,此处仅记录日志。
|
|
310
|
+
*/
|
|
311
|
+
socket.on('connect_error', (err) => {
|
|
312
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
313
|
+
log?.error(`[${CHANNEL_KEY}] connect_error: ${message}`);
|
|
278
314
|
});
|
|
279
|
-
|
|
315
|
+
/**
|
|
316
|
+
* 断线事件处理。
|
|
317
|
+
* 触发时机:网络中断、服务端主动断开、客户端主动断开等。
|
|
318
|
+
* 职责:
|
|
319
|
+
* 1. 暂停 ReliableEmitter(断线期间消息进入缓冲队列)
|
|
320
|
+
* 2. 清除 health-monitor 心跳定时器(避免在未连接状态下假装活跃)
|
|
321
|
+
* 3. 通知框架 gateway 已断线(onDisconnect)
|
|
322
|
+
* 4. 若是服务端主动断开(io server disconnect),手动触发重连
|
|
323
|
+
*
|
|
324
|
+
* 注意:断线时不调用 unregisterSocket,保留 entry 以便 outbound 消息可以缓冲。
|
|
325
|
+
* 仅在 cleanup(gateway 彻底销毁)时才 unregisterSocket。
|
|
326
|
+
*/
|
|
327
|
+
socket.on('disconnect', (reason) => {
|
|
280
328
|
log?.info(`[${CHANNEL_KEY}] Disconnected: ${reason}`);
|
|
329
|
+
// 暂停可靠发送器,断线期间的消息将进入内存缓冲队列
|
|
281
330
|
reliableEmitter.pause();
|
|
282
331
|
// 断线时停止心跳,避免在未连接状态下假装活跃
|
|
283
332
|
if (healthHeartbeatTimer) {
|
|
284
333
|
clearInterval(healthHeartbeatTimer);
|
|
285
334
|
healthHeartbeatTimer = null;
|
|
286
335
|
}
|
|
287
|
-
// 注意:断线时不调用 unregisterSocket,保留 entry 以便 outbound 消息可以缓冲。
|
|
288
|
-
// 仅在 cleanup(gateway 彻底销毁)时才 unregisterSocket。
|
|
289
336
|
onDisconnect?.();
|
|
290
|
-
if (reason ===
|
|
291
|
-
//
|
|
337
|
+
if (reason === 'io server disconnect') {
|
|
338
|
+
// 服务端主动断开(如 token 过期、服务重启),需要手动触发重连
|
|
292
339
|
log?.warn(`[${CHANNEL_KEY}] Server forced disconnect, attempting manual reconnect...`);
|
|
293
340
|
socket.connect();
|
|
294
341
|
}
|
|
295
342
|
});
|
|
296
343
|
// ---- 保持 Promise 挂起直到 abort ----
|
|
297
|
-
//
|
|
298
|
-
// 因此必须让 Promise 一直挂起,直到 abortSignal
|
|
344
|
+
// 框架约定:startAccount 返回的 Promise resolve = gateway 已退出,会触发 auto-restart。
|
|
345
|
+
// 因此必须让 Promise 一直挂起,直到 abortSignal 触发(框架主动停止账号)才 resolve。
|
|
299
346
|
return new Promise((resolve) => {
|
|
300
|
-
abortSignal.addEventListener(
|
|
347
|
+
abortSignal.addEventListener('abort', () => {
|
|
301
348
|
cleanup();
|
|
302
349
|
log?.info(`[${CHANNEL_KEY}] Gateway aborted`);
|
|
303
350
|
resolve();
|
|
304
351
|
});
|
|
305
352
|
});
|
|
306
353
|
}
|
|
307
|
-
//# sourceMappingURL=gateway.js.map
|
|
@@ -21,4 +21,3 @@ export { isSystemInjectedUserMessage, extractText, extractRawText, extractThinki
|
|
|
21
21
|
export { isCronSessionKey, isCronRunKey, isCronBaseKey, extractCronJobId, extractCronRunId, classifySessionKey, listCronSessions, groupCronSessionsByJob, extractCronInfoFromText, cleanCronUserMessage, extractCronJobIdsFromTranscript, findCronSessionsByJobIds, } from "./cron-utils.js";
|
|
22
22
|
// ── Session Reader (核心 API) ──
|
|
23
23
|
export { readSessionHistory, readSessionHistoryTail, readCronHistory, readSessionHistoryWithCron, listSessions, } from "./session-reader.js";
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -267,6 +267,9 @@ function parseLines(lines, opts) {
|
|
|
267
267
|
const msg = parsed?.message;
|
|
268
268
|
if (!msg || typeof msg !== "object")
|
|
269
269
|
continue;
|
|
270
|
+
// 过滤 openclaw delivery-mirror 消息(镜像投递,非真实消息)
|
|
271
|
+
if (msg.model === "delivery-mirror")
|
|
272
|
+
continue;
|
|
270
273
|
// 过滤传输层伪装为 user 的系统注入消息
|
|
271
274
|
if (isSystemInjectedUserMessage(msg))
|
|
272
275
|
continue;
|
|
@@ -284,4 +287,3 @@ function parseLines(lines, opts) {
|
|
|
284
287
|
// 只返回最后 limit 条
|
|
285
288
|
return messages.length > limit ? messages.slice(-limit) : messages;
|
|
286
289
|
}
|
|
287
|
-
//# sourceMappingURL=session-reader.js.map
|