mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-28 14:10:37 +00:00
* feat(gateway): add GET /api/features for frontend feature gating (#3757) * feat(agents): add useAgentsApiEnabled feature-flag hook (#3757) * feat(agents): gate /workspace/agents segment on agents_api flag (#3757) * feat(sidebar): grey out Agents button with tooltip when agents_api disabled (#3757) * fix(sidebar): show disabled Agents tooltip on hover, harden a11y + e2e (#3757) - Wrap the disabled Agents button in a hoverable tooltip trigger so the 'feature not enabled' hint shows in the expanded sidebar, not only when collapsed (the SidebarMenuButton tooltip prop is hidden unless collapsed). - Add tabIndex={-1} and drop the redundant onClick preventDefault. - Add e2e coverage for the disabled state + a default /api/features mock. * style(sidebar): move cursor-not-allowed to the hoverable span (#3757) * test(agents): anchor e2e agents-API request filter with a path regex (#3757) * fix(agents): don't expose backend config in disabled message; tell user to contact admin (#3757) The disabled panel previously said 'Set agents_api.enabled: true in config.yaml', leaking backend configuration to end users. Replace with a generic 'not enabled on this server, contact your administrator' message (matching the existing nameStepApiDisabledError copy). e2e now asserts the contact-admin message and that no config.yaml/agents_api text is rendered. * make format * fix(agents): keep agents_api flag sticky during /api/features outage (#3757) Failing open re-mounted the agents UI and re-triggered the 403 storm when agents_api was genuinely disabled and /api/features was down. Persist the last definitive answer and fall back to it (sticky) before failing open, only failing open when nothing has ever been observed. Read the cached value after mount so the first client render matches the server (no hydration mismatch on the non-loading-gated sidebar). * fix(sidebar): make disabled Agents entry keyboard/SR accessible (#3757) The disabled-state explanation was hover-only: tabIndex={-1} removed the entry from the tab order and the reason lived only in a pointer-triggered tooltip. Keep it in the tab order and wire aria-describedby to a visually-hidden reason so keyboard and screen-reader users learn why it is disabled. --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
// Last-known persistence for the agents_api feature flag.
|
|
//
|
|
// /api/features is fail-open by design so an outage can never hide a working
|
|
// feature. The symmetric risk is that when the feature is genuinely disabled
|
|
// and /api/features is down, failing open re-mounts the agents UI and brings
|
|
// back the 403 storm (#3757). Persisting the last definitive answer lets a
|
|
// cold start during an outage fall back to it instead of failing open.
|
|
|
|
const AGENTS_API_ENABLED_KEY = "deerflow.features.agents_api";
|
|
|
|
function isBrowser(): boolean {
|
|
return typeof window !== "undefined";
|
|
}
|
|
|
|
/** The last definitive value observed from /api/features, or undefined. */
|
|
export function readCachedAgentsApiEnabled(): boolean | undefined {
|
|
if (!isBrowser()) {
|
|
return undefined;
|
|
}
|
|
try {
|
|
const raw = window.localStorage.getItem(AGENTS_API_ENABLED_KEY);
|
|
if (raw === "true") return true;
|
|
if (raw === "false") return false;
|
|
} catch {}
|
|
return undefined;
|
|
}
|
|
|
|
export function writeCachedAgentsApiEnabled(value: boolean): void {
|
|
if (!isBrowser()) {
|
|
return;
|
|
}
|
|
try {
|
|
window.localStorage.setItem(AGENTS_API_ENABLED_KEY, String(value));
|
|
} catch {}
|
|
}
|
|
|
|
/**
|
|
* Resolve the effective flag from the live query value and the last-known
|
|
* cached value:
|
|
* - a live answer always wins;
|
|
* - otherwise fall back to the last value we successfully observed (sticky),
|
|
* so a transient /api/features outage cannot flip a disabled feature back on;
|
|
* - only fail open (true) when we have never had a definitive answer, so a
|
|
* genuinely working feature is never hidden by an outage.
|
|
*/
|
|
export function resolveAgentsApiEnabled(
|
|
live: boolean | undefined,
|
|
cached: boolean | undefined,
|
|
): boolean {
|
|
return live ?? cached ?? true;
|
|
}
|