agent-bridge-service 0.2.3 → 1.1.0
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/CHANGELOG.md +122 -140
- package/README.md +526 -36
- package/README.zh-CN.md +457 -34
- package/assets/agent-icons/agy.svg +27 -0
- package/dist/adapters/acp-auth.js +51 -0
- package/dist/adapters/acp-codebuddy.js +507 -0
- package/dist/adapters/agent-adapters.js +470 -46
- package/dist/adapters/claude-stream.js +159 -0
- package/dist/adapters/codex-app-server.js +365 -0
- package/dist/adapters/host-env.js +48 -0
- package/dist/adapters/mcp-elicitation.js +148 -0
- package/dist/adapters/mcp-host.js +70 -0
- package/dist/adapters/step-parsers.js +583 -0
- package/dist/app/bootstrap.js +163 -74
- package/dist/app/claude-resident.js +204 -0
- package/dist/app/conversation.js +639 -0
- package/dist/app/service-gate.js +1 -1
- package/dist/app/session.js +426 -14
- package/dist/app/task-dispatch.js +883 -7
- package/dist/app/task-registry.js +168 -0
- package/dist/cli/dispatch.js +4 -0
- package/dist/cli/flags.js +11 -0
- package/dist/cli/help.js +26 -7
- package/dist/cli/panel.js +334 -0
- package/dist/cli/render.js +2 -0
- package/dist/commands/approvals.js +80 -0
- package/dist/commands/connect.js +124 -4
- package/dist/commands/daemon-service.js +81 -0
- package/dist/commands/daemon.js +269 -6
- package/dist/commands/logout.js +13 -10
- package/dist/commands/serve.js +100 -12
- package/dist/commands/sessions.js +106 -0
- package/dist/core/ansi.js +5 -0
- package/dist/core/artifact-extract.js +158 -0
- package/dist/core/artifact-transfer.js +583 -0
- package/dist/core/device-identity.js +22 -0
- package/dist/core/emitter.js +50 -8
- package/dist/core/errors.js +43 -0
- package/dist/core/form-schema.js +72 -0
- package/dist/core/interaction-broker.js +440 -0
- package/dist/core/interaction-url.js +63 -0
- package/dist/core/partial-messages.js +99 -0
- package/dist/core/permission-ledger.js +146 -0
- package/dist/core/permission-policy.js +88 -0
- package/dist/core/port-fallback.js +22 -0
- package/dist/core/redact.js +13 -0
- package/dist/core/scan.js +12 -7
- package/dist/core/session-store.js +1632 -0
- package/dist/core/task-supervisor.js +968 -30
- package/dist/infra/atomic-file.js +111 -0
- package/dist/infra/audit.js +7 -0
- package/dist/infra/auth.js +143 -40
- package/dist/infra/config.js +511 -72
- package/dist/infra/device-identity-store.js +87 -0
- package/dist/infra/jwt.js +149 -0
- package/dist/infra/profile-lock.js +295 -0
- package/dist/infra/proxy-env.js +81 -0
- package/dist/infra/service-token.js +25 -4
- package/dist/protocol.js +298 -2
- package/dist/transport/a2a-mapping.js +206 -0
- package/dist/transport/acp-gateway-mapping.js +186 -0
- package/dist/transport/bridge-client.js +31 -22
- package/dist/transport/control-plane-page.js +820 -0
- package/dist/transport/control-plane-sessions-page.js +90 -0
- package/dist/transport/control-plane.js +935 -71
- package/dist/transport/gateway.js +1023 -0
- package/dist/transport/office-preview.js +154 -0
- package/package.json +6 -3
- package/assets/agent-icons/gemini.svg +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MCP elicitation client (stdio JSON-RPC).
|
|
3
|
+
*
|
|
4
|
+
* MCP servers may ask the client for structured input:
|
|
5
|
+
* server -> client elicitation/create { message, requestedSchema }
|
|
6
|
+
* client -> server { action: 'accept'|'decline'|'cancel', content? }
|
|
7
|
+
*
|
|
8
|
+
* This module is transport-only: it does not decide policy, persist forms, or wire bridge
|
|
9
|
+
* interactions. Callers provide the elicitation handler (which can map to task_interaction_request).
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
12
|
+
import { createInterface } from 'node:readline';
|
|
13
|
+
export class McpElicitationClient {
|
|
14
|
+
options;
|
|
15
|
+
child;
|
|
16
|
+
rl;
|
|
17
|
+
nextId = 1;
|
|
18
|
+
pending = new Map();
|
|
19
|
+
closed = false;
|
|
20
|
+
timeoutMs;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.timeoutMs = options.timeoutMs ?? 15_000;
|
|
24
|
+
}
|
|
25
|
+
async start() {
|
|
26
|
+
if (this.child)
|
|
27
|
+
return;
|
|
28
|
+
const { spec } = this.options;
|
|
29
|
+
const child = spawn(spec.command, spec.args ?? [], {
|
|
30
|
+
cwd: spec.cwd,
|
|
31
|
+
env: spec.env ?? process.env,
|
|
32
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
33
|
+
windowsHide: true,
|
|
34
|
+
});
|
|
35
|
+
this.child = child;
|
|
36
|
+
this.rl = createInterface({ input: child.stdout });
|
|
37
|
+
this.rl.on('line', (line) => void this.onLine(line));
|
|
38
|
+
child.on('error', (error) => this.failAll(error));
|
|
39
|
+
child.on('close', () => {
|
|
40
|
+
this.closed = true;
|
|
41
|
+
this.failAll(new Error('MCP 进程已退出'));
|
|
42
|
+
});
|
|
43
|
+
await this.request('initialize', {
|
|
44
|
+
protocolVersion: this.options.protocolVersion ?? '2025-06-18',
|
|
45
|
+
capabilities: { elicitation: {} },
|
|
46
|
+
clientInfo: this.options.clientInfo ?? { name: 'agent-bridge', version: '1.0.0' },
|
|
47
|
+
});
|
|
48
|
+
this.send({ jsonrpc: '2.0', method: 'notifications/initialized' });
|
|
49
|
+
}
|
|
50
|
+
async listTools() {
|
|
51
|
+
await this.start();
|
|
52
|
+
const result = (await this.request('tools/list', {}));
|
|
53
|
+
return Array.isArray(result.tools) ? result.tools : [];
|
|
54
|
+
}
|
|
55
|
+
async callTool(name, args = {}, timeoutMs = this.timeoutMs) {
|
|
56
|
+
await this.start();
|
|
57
|
+
return this.request('tools/call', { name, arguments: args }, timeoutMs);
|
|
58
|
+
}
|
|
59
|
+
close() {
|
|
60
|
+
this.closed = true;
|
|
61
|
+
this.rl?.close();
|
|
62
|
+
this.child?.kill();
|
|
63
|
+
this.child?.stdin.destroy();
|
|
64
|
+
this.child?.stdout.destroy();
|
|
65
|
+
this.child?.stderr.destroy();
|
|
66
|
+
this.child?.unref();
|
|
67
|
+
this.failAll(new Error('MCP 客户端已关闭'));
|
|
68
|
+
}
|
|
69
|
+
send(message) {
|
|
70
|
+
const child = this.child;
|
|
71
|
+
if (!child || this.closed || !child.stdin.writable)
|
|
72
|
+
return;
|
|
73
|
+
child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
74
|
+
}
|
|
75
|
+
request(method, params, timeoutMs = this.timeoutMs) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const id = this.nextId++;
|
|
78
|
+
const timer = setTimeout(() => {
|
|
79
|
+
this.pending.delete(id);
|
|
80
|
+
reject(new Error(`MCP ${method} 超时(${timeoutMs}ms)`));
|
|
81
|
+
}, timeoutMs);
|
|
82
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
83
|
+
this.send({ jsonrpc: '2.0', id, method, params });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async onLine(line) {
|
|
87
|
+
const trimmed = line.trim();
|
|
88
|
+
if (!trimmed)
|
|
89
|
+
return;
|
|
90
|
+
let message;
|
|
91
|
+
try {
|
|
92
|
+
message = JSON.parse(trimmed);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const id = message['id'];
|
|
98
|
+
if (typeof id === 'number' && (message['result'] !== undefined || message['error'] !== undefined)) {
|
|
99
|
+
const pending = this.pending.get(id);
|
|
100
|
+
if (!pending)
|
|
101
|
+
return;
|
|
102
|
+
this.pending.delete(id);
|
|
103
|
+
clearTimeout(pending.timer);
|
|
104
|
+
if (message['error'] !== undefined) {
|
|
105
|
+
pending.reject(new Error(`MCP 错误:${JSON.stringify(message['error'])}`));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
pending.resolve(message['result']);
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (message['method'] === 'elicitation/create' && typeof id === 'number') {
|
|
113
|
+
const params = (message['params'] ?? {});
|
|
114
|
+
let response = { action: 'cancel' };
|
|
115
|
+
try {
|
|
116
|
+
response = this.options.onElicitation
|
|
117
|
+
? await this.options.onElicitation({
|
|
118
|
+
message: String(params['message'] ?? ''),
|
|
119
|
+
requestedSchema: typeof params['requestedSchema'] === 'object' && params['requestedSchema'] !== null
|
|
120
|
+
? params['requestedSchema']
|
|
121
|
+
: {},
|
|
122
|
+
raw: params,
|
|
123
|
+
})
|
|
124
|
+
: { action: 'cancel' };
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
response = { action: 'cancel' };
|
|
128
|
+
}
|
|
129
|
+
this.send({ jsonrpc: '2.0', id, result: response });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// 其他 server -> client 请求:明确返回 method not found,避免 stdio 对端挂死。
|
|
133
|
+
if (typeof id === 'number' && typeof message['method'] === 'string') {
|
|
134
|
+
this.send({
|
|
135
|
+
jsonrpc: '2.0',
|
|
136
|
+
id,
|
|
137
|
+
error: { code: -32601, message: `unsupported client method: ${message['method']}` },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
failAll(error) {
|
|
142
|
+
for (const pending of this.pending.values()) {
|
|
143
|
+
clearTimeout(pending.timer);
|
|
144
|
+
pending.reject(error);
|
|
145
|
+
}
|
|
146
|
+
this.pending.clear();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本机 MCP server 宿主:按 config.toml 的 [mcp.servers.*] 启动 stdio server,
|
|
3
|
+
* 复用 McpElicitationClient 完成 tools/list、tools/call 与 elicitation。
|
|
4
|
+
*
|
|
5
|
+
* 这是“配置入口 + 宿主”,不是平台 Form 的完整链路;平台交互仍由调用方注入 handler。
|
|
6
|
+
*/
|
|
7
|
+
import { McpElicitationClient } from './mcp-elicitation.js';
|
|
8
|
+
export class McpHost {
|
|
9
|
+
servers;
|
|
10
|
+
clients = new Map();
|
|
11
|
+
constructor(servers) {
|
|
12
|
+
this.servers = servers;
|
|
13
|
+
}
|
|
14
|
+
names() {
|
|
15
|
+
return Object.keys(this.servers).sort();
|
|
16
|
+
}
|
|
17
|
+
client(name) {
|
|
18
|
+
const spec = this.servers[name];
|
|
19
|
+
if (!spec)
|
|
20
|
+
throw new Error(`未配置 MCP server:${name}`);
|
|
21
|
+
const cached = this.clients.get(name);
|
|
22
|
+
if (cached)
|
|
23
|
+
return cached;
|
|
24
|
+
const client = new McpElicitationClient({
|
|
25
|
+
spec: {
|
|
26
|
+
command: spec.command,
|
|
27
|
+
args: spec.args ?? [],
|
|
28
|
+
cwd: spec.cwd ?? process.cwd(),
|
|
29
|
+
env: { ...process.env, ...(spec.env ?? {}) },
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
this.clients.set(name, client);
|
|
33
|
+
return client;
|
|
34
|
+
}
|
|
35
|
+
async listTools(name) {
|
|
36
|
+
return this.client(name).listTools();
|
|
37
|
+
}
|
|
38
|
+
async callTool(name, tool, args = {}, onElicitation) {
|
|
39
|
+
if (!this.servers[name])
|
|
40
|
+
throw new Error(`未配置 MCP server:${name}`);
|
|
41
|
+
if (onElicitation) {
|
|
42
|
+
const existing = this.clients.get(name);
|
|
43
|
+
if (existing) {
|
|
44
|
+
existing.close();
|
|
45
|
+
this.clients.delete(name);
|
|
46
|
+
}
|
|
47
|
+
return this.createWithHandler(name, onElicitation).callTool(tool, args);
|
|
48
|
+
}
|
|
49
|
+
return this.client(name).callTool(tool, args);
|
|
50
|
+
}
|
|
51
|
+
createWithHandler(name, onElicitation) {
|
|
52
|
+
const spec = this.servers[name];
|
|
53
|
+
const client = new McpElicitationClient({
|
|
54
|
+
spec: {
|
|
55
|
+
command: spec.command,
|
|
56
|
+
args: spec.args ?? [],
|
|
57
|
+
cwd: spec.cwd ?? process.cwd(),
|
|
58
|
+
env: { ...process.env, ...(spec.env ?? {}) },
|
|
59
|
+
},
|
|
60
|
+
...(onElicitation ? { onElicitation } : {}),
|
|
61
|
+
});
|
|
62
|
+
this.clients.set(name, client);
|
|
63
|
+
return client;
|
|
64
|
+
}
|
|
65
|
+
close() {
|
|
66
|
+
for (const client of this.clients.values())
|
|
67
|
+
client.close();
|
|
68
|
+
this.clients.clear();
|
|
69
|
+
}
|
|
70
|
+
}
|