@xgjktech/xg_cwork_im 1.19.21 → 1.19.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -26
- package/dist/index.js.map +1 -1
- package/dist/src/connection/account-connection.d.ts +37 -0
- package/dist/src/connection/account-connection.d.ts.map +1 -0
- package/dist/src/connection/account-connection.js +548 -0
- package/dist/src/connection/account-connection.js.map +1 -0
- package/dist/src/connection/account-reconciler.d.ts +64 -0
- package/dist/src/connection/account-reconciler.d.ts.map +1 -0
- package/dist/src/connection/account-reconciler.js +314 -0
- package/dist/src/connection/account-reconciler.js.map +1 -0
- package/dist/src/connection/account-reconciler.test.d.ts +2 -0
- package/dist/src/connection/account-reconciler.test.d.ts.map +1 -0
- package/dist/src/connection/account-reconciler.test.js +166 -0
- package/dist/src/connection/account-reconciler.test.js.map +1 -0
- package/dist/src/connection/agent-stream-client-registry.d.ts +8 -0
- package/dist/src/connection/agent-stream-client-registry.d.ts.map +1 -0
- package/dist/src/connection/agent-stream-client-registry.js +19 -0
- package/dist/src/connection/agent-stream-client-registry.js.map +1 -0
- package/dist/src/connection/connection.d.ts +116 -0
- package/dist/src/connection/connection.d.ts.map +1 -0
- package/dist/src/connection/connection.js +469 -0
- package/dist/src/connection/connection.js.map +1 -0
- package/dist/src/connection/connection.test.d.ts +2 -0
- package/dist/src/connection/connection.test.d.ts.map +1 -0
- package/dist/src/connection/connection.test.js +126 -0
- package/dist/src/connection/connection.test.js.map +1 -0
- package/dist/src/connection/ws-inbound-schema.d.ts +14 -0
- package/dist/src/connection/ws-inbound-schema.d.ts.map +1 -0
- package/dist/src/connection/ws-inbound-schema.js +68 -0
- package/dist/src/connection/ws-inbound-schema.js.map +1 -0
- package/dist/src/connection/ws-inbound-schema.test.d.ts +2 -0
- package/dist/src/connection/ws-inbound-schema.test.d.ts.map +1 -0
- package/dist/src/connection/ws-inbound-schema.test.js +58 -0
- package/dist/src/connection/ws-inbound-schema.test.js.map +1 -0
- package/dist/src/delivery/assistant-item-delivery.d.ts +27 -0
- package/dist/src/delivery/assistant-item-delivery.d.ts.map +1 -0
- package/dist/src/delivery/assistant-item-delivery.js +134 -0
- package/dist/src/delivery/assistant-item-delivery.js.map +1 -0
- package/dist/src/delivery/assistant-item-delivery.test.d.ts +2 -0
- package/dist/src/delivery/assistant-item-delivery.test.d.ts.map +1 -0
- package/dist/src/delivery/assistant-item-delivery.test.js +116 -0
- package/dist/src/delivery/assistant-item-delivery.test.js.map +1 -0
- package/dist/src/delivery/assistant-item-sink.d.ts +17 -0
- package/dist/src/delivery/assistant-item-sink.d.ts.map +1 -0
- package/dist/src/delivery/assistant-item-sink.js +34 -0
- package/dist/src/delivery/assistant-item-sink.js.map +1 -0
- package/dist/src/delivery/block-streaming-config.test.d.ts +2 -0
- package/dist/src/delivery/block-streaming-config.test.d.ts.map +1 -0
- package/dist/src/delivery/block-streaming-config.test.js +91 -0
- package/dist/src/delivery/block-streaming-config.test.js.map +1 -0
- package/dist/src/delivery/deliver-text.d.ts +30 -0
- package/dist/src/delivery/deliver-text.d.ts.map +1 -0
- package/dist/src/delivery/deliver-text.js +88 -0
- package/dist/src/delivery/deliver-text.js.map +1 -0
- package/dist/src/delivery/deliver-text.test.d.ts +2 -0
- package/dist/src/delivery/deliver-text.test.d.ts.map +1 -0
- package/dist/src/delivery/deliver-text.test.js +117 -0
- package/dist/src/delivery/deliver-text.test.js.map +1 -0
- package/dist/src/delivery/im-tool-progress.d.ts +4 -0
- package/dist/src/delivery/im-tool-progress.d.ts.map +1 -0
- package/dist/src/delivery/im-tool-progress.js +87 -0
- package/dist/src/delivery/im-tool-progress.js.map +1 -0
- package/dist/src/delivery/inbound-terminal-delivery.d.ts +77 -0
- package/dist/src/delivery/inbound-terminal-delivery.d.ts.map +1 -0
- package/dist/src/delivery/inbound-terminal-delivery.js +251 -0
- package/dist/src/delivery/inbound-terminal-delivery.js.map +1 -0
- package/dist/src/delivery/inbound-terminal-state.d.ts +68 -0
- package/dist/src/delivery/inbound-terminal-state.d.ts.map +1 -0
- package/dist/src/delivery/inbound-terminal-state.js +185 -0
- package/dist/src/delivery/inbound-terminal-state.js.map +1 -0
- package/dist/src/delivery/inbound-terminal-state.test.d.ts +2 -0
- package/dist/src/delivery/inbound-terminal-state.test.d.ts.map +1 -0
- package/dist/src/delivery/inbound-terminal-state.test.js +224 -0
- package/dist/src/delivery/inbound-terminal-state.test.js.map +1 -0
- package/dist/src/delivery/send-file-event.d.ts +26 -0
- package/dist/src/delivery/send-file-event.d.ts.map +1 -0
- package/dist/src/delivery/send-file-event.js +33 -0
- package/dist/src/delivery/send-file-event.js.map +1 -0
- package/dist/src/delivery/send-file-event.test.d.ts +2 -0
- package/dist/src/delivery/send-file-event.test.d.ts.map +1 -0
- package/dist/src/delivery/send-file-event.test.js +86 -0
- package/dist/src/delivery/send-file-event.test.js.map +1 -0
- package/dist/src/delivery/send-service.d.ts +83 -0
- package/dist/src/delivery/send-service.d.ts.map +1 -0
- package/dist/src/delivery/send-service.js +324 -0
- package/dist/src/delivery/send-service.js.map +1 -0
- package/dist/src/delivery/send-service.test.d.ts +2 -0
- package/dist/src/delivery/send-service.test.d.ts.map +1 -0
- package/dist/src/delivery/send-service.test.js +40 -0
- package/dist/src/delivery/send-service.test.js.map +1 -0
- package/dist/src/delivery/thinking-ws-progress.d.ts +24 -0
- package/dist/src/delivery/thinking-ws-progress.d.ts.map +1 -0
- package/dist/src/delivery/thinking-ws-progress.js +45 -0
- package/dist/src/delivery/thinking-ws-progress.js.map +1 -0
- package/dist/src/delivery/thinking-ws-progress.test.d.ts +2 -0
- package/dist/src/delivery/thinking-ws-progress.test.d.ts.map +1 -0
- package/dist/src/delivery/thinking-ws-progress.test.js +38 -0
- package/dist/src/delivery/thinking-ws-progress.test.js.map +1 -0
- package/dist/src/delivery/turn-deliver-buffer.d.ts +60 -0
- package/dist/src/delivery/turn-deliver-buffer.d.ts.map +1 -0
- package/dist/src/delivery/turn-deliver-buffer.js +133 -0
- package/dist/src/delivery/turn-deliver-buffer.js.map +1 -0
- package/dist/src/delivery/turn-deliver-buffer.test.d.ts +2 -0
- package/dist/src/delivery/turn-deliver-buffer.test.d.ts.map +1 -0
- package/dist/src/delivery/turn-deliver-buffer.test.js +184 -0
- package/dist/src/delivery/turn-deliver-buffer.test.js.map +1 -0
- package/dist/src/delivery/user-facing-errors.d.ts +32 -0
- package/dist/src/delivery/user-facing-errors.d.ts.map +1 -0
- package/dist/src/delivery/user-facing-errors.js +120 -0
- package/dist/src/delivery/user-facing-errors.js.map +1 -0
- package/dist/src/delivery/user-facing-errors.test.d.ts +2 -0
- package/dist/src/delivery/user-facing-errors.test.d.ts.map +1 -0
- package/dist/src/delivery/user-facing-errors.test.js +102 -0
- package/dist/src/delivery/user-facing-errors.test.js.map +1 -0
- package/dist/src/inbound/dispatch-mentioned-reply.d.ts +47 -0
- package/dist/src/inbound/dispatch-mentioned-reply.d.ts.map +1 -0
- package/dist/src/inbound/dispatch-mentioned-reply.js +1014 -0
- package/dist/src/inbound/dispatch-mentioned-reply.js.map +1 -0
- package/dist/src/inbound/inbound-archive.d.ts +4 -0
- package/dist/src/inbound/inbound-archive.d.ts.map +1 -0
- package/dist/src/inbound/inbound-archive.js +105 -0
- package/dist/src/inbound/inbound-archive.js.map +1 -0
- package/dist/src/inbound/inbound-attachment-meta.d.ts +13 -0
- package/dist/src/inbound/inbound-attachment-meta.d.ts.map +1 -0
- package/dist/src/inbound/inbound-attachment-meta.js +39 -0
- package/dist/src/inbound/inbound-attachment-meta.js.map +1 -0
- package/dist/src/inbound/inbound-chat-type.d.ts +33 -0
- package/dist/src/inbound/inbound-chat-type.d.ts.map +1 -0
- package/dist/src/inbound/inbound-chat-type.js +52 -0
- package/dist/src/inbound/inbound-chat-type.js.map +1 -0
- package/dist/src/inbound/inbound-display.d.ts +41 -0
- package/dist/src/inbound/inbound-display.d.ts.map +1 -0
- package/dist/src/inbound/inbound-display.js +170 -0
- package/dist/src/inbound/inbound-display.js.map +1 -0
- package/dist/src/inbound/reply-dispatch-driver.d.ts +89 -0
- package/dist/src/inbound/reply-dispatch-driver.d.ts.map +1 -0
- package/dist/src/inbound/reply-dispatch-driver.js +294 -0
- package/dist/src/inbound/reply-dispatch-driver.js.map +1 -0
- package/dist/src/inbound/reply-dispatch-driver.test.d.ts +2 -0
- package/dist/src/inbound/reply-dispatch-driver.test.d.ts.map +1 -0
- package/dist/src/inbound/reply-dispatch-driver.test.js +363 -0
- package/dist/src/inbound/reply-dispatch-driver.test.js.map +1 -0
- package/dist/src/inbound/resolve-inbound-group-prompt.d.ts +37 -0
- package/dist/src/inbound/resolve-inbound-group-prompt.d.ts.map +1 -0
- package/dist/src/inbound/resolve-inbound-group-prompt.js +57 -0
- package/dist/src/inbound/resolve-inbound-group-prompt.js.map +1 -0
- package/dist/src/plan/action-run-event.d.ts +20 -0
- package/dist/src/plan/action-run-event.d.ts.map +1 -0
- package/dist/src/plan/action-run-event.js +62 -0
- package/dist/src/plan/action-run-event.js.map +1 -0
- package/dist/src/plan/action-run-event.test.d.ts +2 -0
- package/dist/src/plan/action-run-event.test.d.ts.map +1 -0
- package/dist/src/plan/action-run-event.test.js +83 -0
- package/dist/src/plan/action-run-event.test.js.map +1 -0
- package/dist/src/plan/action-store-access.d.ts +29 -0
- package/dist/src/plan/action-store-access.d.ts.map +1 -0
- package/dist/src/plan/action-store-access.js +81 -0
- package/dist/src/plan/action-store-access.js.map +1 -0
- package/dist/src/plan/action-store-lifecycle.test.d.ts +2 -0
- package/dist/src/plan/action-store-lifecycle.test.d.ts.map +1 -0
- package/dist/src/plan/action-store-lifecycle.test.js +195 -0
- package/dist/src/plan/action-store-lifecycle.test.js.map +1 -0
- package/dist/src/plan/plan-core-adapter.d.ts +54 -0
- package/dist/src/plan/plan-core-adapter.d.ts.map +1 -0
- package/dist/src/plan/plan-core-adapter.js +104 -0
- package/dist/src/plan/plan-core-adapter.js.map +1 -0
- package/dist/src/plan/plan-core-adapter.test.d.ts +2 -0
- package/dist/src/plan/plan-core-adapter.test.d.ts.map +1 -0
- package/dist/src/plan/plan-core-adapter.test.js +183 -0
- package/dist/src/plan/plan-core-adapter.test.js.map +1 -0
- package/dist/src/plan/plan-core-db.d.ts +22 -0
- package/dist/src/plan/plan-core-db.d.ts.map +1 -0
- package/dist/src/plan/plan-core-db.js +91 -0
- package/dist/src/plan/plan-core-db.js.map +1 -0
- package/dist/src/plan/plan-core-db.test.d.ts +2 -0
- package/dist/src/plan/plan-core-db.test.d.ts.map +1 -0
- package/dist/src/plan/plan-core-db.test.js +115 -0
- package/dist/src/plan/plan-core-db.test.js.map +1 -0
- package/dist/src/plan/plan-core-snapshot.d.ts +23 -0
- package/dist/src/plan/plan-core-snapshot.d.ts.map +1 -0
- package/dist/src/plan/plan-core-snapshot.js +66 -0
- package/dist/src/plan/plan-core-snapshot.js.map +1 -0
- package/dist/src/plan/plan-core-snapshot.test.d.ts +2 -0
- package/dist/src/plan/plan-core-snapshot.test.d.ts.map +1 -0
- package/dist/src/plan/plan-core-snapshot.test.js +157 -0
- package/dist/src/plan/plan-core-snapshot.test.js.map +1 -0
- package/dist/src/plan/plan-stat-event.d.ts +17 -0
- package/dist/src/plan/plan-stat-event.d.ts.map +1 -0
- package/dist/src/plan/plan-stat-event.js +41 -0
- package/dist/src/plan/plan-stat-event.js.map +1 -0
- package/dist/src/plan/plan-stat-event.test.d.ts +2 -0
- package/dist/src/plan/plan-stat-event.test.d.ts.map +1 -0
- package/dist/src/plan/plan-stat-event.test.js +131 -0
- package/dist/src/plan/plan-stat-event.test.js.map +1 -0
- package/dist/src/plan/plan-tool-middleware.d.ts +19 -0
- package/dist/src/plan/plan-tool-middleware.d.ts.map +1 -0
- package/dist/src/plan/plan-tool-middleware.js +63 -0
- package/dist/src/plan/plan-tool-middleware.js.map +1 -0
- package/dist/src/plan/plan-tool-middleware.test.d.ts +2 -0
- package/dist/src/plan/plan-tool-middleware.test.d.ts.map +1 -0
- package/dist/src/plan/plan-tool-middleware.test.js +103 -0
- package/dist/src/plan/plan-tool-middleware.test.js.map +1 -0
- package/dist/src/plan/plan-ws-registry.d.ts +15 -0
- package/dist/src/plan/plan-ws-registry.d.ts.map +1 -0
- package/dist/src/plan/plan-ws-registry.js +39 -0
- package/dist/src/plan/plan-ws-registry.js.map +1 -0
- package/dist/src/plan/plan-ws-registry.test.d.ts +2 -0
- package/dist/src/plan/plan-ws-registry.test.d.ts.map +1 -0
- package/dist/src/plan/plan-ws-registry.test.js +61 -0
- package/dist/src/plan/plan-ws-registry.test.js.map +1 -0
- package/dist/src/plan/tool-event-adapter.d.ts +31 -0
- package/dist/src/plan/tool-event-adapter.d.ts.map +1 -0
- package/dist/src/plan/tool-event-adapter.js +83 -0
- package/dist/src/plan/tool-event-adapter.js.map +1 -0
- package/dist/src/plan/tool-event-adapter.test.d.ts +2 -0
- package/dist/src/plan/tool-event-adapter.test.d.ts.map +1 -0
- package/dist/src/plan/tool-event-adapter.test.js +93 -0
- package/dist/src/plan/tool-event-adapter.test.js.map +1 -0
- package/dist/src/plugin/auth.d.ts +32 -0
- package/dist/src/plugin/auth.d.ts.map +1 -0
- package/dist/src/plugin/auth.js +70 -0
- package/dist/src/plugin/auth.js.map +1 -0
- package/dist/src/plugin/channel-config.d.ts +716 -0
- package/dist/src/plugin/channel-config.d.ts.map +1 -0
- package/dist/src/plugin/channel-config.js +405 -0
- package/dist/src/plugin/channel-config.js.map +1 -0
- package/dist/src/plugin/channel-config.test.d.ts +2 -0
- package/dist/src/plugin/channel-config.test.d.ts.map +1 -0
- package/dist/src/plugin/channel-config.test.js +113 -0
- package/dist/src/plugin/channel-config.test.js.map +1 -0
- package/dist/src/plugin/channel-disabled-account.test.d.ts +2 -0
- package/dist/src/plugin/channel-disabled-account.test.d.ts.map +1 -0
- package/dist/src/plugin/channel-disabled-account.test.js +44 -0
- package/dist/src/plugin/channel-disabled-account.test.js.map +1 -0
- package/dist/src/plugin/channel-log.d.ts +17 -0
- package/dist/src/plugin/channel-log.d.ts.map +1 -0
- package/dist/src/plugin/channel-log.js +45 -0
- package/dist/src/plugin/channel-log.js.map +1 -0
- package/dist/src/plugin/channel.d.ts +17 -0
- package/dist/src/plugin/channel.d.ts.map +1 -0
- package/dist/src/plugin/channel.js +272 -0
- package/dist/src/plugin/channel.js.map +1 -0
- package/dist/src/plugin/plugin-dispose.d.ts +22 -0
- package/dist/src/plugin/plugin-dispose.d.ts.map +1 -0
- package/dist/src/plugin/plugin-dispose.js +66 -0
- package/dist/src/plugin/plugin-dispose.js.map +1 -0
- package/dist/src/plugin/process-shared-store.d.ts +48 -0
- package/dist/src/plugin/process-shared-store.d.ts.map +1 -0
- package/dist/src/plugin/process-shared-store.js +89 -0
- package/dist/src/plugin/process-shared-store.js.map +1 -0
- package/dist/src/plugin/process-shared-store.test.d.ts +2 -0
- package/dist/src/plugin/process-shared-store.test.d.ts.map +1 -0
- package/dist/src/plugin/process-shared-store.test.js +60 -0
- package/dist/src/plugin/process-shared-store.test.js.map +1 -0
- package/dist/src/plugin/recommended-system-prompt.d.ts +3 -0
- package/dist/src/plugin/recommended-system-prompt.d.ts.map +1 -0
- package/dist/src/plugin/recommended-system-prompt.js +8 -0
- package/dist/src/plugin/recommended-system-prompt.js.map +1 -0
- package/dist/src/plugin/types.d.ts +433 -0
- package/dist/src/plugin/types.d.ts.map +1 -0
- package/dist/src/plugin/types.js +32 -0
- package/dist/src/plugin/types.js.map +1 -0
- package/dist/src/session/agent-context-types.d.ts +241 -0
- package/dist/src/session/agent-context-types.d.ts.map +1 -0
- package/dist/src/session/agent-context-types.js +142 -0
- package/dist/src/session/agent-context-types.js.map +1 -0
- package/dist/src/session/agent-context-types.test.d.ts +2 -0
- package/dist/src/session/agent-context-types.test.d.ts.map +1 -0
- package/dist/src/session/agent-context-types.test.js +140 -0
- package/dist/src/session/agent-context-types.test.js.map +1 -0
- package/dist/src/session/auto-model-router.d.ts +36 -0
- package/dist/src/session/auto-model-router.d.ts.map +1 -0
- package/dist/src/session/auto-model-router.js +60 -0
- package/dist/src/session/auto-model-router.js.map +1 -0
- package/dist/src/session/auto-model-router.test.d.ts +2 -0
- package/dist/src/session/auto-model-router.test.d.ts.map +1 -0
- package/dist/src/session/auto-model-router.test.js +99 -0
- package/dist/src/session/auto-model-router.test.js.map +1 -0
- package/dist/src/session/build-project-prompt.d.ts +40 -0
- package/dist/src/session/build-project-prompt.d.ts.map +1 -0
- package/dist/src/session/build-project-prompt.js +190 -0
- package/dist/src/session/build-project-prompt.js.map +1 -0
- package/dist/src/session/build-project-prompt.test.d.ts +2 -0
- package/dist/src/session/build-project-prompt.test.d.ts.map +1 -0
- package/dist/src/session/build-project-prompt.test.js +100 -0
- package/dist/src/session/build-project-prompt.test.js.map +1 -0
- package/dist/src/session/inbound-model.d.ts +39 -0
- package/dist/src/session/inbound-model.d.ts.map +1 -0
- package/dist/src/session/inbound-model.js +66 -0
- package/dist/src/session/inbound-model.js.map +1 -0
- package/dist/src/session/inbound-model.test.d.ts +2 -0
- package/dist/src/session/inbound-model.test.d.ts.map +1 -0
- package/dist/src/session/inbound-model.test.js +88 -0
- package/dist/src/session/inbound-model.test.js.map +1 -0
- package/dist/src/session/per-message-fallback-notice.d.ts +43 -0
- package/dist/src/session/per-message-fallback-notice.d.ts.map +1 -0
- package/dist/src/session/per-message-fallback-notice.js +93 -0
- package/dist/src/session/per-message-fallback-notice.js.map +1 -0
- package/dist/src/session/per-message-fallback-notice.test.d.ts +2 -0
- package/dist/src/session/per-message-fallback-notice.test.d.ts.map +1 -0
- package/dist/src/session/per-message-fallback-notice.test.js +47 -0
- package/dist/src/session/per-message-fallback-notice.test.js.map +1 -0
- package/dist/src/session/per-message-model-pending.d.ts +52 -0
- package/dist/src/session/per-message-model-pending.d.ts.map +1 -0
- package/dist/src/session/per-message-model-pending.js +134 -0
- package/dist/src/session/per-message-model-pending.js.map +1 -0
- package/dist/src/session/register-group-prompt-hook.d.ts +17 -0
- package/dist/src/session/register-group-prompt-hook.d.ts.map +1 -0
- package/dist/src/session/register-group-prompt-hook.js +45 -0
- package/dist/src/session/register-group-prompt-hook.js.map +1 -0
- package/dist/src/session/register-group-prompt-hook.test.d.ts +2 -0
- package/dist/src/session/register-group-prompt-hook.test.d.ts.map +1 -0
- package/dist/src/session/register-group-prompt-hook.test.js +60 -0
- package/dist/src/session/register-group-prompt-hook.test.js.map +1 -0
- package/dist/src/session/register-per-message-model-hook.d.ts +14 -0
- package/dist/src/session/register-per-message-model-hook.d.ts.map +1 -0
- package/dist/src/session/register-per-message-model-hook.js +48 -0
- package/dist/src/session/register-per-message-model-hook.js.map +1 -0
- package/dist/src/session/register-per-message-model-hook.test.d.ts +2 -0
- package/dist/src/session/register-per-message-model-hook.test.d.ts.map +1 -0
- package/dist/src/session/register-per-message-model-hook.test.js +208 -0
- package/dist/src/session/register-per-message-model-hook.test.js.map +1 -0
- package/dist/src/session/register-run-model-context-hook.d.ts +11 -0
- package/dist/src/session/register-run-model-context-hook.d.ts.map +1 -0
- package/dist/src/session/register-run-model-context-hook.js +23 -0
- package/dist/src/session/register-run-model-context-hook.js.map +1 -0
- package/dist/src/session/run-model-context.d.ts +45 -0
- package/dist/src/session/run-model-context.d.ts.map +1 -0
- package/dist/src/session/run-model-context.js +108 -0
- package/dist/src/session/run-model-context.js.map +1 -0
- package/dist/src/session/run-model-context.test.d.ts +2 -0
- package/dist/src/session/run-model-context.test.d.ts.map +1 -0
- package/dist/src/session/run-model-context.test.js +68 -0
- package/dist/src/session/run-model-context.test.js.map +1 -0
- package/dist/src/session/session-env-store.d.ts +55 -0
- package/dist/src/session/session-env-store.d.ts.map +1 -0
- package/dist/src/session/session-env-store.js +328 -0
- package/dist/src/session/session-env-store.js.map +1 -0
- package/dist/src/session/session-env-store.test.d.ts +2 -0
- package/dist/src/session/session-env-store.test.d.ts.map +1 -0
- package/dist/src/session/session-env-store.test.js +151 -0
- package/dist/src/session/session-env-store.test.js.map +1 -0
- package/dist/src/session/session-group-prompt.d.ts +34 -0
- package/dist/src/session/session-group-prompt.d.ts.map +1 -0
- package/dist/src/session/session-group-prompt.js +101 -0
- package/dist/src/session/session-group-prompt.js.map +1 -0
- package/dist/src/session/session-group-prompt.test.d.ts +2 -0
- package/dist/src/session/session-group-prompt.test.d.ts.map +1 -0
- package/dist/src/session/session-group-prompt.test.js +72 -0
- package/dist/src/session/session-group-prompt.test.js.map +1 -0
- package/dist/src/session/session-im-context.d.ts +15 -0
- package/dist/src/session/session-im-context.d.ts.map +1 -0
- package/dist/src/session/session-im-context.js +54 -0
- package/dist/src/session/session-im-context.js.map +1 -0
- package/dist/src/session/session-model-fallback.d.ts +13 -0
- package/dist/src/session/session-model-fallback.d.ts.map +1 -0
- package/dist/src/session/session-model-fallback.js +24 -0
- package/dist/src/session/session-model-fallback.js.map +1 -0
- package/dist/src/tools/active-cron-context-store.d.ts +20 -0
- package/dist/src/tools/active-cron-context-store.d.ts.map +1 -0
- package/dist/src/tools/active-cron-context-store.js +73 -0
- package/dist/src/tools/active-cron-context-store.js.map +1 -0
- package/dist/src/tools/cron-appkey-binding-store.d.ts +29 -0
- package/dist/src/tools/cron-appkey-binding-store.d.ts.map +1 -0
- package/dist/src/tools/cron-appkey-binding-store.js +239 -0
- package/dist/src/tools/cron-appkey-binding-store.js.map +1 -0
- package/dist/src/tools/cron-appkey-binding-store.test.d.ts +2 -0
- package/dist/src/tools/cron-appkey-binding-store.test.d.ts.map +1 -0
- package/dist/src/tools/cron-appkey-binding-store.test.js +387 -0
- package/dist/src/tools/cron-appkey-binding-store.test.js.map +1 -0
- package/dist/src/tools/group-history-tool.d.ts +31 -0
- package/dist/src/tools/group-history-tool.d.ts.map +1 -0
- package/dist/src/tools/group-history-tool.js +177 -0
- package/dist/src/tools/group-history-tool.js.map +1 -0
- package/dist/src/tools/register-exec-env-hook.d.ts +44 -0
- package/dist/src/tools/register-exec-env-hook.d.ts.map +1 -0
- package/dist/src/tools/register-exec-env-hook.js +473 -0
- package/dist/src/tools/register-exec-env-hook.js.map +1 -0
- package/dist/src/tools/register-exec-env-hook.test.d.ts +2 -0
- package/dist/src/tools/register-exec-env-hook.test.d.ts.map +1 -0
- package/dist/src/tools/register-exec-env-hook.test.js +189 -0
- package/dist/src/tools/register-exec-env-hook.test.js.map +1 -0
- package/dist/src/tools/send-file-tool.d.ts +81 -0
- package/dist/src/tools/send-file-tool.d.ts.map +1 -0
- package/dist/src/tools/send-file-tool.js +363 -0
- package/dist/src/tools/send-file-tool.js.map +1 -0
- package/dist/src/tools/send-file-tool.test.d.ts +2 -0
- package/dist/src/tools/send-file-tool.test.d.ts.map +1 -0
- package/dist/src/tools/send-file-tool.test.js +176 -0
- package/dist/src/tools/send-file-tool.test.js.map +1 -0
- package/dist/src/tools/send-group-message-tool.d.ts +17 -0
- package/dist/src/tools/send-group-message-tool.d.ts.map +1 -0
- package/dist/src/tools/send-group-message-tool.js +82 -0
- package/dist/src/tools/send-group-message-tool.js.map +1 -0
- package/dist/src/tools/tool-json-result.d.ts +14 -0
- package/dist/src/tools/tool-json-result.d.ts.map +1 -0
- package/dist/src/tools/tool-json-result.js +20 -0
- package/dist/src/tools/tool-json-result.js.map +1 -0
- package/dist/src/turn/active-round-registry.d.ts +35 -0
- package/dist/src/turn/active-round-registry.d.ts.map +1 -0
- package/dist/src/turn/active-round-registry.js +85 -0
- package/dist/src/turn/active-round-registry.js.map +1 -0
- package/dist/src/turn/active-round-registry.test.d.ts +2 -0
- package/dist/src/turn/active-round-registry.test.d.ts.map +1 -0
- package/dist/src/turn/active-round-registry.test.js +62 -0
- package/dist/src/turn/active-round-registry.test.js.map +1 -0
- package/dist/src/turn/interrupt-round.d.ts +9 -0
- package/dist/src/turn/interrupt-round.d.ts.map +1 -0
- package/dist/src/turn/interrupt-round.js +44 -0
- package/dist/src/turn/interrupt-round.js.map +1 -0
- package/dist/src/turn/interrupt-round.test.d.ts +2 -0
- package/dist/src/turn/interrupt-round.test.d.ts.map +1 -0
- package/dist/src/turn/interrupt-round.test.js +133 -0
- package/dist/src/turn/interrupt-round.test.js.map +1 -0
- package/dist/src/turn/item-event-guard.d.ts +28 -0
- package/dist/src/turn/item-event-guard.d.ts.map +1 -0
- package/dist/src/turn/item-event-guard.js +22 -0
- package/dist/src/turn/item-event-guard.js.map +1 -0
- package/dist/src/turn/item-event-guard.test.d.ts +2 -0
- package/dist/src/turn/item-event-guard.test.d.ts.map +1 -0
- package/dist/src/turn/item-event-guard.test.js +55 -0
- package/dist/src/turn/item-event-guard.test.js.map +1 -0
- package/dist/src/turn/run-usage-session.d.ts +13 -0
- package/dist/src/turn/run-usage-session.d.ts.map +1 -0
- package/dist/src/turn/run-usage-session.js +41 -0
- package/dist/src/turn/run-usage-session.js.map +1 -0
- package/dist/src/turn/run-usage.d.ts +67 -0
- package/dist/src/turn/run-usage.d.ts.map +1 -0
- package/dist/src/turn/run-usage.js +119 -0
- package/dist/src/turn/run-usage.js.map +1 -0
- package/dist/src/turn/run-usage.test.d.ts +2 -0
- package/dist/src/turn/run-usage.test.d.ts.map +1 -0
- package/dist/src/turn/run-usage.test.js +178 -0
- package/dist/src/turn/run-usage.test.js.map +1 -0
- package/dist/src/turn/subagent-monitor.d.ts +45 -0
- package/dist/src/turn/subagent-monitor.d.ts.map +1 -0
- package/dist/src/turn/subagent-monitor.js +498 -0
- package/dist/src/turn/subagent-monitor.js.map +1 -0
- package/dist/src/turn/subagent-monitor.test.d.ts +2 -0
- package/dist/src/turn/subagent-monitor.test.d.ts.map +1 -0
- package/dist/src/turn/subagent-monitor.test.js +335 -0
- package/dist/src/turn/subagent-monitor.test.js.map +1 -0
- package/dist/src/turn/turn-agent-event-subscription.d.ts +29 -0
- package/dist/src/turn/turn-agent-event-subscription.d.ts.map +1 -0
- package/dist/src/turn/turn-agent-event-subscription.js +350 -0
- package/dist/src/turn/turn-agent-event-subscription.js.map +1 -0
- package/dist/src/turn/turn-agent-event-subscription.test.d.ts +2 -0
- package/dist/src/turn/turn-agent-event-subscription.test.d.ts.map +1 -0
- package/dist/src/turn/turn-agent-event-subscription.test.js +257 -0
- package/dist/src/turn/turn-agent-event-subscription.test.js.map +1 -0
- package/dist/src/turn/turn-end-controller.d.ts +61 -0
- package/dist/src/turn/turn-end-controller.d.ts.map +1 -0
- package/dist/src/turn/turn-end-controller.js +239 -0
- package/dist/src/turn/turn-end-controller.js.map +1 -0
- package/dist/src/turn/turn-end-controller.test.d.ts +2 -0
- package/dist/src/turn/turn-end-controller.test.d.ts.map +1 -0
- package/dist/src/turn/turn-end-controller.test.js +97 -0
- package/dist/src/turn/turn-end-controller.test.js.map +1 -0
- package/dist/src/turn/ws-run-event-unmapped.d.ts +10 -0
- package/dist/src/turn/ws-run-event-unmapped.d.ts.map +1 -0
- package/dist/src/turn/ws-run-event-unmapped.js +16 -0
- package/dist/src/turn/ws-run-event-unmapped.js.map +1 -0
- package/dist/src/turn/ws-run-event-unmapped.test.d.ts +2 -0
- package/dist/src/turn/ws-run-event-unmapped.test.d.ts.map +1 -0
- package/dist/src/turn/ws-run-event-unmapped.test.js +15 -0
- package/dist/src/turn/ws-run-event-unmapped.test.js.map +1 -0
- package/dist/src/workspace/apply-sync-mapping.d.ts +15 -0
- package/dist/src/workspace/apply-sync-mapping.d.ts.map +1 -0
- package/dist/src/workspace/apply-sync-mapping.js +98 -0
- package/dist/src/workspace/apply-sync-mapping.js.map +1 -0
- package/dist/src/workspace/connection-workspace-event.test.d.ts +2 -0
- package/dist/src/workspace/connection-workspace-event.test.d.ts.map +1 -0
- package/dist/src/workspace/connection-workspace-event.test.js +74 -0
- package/dist/src/workspace/connection-workspace-event.test.js.map +1 -0
- package/dist/src/workspace/inbound-file-download.d.ts +15 -0
- package/dist/src/workspace/inbound-file-download.d.ts.map +1 -0
- package/dist/src/workspace/inbound-file-download.js +48 -0
- package/dist/src/workspace/inbound-file-download.js.map +1 -0
- package/dist/src/workspace/inbound-input-media.d.ts +43 -0
- package/dist/src/workspace/inbound-input-media.d.ts.map +1 -0
- package/dist/src/workspace/inbound-input-media.js +230 -0
- package/dist/src/workspace/inbound-input-media.js.map +1 -0
- package/dist/src/workspace/inbound-media-local.d.ts +49 -0
- package/dist/src/workspace/inbound-media-local.d.ts.map +1 -0
- package/dist/src/workspace/inbound-media-local.js +194 -0
- package/dist/src/workspace/inbound-media-local.js.map +1 -0
- package/dist/src/workspace/nas-site.d.ts +16 -0
- package/dist/src/workspace/nas-site.d.ts.map +1 -0
- package/dist/src/workspace/nas-site.js +17 -0
- package/dist/src/workspace/nas-site.js.map +1 -0
- package/dist/src/workspace/nas-volume-fs-sync.d.ts +37 -0
- package/dist/src/workspace/nas-volume-fs-sync.d.ts.map +1 -0
- package/dist/src/workspace/nas-volume-fs-sync.js +156 -0
- package/dist/src/workspace/nas-volume-fs-sync.js.map +1 -0
- package/dist/src/workspace/nas-volume-fs-sync.test.d.ts +2 -0
- package/dist/src/workspace/nas-volume-fs-sync.test.d.ts.map +1 -0
- package/dist/src/workspace/nas-volume-fs-sync.test.js +49 -0
- package/dist/src/workspace/nas-volume-fs-sync.test.js.map +1 -0
- package/dist/src/workspace/nas-volumes.d.ts +73 -0
- package/dist/src/workspace/nas-volumes.d.ts.map +1 -0
- package/dist/src/workspace/nas-volumes.js +546 -0
- package/dist/src/workspace/nas-volumes.js.map +1 -0
- package/dist/src/workspace/nas-volumes.test.d.ts +2 -0
- package/dist/src/workspace/nas-volumes.test.d.ts.map +1 -0
- package/dist/src/workspace/nas-volumes.test.js +386 -0
- package/dist/src/workspace/nas-volumes.test.js.map +1 -0
- package/dist/src/workspace/project-path-normalize.d.ts +30 -0
- package/dist/src/workspace/project-path-normalize.d.ts.map +1 -0
- package/dist/src/workspace/project-path-normalize.js +101 -0
- package/dist/src/workspace/project-path-normalize.js.map +1 -0
- package/dist/src/workspace/resource-file.d.ts +119 -0
- package/dist/src/workspace/resource-file.d.ts.map +1 -0
- package/dist/src/workspace/resource-file.js +533 -0
- package/dist/src/workspace/resource-file.js.map +1 -0
- package/dist/src/workspace/resource-file.test.d.ts +2 -0
- package/dist/src/workspace/resource-file.test.d.ts.map +1 -0
- package/dist/src/workspace/resource-file.test.js +64 -0
- package/dist/src/workspace/resource-file.test.js.map +1 -0
- package/dist/src/workspace/sync-mapping-types.d.ts +220 -0
- package/dist/src/workspace/sync-mapping-types.d.ts.map +1 -0
- package/dist/src/workspace/sync-mapping-types.js +55 -0
- package/dist/src/workspace/sync-mapping-types.js.map +1 -0
- package/dist/src/workspace/sync-service-client.d.ts +29 -0
- package/dist/src/workspace/sync-service-client.d.ts.map +1 -0
- package/dist/src/workspace/sync-service-client.js +72 -0
- package/dist/src/workspace/sync-service-client.js.map +1 -0
- package/dist/src/workspace/workspace-event-protocol.d.ts +3 -0
- package/dist/src/workspace/workspace-event-protocol.d.ts.map +1 -0
- package/dist/src/workspace/workspace-event-protocol.js +3 -0
- package/dist/src/workspace/workspace-event-protocol.js.map +1 -0
- package/dist/src/workspace/workspace-event-scheduler.d.ts +54 -0
- package/dist/src/workspace/workspace-event-scheduler.d.ts.map +1 -0
- package/dist/src/workspace/workspace-event-scheduler.js +131 -0
- package/dist/src/workspace/workspace-event-scheduler.js.map +1 -0
- package/dist/src/workspace/workspace-event-scheduler.test.d.ts +2 -0
- package/dist/src/workspace/workspace-event-scheduler.test.d.ts.map +1 -0
- package/dist/src/workspace/workspace-event-scheduler.test.js +157 -0
- package/dist/src/workspace/workspace-event-scheduler.test.js.map +1 -0
- package/dist/src/workspace/workspace-event.d.ts +28 -0
- package/dist/src/workspace/workspace-event.d.ts.map +1 -0
- package/dist/src/workspace/workspace-event.js +674 -0
- package/dist/src/workspace/workspace-event.js.map +1 -0
- package/dist/src/workspace/workspace-event.test.d.ts +2 -0
- package/dist/src/workspace/workspace-event.test.d.ts.map +1 -0
- package/dist/src/workspace/workspace-event.test.js +265 -0
- package/dist/src/workspace/workspace-event.test.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XG-IM 消息发送模块
|
|
3
|
+
*
|
|
4
|
+
* 调用 IM 接口将 AI 回复发送到指定群聊,并 @ 原始发送者。
|
|
5
|
+
* 支持 RICH_TEXT 与带资源 fileId 的 FILE 类型(attachments)。
|
|
6
|
+
*/
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
|
+
import axios from "axios";
|
|
9
|
+
import { downloadMediaBuffer, formatFromFilename, parseWorkspaceRelativeMediaRef, resolveMaxAttachmentBytes, resolveResourceUploadUrl, uploadWholeResourceFile, } from "../workspace/resource-file.js";
|
|
10
|
+
import { stripMediaDirectiveLines, stripModelUsageFooter } from "./deliver-text.js";
|
|
11
|
+
import { formatUserFacingMediaDeliverError } from "./user-facing-errors.js";
|
|
12
|
+
function formatDeliverError(err) {
|
|
13
|
+
if (axios.isAxiosError(err)) {
|
|
14
|
+
const parts = [err.message];
|
|
15
|
+
if (err.code)
|
|
16
|
+
parts.push(`axiosCode=${err.code}`);
|
|
17
|
+
if (err.response?.status != null)
|
|
18
|
+
parts.push(`httpStatus=${err.response.status}`);
|
|
19
|
+
return parts.join(" ");
|
|
20
|
+
}
|
|
21
|
+
if (err instanceof Error)
|
|
22
|
+
return err.message;
|
|
23
|
+
return String(err);
|
|
24
|
+
}
|
|
25
|
+
/** 文件下载/上传失败时:正文 + 原始媒体链接 + 失败说明(链接可供用户或后续轮次使用)。 */
|
|
26
|
+
function buildFileDeliverFallbackText(textToSend, mediaUrls, err) {
|
|
27
|
+
const errNote = `(${formatUserFacingMediaDeliverError(err, mediaUrls)})`;
|
|
28
|
+
const urlBlock = mediaUrls.length > 0
|
|
29
|
+
? `\n\n**附件链接(未能上传 IM)**\n${mediaUrls.map((u) => `- \`${u.trim()}\``).join("\n")}`
|
|
30
|
+
: "";
|
|
31
|
+
if (textToSend.length > 0) {
|
|
32
|
+
return `${textToSend}${urlBlock}\n\n${errNote}`;
|
|
33
|
+
}
|
|
34
|
+
if (urlBlock.trim()) {
|
|
35
|
+
return `${urlBlock.trim()}\n\n${errNote}`;
|
|
36
|
+
}
|
|
37
|
+
return errNote;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 生成一次投递的客户端幂等键。
|
|
41
|
+
*
|
|
42
|
+
* 服务端按 `clientMsgId + groupId + 最近 10 分钟` 去重:同一逻辑消息在其内部 6 次重试间
|
|
43
|
+
* 复用同一 `clientMsgId`,超时/断连重发会命中服务端已有消息,不产生重复气泡。
|
|
44
|
+
* 每个独立投递块生成一次(不同块必须不同)。
|
|
45
|
+
*/
|
|
46
|
+
export function generateClientMsgId() {
|
|
47
|
+
return `ocw_${Date.now()}_${randomUUID()}`;
|
|
48
|
+
}
|
|
49
|
+
/** 从发送接口响应中解析服务端消息 id(`data.id`)与回显 `clientMsgId`,用于对账日志。 */
|
|
50
|
+
export function extractSentMessageInfo(resData) {
|
|
51
|
+
if (!resData || typeof resData !== "object")
|
|
52
|
+
return {};
|
|
53
|
+
const data = resData.data;
|
|
54
|
+
if (!data || typeof data !== "object")
|
|
55
|
+
return {};
|
|
56
|
+
const d = data;
|
|
57
|
+
const serverMsgId = typeof d.id === "string" ? d.id : d.id != null ? String(d.id) : undefined;
|
|
58
|
+
const clientMsgId = typeof d.clientMsgId === "string" ? d.clientMsgId : undefined;
|
|
59
|
+
return { serverMsgId, clientMsgId };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 发消息接口的重试参数。
|
|
63
|
+
*
|
|
64
|
+
* 总尝试次数 = 1(首次) + IM_SEND_MAX_RETRIES(重试) = 6。
|
|
65
|
+
* 重试间隔指数退避:1s → 2s → 4s → 8s → 16s(上限 IM_SEND_RETRY_DELAY_CAP_MS)。
|
|
66
|
+
* 仅对网络层瞬时错误(无响应 / 5xx / 408 / 429)重试;4xx 与业务 resultCode 错误视为永久失败,立即抛出。
|
|
67
|
+
*/
|
|
68
|
+
const IM_SEND_MAX_RETRIES = 5;
|
|
69
|
+
const IM_SEND_RETRY_DELAY_BASE_MS = 1_000;
|
|
70
|
+
const IM_SEND_RETRY_DELAY_CAP_MS = 30_000;
|
|
71
|
+
function calcSendRetryDelayMs(attempt) {
|
|
72
|
+
const exp = IM_SEND_RETRY_DELAY_BASE_MS * 2 ** Math.max(0, attempt - 1);
|
|
73
|
+
return Math.min(exp, IM_SEND_RETRY_DELAY_CAP_MS);
|
|
74
|
+
}
|
|
75
|
+
function delay(ms) {
|
|
76
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 判断错误是否值得重试。
|
|
80
|
+
*
|
|
81
|
+
* - axios 网络错误 / 超时 / 5xx / 408 / 429 → 重试
|
|
82
|
+
* - 4xx(其它)/ 业务 resultCode 错误(普通 Error)→ 永久失败,不重试
|
|
83
|
+
*/
|
|
84
|
+
function isRetryableSendError(err) {
|
|
85
|
+
if (axios.isAxiosError(err)) {
|
|
86
|
+
const status = err.response?.status;
|
|
87
|
+
if (status === undefined)
|
|
88
|
+
return true;
|
|
89
|
+
if (status >= 500)
|
|
90
|
+
return true;
|
|
91
|
+
if (status === 408 || status === 429)
|
|
92
|
+
return true;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
/** POST /im/message/send 相关日志:`log` 未传入或网关未绑定时仍输出到 console,避免「消息已发出却看不到接口日志」 */
|
|
98
|
+
function sendLogInfo(log, msg) {
|
|
99
|
+
if (typeof log?.info === "function") {
|
|
100
|
+
log.info(msg);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const alt = log;
|
|
104
|
+
if (typeof alt?.log === "function") {
|
|
105
|
+
alt.log(msg);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
console.log(`[xg_cwork_im] ${msg}`);
|
|
109
|
+
}
|
|
110
|
+
function sendLogWarn(log, msg) {
|
|
111
|
+
if (typeof log?.warn === "function") {
|
|
112
|
+
log.warn(msg);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
sendLogInfo(log, msg);
|
|
116
|
+
}
|
|
117
|
+
function sendLogError(log, msg) {
|
|
118
|
+
if (typeof log?.error === "function") {
|
|
119
|
+
log.error(msg);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
console.error(`[xg_cwork_im] ${msg}`);
|
|
123
|
+
}
|
|
124
|
+
function sendLogDebug(log, config, msg) {
|
|
125
|
+
if (!config.debug)
|
|
126
|
+
return;
|
|
127
|
+
if (typeof log?.debug === "function") {
|
|
128
|
+
log.debug(msg);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
console.log(`[xg_cwork_im] ${msg}`);
|
|
132
|
+
}
|
|
133
|
+
async function postImMessage(config, token, groupId, body, atUserIds = [], log) {
|
|
134
|
+
const url = `${config.baseUrl}/im/message/send`;
|
|
135
|
+
const full = {
|
|
136
|
+
...body,
|
|
137
|
+
groupId,
|
|
138
|
+
...(atUserIds.length > 0 ? { atUserIds } : {}),
|
|
139
|
+
};
|
|
140
|
+
const bodyClientMsgId = typeof full.clientMsgId === "string" ? full.clientMsgId : undefined;
|
|
141
|
+
sendLogInfo(log, `[cwork_im:send] POST ${url} groupId=${groupId} type=${full.type} ` +
|
|
142
|
+
`clientMsgId=${bodyClientMsgId ?? "none"} ` +
|
|
143
|
+
`atUsers=${JSON.stringify(atUserIds)}`);
|
|
144
|
+
sendLogDebug(log, config, `[cwork_im:send] Request body: ${JSON.stringify(full)}`);
|
|
145
|
+
const totalAttempts = 1 + IM_SEND_MAX_RETRIES;
|
|
146
|
+
let lastErr = undefined;
|
|
147
|
+
for (let attempt = 1; attempt <= totalAttempts; attempt++) {
|
|
148
|
+
try {
|
|
149
|
+
const res = await axios.post(url, full, {
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Type": "application/json",
|
|
152
|
+
"access-token": token,
|
|
153
|
+
},
|
|
154
|
+
timeout: 10_000,
|
|
155
|
+
});
|
|
156
|
+
sendLogInfo(log, `[cwork_im:send] Response status=${res.status} (attempt=${attempt}/${totalAttempts})`);
|
|
157
|
+
sendLogDebug(log, config, `[cwork_im:send] Response body: ${JSON.stringify(res.data)}`);
|
|
158
|
+
// Detect business-level errors that arrive with HTTP 200.
|
|
159
|
+
// IM API unified response: { data, resultCode: 1, resultMsg: "" } — resultCode=1 means success.
|
|
160
|
+
const d = res.data;
|
|
161
|
+
if (d && typeof d === "object") {
|
|
162
|
+
const resultCode = d.resultCode;
|
|
163
|
+
const resultMsg = d.resultMsg;
|
|
164
|
+
if (resultCode !== undefined && resultCode !== 1) {
|
|
165
|
+
throw new Error(`IM API error resultCode=${resultCode}${resultMsg ? ` resultMsg=${resultMsg}` : ""}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// 对账日志:服务端消息 id(data.id)+ 回显 clientMsgId;重试命中去重时会返回既有消息。
|
|
169
|
+
const sent = extractSentMessageInfo(d);
|
|
170
|
+
sendLogInfo(log, `[cwork_im:send] Delivered groupId=${groupId} ` +
|
|
171
|
+
`serverMsgId=${sent.serverMsgId ?? "unknown"} ` +
|
|
172
|
+
`clientMsgId=${sent.clientMsgId ?? bodyClientMsgId ?? "none"} ` +
|
|
173
|
+
`(attempt=${attempt}/${totalAttempts})`);
|
|
174
|
+
return { serverMsgId: sent.serverMsgId, clientMsgId: sent.clientMsgId ?? bodyClientMsgId };
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
lastErr = err;
|
|
178
|
+
const msg = formatDeliverError(err);
|
|
179
|
+
const retryable = isRetryableSendError(err);
|
|
180
|
+
const isLast = attempt >= totalAttempts;
|
|
181
|
+
if (!retryable || isLast) {
|
|
182
|
+
sendLogError(log, `[cwork_im:send] Failed to send message to groupId=${groupId} ` +
|
|
183
|
+
`(attempt=${attempt}/${totalAttempts}, retryable=${retryable}): ${msg}`);
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
186
|
+
const retryDelayMs = calcSendRetryDelayMs(attempt);
|
|
187
|
+
sendLogWarn(log, `[cwork_im:send] Send failed (attempt=${attempt}/${totalAttempts}), ` +
|
|
188
|
+
`retrying in ${retryDelayMs}ms: ${msg}`);
|
|
189
|
+
await delay(retryDelayMs);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// 理论上不可达:上面循环里要么 return 要么 throw。这里只是给 TS 一个安全兜底。
|
|
193
|
+
throw lastErr ?? new Error("[cwork_im:send] Send failed after retries");
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 将 deliver 块发到 IM:若有媒体则先 POST baseUrl/file/upDownload/uploadWholeFile 再发 FILE;否则发 RICH_TEXT。
|
|
197
|
+
*
|
|
198
|
+
* @param agentWorkspaceDir 可选。Agent 在宿主机的 workspace 绝对路径(由 resolveAgentWorkspaceDir 得到)。
|
|
199
|
+
* 用于在多沙箱 agent 场景下正确解析 /workspace/ 前缀路径。
|
|
200
|
+
* 未传时回退到 process.cwd(),单 agent 部署下行为不变。
|
|
201
|
+
*/
|
|
202
|
+
export async function sendReplyDeliverBlock(config, token, groupId, payload, atUserIds = [], log, _deprecatedMsgId, reply, agentWorkspaceDir) {
|
|
203
|
+
// 一个投递块一个 clientMsgId:内部 6 次重试复用同值 → 命中服务端去重,不重复投递。
|
|
204
|
+
const clientMsgId = generateClientMsgId();
|
|
205
|
+
const textToSend = stripModelUsageFooter(stripMediaDirectiveLines((payload.markdown || payload.text || "").trim()));
|
|
206
|
+
const mediaList = [
|
|
207
|
+
...(payload.mediaUrl ? [payload.mediaUrl] : []),
|
|
208
|
+
...((payload.mediaUrls ?? []).filter((u) => typeof u === "string" && u.trim())),
|
|
209
|
+
];
|
|
210
|
+
const uniqueUrls = [...new Set(mediaList)];
|
|
211
|
+
const maxBytes = resolveMaxAttachmentBytes(config);
|
|
212
|
+
const formField = config.fileUploadFormField?.trim() || "file";
|
|
213
|
+
const wantFile = uniqueUrls.length > 0 && !payload.isThinking;
|
|
214
|
+
sendLogInfo(log, `[cwork_im:send] sendReplyDeliverBlock plan kind=${wantFile ? "FILE" : textToSend.length > 0 ? "RICH_TEXT" : "none"} ` +
|
|
215
|
+
`clientMsgId=${clientMsgId} ` +
|
|
216
|
+
`isThinking=${payload.isThinking ?? false}`);
|
|
217
|
+
if (wantFile) {
|
|
218
|
+
const fileUploadUrl = resolveResourceUploadUrl(config.baseUrl);
|
|
219
|
+
if (!agentWorkspaceDir?.trim() && uniqueUrls.some((u) => {
|
|
220
|
+
const t = u.trim();
|
|
221
|
+
return t.startsWith("/workspace") || parseWorkspaceRelativeMediaRef(t) != null;
|
|
222
|
+
})) {
|
|
223
|
+
sendLogWarn(log, `[cwork_im:send] agentWorkspaceDir missing for workspace media; ` +
|
|
224
|
+
`falling back to cwd and /workspace candidates (text-only unaffected) refs=${uniqueUrls.length}`);
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
const attachments = [];
|
|
228
|
+
for (const u of uniqueUrls) {
|
|
229
|
+
const { buffer, filename } = await downloadMediaBuffer(u, maxBytes, log, agentWorkspaceDir);
|
|
230
|
+
const { fileId } = await uploadWholeResourceFile({
|
|
231
|
+
fileUploadUrl,
|
|
232
|
+
token,
|
|
233
|
+
buffer,
|
|
234
|
+
filename,
|
|
235
|
+
formField,
|
|
236
|
+
log,
|
|
237
|
+
});
|
|
238
|
+
attachments.push({
|
|
239
|
+
fileId,
|
|
240
|
+
fileType: "FILE",
|
|
241
|
+
format: formatFromFilename(filename),
|
|
242
|
+
name: filename,
|
|
243
|
+
size: buffer.length,
|
|
244
|
+
source: "resource",
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
const caption = textToSend.length > 0 ? textToSend : " ";
|
|
248
|
+
await postImMessage(config, token, groupId, {
|
|
249
|
+
type: "FILE",
|
|
250
|
+
text: caption,
|
|
251
|
+
attachments,
|
|
252
|
+
clientMsgId,
|
|
253
|
+
...(reply ? { reply } : {}),
|
|
254
|
+
}, atUserIds, log);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
sendLogError(log, `[cwork_im:send] FILE deliver failed, fallback to text if any: ${formatDeliverError(err)}`);
|
|
259
|
+
const fallbackText = buildFileDeliverFallbackText(textToSend, uniqueUrls, err);
|
|
260
|
+
// 下载/上传失败不阻塞:仍发 RICH_TEXT,并附带原始媒体链接
|
|
261
|
+
await postImMessage(config, token, groupId, {
|
|
262
|
+
type: "RICH_TEXT",
|
|
263
|
+
text: fallbackText,
|
|
264
|
+
clientMsgId,
|
|
265
|
+
...(reply ? { reply } : {}),
|
|
266
|
+
}, atUserIds, log);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (textToSend.length > 0) {
|
|
271
|
+
await postImMessage(config, token, groupId, {
|
|
272
|
+
type: "RICH_TEXT",
|
|
273
|
+
text: textToSend,
|
|
274
|
+
clientMsgId,
|
|
275
|
+
...(reply ? { reply } : {}),
|
|
276
|
+
}, atUserIds, log);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 发送一条已上传资源的 FILE 消息到指定 IM 群聊。
|
|
281
|
+
*
|
|
282
|
+
* 与 {@link sendReplyDeliverBlock} 不同:本函数**不做** URL 下载 / 上传失败降级为文本的逻辑,
|
|
283
|
+
* 仅负责把已经拿到 fileId 的附件组装成 FILE 消息发出。失败直接抛出,由调用方(工具)返回明确错误,
|
|
284
|
+
* 不会产生「降级成文本却报成功」的假成功。上传步骤请在调用前用
|
|
285
|
+
* {@link uploadWholeResourceFileWithRetry} 完成。
|
|
286
|
+
*
|
|
287
|
+
* 复用 {@link postImMessage} 的 6 次网络重试与服务端 clientMsgId 去重。
|
|
288
|
+
*/
|
|
289
|
+
export async function sendUploadedFileMessage(args) {
|
|
290
|
+
const caption = args.caption && args.caption.trim().length > 0 ? args.caption : " ";
|
|
291
|
+
const clientMsgId = args.clientMsgId ?? generateClientMsgId();
|
|
292
|
+
const sent = await postImMessage(args.config, args.token, args.groupId, {
|
|
293
|
+
type: "FILE",
|
|
294
|
+
text: caption,
|
|
295
|
+
attachments: [args.attachment],
|
|
296
|
+
clientMsgId,
|
|
297
|
+
...(args.reply ? { reply: args.reply } : {}),
|
|
298
|
+
}, args.atUserIds ?? [], args.log);
|
|
299
|
+
return { clientMsgId, serverMsgId: sent.serverMsgId };
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* 发送文本消息到指定 IM 群聊。
|
|
303
|
+
*
|
|
304
|
+
* @param config 插件配置
|
|
305
|
+
* @param token 鉴权 token
|
|
306
|
+
* @param groupId 目标群聊 ID(gid / groupId)
|
|
307
|
+
* @param content 消息内容文本
|
|
308
|
+
* @param atUserIds 需要 @ 的用户 ID 列表(可为空)
|
|
309
|
+
* @param log 日志接口
|
|
310
|
+
* @param _deprecatedMsgId 已废弃的占位消息 ID 参数,不再使用(保留以兼容旧调用签名)
|
|
311
|
+
* @param reply 可选的被回复消息信息(用于在 IM 中建立“回复某条消息”的关联)
|
|
312
|
+
*/
|
|
313
|
+
export async function sendTextMessage(config, token, groupId, content, atUserIds = [], log, _deprecatedMsgId, reply) {
|
|
314
|
+
const text = stripModelUsageFooter(stripMediaDirectiveLines(content.trim()));
|
|
315
|
+
if (!text)
|
|
316
|
+
return;
|
|
317
|
+
await postImMessage(config, token, groupId, {
|
|
318
|
+
type: "RICH_TEXT",
|
|
319
|
+
text,
|
|
320
|
+
clientMsgId: generateClientMsgId(),
|
|
321
|
+
...(reply ? { reply } : {}),
|
|
322
|
+
}, atUserIds, log);
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=send-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-service.js","sourceRoot":"","sources":["../../../src/delivery/send-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EACH,mBAAmB,EACnB,kBAAkB,EAClB,8BAA8B,EAC9B,yBAAyB,EACzB,wBAAwB,E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AC,CAAC,CAAC,EAAE,CAAC;KAC9B,EACD,SAAS,EACT,GAAG,CACN,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-service.test.d.ts","sourceRoot":"","sources":["../../../src/delivery/send-service.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { extractSentMessageInfo, generateClientMsgId } from "./send-service.js";
|
|
4
|
+
describe("generateClientMsgId", () => {
|
|
5
|
+
it("is unique per call (distinct logical messages)", () => {
|
|
6
|
+
const a = generateClientMsgId();
|
|
7
|
+
const b = generateClientMsgId();
|
|
8
|
+
assert.notEqual(a, b);
|
|
9
|
+
assert.match(a, /^ocw_\d+_/);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe("extractSentMessageInfo", () => {
|
|
13
|
+
it("reads server id and echoed clientMsgId from real send response", () => {
|
|
14
|
+
const res = {
|
|
15
|
+
resultCode: 1,
|
|
16
|
+
resultMsg: null,
|
|
17
|
+
data: {
|
|
18
|
+
id: "2077657906769403905",
|
|
19
|
+
groupId: "2072518674467676162",
|
|
20
|
+
type: "TEXT",
|
|
21
|
+
text: "1",
|
|
22
|
+
clientMsgId: "temp_1784187222818_oe8fjl",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const info = extractSentMessageInfo(res);
|
|
26
|
+
assert.equal(info.serverMsgId, "2077657906769403905");
|
|
27
|
+
assert.equal(info.clientMsgId, "temp_1784187222818_oe8fjl");
|
|
28
|
+
});
|
|
29
|
+
it("coerces numeric id to string", () => {
|
|
30
|
+
const info = extractSentMessageInfo({ data: { id: 12345 } });
|
|
31
|
+
assert.equal(info.serverMsgId, "12345");
|
|
32
|
+
});
|
|
33
|
+
it("returns empty when data missing or malformed", () => {
|
|
34
|
+
assert.deepEqual(extractSentMessageInfo(null), {});
|
|
35
|
+
assert.deepEqual(extractSentMessageInfo({}), {});
|
|
36
|
+
assert.deepEqual(extractSentMessageInfo({ data: null }), {});
|
|
37
|
+
assert.deepEqual(extractSentMessageInfo({ data: "nope" }), {});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=send-service.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-service.test.js","sourceRoot":"","sources":["../../../src/delivery/send-service.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEhF,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,GAAG,mBAAmB,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,mBAAmB,EAAE,CAAC;QAChC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtB,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,gEAAgE,EAAE,GAAG,EAAE;QACtE,MAAM,GAAG,GAAG;YACR,UAAU,EAAE,CAAC;YACb,SAAS,EAAE,IAAI;YACf,IAAI,EAAE;gBACF,EAAE,EAAE,qBAAqB;gBACzB,OAAO,EAAE,qBAAqB;gBAC9B,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,GAAG;gBACT,WAAW,EAAE,2BAA2B;aAC3C;SACJ,CAAC;QACF,MAAM,IAAI,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC;QACtD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,2BAA2B,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACpC,MAAM,IAAI,GAAG,sBAAsB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACnD,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACjD,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7D,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** WS `displayText` 对 thinking 的上限(trim + 长度封顶,不做语义改写) */
|
|
2
|
+
export declare const WS_THINKING_DISPLAY_MAX = 2000;
|
|
3
|
+
/** `RUN_EVENT.data.summary`:IM 用其识别「同一条用户指令的输出位」内的 thinking 片段(非新聊天气泡) */
|
|
4
|
+
export declare const THINKING_WS_SUMMARY_HINT = "thinking";
|
|
5
|
+
/**
|
|
6
|
+
* 将 OpenClaw thinking 文本转为 WS displayText(trim + 长度封顶,不做语义改写)。
|
|
7
|
+
*/
|
|
8
|
+
export declare function clipThinkingForWsDisplay(text: string, max?: number): string;
|
|
9
|
+
/** 仅在裁剪后的 displayText 变化时发送,避免重复 WS。 */
|
|
10
|
+
export declare function resolveThinkingWsDisplayUpdate(lastDisplayed: string, thinkingText: string, max?: number): {
|
|
11
|
+
displayText: string;
|
|
12
|
+
changed: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 单段 thinking:`onReasoningStream` 只累积,块结束再发 **一条** WS。
|
|
16
|
+
* (不做 token 级流式拆分,避免 IM 侧出现多条「输出」。)
|
|
17
|
+
*/
|
|
18
|
+
export declare class ThinkingWsBuffer {
|
|
19
|
+
private buffer;
|
|
20
|
+
noteStream(text: string): void;
|
|
21
|
+
/** 取出当前缓冲并清空;无内容时返回 undefined。 */
|
|
22
|
+
take(): string | undefined;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=thinking-ws-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-ws-progress.d.ts","sourceRoot":"","sources":["../../../src/delivery/thinking-ws-progress.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C,0EAA0E;AAC1E,eAAO,MAAM,wBAAwB,aAAa,CAAC;AAEnD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAA0B,GAAG,MAAM,CAK5F;AAED,wCAAwC;AACxC,wBAAgB,8BAA8B,CAC1C,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,GAAG,SAA0B,GAC9B;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAK3C;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,MAAM,CAAM;IAEpB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK9B,kCAAkC;IAClC,IAAI,IAAI,MAAM,GAAG,SAAS;CAM7B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** WS `displayText` 对 thinking 的上限(trim + 长度封顶,不做语义改写) */
|
|
2
|
+
export const WS_THINKING_DISPLAY_MAX = 2000;
|
|
3
|
+
/** `RUN_EVENT.data.summary`:IM 用其识别「同一条用户指令的输出位」内的 thinking 片段(非新聊天气泡) */
|
|
4
|
+
export const THINKING_WS_SUMMARY_HINT = "thinking";
|
|
5
|
+
/**
|
|
6
|
+
* 将 OpenClaw thinking 文本转为 WS displayText(trim + 长度封顶,不做语义改写)。
|
|
7
|
+
*/
|
|
8
|
+
export function clipThinkingForWsDisplay(text, max = WS_THINKING_DISPLAY_MAX) {
|
|
9
|
+
const t = text.trim();
|
|
10
|
+
if (!t)
|
|
11
|
+
return "";
|
|
12
|
+
if (t.length <= max)
|
|
13
|
+
return t;
|
|
14
|
+
return `${t.slice(0, Math.max(0, max - 1))}…`;
|
|
15
|
+
}
|
|
16
|
+
/** 仅在裁剪后的 displayText 变化时发送,避免重复 WS。 */
|
|
17
|
+
export function resolveThinkingWsDisplayUpdate(lastDisplayed, thinkingText, max = WS_THINKING_DISPLAY_MAX) {
|
|
18
|
+
const displayText = clipThinkingForWsDisplay(thinkingText, max);
|
|
19
|
+
if (!displayText)
|
|
20
|
+
return { displayText: "", changed: false };
|
|
21
|
+
if (displayText === lastDisplayed)
|
|
22
|
+
return { displayText, changed: false };
|
|
23
|
+
return { displayText, changed: true };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 单段 thinking:`onReasoningStream` 只累积,块结束再发 **一条** WS。
|
|
27
|
+
* (不做 token 级流式拆分,避免 IM 侧出现多条「输出」。)
|
|
28
|
+
*/
|
|
29
|
+
export class ThinkingWsBuffer {
|
|
30
|
+
buffer = "";
|
|
31
|
+
noteStream(text) {
|
|
32
|
+
const t = text.trim();
|
|
33
|
+
if (t)
|
|
34
|
+
this.buffer = t;
|
|
35
|
+
}
|
|
36
|
+
/** 取出当前缓冲并清空;无内容时返回 undefined。 */
|
|
37
|
+
take() {
|
|
38
|
+
const t = this.buffer.trim();
|
|
39
|
+
this.buffer = "";
|
|
40
|
+
if (!t)
|
|
41
|
+
return undefined;
|
|
42
|
+
return t;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=thinking-ws-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-ws-progress.js","sourceRoot":"","sources":["../../../src/delivery/thinking-ws-progress.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAEnD;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY,EAAE,GAAG,GAAG,uBAAuB;IAChF,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAClB,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAClD,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,8BAA8B,CAC1C,aAAqB,EACrB,YAAoB,EACpB,GAAG,GAAG,uBAAuB;IAE7B,MAAM,WAAW,GAAG,wBAAwB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IAChE,IAAI,CAAC,WAAW;QAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7D,IAAI,WAAW,KAAK,aAAa;QAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1E,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACjB,MAAM,GAAG,EAAE,CAAC;IAEpB,UAAU,CAAC,IAAY;QACnB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC;YAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,kCAAkC;IAClC,IAAI;QACA,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,CAAC;YAAE,OAAO,SAAS,CAAC;QACzB,OAAO,CAAC,CAAC;IACb,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-ws-progress.test.d.ts","sourceRoot":"","sources":["../../../src/delivery/thinking-ws-progress.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { clipThinkingForWsDisplay, resolveThinkingWsDisplayUpdate, ThinkingWsBuffer, } from "./thinking-ws-progress.js";
|
|
4
|
+
describe("thinking ws progress", () => {
|
|
5
|
+
it("clipThinkingForWsDisplay trims without rewriting", () => {
|
|
6
|
+
assert.equal(clipThinkingForWsDisplay(" hello "), "hello");
|
|
7
|
+
});
|
|
8
|
+
it("clipThinkingForWsDisplay caps length", () => {
|
|
9
|
+
const long = "a".repeat(100);
|
|
10
|
+
assert.equal(clipThinkingForWsDisplay(long, 10), `${"a".repeat(9)}…`);
|
|
11
|
+
});
|
|
12
|
+
it("resolveThinkingWsDisplayUpdate dedupes unchanged clipped text", () => {
|
|
13
|
+
const first = resolveThinkingWsDisplayUpdate("", "same text");
|
|
14
|
+
assert.equal(first.changed, true);
|
|
15
|
+
const second = resolveThinkingWsDisplayUpdate(first.displayText, "same text");
|
|
16
|
+
assert.equal(second.changed, false);
|
|
17
|
+
});
|
|
18
|
+
it("resolveThinkingWsDisplayUpdate emits when thinking grows", () => {
|
|
19
|
+
const first = resolveThinkingWsDisplayUpdate("", "step one");
|
|
20
|
+
const second = resolveThinkingWsDisplayUpdate(first.displayText, "step one and two");
|
|
21
|
+
assert.equal(second.changed, true);
|
|
22
|
+
assert.equal(second.displayText, "step one and two");
|
|
23
|
+
});
|
|
24
|
+
it("ThinkingWsBuffer keeps latest stream chunk until take", () => {
|
|
25
|
+
const buf = new ThinkingWsBuffer();
|
|
26
|
+
buf.noteStream("short");
|
|
27
|
+
buf.noteStream("short longer");
|
|
28
|
+
buf.noteStream("short longer final");
|
|
29
|
+
assert.equal(buf.take(), "short longer final");
|
|
30
|
+
assert.equal(buf.take(), undefined);
|
|
31
|
+
});
|
|
32
|
+
it("ThinkingWsBuffer ignores empty stream chunks", () => {
|
|
33
|
+
const buf = new ThinkingWsBuffer();
|
|
34
|
+
buf.noteStream(" ");
|
|
35
|
+
assert.equal(buf.take(), undefined);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=thinking-ws-progress.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-ws-progress.test.js","sourceRoot":"","sources":["../../../src/delivery/thinking-ws-progress.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACH,wBAAwB,EACxB,8BAA8B,EAC9B,gBAAgB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC;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AG,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAC/C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACpD,MAAM,GAAG,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACnC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACtB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一轮 dispatch 内的 assistant 正文段缓冲:
|
|
3
|
+
* - 同段修稿(新文延展/包住旧文)→ 覆盖
|
|
4
|
+
* - 流式分块新段 → 追加合并
|
|
5
|
+
* 在 tool 边界或轮次结束冲刷 HTTP。
|
|
6
|
+
*/
|
|
7
|
+
import type { ReplyDeliverPayload } from "./send-service.js";
|
|
8
|
+
export type DeliverFlushKind = "interim" | "final";
|
|
9
|
+
export type BufferedDeliverEntry = {
|
|
10
|
+
payload: ReplyDeliverPayload;
|
|
11
|
+
textPart: string;
|
|
12
|
+
rawTextPart: string;
|
|
13
|
+
hasMedia: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type TurnDeliverBufferStats = {
|
|
16
|
+
writeCount: number;
|
|
17
|
+
/** write 时判定为修稿并覆盖 */
|
|
18
|
+
revisionOverwriteCount: number;
|
|
19
|
+
/** write 时判定为新段并追加 */
|
|
20
|
+
segmentAppendCount: number;
|
|
21
|
+
flushInterimCount: number;
|
|
22
|
+
flushFinalCount: number;
|
|
23
|
+
skippedDuplicateFlushCount: number;
|
|
24
|
+
};
|
|
25
|
+
export type TakeForFlushResult = {
|
|
26
|
+
status: "empty";
|
|
27
|
+
} | {
|
|
28
|
+
status: "skipped_duplicate";
|
|
29
|
+
entry: BufferedDeliverEntry;
|
|
30
|
+
} | {
|
|
31
|
+
status: "ready";
|
|
32
|
+
entry: BufferedDeliverEntry;
|
|
33
|
+
};
|
|
34
|
+
/** deliver 正文/附件是否值得写入 buffer 或立即 HTTP。 */
|
|
35
|
+
export declare function isDeliverPayloadSendable(args: {
|
|
36
|
+
textPart: string;
|
|
37
|
+
hasMedia: boolean;
|
|
38
|
+
isThinking?: boolean;
|
|
39
|
+
}): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 新文是否像对旧文的「修稿/延展」(可安全覆盖),而非另一完整分块。
|
|
42
|
+
* 无权威 OpenClaw 标记,偏保守:宁可追加重复,不可覆盖丢段。
|
|
43
|
+
*/
|
|
44
|
+
export declare function isDeliverTextRevision(oldText: string, newText: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 段边界 / 轮末 flush 时,判断是否可用 `onPartialReply` 全量快照覆盖 deliver 拼接文本。
|
|
47
|
+
* 仅当快照(归一化后)与缓冲文本相等或为其超集时才覆盖,避免流式竞态下快照落后导致截断丢内容。
|
|
48
|
+
*/
|
|
49
|
+
export declare function snapshotSupersedesBufferText(snapshot: string, bufferText: string): boolean;
|
|
50
|
+
export declare class TurnDeliverBuffer {
|
|
51
|
+
private buffer;
|
|
52
|
+
private lastFlushedComparable;
|
|
53
|
+
private readonly stats;
|
|
54
|
+
hasContent(): boolean;
|
|
55
|
+
getStats(): TurnDeliverBufferStats;
|
|
56
|
+
write(entry: BufferedDeliverEntry): void;
|
|
57
|
+
takeForFlush(kind: DeliverFlushKind): TakeForFlushResult;
|
|
58
|
+
clear(): void;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=turn-deliver-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-deliver-buffer.d.ts","sourceRoot":"","sources":["../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