agent-bridge-qwenwork 1.0.0 → 1.0.2
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/config.schema.json +2 -1
- package/dist/src-ts/plugins/qwenwork/index.js +39 -12
- package/package.json +12 -3
- package/plugin.json +7 -2
package/config.schema.json
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"subChatId": { "type": "string" },
|
|
9
9
|
"chatId": { "type": "string" },
|
|
10
10
|
"workspace": { "type": "string" },
|
|
11
|
-
"timeoutMs": { "type": "integer", "minimum": 1000, "default": 240000 }
|
|
11
|
+
"timeoutMs": { "type": "integer", "minimum": 1000, "default": 240000 },
|
|
12
|
+
"relayTarget": { "type": "string", "enum": ["dsh"], "description": "将文本原样中继到 DSH,不调用千问 CDP" }
|
|
12
13
|
},
|
|
13
14
|
"additionalProperties": false
|
|
14
15
|
}
|
|
@@ -6,7 +6,7 @@ const openai_adapter_1 = require("./openai-adapter");
|
|
|
6
6
|
const cdp_client_1 = require("./cdp-client");
|
|
7
7
|
exports.qwenworkManifest = {
|
|
8
8
|
id: "qwenwork",
|
|
9
|
-
version: "1.0.
|
|
9
|
+
version: "1.0.2",
|
|
10
10
|
displayName: "千问办公",
|
|
11
11
|
entry: "dist/index.js",
|
|
12
12
|
apiVersion: "1",
|
|
@@ -27,6 +27,9 @@ class QwenworkPlugin {
|
|
|
27
27
|
configuredCdpPort;
|
|
28
28
|
activeCdpPort;
|
|
29
29
|
configuredHttpPort;
|
|
30
|
+
relayTarget;
|
|
31
|
+
callPlugin;
|
|
32
|
+
pluginStatus;
|
|
30
33
|
disposers = [];
|
|
31
34
|
requestQueue = Promise.resolve();
|
|
32
35
|
state = "stopped";
|
|
@@ -42,16 +45,26 @@ class QwenworkPlugin {
|
|
|
42
45
|
this.state = "starting";
|
|
43
46
|
try {
|
|
44
47
|
const config = context.config;
|
|
48
|
+
const relayTarget = config.relayTarget;
|
|
49
|
+
if (relayTarget !== undefined && relayTarget !== "dsh")
|
|
50
|
+
throw new Error("无效的中继目标,仅支持 dsh");
|
|
51
|
+
if (relayTarget === "dsh" && !context.callPlugin)
|
|
52
|
+
throw new Error("中继目标 dsh 不可调用");
|
|
53
|
+
this.relayTarget = relayTarget === "dsh" ? relayTarget : undefined;
|
|
54
|
+
this.callPlugin = context.callPlugin;
|
|
55
|
+
this.pluginStatus = context.pluginStatus;
|
|
45
56
|
this.activeCdpPort = asNumber(config.cdpPort, this.configuredCdpPort ?? exports.qwenworkManifest.defaults.cdpPort);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
if (!this.relayTarget) {
|
|
58
|
+
const client = this.injectedClient ?? new cdp_client_1.QwenCdpClient({
|
|
59
|
+
port: this.activeCdpPort,
|
|
60
|
+
subChatId: typeof config.subChatId === "string" ? config.subChatId : undefined,
|
|
61
|
+
chatId: typeof config.chatId === "string" ? config.chatId : undefined,
|
|
62
|
+
workspace: typeof config.workspace === "string" ? config.workspace : undefined,
|
|
63
|
+
});
|
|
64
|
+
this.client = client;
|
|
65
|
+
await client.connect();
|
|
66
|
+
}
|
|
67
|
+
this.adapter = new openai_adapter_1.OpenAIAdapter((prompt, signal) => this.enqueue(() => this.complete(prompt, asNumber(config.timeoutMs, 240_000), signal)), {
|
|
55
68
|
onLog: (message) => context.logger?.info(message),
|
|
56
69
|
onExchange: (direction, text, peer, agentAid) => context.logger?.info("千问通信", { direction, text, peer, agentAid }),
|
|
57
70
|
});
|
|
@@ -80,16 +93,27 @@ class QwenworkPlugin {
|
|
|
80
93
|
}
|
|
81
94
|
async health() {
|
|
82
95
|
const details = { cdpPort: this.activeCdpPort ?? exports.qwenworkManifest.defaults.cdpPort, httpPort: this.configuredHttpPort ?? exports.qwenworkManifest.defaults.httpPort };
|
|
96
|
+
if (this.state === "ready" && this.relayTarget && this.pluginStatus?.(this.relayTarget) !== "ready")
|
|
97
|
+
return { status: "degraded", message: "DSH 中继目标未就绪", details: { ...details, relayTarget: this.relayTarget } };
|
|
83
98
|
if (this.state === "ready" && this.client && !this.client.connected())
|
|
84
99
|
return { status: "degraded", message: "千问 CDP 已断开", details };
|
|
85
100
|
return { status: this.state, ...(this.message ? { message: this.message } : {}), details };
|
|
86
101
|
}
|
|
87
102
|
async handle(request) {
|
|
88
|
-
if (this.state !== "ready" || !this.client)
|
|
103
|
+
if (this.state !== "ready" || (!this.relayTarget && !this.client))
|
|
89
104
|
throw new Error("qwenwork 插件未就绪");
|
|
90
|
-
const text = await this.enqueue(() => this.
|
|
105
|
+
const text = await this.enqueue(() => this.complete(request.task, request.timeoutMs ?? 240_000));
|
|
91
106
|
return { text };
|
|
92
107
|
}
|
|
108
|
+
async complete(prompt, timeoutMs, signal) {
|
|
109
|
+
if (this.relayTarget) {
|
|
110
|
+
const response = await this.callPlugin(this.relayTarget, { task: prompt, timeoutMs });
|
|
111
|
+
return response.text;
|
|
112
|
+
}
|
|
113
|
+
if (!this.client)
|
|
114
|
+
throw new Error("qwenwork 插件未就绪");
|
|
115
|
+
return this.client.direct(prompt, timeoutMs, signal);
|
|
116
|
+
}
|
|
93
117
|
registerRoutes(http) {
|
|
94
118
|
if (!this.adapter)
|
|
95
119
|
return;
|
|
@@ -107,6 +131,9 @@ class QwenworkPlugin {
|
|
|
107
131
|
this.adapter = undefined;
|
|
108
132
|
this.client?.close();
|
|
109
133
|
this.client = undefined;
|
|
134
|
+
this.relayTarget = undefined;
|
|
135
|
+
this.callPlugin = undefined;
|
|
136
|
+
this.pluginStatus = undefined;
|
|
110
137
|
}
|
|
111
138
|
enqueue(operation) {
|
|
112
139
|
const run = this.requestQueue.then(operation, operation);
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-bridge-qwenwork",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "agent-bridge 的千问办公插件。",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mu-agent-bridge-plugin",
|
|
7
|
+
"mu-agent-bridge-agent"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://codeup.aliyun.com/6808da56fb3da14b899afd54/agent_bridge.git",
|
|
12
|
+
"directory": "packages/qwenwork"
|
|
13
|
+
},
|
|
6
14
|
"main": "dist/src-ts/plugins/qwenwork/index.js",
|
|
7
15
|
"files": [
|
|
8
16
|
"dist/",
|
|
@@ -11,7 +19,8 @@
|
|
|
11
19
|
"README.md"
|
|
12
20
|
],
|
|
13
21
|
"agentBridge": {
|
|
14
|
-
"plugin": "./plugin.json"
|
|
22
|
+
"plugin": "./plugin.json",
|
|
23
|
+
"type": "agent"
|
|
15
24
|
},
|
|
16
25
|
"publishConfig": {
|
|
17
26
|
"access": "public",
|
package/plugin.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "qwenwork",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"type": "agent",
|
|
4
5
|
"displayName": "千问办公",
|
|
5
6
|
"entry": "dist/src-ts/plugins/qwenwork/index.js",
|
|
6
7
|
"apiVersion": "1",
|
|
7
8
|
"process": "in-process",
|
|
8
|
-
"capabilities": [
|
|
9
|
+
"capabilities": [
|
|
10
|
+
"chat",
|
|
11
|
+
"openai-compatible",
|
|
12
|
+
"health"
|
|
13
|
+
],
|
|
9
14
|
"configSchema": "config.schema.json"
|
|
10
15
|
}
|