@yuriai/web 0.2.25 → 0.2.27-beta.2
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-BW4Zg8bo.js +1 -0
- package/dist/assets/AssistantView-Cl0ZeXwr.js +3 -0
- package/dist/assets/{DiagramView-DN_rHdr9.js → DiagramView-D6wdXRzu.js} +1 -1
- package/dist/assets/{FadeInOnReveal-555z1y1N.js → FadeInOnReveal-gOsILpSk.js} +1 -1
- package/dist/assets/{GuiPluginSurface-BPMATuPa.js → GuiPluginSurface-DOZAQKX0.js} +1 -1
- package/dist/assets/{GuiPluginWindow-CAmfr79x.js → GuiPluginWindow-tGvc4_0g.js} +1 -1
- package/dist/assets/Icon-DvUDsV1z.js +1 -0
- package/dist/assets/{ImageLoadingPlaceholder-BMsQLN_b.js → ImageLoadingPlaceholder-9xYbKqtf.js} +1 -1
- package/dist/assets/{LoadingImage-DI7sb_H_.js → LoadingImage-CiOcKPfb.js} +1 -1
- package/dist/assets/MarkdownRenderer-DZkP4UNr.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-B9K5q0Lc.js → MarkdownRendererImpl-BXzPUEEo.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-9gUEVQck.js → MarkstreamRendererImpl-B-NWd069.js} +1 -1
- package/dist/assets/MobileDetailNavigation-5U28hfYf.js +1 -0
- package/dist/assets/{MobileResizableSheet-_6OvPSMI.js → MobileResizableSheet-ZL-zPa3W.js} +1 -1
- package/dist/assets/{MobileShareBridge-BrdOiu_r.js → MobileShareBridge-JSH_Y8Ps.js} +3 -3
- package/dist/assets/MobileTabPageHeader-Bj9MIS38.js +2 -0
- package/dist/assets/MultiRunWindow-ZPz62Aqg.js +1 -0
- package/dist/assets/{OnboardingScreen-g8PDztN3.js → OnboardingScreen-BQNoy9o1.js} +1 -1
- package/dist/assets/{OverlayScrollbar-COv8rH_z.js → OverlayScrollbar-BwCFalSw.js} +1 -1
- package/dist/assets/SettingsView-B17qt8dh.js +29 -0
- package/dist/assets/SettingsWindow-CIFNHb-F.js +1 -0
- package/dist/assets/{TerminalView-BLer-ZhM.js → TerminalView-BZZ8LW4d.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DI-s2TBb.js → ToolOutputDialog-BKuVpgEu.js} +2 -2
- package/dist/assets/{YuriLogo-BP4j1iqV.js → YuriLogo-C1Ty-RTB.js} +1 -1
- package/dist/assets/appThemeRegistry-DqGuzMaH.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-DuHjvKJJ.js} +1 -1
- package/dist/assets/{capgoAdapter-B31jIkD8.js → capgoAdapter-B-tddboe.js} +1 -1
- package/dist/assets/collapsible-B8eL5nLo.js +1 -0
- package/dist/assets/{device-hj359GjJ.js → device-BjRYYXNT.js} +1 -1
- package/dist/assets/{diagram-hEIRiKol.js → diagram-ChoQDKzy.js} +1 -1
- package/dist/assets/dialog-CTYD3Sbr.css +1 -0
- package/dist/assets/dialog-CVhqZux0.js +1 -0
- package/dist/assets/{dropdown-menu.styles-xxM2ofOp.js → dropdown-menu.styles-DGvlOX_5.js} +1 -1
- package/dist/assets/{es-Clj7CS2r.js → es-B8sAsuo5.js} +3 -3
- package/dist/assets/{fileMentionTouchSelection-CTh0Mc2g.js → fileMentionTouchSelection-Dd-iSIe2.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-BPpW8T-l.js} +3 -3
- package/dist/assets/{gitApi-deADOzlN.js → gitApi-D43bAQh1.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-E_oYiXZT.js} +1 -1
- package/dist/assets/insertionBoundaries-BQjiZAmZ.js +1 -0
- package/dist/assets/{ja-Co0dxiN_.js → ja-DEoFDi7P.js} +3 -3
- package/dist/assets/{ko-BltElAGq.js → ko-B45xHN6I.js} +3 -3
- package/dist/assets/main-C6MDfyZy.js +2 -0
- package/dist/assets/main-u5iQScJs.js +169 -0
- package/dist/assets/{markdownHeightCache-DnR01ECa.js → markdownHeightCache-heNXHdzb.js} +1 -1
- package/dist/assets/{markdownTheme-DHoKvD6O.js → markdownTheme-hpURsgju.js} +1 -1
- package/dist/assets/{mcpQueries-Cpb22_60.js → mcpQueries-BqKVe4Su.js} +1 -1
- package/dist/assets/miniChat-Dhfn71Re.js +2 -0
- package/dist/assets/mobile-DSVdPfcG.js +2 -0
- package/dist/assets/{mobileBackNavigation-BibkyIeB.js → mobileBackNavigation-DHxFQ7SY.js} +1 -1
- package/dist/assets/{multirun-CPvUnP91.js → multirun-CPOzaEQj.js} +2 -2
- package/dist/assets/{native-BMAEg2E6.js → native-De1DIkLZ.js} +1 -1
- package/dist/assets/{native-config-DA8S8EqV.js → native-config-oauL2ekt.js} +1 -1
- package/dist/assets/{persistence-CBL0OOdj.js → persistence-JyLTFv27.js} +1 -1
- package/dist/assets/{pl-qd6Wnl7H.js → pl-Bm3Je_AX.js} +3 -3
- package/dist/assets/projectMeta-YDMdD3AP.js +1 -0
- package/dist/assets/{pt-BR-CsOFfQXS.js → pt-BR-BiQwFHhL.js} +3 -3
- package/dist/assets/{react-BYRXYlGz.js → react-CURmDhtB.js} +1 -1
- package/dist/assets/{readiness-RiznV1AX.js → readiness-BveVUOIb.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-DdGqTh4X.js → renderElectronMiniChatApp-NC8iRPyy.js} +2 -2
- package/dist/assets/renderMobileApp-D5ai1i6y.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-BpcgdIV9.js +2 -0
- package/dist/assets/runtimeEndpointReset-BL9hV6J1.css +1 -0
- package/dist/assets/runtimeEndpointReset-ByKa_0nu.js +149 -0
- package/dist/assets/scheduledTaskNavigation-CZfAnPD-.js +1 -0
- package/dist/assets/sessionChangeSummary-8C8nv-EP.css +1 -0
- package/dist/assets/sessionChangeSummary-D6NlE_5k.js +1 -0
- package/dist/assets/{sessionLookup-B7kUOIpO.js → sessionLookup-C70EoX-V.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-CQZ16rbO.js → sortable-tabs-strip-aKussO2c.js} +1 -1
- package/dist/assets/speechSettingsQueries-B6qf-mCh.js +4 -0
- package/dist/assets/src-NKCZI3Lg.css +2 -0
- package/dist/assets/{store-7wItZZ7_.js → store-BeD2keas.js} +4 -4
- package/dist/assets/{terminalApi-C0_GUlPR.js → terminalApi-B5o8UqWA.js} +1 -1
- package/dist/assets/{textarea-BU8JtaSQ.js → textarea-DmKaqHSb.js} +1 -1
- package/dist/assets/{tooltip-C8DhNU1d.js → tooltip-DUKu4nC6.js} +1 -1
- package/dist/assets/{touch-gestures-zegXCZEP.js → touch-gestures-K2_ZOkKW.js} +1 -1
- package/dist/assets/types-DRTMRW4R.js +2 -0
- package/dist/assets/{uk-BNrdZFvK.js → uk-CYZXWdd7.js} +3 -3
- package/dist/assets/{useAppFontEffects-Bs6kVjrE.js → useAppFontEffects-BiQf6tgZ.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-DJxNmCWb.js} +1 -1
- package/dist/assets/useEffectiveDirectory-B8q00InF.js +1 -0
- package/dist/assets/{useFontPreferences-DQAS94Z4.js → useFontPreferences-DMiP_Yy-.js} +1 -1
- package/dist/assets/useMobileNavigationStore-Bn4SaalY.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-B6lWNk01.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-CMLBHipA.js} +3 -3
- package/dist/assets/{zh-TW-D0wsKLs1.js → zh-TW-CJlmnnhK.js} +3 -3
- 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 +58 -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 +54 -27
- package/server/lib/assistants/contact-store.test.js +69 -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/service.js +276 -145
- package/server/lib/assistants/service.test.js +954 -54
- 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/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
|
@@ -61,8 +61,17 @@ Rows are partitioned by a runtime key derived from the desktop
|
|
|
61
61
|
`apiBaseUrl` (Electron falls back to the local sidecar URL so the key stays
|
|
62
62
|
stable between server listen and window activation).
|
|
63
63
|
`service.js` exclusively owns the WAL database and stores at most the
|
|
64
|
-
newest 20 root-session summaries per runtime and directory. It
|
|
65
|
-
|
|
64
|
+
newest 20 root-session summaries per runtime and directory. It also retains the
|
|
65
|
+
minimal session `model: { providerID, id, variant? }` reference (each string is
|
|
66
|
+
bounded to 512 characters), never messages, attachments, permissions, provider
|
|
67
|
+
configuration, or model catalog metadata. Missing/invalid model fields in light
|
|
68
|
+
refreshes preserve the prior reference. Model columns are added transactionally
|
|
69
|
+
without clearing existing summaries, pins or historical synchronization markers.
|
|
70
|
+
Native `session.model.selected` updates only an existing runtime-scoped model
|
|
71
|
+
reference, not activity, directory recency or session ordering. Persisted event
|
|
72
|
+
sequence/clock fences reject stale events and stale list models; exact event
|
|
73
|
+
repeats are write-free. Alias reconciliation retains the newest known model
|
|
74
|
+
independently of title recency. Snapshot and deep-link lookup both expose it.
|
|
66
75
|
Sessions titled `smartfetch-secondary` are temporary SmartFetch model calls;
|
|
67
76
|
the index excludes them from every snapshot and clears prior summaries when a
|
|
68
77
|
matching session update arrives. Reserved leading tags `[Scheduled]`,
|
|
@@ -134,8 +143,13 @@ committed atomically in SQLite under the runtime key; empty success also records
|
|
|
134
143
|
completion. Subsequent launches perform no upstream history reads after completion.
|
|
135
144
|
Failure/shutdown preserves the last committed cursor for retry. Existing summaries
|
|
136
145
|
win over backfill, and normal create/update/archive/delete events maintain the index.
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
The model-reference generation uses its own completion marker, so older indexes
|
|
147
|
+
receive one bounded 30-day pass without clearing rows or their prior progress
|
|
148
|
+
marker. Backfill fills only missing model references on existing summaries;
|
|
149
|
+
titles, activity and already-known models win over historical reads. Model writes
|
|
150
|
+
and the page cursor commit or roll back together. Older sessions acquire the
|
|
151
|
+
reference through normal explicit directory refreshes. Manual directory refresh
|
|
152
|
+
remains a separate explicit operation; cards never fetch messages to find models.
|
|
139
153
|
|
|
140
154
|
The runtime processes explicit directory refreshes sequentially. OpenCode 2.x list is cursor-only (no
|
|
141
155
|
`start` incremental); each directory fetches active-only pages (`limit=20`)
|
|
@@ -37,6 +37,12 @@ export const applySessionIndexEvent = (service, event, observedAt = Date.now(),
|
|
|
37
37
|
|
|
38
38
|
const baseType = normalizeSessionEventType(payload.type);
|
|
39
39
|
|
|
40
|
+
if (baseType === 'session.model.selected') {
|
|
41
|
+
if (isHostReady && !isHostReady()) return false;
|
|
42
|
+
const data = payload.data ?? properties;
|
|
43
|
+
return service.updateModel(data.sessionID, data.model, payload.created ?? observedAt, payload.durable?.seq);
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
if (baseType === 'session.renamed') {
|
|
41
47
|
if (isHostReady && !isHostReady()) return false;
|
|
42
48
|
const data = payload.data ?? properties;
|
|
@@ -3,6 +3,16 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
import { applySessionIndexEvent } from './event-ingest.js';
|
|
4
4
|
|
|
5
5
|
describe('session index event ingest', () => {
|
|
6
|
+
it('ingests native model selection through the existing-row mutation and respects Host readiness', () => {
|
|
7
|
+
const service = { updateModel: vi.fn(() => true) };
|
|
8
|
+
const model = { providerID: 'p', id: 'model', variant: 'high' };
|
|
9
|
+
const event = { payload: { type: 'session.model.selected', created: 20, durable: { seq: 5 }, data: { sessionID: 'session', model } } };
|
|
10
|
+
expect(applySessionIndexEvent(service, event, 30, { isHostReady: () => false })).toBe(false);
|
|
11
|
+
expect(service.updateModel).not.toHaveBeenCalled();
|
|
12
|
+
expect(applySessionIndexEvent(service, event, 30)).toBe(true);
|
|
13
|
+
expect(service.updateModel).toHaveBeenCalledWith('session', model, 20, 5);
|
|
14
|
+
});
|
|
15
|
+
|
|
6
16
|
it('ingests native creation, user input and lifecycle without treating shutdown as completion', () => {
|
|
7
17
|
const service = { upsertAndReportChange: vi.fn(() => true), touchActivity: vi.fn(() => true), updateStatus: vi.fn(() => true) };
|
|
8
18
|
const emit = (type, data = {}) => applySessionIndexEvent(service, { directory: '/repo', payload: { type, created: 20, data: { sessionID: 'ses_native', ...data } } }, 30);
|
|
@@ -43,6 +43,25 @@ const toTimestamp = (value) => (typeof value === 'number' && Number.isFinite(val
|
|
|
43
43
|
|
|
44
44
|
const toBooleanInt = (value) => (value ? 1 : 0);
|
|
45
45
|
|
|
46
|
+
const normalizeModel = (model) => {
|
|
47
|
+
const bounded = (value) => typeof value === 'string' && value.trim() && value.length <= 512;
|
|
48
|
+
if (!model || !bounded(model.providerID) || !bounded(model.id)) return null;
|
|
49
|
+
return { providerID: model.providerID, id: model.id,
|
|
50
|
+
...(bounded(model.variant) ? { variant: model.variant } : {}) };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const modelFromJson = (value) => value ? normalizeModel(JSON.parse(value)) : null;
|
|
54
|
+
|
|
55
|
+
const mergeModel = (summary, previous) => {
|
|
56
|
+
const usePrevious = previous?.modelJson && (!summary.modelJson
|
|
57
|
+
|| summary.modelUpdatedAt < previous.modelUpdatedAt
|
|
58
|
+
|| (summary.modelUpdatedAt === previous.modelUpdatedAt && previous.modelSequence != null));
|
|
59
|
+
return usePrevious ? { modelJson: previous.modelJson, modelUpdatedAt: previous.modelUpdatedAt,
|
|
60
|
+
modelSequence: previous.modelSequence } : {
|
|
61
|
+
modelJson: summary.modelJson, modelUpdatedAt: summary.modelUpdatedAt, modelSequence: previous?.modelSequence ?? null,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
46
65
|
const getActivityUpdatedAt = (session) => {
|
|
47
66
|
const activityUpdatedAt = session?.metadata?.yuri?.titleRefresh?.activityUpdatedAt;
|
|
48
67
|
return Math.max(toTimestamp(activityUpdatedAt), toTimestamp(session?.time?.updated), toTimestamp(session?.time?.created));
|
|
@@ -62,6 +81,7 @@ const toSummary = (session, fallbackDirectory, resolveDirectory = normalizeDirec
|
|
|
62
81
|
const yuri = session.metadata?.yuri;
|
|
63
82
|
const assistant = yuri?.assistant;
|
|
64
83
|
const hideAssistantMarker = isContactAssignedSession(yuri);
|
|
84
|
+
const model = normalizeModel(session.model);
|
|
65
85
|
return {
|
|
66
86
|
id: session.id,
|
|
67
87
|
directory,
|
|
@@ -74,6 +94,8 @@ const toSummary = (session, fallbackDirectory, resolveDirectory = normalizeDirec
|
|
|
74
94
|
hasChildren: typeof session.hasChildren === 'boolean' ? session.hasChildren : null,
|
|
75
95
|
assistantID: hideAssistantMarker || typeof assistant?.assistantID !== 'string' ? null : assistant.assistantID,
|
|
76
96
|
assistantName: hideAssistantMarker || typeof assistant?.name !== 'string' ? null : assistant.name,
|
|
97
|
+
modelJson: model ? JSON.stringify(model) : null,
|
|
98
|
+
modelUpdatedAt: model ? toTimestamp(session.time?.updated) : 0,
|
|
77
99
|
};
|
|
78
100
|
};
|
|
79
101
|
|
|
@@ -168,6 +190,11 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
168
190
|
if (!sessionSummaryColumns.has('pinned_at')) {
|
|
169
191
|
db.exec('ALTER TABLE session_summary ADD COLUMN pinned_at INTEGER');
|
|
170
192
|
}
|
|
193
|
+
db.transaction(() => {
|
|
194
|
+
for (const [column, type] of [['model_json', 'TEXT'], ['model_updated_at', 'INTEGER NOT NULL DEFAULT 0'], ['model_sequence', 'INTEGER']]) {
|
|
195
|
+
if (!sessionSummaryColumns.has(column)) db.exec(`ALTER TABLE session_summary ADD COLUMN ${column} ${type}`);
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
171
198
|
db.prepare(`
|
|
172
199
|
INSERT OR IGNORE INTO session_pin(runtime_key, session_id, pinned_at)
|
|
173
200
|
SELECT runtime_key, session_id, pinned_at
|
|
@@ -209,11 +236,15 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
209
236
|
if (!previous) { merged.set(row.session_id, row); continue; }
|
|
210
237
|
const newest = row.updated_at > previous.updated_at ? row : previous;
|
|
211
238
|
const status = row.status_changed_at > previous.status_changed_at ? row : previous;
|
|
239
|
+
const model = !previous.model_json || (row.model_json && (row.model_updated_at > previous.model_updated_at
|
|
240
|
+
|| (row.model_updated_at === previous.model_updated_at && (row.model_sequence ?? -1) > (previous.model_sequence ?? -1))))
|
|
241
|
+
? row : previous;
|
|
212
242
|
merged.set(row.session_id, { ...newest,
|
|
213
243
|
activity_updated_at: Math.max(row.activity_updated_at, previous.activity_updated_at),
|
|
214
244
|
status: status.status, status_changed_at: status.status_changed_at,
|
|
215
245
|
has_children: Math.max(row.has_children, previous.has_children),
|
|
216
246
|
pinned_at: row.pinned_at ?? previous.pinned_at,
|
|
247
|
+
model_json: model.model_json, model_updated_at: model.model_updated_at, model_sequence: model.model_sequence,
|
|
217
248
|
});
|
|
218
249
|
}
|
|
219
250
|
db.prepare('DELETE FROM session_summary WHERE runtime_key = ? AND directory IN (?, ?)').run(key, source.directory, target);
|
|
@@ -260,13 +291,15 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
260
291
|
const deleteDirectoryRows = db.prepare('DELETE FROM session_summary WHERE runtime_key = ? AND directory = ?');
|
|
261
292
|
const existingSummaryState = db.prepare(`
|
|
262
293
|
SELECT session_id, has_children AS hasChildren, activity_updated_at AS activityUpdatedAt,
|
|
263
|
-
status, status_changed_at AS statusChangedAt, pinned_at AS pinnedAt
|
|
294
|
+
status, status_changed_at AS statusChangedAt, pinned_at AS pinnedAt,
|
|
295
|
+
model_json AS modelJson, model_updated_at AS modelUpdatedAt, model_sequence AS modelSequence
|
|
264
296
|
FROM session_summary WHERE runtime_key = ? AND directory = ?
|
|
265
297
|
`);
|
|
266
298
|
const readSummary = db.prepare(`
|
|
267
299
|
SELECT title, created_at AS createdAt, updated_at AS updatedAt,
|
|
268
300
|
activity_updated_at AS activityUpdatedAt, archived_at AS archivedAt,
|
|
269
|
-
parent_id AS parentID, has_children AS hasChildren
|
|
301
|
+
parent_id AS parentID, has_children AS hasChildren,
|
|
302
|
+
model_json AS modelJson, model_updated_at AS modelUpdatedAt, model_sequence AS modelSequence
|
|
270
303
|
FROM session_summary
|
|
271
304
|
WHERE runtime_key = ? AND directory = ? AND session_id = ?
|
|
272
305
|
`);
|
|
@@ -278,12 +311,12 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
278
311
|
LIMIT 1 OFFSET ?
|
|
279
312
|
`);
|
|
280
313
|
const insertSummary = db.prepare(`
|
|
281
|
-
INSERT INTO session_summary(runtime_key, directory, session_id, title, created_at, updated_at, activity_updated_at, archived_at, pinned_at, status, status_changed_at, parent_id, has_children, assistant_id, assistant_name)
|
|
282
|
-
VALUES (@runtimeKey, @directory, @id, @title, @createdAt, @updatedAt, @activityUpdatedAt, @archivedAt, @pinnedAt, @status, @statusChangedAt, @parentID, @hasChildren, @assistantID, @assistantName)
|
|
314
|
+
INSERT INTO session_summary(runtime_key, directory, session_id, title, created_at, updated_at, activity_updated_at, archived_at, pinned_at, status, status_changed_at, parent_id, has_children, assistant_id, assistant_name, model_json, model_updated_at, model_sequence)
|
|
315
|
+
VALUES (@runtimeKey, @directory, @id, @title, @createdAt, @updatedAt, @activityUpdatedAt, @archivedAt, @pinnedAt, @status, @statusChangedAt, @parentID, @hasChildren, @assistantID, @assistantName, @modelJson, @modelUpdatedAt, @modelSequence)
|
|
283
316
|
`);
|
|
284
317
|
const upsertSummary = db.prepare(`
|
|
285
|
-
INSERT INTO session_summary(runtime_key, directory, session_id, title, created_at, updated_at, activity_updated_at, archived_at, status, status_changed_at, parent_id, has_children, assistant_id, assistant_name)
|
|
286
|
-
VALUES (@runtimeKey, @directory, @id, @title, @createdAt, @updatedAt, @activityUpdatedAt, @archivedAt, NULL, 0, @parentID, @hasChildren, @assistantID, @assistantName)
|
|
318
|
+
INSERT INTO session_summary(runtime_key, directory, session_id, title, created_at, updated_at, activity_updated_at, archived_at, status, status_changed_at, parent_id, has_children, assistant_id, assistant_name, model_json, model_updated_at, model_sequence)
|
|
319
|
+
VALUES (@runtimeKey, @directory, @id, @title, @createdAt, @updatedAt, @activityUpdatedAt, @archivedAt, NULL, 0, @parentID, @hasChildren, @assistantID, @assistantName, @modelJson, @modelUpdatedAt, @modelSequence)
|
|
287
320
|
ON CONFLICT(runtime_key, directory, session_id) DO UPDATE SET
|
|
288
321
|
title = excluded.title,
|
|
289
322
|
created_at = excluded.created_at,
|
|
@@ -293,8 +326,14 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
293
326
|
parent_id = excluded.parent_id,
|
|
294
327
|
has_children = excluded.has_children,
|
|
295
328
|
assistant_id = excluded.assistant_id,
|
|
296
|
-
assistant_name = excluded.assistant_name
|
|
329
|
+
assistant_name = excluded.assistant_name,
|
|
330
|
+
model_json = excluded.model_json,
|
|
331
|
+
model_updated_at = excluded.model_updated_at,
|
|
332
|
+
model_sequence = excluded.model_sequence
|
|
297
333
|
`);
|
|
334
|
+
const writeModel = db.prepare(`UPDATE session_summary
|
|
335
|
+
SET model_json = @modelJson, model_updated_at = @modelUpdatedAt, model_sequence = @modelSequence
|
|
336
|
+
WHERE runtime_key = @runtimeKey AND session_id = @id`);
|
|
298
337
|
const setHasChildren = db.prepare(`
|
|
299
338
|
UPDATE session_summary SET has_children = ?
|
|
300
339
|
WHERE runtime_key = ? AND directory = ? AND session_id = ?
|
|
@@ -401,6 +440,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
401
440
|
const previous = previousStateByID.get(summary.id);
|
|
402
441
|
insertSummary.run({
|
|
403
442
|
...summary,
|
|
443
|
+
...mergeModel(summary, previous),
|
|
404
444
|
activityUpdatedAt: Math.max(summary.activityUpdatedAt, toTimestamp(previous?.activityUpdatedAt)),
|
|
405
445
|
pinnedAt: previous?.pinnedAt != null ? toTimestamp(previous.pinnedAt) : null,
|
|
406
446
|
status: typeof previous?.status === 'string' ? previous.status : null,
|
|
@@ -455,6 +495,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
455
495
|
return { accepted: true, changed: true };
|
|
456
496
|
}
|
|
457
497
|
const existing = readSummary.get(key, summary.directory, summary.id);
|
|
498
|
+
const model = mergeModel(summary, existing);
|
|
458
499
|
const activityUpdatedAt = options.preserveActivity === true && existing
|
|
459
500
|
? toTimestamp(existing.activityUpdatedAt)
|
|
460
501
|
: Math.max(toTimestamp(existing?.activityUpdatedAt), summary.activityUpdatedAt);
|
|
@@ -466,8 +507,14 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
466
507
|
&& toTimestamp(existing.activityUpdatedAt) === activityUpdatedAt
|
|
467
508
|
&& toTimestamp(existing.archivedAt) === summary.archivedAt
|
|
468
509
|
&& (existing.parentID ?? null) === summary.parentID
|
|
469
|
-
&& toBooleanInt(existing.hasChildren) === hasChildren
|
|
470
|
-
|
|
510
|
+
&& toBooleanInt(existing.hasChildren) === hasChildren
|
|
511
|
+
&& existing.modelJson === model.modelJson;
|
|
512
|
+
if (unchanged) {
|
|
513
|
+
if (existing.modelUpdatedAt !== model.modelUpdatedAt || existing.modelSequence !== model.modelSequence) {
|
|
514
|
+
writeModel.run({ ...model, runtimeKey: key, id: summary.id });
|
|
515
|
+
}
|
|
516
|
+
return { accepted: true, changed: false };
|
|
517
|
+
}
|
|
471
518
|
} else {
|
|
472
519
|
const cutoff = readRootRetentionCutoff.get(key, summary.directory, MAX_ROOT_SESSIONS - 1);
|
|
473
520
|
const fallsOutsideBound = cutoff
|
|
@@ -482,6 +529,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
482
529
|
});
|
|
483
530
|
upsertSummary.run({
|
|
484
531
|
...summary,
|
|
532
|
+
...model,
|
|
485
533
|
activityUpdatedAt,
|
|
486
534
|
hasChildren,
|
|
487
535
|
runtimeKey: key,
|
|
@@ -518,13 +566,15 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
518
566
|
activity_updated_at AS activityUpdatedAt, archived_at AS archivedAt,
|
|
519
567
|
pinned_at AS pinnedAt,
|
|
520
568
|
status, status_changed_at AS statusChangedAt, parent_id AS parentID,
|
|
521
|
-
has_children AS hasChildren, assistant_id AS assistantID, assistant_name AS assistantName
|
|
569
|
+
has_children AS hasChildren, assistant_id AS assistantID, assistant_name AS assistantName,
|
|
570
|
+
model_json AS modelJson
|
|
522
571
|
FROM session_summary WHERE runtime_key = ? AND directory = ?
|
|
523
572
|
ORDER BY activity_updated_at DESC, id DESC
|
|
524
573
|
`).all(key, directory.directory)
|
|
525
574
|
.map((session) => ({
|
|
526
575
|
id: session.id,
|
|
527
576
|
title: session.title,
|
|
577
|
+
...(session.modelJson ? { model: modelFromJson(session.modelJson) } : {}),
|
|
528
578
|
directory: directory.directory,
|
|
529
579
|
time: {
|
|
530
580
|
created: session.createdAt,
|
|
@@ -582,7 +632,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
582
632
|
SELECT directory, session_id AS id, title, created_at AS createdAt, updated_at AS updatedAt,
|
|
583
633
|
activity_updated_at AS activityUpdatedAt, archived_at AS archivedAt,
|
|
584
634
|
parent_id AS parentID, has_children AS hasChildren,
|
|
585
|
-
assistant_id AS assistantID, assistant_name AS assistantName
|
|
635
|
+
assistant_id AS assistantID, assistant_name AS assistantName, model_json AS modelJson
|
|
586
636
|
FROM session_summary
|
|
587
637
|
WHERE runtime_key = ? AND session_id = ?
|
|
588
638
|
ORDER BY activity_updated_at DESC, updated_at DESC
|
|
@@ -593,6 +643,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
593
643
|
id: row.id,
|
|
594
644
|
directory: normalizeDirectory(row.directory),
|
|
595
645
|
title: typeof row.title === 'string' ? row.title : '',
|
|
646
|
+
...(row.modelJson ? { model: modelFromJson(row.modelJson) } : {}),
|
|
596
647
|
createdAt: toTimestamp(row.createdAt),
|
|
597
648
|
updatedAt: toTimestamp(row.updatedAt),
|
|
598
649
|
activityUpdatedAt: toTimestamp(row.activityUpdatedAt),
|
|
@@ -616,6 +667,25 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
616
667
|
return result.changes > 0;
|
|
617
668
|
};
|
|
618
669
|
|
|
670
|
+
const updateModel = db.transaction((sessionID, model, observedAt, sequence) => {
|
|
671
|
+
const normalized = normalizeModel(model);
|
|
672
|
+
const timestamp = toTimestamp(observedAt);
|
|
673
|
+
if (!sessionID || !normalized || !timestamp) return false;
|
|
674
|
+
const key = runtimeKey();
|
|
675
|
+
const previous = db.prepare(`SELECT model_json AS modelJson, model_updated_at AS modelUpdatedAt,
|
|
676
|
+
model_sequence AS modelSequence FROM session_summary WHERE runtime_key = ? AND session_id = ?`).get(key, sessionID);
|
|
677
|
+
if (!previous) return false;
|
|
678
|
+
const seq = Number.isSafeInteger(sequence) && sequence >= 0 ? sequence : null;
|
|
679
|
+
if (seq != null && previous.modelSequence != null
|
|
680
|
+
? seq <= previous.modelSequence
|
|
681
|
+
: timestamp < previous.modelUpdatedAt) return false;
|
|
682
|
+
const modelJson = JSON.stringify(normalized);
|
|
683
|
+
if (previous.modelJson === modelJson && previous.modelUpdatedAt === timestamp && previous.modelSequence === seq) return false;
|
|
684
|
+
writeModel.run({ runtimeKey: key, id: sessionID, modelJson,
|
|
685
|
+
modelUpdatedAt: Math.max(timestamp, previous.modelUpdatedAt), modelSequence: seq });
|
|
686
|
+
return previous.modelJson !== modelJson;
|
|
687
|
+
});
|
|
688
|
+
|
|
619
689
|
const rename = (sessionID, title, observedAt) => {
|
|
620
690
|
if (typeof sessionID !== 'string' || !sessionID || typeof title !== 'string') return false;
|
|
621
691
|
const timestamp = toTimestamp(observedAt);
|
|
@@ -688,7 +758,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
688
758
|
`).run(runtimeKey(), directory).changes > 0;
|
|
689
759
|
|
|
690
760
|
try { reconcileDirectoryAliases(runtimeKey()); } catch (error) { db.close(); throw error; }
|
|
691
|
-
const historyKey = () => `history_backfill:${runtimeKey()}`;
|
|
761
|
+
const historyKey = () => `history_backfill:model_ref_v1:${runtimeKey()}`;
|
|
692
762
|
const getHistoryBackfill = () => {
|
|
693
763
|
const row = db.prepare('SELECT value FROM session_index_meta WHERE key = ?').get(historyKey());
|
|
694
764
|
return row ? JSON.parse(row.value) : null;
|
|
@@ -697,12 +767,17 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
697
767
|
if (expectedRuntimeKey !== runtimeKey()) return false;
|
|
698
768
|
for (const session of sessions) {
|
|
699
769
|
// Live events and already indexed summaries win over historical reads.
|
|
700
|
-
|
|
770
|
+
const existing = findBySessionId(session.id);
|
|
771
|
+
if (!existing) {
|
|
701
772
|
upsert(session);
|
|
702
773
|
const directory = normalizeDirectory(session?.location?.directory ?? session?.directory);
|
|
703
774
|
// The bounded 30-day import is not proof that older history is empty.
|
|
704
775
|
db.prepare('UPDATE runtime_directory SET has_more = 1 WHERE runtime_key = ? AND directory = ? AND last_full_synced_at = 0')
|
|
705
776
|
.run(expectedRuntimeKey, directory);
|
|
777
|
+
} else if (!existing.model && isVisibleSession(session) && !session.time?.archived) {
|
|
778
|
+
const model = normalizeModel(session.model);
|
|
779
|
+
if (model) writeModel.run({ runtimeKey: expectedRuntimeKey, id: session.id,
|
|
780
|
+
modelJson: JSON.stringify(model), modelUpdatedAt: toTimestamp(session.time?.updated), modelSequence: null });
|
|
706
781
|
}
|
|
707
782
|
}
|
|
708
783
|
db.prepare('INSERT OR REPLACE INTO session_index_meta(key, value) VALUES (?, ?)')
|
|
@@ -719,6 +794,7 @@ export const createSessionIndexService = ({ dbPath, getRuntimeConfig = () => nul
|
|
|
719
794
|
upsertAndReportChange,
|
|
720
795
|
touchActivity,
|
|
721
796
|
updateStatus,
|
|
797
|
+
updateModel,
|
|
722
798
|
rename,
|
|
723
799
|
move,
|
|
724
800
|
setPinned,
|
|
@@ -2,10 +2,11 @@ import fs from 'node:fs';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { createSessionIndexService } from './service.js';
|
|
8
8
|
import { applySessionIndexEvent } from './event-ingest.js';
|
|
9
|
+
import { createSessionIndexSyncRuntime } from './sync-runtime.js';
|
|
9
10
|
|
|
10
11
|
const tempDirectories = [];
|
|
11
12
|
|
|
@@ -32,6 +33,148 @@ afterEach(() => {
|
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
describe('Electron session index', () => {
|
|
36
|
+
it('uses the existing global startup sync to enrich cached models once without per-session reads', async () => {
|
|
37
|
+
const service = createService({ value: 'http://runtime-a.test' });
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
service.upsert(session('cached', now));
|
|
40
|
+
const fetchFn = vi.fn(async (url) => {
|
|
41
|
+
expect(url.pathname).toBe('/session');
|
|
42
|
+
expect(url.searchParams.get('limit')).toBe('100');
|
|
43
|
+
expect(url.searchParams.has('directory')).toBe(false);
|
|
44
|
+
return Response.json({ data: [{ ...session('cached', now - 1), model: { providerID: 'p', id: 'backfilled' } }] });
|
|
45
|
+
});
|
|
46
|
+
const runtime = createSessionIndexSyncRuntime({ sessionIndexService: service, fetchFn,
|
|
47
|
+
buildOpenCodeUrl: (route) => `http://opencode.test${route}`,
|
|
48
|
+
getOpenCodeAuthHeaders: () => ({}), waitForOpenCodeReady: async () => true });
|
|
49
|
+
try {
|
|
50
|
+
runtime.enqueue([], { startup: true });
|
|
51
|
+
await vi.waitFor(() => expect(service.getHistoryBackfill()?.complete).toBe(true));
|
|
52
|
+
expect(runtime.snapshot().directories[0].sessions[0].model).toEqual({ providerID: 'p', id: 'backfilled' });
|
|
53
|
+
runtime.enqueue([], { startup: true });
|
|
54
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
55
|
+
} finally { runtime.stop(); service.close(); }
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('round-trips only the bounded model reference and preserves it through light refreshes and reopen', () => {
|
|
59
|
+
const service = createService({ value: 'http://runtime-a.test' });
|
|
60
|
+
const model = { providerID: 'openai', id: 'gpt-6.1-sol', variant: 'high' };
|
|
61
|
+
service.upsert({ ...session('model', 10), model: { ...model, credentials: 'not-a-model-field' } });
|
|
62
|
+
expect(service.snapshot().directories[0].sessions[0].model).toEqual(model);
|
|
63
|
+
expect(service.findBySessionId('model').model).toEqual(model);
|
|
64
|
+
expect(service.upsertAndReportChange({ ...session('model', 10), model })).toBe(false);
|
|
65
|
+
service.upsert(session('model', 20));
|
|
66
|
+
service.replaceDirectory({ directory: '/repo', sessions: [session('model', 30)] });
|
|
67
|
+
expect(service.snapshot().directories[0].sessions[0].model).toEqual(model);
|
|
68
|
+
const next = { providerID: 'provider', id: 'other' };
|
|
69
|
+
expect(service.upsertAndReportChange({ ...session('model', 40), model: next })).toBe(true);
|
|
70
|
+
service.close();
|
|
71
|
+
const reopened = createSessionIndexService({ dbPath: path.join(tempDirectories.at(-1), 'session-index.sqlite'),
|
|
72
|
+
getRuntimeConfig: () => ({ apiBaseUrl: 'http://runtime-a.test' }) });
|
|
73
|
+
try { expect(reopened.findBySessionId('model').model).toEqual(next); } finally { reopened.close(); }
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('updates models from ordered native events without changing activity and rejects stale refreshes', () => {
|
|
77
|
+
const runtimeRef = { value: 'http://runtime-a.test' };
|
|
78
|
+
const service = createService(runtimeRef);
|
|
79
|
+
try {
|
|
80
|
+
service.upsert(session('model', 10));
|
|
81
|
+
service.upsert(session('other', 20));
|
|
82
|
+
const before = service.snapshot();
|
|
83
|
+
const emit = (id, created, seq) => applySessionIndexEvent(service, {
|
|
84
|
+
type: 'session.model.selected', created, durable: { seq },
|
|
85
|
+
data: { sessionID: 'model', model: { providerID: 'p', id } },
|
|
86
|
+
});
|
|
87
|
+
expect(emit('new', 30, 5)).toBe(true);
|
|
88
|
+
expect(emit('new', 30, 5)).toBe(false);
|
|
89
|
+
expect(emit('old', 40, 4)).toBe(false);
|
|
90
|
+
expect(service.snapshot().directories[0].sessions.map((row) => [row.id, row.metadata.yuri.titleRefresh]))
|
|
91
|
+
.toEqual(before.directories[0].sessions.map((row) => [row.id, row.metadata.yuri.titleRefresh]));
|
|
92
|
+
service.replaceDirectory({ directory: '/repo', sessions: [session('other', 20),
|
|
93
|
+
{ ...session('model', 25), model: { providerID: 'p', id: 'stale' } }] });
|
|
94
|
+
expect(service.findBySessionId('model').model).toEqual({ providerID: 'p', id: 'new' });
|
|
95
|
+
runtimeRef.value = 'http://runtime-b.test';
|
|
96
|
+
expect(emit('wrong-runtime', 50, 6)).toBe(false);
|
|
97
|
+
runtimeRef.value = 'http://runtime-a.test';
|
|
98
|
+
expect(service.findBySessionId('model').model.id).toBe('new');
|
|
99
|
+
} finally { service.close(); }
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('retains model event fences after reopening and merges alias models independently of title recency', () => {
|
|
103
|
+
const service = createService({ value: 'http://runtime-a.test' });
|
|
104
|
+
service.upsert(session('model', 10, '/alias'));
|
|
105
|
+
service.updateModel('model', { providerID: 'p', id: 'new' }, 40, 5);
|
|
106
|
+
service.upsert({ ...session('model', 50, '/real'), title: 'New title' });
|
|
107
|
+
service.close();
|
|
108
|
+
const reopened = createSessionIndexService({ dbPath: path.join(tempDirectories.at(-1), 'session-index.sqlite'),
|
|
109
|
+
getRuntimeConfig: () => ({ apiBaseUrl: 'http://runtime-a.test' }),
|
|
110
|
+
resolveDirectory: (directory) => directory === '/alias' ? '/real' : directory });
|
|
111
|
+
try {
|
|
112
|
+
expect(reopened.findBySessionId('model')).toMatchObject({ title: 'New title', model: { providerID: 'p', id: 'new' } });
|
|
113
|
+
expect(reopened.updateModel('model', { providerID: 'p', id: 'stale' }, 60, 4)).toBe(false);
|
|
114
|
+
expect(reopened.updateModel('model', { providerID: 'p', id: 'latest' }, 60, 6)).toBe(true);
|
|
115
|
+
} finally { reopened.close(); }
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('reports pure model changes, ignores malformed references and keeps duplicate model events write-free', () => {
|
|
119
|
+
const service = createService({ value: 'http://runtime-a.test' });
|
|
120
|
+
try {
|
|
121
|
+
const row = session('model', 10);
|
|
122
|
+
service.upsert(row);
|
|
123
|
+
for (const model of [null, {}, { providerID: 'p' }, { providerID: 'p', id: 'x'.repeat(513) }]) {
|
|
124
|
+
expect(service.upsertAndReportChange({ ...row, model })).toBe(false);
|
|
125
|
+
}
|
|
126
|
+
expect(service.upsertAndReportChange({ ...row, model: { providerID: 'p', id: 'm' } })).toBe(true);
|
|
127
|
+
service.updateModel('model', { providerID: 'p', id: 'm' }, 20, 5);
|
|
128
|
+
const db = new (createRequire(import.meta.url)('better-sqlite3'))(path.join(tempDirectories.at(-1), 'session-index.sqlite'));
|
|
129
|
+
db.exec("CREATE TRIGGER reject_duplicate_model BEFORE UPDATE ON session_summary BEGIN SELECT RAISE(ABORT, 'duplicate write'); END");
|
|
130
|
+
try {
|
|
131
|
+
for (let i = 0; i < 50; i++) expect(service.updateModel('model', { providerID: 'p', id: 'm' }, 20, 5)).toBe(false);
|
|
132
|
+
} finally { db.close(); }
|
|
133
|
+
} finally { service.close(); }
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('upgrades old rows without clearing history or pins and backfills only missing models atomically', () => {
|
|
137
|
+
const service = createService({ value: 'http://runtime-a.test' });
|
|
138
|
+
const key = service.getRuntimeKey();
|
|
139
|
+
service.upsert(session('missing', 10));
|
|
140
|
+
service.upsert({ ...session('live', 20), model: { providerID: 'p', id: 'live' } });
|
|
141
|
+
service.setPinned('missing', 5);
|
|
142
|
+
service.close();
|
|
143
|
+
const dbPath = path.join(tempDirectories.at(-1), 'session-index.sqlite');
|
|
144
|
+
const Database = createRequire(import.meta.url)('better-sqlite3');
|
|
145
|
+
const db = new Database(dbPath);
|
|
146
|
+
for (const column of ['model_json', 'model_updated_at', 'model_sequence']) {
|
|
147
|
+
if (db.prepare("SELECT name FROM pragma_table_info('session_summary') WHERE name = ?").get(column)) {
|
|
148
|
+
db.exec(`ALTER TABLE session_summary DROP COLUMN ${column}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
db.prepare('INSERT OR REPLACE INTO session_index_meta VALUES (?, ?)')
|
|
152
|
+
.run(`history_backfill:${key}`, JSON.stringify({ complete: true }));
|
|
153
|
+
db.close();
|
|
154
|
+
const reopened = createSessionIndexService({ dbPath, getRuntimeConfig: () => ({ apiBaseUrl: 'http://runtime-a.test' }) });
|
|
155
|
+
try {
|
|
156
|
+
expect(reopened.snapshot().pinnedSessionIds).toEqual(['missing']);
|
|
157
|
+
expect(reopened.findBySessionId('missing').title).toBe('Session missing');
|
|
158
|
+
expect(reopened.getHistoryBackfill()).toBeNull();
|
|
159
|
+
reopened.upsert({ ...session('live', 20), model: { providerID: 'p', id: 'live' } });
|
|
160
|
+
const page = { expectedRuntimeKey: key, progress: { complete: true }, sessions: [
|
|
161
|
+
{ ...session('missing', 1), title: 'stale title', model: { providerID: 'p', id: 'history' } },
|
|
162
|
+
{ ...session('live', 1), model: { providerID: 'p', id: 'stale' } },
|
|
163
|
+
] };
|
|
164
|
+
const writer = new Database(dbPath);
|
|
165
|
+
writer.exec("CREATE TRIGGER reject_model BEFORE UPDATE ON session_summary BEGIN SELECT RAISE(ABORT, 'injected model failure'); END");
|
|
166
|
+
expect(() => reopened.commitHistoryPage(page)).toThrow('injected model failure');
|
|
167
|
+
expect(reopened.findBySessionId('missing').model).toBeUndefined();
|
|
168
|
+
expect(reopened.getHistoryBackfill()).toBeNull();
|
|
169
|
+
writer.exec('DROP TRIGGER reject_model');
|
|
170
|
+
writer.close();
|
|
171
|
+
expect(reopened.commitHistoryPage(page)).toBe(true);
|
|
172
|
+
expect(reopened.findBySessionId('missing')).toMatchObject({ title: 'Session missing', model: { providerID: 'p', id: 'history' } });
|
|
173
|
+
expect(reopened.findBySessionId('live').model.id).toBe('live');
|
|
174
|
+
expect(reopened.getHistoryBackfill()).toEqual({ complete: true });
|
|
175
|
+
} finally { reopened.close(); }
|
|
176
|
+
});
|
|
177
|
+
|
|
35
178
|
it('merges duplicate aliases by freshness, keeps the newest twenty and preserves independent pins', () => {
|
|
36
179
|
const service = createService({ value: 'http://runtime-a.test' });
|
|
37
180
|
service.replaceDirectory({ directory: '/alias', sessions: Array.from({ length: 20 }, (_, i) => session(`alias-${i}`, i + 1, '/alias')) });
|
|
@@ -6,6 +6,8 @@ import request from 'supertest';
|
|
|
6
6
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { createSessionMetadataStore, registerSessionMetadataRoutes } from './routes.js';
|
|
9
|
+
import { createSessionIndexService } from '../session-index/service.js';
|
|
10
|
+
import { projectSessionWithStoredMap } from './session-projection.js';
|
|
9
11
|
|
|
10
12
|
const tempDirs = [];
|
|
11
13
|
|
|
@@ -80,6 +82,48 @@ describe('registerSessionMetadataRoutes', () => {
|
|
|
80
82
|
});
|
|
81
83
|
});
|
|
82
84
|
|
|
85
|
+
it('persists scheduled-fork detachment through the Host route and directory index rebuild', async () => {
|
|
86
|
+
const dataDir = makeDataDir();
|
|
87
|
+
const metadata = { custom: { keep: true }, yuri: {
|
|
88
|
+
scheduledTask: { taskID: 'task-1', runID: 'run-1' },
|
|
89
|
+
titleRefresh: { activityUpdatedAt: 10 },
|
|
90
|
+
} };
|
|
91
|
+
const source = { id: 'ses_source', title: '[Scheduled] Morning Sync', location: { directory: '/repo' }, time: { created: 1, updated: 10 }, metadata };
|
|
92
|
+
const fork = { ...source, id: 'ses_fork', title: 'Morning Sync (fork #1)', time: { created: 20, updated: 20 },
|
|
93
|
+
fork: { sessionID: source.id, boundary: { type: 'through', messageID: 'msg_last' } } };
|
|
94
|
+
const records = new Map([source, fork].map((session) => [session.id, structuredClone(session)]));
|
|
95
|
+
const storeOptions = {
|
|
96
|
+
dataDir,
|
|
97
|
+
recordReader: async (id) => structuredClone(records.get(id)),
|
|
98
|
+
recordWriter: async (id, next) => { records.set(id, { ...records.get(id), metadata: structuredClone(next) }); },
|
|
99
|
+
};
|
|
100
|
+
const store = createSessionMetadataStore(storeOptions);
|
|
101
|
+
const { app } = mount({ sessionMetadataStore: store });
|
|
102
|
+
const indexOptions = { dbPath: path.join(dataDir, 'session-index.sqlite') };
|
|
103
|
+
const index = createSessionIndexService(indexOptions);
|
|
104
|
+
try {
|
|
105
|
+
// Renaming alone leaves both records excluded, even after a refresh.
|
|
106
|
+
index.replaceDirectory({ directory: '/repo', sessions: [...records.values()] });
|
|
107
|
+
expect(index.snapshot().directories[0].sessions).toEqual([]);
|
|
108
|
+
await store.setSessionMetadata(fork.id, metadata);
|
|
109
|
+
|
|
110
|
+
const response = await request(app).put('/api/yuri/sessions/ses_fork/metadata')
|
|
111
|
+
.send({ directory: '/repo', patch: { yuri: { scheduledTask: null } } }).expect(200);
|
|
112
|
+
|
|
113
|
+
expect(response.body.metadata).toEqual({ custom: metadata.custom, yuri: { titleRefresh: metadata.yuri.titleRefresh } });
|
|
114
|
+
const reopenedStore = createSessionMetadataStore(storeOptions);
|
|
115
|
+
await expect(reopenedStore.get(fork.id)).resolves.toEqual(response.body.metadata);
|
|
116
|
+
expect(records.get(source.id)).toEqual(source);
|
|
117
|
+
index.replaceDirectory({ directory: '/repo', sessions: [...records.values()].map((session) =>
|
|
118
|
+
projectSessionWithStoredMap(session, reopenedStore.getSnapshotSync())) });
|
|
119
|
+
expect(index.snapshot().directories[0].sessions.map((session) => session.id)).toEqual([fork.id]);
|
|
120
|
+
} finally { index.close(); }
|
|
121
|
+
const reopenedIndex = createSessionIndexService(indexOptions);
|
|
122
|
+
try {
|
|
123
|
+
expect(reopenedIndex.snapshot().directories[0].sessions.map((session) => session.id)).toEqual([fork.id]);
|
|
124
|
+
} finally { reopenedIndex.close(); }
|
|
125
|
+
});
|
|
126
|
+
|
|
83
127
|
it('rejects a blank session id and a non-object patch with 400', async () => {
|
|
84
128
|
const { app } = mount();
|
|
85
129
|
await request(app)
|
|
@@ -207,6 +207,14 @@ handshakes, sends text, and requires SessionFinished after audio. It adapts
|
|
|
207
207
|
binary PCM into the existing bounded NDJSON player contract (24 kHz mono,
|
|
208
208
|
9600-byte frames), retaining startup buffering, pitch, volume, cancellation,
|
|
209
209
|
and playback-completion semantics. Text and audio go directly to the provider.
|
|
210
|
+
TTS/ICL 2.0 sessions set `req_params.audio_params.enable_subtitle: true` and
|
|
211
|
+
forward `364 / TTSSubtitle` as `{type:'subtitle',text,words}` NDJSON. Words carry
|
|
212
|
+
`word/startTime/endTime` in seconds relative to the whole session, not a sentence
|
|
213
|
+
or network packet. Events 350/351 are not paragraph boundaries. Subtitle receipt
|
|
214
|
+
never splits or delays synthesis; one normal reply sends one TaskRequest/session.
|
|
215
|
+
Other resource IDs do not acquire an unsupported subtitle flag. The old Host HTTP
|
|
216
|
+
fallback and other providers can still return audio without subtitles: playback
|
|
217
|
+
continues, but precise highlighting is unavailable instead of guessed.
|
|
210
218
|
`dictation/volcengine-direct.ts` uses `/api/v3/sauc/bigmodel_async` for 16 kHz
|
|
211
219
|
PCM16, live full-text partials, and an explicit final audio frame. A terminal
|
|
212
220
|
response without text retains the last partial; explicit empty text remains empty.
|
|
@@ -260,11 +268,25 @@ Web Audio context with a 400 ms startup buffer measured in actual playback time
|
|
|
260
268
|
its 20 ms safety margin, it accumulates another 400 ms before resuming, rather
|
|
261
269
|
than playing isolated packets. Terminal success flushes short replies and any
|
|
262
270
|
remaining tail below that threshold. Scheduled audio remains bounded to
|
|
263
|
-
approximately two seconds
|
|
264
|
-
|
|
271
|
+
approximately two seconds. Receipt is independent of scheduling: raw PCM is
|
|
272
|
+
cached up to 24 MiB (8192 chunks), within the 32 MiB NDJSON transfer cap, so a
|
|
273
|
+
subtitle behind queued audio is not blocked by playback backpressure. Only
|
|
274
|
+
scheduled audio is expanded to AudioBuffers. It does not wait for EOF or MP3
|
|
275
|
+
decoding. `speech-timeline.ts` validates/bounds subtitles and aligns source ranges
|
|
276
|
+
in media order. The 50ms output-clock sampler accounts for pitch and starvation,
|
|
277
|
+
emits only cue transitions, and is cleared with playback. Late/expired metadata
|
|
278
|
+
never moves a highlight backwards or holds audio. Source nodes are
|
|
265
279
|
released on completion; stop, runtime switch, unmount and errors cancel the
|
|
266
280
|
reader and queued audio. Playback completion waits for both terminal success
|
|
267
281
|
and the last source's `ended` event, preserving automatic read-aloud ordering.
|
|
282
|
+
`useServerTTS` keeps only one in-memory stream cache keyed by the message playback
|
|
283
|
+
key, exact source and runtime transport identity. Stop preserves received PCM and
|
|
284
|
+
its sample position, but cancels the network. Resume of a complete cache performs
|
|
285
|
+
no request. Partial-cache recovery replays only through a known subtitle boundary
|
|
286
|
+
before one new synthesis of the remaining source; absent alignment falls back to
|
|
287
|
+
the last known passage. Missing terminal success is never promoted to a complete
|
|
288
|
+
cache, even if all text has subtitles. Completion/restart/replacement/runtime
|
|
289
|
+
changes release or replace cached audio. No provider JWT is retained for resume.
|
|
268
290
|
The legacy Host HTTP stream uses `runtimeFetch`, including the existing encrypted
|
|
269
291
|
Relay transport. Current Volcengine clients feed the same player from direct
|
|
270
292
|
WebSocket audio instead. Relay may buffer legacy transport bytes independently
|