-
-
Notifications
You must be signed in to change notification settings - Fork 24.1k
feat: Add defaultChatflowId to OrganizationConfig for org-level default chatflow override #6085
Description
Feature Description
Add a defaultChatflowId field to the OrganizationConfig interface so admins can update the default chatflow for their entire organization through the existing config API — without needing direct database access or server-wide env var changes.
Problem Statement
When an organization needs to change the default chatflow (shown in the Chrome extension and used on login), there are currently only two options:
- Direct database manipulation — update
user.defaultChatflowIdfor every user in the org INITIAL_CHATFLOW_IDSenv var — server-wide setting, not per-org, and still requires clearing per-user DB records to take effect
Neither option is suitable for production org management. There is no self-service, org-scoped way to change the default chatflow template.
Proposed Solution
-
Extend
OrganizationConfiginpackages/server/src/types/guardrails.tsto includedefaultChatflowId?: string -
Update
findOrCreateDefaultChatflowsForUsermiddleware inpackages/server/src/middlewares/authentication/findOrCreateDefaultChatflowsForUser.ts:- After the early-exit check for
latestUser.defaultChatflowId, read the org config - Compare the org config's
defaultChatflowIdagainst the user's existing chatflow'sparentChatflowId - If they differ (template changed), re-clone the new template for the user and update
user.defaultChatflowId - Fall back to
INITIAL_CHATFLOW_IDSenv var if no org-level override is set
- After the early-exit check for
-
No new API endpoints needed — the existing
GET/PUT /api/v1/organizations/:id/configendpoints already handle reading and writingorganizationConfig.
Desired Flow After Implementation
- Admin calls
PUT /api/v1/organizations/:id/configwith{ "defaultChatflowId": "new-chatflow-uuid" } - On next user login,
findOrCreateDefaultChatflowsForUserreads org config, detects the template has changed (viaparentChatflowIdcomparison), re-clones the new template for the user - User's
defaultChatflowIdis updated to point to their new clone - No direct DB manipulation or env var changes required
Key Files to Modify
packages/server/src/types/guardrails.ts— adddefaultChatflowId?: stringtoOrganizationConfiginterface (line 282)packages/server/src/middlewares/authentication/findOrCreateDefaultChatflowsForUser.ts— wire in org config lookup and template-change detection
Files for Reference (No Changes Needed)
packages/server/src/services/organizations/index.ts—getOrganizationConfig/updateOrganizationConfigservices already existpackages/server/src/routes/organizations/index.ts—GET/PUT /api/v1/organizations/:id/configroutes already exist
Acceptance Criteria
-
OrganizationConfiginterface includesdefaultChatflowId?: string -
findOrCreateDefaultChatflowsForUserreads org config and usesdefaultChatflowIdwhen present - If the org config
defaultChatflowIddiffers from the user's currentparentChatflowId, the new template is cloned anduser.defaultChatflowIdis updated on next login - Falls back to
INITIAL_CHATFLOW_IDSenv var when no org-level override is configured - Existing behavior is fully preserved when neither org config nor env var is set
- No new database migrations required (uses existing
organizationConfigJSONB column) - No new API routes required (uses existing
/api/v1/organizations/:id/configendpoints)