@yuriai/web 0.2.20-beta.3 → 0.2.24-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/assets/{AgentAvatar-D5KPQI1N.js → AgentAvatar-uHQNjXpd.js} +1 -1
- package/dist/assets/AssistantView-Drd8VDEa.js +3 -0
- package/dist/assets/{DiagramView-DWV04Xws.js → DiagramView-DkCNPVGi.js} +1 -1
- package/dist/assets/{FadeInOnReveal-CdoLG8fY.js → FadeInOnReveal-C4jDW1zu.js} +1 -1
- package/dist/assets/{GuiPluginSurface-DhD8BqvL.js → GuiPluginSurface-3kvNh8k7.js} +1 -1
- package/dist/assets/{GuiPluginWindow-ezsy5l_y.js → GuiPluginWindow-CBFALwNv.js} +1 -1
- package/dist/assets/Icon-B0ebXdpZ.js +1 -0
- package/dist/assets/{ImageLoadingPlaceholder-BVlgaa2r.js → ImageLoadingPlaceholder-BsOal94e.js} +1 -1
- package/dist/assets/{LoadingImage-BSG8jmn5.js → LoadingImage-DU15BNuP.js} +1 -1
- package/dist/assets/{MarkdownRenderer-BiRplAST.js → MarkdownRenderer--MUzfNV1.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-CH8TUMKZ.js → MarkdownRendererImpl-CRQzKIUS.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-Bmz56IzM.js → MarkstreamRendererImpl-BwCal960.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-kKHM_dU3.js → MobileDetailNavigation-Do2TWnlQ.js} +1 -1
- package/dist/assets/{MobileResizableSheet-jHNytoyX.js → MobileResizableSheet-C5UIcZMP.js} +1 -1
- package/dist/assets/{MobileShareBridge-CSDivsPk.js → MobileShareBridge-D1uMFffj.js} +1 -1
- package/dist/assets/MobileTabPageHeader-qFcP_0DQ.js +2 -0
- package/dist/assets/{MultiRunWindow-DbllgaJR.js → MultiRunWindow-ChKPsoQo.js} +1 -1
- package/dist/assets/{OnboardingScreen-DONIcirJ.js → OnboardingScreen-D5tX10Ru.js} +1 -1
- package/dist/assets/{OverlayScrollbar-DB2eeXFh.js → OverlayScrollbar-Cd3itQWo.js} +1 -1
- package/dist/assets/SettingsView-BRIvklfP.css +1 -0
- package/dist/assets/SettingsView-lVlHvszE.js +29 -0
- package/dist/assets/{SettingsWindow-BrrnHfnR.js → SettingsWindow-BHTfrkKB.js} +1 -1
- package/dist/assets/{TerminalView-8JYW5f-c.js → TerminalView-o9kbH9L7.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DZO89hKv.js → ToolOutputDialog-C-oQW3hF.js} +4 -4
- package/dist/assets/{YuriLogo-CYdRUurL.js → YuriLogo-mo6nZ3PX.js} +1 -1
- package/dist/assets/{appThemeRegistry-Nb-sUfbK.js → appThemeRegistry-Dj_lXuWN.js} +1 -1
- package/dist/assets/{button-nola46HU.js → button-RqfOQVDY.js} +1 -1
- package/dist/assets/{capgoAdapter-CHeo9q51.js → capgoAdapter-BBkQfU5y.js} +1 -1
- package/dist/assets/{collapsible-BQaMLh6O.js → collapsible-Dv8u92TF.js} +1 -1
- package/dist/assets/desktop-5DP3-Bao.js +1 -0
- package/dist/assets/{desktopHosts-B4HMNmrx.js → desktopHosts-CrVcscUO.js} +1 -1
- package/dist/assets/{desktopRelayRestore-CRl62mqn.js → desktopRelayRestore-DJFLfsuw.js} +1 -1
- package/dist/assets/{device-Coc5tapU.js → device-BKQ_0FdZ.js} +1 -1
- package/dist/assets/{diagram-COti_aKS.js → diagram-ChmjoQ5M.js} +1 -1
- package/dist/assets/{dialog-B2CTTXwv.js → dialog-BNwN9E77.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-BzpQaok_.js → dropdown-menu.styles-BeD-5cZr.js} +1 -1
- package/dist/assets/es-BA49Soe0.js +15 -0
- package/dist/assets/{fileMentionTouchSelection-CXepBNtQ.js → fileMentionTouchSelection-BOqFOFuS.js} +1 -1
- package/dist/assets/{fileReferenceActions-BnPPqYXw.js → fileReferenceActions-B1o8IWgw.js} +1 -1
- package/dist/assets/fr-BC5SbQkf.js +13 -0
- package/dist/assets/{gitApi-B7AeNXrj.js → gitApi-BBTlZPHJ.js} +1 -1
- package/dist/assets/{gitApiHttp-CoNokuDM.js → gitApiHttp-Bnr4_wxy.js} +2 -2
- package/dist/assets/{host-BCXyr41J.js → host-DgJqhX6n.js} +1 -1
- package/dist/assets/{input-DGnhaqoc.js → input-0mf9njqM.js} +1 -1
- package/dist/assets/insertionBoundaries-CeIZ6Ryc.js +1 -0
- package/dist/assets/ja-ZVSLBCEX.js +15 -0
- package/dist/assets/ko-UEhdI-6j.js +15 -0
- package/dist/assets/{main-d2AaD_PZ.js → main-B5RgfV79.js} +2 -2
- package/dist/assets/main-DmpGPZGl.js +169 -0
- package/dist/assets/{markdownHeightCache-C_JI5qIR.js → markdownHeightCache-CghsqV5O.js} +1 -1
- package/dist/assets/{mcpQueries-BgFj7wfO.js → mcpQueries-BoO0luGM.js} +1 -1
- package/dist/assets/{miniChat-BHdsTyJ3.js → miniChat-DqITTK1M.js} +2 -2
- package/dist/assets/mobile-BIr1jV5q.js +2 -0
- package/dist/assets/{mobileBackNavigation-s9RsXUUH.js → mobileBackNavigation-BX15eKz3.js} +1 -1
- package/dist/assets/{multirun-BZsBsBAj.js → multirun-YUG6khun.js} +1 -1
- package/dist/assets/{native-config-BmrfOzkM.js → native-config-Bd2dhq7v.js} +1 -1
- package/dist/assets/{persistence-CNEHspb4.js → persistence-BPb2hZ3c.js} +2 -2
- package/dist/assets/pl-CtZa8Aps.js +15 -0
- package/dist/assets/{platform-Q45KPuGv.js → platform-wGCQUVxr.js} +1 -1
- package/dist/assets/{projectMeta-BCGIXTbR.js → projectMeta-zvmpMSQf.js} +1 -1
- package/dist/assets/pt-BR-BLYFPwVu.js +15 -0
- package/dist/assets/{readiness-BxT5OBkk.js → readiness-Cdk9qFe5.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-BbfF6SjM.js → renderElectronMiniChatApp-BGE9uFhc.js} +2 -2
- package/dist/assets/renderMobileApp-6mtuJQ65.js +28 -0
- package/dist/assets/{runtimeConfig-BHRHZbwI.js → runtimeConfig-D-CPiNCJ.js} +1 -1
- package/dist/assets/runtimeEndpointReset-DJiib7qk.js +149 -0
- package/dist/assets/{scheduledTaskNavigation-CkBcoGV4.js → scheduledTaskNavigation-Dhcdlsyj.js} +1 -1
- package/dist/assets/{sessionChangeSummary-CAU-06Bu.js → sessionChangeSummary-CG0wKqkP.js} +1 -1
- package/dist/assets/{sessionLookup-YvkfClst.js → sessionLookup-B61-CKn2.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-pCvZjmMt.js → sortable-tabs-strip-B2s-35-E.js} +1 -1
- package/dist/assets/{speechSettingsQueries-1LD5eEHK.js → speechSettingsQueries-B8ZUB8kC.js} +3 -3
- package/dist/assets/src-CTDGzqeS.css +2 -0
- package/dist/assets/store-DRfILWJT.js +15 -0
- package/dist/assets/{terminalApi-DFhCeMya.js → terminalApi-Cjd7Jry6.js} +1 -1
- package/dist/assets/{textarea-DSHEMw8t.js → textarea-Brud1txt.js} +1 -1
- package/dist/assets/{tooltip-BwTvgqWG.js → tooltip-Bs7jQMa0.js} +1 -1
- package/dist/assets/{types-CiQgQf3s.js → types-DuOMU6Kx.js} +1 -1
- package/dist/assets/uk-CLu6Q5Pq.js +15 -0
- package/dist/assets/{useAppFontEffects-Cz9eoInx.js → useAppFontEffects-BbNLfgyg.js} +53 -53
- package/dist/assets/{useDesktopWindowControlsLayout-HpOlTBoV.js → useDesktopWindowControlsLayout-BobcZLtl.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-DE-YccE8.js → useEffectiveDirectory-DFrDhjCc.js} +1 -1
- package/dist/assets/{useFontPreferences-DmeLn0t9.js → useFontPreferences-CGThMzt0.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-DPE5LVui.js → useMobileNavigationStore-BoltsZEH.js} +16 -15
- package/dist/assets/useWorkerHighlightedLines-BtEOUB_j.js +7 -0
- package/dist/assets/zh-CN-794F19S6.js +15 -0
- package/dist/assets/{zh-TW-CtLsIcFb.js → zh-TW-CIVkGGCd.js} +4 -4
- package/dist/index.html +13 -13
- package/dist/mini-chat.html +13 -13
- package/dist/mobile.html +13 -13
- package/package.json +1 -1
- package/server/index.d.ts +9 -0
- package/server/index.js +10 -0
- package/server/lib/assistants/DOCUMENTATION.md +19 -4
- package/server/lib/assistants/contact-store.js +151 -17
- package/server/lib/assistants/contact-store.test.js +44 -2
- package/server/lib/assistants/contact-tools.js +43 -2
- package/server/lib/assistants/contact-tools.test.js +21 -0
- package/server/lib/assistants/harness.js +18 -12
- package/server/lib/assistants/harness.test.js +62 -8
- package/server/lib/assistants/service.js +64 -6
- package/server/lib/assistants/service.test.js +62 -19
- package/server/lib/assistants/summary.js +90 -0
- package/server/lib/assistants/summary.test.js +118 -0
- package/server/lib/llm/DOCUMENTATION.md +12 -2
- package/server/lib/llm/bridge-client.js +65 -16
- package/server/lib/llm/bridge-client.test.js +63 -2
- package/server/lib/opencode/DOCUMENTATION.md +1 -0
- package/server/lib/opencode/npm-registry.js +106 -11
- package/server/lib/opencode/npm-registry.test.js +64 -0
- package/server/lib/opencode/plugin-routes.js +3 -1
- package/server/lib/opencode/plugin-routes.test.js +3 -3
- package/server/lib/quota/magpie.js +2 -2
- package/server/lib/realtime-proxy.js +2 -1
- package/server/lib/relay/tunnel-host.js +1 -0
- package/server/lib/remote-desktop/DOCUMENTATION.md +52 -0
- package/server/lib/remote-desktop/protocol.js +26 -0
- package/server/lib/remote-desktop/protocol.test.js +18 -0
- package/server/lib/remote-desktop/runtime.js +112 -0
- package/server/lib/remote-desktop/runtime.test.js +135 -0
- package/server/lib/small-model/DOCUMENTATION.md +2 -1
- package/server/lib/ui-auth/DOCUMENTATION.md +2 -0
- package/server/lib/ui-auth/ui-auth.js +2 -1
- package/dist/assets/AssistantView-huAUB-2Y.js +0 -3
- package/dist/assets/Icon-DvqOB4Dx.js +0 -1
- package/dist/assets/MobileTabPageHeader-BkWvNBtr.js +0 -2
- package/dist/assets/SettingsView-6D55BNjw.js +0 -26
- package/dist/assets/desktop-CiqEZVr5.js +0 -1
- package/dist/assets/es-DklBd0ox.js +0 -15
- package/dist/assets/fr-CVUs46wM.js +0 -13
- package/dist/assets/insertionBoundaries-Db0R1aBj.js +0 -1
- package/dist/assets/ja-5reg09JK.js +0 -15
- package/dist/assets/ko-DZdC6ooz.js +0 -15
- package/dist/assets/main-DQ0F0yuL.js +0 -169
- package/dist/assets/mobile-BEhQq4tx.js +0 -2
- package/dist/assets/pl-BerZSK-a.js +0 -15
- package/dist/assets/pt-BR-ydmV6U49.js +0 -15
- package/dist/assets/renderMobileApp-ulSQxT-l.js +0 -28
- package/dist/assets/runtimeEndpointReset-H2W1kxcO.js +0 -149
- package/dist/assets/src-DGCTlpkW.css +0 -2
- package/dist/assets/store-ClIuNNU7.js +0 -15
- package/dist/assets/uk-BnTevguX.js +0 -15
- package/dist/assets/useWorkerHighlightedLines-o-elkNrd.js +0 -7
- package/dist/assets/zh-CN-DT6qIAPJ.js +0 -15
|
@@ -13,18 +13,54 @@ function jsonResponse(body, status = 200) {
|
|
|
13
13
|
}));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const originalCliLookup = npm.npmCli.lookup;
|
|
17
|
+
|
|
16
18
|
describe('npm registry client', () => {
|
|
17
19
|
beforeEach(() => {
|
|
18
20
|
npm.clearCache();
|
|
19
21
|
Date.now = originalDateNow;
|
|
20
22
|
fetchMock = mock(() => jsonResponse({}));
|
|
21
23
|
globalThis.fetch = fetchMock;
|
|
24
|
+
npm.npmCli.lookup = async () => null;
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
afterEach(() => {
|
|
25
28
|
npm.clearCache();
|
|
26
29
|
globalThis.fetch = originalFetch;
|
|
27
30
|
Date.now = originalDateNow;
|
|
31
|
+
npm.npmCli.lookup = originalCliLookup;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('npm CLI answer wins and skips the direct request (scope registries/auth)', async () => {
|
|
35
|
+
npm.npmCli.lookup = async () => ({ ok: true, latest: '2.0.0', versions: ['1.0.0', '2.0.0'], distTags: { latest: '2.0.0' } });
|
|
36
|
+
|
|
37
|
+
const result = await npm.lookupNpmPackage('@private/pkg', { cwd: '/proj' });
|
|
38
|
+
|
|
39
|
+
expect(result).toMatchObject({ ok: true, latest: '2.0.0' });
|
|
40
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('CLI 404 is definitive and not retried over HTTP', async () => {
|
|
44
|
+
npm.npmCli.lookup = async () => ({ ok: false, status: 404, error: 'Package not found' });
|
|
45
|
+
|
|
46
|
+
const result = await npm.lookupNpmPackage('@private/missing');
|
|
47
|
+
|
|
48
|
+
expect(result).toMatchObject({ ok: false, status: 404 });
|
|
49
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('cache is separated by cwd because .npmrc differs per project', async () => {
|
|
53
|
+
let calls = 0;
|
|
54
|
+
npm.npmCli.lookup = async () => {
|
|
55
|
+
calls += 1;
|
|
56
|
+
return { ok: true, latest: '1.0.0', versions: ['1.0.0'], distTags: { latest: '1.0.0' } };
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
await npm.getNpmInfo('foo', { cwd: '/a' });
|
|
60
|
+
await npm.getNpmInfo('foo', { cwd: '/b' });
|
|
61
|
+
await npm.getNpmInfo('foo', { cwd: '/a' });
|
|
62
|
+
|
|
63
|
+
expect(calls).toBe(2);
|
|
28
64
|
});
|
|
29
65
|
|
|
30
66
|
test('200 success returns latest versions and dist tags', async () => {
|
|
@@ -176,4 +212,32 @@ describe('npm registry client', () => {
|
|
|
176
212
|
|
|
177
213
|
expect(fetchMock.mock.calls[0][1].headers['User-Agent']).toMatch(/^yuri-server\//);
|
|
178
214
|
});
|
|
215
|
+
test('npm CLI answer carries a vetted magpie.icon', async () => {
|
|
216
|
+
npm.npmCli.lookup = async () => ({ ok: true, latest: '1.0.0', versions: ['1.0.0'], distTags: { latest: '1.0.0' }, icon: 'https://cdn.example/a.png' });
|
|
217
|
+
|
|
218
|
+
const result = await npm.getNpmInfo('@scope/pkg', { cwd: '/proj' });
|
|
219
|
+
|
|
220
|
+
expect(result.icon).toBe('https://cdn.example/a.png');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('registry fallback reads magpie.icon from the latest release', async () => {
|
|
224
|
+
fetchMock.mockImplementation(() => jsonResponse({
|
|
225
|
+
'dist-tags': { latest: '1.0.0' },
|
|
226
|
+
versions: { '1.0.0': { magpie: { icon: 'data:image/svg+xml;base64,AAAA' } } },
|
|
227
|
+
}));
|
|
228
|
+
|
|
229
|
+
const result = await npm.lookupNpmPackage('foo');
|
|
230
|
+
|
|
231
|
+
expect(result.icon).toBe('data:image/svg+xml;base64,AAAA');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('sanitizePluginIcon keeps only https and data:image, within the size cap', () => {
|
|
235
|
+
expect(npm.sanitizePluginIcon('https://x/y.png')).toBe('https://x/y.png');
|
|
236
|
+
expect(npm.sanitizePluginIcon(' data:image/png;base64,AA ')).toBe('data:image/png;base64,AA');
|
|
237
|
+
expect(npm.sanitizePluginIcon('http://x/y.png')).toBeUndefined();
|
|
238
|
+
expect(npm.sanitizePluginIcon('javascript:alert(1)')).toBeUndefined();
|
|
239
|
+
expect(npm.sanitizePluginIcon('data:text/html;base64,AA')).toBeUndefined();
|
|
240
|
+
expect(npm.sanitizePluginIcon(42)).toBeUndefined();
|
|
241
|
+
expect(npm.sanitizePluginIcon(`https://x/${'a'.repeat(3 << 19)}`)).toBeUndefined();
|
|
242
|
+
});
|
|
179
243
|
});
|
|
@@ -149,7 +149,7 @@ export const registerPluginRoutes = (app, dependencies) => {
|
|
|
149
149
|
|
|
150
150
|
const npmInfoByName = new Map();
|
|
151
151
|
await Promise.all(Array.from(npmJobs.keys()).map(async (name) => {
|
|
152
|
-
npmInfoByName.set(name, await getNpmInfo(name, { forceRefresh: refresh }));
|
|
152
|
+
npmInfoByName.set(name, await getNpmInfo(name, { forceRefresh: refresh, cwd: directory || undefined }));
|
|
153
153
|
}));
|
|
154
154
|
|
|
155
155
|
const results = [];
|
|
@@ -198,6 +198,7 @@ export const registerPluginRoutes = (app, dependencies) => {
|
|
|
198
198
|
currentVersion,
|
|
199
199
|
latestVersion: info.latest,
|
|
200
200
|
versions: info.versions,
|
|
201
|
+
...(info.icon ? { icon: info.icon } : {}),
|
|
201
202
|
});
|
|
202
203
|
continue;
|
|
203
204
|
}
|
|
@@ -210,6 +211,7 @@ export const registerPluginRoutes = (app, dependencies) => {
|
|
|
210
211
|
latestVersion: info.latest,
|
|
211
212
|
versions: info.versions,
|
|
212
213
|
hasUpdate: currentVersion !== null && isExactSemver(currentVersion) && currentVersion !== info.latest,
|
|
214
|
+
...(info.icon ? { icon: info.icon } : {}),
|
|
213
215
|
});
|
|
214
216
|
}
|
|
215
217
|
|
|
@@ -219,7 +219,7 @@ describe('opencode plugin routes', () => {
|
|
|
219
219
|
await request(app).get('/api/config/plugins/registry?specs=foo@1,foo@2,foo@3').expect(200);
|
|
220
220
|
|
|
221
221
|
expect(getNpmInfo).toHaveBeenCalledTimes(1);
|
|
222
|
-
expect(getNpmInfo).toHaveBeenCalledWith('foo', { forceRefresh: false });
|
|
222
|
+
expect(getNpmInfo).toHaveBeenCalledWith('foo', { forceRefresh: false, cwd: expect.any(String) });
|
|
223
223
|
});
|
|
224
224
|
|
|
225
225
|
test('GET /registry forwards refresh true to npm lookup', async () => {
|
|
@@ -228,7 +228,7 @@ describe('opencode plugin routes', () => {
|
|
|
228
228
|
|
|
229
229
|
await request(app).get('/api/config/plugins/registry?specs=foo&refresh=true').expect(200);
|
|
230
230
|
|
|
231
|
-
expect(getNpmInfo).toHaveBeenCalledWith('foo', { forceRefresh: true });
|
|
231
|
+
expect(getNpmInfo).toHaveBeenCalledWith('foo', { forceRefresh: true, cwd: expect.any(String) });
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
test('GET /registry rejects more than 100 unique specs', async () => {
|
|
@@ -261,7 +261,7 @@ describe('opencode plugin routes', () => {
|
|
|
261
261
|
|
|
262
262
|
const response = await request(app).get('/api/config/plugins/registry?specs=%40scope%2Ffoo%401.0.0').expect(200);
|
|
263
263
|
|
|
264
|
-
expect(getNpmInfo).toHaveBeenCalledWith('@scope/foo', { forceRefresh: false });
|
|
264
|
+
expect(getNpmInfo).toHaveBeenCalledWith('@scope/foo', { forceRefresh: false, cwd: expect.any(String) });
|
|
265
265
|
expect(response.body.results[0]).toMatchObject({ kind: 'npm-ok', spec: '@scope/foo@1.0.0', name: '@scope/foo' });
|
|
266
266
|
});
|
|
267
267
|
|
|
@@ -46,7 +46,7 @@ export function projectMagpieQuotas(payload, source, now = Date.now()) {
|
|
|
46
46
|
usedPercent: w.unlimited ? null : percent(w.used), remainingPercent: w.unlimited ? null : percent(w.remaining),
|
|
47
47
|
resetAt, resetAfterSeconds: resetAt === null ? null : Math.max(0, Math.ceil((resetAt - now) / 1000)),
|
|
48
48
|
valueLabel: w.unlimited ? '∞' : text(w.display) || (Number.isFinite(w.amount) && Number.isFinite(w.limit) && w.limit > 0 ? `${w.amount} / ${w.limit}${text(w.unit) ? ` ${w.unit}` : ''}` : null),
|
|
49
|
-
label: w.name,
|
|
49
|
+
label: w.name, disablePace: true,
|
|
50
50
|
};
|
|
51
51
|
account.windows[`${i}:${w.name}`] = window;
|
|
52
52
|
// Magpie serializes this informational window as used: 0 without its
|
|
@@ -57,7 +57,7 @@ export function projectMagpieQuotas(payload, source, now = Date.now()) {
|
|
|
57
57
|
result.usage.windows[key] = window;
|
|
58
58
|
}
|
|
59
59
|
if (account.balance) {
|
|
60
|
-
const window = { ...emptyWindow(), valueLabel: account.balance, label: 'credits_balance',
|
|
60
|
+
const window = { ...emptyWindow(), valueLabel: account.balance, label: 'credits_balance', disablePace: true };
|
|
61
61
|
account.windows.balance = window;
|
|
62
62
|
result.usage.windows[`${account.name} · ${q.kind} (${result.usage.accounts.length + 1})`] = window;
|
|
63
63
|
}
|
|
@@ -14,7 +14,8 @@ const isAllowedSsePath = (pathname) => {
|
|
|
14
14
|
const isAllowedWebSocketPath = (pathname) => {
|
|
15
15
|
return pathname === '/api/event/ws'
|
|
16
16
|
|| pathname === '/api/global/event/ws'
|
|
17
|
-
|| pathname === '/api/terminal/ws'
|
|
17
|
+
|| pathname === '/api/terminal/ws'
|
|
18
|
+
|| pathname === '/api/remote-desktop/ws';
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
const normalizeBaseUrl = (value) => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Remote desktop
|
|
2
|
+
|
|
3
|
+
## Ownership and supported runtimes
|
|
4
|
+
|
|
5
|
+
- `runtime.js` owns the authenticated `/api/remote-desktop/ws` session and `/api/remote-desktop` capability response. The routes are installed before the OpenCode proxy/SPA fallback.
|
|
6
|
+
- Electron injects a process-local adapter from `packages/electron/remote-desktop.mjs`. Only that Electron Host's physical primary display is captured, irrespective of which OpenCode/runtime the desktop window currently shows.
|
|
7
|
+
- The first native input adapter is macOS (Quartz events, Screen Recording and Accessibility consent). CLI/headless, Windows and Linux Hosts return `supported: false`, and WS upgrade returns 501. VS Code explicitly returns 501 rather than proxying these routes to OpenCode.
|
|
8
|
+
- Hosted mobile and Capacitor iOS/Android use the same receiving browser UI. No native WebRTC plugin, new dependency, separate desktop server, or OpenCode changes are required.
|
|
9
|
+
|
|
10
|
+
## Authorization and lifetime
|
|
11
|
+
|
|
12
|
+
Remote desktop is opt-in. The native-only approval store also owns an `enabled` Boolean that defaults false when missing or malformed; pre-existing device approvals do not imply the feature is enabled. `/api/remote-desktop` exposes `{ supported, enabled }`, and WS upgrades are rejected with 403 while disabled, before starting native consent or capture. The native adapter checks the preference independently. Only local main-frame desktop IPC can inspect setup permissions, change the switch, or request a fixed macOS permission pane. There is no HTTP endpoint to enable it remotely.
|
|
13
|
+
|
|
14
|
+
The local desktop Settings → Remote instances → Remote desktop group checks Screen Recording, Accessibility for the app and the actual helper executable, and helper installation. The helper's check-only mode posts no input events. Enabling requires all checks to pass and a successful atomic preference write. Closing the switch immediately ends active and pending native sessions. Failed disable persistence leaves the current app run blocked rather than restoring remote access; a restart may still load the old persisted preference, so the failure is visible and must be retried. Preferences and device IDs share the existing serialized native store without replacing each other. UI permission reads use Query, mutations refresh only their native setup/capability keys, stale runtime completions are rejected, and read failures preserve the last snapshot with explicit error feedback. Non-desktop and remote-runtime Settings cannot change local macOS grants. Unsupported desktop platforms show an unsupported state.
|
|
15
|
+
|
|
16
|
+
The WebSocket must authenticate a paired client or a real password-protected owner session. Password-less/forged owner cookies, loopback source, and raw bearer credentials in query parameters do not qualify. Browser sockets use the existing scoped `yuri_url_token`; the Host checks origin even when password auth is disabled. Both tunnel and URL-token allowlists include exactly `/api/remote-desktop/ws`. Desktop realtime proxying also permits this exact path. No Relay wire-frame types or crypto format change.
|
|
17
|
+
|
|
18
|
+
The first native session requires local confirmation on the Mac. The unchecked-by-default “Always allow this device” checkbox can persist approval for that authenticated client ID only, so later connections work unattended. Other devices and owner-cookie sessions still require confirmation. A dedicated Electron-owned `remote-desktop-approvals.json` stores at most 256 public client IDs, never tokens, in native userData; missing/malformed data does not authorize a device. Adding a new approval evicts the oldest when full, requiring that device to re-confirm. Writes reuse the serialized atomic settings store; failed writes close capture without claiming the approval was saved. The native sharing window can Stop or Forget device; Forget stops immediately and removes its approval. If removal fails, native error feedback directs the owner to revoke pairing. Remote client revocation remains authoritative and also prevents remembered approval from granting access.
|
|
19
|
+
|
|
20
|
+
There is one active or pending capture per Host. Closing the native sharing window also stops capture. Stopping the Host, closing the remote view/socket, backgrounding the phone, removing/changing a display, or a native failure stops the session. Client pings are every 5 seconds; 20 seconds without a ping ends the Host session. Active client revocation is checked every 5 seconds, failing closed on store failure. Maximum session length is one hour. Initial client startup has a 60-second deadline, capability requests a 10-second deadline, and native capture startup a 15-second deadline after the local approval.
|
|
21
|
+
|
|
22
|
+
Runtime generation/transport identity are captured when opening the view. No input or delayed auth result can connect to a different Host. Failure is not an empty success. Reconnection is explicit, not an unattended loop that repeatedly opens native permission dialogs. Closing a pending session aborts the local approval; a later startup completion is immediately disposed. EOF on the helper's pipe releases a held mouse button.
|
|
23
|
+
|
|
24
|
+
## Media and control
|
|
25
|
+
|
|
26
|
+
The isolated file-origin capture window uses Electron's `desktopCapturer` screen identity and Chromium's desktop `getUserMedia`, constrained to 1920×1080 and 30 fps. Chromium owns negotiated video codec and hardware acceleration; H.264 is not forced. A WebRTC offer/answer and trickle ICE pass over the authenticated WS. Media uses WebRTC DTLS-SRTP. Over Relay, the fingerprint-bearing signaling and control are also protected by the existing E2EE tunnel; media does not use Yuri's tunnel encryption format.
|
|
27
|
+
|
|
28
|
+
`YURI_REMOTE_DESKTOP_ICE_SERVERS` optionally supplies an RTCIceServer JSON array (maximum 8 entries). It is configured on the Desktop Host, not the Relay, and passed to both peers for that session. No external STUN service is contacted by default. Deployment-managed TURN credentials are visible to the paired receiving client as necessary for WebRTC and are never persisted or logged by this feature. Prefer short-lived credentials. A TURN credential minting service is not included.
|
|
29
|
+
|
|
30
|
+
If WebRTC fails, is unavailable, or produces no decoded video within 7 seconds of the answer, the client requests JPEG fallback through the existing runtime WS. This works over Relay without TURN. Fallback is at most 1440×900, JPEG quality 0.65, maximum 512 KiB per frame, and at most approximately 12 frames/second. Only one frame is outstanding: the receiver ACKs after image decode, and capture skips work until ACK. Thus effective frame rate also depends on RTT/encode/decode time; this is not a 30-fps WAN guarantee. WS buffering is capped at 512 KiB. The video fallback shares the connection with other Relay traffic.
|
|
31
|
+
|
|
32
|
+
The UI calls JPEG fallback “Compatibility stream”, not “Encrypted tunnel”: direct `ws://` transport is not E2EE. Use HTTPS/WSS for direct network connections and TLS for public Relay ingress. JPEG carried through Relay benefits from the existing endpoint-to-endpoint encrypted tunnel; a plain direct LAN connection does not acquire that property merely by using this feature.
|
|
33
|
+
|
|
34
|
+
Control always stays on the authenticated WS, including when video is P2P. `protocol.js` bounds and projects pointer coordinates, scroll deltas, text (1024 UTF-16 code units), key names, SDP (64 KiB), and ICE candidate fields. There is no arbitrary shell/keycode/file/clipboard API. WS messages are capped at 96 KiB; input is serialized with at most 32 queued commands and 150 messages/second. The native helper checks permission and active display again, and accepts only its own bounded JSON command vocabulary.
|
|
35
|
+
|
|
36
|
+
## Mobile interaction and performance
|
|
37
|
+
|
|
38
|
+
The Projects homepage plus menu ends with a Remote desktop icon/action after instance choices. The chat header overflow menu exposes the same action. `MobileApp` owns one open state, one shared handler and one `RemoteDesktopPanel`; the homepage receives that handler through `MobilePhoneShell` and its Projects container. Opening from chat closes the overflow menu without changing the chat/session route. Android Back dismisses the remote desktop before underlying navigation, and underlying root/header swipe navigation is blocked while it is open. The panel uses the current runtime, not a separately selected machine. Tap clicks, double tap is delivered as native double-click, drag moves a held mouse, and long press right-clicks. Scroll mode turns single-finger movement into scrolling. Two fingers zoom (1–5×) around their midpoint and pan the local viewport without sending mouse input. Switching from dragging to pinching releases the mouse; lifting one finger after pinching never generates a click. Letterboxing is excluded from coordinate mapping.
|
|
39
|
+
|
|
40
|
+
Pointer moves are coalesced to one animation-frame update, zoom transforms update the DOM directly, and frames do not enter a shared store or React state. Repeated transport state notifications are deduplicated. A memo boundary isolates the open panel from unrelated homepage streaming renders. Resize, close, cancellation and transport changes clear pending gestures. Text entry and common navigation keys are available below the screen.
|
|
41
|
+
|
|
42
|
+
## Validation and remaining platform gates
|
|
43
|
+
|
|
44
|
+
Focused tests cover message validation, real auth/origin gates, revocation, single ownership, delayed startup/abort, real Relay WS dispatch/fragmentation, runtime switching, decoded-frame ACK, coordinate mapping, pinch cancellation, and 50 unrelated homepage renders. The Electron evidence fixture runs the production capture page/preload with a synthetic canvas, a real Chromium WebRTC receiver and JPEG fallback; it does not capture or control the user's desktop. A separate local visual fixture was checked in Chromium at 390×844 and 844×390 using the production panel and synthetic screen data. That checks panel layout, not physical-phone rendering or real desktop capture.
|
|
45
|
+
|
|
46
|
+
Development-only native acceptance additionally exercised the production adapter and input helper against the real macOS desktop: JPEG frames decoded at 1440×810, and a fixed 26-character test string reached an isolated test textarea through Quartz input. The focused test window reported native/window/DOM keyboard focus. An earlier run received frames but not the text; that run did not measure focus and its cause is unresolved. This is not yet a repeatability guarantee. No real screen images or user-entered text were retained. The permission probe returned granted Screen Recording and Accessibility when Electron was started through macOS Launch Services; starting the same executable as a shell child reported denied/untrusted. Permission checks must be made under the actual launch context rather than inferred from the app's path or a Settings toggle.
|
|
47
|
+
|
|
48
|
+
Additional local checks confirmed new capture can start while the Mac remains locked (108 non-black JPEG frames), and the user reported the one-shot dummy password input test succeeded; no login was submitted. Transitioning an existing capture into lock still ended the session, and a later transition trace timed out awaiting local consent. These are distinct outcomes: locked capture/input is not evidence that lock/unlock transitions or correct-password unlocking are reliable.
|
|
49
|
+
|
|
50
|
+
The native setup adapter was also exercised via Launch Services with real app/helper permissions: it reported default-off, all required permissions granted, then enabled and disabled correctly using a test-only in-memory preference store. The production Settings group was visually checked at 900px and 350px widths using simulated native status; that does not prove release-signed IPC/permission onboarding. Focused tests cover disabled authenticated upgrades, native default-off, enable checks and failed writes, pending approval cancellation, active-session stop, local-only IPC classification, setup UI guidance and failed refresh preservation.
|
|
51
|
+
|
|
52
|
+
These tests do **not** prove macOS TCC permission inheritance for a release-signed helper, successful password-based unlocking, reliable lock/unlock transitions, iPhone WKWebView playback/gestures, WAN codec negotiation, throughput, battery or latency. Before shipping, verify those on a signed preview installer and a physical phone, including permission denial/regrant, display changes, disconnect while dragging, direct connection, Relay-only fallback and optional TURN. Native main/preload/helper changes require a new desktop installer; UI OTA alone cannot provide them.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const KEYS = new Set(['Enter', 'Backspace', 'Tab', 'Escape', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Delete', 'Home', 'End', 'PageUp', 'PageDown']);
|
|
2
|
+
const unit = (n) => typeof n === 'number' && Number.isFinite(n) && n >= 0 && n <= 1;
|
|
3
|
+
|
|
4
|
+
export function parseDesktopMessage(value) {
|
|
5
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('invalid_message');
|
|
6
|
+
const { type } = value;
|
|
7
|
+
if (type === 'ack' || type === 'fallback' || type === 'ping' || type === 'release') return { type };
|
|
8
|
+
if (type === 'answer' && typeof value.sdp === 'string' && value.sdp.length <= 65536) return { type, sdp: value.sdp };
|
|
9
|
+
if (type === 'ice' && (value.candidate === null || (typeof value.candidate === 'object'
|
|
10
|
+
&& typeof value.candidate.candidate === 'string' && value.candidate.candidate.length <= 2048))) {
|
|
11
|
+
return { type, candidate: value.candidate === null ? null : {
|
|
12
|
+
candidate: value.candidate.candidate,
|
|
13
|
+
sdpMid: typeof value.candidate.sdpMid === 'string' ? value.candidate.sdpMid.slice(0, 128) : null,
|
|
14
|
+
sdpMLineIndex: Number.isInteger(value.candidate.sdpMLineIndex) ? value.candidate.sdpMLineIndex : null,
|
|
15
|
+
} };
|
|
16
|
+
}
|
|
17
|
+
if (type === 'pointer' && ['move', 'down', 'up', 'click', 'right'].includes(value.action) && unit(value.x) && unit(value.y)) {
|
|
18
|
+
return { type, action: value.action, x: value.x, y: value.y };
|
|
19
|
+
}
|
|
20
|
+
if (type === 'scroll' && Number.isFinite(value.dx) && Number.isFinite(value.dy)) {
|
|
21
|
+
return { type, dx: Math.max(-1000, Math.min(1000, value.dx)), dy: Math.max(-1000, Math.min(1000, value.dy)) };
|
|
22
|
+
}
|
|
23
|
+
if (type === 'text' && typeof value.text === 'string' && value.text.length > 0 && value.text.length <= 1024) return { type, text: value.text };
|
|
24
|
+
if (type === 'key' && KEYS.has(value.key)) return { type, key: value.key };
|
|
25
|
+
throw new Error('invalid_message');
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { parseDesktopMessage } from './protocol.js';
|
|
3
|
+
|
|
4
|
+
it.each([null, [], {}, { type: 'exec', command: 'something' }, { type: 'text', text: 'x'.repeat(1025) },
|
|
5
|
+
{ type: 'key', key: 'arbitrary' }, { type: 'pointer', action: 'down', x: NaN, y: 0 },
|
|
6
|
+
{ type: 'pointer', action: 'click', x: 2, y: 0 }, { type: 'scroll', dx: Infinity, dy: 0 },
|
|
7
|
+
{ type: 'answer', sdp: 'x'.repeat(65537) }, { type: 'ice', candidate: { candidate: 'x'.repeat(2049) } },
|
|
8
|
+
])('rejects invalid or oversized messages %#', value => {
|
|
9
|
+
expect(() => parseDesktopMessage(value)).toThrow('invalid_message');
|
|
10
|
+
});
|
|
11
|
+
it('projects only permitted fields and bounds scroll and input', () => {
|
|
12
|
+
expect(parseDesktopMessage({ type: 'pointer', action: 'down', x: 0.2, y: 0.7, command: 'ignored' })).toEqual({ type: 'pointer', action: 'down', x: 0.2, y: 0.7 });
|
|
13
|
+
expect(parseDesktopMessage({ type: 'scroll', dx: -2000, dy: 5000 })).toEqual({ type: 'scroll', dx: -1000, dy: 1000 });
|
|
14
|
+
expect(parseDesktopMessage({ type: 'text', text: '中文🙂' })).toEqual({ type: 'text', text: '中文🙂' });
|
|
15
|
+
expect(parseDesktopMessage({ type: 'ice', candidate: { candidate: 'candidate:test', sdpMid: '0', sdpMLineIndex: 0, unexpected: 'ignored' } })).toEqual({
|
|
16
|
+
type: 'ice', candidate: { candidate: 'candidate:test', sdpMid: '0', sdpMLineIndex: 0 },
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { WebSocketServer } from 'ws';
|
|
2
|
+
import { parseDesktopMessage } from './protocol.js';
|
|
3
|
+
|
|
4
|
+
const REMOTE_DESKTOP_WS_PATH = '/api/remote-desktop/ws';
|
|
5
|
+
|
|
6
|
+
export function attachRemoteDesktop({ app, server, adapter, uiAuthController, isRequestOriginAllowed, isClientActive = async () => true }) {
|
|
7
|
+
const wss = new WebSocketServer({ noServer: true, maxPayload: 96 * 1024, perMessageDeflate: false });
|
|
8
|
+
let stopping = false;
|
|
9
|
+
let occupied = false;
|
|
10
|
+
const reject = (socket, code) => {
|
|
11
|
+
if (!socket.destroyed) socket.end(`HTTP/1.1 ${code} Rejected\r\nConnection: close\r\nContent-Length: 0\r\n\r\n`, () => socket.destroy());
|
|
12
|
+
};
|
|
13
|
+
app.get('/api/remote-desktop', (_req, res) => {
|
|
14
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
15
|
+
res.json({ supported: adapter?.supported === true, enabled: adapter?.enabled === true });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
wss.on('connection', (ws, req, auth) => {
|
|
19
|
+
let session;
|
|
20
|
+
let closed = false;
|
|
21
|
+
let lastPing = Date.now();
|
|
22
|
+
let count = 0;
|
|
23
|
+
let windowStart = Date.now();
|
|
24
|
+
const startedAt = Date.now();
|
|
25
|
+
let queued = 0;
|
|
26
|
+
let chain = Promise.resolve();
|
|
27
|
+
const abort = new AbortController();
|
|
28
|
+
const send = (value) => {
|
|
29
|
+
if (closed || ws.readyState !== 1 || ws.bufferedAmount > 512 * 1024) return false;
|
|
30
|
+
ws.send(Buffer.isBuffer(value) ? value : JSON.stringify(value));
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
const close = () => {
|
|
34
|
+
if (closed) return;
|
|
35
|
+
closed = true;
|
|
36
|
+
abort.abort();
|
|
37
|
+
clearInterval(timer);
|
|
38
|
+
// Keep the slot until asynchronous startup/consent has finished cleaning up.
|
|
39
|
+
if (session) { session.close(); occupied = false; }
|
|
40
|
+
};
|
|
41
|
+
const fail = (code) => {
|
|
42
|
+
send({ type: 'error', code });
|
|
43
|
+
ws.close(1011, code);
|
|
44
|
+
close();
|
|
45
|
+
};
|
|
46
|
+
const timer = setInterval(() => {
|
|
47
|
+
if (Date.now() - lastPing > 20000 || Date.now() - startedAt > 60 * 60 * 1000) { ws.terminate(); close(); return; }
|
|
48
|
+
if (auth.type === 'client') void isClientActive(auth.clientId ?? auth.client?.id).then((active) => {
|
|
49
|
+
if (!active) { ws.close(4001, 'authentication_required'); close(); }
|
|
50
|
+
}).catch(() => { ws.terminate(); close(); });
|
|
51
|
+
}, 5000);
|
|
52
|
+
timer.unref?.();
|
|
53
|
+
ws.on('close', close);
|
|
54
|
+
ws.on('error', close);
|
|
55
|
+
ws.on('message', (data, binary) => {
|
|
56
|
+
if (closed) return;
|
|
57
|
+
if (Date.now() - windowStart >= 1000) { count = 0; windowStart = Date.now(); }
|
|
58
|
+
if (binary || ++count > 150 || queued >= 32) { fail('rate_limited'); return; }
|
|
59
|
+
let message;
|
|
60
|
+
try { message = parseDesktopMessage(JSON.parse(data.toString())); }
|
|
61
|
+
catch { fail('invalid_message'); return; }
|
|
62
|
+
if (message.type === 'ping') { lastPing = Date.now(); send({ type: 'pong' }); return; }
|
|
63
|
+
queued++;
|
|
64
|
+
chain = chain.then(async () => {
|
|
65
|
+
await start;
|
|
66
|
+
if (!closed && session) await session.handle(message);
|
|
67
|
+
}).catch(() => fail('desktop_failed')).finally(() => { queued--; });
|
|
68
|
+
});
|
|
69
|
+
const start = (async () => {
|
|
70
|
+
try {
|
|
71
|
+
session = await adapter.start({ send, onEnded: () => fail('desktop_ended'), signal: abort.signal,
|
|
72
|
+
client: auth.type === 'client' ? { id: auth.clientId ?? auth.client?.id, label: auth.client?.label ?? '' } : null });
|
|
73
|
+
if (closed) { session.close(); occupied = false; }
|
|
74
|
+
} catch (error) {
|
|
75
|
+
occupied = false;
|
|
76
|
+
fail(['disabled', 'permission_required', 'permission_denied', 'unsupported', 'helper_unavailable'].includes(error.code) ? error.code : 'desktop_failed');
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
void start;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const upgrade = (req, socket, head) => {
|
|
83
|
+
let pathname;
|
|
84
|
+
try { pathname = new URL(req.url, 'http://localhost').pathname; } catch { return; }
|
|
85
|
+
if (pathname !== REMOTE_DESKTOP_WS_PATH) return;
|
|
86
|
+
void (async () => {
|
|
87
|
+
try {
|
|
88
|
+
const auth = await uiAuthController.resolveAuthContext(req, null, { allowClientAuth: true, allowUrlToken: true });
|
|
89
|
+
// Password-less owner cookies are not authentication. Relay loopback is not trusted.
|
|
90
|
+
if (!auth || (auth.type !== 'client' && !uiAuthController.enabled)) return reject(socket, 401);
|
|
91
|
+
if (!await isRequestOriginAllowed(req)) return reject(socket, 403);
|
|
92
|
+
if (!adapter?.supported) return reject(socket, 501);
|
|
93
|
+
if (adapter.enabled !== true) return reject(socket, 403);
|
|
94
|
+
if (stopping || occupied) return reject(socket, 409);
|
|
95
|
+
if (socket.destroyed) return;
|
|
96
|
+
occupied = true;
|
|
97
|
+
try { wss.handleUpgrade(req, socket, head, (ws) => wss.emit('connection', ws, req, auth)); }
|
|
98
|
+
catch { occupied = false; socket.destroy(); }
|
|
99
|
+
} catch { reject(socket, 401); }
|
|
100
|
+
})();
|
|
101
|
+
};
|
|
102
|
+
server.on('upgrade', upgrade);
|
|
103
|
+
return {
|
|
104
|
+
stop() {
|
|
105
|
+
stopping = true;
|
|
106
|
+
server.off('upgrade', upgrade);
|
|
107
|
+
for (const ws of wss.clients) ws.terminate();
|
|
108
|
+
wss.close();
|
|
109
|
+
adapter?.stop?.();
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import { once } from 'node:events';
|
|
5
|
+
import * as fsPromises from 'node:fs/promises';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import crypto from 'node:crypto';
|
|
9
|
+
import { WebSocket } from 'ws';
|
|
10
|
+
import request from 'supertest';
|
|
11
|
+
import { createUiAuth } from '../ui-auth/ui-auth.js';
|
|
12
|
+
import { createRemoteClientAuthRuntime } from '../client-auth/remote-clients.js';
|
|
13
|
+
import { createRequestSecurityRuntime } from '../security/request-security.js';
|
|
14
|
+
import { createTunnelHost } from '../relay/tunnel-host.js';
|
|
15
|
+
import { createFragmentAssembler, decodeTunnelFrame, encodeJsonPayload, encodeTunnelFrame, TunnelFrameType } from '../relay/tunnel-codec.js';
|
|
16
|
+
import { attachRemoteDesktop } from './runtime.js';
|
|
17
|
+
|
|
18
|
+
let root, auth, clients, client, server, port, adapter, runtime, token;
|
|
19
|
+
const sockets = new Set();
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
root = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'remote-desktop-test-'));
|
|
22
|
+
clients = createRemoteClientAuthRuntime({ fsPromises, path, crypto, storePath: path.join(root, 'clients.json') });
|
|
23
|
+
client = await clients.createClient({ label: 'Test device', clientKind: 'mobile' });
|
|
24
|
+
auth = createUiAuth({ password: null, clientAuthController: clients, readSettingsFromDiskMigrated: async () => ({}) });
|
|
25
|
+
const security = createRequestSecurityRuntime({ readSettingsFromDiskMigrated: async () => ({}) });
|
|
26
|
+
const app = express();
|
|
27
|
+
app.post('/auth/url-token', auth.handleUrlAuthToken);
|
|
28
|
+
app.use(auth.requireAuth);
|
|
29
|
+
adapter = { supported: true, enabled: true, start: vi.fn(async ({ send }) => {
|
|
30
|
+
send({ type: 'ready', width: 1600, height: 900 });
|
|
31
|
+
return { handle: vi.fn(), close: vi.fn() };
|
|
32
|
+
}), stop: vi.fn() };
|
|
33
|
+
server = http.createServer(app);
|
|
34
|
+
runtime = attachRemoteDesktop({ app, server, adapter, uiAuthController: auth, isRequestOriginAllowed: security.isRequestOriginAllowed,
|
|
35
|
+
isClientActive: async id => (await clients.listClients()).some(entry => entry.id === id && !entry.revokedAt) });
|
|
36
|
+
server.listen(0, '127.0.0.1'); await once(server, 'listening'); port = server.address().port;
|
|
37
|
+
const minted = await request(app).post('/auth/url-token').set('Authorization', `Bearer ${client.token}`);
|
|
38
|
+
expect(minted.status).toBe(200);
|
|
39
|
+
token = minted.body.token;
|
|
40
|
+
});
|
|
41
|
+
afterEach(async () => {
|
|
42
|
+
for (const ws of sockets) ws.terminate(); sockets.clear();
|
|
43
|
+
runtime.stop(); auth.dispose();
|
|
44
|
+
await new Promise(resolve => server.close(resolve));
|
|
45
|
+
await fsPromises.rm(root, { recursive: true, force: true });
|
|
46
|
+
});
|
|
47
|
+
function socket(query = `?yuri_url_token=${encodeURIComponent(token)}`, headers = {}) {
|
|
48
|
+
const ws = new WebSocket(`ws://127.0.0.1:${port}/api/remote-desktop/ws${query}`, { headers: { Origin: `http://127.0.0.1:${port}`, ...headers } });
|
|
49
|
+
ws.on('error', () => {}); sockets.add(ws); return ws;
|
|
50
|
+
}
|
|
51
|
+
async function rejected(ws) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
ws.on('unexpected-response', (_req, res) => { res.resume(); ws.terminate(); resolve(res.statusCode); });
|
|
54
|
+
ws.on('open', () => reject(new Error('Upgrade unexpectedly allowed')));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
it('uses real auth and origin gates, refusing forged owner cookies, bearer query strings and hostile origins', async () => {
|
|
58
|
+
expect(await rejected(socket('', { Cookie: 'yuri_ui_session=forged' }))).toBe(401);
|
|
59
|
+
expect(await rejected(socket(`?yuri_url_token=${client.token}`))).toBe(401);
|
|
60
|
+
expect(await rejected(socket(undefined, { Origin: 'https://attacker.example' }))).toBe(403);
|
|
61
|
+
expect(adapter.start).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('refuses even authenticated devices while the native Host is disabled', async () => {
|
|
65
|
+
adapter.enabled = false;
|
|
66
|
+
expect(await rejected(socket())).toBe(403);
|
|
67
|
+
expect(adapter.start).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
it('allows a scoped device, handles input and pong, rejects simultaneous control, and cleans up on disconnect', async () => {
|
|
70
|
+
const ws = socket(); await once(ws, 'open');
|
|
71
|
+
await vi.waitFor(() => expect(adapter.start).toHaveBeenCalledTimes(1));
|
|
72
|
+
const desktop = await adapter.start.mock.results[0].value;
|
|
73
|
+
ws.send(JSON.stringify({ type: 'pointer', action: 'click', x: 0.4, y: 0.6 }));
|
|
74
|
+
await vi.waitFor(() => expect(desktop.handle).toHaveBeenCalledWith({ type: 'pointer', action: 'click', x: 0.4, y: 0.6 }));
|
|
75
|
+
const pong = once(ws, 'message'); ws.send('{"type":"ping"}');
|
|
76
|
+
expect(JSON.parse((await pong)[0].toString()).type).toBe('pong');
|
|
77
|
+
expect(await rejected(socket())).toBe(409);
|
|
78
|
+
ws.close(); await once(ws, 'close');
|
|
79
|
+
await vi.waitFor(() => expect(desktop.close).toHaveBeenCalledOnce());
|
|
80
|
+
});
|
|
81
|
+
it('keeps an early SDP answer until asynchronous capture startup finishes', async () => {
|
|
82
|
+
let finish;
|
|
83
|
+
const handle = vi.fn();
|
|
84
|
+
adapter.start.mockImplementation(({ send }) => {
|
|
85
|
+
send({ type: 'offer', sdp: 'offer' });
|
|
86
|
+
return new Promise(resolve => { finish = () => resolve({ handle, close: vi.fn() }); });
|
|
87
|
+
});
|
|
88
|
+
const ws = socket(); await once(ws, 'open');
|
|
89
|
+
ws.send('{"type":"answer","sdp":"answer"}');
|
|
90
|
+
await vi.waitFor(() => expect(finish).toBeDefined()); finish();
|
|
91
|
+
await vi.waitFor(() => expect(handle).toHaveBeenCalledWith({ type: 'answer', sdp: 'answer' }));
|
|
92
|
+
});
|
|
93
|
+
it('aborts pending native consent on disconnect and frees the single capture slot', async () => {
|
|
94
|
+
let signal;
|
|
95
|
+
adapter.start.mockImplementation(options => {
|
|
96
|
+
signal = options.signal;
|
|
97
|
+
return new Promise((_resolve, reject) => signal.addEventListener('abort', () => reject(new Error('cancelled'))));
|
|
98
|
+
});
|
|
99
|
+
const ws = socket(); await once(ws, 'open'); ws.close(); await once(ws, 'close');
|
|
100
|
+
await vi.waitFor(() => expect(signal.aborted).toBe(true));
|
|
101
|
+
adapter.start.mockResolvedValue({ handle: vi.fn(), close: vi.fn() });
|
|
102
|
+
const next = socket(); await once(next, 'open');
|
|
103
|
+
});
|
|
104
|
+
it('stops native control when the device is revoked', { timeout: 10000 }, async () => {
|
|
105
|
+
const ws = socket(); await once(ws, 'open');
|
|
106
|
+
const closed = once(ws, 'close');
|
|
107
|
+
await clients.revokeClient(client.client.id);
|
|
108
|
+
expect((await closed)[0]).toBe(4001);
|
|
109
|
+
const desktop = await adapter.start.mock.results[0].value;
|
|
110
|
+
expect(desktop.close).toHaveBeenCalledOnce();
|
|
111
|
+
});
|
|
112
|
+
it('carries screen frames and validated input through the real Relay WS dispatcher and auth gates', async () => {
|
|
113
|
+
const frames = [];
|
|
114
|
+
const host = createTunnelHost({ connectionId: 'desktop-test', getLocalPort: () => port,
|
|
115
|
+
sendFrame: frame => { frames.push(decodeTunnelFrame(frame)); }, getBufferedAmount: () => 0 });
|
|
116
|
+
try {
|
|
117
|
+
await host.handleFrame(encodeTunnelFrame(TunnelFrameType.WsOpen, 2, encodeJsonPayload({ path: '/api/remote-desktop/ws', query: `yuri_url_token=${token}` })));
|
|
118
|
+
await vi.waitFor(() => expect(frames.some(frame => frame.frameType === TunnelFrameType.WsOpened)).toBe(true));
|
|
119
|
+
await host.handleFrame(encodeTunnelFrame(TunnelFrameType.WsText, 2, Buffer.from('{"type":"key","key":"Enter"}')));
|
|
120
|
+
const desktop = await adapter.start.mock.results[0].value;
|
|
121
|
+
await vi.waitFor(() => expect(desktop.handle).toHaveBeenCalledWith({ type: 'key', key: 'Enter' }));
|
|
122
|
+
const jpeg = Buffer.alloc(200000, 17);
|
|
123
|
+
adapter.start.mock.calls[0][0].send(jpeg);
|
|
124
|
+
let reassembled;
|
|
125
|
+
await vi.waitFor(() => {
|
|
126
|
+
const fresh = createFragmentAssembler();
|
|
127
|
+
for (const frame of frames.filter(frame => frame.frameType === TunnelFrameType.WsBinary)) {
|
|
128
|
+
const complete = fresh.push(frame);
|
|
129
|
+
if (complete) reassembled = complete;
|
|
130
|
+
}
|
|
131
|
+
expect(reassembled?.byteLength).toBe(jpeg.length);
|
|
132
|
+
});
|
|
133
|
+
expect(Buffer.from(reassembled)).toEqual(jpeg);
|
|
134
|
+
} finally { host.close(); }
|
|
135
|
+
});
|
|
@@ -111,7 +111,8 @@ the inference input. Clean inference does not use the Session context builder.
|
|
|
111
111
|
`{ buildOpenCodeUrl, getOpenCodeAuthHeaders, persistSessionMetadata,
|
|
112
112
|
onSystemSessionPersisted }` into the factory (and the service into session
|
|
113
113
|
assist/title/goal, scheduled tasks, and `createFeatureRoutesRuntime`). Server
|
|
114
|
-
`stop()` calls `stopLlmBridgeDirectory()` to
|
|
114
|
+
`stop()` calls `stopLlmBridgeDirectory()` to forget the isolated plugin directory;
|
|
115
|
+
the content-addressed directory is shared across hosts and is not deleted.
|
|
115
116
|
|
|
116
117
|
## Summary AI settings
|
|
117
118
|
|
|
@@ -8,6 +8,8 @@ Trusted-device access has one durable credential model: a remote client bearer t
|
|
|
8
8
|
Pairing v2 is implemented by `packages/web/server/lib/client-auth/pairing.js`. It stores short-lived one-time pairing sessions with hashed secrets, exposes create/cancel/redeem routes under `/api/client-auth/pairing/*`, and redeems a valid pairing secret into the same remote client token used by password/passkey trusted-device flows.
|
|
9
9
|
|
|
10
10
|
## Entrypoints and structure
|
|
11
|
+
|
|
12
|
+
Remote desktop uses the exact `/api/remote-desktop/ws` scoped URL-token path, mirrored in the Relay tunnel allowlist. Its own upgrade gate additionally rejects password-less owner cookies and checks origin even when password auth is disabled; see `../remote-desktop/DOCUMENTATION.md`.
|
|
11
13
|
- `packages/web/server/lib/ui-auth/ui-auth.js`: UI auth controller runtime, cookie/session issuance, rate limiting, and auth route handlers.
|
|
12
14
|
- `packages/web/server/lib/ui-auth/ui-passkeys.js`: passkey store and WebAuthn registration/authentication verification helpers.
|
|
13
15
|
- `packages/web/server/lib/client-auth/remote-clients.js`: trusted-device client token storage, bearer authentication, last-used tracking, and revocation.
|
|
@@ -318,7 +318,8 @@ export const isUrlAuthWebSocketPath = (pathname) => {
|
|
|
318
318
|
return pathname === '/api/event/ws'
|
|
319
319
|
|| pathname === '/api/global/event/ws'
|
|
320
320
|
|| pathname === '/api/yuri/realtime-proxy/ws'
|
|
321
|
-
|
|
321
|
+
|| pathname === '/api/terminal/ws'
|
|
322
|
+
|| pathname === '/api/remote-desktop/ws'
|
|
322
323
|
|| pathname === '/api/dictation/ws'
|
|
323
324
|
|| pathname.startsWith('/api/preview/proxy/');
|
|
324
325
|
};
|