agent-bridge-service 0.2.2 → 1.0.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +112 -140
  2. package/README.md +508 -35
  3. package/README.zh-CN.md +443 -33
  4. package/assets/agent-icons/agy.svg +27 -0
  5. package/dist/adapters/acp-auth.js +51 -0
  6. package/dist/adapters/acp-codebuddy.js +507 -0
  7. package/dist/adapters/agent-adapters.js +466 -46
  8. package/dist/adapters/claude-stream.js +159 -0
  9. package/dist/adapters/codex-app-server.js +310 -0
  10. package/dist/adapters/host-env.js +48 -0
  11. package/dist/adapters/mcp-elicitation.js +148 -0
  12. package/dist/adapters/mcp-host.js +70 -0
  13. package/dist/adapters/step-parsers.js +583 -0
  14. package/dist/app/bootstrap.js +163 -74
  15. package/dist/app/claude-resident.js +204 -0
  16. package/dist/app/conversation.js +639 -0
  17. package/dist/app/service-gate.js +1 -1
  18. package/dist/app/session.js +425 -14
  19. package/dist/app/task-dispatch.js +883 -7
  20. package/dist/app/task-registry.js +168 -0
  21. package/dist/cli/dispatch.js +4 -0
  22. package/dist/cli/flags.js +11 -0
  23. package/dist/cli/help.js +25 -7
  24. package/dist/cli/panel.js +334 -0
  25. package/dist/cli/render.js +2 -0
  26. package/dist/commands/approvals.js +80 -0
  27. package/dist/commands/connect.js +122 -4
  28. package/dist/commands/daemon-service.js +81 -0
  29. package/dist/commands/daemon.js +269 -6
  30. package/dist/commands/logout.js +13 -10
  31. package/dist/commands/serve.js +98 -12
  32. package/dist/commands/sessions.js +106 -0
  33. package/dist/core/ansi.js +5 -0
  34. package/dist/core/artifact-extract.js +158 -0
  35. package/dist/core/artifact-transfer.js +583 -0
  36. package/dist/core/device-identity.js +22 -0
  37. package/dist/core/emitter.js +50 -8
  38. package/dist/core/errors.js +43 -0
  39. package/dist/core/form-schema.js +72 -0
  40. package/dist/core/interaction-broker.js +440 -0
  41. package/dist/core/interaction-url.js +63 -0
  42. package/dist/core/partial-messages.js +99 -0
  43. package/dist/core/permission-ledger.js +146 -0
  44. package/dist/core/permission-policy.js +88 -0
  45. package/dist/core/port-fallback.js +22 -0
  46. package/dist/core/redact.js +13 -0
  47. package/dist/core/scan.js +12 -7
  48. package/dist/core/session-store.js +1632 -0
  49. package/dist/core/task-supervisor.js +955 -30
  50. package/dist/infra/atomic-file.js +111 -0
  51. package/dist/infra/audit.js +7 -0
  52. package/dist/infra/auth.js +167 -42
  53. package/dist/infra/config.js +511 -72
  54. package/dist/infra/device-identity-store.js +87 -0
  55. package/dist/infra/jwt.js +149 -0
  56. package/dist/infra/profile-lock.js +295 -0
  57. package/dist/infra/proxy-env.js +60 -0
  58. package/dist/infra/service-token.js +25 -4
  59. package/dist/protocol.js +298 -2
  60. package/dist/transport/a2a-mapping.js +206 -0
  61. package/dist/transport/acp-gateway-mapping.js +186 -0
  62. package/dist/transport/bridge-client.js +31 -22
  63. package/dist/transport/control-plane-page.js +820 -0
  64. package/dist/transport/control-plane-sessions-page.js +90 -0
  65. package/dist/transport/control-plane.js +923 -71
  66. package/dist/transport/gateway.js +1005 -0
  67. package/dist/transport/office-preview.js +154 -0
  68. package/package.json +6 -3
  69. package/assets/agent-icons/gemini.svg +0 -1
