* Adds `enterpriseByokEligible: true` to the initial mothership payload when the * workspace is on an enterprise plan. BYOK is mothership-only, so non-mothership * routes (e.g. `/api/copilot`) are left untouched. Failures default to hosted.
( payload: Record<string, unknown>, route: string, workspaceId?: string )
| 985 | * routes (e.g. `/api/copilot`) are left untouched. Failures default to hosted. |
| 986 | */ |
| 987 | async function withByokEligibilityHint( |
| 988 | payload: Record<string, unknown>, |
| 989 | route: string, |
| 990 | workspaceId?: string |
| 991 | ): Promise<Record<string, unknown>> { |
| 992 | // The eligibility hint is server-authoritative: always overwrite any |
| 993 | // client-supplied value with a server-derived boolean so a client can never |
| 994 | // assert its own eligibility. (Copilot's ValidateBYOK is the final authority, |
| 995 | // but the hint must never originate from the client.) BYOK is mothership-only; |
| 996 | // everything else gets an explicit false. |
| 997 | let eligible = false |
| 998 | if (workspaceId && route.startsWith('/api/mothership')) { |
| 999 | try { |
| 1000 | eligible = await isWorkspaceOnEnterprisePlan(workspaceId) |
| 1001 | } catch (error) { |
| 1002 | logger.warn('Failed to resolve BYOK eligibility; defaulting to hosted', { |
| 1003 | workspaceId, |
| 1004 | error: toError(error).message, |
| 1005 | }) |
| 1006 | } |
| 1007 | } |
| 1008 | return { ...payload, enterpriseByokEligible: eligible } |
| 1009 | } |
| 1010 | |
| 1011 | function isAborted(options: CopilotLifecycleOptions, context: StreamingContext): boolean { |
| 1012 | return !!(options.abortSignal?.aborted || context.wasAborted) |
no test coverage detected