@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
|
@@ -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
|
|
@@ -19,6 +19,7 @@ let mode;
|
|
|
19
19
|
let audioChunks;
|
|
20
20
|
let clients;
|
|
21
21
|
let asrRequests;
|
|
22
|
+
let ttsRequests;
|
|
22
23
|
const ticket = () => ({ transport: 'volcengine-direct', token: 'header.payload.signature', appId: 'fixture-app', expiresAt: Date.now() + 300000,
|
|
23
24
|
resourceId: 'seed-tts-2.0', voice: 'zh_female_vv_uranus_bigtts', speed: 1, pitch: 1.1, volume: 0.8 });
|
|
24
25
|
const waitFor = async (fn) => { for (let n = 0; n < 200; n++) { if (fn()) return; await new Promise((r) => setTimeout(r, 5)); } throw new Error('Fixture timed out'); };
|
|
@@ -41,7 +42,7 @@ function asrResponse(text, final = false) {
|
|
|
41
42
|
|
|
42
43
|
beforeEach(async () => {
|
|
43
44
|
urls = []; sockets = []; audioChunks = []; clients = []; mode = 'success'; mocks.identity = 'host-a';
|
|
44
|
-
asrRequests = [];
|
|
45
|
+
asrRequests = []; ttsRequests = [];
|
|
45
46
|
mocks.openRuntimeWebSocket.mockReset();
|
|
46
47
|
mocks.runtimeFetch.mockReset().mockImplementation(async () => Response.json(ticket()));
|
|
47
48
|
server = new WebSocketServer({ port: 0, host: '127.0.0.1' }); await once(server, 'listening');
|
|
@@ -60,8 +61,19 @@ beforeEach(async () => {
|
|
|
60
61
|
const id = event >= 100 ? bytes.subarray(12, 12 + bytes.readUInt32BE(8)).toString() : '';
|
|
61
62
|
if (event === 1) socket.send(ttsResponse(50, 'connection', {}));
|
|
62
63
|
if (event === 100) socket.send(ttsResponse(150, id, {}));
|
|
63
|
-
if (event === 200)
|
|
64
|
-
|
|
64
|
+
if (event === 200) {
|
|
65
|
+
const offset = 16 + Buffer.byteLength(id);
|
|
66
|
+
ttsRequests.push(JSON.parse(bytes.subarray(offset).toString()));
|
|
67
|
+
socket.send(ttsResponse(352, id, Buffer.alloc(19200), 11));
|
|
68
|
+
if (mode === 'subtitles') {
|
|
69
|
+
socket.send(ttsResponse(350, id, { text: '', words: [] }));
|
|
70
|
+
socket.send(ttsResponse(364, id, { text: '第一句。', words: [{ word: '第一句。', startTime: 0, endTime: 0.2 }] }));
|
|
71
|
+
socket.send(ttsResponse(352, id, Buffer.alloc(9600), 11));
|
|
72
|
+
socket.send(ttsResponse(364, id, { text: '第二句。', words: [{ word: '第二句。', startTime: 0.3, endTime: 0.6 }] }));
|
|
73
|
+
socket.send(ttsResponse(351, id, { text: '第一句。第二句。', words: [] }));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (event === 102 && (mode === 'success' || mode === 'success-close' || mode === 'subtitles')) socket.send(ttsResponse(152, id, {}));
|
|
65
77
|
if (event === 102 && mode === 'success-close') socket.close();
|
|
66
78
|
if (event === 102 && mode === 'failure') socket.send(ttsResponse(153, id, { message: 'private details' }));
|
|
67
79
|
if (event === 102 && mode === 'truncated') socket.close();
|
|
@@ -93,6 +105,19 @@ it('uses only a ticket request through runtime transport and streams TTS PCM dir
|
|
|
93
105
|
expect(mocks.openRuntimeWebSocket).not.toHaveBeenCalled();
|
|
94
106
|
});
|
|
95
107
|
|
|
108
|
+
it('sends the full text once with TTS 2.0 subtitles and forwards event 364 without splitting audio sessions', async () => {
|
|
109
|
+
mode = 'subtitles';
|
|
110
|
+
const text = '第一句。\n\n第二句。';
|
|
111
|
+
const response = await requestSpeechAudio(text, new AbortController().signal);
|
|
112
|
+
const frames = (await response.text()).trim().split('\n').map(JSON.parse);
|
|
113
|
+
expect(ttsRequests).toHaveLength(1);
|
|
114
|
+
expect(ttsRequests[0].req_params.text).toBe(text);
|
|
115
|
+
expect(ttsRequests[0].req_params.audio_params.enable_subtitle).toBe(true);
|
|
116
|
+
expect(frames.map((frame) => frame.type)).toEqual(['audio', 'audio', 'subtitle', 'audio', 'subtitle', 'done']);
|
|
117
|
+
expect(frames.filter((frame) => frame.type === 'subtitle').map((frame) => frame.words[0].startTime)).toEqual([0, 0.3]);
|
|
118
|
+
expect(mocks.runtimeFetch).toHaveBeenCalledTimes(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
96
121
|
it('streams 100 ASR chunks in order, publishes live partials, and accepts a terminal frame without text', async () => {
|
|
97
122
|
const client = new DictationClient(); clients.push(client);
|
|
98
123
|
const partials = []; client.onPartial((_id, text) => partials.push(text));
|
|
@@ -48,12 +48,12 @@ describe('OpenCode proxy SSE forwarding', () => {
|
|
|
48
48
|
const upstream = express();
|
|
49
49
|
upstream.get('/api/location', (_req, res) => res.json({ project: { id: 'project-repo' } }));
|
|
50
50
|
upstream.get('/api/session', (req, res) => {
|
|
51
|
-
expect(req.query.project).
|
|
51
|
+
expect(req.query.project).toBeUndefined();
|
|
52
52
|
expect(req.query.directory).toBeUndefined();
|
|
53
53
|
res.json({ data: [session], cursor: {} });
|
|
54
54
|
});
|
|
55
55
|
upstream.get('/api/session/ses_alias', (_req, res) => res.json({ data: session }));
|
|
56
|
-
upstream.get('/api/
|
|
56
|
+
upstream.get('/api/event', (_req, res) => {
|
|
57
57
|
res.setHeader('Content-Type', 'text/event-stream');
|
|
58
58
|
res.end(`data: ${JSON.stringify({ directory: alias, payload: { type: 'session.updated', data: { info: session } } })}\n\n`);
|
|
59
59
|
});
|
|
@@ -88,7 +88,7 @@ describe('OpenCode proxy SSE forwarding', () => {
|
|
|
88
88
|
let seenAuthorization = null;
|
|
89
89
|
|
|
90
90
|
const upstream = express();
|
|
91
|
-
upstream.get('/api/
|
|
91
|
+
upstream.get('/api/event', (req, res) => {
|
|
92
92
|
seenAuthorization = req.headers.authorization ?? null;
|
|
93
93
|
res.setHeader('Content-Type', 'text/event-stream; charset=utf-8');
|
|
94
94
|
res.setHeader('Cache-Control', 'private, max-age=0');
|
|
@@ -133,7 +133,7 @@ describe('OpenCode proxy SSE forwarding', () => {
|
|
|
133
133
|
|
|
134
134
|
it('returns 504 when the upstream SSE response headers exceed the connection timeout', async () => {
|
|
135
135
|
const upstream = express();
|
|
136
|
-
upstream.get('/api/
|
|
136
|
+
upstream.get('/api/event', (_req, _res) => {});
|
|
137
137
|
upstreamServer = await listen(upstream);
|
|
138
138
|
const upstreamPort = upstreamServer.address().port;
|
|
139
139
|
|
|
@@ -158,7 +158,7 @@ describe('OpenCode proxy SSE forwarding', () => {
|
|
|
158
158
|
|
|
159
159
|
it('ends an established SSE response when upstream remains idle', async () => {
|
|
160
160
|
const upstream = express();
|
|
161
|
-
upstream.get('/api/
|
|
161
|
+
upstream.get('/api/event', (_req, res) => {
|
|
162
162
|
res.setHeader('Content-Type', 'text/event-stream');
|
|
163
163
|
res.flushHeaders();
|
|
164
164
|
});
|