From edd2ac278ac7a4d27d9572be0a5789d9aecbd107 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Thu, 23 Jul 2026 12:14:01 +0800 Subject: [PATCH] fix(onebot): trace empty text placeholder normalization Document the compatibility rule in action metadata and regenerate the MCP catalog. --- packages/mcp/src/generated/catalog.json | 52 ++++++++++++------------- packages/mcp/src/generated/catalog.ts | 52 ++++++++++++------------- packages/onebot/src/action-kit.ts | 8 +++- packages/onebot/src/message-parser.ts | 5 ++- 4 files changed, 63 insertions(+), 54 deletions(-) diff --git a/packages/mcp/src/generated/catalog.json b/packages/mcp/src/generated/catalog.json index bc211963..1b992676 100644 --- a/packages/mcp/src/generated/catalog.json +++ b/packages/mcp/src/generated/catalog.json @@ -7466,7 +7466,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7474,7 +7474,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } } ], @@ -7483,10 +7483,10 @@ "type": "object", "properties": { "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, "additionalProperties": true @@ -7635,7 +7635,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7643,7 +7643,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } } ], @@ -7658,10 +7658,10 @@ "x-role": "group_id" }, "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, "required": [ @@ -7694,7 +7694,7 @@ "type": "message", "required": true, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7718,7 +7718,7 @@ "x-role": "group_id" }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "auto_escape": { "type": "boolean", @@ -7794,7 +7794,7 @@ "type": "message", "required": true, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7840,7 +7840,7 @@ "type": "object", "properties": { "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message_type": { "type": "string" @@ -7998,7 +7998,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -8006,7 +8006,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } } ], @@ -8020,10 +8020,10 @@ "x-role": "user_id" }, "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, "required": [ @@ -8055,7 +8055,7 @@ "type": "message", "required": true, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -8087,7 +8087,7 @@ "x-role": "user_id" }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "group_id": { "type": "integer", @@ -10528,7 +10528,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10536,7 +10536,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10555,10 +10555,10 @@ "type": "object", "properties": { "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "group_id": { "type": "integer", @@ -10581,7 +10581,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10589,7 +10589,7 @@ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10608,10 +10608,10 @@ "type": "object", "properties": { "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "group_id": { "type": "integer", diff --git a/packages/mcp/src/generated/catalog.ts b/packages/mcp/src/generated/catalog.ts index 641f2b3c..e88d4b5e 100644 --- a/packages/mcp/src/generated/catalog.ts +++ b/packages/mcp/src/generated/catalog.ts @@ -7469,7 +7469,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7477,7 +7477,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } } ], @@ -7486,10 +7486,10 @@ export const ACTIONS: CatalogAction[] = [ "type": "object", "properties": { "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, "additionalProperties": true @@ -7638,7 +7638,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7646,7 +7646,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } } ], @@ -7661,10 +7661,10 @@ export const ACTIONS: CatalogAction[] = [ "x-role": "group_id" }, "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, "required": [ @@ -7697,7 +7697,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": true, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7721,7 +7721,7 @@ export const ACTIONS: CatalogAction[] = [ "x-role": "group_id" }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "auto_escape": { "type": "boolean", @@ -7797,7 +7797,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": true, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -7843,7 +7843,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "object", "properties": { "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message_type": { "type": "string" @@ -8001,7 +8001,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -8009,7 +8009,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } } ], @@ -8023,10 +8023,10 @@ export const ACTIONS: CatalogAction[] = [ "x-role": "user_id" }, "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, "required": [ @@ -8058,7 +8058,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": true, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -8090,7 +8090,7 @@ export const ACTIONS: CatalogAction[] = [ "x-role": "user_id" }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "group_id": { "type": "integer", @@ -10531,7 +10531,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10539,7 +10539,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10558,10 +10558,10 @@ export const ACTIONS: CatalogAction[] = [ "type": "object", "properties": { "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "group_id": { "type": "integer", @@ -10584,7 +10584,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10592,7 +10592,7 @@ export const ACTIONS: CatalogAction[] = [ "type": "message", "required": false, "schema": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." } }, { @@ -10611,10 +10611,10 @@ export const ACTIONS: CatalogAction[] = [ "type": "object", "properties": { "messages": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "message": { - "description": "OneBot message: string | segment[] | object" + "description": "OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly \"\" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation." }, "group_id": { "type": "integer", diff --git a/packages/onebot/src/action-kit.ts b/packages/onebot/src/action-kit.ts index 14bf0efb..1805a2bd 100644 --- a/packages/onebot/src/action-kit.ts +++ b/packages/onebot/src/action-kit.ts @@ -323,7 +323,13 @@ export const f = { } } return ok(raw); - }, { type: 'message', required: true, schema: { description: 'OneBot message: string | segment[] | object' } }); + }, { + type: 'message', + required: true, + schema: { + description: 'OneBot message: string | segment[] | object. In segment arrays, text segments whose text field is exactly "" are compatibility placeholders and do not count as sendable segments; missing, null, and whitespace-only text remain subject to normal validation.', + }, + }); }, /** Homogeneous array; `.nonEmpty()` rejects []. */ array(el: Field): Field & { nonEmpty(): Field } { diff --git a/packages/onebot/src/message-parser.ts b/packages/onebot/src/message-parser.ts index 2ac266c1..b4968b7c 100644 --- a/packages/onebot/src/message-parser.ts +++ b/packages/onebot/src/message-parser.ts @@ -411,7 +411,10 @@ export async function parseMessage(message: JsonValue, autoEscape: boolean, opti // Some OneBot clients insert empty text between media as a separator. // Only the exact empty string is a no-op; malformed and whitespace text // must still pass through strict element validation. - if (seg.type.trim().toLowerCase() === 'text' && data.text === '') continue; + if (seg.type.trim().toLowerCase() === 'text' && data.text === '') { + log.debug('ignored explicit empty text placeholder in message segment array'); + continue; + } const elem = await segmentToElement(seg.type, data, options); if (elem) elements.push(elem); }