@@ -37,6 +37,10 @@ const emitters = new Set();
3737// 只能靠状态决定删谁;状态又是所有面板共用的,所以按 scope 记一份,删除前
3838// 与本面板打开的那条核对,不匹配就拒绝(评审 #5)。
3939const openedBy = new Map ( ) ;
40+ // 冲突页的裁决同样改数据,而 state.conflictId 是模块级共享的:两个面板
41+ // 各看一条冲突时,后开的会盖掉前一个的 id。按面板 scope 记一份再核对
42+ // (评审 #3 的 conflict-win 部分)。
43+ const conflictBy = new Map ( ) ;
4044// 上一次推给 App 的完整数据:未重新读取的块从这里并回去,保证每份 data 都
4145// 带着全部绑定键(见 load 的注释)。
4246let lastPayload = null ;
@@ -112,6 +116,16 @@ const defaultState = () => ({
112116 sCmdIns : "" ,
113117 vector : { enabled : false , baseUrl : "" , model : "" } ,
114118 external : { enabled : false , port : 8790 , host : "127.0.0.1" } ,
119+ // 读成功才允许整体写回:读失败时上面的 vector/external 会落成默认值,
120+ // 此时 PUT 会把用户在 Web 面板里配好的地址/端口覆盖掉(评审 #2)。
121+ vectorLoaded : false ,
122+ externalLoaded : false ,
123+ // 实体搜索要重读的是「实体清单」而不是整页;load() 按这个标记补读
124+ // (评审 #4)。
125+ entityDirty : false ,
126+ // 顶层页签由 App 本地切换,state.page 可能还停在 "list";设置项的动作
127+ // 改完数据后也要重读设置块,否则推到面板上的仍是旧值(评审 #6)。
128+ settingsDirty : false ,
115129 versionNote : "" ,
116130 extractText : "" ,
117131 injectPreviewText : "" ,
@@ -503,6 +517,9 @@ export function mountDshGoPanel(ctx, options = {}) {
503517 } ) ;
504518 } else if ( state . sPanel === "vector" ) {
505519 const res = await call ( "/vector-config" ) . catch ( ( ) => null ) ;
520+ // 读到才算 loaded:读失败时下面会落成默认值,不能再拿它整体覆盖
521+ // 服务端配置(评审 #2)。
522+ state . vectorLoaded = res !== null && typeof res === "object" && res . config !== null && typeof res . config === "object" ;
506523 const config = res ?. config ?? { } ;
507524 state . vector = {
508525 enabled : config . enabled === true ,
@@ -531,6 +548,7 @@ export function mountDshGoPanel(ctx, options = {}) {
531548 // 把用户已经在 Web 面板里配好的端口/地址覆盖掉(评审 #6)。
532549 // 必须带 token=omit:不带的话这条 GET 会顺手生成并落库一个 Bearer。
533550 const res = await call ( "/external-api?token=omit" ) . catch ( ( ) => null ) ;
551+ state . externalLoaded = res !== null && typeof res === "object" && res . config !== null && typeof res . config === "object" ;
534552 const config = res ?. config ?? { } ;
535553 state . external = {
536554 enabled : config . enabled === true ,
@@ -819,11 +837,16 @@ export function mountDshGoPanel(ctx, options = {}) {
819837 const memory = page === "detail" ? loadDetail ( ) : page === "editor" ? loadEditor ( ) : loadMemory ( ) ;
820838 merge ( Promise . resolve ( memory ) ) ;
821839 }
822- if ( full || page === "entity" ) merge ( page === "entity" ? loadEntityDetail ( ) : loadEntity ( ) ) ;
823- if ( full || page === "settings" || page === "profile" ) {
840+ const entityPage = page === "entity" ;
841+ // 实体搜索要重读实体清单;但搜索后 state.page 仍是 "list"(视图里实体
842+ // 区就是列表),旧条件只看页面,于是搜索完推的仍是搜索前那份(评审 #4)。
843+ if ( full || entityPage || state . entityDirty ) merge ( entityPage ? loadEntityDetail ( ) : loadEntity ( ) ) ;
844+ state . entityDirty = false ;
845+ if ( full || page === "settings" || page === "profile" || state . settingsDirty ) {
824846 merge ( loadSettings ( ) ) ;
825847 merge ( loadStatus ( ) ) ;
826848 }
849+ state . settingsDirty = false ;
827850 if ( full || ( memoryPage && page === "conflict" ) ) merge ( loadConflict ( ) ) ;
828851 if ( full || page === "profile" ) merge ( loadProfile ( ) ) ;
829852 const settled = await Promise . allSettled ( jobs ) ;
@@ -1046,7 +1069,7 @@ export function mountDshGoPanel(ctx, options = {}) {
10461069 ) ;
10471070 }
10481071 } catch ( error ) {
1049- state . provenanceText = errorText ( error ) . includes ( "DISTILL_RECORDS_DISABLED " )
1072+ state . provenanceText = errorText ( error ) . includes ( "distill-records-disabled " )
10501073 ? "mneme 没开「保留蒸馏原文」,所以这条记忆没有可查的来源窗口。"
10511074 : errorText ( error ) ;
10521075 }
@@ -1131,6 +1154,8 @@ export function mountDshGoPanel(ctx, options = {}) {
11311154 resetNotice ( ) ;
11321155 state . entityQuery = String ( valueOf ( event , [ "entityQuery" , "query" , "q" ] , "" ) ?? "" ) . trim ( ) ;
11331156 state . page = "list" ;
1157+ // 让下一次 load() 补读实体清单(页面仍是列表,见 load 里的注释)。
1158+ state . entityDirty = true ;
11341159 return { } ;
11351160 } ,
11361161
@@ -1141,10 +1166,12 @@ export function mountDshGoPanel(ctx, options = {}) {
11411166 return { } ;
11421167 } ,
11431168
1144- edit ( ) {
1169+ edit ( scope ) {
11451170 resetNotice ( ) ;
11461171 const memo = state . current ;
11471172 if ( memo === null ) return { toast : "先选一条记忆" } ;
1173+ // 记下本面板打开的那条:save 也要按它核对(评审 #3)。
1174+ openedBy . set ( scopeKey ( scope ) , memo . id ) ;
11481175 state . form = {
11491176 id : memo . id ,
11501177 title : memo . title ?? "" ,
@@ -1206,6 +1233,15 @@ export function mountDshGoPanel(ctx, options = {}) {
12061233 const tags = splitTags ( String ( source . tags ?? "" ) ) ;
12071234 if ( title === "" || content === "" ) return { toast : "标题和正文都不能空" } ;
12081235 const id = state . form . id === "" || state . form . id === undefined ? undefined : String ( state . form . id ) ;
1236+ // 编辑既有条目也要核对面板 scope:state.form 是模块级共享的,两个面板
1237+ // 各开一条时,A 面板点保存会把内容写进 B 刚打开的那条(评审 #3)。
1238+ // 新建(id 为空)不涉及已有行,不核对。
1239+ if ( id !== undefined ) {
1240+ const mine = openedBy . get ( scopeKey ( scope ) ) ;
1241+ if ( mine === undefined || mine !== id ) {
1242+ return { toast : "这条不是当前打开的记忆,已取消" } ;
1243+ }
1244+ }
12091245
12101246 if ( id === undefined ) {
12111247 try {
@@ -1473,6 +1509,7 @@ export function mountDshGoPanel(ctx, options = {}) {
14731509 "conflict-pick-row" ( scope , event ) {
14741510 resetNotice ( ) ;
14751511 state . conflictId = String ( valueOf ( event , [ "id" ] , "" ) ?? "" ) ;
1512+ conflictBy . set ( scopeKey ( scope ) , state . conflictId ) ;
14761513 state . conflictPick = "" ;
14771514 state . page = "conflict" ;
14781515 return { } ;
@@ -1491,9 +1528,14 @@ export function mountDshGoPanel(ctx, options = {}) {
14911528 if ( valueOf ( event , [ "confirmed" ] , false ) !== true ) return { } ;
14921529 const id = state . conflictId ;
14931530 if ( id === "" ) return { toast : "先选一条冲突" } ;
1531+ // 冲突 id 也是共享状态:只裁决本面板自己选中的那条(评审 #3)。
1532+ if ( conflictBy . get ( scopeKey ( scope ) ) !== id ) {
1533+ return { toast : "这条不是当前打开的冲突,已取消" } ;
1534+ }
14941535 const winner = state . conflictPick === "a" ? "a" : state . conflictPick === "b" ? "b" : null ;
14951536 try {
14961537 await call ( "/conflicts/resolve" , { method : "POST" , body : { id, winner, apply : true } } ) ;
1538+ conflictBy . delete ( scopeKey ( scope ) ) ;
14971539 state . conflictId = "" ;
14981540 state . conflictPick = "" ;
14991541 notice ( "已按裁决合并。" ) ;
@@ -1566,6 +1608,8 @@ export function mountDshGoPanel(ctx, options = {}) {
15661608
15671609 "vector-toggle" ( scope , event ) {
15681610 resetNotice ( ) ;
1611+ // 没读到真实配置时 state.vector 只是默认值,整体 PUT 会覆盖服务端(评审 #2)。
1612+ if ( ! state . vectorLoaded ) return { toast : "还没读到向量配置,请刷新后再改" } ;
15691613 const value = event ?. value ;
15701614 state . vector . enabled = typeof value === "boolean" ? value : ! state . vector . enabled ;
15711615 return call ( "/vector-config" , {
@@ -1585,6 +1629,7 @@ export function mountDshGoPanel(ctx, options = {}) {
15851629
15861630 "vector-save" ( scope , event ) {
15871631 resetNotice ( ) ;
1632+ if ( ! state . vectorLoaded ) return { toast : "还没读到向量配置,请刷新后再改" } ;
15881633 const value = event ?. value ;
15891634 const source = value !== null && typeof value === "object" && ! Array . isArray ( value ) ? value : { } ;
15901635 const baseUrl = String ( source . sVecUrl ?? state . vector . baseUrl ?? "" ) . trim ( ) ;
@@ -1626,6 +1671,7 @@ export function mountDshGoPanel(ctx, options = {}) {
16261671
16271672 "external-toggle" ( scope , event ) {
16281673 resetNotice ( ) ;
1674+ if ( ! state . externalLoaded ) return { toast : "还没读到外部访问配置,请刷新后再改" } ;
16291675 const value = event ?. value ;
16301676 state . external . enabled = typeof value === "boolean" ? value : ! state . external . enabled ;
16311677 return call ( "/external-api" , {
@@ -1645,6 +1691,7 @@ export function mountDshGoPanel(ctx, options = {}) {
16451691
16461692 "external-save" ( scope , event ) {
16471693 resetNotice ( ) ;
1694+ if ( ! state . externalLoaded ) return { toast : "还没读到外部访问配置,请刷新后再改" } ;
16481695 const value = event ?. value ;
16491696 const source = value !== null && typeof value === "object" && ! Array . isArray ( value ) ? value : { } ;
16501697 const port = Math . round ( num ( source . sExtPort ?? state . external . port , 8790 ) ) ;
@@ -1712,6 +1759,7 @@ export function mountDshGoPanel(ctx, options = {}) {
17121759 state . flagOverrides = features ?. overrides ?? { } ;
17131760 state . pendingRestart = Array . isArray ( features ?. pendingRestart ) ? features . pendingRestart : [ ] ;
17141761 state . flags = features ?. effective ?? state . flags ;
1762+ state . settingsDirty = true ;
17151763 notice (
17161764 `${ FLAG_LABELS . get ( key ) ?? key } :${
17171765 typeof next === "string" ? next : next ? "已开启" : "已关闭"
@@ -1920,6 +1968,7 @@ export function mountDshGoPanel(ctx, options = {}) {
19201968 state . flagOverrides = features ?. overrides ?? { } ;
19211969 state . pendingRestart = Array . isArray ( features ?. pendingRestart ) ? features . pendingRestart : [ ] ;
19221970 state . flags = features ?. effective ?? state . flags ;
1971+ state . settingsDirty = true ;
19231972 notice ( `${ key } :${ next ? "已开启" : "已关闭" } ` ) ;
19241973 } catch ( error ) {
19251974 state . err = errorText ( error ) ;
@@ -2022,6 +2071,7 @@ export function resetPanelState() {
20222071 cache . clear ( ) ;
20232072 emitters . clear ( ) ;
20242073 openedBy . clear ( ) ;
2074+ conflictBy . clear ( ) ;
20252075 lastPayload = null ;
20262076 Object . assign ( state , defaultState ( ) ) ;
20272077}
0 commit comments