@yuriai/web 0.2.27-beta.2 → 0.2.27-beta.6
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 +9 -0
- package/dist/assets/{AgentAvatar-BW4Zg8bo.js → AgentAvatar-Bi1vvWPC.js} +1 -1
- package/dist/assets/AssistantContactStatus-CWq-PDz6.js +3 -0
- package/dist/assets/AssistantUnreadBadge-DdJyySwn.js +1 -0
- package/dist/assets/AssistantView-Br1iETTs.js +1 -0
- package/dist/assets/{DiagramView-D6wdXRzu.js → DiagramView-CI4bTtxy.js} +1 -1
- package/dist/assets/{FadeInOnReveal-gOsILpSk.js → FadeInOnReveal-BB4qEnAn.js} +1 -1
- package/dist/assets/GuiPluginSurface-CguxFUbM.js +1 -0
- package/dist/assets/{GuiPluginWindow-tGvc4_0g.js → GuiPluginWindow-DOJ7wuRH.js} +1 -1
- package/dist/assets/Icon-t2xvbAyN.js +1 -0
- package/dist/assets/{ImageLoadingPlaceholder-9xYbKqtf.js → ImageLoadingPlaceholder-D1L13TK0.js} +1 -1
- package/dist/assets/{LoadingImage-CiOcKPfb.js → LoadingImage-5rY_edNm.js} +1 -1
- package/dist/assets/{MarkdownRenderer-DZkP4UNr.js → MarkdownRenderer-BlGxjOei.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-BXzPUEEo.js → MarkdownRendererImpl-cE-0AYRg.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-B-NWd069.js → MarkstreamRendererImpl-BZyqDl82.js} +1 -1
- package/dist/assets/MobileDetailNavigation-tbfsMfB-.js +1 -0
- package/dist/assets/{MobileResizableSheet-ZL-zPa3W.js → MobileResizableSheet-BeRmT6_x.js} +1 -1
- package/dist/assets/{MobileShareBridge-JSH_Y8Ps.js → MobileShareBridge-C3Equ3P_.js} +2 -2
- package/dist/assets/MobileTabPageHeader-DQRqAAEf.js +2 -0
- package/dist/assets/{MultiRunWindow-ZPz62Aqg.js → MultiRunWindow-CAM2XPII.js} +1 -1
- package/dist/assets/{OnboardingScreen-BQNoy9o1.js → OnboardingScreen-4ftRerP5.js} +1 -1
- package/dist/assets/{OverlayScrollbar-BwCFalSw.js → OverlayScrollbar-CF0PCvQz.js} +1 -1
- package/dist/assets/{SettingsView-B17qt8dh.js → SettingsView-2tk4WH7R.js} +15 -15
- package/dist/assets/{SettingsWindow-CIFNHb-F.js → SettingsWindow-B9zbeJaW.js} +1 -1
- package/dist/assets/TerminalView-DfxvTHye.js +8 -0
- package/dist/assets/{ToolOutputDialog-BKuVpgEu.js → ToolOutputDialog-CrjDIhru.js} +1 -1
- package/dist/assets/{YuriLogo-C1Ty-RTB.js → YuriLogo-QvS1ZEHi.js} +1 -1
- package/dist/assets/{appThemeRegistry-DqGuzMaH.js → appThemeRegistry-Bb_DtiV9.js} +1 -1
- package/dist/assets/{button-DuHjvKJJ.js → button-DinGM3tu.js} +1 -1
- package/dist/assets/{capgoAdapter-B-tddboe.js → capgoAdapter-DufzjXRs.js} +1 -1
- package/dist/assets/{collapsible-B8eL5nLo.js → collapsible-Bh1GLNYV.js} +1 -1
- package/dist/assets/context-menu-DpbkRkk1.js +1 -0
- package/dist/assets/{diagram-ChoQDKzy.js → diagram-BmG-7Jb4.js} +1 -1
- package/dist/assets/{dialog-CVhqZux0.js → dialog-BXssfGXA.js} +1 -1
- package/dist/assets/es-HP_Ise0X.js +15 -0
- package/dist/assets/{fileMentionTouchSelection-Dd-iSIe2.js → fileMentionTouchSelection-DSl0tj2r.js} +1 -1
- package/dist/assets/{fileReferenceActions-BAoEu4z8.js → fileReferenceActions-CGpBSFq4.js} +1 -1
- package/dist/assets/fr-D0kJXJ6U.js +13 -0
- package/dist/assets/gitApi-Wo0IZow9.js +370 -0
- package/dist/assets/{gitApiHttp-DHrRqnYh.js → gitApiHttp-De9liKnG.js} +4 -4
- package/dist/assets/host-FR_grJxM.js +1 -0
- package/dist/assets/{input-E_oYiXZT.js → input-v8-rVbo-.js} +1 -1
- package/dist/assets/insertionBoundaries-CZz7TWJv.js +1 -0
- package/dist/assets/ja-BjHKXazE.js +15 -0
- package/dist/assets/ko-Llwnl876.js +15 -0
- package/dist/assets/main-Bp9HHqTr.js +2 -0
- package/dist/assets/main-DOwAfmxJ.js +169 -0
- package/dist/assets/{markdownHeightCache-heNXHdzb.js → markdownHeightCache-BVV2dktw.js} +1 -1
- package/dist/assets/{mcpQueries-BqKVe4Su.js → mcpQueries-BoBrB4a4.js} +1 -1
- package/dist/assets/miniChat-BJDgCrfF.js +2 -0
- package/dist/assets/mobile-GM9931J_.js +2 -0
- package/dist/assets/{mobileBackNavigation-DHxFQ7SY.js → mobileBackNavigation-DMSzAvb6.js} +1 -1
- package/dist/assets/{multirun-CPOzaEQj.js → multirun-BhWttsRQ.js} +1 -1
- package/dist/assets/{native-De1DIkLZ.js → native-DSvNnKAm.js} +1 -1
- package/dist/assets/{native-config-oauL2ekt.js → native-config-DjdrW_9n.js} +1 -1
- package/dist/assets/{persistence-JyLTFv27.js → persistence-CfrHIiIS.js} +1 -1
- package/dist/assets/pl-BOd_idqn.js +15 -0
- package/dist/assets/{projectMeta-YDMdD3AP.js → projectMeta-31PobC-M.js} +1 -1
- package/dist/assets/pt-BR-B8djxMsl.js +15 -0
- package/dist/assets/react-B9v0P7kT.js +1 -0
- package/dist/assets/{readiness-BveVUOIb.js → readiness-CYNnsekT.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-N2r999Bf.js +2 -0
- package/dist/assets/renderMobileApp-CU1ec6Ak.js +28 -0
- package/dist/assets/{runtimeConfig-BpcgdIV9.js → runtimeConfig-Db7yfo6L.js} +1 -1
- package/dist/assets/runtimeEndpointReset-DO5WVetV.js +149 -0
- package/dist/assets/scheduledTaskNavigation-Bsrhv3Ow.js +1 -0
- package/dist/assets/sessionLookup-DRVy7LM1.js +1 -0
- package/dist/assets/sortable-tabs-strip-yKyqsqut.js +1 -0
- package/dist/assets/speechSettingsQueries-DU25rmGc.js +4 -0
- package/dist/assets/src-Bckdo2XS.css +2 -0
- package/dist/assets/store-CUBymvAC.js +15 -0
- package/dist/assets/{terminalApi-B5o8UqWA.js → terminalApi-BblSkqch.js} +1 -1
- package/dist/assets/{textarea-DmKaqHSb.js → textarea-B39OCNPV.js} +1 -1
- package/dist/assets/{tooltip-DUKu4nC6.js → tooltip-d8TNN4lx.js} +1 -1
- package/dist/assets/{types-DRTMRW4R.js → types-BqFQhQTt.js} +1 -1
- package/dist/assets/{uk-CYZXWdd7.js → uk-BNd7CjVO.js} +4 -4
- package/dist/assets/{useAppFontEffects-BiQf6tgZ.js → useAppFontEffects-BVoVpJYO.js} +57 -55
- package/dist/assets/{useAssistantUIStore-C9FPlYQz.js → useAssistantUIStore-Bp6TxG5E.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-CYx1LNO5.js +1 -0
- package/dist/assets/{useEffectiveDirectory-B8q00InF.js → useEffectiveDirectory-D8FFE5Yn.js} +1 -1
- package/dist/assets/{useFontPreferences-DMiP_Yy-.js → useFontPreferences-BFyBjtQ6.js} +1 -1
- package/dist/assets/useMobileNavigationStore-BHMFeMjo.js +23 -0
- package/dist/assets/useUIStore-BbYD420L.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-B6lWNk01.js → useWorkerHighlightedLines-CPxG8Fya.js} +1 -1
- package/dist/assets/{vendor-codemirror-search-ZqtrPLjU.js → vendor-codemirror-search-DiPwvA-6.js} +2 -2
- package/dist/assets/{vendor-opencode-plugin-Bw7Q6Nv9.js → vendor-opencode-plugin-CgKz9Hcy.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-DDj0dSVY.js → vendor-replit-codemirror-vim-DCdAdxvE.js} +3 -3
- package/dist/assets/zh-CN-BkTAEOZG.js +15 -0
- package/dist/assets/zh-TW-x8SfMzfc.js +15 -0
- package/dist/index.html +10 -10
- package/dist/mini-chat.html +10 -10
- package/dist/mobile.html +10 -10
- package/package.json +3 -3
- package/server/lib/assistants/DOCUMENTATION.md +30 -0
- package/server/lib/assistants/contact-store.js +16 -0
- package/server/lib/assistants/contact-store.test.js +19 -0
- package/server/lib/assistants/contracts.js +1 -0
- package/server/lib/assistants/routes.js +25 -3
- package/server/lib/assistants/service.js +30 -8
- package/server/lib/assistants/service.test.js +151 -0
- package/server/lib/assistants/weixin/DOCUMENTATION.md +199 -0
- package/server/lib/assistants/weixin/api.js +113 -0
- package/server/lib/assistants/weixin/api.test.js +80 -0
- package/server/lib/assistants/weixin/routes.js +24 -0
- package/server/lib/assistants/weixin/routes.test.js +71 -0
- package/server/lib/assistants/weixin/runtime.js +426 -0
- package/server/lib/assistants/weixin/runtime.test.js +500 -0
- package/server/lib/assistants/weixin/store.js +116 -0
- package/server/lib/assistants/weixin/typing.js +88 -0
- package/server/lib/assistants/weixin/typing.test.js +185 -0
- package/server/lib/opencode/DOCUMENTATION.md +2 -1
- package/server/lib/opencode/npm-registry.js +7 -21
- package/server/lib/opencode/npm-registry.test.js +36 -5
- package/server/lib/opencode/plugin-icon.d.ts +2 -0
- package/server/lib/opencode/plugin-icon.js +43 -0
- package/server/lib/opencode/plugin-icon.test.js +41 -0
- package/server/lib/opencode/plugin-routes.js +3 -1
- package/server/lib/opencode/plugin-routes.test.js +13 -0
- package/server/lib/opencode/shutdown-runtime.js +1 -1
- package/server/lib/opencode/shutdown-runtime.test.js +12 -0
- package/dist/assets/AssistantView-Cl0ZeXwr.js +0 -3
- package/dist/assets/GuiPluginSurface-DOZAQKX0.js +0 -1
- package/dist/assets/Icon-DvUDsV1z.js +0 -1
- package/dist/assets/MobileDetailNavigation-5U28hfYf.js +0 -1
- package/dist/assets/MobileTabPageHeader-Bj9MIS38.js +0 -2
- package/dist/assets/TerminalView-BZZ8LW4d.js +0 -8
- package/dist/assets/dropdown-menu.styles-DGvlOX_5.js +0 -1
- package/dist/assets/es-B8sAsuo5.js +0 -15
- package/dist/assets/fr-BPpW8T-l.js +0 -13
- package/dist/assets/gitApi-D43bAQh1.js +0 -10
- package/dist/assets/host-D1EpSUMR.js +0 -1
- package/dist/assets/insertionBoundaries-BQjiZAmZ.js +0 -1
- package/dist/assets/ja-DEoFDi7P.js +0 -15
- package/dist/assets/ko-B45xHN6I.js +0 -15
- package/dist/assets/main-C6MDfyZy.js +0 -2
- package/dist/assets/main-u5iQScJs.js +0 -169
- package/dist/assets/miniChat-Dhfn71Re.js +0 -2
- package/dist/assets/mobile-DSVdPfcG.js +0 -2
- package/dist/assets/pl-Bm3Je_AX.js +0 -15
- package/dist/assets/pt-BR-BiQwFHhL.js +0 -15
- package/dist/assets/react-CURmDhtB.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-NC8iRPyy.js +0 -2
- package/dist/assets/renderMobileApp-D5ai1i6y.js +0 -28
- package/dist/assets/runtimeEndpointReset-ByKa_0nu.js +0 -149
- package/dist/assets/scheduledTaskNavigation-CZfAnPD-.js +0 -1
- package/dist/assets/sessionChangeSummary-D6NlE_5k.js +0 -1
- package/dist/assets/sessionLookup-C70EoX-V.js +0 -1
- package/dist/assets/sortable-tabs-strip-aKussO2c.js +0 -1
- package/dist/assets/speechSettingsQueries-B6qf-mCh.js +0 -4
- package/dist/assets/src-NKCZI3Lg.css +0 -2
- package/dist/assets/store-BeD2keas.js +0 -15
- package/dist/assets/useDesktopWindowControlsLayout-DJxNmCWb.js +0 -1
- package/dist/assets/useMobileNavigationStore-Bn4SaalY.js +0 -418
- package/dist/assets/useUIStore-DI7va1HH.js +0 -1
- package/dist/assets/zh-CN-CMLBHipA.js +0 -15
- package/dist/assets/zh-TW-CJlmnnhK.js +0 -15
- /package/dist/assets/{sessionChangeSummary-8C8nv-EP.css → sessionLookup-8C8nv-EP.css} +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
|
|
3
|
+
const REFRESH_MS = 8000;
|
|
4
|
+
const TICKET_TTL_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
|
|
6
|
+
/** Optional, live-only presence. Never gate contact admission or message delivery. */
|
|
7
|
+
export function createWeixinTyping({ api, getBinding, isCurrent, canCancel, clock = Date.now }) {
|
|
8
|
+
const entries = new Map();
|
|
9
|
+
let closed = false;
|
|
10
|
+
const pause = (ms, signal) => delay(ms, undefined, { signal }).catch(() => {});
|
|
11
|
+
const launch = (entry) => {
|
|
12
|
+
if (entry.running || entry.disposed || closed) return;
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
entry.controller = controller;
|
|
15
|
+
entry.running = (async () => {
|
|
16
|
+
let lastTicket = '';
|
|
17
|
+
let retryMs = 2000;
|
|
18
|
+
try {
|
|
19
|
+
while (!controller.signal.aborted && entry.turns.size && isCurrent(entry.binding)) {
|
|
20
|
+
const binding = getBinding(entry.binding.assistant_id);
|
|
21
|
+
try {
|
|
22
|
+
if (!entry.ticket || clock() >= entry.ticketExpiresAt) {
|
|
23
|
+
const config = await api.getConfig(binding, controller.signal);
|
|
24
|
+
if (config.ret !== 0 || typeof config.typing_ticket !== 'string'
|
|
25
|
+
|| !config.typing_ticket || config.typing_ticket.length > 65_536) throw new Error('typing_unavailable');
|
|
26
|
+
entry.ticket = config.typing_ticket;
|
|
27
|
+
entry.ticketExpiresAt = clock() + TICKET_TTL_MS;
|
|
28
|
+
}
|
|
29
|
+
if (controller.signal.aborted || !entry.turns.size || !isCurrent(entry.binding)) break;
|
|
30
|
+
// Record attempts too: a failed HTTP response may still have set presence.
|
|
31
|
+
lastTicket = entry.ticket;
|
|
32
|
+
await api.sendTyping(binding, entry.ticket, 1, controller.signal);
|
|
33
|
+
retryMs = 2000;
|
|
34
|
+
await pause(REFRESH_MS, controller.signal);
|
|
35
|
+
} catch {
|
|
36
|
+
if (controller.signal.aborted) break;
|
|
37
|
+
entry.ticket = '';
|
|
38
|
+
await pause(retryMs, controller.signal);
|
|
39
|
+
retryMs = Math.min(60_000, retryMs * 2);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
if (lastTicket && canCancel(entry.binding)) {
|
|
44
|
+
// Do not reuse the aborted start signal. Serialize cancellation before a
|
|
45
|
+
// newer turn can publish typing, including during disconnect/shutdown.
|
|
46
|
+
try { await api.sendTyping(entry.binding, lastTicket, 2); } catch { /* Presence is best-effort. */ }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})().finally(() => {
|
|
50
|
+
entry.running = null;
|
|
51
|
+
if (!entry.disposed && !closed && entry.turns.size && isCurrent(entry.binding)) launch(entry);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
const forget = async (assistantID) => {
|
|
55
|
+
const entry = entries.get(assistantID);
|
|
56
|
+
if (!entry) return;
|
|
57
|
+
entry.disposed = true;
|
|
58
|
+
entry.turns.clear();
|
|
59
|
+
entry.controller?.abort();
|
|
60
|
+
await entry.running;
|
|
61
|
+
if (entries.get(assistantID) === entry) entries.delete(assistantID);
|
|
62
|
+
};
|
|
63
|
+
const clear = () => Promise.allSettled([...entries.keys()].map(forget));
|
|
64
|
+
return {
|
|
65
|
+
onTurnEvent: (event) => {
|
|
66
|
+
if (closed || !['yuri:contact-turn-start', 'yuri:contact-turn-end'].includes(event.type)) return;
|
|
67
|
+
const { assistantID, turnID } = event.properties ?? {};
|
|
68
|
+
if (typeof assistantID !== 'string' || typeof turnID !== 'string' || !turnID) return;
|
|
69
|
+
const binding = getBinding(assistantID);
|
|
70
|
+
if (!binding || binding.status === 'expired' || !isCurrent(binding)) return;
|
|
71
|
+
let entry = entries.get(assistantID);
|
|
72
|
+
if (event.type === 'yuri:contact-turn-start') {
|
|
73
|
+
if (!entry) {
|
|
74
|
+
entry = { binding, turns: new Set(), ticket: '', ticketExpiresAt: 0, running: null, disposed: false };
|
|
75
|
+
entries.set(assistantID, entry);
|
|
76
|
+
}
|
|
77
|
+
if (entry.disposed || entry.binding.epoch !== binding.epoch) return;
|
|
78
|
+
entry.turns.add(turnID);
|
|
79
|
+
launch(entry);
|
|
80
|
+
} else if (entry?.binding.epoch === binding.epoch) {
|
|
81
|
+
entry.turns.delete(turnID);
|
|
82
|
+
if (!entry.turns.size) entry.controller?.abort();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
forget, clear,
|
|
86
|
+
close: () => { closed = true; return clear(); },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Node's promise timers capture native timers before Vitest's fake clock installs.
|
|
4
|
+
vi.mock('node:timers/promises', () => ({
|
|
5
|
+
setTimeout: (ms, value, { signal }) => new Promise((resolve, reject) => {
|
|
6
|
+
const abort = () => { clearTimeout(timer); reject(new Error('cancelled')); };
|
|
7
|
+
const timer = setTimeout(() => { signal.removeEventListener('abort', abort); resolve(value); }, ms);
|
|
8
|
+
if (signal.aborted) abort();
|
|
9
|
+
else signal.addEventListener('abort', abort, { once: true });
|
|
10
|
+
}),
|
|
11
|
+
}));
|
|
12
|
+
import { createWeixinTyping } from './typing.js';
|
|
13
|
+
|
|
14
|
+
let typing;
|
|
15
|
+
beforeEach(() => vi.useFakeTimers({ toFake: ['Date', 'setTimeout', 'clearTimeout'] }));
|
|
16
|
+
afterEach(async () => { await typing?.close(); typing = null; vi.useRealTimers(); });
|
|
17
|
+
const turn = (assistantID, turnID, phase = 'start') => ({
|
|
18
|
+
type: `yuri:contact-turn-${phase}`, properties: { assistantID, turnID },
|
|
19
|
+
});
|
|
20
|
+
const flush = async () => { await vi.advanceTimersByTimeAsync(0); };
|
|
21
|
+
const deferred = () => {
|
|
22
|
+
let resolve;
|
|
23
|
+
const promise = new Promise((done) => { resolve = done; });
|
|
24
|
+
return { promise, resolve };
|
|
25
|
+
};
|
|
26
|
+
const fixture = () => {
|
|
27
|
+
const bindings = new Map(['a', 'b'].map((id) => [id, {
|
|
28
|
+
assistant_id: id, epoch: `epoch-${id}`, peer_id: `owner-${id}`, context_token: `context-${id}`, status: 'connected',
|
|
29
|
+
}]));
|
|
30
|
+
const api = {
|
|
31
|
+
getConfig: vi.fn(async (binding) => ({ ret: 0, typing_ticket: `ticket-${binding.assistant_id}` })),
|
|
32
|
+
sendTyping: vi.fn(async () => ({})),
|
|
33
|
+
};
|
|
34
|
+
const current = (binding) => bindings.get(binding.assistant_id)?.epoch === binding.epoch;
|
|
35
|
+
typing = createWeixinTyping({ api, getBinding: (id) => bindings.get(id), isCurrent: current, canCancel: current });
|
|
36
|
+
return { api, bindings };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe('live WeChat typing lifecycle', () => {
|
|
40
|
+
it('stays idle without a live start and coalesces duplicate starts and streaming deltas', async () => {
|
|
41
|
+
const { api } = fixture();
|
|
42
|
+
for (let index = 0; index < 50; index++) {
|
|
43
|
+
typing.onTurnEvent({ type: 'yuri:contact-bubble-delta', properties: { assistantID: 'a', turnID: 'old', delta: 'text' } });
|
|
44
|
+
typing.onTurnEvent(turn('a', 'old', 'end'));
|
|
45
|
+
}
|
|
46
|
+
await flush();
|
|
47
|
+
expect(api.getConfig).not.toHaveBeenCalled();
|
|
48
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
49
|
+
await flush();
|
|
50
|
+
for (let index = 0; index < 50; index++) typing.onTurnEvent(turn('a', 'one'));
|
|
51
|
+
await flush();
|
|
52
|
+
expect(api.getConfig).toHaveBeenCalledTimes(1);
|
|
53
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1]);
|
|
54
|
+
typing.onTurnEvent(turn('a', 'one', 'end'));
|
|
55
|
+
await flush();
|
|
56
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1, 2]);
|
|
57
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
58
|
+
expect(api.sendTyping).toHaveBeenCalledTimes(2);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('refreshes at a bounded cadence, keeps overlapping turns active, and reuses an idle ticket', async () => {
|
|
62
|
+
const { api } = fixture();
|
|
63
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
64
|
+
typing.onTurnEvent(turn('a', 'two'));
|
|
65
|
+
await flush();
|
|
66
|
+
await vi.advanceTimersByTimeAsync(7999);
|
|
67
|
+
expect(api.sendTyping).toHaveBeenCalledTimes(1);
|
|
68
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
69
|
+
expect(api.sendTyping).toHaveBeenCalledTimes(2);
|
|
70
|
+
typing.onTurnEvent(turn('a', 'one', 'end'));
|
|
71
|
+
await flush();
|
|
72
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1, 1]);
|
|
73
|
+
typing.onTurnEvent(turn('a', 'two', 'end'));
|
|
74
|
+
await flush();
|
|
75
|
+
typing.onTurnEvent(turn('a', 'three'));
|
|
76
|
+
await flush();
|
|
77
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1, 1, 2, 1]);
|
|
78
|
+
expect(api.getConfig).toHaveBeenCalledTimes(1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('never starts typing from a ticket that arrives after completion or disconnect', async () => {
|
|
82
|
+
const { api } = fixture();
|
|
83
|
+
const ticket = deferred();
|
|
84
|
+
api.getConfig.mockImplementation(() => ticket.promise);
|
|
85
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
86
|
+
typing.onTurnEvent(turn('a', 'one', 'end'));
|
|
87
|
+
ticket.resolve({ ret: 0, typing_ticket: 'late' });
|
|
88
|
+
await flush();
|
|
89
|
+
expect(api.sendTyping).not.toHaveBeenCalled();
|
|
90
|
+
|
|
91
|
+
const other = deferred();
|
|
92
|
+
api.getConfig.mockImplementation(() => other.promise);
|
|
93
|
+
typing.onTurnEvent(turn('b', 'two'));
|
|
94
|
+
const disconnected = typing.forget('b');
|
|
95
|
+
other.resolve({ ret: 0, typing_ticket: 'late-b' });
|
|
96
|
+
await disconnected;
|
|
97
|
+
expect(api.sendTyping).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('serializes late start completion, cancellation and the next live turn', async () => {
|
|
101
|
+
const { api } = fixture();
|
|
102
|
+
const start = deferred();
|
|
103
|
+
api.sendTyping.mockImplementationOnce(() => start.promise);
|
|
104
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
105
|
+
await flush();
|
|
106
|
+
typing.onTurnEvent(turn('a', 'one', 'end'));
|
|
107
|
+
typing.onTurnEvent(turn('a', 'two'));
|
|
108
|
+
await flush();
|
|
109
|
+
expect(api.sendTyping).toHaveBeenCalledTimes(1);
|
|
110
|
+
start.resolve({});
|
|
111
|
+
await flush();
|
|
112
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1, 2, 1]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('isolates accounts and backs off missing/failed tickets without aborting other typing', async () => {
|
|
116
|
+
const { api } = fixture();
|
|
117
|
+
api.getConfig.mockImplementation(async (binding) => binding.assistant_id === 'a'
|
|
118
|
+
? { ret: 0 } : { ret: 0, typing_ticket: 'ticket-b' });
|
|
119
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
120
|
+
typing.onTurnEvent(turn('b', 'two'));
|
|
121
|
+
await flush();
|
|
122
|
+
expect(api.sendTyping.mock.calls.map((call) => [call[0].assistant_id, call[2]])).toEqual([['b', 1]]);
|
|
123
|
+
await vi.advanceTimersByTimeAsync(1999);
|
|
124
|
+
expect(api.getConfig).toHaveBeenCalledTimes(2);
|
|
125
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
126
|
+
expect(api.getConfig).toHaveBeenCalledTimes(3);
|
|
127
|
+
await vi.advanceTimersByTimeAsync(4000);
|
|
128
|
+
expect(api.getConfig).toHaveBeenCalledTimes(4);
|
|
129
|
+
typing.onTurnEvent(turn('a', 'one', 'end'));
|
|
130
|
+
await flush();
|
|
131
|
+
expect(api.sendTyping).toHaveBeenCalledTimes(1);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('cancels on forget/shutdown with a fresh signal and drops the per-binding ticket cache', async () => {
|
|
135
|
+
const { api, bindings } = fixture();
|
|
136
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
137
|
+
await flush();
|
|
138
|
+
const signal = api.sendTyping.mock.calls[0][3];
|
|
139
|
+
await typing.forget('a');
|
|
140
|
+
expect(signal.aborted).toBe(true);
|
|
141
|
+
expect(api.sendTyping.mock.calls.at(-1).slice(1, 3)).toEqual(['ticket-a', 2]);
|
|
142
|
+
expect(api.sendTyping.mock.calls.at(-1)[3]).toBeUndefined();
|
|
143
|
+
bindings.set('a', { ...bindings.get('a'), epoch: 'new-epoch' });
|
|
144
|
+
typing.onTurnEvent(turn('a', 'two'));
|
|
145
|
+
await flush();
|
|
146
|
+
expect(api.getConfig).toHaveBeenCalledTimes(2);
|
|
147
|
+
await typing.close();
|
|
148
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1, 2, 1, 2]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('fences a ticket completion after lease/epoch changes without cancelling another owner', async () => {
|
|
152
|
+
const { api, bindings } = fixture();
|
|
153
|
+
const ticket = deferred();
|
|
154
|
+
api.getConfig.mockImplementationOnce(() => ticket.promise);
|
|
155
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
156
|
+
bindings.set('a', { ...bindings.get('a'), epoch: 'rebound' });
|
|
157
|
+
ticket.resolve({ ret: 0, typing_ticket: 'old-ticket' });
|
|
158
|
+
await flush();
|
|
159
|
+
expect(api.sendTyping).not.toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('refreshes an expired ticket using the latest conversation context', async () => {
|
|
163
|
+
const { api, bindings } = fixture();
|
|
164
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
165
|
+
await flush();
|
|
166
|
+
typing.onTurnEvent(turn('a', 'one', 'end'));
|
|
167
|
+
await flush();
|
|
168
|
+
vi.setSystemTime(Date.now() + 24 * 60 * 60 * 1000);
|
|
169
|
+
bindings.set('a', { ...bindings.get('a'), context_token: 'new-context' });
|
|
170
|
+
typing.onTurnEvent(turn('a', 'two'));
|
|
171
|
+
await flush();
|
|
172
|
+
expect(api.getConfig).toHaveBeenCalledTimes(2);
|
|
173
|
+
expect(api.getConfig.mock.calls[1][0].context_token).toBe('new-context');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('stops refreshing on ownership loss and does not cancel the replacement owner', async () => {
|
|
177
|
+
const { api, bindings } = fixture();
|
|
178
|
+
typing.onTurnEvent(turn('a', 'one'));
|
|
179
|
+
await flush();
|
|
180
|
+
bindings.set('a', { ...bindings.get('a'), epoch: 'replacement-owner' });
|
|
181
|
+
await vi.advanceTimersByTimeAsync(8000);
|
|
182
|
+
await typing.clear();
|
|
183
|
+
expect(api.sendTyping.mock.calls.map((call) => call[2])).toEqual([1]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -76,7 +76,8 @@ encoding, not removed V1 endpoints.
|
|
|
76
76
|
- `packages/web/server/lib/opencode/settings-normalization-runtime.js`: path/settings normalization and sanitization helpers runtime used by settings/routes/config wiring.
|
|
77
77
|
- `packages/web/server/lib/opencode/theme-runtime.js`: custom theme JSON validation and theme directory loading runtime for settings utility routes.
|
|
78
78
|
- `packages/web/server/lib/opencode/proxy.js`: OpenCode API/SSE forwarding and readiness-gate route registration.
|
|
79
|
-
- `npm-registry.js`: plugin package lookup used by `GET /api/config/plugins/registry`. It asks the user's own `npm view` first (run in the project directory, so scope registries, auth tokens and mirrors from `.npmrc` apply as they do for `npm install`) and falls back to a direct request to the public registry only when the CLI is unavailable; a CLI 404 is final. Results are cached per name and directory. The latest release's `
|
|
79
|
+
- `npm-registry.js`: plugin package lookup used by `GET /api/config/plugins/registry`. It asks the user's own `npm view` first (run in the project directory, so scope registries, auth tokens and mirrors from `.npmrc` apply as they do for `npm install`) and falls back to a direct request to the public registry only when the CLI is unavailable; a CLI 404 is final. Results are cached per name and directory. The latest release's top-level package.json `icon` is returned as `icon` only when it is an `https://` URL or `data:image/` URI of at most ~1.5 MB; nested icon fields are not read or used as fallbacks.
|
|
80
|
+
- `plugin-icon.js` owns the shared icon sanitizer and optional local package metadata read for Web/Electron/mobile and VS Code. Registry `path-ok` includes the nearest package manifest's top-level `icon` for directories or built entry files. Search stops at the first manifest, root or 32 parents; malformed, unreadable or >2 MiB manifests omit artwork without changing path status. No server-side image fetch occurs. Settings displays package images normally; GUI titlebar/sidebar entries use alpha masks in their current text color.
|
|
80
81
|
- `plugin-gui-response.js`: shared Web/Electron/VS Code code-only revision response owner for exact `GET /api/plugin/gui?id=…` (one nonempty id). The installed GUI client alias is official `@opencode/client@2.2.0`: HTTP returns `{ location, data: { code, revision, options } }`. Every call still reads the complete current upstream response through the existing auth/readiness/abort boundary; there is no Host bundle cache.
|
|
81
82
|
- Request `X-Yuri-Gui-Revision: <lowercase SHA-256 hex of UTF-8 revision>` opts into code reuse. This header and HTTP condition/range headers are stripped before upstream so Yuri always requests a complete representation. Other query and request headers retain proxy semantics.
|
|
82
83
|
- A valid upstream 200 JSON bundle (`code` string, nonempty `revision` string, `options` object) receives `X-Yuri-Gui-Revision` and `Cache-Control: private, no-store`. Matching tokens additionally receive `X-Yuri-Gui-Code: cached` and only `data.code` becomes `''`; current `options`, `revision`, location and other fields remain. Unmatched/ordinary calls preserve original body bytes. No 304 or Yuri ETag is generated. Upstream failure statuses/bodies remain failures; malformed successful bodies remain unchanged without a revision receipt.
|
|
@@ -2,6 +2,9 @@ import { execFile } from 'child_process';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { sanitizePluginIcon } from './plugin-icon.js';
|
|
6
|
+
|
|
7
|
+
export { sanitizePluginIcon } from './plugin-icon.js';
|
|
5
8
|
|
|
6
9
|
const NPM_CACHE_TTL_MS = 3_600_000;
|
|
7
10
|
const NPM_FETCH_TIMEOUT_MS = 5_000;
|
|
@@ -13,7 +16,7 @@ const NPM_REGISTRY_BASE = 'https://registry.npmjs.org';
|
|
|
13
16
|
* @property {string|null} latest
|
|
14
17
|
* @property {string[]} versions
|
|
15
18
|
* @property {Record<string, string>} distTags
|
|
16
|
-
* @property {string} [icon] sanitized `
|
|
19
|
+
* @property {string} [icon] sanitized top-level package.json `icon` of the latest release
|
|
17
20
|
*
|
|
18
21
|
* @typedef {Object} NpmLookupError
|
|
19
22
|
* @property {false} ok
|
|
@@ -81,23 +84,6 @@ function cacheResult(name, payload) {
|
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
const NPM_ICON_MAX_LENGTH = 3 << 19;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* A package's own picture, as magpie reads `magpie.icon` from package.json:
|
|
88
|
-
* an https URL or a data:image URI, at most ~1.5 MB. Anything else is dropped.
|
|
89
|
-
* Nothing is fetched here; the client renders it as an image.
|
|
90
|
-
*
|
|
91
|
-
* @param {unknown} value
|
|
92
|
-
* @returns {string | undefined}
|
|
93
|
-
*/
|
|
94
|
-
export function sanitizePluginIcon(value) {
|
|
95
|
-
const icon = typeof value === 'string' ? value.trim() : '';
|
|
96
|
-
return icon.length > 0 && icon.length <= NPM_ICON_MAX_LENGTH && /^(https:\/\/|data:image\/)/i.test(icon)
|
|
97
|
-
? icon
|
|
98
|
-
: undefined;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
87
|
const VALID_NPM_NAME = /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
102
88
|
const NPM_CLI_TIMEOUT_MS = 15_000;
|
|
103
89
|
|
|
@@ -118,7 +104,7 @@ function lookupViaNpmCli(name, cwd) {
|
|
|
118
104
|
return new Promise((resolve) => {
|
|
119
105
|
execFile(
|
|
120
106
|
process.platform === 'win32' ? 'npm.cmd' : 'npm',
|
|
121
|
-
['view', name, 'dist-tags', 'versions', '
|
|
107
|
+
['view', name, 'dist-tags', 'versions', 'icon', '--json'],
|
|
122
108
|
{
|
|
123
109
|
cwd: cwd || undefined,
|
|
124
110
|
timeout: NPM_CLI_TIMEOUT_MS,
|
|
@@ -142,7 +128,7 @@ function lookupViaNpmCli(name, cwd) {
|
|
|
142
128
|
const versions = Array.isArray(data?.versions)
|
|
143
129
|
? data.versions.filter((version) => typeof version === 'string')
|
|
144
130
|
: typeof data?.versions === 'string' ? [data.versions] : [];
|
|
145
|
-
const icon = sanitizePluginIcon(data?.
|
|
131
|
+
const icon = sanitizePluginIcon(data?.icon);
|
|
146
132
|
resolve({ ok: true, latest: distTags.latest ?? null, versions, distTags, ...(icon ? { icon } : {}) });
|
|
147
133
|
} catch {
|
|
148
134
|
resolve(null);
|
|
@@ -189,7 +175,7 @@ async function lookupNpmPackageOverHttp(name) {
|
|
|
189
175
|
const data = await response.json();
|
|
190
176
|
const distTags = parseDistTags(data?.['dist-tags']);
|
|
191
177
|
const latest = distTags.latest ?? null;
|
|
192
|
-
const icon = sanitizePluginIcon(latest ? data?.versions?.[latest]?.
|
|
178
|
+
const icon = sanitizePluginIcon(latest ? data?.versions?.[latest]?.icon : undefined);
|
|
193
179
|
return {
|
|
194
180
|
ok: true,
|
|
195
181
|
latest,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect,
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
2
|
import * as npm from './npm-registry.js';
|
|
3
3
|
|
|
4
|
+
const mock = vi.fn;
|
|
5
|
+
const execFileMock = vi.hoisted(() => vi.fn());
|
|
6
|
+
vi.mock('child_process', () => ({ execFile: execFileMock }));
|
|
7
|
+
|
|
4
8
|
const originalFetch = globalThis.fetch;
|
|
5
9
|
const originalDateNow = Date.now;
|
|
6
10
|
|
|
@@ -18,6 +22,7 @@ const originalCliLookup = npm.npmCli.lookup;
|
|
|
18
22
|
describe('npm registry client', () => {
|
|
19
23
|
beforeEach(() => {
|
|
20
24
|
npm.clearCache();
|
|
25
|
+
execFileMock.mockReset();
|
|
21
26
|
Date.now = originalDateNow;
|
|
22
27
|
fetchMock = mock(() => jsonResponse({}));
|
|
23
28
|
globalThis.fetch = fetchMock;
|
|
@@ -212,18 +217,30 @@ describe('npm registry client', () => {
|
|
|
212
217
|
|
|
213
218
|
expect(fetchMock.mock.calls[0][1].headers['User-Agent']).toMatch(/^yuri-server\//);
|
|
214
219
|
});
|
|
215
|
-
test('npm CLI
|
|
216
|
-
npm.npmCli.lookup =
|
|
220
|
+
test('npm CLI queries and sanitizes the top-level package icon', async () => {
|
|
221
|
+
npm.npmCli.lookup = originalCliLookup;
|
|
222
|
+
execFileMock.mockImplementation((_command, _args, _options, callback) => callback(null, JSON.stringify({
|
|
223
|
+
'dist-tags': { latest: '1.0.0' }, versions: ['1.0.0'],
|
|
224
|
+
icon: ' https://cdn.example/a.png ',
|
|
225
|
+
magpie: { icon: 'https://cdn.example/legacy.png' },
|
|
226
|
+
}), ''));
|
|
217
227
|
|
|
218
228
|
const result = await npm.getNpmInfo('@scope/pkg', { cwd: '/proj' });
|
|
219
229
|
|
|
220
230
|
expect(result.icon).toBe('https://cdn.example/a.png');
|
|
231
|
+
expect(execFileMock).toHaveBeenCalledWith(expect.any(String), ['view', '@scope/pkg', 'dist-tags', 'versions', 'icon', '--json'],
|
|
232
|
+
expect.objectContaining({ cwd: '/proj' }), expect.any(Function));
|
|
233
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
221
234
|
});
|
|
222
235
|
|
|
223
|
-
test('registry fallback reads
|
|
236
|
+
test('registry fallback reads the top-level icon from the latest release', async () => {
|
|
224
237
|
fetchMock.mockImplementation(() => jsonResponse({
|
|
225
238
|
'dist-tags': { latest: '1.0.0' },
|
|
226
|
-
|
|
239
|
+
icon: 'https://cdn.example/packument.png',
|
|
240
|
+
versions: {
|
|
241
|
+
'0.9.0': { icon: 'https://cdn.example/old.png' },
|
|
242
|
+
'1.0.0': { icon: 'data:image/svg+xml;base64,AAAA', magpie: { icon: 'https://cdn.example/legacy.png' } },
|
|
243
|
+
},
|
|
227
244
|
}));
|
|
228
245
|
|
|
229
246
|
const result = await npm.lookupNpmPackage('foo');
|
|
@@ -231,6 +248,20 @@ describe('npm registry client', () => {
|
|
|
231
248
|
expect(result.icon).toBe('data:image/svg+xml;base64,AAAA');
|
|
232
249
|
});
|
|
233
250
|
|
|
251
|
+
test.each(['cli', 'http'])('%s never falls back to magpie.icon when icon is missing or invalid', async (source) => {
|
|
252
|
+
for (const icon of [undefined, 'http://cdn.example/insecure.png', { url: 'https://cdn.example/a.png' }]) {
|
|
253
|
+
const manifest = { icon, magpie: { icon: 'https://cdn.example/legacy.png' }, 'magpie.icon': 'https://cdn.example/legacy-flat.png' };
|
|
254
|
+
if (source === 'cli') {
|
|
255
|
+
npm.npmCli.lookup = originalCliLookup;
|
|
256
|
+
execFileMock.mockImplementation((_command, _args, _options, callback) => callback(null,
|
|
257
|
+
JSON.stringify({ 'dist-tags': { latest: '1.0.0' }, versions: ['1.0.0'], ...manifest }), ''));
|
|
258
|
+
} else fetchMock.mockImplementation(() => jsonResponse({ 'dist-tags': { latest: '1.0.0' }, versions: { '1.0.0': manifest } }));
|
|
259
|
+
const result = await npm.lookupNpmPackage('foo');
|
|
260
|
+
expect(result.ok).toBe(true);
|
|
261
|
+
expect(result).not.toHaveProperty('icon');
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
234
265
|
test('sanitizePluginIcon keeps only https and data:image, within the size cap', () => {
|
|
235
266
|
expect(npm.sanitizePluginIcon('https://x/y.png')).toBe('https://x/y.png');
|
|
236
267
|
expect(npm.sanitizePluginIcon(' data:image/png;base64,AA ')).toBe('data:image/png;base64,AA');
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const ICON_MAX_LENGTH = 3 << 19;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A package's own picture from the top-level package.json `icon`:
|
|
8
|
+
* an https URL or a data:image URI, at most ~1.5 MB. Anything else is dropped.
|
|
9
|
+
* Nothing is fetched here; the client renders it as an image.
|
|
10
|
+
*
|
|
11
|
+
* @param {unknown} value
|
|
12
|
+
* @returns {string | undefined}
|
|
13
|
+
*/
|
|
14
|
+
export function sanitizePluginIcon(value) {
|
|
15
|
+
const icon = typeof value === 'string' ? value.trim() : '';
|
|
16
|
+
return icon.length > 0 && icon.length <= ICON_MAX_LENGTH && /^(https:\/\/|data:image\/)/i.test(icon)
|
|
17
|
+
? icon
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Read the nearest package manifest for a local package directory or entry file. */
|
|
22
|
+
export async function readLocalPluginIcon(absolutePath) {
|
|
23
|
+
try {
|
|
24
|
+
const stat = await fs.stat(absolutePath);
|
|
25
|
+
let directory = stat.isDirectory() ? absolutePath : path.dirname(absolutePath);
|
|
26
|
+
for (let depth = 0; depth < 32; depth++) {
|
|
27
|
+
const manifest = path.join(directory, 'package.json');
|
|
28
|
+
try {
|
|
29
|
+
const metadata = await fs.stat(manifest);
|
|
30
|
+
if (!metadata.isFile() || metadata.size > 2 * 1024 * 1024) return undefined;
|
|
31
|
+
return sanitizePluginIcon(JSON.parse(await fs.readFile(manifest, 'utf8')).icon);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error?.code !== 'ENOENT') return undefined;
|
|
34
|
+
}
|
|
35
|
+
const parent = path.dirname(directory);
|
|
36
|
+
if (parent === directory) break;
|
|
37
|
+
directory = parent;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// Optional artwork must not change the plugin path's load status.
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, test } from 'vitest';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { readLocalPluginIcon } from './plugin-icon.js';
|
|
6
|
+
|
|
7
|
+
let root;
|
|
8
|
+
beforeEach(async () => { root = await fs.mkdtemp(path.join(os.tmpdir(), 'yuri-plugin-icon-')); });
|
|
9
|
+
afterEach(async () => { await fs.rm(root, { recursive: true, force: true }); });
|
|
10
|
+
|
|
11
|
+
test('local directories and built entry files read the nearest top-level icon', async () => {
|
|
12
|
+
const icon = 'data:image/svg+xml,%3Csvg/%3E';
|
|
13
|
+
await fs.mkdir(path.join(root, 'dist'));
|
|
14
|
+
const entry = path.join(root, 'dist', 'index.mjs');
|
|
15
|
+
await fs.writeFile(entry, '');
|
|
16
|
+
await fs.writeFile(path.join(root, 'package.json'), JSON.stringify({ icon, magpie: { icon: 'https://example.test/old.svg' } }));
|
|
17
|
+
expect(await readLocalPluginIcon(root)).toBe(icon);
|
|
18
|
+
expect(await readLocalPluginIcon(entry)).toBe(icon);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test.each([
|
|
22
|
+
{ magpie: { icon: 'https://example.test/old.svg' } },
|
|
23
|
+
{ icon: 'javascript:alert(1)' },
|
|
24
|
+
{ icon: 'file:///private/icon.svg' },
|
|
25
|
+
{ icon: 'data:image/svg+xml,' + 'x'.repeat(3 << 19) },
|
|
26
|
+
])('no nested-field, unsafe-value or parent-package fallback (%j)', async (manifest) => {
|
|
27
|
+
await fs.writeFile(path.join(root, 'package.json'), JSON.stringify({ icon: 'https://example.test/parent.svg' }));
|
|
28
|
+
const child = path.join(root, 'child');
|
|
29
|
+
await fs.mkdir(child);
|
|
30
|
+
await fs.writeFile(path.join(child, 'package.json'), JSON.stringify(manifest));
|
|
31
|
+
expect(await readLocalPluginIcon(child)).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('missing, malformed and oversized optional metadata are harmless', async () => {
|
|
35
|
+
expect(await readLocalPluginIcon(path.join(root, 'missing'))).toBeUndefined();
|
|
36
|
+
const manifest = path.join(root, 'package.json');
|
|
37
|
+
await fs.writeFile(manifest, '{broken');
|
|
38
|
+
expect(await readLocalPluginIcon(root)).toBeUndefined();
|
|
39
|
+
await fs.writeFile(manifest, ' '.repeat(2 * 1024 * 1024 + 1));
|
|
40
|
+
expect(await readLocalPluginIcon(root)).toBeUndefined();
|
|
41
|
+
});
|
|
@@ -2,6 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import os from 'os';
|
|
3
3
|
|
|
4
4
|
import { getNpmInfo as defaultGetNpmInfo } from './npm-registry.js';
|
|
5
|
+
import { readLocalPluginIcon } from './plugin-icon.js';
|
|
5
6
|
import { isExactSemver as defaultIsExactSemver, isPathSpec as defaultIsPathSpec, parseNpmSpec as defaultParseNpmSpec, parsePathSpec as defaultParsePathSpec } from './plugin-spec.js';
|
|
6
7
|
|
|
7
8
|
const ENTRY_EXISTS_CODES = new Set(['ENTRY_EXISTS', 'EEXIST']);
|
|
@@ -170,7 +171,8 @@ export const registerPluginRoutes = (app, dependencies) => {
|
|
|
170
171
|
|
|
171
172
|
try {
|
|
172
173
|
fs.accessSync(absolutePath, fs.constants.R_OK);
|
|
173
|
-
|
|
174
|
+
const icon = await readLocalPluginIcon(absolutePath);
|
|
175
|
+
results.push({ kind: 'path-ok', spec, absolutePath, ...(icon ? { icon } : {}) });
|
|
174
176
|
} catch {
|
|
175
177
|
results.push({ kind: 'path-unreadable', spec, absolutePath });
|
|
176
178
|
}
|
|
@@ -112,6 +112,19 @@ describe('opencode plugin routes', () => {
|
|
|
112
112
|
expect(getNpmInfo).not.toHaveBeenCalled();
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
+
test('GET /registry returns local package icon for directory and built entry', async () => {
|
|
116
|
+
const icon = 'data:image/svg+xml,%3Csvg/%3E';
|
|
117
|
+
const local = path.join(projectDir, 'local-plugin');
|
|
118
|
+
fs.mkdirSync(path.join(local, 'dist'), { recursive: true });
|
|
119
|
+
fs.writeFileSync(path.join(local, 'package.json'), JSON.stringify({ icon }));
|
|
120
|
+
const entry = path.join(local, 'dist', 'index.mjs');
|
|
121
|
+
fs.writeFileSync(entry, '');
|
|
122
|
+
for (const spec of [local, entry]) {
|
|
123
|
+
const response = await request(app).get('/api/config/plugins/registry').query({ specs: spec }).expect(200);
|
|
124
|
+
expect(response.body.results[0]).toMatchObject({ kind: 'path-ok', spec, icon });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
115
128
|
test('GET /registry reports update for exact npm version behind latest', async () => {
|
|
116
129
|
createRegistryApp(mock(async () => ({ ok: true, latest: '2.0.0', versions: ['1.0.0', '2.0.0'], distTags: { latest: '2.0.0' } })));
|
|
117
130
|
|
|
@@ -51,7 +51,7 @@ export const createGracefulShutdownRuntime = (dependencies) => {
|
|
|
51
51
|
// in-flight attach/finalize can still write, and so exitProcess:false restarts
|
|
52
52
|
// can reuse the same global singleton without reopening a closed SQLite handle.
|
|
53
53
|
scheduledTasksRuntime?.stop?.();
|
|
54
|
-
closeFeatureRoutes?.();
|
|
54
|
+
await closeFeatureRoutes?.();
|
|
55
55
|
|
|
56
56
|
const healthCheckInterval = getHealthCheckInterval();
|
|
57
57
|
if (healthCheckInterval) {
|
|
@@ -31,6 +31,18 @@ const createRuntime = (server, shutdownTimeoutMs = 1000, overrides = {}) => crea
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('graceful shutdown runtime', () => {
|
|
34
|
+
it('waits for Host message channels to stop before closing downstream runtimes', async () => {
|
|
35
|
+
let release;
|
|
36
|
+
const closeFeatureRoutes = vi.fn(() => new Promise((resolve) => { release = resolve; }));
|
|
37
|
+
const server = { close: vi.fn((callback) => callback()) };
|
|
38
|
+
const runtime = createRuntime(server, 1000, { closeFeatureRoutes });
|
|
39
|
+
const pending = runtime.gracefulShutdown({ exitProcess: false });
|
|
40
|
+
expect(closeFeatureRoutes).toHaveBeenCalledOnce();
|
|
41
|
+
expect(server.close).not.toHaveBeenCalled();
|
|
42
|
+
release();
|
|
43
|
+
await pending;
|
|
44
|
+
expect(server.close).toHaveBeenCalledOnce();
|
|
45
|
+
});
|
|
34
46
|
afterEach(() => {
|
|
35
47
|
vi.useRealTimers();
|
|
36
48
|
vi.restoreAllMocks();
|