lightclawbot 1.1.2 → 1.2.0-beta.0
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 +301 -257
- 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 +226 -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 +183 -234
- package/dist/src/media.js +0 -1
- package/dist/src/messaging.js +65 -0
- package/dist/src/outbound.js +131 -45
- package/dist/src/runtime.js +29 -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 +23 -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/outbound.js
CHANGED
|
@@ -4,20 +4,39 @@
|
|
|
4
4
|
* 处理 OpenClaw 框架层的主动消息发送(非 deliver 回调场景)。
|
|
5
5
|
* 例如:用户通过 /message 命令发消息、cron 定时任务触发等。
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* 发送策略(双通道 + 自动降级):
|
|
8
8
|
* 1. 优先通过 gateway 的 WS 长连接发送(socket-registry)
|
|
9
|
+
* - 连接正常 → 走可靠发送(emitWithAck + 自动重试)
|
|
10
|
+
* - 连接断开但 entry 存在(重连中)→ 缓冲消息,重连后自动 flush
|
|
9
11
|
* 2. WS 不可用时 fallback 到 REST API(需配置 apiBaseUrl)
|
|
10
12
|
*/
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { getSocket, bufferMessage, hasEntry, getBotClientId, getReliableEmitter } from
|
|
14
|
-
import {
|
|
15
|
-
/**
|
|
13
|
+
import { CHANNEL_KEY, DEFAULT_ACCOUNT_ID, DEFAULT_AGENT_ID, EVENT_MESSAGE_PRIVATE } from './config.js';
|
|
14
|
+
import { getLightclawRuntime } from './runtime.js';
|
|
15
|
+
import { getSocket, bufferMessage, hasEntry, getBotClientId, getReliableEmitter } from './socket/index.js';
|
|
16
|
+
import { resolveAccount } from './utils/index.js';
|
|
17
|
+
/**
|
|
18
|
+
* 获取出站模块专属日志器。
|
|
19
|
+
* 通过 getChildLogger 注入 module 标签,方便在日志系统中过滤出站相关日志。
|
|
20
|
+
*/
|
|
16
21
|
function getLogger() {
|
|
17
|
-
return
|
|
22
|
+
return getLightclawRuntime().logging.getChildLogger({ module: 'outbound' });
|
|
18
23
|
}
|
|
19
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* 出站消息 ID 计数器,用于生成全局唯一的消息序号。
|
|
26
|
+
* 模块级变量,进程生命周期内单调递增,不会重置。
|
|
27
|
+
*/
|
|
20
28
|
let outboundMsgCounter = 0;
|
|
29
|
+
/**
|
|
30
|
+
* 生成出站消息的唯一 ID。
|
|
31
|
+
*
|
|
32
|
+
* ID 格式:`ob-<时间戳base36>-<随机串>-<序号base36>`
|
|
33
|
+
* - `ob-` 前缀:标识来源为 outbound 模块,便于日志追踪
|
|
34
|
+
* - 时间戳(base36):毫秒级,保证时间有序性
|
|
35
|
+
* - 随机串(6位):防止同一毫秒内的碰撞
|
|
36
|
+
* - 序号(base36):进程内单调递增,兜底保证唯一性
|
|
37
|
+
*
|
|
38
|
+
* @returns 格式为 `ob-<ts>-<rand>-<seq>` 的唯一消息 ID
|
|
39
|
+
*/
|
|
21
40
|
function generateOutboundMsgId() {
|
|
22
41
|
const ts = Date.now().toString(36);
|
|
23
42
|
const rand = Math.random().toString(36).substring(2, 8);
|
|
@@ -25,40 +44,70 @@ function generateOutboundMsgId() {
|
|
|
25
44
|
return `ob-${ts}-${rand}-${seq}`;
|
|
26
45
|
}
|
|
27
46
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
47
|
+
* 解析消息目标地址,提取纯用户/群组 ID。
|
|
48
|
+
*
|
|
49
|
+
* 支持的输入格式(均会被剥离前缀,返回纯 ID):
|
|
50
|
+
* - `lightclawbot:dm:123` → `123`
|
|
51
|
+
* - `lightclawbot:group:456` → `456`
|
|
52
|
+
* - `user:123` → `123`
|
|
53
|
+
* - `channel:456` → `456`
|
|
54
|
+
* - `dm:123` → `123`
|
|
55
|
+
* - `group:456` → `456`
|
|
56
|
+
* - `123` → `123`(纯 ID,原样返回)
|
|
57
|
+
*
|
|
58
|
+
* @param to - 原始目标地址字符串
|
|
59
|
+
* @returns 去除所有前缀后的纯 ID 字符串
|
|
30
60
|
*/
|
|
31
61
|
function resolveTarget(to) {
|
|
32
|
-
return to
|
|
33
|
-
|
|
34
|
-
.replace(
|
|
62
|
+
return (to
|
|
63
|
+
// 第一步:去掉通道名前缀(如 "lightclawbot:")
|
|
64
|
+
.replace(new RegExp(`^${CHANNEL_KEY}:`, 'i'), '')
|
|
65
|
+
// 第二步:去掉类型前缀(user: / channel: / dm: / group:)
|
|
66
|
+
.replace(/^(user|channel|dm|group):/, ''));
|
|
35
67
|
}
|
|
36
68
|
/**
|
|
37
|
-
* 通过
|
|
69
|
+
* 通过 WebSocket 长连接发送消息。
|
|
38
70
|
*
|
|
39
|
-
*
|
|
40
|
-
* 1. socket
|
|
41
|
-
*
|
|
42
|
-
*
|
|
71
|
+
* 内部策略(按优先级):
|
|
72
|
+
* 1. **可靠发送**:entry 存在且 socket 已连接 → 使用 `emitWithAck` 发送,
|
|
73
|
+
* 内置 ACK 确认 + 自动重试,发送失败时记录错误日志。
|
|
74
|
+
* 2. **直接 emit(兜底)**:可靠发送器不可用时,直接调用 `socket.emit`,
|
|
75
|
+
* 不保证送达,仅作为最后防线。
|
|
76
|
+
* 3. **消息缓冲**:socket 断开但 entry 仍存在(正在自动重连)→
|
|
77
|
+
* 将消息写入缓冲队列,重连成功后由 gateway 自动 flush。
|
|
78
|
+
* 4. **返回 null**:entry 不存在(gateway 未启动或已销毁)→
|
|
79
|
+
* 调用方应降级到 REST API。
|
|
80
|
+
*
|
|
81
|
+
* @param accountId - 发送账户 ID,为空时使用 DEFAULT_ACCOUNT_ID
|
|
82
|
+
* @param target - 已解析的纯目标 ID(用户 ID 或群组 ID)
|
|
83
|
+
* @param text - 消息文本内容
|
|
84
|
+
* @param replyToId - 回复的原始消息 ID(可选)
|
|
85
|
+
* @returns 成功时返回消息 ID 字符串;无法通过 WS 发送时返回 null
|
|
43
86
|
*/
|
|
44
87
|
function sendViaSocket(accountId, target, text, replyToId) {
|
|
45
88
|
const resolvedAccountId = accountId || DEFAULT_ACCOUNT_ID;
|
|
89
|
+
// 从 socket-registry 中获取当前账户的 socket entry
|
|
46
90
|
const entry = getSocket(resolvedAccountId);
|
|
47
91
|
const msgId = generateOutboundMsgId();
|
|
92
|
+
// 构造标准消息体,格式与 gateway 入站消息保持一致
|
|
48
93
|
const message = {
|
|
49
94
|
msgId,
|
|
50
|
-
|
|
95
|
+
// 优先使用 entry 中缓存的 botClientId,entry 不存在时从 registry 直接查询
|
|
96
|
+
from: entry?.botClientId ?? getBotClientId(resolvedAccountId) ?? '',
|
|
51
97
|
to: target,
|
|
52
|
-
content:
|
|
98
|
+
content: text,
|
|
53
99
|
timestamp: Date.now(),
|
|
100
|
+
// undefined 表示非回复消息,避免发送多余字段
|
|
54
101
|
replyToMsgId: replyToId ?? undefined,
|
|
102
|
+
// 所有出站消息必须携带 agentId,outbound 主动发送场景使用默认 Agent
|
|
103
|
+
agentId: DEFAULT_AGENT_ID,
|
|
55
104
|
};
|
|
56
105
|
if (entry) {
|
|
57
|
-
// Socket
|
|
106
|
+
// 策略 1:Socket 已连接,优先走可靠发送(emitWithAck + 自动重试)
|
|
58
107
|
const emitter = getReliableEmitter(resolvedAccountId);
|
|
59
108
|
if (emitter) {
|
|
60
|
-
emitter.emitWithAck(EVENT_MESSAGE_PRIVATE, message, msgId)
|
|
61
|
-
|
|
109
|
+
emitter.emitWithAck(EVENT_MESSAGE_PRIVATE, message, msgId).then((ok) => {
|
|
110
|
+
// ok=false 表示重试耗尽仍未收到 ACK,记录错误供告警系统捕获
|
|
62
111
|
if (!ok) {
|
|
63
112
|
getLogger().error(`[${CHANNEL_KEY}] outbound delivery failed after retries: msgId=${msgId}`);
|
|
64
113
|
}
|
|
@@ -66,18 +115,20 @@ function sendViaSocket(accountId, target, text, replyToId) {
|
|
|
66
115
|
getLogger().info(`[${CHANNEL_KEY}] outbound sent via reliable WS: to=${target} msgId=${msgId}`);
|
|
67
116
|
return msgId;
|
|
68
117
|
}
|
|
69
|
-
//
|
|
118
|
+
// 策略 2:可靠发送器不可用,直接 emit(兜底,正常情况不应走到此分支)
|
|
70
119
|
try {
|
|
71
120
|
entry.socket.emit(EVENT_MESSAGE_PRIVATE, message);
|
|
72
121
|
getLogger().info(`[${CHANNEL_KEY}] outbound sent via WS (fallback): to=${target} msgId=${msgId}`);
|
|
73
122
|
return msgId;
|
|
74
123
|
}
|
|
75
124
|
catch (err) {
|
|
125
|
+
// emit 本身抛异常(如 socket 已关闭),降级到 REST API
|
|
76
126
|
getLogger().warn(`[${CHANNEL_KEY}] outbound WS emit failed: ${err}`);
|
|
77
127
|
return null;
|
|
78
128
|
}
|
|
79
129
|
}
|
|
80
|
-
// Socket 断开但 entry
|
|
130
|
+
// 策略 3:Socket 断开但 entry 存在(正在自动重连),将消息写入缓冲队列
|
|
131
|
+
// 重连成功后,gateway 会自动 flush 缓冲队列,保证消息最终送达
|
|
81
132
|
if (hasEntry(resolvedAccountId)) {
|
|
82
133
|
const buffered = bufferMessage(resolvedAccountId, message);
|
|
83
134
|
if (buffered) {
|
|
@@ -85,32 +136,47 @@ function sendViaSocket(accountId, target, text, replyToId) {
|
|
|
85
136
|
return msgId;
|
|
86
137
|
}
|
|
87
138
|
}
|
|
88
|
-
//
|
|
139
|
+
// 策略 4:entry 不存在,gateway 未启动或已销毁,返回 null 触发 REST 降级
|
|
89
140
|
return null;
|
|
90
141
|
}
|
|
91
142
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
143
|
+
* 发送纯文本消息。
|
|
144
|
+
*
|
|
145
|
+
* 由 `channel.outbound.sendText` 调用,是框架层文本消息的统一出口。
|
|
146
|
+
*
|
|
147
|
+
* 发送流程:
|
|
148
|
+
* 1. 解析账户配置(API Key、Base URL 等)
|
|
149
|
+
* 2. 规范化目标地址(去除前缀,提取纯 ID)
|
|
150
|
+
* 3. 优先通过 WS 发送;WS 不可用时降级到 REST API
|
|
151
|
+
* 4. REST API 也不可用时抛出错误,由框架层统一处理
|
|
152
|
+
*
|
|
153
|
+
* @param ctx - OpenClaw 框架注入的出站上下文,包含 to、text、accountId、replyToId、cfg 等字段
|
|
154
|
+
* @returns `{ channel, messageId }` — 发送成功后的通道标识和消息 ID
|
|
155
|
+
* @throws 当 WS 和 REST API 均不可用时抛出 Error
|
|
94
156
|
*/
|
|
95
157
|
export async function sendText(ctx) {
|
|
96
158
|
const log = getLogger();
|
|
97
159
|
try {
|
|
160
|
+
// 解析账户配置(含 apiKey、apiBaseUrl、accountId 等)
|
|
98
161
|
const account = resolveAccount(ctx.cfg, ctx.accountId);
|
|
162
|
+
// 将框架格式的目标地址转换为纯 ID
|
|
99
163
|
const target = resolveTarget(ctx.to);
|
|
100
|
-
// 优先走 WS
|
|
164
|
+
// 优先走 WS 长连接(低延迟、无额外网络开销)
|
|
101
165
|
const wsMsgId = sendViaSocket(account.accountId, target, ctx.text, ctx.replyToId);
|
|
102
166
|
if (wsMsgId) {
|
|
103
167
|
return { channel: CHANNEL_KEY, messageId: wsMsgId };
|
|
104
168
|
}
|
|
105
|
-
//
|
|
169
|
+
// WS 不可用,降级到 REST API
|
|
170
|
+
// 若未配置 apiBaseUrl,则无法降级,直接抛出错误
|
|
106
171
|
if (!account.apiBaseUrl) {
|
|
107
|
-
throw new Error(
|
|
172
|
+
throw new Error('WS not connected and apiBaseUrl not configured, cannot send outbound message');
|
|
108
173
|
}
|
|
109
174
|
log.info(`[${CHANNEL_KEY}] outbound fallback to REST API: to=${target}`);
|
|
110
175
|
const resp = await fetch(`${account.apiBaseUrl}/send`, {
|
|
111
|
-
method:
|
|
176
|
+
method: 'POST',
|
|
112
177
|
headers: {
|
|
113
|
-
|
|
178
|
+
'Content-Type': 'application/json',
|
|
179
|
+
// Bearer Token 鉴权,apiKey 来自账户配置
|
|
114
180
|
Authorization: `Bearer ${account.apiKey}`,
|
|
115
181
|
},
|
|
116
182
|
body: JSON.stringify({
|
|
@@ -119,11 +185,13 @@ export async function sendText(ctx) {
|
|
|
119
185
|
replyToMessageId: ctx.replyToId,
|
|
120
186
|
}),
|
|
121
187
|
});
|
|
188
|
+
// HTTP 非 2xx 状态码视为发送失败,读取响应体作为错误信息
|
|
122
189
|
if (!resp.ok) {
|
|
123
190
|
const errText = await resp.text();
|
|
124
191
|
throw new Error(`Send failed (${resp.status}): ${errText}`);
|
|
125
192
|
}
|
|
126
193
|
const data = (await resp.json());
|
|
194
|
+
// 服务端未返回 messageId 时,使用时间戳兜底,保证返回值非空
|
|
127
195
|
return { channel: CHANNEL_KEY, messageId: data.messageId ?? `msg_${Date.now()}` };
|
|
128
196
|
}
|
|
129
197
|
catch (err) {
|
|
@@ -132,50 +200,69 @@ export async function sendText(ctx) {
|
|
|
132
200
|
}
|
|
133
201
|
}
|
|
134
202
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
203
|
+
* 发送媒体消息(图片、文件、视频等)。
|
|
204
|
+
*
|
|
205
|
+
* 由 `channel.outbound.sendMedia` 调用,是框架层媒体消息的统一出口。
|
|
206
|
+
*
|
|
207
|
+
* 发送策略(媒体消息比文本消息更复杂,需区分是否有 mediaUrl):
|
|
208
|
+
* - **无 mediaUrl**:仅发送文字说明,走 WS → REST 降级链路(与 sendText 一致)
|
|
209
|
+
* - **有 mediaUrl + 有 REST API**:走 REST API 发送完整媒体消息(含 URL)
|
|
210
|
+
* - **有 mediaUrl + 无 REST API**:WS 不支持大文件传输,仅发送文字说明部分
|
|
211
|
+
* - **WS 和 REST 均不可用**:抛出错误
|
|
212
|
+
*
|
|
213
|
+
* 注意:WS 通道不适合传输大文件(二进制数据),因此媒体文件始终通过 REST API 发送;
|
|
214
|
+
* WS 仅用于发送媒体消息的文字说明部分(作为降级兜底)。
|
|
215
|
+
*
|
|
216
|
+
* @param ctx - OpenClaw 框架注入的出站上下文,包含 to、text、mediaUrl、accountId、replyToId、cfg 等字段
|
|
217
|
+
* @returns `{ channel, messageId }` — 发送成功后的通道标识和消息 ID
|
|
218
|
+
* @throws 当 WS 和 REST API 均不可用时抛出 Error
|
|
137
219
|
*/
|
|
138
220
|
export async function sendMedia(ctx) {
|
|
139
221
|
const log = getLogger();
|
|
140
222
|
try {
|
|
223
|
+
// 解析账户配置
|
|
141
224
|
const account = resolveAccount(ctx.cfg, ctx.accountId);
|
|
225
|
+
// 规范化目标地址
|
|
142
226
|
const target = resolveTarget(ctx.to);
|
|
143
|
-
//
|
|
144
|
-
// 如果有 mediaUrl 且没有 REST API,仍用 WS 发文本
|
|
227
|
+
// 无 mediaUrl 时,退化为纯文本发送,走 WS → REST 降级链路
|
|
145
228
|
if (!ctx.mediaUrl) {
|
|
146
229
|
const wsMsgId = sendViaSocket(account.accountId, target, ctx.text, ctx.replyToId);
|
|
147
230
|
if (wsMsgId) {
|
|
148
231
|
return { channel: CHANNEL_KEY, messageId: wsMsgId };
|
|
149
232
|
}
|
|
150
233
|
}
|
|
151
|
-
//
|
|
234
|
+
// 未配置 REST API 时的兜底处理:
|
|
235
|
+
// 即使有 mediaUrl 也无法发送完整媒体,退而发送文字说明部分(通过 WS)
|
|
152
236
|
if (!account.apiBaseUrl) {
|
|
153
|
-
// 没有 REST API 也没有 mediaUrl,用 WS 发文本
|
|
154
237
|
const wsMsgId = sendViaSocket(account.accountId, target, ctx.text, ctx.replyToId);
|
|
155
238
|
if (wsMsgId) {
|
|
156
239
|
return { channel: CHANNEL_KEY, messageId: wsMsgId };
|
|
157
240
|
}
|
|
158
|
-
|
|
241
|
+
// WS 也不可用,彻底无法发送,抛出错误
|
|
242
|
+
throw new Error('WS not connected and apiBaseUrl not configured, cannot send outbound media');
|
|
159
243
|
}
|
|
244
|
+
// 通过 REST API 发送完整媒体消息(含 mediaUrl)
|
|
160
245
|
log.info(`[${CHANNEL_KEY}] outbound media via REST API: to=${target}`);
|
|
161
246
|
const resp = await fetch(`${account.apiBaseUrl}/send-media`, {
|
|
162
|
-
method:
|
|
247
|
+
method: 'POST',
|
|
163
248
|
headers: {
|
|
164
|
-
|
|
249
|
+
'Content-Type': 'application/json',
|
|
165
250
|
Authorization: `Bearer ${account.apiKey}`,
|
|
166
251
|
},
|
|
167
252
|
body: JSON.stringify({
|
|
168
253
|
target,
|
|
169
|
-
text: ctx.text,
|
|
170
|
-
mediaUrl: ctx.mediaUrl,
|
|
254
|
+
text: ctx.text, // 媒体消息的文字说明(可选)
|
|
255
|
+
mediaUrl: ctx.mediaUrl, // 媒体资源 URL(图片/文件/视频等)
|
|
171
256
|
replyToMessageId: ctx.replyToId,
|
|
172
257
|
}),
|
|
173
258
|
});
|
|
259
|
+
// HTTP 非 2xx 状态码视为发送失败
|
|
174
260
|
if (!resp.ok) {
|
|
175
261
|
const errText = await resp.text();
|
|
176
262
|
throw new Error(`Send media failed (${resp.status}): ${errText}`);
|
|
177
263
|
}
|
|
178
264
|
const data = (await resp.json());
|
|
265
|
+
// 服务端未返回 messageId 时,使用时间戳兜底
|
|
179
266
|
return { channel: CHANNEL_KEY, messageId: data.messageId ?? `msg_${Date.now()}` };
|
|
180
267
|
}
|
|
181
268
|
catch (err) {
|
|
@@ -183,4 +270,3 @@ export async function sendMedia(ctx) {
|
|
|
183
270
|
throw err;
|
|
184
271
|
}
|
|
185
272
|
}
|
|
186
|
-
//# sourceMappingURL=outbound.js.map
|
package/dist/src/runtime.js
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LightClaw — 插件运行时存储模块
|
|
3
|
+
*
|
|
4
|
+
* 使用 OpenClaw SDK 标准的 createPluginRuntimeStore 工具函数替代传统的手动单例管理模式,
|
|
5
|
+
*
|
|
6
|
+
* 该模块的主要功能:
|
|
7
|
+
* - 提供类型安全的运行时存储管理
|
|
8
|
+
* - 避免手动单例模式带来的潜在问题
|
|
9
|
+
* - 提供统一的错误处理和初始化状态管理
|
|
10
|
+
* - 支持插件运行时的动态设置和获取
|
|
11
|
+
*/
|
|
12
|
+
// 导入运行时存储创建工具函数
|
|
13
|
+
import { createPluginRuntimeStore } from 'openclaw/plugin-sdk/runtime-store';
|
|
14
|
+
/**
|
|
15
|
+
* 创建 LightClaw 插件运行时存储
|
|
16
|
+
*
|
|
17
|
+
* 使用 createPluginRuntimeStore 工厂函数创建运行时存储对象,
|
|
18
|
+
* 该函数返回一个包含 setRuntime 和 getRuntime 方法的对象。
|
|
19
|
+
*
|
|
20
|
+
* @template PluginRuntime - 运行时对象的类型参数
|
|
21
|
+
* @param {string} 'LightClaw runtime not initialized' - 运行时未初始化时的错误消息
|
|
22
|
+
* @returns {Object} 包含 setRuntime 和 getRuntime 方法的对象
|
|
23
|
+
* @property {Function} setRuntime - 设置运行时实例的函数
|
|
24
|
+
* @property {Function} getRuntime - 获取运行时实例的函数(如果未设置会抛出错误)
|
|
25
|
+
*/
|
|
26
|
+
const { setRuntime: setLightclawRuntime, getRuntime: getLightclawRuntime } = createPluginRuntimeStore('LightClaw runtime not initialized' // 运行时未初始化时的自定义错误消息
|
|
27
|
+
);
|
|
28
|
+
// 导出运行时管理函数,供其他模块使用
|
|
29
|
+
export { getLightclawRuntime, setLightclawRuntime };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LightClaw — Setup 核心逻辑
|
|
3
|
+
*
|
|
4
|
+
* 从 channel.ts 中提取的 setup 适配器,
|
|
5
|
+
* 被 channel.ts(完整插件)和 channel.setup.ts(轻量 setup 插件)共享。
|
|
6
|
+
*/
|
|
7
|
+
import { applyAccountNameToChannelSection } from 'openclaw/plugin-sdk/core';
|
|
8
|
+
import { CHANNEL_KEY, applyAccountConfig } from './config.js';
|
|
9
|
+
import { defaultAccountId } from './utils/account.js';
|
|
10
|
+
export const lightclawSetupAdapter = {
|
|
11
|
+
resolveAccountId: ({ accountId, cfg }) => accountId?.trim().toLowerCase() || defaultAccountId(cfg),
|
|
12
|
+
applyAccountName: ({ cfg, accountId, name }) => applyAccountNameToChannelSection({ cfg, channelKey: CHANNEL_KEY, accountId, name }),
|
|
13
|
+
validateInput: ({ input }) => {
|
|
14
|
+
if (!input.token && !input.useEnv) {
|
|
15
|
+
return 'Requires --token <apiKey> or --use-env (set LIGHTCLAW_API_KEY, LIGHTCLAW_API_BASE_URL)';
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
},
|
|
19
|
+
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
20
|
+
const token = input.token;
|
|
21
|
+
return applyAccountConfig(cfg, accountId, {
|
|
22
|
+
apiKey: token,
|
|
23
|
+
apiBaseUrl: input.apiBaseUrl,
|
|
24
|
+
name: input.name,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LightClaw — 插件基础定义(shared)
|
|
3
|
+
*
|
|
4
|
+
* 参照官方 Discord/Slack 的 shared.ts 模式:
|
|
5
|
+
* - 提供 createLightclawPluginBase() 工厂函数
|
|
6
|
+
* - 共享 config adapter 和常量
|
|
7
|
+
*
|
|
8
|
+
* 此模块被 channel.ts(完整插件)和 channel.setup.ts(轻量 setup 插件)同时使用。
|
|
9
|
+
*/
|
|
10
|
+
import { createChannelPluginBase, deleteAccountFromConfigSection, setAccountEnabledInConfigSection, } from 'openclaw/plugin-sdk/core';
|
|
11
|
+
import { CHANNEL_KEY, DEFAULT_ACCOUNT_ID } from './config.js';
|
|
12
|
+
import { listAccountIds, resolveAccount, defaultAccountId } from './utils/account.js';
|
|
13
|
+
// ============================================================
|
|
14
|
+
// 配置适配器
|
|
15
|
+
// ============================================================
|
|
16
|
+
/**
|
|
17
|
+
* LightClaw 配置适配器(config section)
|
|
18
|
+
*
|
|
19
|
+
* 官方渠道使用 createScopedChannelConfigAdapter,
|
|
20
|
+
* LightClaw 因有自定义的 apiKeys 数组等特殊配置,保留自定义实现。
|
|
21
|
+
*/
|
|
22
|
+
export const lightclawConfigAdapter = {
|
|
23
|
+
/**
|
|
24
|
+
* 列出当前配置中所有已注册的账户 ID。
|
|
25
|
+
* @param cfg - 全局 OpenClaw 配置对象
|
|
26
|
+
*/
|
|
27
|
+
listAccountIds: (cfg) => listAccountIds(cfg),
|
|
28
|
+
/**
|
|
29
|
+
* 根据账户 ID 解析出完整的账户配置对象(含 API Key、Base URL 等)。
|
|
30
|
+
* @param cfg - 全局配置对象
|
|
31
|
+
* @param accountId - 目标账户 ID
|
|
32
|
+
*/
|
|
33
|
+
resolveAccount: (cfg, accountId) => {
|
|
34
|
+
return resolveAccount(cfg, accountId);
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* 获取默认账户 ID(通常为 DEFAULT_ACCOUNT_ID 常量)。
|
|
38
|
+
* @param cfg - 全局配置对象
|
|
39
|
+
*/
|
|
40
|
+
defaultAccountId: (cfg) => defaultAccountId(cfg),
|
|
41
|
+
/**
|
|
42
|
+
* 启用或禁用指定账户。
|
|
43
|
+
* 委托给 SDK 的 setAccountEnabledInConfigSection 工具函数,
|
|
44
|
+
* allowTopLevel=true 表示允许在顶层配置节(非 accounts 子对象)中操作。
|
|
45
|
+
*/
|
|
46
|
+
setAccountEnabled: ({ cfg, accountId, enabled }) => {
|
|
47
|
+
return setAccountEnabledInConfigSection({
|
|
48
|
+
cfg,
|
|
49
|
+
sectionKey: CHANNEL_KEY,
|
|
50
|
+
accountId,
|
|
51
|
+
enabled,
|
|
52
|
+
allowTopLevel: true,
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* 从配置中删除指定账户,同时清除关联的基础字段。
|
|
57
|
+
* clearBaseFields 指定了删除账户时需要一并清空的顶层字段。
|
|
58
|
+
*/
|
|
59
|
+
deleteAccount: ({ cfg, accountId }) => {
|
|
60
|
+
return deleteAccountFromConfigSection({
|
|
61
|
+
cfg,
|
|
62
|
+
sectionKey: CHANNEL_KEY,
|
|
63
|
+
accountId,
|
|
64
|
+
clearBaseFields: ['apiBaseUrl', 'name'],
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* 判断账户是否已完成配置, apiKey是否存在。
|
|
69
|
+
* @param account - 已解析的账户对象
|
|
70
|
+
*/
|
|
71
|
+
isConfigured: (account) => {
|
|
72
|
+
return Boolean(account?.apiKey);
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* 将账户信息序列化为框架可展示的摘要对象。
|
|
76
|
+
* 用于 CLI 的 `status` 命令和 UI 的账户列表展示。
|
|
77
|
+
* @param account - 已解析的账户对象
|
|
78
|
+
*/
|
|
79
|
+
describeAccount: (account) => ({
|
|
80
|
+
accountId: account.accountId ?? DEFAULT_ACCOUNT_ID,
|
|
81
|
+
name: account.name || '',
|
|
82
|
+
enabled: account.enabled ?? false,
|
|
83
|
+
configured: Boolean(account?.apiKey),
|
|
84
|
+
}),
|
|
85
|
+
/**
|
|
86
|
+
* 解析账户的 allowFrom 白名单列表(允许接收消息的来源 ID)。
|
|
87
|
+
* 返回字符串数组,供框架做入站消息过滤。
|
|
88
|
+
* @param cfg - 全局配置对象
|
|
89
|
+
* @param accountId - 目标账户 ID
|
|
90
|
+
*/
|
|
91
|
+
resolveAllowFrom: ({ cfg, accountId }) => {
|
|
92
|
+
const account = resolveAccount(cfg, accountId);
|
|
93
|
+
return account.allowFrom?.map(String) ?? [];
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
// ============================================================
|
|
97
|
+
// 插件基础工厂
|
|
98
|
+
// ============================================================
|
|
99
|
+
/**
|
|
100
|
+
* createLightclawPluginBase
|
|
101
|
+
*
|
|
102
|
+
* 参照 Discord 的 createDiscordPluginBase / Slack 的 createSlackPluginBase 模式,
|
|
103
|
+
* 使用 SDK 提供的 createChannelPluginBase 构建插件骨架。
|
|
104
|
+
*
|
|
105
|
+
* 返回的字段集(id, meta, capabilities, streaming, configSchema, config, setup)
|
|
106
|
+
* 被 channel.ts 和 channel.setup.ts 共享。
|
|
107
|
+
*/
|
|
108
|
+
export function createLightclawPluginBase(params) {
|
|
109
|
+
return createChannelPluginBase({
|
|
110
|
+
id: CHANNEL_KEY,
|
|
111
|
+
meta: {
|
|
112
|
+
id: CHANNEL_KEY,
|
|
113
|
+
label: 'LightClawBot',
|
|
114
|
+
selectionLabel: 'LightClawBot',
|
|
115
|
+
docsPath: '/docs/channels/lightclawbot',
|
|
116
|
+
blurb: 'Connect OpenClaw to your LightClawBot via WebSocket long-connection',
|
|
117
|
+
order: 60,
|
|
118
|
+
},
|
|
119
|
+
capabilities: {
|
|
120
|
+
chatTypes: ['direct'],
|
|
121
|
+
media: true,
|
|
122
|
+
reactions: false,
|
|
123
|
+
threads: false,
|
|
124
|
+
// true = deliver 回调会收到 kind="block" 的中间块,实现流式推送
|
|
125
|
+
blockStreaming: true,
|
|
126
|
+
},
|
|
127
|
+
streaming: {
|
|
128
|
+
blockStreamingCoalesceDefaults: { minChars: 1500, idleMs: 1000 },
|
|
129
|
+
},
|
|
130
|
+
reload: { configPrefixes: [`channels.${CHANNEL_KEY}`] },
|
|
131
|
+
configSchema: {
|
|
132
|
+
schema: {
|
|
133
|
+
type: 'object',
|
|
134
|
+
additionalProperties: false,
|
|
135
|
+
properties: {},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
config: lightclawConfigAdapter,
|
|
139
|
+
setup: params.setup,
|
|
140
|
+
});
|
|
141
|
+
}
|