Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/workbench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ npm test -w @calli/e2e -- --test-concurrency=1 test/smoke.spec.mjs

### 安装为桌面应用

在 Chrome 中打开 LooChat 后,可通过浏览器菜单将它安装为应用。安装名称为 LooChat,图标使用蓝白配色的大小钳小螃蟹。
在 macOS 或 Windows 的 Chrome 中打开 LoopX,浏览器允许安装时,侧栏底部会出现「安装 LoopX」。点击「安装」后,在 Chrome 弹窗中确认;网页不能跳过这次确认。安装后可从 Spotlight 或开始菜单打开独立窗口。

选择「以后再说」或取消安装后,7 天内不再主动提示;「配置 → 安装 LoopX」仍可手动进入。没有快捷安装按钮时,该页面会显示浏览器菜单安装说明。请使用 HTTPS(本机 localhost 也可);受管理的浏览器可能禁用安装。独立窗口仍需连接原来的 Workbench 服务,不提供离线 Agent 执行。

如果此前安装的应用仍显示 Limi、AgentHub 或旧图标,先尝试关闭所有应用窗口后重新打开,并接受 Chrome 提供的名称或图标更新。如果仍未更新,可卸载旧应用后从当前网页重新安装;卸载时不要勾选清除网站数据,以保留本机登录和偏好。
85 changes: 85 additions & 0 deletions apps/workbench/packages/e2e/test/pwa-install.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdirSync } from 'node:fs';
import { join } from 'node:path';
import { startDaemon, launchBrowser, openUi, api } from '../harness.mjs';

// Real packaged UI/backend; only browser-owned consent events are simulated. This does not
// certify OS installation on macOS or Windows. Screenshots contain synthetic conversations.
const shots = new URL('../../../../../output/playwright/pwa-install/', import.meta.url).pathname;
async function offer(page, outcome = 'dismissed', fail = false) {
await page.evaluate(({ outcome, fail }) => {
const event = new Event('beforeinstallprompt', { cancelable: true });
event.prompt = () => {
window.installCalls = (window.installCalls ?? 0) + 1;
window.installClickedWithActivation = navigator.userActivation.isActive;
return fail ? Promise.reject(new Error('simulated browser refusal')) : Promise.resolve();
};
event.userChoice = Promise.resolve({ outcome });
window.dispatchEvent(event);
}, { outcome, fail });
}

