Skip to content

feat(mobile): provider keys for organizations and structured credentials - #11214

Open
iscekic wants to merge 1 commit into
mainfrom
igor/mobile-byok-org-structured
Open

iscekic wants to merge 1 commit into
mainfrom
igor/mobile-byok-org-structured

Conversation

@iscekic

@iscekic iscekic commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

What

Provider keys (BYOK) no longer hand off to the web: the account screens cover personal and organization scopes natively, and the Azure, Bedrock, and Vertex credentials get native forms.

  • Scope. provider-keys, provider-key-add, and provider-key-new take ?org=. Any organization member can read its keys; only an owner, admin, or billing manager can add, replace, enable or disable, test, or delete them, the same rule byok-router applies. A member who opens the form gets the permission state, not an input the server would refuse. The org hub's BYOK row moves to the in-app rows with the same role gate.
  • Credentials. @kilocode/app-shared/byok-credentials owns the Azure, Bedrock (API key or access-key pair), and Vertex schemas and the one validation both apps run; web-shared re-exports them so every web import path is unchanged, and the web manager runs the shared check. The native form collects the same fields and stores the same JSON. The "Manage on web" row, its copy, and the URL helpers are removed.
  • Edit. A key row offers Test, Edit, and Remove. Editing means entering a new value; the server never returns the old one.
  • Secret inputs. Every credential field turns off autocorrect, suggestions, autofill, and spell check (one shared prop set). Single-line secrets are masked. The multiline Vertex private key opens no soft keyboard (paste only), so no keyboard ever sees or learns its value.
  • States. The list and the save have pending, empty, happy, retryable failure (with Retry), and non-retryable failure (the server's message, no retry).

Why

Web hand-offs interrupt the user, and the web pages show navigation that leads to billing pages.

Verification

  • Mobile typecheck, lint, check:unused, check:i18n, check:plurals, check:classes, format check, and the full mobile vitest suite: pass. app-shared credential tests: pass.
  • Android on a local stack with a fake owner and member: personal and organization add, edit, delete; member read-only list; the three structured forms submitted to the server; retryable error state; secret fields masked with no suggestion strip.
  • Design gate (standard matrix) on the empty, happy, member, error, picker, and form states: exit 0, 0 errors, 0 warnings.

Production prerequisites

None.

The provider-keys screens now take a scope: the caller's own keys, or one
organization's. An organization's keys are readable by every member and
writable by a billing role, which is the rule every byok procedure applies.
The org hub's BYOK row opens that screen with the organization's scope.

Azure, AWS Bedrock and Google Vertex get native forms for their credential
fields, validated by the same schemas the web BYOK form uses (moved into
app-shared and re-exported at the old path). The provider picker no longer
sends structured providers to the web, and the dead Manage-on-web row, its
copy, and the unused provider predicate are gone.

A key row can now replace its value, which is the only edit the server
allows: the stored credential is never returned, so the form re-collects it.
@iscekic iscekic self-assigned this Nov 16, 2026
@iscekic

iscekic commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

bot: Android proof on a local stack with a fake owner and member organization: personal and organization keys added, edited, and deleted; the member sees a read-only list; Azure, Bedrock, and Vertex forms submitted to the server; secret inputs masked with no keyboard suggestion strip. Design gate contact sheets attached (0 errors, 0 warnings).

Organization keys

Member read-only

Azure key masked, no suggestions

Vertex private key: no keyboard

Retryable error

Design gate: states and forms

Design gate: secret inputs

provider_id: provider.id,
api_key: credential.apiKey,
})
: update.mutateAsync({ ...scopeInput, id: keyId, api_key: credential.apiKey }));

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.

[WARNING]: Replacing an Azure key silently deletes its model mappings

byok.update overwrites the whole stored credential (encrypted_api_key_envelope in byok-router.ts), and this path sends only what the form collected. The edit form starts with an empty mappingsRef because the server never returns the stored credential, so rotating an Azure key without retyping every deployment mapping stores { apiKey, resourceName } and drops modelMappings. The list still shows the key, but requests for the mapped gateway models stop resolving. Warn in editKeyDescription that mappings must be re-entered (or leave them out of the replacement) for Azure.

});
};

