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。

feat(deep-link): 新增 cindy://plugins[/<ghostId>] 打开已装插件

Dash0f2fd465b7d7
diff --git a/apps/desktop/src/main/__tests__/deepLink.test.ts b/apps/desktop/src/main/__tests__/deepLink.test.ts
index 333fe61822..c00f490fd3 100644
--- a/apps/desktop/src/main/__tests__/deepLink.test.ts
+++ b/apps/desktop/src/main/__tests__/deepLink.test.ts
@@ -346,6 +346,16 @@ describe('parseDeepLink', () => {
expect(parseDeepLink('xdt-maker://focus/')).toBeNull();
});
+ it('parses plugins payload to the installed list or one plugin detail', () => {
+ // Bug/规则依据: 随包浏览器扩展的断连引导要把用户带回该插件的设置页。
+ expect(parseDeepLink('cindy://plugins')).toEqual({ type: 'installed-plugin' });
+ expect(parseDeepLink('cindy://plugins/')).toEqual({ type: 'installed-plugin' });
+ expect(parseDeepLink('cindy://plugins/my-browser')).toEqual({ type: 'installed-plugin', ghostId: 'my-browser' });
+ expect(parseDeepLink('cindy://plugins/my-browser/?x=1')).toEqual({ type: 'installed-plugin', ghostId: 'my-browser' });
+ expect(parseDeepLink('cindy://plugins/My Browser')).toBeNull();
+ expect(parseDeepLink('cindy://plugins/..%2Fetc')).toBeNull();
+ });
+
it('parses settings/providers payload with and without a connect target', () => {
expect(parseDeepLink('cindy://settings/providers')).toEqual({
type: 'settings',
diff --git a/apps/desktop/src/main/deepLink.ts b/apps/desktop/src/main/deepLink.ts
index 1dc61dddca..e8782548b5 100644
--- a/apps/desktop/src/main/deepLink.ts
+++ b/apps/desktop/src/main/deepLink.ts
@@ -46,6 +46,7 @@ import { app, BrowserWindow, type IpcMainInvokeEvent } from 'electron';
import path from 'node:path';
import { parseProviderShareInvitationIntent, parseSharedTaskInvitationIntent } from '@cindy/device-link';
import { createLogger } from './logger';
+import { isValidGhostId } from '../shared/ghost';
import { registerWindowsDeepLinkName } from './deepLinkWindowsRegistration';
import {
DEEP_LINK_PRIMARY_SCHEME,
@@ -101,6 +102,12 @@ export type DeepLinkPayload =
* provider / preset id,经白名单校验后透传给 renderer 已有的消费逻辑。
*/
| { type: 'settings'; tab: 'voice-input' | 'providers' | 'billing' | 'remote-control'; connect?: string; intent?: 'topup' }
+ /**
+ * cindy://plugins[/<ghostId>] —— 打开已安装插件列表,带 id 时直达该插件详情页
+ * (随包浏览器扩展等外部表面把用户带回对应插件的启用 / 连接设置)。id 须过
+ * ghost id 白名单,不合法整条拒绝。
+ */
+ | { type: 'installed-plugin'; ghostId?: string }
/**
* 纯"把窗口拉回前台"意图,不携带导航语义 (典型来源:OAuth 授权成功页的
* "打开 xdt-maker" 按钮 / 自动唤起)。main 进程内消化,不发给 renderer、
@@ -142,6 +149,17 @@ export function parseDeepLink(url: string): DeepLinkPayload | null {
const importId = createProviderImportDraftFromRest(rest);
return importId ? { type: 'provider-import', importId } : null;
}
+ if (/^plugins(?:[/?#]|$)/.test(rest)) {
+ const rawId = rest.slice('plugins'.length).replace(/^\//, '').replace(/[?#].*$/, '').replace(/\/+$/, '');
+ if (!rawId) return { type: 'installed-plugin' };
+ let ghostId: string;
+ try {
+ ghostId = decodeURIComponent(rawId);
+ } catch {
+ return null;
+ }
+ return isValidGhostId(ghostId) ? { type: 'installed-plugin', ghostId } : null;
+ }
const slashIdx = rest.indexOf('/');
if (slashIdx <= 0) return null;
const type = rest.slice(0, slashIdx);
diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
index 80922f3072..6be980d0e2 100644
--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
@@ -766,6 +766,10 @@ export function MainLayout() {
navigate(`/plugins?market=${encodeURIComponent(payload.pluginId)}`);
return;
}
+ if (payload.type === 'installed-plugin') {
+ navigate(payload.ghostId ? `/plugins?ghost=${encodeURIComponent(payload.ghostId)}` : '/plugins');
+ return;
+ }
if (payload.type === 'session') {
navigateToSession(payload.id, payload.messageClientId, payload.islandEntryId, payload.deviceId);
return;