@lotaber_wang/openclaw-dc-plugin 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/lib/mcp-bridge.js +50 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,8 +87,10 @@ openclaw plugins install @lotaber_wang/openclaw-dc-plugin
|
|
|
87
87
|
- 本机 Node 版本是否 >= 18.14.1
|
|
88
88
|
- OpenClaw 进程是否有临时目录写权限
|
|
89
89
|
|
|
90
|
-
从 `0.1.
|
|
90
|
+
从 `0.1.5` 开始,插件 bridge 会额外做这些兼容处理:
|
|
91
91
|
|
|
92
92
|
- `initialize` 超时后自动切换到无缓冲 / PTY 启动策略重试
|
|
93
|
+
- `initialize` 默认超时提升到 20 秒,避免宿主启动稍慢时过早失败
|
|
93
94
|
- 兼容解析裸 JSON 输出,不再只接受 `Content-Length` 帧
|
|
95
|
+
- 启动时如果 stdout 混入人类可读日志,会先自动丢弃噪音再解析协议消息
|
|
94
96
|
- 过滤 PTY 场景下被回显到 stdout 的请求消息
|
package/lib/mcp-bridge.js
CHANGED
|
@@ -9,7 +9,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
10
10
|
const HEADER_SEPARATOR = '\r\n\r\n';
|
|
11
11
|
const RUNTIME_PACKAGE_NAME = '@mikoto_zero/minigame-open-mcp';
|
|
12
|
-
const DEFAULT_INIT_TIMEOUT_MS =
|
|
12
|
+
const DEFAULT_INIT_TIMEOUT_MS = 20000;
|
|
13
|
+
const ANSI_ESCAPE_REGEX = /\x1B\[[0-?]*[ -/]*[@-~]/g;
|
|
13
14
|
|
|
14
15
|
function readPluginPackageJson() {
|
|
15
16
|
try {
|
|
@@ -75,6 +76,51 @@ function shellEscape(value) {
|
|
|
75
76
|
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
function stripAnsi(text) {
|
|
80
|
+
return text.replace(ANSI_ESCAPE_REGEX, '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function findLikelyFrameStart(buffer) {
|
|
84
|
+
return buffer.indexOf('Content-Length:', 0, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function findLikelyJsonStart(buffer) {
|
|
88
|
+
const text = buffer.toString('utf8');
|
|
89
|
+
const candidates = ['{"jsonrpc"', '{"result"', '{"method"', '{"error"', '[{"jsonrpc"'];
|
|
90
|
+
let bestIndex = -1;
|
|
91
|
+
|
|
92
|
+
for (const candidate of candidates) {
|
|
93
|
+
const index = text.indexOf(candidate);
|
|
94
|
+
if (index !== -1 && (bestIndex === -1 || index < bestIndex)) {
|
|
95
|
+
bestIndex = index;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return bestIndex;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function trimNonProtocolNoise(buffer, logger) {
|
|
103
|
+
const frameStart = findLikelyFrameStart(buffer);
|
|
104
|
+
const jsonStart = findLikelyJsonStart(buffer);
|
|
105
|
+
|
|
106
|
+
let start = -1;
|
|
107
|
+
if (frameStart !== -1 && jsonStart !== -1) {
|
|
108
|
+
start = Math.min(frameStart, jsonStart);
|
|
109
|
+
} else {
|
|
110
|
+
start = frameStart !== -1 ? frameStart : jsonStart;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (start > 0) {
|
|
114
|
+
const dropped = stripAnsi(buffer.subarray(0, start).toString('utf8')).trim();
|
|
115
|
+
if (dropped) {
|
|
116
|
+
logger?.info?.(`[TapTap DC] Ignoring non-protocol stdout noise: ${dropped.slice(0, 300)}`);
|
|
117
|
+
}
|
|
118
|
+
return buffer.subarray(start);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return buffer;
|
|
122
|
+
}
|
|
123
|
+
|
|
78
124
|
function parseBareJsonMessage(buffer) {
|
|
79
125
|
const text = buffer.toString('utf8');
|
|
80
126
|
let start = 0;
|
|
@@ -137,7 +183,7 @@ function parseBareJsonMessage(buffer) {
|
|
|
137
183
|
|
|
138
184
|
function findNextMessageOffset(buffer) {
|
|
139
185
|
const framedIndex = buffer.indexOf('Content-Length:', 0, 'utf8');
|
|
140
|
-
const jsonIndex = buffer
|
|
186
|
+
const jsonIndex = findLikelyJsonStart(buffer);
|
|
141
187
|
|
|
142
188
|
if (framedIndex === -1) {
|
|
143
189
|
return jsonIndex;
|
|
@@ -547,6 +593,7 @@ export class TapTapMcpBridge {
|
|
|
547
593
|
this.child.stdout.on('data', (chunk) => {
|
|
548
594
|
try {
|
|
549
595
|
this.stdoutBuffer = Buffer.concat([this.stdoutBuffer, chunk]);
|
|
596
|
+
this.stdoutBuffer = trimNonProtocolNoise(this.stdoutBuffer, this.logger);
|
|
550
597
|
this.stdoutBuffer = parseMessageBuffer(this.stdoutBuffer, (message) =>
|
|
551
598
|
this.handleMessage(message)
|
|
552
599
|
);
|
|
@@ -556,6 +603,7 @@ export class TapTapMcpBridge {
|
|
|
556
603
|
error instanceof Error ? error.message : String(error)
|
|
557
604
|
}`
|
|
558
605
|
);
|
|
606
|
+
this.stdoutBuffer = trimNonProtocolNoise(this.stdoutBuffer, this.logger);
|
|
559
607
|
}
|
|
560
608
|
});
|
|
561
609
|
|
package/openclaw.plugin.json
CHANGED