const permissionDenied = scope.kind === 'organization' && !isResolving && !permissions.canView;

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.

[WARNING]: An organization-list failure is reported as a missing membership, with no retry

canView is just role !== undefined, while useOrgBoundary derives isResolving only from isLoaded/isLoading. If organizations.list errors (or is stale and has not yet learned a new membership), role stays undefined after resolution, so this branch renders a terminal variant='permission' state with no retry. It is also evaluated before keys.isError/keys.data, so successfully loaded keys are discarded. OrganizationBoundary treats isError as retryable and integrations-screen.tsx splits the two causes; this should do the same. The check in provider-key-new-screen.tsx:104 turns a billing role into a permission refusal under the same conditions.

{...CREDENTIAL_INPUT_PROPS}
secureTextEntry={field.secret}
multiline={field.multiline}
showSoftInputOnFocus={!field.multiline}

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.

[WARNING] — security (users): showSoftInputOnFocus is Android-only, so the Vertex private key raises a keyboard on iOS

React Native documents showSoftInputOnFocus as an Android-only TextInput prop; iOS ignores it. Focusing this multiline privateKey field therefore opens the software keyboard on iOS, and iOS does not mask a multiline secureTextEntry either (as credential-input-props.ts notes). The PEM is displayed in clear and editable through the IME on iOS, which contradicts the 'no keyboard ever sees or learns its value' rationale for making the field paste-only. Use a masked multiline input on iOS, or document the iOS limitation instead of relying on the prop.

return;
}
if (credential.tag !== 'ready') {
attempt.fail({ kind: 'refused', message: t('profile.providerKeys.apiKeyRequired') });

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.

[SUGGESTION]: A refused structured credential reports 'Enter the key.'

readCredential() returns { tag: 'refused' } when credentialProblem rejects the assembled shape, but this branch shows apiKeyRequired ('Enter the key.') and sets no field error. The reachable case is Azure: filling only one side of a mapping row makes credentialProblem return invalid-model-mapping (credential-fields.test.ts covers it), yet the API key is filled and the reader is told to enter the key. Surface the problem code, or use invalidCredentials for refused as the missing-field branch already does.

const apiKey = keyRef.current.trim();
return apiKey === '' ? { tag: 'missing', field: 'apiKey' } : { tag: 'ready', apiKey };
}
const missing = firstMissingField(form, valuesRef.current);

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.

[SUGGESTION]: Switching Bedrock's authentication method leaves stale values the form no longer shows

valuesRef is shared across both Bedrock forms and is not cleared when authMode changes, while the remounted fields start empty (uncontrolled inputs). Type an API key, switch to access keys and back: the API key field is blank but firstMissingField still sees the old entry, so Save succeeds with a credential the reader cannot see. Clear the draft entries for fields the next form does not render when the mode changes.