@@ -0,0 +1,154 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { extname } from 'node:path';
3
+ import { inflateRawSync } from 'node:zlib';
4
+ /**
5
+ * Office 文件内容预览(本地解析,不上传第三方服务)。
6
+ * 仅提取可读内容:docx 段落、xlsx 工作表、pptx 幻灯片文本。
7
+ * 不是完整 Office 排版引擎;目的是让结果文件无需下载也能快速阅读。
8
+ */
9
+ function zipEntries(file) {
10
+ const entries = new Map();
11
+ const eocd = (() => {
12
+ for (let i = file.length - 22; i >= Math.max(0, file.length - 65557); i -= 1) {
13
+ if (file.readUInt32LE(i) === 0x06054b50)
14
+ return i;
15
+ }
16
+ return -1;
17
+ })();
18
+ if (eocd < 0)
19
+ throw new Error('invalid zip');
20
+ const centralOffset = file.readUInt32LE(eocd + 16);
21
+ const count = file.readUInt16LE(eocd + 10);
22
+ let cursor = centralOffset;
23
+ for (let i = 0; i < count && cursor + 46 <= file.length; i += 1) {
24
+ if (file.readUInt32LE(cursor) !== 0x02014b50)
25
+ break;
26
+ const compression = file.readUInt16LE(cursor + 10);
27
+ const compressedSize = file.readUInt32LE(cursor + 20);
28
+ const nameLength = file.readUInt16LE(cursor + 28);
29
+ const extraLength = file.readUInt16LE(cursor + 30);
30
+ const commentLength = file.readUInt16LE(cursor + 32);
31
+ const localOffset = file.readUInt32LE(cursor + 42);
32
+ const name = file.toString('utf8', cursor + 46, cursor + 46 + nameLength);
33
+ const localNameLength = file.readUInt16LE(localOffset + 26);
34
+ const localExtraLength = file.readUInt16LE(localOffset + 28);
35
+ const dataStart = localOffset + 30 + localNameLength + localExtraLength;
36
+ const compressed = file.subarray(dataStart, dataStart + compressedSize);
37
+ if (compression === 0)
38
+ entries.set(name, compressed);
39
+ else if (compression === 8)
40
+ entries.set(name, inflateRawSync(compressed));
41
+ cursor += 46 + nameLength + extraLength + commentLength;
42
+ }
43
+ return entries;
44
+ }
45
+ function decodeXml(s) {
46
+ return s
47
+ .replace(/&lt;/g, '<')
48
+ .replace(/&gt;/g, '>')
49
+ .replace(/&quot;/g, '"')
50
+ .replace(/&apos;/g, "'")
51
+ .replace(/&amp;/g, '&')
52
+ .replace(/&#(\d+);/g, (_, n) => String.fromCharCode(Number(n)))
53
+ .replace(/&#x([\da-f]+);/gi, (_, n) => String.fromCharCode(parseInt(n, 16)));
54
+ }
55
+ function textOfXml(xml, tag) {
56
+ return [...xml.matchAll(new RegExp(`<${tag}(?:\\s[^>]*)?>([\\s\\S]*?)<\\/${tag}>`, 'g'))]
57
+ .map((m) => decodeXml((m[1] ?? '').replace(/<[^>]+>/g, '')))
58
+ .join('');
59
+ }
60
+ function paragraphs(xml) {
61
+ const out = [];
62
+ for (const p of xml.matchAll(/<w:p\b[^>]*>([\s\S]*?)<\/w:p>/g)) {
63
+ const text = textOfXml(p[1] ?? '', 'w:t');
64
+ if (text.trim())
65
+ out.push(text);
66
+ }
67
+ return out;
68
+ }
69
+ function columnIndex(ref) {
70
+ let n = 0;
71
+ for (const ch of ref.replace(/[^A-Z]/gi, '').toUpperCase())
72
+ n = n * 26 + ch.charCodeAt(0) - 64;
73
+ return Math.max(0, n - 1);
74
+ }
75
+ function escapeHtml(s) {
76
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
77
+ }
78
+ function officeHtml(body) {
79
+ return `<!doctype html><html><head><meta charset="utf-8"><style>
80
+ body{font:14px/1.65 -apple-system,"Segoe UI","Microsoft YaHei",sans-serif;color:#243447;padding:24px;max-width:980px;margin:auto}
81
+ h1{font-size:20px;margin:0 0 18px}h2{font-size:15px;margin:22px 0 8px;color:#3b506b}
82
+ p{margin:7px 0;white-space:pre-wrap}table{border-collapse:collapse;width:100%;font-size:12px}
83
+ td,th{border:1px solid #dce4ee;padding:6px 8px;text-align:left;white-space:pre-wrap}th{background:#f2f6fa}
84
+ .slide{border:1px solid #e0e7ef;border-radius:10px;padding:14px;margin:12px 0;background:#fafcfd}
85
+ </style></head><body>${body}</body></html>`;
86
+ }
87
+ function renderXlsx(files) {
88
+ const workbook = files.get('xl/workbook.xml');
89
+ const rels = files.get('xl/_rels/workbook.xml.rels');
90
+ if (!workbook)
91
+ return '';
92
+ const relMap = new Map();
93
+ if (rels) {
94
+ for (const m of rels.toString('utf8').matchAll(/<Relationship\b[^>]*Id="([^"]+)"[^>]*Target="([^"]+)"/g))
95
+ relMap.set(m[1] ?? '', m[2] ?? '');
96
+ }
97
+ const shared = files.get('xl/sharedStrings.xml');
98
+ const sharedStrings = shared ? [...shared.toString('utf8').matchAll(/<si\b[^>]*>([\s\S]*?)<\/si>/g)].map((m) => textOfXml(m[1] ?? '', 't')) : [];
99
+ const sheets = [];
100
+ for (const sheet of workbook.toString('utf8').matchAll(/<sheet\b[^>]*name="([^"]+)"[^>]*r:id="([^"]+)"/g)) {
101
+ const target = relMap.get(sheet[2] ?? '') || `worksheets/sheet${sheets.length + 1}.xml`;
102
+ const xml = files.get(`xl/${target.replace(/^\//, '')}`)?.toString('utf8');
103
+ if (!xml)
104
+ continue;
105
+ const rows = [];
106
+ for (const row of xml.matchAll(/<row\b[^>]*>([\s\S]*?)<\/row>/g)) {
107
+ const cells = [];
108
+ for (const cell of (row[1] ?? '').matchAll(/<c\b([^>]*)>([\s\S]*?)<\/c>/g)) {
109
+ const attrs = cell[1] ?? '';
110
+ const ref = (attrs.match(/r="([A-Z]+)\d+"/i) || [])[1] || 'A';
111
+ const idx = columnIndex(ref);
112
+ const type = (attrs.match(/t="([^"]+)"/) || [])[1];
113
+ let value = '';
114
+ if (type === 'inlineStr')
115
+ value = textOfXml(cell[2] ?? '', 't');
116
+ else {
117
+ const raw = textOfXml(cell[2] ?? '', 'v');
118
+ value = type === 's' ? sharedStrings[Number(raw)] || raw : raw;
119
+ }
120
+ cells[idx] = value;
121
+ }
122
+ rows.push(`<tr>${cells.map((c) => `<td>${escapeHtml(c)}</td>`).join('')}</tr>`);
123
+ }
124
+ sheets.push(`<h2>${escapeHtml(sheet[1] ?? '')}</h2><table>${rows.slice(0, 100).join('')}</table>`);
125
+ }
126
+ return sheets.join('');
127
+ }
128
+ function renderPptx(files) {
129
+ const slides = [...files.keys()].filter((k) => /^ppt\/slides\/slide\d+\.xml$/.test(k)).sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
130
+ return slides.map((name, i) => {
131
+ const xml = files.get(name).toString('utf8');
132
+ const paragraphs = [...xml.matchAll(/<a:p\b[^>]*>([\s\S]*?)<\/a:p>/g)]
133
+ .map((p) => textOfXml(p[1] ?? '', 'a:t')).filter((t) => t.trim());
134
+ return `<div class="slide"><h2>幻灯片 ${i + 1}</h2>${paragraphs.map((p) => `<p>${escapeHtml(p)}</p>`).join('')}</div>`;
135
+ }).join('');
136
+ }
137
+ export function renderOfficePreview(path) {
138
+ const ext = extname(path).toLowerCase();
139
+ if (!['.docx', '.xlsx', '.pptx'].includes(ext))
140
+ return null;
141
+ const files = zipEntries(readFileSync(path));
142
+ if (ext === '.docx') {
143
+ const xml = files.get('word/document.xml')?.toString('utf8') || '';
144
+ return `<h1>Word 文档</h1>${paragraphs(xml).map((p) => `<p>${escapeHtml(p)}</p>`).join('') || '<p>(未提取到文本)</p>'}`;
145
+ }
146
+ if (ext === '.xlsx')
147
+ return `<h1>Excel 工作簿</h1>${renderXlsx(files)}`;
148
+ return `<h1>PowerPoint 演示文稿</h1>${renderPptx(files)}`;
149
+ }
150
+ export const OFFICE_MIME_TYPES = {
151
+ '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
152
+ '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
153
+ '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
154
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-service",
3
- "version": "0.2.2",
3
+ "version": "1.0.0",
4
4
  "description": "Give a remote platform control of the AI agents installed on your machine, over an outbound WebSocket",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,7 +14,7 @@
14
14
  "CHANGELOG.md"
15
15
  ],
16
16
  "engines": {
17
- "node": ">=20"
17
+ "node": ">=24 <25"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsc -p tsconfig.json",
@@ -34,7 +34,8 @@
34
34
  "site:preview": "npm --prefix site run preview",
35
35
  "site:check": "npm --prefix site run check",
36
36
  "openspec:validate": "bash .harness/skills/openspec-workflow/scripts/validate-change.sh",
37
- "e2e:smoke": "node .harness/skills/protocol-e2e/scripts/e2e-smoke.mjs"
37
+ "e2e:smoke": "node .harness/skills/protocol-e2e/scripts/e2e-smoke.mjs",
38
+ "e2e:gateway": "node scripts/gateway-e2e.mjs"
38
39
  },
39
40
  "keywords": [
40
41
  "ai",
@@ -49,6 +50,7 @@
49
50
  ],
50
51
  "license": "MIT",
51
52
  "dependencies": {
53
+ "better-sqlite3": "^12.11.1",
52
54
  "smol-toml": "^1.3.1",
53
55
  "ws": "^8.18.3"
54
56
  },
@@ -60,6 +62,7 @@
60
62
  "@semantic-release/github": "^12.0.10",
61
63
  "@semantic-release/npm": "^13.2.0",
62
64
  "@semantic-release/release-notes-generator": "^14.1.1",
65
+ "@types/better-sqlite3": "^9.6.0",
63
66
  "@types/node": "^22.15.0",
64
67
  "@types/ws": "^8.18.1",
65
68
  "husky": "^9.1.7",
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>Gemini</title><g transform="translate(1.0909 1.0909) scale(0.9091)"><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="#3186FF"></path><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="url(#lobe-icons-gemini-0-_R_0_)"></path><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="url(#lobe-icons-gemini-1-_R_0_)"></path><path d="M20.616 10.835a14.147 14.147 0 01-4.45-3.001 14.111 14.111 0 01-3.678-6.452.503.503 0 00-.975 0 14.134 14.134 0 01-3.679 6.452 14.155 14.155 0 01-4.45 3.001c-.65.28-1.318.505-2.002.678a.502.502 0 000 .975c.684.172 1.35.397 2.002.677a14.147 14.147 0 014.45 3.001 14.112 14.112 0 013.679 6.453.502.502 0 00.975 0c.172-.685.397-1.351.677-2.003a14.145 14.145 0 013.001-4.45 14.113 14.113 0 016.453-3.678.503.503 0 000-.975 13.245 13.245 0 01-2.003-.678z" fill="url(#lobe-icons-gemini-2-_R_0_)"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-0-_R_0_" x1="7" x2="11" y1="15.5" y2="12"><stop stop-color="#08B962"></stop><stop offset="1" stop-color="#08B962" stop-opacity="0"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-1-_R_0_" x1="8" x2="11.5" y1="5.5" y2="11"><stop stop-color="#F94543"></stop><stop offset="1" stop-color="#F94543" stop-opacity="0"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-2-_R_0_" x1="3.5" x2="17.5" y1="13.5" y2="12"><stop stop-color="#FABC12"></stop><stop offset=".46" stop-color="#FABC12" stop-opacity="0"></stop></linearGradient></defs></g></svg>