dextunnel 0.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.
Files changed (76) hide show
  1. package/LICENSE +211 -0
  2. package/README.md +112 -0
  3. package/SECURITY.md +27 -0
  4. package/SUPPORT.md +43 -0
  5. package/package.json +44 -0
  6. package/public/client-shared.js +1831 -0
  7. package/public/favicon.svg +11 -0
  8. package/public/host.html +29 -0
  9. package/public/host.js +2079 -0
  10. package/public/index.html +28 -0
  11. package/public/index.js +98 -0
  12. package/public/live-bridge-lifecycle.js +258 -0
  13. package/public/live-bridge-retry-state.js +61 -0
  14. package/public/live-selection-intent.js +79 -0
  15. package/public/remote-operator-state.js +316 -0
  16. package/public/remote.html +167 -0
  17. package/public/remote.js +3967 -0
  18. package/public/styles.css +2793 -0
  19. package/public/surface-view-state.js +89 -0
  20. package/public/voice-dictation.js +45 -0
  21. package/src/bin/desktop-rehydration-smoke.mjs +111 -0
  22. package/src/bin/dextunnel.mjs +41 -0
  23. package/src/bin/doctor.mjs +48 -0
  24. package/src/bin/launch-attest.mjs +39 -0
  25. package/src/bin/launch-status.mjs +49 -0
  26. package/src/bin/mobile-link-proxy.mjs +221 -0
  27. package/src/bin/mobile-proof.mjs +164 -0
  28. package/src/bin/mobile-transport-smoke.mjs +200 -0
  29. package/src/bin/probe-codex-app-server-write.mjs +36 -0
  30. package/src/bin/probe-codex-app-server.mjs +30 -0
  31. package/src/lib/agent-room-context.mjs +54 -0
  32. package/src/lib/agent-room-runtime.mjs +355 -0
  33. package/src/lib/agent-room-service.mjs +335 -0
  34. package/src/lib/agent-room-state.mjs +406 -0
  35. package/src/lib/agent-room-store.mjs +71 -0
  36. package/src/lib/agent-room-text.mjs +48 -0
  37. package/src/lib/app-server-contract.mjs +66 -0
  38. package/src/lib/app-server-runtime.mjs +60 -0
  39. package/src/lib/attachment-service.mjs +119 -0
  40. package/src/lib/bridge-api-handler.mjs +719 -0
  41. package/src/lib/bridge-runtime-lifecycle.mjs +51 -0
  42. package/src/lib/bridge-status-builder.mjs +60 -0
  43. package/src/lib/codex-app-server-client.mjs +1511 -0
  44. package/src/lib/companion-state.mjs +453 -0
  45. package/src/lib/control-lease-service.mjs +180 -0
  46. package/src/lib/debug-harness-service.mjs +173 -0
  47. package/src/lib/desktop-integration.mjs +146 -0
  48. package/src/lib/desktop-rehydration-smoke.mjs +269 -0
  49. package/src/lib/dextunnel-cli.mjs +122 -0
  50. package/src/lib/discovery-docs.mjs +1321 -0
  51. package/src/lib/fake-codex-app-server-bridge.mjs +340 -0
  52. package/src/lib/install-preflight.mjs +373 -0
  53. package/src/lib/interaction-resolution-service.mjs +185 -0
  54. package/src/lib/interaction-state.mjs +360 -0
  55. package/src/lib/launch-release-bar.mjs +158 -0
  56. package/src/lib/live-control-state.mjs +107 -0
  57. package/src/lib/live-payload-builder.mjs +298 -0
  58. package/src/lib/live-selection-transition-state.mjs +49 -0
  59. package/src/lib/live-transcript-state.mjs +549 -0
  60. package/src/lib/mobile-network-profile.mjs +39 -0
  61. package/src/lib/mock-codex-adapter.mjs +62 -0
  62. package/src/lib/operator-diagnostics.mjs +82 -0
  63. package/src/lib/repo-changes-service.mjs +527 -0
  64. package/src/lib/runtime-config.mjs +106 -0
  65. package/src/lib/selection-state-service.mjs +214 -0
  66. package/src/lib/session-store.mjs +355 -0
  67. package/src/lib/shared-room-state.mjs +473 -0
  68. package/src/lib/shared-selection-state.mjs +40 -0
  69. package/src/lib/sse-hub.mjs +35 -0
  70. package/src/lib/static-surface-service.mjs +71 -0
  71. package/src/lib/surface-access.mjs +189 -0
  72. package/src/lib/surface-presence-service.mjs +118 -0
  73. package/src/lib/surface-request-guard.mjs +52 -0
  74. package/src/lib/thread-sync-state.mjs +536 -0
  75. package/src/lib/watcher-lifecycle.mjs +287 -0
  76. package/src/server.mjs +1446 -0
