Skip to content

feat(sender):content source registration mechanism - #382

Open
xuanlid wants to merge 3 commits into
opentiny:developfrom
xuanlid:feat/sender-content-source
Open

feat(sender):content source registration mechanism#382
xuanlid wants to merge 3 commits into
opentiny:developfrom
xuanlid:feat/sender-content-source

Conversation

@xuanlid

@xuanlid xuanlid commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

变更说明

Sender 增加内容注册机制,使 TrAttachments 可以作为 Sender 的外部提交内容参与可提交状态判断,并在提交时通过 meta.externalPayloads 返回附件数据。

主要改动

  • Sender 新增 useSenderContentRegistry,用于管理已注册的外部内容,并在提交时收集 payload。
  • TrAttachments 新增 contentSourceId,当上层容器提供附件注册上下文时,会自动注册当前附件列表。
  • Sender 内置附件注册 provider,支持在 Sender 内直接使用 TrAttachments 完成附件提交。
  • submit 事件新增可选第三个参数 SenderSubmitMeta;无外部 payload 时仍保持原有两个参数,兼容旧用法。
  • hasExternalContent 保持兼容可用,但仅用于控制提交状态,不会生成 externalPayloads
  • 新增 attachments-in-sender demo,展示 Sender 内附件列表和附件随消息提交。
  • 简化 actions-enhanced demo,避免继续用增强按钮示例承载附件提交语义。
  • 更新 Sender / Attachments 文档,补充附件提交、contentSourceIdhasExternalContent 兼容说明。
  • 补充 Sender e2e 用例,覆盖附件提交、卸载取消注册、附件为空、contentSourceId 变化等场景。

测试

  • 已补充 packages/test/src/sender/specs/basic.spec.ts 中的 Sender 附件提交相关用例。
  • 已执行 pnpm type-check

Summary by CodeRabbit

New Features

  • Sender can include registered attachments in submission metadata.
  • Submission details now identify attachment sources and included files.
  • Added support for registering and collecting content from multiple sources.
  • Added a demo for submitting text with multiple file attachments.

Documentation

  • Updated attachment and Sender guidance with registration, submission metadata, and type information.

Bug Fixes

  • Improved cleanup when attachment sources change or are removed.
  • Attachment selections now provide clearer submission and status feedback.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds attachment registration and external payload submission to Sender. It exposes related APIs and types, documents usage, adds an attachment demo, simplifies an existing demo, and expands Sender tests for attachment lifecycle and submit metadata.

Changes

Attachments submission flow

Layer / File(s) Summary
Attachment and submission contracts
packages/components/src/attachments/*, packages/components/src/sender/types/*, packages/components/src/*/index*
Defines attachment registration, external payload, submit metadata, and public exports.
Registry and Sender integration
packages/components/src/attachments/index.vue, packages/components/src/sender/composables/*
Registers attachment sources through Vue context, tracks available content, collects payloads, and emits submit metadata.
Demos and usage documentation
docs/demos/sender/*, docs/src/components/attachments.md, docs/src/components/sender.md
Adds attachment submission examples, documents contentSourceId and payload metadata, and simplifies the enhanced-actions demo.
Sender attachment test coverage
packages/test/src/sender/*
Adds attachment controls, submit-detail reporting, selectors, and tests for payloads, unregistering, empty items, and source ID changes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TrAttachments
  participant Sender
  participant useSenderContentRegistry
  TrAttachments->>Sender: register content source
  Sender->>useSenderContentRegistry: store registration
  Sender->>useSenderContentRegistry: collectExternalPayloads()
  useSenderContentRegistry-->>Sender: externalPayloads
  Sender-->>TrAttachments: submit(text, data, meta)
Loading

Possibly related PRs

Suggested reviewers: gene9831

Poem

A rabbit packed attachments tight,
Source IDs stayed clear and bright.
Sender gathered each payload,
Tests checked every submit way.
“Hop!” said Bun, “the flow is right!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a content source registration mechanism for Sender.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7648e33 and 2fda17e.

📒 Files selected for processing (19)
  • docs/demos/sender/actions-enhanced.vue
  • docs/demos/sender/attachments-in-sender.vue
  • docs/src/components/attachments.md
  • docs/src/components/sender.md
  • packages/components/src/attachments/context.ts
  • packages/components/src/attachments/index.ts
  • packages/components/src/attachments/index.type.ts
  • packages/components/src/attachments/index.vue
  • packages/components/src/index.ts
  • packages/components/src/sender/composables/index.ts
  • packages/components/src/sender/composables/useSenderContentRegistry.ts
  • packages/components/src/sender/composables/useSenderCore.ts
  • packages/components/src/sender/index.ts
  • packages/components/src/sender/index.type.ts
  • packages/components/src/sender/types/submit-meta.ts
  • packages/test/src/sender/helpers/index.ts
  • packages/test/src/sender/index.vue
  • packages/test/src/sender/selectors.ts
  • packages/test/src/sender/specs/basic.spec.ts

Comment thread docs/demos/sender/actions-enhanced.vue Outdated
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

✅ Preview build completed successfully!

Click the image above to preview.
Preview will be automatically removed when this PR is closed.

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Comment thread packages/components/src/sender/composables/useSenderCore.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/test/src/sender/specs/attachments.spec.ts (1)

16-35: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover 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 mounted TrAttachments updates Sender submit state when an attachment changes from success to uploading or error.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2fda17e and e84f845.

📒 Files selected for processing (5)
  • docs/demos/sender/actions-enhanced.vue
  • packages/components/src/attachments/index.vue
  • packages/test/src/sender/helpers/index.ts
  • packages/test/src/sender/index.vue
  • packages/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants