import { Tooltip } from 'antd'; import React, { type ReactNode, useState } from 'react'; // Keep this in sync with apps/studio/package.json. The test verifies the // relationship so a Puppeteer upgrade cannot leave users with a stale command. export const STUDIO_PUPPETEER_VERSION = '24.43.1'; const INSTALL_CHROME_COMMAND = `npx puppeteer@${STUDIO_PUPPETEER_VERSION} browsers install chrome`; const PUPPETEER_CONFIGURATION_URL = 'https://pptr.dev/guides/configuration'; const CHROME_MISSING_RE = /could not find (?:google )?chrome/; interface CreateAgentErrorNotification { title: string; description: ReactNode; duration: number; } function getErrorMessage(error: unknown): string { if (error instanceof Error) { return error.message || error.toString(); } if (typeof error === 'string') { return error; } if (error && typeof error === 'object' && 'message' in error) { const value = (error as { message?: unknown }).message; if (typeof value === 'string') { return value; } } return String(error); } export function getPuppeteerChromeInstallCommand(): string { return INSTALL_CHROME_COMMAND; } function copyInstallCommand(command: string) { if (typeof navigator === 'undefined') { return; } try { void navigator.clipboard?.writeText(command).catch(() => undefined); } catch { // Clipboard access can be unavailable or denied; copying is best-effort. } } function CopyIcon() { return ( ); } export function isPuppeteerChromeMissingError(error: unknown): boolean { const message = getErrorMessage(error).toLowerCase(); return ( CHROME_MISSING_RE.test(message) && (message.includes('puppeteer browsers install chrome') || message.includes('cache path') || message.includes('puppeteer')) ); } function ChromeMissingDescription({ error }: { error: unknown }) { const rawMessage = getErrorMessage(error); const installCommand = getPuppeteerChromeInstallCommand(); const [copyVisible, setCopyVisible] = useState(false); return (
Studio could not find the Chrome browser required to create a Web Agent.
Run this command, then try again:
setCopyVisible(true)} onMouseLeave={() => setCopyVisible(false)} style={{ background: '#f6f8fa', border: '1px solid #d9d9d9', borderRadius: 6, boxSizing: 'border-box', maxWidth: '100%', minHeight: 46, position: 'relative', }} >
          {installCommand}
        
Guide:{' '} {PUPPETEER_CONFIGURATION_URL}
document.body} overlayInnerStyle={{ width: 'min(680px, calc(100vw - 48px))', }} overlayStyle={{ maxWidth: 'min(680px, calc(100vw - 48px))', }} placement="topRight" title={
            {rawMessage}
          
} zIndex={10_000} >
); } export function getCreateAgentErrorNotification( error: unknown, ): CreateAgentErrorNotification | undefined { if (!isPuppeteerChromeMissingError(error)) { return undefined; } return { description: , duration: 0, title: 'Failed to create Agent', }; }