@larksuite/openclaw-lark 2025.7.15-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/bin/openclaw-lark.js +39 -0
- package/index.d.ts +36 -0
- package/index.js +188 -0
- package/openclaw.plugin.json +64 -0
- package/package.json +63 -0
- package/secret-contract-api.d.ts +15 -0
- package/secret-contract-api.js +78 -0
- package/skills/feishu-bitable/SKILL.md +248 -0
- package/skills/feishu-bitable/references/examples.md +813 -0
- package/skills/feishu-bitable/references/field-properties.md +763 -0
- package/skills/feishu-bitable/references/record-values.md +911 -0
- package/skills/feishu-calendar/SKILL.md +242 -0
- package/skills/feishu-channel-rules/SKILL.md +18 -0
- package/skills/feishu-channel-rules/references/markdown-syntax.md +138 -0
- package/skills/feishu-create-doc/SKILL.md +719 -0
- package/skills/feishu-fetch-doc/SKILL.md +93 -0
- package/skills/feishu-im-read/SKILL.md +163 -0
- package/skills/feishu-task/SKILL.md +340 -0
- package/skills/feishu-troubleshoot/SKILL.md +70 -0
- package/skills/feishu-update-doc/SKILL.md +285 -0
- package/src/card/builder.d.ts +152 -0
- package/src/card/builder.js +794 -0
- package/src/card/card-error.d.ts +91 -0
- package/src/card/card-error.js +206 -0
- package/src/card/cardkit.d.ts +90 -0
- package/src/card/cardkit.js +203 -0
- package/src/card/flush-controller.d.ts +45 -0
- package/src/card/flush-controller.js +138 -0
- package/src/card/image-resolver.d.ts +45 -0
- package/src/card/image-resolver.js +116 -0
- package/src/card/markdown-style.d.ts +16 -0
- package/src/card/markdown-style.js +106 -0
- package/src/card/reasoning-utils.d.ts +14 -0
- package/src/card/reasoning-utils.js +64 -0
- package/src/card/reply-dispatcher-types.d.ts +132 -0
- package/src/card/reply-dispatcher-types.js +61 -0
- package/src/card/reply-dispatcher.d.ts +15 -0
- package/src/card/reply-dispatcher.js +447 -0
- package/src/card/reply-mode.d.ts +41 -0
- package/src/card/reply-mode.js +70 -0
- package/src/card/streaming-card-controller.d.ts +118 -0
- package/src/card/streaming-card-controller.js +1045 -0
- package/src/card/tool-use-config.d.ts +26 -0
- package/src/card/tool-use-config.js +76 -0
- package/src/card/tool-use-display.d.ts +37 -0
- package/src/card/tool-use-display.js +476 -0
- package/src/card/tool-use-trace-store.d.ts +51 -0
- package/src/card/tool-use-trace-store.js +271 -0
- package/src/card/unavailable-guard.d.ts +35 -0
- package/src/card/unavailable-guard.js +87 -0
- package/src/channel/abort-detect.d.ts +47 -0
- package/src/channel/abort-detect.js +219 -0
- package/src/channel/chat-queue.d.ts +41 -0
- package/src/channel/chat-queue.js +68 -0
- package/src/channel/config-adapter.d.ts +23 -0
- package/src/channel/config-adapter.js +107 -0
- package/src/channel/directory.d.ts +57 -0
- package/src/channel/directory.js +197 -0
- package/src/channel/event-handlers.d.ts +17 -0
- package/src/channel/event-handlers.js +380 -0
- package/src/channel/interactive-dispatch.d.ts +59 -0
- package/src/channel/interactive-dispatch.js +195 -0
- package/src/channel/monitor.d.ts +17 -0
- package/src/channel/monitor.js +140 -0
- package/src/channel/onboarding-config.d.ts +18 -0
- package/src/channel/onboarding-config.js +96 -0
- package/src/channel/onboarding-migrate.d.ts +25 -0
- package/src/channel/onboarding-migrate.js +70 -0
- package/src/channel/onboarding.d.ts +12 -0
- package/src/channel/onboarding.js +300 -0
- package/src/channel/plugin.d.ts +13 -0
- package/src/channel/plugin.js +310 -0
- package/src/channel/probe.d.ts +14 -0
- package/src/channel/probe.js +24 -0
- package/src/channel/types.d.ts +37 -0
- package/src/channel/types.js +8 -0
- package/src/commands/auth.d.ts +21 -0
- package/src/commands/auth.js +165 -0
- package/src/commands/diagnose.d.ts +69 -0
- package/src/commands/diagnose.js +848 -0
- package/src/commands/doctor.d.ts +27 -0
- package/src/commands/doctor.js +588 -0
- package/src/commands/index.d.ts +25 -0
- package/src/commands/index.js +219 -0
- package/src/commands/locale.d.ts +7 -0
- package/src/commands/locale.js +8 -0
- package/src/core/accounts.d.ts +51 -0
- package/src/core/accounts.js +219 -0
- package/src/core/agent-config.d.ts +100 -0
- package/src/core/agent-config.js +148 -0
- package/src/core/api-error.d.ts +48 -0
- package/src/core/api-error.js +117 -0
- package/src/core/app-owner-fallback.d.ts +22 -0
- package/src/core/app-owner-fallback.js +39 -0
- package/src/core/app-scope-checker.d.ts +87 -0
- package/src/core/app-scope-checker.js +198 -0
- package/src/core/auth-errors.d.ts +144 -0
- package/src/core/auth-errors.js +160 -0
- package/src/core/card-action-operator.d.ts +33 -0
- package/src/core/card-action-operator.js +30 -0
- package/src/core/chat-info-cache.d.ts +67 -0
- package/src/core/chat-info-cache.js +165 -0
- package/src/core/comment-target.d.ts +65 -0
- package/src/core/comment-target.js +100 -0
- package/src/core/config-schema.d.ts +490 -0
- package/src/core/config-schema.js +223 -0
- package/src/core/device-flow.d.ts +77 -0
- package/src/core/device-flow.js +217 -0
- package/src/core/domains.d.ts +18 -0
- package/src/core/domains.js +34 -0
- package/src/core/feishu-fetch.d.ts +18 -0
- package/src/core/feishu-fetch.js +28 -0
- package/src/core/footer-config.d.ts +24 -0
- package/src/core/footer-config.js +51 -0
- package/src/core/lark-client.d.ts +125 -0
- package/src/core/lark-client.js +468 -0
- package/src/core/lark-logger.d.ts +23 -0
- package/src/core/lark-logger.js +160 -0
- package/src/core/lark-ticket.d.ts +29 -0
- package/src/core/lark-ticket.js +40 -0
- package/src/core/message-unavailable.d.ts +53 -0
- package/src/core/message-unavailable.js +142 -0
- package/src/core/owner-policy.d.ts +32 -0
- package/src/core/owner-policy.js +55 -0
- package/src/core/permission-url.d.ts +22 -0
- package/src/core/permission-url.js +76 -0
- package/src/core/raw-request.d.ts +27 -0
- package/src/core/raw-request.js +90 -0
- package/src/core/runtime-store.d.ts +13 -0
- package/src/core/runtime-store.js +29 -0
- package/src/core/scope-manager.d.ts +168 -0
- package/src/core/scope-manager.js +224 -0
- package/src/core/sdk-compat.d.ts +20 -0
- package/src/core/sdk-compat.js +28 -0
- package/src/core/security-check.d.ts +72 -0
- package/src/core/security-check.js +184 -0
- package/src/core/shutdown-hooks.d.ts +22 -0
- package/src/core/shutdown-hooks.js +61 -0
- package/src/core/synthetic-target.d.ts +33 -0
- package/src/core/synthetic-target.js +40 -0
- package/src/core/targets.d.ts +60 -0
- package/src/core/targets.js +173 -0
- package/src/core/token-store.d.ts +54 -0
- package/src/core/token-store.js +326 -0
- package/src/core/tool-client.d.ts +176 -0
- package/src/core/tool-client.js +426 -0
- package/src/core/tool-scopes.d.ts +156 -0
- package/src/core/tool-scopes.js +344 -0
- package/src/core/tools-config.d.ts +55 -0
- package/src/core/tools-config.js +143 -0
- package/src/core/types.d.ts +91 -0
- package/src/core/types.js +12 -0
- package/src/core/uat-client.d.ts +46 -0
- package/src/core/uat-client.js +192 -0
- package/src/core/version.d.ts +31 -0
- package/src/core/version.js +69 -0
- package/src/messaging/converters/audio.d.ts +8 -0
- package/src/messaging/converters/audio.js +24 -0
- package/src/messaging/converters/calendar.d.ts +13 -0
- package/src/messaging/converters/calendar.js +56 -0
- package/src/messaging/converters/content-converter-helpers.d.ts +30 -0
- package/src/messaging/converters/content-converter-helpers.js +82 -0
- package/src/messaging/converters/content-converter.d.ts +24 -0
- package/src/messaging/converters/content-converter.js +40 -0
- package/src/messaging/converters/file.d.ts +8 -0
- package/src/messaging/converters/file.js +24 -0
- package/src/messaging/converters/folder.d.ts +8 -0
- package/src/messaging/converters/folder.js +24 -0
- package/src/messaging/converters/hongbao.d.ts +8 -0
- package/src/messaging/converters/hongbao.js +20 -0
- package/src/messaging/converters/image.d.ts +8 -0
- package/src/messaging/converters/image.js +22 -0
- package/src/messaging/converters/index.d.ts +8 -0
- package/src/messaging/converters/index.js +53 -0
- package/src/messaging/converters/interactive/card-converter.d.ts +76 -0
- package/src/messaging/converters/interactive/card-converter.js +1177 -0
- package/src/messaging/converters/interactive/card-utils.d.ts +9 -0
- package/src/messaging/converters/interactive/card-utils.js +47 -0
- package/src/messaging/converters/interactive/index.d.ts +8 -0
- package/src/messaging/converters/interactive/index.js +25 -0
- package/src/messaging/converters/interactive/legacy.d.ts +11 -0
- package/src/messaging/converters/interactive/legacy.js +60 -0
- package/src/messaging/converters/interactive/types.d.ts +23 -0
- package/src/messaging/converters/interactive/types.js +27 -0
- package/src/messaging/converters/location.d.ts +8 -0
- package/src/messaging/converters/location.js +23 -0
- package/src/messaging/converters/merge-forward.d.ts +32 -0
- package/src/messaging/converters/merge-forward.js +235 -0
- package/src/messaging/converters/post.d.ts +11 -0
- package/src/messaging/converters/post.js +235 -0
- package/src/messaging/converters/share.d.ts +9 -0
- package/src/messaging/converters/share.js +28 -0
- package/src/messaging/converters/sticker.d.ts +8 -0
- package/src/messaging/converters/sticker.js +22 -0
- package/src/messaging/converters/system.d.ts +12 -0
- package/src/messaging/converters/system.js +36 -0
- package/src/messaging/converters/text.d.ts +8 -0
- package/src/messaging/converters/text.js +18 -0
- package/src/messaging/converters/todo.d.ts +8 -0
- package/src/messaging/converters/todo.js +45 -0
- package/src/messaging/converters/types.d.ts +114 -0
- package/src/messaging/converters/types.js +8 -0
- package/src/messaging/converters/unknown.d.ts +8 -0
- package/src/messaging/converters/unknown.js +20 -0
- package/src/messaging/converters/utils.d.ts +22 -0
- package/src/messaging/converters/utils.js +57 -0
- package/src/messaging/converters/video-chat.d.ts +8 -0
- package/src/messaging/converters/video-chat.js +31 -0
- package/src/messaging/converters/video.d.ts +8 -0
- package/src/messaging/converters/video.js +35 -0
- package/src/messaging/converters/vote.d.ts +8 -0
- package/src/messaging/converters/vote.js +28 -0
- package/src/messaging/inbound/bot-content.d.ts +84 -0
- package/src/messaging/inbound/bot-content.js +117 -0
- package/src/messaging/inbound/bot-loop-guard.d.ts +48 -0
- package/src/messaging/inbound/bot-loop-guard.js +89 -0
- package/src/messaging/inbound/comment-context.d.ts +82 -0
- package/src/messaging/inbound/comment-context.js +353 -0
- package/src/messaging/inbound/comment-handler.d.ts +30 -0
- package/src/messaging/inbound/comment-handler.js +269 -0
- package/src/messaging/inbound/dedup.d.ts +59 -0
- package/src/messaging/inbound/dedup.js +121 -0
- package/src/messaging/inbound/dispatch-builders.d.ts +104 -0
- package/src/messaging/inbound/dispatch-builders.js +241 -0
- package/src/messaging/inbound/dispatch-commands.d.ts +22 -0
- package/src/messaging/inbound/dispatch-commands.js +131 -0
- package/src/messaging/inbound/dispatch-context.d.ts +67 -0
- package/src/messaging/inbound/dispatch-context.js +153 -0
- package/src/messaging/inbound/dispatch.d.ts +50 -0
- package/src/messaging/inbound/dispatch.js +477 -0
- package/src/messaging/inbound/enrich.d.ts +102 -0
- package/src/messaging/inbound/enrich.js +236 -0
- package/src/messaging/inbound/gate-effects.d.ts +23 -0
- package/src/messaging/inbound/gate-effects.js +46 -0
- package/src/messaging/inbound/gate.d.ts +91 -0
- package/src/messaging/inbound/gate.js +342 -0
- package/src/messaging/inbound/handler-registry.d.ts +25 -0
- package/src/messaging/inbound/handler-registry.js +23 -0
- package/src/messaging/inbound/handler.d.ts +37 -0
- package/src/messaging/inbound/handler.js +286 -0
- package/src/messaging/inbound/media-resolver.d.ts +32 -0
- package/src/messaging/inbound/media-resolver.js +91 -0
- package/src/messaging/inbound/mention-registry.d.ts +59 -0
- package/src/messaging/inbound/mention-registry.js +115 -0
- package/src/messaging/inbound/mention.d.ts +48 -0
- package/src/messaging/inbound/mention.js +102 -0
- package/src/messaging/inbound/parse-io.d.ts +50 -0
- package/src/messaging/inbound/parse-io.js +86 -0
- package/src/messaging/inbound/parse.d.ts +28 -0
- package/src/messaging/inbound/parse.js +128 -0
- package/src/messaging/inbound/permission.d.ts +17 -0
- package/src/messaging/inbound/permission.js +44 -0
- package/src/messaging/inbound/policy.d.ts +95 -0
- package/src/messaging/inbound/policy.js +168 -0
- package/src/messaging/inbound/reaction-handler.d.ts +62 -0
- package/src/messaging/inbound/reaction-handler.js +259 -0
- package/src/messaging/inbound/sentinel-store.d.ts +37 -0
- package/src/messaging/inbound/sentinel-store.js +98 -0
- package/src/messaging/inbound/synthetic-message.d.ts +26 -0
- package/src/messaging/inbound/synthetic-message.js +59 -0
- package/src/messaging/inbound/user-name-cache-store.d.ts +62 -0
- package/src/messaging/inbound/user-name-cache-store.js +236 -0
- package/src/messaging/inbound/user-name-cache.d.ts +78 -0
- package/src/messaging/inbound/user-name-cache.js +306 -0
- package/src/messaging/inbound/vc-meeting-invited-handler.d.ts +20 -0
- package/src/messaging/inbound/vc-meeting-invited-handler.js +236 -0
- package/src/messaging/inbound/vc-sender.d.ts +41 -0
- package/src/messaging/inbound/vc-sender.js +53 -0
- package/src/messaging/outbound/actions.d.ts +16 -0
- package/src/messaging/outbound/actions.js +329 -0
- package/src/messaging/outbound/bot-peer-context.d.ts +42 -0
- package/src/messaging/outbound/bot-peer-context.js +40 -0
- package/src/messaging/outbound/chat-manage.d.ts +64 -0
- package/src/messaging/outbound/chat-manage.js +117 -0
- package/src/messaging/outbound/deliver.d.ts +186 -0
- package/src/messaging/outbound/deliver.js +410 -0
- package/src/messaging/outbound/fetch.d.ts +12 -0
- package/src/messaging/outbound/fetch.js +17 -0
- package/src/messaging/outbound/forward.d.ts +26 -0
- package/src/messaging/outbound/forward.js +51 -0
- package/src/messaging/outbound/media-url-utils.d.ts +29 -0
- package/src/messaging/outbound/media-url-utils.js +172 -0
- package/src/messaging/outbound/media.d.ts +260 -0
- package/src/messaging/outbound/media.js +865 -0
- package/src/messaging/outbound/normalize-mentions.d.ts +50 -0
- package/src/messaging/outbound/normalize-mentions.js +166 -0
- package/src/messaging/outbound/outbound-mention.d.ts +41 -0
- package/src/messaging/outbound/outbound-mention.js +112 -0
- package/src/messaging/outbound/outbound.d.ts +79 -0
- package/src/messaging/outbound/outbound.js +195 -0
- package/src/messaging/outbound/reactions.d.ts +124 -0
- package/src/messaging/outbound/reactions.js +384 -0
- package/src/messaging/outbound/send.d.ts +153 -0
- package/src/messaging/outbound/send.js +417 -0
- package/src/messaging/outbound/typing.d.ts +60 -0
- package/src/messaging/outbound/typing.js +139 -0
- package/src/messaging/shared/message-lookup.d.ts +54 -0
- package/src/messaging/shared/message-lookup.js +120 -0
- package/src/messaging/types.d.ts +316 -0
- package/src/messaging/types.js +11 -0
- package/src/tools/ask-user-question.d.ts +32 -0
- package/src/tools/ask-user-question.js +922 -0
- package/src/tools/auto-auth.d.ts +57 -0
- package/src/tools/auto-auth.js +904 -0
- package/src/tools/helpers.d.ts +264 -0
- package/src/tools/helpers.js +389 -0
- package/src/tools/mcp/doc/create.d.ts +12 -0
- package/src/tools/mcp/doc/create.js +47 -0
- package/src/tools/mcp/doc/fetch.d.ts +12 -0
- package/src/tools/mcp/doc/fetch.js +39 -0
- package/src/tools/mcp/doc/index.d.ts +12 -0
- package/src/tools/mcp/doc/index.js +50 -0
- package/src/tools/mcp/doc/update.d.ts +12 -0
- package/src/tools/mcp/doc/update.js +64 -0
- package/src/tools/mcp/shared.d.ts +59 -0
- package/src/tools/mcp/shared.js +239 -0
- package/src/tools/oapi/bitable/app-table-field.d.ts +16 -0
- package/src/tools/oapi/bitable/app-table-field.js +225 -0
- package/src/tools/oapi/bitable/app-table-record.d.ts +20 -0
- package/src/tools/oapi/bitable/app-table-record.js +439 -0
- package/src/tools/oapi/bitable/app-table-view.d.ts +16 -0
- package/src/tools/oapi/bitable/app-table-view.js +172 -0
- package/src/tools/oapi/bitable/app-table.d.ts +17 -0
- package/src/tools/oapi/bitable/app-table.js +195 -0
- package/src/tools/oapi/bitable/app.d.ts +18 -0
- package/src/tools/oapi/bitable/app.js +189 -0
- package/src/tools/oapi/bitable/index.d.ts +9 -0
- package/src/tools/oapi/bitable/index.js +17 -0
- package/src/tools/oapi/calendar/calendar.d.ts +15 -0
- package/src/tools/oapi/calendar/calendar.js +125 -0
- package/src/tools/oapi/calendar/event-attendee.d.ts +14 -0
- package/src/tools/oapi/calendar/event-attendee.js +161 -0
- package/src/tools/oapi/calendar/event.d.ts +16 -0
- package/src/tools/oapi/calendar/event.js +712 -0
- package/src/tools/oapi/calendar/freebusy.d.ts +13 -0
- package/src/tools/oapi/calendar/freebusy.js +114 -0
- package/src/tools/oapi/calendar/index.d.ts +8 -0
- package/src/tools/oapi/calendar/index.js +15 -0
- package/src/tools/oapi/chat/chat.d.ts +16 -0
- package/src/tools/oapi/chat/chat.js +127 -0
- package/src/tools/oapi/chat/index.d.ts +10 -0
- package/src/tools/oapi/chat/index.js +23 -0
- package/src/tools/oapi/chat/members.d.ts +11 -0
- package/src/tools/oapi/chat/members.js +84 -0
- package/src/tools/oapi/common/get-user.d.ts +12 -0
- package/src/tools/oapi/common/get-user.js +109 -0
- package/src/tools/oapi/common/index.d.ts +6 -0
- package/src/tools/oapi/common/index.js +11 -0
- package/src/tools/oapi/common/search-user.d.ts +11 -0
- package/src/tools/oapi/common/search-user.js +76 -0
- package/src/tools/oapi/drive/doc-comments.d.ts +15 -0
- package/src/tools/oapi/drive/doc-comments.js +351 -0
- package/src/tools/oapi/drive/doc-media.d.ts +19 -0
- package/src/tools/oapi/drive/doc-media.js +371 -0
- package/src/tools/oapi/drive/file.d.ts +19 -0
- package/src/tools/oapi/drive/file.js +519 -0
- package/src/tools/oapi/drive/index.d.ts +12 -0
- package/src/tools/oapi/drive/index.js +45 -0
- package/src/tools/oapi/helpers.d.ts +183 -0
- package/src/tools/oapi/helpers.js +385 -0
- package/src/tools/oapi/im/format-messages.d.ts +50 -0
- package/src/tools/oapi/im/format-messages.js +169 -0
- package/src/tools/oapi/im/index.d.ts +10 -0
- package/src/tools/oapi/im/index.js +25 -0
- package/src/tools/oapi/im/message-read.d.ts +13 -0
- package/src/tools/oapi/im/message-read.js +419 -0
- package/src/tools/oapi/im/message.d.ts +16 -0
- package/src/tools/oapi/im/message.js +152 -0
- package/src/tools/oapi/im/resource.d.ts +13 -0
- package/src/tools/oapi/im/resource.js +186 -0
- package/src/tools/oapi/im/time-utils.d.ts +46 -0
- package/src/tools/oapi/im/time-utils.js +212 -0
- package/src/tools/oapi/im/user-name-uat.d.ts +26 -0
- package/src/tools/oapi/im/user-name-uat.js +143 -0
- package/src/tools/oapi/index.d.ts +11 -0
- package/src/tools/oapi/index.js +64 -0
- package/src/tools/oapi/sdk-types.d.ts +96 -0
- package/src/tools/oapi/sdk-types.js +13 -0
- package/src/tools/oapi/search/doc-search.d.ts +13 -0
- package/src/tools/oapi/search/doc-search.js +194 -0
- package/src/tools/oapi/search/index.d.ts +12 -0
- package/src/tools/oapi/search/index.js +37 -0
- package/src/tools/oapi/sheets/index.d.ts +12 -0
- package/src/tools/oapi/sheets/index.js +35 -0
- package/src/tools/oapi/sheets/sheet.d.ts +16 -0
- package/src/tools/oapi/sheets/sheet.js +688 -0
- package/src/tools/oapi/task/attachment.d.ts +18 -0
- package/src/tools/oapi/task/attachment.js +107 -0
- package/src/tools/oapi/task/comment.d.ts +15 -0
- package/src/tools/oapi/task/comment.js +149 -0
- package/src/tools/oapi/task/index.d.ts +11 -0
- package/src/tools/oapi/task/index.js +21 -0
- package/src/tools/oapi/task/section.d.ts +17 -0
- package/src/tools/oapi/task/section.js +293 -0
- package/src/tools/oapi/task/subtask.d.ts +14 -0
- package/src/tools/oapi/task/subtask.js +171 -0
- package/src/tools/oapi/task/task.d.ts +19 -0
- package/src/tools/oapi/task/task.js +512 -0
- package/src/tools/oapi/task/task_agent.d.ts +14 -0
- package/src/tools/oapi/task/task_agent.js +108 -0
- package/src/tools/oapi/task/tasklist.d.ts +19 -0
- package/src/tools/oapi/task/tasklist.js +276 -0
- package/src/tools/oapi/wiki/index.d.ts +12 -0
- package/src/tools/oapi/wiki/index.js +42 -0
- package/src/tools/oapi/wiki/space-node.d.ts +17 -0
- package/src/tools/oapi/wiki/space-node.js +233 -0
- package/src/tools/oapi/wiki/space.d.ts +15 -0
- package/src/tools/oapi/wiki/space.js +133 -0
- package/src/tools/oauth-batch-auth.d.ts +11 -0
- package/src/tools/oauth-batch-auth.js +150 -0
- package/src/tools/oauth-cards.d.ts +39 -0
- package/src/tools/oauth-cards.js +324 -0
- package/src/tools/oauth.d.ts +47 -0
- package/src/tools/oauth.js +592 -0
- package/src/tools/onboarding-auth.d.ts +27 -0
- package/src/tools/onboarding-auth.js +133 -0
- package/src/tools/tat/im/index.d.ts +15 -0
- package/src/tools/tat/im/index.js +22 -0
- package/src/tools/tat/im/resource.d.ts +15 -0
- package/src/tools/tat/im/resource.js +192 -0
- package/tsdown.config.d.ts +2 -0
- package/tsdown.config.js +25 -0
- package/vitest.config.d.ts +2 -0
- package/vitest.config.js +12 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Utility functions for card content conversion.
|
|
6
|
+
*/
|
|
7
|
+
export declare function escapeAttr(s: string): string;
|
|
8
|
+
export declare function formatMillisecondsToISO8601(milliseconds: string): string;
|
|
9
|
+
export declare function normalizeTimeFormat(input: string): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Utility functions for card content conversion.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.escapeAttr = escapeAttr;
|
|
10
|
+
exports.formatMillisecondsToISO8601 = formatMillisecondsToISO8601;
|
|
11
|
+
exports.normalizeTimeFormat = normalizeTimeFormat;
|
|
12
|
+
function escapeAttr(s) {
|
|
13
|
+
return s.replace(/"/g, '\\"').replace(/\n/g, '\\n');
|
|
14
|
+
}
|
|
15
|
+
function formatMillisecondsToISO8601(milliseconds) {
|
|
16
|
+
const ms = parseInt(milliseconds, 10);
|
|
17
|
+
if (isNaN(ms))
|
|
18
|
+
return '';
|
|
19
|
+
return new Date(ms).toISOString();
|
|
20
|
+
}
|
|
21
|
+
function normalizeTimeFormat(input) {
|
|
22
|
+
if (!input)
|
|
23
|
+
return '';
|
|
24
|
+
const num = parseInt(input, 10);
|
|
25
|
+
if (!isNaN(num) && String(num) === input.trim()) {
|
|
26
|
+
if (input.length >= 13) {
|
|
27
|
+
return new Date(num).toISOString();
|
|
28
|
+
}
|
|
29
|
+
else if (input.length >= 10) {
|
|
30
|
+
return new Date(num * 1000).toISOString();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(input)) {
|
|
34
|
+
return input;
|
|
35
|
+
}
|
|
36
|
+
const dtMatch = /^(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}(?::\d{2})?)$/.exec(input);
|
|
37
|
+
if (dtMatch) {
|
|
38
|
+
const d = new Date(`${dtMatch[1]}T${dtMatch[2]}`);
|
|
39
|
+
if (!isNaN(d.getTime()))
|
|
40
|
+
return d.toISOString();
|
|
41
|
+
}
|
|
42
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(input))
|
|
43
|
+
return input;
|
|
44
|
+
if (/^\d{2}:\d{2}(:\d{2})?$/.test(input))
|
|
45
|
+
return input;
|
|
46
|
+
return input;
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Entry point for the interactive (card) message converter.
|
|
6
|
+
*/
|
|
7
|
+
import type { ContentConverterFn } from '../types';
|
|
8
|
+
export declare const convertInteractive: ContentConverterFn;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Entry point for the interactive (card) message converter.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.convertInteractive = void 0;
|
|
10
|
+
const utils_1 = require("../utils.js");
|
|
11
|
+
const card_converter_1 = require("./card-converter.js");
|
|
12
|
+
const legacy_1 = require("./legacy.js");
|
|
13
|
+
const convertInteractive = (raw) => {
|
|
14
|
+
const parsed = (0, utils_1.safeParse)(raw);
|
|
15
|
+
if (!parsed) {
|
|
16
|
+
return { content: '[interactive card]', resources: [] };
|
|
17
|
+
}
|
|
18
|
+
if (typeof parsed.json_card === 'string') {
|
|
19
|
+
const converter = new card_converter_1.CardConverter(card_converter_1.MODE.Concise);
|
|
20
|
+
const result = converter.convert(parsed);
|
|
21
|
+
return { content: result.content || '[interactive card]', resources: [] };
|
|
22
|
+
}
|
|
23
|
+
return (0, legacy_1.convertLegacyCard)(parsed);
|
|
24
|
+
};
|
|
25
|
+
exports.convertInteractive = convertInteractive;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Legacy card converter for non-raw_card_content format.
|
|
6
|
+
*/
|
|
7
|
+
import type { Obj } from './types';
|
|
8
|
+
export declare function convertLegacyCard(parsed: Obj): {
|
|
9
|
+
content: string;
|
|
10
|
+
resources: never[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Legacy card converter for non-raw_card_content format.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.convertLegacyCard = convertLegacyCard;
|
|
10
|
+
function convertLegacyCard(parsed) {
|
|
11
|
+
const texts = [];
|
|
12
|
+
const header = parsed.header;
|
|
13
|
+
if (header) {
|
|
14
|
+
const title = header.title;
|
|
15
|
+
if (title && typeof title.content === 'string') {
|
|
16
|
+
texts.push(`**${title.content}**`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const body = parsed.body;
|
|
20
|
+
const elements = (parsed.elements ?? body?.elements ?? []);
|
|
21
|
+
extractTexts(elements, texts);
|
|
22
|
+
const content = texts.length > 0 ? texts.join('\n') : '[interactive card]';
|
|
23
|
+
return { content, resources: [] };
|
|
24
|
+
}
|
|
25
|
+
function extractTexts(elements, out) {
|
|
26
|
+
if (!Array.isArray(elements))
|
|
27
|
+
return;
|
|
28
|
+
for (const el of elements) {
|
|
29
|
+
if (typeof el !== 'object' || el == null)
|
|
30
|
+
continue;
|
|
31
|
+
const elem = el;
|
|
32
|
+
if (elem.tag === 'markdown' && typeof elem.content === 'string') {
|
|
33
|
+
out.push(elem.content);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (elem.tag === 'div' || elem.tag === 'plain_text' || elem.tag === 'lark_md') {
|
|
37
|
+
const text = elem.text;
|
|
38
|
+
if (text?.content && typeof text.content === 'string') {
|
|
39
|
+
out.push(text.content);
|
|
40
|
+
}
|
|
41
|
+
if (typeof elem.content === 'string') {
|
|
42
|
+
out.push(elem.content);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (elem.tag === 'column_set') {
|
|
46
|
+
const columns = elem.columns;
|
|
47
|
+
if (columns) {
|
|
48
|
+
for (const col of columns) {
|
|
49
|
+
const colObj = col;
|
|
50
|
+
if (colObj.elements) {
|
|
51
|
+
extractTexts(colObj.elements, out);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (elem.elements) {
|
|
57
|
+
extractTexts(elem.elements, out);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Types and constants for the interactive (card) converter.
|
|
6
|
+
*/
|
|
7
|
+
export type Obj = Record<string, unknown>;
|
|
8
|
+
export interface RawCardContent {
|
|
9
|
+
json_card: string;
|
|
10
|
+
json_attachment?: string;
|
|
11
|
+
card_schema?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ConvertCardResult {
|
|
14
|
+
content: string;
|
|
15
|
+
schema: number;
|
|
16
|
+
}
|
|
17
|
+
export interface TextStyle {
|
|
18
|
+
bold: boolean;
|
|
19
|
+
italic: boolean;
|
|
20
|
+
strikethrough: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const EMOJI_MAP: Record<string, string>;
|
|
23
|
+
export declare const CHART_TYPE_NAMES: Record<string, string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Types and constants for the interactive (card) converter.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CHART_TYPE_NAMES = exports.EMOJI_MAP = void 0;
|
|
10
|
+
exports.EMOJI_MAP = {
|
|
11
|
+
OK: '👌',
|
|
12
|
+
THUMBSUP: '👍',
|
|
13
|
+
SMILE: '😊',
|
|
14
|
+
HEART: '❤️',
|
|
15
|
+
CLAP: '👏',
|
|
16
|
+
FIRE: '🔥',
|
|
17
|
+
PARTY: '🎉',
|
|
18
|
+
THINK: '🤔',
|
|
19
|
+
};
|
|
20
|
+
exports.CHART_TYPE_NAMES = {
|
|
21
|
+
bar: '柱状图',
|
|
22
|
+
line: '折线图',
|
|
23
|
+
pie: '饼图',
|
|
24
|
+
area: '面积图',
|
|
25
|
+
radar: '雷达图',
|
|
26
|
+
scatter: '散点图',
|
|
27
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Converter for "location" message type.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.convertLocation = void 0;
|
|
10
|
+
const utils_1 = require("./utils.js");
|
|
11
|
+
const convertLocation = (raw) => {
|
|
12
|
+
const parsed = (0, utils_1.safeParse)(raw);
|
|
13
|
+
const name = parsed?.name ?? '';
|
|
14
|
+
const lat = parsed?.latitude ?? '';
|
|
15
|
+
const lng = parsed?.longitude ?? '';
|
|
16
|
+
const nameAttr = name ? ` name="${name}"` : '';
|
|
17
|
+
const coordsAttr = lat && lng ? ` coords="lat:${lat},lng:${lng}"` : '';
|
|
18
|
+
return {
|
|
19
|
+
content: `<location${nameAttr}${coordsAttr}/>`,
|
|
20
|
+
resources: [],
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.convertLocation = convertLocation;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Converter for "merge_forward" message type.
|
|
6
|
+
*
|
|
7
|
+
* Unlike other converters this is async — it fetches sub-messages via
|
|
8
|
+
* the Feishu IM API and recursively expands nested merge_forward messages.
|
|
9
|
+
*
|
|
10
|
+
* The API returns ALL nested sub-messages in a single flat `items`
|
|
11
|
+
* array with `upper_message_id` pointing to the parent container.
|
|
12
|
+
* We build a tree from this flat list and recursively format it —
|
|
13
|
+
* only one API call is needed regardless of nesting depth.
|
|
14
|
+
*
|
|
15
|
+
* This module is a pure "data → format" converter: all API capabilities
|
|
16
|
+
* (`fetchSubMessages`, `batchResolveNames`, `resolveUserName`) are
|
|
17
|
+
* injected via callbacks in `ConvertContext`. Callers are responsible
|
|
18
|
+
* for creating the appropriate callbacks (UAT / TAT / event push).
|
|
19
|
+
*/
|
|
20
|
+
import type { ContentConverterFn } from './types';
|
|
21
|
+
/**
|
|
22
|
+
* Recursively expand a merge_forward message.
|
|
23
|
+
*
|
|
24
|
+
* Output format aligns with the Go reference implementation:
|
|
25
|
+
* ```
|
|
26
|
+
* <forwarded_messages>
|
|
27
|
+
* [RFC3339] sender_id:
|
|
28
|
+
* message content
|
|
29
|
+
* </forwarded_messages>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const convertMergeForward: ContentConverterFn;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Converter for "merge_forward" message type.
|
|
7
|
+
*
|
|
8
|
+
* Unlike other converters this is async — it fetches sub-messages via
|
|
9
|
+
* the Feishu IM API and recursively expands nested merge_forward messages.
|
|
10
|
+
*
|
|
11
|
+
* The API returns ALL nested sub-messages in a single flat `items`
|
|
12
|
+
* array with `upper_message_id` pointing to the parent container.
|
|
13
|
+
* We build a tree from this flat list and recursively format it —
|
|
14
|
+
* only one API call is needed regardless of nesting depth.
|
|
15
|
+
*
|
|
16
|
+
* This module is a pure "data → format" converter: all API capabilities
|
|
17
|
+
* (`fetchSubMessages`, `batchResolveNames`, `resolveUserName`) are
|
|
18
|
+
* injected via callbacks in `ConvertContext`. Callers are responsible
|
|
19
|
+
* for creating the appropriate callbacks (UAT / TAT / event push).
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.convertMergeForward = void 0;
|
|
23
|
+
const lark_logger_1 = require("../../core/lark-logger.js");
|
|
24
|
+
const content_converter_helpers_1 = require("./content-converter-helpers.js");
|
|
25
|
+
const log = (0, lark_logger_1.larkLogger)('converters/merge-forward');
|
|
26
|
+
/**
|
|
27
|
+
* Recursively expand a merge_forward message.
|
|
28
|
+
*
|
|
29
|
+
* Output format aligns with the Go reference implementation:
|
|
30
|
+
* ```
|
|
31
|
+
* <forwarded_messages>
|
|
32
|
+
* [RFC3339] sender_id:
|
|
33
|
+
* message content
|
|
34
|
+
* </forwarded_messages>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const convertMergeForward = async (_raw, ctx) => {
|
|
38
|
+
const { accountId, messageId, resolveUserName, batchResolveNames, fetchSubMessages, convertMessageContent } = ctx;
|
|
39
|
+
if (!fetchSubMessages) {
|
|
40
|
+
return { content: '<forwarded_messages/>', resources: [] };
|
|
41
|
+
}
|
|
42
|
+
const content = await expand(accountId, messageId, resolveUserName, batchResolveNames, fetchSubMessages, convertMessageContent);
|
|
43
|
+
return { content, resources: [] };
|
|
44
|
+
};
|
|
45
|
+
exports.convertMergeForward = convertMergeForward;
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Single-API-call expansion with tree building
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
async function expand(accountId, messageId, resolveUserName, batchResolveNames, fetchSubMessages, convertContent) {
|
|
50
|
+
// --- Phase 1: Fetch (single API call via callback) ---
|
|
51
|
+
let items;
|
|
52
|
+
try {
|
|
53
|
+
items = await fetchSubMessages(messageId);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
log.error('fetch sub-messages failed', {
|
|
57
|
+
messageId,
|
|
58
|
+
error: error instanceof Error ? error.message : String(error),
|
|
59
|
+
});
|
|
60
|
+
return '<forwarded_messages/>';
|
|
61
|
+
}
|
|
62
|
+
if (items.length === 0) {
|
|
63
|
+
return '<forwarded_messages/>';
|
|
64
|
+
}
|
|
65
|
+
// --- Phase 2: Build children map ---
|
|
66
|
+
const childrenMap = buildChildrenMap(items, messageId);
|
|
67
|
+
// --- Phase 2.5: Batch resolve sender names (via callback) ---
|
|
68
|
+
const senderIds = collectSenderIds(items, messageId);
|
|
69
|
+
if (senderIds.length > 0 && batchResolveNames) {
|
|
70
|
+
try {
|
|
71
|
+
await batchResolveNames(senderIds);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
log.debug('batchResolveNames failed (best-effort)', {
|
|
75
|
+
error: err instanceof Error ? err.message : String(err),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// --- Phase 3: Format tree recursively ---
|
|
80
|
+
return formatSubTree(messageId, childrenMap, accountId, resolveUserName, convertContent);
|
|
81
|
+
}
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Tree building
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
/**
|
|
86
|
+
* Build a map from parent message ID → ordered child items.
|
|
87
|
+
*
|
|
88
|
+
* The API returns a flat `items` array where each item may carry an
|
|
89
|
+
* `upper_message_id` pointing to its parent container. Items without
|
|
90
|
+
* `upper_message_id` are direct children of the root container.
|
|
91
|
+
*
|
|
92
|
+
* The root container message itself (matching `rootMessageId`) is skipped.
|
|
93
|
+
*/
|
|
94
|
+
function buildChildrenMap(items, rootMessageId) {
|
|
95
|
+
const map = new Map();
|
|
96
|
+
for (const item of items) {
|
|
97
|
+
// Skip the root container message itself
|
|
98
|
+
if (item.message_id === rootMessageId && !item.upper_message_id) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const parentId = item.upper_message_id ?? rootMessageId;
|
|
102
|
+
let children = map.get(parentId);
|
|
103
|
+
if (!children) {
|
|
104
|
+
children = [];
|
|
105
|
+
map.set(parentId, children);
|
|
106
|
+
}
|
|
107
|
+
children.push(item);
|
|
108
|
+
}
|
|
109
|
+
// Sort each group by create_time ascending
|
|
110
|
+
for (const children of map.values()) {
|
|
111
|
+
children.sort((a, b) => {
|
|
112
|
+
const ta = parseInt(String(a.create_time ?? '0'), 10);
|
|
113
|
+
const tb = parseInt(String(b.create_time ?? '0'), 10);
|
|
114
|
+
return ta - tb;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return map;
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Sender ID collection
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
/**
|
|
123
|
+
* Collect all unique sender IDs from non-root items for batch name resolution.
|
|
124
|
+
*/
|
|
125
|
+
function collectSenderIds(items, rootMessageId) {
|
|
126
|
+
const ids = new Set();
|
|
127
|
+
for (const item of items) {
|
|
128
|
+
// Skip the root container
|
|
129
|
+
if (item.message_id === rootMessageId && !item.upper_message_id) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (item.sender?.sender_type === 'user') {
|
|
133
|
+
const senderId = item.sender.id;
|
|
134
|
+
if (senderId) {
|
|
135
|
+
ids.add(senderId);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return [...ids];
|
|
140
|
+
}
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// Recursive tree formatting
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
/**
|
|
145
|
+
* Recursively format a sub-tree of messages rooted at `parentId`.
|
|
146
|
+
*
|
|
147
|
+
* For `merge_forward` children this recurses into `formatSubTree`
|
|
148
|
+
* directly (no additional API calls). For other message types it
|
|
149
|
+
* delegates to `convertMessageContent`.
|
|
150
|
+
*/
|
|
151
|
+
async function formatSubTree(parentId, childrenMap, accountId, resolveUserName, convertContent) {
|
|
152
|
+
const children = childrenMap.get(parentId);
|
|
153
|
+
if (!children || children.length === 0) {
|
|
154
|
+
return '<forwarded_messages/>';
|
|
155
|
+
}
|
|
156
|
+
const parts = [];
|
|
157
|
+
for (const item of children) {
|
|
158
|
+
try {
|
|
159
|
+
const msgType = item.msg_type ?? 'text';
|
|
160
|
+
const senderId = item.sender?.id ?? 'unknown';
|
|
161
|
+
const createTime = item.create_time ? parseInt(String(item.create_time), 10) : undefined;
|
|
162
|
+
const timestamp = createTime ? formatTimestamp(createTime) : 'unknown';
|
|
163
|
+
const rawContent = item.body?.content ?? '{}';
|
|
164
|
+
let content;
|
|
165
|
+
if (msgType === 'merge_forward') {
|
|
166
|
+
// Recurse into nested merge_forward via the tree — no API call
|
|
167
|
+
const nestedId = item.message_id;
|
|
168
|
+
if (nestedId) {
|
|
169
|
+
content = await formatSubTree(nestedId, childrenMap, accountId, resolveUserName, convertContent);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
content = '<forwarded_messages/>';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// Delegate to the unified converter system.
|
|
177
|
+
// Do NOT pass cfg/account here — sub-converters for non-merge_forward
|
|
178
|
+
// types don't need it, and passing it would cause nested
|
|
179
|
+
// merge_forward to re-enter expand() via convertMessageContent.
|
|
180
|
+
const subCtx = {
|
|
181
|
+
...(0, content_converter_helpers_1.buildConvertContextFromItem)(item, parentId, accountId),
|
|
182
|
+
accountId,
|
|
183
|
+
resolveUserName,
|
|
184
|
+
convertMessageContent: convertContent,
|
|
185
|
+
};
|
|
186
|
+
if (!convertContent) {
|
|
187
|
+
content = rawContent;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
content = (await convertContent(rawContent, msgType, subCtx)).content;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const displayName = resolveUserName?.(senderId) ?? senderId;
|
|
194
|
+
const indented = indentLines(content, ' ');
|
|
195
|
+
parts.push(`[${timestamp}] ${displayName}:\n${indented}`);
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
log.warn('failed to convert sub-message', {
|
|
199
|
+
messageId: item.message_id,
|
|
200
|
+
msgType: item.msg_type ?? 'unknown',
|
|
201
|
+
error: err instanceof Error ? err.message : String(err),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (parts.length === 0) {
|
|
206
|
+
return '<forwarded_messages/>';
|
|
207
|
+
}
|
|
208
|
+
return `<forwarded_messages>\n${parts.join('\n')}\n</forwarded_messages>`;
|
|
209
|
+
}
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Helpers
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
/**
|
|
214
|
+
* Convert a millisecond timestamp to RFC 3339 format with +08:00 offset
|
|
215
|
+
* (Beijing time).
|
|
216
|
+
*/
|
|
217
|
+
function formatTimestamp(ms) {
|
|
218
|
+
const date = new Date(ms);
|
|
219
|
+
const utcMs = date.getTime() + date.getTimezoneOffset() * 60_000;
|
|
220
|
+
const bjDate = new Date(utcMs + 8 * 3600_000);
|
|
221
|
+
const y = bjDate.getFullYear();
|
|
222
|
+
const mo = String(bjDate.getMonth() + 1).padStart(2, '0');
|
|
223
|
+
const d = String(bjDate.getDate()).padStart(2, '0');
|
|
224
|
+
const h = String(bjDate.getHours()).padStart(2, '0');
|
|
225
|
+
const mi = String(bjDate.getMinutes()).padStart(2, '0');
|
|
226
|
+
const s = String(bjDate.getSeconds()).padStart(2, '0');
|
|
227
|
+
return `${y}-${mo}-${d}T${h}:${mi}:${s}+08:00`;
|
|
228
|
+
}
|
|
229
|
+
/** Add a prefix indent to every line of text. */
|
|
230
|
+
function indentLines(text, indent) {
|
|
231
|
+
return text
|
|
232
|
+
.split('\n')
|
|
233
|
+
.map((line) => `${indent}${line}`)
|
|
234
|
+
.join('\n');
|
|
235
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Converter for "post" (rich text) message type.
|
|
6
|
+
*
|
|
7
|
+
* Preserves structure as Markdown: links as `[text](href)`,
|
|
8
|
+
* images as ``, code blocks, and mention resolution.
|
|
9
|
+
*/
|
|
10
|
+
import type { ContentConverterFn } from './types';
|
|
11
|
+
export declare const convertPost: ContentConverterFn;
|