Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): hide "Edit with AI" bubble button when embedded in an agent … (#1787)

sarahd78f45a5ffa6
diff --git a/.changeset/hide-edit-with-ai-when-embedded.md b/.changeset/hide-edit-with-ai-when-embedded.md
new file mode 100644
index 000000000..5a8eac199
--- /dev/null
+++ b/.changeset/hide-edit-with-ai-when-embedded.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Hide the "Edit with AI" button in the WYSIWYG bubble menu when Open Knowledge is embedded inside an agent host (Cursor, Codex, Claude Desktop). The button opens the header's "Open with AI" menu, but that menu is already hidden in embedded hosts — so clicking the bubble button there did nothing. The button (and its Cmd+Shift+I shortcut) now hide in lockstep with the header menu, matching the rest of the embedded-host chrome.
diff --git a/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.dom.test.tsx b/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.dom.test.tsx
index 8bbc1a73f..178b1f121 100644
--- a/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.dom.test.tsx
+++ b/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.dom.test.tsx
@@ -63,6 +63,16 @@ function setPlatform(platform: string): void {
});
}
+function setUserAgent(userAgent: string): void {
+ Object.defineProperty(globalThis.navigator, 'userAgent', {
+ value: userAgent,
+ configurable: true,
+ });
+}
+
+const PLAIN_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Chrome/120 Safari/537.36';
+const EMBEDDED_UA = `${PLAIN_UA} Cursor/1.2.3`;
+
function renderButton({
editor,
shortcutEnabled = true,
@@ -91,6 +101,7 @@ afterEach(() => {
cleanup();
openRequests.length = 0;
toastError.mockClear();
+ setUserAgent(PLAIN_UA);
});
describe('EditWithAiBubbleButton', () => {
@@ -112,6 +123,38 @@ describe('EditWithAiBubbleButton', () => {
expect(container.firstChild).toBeNull();
});
+ test('does not render anything when embedded inside an agent host', () => {
+ setPlatform('MacIntel');
+ setUserAgent(EMBEDDED_UA);
+ const { editor } = makeEditor('specs/foo/SPEC', 'A passage.');
+ const { container } = renderButton({ editor });
+
+ expect(screen.queryByTestId('edit-with-ai-bubble-button')).toBeNull();
+ expect(container.firstChild).toBeNull();
+ });
+
+ test('Cmd+Shift+I does nothing when embedded inside an agent host', async () => {
+ setPlatform('MacIntel');
+ setUserAgent(EMBEDDED_UA);
+ const { editor } = makeEditor('specs/foo/SPEC', 'A passage.');
+ renderButton({ editor });
+
+ await act(async () => {
+ window.dispatchEvent(
+ new KeyboardEvent('keydown', {
+ key: 'I',
+ code: 'KeyI',
+ metaKey: true,
+ shiftKey: true,
+ bubbles: true,
+ cancelable: true,
+ }),
+ );
+ });
+
+ expect(openRequests).toEqual([]);
+ });
+
test('clicking the trigger requests the header Open with AI menu', async () => {
setPlatform('MacIntel');
const user = userEvent.setup();
diff --git a/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.tsx b/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.tsx
index 7866937f0..39104c990 100644
--- a/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.tsx
+++ b/packages/app/src/editor/bubble-menu/EditWithAiBubbleButton.tsx
@@ -7,6 +7,7 @@ import { toast } from 'sonner';
import { useOpenInAgentMenuRequest } from '@/components/handoff/OpenInAgentMenuRequestContext';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
+import { useIsEmbedded } from '@/hooks/use-is-embedded';
import { matchesKeyboardShortcut } from '@/lib/keyboard-shortcuts';
import { serializeWysiwygSelection } from '../edit-with-ai-selection.ts';
import { getEditorDocName } from '../extensions/doc-context.ts';
@@ -27,6 +28,7 @@ export function EditWithAiBubbleButton({
const { t } = useLingui();
const { openSelection } = useOpenInAgentMenuRequest();
const isMac = isMacOS();
+ const isEmbedded = useIsEmbedded();
const openSelectionMenu = (): void => {
let selectionMarkdown: string;
@@ -46,7 +48,7 @@ export function EditWithAiBubbleButton({
};
useEffect(() => {
- if (!isMac) return;
+ if (!isMac || isEmbedded) return;
const handleKeyDown = (event: KeyboardEvent): void => {
if (!shortcutEnabled) return;
if (!matchesKeyboardShortcut(event, 'edit-with-ai')) return;
@@ -62,12 +64,13 @@ export function EditWithAiBubbleButton({
return () => window.removeEventListener('keydown', handleKeyDown, { capture: true });
}, [
isMac,
+ isEmbedded,
shortcutEnabled,
// biome-ignore lint/correctness/useExhaustiveDependencies: openSelectionMenu is render-bound; re-subscribing keeps the handler fresh for the current editor selection.
openSelectionMenu,
]);
- if (!isMac) return null;
+ if (!isMac || isEmbedded) return null;
return (
<>