@yuriai/web 0.2.25 → 0.2.27-beta.3
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 +21 -1
- package/dist/assets/AgentAvatar-kIN4sZMz.js +1 -0
- package/dist/assets/AssistantView-C2KQZ6a4.js +3 -0
- package/dist/assets/{DiagramView-DN_rHdr9.js → DiagramView-DK0iXm9b.js} +1 -1
- package/dist/assets/{FadeInOnReveal-555z1y1N.js → FadeInOnReveal-BJA9Za3T.js} +1 -1
- package/dist/assets/{GuiPluginSurface-BPMATuPa.js → GuiPluginSurface-Dz2CdSUA.js} +1 -1
- package/dist/assets/{GuiPluginWindow-CAmfr79x.js → GuiPluginWindow-l4FYY6S-.js} +1 -1
- package/dist/assets/Icon-BP1sfnHn.js +1 -0
- package/dist/assets/{ImageLoadingPlaceholder-BMsQLN_b.js → ImageLoadingPlaceholder-DCWssLJG.js} +1 -1
- package/dist/assets/{LoadingImage-DI7sb_H_.js → LoadingImage-C_Hryaqe.js} +1 -1
- package/dist/assets/MarkdownRenderer-Y6uQXIFH.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-B9K5q0Lc.js → MarkdownRendererImpl-qKp1tQrP.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-9gUEVQck.js → MarkstreamRendererImpl-B_JTod0h.js} +1 -1
- package/dist/assets/MobileDetailNavigation-B3rUx5Ve.js +1 -0
- package/dist/assets/{MobileResizableSheet-_6OvPSMI.js → MobileResizableSheet-F1zSUD1S.js} +1 -1
- package/dist/assets/{MobileShareBridge-BrdOiu_r.js → MobileShareBridge-F70fkIfS.js} +3 -3
- package/dist/assets/MobileTabPageHeader-0esgB2TO.js +2 -0
- package/dist/assets/MultiRunWindow-D8m6R_4x.js +1 -0
- package/dist/assets/{OnboardingScreen-g8PDztN3.js → OnboardingScreen-BAsPVV_W.js} +1 -1
- package/dist/assets/{OverlayScrollbar-COv8rH_z.js → OverlayScrollbar-wiRM4AGj.js} +1 -1
- package/dist/assets/SettingsView-izzjIckv.js +29 -0
- package/dist/assets/SettingsWindow-CSuHDq_c.js +1 -0
- package/dist/assets/{TerminalView-BLer-ZhM.js → TerminalView-BtM5-BVx.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DI-s2TBb.js → ToolOutputDialog-DJs9w1_J.js} +2 -2
- package/dist/assets/{YuriLogo-BP4j1iqV.js → YuriLogo-aBS6wlYU.js} +1 -1
- package/dist/assets/appThemeRegistry-BY5rY9-W.js +1 -0
- package/dist/assets/{assistant-attachment-cache-Cis9yYGt.js → assistant-attachment-cache-B9iHLlm2.js} +1 -1
- package/dist/assets/{button-Be1cqulG.js → button-Dt6Ygbc7.js} +1 -1
- package/dist/assets/{capgoAdapter-B31jIkD8.js → capgoAdapter-MQ1qpf60.js} +1 -1
- package/dist/assets/collapsible-Dm7OHk7m.js +1 -0
- package/dist/assets/{device-hj359GjJ.js → device-BjRYYXNT.js} +1 -1
- package/dist/assets/{diagram-hEIRiKol.js → diagram-DWZaG3_v.js} +1 -1
- package/dist/assets/dialog-CTYD3Sbr.css +1 -0
- package/dist/assets/dialog-CjQeHVOc.js +1 -0
- package/dist/assets/{dropdown-menu.styles-xxM2ofOp.js → dropdown-menu.styles-PdxueXzN.js} +1 -1
- package/dist/assets/{es-Clj7CS2r.js → es-BjI1GHJ5.js} +3 -3
- package/dist/assets/{fileMentionTouchSelection-CTh0Mc2g.js → fileMentionTouchSelection-D7QtVxjI.js} +2 -2
- package/dist/assets/{fileQueries-COS23nLq.js → fileQueries-5a1jkme2.js} +1 -1
- package/dist/assets/{fileReferenceActions-Cus9oSW7.js → fileReferenceActions-BAoEu4z8.js} +1 -1
- package/dist/assets/{fr-dmrFQLCO.js → fr-Bs7ndHkb.js} +4 -4
- package/dist/assets/{gitApi-deADOzlN.js → gitApi-BxQmH8Wg.js} +1 -1
- package/dist/assets/{gitApiHttp-BBRKl9WX.js → gitApiHttp-DHrRqnYh.js} +3 -3
- package/dist/assets/{gui-BHEKelUx.js → gui-9enrif_1.js} +1 -1
- package/dist/assets/{host-DrqLUbqt.js → host-D1EpSUMR.js} +1 -1
- package/dist/assets/image-loading-Dq1g_wpm.js +1 -0
- package/dist/assets/{input-DTdHYZ6r.js → input-Dq4usRDa.js} +1 -1
- package/dist/assets/insertionBoundaries-CKQL85zy.js +1 -0
- package/dist/assets/{ja-Co0dxiN_.js → ja-DkdV26EW.js} +4 -4
- package/dist/assets/{ko-BltElAGq.js → ko-B0qoC5da.js} +4 -4
- package/dist/assets/main-CNwFqQQd.js +2 -0
- package/dist/assets/main-DPhcXanT.js +169 -0
- package/dist/assets/{markdownHeightCache-DnR01ECa.js → markdownHeightCache-C1u0bWDL.js} +1 -1
- package/dist/assets/{markdownTheme-DHoKvD6O.js → markdownTheme-hpURsgju.js} +1 -1
- package/dist/assets/{mcpQueries-Cpb22_60.js → mcpQueries-D2IxTr4k.js} +1 -1
- package/dist/assets/miniChat-CF2vb25D.js +2 -0
- package/dist/assets/mobile-C24qSj44.js +2 -0
- package/dist/assets/{mobileBackNavigation-BibkyIeB.js → mobileBackNavigation-vpCg1S7j.js} +1 -1
- package/dist/assets/{multirun-CPvUnP91.js → multirun-DT-dFXud.js} +2 -2
- package/dist/assets/{native-BMAEg2E6.js → native-De1DIkLZ.js} +1 -1
- package/dist/assets/{native-config-DA8S8EqV.js → native-config-ncdoz9Wl.js} +1 -1
- package/dist/assets/{persistence-CBL0OOdj.js → persistence-JyLTFv27.js} +1 -1
- package/dist/assets/{pl-qd6Wnl7H.js → pl-D27Y_GBs.js} +4 -4
- package/dist/assets/projectMeta-CG8NLahh.js +1 -0
- package/dist/assets/{pt-BR-CsOFfQXS.js → pt-BR-DbocEu4b.js} +3 -3
- package/dist/assets/{react-BYRXYlGz.js → react-CURmDhtB.js} +1 -1
- package/dist/assets/{readiness-RiznV1AX.js → readiness-DSJs_3v4.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-DdGqTh4X.js → renderElectronMiniChatApp-ChZCxxH6.js} +2 -2
- package/dist/assets/renderMobileApp-CRv3Il6P.js +28 -0
- package/dist/assets/{runtime-file-download-B_c7JBoS.js → runtime-file-download-CcNIVp7u.js} +1 -1
- package/dist/assets/{runtime-file-resource-DpTxBCsp.js → runtime-file-resource-6np6lzoV.js} +1 -1
- package/dist/assets/runtimeConfig-CZrflo-r.js +2 -0
- package/dist/assets/runtimeEndpointReset-BL9hV6J1.css +1 -0
- package/dist/assets/runtimeEndpointReset-Cx3RE97b.js +149 -0
- package/dist/assets/scheduledTaskNavigation-rhgnZaaj.js +1 -0
- package/dist/assets/sessionChangeSummary-8C8nv-EP.css +1 -0
- package/dist/assets/sessionChangeSummary-CVUA1AFw.js +1 -0
- package/dist/assets/{sessionLookup-B7kUOIpO.js → sessionLookup-C3_vQwLe.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-CQZ16rbO.js → sortable-tabs-strip-C1QmKFdb.js} +1 -1
- package/dist/assets/speechSettingsQueries-BSQ-2JTv.js +4 -0
- package/dist/assets/src-NKCZI3Lg.css +2 -0
- package/dist/assets/{store-7wItZZ7_.js → store-DvN2L3vf.js} +4 -4
- package/dist/assets/{terminalApi-C0_GUlPR.js → terminalApi-B5o8UqWA.js} +1 -1
- package/dist/assets/{textarea-BU8JtaSQ.js → textarea-vtIQM2iP.js} +1 -1
- package/dist/assets/{tooltip-C8DhNU1d.js → tooltip-BpG2mxrT.js} +1 -1
- package/dist/assets/{touch-gestures-zegXCZEP.js → touch-gestures-K2_ZOkKW.js} +1 -1
- package/dist/assets/types-CNTgeeM1.js +2 -0
- package/dist/assets/{uk-BNrdZFvK.js → uk-B_JwElWz.js} +3 -3
- package/dist/assets/{useAppFontEffects-Bs6kVjrE.js → useAppFontEffects-BguV1Hfa.js} +55 -51
- package/dist/assets/useAppFontEffects-RpgNbjA4.css +1 -0
- package/dist/assets/{useAssistantUIStore-NlYBroMc.js → useAssistantUIStore-C9FPlYQz.js} +1 -1
- package/dist/assets/{useDesktopWindowControlsLayout-COBTly74.js → useDesktopWindowControlsLayout-CwgkVw9f.js} +1 -1
- package/dist/assets/useEffectiveDirectory-Ci6Z13kj.js +1 -0
- package/dist/assets/{useFontPreferences-DQAS94Z4.js → useFontPreferences-DMiP_Yy-.js} +1 -1
- package/dist/assets/useMobileNavigationStore-TCj7ZnhV.js +418 -0
- package/dist/assets/{useThemeSystem-8jhE4Zyk.js → useThemeSystem-CGF5jnIh.js} +1 -1
- package/dist/assets/{useUIStore-96W41KFb.js → useUIStore-DI7va1HH.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-BZUO0Si5.js → useWorkerHighlightedLines-HKhuYGSj.js} +1 -1
- package/dist/assets/{vendor-base-ui-CdzJ6My_.js → vendor-base-ui-BQjbsJ43.js} +1 -1
- package/dist/assets/{vendor-cmdk-RDxC-9Iz.js → vendor-cmdk-C3oBVL9X.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-accessibility-COSwgjFs.js → vendor-dnd-kit-accessibility-DxpFzZhi.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-core-5pNnzVdw.js → vendor-dnd-kit-core-B3g3zWQd.js} +1 -1
- package/dist/assets/{vendor-dnd-kit-sortable-Dm50I0m7.js → vendor-dnd-kit-sortable-BKewx0Py.js} +1 -1
- package/dist/assets/{vendor-framer-motion-BQ3-sJMO.js → vendor-framer-motion-C1twy-GF.js} +1 -1
- package/dist/assets/{vendor-markstream-react-Bm0cO70Z.js → vendor-markstream-react-BlbOg72y.js} +3 -3
- package/dist/assets/vendor-motion-BmLx2V78.js +1 -0
- package/dist/assets/{vendor-opencode-client-fxfj4IA_.js → vendor-opencode-client-UL_TecvQ.js} +1 -1
- package/dist/assets/{vendor-opencode-plugin-CQ5ogY33.js → vendor-opencode-plugin-Bw7Q6Nv9.js} +1 -1
- package/dist/assets/{vendor-pierre-diffs-DPBtNDJ5.js → vendor-pierre-diffs-Bj9Nqn6w.js} +1 -1
- package/dist/assets/{vendor-react-BP2cRVqX.js → vendor-react-D5d-V1vN.js} +1 -1
- package/dist/assets/{vendor-react-drawio-Ck9ZKdNN.js → vendor-react-drawio-C-iPmmED.js} +1 -1
- package/dist/assets/{vendor-reactuses-core-BJ-jJ4YM.js → vendor-reactuses-core-BcebBLwF.js} +1 -1
- package/dist/assets/{vendor-solid-js-Dmt4_-Zk.js → vendor-solid-js-0T254UHG.js} +1 -1
- package/dist/assets/{vendor-sonner-ZS8XIOVl.js → vendor-sonner-r2EJnfoo.js} +1 -1
- package/dist/assets/{vendor-stream-diffs-TgIdH4lX.js → vendor-stream-diffs-BnLmeqg2.js} +2 -2
- package/dist/assets/{vendor-tanstack-react-query-CdqCAt40.js → vendor-tanstack-react-query-C4SG3JZB.js} +1 -1
- package/dist/assets/vendor-tanstack-react-virtual-BeZn51tF.js +1 -0
- package/dist/assets/{vendor-zustand-o69pgTEK.js → vendor-zustand-B43HCgwC.js} +1 -1
- package/dist/assets/{zh-CN-DMvJXS23.js → zh-CN-DhFFdHQu.js} +4 -4
- package/dist/assets/{zh-TW-D0wsKLs1.js → zh-TW-BvehppXO.js} +4 -4
- package/dist/index.html +18 -18
- package/dist/mini-chat.html +18 -18
- package/dist/mobile.html +18 -18
- package/package.json +1 -1
- package/server/lib/assistants/DOCUMENTATION.md +68 -37
- package/server/lib/assistants/cards.js +4 -0
- package/server/lib/assistants/cards.test.js +11 -1
- package/server/lib/assistants/contact-attachments.http.test.js +31 -7
- package/server/lib/assistants/contact-store.js +70 -27
- package/server/lib/assistants/contact-store.test.js +88 -8
- package/server/lib/assistants/contact-tools.js +68 -84
- package/server/lib/assistants/contact-tools.test.js +85 -42
- package/server/lib/assistants/harness.js +6 -3
- package/server/lib/assistants/harness.test.js +25 -10
- package/server/lib/assistants/routes.js +25 -3
- package/server/lib/assistants/service.js +283 -146
- package/server/lib/assistants/service.test.js +954 -54
- package/server/lib/assistants/weixin/DOCUMENTATION.md +142 -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 +23 -0
- package/server/lib/assistants/weixin/routes.test.js +41 -0
- package/server/lib/assistants/weixin/runtime.js +357 -0
- package/server/lib/assistants/weixin/runtime.test.js +286 -0
- package/server/lib/assistants/weixin/store.js +103 -0
- package/server/lib/assistants/weixin/typing.js +88 -0
- package/server/lib/assistants/weixin/typing.test.js +185 -0
- package/server/lib/assistants/yuri-project.http.test.js +47 -0
- package/server/lib/assistants/yuri-tools.js +1 -1
- package/server/lib/assistants/yuri-tools.test.js +3 -2
- package/server/lib/git/DOCUMENTATION.md +6 -0
- package/server/lib/git/branches.test.js +18 -0
- package/server/lib/git/service.js +6 -3
- package/server/lib/llm/DOCUMENTATION.md +15 -7
- package/server/lib/llm/bridge-client.js +58 -34
- package/server/lib/llm/bridge-client.test.js +123 -16
- package/server/lib/notifications/APNS.md +7 -4
- package/server/lib/notifications/DOCUMENTATION.md +3 -1
- package/server/lib/notifications/apns-runtime.js +14 -8
- package/server/lib/notifications/apns-runtime.test.js +28 -0
- package/server/lib/notifications/family-completion-gate.js +37 -31
- package/server/lib/notifications/family-completion-gate.test.js +32 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -0
- package/server/lib/opencode/hmr-isolation.test.js +56 -0
- package/server/lib/opencode/lifecycle.js +23 -27
- package/server/lib/opencode/network-runtime.js +8 -14
- package/server/lib/opencode/network-runtime.test.js +4 -4
- package/server/lib/opencode/proxy.js +2 -1
- package/server/lib/opencode/proxy.test.js +1 -0
- package/server/lib/opencode/shutdown-runtime.js +1 -1
- package/server/lib/opencode/shutdown-runtime.test.js +12 -0
- package/server/lib/relay/DOCUMENTATION.md +8 -1
- package/server/lib/relay/relay-server.e2e.test.ts +102 -1
- package/server/lib/relay/service.js +1 -1
- package/server/lib/relay/service.test.js +14 -1
- package/server/lib/request-cors.js +1 -1
- package/server/lib/request-cors.test.js +13 -1
- package/server/lib/session-goal/DOCUMENTATION.md +3 -0
- package/server/lib/session-goal/runtime.js +0 -4
- package/server/lib/session-index/DOCUMENTATION.md +18 -4
- package/server/lib/session-index/event-ingest.js +6 -0
- package/server/lib/session-index/event-ingest.test.js +10 -0
- package/server/lib/session-index/service.js +89 -13
- package/server/lib/session-index/service.test.js +144 -1
- package/server/lib/session-metadata/routes.test.js +44 -0
- package/server/lib/tts/DOCUMENTATION.md +24 -2
- package/server/lib/tts/direct-speech.test.js +28 -3
- package/server/opencode-proxy.test.js +5 -5
- package/dist/assets/AgentAvatar--wjVXk3I.js +0 -1
- package/dist/assets/AssistantView-CSpW-4g6.js +0 -3
- package/dist/assets/Icon-Bn4Eec3Y.js +0 -1
- package/dist/assets/MarkdownRenderer-DP2a0lfG.js +0 -2
- package/dist/assets/MobileDetailNavigation-C9NHt08G.js +0 -1
- package/dist/assets/MobileTabPageHeader-qe23xT2-.js +0 -2
- package/dist/assets/MultiRunWindow-CvHADKf9.js +0 -1
- package/dist/assets/SettingsView-DK8Jkkhd.js +0 -29
- package/dist/assets/SettingsWindow-EP8KZok8.js +0 -1
- package/dist/assets/appThemeRegistry-BnQF2GlY.js +0 -1
- package/dist/assets/collapsible-DqfguRMp.js +0 -1
- package/dist/assets/dialog-BS-KgM5J.js +0 -1
- package/dist/assets/image-loading-DJZLvhMd.js +0 -1
- package/dist/assets/insertionBoundaries-h2be7xbf.js +0 -1
- package/dist/assets/main-BpBrYqtJ.js +0 -169
- package/dist/assets/main-C2QklNP4.js +0 -2
- package/dist/assets/miniChat-C-9deNrt.js +0 -2
- package/dist/assets/mobile-DW7tEL-k.js +0 -2
- package/dist/assets/projectMeta-BwAS96mf.js +0 -1
- package/dist/assets/renderMobileApp-Bipi0hKv.js +0 -28
- package/dist/assets/runtimeConfig-Dx7Y6Yvp.js +0 -2
- package/dist/assets/runtimeEndpointReset-0buInzjw.js +0 -149
- package/dist/assets/runtimeEndpointReset-HYSytKO-.css +0 -1
- package/dist/assets/scheduledTaskNavigation-CYozx15H.js +0 -1
- package/dist/assets/sessionChangeSummary-BGisROOB.js +0 -1
- package/dist/assets/sessionChangeSummary-CRYRvpy7.css +0 -1
- package/dist/assets/speechSettingsQueries-CWXTghOr.js +0 -4
- package/dist/assets/src-BFsc_2gs.css +0 -2
- package/dist/assets/types-C9aO7yfx.js +0 -2
- package/dist/assets/useEffectiveDirectory-Bg0LmEqP.js +0 -1
- package/dist/assets/useMobileNavigationStore-hhiMBg5n.js +0 -418
- package/dist/assets/vendor-motion-B4xmxmaP.js +0 -1
- package/dist/assets/vendor-tanstack-react-virtual-B_EO--9t.js +0 -1
|
@@ -32,66 +32,89 @@ export async function prepareLlmBridgeDirectory({ pluginPath = BRIDGE_PLUGIN_PAT
|
|
|
32
32
|
return directory;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
* Removes bridge directories left by earlier builds or by the former per-process
|
|
37
|
-
* temporary layout. A directory whose Location is still loaded upstream may be
|
|
38
|
-
* in use by another host, so it stays until the upstream idle sweep unloads it.
|
|
39
|
-
* Only failure to read the live inventory skips the whole pass.
|
|
40
|
-
*/
|
|
41
|
-
export async function pruneStaleLlmBridgeDirectories({ client, keep, root = os.tmpdir(), fsLike = fs, signal }) {
|
|
42
|
-
const entries = await Promise.resolve().then(() => client.debug.location.list(signal ? { signal } : undefined)).catch(() => null);
|
|
43
|
-
if (!Array.isArray(entries)) return [];
|
|
44
|
-
const live = new Set(entries.map((entry) => entry?.directory && path.resolve(entry.directory)).filter(Boolean));
|
|
45
|
-
const names = await fsLike.readdir(root).catch(() => []);
|
|
46
|
-
const removed = [];
|
|
47
|
-
for (const name of names) {
|
|
48
|
-
if (!name.startsWith('yuri-inference-')) continue;
|
|
49
|
-
const directory = path.join(root, name);
|
|
50
|
-
if (directory === keep || live.has(directory)) continue;
|
|
51
|
-
const resolved = await fsLike.realpath(directory).catch(() => directory);
|
|
52
|
-
if (live.has(resolved)) continue;
|
|
53
|
-
await fsLike.rm(directory, { recursive: true, force: true }).then(() => removed.push(directory), () => undefined);
|
|
54
|
-
}
|
|
55
|
-
return removed;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
35
|
let directoryPromise;
|
|
59
|
-
|
|
60
|
-
export async function ensureLlmBridgeDirectory({ client } = {}) {
|
|
36
|
+
export async function ensureLlmBridgeDirectory() {
|
|
61
37
|
if (!directoryPromise) directoryPromise = prepareLlmBridgeDirectory()
|
|
62
38
|
.catch(error => { directoryPromise = undefined; throw error; });
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
39
|
+
const pending = directoryPromise;
|
|
40
|
+
const directory = await pending;
|
|
41
|
+
try {
|
|
42
|
+
await fs.access(path.join(directory, '.opencode', 'plugins', 'yuri-llm.js'));
|
|
43
|
+
return directory;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
46
|
+
if (directoryPromise === pending) {
|
|
47
|
+
directoryPromise = prepareLlmBridgeDirectory()
|
|
48
|
+
.catch(error => { directoryPromise = undefined; throw error; });
|
|
49
|
+
}
|
|
50
|
+
return directoryPromise;
|
|
68
51
|
}
|
|
69
|
-
return directory;
|
|
70
52
|
}
|
|
71
53
|
|
|
72
54
|
// The content-addressed directory may be shared with other hosts, so shutdown
|
|
73
55
|
// only forgets it and never deletes it.
|
|
74
56
|
export async function stopLlmBridgeDirectory() {
|
|
75
57
|
directoryPromise = undefined;
|
|
76
|
-
pruneStarted = false;
|
|
77
58
|
}
|
|
78
59
|
|
|
60
|
+
// A Location inventory describes one OpenCode service, not every service using
|
|
61
|
+
// this temporary root. Never delete peer directories based on that inventory.
|
|
62
|
+
const bridgeReloads = new Map();
|
|
63
|
+
const reloadBridgeLocation = ({ key, client, directory, ensureBridgeDirectory }) => {
|
|
64
|
+
const current = bridgeReloads.get(key);
|
|
65
|
+
if (current?.directory === directory) return current.promise;
|
|
66
|
+
const entry = { directory, promise: null };
|
|
67
|
+
entry.promise = Promise.resolve().then(async () => {
|
|
68
|
+
await ensureBridgeDirectory({ client });
|
|
69
|
+
await client.debug.location.evict({ location: { directory } });
|
|
70
|
+
await client.plugin.list({ location: { directory } });
|
|
71
|
+
}).finally(() => {
|
|
72
|
+
if (bridgeReloads.get(key) === entry) bridgeReloads.delete(key);
|
|
73
|
+
});
|
|
74
|
+
// A caller may cancel before subscribing; a shared repair can still finish.
|
|
75
|
+
void entry.promise.catch(() => undefined);
|
|
76
|
+
bridgeReloads.set(key, entry);
|
|
77
|
+
return entry.promise;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const awaitBridgeReload = async (promise, signal) => {
|
|
81
|
+
signal?.throwIfAborted();
|
|
82
|
+
if (!signal) return promise;
|
|
83
|
+
let abort;
|
|
84
|
+
const cancelled = new Promise((_, reject) => {
|
|
85
|
+
abort = () => reject(signal.reason);
|
|
86
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
87
|
+
});
|
|
88
|
+
try { return await Promise.race([promise, cancelled]); }
|
|
89
|
+
finally { signal.removeEventListener('abort', abort); }
|
|
90
|
+
};
|
|
91
|
+
|
|
79
92
|
export async function generateCleanCompletion({ buildOpenCodeUrl, getOpenCodeAuthHeaders, clientFactory,
|
|
80
93
|
providerID, modelID, variant, messages, tools, cacheKey = randomUUID(), maxOutputTokens, signal,
|
|
81
94
|
ensureBridgeDirectory = ensureLlmBridgeDirectory,
|
|
82
95
|
}) {
|
|
83
96
|
signal?.throwIfAborted();
|
|
84
|
-
const
|
|
97
|
+
const providedClient = clientFactory?.();
|
|
98
|
+
const baseUrl = providedClient ? null : buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
99
|
+
const client = providedClient ?? OpenCode.make({ baseUrl, headers: getOpenCodeAuthHeaders() });
|
|
85
100
|
const directory = await ensureBridgeDirectory({ client });
|
|
86
101
|
const options = { location: { directory }, signal };
|
|
87
102
|
const rpc = client.rpc(LlmBridge);
|
|
88
103
|
// Loading this isolated Location activates only its own plugin file, without global config writes.
|
|
89
104
|
await client.plugin.list({ location: { directory } }, { signal });
|
|
90
105
|
let ready;
|
|
106
|
+
let reloaded = false;
|
|
91
107
|
for (let attempt = 0; ; attempt++) {
|
|
92
108
|
try { ready = await rpc.ready({}, options); break; }
|
|
93
109
|
catch (error) {
|
|
94
|
-
if (signal?.aborted || error?.type !== 'rpc.unavailable'
|
|
110
|
+
if (signal?.aborted || error?.type !== 'rpc.unavailable') throw error;
|
|
111
|
+
if (attempt >= 20) {
|
|
112
|
+
if (reloaded || typeof client.debug?.location?.evict !== 'function') throw error;
|
|
113
|
+
reloaded = true;
|
|
114
|
+
await awaitBridgeReload(reloadBridgeLocation({ key: baseUrl ?? client, client, directory, ensureBridgeDirectory }), signal);
|
|
115
|
+
attempt = -1;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
95
118
|
await new Promise((resolve, reject) => {
|
|
96
119
|
const abort = () => { clearTimeout(timer); signal.removeEventListener('abort', abort); reject(signal.reason); };
|
|
97
120
|
const timer = setTimeout(() => { signal?.removeEventListener('abort', abort); resolve(); }, 250);
|
|
@@ -100,6 +123,7 @@ export async function generateCleanCompletion({ buildOpenCodeUrl, getOpenCodeAut
|
|
|
100
123
|
});
|
|
101
124
|
}
|
|
102
125
|
}
|
|
126
|
+
signal?.throwIfAborted();
|
|
103
127
|
if (ready.version !== LLM_BRIDGE_VERSION) throw new Error('Incompatible Yuri LLM bridge');
|
|
104
128
|
const result = await rpc.generate({ providerID, modelID, ...(variant ? { variant } : {}), messages,
|
|
105
129
|
...(tools ? { tools } : {}), cacheKey, ...(maxOutputTokens ? { maxOutputTokens } : {}),
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import { generateCleanCompletion, prepareLlmBridgeDirectory,
|
|
5
|
+
import { ensureLlmBridgeDirectory, generateCleanCompletion, prepareLlmBridgeDirectory, stopLlmBridgeDirectory } from './bridge-client.js';
|
|
6
6
|
import { LLM_BRIDGE_VERSION } from './bridge-contract.js';
|
|
7
7
|
|
|
8
8
|
describe('external OpenCode inference bridge', () => {
|
|
@@ -36,12 +36,102 @@ describe('external OpenCode inference bridge', () => {
|
|
|
36
36
|
} finally { vi.useRealTimers(); }
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
it('passes the client to directory preparation
|
|
39
|
+
it('passes the current client to the injected directory preparation', async () => {
|
|
40
40
|
const client = { plugin: { list: async () => [] }, rpc: () => ({ ready: async () => ({ version: LLM_BRIDGE_VERSION }), generate: async () => ({ text: '', toolCalls: [] }) }) };
|
|
41
41
|
const ensureBridgeDirectory = vi.fn(async () => '/isolated');
|
|
42
42
|
await generateCleanCompletion({ clientFactory: () => client, ensureBridgeDirectory });
|
|
43
43
|
expect(ensureBridgeDirectory).toHaveBeenCalledWith({ client });
|
|
44
44
|
});
|
|
45
|
+
|
|
46
|
+
it('reloads only the isolated Location when a recreated plugin is absent from the loaded runtime', async () => {
|
|
47
|
+
vi.useFakeTimers();
|
|
48
|
+
try {
|
|
49
|
+
let loaded = false;
|
|
50
|
+
const ready = vi.fn(async () => {
|
|
51
|
+
if (!loaded) throw { type: 'rpc.unavailable' };
|
|
52
|
+
return { version: LLM_BRIDGE_VERSION };
|
|
53
|
+
});
|
|
54
|
+
const generate = vi.fn(async () => ({ text: 'recovered', toolCalls: [] }));
|
|
55
|
+
const evict = vi.fn(async () => { loaded = true; });
|
|
56
|
+
const client = {
|
|
57
|
+
plugin: { list: vi.fn(async () => ({ data: [] })) },
|
|
58
|
+
debug: { location: { evict } },
|
|
59
|
+
rpc: () => ({ ready, generate }),
|
|
60
|
+
};
|
|
61
|
+
const ensureBridgeDirectory = vi.fn(async () => '/isolated/bridge');
|
|
62
|
+
const result = generateCleanCompletion({ clientFactory: () => client, ensureBridgeDirectory }).catch(error => error);
|
|
63
|
+
await vi.runAllTimersAsync();
|
|
64
|
+
expect(await result).toMatchObject({ text: 'recovered' });
|
|
65
|
+
expect(evict).toHaveBeenCalledExactlyOnceWith({ location: { directory: '/isolated/bridge' } });
|
|
66
|
+
expect(ensureBridgeDirectory).toHaveBeenCalledTimes(2);
|
|
67
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
68
|
+
} finally { vi.useRealTimers(); }
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('bounds readiness recovery and never generates while RPC remains unavailable', async () => {
|
|
72
|
+
vi.useFakeTimers();
|
|
73
|
+
try {
|
|
74
|
+
const ready = vi.fn(async () => { throw { type: 'rpc.unavailable' }; });
|
|
75
|
+
const generate = vi.fn();
|
|
76
|
+
const evict = vi.fn(async () => {});
|
|
77
|
+
const client = { plugin: { list: async () => [] }, debug: { location: { evict } }, rpc: () => ({ ready, generate }) };
|
|
78
|
+
const result = generateCleanCompletion({ clientFactory: () => client, ensureBridgeDirectory: async () => '/isolated' }).catch(error => error);
|
|
79
|
+
await vi.runAllTimersAsync();
|
|
80
|
+
expect(await result).toMatchObject({ type: 'rpc.unavailable' });
|
|
81
|
+
expect(ready).toHaveBeenCalledTimes(42);
|
|
82
|
+
expect(evict).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(generate).not.toHaveBeenCalled();
|
|
84
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
85
|
+
} finally { vi.useRealTimers(); }
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('shares recovery without letting a cancelled caller abort its peer or generate late', async () => {
|
|
89
|
+
vi.useFakeTimers();
|
|
90
|
+
try {
|
|
91
|
+
let loaded = false;
|
|
92
|
+
let release;
|
|
93
|
+
const ready = vi.fn(async () => {
|
|
94
|
+
if (!loaded) throw { type: 'rpc.unavailable' };
|
|
95
|
+
return { version: LLM_BRIDGE_VERSION };
|
|
96
|
+
});
|
|
97
|
+
const generate = vi.fn(async () => ({ text: 'recovered' }));
|
|
98
|
+
const evict = vi.fn(() => new Promise(resolve => { release = () => { loaded = true; resolve(); }; }));
|
|
99
|
+
const client = { plugin: { list: async () => [] }, debug: { location: { evict } }, rpc: () => ({ ready, generate }) };
|
|
100
|
+
const controller = new AbortController();
|
|
101
|
+
const input = { clientFactory: () => client, ensureBridgeDirectory: async () => '/isolated' };
|
|
102
|
+
const first = generateCleanCompletion({ ...input, signal: controller.signal }).catch(error => error);
|
|
103
|
+
const second = generateCleanCompletion(input);
|
|
104
|
+
await vi.advanceTimersByTimeAsync(5_000);
|
|
105
|
+
expect(evict).toHaveBeenCalledTimes(1);
|
|
106
|
+
const reason = new Error('user cancelled');
|
|
107
|
+
controller.abort(reason);
|
|
108
|
+
expect(await first).toBe(reason);
|
|
109
|
+
release();
|
|
110
|
+
expect(await second).toMatchObject({ text: 'recovered' });
|
|
111
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
112
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
113
|
+
} finally { vi.useRealTimers(); }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it.each(['authentication_required', 'transport'])('does not reload a Location for %s readiness errors', async (type) => {
|
|
117
|
+
const error = { type };
|
|
118
|
+
const evict = vi.fn();
|
|
119
|
+
const generate = vi.fn();
|
|
120
|
+
const client = { plugin: { list: async () => [] }, debug: { location: { evict } }, rpc: () => ({ ready: async () => { throw error; }, generate }) };
|
|
121
|
+
await expect(generateCleanCompletion({ clientFactory: () => client, ensureBridgeDirectory: async () => '/isolated' })).rejects.toBe(error);
|
|
122
|
+
expect(evict).not.toHaveBeenCalled();
|
|
123
|
+
expect(generate).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('never replays generation even when it returns rpc.unavailable after readiness', async () => {
|
|
127
|
+
const error = { type: 'rpc.unavailable' };
|
|
128
|
+
const evict = vi.fn();
|
|
129
|
+
const generate = vi.fn(async () => { throw error; });
|
|
130
|
+
const client = { plugin: { list: async () => [] }, debug: { location: { evict } }, rpc: () => ({ ready: async () => ({ version: LLM_BRIDGE_VERSION }), generate }) };
|
|
131
|
+
await expect(generateCleanCompletion({ clientFactory: () => client, ensureBridgeDirectory: async () => '/isolated' })).rejects.toBe(error);
|
|
132
|
+
expect(generate).toHaveBeenCalledTimes(1);
|
|
133
|
+
expect(evict).not.toHaveBeenCalled();
|
|
134
|
+
});
|
|
45
135
|
});
|
|
46
136
|
|
|
47
137
|
describe('bridge directory lifecycle', () => {
|
|
@@ -52,6 +142,8 @@ describe('bridge directory lifecycle', () => {
|
|
|
52
142
|
return root;
|
|
53
143
|
};
|
|
54
144
|
afterEach(async () => {
|
|
145
|
+
await stopLlmBridgeDirectory();
|
|
146
|
+
vi.restoreAllMocks();
|
|
55
147
|
await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true })));
|
|
56
148
|
});
|
|
57
149
|
|
|
@@ -74,23 +166,38 @@ describe('bridge directory lifecycle', () => {
|
|
|
74
166
|
expect((await fs.readdir(path.join(second, '.opencode', 'plugins')))).toEqual(['yuri-llm.js']);
|
|
75
167
|
});
|
|
76
168
|
|
|
77
|
-
it('
|
|
169
|
+
it('never deletes another upstream service\'s bridge directory', async () => {
|
|
170
|
+
const root = await makeRoot();
|
|
171
|
+
vi.spyOn(os, 'tmpdir').mockReturnValue(root);
|
|
172
|
+
const peer = path.join(root, 'yuri-inference-other-service');
|
|
173
|
+
await fs.mkdir(peer);
|
|
174
|
+
const list = vi.fn(async () => []);
|
|
175
|
+
await ensureLlmBridgeDirectory({ client: { debug: { location: { list } } } });
|
|
176
|
+
expect(list).not.toHaveBeenCalled();
|
|
177
|
+
expect(await fs.stat(peer)).toBeDefined();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('restages a deleted plugin instead of trusting a cached directory path', async () => {
|
|
78
181
|
const root = await makeRoot();
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
expect(await
|
|
86
|
-
expect((await fs.readdir(root)).sort()).toEqual([path.basename(unrelated), path.basename(keep), path.basename(loaded)].sort());
|
|
182
|
+
vi.spyOn(os, 'tmpdir').mockReturnValue(root);
|
|
183
|
+
const directory = await ensureLlmBridgeDirectory();
|
|
184
|
+
const target = path.join(directory, '.opencode', 'plugins', 'yuri-llm.js');
|
|
185
|
+
const code = await fs.readFile(target);
|
|
186
|
+
await fs.rm(directory, { recursive: true });
|
|
187
|
+
expect(await ensureLlmBridgeDirectory()).toBe(directory);
|
|
188
|
+
expect(await fs.readFile(target)).toEqual(code);
|
|
87
189
|
});
|
|
88
190
|
|
|
89
|
-
it('
|
|
191
|
+
it('checks warm staged assets without rereading the bundle or rewriting files', async () => {
|
|
90
192
|
const root = await makeRoot();
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
193
|
+
vi.spyOn(os, 'tmpdir').mockReturnValue(root);
|
|
194
|
+
const directory = await ensureLlmBridgeDirectory();
|
|
195
|
+
const read = vi.spyOn(fs, 'readFile');
|
|
196
|
+
const write = vi.spyOn(fs, 'writeFile');
|
|
197
|
+
const access = vi.spyOn(fs, 'access');
|
|
198
|
+
for (let index = 0; index < 50; index++) expect(await ensureLlmBridgeDirectory()).toBe(directory);
|
|
199
|
+
expect(access).toHaveBeenCalledTimes(50);
|
|
200
|
+
expect(read).not.toHaveBeenCalled();
|
|
201
|
+
expect(write).not.toHaveBeenCalled();
|
|
95
202
|
});
|
|
96
203
|
});
|
|
@@ -138,10 +138,13 @@ is server-global, so every device token of a server sees the same badge.
|
|
|
138
138
|
|
|
139
139
|
## Modes
|
|
140
140
|
|
|
141
|
-
- **Relay (default):** Host has no Apple key.
|
|
142
|
-
|
|
143
|
-
`/v1/push/send` (register URL is
|
|
144
|
-
|
|
141
|
+
- **Relay (default):** Host has no Apple key. `YURI_PUSH_RELAY_URL` selects the Push
|
|
142
|
+
send URL independently. Without that override, a custom effective Relay `wss://`/`ws://`
|
|
143
|
+
URL maps to same-host `https://`/`http://` `/v1/push/send` (register URL is
|
|
144
|
+
`/v1/push/register-token`). The product default Workers Relay provides data transport
|
|
145
|
+
only: APNs and Live Activity delivery require a separate Push URL or direct credentials,
|
|
146
|
+
and no device tokens are sent to that Worker. A Push origin switch re-registers persisted
|
|
147
|
+
tokens and binds them again before the first send. Resolver failure leaves Push unavailable.
|
|
145
148
|
- **Direct (fallback):** set `YURI_PUSH_RELAY_DISABLED=true` + `YURI_APNS_KEY_ID/
|
|
146
149
|
TEAM_ID/P8` to sign+send from the server itself (HTTP/2 + ES256 JWT); no relay binding needed.
|
|
147
150
|
|
|
@@ -14,7 +14,7 @@ Android notification-only subscriptions send the App locale in `Accept-Language`
|
|
|
14
14
|
- `packages/web/server/lib/notifications/index.js`: public entrypoint imported by `packages/web/server/index.js`.
|
|
15
15
|
- `packages/web/server/lib/notifications/routes.js`: route registration for push, visibility, and session status/attention endpoints.
|
|
16
16
|
- `packages/web/server/lib/notifications/push-runtime.js`: push subscription persistence, VAPID initialization, and UI visibility runtime.
|
|
17
|
-
- `packages/web/server/lib/notifications/apns-runtime.js`: native iOS APNs device-token persistence + delivery, plus a separate Live Activity token store and `end` send path. Two modes: **relay** (default — sign + POST tokens + generic text to the isolated Push Relay in `packages/relay-server/src/push/`, which holds the project APNs key) and **direct** (fallback — sign ES256 JWT with Node crypto + HTTP/2, when `YURI_PUSH_RELAY_DISABLED=true`).
|
|
17
|
+
- `packages/web/server/lib/notifications/apns-runtime.js`: native iOS APNs device-token persistence + delivery, plus a separate Live Activity token store and `end` send path. Two modes: **relay** (default — sign + POST tokens + generic text to the isolated Push Relay in `packages/relay-server/src/push/`, which holds the project APNs key) and **direct** (fallback — sign ES256 JWT with Node crypto + HTTP/2, when `YURI_PUSH_RELAY_DISABLED=true`). `YURI_PUSH_RELAY_URL` explicitly selects an independent Push service. Otherwise, only a custom effective Relay `wss`/`ws` URL maps to same-host `https`/`http` `/v1/push/send`; the product default Workers Relay has no Push service and receives no device tokens. An invalid or failed Relay resolver leaves Push unavailable rather than falling back to a hosted origin. Before each relay send, the runtime checks an in-memory registration success cache (keyed by current register URL + token + platform) and only POSTs `/v1/push/register-token` for cache misses; only successfully bound tokens are sent. Switching Relay/Push URL clears that cache so persisted tokens re-bind to the new origin on the next send or `reRegisterAllTokens()`. Each server has an auto-generated ECDSA P-256 keypair (`getOrCreateRelayKeypair`, persisted in settings); it binds tokens on the relay (`/v1/push/register-token`) and signs every relay request, so the relay only delivers to tokens bound to that server. APNs is the iOS app's sole notification channel (no local notifications) and is NOT gated on UI visibility — iOS suppresses the foreground banner instead. APNs push carries only generic text (scenario title + session name) — see `APNS.md`. Android uses the separate native notification stream described above. Live Activity tokens are persisted beside alert tokens in the same file (`version` 2, `liveActivityTokensBySession`) without mixing the two token types; v1 files remain readable. Live Activity relay bind/send uses `/v1/push/register-live-activity-token`, `/v1/push/unregister-live-activity-token`, and `/v1/push/live-activity`.
|
|
18
18
|
- `packages/web/server/lib/notifications/emitter-runtime.js`: desktop/stdout + UI SSE notification emission runtime.
|
|
19
19
|
- `packages/web/server/lib/notifications/runtime.js`: trigger runtime for OpenCode event-driven notification fanout.
|
|
20
20
|
- Assistant-owned scheduled results first enter the assistant's read-only result
|
|
@@ -63,6 +63,8 @@ Ordinary completion means the whole root-session family has stopped. An assistan
|
|
|
63
63
|
|
|
64
64
|
Failed/malformed activity or unknown/cyclic ancestry defers completion rather than treating it as empty. While candidates exist, a single two-second retry timer recovers failed reads and missed child terminal events; no candidates means no polling. Execution/retry/step starts invalidate in-flight eligibility, and a new root run cancels its older candidate. Parent failures, deletion and user interruption cancel success. Event revisions fence stale reads and notification-template enrichment. Successful handling deduplicates terminal events for that root until a new execution starts, replacing the old five-second cooldown so a legitimate short next task can notify. Pending/dedup state is in-memory for the runtime lifetime; historical completions are not replayed after Host restart. `dispose()` clears completion retries and question/permission timers; VS Code also resets its gate on runtime switches.
|
|
65
65
|
|
|
66
|
+
Assistant worker watches reuse this gate and its `readSessionFamilyActivity` reader. Their `rootsOnly: false` mode supports explicitly watched child subtrees; `deduplicate: false` delegates one-shot consumption to the Assistant SQLite watch transaction instead of retaining parallel lifetime state. Defaults preserve ordinary Host/VS Code root-only notification deduplication. `flush()` lets Assistant reconciliation await currently admitted checks. Parent reads are deduplicated within each family snapshot with concurrency capped at four.
|
|
67
|
+
|
|
66
68
|
Desktop, UI SSE, web-push, APNs and completion-triggered Live Activity end all pass this barrier. Existing visibility/settings, root/system-session suppression, goal-specific notifications and channel failure isolation remain delivery-owned. Error Live Activity updates and question/permission prompts remain immediate under their existing policies.
|
|
67
69
|
- `createNotificationTriggerRuntime(dependencies)`: creates runtime-owned debounced trigger handling for OpenCode events.
|
|
68
70
|
- Returned API:
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Device tokens are persisted per UI session (mirrors push-runtime.js). Delivery has two
|
|
4
4
|
// modes, chosen at send time:
|
|
5
|
-
// - Relay (default): POST tokens + generic text to
|
|
6
|
-
// (`/v1/push/*` on
|
|
7
|
-
//
|
|
5
|
+
// - Relay (default): POST tokens + generic text to a configured Push service
|
|
6
|
+
// (`YURI_PUSH_RELAY_URL`, or `/v1/push/*` on a custom Relay host). The product
|
|
7
|
+
// default Workers Relay has no Push service. The isolated Push process holds
|
|
8
|
+
// the project APNs key and signs+sends.
|
|
8
9
|
// - Direct (fallback): sign an ES256 JWT with Node crypto and send over HTTP/2 ourselves,
|
|
9
10
|
// for self-hosters who set YURI_APNS_* and YURI_PUSH_RELAY_DISABLED=true.
|
|
10
11
|
// Wired into the same trigger fanout as web push (see runtime.js); the relay carries only
|
|
@@ -784,8 +785,8 @@ export const createApnsRuntime = (deps) => {
|
|
|
784
785
|
req.end(body);
|
|
785
786
|
});
|
|
786
787
|
|
|
787
|
-
// Relay mode (default): the single APNs key lives in the isolated Push process on
|
|
788
|
-
//
|
|
788
|
+
// Relay mode (default): the single APNs key lives in the isolated Push process, not on
|
|
789
|
+
// each user's server. Custom Relay origins may serve Push at `/v1/push/*`. The
|
|
789
790
|
// server just POSTs device tokens + generic text; Push signs + sends and reports which tokens
|
|
790
791
|
// to drop. Direct mode (below) is the fallback for self-hosters who set YURI_APNS_*
|
|
791
792
|
// and disable the relay.
|
|
@@ -812,14 +813,19 @@ export const createApnsRuntime = (deps) => {
|
|
|
812
813
|
const resolved = await resolveEffectiveRelayUrl();
|
|
813
814
|
if (typeof resolved === 'string' && resolved.trim()) {
|
|
814
815
|
if (derivePushSendUrlFromRelayUrl(resolved)) relayWsUrl = resolved.trim();
|
|
815
|
-
else
|
|
816
|
+
else {
|
|
817
|
+
console.warn('[Push relay] resolver returned a non-WebSocket URL; Push Relay unavailable');
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
816
820
|
}
|
|
817
821
|
} catch {
|
|
818
822
|
console.warn('[Push relay] resolver failed; Push Relay unavailable');
|
|
823
|
+
return null;
|
|
819
824
|
}
|
|
820
825
|
}
|
|
821
|
-
const url = derivePushSendUrlFromRelayUrl(relayWsUrl)
|
|
822
|
-
|
|
826
|
+
const url = derivePushSendUrlFromRelayUrl(relayWsUrl);
|
|
827
|
+
// The product Worker only forwards encrypted data; never send device tokens to it.
|
|
828
|
+
if (!url || url === derivePushSendUrlFromRelayUrl(DEFAULT_RELAY_URL)) return null;
|
|
823
829
|
return buildRelayConfig(url);
|
|
824
830
|
};
|
|
825
831
|
|
|
@@ -463,6 +463,34 @@ describe('apns runtime push relay derivation and re-register', () => {
|
|
|
463
463
|
expect(registerUrls(fetchMock)).toEqual([]);
|
|
464
464
|
});
|
|
465
465
|
|
|
466
|
+
it.each(['settings', 'env'])('does not derive Push from the product Worker selected through %s', async (source) => {
|
|
467
|
+
const relayUrl = 'wss://relay.useyuri.top/ws';
|
|
468
|
+
if (source === 'env') process.env.YURI_RELAY_URL = relayUrl;
|
|
469
|
+
let settings = source === 'settings' ? { privateRelay: { relayUrl } } : {};
|
|
470
|
+
const fetchMock = vi.fn(async () => jsonResponse({ ok: true, results: [] }));
|
|
471
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
472
|
+
const runtime = createApnsRuntime(makeDeps({
|
|
473
|
+
readSettingsFromDiskMigrated: async () => settings,
|
|
474
|
+
writeSettingsToDisk: async (next) => { settings = next; },
|
|
475
|
+
resolveEffectiveRelayUrl: async () => resolveEffectiveRelayUrl({ settings }),
|
|
476
|
+
}));
|
|
477
|
+
await runtime.addOrUpdateApnsToken('s1', 'tokenA');
|
|
478
|
+
await runtime.sendApnsToAllUiSessions({ title: 'Ready' });
|
|
479
|
+
await expect(runtime.reRegisterAllTokens()).resolves.toEqual({ attempted: 0, succeeded: 0, failed: 0 });
|
|
480
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('uses a separately configured Push service with the default Workers data Relay', async () => {
|
|
484
|
+
process.env.YURI_PUSH_RELAY_URL = 'https://push.example/v1/push/send';
|
|
485
|
+
const fetchMock = vi.fn(async () => jsonResponse({ ok: true, results: [] }));
|
|
486
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
487
|
+
const runtime = createApnsRuntime(makeDeps());
|
|
488
|
+
await runtime.addOrUpdateApnsToken('s1', 'tokenA');
|
|
489
|
+
await runtime.sendApnsToAllUiSessions({ title: 'Ready' });
|
|
490
|
+
expect(registerUrls(fetchMock)).toEqual(['https://push.example/v1/push/register-token']);
|
|
491
|
+
expect(sendUrls(fetchMock)).toEqual(['https://push.example/v1/push/send']);
|
|
492
|
+
});
|
|
493
|
+
|
|
466
494
|
it('re-registers persisted tokens against the current relay', async () => {
|
|
467
495
|
process.env.YURI_PUSH_RELAY_URL = 'https://relay-a.test/v1/push/send';
|
|
468
496
|
const fetchMock = vi.fn(async () => jsonResponse({ ok: true, results: [] }));
|
|
@@ -25,8 +25,39 @@ export function completionEvent(payload) {
|
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** Read process activity and its authoritative ancestry once, with bounded metadata concurrency. */
|
|
29
|
+
export async function readSessionFamilyActivity({ loadActiveSessionIds, loadParent }) {
|
|
30
|
+
const membership = await loadActiveSessionIds();
|
|
31
|
+
if (!membership || typeof membership[Symbol.iterator] !== 'function') throw new Error('Unknown session activity');
|
|
32
|
+
const parents = new Map();
|
|
33
|
+
const parentOf = (id) => {
|
|
34
|
+
if (!parents.has(id)) parents.set(id, Promise.resolve().then(() => loadParent(id)).then((parent) => {
|
|
35
|
+
if (parent !== null && (typeof parent !== 'string' || !parent)) throw new Error('Unknown session ancestry');
|
|
36
|
+
return parent;
|
|
37
|
+
}));
|
|
38
|
+
return parents.get(id);
|
|
39
|
+
};
|
|
40
|
+
const activeRoots = new Set();
|
|
41
|
+
const activeSessions = new Set(membership);
|
|
42
|
+
const ids = [...activeSessions];
|
|
43
|
+
let cursor = 0;
|
|
44
|
+
await Promise.all(Array.from({ length: Math.min(4, ids.length) }, async () => {
|
|
45
|
+
while (cursor < ids.length) {
|
|
46
|
+
let id = ids[cursor++];
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
while (id) {
|
|
49
|
+
if (seen.has(id)) throw new Error('Cyclic session ancestry');
|
|
50
|
+
seen.add(id);
|
|
51
|
+
activeRoots.add(id);
|
|
52
|
+
id = await parentOf(id);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
return { activeRoots, activeSessions, parentOf };
|
|
57
|
+
}
|
|
58
|
+
|
|
28
59
|
/** Runtime-local completion barrier shared by Host fanout and VS Code. */
|
|
29
|
-
export function createFamilyCompletionGate({ loadActiveSessionIds, loadParent, onReady, retryMs = 2000 }) {
|
|
60
|
+
export function createFamilyCompletionGate({ loadActiveSessionIds, loadParent, onReady, retryMs = 2000, rootsOnly = true, deduplicate = true }) {
|
|
30
61
|
const pending = new Map();
|
|
31
62
|
const delivered = new Set();
|
|
32
63
|
const running = new Set();
|
|
@@ -50,39 +81,13 @@ export function createFamilyCompletionGate({ loadActiveSessionIds, loadParent, o
|
|
|
50
81
|
const version = revision;
|
|
51
82
|
const generation = epoch;
|
|
52
83
|
const current = () => !disposed && epoch === generation && revision === version;
|
|
53
|
-
const membership = await loadActiveSessionIds();
|
|
54
|
-
if (!membership || typeof membership[Symbol.iterator] !== 'function') throw new Error('Unknown session activity');
|
|
55
|
-
const active = new Set(membership);
|
|
56
|
-
if (!current()) return;
|
|
57
|
-
const parents = new Map();
|
|
58
|
-
const parentOf = (id) => {
|
|
59
|
-
if (!parents.has(id)) parents.set(id, Promise.resolve().then(() => loadParent(id)).then((parent) => {
|
|
60
|
-
if (parent !== null && (typeof parent !== 'string' || !parent)) throw new Error('Unknown session ancestry');
|
|
61
|
-
return parent;
|
|
62
|
-
}));
|
|
63
|
-
return parents.get(id);
|
|
64
|
-
};
|
|
65
84
|
// A running ID can belong to any pending root, including through idle ancestors.
|
|
66
|
-
const activeRoots =
|
|
67
|
-
const ids = [...active];
|
|
68
|
-
let cursor = 0;
|
|
69
|
-
await Promise.all(Array.from({ length: Math.min(4, ids.length) }, async () => {
|
|
70
|
-
while (cursor < ids.length) {
|
|
71
|
-
let id = ids[cursor++];
|
|
72
|
-
const seen = new Set();
|
|
73
|
-
while (id) {
|
|
74
|
-
if (seen.has(id)) throw new Error('Cyclic session ancestry');
|
|
75
|
-
seen.add(id);
|
|
76
|
-
activeRoots.add(id);
|
|
77
|
-
id = await parentOf(id);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}));
|
|
85
|
+
const { activeRoots, parentOf } = await readSessionFamilyActivity({ loadActiveSessionIds, loadParent });
|
|
81
86
|
for (const [id, candidate] of pending) {
|
|
82
87
|
if (!current()) return;
|
|
83
88
|
const parent = await parentOf(id);
|
|
84
89
|
if (!current() || pending.get(id) !== candidate) continue;
|
|
85
|
-
if (parent) { pending.delete(id); continue; }
|
|
90
|
+
if (rootsOnly && parent) { pending.delete(id); continue; }
|
|
86
91
|
if (activeRoots.has(id)) continue;
|
|
87
92
|
const isCurrent = () => current() && pending.get(id) === candidate;
|
|
88
93
|
const handled = await onReady(candidate.payload, isCurrent);
|
|
@@ -90,7 +95,7 @@ export function createFamilyCompletionGate({ loadActiveSessionIds, loadParent, o
|
|
|
90
95
|
// fanout must not make that same completion eligible a second time.
|
|
91
96
|
if (handled === false || pending.get(id) !== candidate) continue;
|
|
92
97
|
pending.delete(id);
|
|
93
|
-
delivered.add(id);
|
|
98
|
+
if (deduplicate) delivered.add(id);
|
|
94
99
|
running.delete(id);
|
|
95
100
|
}
|
|
96
101
|
};
|
|
@@ -122,6 +127,7 @@ export function createFamilyCompletionGate({ loadActiveSessionIds, loadParent, o
|
|
|
122
127
|
};
|
|
123
128
|
|
|
124
129
|
return {
|
|
130
|
+
flush: drain,
|
|
125
131
|
observe(event, payload) {
|
|
126
132
|
if (disposed || !event) return Promise.resolve();
|
|
127
133
|
revision += 1;
|
|
@@ -135,7 +141,7 @@ export function createFamilyCompletionGate({ loadActiveSessionIds, loadParent, o
|
|
|
135
141
|
} else if (kind === 'cancel') {
|
|
136
142
|
running.delete(sessionId);
|
|
137
143
|
pending.delete(sessionId);
|
|
138
|
-
delivered.add(sessionId);
|
|
144
|
+
if (deduplicate) delivered.add(sessionId);
|
|
139
145
|
} else if (kind === 'complete') {
|
|
140
146
|
running.delete(sessionId);
|
|
141
147
|
if (!delivered.has(sessionId)) {
|
|
@@ -17,6 +17,38 @@ const setup = (overrides = {}) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
describe('family completion authority', () => {
|
|
20
|
+
it('bounds ancestor reads to four and deduplicates a shared parent across 40 active children', async () => {
|
|
21
|
+
const children = Array.from({ length: 40 }, (_, index) => `child-${index}`);
|
|
22
|
+
let concurrent = 0;
|
|
23
|
+
let peak = 0;
|
|
24
|
+
const loadActiveSessionIds = vi.fn(async () => children);
|
|
25
|
+
const loadParent = vi.fn(async (id) => {
|
|
26
|
+
concurrent += 1;
|
|
27
|
+
peak = Math.max(peak, concurrent);
|
|
28
|
+
await Promise.resolve();
|
|
29
|
+
concurrent -= 1;
|
|
30
|
+
return id === 'root' ? null : 'root';
|
|
31
|
+
});
|
|
32
|
+
const { onReady } = setup({ loadActiveSessionIds, loadParent });
|
|
33
|
+
await gate.observe(event('complete', 'root'), {});
|
|
34
|
+
expect(onReady).not.toHaveBeenCalled();
|
|
35
|
+
expect(loadActiveSessionIds).toHaveBeenCalledTimes(1);
|
|
36
|
+
expect(loadParent).toHaveBeenCalledTimes(41);
|
|
37
|
+
expect(loadParent.mock.calls.filter(([id]) => id === 'root')).toHaveLength(1);
|
|
38
|
+
expect(peak).toBeLessThanOrEqual(4);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('can monitor an explicitly watched child subtree without notifying its ancestors', async () => {
|
|
42
|
+
const { state, onReady } = setup({ rootsOnly: false });
|
|
43
|
+
state.active = ['root', 'nested'];
|
|
44
|
+
await gate.observe(event('complete', 'child'), { id: 'child' });
|
|
45
|
+
expect(onReady).not.toHaveBeenCalled();
|
|
46
|
+
state.active = ['root'];
|
|
47
|
+
await gate.observe(event('changed', 'nested'), {});
|
|
48
|
+
expect(onReady).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(onReady.mock.calls[0][0]).toEqual({ id: 'child' });
|
|
50
|
+
});
|
|
51
|
+
|
|
20
52
|
it('waits for an idle parent and all nested descendants, then emits only the parent once', async () => {
|
|
21
53
|
const { state, onReady } = setup();
|
|
22
54
|
state.active = ['child', 'nested', 'other'];
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
## Purpose
|
|
4
4
|
This module provides OpenCode server integration utilities for the web server runtime, including configuration management and provider authentication.
|
|
5
5
|
|
|
6
|
+
OpenCode upstream calls are V2-only: startup/readiness probes use `/api/info`
|
|
7
|
+
without a legacy health fallback. Both Host SSE entrypoints forward upstream
|
|
8
|
+
to `/api/event`; the Host-owned global WebSocket route is unchanged. Status
|
|
9
|
+
diagnostics use provider/location/session-active V2 routes and location query
|
|
10
|
+
encoding, not removed V1 endpoints.
|
|
11
|
+
|
|
6
12
|
## Entrypoints and structure
|
|
7
13
|
- Pairing transport discovery includes the serving host's `serverName` (OS
|
|
8
14
|
hostname), not the browser's machine name. The pairing form uses it as an
|