Skip to content

✨ feat(db): add agent share schema and model#15430

Closed
ONLY-yours wants to merge 7 commits into
canaryfrom
feat/agent-share-db
Closed

✨ feat(db): add agent share schema and model#15430
ONLY-yours wants to merge 7 commits into
canaryfrom
feat/agent-share-db

Conversation

@ONLY-yours

Copy link
Copy Markdown
Member

Summary

  • Add agent_shares table: one share per agent, shareConfig jsonb for all share settings (guestEnabled, maxGuestTopics, tipSplitRatio, filePermissionConfig, etc.)
  • Extend topics table with 3 columns: shareId, guestToken, visitorUserId
  • Add AgentShareModel with ownership-via-agents-join pattern; findByShareId returns creatorId from agents.userId
  • Guest 1-topic limit enforced by querying topics WHERE share_id=$x AND guest_token=$y AND trigger='share' — no dedicated table needed

Design decisions

No userId in agent_shares: creator identity derivable via agents.userId, no redundancy needed.

shareConfig jsonb not multiple columns: share config is extensible (upcoming: maxGuestTopics, allowReadMemory, accessControl). jsonb avoids repeated ALTER TABLE.

No FK on shareId in topics: share deletion must not cascade-delete conversations.

Test plan

  • AgentShareModel.create() — idempotent (unique constraint on agentId)
  • AgentShareModel.findByShareIdWithAccessCheck() — throws FORBIDDEN for private shares
  • Migration 0105_add_agent_share.sql applies cleanly

Linear: LOBE-9941

🤖 Generated with Claude Code

ONLY-yours and others added 3 commits June 3, 2026 16:01
- New `agent_shares` table: one share record per agent, stores visibility,
  guestEnabled, tipSplitRatio, and file-permission config
- Extend `topics` with shareId / guestToken / visitorUserId columns to
  support guest-originated conversations owned by the creator
- Add AgentShareModel with create/update/delete and public findByShareId
  helpers (mirrors TopicShareModel pattern)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…op userId/pageViewCount

- Remove userId (derivable via agent.userId), guestEnabled, tipSplitRatio,
  filePermissionConfig, pageViewCount from agent_shares
- Add shareConfig jsonb with AgentShareConfig interface covering all
  share settings (guestEnabled, maxGuestTopics, tipSplitRatio, etc.)
- Update AgentShareModel: ownership checks via agents join, findByShareId
  now returns creatorId from agents.userId, remove incrementPageViewCount
- Regenerate 0105 migration (clean diff against 0104 baseline)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Jun 3, 2026 12:32pm

Request Review

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 3, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26d66585d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/database/migrations/0105_add_agent_share.sql Outdated
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.18%. Comparing base (2eb9e34) to head (a860a36).
⚠️ Report is 7 commits behind head on canary.

❗ There is a different number of reports uploaded between BASE (2eb9e34) and HEAD (a860a36). Click for more details.

HEAD has 11 uploads less than BASE
Flag BASE (2eb9e34) HEAD (a860a36)
packages/utils 1 0
packages/python-interpreter 1 0
packages/context-engine 1 0
packages/agent-runtime 1 0
packages/conversation-flow 1 0
packages/ssrf-safe-fetch 1 0
packages/memory-user-memory 1 0
packages/types 1 0
packages/builtin-tool-lobe-agent 1 0
database 1 0
packages/model-bank 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15430      +/-   ##
==========================================
- Coverage   71.02%   64.18%   -6.84%     
==========================================
  Files        3212     2679     -533     
  Lines      321285   241619   -79666     
  Branches    29240    23781    -5459     
==========================================
- Hits       228179   155086   -73093     
+ Misses      92931    86415    -6516     
+ Partials      175      118      -57     
Flag Coverage Δ
app 61.84% <ø> (+<0.01%) ⬆️
database ?
packages/agent-runtime ?
packages/builtin-tool-lobe-agent ?
packages/context-engine ?
packages/conversation-flow ?
packages/file-loaders 87.89% <ø> (ø)
packages/memory-user-memory ?
packages/model-bank ?
packages/model-runtime 84.72% <ø> (ø)
packages/prompts 72.49% <ø> (ø)
packages/python-interpreter ?
packages/ssrf-safe-fetch ?
packages/types ?
packages/utils ?
packages/web-crawler 88.08% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 68.43% <ø> (ø)
Services 54.58% <ø> (ø)
Server 72.32% <ø> (+<0.01%) ⬆️
Libs 57.01% <ø> (ø)
Utils 81.44% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ONLY-yours and others added 3 commits June 3, 2026 18:06
… drop legacy share columns

- agent_shares: add userViewCount (UV), remove tipSplitRatio from AgentShareConfig
- topics: replace shareId/guestToken/visitorUserId with single senderId column;
  guest=UUID, post-login=userId, app layer overwrites on bind
- AgentShareModel: add incrementUserViewCount, expose userViewCount in findByShareId
- Regenerate 0105_add_agent_share migration (clean diff vs 0104)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wrap CREATE TABLE with IF NOT EXISTS, ALTER TABLE ADD COLUMN with
IF NOT EXISTS, FK constraints with DO $$ BEGIN...EXCEPTION WHEN
duplicate_object THEN NULL; END $$, and indexes with IF NOT EXISTS.
Mirrors pattern used in 0069_add_topic_shares_table.sql.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread packages/database/src/schemas/agentShare.ts Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
arvinxx added a commit that referenced this pull request Jun 3, 2026
Bring the agent-share schema layer over from #15430: new `agent_shares`
table + `topics.sender_id` column/index, schema relations and barrel
export. Migration renumbered to 0106 to sit after the usage column.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
arvinxx added a commit that referenced this pull request Jun 3, 2026
Bring the agent-share schema layer over from #15430: new `agent_shares`
table + `topics.sender_id` column/index, schema relations and barrel
export. Migration renumbered to 0106 to sit after the usage column.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
arvinxx added a commit that referenced this pull request Jun 3, 2026
* ✨ feat(db): add usage column to messages table

Promote token usage/cost out of `metadata.usage` into a dedicated
`messages.usage` jsonb column, with btree expression indexes on
`usage.cost` and `usage.totalTokens`. Additive only — no data backfill;
`metadata.usage` stays the source of truth during the transition.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ✨ feat(db): add agent share schema (picked from #15430)

Bring the agent-share schema layer over from #15430: new `agent_shares`
table + `topics.sender_id` column/index, schema relations and barrel
export. Migration renumbered to 0106 to sit after the usage column.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ✨ feat(db): add workspace schema (picked from #15414)

Bring over only the standalone `workspace.ts` schema from #15414 — the
workspaces / workspace_members / workspace_invitations / workspace_audit_logs
tables (self-contained, FK to users only). None of #15414's workspaceId
column additions across other tables are included. Migration is 0108-safe,
renumbered to 0107.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* 🗃️ chore(db): squash usage/agent-share/workspace into one migration

Collapse the three stacked migrations (0105 usage, 0106 agent_share,
0107 workspace) into a single idempotent 0105_add_usage_agent_share_workspace.
Schema source is unchanged; only the migration files/snapshot/journal are
consolidated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* ✅ test(db): add senderId to expected topic shape in create test

The picked agent-share schema added topics.senderId, so the created row
now returns it; update the two toEqual assertions accordingly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@arvinxx arvinxx closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants