Skip to content

feat: add public answer sharing#3306

Open
LittleChenLiya wants to merge 5 commits into
bytedance:mainfrom
LittleChenLiya:fix/issue-3288-share-answer
Open

feat: add public answer sharing#3306
LittleChenLiya wants to merge 5 commits into
bytedance:mainfrom
LittleChenLiya:fix/issue-3288-share-answer

Conversation

@LittleChenLiya
Copy link
Copy Markdown
Collaborator

@LittleChenLiya LittleChenLiya commented May 28, 2026

问题原因

当前聊天回答只能在登录后的原会话中查看,用户无法把某个问答片段生成可公开访问的只读链接。

修改内容

  • 新增分享快照接口:登录用户可从有权限的 thread 中按消息 ID 创建公开分享,公开读取仅开放 GET /api/shares/{share_id}
  • 在助手回答操作区增加分享按钮,生成并复制 /share/{share_id} 链接。
  • 新增公开只读分享页,免登录展示已分享的问答快照。

关联 issue

Closes #3288

Problem Cause

Chat answers can currently only be viewed from the authenticated source conversation, so users cannot create a public read-only link for a selected Q&A snippet.

Changes

  • Add share snapshot APIs: authenticated users can create a public share from an authorized thread by message ID, while anonymous access is limited to GET /api/shares/{share_id}.
  • Add a share action to assistant answer controls that creates and copies a /share/{share_id} link.
  • Add a public read-only share page that displays the shared Q&A snapshot without login.

Related Issue

Closes #3288

@LittleChenLiya LittleChenLiya requested a review from Copilot May 28, 2026 12:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a “public share” feature for conversation threads, including backend endpoints to create/read immutable share snapshots and a frontend UI flow to generate and copy share links, plus tests and auth middleware updates to allow anonymous share reads.

Changes:

  • Backend: introduce /api/shares router (create share from owned thread; public read by share id) and update auth middleware to allow anonymous GETs for share reads.
  • Frontend: add createThreadShare API + types, add share button in MessageList, and add a new /share/[share_id] page for public viewing.
  • Tests: add backend router/auth middleware tests and a frontend unit test for the share create API.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
frontend/tests/unit/core/threads/api.test.ts Adds a unit test validating createThreadShare request payload.
frontend/src/core/threads/types.ts Introduces share response types used by the frontend.
frontend/src/core/threads/api.ts Adds createThreadShare API wrapper for creating a share.
frontend/src/components/workspace/messages/message-list.tsx Adds share action UI per assistant turn and supporting logic.
frontend/src/app/share/[share_id]/page.tsx New public share viewer page that loads and displays shared messages.
backend/tests/test_shares_router.py Adds coverage for share creation, validation, and public read behavior.
backend/tests/test_auth_middleware.py Adds coverage for anonymous share reads vs protected share creation.
backend/app/gateway/routers/shares.py Implements share create/read endpoints and snapshot persistence.
backend/app/gateway/routers/init.py Exposes the new shares router module.
backend/app/gateway/auth_middleware.py Adds method+path-based public-route detection for share reads.
backend/app/gateway/app.py Mounts the new shares router into the gateway app.

Comment thread backend/app/gateway/auth_middleware.py Outdated
Comment thread frontend/src/app/share/[share_id]/page.tsx
Comment thread frontend/src/components/workspace/messages/message-list.tsx
Comment thread frontend/src/core/threads/api.ts
Comment thread frontend/src/core/threads/api.ts
Comment thread frontend/src/components/workspace/messages/message-list.tsx Outdated
Comment thread backend/app/gateway/routers/shares.py
@LittleChenLiya LittleChenLiya requested a review from Copilot May 28, 2026 13:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Comment thread frontend/src/components/workspace/messages/message-list.tsx
Comment thread frontend/src/app/share/[share_id]/page.tsx
Comment thread backend/app/gateway/routers/shares.py
Comment thread backend/app/gateway/routers/shares.py
Comment thread backend/app/gateway/routers/shares.py Outdated
Comment thread backend/app/gateway/routers/shares.py Outdated
Comment thread backend/app/gateway/routers/shares.py Outdated
@LittleChenLiya LittleChenLiya requested a review from Copilot May 28, 2026 13:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Comment thread backend/app/gateway/routers/shares.py
Comment thread backend/app/gateway/routers/shares.py
Comment thread frontend/src/core/threads/api.ts Outdated
Comment thread frontend/src/app/share/[share_id]/page.tsx
@WillemJiang
Copy link
Copy Markdown
Collaborator

@LittleChenLiya, we cannot publicly share the thread without the owner's permission. How do we store this permission in the system?

@LittleChenLiya
Copy link
Copy Markdown
Collaborator Author

LittleChenLiya commented May 29, 2026

@WillemJiang

现在公开分享权限会作为内部分享元数据持久化,包括 source_thread_idcreated_by_user_id、选中的 message_idsvisibilitygranted_at。公开读取接口仍只返回不可变快照内容,不会通过 GET /api/shares/{share_id} 暴露这些授权元数据。

我也收紧了创建分享的权限边界:公开分享必须来自明确归当前用户所有的 thread,不再接受 legacy/null-owner thread 的宽松访问路径。同时新增 DELETE /api/shares/{share_id},创建者可以撤销公开链接;撤销后的链接返回 404,但内部会保留撤销记录。

验证:

  • uv run python -m pytest tests/test_shares_router.py tests/test_auth_middleware.py -v
  • uvx ruff check app/gateway/routers/shares.py tests/test_shares_router.py tests/test_auth_middleware.py
  • uvx ruff format --check app/gateway/routers/shares.py tests/test_shares_router.py tests/test_auth_middleware.py

Addressed in 903bcf9.

Public share permission is now persisted as internal share metadata, including source_thread_id, created_by_user_id, selected message_ids, visibility, and granted_at. Public reads still return only the immutable snapshot fields, so this authorization metadata is not exposed by GET /api/shares/{share_id}.

I also tightened the creation boundary: public shares must come from a thread explicitly owned by the current user, instead of accepting the legacy/null-owner access path. I added DELETE /api/shares/{share_id} so the creator can revoke a public link; revoked links return 404 while keeping the revocation record internally.

Validation:

  • uv run python -m pytest tests/test_shares_router.py tests/test_auth_middleware.py -v
  • uvx ruff check app/gateway/routers/shares.py tests/test_shares_router.py tests/test_auth_middleware.py
  • uvx ruff format --check app/gateway/routers/shares.py tests/test_shares_router.py tests/test_auth_middleware.py

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.

[Feature]增加回答分享功能

3 participants