An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
♻️ Declare deprecated API contracts https://github.com/siyuan-note/siyuan/issues/19378
Daniel413a572c9ec5
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.tsindex fcc812f118..b5fb697d3f 100644--- a/app/src/types/api/index.d.ts+++ b/app/src/types/api/index.d.ts@@ -386,7 +386,6 @@ export type APILegacyPOSTPath ="/api/asset/upload" |"/api/asset/uploadCloud" |"/api/asset/uploadCloudByAssetsPaths" |- "/api/attr/resetBlockAttrs" |"/api/av/addAttributeViewBlocks" |"/api/av/addAttributeViewKey" |"/api/av/appendAttributeViewDetachedBlocksWithValues" |@@ -424,7 +423,6 @@ export type APILegacyPOSTPath ="/api/av/renderHistoryAttributeView" |"/api/av/renderSnapshotAttributeView" |"/api/av/searchAttributeView" |- "/api/av/searchAttributeViewNonRelationKey" |"/api/av/searchAttributeViewRelationKey" |"/api/av/searchAttributeViewRollupDestKeys" |"/api/av/setAttrViewContextFilter" |@@ -709,7 +707,6 @@ export type APILegacyPOSTPath ="/api/storage/removeViewState" |"/api/storage/setCriterion" |"/api/storage/setInlineStyles" |- "/api/storage/setLocalStorage" |"/api/storage/setLocalStorageVal" |"/api/storage/setLocalStorageVals" |"/api/storage/setOutlineStorage" |@@ -771,7 +768,6 @@ export type APILegacyPOSTPath ="/api/system/oidc/validateActivate" |"/api/system/oidc/validateCancel" |"/api/system/oidc/validatePoll" |- "/api/system/reloadUI" |"/api/system/removeCustomFont" |"/api/system/removeWorkspaceDir" |"/api/system/removeWorkspaceDirPhysically" |@@ -825,11 +821,21 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": Array<string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "none";};+ "/api/attr/resetBlockAttrs": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };"/api/attr/setBlockAttrs": {request: SetBlockAttrsRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/av/searchAttributeViewNonRelationKey": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };"/api/block/appendBlock": {request: AppendBlockRequestInput;response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -1390,6 +1396,11 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "none";};+ "/api/storage/setLocalStorage": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };"/api/system/addMicrosoftDefenderExclusion": {request: EmptyRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -1430,6 +1441,11 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "none";};+ "/api/system/reloadUI": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };"/api/system/setAutoLaunch": {request: AutoLaunchRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };diff --git a/kernel/api/contract_deprecated_test.go b/kernel/api/contract_deprecated_test.gonew file mode 100644index 0000000000..79d0330577--- /dev/null+++ b/kernel/api/contract_deprecated_test.go@@ -0,0 +1,39 @@+package api++import (+ "encoding/json"+ "fmt"+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+)++func TestAPIContractDeprecatedResponses(t *testing.T) {+ engine := gin.New()+ engine.POST("/api/attr/resetBlockAttrs", resetBlockAttrs)+ engine.POST("/api/av/searchAttributeViewNonRelationKey", searchAttributeViewNonRelationKey)+ engine.POST("/api/storage/setLocalStorage", setLocalStorage)+ engine.POST("/api/system/reloadUI", deprecatedReloadUI)+ for _, path := range []string{"/api/attr/resetBlockAttrs", "/api/av/searchAttributeViewNonRelationKey", "/api/storage/setLocalStorage", "/api/system/reloadUI"} {+ for _, body := range []string{"", "{", "null", "{}"} {+ recorder := httptest.NewRecorder()+ uri := path + "?source=legacy"+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", uri, strings.NewReader(body)))+ requireAPIContract(t, "POST", path, recorder)+ var response struct {+ Code int `json:"code"`+ Msg string `json:"msg"`+ Data json.RawMessage `json:"data"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ want := fmt.Sprintf("[%s] is deprecated, visit [https://github.com/siyuan-note/siyuan/issues/15727] for details", uri)+ if response.Code != -1 || response.Msg != want || string(response.Data) != "null" {+ t.Fatalf("deprecated response changed: %s", recorder.Body.String())+ }+ }+ }+}diff --git a/kernel/api/router.go b/kernel/api/router.goindex 3a6e7ad2a4..b7a230158a 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -18,9 +18,8 @@ package apiimport ("fmt"- "net/http"+ "github.com/siyuan-note/siyuan/kernel/apicontract"- "github.com/88250/gulu""github.com/gin-gonic/gin""github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/model"@@ -94,7 +93,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/system/exportConf", model.CheckAuth, model.CheckAdminRole, exportConf)ginServer.Handle("POST", "/api/system/importConf", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, importConf)ginServer.Handle("POST", "/api/system/getWorkspaceInfo", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getWorkspaceInfo)- ginServer.Handle("POST", "/api/system/reloadUI", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, deprecated) // TODO 请使用 /api/ui/reloadUI,该端点将于 2026 年 12 月 1 日后删除+ ginServer.Handle("POST", "/api/system/reloadUI", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, deprecatedReloadUI) // TODO 请使用 /api/ui/reloadUI,该端点将于 2026 年 12 月 1 日后删除ginServer.Handle("POST", "/api/system/addMicrosoftDefenderExclusion", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, addMicrosoftDefenderExclusion)ginServer.Handle("POST", "/api/system/ignoreAddMicrosoftDefenderExclusion", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, ignoreAddMicrosoftDefenderExclusion)ginServer.Handle("POST", "/api/system/vacuumDataIndex", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, vacuumDataIndex)@@ -104,7 +103,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)ginServer.Handle("POST", "/api/storage/getLocalStorageVal", model.CheckAuth, getLocalStorageVal)ginServer.Handle("POST", "/api/storage/getLocalStorageVals", model.CheckAuth, getLocalStorageVals)- ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, deprecated) // TODO 请使用 /api/storage/setLocalStorageVal,该端点将于 2026 年 12 月 1 日后删除+ ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage) // TODO 请使用 /api/storage/setLocalStorageVal,该端点将于 2026 年 12 月 1 日后删除ginServer.Handle("POST", "/api/storage/setLocalStorageVal", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorageVal)ginServer.Handle("POST", "/api/storage/setLocalStorageVals", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorageVals)ginServer.Handle("POST", "/api/storage/removeLocalStorageVal", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, removeLocalStorageVal)@@ -333,7 +332,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/ref/getBackmentionDoc", model.CheckAuth, getBackmentionDoc)ginServer.Handle("POST", "/api/attr/getBookmarkLabels", model.CheckAuth, getBookmarkLabels)- ginServer.Handle("POST", "/api/attr/resetBlockAttrs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, deprecated) // TODO 请使用 /api/attr/setBlockAttrs,该端点将于 2026 年 12 月 1 日后删除+ ginServer.Handle("POST", "/api/attr/resetBlockAttrs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, resetBlockAttrs) // TODO 请使用 /api/attr/setBlockAttrs,该端点将于 2026 年 12 月 1 日后删除ginServer.Handle("POST", "/api/attr/setBlockAttrs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setBlockAttrs)ginServer.Handle("POST", "/api/attr/batchSetBlockAttrs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, batchSetBlockAttrs)ginServer.Handle("POST", "/api/attr/getBlockAttrs", model.CheckAuth, getBlockAttrs)@@ -597,7 +596,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/av/getAttributeView", model.CheckAuth, model.CheckReadonly, getAttributeView)ginServer.Handle("POST", "/api/av/getAttributeViewPasteRows", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getAttributeViewPasteRows)ginServer.Handle("POST", "/api/av/searchAttributeViewRelationKey", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, searchAttributeViewRelationKey)- ginServer.Handle("POST", "/api/av/searchAttributeViewNonRelationKey", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, deprecated) // TODO 请勿使用,该端点将于 2026 年 12 月 1 日后删除+ ginServer.Handle("POST", "/api/av/searchAttributeViewNonRelationKey", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, searchAttributeViewNonRelationKey) // TODO 请勿使用,该端点将于 2026 年 12 月 1 日后删除ginServer.Handle("POST", "/api/av/searchAttributeViewRollupDestKeys", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, searchAttributeViewRollupDestKeys)ginServer.Handle("POST", "/api/av/getAttributeViewFilterSort", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getAttributeViewFilterSort)ginServer.Handle("POST", "/api/av/setAttrViewFilters", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setAttrViewFilters)@@ -715,14 +714,19 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/ui/reloadTag", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, reloadTag)}-func deprecated(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)+func deprecatedResponse(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {msg := fmt.Sprintf("[%s] is deprecated, visit [https://github.com/siyuan-note/siyuan/issues/15727] for details",c.Request.RequestURI)logging.LogWarn(msg)- ret.Code = -1- ret.Msg = msg+ return apicontract.Failure[apicontract.Null](-1, msg)}++var resetBlockAttrs = contractHandler(apicontract.ResetBlockAttrs, deprecatedResponse)++var searchAttributeViewNonRelationKey = contractHandler(apicontract.SearchAttributeViewNonRelationKey, deprecatedResponse)++var setLocalStorage = contractHandler(apicontract.SetLocalStorage, deprecatedResponse)++var deprecatedReloadUI = contractHandler(apicontract.DeprecatedReloadUI, deprecatedResponse)diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.goindex 3dfaeccd7d..3dd8fd2d78 100644--- a/kernel/apicontract/contracts.go+++ b/kernel/apicontract/contracts.go@@ -380,3 +380,8 @@ var FlushTransaction = define[EmptyRequest, Null]("flushTransaction", "/api/sqlivar GetSnippet = define[GetSnippetRequest, SnippetsData]("getSnippet", "/api/snippet/getSnippet", JSONBody, ResponseOptions{}, "POST")var SetSnippet = define[SetSnippetRequest, Null]("setSnippet", "/api/snippet/setSnippet", JSONBody, ResponseOptions{}, "POST")var RemoveSnippet = define[TrimmedIDRequest, *Snippet]("removeSnippet", "/api/snippet/removeSnippet", JSONBody, ResponseOptions{}, "POST")++var ResetBlockAttrs = define[EmptyRequest, Null]("resetBlockAttrs", "/api/attr/resetBlockAttrs", NoBody, ResponseOptions{}, "POST")+var SearchAttributeViewNonRelationKey = define[EmptyRequest, Null]("searchAttributeViewNonRelationKey", "/api/av/searchAttributeViewNonRelationKey", NoBody, ResponseOptions{}, "POST")+var SetLocalStorage = define[EmptyRequest, Null]("setLocalStorage", "/api/storage/setLocalStorage", NoBody, ResponseOptions{}, "POST")+var DeprecatedReloadUI = define[EmptyRequest, Null]("deprecatedReloadUI", "/api/system/reloadUI", NoBody, ResponseOptions{}, "POST")diff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.jsonindex 85fbd9f7d1..30d5b09f31 100644--- a/kernel/apicontract/legacy_routes.json+++ b/kernel/apicontract/legacy_routes.json@@ -77,7 +77,6 @@{"method":"POST","path":"/api/asset/upload","handler":"model.Upload"},{"method":"POST","path":"/api/asset/uploadCloud","handler":"uploadCloud"},{"method":"POST","path":"/api/asset/uploadCloudByAssetsPaths","handler":"uploadCloudByAssetsPaths"},- {"method":"POST","path":"/api/attr/resetBlockAttrs","handler":"deprecated"},{"method":"POST","path":"/api/av/addAttributeViewBlocks","handler":"addAttributeViewBlocks"},{"method":"POST","path":"/api/av/addAttributeViewKey","handler":"addAttributeViewKey"},{"method":"POST","path":"/api/av/appendAttributeViewDetachedBlocksWithValues","handler":"appendAttributeViewDetachedBlocksWithValues"},@@ -115,7 +114,6 @@{"method":"POST","path":"/api/av/renderHistoryAttributeView","handler":"renderHistoryAttributeView"},{"method":"POST","path":"/api/av/renderSnapshotAttributeView","handler":"renderSnapshotAttributeView"},{"method":"POST","path":"/api/av/searchAttributeView","handler":"searchAttributeView"},- {"method":"POST","path":"/api/av/searchAttributeViewNonRelationKey","handler":"deprecated"},{"method":"POST","path":"/api/av/searchAttributeViewRelationKey","handler":"searchAttributeViewRelationKey"},{"method":"POST","path":"/api/av/searchAttributeViewRollupDestKeys","handler":"searchAttributeViewRollupDestKeys"},{"method":"POST","path":"/api/av/setAttrViewContextFilter","handler":"setAttrViewContextFilter"},@@ -397,7 +395,6 @@{"method":"POST","path":"/api/storage/removeViewState","handler":"removeViewState"},{"method":"POST","path":"/api/storage/setCriterion","handler":"setCriterion"},{"method":"POST","path":"/api/storage/setInlineStyles","handler":"setInlineStyles"},- {"method":"POST","path":"/api/storage/setLocalStorage","handler":"deprecated"},{"method":"POST","path":"/api/storage/setLocalStorageVal","handler":"setLocalStorageVal"},{"method":"POST","path":"/api/storage/setLocalStorageVals","handler":"setLocalStorageVals"},{"method":"POST","path":"/api/storage/setOutlineStorage","handler":"setOutlineStorage"},@@ -459,7 +456,6 @@{"method":"POST","path":"/api/system/oidc/validateActivate","handler":"model.OIDCValidateActivate"},{"method":"POST","path":"/api/system/oidc/validateCancel","handler":"model.OIDCValidateCancel"},{"method":"POST","path":"/api/system/oidc/validatePoll","handler":"model.OIDCValidatePoll"},- {"method":"POST","path":"/api/system/reloadUI","handler":"deprecated"},{"method":"POST","path":"/api/system/removeCustomFont","handler":"removeCustomFont"},{"method":"POST","path":"/api/system/removeWorkspaceDir","handler":"removeWorkspaceDir"},{"method":"POST","path":"/api/system/removeWorkspaceDirPhysically","handler":"removeWorkspaceDirPhysically"},diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.jsonindex e896885036..e6cf5e6ae8 100644--- a/kernel/apicontract/schema.json+++ b/kernel/apicontract/schema.json@@ -4899,6 +4899,81 @@]}},+ {+ "method": "POST",+ "path": "/api/attr/resetBlockAttrs",+ "handler": "resetBlockAttrs",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },{"method": "POST","path": "/api/attr/setBlockAttrs",@@ -4974,6 +5049,81 @@]}},+ {+ "method": "POST",+ "path": "/api/av/searchAttributeViewNonRelationKey",+ "handler": "searchAttributeViewNonRelationKey",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },{"method": "POST","path": "/api/block/appendBlock",@@ -13884,6 +14034,81 @@]}},+ {+ "method": "POST",+ "path": "/api/storage/setLocalStorage",+ "handler": "setLocalStorage",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },{"method": "POST","path": "/api/system/addMicrosoftDefenderExclusion",@@ -14484,6 +14709,81 @@]}},+ {+ "method": "POST",+ "path": "/api/system/reloadUI",+ "handler": "deprecatedReloadUI",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },{"method": "POST","path": "/api/system/setAutoLaunch",