agent-bridge-doubao 1.0.9 → 1.0.11
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.
|
@@ -53,10 +53,17 @@ class DoubaoCdpClient {
|
|
|
53
53
|
socket.onmessage = event => this.onMessage(String(event.data));
|
|
54
54
|
await new Promise((resolve, reject) => { socket.onopen = () => resolve(); socket.onerror = () => reject(new Error("豆包 CDP WebSocket 连接失败")); });
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
async cancel() {
|
|
57
57
|
this.closeController.abort();
|
|
58
|
-
if (this.socket)
|
|
59
|
-
|
|
58
|
+
if (this.socket) {
|
|
59
|
+
try {
|
|
60
|
+
await this.cdp("Runtime.evaluate", { expression: "window.__mab_doubao_controller?.abort()", returnByValue: true }, 3_000);
|
|
61
|
+
}
|
|
62
|
+
catch { /* CDP 已断开时无需等待页面确认 */ }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async close() {
|
|
66
|
+
await this.cancel();
|
|
60
67
|
this.socket?.close();
|
|
61
68
|
this.socket = undefined;
|
|
62
69
|
for (const pending of this.pending.values())
|
|
@@ -88,8 +95,14 @@ class DoubaoCdpClient {
|
|
|
88
95
|
} if (message.id === undefined)
|
|
89
96
|
return; const pending = this.pending.get(message.id); if (!pending)
|
|
90
97
|
return; this.pending.delete(message.id); pending.resolve(message); }
|
|
91
|
-
async cdp(method, params = {}) { if (!this.socket)
|
|
92
|
-
throw new Error("豆包 CDP 尚未连接"); const id = ++this.sequence; const result = new Promise((resolve, reject) => this.pending.set(id, { resolve, reject }));
|
|
98
|
+
async cdp(method, params = {}, timeoutMs = this.options.timeoutMs) { if (!this.socket)
|
|
99
|
+
throw new Error("豆包 CDP 尚未连接"); const id = ++this.sequence; const result = new Promise((resolve, reject) => this.pending.set(id, { resolve, reject })); let timer; try {
|
|
100
|
+
this.socket.send(JSON.stringify({ id, method, params }));
|
|
101
|
+
return await Promise.race([result, new Promise((_, reject) => { timer = setTimeout(() => { this.pending.delete(id); reject(new Error(`CDP ${method} 超时`)); }, timeoutMs); })]);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
} }
|
|
93
106
|
async evaluate(expression) { const response = await this.cdp("Runtime.evaluate", { expression, returnByValue: true, awaitPromise: false }); if (response.result?.exceptionDetails)
|
|
94
107
|
throw new Error(`豆包页面 JS 异常: ${JSON.stringify(response.result.exceptionDetails).slice(0, 300)}`); return response.result?.result?.value; }
|
|
95
108
|
}
|
|
@@ -6,7 +6,7 @@ const plugin_1 = require("../../plugin");
|
|
|
6
6
|
const desktop_launch_1 = require("../desktop-launch");
|
|
7
7
|
exports.doubaoManifest = {
|
|
8
8
|
id: "doubao",
|
|
9
|
-
version: "1.0.
|
|
9
|
+
version: "1.0.11",
|
|
10
10
|
displayName: "豆包",
|
|
11
11
|
entry: "dist/index.js",
|
|
12
12
|
apiVersion: "1",
|
|
@@ -67,7 +67,7 @@ class DoubaoPlugin {
|
|
|
67
67
|
async deactivate() {
|
|
68
68
|
this.disposer?.();
|
|
69
69
|
this.disposer = undefined;
|
|
70
|
-
this.client?.close();
|
|
70
|
+
await this.client?.close();
|
|
71
71
|
this.client = undefined;
|
|
72
72
|
this.state = "stopped";
|
|
73
73
|
}
|
package/package.json
CHANGED