agent-bridge-qwenwork 1.0.1 → 1.0.3

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.
@@ -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
  }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveRuntimePort = resolveRuntimePort;
4
+ function resolveRuntimePort(config, runtime, pluginId, envName, fallback) {
5
+ const injected = runtime?.ports?.[pluginId];
6
+ if (typeof injected === "number" && Number.isInteger(injected) && injected > 0)
7
+ return injected;
8
+ const configured = config.cdpPort;
9
+ if (typeof configured === "number" && Number.isInteger(configured) && configured > 0)
10
+ return configured;
11
+ const environment = Number(process.env[envName] ?? "");
12
+ return Number.isInteger(environment) && environment > 0 ? environment : fallback;
13
+ }
@@ -27,7 +27,7 @@ class QwenCdpClient {
27
27
  options;
28
28
  constructor(options = {}) {
29
29
  this.options = {
30
- port: options.port ?? Number(process.env.QWEN_CDP_PORT ?? "9226"),
30
+ port: options.port ?? Number(process.env.QWEN_CDP_PORT ?? "9228"),
31
31
  subChatId: options.subChatId ?? process.env.QWEN_SUBCHAT ?? "muj55ep9426gudjw",
32
32
  chatId: options.chatId ?? process.env.QWEN_CHAT ?? "muj55ep9u6wbv0eo",
33
33
  workspace: options.workspace ?? `${process.env.APPDATA ?? ""}\\QwenWorkCN\\workspace`,
@@ -40,7 +40,14 @@ class QwenCdpClient {
40
40
  if (this.socket)
41
41
  return;
42
42
  const fetchImpl = this.options.fetchImpl ?? fetch;
43
- const response = await fetchImpl(`http://127.0.0.1:${this.options.port}/json`);
43
+ let response;
44
+ try {
45
+ response = await fetchImpl(`http://127.0.0.1:${this.options.port}/json`);
46
+ }
47
+ catch (error) {
48
+ const code = error?.cause?.code ?? String(error);
49
+ throw new Error(`无法连接千问办公 CDP 端口 ${this.options.port}(请先以 --remote-debugging-port=${this.options.port} 启动千问办公客户端): ${code}`);
50
+ }
44
51
  if (!response.ok)
45
52
  throw new Error(`CDP /json HTTP ${response.status}`);
46
53
  const targets = await response.json();
@@ -4,16 +4,17 @@ exports.QwenworkPlugin = exports.qwenworkManifest = void 0;
4
4
  exports.createQwenworkPlugin = createQwenworkPlugin;
5
5
  const openai_adapter_1 = require("./openai-adapter");
6
6
  const cdp_client_1 = require("./cdp-client");
7
+ const plugin_1 = require("../../plugin");
7
8
  exports.qwenworkManifest = {
8
9
  id: "qwenwork",
9
- version: "1.0.1",
10
+ version: "1.0.3",
10
11
  displayName: "千问办公",
11
12
  entry: "dist/index.js",
12
13
  apiVersion: "1",
13
14
  process: "in-process",
14
15
  capabilities: ["chat", "openai-compatible", "health"],
15
16
  configSchema: "config.schema.json",
16
- defaults: { cdpPort: 9226, httpPort: 17893 },
17
+ defaults: { cdpPort: 9228, httpPort: 17893 },
17
18
  };
18
19
  function asNumber(value, fallback) {
19
20
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
@@ -27,6 +28,9 @@ class QwenworkPlugin {
27
28
  configuredCdpPort;
28
29
  activeCdpPort;
29
30
  configuredHttpPort;
31
+ relayTarget;
32
+ callPlugin;
33
+ pluginStatus;
30
34
  disposers = [];
31
35
  requestQueue = Promise.resolve();
32
36
  state = "stopped";
@@ -42,16 +46,26 @@ class QwenworkPlugin {
42
46
  this.state = "starting";
43
47
  try {
44
48
  const config = context.config;
45
- this.activeCdpPort = asNumber(config.cdpPort, this.configuredCdpPort ?? exports.qwenworkManifest.defaults.cdpPort);
46
- const client = this.injectedClient ?? new cdp_client_1.QwenCdpClient({
47
- port: this.activeCdpPort,
48
- subChatId: typeof config.subChatId === "string" ? config.subChatId : undefined,
49
- chatId: typeof config.chatId === "string" ? config.chatId : undefined,
50
- workspace: typeof config.workspace === "string" ? config.workspace : undefined,
51
- });
52
- this.client = client;
53
- await client.connect();
54
- this.adapter = new openai_adapter_1.OpenAIAdapter((prompt, signal) => this.enqueue(() => client.direct(prompt, asNumber(config.timeoutMs, 240_000), signal)), {
49
+ const relayTarget = config.relayTarget;
50
+ if (relayTarget !== undefined && relayTarget !== "dsh")
51
+ throw new Error("无效的中继目标,仅支持 dsh");
52
+ if (relayTarget === "dsh" && !context.callPlugin)
53
+ throw new Error("中继目标 dsh 不可调用");
54
+ this.relayTarget = relayTarget === "dsh" ? relayTarget : undefined;
55
+ this.callPlugin = context.callPlugin;
56
+ this.pluginStatus = context.pluginStatus;
57
+ this.activeCdpPort = (0, plugin_1.resolveRuntimePort)(config, context.runtime, "qwenwork", "QWEN_CDP_PORT", this.configuredCdpPort ?? exports.qwenworkManifest.defaults.cdpPort);
58
+ if (!this.relayTarget) {
59
+ const client = this.injectedClient ?? new cdp_client_1.QwenCdpClient({
60
+ port: this.activeCdpPort,
61
+ subChatId: typeof config.subChatId === "string" ? config.subChatId : undefined,
62
+ chatId: typeof config.chatId === "string" ? config.chatId : undefined,
63
+ workspace: typeof config.workspace === "string" ? config.workspace : undefined,
64
+ });
65
+ this.client = client;
66
+ await client.connect();
67
+ }
68
+ this.adapter = new openai_adapter_1.OpenAIAdapter((prompt, signal) => this.enqueue(() => this.complete(prompt, asNumber(config.timeoutMs, 240_000), signal)), {
55
69
  onLog: (message) => context.logger?.info(message),
56
70
  onExchange: (direction, text, peer, agentAid) => context.logger?.info("千问通信", { direction, text, peer, agentAid }),
57
71
  });
@@ -80,16 +94,27 @@ class QwenworkPlugin {
80
94
  }
81
95
  async health() {
82
96
  const details = { cdpPort: this.activeCdpPort ?? exports.qwenworkManifest.defaults.cdpPort, httpPort: this.configuredHttpPort ?? exports.qwenworkManifest.defaults.httpPort };
97
+ if (this.state === "ready" && this.relayTarget && this.pluginStatus?.(this.relayTarget) !== "ready")
98
+ return { status: "degraded", message: "DSH 中继目标未就绪", details: { ...details, relayTarget: this.relayTarget } };
83
99
  if (this.state === "ready" && this.client && !this.client.connected())
84
100
  return { status: "degraded", message: "千问 CDP 已断开", details };
85
101
  return { status: this.state, ...(this.message ? { message: this.message } : {}), details };
86
102
  }
87
103
  async handle(request) {
88
- if (this.state !== "ready" || !this.client)
104
+ if (this.state !== "ready" || (!this.relayTarget && !this.client))
89
105
  throw new Error("qwenwork 插件未就绪");
90
- const text = await this.enqueue(() => this.client.direct(request.task, request.timeoutMs ?? 240_000));
106
+ const text = await this.enqueue(() => this.complete(request.task, request.timeoutMs ?? 240_000));
91
107
  return { text };
92
108
  }
109
+ async complete(prompt, timeoutMs, signal) {
110
+ if (this.relayTarget) {
111
+ const response = await this.callPlugin(this.relayTarget, { task: prompt, timeoutMs });
112
+ return response.text;
113
+ }
114
+ if (!this.client)
115
+ throw new Error("qwenwork 插件未就绪");
116
+ return this.client.direct(prompt, timeoutMs, signal);
117
+ }
93
118
  registerRoutes(http) {
94
119
  if (!this.adapter)
95
120
  return;
@@ -107,6 +132,9 @@ class QwenworkPlugin {
107
132
  this.adapter = undefined;
108
133
  this.client?.close();
109
134
  this.client = undefined;
135
+ this.relayTarget = undefined;
136
+ this.callPlugin = undefined;
137
+ this.pluginStatus = undefined;
110
138
  }
111
139
  enqueue(operation) {
112
140
  const run = this.requestQueue.then(operation, operation);
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "agent-bridge-qwenwork",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "agent-bridge 的千问办公插件。",
5
- "keywords": ["mu-agent-bridge-plugin", "mu-agent-bridge-agent"],
6
- "repository": { "type": "git", "url": "https://codeup.aliyun.com/6808da56fb3da14b899afd54/agent_bridge.git", "directory": "packages/qwenwork" },
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
+ },
7
14
  "main": "dist/src-ts/plugins/qwenwork/index.js",
8
15
  "files": [
9
16
  "dist/",
package/plugin.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "id": "qwenwork",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "agent",
5
5
  "displayName": "千问办公",
6
6
  "entry": "dist/src-ts/plugins/qwenwork/index.js",
7
7
  "apiVersion": "1",
8
8
  "process": "in-process",
9
- "capabilities": ["chat", "openai-compatible", "health"],
10
- "configSchema": "config.schema.json"
9
+ "capabilities": [
10
+ "chat",
11
+ "openai-compatible",
12
+ "health"
13
+ ],
14
+ "configSchema": "config.schema.json",
15
+ "clientDownloadUrl": "https://tongyi.aliyun.com/"
11
16
  }