test('install entrypoints preserve consent, suppression, recovery and populated layouts', { timeout: 120000 }, async () => {
mkdirSync(shots, { recursive: true });
const daemon = await startDaemon();
const browser = await launchBrowser();
try {
for (let i = 0; i < 18; i++) await api(daemon, '/api/threads', {
method: 'POST', body: JSON.stringify({ agent: 'pi', cwd: daemon.workdir, title: `Workspace review ${i + 1} — long conversation title for layout verification` }),
});
for (const mobile of [false, true]) for (const theme of ['light', 'dark']) {
const context = await browser.newContext({ viewport: mobile ? { width: 390, height: 844 } : { width: 1440, height: 1000 }, isMobile: mobile, hasTouch: mobile, colorScheme: theme });
const page = await context.newPage(); page.setDefaultTimeout(10000);
const errors = []; page.on('pageerror', error => errors.push(error.message));
try {
// A synthetic expiring credential exercises the other standing footer notice.
await page.route('**/api/auth/kind', route => route.fulfill({ json: { kind: 'link', linkId: 'layout-fixture', expiresAt: new Date(Date.now() + 3600000).toISOString() } }));
await openUi(page, daemon);
await page.addStyleTag({ content: '*,*::before,*::after{animation:none!important;transition:none!important}' });
if (!mobile && theme === 'light') {
const cdp = await context.newCDPSession(page);
const manifest = await cdp.send('Page.getAppManifest');
assert.deepEqual(manifest.errors, [], 'the served manifest parses without errors');
assert.equal(JSON.parse(manifest.data).name, 'LoopX');
assert.deepEqual((await cdp.send('Page.getInstallabilityErrors')).installabilityErrors, []);
await cdp.detach();
}
if (mobile) await page.getByRole('button', { name: '打开对话列表', exact: true }).click();
await page.screenshot({ path: join(shots, `before-${mobile ? 'phone' : 'desktop'}-${theme}.png`) });
await offer(page);
const promo = page.locator('.pwa-install-promo');
await promo.waitFor();
await page.locator('.sidebar-scroll').evaluate(el => { el.scrollTop = el.scrollHeight; });
const [list, card] = await Promise.all([page.locator('.sidebar-scroll').boundingBox(), promo.boundingBox()]);
assert.ok(list.y + list.height <= card.y + 1, 'installation does not cover the populated list');
assert.ok(card.x >= 0 && card.x + card.width <= (mobile ? 390 : 1440), 'card fits viewport');
const notice = await page.locator('.link-login-notice').boundingBox();
assert.ok(card.y + card.height <= notice.y + 1, 'installation does not cover the expiring-login notice');
await page.screenshot({ path: join(shots, `after-${mobile ? 'phone' : 'desktop'}-${theme}.png`) });
await promo.getByRole('button', { name: '以后再说' }).click();
await promo.waitFor({ state: 'detached' });
await page.locator('.sidebar').getByRole('button', { name: '配置', exact: true }).click();
await page.locator('.settings-nav').getByRole('button', { name: '安装 LoopX', exact: true }).click();
const settings = page.getByRole('region', { name: '安装 LoopX', exact: true });
await settings.getByRole('button', { name: '安装', exact: true }).click();
assert.equal(await page.evaluate(() => window.installCalls), 1);
assert.equal(await page.evaluate(() => window.installClickedWithActivation), true);
await settings.getByText('浏览器尚未提供快捷安装。', { exact: false }).waitFor();
await page.reload(); await settings.waitFor(); await offer(page);
assert.equal(await promo.count(), 0, 'dismissal survives reload and renewed offers');
await offer(page, 'dismissed', true);
await settings.getByRole('button', { name: '安装', exact: true }).click();
await settings.getByRole('alert').waitFor();
await page.screenshot({ path: join(shots, `recovery-${mobile ? 'phone' : 'desktop'}-${theme}.png`) });
await offer(page, 'accepted');
await settings.getByRole('button', { name: '安装', exact: true }).click();
await settings.getByRole('status').filter({ hasText: '已接受安装' }).waitFor();
await page.evaluate(() => window.dispatchEvent(new Event('appinstalled')));
await settings.getByRole('status').filter({ hasText: '已安装' }).waitFor();
assert.equal(await settings.getByRole('button', { name: '安装', exact: true }).count(), 0);
assert.deepEqual(errors, []);
} finally { await context.close(); }
}
} finally { await browser.close(); await daemon.stop(); }
});
12 changes: 12 additions & 0 deletions apps/workbench/packages/web/public/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
"background_color": "#f8f6f1",
"theme_color": "#f8f6f1",
"icons": [
{
"src": "/pwa/icon-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/pwa/icon-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/loochat-icon.png?v=crab-1",
"sizes": "1024x1024",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions apps/workbench/packages/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import { SchedulesPage } from './components/SchedulesPage';
import { GoalWorkPage, GOAL_TABS, type GoalTab } from './components/GoalWorkPage';
import { GoalsPage, type GoalsFilter } from './components/GoalsPage';
import { AccessSettings } from './components/AccessSettings';
import { PwaInstallPromotion, PwaInstallSettings } from './components/PwaInstall';
import { LinkLoginNotice, useAuthKind } from './components/LinkLoginNotice';
import { StewardActions, StewardPage } from './components/StewardPage';
import { SidebarGoals, useLoopxStatus } from './components/SidebarGoals';
Expand Down Expand Up @@ -133,7 +134,7 @@ import { ConnectDialog, DemoBar } from './components/ConnectDialog';
import { DemoApi, DemoError } from './demo/DemoApi';
import { EMPTY_MODEL_PREFERENCE, type DraftModelPreference } from '../../daemon/src/model-preferences';
import { QUICK_SWITCH_HIDDEN_KEY, clampQuickSwitchBottom, savedQuickSwitchBottom, saveQuickSwitchBottom } from './quick-switch';
import { IconCheck, IconBell, AgentMark, IconActivity, IconAgents, IconArchive, IconArrowLeft, IconArrowDown, IconBack, IconClose, IconEdit, IconFolder, IconGauge, IconGlobe, IconList, IconMenu, IconSettings, IconMore, IconOverview, IconPalette, IconPlus, IconPuzzle, IconServer, IconShield, IconSidebar, IconSignIn, IconSignOut, IconSparkle, IconTerminal, IconTrace, IconLanguage, IconWaveform, IconSideChat } from './components/icons';
import { IconDownload, IconCheck, IconBell, AgentMark, IconActivity, IconAgents, IconArchive, IconArrowLeft, IconArrowDown, IconBack, IconClose, IconEdit, IconFolder, IconGauge, IconGlobe, IconList, IconMenu, IconSettings, IconMore, IconOverview, IconPalette, IconPlus, IconPuzzle, IconServer, IconShield, IconSidebar, IconSignIn, IconSignOut, IconSparkle, IconTerminal, IconTrace, IconLanguage, IconWaveform, IconSideChat } from './components/icons';
import { StatReadings } from './components/SessionStats';
import { ThreadTracePanel } from './components/TracePanel';
import { chooseLocale, locale, LOCALES, localeChoice, t } from './i18n';
Expand Down Expand Up @@ -2829,6 +2830,7 @@ function Hub({ token, onToken, connect, hostId = null, onHost, start, showcase }
{ label: t('settings.preferences'), entries: [
...(!demo ? [{ id: 'general', label: t('general.title'), icon: IconSettings, render: () => <GeneralSettingsDialog api={api} onSave={value => { setStartupSettings(value); setExternalNonce(n => n + 1); }} onClose={closeSettings} /> }] : []),
{ id: 'appearance', label: t('appearance.title'), icon: IconPalette, render: () => <AppearancePanel appearance={appearance} theme={theme} onChange={setAppearance} onClose={closeSettings} /> },
...(!showcase ? [{ id: 'install', label: t('pwa.title'), icon: IconDownload, render: () => <PwaInstallSettings /> }] : []),
{ id: 'language', label: t('locale.menu'), icon: IconLanguage, render: () => <SettingsSection title={t('locale.menu')} hint={t('settings.automatic')}><div className="settings-options">
{[{ id: 'system' as const, name: t('locale.system') }, ...LOCALES].map(l => <button key={l.id} className="settings-link-row" role="radio" aria-checked={localeChoice() === l.id} onClick={() => navigate(() => chooseLocale(l.id))}><span>{l.name}</span>{localeChoice() === l.id && <IconCheck size={16} />}</button>)}
</div></SettingsSection> },
Expand Down Expand Up @@ -3020,7 +3022,10 @@ function Hub({ token, onToken, connect, hostId = null, onHost, start, showcase }
schedulesActive={onSchedules}
extensionNav={extensionNav}
notice={demo && compact ? showcase ? showcase.notice(selectedId, extWant) : <DemoBar compact onConnect={askToConnect} /> : undefined}
footerNotice={authKind?.kind === 'link' && !showcase ? <LinkLoginNotice auth={authKind} onOpenAccess={() => openSettings('access')} /> : undefined}
footerNotice={!showcase ? <>
<PwaInstallPromotion onHelp={() => openSettings('install')} />
{authKind?.kind === 'link' && <LinkLoginNotice auth={authKind} onOpenAccess={() => openSettings('access')} />}
</> : undefined}
/>
</aside>
{!compact && !sidebarHidden && (
Expand Down
48 changes: 48 additions & 0 deletions apps/workbench/packages/web/src/components/PwaInstall.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useSyncExternalStore } from 'react';
import { createPwaInstall } from '../pwa-install';
import { t } from '../i18n';
import { SettingsSection } from './PageNavigation';
import { IconDownload } from './icons';

// Capture eligibility before React mounts, and share one single-use offer across both entrypoints.
const install = typeof window !== 'undefined' && typeof window.matchMedia === 'function' ? createPwaInstall(window) : null;
if (import.meta.hot) import.meta.hot.dispose(() => install?.dispose());
const empty = { available: false, installed: false, busy: false, accepted: false, failed: false, dismissedUntil: 0 };
const snapshot = () => install?.getSnapshot() ?? empty;
const subscribe = (listener: () => void) => install?.subscribe(listener) ?? (() => {});
const useInstall = () => useSyncExternalStore(subscribe, snapshot);

export function PwaInstallPromotion({ onHelp }: { onHelp: () => void }) {
const state = useInstall();
if (state.installed || state.dismissedUntil > Date.now() || (!state.available && !state.busy && !state.failed)) return null;
return <section className="pwa-install-promo" aria-label={t('pwa.title')}>
<strong><IconDownload size={16} />{t('pwa.title')}</strong>
<p>{t('pwa.hint')}</p>
{state.failed && <p role="alert">{t('pwa.failed')}</p>}
<div className="pwa-install-actions">
{state.failed
? <button type="button" className="ghost" onClick={onHelp}>{t('pwa.help')}</button>
: <button type="button" className="primary" disabled={state.busy} onClick={() => void install?.install()}>{t(state.busy ? 'pwa.prompting' : 'pwa.install')}</button>}
<button type="button" className="ghost" onClick={() => install?.dismiss()}>{t('pwa.later')}</button>
</div>
</section>;
}

export function PwaInstallSettings() {
const state = useInstall();
const secure = typeof window !== 'undefined' && window.isSecureContext;
return <SettingsSection title={t('pwa.title')} hint={t('pwa.hint')}>
{state.installed ? <p role="status">{t('pwa.installed')}</p> : <>
{state.failed && <p role="alert">{t('pwa.failed')}</p>}
{state.accepted && <p role="status">{t('pwa.accepted')}</p>}
{state.available || state.busy
? <button type="button" className="primary" disabled={state.busy} onClick={() => void install?.install()}>{t(state.busy ? 'pwa.prompting' : 'pwa.install')}</button>
: !state.accepted && <p className="settings-hint">{t(secure ? 'pwa.unavailable' : 'pwa.insecure')}</p>}
<details className="pwa-install-help" open={!state.available && !state.busy && !state.accepted}>
<summary>{t('pwa.help')}</summary>
<p>{t('pwa.chrome')}</p>
<p>{t('pwa.launch')}</p>
</details>
</>}
</SettingsSection>;
}
14 changes: 14 additions & 0 deletions apps/workbench/packages/web/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import type { Messages } from './zh';
const plural = (n: number, one: string, other: string) => `${n} ${n === 1 ? one : other}`;

export const en: Messages = {
"pwa.title": "Install LoopX",
"pwa.hint": "Open in its own window, ready to launch from your computer.",
"pwa.install": "Install",
"pwa.later": "Not now",
"pwa.prompting": "Confirm in Chrome…",
"pwa.help": "Installation help",
"pwa.failed": "Installation could not start. Try the browser menu.",
"pwa.installed": "Installed. Open LoopX from your computer’s app list.",
"pwa.accepted": "Installation accepted. Waiting for Chrome to finish.",
"pwa.unavailable": "The browser has not offered quick installation. Try the Chrome menu; if already installed, open LoopX from your app list.",
"pwa.insecure": "Open this site over HTTPS or local localhost, then try installing again.",
"pwa.chrome": "In Chrome on macOS or Windows, use the address bar’s install icon, or find “Cast, save, and share” → “Install page as app” in the menu. Labels vary by Chrome version; managed browsers may disable installation.",
"pwa.launch": "After installing, find LoopX with Spotlight on Mac or the Windows Start menu. You can pin it to the Dock or taskbar yourself. Installation does not make the remote service available offline.",

"references.message": (value: string) => `Message · ${value}`,
"references.messageHint": "A snapshot of this message for the agent to read as needed.",
"messageActions.context": "Use as context",
Expand Down
14 changes: 14 additions & 0 deletions apps/workbench/packages/web/src/i18n/locales/ja.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import type { Messages } from './zh';

export const ja: Messages = {
"pwa.title": "LoopX をインストール",
"pwa.hint": "独立したウィンドウで開き、パソコンからすぐに起動できます。",
"pwa.install": "インストール",
"pwa.later": "後で",
"pwa.prompting": "Chrome で確認してください…",
"pwa.help": "インストール方法",
"pwa.failed": "インストールを開始できませんでした。ブラウザのメニューから再試行してください。",
"pwa.installed": "インストール済みです。パソコンのアプリ一覧から LoopX を開けます。",
"pwa.accepted": "インストールを承認しました。Chrome の処理をお待ちください。",
"pwa.unavailable": "ブラウザからインストールの案内がまだ届いていません。Chrome のメニューをお試しください。インストール済みならアプリ一覧から開けます。",
"pwa.insecure": "HTTPS またはローカルの localhost で開いてから、再度インストールしてください。",
"pwa.chrome": "macOS または Windows の Chrome で、アドレスバーのインストールアイコン、またはメニューの「キャスト、保存、共有」→「ページをアプリとしてインストール」を選びます。名称は Chrome のバージョンによって異なります。管理対象のブラウザではインストールが禁止されている場合があります。",
"pwa.launch": "インストール後は Mac の Spotlight または Windows のスタートメニューで LoopX を検索できます。Dock やタスクバーへの固定は手動で行えます。リモートサービスがオフラインで使えるようになるわけではありません。",

"references.message": (value: string) => `メッセージ · ${value}`,
"references.messageHint": "このメッセージの本文を保存し、必要に応じてエージェントが読みます。",
"messageActions.context": "コンテキストにする",
Expand Down
14 changes: 14 additions & 0 deletions apps/workbench/packages/web/src/i18n/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
* a key added here has to be added to them too. Messages with values are functions.
*/
export const zh = {
"pwa.title": "安装 LoopX",
"pwa.hint": "用独立窗口打开,随时从电脑启动。",
"pwa.install": "安装",
"pwa.later": "以后再说",
"pwa.prompting": "请在 Chrome 中确认…",
"pwa.help": "安装说明",
"pwa.failed": "安装未能启动,请通过浏览器菜单重试。",
"pwa.installed": "已安装,可从电脑的应用列表打开 LoopX。",
"pwa.accepted": "已接受安装,请等待 Chrome 完成。",
"pwa.unavailable": "浏览器尚未提供快捷安装。可以尝试从 Chrome 菜单安装;如果已安装,直接从应用列表打开。",
"pwa.insecure": "请通过 HTTPS 或本机 localhost 打开,再尝试安装。",
"pwa.chrome": "在 macOS 或 Windows 的 Chrome 中,点击地址栏的安装图标,或在菜单中找到「投放、保存和分享」→「将网页安装为应用」。菜单名称可能随 Chrome 版本变化;受管理的浏览器可能禁用安装。",
"pwa.launch": "安装后可在 Mac 的 Spotlight 或 Windows 开始菜单搜索 LoopX,也可以自行固定到 Dock 或任务栏。安装不会让远程服务离线可用。",

"references.message": (value: string) => `消息 · ${value}`,
"references.messageHint": "保存这条消息的正文快照,供 agent 按需读取。",
"messageActions.context": "作为上下文",
Expand Down
Loading
Loading