An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Migrate plugin RPC API contracts https://github.com/siyuan-note/siyuan/issues/19378
Daniel9351d1151d0f
diff --git a/app/src/plugin/kernel.ts b/app/src/plugin/kernel.tsindex 12d994251a..bd93e3e5b3 100644--- a/app/src/plugin/kernel.ts+++ b/app/src/plugin/kernel.ts@@ -192,8 +192,11 @@ export class Kernel implements IKernelPlugin {async #initState() {const response = await fetchSyncPost("/api/plugin/getLoadedPlugin", { name: this.#name });- if (this.state.code === -1 && response.data?.stateCode != null) {- this.state.code = response.data.stateCode;+ if (this.state.code === -1 && response.code === 0 && response.data?.stateCode != null) {+ const state = response.data.stateCode;+ if (state === 0 || state === 1 || state === 2 || state === 3 || state === 4 || state === 5) {+ this.state.code = state;+ }}}diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.tsindex 39e0199f66..0dac140e7c 100644--- a/app/src/types/api/index.d.ts+++ b/app/src/types/api/index.d.ts@@ -388,6 +388,10 @@ export type ListNotebooksRequestInput = { "flashcard"?: boolean | null; };export type LoadPetalsRequestInput = { "frontend": string; };+export type LoadedPlugin = { "methods": Array<PluginRPCMethod | null> | null; "name": string; "state": string; "stateCode": number; };++export type LoadedPluginRequestInput = { "name": string; };+export type LocalGraphConf = { "d3": GraphD3 | null; "dailyNote": boolean; "type": GraphTypeFilter | null; };export type LocalGraphRequestInput = { "conf"?: GraphConfigurationFieldsInput; "id"?: string | null; "k"?: string | null; "notebook"?: string | null; "reqId"?: JSONValue | null; "type"?: string | null; };@@ -472,6 +476,18 @@ export type Petal = { "css": string; "disabledInPublish": boolean; "disallowInstexport type PinnedDoc = { "childrenSortMode": number | null; "icon": string; "id": string; "name": string; "notebook": string; "path": string; "subFileCount": number; "unavailable": boolean; };+export type PluginRPCError = { "code": number; "data"?: JSONValue; "message": string; };++export type PluginRPCFailure = { "error": PluginRPCError | null; "id": string | number | null; "jsonrpc": "2.0"; };++export type PluginRPCMethod = { "descriptions": Array<string> | null; "name": string; };++export type PluginRPCNotification = { "jsonrpc": "2.0"; "method": string; "params"?: JSONValue; };++export type PluginRPCRequestFieldsInput = { "id"?: string | number | null; "jsonrpc": "2.0"; "method": string; "params"?: Array<JSONValue> | { [key: string]: JSONValue } | null; };++export type PluginRPCSuccess = { "id": string | number | null; "jsonrpc": "2.0"; "result": JSONValue; };+export type PrepareRichTextRequestInput = { "assets": Array<RichClipboardAssetInput>; };export type PrependBlockRequestInput = { "data": string; "dataType": string; "parentID": string; };@@ -720,9 +736,6 @@ export type APILegacyGETPath ="/api/network/echo" |"/api/network/echo/*path" |"/api/network/proxy" |- "/api/plugin" |- "/api/plugin/rpc" |- "/api/plugin/rpc/:name" |"/api/system/bootProgressSSE" |"/api/system/getBootAppearance" |"/api/system/getCaptcha" |@@ -731,11 +744,24 @@ export type APILegacyGETPath ="/es/network/proxy" |"/plugin/private/:name/*path" |"/ws/broadcast" |- "/ws/network/proxy" |- "/ws/plugin/rpc" |- "/ws/plugin/rpc/:name";+ "/ws/network/proxy";export interface APIGETRoutes {+ "/api/plugin": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": Array<LoadedPlugin | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };+ "/api/plugin/rpc": {+ request: LoadedPluginRequestInput;+ response: { "code": 0; "data": LoadedPlugin | null; "msg": string; } | { "code": -1 | 1 | 2 | 3 | 4; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/plugin/rpc/:name": {+ request: LoadedPluginRequestInput;+ response: { "code": 0; "data": LoadedPlugin | null; "msg": string; } | { "code": -1 | 1 | 2 | 3 | 4; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/system/bootProgress": {request: EmptyRequestInput;response: { "code": 0; "data": BootProgressData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -746,6 +772,20 @@ export interface APIGETRoutes {response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "none";};+ "/ws/plugin/rpc": {+ request: EmptyRequestInput;+ response: (PluginRPCFailure & { "code"?: never; "data"?: never; "msg"?: never; }) | ({ "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; } & { "error"?: never; "id"?: never; "jsonrpc"?: never; });+ body: "none";+ output: "websocket";+ websocket: { incoming: PluginRPCRequestFieldsInput | [PluginRPCRequestFieldsInput, ...Array<PluginRPCRequestFieldsInput>]; outgoing: (PluginRPCSuccess & { "error"?: never; "method"?: never; "params"?: never; }) | (PluginRPCFailure & { "method"?: never; "params"?: never; "result"?: never; }) | [(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; }), ...Array<(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; })>] | (PluginRPCNotification & { "error"?: never; "id"?: never; "result"?: never; }); failureStatus: 404; };+ };+ "/ws/plugin/rpc/:name": {+ request: EmptyRequestInput;+ response: (PluginRPCFailure & { "code"?: never; "data"?: never; "msg"?: never; }) | ({ "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; } & { "error"?: never; "id"?: never; "jsonrpc"?: never; });+ body: "none";+ output: "websocket";+ websocket: { incoming: PluginRPCRequestFieldsInput | [PluginRPCRequestFieldsInput, ...Array<PluginRPCRequestFieldsInput>]; outgoing: (PluginRPCSuccess & { "error"?: never; "method"?: never; "params"?: never; }) | (PluginRPCFailure & { "method"?: never; "params"?: never; "result"?: never; }) | [(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; }), ...Array<(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; })>] | (PluginRPCNotification & { "error"?: never; "id"?: never; "result"?: never; }); failureStatus: 404; };+ };}export type APILegacyPOSTPath =@@ -957,10 +997,6 @@ export type APILegacyPOSTPath ="/api/network/echo/*path" |"/api/network/forwardProxy" |"/api/network/proxy" |- "/api/plugin/getLoadedPlugin" |- "/api/plugin/listLoadedPlugins" |- "/api/plugin/rpc" |- "/api/plugin/rpc/:name" |"/api/repo/checkoutRepo" |"/api/repo/diffRepoSnapshots" |"/api/repo/downloadCloudSnapshot" |@@ -1807,7 +1843,7 @@ export interface APIPOSTRoutes {};"/api/lute/wpsPresentation2BlockDOM": {request: WPSPresentationRequestInput;- response: { "code": 0; "data": WPSPresentationData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null | WPSPresentationData; "msg": string; };+ response: { "code": 0; "data": WPSPresentationData; "msg": string; } | { "code": -1; "data": ({ "closeTimeout": number; } & { "converted"?: never; "dom"?: never; }) | null | (WPSPresentationData & { "closeTimeout"?: never; }); "msg": string; };body: "json";};"/api/notebook/changeMasterPassword": {@@ -1965,6 +2001,30 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": Petal | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/plugin/getLoadedPlugin": {+ request: LoadedPluginRequestInput;+ response: { "code": 0; "data": LoadedPlugin | null; "msg": string; } | { "code": -1 | 1 | 2 | 3 | 4; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/plugin/listLoadedPlugins": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": Array<LoadedPlugin | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };+ "/api/plugin/rpc": {+ request: PluginRPCRequestFieldsInput | [PluginRPCRequestFieldsInput, ...Array<PluginRPCRequestFieldsInput>];+ response: (PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; }) | [(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; }), ...Array<(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; })>] | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ output: "directJSON";+ noContent: true;+ };+ "/api/plugin/rpc/:name": {+ request: PluginRPCRequestFieldsInput | [PluginRPCRequestFieldsInput, ...Array<PluginRPCRequestFieldsInput>];+ response: (PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; }) | [(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; }), ...Array<(PluginRPCSuccess & { "error"?: never; }) | (PluginRPCFailure & { "result"?: never; })>] | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ output: "directJSON";+ noContent: true;+ };"/api/query/sql": {request: SQLQueryRequestInput;response: { "code": 0; "data": Array<Record<string, null | string | number | boolean> | null>; "limit": number; "msg": string; "truncated": boolean; } | ({ "code": -1 | 1; "data": { "closeTimeout": number; } | null; "msg": string; } & { "limit"?: never; "truncated"?: never; });@@ -1972,7 +2032,7 @@ export interface APIPOSTRoutes {};"/api/ref/getBacklink2": {request: BacklinkListRequestInput;- response: { "code": 0; "data": BacklinkList | BacklinkRefDefs | null; "msg": string; } | { "code": -1 | 1; "data": { "closeTimeout": number; } | null | BacklinkList | BacklinkRefDefs | null; "msg": string; };+ response: { "code": 0; "data": (BacklinkList & { "refDefs"?: never; }) | (BacklinkRefDefs & { "backlinks"?: never; "backmentions"?: never; "box"?: never; "k"?: never; "linkRefsCount"?: never; "mentionsCount"?: never; "mk"?: never; "revision"?: never; "unchanged"?: never; }) | null; "msg": string; } | { "code": -1 | 1; "data": { "closeTimeout": number; } | null | (BacklinkList & { "refDefs"?: never; }) | (BacklinkRefDefs & { "backlinks"?: never; "backmentions"?: never; "box"?: never; "k"?: never; "linkRefsCount"?: never; "mentionsCount"?: never; "mk"?: never; "revision"?: never; "unchanged"?: never; }) | null; "msg": string; };body: "json";};"/api/ref/getBacklinkDoc": {@@ -2372,7 +2432,7 @@ export interface APIPOSTRoutes {};"/api/template/manage": {request: TemplateFileRequestInput;- response: { "code": 0; "data": Array<TemplateFileEntry> | TemplateFileSource | TemplateFileRevision | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ response: { "code": 0; "data": Array<TemplateFileEntry> | TemplateFileSource | (TemplateFileRevision & { "content"?: never; "path"?: never; }) | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "structJSON";};"/api/template/render": {@@ -2459,8 +2519,10 @@ export type APICallbackResponse<R> = R extends {code: infer C extends number}? NonNegative<C> extends never ? never : R & {code: NonNegative<C>}: never;+type APIDirectCallbackResponse<R> = R extends {code: number} ? APICallbackResponse<R> : R;+type APIPostTail<C extends APIContract> = [- cb?: (response: C extends {output: "binary"} ? JSONValue : APICallbackResponse<C["response"]>) => void,+ cb?: (response: C extends {output: "binary"} ? JSONValue : C extends {output: "directJSON"} ? APIDirectCallbackResponse<C["response"]> | (C extends {noContent: true} ? "" : never) : APICallbackResponse<C["response"]>) => void,headers?: Record<string, string>,failCallback?: (response: APIFetchFailure) => void,signal?: AbortSignal,@@ -2498,7 +2560,7 @@ export type FetchSyncPost<Legacy = APILegacyResponse> = <Path extends string>(export type FetchGet<Legacy = APILegacyResponse | string> = <Path extends string>(url: Path,...args: Path extends keyof APIGETRoutes- ? [cb: (response: APIGETRoutes[Path]["response"]) => void]+ ? [cb: (response: APIGETRoutes[Path]["response"] | (APIGETRoutes[Path] extends {output: "websocket"} ? string : never)) => void]: Path extends keyof APIPOSTRoutes ? never: [cb: (response: Legacy) => void]) => void;diff --git a/app/src/util/fetch.test.ts b/app/src/util/fetch.test.tsindex ddaeb11afe..5176dde54e 100644--- a/app/src/util/fetch.test.ts+++ b/app/src/util/fetch.test.ts@@ -79,6 +79,13 @@ it("keeps asynchronous error responses and the process option", async () => {assert.equal(processed, 1);});+it("preserves notification-only RPC responses as empty callback text", async () => {+ const {fetchPost} = loadFetchPost(async () => new Response(null, {status: 204}));+ let received: unknown;+ await fetchPost("/api/plugin/rpc", {jsonrpc: "2.0", method: "notify"}, (response: unknown) => received = response);+ assert.equal(received, "");+});+it("preserves raw file text and routes HTTP 202 file errors to the failure callback", async () => {const text = "file content";const raw = loadFetchPost(async () => new Response(text, {headers: {"Content-Type": "text/plain"}}));diff --git a/app/tests/api-contract.types.ts b/app/tests/api-contract.types.tsindex f5478c49a0..46b8562c28 100644--- a/app/tests/api-contract.types.ts+++ b/app/tests/api-contract.types.ts@@ -1,4 +1,4 @@-import type {APIPOSTRoutes, FetchGet, FetchPost, FetchSyncPost, JSONValue} from "../src/types/api";+import type {APIGETRoutes, APIPOSTRoutes, FetchGet, FetchPost, FetchSyncPost, JSONValue} from "../src/types/api";import {ContractFormData} from "../src/util/contractFormData";declare const fetchPost: FetchPost;@@ -6,6 +6,65 @@ declare const fetchGet: FetchGet;declare const fetchSyncPost: FetchSyncPost;declare const dynamicURL: string;+type RPCWebSocket = APIGETRoutes["/ws/plugin/rpc"]["websocket"];+const rpcCall: RPCWebSocket["incoming"] = {jsonrpc: "2.0", method: "call", id: 1};+const rpcNotice: RPCWebSocket["outgoing"] = {jsonrpc: "2.0", method: "event", params: null};+// @ts-expect-error 批量调用不能为空。+const rpcEmptyBatch: RPCWebSocket["incoming"] = [];+// @ts-expect-error 出站通知不能携带调用 ID。+const rpcInvalidNotice: RPCWebSocket["outgoing"] = {jsonrpc: "2.0", method: "event", id: 1};+// @ts-expect-error HTTP 中间件信封不是连接内的消息。+const rpcInvalidFrame: RPCWebSocket["outgoing"] = {code: -1, msg: "denied", data: null};+void [rpcCall, rpcNotice, rpcEmptyBatch, rpcInvalidNotice, rpcInvalidFrame];++fetchPost("/api/plugin/rpc", {jsonrpc: "2.0", method: "notify"}, response => {+ const empty: "" | object = response;+ // @ts-expect-error 纯通知请求的回调可能为空字符串。+ const objectOnly: object = response;+ void [empty, objectOnly];+});+fetchGet("/ws/plugin/rpc", response => {+ if (typeof response === "string") {+ const rejection: string = response;+ void rejection;+ }+ // @ts-expect-error 普通 GET 可能收到拒绝升级的文本。+ const objectOnly: object = response;+ void objectOnly;+});++fetchPost("/api/plugin/rpc", {jsonrpc: "2.0", method: "call", params: {key: [1, true]}, id: 1}, response => {+ if (response !== "" && !Array.isArray(response) && "jsonrpc" in response) {+ const version: "2.0" = response.jsonrpc;+ const id: string | number | null = response.id;+ void [version, id];+ }+});+fetchPost("/api/plugin/rpc/:name", [{jsonrpc: "2.0", method: "notify"}, {jsonrpc: "2.0", method: "call", id: null}]);+// @ts-expect-error RPC 请求需要协议版本。+fetchPost("/api/plugin/rpc", {method: "call"});+// @ts-expect-error RPC 关联标识不接受布尔值。+fetchPost("/api/plugin/rpc", {jsonrpc: "2.0", method: "call", id: true});+// @ts-expect-error RPC 参数应为数组或对象。+fetchPost("/api/plugin/rpc", {jsonrpc: "2.0", method: "call", params: "text"});++fetchPost("/api/plugin/getLoadedPlugin", {name: "plugin"}, response => {+ if (response.code === 0 && response.data) {+ const state: number = response.data.stateCode;+ const descriptions: string[] | null | undefined = response.data.methods?.[0]?.descriptions;+ void [state, descriptions];+ }+ // @ts-expect-error 插件查询的非零业务码不携带插件信息。+ const state: number = response.data.stateCode;+ void state;+});+// @ts-expect-error 插件名称必须为字符串。+fetchPost("/api/plugin/getLoadedPlugin", {name: 1});+fetchPost("/api/plugin/listLoadedPlugins", undefined, response => {+ const name: string | undefined = response.data?.[0]?.name;+ void name;+});+fetchPost("/api/search/fullTextSearchBlock", {query: "text", subTypes: {heading: {h1: true}}}, response => {if (response.data) {const count: number = response.data.matchedBlockCount;diff --git a/docs/API-CONTRACTS.md b/docs/API-CONTRACTS.mdindex 0ead182e0f..f3446b8364 100644--- a/docs/API-CONTRACTS.md+++ b/docs/API-CONTRACTS.md@@ -24,6 +24,8 @@ Encrypted notebook lifecycle endpoints use typed requests and responses while re## Compatibility requirements+Plugin information queries retain path, query-string, and JSON-body name precedence, including whitespace and business error codes 1 through 4. URL parameters bypass body decoding, and list queries ignore the body. Plugin and RPC-method lists retain nullable arrays and entries. HTTP JSON-RPC has a separate contract for single and batch requests, success and error replies, and notification-only HTTP 204 responses. Plugin admission occurs before body reads, batch errors retain their order, and arbitrary JSON is limited to RPC parameters, results, and error details. RPC WebSocket routes declare HTTP 101 upgrades, HTTP 404 plugin admission errors, HTTP 400 text rejections, and separate incoming calls and outgoing replies or notifications. Origin authorization and connection cleanup remain in the existing upgrade lifecycle. Plugin HTTP services remain a separate protocol migration.+Search contracts retain pagination defaults and numeric truncation, path validation and deduplication, ignored historical subtype filters, and null versus empty arrays. Reference search distinguishes correlation-only responses from block results and retains notebook admission before deferred parameter validation. SQL search authorization, publish filtering, encrypted notebook leases, cancellation responses, and read-only embed-update no-ops remain in their original order. Desktop and mobile callers share generated request types.History contracts retain path trimming, optional highlight defaults, fractional history-type truncation, and null versus empty result arrays. Version comparison checks both reference objects before their fields and acquires notebook leases in sorted order. Content reads and document, asset, and attribute-view rollbacks retain their history-path lease checks; notebook rollback keeps its existing model-level recovery behavior.@@ -66,8 +68,12 @@ All `/api/block/` routes use contracts. Heading-level queries retain batch-ID prStorage contracts keep arbitrary JSON limited to storage values; keys, recent documents, search criteria, inline styles, and attribute-view palettes have structured types. Recent-document mutations retain their read-only no-op before parsing the body. An optional typed `beforeDecode` callback on `contractHandler` preserves this ordering and may return a response before decoding; route checks still require an explicit endpoint binding. Inline-style version 1 updates preserve existing built-in configuration, while version 2 and palette requests retain their struct-decoding compatibility.+`DirectJSONOutput` preserves protocols that return their own JSON objects or arrays without the kernel envelope. Use `SuccessDirectJSON` for these payloads. Endpoints that also support empty notification responses explicitly declare `NoContent` and return `SuccessNoContent`; HTTP validation requires status 204 and an empty body. Authentication and read-only failures retain the kernel error envelope. Generated declarations record the direct output mode and optional empty-response support.+## Multipart requests+`WebSocketOutput` uses `WebSocketOptions` to declare incoming and outgoing message types and the plugin admission failure status. `UpgradeWebSocket` hands the response writer to the connection lifecycle from `contractHandler`; `RejectWebSocket` serializes the declared rejection payload. Generated route metadata includes both message schemas, and `ValidateWebSocketMessage` validates frames separately from handshake responses and middleware envelopes. Handshake validation checks HTTP status and body; network regression tests verify upgrade headers, Origin rejection, message exchange, and cancellation.+Optional `*string` form fields preserve omission separately from an explicit empty string; use `nonnullable` because multipart text fields cannot contain JSON null. Import handlers use this distinction for defaults and delayed field validation. Upload progress starts before multipart parsing, and parse failures clear it before responding; Gin's cached form is reused for typed binding.`BinaryOutput` declares raw file responses with `BinaryContent` and `SuccessBinary`. The adapter preserves bytes and media type, while `ErrorStatus` declares the distinct HTTP status for JSON failures (`getFile` uses 202). The schema records binary success and typed JSON errors; `ValidateHTTPResponse` checks the status and media type before validating an error envelope. Generated route responses expose `Blob`, while the existing fetch helpers expose `JSONValue` because they parse file contents as text or JSON according to their existing behavior. JSON file contents can contain arbitrary JSON; this does not relax the structured error contract.diff --git a/docs/API-CONTRACTS.zh-CN.md b/docs/API-CONTRACTS.zh-CN.mdindex 33b9e437c6..a74526e9b9 100644--- a/docs/API-CONTRACTS.zh-CN.md+++ b/docs/API-CONTRACTS.zh-CN.md@@ -24,6 +24,8 @@## 兼容要求+插件信息查询保留路径参数、查询参数和 JSON 请求体中名称的优先级,包括空白及业务错误码 1 至 4。命中 URL 参数时不解析请求体,列表查询忽略请求体。插件列表与 RPC 方法列表保留数组及数组元素的空值语义。HTTP JSON-RPC 使用独立契约描述单次与批量请求、成功与错误回复,以及纯通知请求的 HTTP 204 响应。插件准入先于请求体读取,批量错误保留原有顺序,任意 JSON 仅用于 RPC 参数、返回值和错误详情。RPC WebSocket 路由声明 HTTP 101 升级、HTTP 404 插件准入错误、HTTP 400 文本拒绝,以及独立的入站调用和出站回复或通知。Origin 授权与连接清理保留在既有升级生命周期中。插件 HTTP 服务仍需单独迁移。+搜索契约保留分页默认值与小数截断、路径校验与去重、历史子类型筛选的忽略规则,以及空值与空数组的区别。引用搜索区分仅回传请求标识和完整块结果,保留笔记本准入先于延迟参数校验的顺序。SQL 搜索权限、发布过滤、加密笔记本租约、取消请求的响应和只读嵌入块更新的空操作保持原有顺序。桌面端与移动端调用使用生成的请求类型。历史契约保留路径去空白、可选高亮默认值、历史类型的小数截断,以及空值与空数组的区别。版本对比先检查两个引用对象,再检查对象字段,并按排序后的笔记本 ID 获取租约。内容读取及文档、资源和数据库回滚保留历史路径租约检查,笔记本回滚沿用模型层的恢复行为。@@ -66,6 +68,10 @@ SQL 查询契约保留成功信封顶层的 `limit` 和 `truncated`。`SuccessSQ存储契约仅在存储值中允许任意 JSON,键、最近文档、搜索条件、行内样式和属性视图调色板均使用结构化类型。最近文档写入接口保留只读角色在解析请求体前直接返回成功的行为。`contractHandler` 可选的类型化 `beforeDecode` 回调用于保留这一执行顺序,允许在解码前返回响应;路由检查仍要求显式绑定端点。行内样式版本 1 的更新保留已有内置配置,版本 2 和调色板请求保留结构体解码的兼容行为。+`DirectJSONOutput` 保留直接返回 JSON 对象或数组的独立协议,不添加内核信封,此类载荷使用 `SuccessDirectJSON` 返回。支持通知空响应的端点显式声明 `NoContent` 并返回 `SuccessNoContent`;HTTP 校验要求状态码为 204 且响应体为空。鉴权和只读错误仍保留内核错误信封。生成声明记录直接输出模式及可选的空响应支持。++`WebSocketOutput` 通过 `WebSocketOptions` 声明入站和出站消息类型及插件准入失败状态。`UpgradeWebSocket` 在 `contractHandler` 的响应阶段将写入器交给连接生命周期;`RejectWebSocket` 序列化声明的拒绝载荷。生成的路由元数据包含双向消息模式,`ValidateWebSocketMessage` 单独校验连接内消息,避免与握手响应或中间件信封混淆。握手校验检查 HTTP 状态和响应体,网络回归验证升级头、Origin 拒绝、消息交互和取消后的连接关闭。+## 文件上传请求可选的 `*string` 表单字段区分未传字段与显式空字符串,并使用 `nonnullable`,因为表单文本不能包含 JSON 空值。导入处理器据此保留默认值和延后校验的行为。上传进度在解析表单前启动,解析失败时先清理进度再返回;类型绑定复用 Gin 缓存的表单。diff --git a/kernel/api/contract.go b/kernel/api/contract.goindex 108e9300cd..29baa52a1f 100644--- a/kernel/api/contract.go+++ b/kernel/api/contract.go@@ -43,6 +43,14 @@ func contractHandler[Request, Data any](endpoint apicontract.Endpoint[Request, Dreturn func(c *gin.Context) {writeResponse := func(response apicontract.Response[Data]) {status := endpoint.Status(response)+ if upgrade := response.Upgrade(); upgrade != nil {+ upgrade(c.Writer, c.Request)+ return+ }+ if status == 204 {+ c.Status(status)+ return+ }if content := response.Binary(); content != nil {c.Data(status, content.ContentType, content.Bytes)returndiff --git a/kernel/api/contract_plugin_test.go b/kernel/api/contract_plugin_test.gonew file mode 100644index 0000000000..968fd33ca7--- /dev/null+++ b/kernel/api/contract_plugin_test.go@@ -0,0 +1,164 @@+package api++import (+ "encoding/json"+ "io"+ "net/http"+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/plugin"+)++func TestAPIContractPluginWebSocketAdapter(t *testing.T) {+ engine := gin.New()+ engine.GET("/ws/plugin/rpc", pluginJsonRpcWebSocket)+ engine.GET("/ws/plugin/rpc/:name", pluginJsonRpcWebSocketByName)+ bundle, err := apicontract.BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ for _, path := range []string{"/ws/plugin/rpc", "/ws/plugin/rpc/missing"} {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("GET", path, strings.NewReader("invalid JSON")))+ if recorder.Code != 404 {+ t.Fatalf("unexpected handshake status: %d", recorder.Code)+ }+ if err := bundle.ValidateHTTPResponse("GET", "/ws/plugin/rpc", recorder.Code, recorder.Header().Get("Content-Type"), recorder.Body.Bytes()); err != nil {+ t.Fatal(err)+ }+ }+ called := false+ handler := contractHandler(apicontract.PluginRPCWebSocket, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.PluginRPCFailure] {+ return apicontract.UpgradeWebSocket[apicontract.PluginRPCFailure](func(writer http.ResponseWriter, request *http.Request) {+ called = true+ writer.WriteHeader(http.StatusSwitchingProtocols)+ })+ })+ engine.GET("/upgrade", handler)+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("GET", "/upgrade", nil))+ if !called || recorder.Code != 101 || recorder.Body.Len() != 0 {+ t.Fatalf("adapter did not hand off connection: %v %d %s", called, recorder.Code, recorder.Body.String())+ }+}++func TestAPIContractPluginNameCompatibility(t *testing.T) {+ engine := gin.New()+ engine.POST("/api/plugin/getLoadedPlugin", getLoadedPlugin)+ engine.GET("/api/plugin/rpc", getLoadedPluginRPC)+ engine.GET("/api/plugin/rpc/:name", getLoadedPluginRPCByName)+ for _, entry := range []struct {+ method, route, url, body string+ code int+ message string+ }{+ {"POST", "/api/plugin/getLoadedPlugin", "/api/plugin/getLoadedPlugin", `{}`, 1, "Request body prop [name] does not exist"},+ {"POST", "/api/plugin/getLoadedPlugin", "/api/plugin/getLoadedPlugin", `{"name":null}`, 1, "Request body prop [name] does not exist"},+ {"POST", "/api/plugin/getLoadedPlugin", "/api/plugin/getLoadedPlugin", `{"name":12}`, 2, "Request body prop [name] is not a string"},+ {"POST", "/api/plugin/getLoadedPlugin", "/api/plugin/getLoadedPlugin", `{"name":""}`, 3, "Plugin name is required"},+ {"POST", "/api/plugin/getLoadedPlugin", "/api/plugin/getLoadedPlugin", `{"name":" missing "}`, 4, "Plugin [ missing ] not loaded"},+ {"POST", "/api/plugin/getLoadedPlugin", "/api/plugin/getLoadedPlugin?name=query", `invalid JSON`, 4, "Plugin [query] not loaded"},+ {"GET", "/api/plugin/rpc", "/api/plugin/rpc?name=query", `invalid JSON`, 4, "Plugin [query] not loaded"},+ {"GET", "/api/plugin/rpc", "/api/plugin/rpc?name=", `{"name":"body"}`, 4, "Plugin [body] not loaded"},+ {"GET", "/api/plugin/rpc/:name", "/api/plugin/rpc/path?name=query", `invalid JSON`, 4, "Plugin [path] not loaded"},+ {"GET", "/api/plugin/rpc", "/api/plugin/rpc", ``, -1, "Parses request [/api/plugin/rpc] failed:"},+ } {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest(entry.method, entry.url, strings.NewReader(entry.body)))+ requireAPIContract(t, entry.method, entry.route, 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 || response.Code != entry.code || !strings.HasPrefix(response.Msg, entry.message) || string(response.Data) != "null" {+ t.Fatalf("plugin parameter behavior changed: %s: %s, %v", entry.url, recorder.Body.String(), err)+ }+ }+}++func TestAPIContractLoadedPluginList(t *testing.T) {+ engine := gin.New()+ engine.GET("/api/plugin", listLoadedPluginsGET)+ engine.POST("/api/plugin/listLoadedPlugins", listLoadedPlugins)+ expected, err := json.Marshal(plugin.GetManager().GetLoadedPluginsInfo())+ if err != nil {+ t.Fatal(err)+ }+ for _, entry := range []struct{ method, path string }{{"GET", "/api/plugin"}, {"POST", "/api/plugin/listLoadedPlugins"}} {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest(entry.method, entry.path, strings.NewReader("ignored malformed body")))+ requireAPIContract(t, entry.method, entry.path, recorder)+ var response struct {+ Code int `json:"code"`+ Data json.RawMessage `json:"data"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != 0 || string(response.Data) != string(expected) {+ t.Fatalf("plugin list changed: %s, %v", recorder.Body.String(), err)+ }+ }+}++func TestAPIContractLoadedPluginConversion(t *testing.T) {+ for _, value := range []*plugin.PluginInfo{nil, {}, {Name: "plugin", State: "Running", StateCode: 2, Methods: []*plugin.RpcMethodInfo{nil, {}, {Name: "rpc", Descriptions: []string{"first", "second"}}}}, {Methods: []*plugin.RpcMethodInfo{}}} {+ expected, err := json.Marshal(value)+ if err != nil {+ t.Fatal(err)+ }+ actual, err := json.Marshal(loadedPluginContract(value))+ if err != nil || string(actual) != string(expected) {+ t.Fatalf("plugin info changed: %s != %s, %v", actual, expected, err)+ }+ }+}++type pluginRPCUnreadBody struct{ reads int }++func (r *pluginRPCUnreadBody) Read([]byte) (int, error) { r.reads++; return 0, io.ErrUnexpectedEOF }+func (r *pluginRPCUnreadBody) Close() error { return nil }++func TestAPIContractPluginRPCAdmission(t *testing.T) {+ engine := gin.New()+ engine.POST("/api/plugin/rpc", pluginJsonRpcHttp)+ engine.POST("/api/plugin/rpc/:name", pluginJsonRpcHttpByName)+ for _, entry := range []struct{ path, url string }{{"/api/plugin/rpc", "/api/plugin/rpc?name=missing"}, {"/api/plugin/rpc/:name", "/api/plugin/rpc/missing?name=other"}} {+ body := &pluginRPCUnreadBody{}+ request := httptest.NewRequest("POST", entry.url, nil)+ request.Body = body+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, request)+ requireAPIContract(t, "POST", entry.path, recorder)+ if body.reads != 0 || recorder.Body.String() != `{"jsonrpc":"2.0","error":{"code":-32001,"message":"Plugin not loaded"},"id":null}` {+ t.Fatalf("plugin admission order changed: %d reads, %s", body.reads, recorder.Body)+ }+ }+}++func TestAPIContractPluginRPCDirectAdapter(t *testing.T) {+ endpoint := apicontract.PluginRPCHTTP+ for _, empty := range []bool{false, true} {+ handler := contractHandler(endpoint, func(c *gin.Context, request apicontract.PluginRPCBatchRequest) apicontract.Response[apicontract.PluginRPCResponse] {+ if empty {+ return apicontract.SuccessNoContent[apicontract.PluginRPCResponse]()+ }+ failure := apicontract.RPCErrorResponse(-32601, "Method not found", "")+ return apicontract.SuccessDirectJSON(apicontract.RPCSingleResponse(apicontract.RPCFailureReply(failure)))+ })+ engine := gin.New()+ engine.POST("/api/plugin/rpc", handler)+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/plugin/rpc", strings.NewReader(`{"jsonrpc":"2.0","method":"notification"}`)))+ requireAPIContract(t, "POST", "/api/plugin/rpc", recorder)+ if empty {+ if recorder.Code != 204 || recorder.Body.Len() != 0 {+ t.Fatalf("notification was serialized: %d %s", recorder.Code, recorder.Body)+ }+ } else if recorder.Code != 200 || recorder.Body.String() != `{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found"},"id":null}` {+ t.Fatalf("RPC response was wrapped: %d %s", recorder.Code, recorder.Body)+ }+ }+}diff --git a/kernel/api/plugin.go b/kernel/api/plugin.goindex 70b05a34ab..da6f388c08 100644--- a/kernel/api/plugin.go+++ b/kernel/api/plugin.go@@ -18,58 +18,69 @@ package apiimport ("fmt"- "net/http"-- "github.com/88250/gulu""github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract""github.com/siyuan-note/siyuan/kernel/plugin""github.com/siyuan-note/siyuan/kernel/util")-func listLoadedPlugins(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)+var listLoadedPlugins = contractHandler(apicontract.ListLoadedPlugins, loadedPluginsResponse)+var listLoadedPluginsGET = contractHandler(apicontract.ListLoadedPluginsGET, loadedPluginsResponse)+var getLoadedPlugin = contractHandler(apicontract.GetLoadedPlugin, loadedPluginResponse, loadedPluginURLResponse)+var getLoadedPluginRPC = contractHandler(apicontract.GetLoadedPluginRPC, loadedPluginResponse, loadedPluginURLResponse)+var getLoadedPluginRPCByName = contractHandler(apicontract.GetLoadedPluginRPCByName, loadedPluginResponse, loadedPluginURLResponse)- ret.Data = plugin.GetManager().GetLoadedPluginsInfo()+func loadedPluginsResponse(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[[]*apicontract.LoadedPlugin] {+ values := plugin.GetManager().GetLoadedPluginsInfo()+ var result []*apicontract.LoadedPlugin+ if values != nil {+ result = make([]*apicontract.LoadedPlugin, len(values))+ for i, value := range values {+ result[i] = loadedPluginContract(value)+ }+ }+ return apicontract.Success(result)}-func getPluginName(c *gin.Context, ret *gulu.Result) (name string) {- name = util.GetRequestStringParam(c, "name", ret)- if name == "" {- if ret.Code == 0 {- ret.Code = 3- ret.Msg = "Plugin name is required"+func loadedPluginContract(value *plugin.PluginInfo) *apicontract.LoadedPlugin {+ if value == nil {+ return nil+ }+ var methods []*apicontract.PluginRPCMethod+ if value.Methods != nil {+ methods = make([]*apicontract.PluginRPCMethod, len(value.Methods))+ for i, method := range value.Methods {+ methods[i] = (*apicontract.PluginRPCMethod)(method)}}- return+ return &apicontract.LoadedPlugin{Name: value.Name, State: value.State, StateCode: value.StateCode, Methods: methods}}-func getLoadedPlugin(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- pluginName := getPluginName(c, ret)- if pluginName == "" {- return+// 路径和查询参数优先于请求体,命中时不解析请求体。+func loadedPluginURLResponse(c *gin.Context) *apicontract.Response[*apicontract.LoadedPlugin] {+ if name := util.GetRequestUrlStringParam(c, "name"); name != "" {+ response := loadedPluginResponse(c, apicontract.LoadedPluginRequest{Name: name})+ return &response}+ return nil+}- pluginInfo, found := plugin.GetManager().GetLoadedPlugin(pluginName)+func loadedPluginResponse(c *gin.Context, request apicontract.LoadedPluginRequest) apicontract.Response[*apicontract.LoadedPlugin] {+ if request.Name == "" {+ return apicontract.Failure[*apicontract.LoadedPlugin](3, "Plugin name is required")+ }+ value, found := plugin.GetManager().GetLoadedPlugin(request.Name)if !found {- ret.Code = 4- ret.Msg = fmt.Sprintf("Plugin [%s] not loaded", pluginName)- return+ return apicontract.Failure[*apicontract.LoadedPlugin](4, fmt.Sprintf("Plugin [%s] not loaded", request.Name))}-- ret.Data = pluginInfo+ return apicontract.Success(loadedPluginContract(value))}-func pluginJsonRpcHttp(c *gin.Context) {- plugin.HandleRpcHttp(c)-}+var pluginJsonRpcHttp = contractHandler(apicontract.PluginRPCHTTP, plugin.DispatchRPCContract, plugin.PrepareRPCContract)+var pluginJsonRpcHttpByName = contractHandler(apicontract.PluginRPCHTTPByName, plugin.DispatchRPCContract, plugin.PrepareRPCContract)-func pluginJsonRpcWebSocket(c *gin.Context) {- plugin.HandleRpcWebSocket(c)-}+var pluginJsonRpcWebSocket = contractHandler(apicontract.PluginRPCWebSocket, plugin.OpenRPCWebSocket)+var pluginJsonRpcWebSocketByName = contractHandler(apicontract.PluginRPCWebSocketByName, plugin.OpenRPCWebSocket)// func pluginPublicWebServer(c *gin.Context) {// plugin.HandleHttpRequest(c, plugin.AccessScopePublic)diff --git a/kernel/api/router.go b/kernel/api/router.goindex b7a230158a..8aed3e5cb8 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -670,18 +670,18 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/petal/setPetalEnabled", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setPetalEnabled)ginServer.Handle("POST", "/api/petal/setPetalPublishEnabled", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setPetalPublishEnabled)- ginServer.Handle("GET", "/api/plugin/rpc", model.CheckAuth, getLoadedPlugin)- ginServer.Handle("GET", "/api/plugin/rpc/:name", model.CheckAuth, getLoadedPlugin)- ginServer.Handle("GET", "/api/plugin", model.CheckAuth, listLoadedPlugins)+ ginServer.Handle("GET", "/api/plugin/rpc", model.CheckAuth, getLoadedPluginRPC)+ ginServer.Handle("GET", "/api/plugin/rpc/:name", model.CheckAuth, getLoadedPluginRPCByName)+ ginServer.Handle("GET", "/api/plugin", model.CheckAuth, listLoadedPluginsGET)ginServer.Handle("POST", "/api/plugin/getLoadedPlugin", model.CheckAuth, getLoadedPlugin)ginServer.Handle("POST", "/api/plugin/listLoadedPlugins", model.CheckAuth, listLoadedPlugins)ginServer.Handle("POST", "/api/plugin/rpc", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginJsonRpcHttp)- ginServer.Handle("POST", "/api/plugin/rpc/:name", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginJsonRpcHttp)+ ginServer.Handle("POST", "/api/plugin/rpc/:name", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginJsonRpcHttpByName)ginServer.Handle("GET", "/ws/plugin/rpc", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginJsonRpcWebSocket)- ginServer.Handle("GET", "/ws/plugin/rpc/:name", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginJsonRpcWebSocket)+ ginServer.Handle("GET", "/ws/plugin/rpc/:name", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginJsonRpcWebSocketByName)// ginServer.Any("/plugin/public/:name/*path", pluginPublicWebServer)ginServer.Any("/plugin/private/:name/*path", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, pluginPrivateWebServer)diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.goindex 2f24e854ee..c67463f36c 100644--- a/kernel/apicontract/contracts.go+++ b/kernel/apicontract/contracts.go@@ -12,6 +12,10 @@ type OutputMode stringconst BinaryOutput OutputMode = "binary"+const DirectJSONOutput OutputMode = "directJSON"++const WebSocketOutput OutputMode = "websocket"+const (JSONBody BodyMode = "json"MultipartBody BodyMode = "multipart"@@ -34,6 +38,8 @@ type Definition struct {DataOnError boolOutput OutputModeErrorStatus int+ NoContent bool+ WebSocket *WebSocketDefinition}type Endpoint[Request, Data any] struct {@@ -49,6 +55,8 @@ type ResponseOptions struct {DataOnError boolOutput OutputModeErrorStatus int+ NoContent bool+ WebSocket *WebSocketDefinition}var definitions []Definition@@ -102,7 +110,7 @@ func define[Request, Data any](name, path string, body BodyMode, response Respond := Definition{Name: name, Path: path, Methods: methods, Body: body,Request: reflect.TypeFor[Request](), Data: reflect.TypeFor[Data](),ErrorCodes: append([]int{-1}, response.AdditionalCodes...), ErrorText: response.Text, DataNonNullable: response.NonNullable, DataOnError: response.DataOnError,- Output: response.Output, ErrorStatus: response.ErrorStatus}+ Output: response.Output, ErrorStatus: response.ErrorStatus, NoContent: response.NoContent, WebSocket: response.WebSocket}definitions = append(definitions, d)return Endpoint[Request, Data]{definition: d}}@@ -545,3 +553,21 @@ var FindReplace = define[FindReplaceRequest, Null]("findReplace", "/api/search/fvar SemanticSearchBlock = define[SearchBlockRequest, SearchBlocksData]("semanticSearchBlock", "/api/search/semanticSearchBlock", JSONBody, ResponseOptions{}, "POST")var FullTextSearchBlock = define[FullTextSearchBlockRequest, *FullTextSearchBlockData]("fullTextSearchBlock", "/api/search/fullTextSearchBlock", JSONBody, ResponseOptions{}, "POST")var SearchRefBlock = define[SearchRefBlockRequest, SearchRefData]("searchRefBlock", "/api/search/searchRefBlock", JSONBody, ResponseOptions{DataOnError: true}, "POST")++var ListLoadedPlugins = define[EmptyRequest, []*LoadedPlugin]("listLoadedPlugins", "/api/plugin/listLoadedPlugins", NoBody, ResponseOptions{}, "POST")++var ListLoadedPluginsGET = define[EmptyRequest, []*LoadedPlugin]("listLoadedPluginsGET", "/api/plugin", NoBody, ResponseOptions{}, "GET")++var GetLoadedPlugin = define[LoadedPluginRequest, *LoadedPlugin]("getLoadedPlugin", "/api/plugin/getLoadedPlugin", JSONBody, ResponseOptions{AdditionalCodes: []int{1, 2, 3, 4}}, "POST")++var GetLoadedPluginRPC = define[LoadedPluginRequest, *LoadedPlugin]("getLoadedPluginRPC", "/api/plugin/rpc", JSONBody, ResponseOptions{AdditionalCodes: []int{1, 2, 3, 4}}, "GET")++var GetLoadedPluginRPCByName = define[LoadedPluginRequest, *LoadedPlugin]("getLoadedPluginRPCByName", "/api/plugin/rpc/:name", JSONBody, ResponseOptions{AdditionalCodes: []int{1, 2, 3, 4}}, "GET")++var PluginRPCHTTP = define[PluginRPCBatchRequest, PluginRPCResponse]("pluginJsonRpcHttp", "/api/plugin/rpc", JSONBody, ResponseOptions{Output: DirectJSONOutput, NoContent: true}, "POST")++var PluginRPCHTTPByName = define[PluginRPCBatchRequest, PluginRPCResponse]("pluginJsonRpcHttpByName", "/api/plugin/rpc/:name", JSONBody, ResponseOptions{Output: DirectJSONOutput, NoContent: true}, "POST")++var PluginRPCWebSocket = define[EmptyRequest, PluginRPCFailure]("pluginJsonRpcWebSocket", "/ws/plugin/rpc", NoBody, WebSocketOptions[PluginRPCBatchRequest, PluginRPCMessage](404), "GET")++var PluginRPCWebSocketByName = define[EmptyRequest, PluginRPCFailure]("pluginJsonRpcWebSocketByName", "/ws/plugin/rpc/:name", NoBody, WebSocketOptions[PluginRPCBatchRequest, PluginRPCMessage](404), "GET")diff --git a/kernel/apicontract/direct_json_test.go b/kernel/apicontract/direct_json_test.gonew file mode 100644index 0000000000..3d848a7160--- /dev/null+++ b/kernel/apicontract/direct_json_test.go@@ -0,0 +1,84 @@+package apicontract++import (+ "encoding/json"+ "reflect"+ "strings"+ "testing"+)++type directJSONTestResult struct {+ JSONRPC string `json:"jsonrpc" api:"const=\"2.0\""`+ Result string `json:"result"`+ ID int `json:"id"`+}++func TestDirectJSONHTTPResponses(t *testing.T) {+ previous := definitions+ t.Cleanup(func() { definitions = previous })+ endpoint := define[EmptyRequest, directJSONTestResult]("directJSONTest", "/test/direct-json", NoBody, ResponseOptions{Output: DirectJSONOutput, NoContent: true}, "POST")+ bundle, err := BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ result := directJSONTestResult{JSONRPC: "2.0", Result: "value", ID: 1}+ response := SuccessDirectJSON(result)+ payload, err := json.Marshal(response)+ if err != nil || string(payload) != `{"jsonrpc":"2.0","result":"value","id":1}` || endpoint.Status(response) != 200 {+ t.Fatalf("direct JSON was wrapped: %s, %v", payload, err)+ }+ if err := bundle.ValidateHTTPResponse("POST", "/test/direct-json", 200, "application/json", payload); err != nil {+ t.Fatal(err)+ }+ for _, entry := range []struct {+ status int+ media, body string+ valid bool+ }{+ {204, "", "", true},+ {204, "application/json", "null", false},+ {200, "application/json", `{"jsonrpc":"2.0","result":"value","id":1}`, true},+ {200, "application/json", `{"jsonrpc":"1.0","result":"value","id":1}`, false},+ {200, "application/json", `{"code":0,"msg":"","data":{"jsonrpc":"2.0","result":"value","id":1}}`, false},+ {200, "application/json", `{"code":-1,"msg":"denied","data":null}`, true},+ {200, "application/json", `{"code":-1,"msg":"readonly","data":{"closeTimeout":5000}}`, true},+ {200, "text/plain", `{"jsonrpc":"2.0","result":"value","id":1}`, false},+ {201, "application/json", `{"jsonrpc":"2.0","result":"value","id":1}`, false},+ } {+ err := bundle.ValidateHTTPResponse("POST", "/test/direct-json", entry.status, entry.media, []byte(entry.body))+ if (err == nil) != entry.valid {+ t.Fatalf("unexpected HTTP validation: %+v, %v", entry, err)+ }+ }+ if endpoint.Status(SuccessNoContent[directJSONTestResult]()) != 204 {+ t.Fatal("notification must return HTTP 204")+ }+ if _, err := json.Marshal(SuccessNoContent[directJSONTestResult]()); err == nil {+ t.Fatal("empty response was serialized")+ }+ declarations := string(bundle.TypeScript(nil))+ if !strings.Contains(declarations, `output: "directJSON"`) || !strings.Contains(declarations, "noContent: true") {+ t.Fatal("direct JSON protocol metadata missing")+ }+}++func TestDirectJSONOutputGuards(t *testing.T) {+ ordinary := Endpoint[EmptyRequest, directJSONTestResult]{definition: Definition{Data: reflect.TypeFor[directJSONTestResult]()}}+ direct := ordinary+ direct.definition.Output = DirectJSONOutput+ for _, call := range []func(){+ func() { ordinary.Status(SuccessDirectJSON(directJSONTestResult{})) },+ func() { ordinary.Status(SuccessNoContent[directJSONTestResult]()) },+ func() { direct.Status(SuccessNoContent[directJSONTestResult]()) },+ func() { direct.Status(Success(directJSONTestResult{})) },+ } {+ func() {+ defer func() {+ if recover() == nil {+ t.Error("undeclared protocol output was accepted")+ }+ }()+ call()+ }()+ }+}diff --git a/kernel/apicontract/json_value.go b/kernel/apicontract/json_value.goindex cf83d487e7..2a22bf98db 100644--- a/kernel/apicontract/json_value.go+++ b/kernel/apicontract/json_value.go@@ -1,10 +1,21 @@package apicontract-import "encoding/json"+import (+ "encoding/json"+ "fmt"+)// JSONValue 仅用于协议明确允许任意 JSON 的透传字段,零值表示 null。type JSONValue struct{ raw json.RawMessage }+// EncodedJSONValue 保留业务层已编码的任意 JSON 值,包括整型结果的完整数字精度。+func EncodedJSONValue(data []byte) (JSONValue, error) {+ if !json.Valid(data) {+ return JSONValue{}, fmt.Errorf("invalid encoded JSON value")+ }+ return JSONValue{raw: append(json.RawMessage(nil), data...)}, nil+}+func (v JSONValue) StringValue() (value string, ok bool) {if len(v.raw) == 0 || v.raw[0] != '"' {return "", falsediff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.jsonindex 849c2ece4b..baca6d62cd 100644--- a/kernel/apicontract/legacy_routes.json+++ b/kernel/apicontract/legacy_routes.json@@ -5,9 +5,6 @@{"method":"ANY","path":"/plugin/private/:name/*path","handler":"pluginPrivateWebServer"},{"method":"GET","path":"/api/ai/mcp/oauth/callback/:flowID","handler":"mcpOAuthCallback"},{"method":"GET","path":"/api/icon/getDynamicIcon","handler":"getDynamicIcon"},- {"method":"GET","path":"/api/plugin","handler":"listLoadedPlugins"},- {"method":"GET","path":"/api/plugin/rpc","handler":"getLoadedPlugin"},- {"method":"GET","path":"/api/plugin/rpc/:name","handler":"getLoadedPlugin"},{"method":"GET","path":"/api/system/bootProgressSSE","handler":"bootProgressSSE"},{"method":"GET","path":"/api/system/getBootAppearance","handler":"getBootAppearance"},{"method":"GET","path":"/api/system/getCaptcha","handler":"model.GetCaptcha"},@@ -16,8 +13,6 @@{"method":"GET","path":"/es/network/proxy","handler":"esProxy"},{"method":"GET","path":"/ws/broadcast","handler":"broadcast"},{"method":"GET","path":"/ws/network/proxy","handler":"wsProxy"},- {"method":"GET","path":"/ws/plugin/rpc","handler":"pluginJsonRpcWebSocket"},- {"method":"GET","path":"/ws/plugin/rpc/:name","handler":"pluginJsonRpcWebSocket"},{"method":"POST","path":"/api/ai/agent/browserCapabilityResult","handler":"agentChatBrowserCapabilityResult"},{"method":"POST","path":"/api/ai/agent/chat","handler":"agentChat"},{"method":"POST","path":"/api/ai/agent/confirm","handler":"agentChatConfirm"},@@ -223,10 +218,6 @@{"method":"POST","path":"/api/filetree/setSort","handler":"setSort"},{"method":"POST","path":"/api/filetree/upsertIndexes","handler":"upsertIndexes"},{"method":"POST","path":"/api/network/forwardProxy","handler":"forwardProxy"},- {"method":"POST","path":"/api/plugin/getLoadedPlugin","handler":"getLoadedPlugin"},- {"method":"POST","path":"/api/plugin/listLoadedPlugins","handler":"listLoadedPlugins"},- {"method":"POST","path":"/api/plugin/rpc","handler":"pluginJsonRpcHttp"},- {"method":"POST","path":"/api/plugin/rpc/:name","handler":"pluginJsonRpcHttp"},{"method":"POST","path":"/api/repo/checkoutRepo","handler":"checkoutRepo"},{"method":"POST","path":"/api/repo/diffRepoSnapshots","handler":"diffRepoSnapshots"},{"method":"POST","path":"/api/repo/downloadCloudSnapshot","handler":"downloadCloudSnapshot"},diff --git a/kernel/apicontract/plugin.go b/kernel/apicontract/plugin.gonew file mode 100644index 0000000000..1f91f64db6--- /dev/null+++ b/kernel/apicontract/plugin.go@@ -0,0 +1,57 @@+package apicontract++import (+ "bytes"+ "encoding/json"+ "errors"+ "io"+)++type LoadedPluginRequest struct {+ Name string `json:"name"`+}++type LoadedPlugin struct {+ Name string `json:"name"`+ State string `json:"state"`+ StateCode int `json:"stateCode"`+ Methods []*PluginRPCMethod `json:"methods"`+}++type PluginRPCMethod struct {+ Name string `json:"name"`+ Descriptions []string `json:"descriptions"`+}++type pluginNameError struct {+ code int+ message string+}++func (e *pluginNameError) Error() string { return e.message }++func init() {+ for _, endpoint := range []*Endpoint[LoadedPluginRequest, *LoadedPlugin]{&GetLoadedPlugin, &GetLoadedPluginRPC, &GetLoadedPluginRPCByName} {+ endpoint.decodeRequest = func(reader io.Reader) (request LoadedPluginRequest, err error) {+ fields, err := blockRequestFields(reader, endpoint.Definition().Path)+ if err != nil {+ return request, err+ }+ raw := fields["name"]+ if len(raw) == 0 || bytes.Equal(bytes.TrimSpace(raw), []byte("null")) {+ return request, &pluginNameError{1, "Request body prop [name] does not exist"}+ }+ if json.Unmarshal(raw, &request.Name) != nil {+ return request, &pluginNameError{2, "Request body prop [name] is not a string"}+ }+ return request, nil+ }+ endpoint.decodeFailure = func(err error) Response[*LoadedPlugin] {+ var nameError *pluginNameError+ if errors.As(err, &nameError) {+ return Failure[*LoadedPlugin](nameError.code, nameError.message)+ }+ return Failure[*LoadedPlugin](-1, err.Error())+ }+ }+}diff --git a/kernel/apicontract/plugin_rpc.go b/kernel/apicontract/plugin_rpc.gonew file mode 100644index 0000000000..75d57c593e--- /dev/null+++ b/kernel/apicontract/plugin_rpc.go@@ -0,0 +1,237 @@+package apicontract++import (+ "bytes"+ "encoding/json"+ "fmt"+ "io"+ "strings"+)++type PluginRPCID struct{ value JSONValue }++func (id PluginRPCID) MarshalJSON() ([]byte, error) { return json.Marshal(id.value) }+func (id *PluginRPCID) UnmarshalJSON(data []byte) error {+ data = bytes.TrimSpace(data)+ if !json.Valid(data) || len(data) == 0 {+ return fmt.Errorf("invalid RPC ID")+ }+ if data[0] != '"' && data[0] != '-' && (data[0] < '0' || data[0] > '9') && string(data) != "null" {+ return fmt.Errorf("invalid id field: must be string, number, null or omitted")+ }+ return json.Unmarshal(data, &id.value)+}++type PluginRPCParams struct{ value JSONValue }++type PluginRPCRequestFields struct {+ JSONRPC string `json:"jsonrpc" api:"const=\"2.0\""`+ Method string `json:"method"`+ Params *PluginRPCParams `json:"params" api:"optional"`+ ID *PluginRPCID `json:"id" api:"optional"`+}++type PluginRPCSuccess struct {+ JSONRPC string `json:"jsonrpc" api:"const=\"2.0\""`+ Result JSONValue `json:"result"`+ ID PluginRPCID `json:"id"`+}++type PluginRPCNotification struct {+ JSONRPC string `json:"jsonrpc" api:"const=\"2.0\""`+ Method string `json:"method"`+ Params *JSONValue `json:"params,omitempty"`+}++type PluginRPCError struct {+ Code int `json:"code"`+ Message string `json:"message"`+ Data *JSONValue `json:"data,omitempty"`+}++// PluginRPCMessage 是出站回复或主动通知,两者不共享可选的协议字段。+type PluginRPCMessage struct {+ response *PluginRPCResponse+ notification *PluginRPCNotification+}++func RPCResponseMessage(response PluginRPCResponse) PluginRPCMessage {+ return PluginRPCMessage{response: &response}+}++func RPCNotificationMessage(notification PluginRPCNotification) PluginRPCMessage {+ return PluginRPCMessage{notification: ¬ification}+}++func (m PluginRPCMessage) MarshalJSON() ([]byte, error) {+ if m.response != nil {+ return json.Marshal(m.response)+ }+ if m.notification != nil {+ return json.Marshal(m.notification)+ }+ return nil, fmt.Errorf("RPC message requires a response or notification")+}++type PluginRPCFailure struct {+ JSONRPC string `json:"jsonrpc" api:"const=\"2.0\""`+ Error *PluginRPCError `json:"error"`+ ID PluginRPCID `json:"id"`+}++type PluginRPCReply struct {+ success *PluginRPCSuccess+ failure *PluginRPCFailure+}++func RPCSuccessReply(result PluginRPCSuccess) PluginRPCReply { return PluginRPCReply{success: &result} }+func RPCFailureReply(result PluginRPCFailure) PluginRPCReply { return PluginRPCReply{failure: &result} }+func (r PluginRPCReply) MarshalJSON() ([]byte, error) {+ if r.success != nil {+ return json.Marshal(r.success)+ }+ if r.failure != nil {+ return json.Marshal(r.failure)+ }+ return nil, fmt.Errorf("RPC reply requires success or failure")+}++type PluginRPCResponse struct {+ single *PluginRPCReply+ batch []PluginRPCReply+}++func RPCSingleResponse(reply PluginRPCReply) PluginRPCResponse {+ return PluginRPCResponse{single: &reply}+}+func RPCBatchResponse(replies []PluginRPCReply) PluginRPCResponse {+ return PluginRPCResponse{batch: replies}+}+func (r PluginRPCResponse) MarshalJSON() ([]byte, error) {+ if r.single != nil {+ return json.Marshal(r.single)+ }+ if len(r.batch) == 0 {+ return nil, fmt.Errorf("RPC batch response must not be empty")+ }+ return json.Marshal(r.batch)+}++type PluginRPCCall struct {+ Method string+ Params JSONValue+ ParamsPresent bool+ ParamsNull bool+ ID PluginRPCID+ IDPresent bool+}++type PluginRPCParsedCall struct {+ Request *PluginRPCCall+ Error *PluginRPCFailure+}++type PluginRPCBatchRequest struct {+ Batch bool `json:"-"`+ Calls []PluginRPCParsedCall `json:"-"`+ Error *PluginRPCFailure `json:"-"`+}++func RPCErrorResponse(code int, message, detail string) PluginRPCFailure {+ result := PluginRPCFailure{JSONRPC: "2.0", Error: &PluginRPCError{Code: code, Message: message}}+ if detail != "" {+ data, _ := json.Marshal(detail)+ var value JSONValue+ _ = json.Unmarshal(data, &value)+ result.Error.Data = &value+ }+ return result+}++type rpcOptional[T any] struct {+ Value T+ Exists bool+ IsNull bool+}++func (o *rpcOptional[T]) UnmarshalJSON(data []byte) error {+ o.Exists = true+ if string(data) == "null" {+ o.IsNull = true+ return nil+ }+ o.IsNull = false+ return json.Unmarshal(data, &o.Value)+}++func parsePluginRPCCall(data []byte) PluginRPCParsedCall {+ type JsonRpcRequestObject struct {+ JsonRpc rpcOptional[string] `json:"jsonrpc"`+ Method rpcOptional[string] `json:"method"`+ Params rpcOptional[JSONValue] `json:"params"`+ ID rpcOptional[JSONValue] `json:"id"`+ }+ var fields JsonRpcRequestObject+ err := json.Unmarshal(data, &fields)+ var id PluginRPCID+ if err == nil {+ switch {+ case !fields.JsonRpc.Exists:+ err = fmt.Errorf("missing jsonrpc field")+ case fields.JsonRpc.Value != "2.0":+ err = fmt.Errorf("invalid jsonrpc version: %s", fields.JsonRpc.Value)+ case !fields.Method.Exists || fields.Method.IsNull:+ err = fmt.Errorf("missing method field")+ default:+ if fields.ID.Exists && !fields.ID.IsNull {+ raw, _ := json.Marshal(fields.ID.Value)+ err = json.Unmarshal(raw, &id)+ }+ }+ }+ if err != nil {+ message := strings.ReplaceAll(err.Error(), "apicontract.JsonRpcRequestObject", "plugin.JsonRpcRequestObject")+ failure := RPCErrorResponse(-32600, "Invalid Request", "RPC request is not a valid JSON-RPC object: "+message)+ return PluginRPCParsedCall{Error: &failure}+ }+ return PluginRPCParsedCall{Request: &PluginRPCCall{Method: fields.Method.Value, Params: fields.Params.Value, ParamsPresent: fields.Params.Exists, ParamsNull: fields.Params.IsNull, ID: id, IDPresent: fields.ID.Exists}}+}++// RPC 请求保留批量中的单项结构错误,参数形状错误仍交给调用分发处理通知语义。+func DecodePluginRPC(reader io.Reader) (request PluginRPCBatchRequest, err error) {+ body, err := io.ReadAll(reader)+ if err != nil {+ return request, err+ }+ if !json.Valid(body) {+ failure := RPCErrorResponse(-32700, "Parse error", "RPC request is not valid JSON")+ request.Error = &failure+ return request, nil+ }+ var entries []json.RawMessage+ if json.Unmarshal(body, &entries) != nil {+ request.Calls = []PluginRPCParsedCall{parsePluginRPCCall(body)}+ return request, nil+ }+ if len(entries) == 0 {+ failure := RPCErrorResponse(-32600, "Invalid Request", "RPC request is not allowed to be an empty array")+ request.Error = &failure+ return request, nil+ }+ request.Batch = true+ request.Calls = make([]PluginRPCParsedCall, len(entries))+ for i, entry := range entries {+ request.Calls[i] = parsePluginRPCCall(entry)+ }+ return request, nil+}++func init() {+ for _, endpoint := range []*Endpoint[PluginRPCBatchRequest, PluginRPCResponse]{&PluginRPCHTTP, &PluginRPCHTTPByName} {+ endpoint.decodeRequest = DecodePluginRPC+ endpoint.decodeFailure = func(err error) Response[PluginRPCResponse] {+ failure := RPCErrorResponse(-32603, "Internal error", "Failed to read request body: "+err.Error())+ return SuccessDirectJSON(RPCSingleResponse(RPCFailureReply(failure)))+ }+ }+}diff --git a/kernel/apicontract/plugin_rpc_test.go b/kernel/apicontract/plugin_rpc_test.gonew file mode 100644index 0000000000..ea99a1070b--- /dev/null+++ b/kernel/apicontract/plugin_rpc_test.go@@ -0,0 +1,54 @@+package apicontract++import (+ "encoding/json"+ "testing"+)++func TestPluginRPCResponseSchema(t *testing.T) {+ bundle, err := BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ for _, entry := range []struct {+ body string+ valid bool+ }{+ {`{"jsonrpc":"2.0","result":{"arbitrary":[1,true,null]},"id":"id"}`, true},+ {`{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid","data":false},"id":null}`, true},+ {`[{"jsonrpc":"2.0","result":null,"id":1},{"jsonrpc":"2.0","error":{"code":-32601,"message":"missing"},"id":2}]`, true},+ {`[]`, false}, {`null`, false},+ {`{"jsonrpc":"2.0","result":1,"id":false}`, false},+ {`{"jsonrpc":"1.0","result":1,"id":1}`, false},+ {`{"jsonrpc":"2.0","result":1,"error":{"code":-1,"message":"invalid"},"id":1}`, false},+ {`{"code":0,"msg":"","data":{"jsonrpc":"2.0","result":1,"id":1}}`, false},+ {`{"code":-1,"msg":"readonly","data":{"closeTimeout":5000}}`, true},+ } {+ err := bundle.ValidateHTTPResponse("POST", "/api/plugin/rpc", 200, "application/json", []byte(entry.body))+ if (err == nil) != entry.valid {+ t.Fatalf("RPC schema result changed for %s: %v", entry.body, err)+ }+ }+ if _, err := json.Marshal(RPCBatchResponse(nil)); err == nil {+ t.Fatal("empty RPC response array accepted")+ }+ if _, err := json.Marshal(PluginRPCReply{}); err == nil {+ t.Fatal("empty RPC reply accepted")+ }+}++func TestEncodedJSONValuePreservesNumbers(t *testing.T) {+ data := []byte(`{"n":9223372036854775807}`)+ value, err := EncodedJSONValue(data)+ if err != nil {+ t.Fatal(err)+ }+ data[2] = 'x'+ actual, err := json.Marshal(value)+ if err != nil || string(actual) != `{"n":9223372036854775807}` {+ t.Fatalf("encoded JSON precision or ownership changed: %s, %v", actual, err)+ }+ if _, err := EncodedJSONValue([]byte("invalid")); err == nil {+ t.Fatal("invalid encoded JSON accepted")+ }+}diff --git a/kernel/apicontract/plugin_test.go b/kernel/apicontract/plugin_test.gonew file mode 100644index 0000000000..ff13d4342f--- /dev/null+++ b/kernel/apicontract/plugin_test.go@@ -0,0 +1,37 @@+package apicontract++import (+ "encoding/json"+ "strings"+ "testing"+)++func TestPluginNameDecodeCompatibility(t *testing.T) {+ for _, endpoint := range []Endpoint[LoadedPluginRequest, *LoadedPlugin]{GetLoadedPlugin, GetLoadedPluginRPC, GetLoadedPluginRPCByName} {+ for _, entry := range []struct {+ body string+ code int+ }{{`{}`, 1}, {`null`, 1}, {`{"name":null}`, 1}, {`{"name":false}`, 2}, {`{"name":[]}`, 2}, {`{`, -1}} {+ _, err := endpoint.Decode(strings.NewReader(entry.body))+ if err == nil {+ t.Fatalf("invalid plugin name accepted: %s", entry.body)+ }+ payload, err := json.Marshal(endpoint.DecodeFailure(err))+ if err != nil {+ t.Fatal(err)+ }+ var response struct {+ Code int `json:"code"`+ }+ if err := json.Unmarshal(payload, &response); err != nil || response.Code != entry.code {+ t.Fatalf("plugin name error changed: %s, %v", payload, err)+ }+ }+ for _, name := range []string{"", " plugin "} {+ request, err := endpoint.Decode(strings.NewReader(`{"name":"` + name + `"}`))+ if err != nil || request.Name != name {+ t.Fatalf("plugin name trimming changed: %+v, %v", request, err)+ }+ }+ }+}diff --git a/kernel/apicontract/response.go b/kernel/apicontract/response.goindex b7b44f58a1..149d17f3a8 100644--- a/kernel/apicontract/response.go+++ b/kernel/apicontract/response.go@@ -3,6 +3,7 @@ package apicontractimport ("encoding/json""fmt"+ "net/http")// BinaryContent 保留文件的原始字节和媒体类型,不经过 JSON 编码。@@ -17,8 +18,42 @@ func SuccessBinary(contentType string, data []byte) Response[BinaryContent] {func (r Response[Data]) Binary() *BinaryContent { return r.binary }+// SuccessDirectJSON 返回协议自身定义的 JSON 载荷,不添加统一信封。+func SuccessDirectJSON[Data any](data Data) Response[Data] {+ return Response[Data]{data: data, directJSON: true}+}++// SuccessNoContent 保留通知类请求的空响应,是否允许由端点声明控制。+func SuccessNoContent[Data any]() Response[Data] {+ return Response[Data]{noContent: true}+}+// Status 只为显式声明的非 JSON 协议使用独立错误状态。func (e Endpoint[Request, Data]) Status(r Response[Data]) int {+ if r.upgrade != nil || r.websocketFailure {+ if e.definition.Output != WebSocketOutput || e.definition.WebSocket == nil {+ panic("endpoint does not declare WebSocket output")+ }+ if r.upgrade != nil {+ return 101+ }+ return e.definition.WebSocket.FailureStatus+ }+ if e.definition.Output == WebSocketOutput && r.code == 0 {+ panic("WebSocket response requires an upgrade or rejection")+ }+ if r.noContent {+ if e.definition.Output != DirectJSONOutput || !e.definition.NoContent {+ panic("endpoint does not declare an empty response")+ }+ return 204+ }+ if r.directJSON && e.definition.Output != DirectJSONOutput {+ panic("endpoint does not declare a direct JSON response")+ }+ if e.definition.Output == DirectJSONOutput && r.code == 0 && !r.directJSON {+ panic("direct JSON response requires SuccessDirectJSON")+ }if e.definition.Output == BinaryOutput {if r.binary != nil {return 200@@ -58,11 +93,15 @@ func (Null) MarshalJSON() ([]byte, error) { return []byte("null"), nil }// Response 的载荷仅能通过有类型的成功构造函数或明确的错误构造函数设置。type Response[Data any] struct {- code int- msg string- data any- binary *BinaryContent- queryLimit *SQLQueryLimit+ code int+ msg string+ data any+ binary *BinaryContent+ queryLimit *SQLQueryLimit+ directJSON bool+ noContent bool+ upgrade func(http.ResponseWriter, *http.Request)+ websocketFailure bool}func Success[Data any](data Data) Response[Data] { return Response[Data]{data: data} }@@ -83,6 +122,18 @@ func FailureWithTimeout[Data any](code int, msg string, milliseconds int) Respon}func (r Response[Data]) MarshalJSON() ([]byte, error) {+ if r.upgrade != nil {+ return nil, fmt.Errorf("WebSocket upgrade cannot be encoded as JSON")+ }+ if r.websocketFailure {+ return json.Marshal(r.data)+ }+ if r.noContent {+ return nil, fmt.Errorf("empty response cannot be encoded as JSON")+ }+ if r.directJSON {+ return json.Marshal(r.data)+ }if r.binary != nil {return nil, fmt.Errorf("binary response cannot be encoded as JSON")}diff --git a/kernel/apicontract/schema.go b/kernel/apicontract/schema.goindex 3ef38208f9..79448cf380 100644--- a/kernel/apicontract/schema.go+++ b/kernel/apicontract/schema.go@@ -21,18 +21,27 @@ type Schema struct {Properties map[string]*Schema `json:"properties,omitempty"`Required []string `json:"required,omitempty"`Items *Schema `json:"items,omitempty"`+ MinItems int `json:"minItems,omitempty"`AdditionalProperties any `json:"additionalProperties,omitempty"`}type EndpointSchema struct {- Method string `json:"method"`- Path string `json:"path"`- Handler string `json:"handler"`- Body BodyMode `json:"body"`- Request *Schema `json:"request"`- Response *Schema `json:"response"`- Output OutputMode `json:"output,omitempty"`- ErrorStatus int `json:"errorStatus,omitempty"`+ Method string `json:"method"`+ Path string `json:"path"`+ Handler string `json:"handler"`+ Body BodyMode `json:"body"`+ Request *Schema `json:"request"`+ Response *Schema `json:"response"`+ Output OutputMode `json:"output,omitempty"`+ ErrorStatus int `json:"errorStatus,omitempty"`+ NoContent bool `json:"noContent,omitempty"`+ WebSocket *WebSocketSchema `json:"websocket,omitempty"`+}++type WebSocketSchema struct {+ Incoming *Schema `json:"incoming"`+ Outgoing *Schema `json:"outgoing"`+ FailureStatus int `json:"failureStatus"`}type Bundle struct {@@ -75,6 +84,62 @@ func nonnullable(schema *Schema) *Schema {}func (b *schemaBuilder) schema(t reflect.Type, input bool) (*Schema, error) {+ if t == reflect.TypeFor[PluginRPCMessage]() {+ response, err := b.schema(reflect.TypeFor[PluginRPCResponse](), false)+ if err != nil {+ return nil, err+ }+ notification, err := b.schema(reflect.TypeFor[PluginRPCNotification](), false)+ if err != nil {+ return nil, err+ }+ // 展开单条回复分支,使声明生成器能排除通知中的 ID 和回复中的 method。+ variants := append([]*Schema{}, response.AnyOf[0].AnyOf...)+ variants = append(variants, response.AnyOf[1], notification)+ return &Schema{AnyOf: variants}, nil+ }+ if t == reflect.TypeFor[*JSONValue]() {+ value, err := b.schema(reflect.TypeFor[JSONValue](), input)+ if err != nil {+ return nil, err+ }+ return nullable(value), nil+ }+ if t == reflect.TypeFor[PluginRPCID]() || t == reflect.TypeFor[*PluginRPCID]() {+ return &Schema{AnyOf: []*Schema{{Type: "string"}, {Type: "number"}, {Type: "null"}}}, nil+ }+ if t == reflect.TypeFor[PluginRPCParams]() {+ value, err := b.schema(reflect.TypeFor[JSONValue](), input)+ if err != nil {+ return nil, err+ }+ return &Schema{AnyOf: []*Schema{{Type: "array", Items: value}, {Type: "object", AdditionalProperties: value}}}, nil+ }+ if t == reflect.TypeFor[PluginRPCBatchRequest]() {+ call, err := b.schema(reflect.TypeFor[PluginRPCRequestFields](), true)+ if err != nil {+ return nil, err+ }+ return &Schema{AnyOf: []*Schema{call, {Type: "array", Items: call, MinItems: 1}}}, nil+ }+ if t == reflect.TypeFor[PluginRPCReply]() {+ success, err := b.schema(reflect.TypeFor[PluginRPCSuccess](), false)+ if err != nil {+ return nil, err+ }+ failure, err := b.schema(reflect.TypeFor[PluginRPCFailure](), false)+ if err != nil {+ return nil, err+ }+ return &Schema{AnyOf: []*Schema{success, failure}}, nil+ }+ if t == reflect.TypeFor[PluginRPCResponse]() {+ reply, err := b.schema(reflect.TypeFor[PluginRPCReply](), false)+ if err != nil {+ return nil, err+ }+ return &Schema{AnyOf: []*Schema{reply, {Type: "array", Items: reply, MinItems: 1}}}, nil+ }if t == reflect.TypeFor[ImportAutoData]() {var variants []*Schemafor _, member := range []reflect.Type{reflect.TypeFor[ImportAutoDocument](), reflect.TypeFor[ImportAutoNotebook](), reflect.TypeFor[ImportAutoNotebooks]()} {@@ -407,9 +472,38 @@ func BuildBundle() (*Bundle, error) {b := &schemaBuilder{definitions: map[string]*Schema{}, owners: map[string]reflect.Type{}}bundle := &Bundle{Dialect: "https://json-schema.org/draft/2020-12/schema", Definitions: b.definitions}for _, definition := range Definitions() {- if definition.Output != "" && definition.Output != BinaryOutput {+ if definition.Output != "" && definition.Output != BinaryOutput && definition.Output != DirectJSONOutput && definition.Output != WebSocketOutput {return nil, fmt.Errorf("unsupported response output: %s", definition.Name)}+ if definition.NoContent && definition.Output != DirectJSONOutput {+ return nil, fmt.Errorf("empty responses require direct JSON output: %s", definition.Name)+ }+ var websocket *WebSocketSchema+ if (definition.Output == WebSocketOutput) != (definition.WebSocket != nil) {+ return nil, fmt.Errorf("WebSocket output requires message declarations: %s", definition.Name)+ }+ if ws := definition.WebSocket; ws != nil {+ if definition.Body != NoBody || definition.DataOnError || definition.ErrorStatus != 0 || ws.FailureStatus < 400 || ws.FailureStatus > 599 {+ return nil, fmt.Errorf("invalid WebSocket response options: %s", definition.Name)+ }+ for _, method := range definition.Methods {+ if method != "GET" {+ return nil, fmt.Errorf("WebSocket upgrade requires GET: %s", definition.Name)+ }+ }+ incoming, err := b.schema(ws.Incoming, true)+ if err != nil {+ return nil, err+ }+ outgoing, err := b.schema(ws.Outgoing, false)+ if err != nil {+ return nil, err+ }+ websocket = &WebSocketSchema{Incoming: incoming, Outgoing: outgoing, FailureStatus: ws.FailureStatus}+ }+ if definition.Output == DirectJSONOutput && (definition.DataOnError || definition.ErrorStatus != 0) {+ return nil, fmt.Errorf("direct JSON output cannot use envelope data or error status options: %s", definition.Name)+ }if (definition.Output == BinaryOutput) != (definition.Data == reflect.TypeFor[BinaryContent]()) {return nil, fmt.Errorf("binary output requires BinaryContent: %s", definition.Name)}@@ -451,6 +545,9 @@ func BuildBundle() (*Bundle, error) {return nil, err}}+ if definition.Output == DirectJSONOutput || definition.Output == WebSocketOutput {+ success = data+ }var codes []anyfor _, code := range definition.ErrorCodes {codes = append(codes, code)@@ -469,7 +566,7 @@ func BuildBundle() (*Bundle, error) {response := &Schema{AnyOf: []*Schema{success, failure}}for _, method := range definition.Methods {bundle.Endpoints = append(bundle.Endpoints, EndpointSchema{Method: method, Path: definition.Path, Handler: definition.Name,- Body: definition.Body, Request: request, Response: response, Output: definition.Output, ErrorStatus: definition.ErrorStatus})+ Body: definition.Body, Request: request, Response: response, Output: definition.Output, ErrorStatus: definition.ErrorStatus, NoContent: definition.NoContent, WebSocket: websocket})}}sort.Slice(bundle.Endpoints, func(i, j int) bool {@@ -485,7 +582,7 @@ func (b *Bundle) ValidateResponse(method, path string, payload []byte) error {}for _, endpoint := range b.Endpoints {if endpoint.Method == method && endpoint.Path == path {- if endpoint.Output == BinaryOutput {+ if endpoint.Output == BinaryOutput || endpoint.Output == WebSocketOutput {return fmt.Errorf("binary endpoint requires HTTP response validation")}return b.validate(endpoint.Response, value, "$")@@ -500,6 +597,18 @@ func (b *Bundle) ValidateHTTPResponse(method, path string, status int, contentTyif endpoint.Method != method || endpoint.Path != path {continue}+ if endpoint.NoContent && status == 204 {+ if len(payload) != 0 {+ return fmt.Errorf("empty response must not contain a body")+ }+ return nil+ }+ if endpoint.WebSocket != nil && status == 101 {+ if len(payload) != 0 {+ return fmt.Errorf("WebSocket upgrade must not contain an HTTP body")+ }+ return nil+ }mediaType, _, err := mime.ParseMediaType(contentType)if err != nil {return fmt.Errorf("invalid response content type: %w", err)@@ -509,6 +618,16 @@ func (b *Bundle) ValidateHTTPResponse(method, path string, status int, contentTy}expectedStatus := 200response := endpoint.Response+ if endpoint.WebSocket != nil {+ if status == 400 && mediaType == "text/plain" {+ return nil+ }+ response = endpoint.Response.AnyOf[1]+ if status == endpoint.WebSocket.FailureStatus {+ expectedStatus = status+ response = endpoint.Response.AnyOf[0]+ }+ }if endpoint.Output == BinaryOutput {if endpoint.ErrorStatus != 0 {expectedStatus = endpoint.ErrorStatus@@ -572,6 +691,9 @@ func (b *Bundle) validate(schema *Schema, value any, path string) error {array, ok := value.([]any)valid = okif ok {+ if len(array) < schema.MinItems {+ return fmt.Errorf("%s has too few array items", path)+ }for i, element := range array {if err := b.validate(schema.Items, element, fmt.Sprintf("%s[%d]", path, i)); err != nil {return errdiff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.jsonindex 9813bb1f7a..d9cf2e9231 100644--- a/kernel/apicontract/schema.json+++ b/kernel/apicontract/schema.json@@ -7137,6 +7137,59 @@],"additionalProperties": false},+ "LoadedPlugin": {+ "type": "object",+ "properties": {+ "methods": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCMethod"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "name": {+ "type": "string"+ },+ "state": {+ "type": "string"+ },+ "stateCode": {+ "type": "integer"+ }+ },+ "required": [+ "methods",+ "name",+ "state",+ "stateCode"+ ],+ "additionalProperties": false+ },+ "LoadedPluginRequestInput": {+ "type": "object",+ "properties": {+ "name": {+ "type": "string"+ }+ },+ "required": [+ "name"+ ],+ "additionalProperties": false+ },"LocalGraphConf": {"type": "object","properties": {@@ -8596,6 +8649,201 @@],"additionalProperties": false},+ "PluginRPCError": {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer"+ },+ "data": {+ "$ref": "#/$defs/JSONValue"+ },+ "message": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "message"+ ],+ "additionalProperties": false+ },+ "PluginRPCFailure": {+ "type": "object",+ "properties": {+ "error": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCError"+ },+ {+ "type": "null"+ }+ ]+ },+ "id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ },+ "jsonrpc": {+ "type": "string",+ "enum": [+ "2.0"+ ]+ }+ },+ "required": [+ "error",+ "id",+ "jsonrpc"+ ],+ "additionalProperties": false+ },+ "PluginRPCMethod": {+ "type": "object",+ "properties": {+ "descriptions": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "name": {+ "type": "string"+ }+ },+ "required": [+ "descriptions",+ "name"+ ],+ "additionalProperties": false+ },+ "PluginRPCNotification": {+ "type": "object",+ "properties": {+ "jsonrpc": {+ "type": "string",+ "enum": [+ "2.0"+ ]+ },+ "method": {+ "type": "string"+ },+ "params": {+ "$ref": "#/$defs/JSONValue"+ }+ },+ "required": [+ "jsonrpc",+ "method"+ ],+ "additionalProperties": false+ },+ "PluginRPCRequestFieldsInput": {+ "type": "object",+ "properties": {+ "id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ },+ "jsonrpc": {+ "type": "string",+ "enum": [+ "2.0"+ ]+ },+ "method": {+ "type": "string"+ },+ "params": {+ "anyOf": [+ {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "$ref": "#/$defs/JSONValue"+ }+ },+ {+ "type": "object",+ "additionalProperties": {+ "$ref": "#/$defs/JSONValue"+ }+ }+ ]+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "jsonrpc",+ "method"+ ],+ "additionalProperties": false+ },+ "PluginRPCSuccess": {+ "type": "object",+ "properties": {+ "id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ },+ "jsonrpc": {+ "type": "string",+ "enum": [+ "2.0"+ ]+ },+ "result": {+ "$ref": "#/$defs/JSONValue"+ }+ },+ "required": [+ "id",+ "jsonrpc",+ "result"+ ],+ "additionalProperties": false+ },"PrepareRichTextRequestInput": {"type": "object","properties": {@@ -12039,8 +12287,8 @@"endpoints": [{"method": "GET",- "path": "/api/system/bootProgress",- "handler": "bootProgress",+ "path": "/api/plugin",+ "handler": "listLoadedPluginsGET","body": "none","request": {"$ref": "#/$defs/EmptyRequestInput"@@ -12057,7 +12305,24 @@]},"data": {- "$ref": "#/$defs/BootProgressData"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/LoadedPlugin"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -12114,11 +12379,11 @@},{"method": "GET",- "path": "/api/system/version",- "handler": "version",- "body": "none",+ "path": "/api/plugin/rpc",+ "handler": "getLoadedPluginRPC",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/LoadedPluginRequestInput"},"response": {"anyOf": [@@ -12132,7 +12397,14 @@]},"data": {- "type": "string"+ "anyOf": [+ {+ "$ref": "#/$defs/LoadedPlugin"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -12151,7 +12423,11 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1,+ 2,+ 3,+ 4]},"data": {@@ -12188,12 +12464,12 @@}},{- "method": "POST",- "path": "/api/account/checkActivationcode",- "handler": "checkActivationcode",+ "method": "GET",+ "path": "/api/plugin/rpc/:name",+ "handler": "getLoadedPluginRPCByName","body": "json","request": {- "$ref": "#/$defs/CheckActivationCodeRequestInput"+ "$ref": "#/$defs/LoadedPluginRequestInput"},"response": {"anyOf": [@@ -12207,11 +12483,770 @@]},"data": {- "type": "null"- },- "msg": {- "type": "string"- }+ "anyOf": [+ {+ "$ref": "#/$defs/LoadedPlugin"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1,+ 1,+ 2,+ 3,+ 4+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "GET",+ "path": "/api/system/bootProgress",+ "handler": "bootProgress",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BootProgressData"+ },+ "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": "GET",+ "path": "/api/system/version",+ "handler": "version",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "string"+ },+ "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": "GET",+ "path": "/ws/plugin/rpc",+ "handler": "pluginJsonRpcWebSocket",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCFailure"+ },+ {+ "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+ }+ ]+ },+ "output": "websocket",+ "websocket": {+ "incoming": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ {+ "type": "array",+ "items": {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ "minItems": 1+ }+ ]+ },+ "outgoing": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCSuccess"+ },+ {+ "$ref": "#/$defs/PluginRPCFailure"+ },+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCSuccess"+ },+ {+ "$ref": "#/$defs/PluginRPCFailure"+ }+ ]+ },+ "minItems": 1+ },+ {+ "$ref": "#/$defs/PluginRPCNotification"+ }+ ]+ },+ "failureStatus": 404+ }+ },+ {+ "method": "GET",+ "path": "/ws/plugin/rpc/:name",+ "handler": "pluginJsonRpcWebSocketByName",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCFailure"+ },+ {+ "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+ }+ ]+ },+ "output": "websocket",+ "websocket": {+ "incoming": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ {+ "type": "array",+ "items": {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ "minItems": 1+ }+ ]+ },+ "outgoing": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCSuccess"+ },+ {+ "$ref": "#/$defs/PluginRPCFailure"+ },+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCSuccess"+ },+ {+ "$ref": "#/$defs/PluginRPCFailure"+ }+ ]+ },+ "minItems": 1+ },+ {+ "$ref": "#/$defs/PluginRPCNotification"+ }+ ]+ },+ "failureStatus": 404+ }+ },+ {+ "method": "POST",+ "path": "/api/account/checkActivationcode",+ "handler": "checkActivationcode",+ "body": "json",+ "request": {+ "$ref": "#/$defs/CheckActivationCodeRequestInput"+ },+ "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,+ 1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/account/deactivate",+ "handler": "deactivateUser",+ "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/account/login",+ "handler": "login",+ "body": "json",+ "request": {+ "$ref": "#/$defs/AccountLoginRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "$ref": "#/$defs/AccountLoginData"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1,+ 1,+ 10+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/AccountLoginData"+ },+ {+ "type": "null"+ }+ ]+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/account/startFreeTrial",+ "handler": "startFreeTrial",+ "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/account/useActivationcode",+ "handler": "useActivationcode",+ "body": "json",+ "request": {+ "$ref": "#/$defs/ActivationCodeRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }},"required": ["code",@@ -12226,8 +13261,7 @@"code": {"type": "integer","enum": [- -1,- 1+ -1]},"data": {@@ -12244,9 +13278,6 @@],"additionalProperties": false},- {- "type": "null"- },{"type": "null"}@@ -12268,11 +13299,11 @@},{"method": "POST",- "path": "/api/account/deactivate",- "handler": "deactivateUser",- "body": "none",+ "path": "/api/archive/unzip",+ "handler": "unzip",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/UnzipRequestInput"},"response": {"anyOf": [@@ -12343,11 +13374,11 @@},{"method": "POST",- "path": "/api/account/login",- "handler": "login",+ "path": "/api/archive/zip",+ "handler": "zip","body": "json","request": {- "$ref": "#/$defs/AccountLoginRequestInput"+ "$ref": "#/$defs/ZipRequestInput"},"response": {"anyOf": [@@ -12361,14 +13392,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/AccountLoginData"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -12387,9 +13411,7 @@"code": {"type": "integer","enum": [- -1,- 1,- 10+ -1]},"data": {@@ -12408,16 +13430,6 @@},{"type": "null"- },- {- "anyOf": [- {- "$ref": "#/$defs/AccountLoginData"- },- {- "type": "null"- }- ]}]},@@ -12437,11 +13449,11 @@},{"method": "POST",- "path": "/api/account/startFreeTrial",- "handler": "startFreeTrial",- "body": "none",+ "path": "/api/attr/batchGetBlockAttrs",+ "handler": "batchGetBlockAttrs",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/BlockIDsRequestInput"},"response": {"anyOf": [@@ -12455,7 +13467,20 @@]},"data": {- "type": "null"+ "type": "object",+ "additionalProperties": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ }},"msg": {"type": "string"@@ -12512,11 +13537,11 @@},{"method": "POST",- "path": "/api/account/useActivationcode",- "handler": "useActivationcode",+ "path": "/api/attr/batchSetBlockAttrs",+ "handler": "batchSetBlockAttrs","body": "json","request": {- "$ref": "#/$defs/ActivationCodeRequestInput"+ "$ref": "#/$defs/BatchSetBlockAttrsRequestInput"},"response": {"anyOf": [@@ -12587,11 +13612,11 @@},{"method": "POST",- "path": "/api/archive/unzip",- "handler": "unzip",+ "path": "/api/attr/getBlockAttrs",+ "handler": "getBlockAttrs","body": "json","request": {- "$ref": "#/$defs/UnzipRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -12605,7 +13630,10 @@]},"data": {- "type": "null"+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }},"msg": {"type": "string"@@ -12662,11 +13690,11 @@},{"method": "POST",- "path": "/api/archive/zip",- "handler": "zip",- "body": "json",+ "path": "/api/attr/getBookmarkLabels",+ "handler": "getBookmarkLabels",+ "body": "none","request": {- "$ref": "#/$defs/ZipRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -12680,7 +13708,17 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -12737,11 +13775,11 @@},{"method": "POST",- "path": "/api/attr/batchGetBlockAttrs",- "handler": "batchGetBlockAttrs",- "body": "json",+ "path": "/api/attr/resetBlockAttrs",+ "handler": "resetBlockAttrs",+ "body": "none","request": {- "$ref": "#/$defs/BlockIDsRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -12755,20 +13793,7 @@]},"data": {- "type": "object",- "additionalProperties": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "type": "string"- }- },- {- "type": "null"- }- ]- }+ "type": "null"},"msg": {"type": "string"@@ -12825,11 +13850,11 @@},{"method": "POST",- "path": "/api/attr/batchSetBlockAttrs",- "handler": "batchSetBlockAttrs",+ "path": "/api/attr/setBlockAttrs",+ "handler": "setBlockAttrs","body": "json","request": {- "$ref": "#/$defs/BatchSetBlockAttrsRequestInput"+ "$ref": "#/$defs/SetBlockAttrsRequestInput"},"response": {"anyOf": [@@ -12900,11 +13925,11 @@},{"method": "POST",- "path": "/api/attr/getBlockAttrs",- "handler": "getBlockAttrs",- "body": "json",+ "path": "/api/av/searchAttributeViewNonRelationKey",+ "handler": "searchAttributeViewNonRelationKey",+ "body": "none","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -12918,10 +13943,7 @@]},"data": {- "type": "object",- "additionalProperties": {- "type": "string"- }+ "type": "null"},"msg": {"type": "string"@@ -12978,11 +14000,11 @@},{"method": "POST",- "path": "/api/attr/getBookmarkLabels",- "handler": "getBookmarkLabels",- "body": "none",+ "path": "/api/block/appendBlock",+ "handler": "appendBlock",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/AppendBlockRequestInput"},"response": {"anyOf": [@@ -13000,7 +14022,14 @@{"type": "array","items": {- "type": "string"+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]}},{@@ -13063,11 +14092,11 @@},{"method": "POST",- "path": "/api/attr/resetBlockAttrs",- "handler": "resetBlockAttrs",- "body": "none",+ "path": "/api/block/appendDailyNoteBlock",+ "handler": "appendDailyNoteBlock",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/DailyNoteBlockRequestInput"},"response": {"anyOf": [@@ -13081,7 +14110,24 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -13138,11 +14184,11 @@},{"method": "POST",- "path": "/api/attr/setBlockAttrs",- "handler": "setBlockAttrs",+ "path": "/api/block/appendHeadingChildren",+ "handler": "appendHeadingChildren","body": "json","request": {- "$ref": "#/$defs/SetBlockAttrsRequestInput"+ "$ref": "#/$defs/AppendHeadingChildrenRequestInput"},"response": {"anyOf": [@@ -13213,11 +14259,11 @@},{"method": "POST",- "path": "/api/av/searchAttributeViewNonRelationKey",- "handler": "searchAttributeViewNonRelationKey",- "body": "none",+ "path": "/api/block/batchAppendBlock",+ "handler": "batchAppendBlock",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/BatchParentBlockRequestInput"},"response": {"anyOf": [@@ -13230,9 +14276,26 @@0]},- "data": {- "type": "null"- },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },"msg": {"type": "string"}@@ -13288,11 +14351,11 @@},{"method": "POST",- "path": "/api/block/appendBlock",- "handler": "appendBlock",+ "path": "/api/block/batchInsertBlock",+ "handler": "batchInsertBlock","body": "json","request": {- "$ref": "#/$defs/AppendBlockRequestInput"+ "$ref": "#/$defs/BatchInsertBlockRequestInput"},"response": {"anyOf": [@@ -13380,11 +14443,11 @@},{"method": "POST",- "path": "/api/block/appendDailyNoteBlock",- "handler": "appendDailyNoteBlock",+ "path": "/api/block/batchPrependBlock",+ "handler": "batchPrependBlock","body": "json","request": {- "$ref": "#/$defs/DailyNoteBlockRequestInput"+ "$ref": "#/$defs/BatchParentBlockRequestInput"},"response": {"anyOf": [@@ -13472,11 +14535,11 @@},{"method": "POST",- "path": "/api/block/appendHeadingChildren",- "handler": "appendHeadingChildren",+ "path": "/api/block/batchUpdateBlock",+ "handler": "batchUpdateBlock","body": "json","request": {- "$ref": "#/$defs/AppendHeadingChildrenRequestInput"+ "$ref": "#/$defs/BatchUpdateBlockRequestInput"},"response": {"anyOf": [@@ -13490,7 +14553,24 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -13547,11 +14627,11 @@},{"method": "POST",- "path": "/api/block/batchAppendBlock",- "handler": "batchAppendBlock",+ "path": "/api/block/batchUpdateTaskListItemMarker",+ "handler": "batchUpdateTaskListItemMarker","body": "json","request": {- "$ref": "#/$defs/BatchParentBlockRequestInput"+ "$ref": "#/$defs/BatchTaskListMarkerRequestInput"},"response": {"anyOf": [@@ -13639,11 +14719,11 @@},{"method": "POST",- "path": "/api/block/batchInsertBlock",- "handler": "batchInsertBlock",+ "path": "/api/block/checkBlockExist",+ "handler": "checkBlockExist","body": "json","request": {- "$ref": "#/$defs/BatchInsertBlockRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -13657,24 +14737,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "type": "boolean"},"msg": {"type": "string"@@ -13731,11 +14794,11 @@},{"method": "POST",- "path": "/api/block/batchPrependBlock",- "handler": "batchPrependBlock",+ "path": "/api/block/checkBlockFold",+ "handler": "checkBlockFold","body": "json","request": {- "$ref": "#/$defs/BatchParentBlockRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -13749,24 +14812,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/BlockFoldData"},"msg": {"type": "string"@@ -13823,11 +14869,11 @@},{"method": "POST",- "path": "/api/block/batchUpdateBlock",- "handler": "batchUpdateBlock",+ "path": "/api/block/checkBlockRef",+ "handler": "checkBlockRef","body": "json","request": {- "$ref": "#/$defs/BatchUpdateBlockRequestInput"+ "$ref": "#/$defs/CheckBlockRefRequestInput"},"response": {"anyOf": [@@ -13841,24 +14887,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "type": "boolean"},"msg": {"type": "string"@@ -13896,6 +14925,9 @@},{"type": "null"+ },+ {+ "type": "boolean"}]},@@ -13915,11 +14947,11 @@},{"method": "POST",- "path": "/api/block/batchUpdateTaskListItemMarker",- "handler": "batchUpdateTaskListItemMarker",+ "path": "/api/block/checkBlocksExist",+ "handler": "checkBlocksExist","body": "json","request": {- "$ref": "#/$defs/BatchTaskListMarkerRequestInput"+ "$ref": "#/$defs/CheckBlocksExistRequestInput"},"response": {"anyOf": [@@ -13935,16 +14967,9 @@"data": {"anyOf": [{- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]+ "type": "object",+ "additionalProperties": {+ "type": "boolean"}},{@@ -14007,11 +15032,11 @@},{"method": "POST",- "path": "/api/block/checkBlockExist",- "handler": "checkBlockExist",+ "path": "/api/block/deleteBlock",+ "handler": "deleteBlock","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/DeleteBlockRequestInput"},"response": {"anyOf": [@@ -14025,7 +15050,24 @@]},"data": {- "type": "boolean"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -14082,11 +15124,11 @@},{"method": "POST",- "path": "/api/block/checkBlockFold",- "handler": "checkBlockFold",+ "path": "/api/block/foldBlock",+ "handler": "foldBlock","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -14100,7 +15142,7 @@]},"data": {- "$ref": "#/$defs/BlockFoldData"+ "type": "null"},"msg": {"type": "string"@@ -14157,11 +15199,11 @@},{"method": "POST",- "path": "/api/block/checkBlockRef",- "handler": "checkBlockRef",+ "path": "/api/block/getBlockBreadcrumb",+ "handler": "getBlockBreadcrumb","body": "json","request": {- "$ref": "#/$defs/CheckBlockRefRequestInput"+ "$ref": "#/$defs/BlockBreadcrumbRequestInput"},"response": {"anyOf": [@@ -14175,7 +15217,24 @@]},"data": {- "type": "boolean"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockPath"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -14213,9 +15272,6 @@},{"type": "null"- },- {- "type": "boolean"}]},@@ -14235,11 +15291,11 @@},{"method": "POST",- "path": "/api/block/checkBlocksExist",- "handler": "checkBlocksExist",+ "path": "/api/block/getBlockBreadcrumbChildren",+ "handler": "getBlockBreadcrumbChildren","body": "json","request": {- "$ref": "#/$defs/CheckBlocksExistRequestInput"+ "$ref": "#/$defs/BlockBreadcrumbChildrenRequestInput"},"response": {"anyOf": [@@ -14255,10 +15311,7 @@"data": {"anyOf": [{- "type": "object",- "additionalProperties": {- "type": "boolean"- }+ "$ref": "#/$defs/BlockBreadcrumbChildren"},{"type": "null"@@ -14320,11 +15373,11 @@},{"method": "POST",- "path": "/api/block/deleteBlock",- "handler": "deleteBlock",+ "path": "/api/block/getBlockDOM",+ "handler": "getBlockDOM","body": "json","request": {- "$ref": "#/$defs/DeleteBlockRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -14332,31 +15385,14 @@"type": "object","properties": {"code": {- "type": "integer",- "enum": [- 0- ]- },- "data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }+ "type": "integer",+ "enum": [+ 0]},+ "data": {+ "$ref": "#/$defs/BlockDOMData"+ },"msg": {"type": "string"}@@ -14412,11 +15448,11 @@},{"method": "POST",- "path": "/api/block/foldBlock",- "handler": "foldBlock",+ "path": "/api/block/getBlockDOMWithEmbed",+ "handler": "getBlockDOMWithEmbed","body": "json","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -14430,7 +15466,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/BlockDOMData"},"msg": {"type": "string"@@ -14487,11 +15523,11 @@},{"method": "POST",- "path": "/api/block/getBlockBreadcrumb",- "handler": "getBlockBreadcrumb",+ "path": "/api/block/getBlockDOMs",+ "handler": "getBlockDOMs","body": "json","request": {- "$ref": "#/$defs/BlockBreadcrumbRequestInput"+ "$ref": "#/$defs/BlocksQueryRequestInput"},"response": {"anyOf": [@@ -14507,16 +15543,9 @@"data": {"anyOf": [{- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockPath"- },- {- "type": "null"- }- ]+ "type": "object",+ "additionalProperties": {+ "type": "string"}},{@@ -14579,11 +15608,11 @@},{"method": "POST",- "path": "/api/block/getBlockBreadcrumbChildren",- "handler": "getBlockBreadcrumbChildren",+ "path": "/api/block/getBlockDOMsWithEmbed",+ "handler": "getBlockDOMsWithEmbed","body": "json","request": {- "$ref": "#/$defs/BlockBreadcrumbChildrenRequestInput"+ "$ref": "#/$defs/BlocksQueryRequestInput"},"response": {"anyOf": [@@ -14599,7 +15628,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/BlockBreadcrumbChildren"+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }},{"type": "null"@@ -14661,11 +15693,11 @@},{"method": "POST",- "path": "/api/block/getBlockDOM",- "handler": "getBlockDOM",+ "path": "/api/block/getBlockDefIDsByRefText",+ "handler": "getBlockDefIDsByRefText","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/RefTextQueryRequestInput"},"response": {"anyOf": [@@ -14679,7 +15711,7 @@]},"data": {- "$ref": "#/$defs/BlockDOMData"+ "$ref": "#/$defs/RefDefsData"},"msg": {"type": "string"@@ -14736,8 +15768,8 @@},{"method": "POST",- "path": "/api/block/getBlockDOMWithEmbed",- "handler": "getBlockDOMWithEmbed",+ "path": "/api/block/getBlockIndex",+ "handler": "getBlockIndex","body": "json","request": {"$ref": "#/$defs/BlockQueryRequestInput"@@ -14754,7 +15786,7 @@]},"data": {- "$ref": "#/$defs/BlockDOMData"+ "type": "integer"},"msg": {"type": "string"@@ -14811,11 +15843,11 @@},{"method": "POST",- "path": "/api/block/getBlockDOMs",- "handler": "getBlockDOMs",+ "path": "/api/block/getBlockInfo",+ "handler": "getBlockInfo","body": "json","request": {- "$ref": "#/$defs/BlocksQueryRequestInput"+ "$ref": "#/$defs/BlockInfoRequestInput"},"response": {"anyOf": [@@ -14829,17 +15861,7 @@]},"data": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "type": "string"- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/BlockInfoData"},"msg": {"type": "string"@@ -14858,7 +15880,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 3]},"data": {@@ -14877,6 +15900,9 @@},{"type": "null"+ },+ {+ "type": "string"}]},@@ -14896,11 +15922,11 @@},{"method": "POST",- "path": "/api/block/getBlockDOMsWithEmbed",- "handler": "getBlockDOMsWithEmbed",+ "path": "/api/block/getBlockKramdown",+ "handler": "getBlockKramdown","body": "json","request": {- "$ref": "#/$defs/BlocksQueryRequestInput"+ "$ref": "#/$defs/BlockKramdownRequestInput"},"response": {"anyOf": [@@ -14914,17 +15940,7 @@]},"data": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "type": "string"- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/BlockKramdownData"},"msg": {"type": "string"@@ -14981,11 +15997,11 @@},{"method": "POST",- "path": "/api/block/getBlockDefIDsByRefText",- "handler": "getBlockDefIDsByRefText",+ "path": "/api/block/getBlockKramdowns",+ "handler": "getBlockKramdowns","body": "json","request": {- "$ref": "#/$defs/RefTextQueryRequestInput"+ "$ref": "#/$defs/BlocksKramdownRequestInput"},"response": {"anyOf": [@@ -14999,7 +16015,17 @@]},"data": {- "$ref": "#/$defs/RefDefsData"+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -15056,8 +16082,8 @@},{"method": "POST",- "path": "/api/block/getBlockIndex",- "handler": "getBlockIndex",+ "path": "/api/block/getBlockRelevantIDs",+ "handler": "getBlockRelevantIDs","body": "json","request": {"$ref": "#/$defs/BlockQueryRequestInput"@@ -15074,7 +16100,7 @@]},"data": {- "type": "integer"+ "$ref": "#/$defs/BlockRelevantData"},"msg": {"type": "string"@@ -15131,11 +16157,11 @@},{"method": "POST",- "path": "/api/block/getBlockInfo",- "handler": "getBlockInfo",+ "path": "/api/block/getBlockSiblingID",+ "handler": "getBlockSiblingID","body": "json","request": {- "$ref": "#/$defs/BlockInfoRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -15149,7 +16175,7 @@]},"data": {- "$ref": "#/$defs/BlockInfoData"+ "$ref": "#/$defs/BlockSiblingData"},"msg": {"type": "string"@@ -15168,8 +16194,7 @@"code": {"type": "integer","enum": [- -1,- 3+ -1]},"data": {@@ -15188,9 +16213,6 @@},{"type": "null"- },- {- "type": "string"}]},@@ -15210,11 +16232,11 @@},{"method": "POST",- "path": "/api/block/getBlockKramdown",- "handler": "getBlockKramdown",+ "path": "/api/block/getBlockTreeInfos",+ "handler": "getBlockTreeInfos","body": "json","request": {- "$ref": "#/$defs/BlockKramdownRequestInput"+ "$ref": "#/$defs/BlocksQueryRequestInput"},"response": {"anyOf": [@@ -15228,7 +16250,24 @@]},"data": {- "$ref": "#/$defs/BlockKramdownData"+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTreeInfo"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -15285,11 +16324,11 @@},{"method": "POST",- "path": "/api/block/getBlockKramdowns",- "handler": "getBlockKramdowns",+ "path": "/api/block/getBlocksIndexes",+ "handler": "getBlocksIndexes","body": "json","request": {- "$ref": "#/$defs/BlocksKramdownRequestInput"+ "$ref": "#/$defs/BlocksQueryRequestInput"},"response": {"anyOf": [@@ -15307,7 +16346,7 @@{"type": "object","additionalProperties": {- "type": "string"+ "type": "integer"}},{@@ -15370,11 +16409,11 @@},{"method": "POST",- "path": "/api/block/getBlockRelevantIDs",- "handler": "getBlockRelevantIDs",+ "path": "/api/block/getBlocksWordCount",+ "handler": "getBlocksWordCount","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/BlocksWordCountRequestInput"},"response": {"anyOf": [@@ -15388,7 +16427,7 @@]},"data": {- "$ref": "#/$defs/BlockRelevantData"+ "$ref": "#/$defs/WordCountData"},"msg": {"type": "string"@@ -15445,8 +16484,8 @@},{"method": "POST",- "path": "/api/block/getBlockSiblingID",- "handler": "getBlockSiblingID",+ "path": "/api/block/getChildBlocks",+ "handler": "getChildBlocks","body": "json","request": {"$ref": "#/$defs/BlockQueryRequestInput"@@ -15463,7 +16502,17 @@]},"data": {- "$ref": "#/$defs/BlockSiblingData"+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/ChildBlock"+ },+ {+ "type": "null"+ }+ ]+ }},"msg": {"type": "string"@@ -15520,11 +16569,11 @@},{"method": "POST",- "path": "/api/block/getBlockTreeInfos",- "handler": "getBlockTreeInfos",+ "path": "/api/block/getContentWordCount",+ "handler": "getContentWordCount","body": "json","request": {- "$ref": "#/$defs/BlocksQueryRequestInput"+ "$ref": "#/$defs/ContentWordCountRequestInput"},"response": {"anyOf": [@@ -15538,24 +16587,7 @@]},"data": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "anyOf": [- {- "$ref": "#/$defs/BlockTreeInfo"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/WordCountData"},"msg": {"type": "string"@@ -15612,11 +16644,11 @@},{"method": "POST",- "path": "/api/block/getBlocksIndexes",- "handler": "getBlocksIndexes",+ "path": "/api/block/getDOMText",+ "handler": "getDOMText","body": "json","request": {- "$ref": "#/$defs/BlocksQueryRequestInput"+ "$ref": "#/$defs/DOMTextRequestInput"},"response": {"anyOf": [@@ -15630,17 +16662,7 @@]},"data": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "type": "integer"- }- },- {- "type": "null"- }- ]+ "type": "string"},"msg": {"type": "string"@@ -15697,11 +16719,11 @@},{"method": "POST",- "path": "/api/block/getBlocksWordCount",- "handler": "getBlocksWordCount",+ "path": "/api/block/getDocBlocksOrders",+ "handler": "getDocBlocksOrders","body": "json","request": {- "$ref": "#/$defs/BlocksWordCountRequestInput"+ "$ref": "#/$defs/DocOrdersRequestInput"},"response": {"anyOf": [@@ -15714,9 +16736,19 @@0]},- "data": {- "$ref": "#/$defs/WordCountData"- },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },"msg": {"type": "string"}@@ -15772,11 +16804,11 @@},{"method": "POST",- "path": "/api/block/getChildBlocks",- "handler": "getChildBlocks",- "body": "json",+ "path": "/api/block/getDocHeadingLevelTransaction",+ "handler": "getDocHeadingLevelTransaction",+ "body": "structJSON","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/DocHeadingLevelRequestInput"},"response": {"anyOf": [@@ -15790,17 +16822,14 @@]},"data": {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/ChildBlock"- },- {- "type": "null"- }- ]- }+ "anyOf": [+ {+ "$ref": "#/$defs/DocHeadingLevelData"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -15857,11 +16886,11 @@},{"method": "POST",- "path": "/api/block/getContentWordCount",- "handler": "getContentWordCount",+ "path": "/api/block/getDocInfo",+ "handler": "getDocInfo","body": "json","request": {- "$ref": "#/$defs/ContentWordCountRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -15875,7 +16904,14 @@]},"data": {- "$ref": "#/$defs/WordCountData"+ "anyOf": [+ {+ "$ref": "#/$defs/DocInfo"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -15932,11 +16968,11 @@},{"method": "POST",- "path": "/api/block/getDOMText",- "handler": "getDOMText",+ "path": "/api/block/getDocsInfo",+ "handler": "getDocsInfo","body": "json","request": {- "$ref": "#/$defs/DOMTextRequestInput"+ "$ref": "#/$defs/DocsInfoRequestInput"},"response": {"anyOf": [@@ -15950,7 +16986,24 @@]},"data": {- "type": "string"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/DocInfo"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -16007,11 +17060,11 @@},{"method": "POST",- "path": "/api/block/getDocBlocksOrders",- "handler": "getDocBlocksOrders",+ "path": "/api/block/getHeadingChildrenDOM",+ "handler": "getHeadingChildrenDOM","body": "json","request": {- "$ref": "#/$defs/DocOrdersRequestInput"+ "$ref": "#/$defs/HeadingChildrenRequestInput"},"response": {"anyOf": [@@ -16025,17 +17078,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "type": "string"- }- },- {- "type": "null"- }- ]+ "type": "string"},"msg": {"type": "string"@@ -16092,11 +17135,11 @@},{"method": "POST",- "path": "/api/block/getDocHeadingLevelTransaction",- "handler": "getDocHeadingLevelTransaction",- "body": "structJSON",+ "path": "/api/block/getHeadingChildrenIDs",+ "handler": "getHeadingChildrenIDs",+ "body": "json","request": {- "$ref": "#/$defs/DocHeadingLevelRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -16112,7 +17155,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/DocHeadingLevelData"+ "type": "array",+ "items": {+ "type": "string"+ }},{"type": "null"@@ -16174,11 +17220,11 @@},{"method": "POST",- "path": "/api/block/getDocInfo",- "handler": "getDocInfo",+ "path": "/api/block/getHeadingDeleteTransaction",+ "handler": "getHeadingDeleteTransaction","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -16194,7 +17240,7 @@"data": {"anyOf": [{- "$ref": "#/$defs/DocInfo"+ "$ref": "#/$defs/BlockTransaction"},{"type": "null"@@ -16256,11 +17302,11 @@},{"method": "POST",- "path": "/api/block/getDocsInfo",- "handler": "getDocsInfo",+ "path": "/api/block/getHeadingFoldTransaction",+ "handler": "getHeadingFoldTransaction","body": "json","request": {- "$ref": "#/$defs/DocsInfoRequestInput"+ "$ref": "#/$defs/HeadingFoldRequestInput"},"response": {"anyOf": [@@ -16276,17 +17322,7 @@"data": {"anyOf": [{- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/DocInfo"- },- {- "type": "null"- }- ]- }+ "$ref": "#/$defs/BlockTransaction"},{"type": "null"@@ -16348,11 +17384,11 @@},{"method": "POST",- "path": "/api/block/getHeadingChildrenDOM",- "handler": "getHeadingChildrenDOM",+ "path": "/api/block/getHeadingInsertTransaction",+ "handler": "getHeadingInsertTransaction","body": "json","request": {- "$ref": "#/$defs/HeadingChildrenRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -16366,7 +17402,14 @@]},"data": {- "type": "string"+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -16423,11 +17466,11 @@},{"method": "POST",- "path": "/api/block/getHeadingChildrenIDs",- "handler": "getHeadingChildrenIDs",+ "path": "/api/block/getHeadingLevelTransaction",+ "handler": "getHeadingLevelTransaction","body": "json","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/HeadingLevelRequestInput"},"response": {"anyOf": [@@ -16443,10 +17486,7 @@"data": {"anyOf": [{- "type": "array",- "items": {- "type": "string"- }+ "$ref": "#/$defs/BlockTransaction"},{"type": "null"@@ -16508,11 +17548,11 @@},{"method": "POST",- "path": "/api/block/getHeadingDeleteTransaction",- "handler": "getHeadingDeleteTransaction",+ "path": "/api/block/getOrderedListContinueStart",+ "handler": "getOrderedListContinueStart","body": "json","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -16526,14 +17566,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/OrderedListStartData"},"msg": {"type": "string"@@ -16590,11 +17623,11 @@},{"method": "POST",- "path": "/api/block/getHeadingFoldTransaction",- "handler": "getHeadingFoldTransaction",- "body": "json",+ "path": "/api/block/getRecentUpdatedBlocks",+ "handler": "getRecentUpdatedBlocks",+ "body": "none","request": {- "$ref": "#/$defs/HeadingFoldRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -16610,7 +17643,17 @@"data": {"anyOf": [{- "$ref": "#/$defs/BlockTransaction"+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/SearchBlock"+ },+ {+ "type": "null"+ }+ ]+ }},{"type": "null"@@ -16672,11 +17715,11 @@},{"method": "POST",- "path": "/api/block/getHeadingInsertTransaction",- "handler": "getHeadingInsertTransaction",+ "path": "/api/block/getRefIDs",+ "handler": "getRefIDs","body": "json","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/RefIDsRequestInput"},"response": {"anyOf": [@@ -16690,14 +17733,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/RefIDsData"},"msg": {"type": "string"@@ -16754,11 +17790,11 @@},{"method": "POST",- "path": "/api/block/getHeadingLevelTransaction",- "handler": "getHeadingLevelTransaction",+ "path": "/api/block/getRefIDsByFileAnnotationID",+ "handler": "getRefIDsByFileAnnotationID","body": "json","request": {- "$ref": "#/$defs/HeadingLevelRequestInput"+ "$ref": "#/$defs/FileAnnotationRefRequestInput"},"response": {"anyOf": [@@ -16772,14 +17808,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/RefDefsData"},"msg": {"type": "string"@@ -16836,8 +17865,8 @@},{"method": "POST",- "path": "/api/block/getOrderedListContinueStart",- "handler": "getOrderedListContinueStart",+ "path": "/api/block/getRefText",+ "handler": "getRefText","body": "json","request": {"$ref": "#/$defs/BlockQueryRequestInput"@@ -16854,7 +17883,7 @@]},"data": {- "$ref": "#/$defs/OrderedListStartData"+ "type": "string"},"msg": {"type": "string"@@ -16911,11 +17940,11 @@},{"method": "POST",- "path": "/api/block/getRecentUpdatedBlocks",- "handler": "getRecentUpdatedBlocks",- "body": "none",+ "path": "/api/block/getTailChildBlocks",+ "handler": "getTailChildBlocks",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/TailChildBlocksRequestInput"},"response": {"anyOf": [@@ -16923,31 +17952,24 @@"type": "object","properties": {"code": {- "type": "integer",- "enum": [- 0- ]- },- "data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/SearchBlock"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }+ "type": "integer",+ "enum": [+ 0]},+ "data": {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/ChildBlock"+ },+ {+ "type": "null"+ }+ ]+ }+ },"msg": {"type": "string"}@@ -17003,11 +18025,11 @@},{"method": "POST",- "path": "/api/block/getRefIDs",- "handler": "getRefIDs",+ "path": "/api/block/getTreeStat",+ "handler": "getTreeStat","body": "json","request": {- "$ref": "#/$defs/RefIDsRequestInput"+ "$ref": "#/$defs/TreeStatRequestInput"},"response": {"anyOf": [@@ -17021,7 +18043,7 @@]},"data": {- "$ref": "#/$defs/RefIDsData"+ "$ref": "#/$defs/TreeStatData"},"msg": {"type": "string"@@ -17078,11 +18100,11 @@},{"method": "POST",- "path": "/api/block/getRefIDsByFileAnnotationID",- "handler": "getRefIDsByFileAnnotationID",+ "path": "/api/block/getUnfoldedParentID",+ "handler": "getUnfoldedParentID","body": "json","request": {- "$ref": "#/$defs/FileAnnotationRefRequestInput"+ "$ref": "#/$defs/BlockQueryRequestInput"},"response": {"anyOf": [@@ -17096,7 +18118,7 @@]},"data": {- "$ref": "#/$defs/RefDefsData"+ "$ref": "#/$defs/UnfoldedParentData"},"msg": {"type": "string"@@ -17153,11 +18175,11 @@},{"method": "POST",- "path": "/api/block/getRefText",- "handler": "getRefText",+ "path": "/api/block/insertBlock",+ "handler": "insertBlock","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/InsertBlockRequestInput"},"response": {"anyOf": [@@ -17171,7 +18193,24 @@]},"data": {- "type": "string"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -17228,11 +18267,11 @@},{"method": "POST",- "path": "/api/block/getTailChildBlocks",- "handler": "getTailChildBlocks",+ "path": "/api/block/moveBlock",+ "handler": "moveBlock","body": "json","request": {- "$ref": "#/$defs/TailChildBlocksRequestInput"+ "$ref": "#/$defs/MoveBlockRequestInput"},"response": {"anyOf": [@@ -17246,17 +18285,7 @@]},"data": {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/ChildBlock"- },- {- "type": "null"- }- ]- }+ "type": "null"},"msg": {"type": "string"@@ -17313,11 +18342,11 @@},{"method": "POST",- "path": "/api/block/getTreeStat",- "handler": "getTreeStat",+ "path": "/api/block/moveOutlineHeading",+ "handler": "moveOutlineHeading","body": "json","request": {- "$ref": "#/$defs/TreeStatRequestInput"+ "$ref": "#/$defs/MoveBlockRequestInput"},"response": {"anyOf": [@@ -17331,7 +18360,24 @@]},"data": {- "$ref": "#/$defs/TreeStatData"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -17388,11 +18434,11 @@},{"method": "POST",- "path": "/api/block/getUnfoldedParentID",- "handler": "getUnfoldedParentID",+ "path": "/api/block/prependBlock",+ "handler": "prependBlock","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/PrependBlockRequestInput"},"response": {"anyOf": [@@ -17406,7 +18452,24 @@]},"data": {- "$ref": "#/$defs/UnfoldedParentData"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -17463,11 +18526,11 @@},{"method": "POST",- "path": "/api/block/insertBlock",- "handler": "insertBlock",+ "path": "/api/block/prependDailyNoteBlock",+ "handler": "prependDailyNoteBlock","body": "json","request": {- "$ref": "#/$defs/InsertBlockRequestInput"+ "$ref": "#/$defs/DailyNoteBlockRequestInput"},"response": {"anyOf": [@@ -17555,11 +18618,11 @@},{"method": "POST",- "path": "/api/block/moveBlock",- "handler": "moveBlock",+ "path": "/api/block/setBlockReminder",+ "handler": "setBlockReminder","body": "json","request": {- "$ref": "#/$defs/MoveBlockRequestInput"+ "$ref": "#/$defs/BlockReminderRequestInput"},"response": {"anyOf": [@@ -17630,11 +18693,11 @@},{"method": "POST",- "path": "/api/block/moveOutlineHeading",- "handler": "moveOutlineHeading",+ "path": "/api/block/swapBlockRef",+ "handler": "swapBlockRef","body": "json","request": {- "$ref": "#/$defs/MoveBlockRequestInput"+ "$ref": "#/$defs/SwapBlockRefRequestInput"},"response": {"anyOf": [@@ -17648,24 +18711,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -17722,11 +18768,11 @@},{"method": "POST",- "path": "/api/block/prependBlock",- "handler": "prependBlock",+ "path": "/api/block/transferBlockRef",+ "handler": "transferBlockRef","body": "json","request": {- "$ref": "#/$defs/PrependBlockRequestInput"+ "$ref": "#/$defs/TransferBlockRefRequestInput"},"response": {"anyOf": [@@ -17740,24 +18786,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -17814,11 +18843,11 @@},{"method": "POST",- "path": "/api/block/prependDailyNoteBlock",- "handler": "prependDailyNoteBlock",+ "path": "/api/block/unfoldBlock",+ "handler": "unfoldBlock","body": "json","request": {- "$ref": "#/$defs/DailyNoteBlockRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -17832,24 +18861,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -17906,11 +18918,11 @@},{"method": "POST",- "path": "/api/block/setBlockReminder",- "handler": "setBlockReminder",+ "path": "/api/block/updateBlock",+ "handler": "updateBlock","body": "json","request": {- "$ref": "#/$defs/BlockReminderRequestInput"+ "$ref": "#/$defs/UpdateBlockRequestInput"},"response": {"anyOf": [@@ -17924,7 +18936,24 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -17981,11 +19010,11 @@},{"method": "POST",- "path": "/api/block/swapBlockRef",- "handler": "swapBlockRef",+ "path": "/api/block/updateTaskListItemMarker",+ "handler": "updateTaskListItemMarker","body": "json","request": {- "$ref": "#/$defs/SwapBlockRefRequestInput"+ "$ref": "#/$defs/TaskListMarkerRequestInput"},"response": {"anyOf": [@@ -17998,9 +19027,26 @@0]},- "data": {- "type": "null"- },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },"msg": {"type": "string"}@@ -18056,11 +19102,11 @@},{"method": "POST",- "path": "/api/block/transferBlockRef",- "handler": "transferBlockRef",- "body": "json",+ "path": "/api/bookmark/getBookmark",+ "handler": "getBookmark",+ "body": "none","request": {- "$ref": "#/$defs/TransferBlockRefRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -18074,7 +19120,24 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/Bookmark"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -18131,11 +19194,11 @@},{"method": "POST",- "path": "/api/block/unfoldBlock",- "handler": "unfoldBlock",+ "path": "/api/bookmark/removeBookmark",+ "handler": "removeBookmark","body": "json","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/RemoveBookmarkRequestInput"},"response": {"anyOf": [@@ -18206,11 +19269,11 @@},{"method": "POST",- "path": "/api/block/updateBlock",- "handler": "updateBlock",+ "path": "/api/bookmark/renameBookmark",+ "handler": "renameBookmark","body": "json","request": {- "$ref": "#/$defs/UpdateBlockRequestInput"+ "$ref": "#/$defs/RenameBookmarkRequestInput"},"response": {"anyOf": [@@ -18224,24 +19287,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -18298,11 +19344,11 @@},{"method": "POST",- "path": "/api/block/updateTaskListItemMarker",- "handler": "updateTaskListItemMarker",+ "path": "/api/broadcast/getChannelInfo",+ "handler": "getChannelInfo","body": "json","request": {- "$ref": "#/$defs/TaskListMarkerRequestInput"+ "$ref": "#/$defs/BroadcastChannelRequestInput"},"response": {"anyOf": [@@ -18316,24 +19362,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/BlockTransaction"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/BroadcastChannelData"},"msg": {"type": "string"@@ -18390,8 +19419,8 @@},{"method": "POST",- "path": "/api/bookmark/getBookmark",- "handler": "getBookmark",+ "path": "/api/broadcast/getChannels",+ "handler": "getChannels","body": "none","request": {"$ref": "#/$defs/EmptyRequestInput"@@ -18408,24 +19437,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/Bookmark"- },- {- "type": "null"- }- ]- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/BroadcastChannelsData"},"msg": {"type": "string"@@ -18482,11 +19494,11 @@},{"method": "POST",- "path": "/api/bookmark/removeBookmark",- "handler": "removeBookmark",+ "path": "/api/broadcast/postMessage",+ "handler": "postMessage","body": "json","request": {- "$ref": "#/$defs/RemoveBookmarkRequestInput"+ "$ref": "#/$defs/BroadcastMessageRequestInput"},"response": {"anyOf": [@@ -18500,7 +19512,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/BroadcastChannelData"},"msg": {"type": "string"@@ -18519,7 +19531,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -18557,11 +19570,25 @@},{"method": "POST",- "path": "/api/bookmark/renameBookmark",- "handler": "renameBookmark",- "body": "json",+ "path": "/api/broadcast/publish",+ "handler": "broadcastPublish",+ "body": "multipart","request": {- "$ref": "#/$defs/RenameBookmarkRequestInput"+ "type": "object",+ "additionalProperties": {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "string",+ "format": "binary"+ }+ ]+ }+ }},"response": {"anyOf": [@@ -18575,7 +19602,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/BroadcastPublishData"},"msg": {"type": "string"@@ -18594,7 +19621,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -18632,11 +19660,11 @@},{"method": "POST",- "path": "/api/broadcast/getChannelInfo",- "handler": "getChannelInfo",+ "path": "/api/clipboard/cleanupRichText",+ "handler": "cleanupRichText","body": "json","request": {- "$ref": "#/$defs/BroadcastChannelRequestInput"+ "$ref": "#/$defs/CleanupRichTextRequestInput"},"response": {"anyOf": [@@ -18650,7 +19678,7 @@]},"data": {- "$ref": "#/$defs/BroadcastChannelData"+ "type": "null"},"msg": {"type": "string"@@ -18707,11 +19735,11 @@},{"method": "POST",- "path": "/api/broadcast/getChannels",- "handler": "getChannels",- "body": "none",+ "path": "/api/clipboard/prepareRichText",+ "handler": "prepareRichText",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/PrepareRichTextRequestInput"},"response": {"anyOf": [@@ -18725,7 +19753,14 @@]},"data": {- "$ref": "#/$defs/BroadcastChannelsData"+ "anyOf": [+ {+ "$ref": "#/$defs/RichClipboardPrepared"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -18782,11 +19817,11 @@},{"method": "POST",- "path": "/api/broadcast/postMessage",- "handler": "postMessage",- "body": "json",+ "path": "/api/clipboard/readFilePaths",+ "handler": "readFilePaths",+ "body": "none","request": {- "$ref": "#/$defs/BroadcastMessageRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -18800,7 +19835,10 @@]},"data": {- "$ref": "#/$defs/BroadcastChannelData"+ "type": "array",+ "items": {+ "$ref": "#/$defs/ClipboardFile"+ }},"msg": {"type": "string"@@ -18819,8 +19857,7 @@"code": {"type": "integer","enum": [- -1,- 1+ -1]},"data": {@@ -18858,25 +19895,11 @@},{"method": "POST",- "path": "/api/broadcast/publish",- "handler": "broadcastPublish",- "body": "multipart",+ "path": "/api/clipboard/writeFilePath",+ "handler": "writeFilePath",+ "body": "json","request": {- "type": "object",- "additionalProperties": {- "type": "array",- "items": {- "anyOf": [- {- "type": "string"- },- {- "type": "string",- "format": "binary"- }- ]- }- }+ "$ref": "#/$defs/ClipboardPathRequestInput"},"response": {"anyOf": [@@ -18890,7 +19913,7 @@]},"data": {- "$ref": "#/$defs/BroadcastPublishData"+ "type": "null"},"msg": {"type": "string"@@ -18909,8 +19932,7 @@"code": {"type": "integer","enum": [- -1,- 1+ -1]},"data": {@@ -18948,11 +19970,11 @@},{"method": "POST",- "path": "/api/clipboard/cleanupRichText",- "handler": "cleanupRichText",- "body": "json",+ "path": "/api/cloud/getCloudSpace",+ "handler": "getCloudSpace",+ "body": "none","request": {- "$ref": "#/$defs/CleanupRichTextRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -18966,7 +19988,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/CloudSpaceData"},"msg": {"type": "string"@@ -18985,7 +20007,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -19023,11 +20046,11 @@},{"method": "POST",- "path": "/api/clipboard/prepareRichText",- "handler": "prepareRichText",+ "path": "/api/cloud/setCloudReminder",+ "handler": "setCloudReminder","body": "json","request": {- "$ref": "#/$defs/PrepareRichTextRequestInput"+ "$ref": "#/$defs/CloudReminderRequestInput"},"response": {"anyOf": [@@ -19041,14 +20064,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/RichClipboardPrepared"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -19105,11 +20121,11 @@},{"method": "POST",- "path": "/api/clipboard/readFilePaths",- "handler": "readFilePaths",- "body": "none",+ "path": "/api/convert/pandoc",+ "handler": "pandoc",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/PandocRequestInput"},"response": {"anyOf": [@@ -19123,10 +20139,7 @@]},"data": {- "type": "array",- "items": {- "$ref": "#/$defs/ClipboardFile"- }+ "$ref": "#/$defs/PandocData"},"msg": {"type": "string"@@ -19183,11 +20196,11 @@},{"method": "POST",- "path": "/api/clipboard/writeFilePath",- "handler": "writeFilePath",+ "path": "/api/file/copyFile",+ "handler": "copyFile","body": "json","request": {- "$ref": "#/$defs/ClipboardPathRequestInput"+ "$ref": "#/$defs/CopyFileRequestInput"},"response": {"anyOf": [@@ -19220,7 +20233,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ -2]},"data": {@@ -19258,36 +20272,17 @@},{"method": "POST",- "path": "/api/cloud/getCloudSpace",- "handler": "getCloudSpace",- "body": "none",+ "path": "/api/file/getFile",+ "handler": "getFile",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/FilePathRequestInput"},"response": {"anyOf": [{- "type": "object",- "properties": {- "code": {- "type": "integer",- "enum": [- 0- ]- },- "data": {- "$ref": "#/$defs/CloudSpaceData"- },- "msg": {- "type": "string"- }- },- "required": [- "code",- "msg",- "data"- ],- "additionalProperties": false+ "type": "string",+ "format": "binary"},{"type": "object",@@ -19296,7 +20291,12 @@"type": "integer","enum": [-1,- 1+ -3,+ 403,+ 404,+ 409,+ 500,+ 503]},"data": {@@ -19330,15 +20330,17 @@"additionalProperties": true}]- }+ },+ "output": "binary",+ "errorStatus": 202},{"method": "POST",- "path": "/api/cloud/setCloudReminder",- "handler": "setCloudReminder",+ "path": "/api/file/getUniqueFilename",+ "handler": "getUniqueFilename","body": "json","request": {- "$ref": "#/$defs/CloudReminderRequestInput"+ "$ref": "#/$defs/FilePathRequestInput"},"response": {"anyOf": [@@ -19352,7 +20354,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/FilePathData"},"msg": {"type": "string"@@ -19371,7 +20373,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ -3]},"data": {@@ -19409,11 +20412,11 @@},{"method": "POST",- "path": "/api/convert/pandoc",- "handler": "pandoc",+ "path": "/api/file/globalCopyFiles",+ "handler": "globalCopyFiles","body": "json","request": {- "$ref": "#/$defs/PandocRequestInput"+ "$ref": "#/$defs/CopyFilesRequestInput"},"response": {"anyOf": [@@ -19427,7 +20430,7 @@]},"data": {- "$ref": "#/$defs/PandocData"+ "type": "null"},"msg": {"type": "string"@@ -19446,7 +20449,10 @@"code": {"type": "integer","enum": [- -1+ -1,+ -2,+ -3,+ 403]},"data": {@@ -19484,11 +20490,11 @@},{"method": "POST",- "path": "/api/file/copyFile",- "handler": "copyFile",- "body": "json",+ "path": "/api/file/putFile",+ "handler": "putFile",+ "body": "form","request": {- "$ref": "#/$defs/CopyFileRequestInput"+ "$ref": "#/$defs/PutFileRequestInput"},"response": {"anyOf": [@@ -19522,7 +20528,10 @@"type": "integer","enum": [-1,- -2+ -3,+ 400,+ 403,+ 500]},"data": {@@ -19560,17 +20569,39 @@},{"method": "POST",- "path": "/api/file/getFile",- "handler": "getFile",+ "path": "/api/file/readDir",+ "handler": "readDir","body": "json","request": {- "$ref": "#/$defs/FilePathRequestInput"+ "$ref": "#/$defs/ReadDirectoryRequestInput"},"response": {"anyOf": [{- "type": "string",- "format": "binary"+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/DirectoryEntry"+ }+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false},{"type": "object",@@ -19583,8 +20614,7 @@403,404,409,- 500,- 503+ 500]},"data": {@@ -19618,17 +20648,15 @@"additionalProperties": true}]- },- "output": "binary",- "errorStatus": 202+ }},{"method": "POST",- "path": "/api/file/getUniqueFilename",- "handler": "getUniqueFilename",+ "path": "/api/file/removeFile",+ "handler": "removeFile","body": "json","request": {- "$ref": "#/$defs/FilePathRequestInput"+ "$ref": "#/$defs/RemoveFileRequestInput"},"response": {"anyOf": [@@ -19642,7 +20670,7 @@]},"data": {- "$ref": "#/$defs/FilePathData"+ "type": "null"},"msg": {"type": "string"@@ -19662,7 +20690,10 @@"type": "integer","enum": [-1,- -3+ -3,+ 403,+ 404,+ 500]},"data": {@@ -19700,11 +20731,11 @@},{"method": "POST",- "path": "/api/file/globalCopyFiles",- "handler": "globalCopyFiles",+ "path": "/api/file/renameFile",+ "handler": "renameFile","body": "json","request": {- "$ref": "#/$defs/CopyFilesRequestInput"+ "$ref": "#/$defs/RenameFileRequestInput"},"response": {"anyOf": [@@ -19738,9 +20769,11 @@"type": "integer","enum": [-1,- -2,-3,- 403+ 403,+ 404,+ 409,+ 500]},"data": {@@ -19778,11 +20811,11 @@},{"method": "POST",- "path": "/api/file/putFile",- "handler": "putFile",- "body": "form",+ "path": "/api/file/workspaceCopyFiles",+ "handler": "workspaceCopyFiles",+ "body": "json","request": {- "$ref": "#/$defs/PutFileRequestInput"+ "$ref": "#/$defs/CopyFilesRequestInput"},"response": {"anyOf": [@@ -19816,10 +20849,9 @@"type": "integer","enum": [-1,+ -2,-3,- 400,- 403,- 500+ 403]},"data": {@@ -19857,11 +20889,11 @@},{"method": "POST",- "path": "/api/file/readDir",- "handler": "readDir",- "body": "json",+ "path": "/api/filetree/getPinnedDocs",+ "handler": "getPinnedDocs",+ "body": "none","request": {- "$ref": "#/$defs/ReadDirectoryRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -19877,7 +20909,7 @@"data": {"type": "array","items": {- "$ref": "#/$defs/DirectoryEntry"+ "$ref": "#/$defs/PinnedDoc"}},"msg": {@@ -19897,12 +20929,7 @@"code": {"type": "integer","enum": [- -1,- -3,- 403,- 404,- 409,- 500+ -1]},"data": {@@ -19940,11 +20967,11 @@},{"method": "POST",- "path": "/api/file/removeFile",- "handler": "removeFile",+ "path": "/api/filetree/updatePinnedDocs",+ "handler": "updatePinnedDocs","body": "json","request": {- "$ref": "#/$defs/RemoveFileRequestInput"+ "$ref": "#/$defs/UpdatePinnedDocsRequestInput"},"response": {"anyOf": [@@ -19977,11 +21004,7 @@"code": {"type": "integer","enum": [- -1,- -3,- 403,- 404,- 500+ -1]},"data": {@@ -20019,11 +21042,11 @@},{"method": "POST",- "path": "/api/file/renameFile",- "handler": "renameFile",+ "path": "/api/format/autoSpace",+ "handler": "autoSpace","body": "json","request": {- "$ref": "#/$defs/RenameFileRequestInput"+ "$ref": "#/$defs/TrimmedIDRequestInput"},"response": {"anyOf": [@@ -20056,12 +21079,7 @@"code": {"type": "integer","enum": [- -1,- -3,- 403,- 404,- 409,- 500+ -1]},"data": {@@ -20099,11 +21117,11 @@},{"method": "POST",- "path": "/api/file/workspaceCopyFiles",- "handler": "workspaceCopyFiles",+ "path": "/api/format/netAssets2LocalAssets",+ "handler": "netAssets2LocalAssets","body": "json","request": {- "$ref": "#/$defs/CopyFilesRequestInput"+ "$ref": "#/$defs/TrimmedIDRequestInput"},"response": {"anyOf": [@@ -20136,10 +21154,7 @@"code": {"type": "integer","enum": [- -1,- -2,- -3,- 403+ -1]},"data": {@@ -20177,11 +21192,11 @@},{"method": "POST",- "path": "/api/filetree/getPinnedDocs",- "handler": "getPinnedDocs",- "body": "none",+ "path": "/api/format/netImg2LocalAssets",+ "handler": "netImg2LocalAssets",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/NetImageAssetsRequestInput"},"response": {"anyOf": [@@ -20195,10 +21210,7 @@]},"data": {- "type": "array",- "items": {- "$ref": "#/$defs/PinnedDoc"- }+ "type": "null"},"msg": {"type": "string"@@ -20255,11 +21267,11 @@},{"method": "POST",- "path": "/api/filetree/updatePinnedDocs",- "handler": "updatePinnedDocs",+ "path": "/api/graph/getGraph",+ "handler": "getGraph","body": "json","request": {- "$ref": "#/$defs/UpdatePinnedDocsRequestInput"+ "$ref": "#/$defs/GlobalGraphRequestInput"},"response": {"anyOf": [@@ -20273,7 +21285,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/GlobalGraphResult"+ },+ {+ "$ref": "#/$defs/GraphCorrelation"+ }+ ]},"msg": {"type": "string"@@ -20310,7 +21329,17 @@"additionalProperties": false},{- "type": "null"+ "type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/GlobalGraphResult"+ },+ {+ "$ref": "#/$defs/GraphCorrelation"+ }+ ]}]},@@ -20330,11 +21359,11 @@},{"method": "POST",- "path": "/api/format/autoSpace",- "handler": "autoSpace",+ "path": "/api/graph/getLocalGraph",+ "handler": "getLocalGraph","body": "json","request": {- "$ref": "#/$defs/TrimmedIDRequestInput"+ "$ref": "#/$defs/LocalGraphRequestInput"},"response": {"anyOf": [@@ -20348,7 +21377,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/LocalGraphResult"+ },+ {+ "$ref": "#/$defs/GraphCorrelation"+ }+ ]},"msg": {"type": "string"@@ -20386,6 +21422,16 @@},{"type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/LocalGraphResult"+ },+ {+ "$ref": "#/$defs/GraphCorrelation"+ }+ ]}]},@@ -20405,11 +21451,11 @@},{"method": "POST",- "path": "/api/format/netAssets2LocalAssets",- "handler": "netAssets2LocalAssets",- "body": "json",+ "path": "/api/graph/resetGraph",+ "handler": "resetGraph",+ "body": "none","request": {- "$ref": "#/$defs/TrimmedIDRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -20423,7 +21469,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/ResetGraphData"},"msg": {"type": "string"@@ -20480,11 +21526,11 @@},{"method": "POST",- "path": "/api/format/netImg2LocalAssets",- "handler": "netImg2LocalAssets",- "body": "json",+ "path": "/api/graph/resetLocalGraph",+ "handler": "resetLocalGraph",+ "body": "none","request": {- "$ref": "#/$defs/NetImageAssetsRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -20498,7 +21544,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/ResetLocalGraphData"},"msg": {"type": "string"@@ -20555,11 +21601,11 @@},{"method": "POST",- "path": "/api/graph/getGraph",- "handler": "getGraph",+ "path": "/api/graph/setGraphConf",+ "handler": "setGraphConf","body": "json","request": {- "$ref": "#/$defs/GlobalGraphRequestInput"+ "$ref": "#/$defs/SetGraphConfRequestInput"},"response": {"anyOf": [@@ -20575,10 +21621,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/GlobalGraphResult"+ "$ref": "#/$defs/GlobalGraphConf"},{- "$ref": "#/$defs/GraphCorrelation"+ "$ref": "#/$defs/LocalGraphConf"}]},@@ -20618,16 +21664,6 @@},{"type": "null"- },- {- "anyOf": [- {- "$ref": "#/$defs/GlobalGraphResult"- },- {- "$ref": "#/$defs/GraphCorrelation"- }- ]}]},@@ -20647,11 +21683,11 @@},{"method": "POST",- "path": "/api/graph/getLocalGraph",- "handler": "getLocalGraph",- "body": "json",+ "path": "/api/history/clearWorkspaceHistory",+ "handler": "clearWorkspaceHistory",+ "body": "none","request": {- "$ref": "#/$defs/LocalGraphRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -20665,14 +21701,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/LocalGraphResult"- },- {- "$ref": "#/$defs/GraphCorrelation"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -20710,16 +21739,6 @@},{"type": "null"- },- {- "anyOf": [- {- "$ref": "#/$defs/LocalGraphResult"- },- {- "$ref": "#/$defs/GraphCorrelation"- }- ]}]},@@ -20739,11 +21758,11 @@},{"method": "POST",- "path": "/api/graph/resetGraph",- "handler": "resetGraph",- "body": "none",+ "path": "/api/history/createAssetHistory",+ "handler": "createAssetHistory",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/CreateAssetHistoryRequestInput"},"response": {"anyOf": [@@ -20757,7 +21776,7 @@]},"data": {- "$ref": "#/$defs/ResetGraphData"+ "type": "null"},"msg": {"type": "string"@@ -20814,11 +21833,11 @@},{"method": "POST",- "path": "/api/graph/resetLocalGraph",- "handler": "resetLocalGraph",- "body": "none",+ "path": "/api/history/createDocHistory",+ "handler": "createDocHistory",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/CreateDocHistoryRequestInput"},"response": {"anyOf": [@@ -20832,7 +21851,7 @@]},"data": {- "$ref": "#/$defs/ResetLocalGraphData"+ "type": "null"},"msg": {"type": "string"@@ -20889,11 +21908,11 @@},{"method": "POST",- "path": "/api/graph/setGraphConf",- "handler": "setGraphConf",+ "path": "/api/history/diffDocVersions",+ "handler": "diffDocVersions","body": "json","request": {- "$ref": "#/$defs/SetGraphConfRequestInput"+ "$ref": "#/$defs/DiffDocVersionsRequestInput"},"response": {"anyOf": [@@ -20909,10 +21928,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/GlobalGraphConf"+ "$ref": "#/$defs/DocVersionDiffResult"},{- "$ref": "#/$defs/LocalGraphConf"+ "type": "null"}]},@@ -20971,11 +21990,11 @@},{"method": "POST",- "path": "/api/history/clearWorkspaceHistory",- "handler": "clearWorkspaceHistory",- "body": "none",+ "path": "/api/history/getDocHistoryContent",+ "handler": "getDocHistoryContent",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/DocHistoryContentRequestInput"},"response": {"anyOf": [@@ -20989,7 +22008,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/DocHistoryContentData"},"msg": {"type": "string"@@ -21046,11 +22065,11 @@},{"method": "POST",- "path": "/api/history/createAssetHistory",- "handler": "createAssetHistory",+ "path": "/api/history/getHistoryItems",+ "handler": "getHistoryItems","body": "json","request": {- "$ref": "#/$defs/CreateAssetHistoryRequestInput"+ "$ref": "#/$defs/HistoryItemsRequestInput"},"response": {"anyOf": [@@ -21064,7 +22083,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/HistoryItemsData"},"msg": {"type": "string"@@ -21121,11 +22140,11 @@},{"method": "POST",- "path": "/api/history/createDocHistory",- "handler": "createDocHistory",- "body": "json",+ "path": "/api/history/getNotebookHistory",+ "handler": "getNotebookHistory",+ "body": "none","request": {- "$ref": "#/$defs/CreateDocHistoryRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -21139,7 +22158,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/NotebookHistoryData"},"msg": {"type": "string"@@ -21196,11 +22215,11 @@},{"method": "POST",- "path": "/api/history/diffDocVersions",- "handler": "diffDocVersions",- "body": "json",+ "path": "/api/history/reindexHistory",+ "handler": "reindexHistory",+ "body": "none","request": {- "$ref": "#/$defs/DiffDocVersionsRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -21214,14 +22233,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/DocVersionDiffResult"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -21278,11 +22290,11 @@},{"method": "POST",- "path": "/api/history/getDocHistoryContent",- "handler": "getDocHistoryContent",+ "path": "/api/history/rollbackAssetsHistory",+ "handler": "rollbackAssetsHistory","body": "json","request": {- "$ref": "#/$defs/DocHistoryContentRequestInput"+ "$ref": "#/$defs/HistoryPathRequestInput"},"response": {"anyOf": [@@ -21296,7 +22308,7 @@]},"data": {- "$ref": "#/$defs/DocHistoryContentData"+ "type": "null"},"msg": {"type": "string"@@ -21353,11 +22365,11 @@},{"method": "POST",- "path": "/api/history/getHistoryItems",- "handler": "getHistoryItems",+ "path": "/api/history/rollbackAttributeViewHistory",+ "handler": "rollbackAttributeViewHistory","body": "json","request": {- "$ref": "#/$defs/HistoryItemsRequestInput"+ "$ref": "#/$defs/HistoryPathRequestInput"},"response": {"anyOf": [@@ -21371,7 +22383,7 @@]},"data": {- "$ref": "#/$defs/HistoryItemsData"+ "type": "null"},"msg": {"type": "string"@@ -21428,11 +22440,11 @@},{"method": "POST",- "path": "/api/history/getNotebookHistory",- "handler": "getNotebookHistory",- "body": "none",+ "path": "/api/history/rollbackDocHistory",+ "handler": "rollbackDocHistory",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/HistoryPathRequestInput"},"response": {"anyOf": [@@ -21446,7 +22458,7 @@]},"data": {- "$ref": "#/$defs/NotebookHistoryData"+ "type": "null"},"msg": {"type": "string"@@ -21503,11 +22515,11 @@},{"method": "POST",- "path": "/api/history/reindexHistory",- "handler": "reindexHistory",- "body": "none",+ "path": "/api/history/rollbackNotebookHistory",+ "handler": "rollbackNotebookHistory",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/HistoryPathRequestInput"},"response": {"anyOf": [@@ -21578,11 +22590,11 @@},{"method": "POST",- "path": "/api/history/rollbackAssetsHistory",- "handler": "rollbackAssetsHistory",+ "path": "/api/history/searchHistory",+ "handler": "searchHistory","body": "json","request": {- "$ref": "#/$defs/HistoryPathRequestInput"+ "$ref": "#/$defs/SearchHistoryRequestInput"},"response": {"anyOf": [@@ -21596,7 +22608,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/SearchHistoryData"},"msg": {"type": "string"@@ -21653,11 +22665,11 @@},{"method": "POST",- "path": "/api/history/rollbackAttributeViewHistory",- "handler": "rollbackAttributeViewHistory",+ "path": "/api/import/cancelImportSY",+ "handler": "cancelImportSY","body": "json","request": {- "$ref": "#/$defs/HistoryPathRequestInput"+ "$ref": "#/$defs/ImportTokenRequestInput"},"response": {"anyOf": [@@ -21728,11 +22740,11 @@},{"method": "POST",- "path": "/api/history/rollbackDocHistory",- "handler": "rollbackDocHistory",+ "path": "/api/import/cancelObsidianVaultTask",+ "handler": "cancelObsidianVaultTask","body": "json","request": {- "$ref": "#/$defs/HistoryPathRequestInput"+ "$ref": "#/$defs/ObsidianTaskRequestInput"},"response": {"anyOf": [@@ -21746,7 +22758,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/ObsidianVaultTask"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -21784,6 +22803,16 @@},{"type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/ObsidianVaultTask"+ },+ {+ "type": "null"+ }+ ]}]},@@ -21803,11 +22832,11 @@},{"method": "POST",- "path": "/api/history/rollbackNotebookHistory",- "handler": "rollbackNotebookHistory",+ "path": "/api/import/continueImportSY",+ "handler": "continueImportSY","body": "json","request": {- "$ref": "#/$defs/HistoryPathRequestInput"+ "$ref": "#/$defs/ContinueImportSYRequestInput"},"response": {"anyOf": [@@ -21821,7 +22850,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/ImportDocumentData"},"msg": {"type": "string"@@ -21878,11 +22907,11 @@},{"method": "POST",- "path": "/api/history/searchHistory",- "handler": "searchHistory",+ "path": "/api/import/getObsidianVaultTask",+ "handler": "getObsidianVaultTask","body": "json","request": {- "$ref": "#/$defs/SearchHistoryRequestInput"+ "$ref": "#/$defs/ObsidianTaskRequestInput"},"response": {"anyOf": [@@ -21896,7 +22925,14 @@]},"data": {- "$ref": "#/$defs/SearchHistoryData"+ "anyOf": [+ {+ "$ref": "#/$defs/ObsidianVaultTask"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -21953,11 +22989,11 @@},{"method": "POST",- "path": "/api/import/cancelImportSY",- "handler": "cancelImportSY",- "body": "json",+ "path": "/api/import/importData",+ "handler": "importData",+ "body": "multipart","request": {- "$ref": "#/$defs/ImportTokenRequestInput"+ "$ref": "#/$defs/ImportDataRequestInput"},"response": {"anyOf": [@@ -22028,11 +23064,11 @@},{"method": "POST",- "path": "/api/import/cancelObsidianVaultTask",- "handler": "cancelObsidianVaultTask",- "body": "json",+ "path": "/api/import/importSY",+ "handler": "importSY",+ "body": "multipart","request": {- "$ref": "#/$defs/ObsidianTaskRequestInput"+ "$ref": "#/$defs/ImportSYRequestInput"},"response": {"anyOf": [@@ -22046,14 +23082,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/ObsidianVaultTask"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -22091,16 +23120,6 @@},{"type": "null"- },- {- "anyOf": [- {- "$ref": "#/$defs/ObsidianVaultTask"- },- {- "type": "null"- }- ]}]},@@ -22120,11 +23139,11 @@},{"method": "POST",- "path": "/api/import/continueImportSY",- "handler": "continueImportSY",- "body": "json",+ "path": "/api/import/importSYAuto",+ "handler": "importSYAuto",+ "body": "multipart","request": {- "$ref": "#/$defs/ContinueImportSYRequestInput"+ "$ref": "#/$defs/ImportSYRequestInput"},"response": {"anyOf": [@@ -22138,7 +23157,17 @@]},"data": {- "$ref": "#/$defs/ImportDocumentData"+ "anyOf": [+ {+ "$ref": "#/$defs/ImportAutoDocument"+ },+ {+ "$ref": "#/$defs/ImportAutoNotebook"+ },+ {+ "$ref": "#/$defs/ImportAutoNotebooks"+ }+ ]},"msg": {"type": "string"@@ -22176,6 +23205,19 @@},{"type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/ImportAutoDocument"+ },+ {+ "$ref": "#/$defs/ImportAutoNotebook"+ },+ {+ "$ref": "#/$defs/ImportAutoNotebooks"+ }+ ]}]},@@ -22195,11 +23237,11 @@},{"method": "POST",- "path": "/api/import/getObsidianVaultTask",- "handler": "getObsidianVaultTask",- "body": "json",+ "path": "/api/import/importSYNotebook",+ "handler": "importSYNotebook",+ "body": "multipart","request": {- "$ref": "#/$defs/ObsidianTaskRequestInput"+ "$ref": "#/$defs/ImportDataRequestInput"},"response": {"anyOf": [@@ -22215,10 +23257,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/ObsidianVaultTask"+ "$ref": "#/$defs/ImportedNotebook"},{- "type": "null"+ "$ref": "#/$defs/ImportedNotebooks"}]},@@ -22277,11 +23319,11 @@},{"method": "POST",- "path": "/api/import/importData",- "handler": "importData",- "body": "multipart",+ "path": "/api/import/importStdMd",+ "handler": "importStdMd",+ "body": "json","request": {- "$ref": "#/$defs/ImportDataRequestInput"+ "$ref": "#/$defs/ImportMarkdownRequestInput"},"response": {"anyOf": [@@ -22352,11 +23394,11 @@},{"method": "POST",- "path": "/api/import/importSY",- "handler": "importSY",+ "path": "/api/import/importZipMd",+ "handler": "importZipMd","body": "multipart","request": {- "$ref": "#/$defs/ImportSYRequestInput"+ "$ref": "#/$defs/ImportZipMarkdownRequestInput"},"response": {"anyOf": [@@ -22427,11 +23469,11 @@},{"method": "POST",- "path": "/api/import/importSYAuto",- "handler": "importSYAuto",- "body": "multipart",+ "path": "/api/import/startObsidianVaultAnalysis",+ "handler": "startObsidianVaultAnalysis",+ "body": "json","request": {- "$ref": "#/$defs/ImportSYRequestInput"+ "$ref": "#/$defs/ObsidianAnalysisRequestInput"},"response": {"anyOf": [@@ -22447,13 +23489,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/ImportAutoDocument"- },- {- "$ref": "#/$defs/ImportAutoNotebook"+ "$ref": "#/$defs/ObsidianVaultTask"},{- "$ref": "#/$defs/ImportAutoNotebooks"+ "type": "null"}]},@@ -22493,19 +23532,6 @@},{"type": "null"- },- {- "anyOf": [- {- "$ref": "#/$defs/ImportAutoDocument"- },- {- "$ref": "#/$defs/ImportAutoNotebook"- },- {- "$ref": "#/$defs/ImportAutoNotebooks"- }- ]}]},@@ -22525,11 +23551,11 @@},{"method": "POST",- "path": "/api/import/importSYNotebook",- "handler": "importSYNotebook",- "body": "multipart",+ "path": "/api/import/startObsidianVaultImport",+ "handler": "startObsidianVaultImport",+ "body": "json","request": {- "$ref": "#/$defs/ImportDataRequestInput"+ "$ref": "#/$defs/ObsidianImportRequestInput"},"response": {"anyOf": [@@ -22545,10 +23571,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/ImportedNotebook"+ "$ref": "#/$defs/ObsidianVaultTask"},{- "$ref": "#/$defs/ImportedNotebooks"+ "type": "null"}]},@@ -22607,11 +23633,11 @@},{"method": "POST",- "path": "/api/import/importStdMd",- "handler": "importStdMd",+ "path": "/api/inbox/getShorthand",+ "handler": "getShorthand","body": "json","request": {- "$ref": "#/$defs/ImportMarkdownRequestInput"+ "$ref": "#/$defs/TrimmedIDRequestInput"},"response": {"anyOf": [@@ -22625,7 +23651,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/Shorthand"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -22644,7 +23677,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -22682,11 +23716,11 @@},{"method": "POST",- "path": "/api/import/importZipMd",- "handler": "importZipMd",- "body": "multipart",+ "path": "/api/inbox/getShorthands",+ "handler": "getShorthands",+ "body": "json","request": {- "$ref": "#/$defs/ImportZipMarkdownRequestInput"+ "$ref": "#/$defs/ShorthandsRequestInput"},"response": {"anyOf": [@@ -22700,7 +23734,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/ShorthandsData"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -22719,7 +23760,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -22757,11 +23799,11 @@},{"method": "POST",- "path": "/api/import/startObsidianVaultAnalysis",- "handler": "startObsidianVaultAnalysis",+ "path": "/api/inbox/removeShorthands",+ "handler": "removeShorthands","body": "json","request": {- "$ref": "#/$defs/ObsidianAnalysisRequestInput"+ "$ref": "#/$defs/RemoveShorthandsRequestInput"},"response": {"anyOf": [@@ -22775,14 +23817,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/ObsidianVaultTask"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -22801,7 +23836,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -22839,11 +23875,11 @@},{"method": "POST",- "path": "/api/import/startObsidianVaultImport",- "handler": "startObsidianVaultImport",+ "path": "/api/lute/copyStdMarkdown",+ "handler": "copyStdMarkdown","body": "json","request": {- "$ref": "#/$defs/ObsidianImportRequestInput"+ "$ref": "#/$defs/CopyStdMarkdownRequestInput"},"response": {"anyOf": [@@ -22857,14 +23893,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/ObsidianVaultTask"- },- {- "type": "null"- }- ]+ "type": "string"},"msg": {"type": "string"@@ -22921,11 +23950,11 @@},{"method": "POST",- "path": "/api/inbox/getShorthand",- "handler": "getShorthand",+ "path": "/api/lute/html2BlockDOM",+ "handler": "html2BlockDOM","body": "json","request": {- "$ref": "#/$defs/TrimmedIDRequestInput"+ "$ref": "#/$defs/HTMLClipboardRequestInput"},"response": {"anyOf": [@@ -22941,10 +23970,10 @@"data": {"anyOf": [{- "$ref": "#/$defs/Shorthand"+ "type": "string"},{- "type": "null"+ "$ref": "#/$defs/HTMLClipboardPreflight"}]},@@ -22965,8 +23994,7 @@"code": {"type": "integer","enum": [- -1,- 1+ -1]},"data": {@@ -23004,11 +24032,11 @@},{"method": "POST",- "path": "/api/inbox/getShorthands",- "handler": "getShorthands",+ "path": "/api/lute/md2html",+ "handler": "md2HTML","body": "json","request": {- "$ref": "#/$defs/ShorthandsRequestInput"+ "$ref": "#/$defs/MarkdownHTMLRequestInput"},"response": {"anyOf": [@@ -23022,14 +24050,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/ShorthandsData"- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/HTMLData"},"msg": {"type": "string"@@ -23048,8 +24069,7 @@"code": {"type": "integer","enum": [- -1,- 1+ -1]},"data": {@@ -23087,11 +24107,11 @@},{"method": "POST",- "path": "/api/inbox/removeShorthands",- "handler": "removeShorthands",+ "path": "/api/lute/spinBlockDOM",+ "handler": "spinBlockDOM","body": "json","request": {- "$ref": "#/$defs/RemoveShorthandsRequestInput"+ "$ref": "#/$defs/DOMTextRequestInput"},"response": {"anyOf": [@@ -23105,7 +24125,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/DOMData"},"msg": {"type": "string"@@ -23125,7 +24145,7 @@"type": "integer","enum": [-1,- 1+ 413]},"data": {@@ -23163,11 +24183,11 @@},{"method": "POST",- "path": "/api/lute/copyStdMarkdown",- "handler": "copyStdMarkdown",+ "path": "/api/lute/wpsPresentation2BlockDOM",+ "handler": "wpsPresentation2BlockDOM","body": "json","request": {- "$ref": "#/$defs/CopyStdMarkdownRequestInput"+ "$ref": "#/$defs/WPSPresentationRequestInput"},"response": {"anyOf": [@@ -23181,7 +24201,7 @@]},"data": {- "type": "string"+ "$ref": "#/$defs/WPSPresentationData"},"msg": {"type": "string"@@ -23219,6 +24239,9 @@},{"type": "null"+ },+ {+ "$ref": "#/$defs/WPSPresentationData"}]},@@ -23238,11 +24261,11 @@},{"method": "POST",- "path": "/api/lute/html2BlockDOM",- "handler": "html2BlockDOM",+ "path": "/api/notebook/changeMasterPassword",+ "handler": "changeMasterPassword","body": "json","request": {- "$ref": "#/$defs/HTMLClipboardRequestInput"+ "$ref": "#/$defs/ChangeMasterPasswordRequestInput"},"response": {"anyOf": [@@ -23256,14 +24279,7 @@]},"data": {- "anyOf": [- {- "type": "string"- },- {- "$ref": "#/$defs/HTMLClipboardPreflight"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -23320,11 +24336,11 @@},{"method": "POST",- "path": "/api/lute/md2html",- "handler": "md2HTML",+ "path": "/api/notebook/changeSortNotebook",+ "handler": "changeSortNotebook","body": "json","request": {- "$ref": "#/$defs/MarkdownHTMLRequestInput"+ "$ref": "#/$defs/ChangeSortNotebookRequestInput"},"response": {"anyOf": [@@ -23338,7 +24354,7 @@]},"data": {- "$ref": "#/$defs/HTMLData"+ "type": "null"},"msg": {"type": "string"@@ -23395,11 +24411,11 @@},{"method": "POST",- "path": "/api/lute/spinBlockDOM",- "handler": "spinBlockDOM",+ "path": "/api/notebook/closeNotebook",+ "handler": "closeNotebook","body": "json","request": {- "$ref": "#/$defs/DOMTextRequestInput"+ "$ref": "#/$defs/CloseNotebookRequestInput"},"response": {"anyOf": [@@ -23413,7 +24429,7 @@]},"data": {- "$ref": "#/$defs/DOMData"+ "type": "null"},"msg": {"type": "string"@@ -23432,8 +24448,7 @@"code": {"type": "integer","enum": [- -1,- 413+ -1]},"data": {@@ -23471,11 +24486,11 @@},{"method": "POST",- "path": "/api/lute/wpsPresentation2BlockDOM",- "handler": "wpsPresentation2BlockDOM",+ "path": "/api/notebook/createEncryptedNotebook",+ "handler": "createEncryptedNotebook","body": "json","request": {- "$ref": "#/$defs/WPSPresentationRequestInput"+ "$ref": "#/$defs/CreateEncryptedNotebookRequestInput"},"response": {"anyOf": [@@ -23489,7 +24504,7 @@]},"data": {- "$ref": "#/$defs/WPSPresentationData"+ "$ref": "#/$defs/CreateNotebookData"},"msg": {"type": "string"@@ -23527,9 +24542,6 @@},{"type": "null"- },- {- "$ref": "#/$defs/WPSPresentationData"}]},@@ -23549,11 +24561,11 @@},{"method": "POST",- "path": "/api/notebook/changeMasterPassword",- "handler": "changeMasterPassword",+ "path": "/api/notebook/createNotebook",+ "handler": "createNotebook","body": "json","request": {- "$ref": "#/$defs/ChangeMasterPasswordRequestInput"+ "$ref": "#/$defs/CreateNotebookRequestInput"},"response": {"anyOf": [@@ -23567,7 +24579,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/CreateNotebookData"},"msg": {"type": "string"@@ -23624,11 +24636,11 @@},{"method": "POST",- "path": "/api/notebook/changeSortNotebook",- "handler": "changeSortNotebook",- "body": "json",+ "path": "/api/notebook/disableEncryptedNotebooks",+ "handler": "disableEncryptedNotebooks",+ "body": "none","request": {- "$ref": "#/$defs/ChangeSortNotebookRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -23699,11 +24711,11 @@},{"method": "POST",- "path": "/api/notebook/closeNotebook",- "handler": "closeNotebook",+ "path": "/api/notebook/enableEncryptedNotebooks",+ "handler": "enableEncryptedNotebooks","body": "json","request": {- "$ref": "#/$defs/CloseNotebookRequestInput"+ "$ref": "#/$defs/NotebookPasswordRequestInput"},"response": {"anyOf": [@@ -23774,11 +24786,11 @@},{"method": "POST",- "path": "/api/notebook/createEncryptedNotebook",- "handler": "createEncryptedNotebook",- "body": "json",+ "path": "/api/notebook/exportNotebookCryptoBackup",+ "handler": "exportNotebookCryptoBackup",+ "body": "none","request": {- "$ref": "#/$defs/CreateEncryptedNotebookRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -23792,7 +24804,7 @@]},"data": {- "$ref": "#/$defs/CreateNotebookData"+ "$ref": "#/$defs/NotebookCryptoBackupData"},"msg": {"type": "string"@@ -23849,11 +24861,11 @@},{"method": "POST",- "path": "/api/notebook/createNotebook",- "handler": "createNotebook",- "body": "json",+ "path": "/api/notebook/getEncryptedNotebookStatus",+ "handler": "getEncryptedNotebookStatus",+ "body": "none","request": {- "$ref": "#/$defs/CreateNotebookRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -23867,7 +24879,7 @@]},"data": {- "$ref": "#/$defs/CreateNotebookData"+ "$ref": "#/$defs/EncryptedNotebookStatusData"},"msg": {"type": "string"@@ -23924,11 +24936,11 @@},{"method": "POST",- "path": "/api/notebook/disableEncryptedNotebooks",- "handler": "disableEncryptedNotebooks",- "body": "none",+ "path": "/api/notebook/getNotebookConf",+ "handler": "getNotebookConf",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/CloseNotebookRequestInput"},"response": {"anyOf": [@@ -23942,7 +24954,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/NotebookConfData"},"msg": {"type": "string"@@ -23999,11 +25011,11 @@},{"method": "POST",- "path": "/api/notebook/enableEncryptedNotebooks",- "handler": "enableEncryptedNotebooks",+ "path": "/api/notebook/getNotebookInfo",+ "handler": "getNotebookInfo","body": "json","request": {- "$ref": "#/$defs/NotebookPasswordRequestInput"+ "$ref": "#/$defs/NotebookIDRequestInput"},"response": {"anyOf": [@@ -24017,7 +25029,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/NotebookInfoData"},"msg": {"type": "string"@@ -24074,11 +25086,11 @@},{"method": "POST",- "path": "/api/notebook/exportNotebookCryptoBackup",- "handler": "exportNotebookCryptoBackup",- "body": "none",+ "path": "/api/notebook/importNotebookCryptoBackup",+ "handler": "importNotebookCryptoBackup",+ "body": "multipart","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/ImportNotebookCryptoBackupRequestInput"},"response": {"anyOf": [@@ -24092,7 +25104,7 @@]},"data": {- "$ref": "#/$defs/NotebookCryptoBackupData"+ "type": "null"},"msg": {"type": "string"@@ -24149,11 +25161,11 @@},{"method": "POST",- "path": "/api/notebook/getEncryptedNotebookStatus",- "handler": "getEncryptedNotebookStatus",- "body": "none",+ "path": "/api/notebook/lockNotebook",+ "handler": "lockNotebook",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/NotebookIDRequestInput"},"response": {"anyOf": [@@ -24167,7 +25179,7 @@]},"data": {- "$ref": "#/$defs/EncryptedNotebookStatusData"+ "type": "null"},"msg": {"type": "string"@@ -24224,11 +25236,11 @@},{"method": "POST",- "path": "/api/notebook/getNotebookConf",- "handler": "getNotebookConf",- "body": "json",+ "path": "/api/notebook/lsNotebooks",+ "handler": "lsNotebooks",+ "body": "legacyOptional","request": {- "$ref": "#/$defs/CloseNotebookRequestInput"+ "$ref": "#/$defs/ListNotebooksRequestInput"},"response": {"anyOf": [@@ -24242,7 +25254,14 @@]},"data": {- "$ref": "#/$defs/NotebookConfData"+ "anyOf": [+ {+ "$ref": "#/$defs/ListNotebooksData"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -24299,11 +25318,11 @@},{"method": "POST",- "path": "/api/notebook/getNotebookInfo",- "handler": "getNotebookInfo",+ "path": "/api/notebook/openNotebook",+ "handler": "openNotebook","body": "json","request": {- "$ref": "#/$defs/NotebookIDRequestInput"+ "$ref": "#/$defs/OpenNotebookRequestInput"},"response": {"anyOf": [@@ -24317,7 +25336,7 @@]},"data": {- "$ref": "#/$defs/NotebookInfoData"+ "type": "null"},"msg": {"type": "string"@@ -24374,11 +25393,11 @@},{"method": "POST",- "path": "/api/notebook/importNotebookCryptoBackup",- "handler": "importNotebookCryptoBackup",- "body": "multipart",+ "path": "/api/notebook/removeNotebook",+ "handler": "removeNotebook",+ "body": "json","request": {- "$ref": "#/$defs/ImportNotebookCryptoBackupRequestInput"+ "$ref": "#/$defs/NotebookIDRequestInput"},"response": {"anyOf": [@@ -24449,11 +25468,11 @@},{"method": "POST",- "path": "/api/notebook/lockNotebook",- "handler": "lockNotebook",+ "path": "/api/notebook/renameNotebook",+ "handler": "renameNotebook","body": "json","request": {- "$ref": "#/$defs/NotebookIDRequestInput"+ "$ref": "#/$defs/RenameNotebookRequestInput"},"response": {"anyOf": [@@ -24524,11 +25543,11 @@},{"method": "POST",- "path": "/api/notebook/lsNotebooks",- "handler": "lsNotebooks",- "body": "legacyOptional",+ "path": "/api/notebook/reorder",+ "handler": "reorderNotebooks",+ "body": "structJSON","request": {- "$ref": "#/$defs/ListNotebooksRequestInput"+ "$ref": "#/$defs/ReorderNotebooksRequestInput"},"response": {"anyOf": [@@ -24544,7 +25563,7 @@"data": {"anyOf": [{- "$ref": "#/$defs/ListNotebooksData"+ "$ref": "#/$defs/ReorderData"},{"type": "null"@@ -24587,6 +25606,16 @@},{"type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/ReorderData"+ },+ {+ "type": "null"+ }+ ]}]},@@ -24606,11 +25635,11 @@},{"method": "POST",- "path": "/api/notebook/openNotebook",- "handler": "openNotebook",+ "path": "/api/notebook/setNotebookConf",+ "handler": "setNotebookConf","body": "json","request": {- "$ref": "#/$defs/OpenNotebookRequestInput"+ "$ref": "#/$defs/SetNotebookConfRequestInput"},"response": {"anyOf": [@@ -24624,7 +25653,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookConf"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -24681,11 +25717,11 @@},{"method": "POST",- "path": "/api/notebook/removeNotebook",- "handler": "removeNotebook",+ "path": "/api/notebook/setNotebookCryptoAutoLock",+ "handler": "setNotebookCryptoAutoLock","body": "json","request": {- "$ref": "#/$defs/NotebookIDRequestInput"+ "$ref": "#/$defs/NotebookCryptoAutoLockRequestInput"},"response": {"anyOf": [@@ -24756,11 +25792,11 @@},{"method": "POST",- "path": "/api/notebook/renameNotebook",- "handler": "renameNotebook",+ "path": "/api/notebook/setNotebookIcon",+ "handler": "setNotebookIcon","body": "json","request": {- "$ref": "#/$defs/RenameNotebookRequestInput"+ "$ref": "#/$defs/SetNotebookIconRequestInput"},"response": {"anyOf": [@@ -24831,11 +25867,11 @@},{"method": "POST",- "path": "/api/notebook/reorder",- "handler": "reorderNotebooks",- "body": "structJSON",+ "path": "/api/notebook/touchEncryptedNotebooks",+ "handler": "touchEncryptedNotebooks",+ "body": "none","request": {- "$ref": "#/$defs/ReorderNotebooksRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -24849,14 +25885,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/ReorderData"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -24893,17 +25922,7 @@"additionalProperties": false},{- "type": "null"- },- {- "anyOf": [- {- "$ref": "#/$defs/ReorderData"- },- {- "type": "null"- }- ]+ "type": "null"}]},@@ -24923,11 +25942,11 @@},{"method": "POST",- "path": "/api/notebook/setNotebookConf",- "handler": "setNotebookConf",+ "path": "/api/notebook/unlockAndOpenNotebook",+ "handler": "unlockAndOpenNotebook","body": "json","request": {- "$ref": "#/$defs/SetNotebookConfRequestInput"+ "$ref": "#/$defs/UnlockNotebookRequestInput"},"response": {"anyOf": [@@ -24941,14 +25960,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/NotebookConf"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -25005,11 +26017,11 @@},{"method": "POST",- "path": "/api/notebook/setNotebookCryptoAutoLock",- "handler": "setNotebookCryptoAutoLock",+ "path": "/api/notebook/unlockNotebook",+ "handler": "unlockNotebook","body": "json","request": {- "$ref": "#/$defs/NotebookCryptoAutoLockRequestInput"+ "$ref": "#/$defs/UnlockNotebookRequestInput"},"response": {"anyOf": [@@ -25080,11 +26092,11 @@},{"method": "POST",- "path": "/api/notebook/setNotebookIcon",- "handler": "setNotebookIcon",+ "path": "/api/notification/pushErrMsg",+ "handler": "pushErrMsg","body": "json","request": {- "$ref": "#/$defs/SetNotebookIconRequestInput"+ "$ref": "#/$defs/NotificationRequestInput"},"response": {"anyOf": [@@ -25098,7 +26110,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/NotificationData"},"msg": {"type": "string"@@ -25155,11 +26167,11 @@},{"method": "POST",- "path": "/api/notebook/touchEncryptedNotebooks",- "handler": "touchEncryptedNotebooks",- "body": "none",+ "path": "/api/notification/pushMsg",+ "handler": "pushMsg",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/NotificationRequestInput"},"response": {"anyOf": [@@ -25173,7 +26185,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/NotificationData"},"msg": {"type": "string"@@ -25230,11 +26242,11 @@},{"method": "POST",- "path": "/api/notebook/unlockAndOpenNotebook",- "handler": "unlockAndOpenNotebook",+ "path": "/api/outline/getDocHeadingNumbers",+ "handler": "getDocHeadingNumbers","body": "json","request": {- "$ref": "#/$defs/UnlockNotebookRequestInput"+ "$ref": "#/$defs/HeadingNumbersRequestInput"},"response": {"anyOf": [@@ -25248,7 +26260,17 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -25267,7 +26289,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -25305,11 +26328,11 @@},{"method": "POST",- "path": "/api/notebook/unlockNotebook",- "handler": "unlockNotebook",+ "path": "/api/outline/getDocOutline",+ "handler": "getDocOutline","body": "json","request": {- "$ref": "#/$defs/UnlockNotebookRequestInput"+ "$ref": "#/$defs/OutlineRequestInput"},"response": {"anyOf": [@@ -25323,7 +26346,24 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/SearchPath"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -25342,7 +26382,8 @@"code": {"type": "integer","enum": [- -1+ -1,+ 1]},"data": {@@ -25380,11 +26421,11 @@},{"method": "POST",- "path": "/api/notification/pushErrMsg",- "handler": "pushErrMsg",+ "path": "/api/petal/loadPetals",+ "handler": "loadPetals","body": "json","request": {- "$ref": "#/$defs/NotificationRequestInput"+ "$ref": "#/$defs/LoadPetalsRequestInput"},"response": {"anyOf": [@@ -25398,7 +26439,24 @@]},"data": {- "$ref": "#/$defs/NotificationData"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/Petal"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -25455,11 +26513,11 @@},{"method": "POST",- "path": "/api/notification/pushMsg",- "handler": "pushMsg",+ "path": "/api/petal/setPetalEnabled",+ "handler": "setPetalEnabled","body": "json","request": {- "$ref": "#/$defs/NotificationRequestInput"+ "$ref": "#/$defs/SetPetalEnabledRequestInput"},"response": {"anyOf": [@@ -25473,7 +26531,14 @@]},"data": {- "$ref": "#/$defs/NotificationData"+ "anyOf": [+ {+ "$ref": "#/$defs/Petal"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -25530,11 +26595,11 @@},{"method": "POST",- "path": "/api/outline/getDocHeadingNumbers",- "handler": "getDocHeadingNumbers",+ "path": "/api/petal/setPetalPublishEnabled",+ "handler": "setPetalPublishEnabled","body": "json","request": {- "$ref": "#/$defs/HeadingNumbersRequestInput"+ "$ref": "#/$defs/SetPetalPublishEnabledRequestInput"},"response": {"anyOf": [@@ -25550,10 +26615,7 @@"data": {"anyOf": [{- "type": "object",- "additionalProperties": {- "type": "string"- }+ "$ref": "#/$defs/Petal"},{"type": "null"@@ -25577,8 +26639,7 @@"code": {"type": "integer","enum": [- -1,- 1+ -1]},"data": {@@ -25616,11 +26677,11 @@},{"method": "POST",- "path": "/api/outline/getDocOutline",- "handler": "getDocOutline",+ "path": "/api/plugin/getLoadedPlugin",+ "handler": "getLoadedPlugin","body": "json","request": {- "$ref": "#/$defs/OutlineRequestInput"+ "$ref": "#/$defs/LoadedPluginRequestInput"},"response": {"anyOf": [@@ -25636,17 +26697,7 @@"data": {"anyOf": [{- "type": "array",- "items": {- "anyOf": [- {- "$ref": "#/$defs/SearchPath"- },- {- "type": "null"- }- ]- }+ "$ref": "#/$defs/LoadedPlugin"},{"type": "null"@@ -25671,7 +26722,10 @@"type": "integer","enum": [-1,- 1+ 1,+ 2,+ 3,+ 4]},"data": {@@ -25709,11 +26763,11 @@},{"method": "POST",- "path": "/api/petal/loadPetals",- "handler": "loadPetals",- "body": "json",+ "path": "/api/plugin/listLoadedPlugins",+ "handler": "listLoadedPlugins",+ "body": "none","request": {- "$ref": "#/$defs/LoadPetalsRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -25733,7 +26787,7 @@"items": {"anyOf": [{- "$ref": "#/$defs/Petal"+ "$ref": "#/$defs/LoadedPlugin"},{"type": "null"@@ -25801,43 +26855,52 @@},{"method": "POST",- "path": "/api/petal/setPetalEnabled",- "handler": "setPetalEnabled",+ "path": "/api/plugin/rpc",+ "handler": "pluginJsonRpcHttp","body": "json","request": {- "$ref": "#/$defs/SetPetalEnabledRequestInput"+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ {+ "type": "array",+ "items": {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ "minItems": 1+ }+ ]},"response": {"anyOf": [{- "type": "object",- "properties": {- "code": {- "type": "integer",- "enum": [- 0- ]- },- "data": {+ "anyOf": [+ {"anyOf": [{- "$ref": "#/$defs/Petal"+ "$ref": "#/$defs/PluginRPCSuccess"},{- "type": "null"+ "$ref": "#/$defs/PluginRPCFailure"}]},- "msg": {- "type": "string"+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCSuccess"+ },+ {+ "$ref": "#/$defs/PluginRPCFailure"+ }+ ]+ },+ "minItems": 1}- },- "required": [- "code",- "msg",- "data"- ],- "additionalProperties": false+ ]},{"type": "object",@@ -25879,47 +26942,58 @@"additionalProperties": true}]- }+ },+ "output": "directJSON",+ "noContent": true},{"method": "POST",- "path": "/api/petal/setPetalPublishEnabled",- "handler": "setPetalPublishEnabled",+ "path": "/api/plugin/rpc/:name",+ "handler": "pluginJsonRpcHttpByName","body": "json","request": {- "$ref": "#/$defs/SetPetalPublishEnabledRequestInput"+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ {+ "type": "array",+ "items": {+ "$ref": "#/$defs/PluginRPCRequestFieldsInput"+ },+ "minItems": 1+ }+ ]},"response": {"anyOf": [{- "type": "object",- "properties": {- "code": {- "type": "integer",- "enum": [- 0- ]- },- "data": {+ "anyOf": [+ {"anyOf": [{- "$ref": "#/$defs/Petal"+ "$ref": "#/$defs/PluginRPCSuccess"},{- "type": "null"+ "$ref": "#/$defs/PluginRPCFailure"}]},- "msg": {- "type": "string"+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/PluginRPCSuccess"+ },+ {+ "$ref": "#/$defs/PluginRPCFailure"+ }+ ]+ },+ "minItems": 1}- },- "required": [- "code",- "msg",- "data"- ],- "additionalProperties": false+ ]},{"type": "object",@@ -25961,7 +27035,9 @@"additionalProperties": true}]- }+ },+ "output": "directJSON",+ "noContent": true},{"method": "POST",diff --git a/kernel/apicontract/typescript.go b/kernel/apicontract/typescript.goindex 45024c4cfa..ff1f64add1 100644--- a/kernel/apicontract/typescript.go+++ b/kernel/apicontract/typescript.go@@ -38,15 +38,13 @@ func (b *Bundle) typeScript(schema *Schema) string {// 联合成员缺少的字段标记为可选 never,保留精确的属性存在性和判别能力。allProperties := map[string]bool{}objects := make([]*Schema, len(schema.AnyOf))- allObjects := truefor i, option := range schema.AnyOf {target := optionif option.Ref != "" {target = b.Definitions[strings.TrimPrefix(option.Ref, "#/$defs/")]}if target == nil || target.Type != "object" {- allObjects = false- break+ continue}objects[i] = targetfor key := range target.Properties {@@ -55,7 +53,7 @@ func (b *Bundle) typeScript(schema *Schema) string {}for i, option := range schema.AnyOf {variant := b.typeScript(option)- if allObjects {+ if objects[i] != nil {var absent []stringfor _, key := range sortedKeys(allProperties) {if _, exists := objects[i].Properties[key]; !exists {@@ -76,6 +74,10 @@ func (b *Bundle) typeScript(schema *Schema) string {case "null", "string", "boolean":return schema.Typecase "array":+ if schema.MinItems == 1 {+ item := b.typeScript(schema.Items)+ return "[" + item + ", ...Array<" + item + ">]"+ }return "Array<" + b.typeScript(schema.Items) + ">"case "object":if additional, ok := schema.AdditionalProperties.(*Schema); ok {@@ -140,6 +142,12 @@ func (b *Bundle) TypeScript(legacy []Route) []byte {if endpoint.Output != "" {fmt.Fprintf(&output, " output: %s;\n", quote(string(endpoint.Output)))}+ if endpoint.NoContent {+ output.WriteString(" noContent: true;\n")+ }+ if ws := endpoint.WebSocket; ws != nil {+ fmt.Fprintf(&output, " websocket: { incoming: %s; outgoing: %s; failureStatus: %d; };\n", b.typeScript(ws.Incoming), b.typeScript(ws.Outgoing), ws.FailureStatus)+ }output.WriteString(" };\n")}output.WriteString("}\n\n")@@ -185,8 +193,10 @@ export type APICallbackResponse<R> = R extends {code: infer C extends number}? NonNegative<C> extends never ? never : R & {code: NonNegative<C>}: never;+type APIDirectCallbackResponse<R> = R extends {code: number} ? APICallbackResponse<R> : R;+type APIPostTail<C extends APIContract> = [- cb?: (response: C extends {output: "binary"} ? JSONValue : APICallbackResponse<C["response"]>) => void,+ cb?: (response: C extends {output: "binary"} ? JSONValue : C extends {output: "directJSON"} ? APIDirectCallbackResponse<C["response"]> | (C extends {noContent: true} ? "" : never) : APICallbackResponse<C["response"]>) => void,headers?: Record<string, string>,failCallback?: (response: APIFetchFailure) => void,signal?: AbortSignal,@@ -224,7 +234,7 @@ export type FetchSyncPost<Legacy = APILegacyResponse> = <Path extends string>(export type FetchGet<Legacy = APILegacyResponse | string> = <Path extends string>(url: Path,...args: Path extends keyof APIGETRoutes- ? [cb: (response: APIGETRoutes[Path]["response"]) => void]+ ? [cb: (response: APIGETRoutes[Path]["response"] | (APIGETRoutes[Path] extends {output: "websocket"} ? string : never)) => void]: Path extends keyof APIPOSTRoutes ? never: [cb: (response: Legacy) => void]) => void;diff --git a/kernel/apicontract/websocket.go b/kernel/apicontract/websocket.gonew file mode 100644index 0000000000..78e9bc6738--- /dev/null+++ b/kernel/apicontract/websocket.go@@ -0,0 +1,57 @@+package apicontract++import (+ "encoding/json"+ "fmt"+ "net/http"+ "reflect"+)++// WebSocketDefinition 分别声明连接升级后的入站、出站消息和升级失败状态。+type WebSocketDefinition struct {+ Incoming reflect.Type+ Outgoing reflect.Type+ FailureStatus int+}++func WebSocketOptions[Incoming, Outgoing any](failureStatus int) ResponseOptions {+ return ResponseOptions{Output: WebSocketOutput, WebSocket: &WebSocketDefinition{+ Incoming: reflect.TypeFor[Incoming](), Outgoing: reflect.TypeFor[Outgoing](), FailureStatus: failureStatus,+ }}+}++// UpgradeWebSocket 延迟升级,使契约适配器在响应阶段接管连接生命周期。+func UpgradeWebSocket[Data any](serve func(http.ResponseWriter, *http.Request)) Response[Data] {+ if serve == nil {+ panic("WebSocket upgrade requires a connection handler")+ }+ return Response[Data]{upgrade: serve}+}++func RejectWebSocket[Data any](data Data) Response[Data] {+ return Response[Data]{data: data, websocketFailure: true}+}++func (r Response[Data]) Upgrade() func(http.ResponseWriter, *http.Request) { return r.upgrade }++// ValidateWebSocketMessage 校验消息载荷,不将 HTTP 中间件信封混入连接内的消息协议。+func (b *Bundle) ValidateWebSocketMessage(method, path string, incoming bool, payload []byte) error {+ for _, endpoint := range b.Endpoints {+ if endpoint.Method != method || endpoint.Path != path {+ continue+ }+ if endpoint.WebSocket == nil {+ return fmt.Errorf("endpoint does not declare WebSocket messages")+ }+ schema := endpoint.WebSocket.Outgoing+ if incoming {+ schema = endpoint.WebSocket.Incoming+ }+ var value any+ if err := json.Unmarshal(payload, &value); err != nil {+ return err+ }+ return b.validate(schema, value, "$")+ }+ return fmt.Errorf("unregistered API contract: %s %s", method, path)+}diff --git a/kernel/apicontract/websocket_test.go b/kernel/apicontract/websocket_test.gonew file mode 100644index 0000000000..c9ee846824--- /dev/null+++ b/kernel/apicontract/websocket_test.go@@ -0,0 +1,46 @@+package apicontract++import "testing"++func TestWebSocketContractValidation(t *testing.T) {+ bundle, err := BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ for _, entry := range []struct {+ incoming bool+ body string+ valid bool+ }{+ {true, `{"jsonrpc":"2.0","method":"call","id":1}`, true},+ {true, `[]`, false},+ {true, `{"jsonrpc":"2.0","result":null,"id":1}`, false},+ {false, `{"jsonrpc":"2.0","result":null,"id":1}`, true},+ {false, `{"jsonrpc":"2.0","method":"event","params":null}`, true},+ {false, `{"jsonrpc":"2.0","method":"event","id":1}`, false},+ {false, `{"code":-1,"msg":"denied","data":null}`, false},+ {false, `[]`, false},+ } {+ err := bundle.ValidateWebSocketMessage("GET", "/ws/plugin/rpc", entry.incoming, []byte(entry.body))+ if (err == nil) != entry.valid {+ t.Fatalf("message validation mismatch: %+v, %v", entry, err)+ }+ }+ for _, entry := range []struct {+ status int+ media, body string+ valid bool+ }{+ {101, "", "", true},+ {101, "application/json", `{}`, false},+ {400, "text/plain; charset=utf-8", "bad request", true},+ {404, "application/json", `{"jsonrpc":"2.0","error":{"code":-32001,"message":"Plugin not loaded"},"id":null}`, true},+ {200, "application/json", `{"code":-1,"msg":"denied","data":null}`, true},+ {200, "application/json", `{"jsonrpc":"2.0","error":{"code":-32001,"message":"Plugin not loaded"},"id":null}`, false},+ } {+ err := bundle.ValidateHTTPResponse("GET", "/ws/plugin/rpc", entry.status, entry.media, []byte(entry.body))+ if (err == nil) != entry.valid {+ t.Fatalf("handshake validation mismatch: %+v, %v", entry, err)+ }+ }+}diff --git a/kernel/plugin/plugin.go b/kernel/plugin/plugin.goindex 2bf6e65c2e..0a191ff624 100644--- a/kernel/plugin/plugin.go+++ b/kernel/plugin/plugin.go@@ -36,6 +36,7 @@ import ("github.com/lxzan/gws""github.com/samber/lo""github.com/siyuan-note/logging"+ "github.com/siyuan-note/siyuan/kernel/apicontract""github.com/siyuan-note/siyuan/kernel/mcp/tools""github.com/siyuan-note/siyuan/kernel/model""github.com/siyuan-note/siyuan/kernel/util"@@ -507,12 +508,12 @@ func (p *KernelPlugin) GetRpcMethodsInfo() (methods []*RpcMethodInfo) {// BroadcastNotification sends a JSON-RPC 2.0 notification to all inbound RPC WebSocket clients.func (p *KernelPlugin) BroadcastNotification(method string, params util.Optional[any]) {- notification := JsonRpcRequest{- JsonRpc: JsonRpcVersion,- Method: method,- Params: params,+ notification, err := pluginRPCNotification(method, params)+ if err != nil {+ logging.LogWarnf("[plugin:%s] broadcast marshal: %s", p.Name, err)+ return}- data, err := json.Marshal(notification)+ data, err := json.Marshal(apicontract.RPCNotificationMessage(notification))if err != nil {logging.LogWarnf("[plugin:%s] broadcast marshal: %s", p.Name, err)returndiff --git a/kernel/plugin/rpc.go b/kernel/plugin/rpc.goindex fc15efc084..7c0181e616 100644--- a/kernel/plugin/rpc.go+++ b/kernel/plugin/rpc.go@@ -23,11 +23,13 @@ import ("fmt""io""net/http"+ "strings""sync""github.com/gin-gonic/gin""github.com/lxzan/gws""github.com/siyuan-note/logging"+ "github.com/siyuan-note/siyuan/kernel/apicontract""github.com/siyuan-note/siyuan/kernel/util")@@ -298,58 +300,46 @@ func HandleRpcWebSocket(c *gin.Context) {c.String(http.StatusBadRequest, "This endpoint only accepts WebSocket connections")return}+ p.serveRPCWebSocket(c.Writer, c.Request)+}++func (p *KernelPlugin) serveRPCWebSocket(writer http.ResponseWriter, request *http.Request) {+ name := p.Name+ if !strings.EqualFold(request.Header.Get("Upgrade"), "websocket") || !strings.Contains(strings.ToLower(request.Header.Get("Connection")), "upgrade") {+ writer.Header().Set("Content-Type", "text/plain; charset=utf-8")+ writer.WriteHeader(http.StatusBadRequest)+ _, _ = io.WriteString(writer, "This endpoint only accepts WebSocket connections")+ return+ }h := &WsEventHandler{p: p}h.onMessage = func(socket *gws.Conn, message *gws.Message) {defer message.Close()- results := parseRpcRequests(message.Bytes())- if results.GlobalError != nil {- if respBytes, marshalErr := json.Marshal(results.GlobalError); marshalErr == nil {- socket.WriteAsync(gws.OpcodeText, respBytes, func(err error) {- if err != nil {- logging.LogWarnf("[plugin:%s] RPC WebSocket response write failed: %s", name, err)- }- })- } else {- logging.LogErrorf("[plugin:%s] RPC WebSocket response marshal failed: %s", name, marshalErr)- }+ request, err := apicontract.DecodePluginRPC(bytes.NewReader(message.Bytes()))+ if err != nil {+ logging.LogErrorf("[plugin:%s] RPC WebSocket request read failed: %s", name, err)return}-- responses := p.dispatchRpcRequests(results.Requests)-- var responseBytes []byte- var marshalErr error- var needToSend bool-- if !results.Batch {- if len(responses) > 0 && responses[0] != nil {- if response := responses[0].JsonRpcResponse(); response != nil {- needToSend = true- responseBytes, marshalErr = json.Marshal(response)- }- }- } else {- filtered := filterRpcResponses(responses)- if len(filtered) > 0 {- needToSend = true- responseBytes, marshalErr = json.Marshal(filtered)- }+ response, err := p.dispatchRPCContract(request)+ if err != nil {+ logging.LogErrorf("[plugin:%s] RPC response marshal failed: %s", name, err)+ return}-- if needToSend {- if marshalErr != nil {- logging.LogErrorf("[plugin:%s] RPC response marshal failed: %s", name, marshalErr)- return- }- socket.WriteAsync(gws.OpcodeText, responseBytes, func(err error) {- if err != nil {- logging.LogWarnf("[plugin:%s] RPC WebSocket response write failed: %s", name, err)- }- })+ if response == nil {+ return+ }+ responseBytes, err := json.Marshal(apicontract.RPCResponseMessage(*response))+ if err != nil {+ logging.LogErrorf("[plugin:%s] RPC response marshal failed: %s", name, err)+ return}+ socket.WriteAsync(gws.OpcodeText, responseBytes, func(err error) {+ if err != nil {+ logging.LogWarnf("[plugin:%s] RPC WebSocket response write failed: %s", name, err)+ }+ })}upgrader := gws.NewUpgrader(h, &gws.ServerOption{@@ -358,7 +348,7 @@ func HandleRpcWebSocket(c *gin.Context) {return util.IsSessionOriginAllowedRequest(r)},})- socket, err := upgrader.Upgrade(c.Writer, c.Request)+ socket, err := upgrader.Upgrade(writer, request)if err != nil {logging.LogErrorf("[plugin:%s] RPC WebSocket upgrade failed: %s", name, err)returndiff --git a/kernel/plugin/rpc_contract.go b/kernel/plugin/rpc_contract.gonew file mode 100644index 0000000000..e8f4361c4e--- /dev/null+++ b/kernel/plugin/rpc_contract.go@@ -0,0 +1,205 @@+package plugin++import (+ "encoding/json"+ "fmt"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/util"+)++const rpcContractPluginKey = "siyuan.plugin.rpc.contract.plugin"++func OpenRPCWebSocket(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.PluginRPCFailure] {+ name := util.GetRequestUrlStringParam(c, "name")+ p := GetManager().GetPlugin(name)+ if p == nil {+ return apicontract.RejectWebSocket(apicontract.RPCErrorResponse(-32001, "Plugin not loaded", ""))+ }+ if p.State() != PluginStateRunning {+ return apicontract.RejectWebSocket(apicontract.RPCErrorResponse(-32002, "Plugin not running", ""))+ }+ return apicontract.UpgradeWebSocket[apicontract.PluginRPCFailure](p.serveRPCWebSocket)+}++// PrepareRPCContract 在读取请求体前选定运行中的插件,请求期间继续使用同一实例。+func PrepareRPCContract(c *gin.Context) *apicontract.Response[apicontract.PluginRPCResponse] {+ name := util.GetRequestUrlStringParam(c, "name")+ p := GetManager().GetPlugin(name)+ var failure apicontract.PluginRPCFailure+ if p == nil {+ failure = apicontract.RPCErrorResponse(-32001, "Plugin not loaded", "")+ } else if p.State() != PluginStateRunning {+ failure = apicontract.RPCErrorResponse(-32002, "Plugin not running", "")+ } else {+ c.Set(rpcContractPluginKey, p)+ return nil+ }+ response := apicontract.SuccessDirectJSON(apicontract.RPCSingleResponse(apicontract.RPCFailureReply(failure)))+ return &response+}++func DispatchRPCContract(c *gin.Context, request apicontract.PluginRPCBatchRequest) apicontract.Response[apicontract.PluginRPCResponse] {+ // 此上下文值只由请求的准备阶段写入,不参与请求参数解码。+ value, _ := c.Get(rpcContractPluginKey)+ p, ok := value.(*KernelPlugin)+ if !ok {+ panic("RPC plugin was not prepared")+ }+ response, err := p.dispatchRPCContract(request)+ if err != nil {+ return rpcContractInternalError(err)+ }+ if response == nil {+ return apicontract.SuccessNoContent[apicontract.PluginRPCResponse]()+ }+ return apicontract.SuccessDirectJSON(*response)+}++// dispatchRPCContract 共用单次与批量调用的类型化响应,空值表示不发送通知回复。+func (p *KernelPlugin) dispatchRPCContract(request apicontract.PluginRPCBatchRequest) (*apicontract.PluginRPCResponse, error) {+ if request.Error != nil {+ response := apicontract.RPCSingleResponse(apicontract.RPCFailureReply(*request.Error))+ return &response, nil+ }+ requests, err := pluginRPCRequests(request.Calls)+ if err != nil {+ return nil, err+ }+ responses := p.dispatchRpcRequests(requests)+ var replies []apicontract.PluginRPCReply+ for _, response := range responses {+ if response == nil || response.Response == nil && response.Error == nil {+ continue+ }+ reply, err := pluginRPCReply(response)+ if err != nil {+ return nil, err+ }+ replies = append(replies, reply)+ }+ if len(replies) == 0 {+ return nil, nil+ }+ if request.Batch {+ response := apicontract.RPCBatchResponse(replies)+ return &response, nil+ }+ response := apicontract.RPCSingleResponse(replies[0])+ return &response, nil+}++func rpcContractInternalError(err error) apicontract.Response[apicontract.PluginRPCResponse] {+ failure := apicontract.RPCErrorResponse(-32603, "Internal error", err.Error())+ return apicontract.SuccessDirectJSON(apicontract.RPCSingleResponse(apicontract.RPCFailureReply(failure)))+}++func pluginRPCRequests(calls []apicontract.PluginRPCParsedCall) ([]*JsonRpcProcessingRequest, error) {+ requests := make([]*JsonRpcProcessingRequest, len(calls))+ for i, call := range calls {+ if call.Error != nil {+ data, err := json.Marshal(call.Error)+ if err != nil {+ return nil, err+ }+ var failure JsonRpcErrorResponse+ if err := json.Unmarshal(data, &failure); err != nil {+ return nil, err+ }+ requests[i] = &JsonRpcProcessingRequest{Error: &failure}+ continue+ }+ if call.Request == nil {+ return nil, fmt.Errorf("RPC call requires a request or error")+ }+ request := &JsonRpcRequest{JsonRpc: JsonRpcVersion, Method: call.Request.Method}+ request.Params.Exists, request.ID.Exists = call.Request.ParamsPresent, call.Request.IDPresent+ // 只有 RPC 的参数和关联标识进入脚本运行时的动态值,方法和请求结构保持类型约束。+ params, err := json.Marshal(call.Request.Params)+ if err != nil {+ return nil, err+ }+ if err := json.Unmarshal(params, &request.Params.Value); err != nil {+ return nil, err+ }+ request.Params.IsNull = call.Request.ParamsNull+ id, err := json.Marshal(call.Request.ID)+ if err != nil {+ return nil, err+ }+ if err := json.Unmarshal(id, &request.ID.Value); err != nil {+ return nil, err+ }+ request.ID.IsNull = string(id) == "null" && request.ID.Exists+ requests[i] = &JsonRpcProcessingRequest{Request: request}+ }+ return requests, nil+}++func pluginRPCReply(response *JsonRpcProcessingResponse) (apicontract.PluginRPCReply, error) {+ if response.Response != nil {+ value := response.Response+ result, err := json.Marshal(value.Result)+ if err != nil {+ return apicontract.PluginRPCReply{}, err+ }+ encoded, err := apicontract.EncodedJSONValue(result)+ if err != nil {+ return apicontract.PluginRPCReply{}, err+ }+ id, err := pluginRPCID(value.ID)+ if err != nil {+ return apicontract.PluginRPCReply{}, err+ }+ return apicontract.RPCSuccessReply(apicontract.PluginRPCSuccess{JSONRPC: value.JsonRpc, Result: encoded, ID: id}), nil+ }+ value := response.Error+ if value == nil {+ return apicontract.PluginRPCReply{}, fmt.Errorf("RPC reply requires a response or error")+ }+ id, err := pluginRPCID(value.ID)+ if err != nil {+ return apicontract.PluginRPCReply{}, err+ }+ result := apicontract.PluginRPCFailure{JSONRPC: value.JsonRpc, ID: id}+ if value.Error != nil {+ result.Error = &apicontract.PluginRPCError{Code: int(value.Error.Code), Message: value.Error.Message}+ if value.Error.Data != nil {+ data, err := json.Marshal(value.Error.Data)+ if err != nil {+ return apicontract.PluginRPCReply{}, err+ }+ encoded, err := apicontract.EncodedJSONValue(data)+ if err != nil {+ return apicontract.PluginRPCReply{}, err+ }+ result.Error.Data = &encoded+ }+ }+ return apicontract.RPCFailureReply(result), nil+}++func pluginRPCID(value interface{}) (id apicontract.PluginRPCID, err error) {+ data, err := json.Marshal(value)+ if err == nil {+ err = json.Unmarshal(data, &id)+ }+ return+}++func pluginRPCNotification(method string, params util.Optional[any]) (apicontract.PluginRPCNotification, error) {+ result := apicontract.PluginRPCNotification{JSONRPC: JsonRpcVersion, Method: method}+ if params.Exists {+ data, err := json.Marshal(params)+ if err != nil {+ return result, err+ }+ value, err := apicontract.EncodedJSONValue(data)+ if err != nil {+ return result, err+ }+ result.Params = &value+ }+ return result, nil+}diff --git a/kernel/plugin/rpc_contract_test.go b/kernel/plugin/rpc_contract_test.gonew file mode 100644index 0000000000..3a5d8959ce--- /dev/null+++ b/kernel/plugin/rpc_contract_test.go@@ -0,0 +1,162 @@+package plugin++import (+ "bytes"+ "encoding/json"+ "io"+ "math"+ "net/http/httptest"+ "reflect"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/model"+)++func TestRPCContractParserCompatibility(t *testing.T) {+ for _, body := range []string{+ ``, `{`, `null`, `[]`, `true`, `1`, `"text"`, `{}`, `{"method":"m"}`,+ `{"jsonrpc":"1.0","method":"m"}`, `{"jsonrpc":null,"method":"m"}`, `{"jsonrpc":2,"method":"m"}`,+ `{"jsonrpc":"2.0"}`, `{"jsonrpc":"2.0","method":null}`, `{"jsonrpc":"2.0","method":true}`,+ `{"jsonrpc":"2.0","method":""}`, `{"jsonrpc":"2.0","method":" m ","id":null}`,+ `{"jsonrpc":"2.0","method":"m","id":1.5}`, `{"jsonrpc":"2.0","method":"m","id":" id "}`,+ `{"jsonrpc":"2.0","method":"m","id":false}`, `{"jsonrpc":"2.0","method":"m","id":[]}`,+ `{"jsonrpc":"2.0","method":"m","params":null}`, `{"jsonrpc":"2.0","method":"m","params":false}`,+ `{"jsonrpc":"2.0","method":"m","params":[1,{"key":false},null],"id":1}`,+ `{"JSONRPC":"2.0","METHOD":"m","PARAMS":{"key":[1]},"ID":2}`,+ `[{"jsonrpc":"2.0","method":"m"},false,{},null,[],{"jsonrpc":"2.0","method":"m","id":2}]`,+ `{"jsonrpc":"2.0","method":"m","params":1e999}`, `{"jsonrpc":"2.0","method":"m","id":1e999}`,+ `{"jsonrpc":"2.0","method":"m","params":[1],"params":null,"id":1}`,+ } {+ legacy := parseRpcRequests([]byte(body))+ request, err := apicontract.DecodePluginRPC(strings.NewReader(body))+ if err != nil {+ t.Fatalf("decode failed: %s, %v", body, err)+ }+ compareRPCJSON(t, body, legacy.GlobalError, request.Error)+ if legacy.Batch != request.Batch {+ t.Fatalf("batch flag changed: %s", body)+ }+ calls, err := pluginRPCRequests(request.Calls)+ if err != nil {+ t.Fatal(err)+ }+ if len(calls) != len(legacy.Requests) {+ t.Fatalf("request count changed: %s", body)+ }+ for i, call := range calls {+ compareRPCJSON(t, body, legacy.Requests[i].Error, call.Error)+ compareRPCJSON(t, body, legacy.Requests[i].Request, call.Request)+ if call.Request != nil && (!reflect.DeepEqual(call.Request.ID, legacy.Requests[i].Request.ID) || !reflect.DeepEqual(call.Request.Params, legacy.Requests[i].Request.Params)) {+ t.Fatalf("optional parameter states changed: %s: %+v != %+v", body, call.Request, legacy.Requests[i].Request)+ }+ }+ }+}++func compareRPCJSON(t *testing.T, label string, expected, actual interface{}) {+ t.Helper()+ left, err := json.Marshal(expected)+ if err != nil {+ t.Fatal(err)+ }+ right, err := json.Marshal(actual)+ if err != nil {+ t.Fatal(err)+ }+ var leftValue, rightValue interface{}+ if err := json.Unmarshal(left, &leftValue); err != nil {+ t.Fatal(err)+ }+ if err := json.Unmarshal(right, &rightValue); err != nil {+ t.Fatal(err)+ }+ if !reflect.DeepEqual(leftValue, rightValue) {+ t.Fatalf("RPC JSON changed for %s:\n%s\n%s", label, left, right)+ }+}++func TestRPCContractHTTPCompatibility(t *testing.T) {+ p := &KernelPlugin{Petal: &model.Petal{Name: "contract-rpc"}}+ p.state.Store(int64(PluginStateRunning))+ manager := GetManager()+ manager.plugins.Store(p.Name, p)+ t.Cleanup(func() { manager.plugins.Delete(p.Name) })+ endpoint := apicontract.PluginRPCHTTPByName+ bundle, err := apicontract.BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ for _, body := range []string{+ `invalid`, `null`, `[]`, `{}`,+ `{"jsonrpc":"2.0","method":"missing","id":1}`,+ `{"jsonrpc":"2.0","method":"missing","params":null}`,+ `{"jsonrpc":"2.0","method":"missing","params":null,"id":null}`,+ `[{"jsonrpc":"2.0","method":"missing","params":null}]`,+ `[false,{"jsonrpc":"2.0","method":"missing","params":null},{"jsonrpc":"2.0","method":"missing","id":"id"}]`,+ } {+ call := func(handler gin.HandlerFunc) *httptest.ResponseRecorder {+ engine := gin.New()+ engine.POST("/api/plugin/rpc/:name", handler)+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/plugin/rpc/contract-rpc", strings.NewReader(body)))+ return recorder+ }+ legacy := call(HandleRpcHttp)+ actual := call(func(c *gin.Context) {+ var response apicontract.Response[apicontract.PluginRPCResponse]+ if early := PrepareRPCContract(c); early != nil {+ response = *early+ } else {+ request, err := endpoint.Decode(c.Request.Body)+ if err != nil {+ response = endpoint.DecodeFailure(err)+ } else {+ response = DispatchRPCContract(c, request)+ }+ }+ if status := endpoint.Status(response); status == 204 {+ c.Status(status)+ } else {+ c.JSON(status, response)+ }+ })+ if legacy.Code != actual.Code || !bytes.Equal(legacy.Body.Bytes(), actual.Body.Bytes()) {+ t.Fatalf("RPC HTTP changed for %s:\n%d %s\n%d %s", body, legacy.Code, legacy.Body, actual.Code, actual.Body)+ }+ if err := bundle.ValidateHTTPResponse("POST", "/api/plugin/rpc/:name", actual.Code, actual.Header().Get("Content-Type"), actual.Body.Bytes()); err != nil {+ t.Fatalf("RPC response violates contract: %s, %v", actual.Body, err)+ }+ }+}++func TestRPCContractResultPrecision(t *testing.T) {+ response := &JsonRpcProcessingResponse{Response: &JsonRpcRequestResponse{JsonRpc: "2.0", ID: "id", Result: int64(math.MaxInt64)}}+ reply, err := pluginRPCReply(response)+ if err != nil {+ t.Fatal(err)+ }+ expected, _ := json.Marshal(response.Response)+ actual, err := json.Marshal(reply)+ if err != nil || !bytes.Equal(expected, actual) {+ t.Fatalf("RPC result precision changed: %s != %s, %v", actual, expected, err)+ }+}++type rpcFailingReader struct{}++func (rpcFailingReader) Read([]byte) (int, error) { return 0, io.ErrUnexpectedEOF }++func TestRPCContractReadFailure(t *testing.T) {+ _, err := apicontract.PluginRPCHTTP.Decode(rpcFailingReader{})+ if err == nil {+ t.Fatal("read failure was ignored")+ }+ response := apicontract.PluginRPCHTTP.DecodeFailure(err)+ actual, err := json.Marshal(response)+ if err != nil || !strings.Contains(string(actual), `"code":-32603`) || !strings.Contains(string(actual), "Failed to read request body: unexpected EOF") {+ t.Fatalf("RPC read error changed: %s, %v", actual, err)+ }+}diff --git a/kernel/plugin/rpc_websocket_contract_test.go b/kernel/plugin/rpc_websocket_contract_test.gonew file mode 100644index 0000000000..b39f25dac5--- /dev/null+++ b/kernel/plugin/rpc_websocket_contract_test.go@@ -0,0 +1,184 @@+package plugin++import (+ "context"+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "strings"+ "testing"+ "time"++ "github.com/gin-gonic/gin"+ "github.com/gorilla/websocket"+ "github.com/lxzan/gws"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestRPCWebSocketContractMessages(t *testing.T) {+ ctx, cancel := context.WithCancel(context.Background())+ p := &KernelPlugin{Petal: &model.Petal{Name: "contract-rpc-ws"}, context: ctx, sockets: map[*gws.Conn]bool{}}+ p.state.Store(int64(PluginStateRunning))+ manager := GetManager()+ manager.plugins.Store(p.Name, p)+ engine := gin.New()+ engine.GET("/ws/plugin/rpc/:name", rpcWebSocketContractTestHandler)+ server := httptest.NewServer(engine)+ t.Cleanup(func() { cancel(); server.Close(); manager.plugins.Delete(p.Name) })+ url := "ws" + strings.TrimPrefix(server.URL, "http") + "/ws/plugin/rpc/" + p.Name+ conn, response, err := websocket.DefaultDialer.Dial(url, nil)+ if err != nil {+ t.Fatalf("WebSocket upgrade failed: %v, %+v", err, response)+ }+ defer conn.Close()+ bundle, err := apicontract.BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ read := func() []byte {+ t.Helper()+ if err := conn.SetReadDeadline(time.Now().Add(3 * time.Second)); err != nil {+ t.Fatal(err)+ }+ opcode, payload, err := conn.ReadMessage()+ if err != nil || opcode != websocket.TextMessage {+ t.Fatalf("RPC frame read failed: %d, %s, %v", opcode, payload, err)+ }+ return payload+ }+ for _, body := range []string{`invalid`, `{}`, `{"jsonrpc":"2.0","method":"missing","id":1}`, `[false,{"jsonrpc":"2.0","method":"missing","id":"batch"}]`} {+ if err := conn.WriteMessage(websocket.TextMessage, []byte(body)); err != nil {+ t.Fatal(err)+ }+ payload := read()+ if err := bundle.ValidateWebSocketMessage("GET", "/ws/plugin/rpc/:name", false, payload); err != nil {+ t.Fatalf("RPC frame violates reply schema: %s, %v", payload, err)+ }+ request, err := apicontract.DecodePluginRPC(strings.NewReader(body))+ if err != nil {+ t.Fatal(err)+ }+ expected, err := p.dispatchRPCContract(request)+ if err != nil {+ t.Fatal(err)+ }+ compareRPCJSON(t, body, expected, json.RawMessage(payload))+ }+ // 通知后发送普通调用,收到的下一帧必须属于普通调用。+ if err := conn.WriteMessage(websocket.TextMessage, []byte(`{"jsonrpc":"2.0","method":"missing","params":null}`)); err != nil {+ t.Fatal(err)+ }+ if err := conn.WriteMessage(websocket.TextMessage, []byte(`{"jsonrpc":"2.0","method":"missing","id":"after-notification"}`)); err != nil {+ t.Fatal(err)+ }+ var reply struct {+ ID string `json:"id"`+ }+ if payload := read(); json.Unmarshal(payload, &reply) != nil || reply.ID != "after-notification" {+ t.Fatalf("notification unexpectedly produced a reply: %s", payload)+ }+ p.BroadcastNotification("event", util.Optional[any]{Exists: true, Value: []string{"value"}})+ if payload := read(); string(payload) != `{"jsonrpc":"2.0","method":"event","params":["value"]}` {+ t.Fatalf("server notification changed: %s", payload)+ }+ cancel()+ if err := conn.SetReadDeadline(time.Now().Add(3 * time.Second)); err != nil {+ t.Fatal(err)+ }+ if _, _, err := conn.ReadMessage(); err == nil {+ t.Fatal("plugin cancellation did not close the connection")+ }+}++func TestRPCWebSocketOriginCheck(t *testing.T) {+ ctx, cancel := context.WithCancel(context.Background())+ p := &KernelPlugin{Petal: &model.Petal{Name: "contract-rpc-origin"}, context: ctx, sockets: map[*gws.Conn]bool{}}+ p.state.Store(int64(PluginStateRunning))+ manager := GetManager()+ manager.plugins.Store(p.Name, p)+ engine := gin.New()+ engine.GET("/ws/plugin/rpc/:name", rpcWebSocketContractTestHandler)+ server := httptest.NewServer(engine)+ t.Cleanup(func() { cancel(); server.Close(); manager.plugins.Delete(p.Name) })+ url := "ws" + strings.TrimPrefix(server.URL, "http") + "/ws/plugin/rpc/" + p.Name+ conn, response, err := websocket.DefaultDialer.Dial(url, http.Header{"Origin": []string{"https://untrusted.invalid"}, "Sec-Fetch-Site": []string{"cross-site"}})+ if conn != nil {+ conn.Close()+ }+ if response != nil {+ defer response.Body.Close()+ }+ if err == nil || response == nil || response.StatusCode != http.StatusBadRequest {+ t.Fatalf("cross-site RPC WebSocket was not rejected: %+v, %v", response, err)+ }+}++func TestRPCNotificationContractCompatibility(t *testing.T) {+ for _, params := range []util.Optional[any]{{}, {Exists: true, IsNull: true}, {Exists: true, Value: false}, {Exists: true, Value: int64(9223372036854775807)}, {Exists: true, Value: []any{}}, {Exists: true, Value: map[string]any{"key": nil}}} {+ notification, err := pluginRPCNotification("event", params)+ if err != nil {+ t.Fatal(err)+ }+ expected, err := json.Marshal(JsonRpcRequest{JsonRpc: "2.0", Method: "event", Params: params})+ if err != nil {+ t.Fatal(err)+ }+ actual, err := json.Marshal(notification)+ if err != nil || string(actual) != string(expected) {+ t.Fatalf("notification changed: %s != %s, %v", actual, expected, err)+ }+ }+}++func rpcWebSocketContractTestHandler(c *gin.Context) {+ response := OpenRPCWebSocket(c, apicontract.EmptyRequest{})+ status := apicontract.PluginRPCWebSocketByName.Status(response)+ if upgrade := response.Upgrade(); upgrade != nil {+ upgrade(c.Writer, c.Request)+ return+ }+ c.JSON(status, response)+}++func TestRPCWebSocketContractAdmission(t *testing.T) {+ p := &KernelPlugin{Petal: &model.Petal{Name: "contract-rpc-stopped"}}+ GetManager().plugins.Store(p.Name, p)+ t.Cleanup(func() { GetManager().plugins.Delete(p.Name) })+ engine := gin.New()+ engine.GET("/ws/plugin/rpc", rpcWebSocketContractTestHandler)+ engine.GET("/ws/plugin/rpc/:name", rpcWebSocketContractTestHandler)+ bundle, err := apicontract.BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ for _, entry := range []struct {+ url string+ code int+ }{+ {"/ws/plugin/rpc?name=contract-rpc-stopped", -32002},+ {"/ws/plugin/rpc/missing?name=contract-rpc-stopped", -32001},+ {"/ws/plugin/rpc", -32001},+ } {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("GET", entry.url, strings.NewReader("invalid body")))+ if err := bundle.ValidateHTTPResponse("GET", "/ws/plugin/rpc", recorder.Code, recorder.Header().Get("Content-Type"), recorder.Body.Bytes()); err != nil {+ t.Fatal(err)+ }+ var reply struct {+ Error struct {+ Code int `json:"code"`+ } `json:"error"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &reply); err != nil || recorder.Code != 404 || reply.Error.Code != entry.code {+ t.Fatalf("admission changed: %s: %d %s, %v", entry.url, recorder.Code, recorder.Body.String(), err)+ }+ }+ p.state.Store(int64(PluginStateRunning))+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("GET", "/ws/plugin/rpc/"+p.Name, nil))+ if recorder.Code != 400 || recorder.Body.String() != "This endpoint only accepts WebSocket connections" {+ t.Fatalf("non-WebSocket request changed: %d %s", recorder.Code, recorder.Body.String())+ }+}