@wonderwhy-er/desktop-commander 0.3.1-alpha.1 → 0.3.1
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/LICENSE +20 -20
- package/README.md +1152 -1152
- package/dist/bootstrap.js +0 -0
- package/dist/command-manager.js +0 -0
- package/dist/config-field-definitions.js +0 -0
- package/dist/config-manager.js +0 -0
- package/dist/config-recovery.js +0 -0
- package/dist/config.js +0 -0
- package/dist/custom-stdio.js +0 -0
- package/dist/data/onboarding-prompts.json +70 -70
- package/dist/error-handlers.js +0 -0
- package/dist/handlers/filesystem-handlers.js +2 -2
- package/dist/index.js +0 -0
- package/dist/npm-scripts/remote.js +25 -23
- package/dist/remote-device/desktop-commander-integration.d.ts +1 -0
- package/dist/remote-device/device.js +14 -2
- package/dist/remote-device/realtime-health-telemetry.d.ts +35 -0
- package/dist/remote-device/realtime-health-telemetry.js +110 -0
- package/dist/remote-device/remote-channel.d.ts +66 -55
- package/dist/remote-device/remote-channel.js +336 -389
- package/dist/remote-device/rollouts.d.ts +48 -0
- package/dist/remote-device/rollouts.js +105 -0
- package/dist/remote-device/scripts/blocking-offline-update.js +135 -133
- package/dist/search-manager.js +0 -0
- package/dist/server.js +581 -712
- package/dist/setup-claude-server.js +942 -942
- package/dist/terminal-manager.js +0 -0
- package/dist/tools/edit.js +2 -2
- package/dist/tools/fuzzySearch.js +9 -9
- package/dist/tools/improved-process-tools.js +10 -10
- package/dist/tools/pdf/extract-images.js +3 -7
- package/dist/tools/pdf/lib/pdf2md.js +28 -33
- package/dist/tools/pdf/utils.d.ts +10 -0
- package/dist/tools/pdf/utils.js +11 -0
- package/dist/tools/prompts.js +1 -1
- package/dist/tools/schemas.d.ts +0 -10
- package/dist/tools/schemas.js +0 -8
- package/dist/track-installation.js +387 -387
- package/dist/types.js +0 -0
- package/dist/ui/config-editor/config-editor-runtime.js +53 -53
- package/dist/ui/config-editor/index.html +13 -13
- package/dist/ui/config-editor/src/app.js +30 -30
- package/dist/ui/config-editor/src/array-modal.js +32 -32
- package/dist/ui/config-editor/styles.css +586 -586
- package/dist/ui/contracts.d.ts +27 -0
- package/dist/ui/contracts.js +36 -0
- package/dist/ui/file-preview/index.html +16 -16
- package/dist/ui/file-preview/preview-runtime.js +190 -182
- package/dist/ui/file-preview/src/app.js +8 -8
- package/dist/ui/file-preview/src/components/html-renderer.js +4 -2
- package/dist/ui/file-preview/src/document-layout.js +31 -31
- package/dist/ui/file-preview/src/document-outline.js +8 -8
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
- package/dist/ui/file-preview/src/markdown/controller.js +9 -9
- package/dist/ui/file-preview/src/markdown/editor.js +31 -31
- package/dist/ui/file-preview/styles.css +1630 -1630
- package/dist/ui/resources.js +11 -4
- package/dist/uninstall-claude-server.js +745 -745
- package/dist/utils/files/binary.js +4 -4
- package/dist/utils/files/excel.js +3 -3
- package/dist/utils/files/text.d.ts +7 -0
- package/dist/utils/files/text.js +40 -21
- package/dist/utils/lazy-package.d.ts +5 -3
- package/dist/utils/lazy-package.js +6 -4
- package/dist/utils/system-info.d.ts +1 -0
- package/dist/utils/system-info.js +110 -97
- package/dist/utils/terminal-timestamps.d.ts +2 -0
- package/dist/utils/terminal-timestamps.js +18 -0
- package/dist/utils/usageTracker.d.ts +0 -39
- package/dist/utils/usageTracker.js +16 -176
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -56
- package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -32
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -38
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -164
- package/package.json +24 -15
- package/vendor/telemetry-contract/README.md +56 -56
- package/vendor/telemetry-contract/package.json +32 -32
- package/vendor/telemetry-contract/transport.d.ts +38 -38
- package/vendor/telemetry-contract/transport.js +164 -164
- package/vendor/telemetry-contract/transport.test.js +39 -39
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
const REQUIRED = ["call_id", "stage", "timestamp_utc"];
|
|
2
|
-
const OPTIONAL = [
|
|
3
|
-
"monotonic_ms",
|
|
4
|
-
"transport",
|
|
5
|
-
"notification_id",
|
|
6
|
-
"attempt_number",
|
|
7
|
-
"observation_id",
|
|
8
|
-
"source_process_id",
|
|
9
|
-
"schema_version",
|
|
10
|
-
"outcome",
|
|
11
|
-
"reason",
|
|
12
|
-
"duration_ms",
|
|
13
|
-
"retry_wait_ms",
|
|
14
|
-
"arrival_gap_ms",
|
|
15
|
-
"deadline_utc",
|
|
16
|
-
"tool_call_received_utc",
|
|
17
|
-
"tool_call_received_monotonic_ms",
|
|
18
|
-
"duplicate_count",
|
|
19
|
-
"dropped_count",
|
|
20
|
-
"source",
|
|
21
|
-
"device_id",
|
|
22
|
-
"environment",
|
|
23
|
-
"operation",
|
|
24
|
-
"operation_id",
|
|
25
|
-
"operation_attempt",
|
|
26
|
-
"result_source",
|
|
27
|
-
"tool_name",
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
function isTimestamp(value) {
|
|
31
|
-
const iso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
32
|
-
return typeof value === "string" && iso.test(value) && !Number.isNaN(Date.parse(value));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function validProperty(key, value) {
|
|
36
|
-
switch (key) {
|
|
37
|
-
case "source_process_id":
|
|
38
|
-
case "device_id":
|
|
39
|
-
case "call_id":
|
|
40
|
-
case "notification_id":
|
|
41
|
-
case "observation_id":
|
|
42
|
-
case "operation_id":
|
|
43
|
-
return typeof value === "string" && value.length > 0;
|
|
44
|
-
case "transport":
|
|
45
|
-
return value === "mqtt" || value === "broadcast";
|
|
46
|
-
case "stage":
|
|
47
|
-
case "outcome":
|
|
48
|
-
case "reason":
|
|
49
|
-
case "operation":
|
|
50
|
-
case "environment":
|
|
51
|
-
return typeof value === "string" && value.length > 0;
|
|
52
|
-
case "tool_name":
|
|
53
|
-
return typeof value === "string";
|
|
54
|
-
case "result_source":
|
|
55
|
-
return value === "doorbell" || value === "recovery";
|
|
56
|
-
case "operation_attempt":
|
|
57
|
-
case "schema_version":
|
|
58
|
-
return Number.isSafeInteger(value) && value >= 1;
|
|
59
|
-
case "source":
|
|
60
|
-
return value === "server" || value === "device";
|
|
61
|
-
case "attempt_number":
|
|
62
|
-
case "duplicate_count":
|
|
63
|
-
case "dropped_count":
|
|
64
|
-
return Number.isSafeInteger(value) && value >= 0;
|
|
65
|
-
case "timestamp_utc":
|
|
66
|
-
case "deadline_utc":
|
|
67
|
-
case "tool_call_received_utc":
|
|
68
|
-
return isTimestamp(value);
|
|
69
|
-
default:
|
|
70
|
-
return (
|
|
71
|
-
typeof value === "number" &&
|
|
72
|
-
Number.isFinite(value) &&
|
|
73
|
-
Math.abs(value) <= Number.MAX_SAFE_INTEGER &&
|
|
74
|
-
(key === "arrival_gap_ms" || value >= 0)
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function hasTransportEvents(payload) {
|
|
80
|
-
return (
|
|
81
|
-
Array.isArray(payload?.events) &&
|
|
82
|
-
payload.events.some((event) => {
|
|
83
|
-
const params = event?.params;
|
|
84
|
-
const transport = params?.transport;
|
|
85
|
-
return (
|
|
86
|
-
event?.name === "mqtt" ||
|
|
87
|
-
event?.name === "broadcast" ||
|
|
88
|
-
(["mqtt", "broadcast"].includes(transport) && (params?.call_id !== undefined || params?.stage !== undefined)) ||
|
|
89
|
-
(params?.call_id !== undefined && event?.name === params?.stage)
|
|
90
|
-
);
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function sanitizeTransportEvent(eventName, rawParams) {
|
|
96
|
-
if (
|
|
97
|
-
!rawParams ||
|
|
98
|
-
typeof rawParams !== "object" ||
|
|
99
|
-
Array.isArray(rawParams) ||
|
|
100
|
-
(eventName !== rawParams.stage && eventName !== rawParams.transport)
|
|
101
|
-
) {
|
|
102
|
-
throw new Error("Invalid transport event");
|
|
103
|
-
}
|
|
104
|
-
const params = {};
|
|
105
|
-
for (const key of REQUIRED) {
|
|
106
|
-
if (!Object.hasOwn(rawParams, key) || !validProperty(key, rawParams[key])) {
|
|
107
|
-
throw new Error("Invalid transport event property");
|
|
108
|
-
}
|
|
109
|
-
params[key] = key.endsWith("_utc") ? new Date(rawParams[key]).toISOString() : rawParams[key];
|
|
110
|
-
}
|
|
111
|
-
for (const key of OPTIONAL) {
|
|
112
|
-
if (!Object.hasOwn(rawParams, key) || !validProperty(key, rawParams[key])) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
params[key] = key.endsWith("_utc") ? new Date(rawParams[key]).toISOString() : rawParams[key];
|
|
116
|
-
}
|
|
117
|
-
return params;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function parseTransportPayload(payload, isServer) {
|
|
121
|
-
if (
|
|
122
|
-
!payload ||
|
|
123
|
-
typeof payload !== "object" ||
|
|
124
|
-
Array.isArray(payload) ||
|
|
125
|
-
!Array.isArray(payload.events) ||
|
|
126
|
-
payload.events.length < 1 ||
|
|
127
|
-
payload.events.length > 10
|
|
128
|
-
) {
|
|
129
|
-
throw new Error("Invalid events");
|
|
130
|
-
}
|
|
131
|
-
const userId = typeof payload.user_id === "string" ? payload.user_id.trim() : "";
|
|
132
|
-
if (isServer && (!userId || userId.length > 128)) {
|
|
133
|
-
throw new Error("Invalid user_id");
|
|
134
|
-
}
|
|
135
|
-
if (!isServer && (typeof payload.client_id !== "string" || !payload.client_id)) {
|
|
136
|
-
throw new Error("Invalid client_id");
|
|
137
|
-
}
|
|
138
|
-
const events = payload.events.map((event) => {
|
|
139
|
-
if (!event || typeof event !== "object" || Array.isArray(event)) {
|
|
140
|
-
throw new Error("Invalid event");
|
|
141
|
-
}
|
|
142
|
-
const raw = event.params;
|
|
143
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
144
|
-
throw new Error("Invalid params");
|
|
145
|
-
}
|
|
146
|
-
const params = sanitizeTransportEvent(event.name, isServer ? raw : { ...raw, source: "device" });
|
|
147
|
-
if (!isServer && !params.device_id) {
|
|
148
|
-
throw new Error("Missing device_id");
|
|
149
|
-
}
|
|
150
|
-
return { name: params.stage, params };
|
|
151
|
-
});
|
|
152
|
-
if (isServer) {
|
|
153
|
-
return { user_id: userId, events };
|
|
154
|
-
}
|
|
155
|
-
return { client_id: payload.client_id, events };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function parseRemoteTransportPayload(payload) {
|
|
159
|
-
return parseTransportPayload(payload, true);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function parseDeviceTransportPayload(payload) {
|
|
163
|
-
return parseTransportPayload(payload, false);
|
|
164
|
-
}
|
|
1
|
+
const REQUIRED = ["call_id", "stage", "timestamp_utc"];
|
|
2
|
+
const OPTIONAL = [
|
|
3
|
+
"monotonic_ms",
|
|
4
|
+
"transport",
|
|
5
|
+
"notification_id",
|
|
6
|
+
"attempt_number",
|
|
7
|
+
"observation_id",
|
|
8
|
+
"source_process_id",
|
|
9
|
+
"schema_version",
|
|
10
|
+
"outcome",
|
|
11
|
+
"reason",
|
|
12
|
+
"duration_ms",
|
|
13
|
+
"retry_wait_ms",
|
|
14
|
+
"arrival_gap_ms",
|
|
15
|
+
"deadline_utc",
|
|
16
|
+
"tool_call_received_utc",
|
|
17
|
+
"tool_call_received_monotonic_ms",
|
|
18
|
+
"duplicate_count",
|
|
19
|
+
"dropped_count",
|
|
20
|
+
"source",
|
|
21
|
+
"device_id",
|
|
22
|
+
"environment",
|
|
23
|
+
"operation",
|
|
24
|
+
"operation_id",
|
|
25
|
+
"operation_attempt",
|
|
26
|
+
"result_source",
|
|
27
|
+
"tool_name",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
function isTimestamp(value) {
|
|
31
|
+
const iso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
32
|
+
return typeof value === "string" && iso.test(value) && !Number.isNaN(Date.parse(value));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function validProperty(key, value) {
|
|
36
|
+
switch (key) {
|
|
37
|
+
case "source_process_id":
|
|
38
|
+
case "device_id":
|
|
39
|
+
case "call_id":
|
|
40
|
+
case "notification_id":
|
|
41
|
+
case "observation_id":
|
|
42
|
+
case "operation_id":
|
|
43
|
+
return typeof value === "string" && value.length > 0;
|
|
44
|
+
case "transport":
|
|
45
|
+
return value === "mqtt" || value === "broadcast";
|
|
46
|
+
case "stage":
|
|
47
|
+
case "outcome":
|
|
48
|
+
case "reason":
|
|
49
|
+
case "operation":
|
|
50
|
+
case "environment":
|
|
51
|
+
return typeof value === "string" && value.length > 0;
|
|
52
|
+
case "tool_name":
|
|
53
|
+
return typeof value === "string";
|
|
54
|
+
case "result_source":
|
|
55
|
+
return value === "doorbell" || value === "recovery";
|
|
56
|
+
case "operation_attempt":
|
|
57
|
+
case "schema_version":
|
|
58
|
+
return Number.isSafeInteger(value) && value >= 1;
|
|
59
|
+
case "source":
|
|
60
|
+
return value === "server" || value === "device";
|
|
61
|
+
case "attempt_number":
|
|
62
|
+
case "duplicate_count":
|
|
63
|
+
case "dropped_count":
|
|
64
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
65
|
+
case "timestamp_utc":
|
|
66
|
+
case "deadline_utc":
|
|
67
|
+
case "tool_call_received_utc":
|
|
68
|
+
return isTimestamp(value);
|
|
69
|
+
default:
|
|
70
|
+
return (
|
|
71
|
+
typeof value === "number" &&
|
|
72
|
+
Number.isFinite(value) &&
|
|
73
|
+
Math.abs(value) <= Number.MAX_SAFE_INTEGER &&
|
|
74
|
+
(key === "arrival_gap_ms" || value >= 0)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function hasTransportEvents(payload) {
|
|
80
|
+
return (
|
|
81
|
+
Array.isArray(payload?.events) &&
|
|
82
|
+
payload.events.some((event) => {
|
|
83
|
+
const params = event?.params;
|
|
84
|
+
const transport = params?.transport;
|
|
85
|
+
return (
|
|
86
|
+
event?.name === "mqtt" ||
|
|
87
|
+
event?.name === "broadcast" ||
|
|
88
|
+
(["mqtt", "broadcast"].includes(transport) && (params?.call_id !== undefined || params?.stage !== undefined)) ||
|
|
89
|
+
(params?.call_id !== undefined && event?.name === params?.stage)
|
|
90
|
+
);
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function sanitizeTransportEvent(eventName, rawParams) {
|
|
96
|
+
if (
|
|
97
|
+
!rawParams ||
|
|
98
|
+
typeof rawParams !== "object" ||
|
|
99
|
+
Array.isArray(rawParams) ||
|
|
100
|
+
(eventName !== rawParams.stage && eventName !== rawParams.transport)
|
|
101
|
+
) {
|
|
102
|
+
throw new Error("Invalid transport event");
|
|
103
|
+
}
|
|
104
|
+
const params = {};
|
|
105
|
+
for (const key of REQUIRED) {
|
|
106
|
+
if (!Object.hasOwn(rawParams, key) || !validProperty(key, rawParams[key])) {
|
|
107
|
+
throw new Error("Invalid transport event property");
|
|
108
|
+
}
|
|
109
|
+
params[key] = key.endsWith("_utc") ? new Date(rawParams[key]).toISOString() : rawParams[key];
|
|
110
|
+
}
|
|
111
|
+
for (const key of OPTIONAL) {
|
|
112
|
+
if (!Object.hasOwn(rawParams, key) || !validProperty(key, rawParams[key])) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
params[key] = key.endsWith("_utc") ? new Date(rawParams[key]).toISOString() : rawParams[key];
|
|
116
|
+
}
|
|
117
|
+
return params;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function parseTransportPayload(payload, isServer) {
|
|
121
|
+
if (
|
|
122
|
+
!payload ||
|
|
123
|
+
typeof payload !== "object" ||
|
|
124
|
+
Array.isArray(payload) ||
|
|
125
|
+
!Array.isArray(payload.events) ||
|
|
126
|
+
payload.events.length < 1 ||
|
|
127
|
+
payload.events.length > 10
|
|
128
|
+
) {
|
|
129
|
+
throw new Error("Invalid events");
|
|
130
|
+
}
|
|
131
|
+
const userId = typeof payload.user_id === "string" ? payload.user_id.trim() : "";
|
|
132
|
+
if (isServer && (!userId || userId.length > 128)) {
|
|
133
|
+
throw new Error("Invalid user_id");
|
|
134
|
+
}
|
|
135
|
+
if (!isServer && (typeof payload.client_id !== "string" || !payload.client_id)) {
|
|
136
|
+
throw new Error("Invalid client_id");
|
|
137
|
+
}
|
|
138
|
+
const events = payload.events.map((event) => {
|
|
139
|
+
if (!event || typeof event !== "object" || Array.isArray(event)) {
|
|
140
|
+
throw new Error("Invalid event");
|
|
141
|
+
}
|
|
142
|
+
const raw = event.params;
|
|
143
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
144
|
+
throw new Error("Invalid params");
|
|
145
|
+
}
|
|
146
|
+
const params = sanitizeTransportEvent(event.name, isServer ? raw : { ...raw, source: "device" });
|
|
147
|
+
if (!isServer && !params.device_id) {
|
|
148
|
+
throw new Error("Missing device_id");
|
|
149
|
+
}
|
|
150
|
+
return { name: params.stage, params };
|
|
151
|
+
});
|
|
152
|
+
if (isServer) {
|
|
153
|
+
return { user_id: userId, events };
|
|
154
|
+
}
|
|
155
|
+
return { client_id: payload.client_id, events };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function parseRemoteTransportPayload(payload) {
|
|
159
|
+
return parseTransportPayload(payload, true);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function parseDeviceTransportPayload(payload) {
|
|
163
|
+
return parseTransportPayload(payload, false);
|
|
164
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { parseDeviceTransportPayload, parseRemoteTransportPayload } from "./transport.js";
|
|
3
|
-
|
|
4
|
-
const event = {
|
|
5
|
-
name: "broadcast",
|
|
6
|
-
params: {
|
|
7
|
-
call_id: "call-1",
|
|
8
|
-
stage: "received",
|
|
9
|
-
transport: "broadcast",
|
|
10
|
-
timestamp_utc: "2026-09-21T09:00:00Z",
|
|
11
|
-
monotonic_ms: 12,
|
|
12
|
-
device_id: "device-1",
|
|
13
|
-
arrival_gap_ms: -5,
|
|
14
|
-
source: "server",
|
|
15
|
-
raw_args: "private",
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const remote = parseRemoteTransportPayload({ user_id: " user-1 ", events: [event] });
|
|
19
|
-
assert.equal(remote.user_id, "user-1");
|
|
20
|
-
assert.equal(remote.events[0].name, "received");
|
|
21
|
-
assert.equal(remote.events[0].params.arrival_gap_ms, -5);
|
|
22
|
-
assert.equal(remote.events[0].params.raw_args, undefined);
|
|
23
|
-
const device = parseDeviceTransportPayload({ client_id: "installation-1", events: [event] });
|
|
24
|
-
assert.equal(device.events[0].params.source, "device");
|
|
25
|
-
const withoutMonotonic = { ...event, params: { ...event.params } };
|
|
26
|
-
delete withoutMonotonic.params.monotonic_ms;
|
|
27
|
-
assert.equal(
|
|
28
|
-
parseDeviceTransportPayload({ client_id: "installation-1", events: [withoutMonotonic] }).events[0].params.monotonic_ms,
|
|
29
|
-
undefined,
|
|
30
|
-
);
|
|
31
|
-
assert.throws(
|
|
32
|
-
() => parseDeviceTransportPayload({ client_id: "installation-1", events: [{ ...event, params: { ...event.params, device_id: "" } }] }),
|
|
33
|
-
/Missing device_id/,
|
|
34
|
-
);
|
|
35
|
-
assert.throws(
|
|
36
|
-
() => parseRemoteTransportPayload({ user_id: "user-1", events: [event, { ...event, params: { ...event.params, call_id: "" } }] }),
|
|
37
|
-
/Invalid transport event property/,
|
|
38
|
-
);
|
|
39
|
-
console.log("PASS transport contract: backend and device identity, legacy names and atomic validation");
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { parseDeviceTransportPayload, parseRemoteTransportPayload } from "./transport.js";
|
|
3
|
+
|
|
4
|
+
const event = {
|
|
5
|
+
name: "broadcast",
|
|
6
|
+
params: {
|
|
7
|
+
call_id: "call-1",
|
|
8
|
+
stage: "received",
|
|
9
|
+
transport: "broadcast",
|
|
10
|
+
timestamp_utc: "2026-09-21T09:00:00Z",
|
|
11
|
+
monotonic_ms: 12,
|
|
12
|
+
device_id: "device-1",
|
|
13
|
+
arrival_gap_ms: -5,
|
|
14
|
+
source: "server",
|
|
15
|
+
raw_args: "private",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const remote = parseRemoteTransportPayload({ user_id: " user-1 ", events: [event] });
|
|
19
|
+
assert.equal(remote.user_id, "user-1");
|
|
20
|
+
assert.equal(remote.events[0].name, "received");
|
|
21
|
+
assert.equal(remote.events[0].params.arrival_gap_ms, -5);
|
|
22
|
+
assert.equal(remote.events[0].params.raw_args, undefined);
|
|
23
|
+
const device = parseDeviceTransportPayload({ client_id: "installation-1", events: [event] });
|
|
24
|
+
assert.equal(device.events[0].params.source, "device");
|
|
25
|
+
const withoutMonotonic = { ...event, params: { ...event.params } };
|
|
26
|
+
delete withoutMonotonic.params.monotonic_ms;
|
|
27
|
+
assert.equal(
|
|
28
|
+
parseDeviceTransportPayload({ client_id: "installation-1", events: [withoutMonotonic] }).events[0].params.monotonic_ms,
|
|
29
|
+
undefined,
|
|
30
|
+
);
|
|
31
|
+
assert.throws(
|
|
32
|
+
() => parseDeviceTransportPayload({ client_id: "installation-1", events: [{ ...event, params: { ...event.params, device_id: "" } }] }),
|
|
33
|
+
/Missing device_id/,
|
|
34
|
+
);
|
|
35
|
+
assert.throws(
|
|
36
|
+
() => parseRemoteTransportPayload({ user_id: "user-1", events: [event, { ...event, params: { ...event.params, call_id: "" } }] }),
|
|
37
|
+
/Invalid transport event property/,
|
|
38
|
+
);
|
|
39
|
+
console.log("PASS transport contract: backend and device identity, legacy names and atomic validation");
|