Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(settings): find the My browser plugin by ghost id and guide outdated installs

Dash0f2ef74a8a69
diff --git a/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx b/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx
index 24435cb741..6656fa191e 100644
--- a/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx
+++ b/apps/desktop/src/renderer/components/settings/BrowserBackendSubsection.tsx
@@ -29,14 +29,36 @@ interface BrowserBackendSubsectionProps {
health: BrowserBackendHealth | null;
onSelect: (kind: BackendKind) => void;
onRecover: () => void;
- /** 推荐的页面控制插件已装在本机(可能未启用);决定第 1 步写「安装」还是「启用」。 */
- userBrowserPluginInstalled?: boolean;
+ /**
+ * 推荐的页面控制插件在本机的状态,决定第 1 步写「安装」「启用」还是「更新」:
+ * 已启用却仍报缺插件,说明装的版本还不支持「我的浏览器」。
+ */
+ userBrowserPluginState?: 'not-installed' | 'disabled' | 'enabled';
/** 第 1 步就地安装或启用推荐插件;第 2 步打开插件详情,里面有装浏览器扩展的入口。 */
onSetUpUserBrowser?: () => void;
/** 正在就地安装或启用插件。 */
userBrowserSetupBusy?: boolean;
}
+const SETUP_KEY = 'settings.computerUse.browserBackend.userBrowserSetup';
+const PLUGIN_STEP_KEYS = {
+ 'not-installed': {
+ title: `${SETUP_KEY}.installPluginTitle`,
+ body: `${SETUP_KEY}.pluginBody`,
+ action: `${SETUP_KEY}.installPlugin`,
+ },
+ disabled: {
+ title: `${SETUP_KEY}.enablePluginTitle`,
+ body: `${SETUP_KEY}.pluginBody`,
+ action: `${SETUP_KEY}.enablePlugin`,
+ },
+ enabled: {
+ title: `${SETUP_KEY}.updatePluginTitle`,
+ body: `${SETUP_KEY}.updatePluginBody`,
+ action: `${SETUP_KEY}.updatePlugin`,
+ },
+} as const;
+
function healthReasonKey(reason: BrowserBackendHealthReason | undefined): string {
switch (reason) {
case 'disposing':
@@ -64,7 +86,7 @@ export function BrowserBackendSubsection({
health,
onSelect,
onRecover,
- userBrowserPluginInstalled = false,
+ userBrowserPluginState = 'not-installed',
onSetUpUserBrowser,
userBrowserSetupBusy = false,
}: BrowserBackendSubsectionProps) {
@@ -158,18 +180,18 @@ export function BrowserBackendSubsection({
)}
<div className="flex min-w-0 flex-col gap-0.5">
<span className="font-medium text-[var(--settings-section-title)]">
- {userBrowserHealth.reason === 'plugin-missing'
- ? t(
- userBrowserPluginInstalled
- ? 'settings.computerUse.browserBackend.userBrowserSetup.enablePluginTitle'
- : 'settings.computerUse.browserBackend.userBrowserSetup.installPluginTitle',
- )
- : t('settings.computerUse.browserBackend.userBrowserSetup.installExtensionTitle')}
+ {t(
+ userBrowserHealth.reason === 'plugin-missing'
+ ? PLUGIN_STEP_KEYS[userBrowserPluginState].title
+ : 'settings.computerUse.browserBackend.userBrowserSetup.installExtensionTitle',
+ )}
</span>
<span className="text-[var(--settings-section-desc)]">
- {userBrowserHealth.reason === 'plugin-missing'
- ? t('settings.computerUse.browserBackend.userBrowserSetup.pluginBody')
- : t('settings.computerUse.browserBackend.userBrowserSetup.extensionBody')}
+ {t(
+ userBrowserHealth.reason === 'plugin-missing'
+ ? PLUGIN_STEP_KEYS[userBrowserPluginState].body
+ : 'settings.computerUse.browserBackend.userBrowserSetup.extensionBody',
+ )}
</span>
</div>
</div>
@@ -181,13 +203,11 @@ export function BrowserBackendSubsection({
onClick={onSetUpUserBrowser}
disabled={pending || userBrowserSetupBusy}
>
- {userBrowserHealth.reason === 'plugin-missing'
- ? t(
- userBrowserPluginInstalled
- ? 'settings.computerUse.browserBackend.userBrowserSetup.enablePlugin'
- : 'settings.computerUse.browserBackend.userBrowserSetup.installPlugin',
- )
- : t('settings.computerUse.browserBackend.userBrowserSetup.installExtension')}
+ {t(
+ userBrowserHealth.reason === 'plugin-missing'
+ ? PLUGIN_STEP_KEYS[userBrowserPluginState].action
+ : 'settings.computerUse.browserBackend.userBrowserSetup.installExtension',
+ )}
</Button>
) : null}
</div>
diff --git a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
index 5d05dbdaff..a8fd161840 100644
--- a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
@@ -468,10 +468,15 @@ export function ComputerUseSection({ workingDir }: ComputerUseSectionProps) {
}, []);
// Step 1 happens right here: install the plugin from the market (Main still shows its usual
// permission confirmation) or turn it on, then re-check so the guidance moves on to step 2.
- // Step 2 and anything unexpected open the plugin's own page, which has the extension install entry.
+ // Step 2, an installed version too old to connect, and anything unexpected open the plugin's own
+ // page, which has the update button and the extension install entry.
const handleSetUpUserBrowser = useCallback(async () => {
const openPluginPage = () =>
- navigate(`/plugins?market=${encodeURIComponent(RECOMMENDED_PAGE_CONTROL_PLUGIN_ID)}`);
+ navigate(
+ userBrowserPlugin
+ ? `/plugins?ghost=${encodeURIComponent(installedGhostStoragePart(userBrowserPlugin))}`
+ : '/plugins',
+ );
if (browserBackendHealth?.reason !== 'plugin-missing' || userBrowserPlugin?.enabled) {
openPluginPage();
return;
@@ -485,8 +490,12 @@ export function ComputerUseSection({ workingDir }: ComputerUseSectionProps) {
ghostInstallApprovalToken(userBrowserPlugin.approval),
);
} else {
- const detail = await window.electronAPI.pluginMarket.detail(RECOMMENDED_PAGE_CONTROL_PLUGIN_ID);
- if (detail.installState !== 'not-installed') {
+ // Market ids are opaque; the plugin is found by the ghost id it installs as.
+ const item = (await window.electronAPI.pluginMarket.snapshot()).items.find(
+ (entry) => entry.ghostId === RECOMMENDED_PAGE_CONTROL_PLUGIN_ID,
+ );
+ const detail = item ? await window.electronAPI.pluginMarket.detail(item.pluginId) : null;
+ if (detail?.installState !== 'not-installed') {
openPluginPage();
return;
}
@@ -1530,7 +1539,13 @@ export function ComputerUseSection({ workingDir }: ComputerUseSectionProps) {
health={browserBackendHealth}
onSelect={(kind) => void handleSelectBackend(kind)}
onRecover={() => void handleRecoverBrowserBackend()}
- userBrowserPluginInstalled={userBrowserPlugin !== null}
+ userBrowserPluginState={
+ userBrowserPlugin === null
+ ? 'not-installed'
+ : userBrowserPlugin.enabled
+ ? 'enabled'
+ : 'disabled'
+ }
userBrowserSetupBusy={userBrowserSetupBusy}
onSetUpUserBrowser={() => void handleSetUpUserBrowser()}
/>
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx
index c98151e3f9..5ef834e27e 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/ComputerUseSection.browserHealth.test.tsx
@@ -526,14 +526,21 @@ describe('ComputerUseSection browser backend health loading', () => {
// and the guidance moves on to step 2 as soon as the host reports the extension as the gap.
it('installs the My browser plugin from settings and moves on to the extension step', async () => {
const detail = {
- pluginId: 'my-browser',
+ pluginId: 'market-opaque-id',
releaseId: 'release-1',
manifest: { id: 'my-browser' },
installState: 'not-installed',
};
+ // Market ids are opaque: the plugin has to be found by the ghost id it installs as.
+ const snapshot = vi.fn().mockResolvedValue({
+ items: [
+ { pluginId: 'other-id', ghostId: 'other-plugin' },
+ { pluginId: 'market-opaque-id', ghostId: 'my-browser' },
+ ],
+ });
const marketDetail = vi.fn().mockResolvedValue(detail);
const install = vi.fn().mockResolvedValue({ ghost: { manifest: { name: 'Cindy Chrome' } } });
- Object.assign(window.electronAPI, { pluginMarket: { detail: marketDetail, install } });
+ Object.assign(window.electronAPI, { pluginMarket: { snapshot, detail: marketDetail, install } });
api.getBackendState.mockResolvedValue({ active: 'user-browser' });
api.getBackendHealth
.mockResolvedValueOnce({ active: 'user-browser', status: 'error', reason: 'plugin-missing', canRecover: false })
@@ -554,7 +561,7 @@ describe('ComputerUseSection browser backend health loading', () => {
expect(
await screen.findByText('settings.computerUse.browserBackend.userBrowserSetup.installExtensionTitle'),
).toBeTruthy();
- expect(install).toHaveBeenCalledWith('my-browser', {
+ expect(install).toHaveBeenCalledWith('market-opaque-id', {
expectedReleaseId: 'release-1',
expectedManifest: { id: 'my-browser' },
allowSourceReplacement: false,
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 02b5737755..59bdaa90e9 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -5318,7 +5318,10 @@
"extensionBody": "Add the Cindy extension in Chrome or Edge; this turns to connected on its own once it is in. Already added? Turn it on in the browser’s extension settings, or reload it.",
"installPlugin": "Install plugin",
"enablePlugin": "Turn on",
- "installExtension": "Add browser extension"
+ "installExtension": "Add browser extension",
+ "updatePluginTitle": "Step 1: Update the Cindy Chrome plugin",
+ "updatePluginBody": "The installed Cindy Chrome plugin is too old for My browser. Update it to the latest version, then follow its prompt to add the extension.",
+ "updatePlugin": "Update"
}
},
"android": {
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index a45ba30fdb..ad6b9fb23f 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -5286,7 +5286,10 @@
"extensionBody": "Chrome または Edge に Cindy 拡張機能を追加すると、ここは自動的に「接続済み」になります。追加済みの場合は、ブラウザの拡張機能管理で有効にするか、再読み込みしてください。",
"installPlugin": "プラグインをインストール",
"enablePlugin": "有効にする",
- "installExtension": "ブラウザ拡張機能を追加"
+ "installExtension": "ブラウザ拡張機能を追加",
+ "updatePluginTitle": "ステップ 1:Cindy Chrome プラグインを更新",
+ "updatePluginBody": "インストール済みの Cindy Chrome プラグインは古く、「自分のブラウザ」に対応していません。最新版に更新してから、案内に従って拡張機能を追加してください。",
+ "updatePlugin": "更新する"
}
},
"android": {
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 2e73e21a95..ccd2173590 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -5286,7 +5286,10 @@
"extensionBody": "Chrome 또는 Edge에 Cindy 확장을 추가하면 이곳이 자동으로 연결됨으로 바뀝니다. 이미 추가했다면 브라우저의 확장 관리에서 켜거나 새로고침하세요.",
"installPlugin": "플러그인 설치",
"enablePlugin": "켜러 가기",
- "installExtension": "브라우저 확장 추가"
+ "installExtension": "브라우저 확장 추가",
+ "updatePluginTitle": "1단계: Cindy Chrome 플러그인 업데이트",
+ "updatePluginBody": "설치된 Cindy Chrome 플러그인이 오래되어 내 브라우저를 지원하지 않습니다. 최신 버전으로 업데이트한 뒤 안내에 따라 확장을 추가하세요.",
+ "updatePlugin": "업데이트하러 가기"
}
},
"android": {
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 362a846e23..d031b8ecc5 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -5286,7 +5286,10 @@
"extensionBody": "在 Chrome 或 Edge 里安装 Cindy 扩展,装好后这里会自动变成已连接。已经装过?在浏览器的扩展管理里启用它,或点一下刷新。",
"installPlugin": "安装插件",
"enablePlugin": "去启用",
- "installExtension": "安装浏览器扩展"
+ "installExtension": "安装浏览器扩展",
+ "updatePluginTitle": "第 1 步:更新 Cindy Chrome 插件",
+ "updatePluginBody": "已装的 Cindy Chrome 插件版本较旧,还不支持「我的浏览器」。更新到最新版后,再按提示把扩展装进浏览器。",
+ "updatePlugin": "去更新"
}
},
"android": {
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index aa5bc0562b..58cd0e68e7 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -5286,7 +5286,10 @@
"extensionBody": "在 Chrome 或 Edge 裡安裝 Cindy 擴充功能,裝好後這裡會自動變成已連線。已經裝過?在瀏覽器的擴充功能管理裡啟用它,或點一下重新整理。",
"installPlugin": "安裝插件",
"enablePlugin": "前往啟用",
- "installExtension": "安裝瀏覽器擴充功能"
+ "installExtension": "安裝瀏覽器擴充功能",
+ "updatePluginTitle": "第 1 步:更新 Cindy Chrome 插件",
+ "updatePluginBody": "已安裝的 Cindy Chrome 插件版本較舊,還不支援「我的瀏覽器」。更新到最新版後,再依提示把擴充功能裝進瀏覽器。",
+ "updatePlugin": "前往更新"
}
},
"android": {