export default function ProviderKeyAddRoute() {
return <ProviderKeyProviderPickerScreen />;
const { org } = useLocalSearchParams<{ org?: string }>();

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.

[SUGGESTION]: Normalize the org query param

Every other ?org= route uses normalizeOrgQueryParam (integrations.tsx, organization/usage.tsx, organization/credit-activity.tsx) and types the param string | string[]. Here a repeated ?org= arrives as an array, is treated as a truthy organization id, and then fails the router's z.string().uuid() instead of selecting the first value. provider-keys.tsx:6 has the same gap.

disabled={pending}
error={fieldErrors.apiKey}
onChangeText={value => {
keyRef.current = value;

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.

[SUGGESTION]: A stale save failure stays on screen while the reader corrects the value

The previous form cleared its submit error on every keystroke; now save.failure (a server refusal or a required-field message) and fieldErrors are only retired at the next submit. useSurfaceFeedback exposes clearWhere for this. Retire the failure once the reader edits the credential so the refusal is not shown beside a value that has already changed. The structured form's onChangeText in provider-key-credential-form.tsx has the same gap.

@kilo-code-bot

kilo-code-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 7 Issues Found | Recommendation: Address before merge

Executive Summary

The highest-risk issues are silent loss of an existing Azure key's model mappings when its credential is replaced, and organization-list failures being shown as a non-retryable "not a member" state, followed by the Vertex private key unexpectedly raising a keyboard on iOS.

Assumptions: [INFERENCE] iOS multiline masking and showSoftInputOnFocus platform support were assessed from React Native's documented platform support, not a device run. No new listener, timer, or retained subscription is introduced and the credential drafts are cleared on unmount and after success, so no memory-leak vector was found in this change.

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 4
Issue Details (click to expand)

WARNING

File Line Issue
apps/mobile/src/components/account/provider-key-new-screen.tsx 218 Replacing an Azure key overwrites the whole stored credential, silently dropping its modelMappings
apps/mobile/src/components/account/provider-keys-screen.tsx 230 An organizations.list failure is rendered as a terminal non-membership state with no retry and discards loaded keys; provider-key-new-screen.tsx:104 has the same check
apps/mobile/src/components/account/provider-key-credential-form.tsx 90 showSoftInputOnFocus is Android-only, so iOS opens a keyboard and displays the multiline Vertex PEM unmasked

SUGGESTION

File Line Issue
apps/mobile/src/components/account/provider-key-new-screen.tsx 208 A refused structured credential reports "Enter the key." and highlights no field
apps/mobile/src/components/account/provider-key-new-screen.tsx 158 Stale draft values across a Bedrock auth-method switch make a visibly empty field count as filled
apps/mobile/src/app/(app)/(tabs)/(3_profile)/provider-key-add.tsx 6 org is not normalized with normalizeOrgQueryParam; provider-keys.tsx:6 has the same gap
apps/mobile/src/components/account/provider-key-new-screen.tsx 313 A stale save failure is not retired while the reader corrects the value
Files Reviewed (23 code files + 87 locale catalogs)
  • apps/mobile/src/app/(app)/(tabs)/(3_profile)/provider-key-add.tsx - 1 issue
  • apps/mobile/src/app/(app)/(tabs)/(3_profile)/provider-keys.tsx - 1 issue (covered by the provider-key-add comment)
  • apps/mobile/src/components/account/provider-key-credential-form.tsx - 1 issue
  • apps/mobile/src/components/account/provider-key-credential-form.mounted.test.tsx
  • apps/mobile/src/components/account/provider-key-new-screen.tsx - 4 issues
  • apps/mobile/src/components/account/provider-key-new-screen.mounted.test.tsx
  • apps/mobile/src/components/account/provider-key-provider-picker-screen.tsx
  • apps/mobile/src/components/account/provider-key-provider-picker-screen.mounted.test.tsx
  • apps/mobile/src/components/account/provider-keys-screen.tsx - 1 issue
  • apps/mobile/src/components/account/provider-keys-screen.mounted.test.tsx
  • apps/mobile/src/components/organization/hub-screen.tsx
  • apps/mobile/src/components/organization/organization-settings-rows.ts
  • apps/mobile/src/components/organization/organization-settings-rows.test.ts
  • apps/mobile/src/lib/byok/credential-fields.ts
  • apps/mobile/src/lib/byok/credential-fields.test.ts
  • apps/mobile/src/lib/byok/credential-input-props.ts
  • apps/mobile/src/lib/byok/provider-key-scope.ts
  • apps/mobile/src/lib/byok/provider-key-scope.test.ts
  • apps/mobile/vitest.pure.config.ts
  • apps/web/src/components/organizations/byok/BYOKKeysManager.tsx
  • packages/app-shared/src/byok-credentials.ts
  • packages/app-shared/src/byok-credentials.test.ts
  • packages/web-shared/src/lib/ai-gateway/providers/openrouter/inference-provider-id.ts
  • apps/mobile/src/i18n/locales/*.json (87 catalogs, checked for key and placeholder parity)

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 171.2K · Output: 47.1K · Cached: 6M

Review guidance: REVIEW.md from base branch main

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant