@ai-matrx/desktop-protocol 0.5.0 → 0.7.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/CHANGELOG.md +25 -0
- package/dist/client.cjs +47 -13
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +4 -2
- package/dist/client.d.ts +4 -2
- package/dist/client.js +47 -13
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +57 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -6
- package/dist/index.d.ts +29 -6
- package/dist/index.js +57 -2
- package/dist/index.js.map +1 -1
- package/dist/react.d.cts +20 -1
- package/dist/react.d.ts +20 -1
- package/dist/{registry-BeY9D7h0.d.cts → registry-Duc_VFN8.d.cts} +93 -3
- package/dist/{registry-BeY9D7h0.d.ts → registry-Duc_VFN8.d.ts} +93 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(src_exports, {
|
|
|
23
23
|
AbsPath: () => AbsPath,
|
|
24
24
|
BEARER_PREFIX: () => BEARER_PREFIX,
|
|
25
25
|
BROADCAST_CID: () => BROADCAST_CID,
|
|
26
|
+
CLOSE_RULES: () => CLOSE_RULES,
|
|
26
27
|
CancelMsg: () => CancelMsg,
|
|
27
28
|
ClientToCoreMsg: () => ClientToCoreMsg,
|
|
28
29
|
ClientType: () => ClientType,
|
|
@@ -100,6 +101,7 @@ __export(src_exports, {
|
|
|
100
101
|
HelloMsg: () => HelloMsg,
|
|
101
102
|
Limits: () => Limits,
|
|
102
103
|
NAMED_SCHEMAS: () => NAMED_SCHEMAS,
|
|
104
|
+
NULL_SINCE: () => NULL_SINCE,
|
|
103
105
|
OPS: () => OPS,
|
|
104
106
|
OpDescriptor: () => OpDescriptor,
|
|
105
107
|
OsPermissionName: () => OsPermissionName,
|
|
@@ -146,7 +148,9 @@ __export(src_exports, {
|
|
|
146
148
|
SysinfoGetResult: () => SysinfoGetResult,
|
|
147
149
|
VERSIONED_RESULT_OPS: () => VERSIONED_RESULT_OPS,
|
|
148
150
|
Welcome: () => Welcome,
|
|
151
|
+
announcedVersion: () => announcedVersion,
|
|
149
152
|
assertFrameHeader: () => assertFrameHeader,
|
|
153
|
+
closeRule: () => closeRule,
|
|
150
154
|
compareVersions: () => compareVersions,
|
|
151
155
|
connectionEndFrame: () => connectionEndFrame,
|
|
152
156
|
decodeFrame: () => decodeFrame,
|
|
@@ -156,12 +160,15 @@ __export(src_exports, {
|
|
|
156
160
|
hasFlag: () => hasFlag,
|
|
157
161
|
isConnectionEnd: () => isConnectionEnd,
|
|
158
162
|
isDesktopProtocolError: () => isDesktopProtocolError,
|
|
163
|
+
isTerminalClose: () => isTerminalClose,
|
|
159
164
|
knows: () => knows,
|
|
160
165
|
negotiate: () => negotiate,
|
|
161
166
|
nonNegInt: () => nonNegInt,
|
|
162
167
|
readCid: () => readCid,
|
|
163
168
|
stampCid: () => stampCid,
|
|
164
|
-
|
|
169
|
+
statusForPeer: () => statusForPeer,
|
|
170
|
+
u32: () => u32,
|
|
171
|
+
versionSubprotocol: () => versionSubprotocol
|
|
165
172
|
});
|
|
166
173
|
module.exports = __toCommonJS(src_exports);
|
|
167
174
|
|
|
@@ -805,7 +812,11 @@ var SessionControlChangedEvent = import_zod8.z.strictObject({ controller_client_
|
|
|
805
812
|
var import_zod9 = require("zod");
|
|
806
813
|
var RelayDeviceStatusEvent = import_zod9.z.strictObject({
|
|
807
814
|
online: import_zod9.z.boolean(),
|
|
808
|
-
|
|
815
|
+
/**
|
|
816
|
+
* When the device last went online/offline; null = it has never connected (since 1.1 —
|
|
817
|
+
* NULL_SINCE: a 1.0 reader is sent 0, its old meaning).
|
|
818
|
+
*/
|
|
819
|
+
since_ms: epochMs.nullable(),
|
|
809
820
|
app_version: import_zod9.z.string().max(32).nullable(),
|
|
810
821
|
protocol_version: ProtocolVersion.nullable()
|
|
811
822
|
});
|
|
@@ -992,6 +1003,24 @@ var FIELDS_SINCE = {
|
|
|
992
1003
|
"RelayCallResponse|0": { protocol_version: "1.1" },
|
|
993
1004
|
"RelayCallResponse|1": { protocol_version: "1.1" }
|
|
994
1005
|
};
|
|
1006
|
+
var NULL_SINCE = {
|
|
1007
|
+
"RelayDeviceStatusEvent.since_ms": { since: "1.1", olderPeersGet: 0 }
|
|
1008
|
+
};
|
|
1009
|
+
function statusForPeer(status, version) {
|
|
1010
|
+
const rule = NULL_SINCE["RelayDeviceStatusEvent.since_ms"];
|
|
1011
|
+
return status.since_ms === null && !knows(version, rule.since) ? { ...status, since_ms: rule.olderPeersGet } : status;
|
|
1012
|
+
}
|
|
1013
|
+
function versionSubprotocol(version) {
|
|
1014
|
+
return `matrx.v${version}`;
|
|
1015
|
+
}
|
|
1016
|
+
function announcedVersion(offered) {
|
|
1017
|
+
let best = `${PROTOCOL_MAJOR}.0`;
|
|
1018
|
+
for (const p of offered) {
|
|
1019
|
+
const m = /^matrx\.v(\d+\.\d+)$/.exec(p.trim());
|
|
1020
|
+
if (m?.[1] && compareVersions(m[1], best) > 0 && m[1].startsWith(`${PROTOCOL_MAJOR}.`)) best = m[1];
|
|
1021
|
+
}
|
|
1022
|
+
return best;
|
|
1023
|
+
}
|
|
995
1024
|
function compareVersions(a, b) {
|
|
996
1025
|
const [am = 0, an = 0] = a.split(".").map(Number);
|
|
997
1026
|
const [bm = 0, bn = 0] = b.split(".").map(Number);
|
|
@@ -1029,4 +1058,30 @@ function forPeer(op, part, value, version) {
|
|
|
1029
1058
|
return data === body.data ? value : { ...body, data };
|
|
1030
1059
|
}
|
|
1031
1060
|
var VERSIONED_RESULT_OPS = [...RESULT_PATH.keys()];
|
|
1061
|
+
|
|
1062
|
+
// src/close-policy.ts
|
|
1063
|
+
var CLOSE_RULES = {
|
|
1064
|
+
[CloseCode.NORMAL]: { action: "reconnect", error: ["DEVICE_OFFLINE", "Connection closed"] },
|
|
1065
|
+
[CloseCode.GOING_AWAY]: { action: "reconnect_now", error: ["DEVICE_OFFLINE", "Connection lost"] },
|
|
1066
|
+
[CloseCode.ABNORMAL]: { action: "reconnect_now", error: ["DEVICE_OFFLINE", "Connection lost"] },
|
|
1067
|
+
[CloseCode.DEVICE_RECONNECTED]: { action: "reconnect_now", error: ["DEVICE_OFFLINE", "Device reconnected"] },
|
|
1068
|
+
[CloseCode.TRY_AGAIN_LATER]: { action: "reconnect", error: ["DEVICE_OFFLINE", "Relay busy; retrying"] },
|
|
1069
|
+
[CloseCode.AUTH_INVALID]: { action: "reauth", outcome: "signed_out", error: ["AUTH_INVALID", "Sign-in was not accepted"] },
|
|
1070
|
+
[CloseCode.AUTH_FORBIDDEN]: { action: "stop", outcome: "not_owned", error: ["AUTH_FORBIDDEN", "Not this device's owner"] },
|
|
1071
|
+
[CloseCode.DEVICE_NOT_FOUND]: { action: "stop", outcome: "removed", error: ["NOT_FOUND", "Device not found"] },
|
|
1072
|
+
[CloseCode.AUTH_EXPIRED]: { action: "reauth", outcome: "signed_out", error: ["AUTH_EXPIRED", "Sign-in expired"] },
|
|
1073
|
+
[CloseCode.REPLACED]: { action: "stop", outcome: "replaced", error: ["CONFLICT", "Replaced by a newer connection"] },
|
|
1074
|
+
[CloseCode.DEVICE_REVOKED]: { action: "stop", outcome: "revoked", error: ["AUTH_DEVICE_REVOKED", "This device was revoked"] },
|
|
1075
|
+
// A malformed message, or a connection the relay lost track of: a fresh socket starts clean.
|
|
1076
|
+
[CloseCode.PROTOCOL_ERROR]: { action: "reconnect", error: ["PROTOCOL_ERROR", "Connection reset by the relay"] },
|
|
1077
|
+
[CloseCode.UPGRADE_REQUIRED]: { action: "stop", outcome: "upgrade_required", error: ["PROTOCOL_VERSION_UNSUPPORTED", "Protocol upgrade required"] }
|
|
1078
|
+
};
|
|
1079
|
+
var UNKNOWN = { action: "reconnect", error: ["DEVICE_OFFLINE", "Connection lost"] };
|
|
1080
|
+
function closeRule(code) {
|
|
1081
|
+
if (code === null || code === void 0) return CLOSE_RULES[CloseCode.ABNORMAL];
|
|
1082
|
+
return CLOSE_RULES[code] ?? UNKNOWN;
|
|
1083
|
+
}
|
|
1084
|
+
function isTerminalClose(code) {
|
|
1085
|
+
return closeRule(code).action === "stop";
|
|
1086
|
+
}
|
|
1032
1087
|
//# sourceMappingURL=index.cjs.map
|