Skip to content

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

Merged
gene9831 merged 9 commits into
opentiny:developfrom
xuanlid:feat/sender-content-source
Aug 6, 2026
Merged

feat(sender):content source registration mechanism#382
gene9831 merged 9 commits into
opentiny:developfrom
xuanlid:feat/sender-content-source

Conversation

@xuanlid

@xuanlid xuanlid commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

背景

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-check
  • pnpm -F @opentiny/tiny-robot build

Summary by CodeRabbit

  • New Features

    • Added support for submitting multiple attachments through Sender.
    • Successful attachments are included automatically in submission details, while uploading or failed files are excluded.
    • Added attachment previews, selection controls, status handling, and post-submission cleanup.
    • Submission events can now include optional external attachment metadata.
  • Documentation

    • Updated Sender guidance and examples for attachment uploads.
    • Deprecated the previous external-content configuration in favor of placing attachments inside Sender.
  • Tests

    • Expanded coverage for attachment submission, status filtering, cleanup, and external payload details.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The PR adds a centralized Sender content registry. TrAttachments registers successful attachments, and Sender includes them in optional submit metadata. It updates public types, tests, documentation, and Sender demos.

Changes

Attachments submission flow

Layer / File(s) Summary
Attachment and submission contracts
packages/components/src/sender/types/submit-extra.ts, packages/components/src/sender/index.type.ts, packages/components/src/sender/composables/useSenderContentRegistry.ts, packages/components/src/shared/composables/*, packages/components/src/index.ts, packages/components/src/sender/index.ts
Defines external payload and submit-extra types, registration contracts, dependency-injection helpers, and public exports.
Registry and Sender integration
packages/components/src/sender/composables/useSenderContentRegistry.ts, packages/components/src/sender/composables/useSenderCore.ts, packages/components/src/attachments/index.vue
Tracks registered content, registers successful attachments, removes registrations during unmount, and emits collected payloads during submission.
Sender attachment test coverage
packages/test/src/sender/*
Adds attachment-source controls, submit-detail output, test helpers, selectors, and coverage for successful, uploading, and error attachment states.
Demos and usage documentation
docs/demos/sender/*, docs/src/components/sender.md
Adds an attachment-in-Sender demo, simplifies the enhanced-actions demo, and documents attachment registration and submit metadata.

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
Loading

Possibly related PRs

  • opentiny/tiny-robot#375: Directly evolves the Sender external-content handling used by the same demos, documentation, core logic, and tests.

Suggested reviewers: sonyleo, gene9831

Poem

A rabbit packs files in a Sender so neat,
The registry gathers each payload complete.
Successful ones hop into metadata bright,
Empty ones vanish from submit’s sight.
Tests guard the trail from source to flight.

🚥 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a Sender content source registration mechanism.
✨ 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/useSenderContentRegistry.ts Outdated
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

@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 `@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

📥 Commits

Reviewing files that changed from the base of the PR and between e84f845 and 32055b4.

📒 Files selected for processing (17)
  • docs/demos/sender/attachments-in-sender.vue
  • docs/src/components/attachments.md
  • docs/src/components/sender.md
  • 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/components/src/shared/composables/index.ts
  • packages/components/src/shared/composables/useSenderContentRegistration.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
💤 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

Comment thread packages/components/src/shared/composables/useSenderContentRegistration.ts Outdated
Comment thread packages/components/src/sender/composables/useSenderContentRegistry.ts Outdated
Comment thread packages/components/src/sender/composables/useSenderContentRegistry.ts Outdated
Comment thread packages/components/src/sender/composables/useSenderContentRegistry.ts Outdated
Comment thread packages/components/src/sender/types/submit-meta.ts Outdated
Comment thread packages/components/src/sender/composables/useSenderContentRegistry.ts Outdated
Comment thread packages/components/src/sender/types/submit-meta.ts Outdated
Comment thread packages/components/src/sender/composables/useSenderContentRegistry.ts Outdated
Comment thread packages/components/src/attachments/index.vue Outdated
Comment thread packages/components/src/sender/index.ts Outdated
Comment thread packages/components/src/index.ts Outdated
Comment thread packages/components/src/sender/composables/useSenderContentRegistry.ts Outdated
Comment thread packages/components/src/sender/index.type.ts
@gene9831
gene9831 merged commit ca51f9d into opentiny:develop Aug 6, 2026
4 checks passed
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🧹 Preview Cleaned Up

The preview deployment has been removed.

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.

3 participants