openclaw-plugin-yuanbao 2.11.0 → 3.0.1-beta.fc13eaa5
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/api.ts +12 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.js +7 -0
- package/dist/index.d.ts +2 -9
- package/dist/index.js +48 -33
- package/dist/runtime-api.d.ts +5 -0
- package/dist/runtime-api.js +1 -0
- package/dist/setup-entry.d.ts +2 -0
- package/dist/setup-entry.js +8 -0
- package/dist/src/{yuanbao-server → access}/api.d.ts +3 -3
- package/dist/src/access/api.js +2 -0
- package/dist/src/access/http/bot-id-cache.d.ts +3 -0
- package/dist/src/access/http/bot-id-cache.js +14 -0
- package/dist/src/access/http/main.d.ts +4 -0
- package/dist/src/access/http/main.js +18 -0
- package/dist/src/{yuanbao-server → access}/http/request.d.ts +16 -17
- package/dist/src/{yuanbao-server → access}/http/request.js +98 -96
- package/dist/src/{yuanbao-server → access}/ws/biz-codec.d.ts +5 -5
- package/dist/src/{yuanbao-server → access}/ws/biz-codec.js +93 -60
- package/dist/src/{yuanbao-server → access}/ws/client.d.ts +4 -2
- package/dist/src/{yuanbao-server → access}/ws/client.js +176 -132
- package/dist/src/{yuanbao-server → access}/ws/conn-codec.d.ts +1 -1
- package/dist/src/{yuanbao-server → access}/ws/conn-codec.js +22 -19
- package/dist/src/{yuanbao-server → access}/ws/gateway.d.ts +12 -5
- package/dist/src/access/ws/gateway.js +328 -0
- package/dist/src/{yuanbao-server → access}/ws/index.d.ts +9 -9
- package/dist/src/{yuanbao-server → access}/ws/index.js +6 -6
- package/dist/src/{yuanbao-server → access}/ws/runtime.d.ts +1 -1
- package/dist/src/{yuanbao-server → access}/ws/types.d.ts +4 -4
- package/dist/src/accounts.d.ts +2 -2
- package/dist/src/accounts.js +33 -57
- package/dist/src/business/actions/deliver.d.ts +16 -0
- package/dist/src/business/actions/deliver.js +23 -0
- package/dist/src/business/actions/handler.d.ts +9 -0
- package/dist/src/business/actions/handler.js +120 -0
- package/dist/src/business/actions/index.d.ts +3 -0
- package/dist/src/business/actions/index.js +16 -0
- package/dist/src/business/actions/media/send.d.ts +11 -0
- package/dist/src/business/actions/media/send.js +31 -0
- package/dist/src/business/actions/resolve-target.d.ts +37 -0
- package/dist/src/business/actions/resolve-target.js +36 -0
- package/dist/src/business/actions/sticker/builtin-stickers.json +542 -0
- package/dist/src/{sticker → business/actions/sticker}/init-builtin-stickers.js +4 -4
- package/dist/src/business/actions/sticker/send.d.ts +18 -0
- package/dist/src/business/actions/sticker/send.js +56 -0
- package/dist/src/{sticker → business/actions/sticker}/sticker-cache.d.ts +1 -1
- package/dist/src/{sticker → business/actions/sticker}/sticker-cache.js +56 -38
- package/dist/src/{sticker → business/actions/sticker}/sticker-types.d.ts +1 -1
- package/dist/src/business/actions/text/send.d.ts +7 -0
- package/dist/src/business/actions/text/send.js +15 -0
- package/dist/src/{commands/slash-commands → business/commands/command-sync}/index.d.ts +2 -2
- package/dist/src/business/commands/command-sync/index.js +83 -0
- package/dist/src/{module → business/commands}/log-upload/cos-upload.d.ts +2 -2
- package/dist/src/{module → business/commands}/log-upload/cos-upload.js +32 -29
- package/dist/src/{module → business/commands}/log-upload/extractor.d.ts +1 -1
- package/dist/src/{module → business/commands}/log-upload/extractor.js +56 -40
- package/dist/src/business/commands/log-upload/index.d.ts +4 -0
- package/dist/src/business/commands/log-upload/index.js +25 -0
- package/dist/src/{module/log-upload/index.d.ts → business/commands/log-upload/perform.d.ts} +2 -2
- package/dist/src/{module/log-upload/index.js → business/commands/log-upload/perform.js} +51 -54
- package/dist/src/{module → business/commands}/log-upload/types.d.ts +2 -2
- package/dist/src/business/inbound/index.d.ts +25 -0
- package/dist/src/business/inbound/index.js +25 -0
- package/dist/src/{message-handler → business/messaging}/callbacks/recall.d.ts +2 -2
- package/dist/src/{message-handler → business/messaging}/callbacks/recall.js +27 -30
- package/dist/src/{message-handler → business/messaging}/chat-history.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/chat-history.js +2 -1
- package/dist/src/business/messaging/chat-history.test.js +41 -0
- package/dist/src/business/messaging/context.d.ts +22 -0
- package/dist/src/business/messaging/context.js +1 -0
- package/dist/src/{dm → business/messaging}/directory.d.ts +5 -2
- package/dist/src/business/messaging/directory.js +94 -0
- package/dist/src/{message-handler → business/messaging}/extract.d.ts +3 -3
- package/dist/src/{message-handler → business/messaging}/extract.js +13 -5
- package/dist/src/business/messaging/extract.test.d.ts +1 -0
- package/dist/src/business/messaging/extract.test.js +66 -0
- package/dist/src/{message-handler → business/messaging}/handlers/custom/index.d.ts +2 -2
- package/dist/src/{message-handler → business/messaging}/handlers/custom/index.js +27 -15
- package/dist/src/{message-handler → business/messaging}/handlers/custom/link-card.js +21 -16
- package/dist/src/business/messaging/handlers/custom.d.ts +1 -0
- package/dist/src/business/messaging/handlers/custom.js +1 -0
- package/dist/src/business/messaging/handlers/custom.test.d.ts +1 -0
- package/dist/src/business/messaging/handlers/custom.test.js +77 -0
- package/dist/src/{message-handler → business/messaging}/handlers/face.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/handlers/face.js +3 -3
- package/dist/src/business/messaging/handlers/face.test.d.ts +1 -0
- package/dist/src/business/messaging/handlers/face.test.js +54 -0
- package/dist/src/{message-handler → business/messaging}/handlers/file.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/handlers/file.js +7 -5
- package/dist/src/{message-handler → business/messaging}/handlers/image.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/handlers/image.js +4 -4
- package/dist/src/business/messaging/handlers/image.test.d.ts +1 -0
- package/dist/src/business/messaging/handlers/image.test.js +49 -0
- package/dist/src/{message-handler → business/messaging}/handlers/index.d.ts +10 -10
- package/dist/src/{message-handler → business/messaging}/handlers/index.js +32 -30
- package/dist/src/business/messaging/handlers/index.test.d.ts +1 -0
- package/dist/src/business/messaging/handlers/index.test.js +67 -0
- package/dist/src/{message-handler → business/messaging}/handlers/sound.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/handlers/sound.js +2 -2
- package/dist/src/{message-handler → business/messaging}/handlers/text.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/handlers/text.js +2 -2
- package/dist/src/business/messaging/handlers/text.test.d.ts +1 -0
- package/dist/src/business/messaging/handlers/text.test.js +33 -0
- package/dist/src/{message-handler → business/messaging}/handlers/types.d.ts +7 -7
- package/dist/src/business/messaging/handlers/types.js +1 -0
- package/dist/src/{message-handler → business/messaging}/handlers/video.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/handlers/video.js +3 -3
- package/dist/src/business/messaging/index.d.ts +7 -0
- package/dist/src/business/messaging/index.js +3 -0
- package/dist/src/{dm/inbound.d.ts → business/messaging/mention.d.ts} +1 -1
- package/dist/src/{dm/inbound.js → business/messaging/mention.js} +17 -9
- package/dist/src/{message-handler → business/messaging}/quote.d.ts +1 -1
- package/dist/src/{message-handler → business/messaging}/quote.js +13 -10
- package/dist/src/business/messaging/quote.test.d.ts +1 -0
- package/dist/src/business/messaging/quote.test.js +68 -0
- package/dist/src/{message-handler → business/messaging}/system-callbacks.d.ts +3 -3
- package/dist/src/{message-handler → business/messaging}/system-callbacks.js +7 -5
- package/dist/src/business/messaging/targets.d.ts +9 -0
- package/dist/src/business/messaging/targets.js +38 -0
- package/dist/src/business/messaging/targets.test.d.ts +1 -0
- package/dist/src/business/messaging/targets.test.js +36 -0
- package/dist/src/business/outbound/create-sender.d.ts +2 -0
- package/dist/src/business/outbound/create-sender.js +66 -0
- package/dist/src/{module/reply-heartbeat.d.ts → business/outbound/heartbeat.d.ts} +3 -3
- package/dist/src/{module/reply-heartbeat.js → business/outbound/heartbeat.js} +20 -15
- package/dist/src/business/outbound/index.d.ts +4 -0
- package/dist/src/business/outbound/index.js +2 -0
- package/dist/src/business/outbound/queue.d.ts +21 -0
- package/dist/src/business/outbound/queue.js +278 -0
- package/dist/src/business/outbound/types.d.ts +45 -0
- package/dist/src/business/outbound/types.js +1 -0
- package/dist/src/business/pipeline/create.d.ts +2 -0
- package/dist/src/business/pipeline/create.js +22 -0
- package/dist/src/business/pipeline/engine.d.ts +9 -0
- package/dist/src/business/pipeline/engine.js +55 -0
- package/dist/src/business/pipeline/engine.test.d.ts +1 -0
- package/dist/src/business/pipeline/engine.test.js +187 -0
- package/dist/src/business/pipeline/index.d.ts +3 -0
- package/dist/src/business/pipeline/index.js +2 -0
- package/dist/src/business/pipeline/middlewares/build-context.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/build-context.js +84 -0
- package/dist/src/business/pipeline/middlewares/build-context.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/build-context.test.js +128 -0
- package/dist/src/business/pipeline/middlewares/dispatch-reply.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/dispatch-reply.js +190 -0
- package/dist/src/business/pipeline/middlewares/dispatch-reply.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/dispatch-reply.test.js +200 -0
- package/dist/src/business/pipeline/middlewares/download-media.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/download-media.js +59 -0
- package/dist/src/business/pipeline/middlewares/download-media.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/download-media.test.js +112 -0
- package/dist/src/business/pipeline/middlewares/extract-content.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/extract-content.js +39 -0
- package/dist/src/business/pipeline/middlewares/extract-content.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/extract-content.test.js +87 -0
- package/dist/src/business/pipeline/middlewares/guard-command.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/guard-command.js +30 -0
- package/dist/src/business/pipeline/middlewares/guard-command.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/guard-command.test.js +125 -0
- package/dist/src/business/pipeline/middlewares/guard-group-command.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/guard-group-command.js +33 -0
- package/dist/src/business/pipeline/middlewares/guard-group-command.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/guard-group-command.test.js +118 -0
- package/dist/src/business/pipeline/middlewares/guard-send-access.d.ts +3 -0
- package/dist/src/business/pipeline/middlewares/guard-send-access.js +78 -0
- package/dist/src/business/pipeline/middlewares/guard-send-access.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/guard-send-access.test.js +72 -0
- package/dist/src/business/pipeline/middlewares/guard-special-command.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/guard-special-command.js +44 -0
- package/dist/src/business/pipeline/middlewares/guard-special-command.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/guard-special-command.test.js +121 -0
- package/dist/src/business/pipeline/middlewares/index.d.ts +17 -0
- package/dist/src/business/pipeline/middlewares/index.js +17 -0
- package/dist/src/business/pipeline/middlewares/prepare-sender.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/prepare-sender.js +36 -0
- package/dist/src/business/pipeline/middlewares/prepare-sender.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/prepare-sender.test.js +128 -0
- package/dist/src/business/pipeline/middlewares/record-member.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/record-member.js +9 -0
- package/dist/src/business/pipeline/middlewares/record-member.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/record-member.test.js +61 -0
- package/dist/src/business/pipeline/middlewares/resolve-mention.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/resolve-mention.js +58 -0
- package/dist/src/business/pipeline/middlewares/resolve-mention.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/resolve-mention.test.js +121 -0
- package/dist/src/business/pipeline/middlewares/resolve-quote.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/resolve-quote.js +13 -0
- package/dist/src/business/pipeline/middlewares/resolve-quote.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/resolve-quote.test.js +48 -0
- package/dist/src/business/pipeline/middlewares/resolve-route.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/resolve-route.js +24 -0
- package/dist/src/business/pipeline/middlewares/resolve-route.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/resolve-route.test.js +84 -0
- package/dist/src/business/pipeline/middlewares/resolve-trace.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/resolve-trace.js +15 -0
- package/dist/src/business/pipeline/middlewares/rewrite-body.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/rewrite-body.js +41 -0
- package/dist/src/business/pipeline/middlewares/rewrite-body.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/rewrite-body.test.js +103 -0
- package/dist/src/business/pipeline/middlewares/skip-placeholder.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/skip-placeholder.js +39 -0
- package/dist/src/business/pipeline/middlewares/skip-placeholder.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/skip-placeholder.test.js +94 -0
- package/dist/src/business/pipeline/middlewares/skip-self.d.ts +2 -0
- package/dist/src/business/pipeline/middlewares/skip-self.js +10 -0
- package/dist/src/business/pipeline/middlewares/skip-self.test.d.ts +1 -0
- package/dist/src/business/pipeline/middlewares/skip-self.test.js +31 -0
- package/dist/src/business/pipeline/test-helpers/mock-ctx.d.ts +15 -0
- package/dist/src/business/pipeline/test-helpers/mock-ctx.js +104 -0
- package/dist/src/business/pipeline/types.d.ts +78 -0
- package/dist/src/business/pipeline/types.js +1 -0
- package/dist/src/{tools → business/tools}/group.d.ts +1 -1
- package/dist/src/{tools → business/tools}/group.js +17 -11
- package/dist/src/{tools → business/tools}/index.d.ts +1 -1
- package/dist/src/business/tools/index.js +8 -0
- package/dist/src/{tools → business/tools}/member.d.ts +1 -1
- package/dist/src/{tools → business/tools}/member.js +46 -37
- package/dist/src/{tools → business/tools}/remind.d.ts +1 -1
- package/dist/src/{tools → business/tools}/remind.js +109 -99
- package/dist/src/{trace → business/trace}/context.js +21 -13
- package/dist/src/business/utils/markdown.d.ts +40 -0
- package/dist/src/business/utils/markdown.js +382 -0
- package/dist/src/{media.d.ts → business/utils/media.d.ts} +7 -5
- package/dist/src/{media.js → business/utils/media.js} +133 -238
- package/dist/src/{tools → business/utils}/utils.d.ts +10 -3
- package/dist/src/business/utils/utils.js +41 -0
- package/dist/src/business/utils/utils.test.d.ts +1 -0
- package/dist/src/business/utils/utils.test.js +37 -0
- package/dist/src/channel-shared.d.ts +60 -0
- package/dist/src/channel-shared.js +77 -0
- package/dist/src/channel.d.ts +2 -2
- package/dist/src/channel.js +146 -342
- package/dist/src/channel.setup.d.ts +3 -0
- package/dist/src/channel.setup.js +11 -0
- package/dist/src/config-schema.d.ts +113 -9
- package/dist/src/config-schema.js +60 -73
- package/dist/src/dispatcher/debouncer/index.d.ts +6 -0
- package/dist/src/dispatcher/debouncer/index.js +221 -0
- package/dist/src/dispatcher/queue/session-abort-manager.d.ts +6 -0
- package/dist/src/dispatcher/queue/session-abort-manager.js +24 -0
- package/dist/src/dispatcher/queue/session-queue.d.ts +9 -0
- package/dist/src/dispatcher/queue/session-queue.js +38 -0
- package/dist/src/{module → infra/cache}/member.d.ts +7 -8
- package/dist/src/{module → infra/cache}/member.js +63 -98
- package/dist/src/{utils → infra/cache}/ttl-db.js +7 -4
- package/dist/src/infra/cache/ttl-db.test.d.ts +1 -0
- package/dist/src/infra/cache/ttl-db.test.js +50 -0
- package/dist/src/{utils/get-env.d.ts → infra/env.d.ts} +1 -1
- package/dist/src/{utils/get-env.js → infra/env.js} +9 -9
- package/dist/src/infra/transport.d.ts +23 -0
- package/dist/src/infra/transport.js +100 -0
- package/dist/src/logger.d.ts +8 -6
- package/dist/src/logger.js +91 -57
- package/dist/src/runtime.d.ts +3 -3
- package/dist/src/runtime.js +3 -10
- package/dist/src/setup-core.d.ts +2 -0
- package/dist/src/{setup.js → setup-core.js} +7 -5
- package/dist/src/setup-surface.d.ts +2 -0
- package/dist/src/setup-surface.js +128 -0
- package/dist/src/types.d.ts +6 -21
- package/dist/src/types.js +0 -5
- package/index.ts +73 -0
- package/openclaw.plugin.json +38 -8
- package/package.json +30 -23
- package/runtime-api.ts +9 -0
- package/setup-entry.ts +9 -0
- package/src/access/api.ts +22 -0
- package/src/access/http/bot-id-cache.ts +30 -0
- package/src/access/http/main.ts +59 -0
- package/src/access/http/request.ts +415 -0
- package/src/access/ws/biz-codec.ts +506 -0
- package/src/access/ws/client.ts +978 -0
- package/src/access/ws/conn-codec.ts +226 -0
- package/src/access/ws/gateway.ts +444 -0
- package/src/access/ws/index.ts +77 -0
- package/src/access/ws/proto/biz/get_group_member_list.proto +29 -0
- package/src/access/ws/proto/biz/inbound_message.proto +44 -0
- package/src/access/ws/proto/biz/msg_body.proto +54 -0
- package/src/access/ws/proto/biz/openclaw_proxy_svr.proto +29 -0
- package/src/access/ws/proto/biz/query_group_info.proto +30 -0
- package/src/access/ws/proto/biz/send_c2c_message.proto +33 -0
- package/src/access/ws/proto/biz/send_group_heartbeat.proto +27 -0
- package/src/access/ws/proto/biz/send_group_message.proto +33 -0
- package/src/access/ws/proto/biz/send_private_heartbeat.proto +30 -0
- package/src/access/ws/proto/biz.json +552 -0
- package/src/access/ws/proto/conn.json +391 -0
- package/src/access/ws/proto/conn.proto +176 -0
- package/src/access/ws/runtime.ts +35 -0
- package/src/access/ws/types.ts +202 -0
- package/src/accounts.ts +183 -0
- package/src/business/actions/deliver.ts +58 -0
- package/src/business/actions/handler.ts +181 -0
- package/src/business/actions/index.ts +46 -0
- package/src/business/actions/media/send.ts +64 -0
- package/src/business/actions/resolve-target.ts +115 -0
- package/src/business/actions/sticker/builtin-stickers.json +542 -0
- package/src/business/actions/sticker/init-builtin-stickers.ts +31 -0
- package/src/business/actions/sticker/send.ts +93 -0
- package/src/business/actions/sticker/sticker-cache.ts +344 -0
- package/src/business/actions/sticker/sticker-types.ts +35 -0
- package/src/business/actions/text/send.ts +38 -0
- package/src/business/commands/command-sync/index.ts +118 -0
- package/src/business/commands/log-upload/cos-upload.ts +181 -0
- package/src/business/commands/log-upload/extractor.ts +307 -0
- package/src/business/commands/log-upload/index.ts +33 -0
- package/src/business/commands/log-upload/perform.ts +212 -0
- package/src/business/commands/log-upload/types.ts +49 -0
- package/src/business/inbound/index.ts +67 -0
- package/src/business/messaging/callbacks/recall.ts +127 -0
- package/src/business/messaging/chat-history.test.ts +61 -0
- package/src/business/messaging/chat-history.ts +50 -0
- package/src/business/messaging/context.ts +27 -0
- package/src/business/messaging/directory.ts +152 -0
- package/src/business/messaging/extract.test.ts +82 -0
- package/src/business/messaging/extract.ts +51 -0
- package/src/business/messaging/handlers/custom/index.ts +120 -0
- package/src/business/messaging/handlers/custom/link-card.ts +109 -0
- package/src/business/messaging/handlers/custom.test.ts +99 -0
- package/src/business/messaging/handlers/custom.ts +6 -0
- package/src/business/messaging/handlers/face.test.ts +72 -0
- package/src/business/messaging/handlers/face.ts +56 -0
- package/src/business/messaging/handlers/file.ts +50 -0
- package/src/business/messaging/handlers/image.test.ts +67 -0
- package/src/business/messaging/handlers/image.ts +58 -0
- package/src/business/messaging/handlers/index.test.ts +89 -0
- package/src/business/messaging/handlers/index.ts +176 -0
- package/src/business/messaging/handlers/sound.ts +25 -0
- package/src/business/messaging/handlers/text.test.ts +59 -0
- package/src/business/messaging/handlers/text.ts +36 -0
- package/src/business/messaging/handlers/types.ts +113 -0
- package/src/business/messaging/handlers/video.ts +48 -0
- package/src/business/messaging/index.ts +30 -0
- package/src/business/messaging/mention.ts +134 -0
- package/src/business/messaging/quote.test.ts +85 -0
- package/src/business/messaging/quote.ts +81 -0
- package/src/business/messaging/system-callbacks.ts +58 -0
- package/src/business/messaging/targets.test.ts +56 -0
- package/src/business/messaging/targets.ts +93 -0
- package/src/business/outbound/create-sender.ts +93 -0
- package/src/business/outbound/heartbeat.ts +184 -0
- package/src/business/outbound/index.ts +8 -0
- package/src/business/outbound/queue.ts +341 -0
- package/src/business/outbound/types.ts +52 -0
- package/src/business/pipeline/create.ts +54 -0
- package/src/business/pipeline/engine.test.ts +217 -0
- package/src/business/pipeline/engine.ts +75 -0
- package/src/business/pipeline/index.ts +9 -0
- package/src/business/pipeline/middlewares/build-context.test.ts +156 -0
- package/src/business/pipeline/middlewares/build-context.ts +125 -0
- package/src/business/pipeline/middlewares/dispatch-reply.test.ts +245 -0
- package/src/business/pipeline/middlewares/dispatch-reply.ts +258 -0
- package/src/business/pipeline/middlewares/download-media.test.ts +139 -0
- package/src/business/pipeline/middlewares/download-media.ts +94 -0
- package/src/business/pipeline/middlewares/extract-content.test.ts +125 -0
- package/src/business/pipeline/middlewares/extract-content.ts +57 -0
- package/src/business/pipeline/middlewares/guard-command.test.ts +156 -0
- package/src/business/pipeline/middlewares/guard-command.ts +44 -0
- package/src/business/pipeline/middlewares/guard-group-command.test.ts +144 -0
- package/src/business/pipeline/middlewares/guard-group-command.ts +54 -0
- package/src/business/pipeline/middlewares/guard-send-access.test.ts +97 -0
- package/src/business/pipeline/middlewares/guard-send-access.ts +137 -0
- package/src/business/pipeline/middlewares/guard-special-command.test.ts +159 -0
- package/src/business/pipeline/middlewares/guard-special-command.ts +73 -0
- package/src/business/pipeline/middlewares/index.ts +21 -0
- package/src/business/pipeline/middlewares/prepare-sender.test.ts +151 -0
- package/src/business/pipeline/middlewares/prepare-sender.ts +50 -0
- package/src/business/pipeline/middlewares/record-member.test.ts +80 -0
- package/src/business/pipeline/middlewares/record-member.ts +20 -0
- package/src/business/pipeline/middlewares/resolve-mention.test.ts +149 -0
- package/src/business/pipeline/middlewares/resolve-mention.ts +80 -0
- package/src/business/pipeline/middlewares/resolve-quote.test.ts +67 -0
- package/src/business/pipeline/middlewares/resolve-quote.ts +21 -0
- package/src/business/pipeline/middlewares/resolve-route.test.ts +107 -0
- package/src/business/pipeline/middlewares/resolve-route.ts +37 -0
- package/src/business/pipeline/middlewares/resolve-trace.ts +25 -0
- package/src/business/pipeline/middlewares/rewrite-body.test.ts +142 -0
- package/src/business/pipeline/middlewares/rewrite-body.ts +68 -0
- package/src/business/pipeline/middlewares/skip-placeholder.test.ts +134 -0
- package/src/business/pipeline/middlewares/skip-placeholder.ts +58 -0
- package/src/business/pipeline/middlewares/skip-self.test.ts +44 -0
- package/src/business/pipeline/middlewares/skip-self.ts +16 -0
- package/src/business/pipeline/test-helpers/mock-ctx.ts +125 -0
- package/src/business/pipeline/types.ts +108 -0
- package/src/business/tools/group.ts +89 -0
- package/src/business/tools/index.ts +32 -0
- package/src/business/tools/member.ts +199 -0
- package/src/business/tools/remind.ts +396 -0
- package/src/business/trace/context.ts +116 -0
- package/src/business/utils/markdown.ts +491 -0
- package/src/business/utils/media.ts +598 -0
- package/src/business/utils/utils.test.ts +51 -0
- package/src/business/utils/utils.ts +96 -0
- package/src/channel-shared.ts +126 -0
- package/src/channel.setup.ts +31 -0
- package/src/channel.ts +212 -0
- package/src/config-schema.ts +125 -0
- package/src/dispatcher/debouncer/index.ts +283 -0
- package/src/dispatcher/queue/session-abort-manager.ts +49 -0
- package/src/dispatcher/queue/session-queue.ts +69 -0
- package/src/infra/cache/member.ts +478 -0
- package/src/infra/cache/ttl-db.test.ts +71 -0
- package/src/infra/cache/ttl-db.ts +93 -0
- package/src/infra/env.ts +58 -0
- package/src/infra/transport.ts +160 -0
- package/src/logger.ts +238 -0
- package/src/runtime.ts +11 -0
- package/src/setup-core.ts +82 -0
- package/src/setup-surface.ts +150 -0
- package/src/types.ts +219 -0
- package/dist/openclaw.plugin.json +0 -19
- package/dist/src/agent-isolation.d.ts +0 -10
- package/dist/src/agent-isolation.js +0 -133
- package/dist/src/commands/log-upload.d.ts +0 -2
- package/dist/src/commands/log-upload.js +0 -22
- package/dist/src/commands/slash-commands/index.js +0 -116
- package/dist/src/commands/upgrade/index.d.ts +0 -8
- package/dist/src/commands/upgrade/index.js +0 -28
- package/dist/src/commands/upgrade/upgrade.d.ts +0 -2
- package/dist/src/commands/upgrade/upgrade.js +0 -254
- package/dist/src/commands/upgrade/utils.d.ts +0 -24
- package/dist/src/commands/upgrade/utils.js +0 -220
- package/dist/src/directory-adapter.d.ts +0 -2
- package/dist/src/directory-adapter.js +0 -58
- package/dist/src/dm/agent-prompt.d.ts +0 -1
- package/dist/src/dm/agent-prompt.js +0 -9
- package/dist/src/dm/directory-cache.d.ts +0 -7
- package/dist/src/dm/directory-cache.js +0 -52
- package/dist/src/dm/directory.js +0 -53
- package/dist/src/dm/dm-access.d.ts +0 -13
- package/dist/src/dm/dm-access.js +0 -45
- package/dist/src/dm/error-handler.d.ts +0 -28
- package/dist/src/dm/error-handler.js +0 -74
- package/dist/src/dm/handle-action.d.ts +0 -20
- package/dist/src/dm/handle-action.js +0 -100
- package/dist/src/dm/index.d.ts +0 -16
- package/dist/src/dm/index.js +0 -9
- package/dist/src/dm/send-dm.d.ts +0 -14
- package/dist/src/dm/send-dm.js +0 -95
- package/dist/src/dm/targets.d.ts +0 -12
- package/dist/src/dm/targets.js +0 -44
- package/dist/src/message-handler/context.d.ts +0 -24
- package/dist/src/message-handler/context.js +0 -34
- package/dist/src/message-handler/inbound.d.ts +0 -8
- package/dist/src/message-handler/inbound.js +0 -713
- package/dist/src/message-handler/index.d.ts +0 -9
- package/dist/src/message-handler/index.js +0 -5
- package/dist/src/message-handler/outbound.d.ts +0 -106
- package/dist/src/message-handler/outbound.js +0 -344
- package/dist/src/message-tool/action-runtime.d.ts +0 -17
- package/dist/src/message-tool/action-runtime.js +0 -79
- package/dist/src/message-tool/hints.d.ts +0 -1
- package/dist/src/message-tool/hints.js +0 -10
- package/dist/src/message-tool/index.d.ts +0 -2
- package/dist/src/message-tool/index.js +0 -45
- package/dist/src/messaging-adapter.d.ts +0 -4
- package/dist/src/messaging-adapter.js +0 -31
- package/dist/src/onboarding.d.ts +0 -2
- package/dist/src/onboarding.js +0 -99
- package/dist/src/outbound-queue.d.ts +0 -91
- package/dist/src/outbound-queue.js +0 -538
- package/dist/src/setup.d.ts +0 -2
- package/dist/src/sticker/builtin-stickers.json +0 -62
- package/dist/src/sticker/sticker-sender.d.ts +0 -18
- package/dist/src/sticker/sticker-sender.js +0 -36
- package/dist/src/targets.d.ts +0 -13
- package/dist/src/targets.js +0 -40
- package/dist/src/tools/index.js +0 -8
- package/dist/src/tools/utils.js +0 -22
- package/dist/src/utils/markdown-stream.d.ts +0 -14
- package/dist/src/utils/markdown-stream.js +0 -242
- package/dist/src/utils/markdown-table-sanitize.d.ts +0 -1
- package/dist/src/utils/markdown-table-sanitize.js +0 -89
- package/dist/src/utils.d.ts +0 -2
- package/dist/src/utils.js +0 -18
- package/dist/src/yuanbao-server/api.js +0 -2
- package/dist/src/yuanbao-server/http/main.d.ts +0 -4
- package/dist/src/yuanbao-server/http/main.js +0 -18
- package/dist/src/yuanbao-server/ws/gateway.js +0 -292
- /package/dist/src/{yuanbao-server → access}/ws/proto/biz.json +0 -0
- /package/dist/src/{yuanbao-server → access}/ws/proto/conn.json +0 -0
- /package/dist/src/{yuanbao-server → access}/ws/runtime.js +0 -0
- /package/dist/src/{yuanbao-server → access}/ws/types.js +0 -0
- /package/dist/src/{sticker → business/actions/sticker}/init-builtin-stickers.d.ts +0 -0
- /package/dist/src/{sticker → business/actions/sticker}/sticker-types.js +0 -0
- /package/dist/src/{message-handler/handlers → business/commands/log-upload}/types.js +0 -0
- /package/dist/src/{module/log-upload/types.js → business/messaging/chat-history.test.d.ts} +0 -0
- /package/dist/src/{message-handler → business/messaging}/handlers/custom/link-card.d.ts +0 -0
- /package/dist/src/{trace → business/trace}/context.d.ts +0 -0
- /package/dist/src/{utils → infra/cache}/ttl-db.d.ts +0 -0
package/README.md
CHANGED
package/api.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregated export file
|
|
3
|
+
* 供 index.ts 通过 loadBundledEntryExportSync 懒加载引用
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { yuanbaoPlugin } from "./src/channel.js";
|
|
7
|
+
export { yuanbaoSetupPlugin } from "./src/channel.setup.js";
|
|
8
|
+
export { initLogger } from "./src/logger.js";
|
|
9
|
+
export { initEnv } from "./src/infra/env.js";
|
|
10
|
+
export { registerTools } from "./src/business/tools/index.js";
|
|
11
|
+
export { logUploadCommandDefinition } from "./src/business/commands/log-upload/index.js";
|
|
12
|
+
export { initBuiltinStickers } from "./src/business/actions/sticker/init-builtin-stickers.js";
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { yuanbaoPlugin } from "./src/channel.js";
|
|
2
|
+
export { yuanbaoSetupPlugin } from "./src/channel.setup.js";
|
|
3
|
+
export { initLogger } from "./src/logger.js";
|
|
4
|
+
export { initEnv } from "./src/infra/env.js";
|
|
5
|
+
export { registerTools } from "./src/business/tools/index.js";
|
|
6
|
+
export { logUploadCommandDefinition } from "./src/business/commands/log-upload/index.js";
|
|
7
|
+
export { initBuiltinStickers } from "./src/business/actions/sticker/init-builtin-stickers.js";
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { yuanbaoPlugin } from "./src/channel.js";
|
|
2
|
+
export { yuanbaoSetupPlugin } from "./src/channel.setup.js";
|
|
3
|
+
export { initLogger } from "./src/logger.js";
|
|
4
|
+
export { initEnv } from "./src/infra/env.js";
|
|
5
|
+
export { registerTools } from "./src/business/tools/index.js";
|
|
6
|
+
export { logUploadCommandDefinition } from "./src/business/commands/log-upload/index.js";
|
|
7
|
+
export { initBuiltinStickers } from "./src/business/actions/sticker/init-builtin-stickers.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
configSchema: any;
|
|
7
|
-
register(api: OpenClawPluginApi): void;
|
|
8
|
-
};
|
|
9
|
-
export default plugin;
|
|
1
|
+
declare const _default: import("openclaw/plugin-sdk/channel-entry-contract").BundledChannelEntryContract<import("openclaw/plugin-sdk").ChannelPlugin>;
|
|
2
|
+
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { registerPluginCommand } from './src/commands/slash-commands/index.js';
|
|
9
|
-
import { initEnv } from './src/utils/get-env.js';
|
|
10
|
-
import { initBuiltinStickers } from './src/sticker/init-builtin-stickers.js';
|
|
11
|
-
import pluginManifest from './openclaw.plugin.json' with { type: 'json' };
|
|
12
|
-
function patchCommandQueueState() {
|
|
13
|
-
const key = Symbol.for('openclaw.commandQueueState');
|
|
14
|
-
const state = globalThis[key];
|
|
15
|
-
if (state && !state.activeTaskWaiters) {
|
|
16
|
-
state.activeTaskWaiters = new Set();
|
|
17
|
-
}
|
|
1
|
+
import { defineBundledChannelEntry, loadBundledEntryExportSync, } from "openclaw/plugin-sdk/channel-entry-contract";
|
|
2
|
+
function registerTools(api) {
|
|
3
|
+
const register = loadBundledEntryExportSync(import.meta.url, {
|
|
4
|
+
specifier: "./api.js",
|
|
5
|
+
exportName: "registerTools",
|
|
6
|
+
});
|
|
7
|
+
register(api);
|
|
18
8
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
function registerCommands(api) {
|
|
10
|
+
const logUploadCommandDefinition = loadBundledEntryExportSync(import.meta.url, { specifier: "./api.js", exportName: "logUploadCommandDefinition" });
|
|
11
|
+
api.registerCommand(logUploadCommandDefinition);
|
|
12
|
+
}
|
|
13
|
+
function initBuiltinStickers() {
|
|
14
|
+
const init = loadBundledEntryExportSync(import.meta.url, {
|
|
15
|
+
specifier: "./api.js",
|
|
16
|
+
exportName: "initBuiltinStickers",
|
|
17
|
+
});
|
|
18
|
+
init();
|
|
19
|
+
}
|
|
20
|
+
function initEnv(api) {
|
|
21
|
+
const init = loadBundledEntryExportSync(import.meta.url, {
|
|
22
|
+
specifier: "./api.js",
|
|
23
|
+
exportName: "initEnv",
|
|
24
|
+
});
|
|
25
|
+
init(api);
|
|
26
|
+
}
|
|
27
|
+
function initLogger(api) {
|
|
28
|
+
const init = loadBundledEntryExportSync(import.meta.url, {
|
|
29
|
+
specifier: "./api.js",
|
|
30
|
+
exportName: "initLogger",
|
|
31
|
+
});
|
|
32
|
+
init(api);
|
|
33
|
+
}
|
|
34
|
+
export default defineBundledChannelEntry({
|
|
35
|
+
id: "yuanbao",
|
|
36
|
+
name: "YuanBao",
|
|
37
|
+
description: "YuanBao channel plugin",
|
|
38
|
+
importMetaUrl: import.meta.url,
|
|
39
|
+
plugin: {
|
|
40
|
+
specifier: "./api.js",
|
|
41
|
+
exportName: "yuanbaoPlugin",
|
|
42
|
+
},
|
|
43
|
+
runtime: {
|
|
44
|
+
specifier: "./runtime-api.js",
|
|
45
|
+
exportName: "setYuanbaoRuntime",
|
|
46
|
+
},
|
|
47
|
+
registerFull(api) {
|
|
26
48
|
initEnv(api);
|
|
27
49
|
initLogger(api);
|
|
28
|
-
setYuanbaoRuntime(api.runtime);
|
|
29
|
-
api.registerChannel({ plugin: yuanbaoPlugin });
|
|
30
50
|
registerTools(api);
|
|
31
|
-
api
|
|
32
|
-
api.registerCommand(yuanbaobotUpgradeCommand);
|
|
33
|
-
registerPluginCommand(yuanbaobotUpgradeCommand.name, yuanbaobotUpgradeCommand.description);
|
|
34
|
-
api.registerCommand(logUploadCommandDefinition);
|
|
35
|
-
registerPluginCommand(logUploadCommandDefinition.name, logUploadCommandDefinition.description);
|
|
51
|
+
registerCommands(api);
|
|
36
52
|
initBuiltinStickers();
|
|
37
53
|
},
|
|
38
|
-
};
|
|
39
|
-
export default plugin;
|
|
54
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ChannelPlugin, OpenClawPluginApi, PluginRuntime } from "openclaw/plugin-sdk/core";
|
|
2
|
+
export type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
|
3
|
+
export type { OpenClawPluginService, OpenClawPluginServiceContext, PluginLogger, } from "openclaw/plugin-sdk/core";
|
|
4
|
+
export type { ResolvedYuanbaoAccount } from "./src/types.js";
|
|
5
|
+
export { getYuanbaoRuntime, setYuanbaoRuntime } from "./src/runtime.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getYuanbaoRuntime, setYuanbaoRuntime } from "./src/runtime.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { SignTokenData, AuthHeaders, CosUploadConfig, Log } from
|
|
2
|
-
export { clearSignTokenCache, clearAllSignTokenCache, getTokenStatus, verifySignature, getSignToken, forceRefreshSignToken, getAuthHeaders, yuanbaoPost, yuanbaoGet, } from
|
|
3
|
-
export { apiGetUploadInfo, apiGetDownloadUrl } from
|
|
1
|
+
export type { SignTokenData, AuthHeaders, CosUploadConfig, Log } from "./http/request.js";
|
|
2
|
+
export { clearSignTokenCache, clearAllSignTokenCache, getTokenStatus, verifySignature, getSignToken, forceRefreshSignToken, getAuthHeaders, yuanbaoPost, yuanbaoGet, } from "./http/request.js";
|
|
3
|
+
export { apiGetUploadInfo, apiGetDownloadUrl } from "./http/main.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const botIdCache = new Map();
|
|
2
|
+
export function getCachedBotId(accountId) {
|
|
3
|
+
const value = botIdCache.get(accountId);
|
|
4
|
+
return value && value.length > 0 ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
export function setCachedBotId(accountId, botId) {
|
|
7
|
+
if (!accountId || !botId) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
botIdCache.set(accountId, botId);
|
|
11
|
+
}
|
|
12
|
+
export function clearCachedBotId(accountId) {
|
|
13
|
+
botIdCache.delete(accountId);
|
|
14
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResolvedYuanbaoAccount } from "../../types.js";
|
|
2
|
+
import type { Log, CosUploadConfig } from "./request.js";
|
|
3
|
+
export declare function apiGetUploadInfo(account: ResolvedYuanbaoAccount, fileName: string, fileId: string, log?: Log): Promise<CosUploadConfig>;
|
|
4
|
+
export declare function apiGetDownloadUrl(account: ResolvedYuanbaoAccount, resourceId: string, log?: Log): Promise<string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { yuanbaoPost, yuanbaoGet } from "./request.js";
|
|
2
|
+
const UPLOAD_INFO_PATH = "/api/resource/genUploadInfo";
|
|
3
|
+
const DOWNLOAD_INFO_PATH = "/api/resource/v1/download";
|
|
4
|
+
export async function apiGetUploadInfo(account, fileName, fileId, log) {
|
|
5
|
+
const data = await yuanbaoPost(account, UPLOAD_INFO_PATH, { fileName, fileId, docFrom: "localDoc", docOpenId: "" }, log);
|
|
6
|
+
if (!data.bucketName || !data.location) {
|
|
7
|
+
throw new Error(`[yuanbao-api] genUploadInfo incomplete config: ${JSON.stringify(data)}`);
|
|
8
|
+
}
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
export async function apiGetDownloadUrl(account, resourceId, log) {
|
|
12
|
+
const data = await yuanbaoGet(account, DOWNLOAD_INFO_PATH, { resourceId }, log);
|
|
13
|
+
const downloadUrl = data.url ?? data.realUrl;
|
|
14
|
+
if (!downloadUrl) {
|
|
15
|
+
throw new Error(`[yuanbao-api] resource/v1/download returned no valid URL: ${JSON.stringify(data)}`);
|
|
16
|
+
}
|
|
17
|
+
return downloadUrl;
|
|
18
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ResolvedYuanbaoAccount } from "../../types.js";
|
|
2
|
+
export { getCachedBotId } from "./bot-id-cache.js";
|
|
2
3
|
export type SignTokenData = {
|
|
3
4
|
bot_id: string;
|
|
4
5
|
duration: number;
|
|
5
6
|
product: string;
|
|
6
7
|
source: string;
|
|
7
8
|
token: string;
|
|
8
|
-
create_type?: BotCreateType;
|
|
9
9
|
};
|
|
10
10
|
export type AuthHeaders = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
"X-ID": string;
|
|
12
|
+
"X-Token": string;
|
|
13
|
+
"X-Source": string;
|
|
14
|
+
"X-Route-Env"?: string;
|
|
15
|
+
"X-AppVersion": string;
|
|
16
|
+
"X-OperationSystem": string;
|
|
17
|
+
"X-Instance-Id": string;
|
|
18
|
+
"X-Bot-Version": string;
|
|
19
19
|
};
|
|
20
20
|
export type CosUploadConfig = {
|
|
21
21
|
bucketName: string;
|
|
@@ -40,13 +40,12 @@ export declare const DOWNLOAD_INFO_PATH = "/api/resource/v1/download";
|
|
|
40
40
|
export declare function clearSignTokenCache(accountId: string): void;
|
|
41
41
|
export declare function clearAllSignTokenCache(): void;
|
|
42
42
|
export declare function getTokenStatus(accountId: string): {
|
|
43
|
-
status:
|
|
43
|
+
status: "valid" | "expired" | "refreshing" | "none";
|
|
44
44
|
expiresAt: number | null;
|
|
45
45
|
};
|
|
46
|
-
export declare function getCachedBotId(accountId: string): string | undefined;
|
|
47
46
|
export declare function verifySignature(expected: string, actual: string): boolean;
|
|
48
|
-
export declare function getSignToken(account: ResolvedYuanbaoAccount): Promise<SignTokenData>;
|
|
49
|
-
export declare function forceRefreshSignToken(account: ResolvedYuanbaoAccount): Promise<SignTokenData>;
|
|
50
|
-
export declare function getAuthHeaders(account: ResolvedYuanbaoAccount): Promise<AuthHeaders>;
|
|
51
|
-
export declare function yuanbaoPost<T>(account: ResolvedYuanbaoAccount, path: string, body: unknown): Promise<T>;
|
|
52
|
-
export declare function yuanbaoGet<T>(account: ResolvedYuanbaoAccount, path: string, params?: Record<string, string
|
|
47
|
+
export declare function getSignToken(account: ResolvedYuanbaoAccount, log?: Log): Promise<SignTokenData>;
|
|
48
|
+
export declare function forceRefreshSignToken(account: ResolvedYuanbaoAccount, log?: Log): Promise<SignTokenData>;
|
|
49
|
+
export declare function getAuthHeaders(account: ResolvedYuanbaoAccount, log?: Log): Promise<AuthHeaders>;
|
|
50
|
+
export declare function yuanbaoPost<T>(account: ResolvedYuanbaoAccount, path: string, body: unknown, log?: Log): Promise<T>;
|
|
51
|
+
export declare function yuanbaoGet<T>(account: ResolvedYuanbaoAccount, path: string, params?: Record<string, string>, log?: Log): Promise<T>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { createHmac, randomBytes, timingSafeEqual } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export const
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { getOpenclawVersion, getOperationSystem, getPluginVersion } from "../../infra/env.js";
|
|
3
|
+
import { createLog } from "../../logger.js";
|
|
4
|
+
import { clearCachedBotId, setCachedBotId } from "./bot-id-cache.js";
|
|
5
|
+
export { getCachedBotId } from "./bot-id-cache.js";
|
|
6
|
+
export const SIGN_TOKEN_PATH = "/api/v5/robotLogic/sign-token";
|
|
7
|
+
export const UPLOAD_INFO_PATH = "/api/resource/genUploadInfo";
|
|
8
|
+
export const DOWNLOAD_INFO_PATH = "/api/resource/v1/download";
|
|
7
9
|
const RETRYABLE_SIGN_CODE = 10099;
|
|
8
10
|
const SIGN_MAX_RETRIES = 3;
|
|
9
11
|
const SIGN_RETRY_DELAY_MS = 1000;
|
|
@@ -15,6 +17,7 @@ const tokenFetchPromises = new Map();
|
|
|
15
17
|
const tokenRefreshTimers = new Map();
|
|
16
18
|
export function clearSignTokenCache(accountId) {
|
|
17
19
|
tokenCacheMap.delete(accountId);
|
|
20
|
+
clearCachedBotId(accountId);
|
|
18
21
|
const timer = tokenRefreshTimers.get(accountId);
|
|
19
22
|
if (timer) {
|
|
20
23
|
clearTimeout(timer);
|
|
@@ -30,111 +33,109 @@ export function clearAllSignTokenCache() {
|
|
|
30
33
|
}
|
|
31
34
|
export function getTokenStatus(accountId) {
|
|
32
35
|
if (tokenFetchPromises.has(accountId)) {
|
|
33
|
-
return { status:
|
|
36
|
+
return { status: "refreshing", expiresAt: tokenCacheMap.get(accountId)?.expiresAt ?? null };
|
|
34
37
|
}
|
|
35
38
|
const cached = tokenCacheMap.get(accountId);
|
|
36
|
-
if (!cached)
|
|
37
|
-
return { status:
|
|
39
|
+
if (!cached) {
|
|
40
|
+
return { status: "none", expiresAt: null };
|
|
41
|
+
}
|
|
38
42
|
return {
|
|
39
|
-
status: cached.expiresAt > Date.now() ?
|
|
43
|
+
status: cached.expiresAt > Date.now() ? "valid" : "expired",
|
|
40
44
|
expiresAt: cached.expiresAt,
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
|
-
export function getCachedBotId(accountId) {
|
|
44
|
-
const cached = tokenCacheMap.get(accountId);
|
|
45
|
-
if (!cached || cached.expiresAt <= Date.now())
|
|
46
|
-
return undefined;
|
|
47
|
-
return cached.data.bot_id || undefined;
|
|
48
|
-
}
|
|
49
47
|
function computeSignature(params) {
|
|
50
48
|
const plain = params.nonce + params.timestamp + params.appKey + params.appSecret;
|
|
51
|
-
return createHmac(
|
|
52
|
-
.digest(
|
|
49
|
+
return createHmac("sha256", params.appSecret).update(plain)
|
|
50
|
+
.digest("hex");
|
|
53
51
|
}
|
|
54
52
|
export function verifySignature(expected, actual) {
|
|
55
|
-
const expectedBuf = Buffer.from(expected,
|
|
56
|
-
const actualBuf = Buffer.from(actual,
|
|
53
|
+
const expectedBuf = Buffer.from(expected, "hex");
|
|
54
|
+
const actualBuf = Buffer.from(actual, "hex");
|
|
57
55
|
if (expectedBuf.length !== actualBuf.length) {
|
|
58
56
|
return false;
|
|
59
57
|
}
|
|
60
58
|
return timingSafeEqual(expectedBuf, actualBuf);
|
|
61
59
|
}
|
|
62
|
-
async function doFetchSignToken(account) {
|
|
63
|
-
const mlog = createLog(
|
|
60
|
+
async function doFetchSignToken(account, log) {
|
|
61
|
+
const mlog = createLog("http", log);
|
|
64
62
|
const { appKey, appSecret, apiDomain } = account;
|
|
65
|
-
if (!appKey || !appSecret)
|
|
66
|
-
throw new Error(
|
|
63
|
+
if (!appKey || !appSecret) {
|
|
64
|
+
throw new Error("sign-token failed: missing appKey or appSecret");
|
|
65
|
+
}
|
|
67
66
|
const url = `https://${apiDomain}${SIGN_TOKEN_PATH}`;
|
|
68
67
|
for (let attempt = 0; attempt <= SIGN_MAX_RETRIES; attempt++) {
|
|
69
|
-
const nonce = randomBytes(16).toString(
|
|
68
|
+
const nonce = randomBytes(16).toString("hex");
|
|
70
69
|
const bjTime = new Date(Date.now() + 8 * 3600000);
|
|
71
|
-
const timestamp = bjTime
|
|
72
|
-
.
|
|
70
|
+
const timestamp = bjTime
|
|
71
|
+
.toISOString()
|
|
72
|
+
.replace("Z", "+08:00")
|
|
73
|
+
.replace(/\.\d{3}/, "");
|
|
73
74
|
const signature = computeSignature({ nonce, timestamp, appKey, appSecret });
|
|
74
75
|
const body = { app_key: appKey, nonce, signature, timestamp };
|
|
75
|
-
mlog.info(
|
|
76
|
-
mlog.info(
|
|
76
|
+
mlog.info(`signing token: url=${url}${attempt > 0 ? ` (retry ${attempt}/${SIGN_MAX_RETRIES})` : ""}`);
|
|
77
|
+
mlog.info("sign-token params", body);
|
|
77
78
|
const headers = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
"X-AppVersion": getPluginVersion(),
|
|
81
|
+
"X-OperationSystem": getOperationSystem(),
|
|
82
|
+
"X-Instance-Id": "16",
|
|
83
|
+
"X-Bot-Version": getOpenclawVersion(),
|
|
83
84
|
};
|
|
84
85
|
if (account.config?.routeEnv) {
|
|
85
|
-
headers[
|
|
86
|
+
headers["x-route-env"] = account.config.routeEnv;
|
|
86
87
|
}
|
|
87
88
|
const response = await fetch(url, {
|
|
88
|
-
method:
|
|
89
|
+
method: "POST",
|
|
89
90
|
headers,
|
|
90
91
|
body: JSON.stringify(body),
|
|
91
92
|
});
|
|
92
93
|
if (!response.ok) {
|
|
93
|
-
throw new Error(
|
|
94
|
+
throw new Error(`sign-token HTTP error: ${response.status} ${response.statusText}`);
|
|
94
95
|
}
|
|
95
96
|
const result = (await response.json());
|
|
96
97
|
if (result.code === 0) {
|
|
97
|
-
mlog.info(
|
|
98
|
+
mlog.info(`sign-token success: bot_id=${result.data.bot_id}`);
|
|
98
99
|
return result.data;
|
|
99
100
|
}
|
|
100
101
|
if (result.code === RETRYABLE_SIGN_CODE && attempt < SIGN_MAX_RETRIES) {
|
|
101
|
-
mlog.warn(
|
|
102
|
+
mlog.warn(`sign-token retryable: code=${result.code}, retrying in ${SIGN_RETRY_DELAY_MS}ms`);
|
|
102
103
|
await new Promise(r => setTimeout(r, SIGN_RETRY_DELAY_MS));
|
|
103
104
|
continue;
|
|
104
105
|
}
|
|
105
|
-
throw new Error(
|
|
106
|
+
throw new Error(`sign-token error: code=${result.code}, msg=${result.msg}`);
|
|
106
107
|
}
|
|
107
|
-
throw new Error(
|
|
108
|
+
throw new Error("sign-token failed: max retries exceeded");
|
|
108
109
|
}
|
|
109
|
-
function scheduleTokenRefresh(account, durationSec) {
|
|
110
|
-
const mlog = createLog(
|
|
110
|
+
function scheduleTokenRefresh(account, durationSec, log) {
|
|
111
|
+
const mlog = createLog("http", log);
|
|
111
112
|
const existing = tokenRefreshTimers.get(account.accountId);
|
|
112
113
|
if (existing) {
|
|
113
114
|
clearTimeout(existing);
|
|
114
115
|
}
|
|
115
116
|
const rawMs = durationSec * 1000 - CACHE_REFRESH_MARGIN_MS;
|
|
116
117
|
const refreshAfterMs = Math.min(Math.max(rawMs, 60_000), MAX_SAFE_TIMEOUT_MS);
|
|
117
|
-
const clampedHint = rawMs > MAX_SAFE_TIMEOUT_MS ?
|
|
118
|
-
mlog.info(`[${account.accountId}][token-timer]
|
|
119
|
-
+ `${Math.round(refreshAfterMs / 1000)}s
|
|
118
|
+
const clampedHint = rawMs > MAX_SAFE_TIMEOUT_MS ? ", clamped to max safe timeout" : "";
|
|
119
|
+
mlog.info(`[${account.accountId}][token-timer] scheduled refresh: `
|
|
120
|
+
+ `${Math.round(refreshAfterMs / 1000)}s later (duration=${durationSec}s, `
|
|
120
121
|
+ `margin=${CACHE_REFRESH_MARGIN_MS / 1000}s${clampedHint})`);
|
|
121
122
|
const timer = setTimeout(async () => {
|
|
122
123
|
tokenRefreshTimers.delete(account.accountId);
|
|
123
124
|
try {
|
|
124
|
-
mlog.info(`[${account.accountId}][token-timer]
|
|
125
|
-
await forceRefreshSignToken(account);
|
|
126
|
-
mlog.info(`[${account.accountId}][token-timer]
|
|
125
|
+
mlog.info(`[${account.accountId}][token-timer] scheduled refresh triggered, re-signing token`);
|
|
126
|
+
await forceRefreshSignToken(account, log);
|
|
127
|
+
mlog.info(`[${account.accountId}][token-timer] scheduled refresh done`);
|
|
127
128
|
}
|
|
128
129
|
catch (err) {
|
|
129
|
-
mlog.error(`[${account.accountId}][token-timer]
|
|
130
|
+
mlog.error(`[${account.accountId}][token-timer] scheduled refresh failed: ${String(err)}, retrying in 30s`);
|
|
130
131
|
const retryTimer = setTimeout(async () => {
|
|
131
132
|
tokenRefreshTimers.delete(account.accountId);
|
|
132
133
|
try {
|
|
133
|
-
await forceRefreshSignToken(account);
|
|
134
|
-
mlog.info(`[${account.accountId}][token-timer]
|
|
134
|
+
await forceRefreshSignToken(account, log);
|
|
135
|
+
mlog.info(`[${account.accountId}][token-timer] scheduled refresh retry succeeded`);
|
|
135
136
|
}
|
|
136
137
|
catch (retryErr) {
|
|
137
|
-
mlog.error(`[${account.accountId}][token-timer]
|
|
138
|
+
mlog.error(`[${account.accountId}][token-timer] scheduled refresh retry also failed: ${String(retryErr)}, waiting for next request to trigger refresh`);
|
|
138
139
|
}
|
|
139
140
|
}, 30_000);
|
|
140
141
|
tokenRefreshTimers.set(account.accountId, retryTimer);
|
|
@@ -142,35 +143,36 @@ function scheduleTokenRefresh(account, durationSec) {
|
|
|
142
143
|
}, refreshAfterMs);
|
|
143
144
|
tokenRefreshTimers.set(account.accountId, timer);
|
|
144
145
|
}
|
|
145
|
-
export async function getSignToken(account) {
|
|
146
|
+
export async function getSignToken(account, log) {
|
|
146
147
|
if (account.token) {
|
|
147
148
|
return {
|
|
148
|
-
bot_id: account.botId ||
|
|
149
|
+
bot_id: account.botId || "",
|
|
149
150
|
duration: 0,
|
|
150
|
-
product:
|
|
151
|
-
source:
|
|
151
|
+
product: "yuanbao",
|
|
152
|
+
source: "bot",
|
|
152
153
|
token: account.token,
|
|
153
154
|
};
|
|
154
155
|
}
|
|
155
|
-
const tlog = createLog(
|
|
156
|
+
const tlog = createLog("http", log);
|
|
156
157
|
const cached = tokenCacheMap.get(account.accountId);
|
|
157
158
|
if (cached && cached.expiresAt > Date.now()) {
|
|
158
159
|
const remainSec = Math.round((cached.expiresAt - Date.now()) / 1000);
|
|
159
|
-
tlog.info(`[${account.accountId}]
|
|
160
|
+
tlog.info(`[${account.accountId}] using cached token (${remainSec}s remaining)`);
|
|
160
161
|
return cached.data;
|
|
161
162
|
}
|
|
162
163
|
let fetchPromise = tokenFetchPromises.get(account.accountId);
|
|
163
164
|
if (fetchPromise) {
|
|
164
|
-
tlog.info(`[${account.accountId}]
|
|
165
|
+
tlog.info(`[${account.accountId}] sign-token in progress, waiting for existing request`);
|
|
165
166
|
return fetchPromise;
|
|
166
167
|
}
|
|
167
168
|
fetchPromise = (async () => {
|
|
168
169
|
try {
|
|
169
|
-
const data = await doFetchSignToken(account);
|
|
170
|
+
const data = await doFetchSignToken(account, log);
|
|
170
171
|
const ttlMs = data.duration > 0 ? data.duration * 1000 : 0;
|
|
171
172
|
if (ttlMs > 0) {
|
|
172
173
|
tokenCacheMap.set(account.accountId, { data, expiresAt: Date.now() + ttlMs });
|
|
173
|
-
|
|
174
|
+
setCachedBotId(account.accountId, data.bot_id);
|
|
175
|
+
scheduleTokenRefresh(account, data.duration, log);
|
|
174
176
|
}
|
|
175
177
|
return data;
|
|
176
178
|
}
|
|
@@ -181,48 +183,48 @@ export async function getSignToken(account) {
|
|
|
181
183
|
tokenFetchPromises.set(account.accountId, fetchPromise);
|
|
182
184
|
return fetchPromise;
|
|
183
185
|
}
|
|
184
|
-
export async function forceRefreshSignToken(account) {
|
|
185
|
-
const flog = createLog(
|
|
186
|
-
flog.warn(`[${account.accountId}][force-refresh]
|
|
186
|
+
export async function forceRefreshSignToken(account, log) {
|
|
187
|
+
const flog = createLog("http", log);
|
|
188
|
+
flog.warn(`[${account.accountId}][force-refresh] clearing cache and re-signing token`);
|
|
187
189
|
clearSignTokenCache(account.accountId);
|
|
188
190
|
tokenFetchPromises.delete(account.accountId);
|
|
189
|
-
return getSignToken(account);
|
|
191
|
+
return getSignToken(account, log);
|
|
190
192
|
}
|
|
191
|
-
export async function getAuthHeaders(account) {
|
|
192
|
-
const data = await getSignToken(account);
|
|
193
|
+
export async function getAuthHeaders(account, log) {
|
|
194
|
+
const data = await getSignToken(account, log);
|
|
193
195
|
if (data.bot_id && !account.botId) {
|
|
194
196
|
account.botId = data.bot_id;
|
|
195
197
|
}
|
|
196
198
|
const authHeaders = {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
"X-ID": data.bot_id || account.botId || "",
|
|
200
|
+
"X-Token": data.token,
|
|
201
|
+
"X-Source": data.source || "web",
|
|
202
|
+
"X-AppVersion": getPluginVersion(),
|
|
203
|
+
"X-OperationSystem": getOperationSystem(),
|
|
204
|
+
"X-Instance-Id": "16",
|
|
205
|
+
"X-Bot-Version": getOpenclawVersion(),
|
|
204
206
|
};
|
|
205
207
|
if (account.config?.routeEnv) {
|
|
206
|
-
authHeaders[
|
|
208
|
+
authHeaders["X-Route-Env"] = account.config.routeEnv;
|
|
207
209
|
}
|
|
208
210
|
return authHeaders;
|
|
209
211
|
}
|
|
210
|
-
export async function yuanbaoPost(account, path, body) {
|
|
211
|
-
const plog = createLog(
|
|
212
|
+
export async function yuanbaoPost(account, path, body, log) {
|
|
213
|
+
const plog = createLog("http", log);
|
|
212
214
|
const url = `https://${account.apiDomain}${path}`;
|
|
213
215
|
for (let attempt = 0; attempt <= HTTP_AUTH_RETRY_MAX; attempt++) {
|
|
214
|
-
const authHeaders = await getAuthHeaders(account);
|
|
216
|
+
const authHeaders = await getAuthHeaders(account, log);
|
|
215
217
|
const response = await fetch(url, {
|
|
216
|
-
method:
|
|
218
|
+
method: "POST",
|
|
217
219
|
headers: {
|
|
218
|
-
|
|
220
|
+
"Content-Type": "application/json",
|
|
219
221
|
...authHeaders,
|
|
220
222
|
},
|
|
221
223
|
body: JSON.stringify(body),
|
|
222
224
|
});
|
|
223
225
|
if (response.status === 401 && attempt < HTTP_AUTH_RETRY_MAX) {
|
|
224
|
-
plog.warn(`[post][${account.accountId}] ${path}
|
|
225
|
-
await forceRefreshSignToken(account);
|
|
226
|
+
plog.warn(`[post][${account.accountId}] ${path} received 401, refreshing token and retrying (attempt=${attempt + 1})`);
|
|
227
|
+
await forceRefreshSignToken(account, log);
|
|
226
228
|
continue;
|
|
227
229
|
}
|
|
228
230
|
if (!response.ok) {
|
|
@@ -230,28 +232,28 @@ export async function yuanbaoPost(account, path, body) {
|
|
|
230
232
|
}
|
|
231
233
|
const json = (await response.json());
|
|
232
234
|
if (json.code !== 0 && json.code !== undefined) {
|
|
233
|
-
throw new Error(`[yuanbao-api][POST] ${path}
|
|
235
|
+
throw new Error(`[yuanbao-api][POST] ${path} business error: code=${json.code}, msg=${json.msg}`);
|
|
234
236
|
}
|
|
235
|
-
plog.info(`[post][${account.accountId}] ${path}
|
|
237
|
+
plog.info(`[post][${account.accountId}] ${path} request succeeded`);
|
|
236
238
|
return (json.data ?? json);
|
|
237
239
|
}
|
|
238
|
-
throw new Error(`[yuanbao-api][POST] ${path} 401
|
|
240
|
+
throw new Error(`[yuanbao-api][POST] ${path} 401 retries exhausted`);
|
|
239
241
|
}
|
|
240
|
-
export async function yuanbaoGet(account, path, params) {
|
|
241
|
-
const glog = createLog(
|
|
242
|
-
const url = `https://${account.apiDomain}${path}${params ? `?${new URLSearchParams(params).toString()}` :
|
|
242
|
+
export async function yuanbaoGet(account, path, params, log) {
|
|
243
|
+
const glog = createLog("http", log);
|
|
244
|
+
const url = `https://${account.apiDomain}${path}${params ? `?${new URLSearchParams(params).toString()}` : ""}`;
|
|
243
245
|
for (let attempt = 0; attempt <= HTTP_AUTH_RETRY_MAX; attempt++) {
|
|
244
|
-
const authHeaders = await getAuthHeaders(account);
|
|
246
|
+
const authHeaders = await getAuthHeaders(account, log);
|
|
245
247
|
const response = await fetch(url, {
|
|
246
|
-
method:
|
|
248
|
+
method: "GET",
|
|
247
249
|
headers: {
|
|
248
|
-
|
|
250
|
+
"Content-Type": "application/json",
|
|
249
251
|
...authHeaders,
|
|
250
252
|
},
|
|
251
253
|
});
|
|
252
254
|
if (response.status === 401 && attempt < HTTP_AUTH_RETRY_MAX) {
|
|
253
|
-
glog.warn(`[get][${account.accountId}] ${path}
|
|
254
|
-
await forceRefreshSignToken(account);
|
|
255
|
+
glog.warn(`[get][${account.accountId}] ${path} received 401, refreshing token and retrying (attempt=${attempt + 1})`);
|
|
256
|
+
await forceRefreshSignToken(account, log);
|
|
255
257
|
continue;
|
|
256
258
|
}
|
|
257
259
|
if (!response.ok) {
|
|
@@ -259,9 +261,9 @@ export async function yuanbaoGet(account, path, params) {
|
|
|
259
261
|
}
|
|
260
262
|
const json = (await response.json());
|
|
261
263
|
if (json.code !== 0 && json.code !== undefined) {
|
|
262
|
-
throw new Error(`[yuanbao-api][GET] ${path}
|
|
264
|
+
throw new Error(`[yuanbao-api][GET] ${path} business error: code=${json.code}, msg=${json.msg}`);
|
|
263
265
|
}
|
|
264
266
|
return (json.data ?? json);
|
|
265
267
|
}
|
|
266
|
-
throw new Error(`[yuanbao-api][GET] ${path} 401
|
|
268
|
+
throw new Error(`[yuanbao-api][GET] ${path} 401 retries exhausted`);
|
|
267
269
|
}
|