feat(sender):content source registration mechanism - #382
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe PR adds a centralized Sender content registry. ChangesAttachments submission flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant TrAttachments
participant TrSender
participant ContentRegistry
TrAttachments->>TrSender: Register successful attachments
TrSender->>ContentRegistry: Store attachment payload
TrSender->>ContentRegistry: Collect external payloads
ContentRegistry-->>TrSender: Return externalPayloads
TrSender-->>TrAttachments: Emit submit event with extra metadata
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/demos/sender/actions-enhanced.vue`:
- Line 11: The feedback timers in docs/demos/sender/actions-enhanced.vue must
share one handle so newer messages are not cleared by older callbacks. In the
submit-message logic at lines 11-11, cancel the existing timer before scheduling
the new clear timeout; in the file-selection feedback at lines 16-16, use that
same timer handle.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e02e4910-d554-42c2-b391-156abd28121c
📒 Files selected for processing (19)
docs/demos/sender/actions-enhanced.vuedocs/demos/sender/attachments-in-sender.vuedocs/src/components/attachments.mddocs/src/components/sender.mdpackages/components/src/attachments/context.tspackages/components/src/attachments/index.tspackages/components/src/attachments/index.type.tspackages/components/src/attachments/index.vuepackages/components/src/index.tspackages/components/src/sender/composables/index.tspackages/components/src/sender/composables/useSenderContentRegistry.tspackages/components/src/sender/composables/useSenderCore.tspackages/components/src/sender/index.tspackages/components/src/sender/index.type.tspackages/components/src/sender/types/submit-meta.tspackages/test/src/sender/helpers/index.tspackages/test/src/sender/index.vuepackages/test/src/sender/selectors.tspackages/test/src/sender/specs/basic.spec.ts
📦 Package Previewpnpm add https://pkg.pr.new/@opentiny/tiny-robot@3886715 pnpm add https://pkg.pr.new/@opentiny/tiny-robot-kit@3886715 pnpm add https://pkg.pr.new/@opentiny/tiny-robot-svgs@3886715 commit: 3886715 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/test/src/sender/specs/attachments.spec.ts (1)
16-35: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover status changes after source registration.
The test sets the status before
toggleAttachmentsSource, so it only verifies the initial mount state. It does not verify that a mountedTrAttachmentsupdates Sender submit state when an attachment changes fromsuccesstouploadingorerror.Mount the source with a successful item first, then change its status and assert the submit state and metadata.
Suggested test adjustment
+ await helper.setSenderAttachmentStatus('success') await helper.toggleAttachmentsSource() + await helper.expectSubmitButtonVisible(true) + await helper.setSenderAttachmentStatus(status) await helper.expectSubmitButtonVisible(false)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/test/src/sender/specs/attachments.spec.ts` around lines 16 - 35, Update the test around setSenderAttachmentStatus, toggleAttachmentsSource, and submit assertions so the attachment source is registered while the item is successful, then transition it to uploading and error afterward. For each transition, assert the submit button is hidden and the submitted detail retains the text while exposing the expected attachment metadata behavior, verifying mounted TrAttachments reacts to status changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/test/src/sender/specs/attachments.spec.ts`:
- Around line 16-35: Update the test around setSenderAttachmentStatus,
toggleAttachmentsSource, and submit assertions so the attachment source is
registered while the item is successful, then transition it to uploading and
error afterward. For each transition, assert the submit button is hidden and the
submitted detail retains the text while exposing the expected attachment
metadata behavior, verifying mounted TrAttachments reacts to status changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5ef2f23f-ab36-41df-9193-99734e545f62
📒 Files selected for processing (5)
docs/demos/sender/actions-enhanced.vuepackages/components/src/attachments/index.vuepackages/test/src/sender/helpers/index.tspackages/test/src/sender/index.vuepackages/test/src/sender/specs/attachments.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/test/src/sender/helpers/index.ts
- packages/components/src/attachments/index.vue
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/components/src/shared/composables/useSenderContentRegistration.ts`:
- Around line 6-9: Update useSenderContentRegistration to return
SenderContentRegister | undefined and type the injected registerFn accordingly,
preserving the existing undefined fallback. In
packages/components/src/attachments/index.vue lines 68-70, remove the unsafe
cast and call the typed composable result directly.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c3a87fea-b248-43d5-bf21-4f53a4aac15f
📒 Files selected for processing (17)
docs/demos/sender/attachments-in-sender.vuedocs/src/components/attachments.mddocs/src/components/sender.mdpackages/components/src/attachments/index.vuepackages/components/src/index.tspackages/components/src/sender/composables/index.tspackages/components/src/sender/composables/useSenderContentRegistry.tspackages/components/src/sender/composables/useSenderCore.tspackages/components/src/sender/index.tspackages/components/src/sender/index.type.tspackages/components/src/sender/types/submit-meta.tspackages/components/src/shared/composables/index.tspackages/components/src/shared/composables/useSenderContentRegistration.tspackages/test/src/sender/helpers/index.tspackages/test/src/sender/index.vuepackages/test/src/sender/selectors.tspackages/test/src/sender/specs/basic.spec.ts
💤 Files with no reviewable changes (2)
- packages/test/src/sender/helpers/index.ts
- packages/test/src/sender/selectors.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- packages/components/src/sender/index.ts
- packages/components/src/sender/index.type.ts
- packages/test/src/sender/specs/basic.spec.ts
- packages/components/src/sender/composables/index.ts
- docs/src/components/sender.md
- packages/test/src/sender/index.vue
- docs/demos/sender/attachments-in-sender.vue
🧹 Preview Cleaned UpThe preview deployment has been removed. |

背景
Sender 目前主要围绕编辑器文本和结构化数据提交,附件这类外部内容需要额外处理。为了避免 Sender 内部继续耦合具体内容类型,本 PR 将外部内容提交能力抽象成统一机制。
核心改动
本 PR 为 Sender 增加了外部内容注册与提交机制。Sender 会通过上下文向内部子组件提供注册能力,子组件可以主动注册需要随 submit 一起提交的外部数据。
提交时,Sender 会统一收集已注册的外部内容,并通过第三个参数
extra.externalPayloads返回给业务侧。提交数据结构
外部内容统一使用
{ source: string, payload: unknown }结构。其中
source用于标识内容来源,payload保留注册方提供的原始数据。附件接入方式
Attachments 已接入这套注册机制。附件组件自身负责整理可提交的附件内容,Sender 只负责收集和透传。
因此 Sender 不再内置附件来源识别、附件状态过滤或附件 payload 适配逻辑。
收益
这次调整把 Sender 的提交能力扩展为:文本内容 + 结构化数据 + 外部注册内容。
后续图片、文件、工具结果等更多外部内容类型,都可以通过同一套注册机制接入,不需要继续修改 Sender 内部逻辑。
验证
pnpm -F @opentiny/tiny-robot type-checkpnpm -F @opentiny/tiny-robot buildSummary by CodeRabbit
New Features
Documentation
Tests