An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: localStorage 支持在多界面实例间同步 https://github.com/siyuan-note/siyuan/issues/6965
Liang Ding853ba5be3a29
diff --git a/kernel/api/storage.go b/kernel/api/storage.goindex e8ea3e6cab..0066eed892 100644--- a/kernel/api/storage.go+++ b/kernel/api/storage.go@@ -188,11 +188,16 @@ func setLocalStorage(c *gin.Context) {}val := arg["val"].(interface{})-err := model.SetLocalStorage(val)if nil != err {ret.Code = -1ret.Msg = err.Error()return}++ app := arg["app"].(string)+ evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcastMainExcludeSelfApp, util.PushModeBroadcastMainExcludeSelfApp)+ evt.AppId = app+ evt.Data = val+ util.PushEvent(evt)}diff --git a/kernel/go.mod b/kernel/go.modindex f6d6f980a3..31c5126838 100644--- a/kernel/go.mod+++ b/kernel/go.mod@@ -39,7 +39,7 @@ require (github.com/patrickmn/go-cache v2.1.0+incompatiblegithub.com/radovskyb/watcher v1.0.7github.com/shirou/gopsutil/v3 v3.22.11- github.com/siyuan-note/dejavu v0.0.0-20230101033600-8b9f3e6befc0+ github.com/siyuan-note/dejavu v0.0.0-20230101054002-870267a37485github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522dagithub.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35ediff --git a/kernel/go.sum b/kernel/go.sumindex fa8b038aed..b8d51bb0a8 100644--- a/kernel/go.sum+++ b/kernel/go.sum@@ -374,8 +374,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1lgithub.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=-github.com/siyuan-note/dejavu v0.0.0-20230101033600-8b9f3e6befc0 h1:iIpzMneefDIHZk3xyXuDSxgz4ZsIvXCgB37LwdpnpBA=-github.com/siyuan-note/dejavu v0.0.0-20230101033600-8b9f3e6befc0/go.mod h1:gTazhE8f5TuknSodwQukv7GHy+qR1crX5SCxARrTXZU=+github.com/siyuan-note/dejavu v0.0.0-20230101054002-870267a37485 h1:oqHz0bGugvtUc9sl6YEru8jSA1YNHhMnPcvHLF/RuyM=+github.com/siyuan-note/dejavu v0.0.0-20230101054002-870267a37485/go.mod h1:gTazhE8f5TuknSodwQukv7GHy+qR1crX5SCxARrTXZU=github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=diff --git a/kernel/util/result.go b/kernel/util/result.goindex 0365252432..7ea9bf55db 100644--- a/kernel/util/result.go+++ b/kernel/util/result.go@@ -24,12 +24,13 @@ import (type PushMode intconst (- PushModeBroadcast PushMode = 0 // 所有应用所有会话广播- PushModeSingleSelf PushMode = 1 // 自我应用会话单播- PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播- PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播- PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播- PushModeNone PushMode = 10 // 不进行 reload+ PushModeBroadcast PushMode = 0 // 所有应用所有会话广播+ PushModeSingleSelf PushMode = 1 // 自我应用会话单播+ PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播+ PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播+ PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播+ PushModeBroadcastMainExcludeSelfApp PushMode = 6 // 非自我应用主会话广播+ PushModeNone PushMode = 10 // 不进行 reload)type Result struct {diff --git a/kernel/util/websocket.go b/kernel/util/websocket.goindex 76c25fb653..6e9b8a0ddf 100644--- a/kernel/util/websocket.go+++ b/kernel/util/websocket.go@@ -233,6 +233,8 @@ func PushEvent(event *Result) {broadcastOtherApps(msg, event.AppId)case PushModeBroadcastApp:broadcastApp(msg, event.AppId)+ case PushModeBroadcastMainExcludeSelfApp:+ broadcastOtherAppMains(msg, event.AppId)case PushModeNone:}}@@ -282,6 +284,26 @@ func broadcastOtherApps(msg []byte, excludeApp string) {})}+func broadcastOtherAppMains(msg []byte, excludeApp string) {+ sessions.Range(func(key, value interface{}) bool {+ appSessions := value.(*sync.Map)+ appSessions.Range(func(key, value interface{}) bool {+ session := value.(*melody.Session)+ if app, _ := session.Get("app"); app == excludeApp {+ return true+ }++ if t, ok := session.Get("type"); ok && "main" != t {+ return true+ }++ session.Write(msg)+ return true+ })+ return true+ })+}+func broadcastApp(msg []byte, app string) {sessions.Range(func(key, value interface{}) bool {appSessions := value.(*sync.Map)