@@ -0,0 +1,119 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import path from "node:path";
3
+ import { mkdir, readdir, stat, unlink, writeFile } from "node:fs/promises";
4
+
5
+ function extensionFromMimeType(mimeType) {
6
+ switch (String(mimeType || "").toLowerCase()) {
7
+ case "image/jpeg":
8
+ case "image/jpg":
9
+ return "jpg";
10
+ case "image/webp":
11
+ return "webp";
12
+ case "image/gif":
13
+ return "gif";
14
+ case "image/svg+xml":
15
+ return "svg";
16
+ default:
17
+ return "png";
18
+ }
19
+ }
20
+
21
+ function parseImageDataUrl(dataUrl) {
22
+ const match = String(dataUrl || "").match(/^data:(image\/[A-Za-z0-9.+-]+);base64,(.+)$/);
23
+ if (!match) {
24
+ throw new Error("Attachment must be a base64 image data URL.");
25
+ }
26
+
27
+ return {
28
+ mimeType: match[1],
29
+ buffer: Buffer.from(match[2], "base64")
30
+ };
31
+ }
32
+
33
+ function sanitizeAttachmentName(name, fallbackExt) {
34
+ const stem = String(name || "image")
35
+ .replace(/\.[^.]+$/, "")
36
+ .replace(/[^a-zA-Z0-9_-]+/g, "-")
37
+ .replace(/-+/g, "-")
38
+ .replace(/^-|-$/g, "")
39
+ .slice(0, 48) || "image";
40
+
41
+ return `${stem}.${fallbackExt}`;
42
+ }
43
+
44
+ export function createAttachmentService({
45
+ attachmentDir,
46
+ maxAgeMs,
47
+ mkdirFn = mkdir,
48
+ randomId = () => randomUUID(),
49
+ readdirFn = readdir,
50
+ statFn = stat,
51
+ unlinkFn = unlink,
52
+ writeFileFn = writeFile
53
+ } = {}) {
54
+ if (!attachmentDir) {
55
+ throw new Error("createAttachmentService requires an attachmentDir.");
56
+ }
57
+ if (!Number.isFinite(maxAgeMs) || maxAgeMs <= 0) {
58
+ throw new Error("createAttachmentService requires a positive maxAgeMs.");
59
+ }
60
+
61
+ async function cleanupAttachmentDir({ now = Date.now(), maxAgeMs: nextMaxAgeMs = maxAgeMs } = {}) {
62
+ try {
63
+ const entries = await readdirFn(attachmentDir, { withFileTypes: true });
64
+ await Promise.all(
65
+ entries.map(async (entry) => {
66
+ if (!entry.isFile()) {
67
+ return;
68
+ }
69
+
70
+ const filePath = path.join(attachmentDir, entry.name);
71
+ try {
72
+ const fileStat = await statFn(filePath);
73
+ if (now - fileStat.mtimeMs > nextMaxAgeMs) {
74
+ await unlinkFn(filePath);
75
+ }
76
+ } catch {
77
+ return;
78
+ }
79
+ })
80
+ );
81
+ } catch {
82
+ return;
83
+ }
84
+ }
85
+
86
+ async function persistImageAttachments(attachments = []) {
87
+ if (!Array.isArray(attachments) || attachments.length === 0) {
88
+ return [];
89
+ }
90
+
91
+ await cleanupAttachmentDir();
92
+ await mkdirFn(attachmentDir, { recursive: true });
93
+
94
+ return Promise.all(
95
+ attachments.map(async (attachment, index) => {
96
+ const { buffer, mimeType } = parseImageDataUrl(attachment.dataUrl);
97
+ const ext = extensionFromMimeType(attachment.type || mimeType);
98
+ const baseName = sanitizeAttachmentName(attachment.name, ext);
99
+ const filePath = path.join(attachmentDir, `${randomId()}-${index}-${baseName}`);
100
+ await writeFileFn(filePath, buffer);
101
+ return {
102
+ path: filePath,
103
+ type: "localImage"
104
+ };
105
+ })
106
+ );
107
+ }
108
+
109
+ return {
110
+ cleanupAttachmentDir,
111
+ persistImageAttachments
112
+ };
113
+ }
114
+
115
+ export {
116
+ extensionFromMimeType,
117
+ parseImageDataUrl,
118
+ sanitizeAttachmentName
119
+ };