@securecoms/agent-bridge 0.3.2 → 0.5.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 (47) hide show
  1. package/README.md +21 -1
  2. package/dist/bin.js +1073 -90
  3. package/dist/bridge-agent.d.ts +68 -7
  4. package/dist/config.d.ts +7 -0
  5. package/dist/http-server.d.ts +42 -0
  6. package/dist/index.js +837 -63
  7. package/dist/memory/hermes-provider.d.ts +21 -0
  8. package/dist/memory/hermes-session-map.d.ts +8 -0
  9. package/dist/memory/hermes-store.d.ts +32 -0
  10. package/dist/memory/hermes-test-fixture.d.ts +5 -0
  11. package/dist/memory/openclaw-provider.d.ts +24 -0
  12. package/dist/memory/openclaw-session-log.d.ts +15 -0
  13. package/dist/memory/openclaw-session-map.d.ts +7 -0
  14. package/dist/memory/provider.d.ts +29 -0
  15. package/dist/memory-taps.d.ts +13 -0
  16. package/dist/preflight-modern.cjs +35 -0
  17. package/dist/preflight-modern.d.cts +1 -0
  18. package/dist/preflight-upgrade.d.cts +30 -0
  19. package/dist/preflight.cjs +277 -0
  20. package/dist/preflight.d.cts +14 -0
  21. package/dist/service/config.d.ts +1 -0
  22. package/dist/service/install-prep.d.ts +68 -0
  23. package/package.json +3 -5
  24. package/dist/attachments.js +0 -49
  25. package/dist/auth.js +0 -56
  26. package/dist/bin.js.pre-c1-f803007 +0 -5795
  27. package/dist/bin.js.pre-c3-096a9a3 +0 -5832
  28. package/dist/bin.js.pre-ffrebuild-b162d4a +0 -5639
  29. package/dist/bin.js.pre-kpheal-20260708-150924 +0 -5531
  30. package/dist/bin.js.pre-kppersist-20260708-152341 +0 -5543
  31. package/dist/bin.js.pre-p0-20260708-102415 +0 -5196
  32. package/dist/bin.js.pre-p1b-02f47e1 +0 -5639
  33. package/dist/bin.js.pre-warmfix-20260708-153705 +0 -5613
  34. package/dist/bin.js.pretrace-113205 +0 -5395
  35. package/dist/bridge-agent.js +0 -831
  36. package/dist/config.js +0 -74
  37. package/dist/coordination.js +0 -63
  38. package/dist/errors.js +0 -25
  39. package/dist/http-server.js +0 -220
  40. package/dist/index.js.pre-p0-20260708-102415 +0 -4879
  41. package/dist/latency.js +0 -87
  42. package/dist/rate-limit.js +0 -56
  43. package/dist/service/config.js +0 -26
  44. package/dist/service/install.js +0 -60
  45. package/dist/service/launchd.js +0 -30
  46. package/dist/service/systemd.js +0 -25
  47. package/dist/ws-server.js +0 -254
