@wonderwhy-er/desktop-commander 0.2.51 → 0.3.1-alpha.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/README.md +14 -24
- package/dist/command-manager.d.ts +7 -2
- package/dist/command-manager.js +16 -11
- package/dist/config-manager.d.ts +49 -3
- package/dist/config-manager.js +329 -87
- package/dist/config-recovery.d.ts +28 -0
- package/dist/config-recovery.js +81 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +9 -0
- package/dist/handlers/filesystem-handlers.d.ts +1 -1
- package/dist/handlers/filesystem-handlers.js +26 -16
- package/dist/handlers/search-answers.d.ts +58 -0
- package/dist/handlers/search-answers.js +172 -0
- package/dist/handlers/search-handlers.js +4 -92
- package/dist/index.js +14 -7
- package/dist/npm-scripts/remote.js +32 -4
- package/dist/remote-device/broadcast-analytics.d.ts +28 -0
- package/dist/remote-device/broadcast-analytics.js +41 -0
- package/dist/remote-device/desktop-commander-integration.d.ts +20 -0
- package/dist/remote-device/desktop-commander-integration.js +121 -40
- package/dist/remote-device/device-authenticator.d.ts +13 -1
- package/dist/remote-device/device-authenticator.js +87 -47
- package/dist/remote-device/device.d.ts +14 -0
- package/dist/remote-device/device.js +244 -51
- package/dist/remote-device/mqtt-enrollment.d.ts +16 -0
- package/dist/remote-device/mqtt-enrollment.js +162 -0
- package/dist/remote-device/mqtt-transport.d.ts +44 -0
- package/dist/remote-device/mqtt-transport.js +197 -0
- package/dist/remote-device/remote-channel.d.ts +64 -3
- package/dist/remote-device/remote-channel.js +317 -48
- package/dist/remote-device/scripts/blocking-offline-update.js +106 -69
- package/dist/remote-device/transport-analytics.d.ts +29 -0
- package/dist/remote-device/transport-analytics.js +44 -0
- package/dist/remote-device/transport-telemetry.d.ts +32 -0
- package/dist/remote-device/transport-telemetry.js +48 -0
- package/dist/search-manager.d.ts +239 -27
- package/dist/search-manager.js +746 -312
- package/dist/server.js +77 -92
- package/dist/terminal-manager.d.ts +138 -21
- package/dist/terminal-manager.js +300 -215
- package/dist/tools/config.d.ts +1 -1
- package/dist/tools/config.js +21 -70
- package/dist/tools/edit.js +12 -4
- package/dist/tools/filesystem.d.ts +30 -6
- package/dist/tools/filesystem.js +246 -140
- package/dist/tools/improved-process-tools.d.ts +9 -3
- package/dist/tools/improved-process-tools.js +171 -68
- package/dist/tools/pdf/extract-images.d.ts +2 -0
- package/dist/tools/pdf/extract-images.js +4 -1
- package/dist/tools/pdf/index.d.ts +5 -3
- package/dist/tools/pdf/index.js +4 -3
- package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
- package/dist/tools/pdf/lib/pdf2md.js +12 -5
- package/dist/tools/pdf/manipulations.d.ts +12 -1
- package/dist/tools/pdf/manipulations.js +17 -4
- package/dist/tools/pdf/markdown.d.ts +96 -0
- package/dist/tools/pdf/markdown.js +485 -20
- package/dist/tools/pdf/utils.d.ts +2 -2
- package/dist/tools/pdf/utils.js +4 -4
- package/dist/tools/process.js +8 -5
- package/dist/tools/schemas.d.ts +1 -1
- package/dist/tools/schemas.js +15 -6
- package/dist/tools/search.d.ts +32 -0
- package/dist/tools/search.js +202 -0
- package/dist/types.d.ts +1 -1
- package/dist/ui/config-editor/config-editor-runtime.js +6 -6
- package/dist/ui/config-editor/src/app.js +2 -15
- package/dist/utils/ab-test.js +27 -9
- package/dist/utils/atomic-write.d.ts +14 -0
- package/dist/utils/atomic-write.js +80 -0
- package/dist/utils/capture.d.ts +17 -1
- package/dist/utils/capture.js +177 -68
- package/dist/utils/exit-process.d.ts +24 -0
- package/dist/utils/exit-process.js +31 -0
- package/dist/utils/feature-flags.js +2 -1
- package/dist/utils/files/base.d.ts +3 -1
- package/dist/utils/files/docx.d.ts +3 -0
- package/dist/utils/files/docx.js +24 -9
- package/dist/utils/files/excel.d.ts +10 -0
- package/dist/utils/files/excel.js +93 -33
- package/dist/utils/files/factory.d.ts +22 -1
- package/dist/utils/files/factory.js +59 -4
- package/dist/utils/files/image.d.ts +12 -4
- package/dist/utils/files/image.js +19 -8
- package/dist/utils/files/index.d.ts +5 -3
- package/dist/utils/files/index.js +4 -3
- package/dist/utils/files/pdf.js +18 -36
- package/dist/utils/files/text.d.ts +21 -5
- package/dist/utils/files/text.js +90 -86
- package/dist/utils/internal-facts.d.ts +3 -0
- package/dist/utils/internal-facts.js +23 -0
- package/dist/utils/lazy-package.d.ts +23 -0
- package/dist/utils/lazy-package.js +42 -0
- package/dist/utils/open-browser.js +2 -1
- package/dist/utils/process-detection.d.ts +24 -5
- package/dist/utils/process-detection.js +199 -89
- package/dist/utils/process-tree.d.ts +14 -0
- package/dist/utils/process-tree.js +223 -0
- package/dist/utils/rename.d.ts +9 -0
- package/dist/utils/rename.js +74 -0
- package/dist/utils/ripgrep-resolver.js +9 -14
- package/dist/utils/shell.d.ts +42 -0
- package/dist/utils/shell.js +187 -0
- package/dist/utils/system-info.js +9 -7
- package/dist/utils/trackTools.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
- package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
- package/package.json +8 -2
- package/vendor/telemetry-contract/README.md +56 -0
- package/vendor/telemetry-contract/package.json +32 -0
- package/vendor/telemetry-contract/transport.d.ts +38 -0
- package/vendor/telemetry-contract/transport.js +164 -0
- package/vendor/telemetry-contract/transport.test.js +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderwhy-er/desktop-commander",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1-alpha.0",
|
|
4
4
|
"description": "MCP server for terminal operations and file editing",
|
|
5
5
|
"mcpName": "io.github.wonderwhy-er/desktop-commander",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
25
|
"logo.png",
|
|
26
|
-
"testemonials"
|
|
26
|
+
"testemonials",
|
|
27
|
+
"vendor/telemetry-contract"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"postinstall": "node dist/track-installation.js && node dist/npm-scripts/verify-ripgrep.js || node -e \"process.exit(0)\"",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"clean": "shx rm -rf dist",
|
|
47
48
|
"test": "npm run build && node test/run-all-tests.js",
|
|
48
49
|
"test:integration": "npm run build && node test/integration/run-all-integration-tests.js",
|
|
50
|
+
"test:transport:telemetry": "npm run build && node test/test-transport-telemetry.js",
|
|
49
51
|
"test:debug": "node --inspect test/run-all-tests.js",
|
|
50
52
|
"validate:tools": "npm run build && node scripts/validate-tools-sync.js",
|
|
51
53
|
"link:local": "npm run build && npm link",
|
|
@@ -88,6 +90,7 @@
|
|
|
88
90
|
"file-operations"
|
|
89
91
|
],
|
|
90
92
|
"dependencies": {
|
|
93
|
+
"@desktop-commander/telemetry-contract": "file:vendor/telemetry-contract",
|
|
91
94
|
"@modelcontextprotocol/sdk": "^1.9.0",
|
|
92
95
|
"@opendocsg/pdf2md": "^0.2.2",
|
|
93
96
|
"@supabase/supabase-js": "^2.89.0",
|
|
@@ -123,6 +126,9 @@
|
|
|
123
126
|
"zod": "^3.24.1",
|
|
124
127
|
"zod-to-json-schema": "^3.23.5"
|
|
125
128
|
},
|
|
129
|
+
"bundleDependencies": [
|
|
130
|
+
"@desktop-commander/telemetry-contract"
|
|
131
|
+
],
|
|
126
132
|
"optionalDependencies": {
|
|
127
133
|
"caffeinate": "^1.0.1"
|
|
128
134
|
},
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @desktop-commander/telemetry-contract
|
|
2
|
+
|
|
3
|
+
Transport observation request contract shared by telemetry-proxy and Remote MCP.
|
|
4
|
+
Import it as `@desktop-commander/telemetry-contract/transport`.
|
|
5
|
+
|
|
6
|
+
`parseRemoteTransportPayload(body)` validates 1–10 transport events for authenticated
|
|
7
|
+
`/remote/collect` requests with a top-level `user_id`.
|
|
8
|
+
`parseDeviceTransportPayload(body)` validates the same event shape for `/mp/collect`
|
|
9
|
+
with a top-level `client_id` and an event `device_id`. It assigns `source=device`.
|
|
10
|
+
|
|
11
|
+
Both functions return normalized events or throw before admitting any event. Event
|
|
12
|
+
names may match `params.stage` or `params.transport`, preserving older transport-named
|
|
13
|
+
events. Unknown and invalid optional parameters are removed. TypeScript declarations
|
|
14
|
+
describe the transport payloads; ordinary device and command telemetry are outside
|
|
15
|
+
this package.
|
|
16
|
+
|
|
17
|
+
## Make a contract change
|
|
18
|
+
|
|
19
|
+
Edit `transport.js` and its matching `transport.d.ts` types, then update
|
|
20
|
+
`transport.test.js`. Keep changes to ordinary device and command telemetry out
|
|
21
|
+
of this package. From the telemetry-proxy root, run `npm test`, then commit and
|
|
22
|
+
push the change for review.
|
|
23
|
+
|
|
24
|
+
## Publish a version
|
|
25
|
+
|
|
26
|
+
1. On a clean branch containing the reviewed changes, run this from the
|
|
27
|
+
telemetry-proxy root for a compatible fix:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
cd packages/telemetry-contract
|
|
31
|
+
npm version patch
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`preversion` checks for tracked changes and runs the contract test.
|
|
35
|
+
`npm version` bumps `package.json`; the `version` script commits it and
|
|
36
|
+
creates the tag using the prefix in this package's `.npmrc`. `postversion`
|
|
37
|
+
pushes the commit and tag to `origin` together. If that push fails, fix the
|
|
38
|
+
cause and push the existing commit and tag; do not run `npm version` again.
|
|
39
|
+
Use `minor` for compatible additions or coordinate breaking changes with
|
|
40
|
+
consumers before a `major` release.
|
|
41
|
+
|
|
42
|
+
2. Check the **Publish telemetry contract** GitHub Actions run. It verifies that
|
|
43
|
+
the tag matches `package.json`, runs the package test, and publishes to
|
|
44
|
+
GitHub Packages as `@desktop-commander/telemetry-contract@0.1.1`. Published
|
|
45
|
+
versions cannot be overwritten; bump the version for another release.
|
|
46
|
+
3. In Remote MCP, with `GITHUB_PACKAGES_TOKEN` available to npm, update the
|
|
47
|
+
pinned dependency and lockfile, then run its tests:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npm install --save-exact @desktop-commander/telemetry-contract@0.1.1
|
|
51
|
+
npm test
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Commit `package.json` and `package-lock.json` together. Remote MCP's Cloud
|
|
55
|
+
Build uses `MCP_REMOTE_GITHUB_PACKAGES_TOKEN` from Secret Manager to install
|
|
56
|
+
the private package. No tarball needs to be copied between repositories.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@desktop-commander/telemetry-contract",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/desktop-commander/telemetry-proxy.git",
|
|
8
|
+
"directory": "packages/telemetry-contract"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://npm.pkg.github.com"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
"./transport": {
|
|
15
|
+
"types": "./transport.d.ts",
|
|
16
|
+
"default": "./transport.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"transport.js",
|
|
21
|
+
"transport.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"preversion": "git diff --quiet && git diff --cached --quiet && npm test",
|
|
25
|
+
"version": "git add package.json && git commit -m \"chore: release telemetry contract v${npm_new_version}\" && git tag \"$(npm config get tag-version-prefix)${npm_new_version}\"",
|
|
26
|
+
"postversion": "git push --atomic origin HEAD \"refs/tags/$(npm config get tag-version-prefix)${npm_new_version}\"",
|
|
27
|
+
"test": "node transport.test.js"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface TransportParams {
|
|
2
|
+
call_id: string;
|
|
3
|
+
stage: string;
|
|
4
|
+
timestamp_utc: string;
|
|
5
|
+
monotonic_ms?: number;
|
|
6
|
+
transport?: 'mqtt' | 'broadcast';
|
|
7
|
+
device_id?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface TransportEvent {
|
|
12
|
+
name: string;
|
|
13
|
+
params: TransportParams;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RemoteTransportPayload {
|
|
17
|
+
user_id: string;
|
|
18
|
+
timestamp_micros?: number;
|
|
19
|
+
events: TransportEvent[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DeviceTransportPayload {
|
|
23
|
+
client_id: string;
|
|
24
|
+
timestamp_micros?: number;
|
|
25
|
+
events: Array<{ name: string; params: TransportParams & { device_id: string } }>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Identifies a transport batch before choosing the ordinary event path. */
|
|
29
|
+
export function hasTransportEvents(payload: unknown): boolean;
|
|
30
|
+
|
|
31
|
+
/** Validates one event and removes unknown or invalid optional fields. */
|
|
32
|
+
export function sanitizeTransportEvent(eventName: string, params: unknown): TransportParams;
|
|
33
|
+
|
|
34
|
+
/** Validates a 1–10 event authenticated backend batch. */
|
|
35
|
+
export function parseRemoteTransportPayload(payload: unknown): RemoteTransportPayload;
|
|
36
|
+
|
|
37
|
+
/** Validates a 1–10 event device batch and assigns source=device. */
|
|
38
|
+
export function parseDeviceTransportPayload(payload: unknown): DeviceTransportPayload;
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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");
|