Summary
Enable users to convert a private brain into a shared brain and add members/teams during the conversion. This involves a small backend extension (conversion endpoint + sharing logic) and frontend UI to trigger conversion and select invitees.
Why
- Collaboration: teams can work on the same brain.
- Smooth UX: convert and invite in one step.
Scope
- Add a “Move to Shared” action for a private brain.
- During conversion, allow selecting users and teams to share with.
- Update state so the converted brain appears under shared brains.
- Enforce permissions (owner/admin only).
Out of scope for this task:
- Advanced auditing or activity history.
- Converting back to private (can be a follow-up task).
Backend (Node.js)
Controllers
Routes
nodejs/src/routes/web/brains.js
- Add:
PUT /web/brains/convert-to-shared/:id (preferred), or extend PUT /web/brains/update/:id to accept conversion payload.
- Apply
authentication middleware and validation.
Services
nodejs/src/services/brain.js
- Implement conversion flow:
- Load brain, ensure ownership/admin.
- Set
isShare = true.
- Attach users and teams using existing helpers:
shareBrainWithUser
shareBrainList
- Confirm queries like
workspaceWiseList, getShareBrains, getGeneralBrain reflect new state.
- Ensure idempotency (no duplicate shares on repeated calls).
Validations
nodejs/src/utils/validations/brain
- Accept payload for conversion/update:
{ isShare: true, shareWith?: ShareUser[], teams?: ShareTeam[], customInstruction?: string }
ShareUser: { id, email, fname?, lname? }
ShareTeam: { id, teamName, teamUsers?: [] }
Models (reuse)
nodejs/src/models/shareBrain.js (mapping for shared access)
- No schema changes expected for this task.
Suggested API Contract
- Method:
PUT /web/brains/convert-to-shared/:id
- Body:
{ isShare: true, shareWith: ShareUser[], teams: ShareTeam[], customInstruction?: string }
- Response: updated brain record with
isShare: true and assigned members/teams.
Frontend (Next.js)
Types
nextjs/src/types/brain.ts
- Ensure
BrainType.isShare and related types are used by the UI and actions.
Redux Slice
nextjs/src/lib/slices/brain/brainlist.ts
- On successful conversion:
- Remove brain from
privateList.
- Add brain to
shareList.
- Recompute
combined to reflect the change.
Hooks
nextjs/src/hooks/brains/useBrains.ts
- Extend to support a conversion flow:
- Modal form defaults for members/teams.
- Submit handler calls
convertToSharedAction with payload.
Actions (API calls)
nextjs/src/actions/brains.ts
- Add
convertToSharedAction(brainId, { members, teams, customInstruction? }).
- After success, revalidate tags similar to
createBrainAction:
REVALIDATE_TAG_NAME.BRAIN
REVALIDATE_TAG_NAME.WORKSPACE
UI
- Brains UI:
nextjs/src/components/Brains/*
- Add a “Move to Shared” action in the brain card/menu for private brains.
- Modal for selecting users (emails) and teams (multi-select), optional
customInstruction.
- Toast notifications on success/failure; instant state update via slice.
Permissions and Edge Cases
- Only brain owner or admin can convert.
- Idempotent member/team assignment (no duplicates on repeated requests).
- Rollback or consistent state on partial failures (aim for atomic update if infra permits).
Acceptance Criteria
- Owner/admin can convert a private brain to shared in one flow.
- During conversion, members and/or teams can be added.
- Converted brain moves to shared list and is removed from private list for the owner.
- Assigned users/teams can access associated prompts/agents/threads.
- Proper error handling and user feedback (toasts) on the frontend.
Test Plan
- Convert a private brain with two users and one team; verify list placement and access.
- Attempt conversion by a non-owner; expect 403.
- Re-run conversion with same members; verify no duplicates.
- Remove a member post-conversion; verify access is revoked.
Tasks (Contributor Checklist)
Summary
Enable users to convert a private brain into a shared brain and add members/teams during the conversion. This involves a small backend extension (conversion endpoint + sharing logic) and frontend UI to trigger conversion and select invitees.
Why
Scope
Out of scope for this task:
Backend (Node.js)
Controllers
nodejs/src/controller/web/brainController.jsconvertToSharedor extendupdateBrainto support conversion.isShareto true.shareWith(users) andteamsarrays.Optional (admin parity):
nodejs/src/controller/admin/brainController.jsRoutes
nodejs/src/routes/web/brains.jsPUT /web/brains/convert-to-shared/:id(preferred), or extendPUT /web/brains/update/:idto accept conversion payload.authenticationmiddleware and validation.Services
nodejs/src/services/brain.jsisShare = true.shareBrainWithUsershareBrainListworkspaceWiseList,getShareBrains,getGeneralBrainreflect new state.Validations
nodejs/src/utils/validations/brain{ isShare: true, shareWith?: ShareUser[], teams?: ShareTeam[], customInstruction?: string }ShareUser:{ id, email, fname?, lname? }ShareTeam:{ id, teamName, teamUsers?: [] }Models (reuse)
nodejs/src/models/shareBrain.js(mapping for shared access)Suggested API Contract
PUT /web/brains/convert-to-shared/:id{ isShare: true, shareWith: ShareUser[], teams: ShareTeam[], customInstruction?: string }isShare: trueand assigned members/teams.Frontend (Next.js)
Types
nextjs/src/types/brain.tsBrainType.isShareand related types are used by the UI and actions.Redux Slice
nextjs/src/lib/slices/brain/brainlist.tsprivateList.shareList.combinedto reflect the change.Hooks
nextjs/src/hooks/brains/useBrains.tsconvertToSharedActionwith payload.Actions (API calls)
nextjs/src/actions/brains.tsconvertToSharedAction(brainId, { members, teams, customInstruction? }).createBrainAction:REVALIDATE_TAG_NAME.BRAINREVALIDATE_TAG_NAME.WORKSPACEUI
nextjs/src/components/Brains/*customInstruction.Permissions and Edge Cases
Acceptance Criteria
Test Plan
Tasks (Contributor Checklist)
nodejs/src/routes/web/brains.jsfor convert-to-shared.nodejs/src/controller/web/brainController.js.nodejs/src/services/brain.js(flipisShare, attach users/teams, idempotent).nodejs/src/utils/validations/brain.convertToSharedActioninnextjs/src/actions/brains.tswith revalidation.nextjs/src/lib/slices/brain/brainlist.tsto move from private → shared.nextjs/src/components/Brains/*to pick users/teams.contributions.md.