Skip to content

Commit 8436f67

Browse files
fix(console): show the platform-managed state on hosted storage and AI provider settings (#34327)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi99tocKWwN1LMoWm6vP4y3d6)_ Fixes #34149 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:托管环境里直接打开 Setup →「文件存储」时,控制台显示「此项由平台托管」,不再是通用报错;「AI 与向量化」页顶部多一行「AI 提供商、模型与凭据由平台托管」,对话标题与可观测性设置照常可改。 - **为什么改**:#33891 让服务端在托管环境拒绝存储设置、裁掉 AI 提供商键,控制台还不认这个拒绝,书签或手输网址会看到报错或缺了提供商的表单。 - **风险与回滚**:只改控制台设置页的读法与三条文案;自托管环境不受影响(对照用例钉住)。回滚即还原本 PR。 - **先看**:`ui/apps/console/src/pages/settings/platformManaged.ts`(拒绝与 AI 投影的判定)、`SettingsView.tsx` 的 `error?.managed` 分支与 `aiProviderManaged` 行、`api.ts` 的 `runSettingsAction` 新增一行。 - **两分钟验证**:在 `ui/` 下跑 `pnpm exec vitest run apps/console/src/pages/settings/__tests__/SettingsView.platformManaged-34149.test.tsx`,预期 9 例全绿。 - **需要你做的**:无,席位落地。 ## What changes The console half of #33891 (server contract landed in #34254). - **Storage page, hosted.** `GET /api/settings/storage` answers `409 RESOURCE_CONFLICT` with `error.details.managedBy: 'platform'` on a cloud-managed environment. `SettingsView` now reads that refusal by its declared shape (status, code and `details.managedBy`, never the message, via `isPlatformManagedRefusal` in the new `platformManaged.ts`) and draws a "Managed by the platform" card: no form, no save bar, no retry. A `409` without `managedBy: 'platform'` keeps today's error card. - **AI page, hosted (Ask 2).** The page is served projected, so nothing errors. The console draws one line, "The AI provider, its model and credentials are managed by the platform.", only when two served facts agree: the auth config's `features.cloudManaged === true` (plugin-auth answers it from the same `isCloudManaged()` the settings projection reads, and `FirstRunChecklist` already reads it through `getAuthConfig`, which asks no new request) and the served `ai` manifest carries no `provider` key (the projection actually ran). No served field was added. - **Stale page refusals.** `runSettingsAction` now throws the managed refusal like a failed read (status + raw body on `payload`) instead of folding it into `{ ok: false, message }`; `onAction` and `onSave` toast "Managed by the platform" for that shape. Read from the code before this change: such a refusal fell to the last branch of `runSettingsAction` and a stale `ai.test` click toasted the server's English sentence. - **i18n.** Three keys under `console.settingsView` in every pack (`platformManagedTitle`, `platformManagedBody`, `aiProviderManaged`); `zh-Hant` regenerated with `node scripts/gen-zh-hant.mjs`. - `SettingsHub.tsx` is untouched: it reads the list (`GET /api/settings`), which already leaves `storage` out on a hosted environment. ## Tests New: `__tests__/SettingsView.platformManaged-34149.test.tsx` (9 cases) and `platformManaged.test.ts` (5 cases). - hosted `GET storage` 409 + `managedBy: 'platform'` → managed card, no input, no retry, one read; - CONTROL: 409 `RESOURCE_CONFLICT` without `managedBy` → today's error card with the server's sentence; - CONTROL: self-hosted storage → form renders; - hosted AI (flag on, provider withheld) → one line, served keys still render; - CONTROLs: flag off with a projected manifest → no line; flag off with the full manifest → no line; flag on but provider served → no line; - stale action and stale save refused as platform-managed → the managed toast; - `runSettingsAction`: the managed 409 throws with status and raw body; another 409 stays `{ ok: false, message }`. No existing test was edited. <details><summary>Ablations (each landed on disk through scripts/ablation-replace.mjs, restored to the HEAD blob)</summary> - A1 `isPlatformManagedRefusal` returns false → 5 red (storage managed state, stale action, stale save, the helper, the api throw). - A2 the `features.cloudManaged` check dropped → red: the helper case and the view CONTROL "a page served without a provider on a self-hosted environment draws no line". - A3 the `runSettingsAction` throw line deleted → red: "throws the refusal with its status and raw body". Each run: `ok mutation landed` then `ok restored: blob == HEAD and git diff HEAD is empty`. </details> ## Acceptance notes - The console names the `ai` namespace and its `provider` key as constants (`platformManaged.ts`); the server's table is `CLOUD_MANAGED_HIDDEN_SETTINGS`. If a later server stops withholding the provider, the line disappears by itself (the manifest check); if it starts projecting another namespace partially, that page draws no line until the console learns it. A served marker on the projected manifest would remove the console constant, but it is a served field (Clause-②, server), so it was not added here. - `onClearSaved` (clear a value beneath an env pin) on a stale page still toasts the server's sentence for a managed refusal; on a hosted environment the managed keys are not served, so the row is not reachable without a stale page. ## Verification All on head `febd90e8`, run after the last commit. - `pnpm --filter @object-ui/console type-check`: exit 0. - `cd ui && pnpm exec vitest run packages/i18n/ apps/console/src/pages/settings/`: 145 files, 2313 passed, 13 skipped, exit 0 (includes the zh-Hant generated-pack pin and the settings-page bare-literal pin). - Derived gate set (`node scripts/pm/dispatch-gates.mjs --commands`): 40 commands, all exit 0; `--ran` reconciliation: 40 derived, 40 run, 0 NOT-MEASURED, 0 UNRUN. - `pnpm check:new-line-citations` (ui): 0 new citations. - eslint on the five changed console files: 0 errors. - Narrowing, declared: the console run covers `apps/console/src/pages/settings/` and `packages/i18n/`, the modules that import the changed files; CI's Test UI shards run the whole tree. No dogfood battery: no `!` in the title and no `(narrowing)` arm. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSWkWcHBfKEZ8RmTrv)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c934631 commit 8436f67

17 files changed

Lines changed: 549 additions & 10 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/console': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(console): on a cloud-managed environment, Setup's File storage page and the AI provider part of the AI page say the platform manages them
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A direct route (a bookmark or a typed URL) to Setup → File storage on a cloud-managed environment used to draw the generic load error, because the server refuses that namespace there. The console now reads that refusal by its declared shape (`409 RESOURCE_CONFLICT` with `error.details.managedBy: 'platform'`) and draws "Managed by the platform" with no form and no retry. A `409` without `managedBy: 'platform'` keeps the error card.
12+
13+
The AI page is served without its provider, model and credential keys on a cloud-managed environment. When the served auth config says the environment is cloud-managed (`features.cloudManaged`) and the served page carries no `provider` key, the page draws one line saying the platform manages the AI provider; the conversation-title and observability settings stay editable. A save or an action the server refuses as platform-managed (a page loaded earlier) toasts the same managed text instead of the server's sentence.
14+
15+
Self-hosted environments are unchanged. Three new keys under `console.settingsView` in every `@object-ui/i18n` pack: `platformManagedTitle`, `platformManagedBody`, `aiProviderManaged`.

‎ui/apps/console/src/pages/settings/SettingsView.tsx‎

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import { useEffect, useMemo, useRef, useState } from 'react';
1212
import { useParams, useNavigate } from 'react-router-dom';
1313
import { toast } from 'sonner';
1414
import { ConsolePageHeader } from '@object-ui/app-shell';
15-
import { Loader2, ArrowLeft, ChevronRight, RotateCcw, ShieldAlert } from 'lucide-react';
15+
import { Loader2, ArrowLeft, ChevronRight, RotateCcw, ShieldAlert, Cloud } from 'lucide-react';
1616
import { Button, Card, CardContent, Skeleton, Badge, getLazyIcon } from '@object-ui/components';
1717
import { ExpressionEvaluator } from '@object-ui/core';
1818
import { useObjectTranslation } from '@object-ui/i18n';
19+
import { useAuth } from '@object-ui/auth';
1920
import { SettingsField } from './SettingsField';
2021
import type { MapRefusalAt } from './SettingsMapField';
2122
import { fieldWording, settingsFieldRefusals } from './settingsFieldRefusals';
@@ -28,6 +29,7 @@ import {
2829
type JudgedClientAddress,
2930
type JudgedClientAddressRoute,
3031
} from './api';
32+
import { AI_PROVIDER_NAMESPACE, aiProviderManagedByPlatform, isPlatformManagedRefusal } from './platformManaged';
3133
import { resolveLabel, type SettingsNamespacePayload, type Specifier } from './types';
3234
import { useSettingsLabel, type SettingsLabelHelpers } from './useSettingsLabel';
3335
import { useUnsavedLeaveGuard } from './useUnsavedLeaveGuard';
@@ -371,7 +373,12 @@ export function SettingsView() {
371373
* when it sent one; without one the card shows `console.settingsView.loadError`,
372374
* translated at render so the fetch below reads no `t` (objectui#13254).
373375
*/
374-
const [error, setError] = useState<{ message?: string } | null>(null);
376+
/**
377+
* The load's failure, or null. `managed` marks the hosted refusal
378+
* (`platformManaged.ts`): the platform provides this page's settings, so the
379+
* page says so instead of drawing an error or a form.
380+
*/
381+
const [error, setError] = useState<{ message?: string; managed?: boolean } | null>(null);
375382
/** Live edit map keyed by spec.key. Falls back to resolved value when undefined. */
376383
const [draft, setDraft] = useState<Record<string, unknown>>({});
377384
/**
@@ -448,14 +455,47 @@ export function SettingsView() {
448455
setFieldErrors({});
449456
setCryptoRefusal(null);
450457
} catch (err: any) {
451-
setError({ message: err?.message });
458+
setError(
459+
isPlatformManagedRefusal(err?.status, err?.payload)
460+
? { managed: true }
461+
: { message: err?.message },
462+
);
452463
} finally {
453464
setLoading(false);
454465
}
455466
};
456467
void loadNamespace();
457468
}, [namespace]);
458469

470+
/**
471+
* The served auth config's `features`, read once per page that can use them:
472+
* the AI page draws one line when the platform manages its provider
473+
* ({@link aiProviderManagedByPlatform}). The auth client holds the config
474+
* sign-in already read, so this asks no new request. The read goes through a
475+
* ref so the effect keys on the namespace alone (AGENTS.md #10).
476+
*/
477+
const { getAuthConfig } = useAuth();
478+
const getAuthConfigRef = useRef(getAuthConfig);
479+
useEffect(() => {
480+
getAuthConfigRef.current = getAuthConfig;
481+
});
482+
const [authFeatures, setAuthFeatures] = useState<{ cloudManaged?: unknown } | null>(null);
483+
const readsAuthFeatures = namespace === AI_PROVIDER_NAMESPACE;
484+
useEffect(() => {
485+
if (!readsAuthFeatures) return;
486+
let live = true;
487+
Promise.resolve(getAuthConfigRef.current?.())
488+
.then((config) => {
489+
if (live) setAuthFeatures(config?.features ?? null);
490+
})
491+
.catch(() => {
492+
// Unreadable: no line, the page is what it serves.
493+
});
494+
return () => {
495+
live = false;
496+
};
497+
}, [readsAuthFeatures]);
498+
459499
/**
460500
* The caller's address as the server judges it, on a page that draws it
461501
* ({@link CLIENT_ADDRESS_ROUTES}), or null: another page, not read yet, or
@@ -529,6 +569,24 @@ export function SettingsView() {
529569
);
530570
}
531571

572+
if (error?.managed) {
573+
// No form and no retry: nothing here is the administrator's to set.
574+
return (
575+
<div className="p-6 max-w-3xl">
576+
<Button variant="ghost" size="sm" onClick={() => navigate(-1)}>
577+
<ArrowLeft className="h-4 w-4 mr-1" /> {t('console.settingsView.back')}
578+
</Button>
579+
<Card className="mt-3" data-testid="settings-platform-managed">
580+
<CardContent className="py-8 text-center text-sm">
581+
<Cloud className="h-6 w-6 mx-auto mb-2 text-muted-foreground" aria-hidden="true" />
582+
<p className="font-medium">{t('console.settingsView.platformManagedTitle')}</p>
583+
<p className="mt-1 text-muted-foreground">{t('console.settingsView.platformManagedBody')}</p>
584+
</CardContent>
585+
</Card>
586+
</div>
587+
);
588+
}
589+
532590
if (error) {
533591
return (
534592
<div className="p-6 max-w-3xl">
@@ -550,6 +608,7 @@ export function SettingsView() {
550608
const Icon = manifest.icon ? getLazyIcon(manifest.icon) : null;
551609
const title = labels.title(resolveLabel(manifest.label));
552610
const description = labels.description(manifest.description);
611+
const aiProviderManaged = aiProviderManagedByPlatform(namespace, manifest.specifiers, authFeatures);
553612

554613
/**
555614
* Read the namespace again after a successful save or action and take the
@@ -650,6 +709,10 @@ export function SettingsView() {
650709
? t('console.settingsView.cryptoRefusalToast', { subject: refusal.subject })
651710
: t('console.settingsView.cryptoRefusalToastNoSubject'),
652711
);
712+
} else if (isPlatformManagedRefusal(err?.status, err?.payload)) {
713+
// A page read before the environment became hosted wrote a key the
714+
// platform now manages: nothing was written.
715+
toast.error(t('console.settingsView.platformManagedTitle'));
653716
} else {
654717
// Per-field rejections render against the inputs that caused them
655718
// (objectstack#4224). `extractFieldErrors` reads `details.fields`, so it
@@ -731,7 +794,11 @@ export function SettingsView() {
731794
toast.error(result.message ?? t('console.settingsView.actionFailed'));
732795
}
733796
} catch (err: any) {
734-
toast.error(err?.message ?? t('console.settingsView.actionFailed'));
797+
toast.error(
798+
isPlatformManagedRefusal(err?.status, err?.payload)
799+
? t('console.settingsView.platformManagedTitle')
800+
: (err?.message ?? t('console.settingsView.actionFailed')),
801+
);
735802
} finally {
736803
setSaving(false);
737804
}
@@ -790,6 +857,17 @@ export function SettingsView() {
790857
<p className="text-sm text-muted-foreground whitespace-pre-wrap">{manifest.helpText}</p>
791858
) : null}
792859

860+
{aiProviderManaged ? (
861+
<Card className="mt-4" data-testid="settings-ai-provider-managed">
862+
<CardContent className="py-3">
863+
<p className="flex items-center gap-2 text-sm text-muted-foreground">
864+
<Cloud className="h-4 w-4 shrink-0" aria-hidden="true" />
865+
{t('console.settingsView.aiProviderManaged')}
866+
</p>
867+
</CardContent>
868+
</Card>
869+
) : null}
870+
793871
{cryptoRefusal ? (
794872
<Card className="mt-4 border-destructive/50 bg-destructive/5">
795873
<CardContent className="py-4">

0 commit comments

Comments
 (0)