Skip to content

feat(core): improve byok ux - #15303

Merged
darkskygit merged 1 commit into
canaryfrom
darksky/improvve-byok-settings
Jul 21, 2026
Merged

feat(core): improve byok ux#15303
darkskygit merged 1 commit into
canaryfrom
darksky/improvve-byok-settings

Conversation

@darkskygit

@darkskygit darkskygit commented Jul 21, 2026

Copy link
Copy Markdown
Member

fix #15265

PR Dependency Tree

This tree was auto-generated by Charcoal

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

BYOK private endpoint support

Layer / File(s) Summary
Probe policy and provider requests
.docker/selfhost/schema.json, packages/backend/server/src/plugins/copilot/{config.ts,byok/probe.ts}, packages/backend/server/src/__tests__/copilot/byok-probe.spec.ts, packages/frontend/admin/src/config.json
Adds the allowPrivateEndpoint setting and provider probes with bounded request options, provider authentication, private-target controls, and status-specific failures.
Capability calculation and service integration
packages/backend/server/src/plugins/copilot/byok/service.ts
Computes and returns privateEndpointSupported, delegates configuration checks to the probe helper, and removes the previous inline probe implementation.
GraphQL capability contract
packages/backend/server/src/{schema.gql,plugins/copilot/byok/resolver.ts}, packages/common/graphql/src/{schema.ts,graphql/*}
Exposes privateEndpointSupported through the backend schema, query selection, and generated client types.
Endpoint visibility and restriction messaging
packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/*, packages/frontend/i18n/src/{i18n.gen.ts,resources/*}
Updates BYOK endpoint visibility, disabled-state hints, deployment detection, styles, tests, and English/Chinese translations.
Native password sign-in validation
packages/frontend/core/src/__tests__/auth-native-sign-in.spec.ts
Adds Android and iOS coverage ensuring password sign-in waits for auth-session revalidation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BYOKModal
  participant ByokSettingsQuery
  participant ByokService
  participant runProviderProbe
  participant Provider
  BYOKModal->>ByokSettingsQuery: Request privateEndpointSupported
  ByokSettingsQuery->>ByokService: Resolve workspace BYOK settings
  ByokService-->>BYOKModal: Return endpoint capabilities
  BYOKModal->>ByokService: Test provider configuration
  ByokService->>runProviderProbe: Pass provider, credentials, endpoint, capability
  runProviderProbe->>Provider: GET models endpoint
  Provider-->>runProviderProbe: HTTP response
  runProviderProbe-->>BYOKModal: Success or probe error
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly related to the BYOK UX changes, even though it does not mention the new private-endpoint support specifically.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (3)
packages/frontend/core/src/__tests__/auth-native-sign-in.spec.ts (2)

49-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove unnecessary computed property syntax.

The property name config$ is a valid identifier and does not require computed property brackets.

♻️ Proposed refactor
-          ['config$']: {
+          config$: {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/frontend/core/src/__tests__/auth-native-sign-in.spec.ts` at line 49,
Update the object literal in the auth native sign-in test to use the direct
config$ property syntax instead of the unnecessary computed-property brackets,
preserving its existing value and behavior.

15-18: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Remove redundant parameterization or utilize the platform parameter.

The test uses test.each(['android', 'ios']) but does not accept or use the platform argument in its callback. Consequently, the exact same test runs twice without verifying any platform-specific logic or state.

If the environment needs to be mocked per platform (e.g., injecting the platform into a service or global config), pass the parameter to the closure (like async (platform) => { ... }) and configure the dependency injection accordingly. Otherwise, simplify the test to a single execution.

♻️ Proposed refactor (simplifying to a single test)
-  test.each(['android', 'ios'])(
-    'waits for the %s session bootstrap before completing',
-    async () => {
+  test('waits for the native session bootstrap before completing', async () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/frontend/core/src/__tests__/auth-native-sign-in.spec.ts` around
lines 15 - 18, Remove the redundant test.each(['android', 'ios'])
parameterization around the session bootstrap test and make it a single test,
unless platform-specific setup is required. If retaining parameterization,
accept the platform argument in the callback and use it to configure the
relevant mocked dependency or state.
packages/backend/server/src/__tests__/copilot/byok-probe.spec.ts (1)

11-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the probe failure path.

Both tests only cover the response.ok path. providerProbeFailureMessage (probe.ts Lines 79-94) status-code mapping and the BadRequestException throw on non-ok responses aren't exercised here, so a regression in that mapping wouldn't be caught.

♻️ Suggested additional test
test('provider probe surfaces provider rejection as BadRequestException', async t => {
  const fetch = Sinon.stub<
    Parameters<typeof safeFetch>,
    ReturnType<typeof safeFetch>
  >().resolves(new Response('{}', { status: 401 }));

  await t.throwsAsync(
    () => runProviderProbe(fetch, ByokProvider.openai, 'secret', null, false),
    { message: 'Provider rejected the BYOK key.' }
  );
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/server/src/__tests__/copilot/byok-probe.spec.ts` around
lines 11 - 53, Add a test covering the non-ok response path of runProviderProbe:
stub safeFetch to return a 401 response, invoke the probe with no private
target, and assert it throws BadRequestException with the mapped message
“Provider rejected the BYOK key.”
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/backend/server/src/__tests__/copilot/byok-probe.spec.ts`:
- Around line 11-53: Add a test covering the non-ok response path of
runProviderProbe: stub safeFetch to return a 401 response, invoke the probe with
no private target, and assert it throws BadRequestException with the mapped
message “Provider rejected the BYOK key.”

In `@packages/frontend/core/src/__tests__/auth-native-sign-in.spec.ts`:
- Line 49: Update the object literal in the auth native sign-in test to use the
direct config$ property syntax instead of the unnecessary computed-property
brackets, preserving its existing value and behavior.
- Around line 15-18: Remove the redundant test.each(['android', 'ios'])
parameterization around the session bootstrap test and make it a single test,
unless platform-specific setup is required. If retaining parameterization,
accept the platform argument in the callback and use it to configure the
relevant mocked dependency or state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44858eeb-e576-4828-8d58-ba55ea47a93b

📥 Commits

Reviewing files that changed from the base of the PR and between 7318ef1 and 4d498a3.

📒 Files selected for processing (22)
  • .docker/selfhost/schema.json
  • packages/backend/server/src/__tests__/copilot/byok-probe.spec.ts
  • packages/backend/server/src/plugins/copilot/byok/probe.ts
  • packages/backend/server/src/plugins/copilot/byok/resolver.ts
  • packages/backend/server/src/plugins/copilot/byok/service.ts
  • packages/backend/server/src/plugins/copilot/config.ts
  • packages/backend/server/src/schema.gql
  • packages/common/graphql/src/graphql/index.ts
  • packages/common/graphql/src/graphql/workspace-byok-settings.gql
  • packages/common/graphql/src/schema.ts
  • packages/frontend/admin/src/config.json
  • packages/frontend/core/src/__tests__/auth-native-sign-in.spec.ts
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/add-key-modal.tsx
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/index.css.ts
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/index.spec.tsx
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/index.tsx
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/metadata.spec.ts
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/metadata.ts
  • packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/byok/types.ts
  • packages/frontend/i18n/src/i18n.gen.ts
  • packages/frontend/i18n/src/resources/en.json
  • packages/frontend/i18n/src/resources/zh-Hans.json

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying blocksuite-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4d498a3
Status: ✅  Deploy successful!
Preview URL: https://a2a0e3b5.blocksuite-docs.pages.dev
Branch Preview URL: https://darksky-improvve-byok-settin.blocksuite-docs.pages.dev

View logs

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.87879% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.04%. Comparing base (7318ef1) to head (4d498a3).

Files with missing lines Patch % Lines
...s/backend/server/src/plugins/copilot/byok/probe.ts 87.23% 12 Missing ⚠️
...backend/server/src/plugins/copilot/byok/service.ts 89.47% 2 Missing ⚠️
...s/setting/workspace-setting/byok/add-key-modal.tsx 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #15303      +/-   ##
==========================================
+ Coverage   60.72%   61.04%   +0.32%     
==========================================
  Files        3311     3312       +1     
  Lines      191936   191988      +52     
  Branches    28277    28335      +58     
==========================================
+ Hits       116548   117196     +648     
+ Misses      71600    71012     -588     
+ Partials     3788     3780       -8     
Flag Coverage Δ
server-test 81.10% <88.52%> (+0.41%) ⬆️
unittest 35.86% <80.00%> (+0.06%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@darkskygit
darkskygit merged commit b6b7f1e into canary Jul 21, 2026
67 of 70 checks passed
@darkskygit
darkskygit deleted the darksky/improvve-byok-settings branch July 21, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Bug]: [Self-host] Copilot always returns COPILOT_QUOTA_EXCEEDED after configuring AI provider

1 participant