@@ -1,49 +0,0 @@
1
- import { basename } from "node:path";
2
- /** Reduce any name to a safe basename inside the target dir. Strips path
3
- * separators and `..`; falls back when nothing usable remains. */
4
- export function sanitizeFilename(name, fallback) {
5
- const base = basename(name ?? "");
6
- const cleaned = base.replace(/[/\\]/g, "").replace(/^\.+$/, "");
7
- return cleaned.length > 0 ? cleaned : fallback;
8
- }
9
- const MIME_BY_EXT = {
10
- png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif",
11
- webp: "image/webp", svg: "image/svg+xml", pdf: "application/pdf",
12
- txt: "text/plain", md: "text/markdown", json: "application/json",
13
- csv: "text/csv", html: "text/html", mp4: "video/mp4", mp3: "audio/mpeg",
14
- zip: "application/zip", wav: "audio/wav",
15
- };
16
- export function mimeForName(name) {
17
- const dot = name.lastIndexOf(".");
18
- if (dot < 0 || dot === name.length - 1)
19
- return "application/octet-stream";
20
- return MIME_BY_EXT[name.slice(dot + 1).toLowerCase()] ?? "application/octet-stream";
21
- }
22
- export async function prepareAttachment(filePath, caption, channelId, deps) {
23
- const bytes = await deps.readFile(filePath);
24
- const name = basename(filePath);
25
- const { encryptedData, fileKey, fileNonce, digest } = deps.encryptFile(bytes);
26
- const blobId = await deps.uploadBlob(encryptedData, channelId);
27
- const body = {
28
- v: 1, type: "artifact_share", name, mime: mimeForName(name), size: bytes.length,
29
- blobId, fileKey: deps.bytesToBase64(fileKey), fileNonce: deps.bytesToBase64(fileNonce), digest,
30
- };
31
- if (caption)
32
- body.text = caption;
33
- return body;
34
- }
35
- export async function materializeAttachment(body, ctx, deps) {
36
- const ciphertext = await deps.downloadBlob(body.blobId);
37
- // Verify digest on ciphertext BEFORE decrypting — tampered blobs fail here.
38
- const sha256 = deps.computeFileDigest(ciphertext);
39
- if (sha256 !== body.digest) {
40
- throw new Error(`attachment digest mismatch for blob ${body.blobId}`);
41
- }
42
- const plain = deps.decryptFile(ciphertext, deps.base64ToBytes(body.fileKey), deps.base64ToBytes(body.fileNonce));
43
- const safeName = sanitizeFilename(body.name, ctx.messageId);
44
- const dir = `${ctx.attachmentsDir}/${ctx.channelId}`;
45
- const path = `${dir}/${ctx.messageId}-${safeName}`;
46
- await deps.mkdirp(dir);
47
- await deps.writeFile(path, plain);
48
- return { filename: safeName, mime: body.mime, size: plain.length, path, sha256 };
49
- }
package/dist/auth.js DELETED
@@ -1,56 +0,0 @@
1
- import { randomBytes, timingSafeEqual } from "node:crypto";
2
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
- import { isLoopback } from "./config.js";
4
- export function resolveToken(opts) {
5
- if (opts.token)
6
- return opts.token;
7
- const f = opts.tokenFile;
8
- if (f && existsSync(f))
9
- return readFileSync(f, "utf8").trim();
10
- const tok = randomBytes(32).toString("base64url");
11
- if (f)
12
- writeFileSync(f, tok, { mode: 0o600 });
13
- return tok;
14
- }
15
- export function tokenMatches(provided, expected) {
16
- if (!provided)
17
- return false;
18
- const a = Buffer.from(provided);
19
- const b = Buffer.from(expected);
20
- if (a.length !== b.length)
21
- return false;
22
- return timingSafeEqual(a, b);
23
- }
24
- export function bearerFrom(header) {
25
- if (!header)
26
- return undefined;
27
- const m = /^Bearer (.+)$/i.exec(header.trim());
28
- return m ? m[1] : undefined;
29
- }
30
- function hostnameOf(hostHeader) {
31
- if (!hostHeader)
32
- return undefined;
33
- // Strip an optional :port (but keep [::1] intact).
34
- if (hostHeader.startsWith("["))
35
- return hostHeader.slice(0, hostHeader.indexOf("]") + 1);
36
- const i = hostHeader.lastIndexOf(":");
37
- return i > 0 ? hostHeader.slice(0, i) : hostHeader;
38
- }
39
- export function originHostAllowed(headers, allowOrigins) {
40
- // Host must be a loopback name (blocks the DNS-rebind target Host: evil.com).
41
- const host = hostnameOf(headers.host);
42
- if (host && !isLoopback(host) && !isLoopback(`[${host}]`))
43
- return false;
44
- // Origin: absent → allow (non-browser). Present → must be loopback or allow-listed.
45
- const origin = headers.origin;
46
- if (!origin)
47
- return true;
48
- if (allowOrigins.includes(origin))
49
- return true;
50
- try {
51
- return isLoopback(new URL(origin).hostname);
52
- }
53
- catch {
54
- return false;
55
- }
56
- }