@ai-matrx/desktop-protocol 0.3.0 → 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.
- package/CHANGELOG.md +32 -0
- package/dist/client.cjs +32 -4
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +32 -4
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +89 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -4
- package/dist/index.d.ts +100 -4
- package/dist/index.js +89 -4
- package/dist/index.js.map +1 -1
- package/dist/react.d.cts +13 -0
- package/dist/react.d.ts +13 -0
- package/dist/{registry-DQ5_mP_5.d.cts → registry-BeY9D7h0.d.cts} +80 -1
- package/dist/{registry-DQ5_mP_5.d.ts → registry-BeY9D7h0.d.ts} +80 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -59,6 +59,7 @@ __export(src_exports, {
|
|
|
59
59
|
ExecRunParams: () => ExecRunParams,
|
|
60
60
|
ExecRunResult: () => ExecRunResult,
|
|
61
61
|
ExecTitleEvent: () => ExecTitleEvent,
|
|
62
|
+
FIELDS_SINCE: () => FIELDS_SINCE,
|
|
62
63
|
FRAME_HEADER_BYTES: () => FRAME_HEADER_BYTES,
|
|
63
64
|
FRAME_STRUCT_FORMAT: () => FRAME_STRUCT_FORMAT,
|
|
64
65
|
FRAME_VERSION: () => FRAME_VERSION,
|
|
@@ -78,6 +79,8 @@ __export(src_exports, {
|
|
|
78
79
|
FsMkdirResult: () => FsMkdirResult,
|
|
79
80
|
FsMoveParams: () => FsMoveParams,
|
|
80
81
|
FsMoveResult: () => FsMoveResult,
|
|
82
|
+
FsPatchEditApplied: () => FsPatchEditApplied,
|
|
83
|
+
FsPatchEditFailure: () => FsPatchEditFailure,
|
|
81
84
|
FsPatchParams: () => FsPatchParams,
|
|
82
85
|
FsPatchResult: () => FsPatchResult,
|
|
83
86
|
FsReadParams: () => FsReadParams,
|
|
@@ -110,6 +113,7 @@ __export(src_exports, {
|
|
|
110
113
|
PtyInfo: () => PtyInfo,
|
|
111
114
|
RELAY_CALL_HELLO_ID: () => RELAY_CALL_HELLO_ID,
|
|
112
115
|
RELAY_CALL_REQUEST_ID: () => RELAY_CALL_REQUEST_ID,
|
|
116
|
+
RELAY_CALL_VERSION_HEADER: () => RELAY_CALL_VERSION_HEADER,
|
|
113
117
|
RelayAuthExpiringEvent: () => RelayAuthExpiringEvent,
|
|
114
118
|
RelayCallEnvelope: () => RelayCallEnvelope,
|
|
115
119
|
RelayCallHello: () => RelayCallHello,
|
|
@@ -140,15 +144,20 @@ __export(src_exports, {
|
|
|
140
144
|
StreamMsg: () => StreamMsg,
|
|
141
145
|
SysinfoGetParams: () => SysinfoGetParams,
|
|
142
146
|
SysinfoGetResult: () => SysinfoGetResult,
|
|
147
|
+
VERSIONED_RESULT_OPS: () => VERSIONED_RESULT_OPS,
|
|
143
148
|
Welcome: () => Welcome,
|
|
144
149
|
assertFrameHeader: () => assertFrameHeader,
|
|
150
|
+
compareVersions: () => compareVersions,
|
|
145
151
|
connectionEndFrame: () => connectionEndFrame,
|
|
146
152
|
decodeFrame: () => decodeFrame,
|
|
147
153
|
encodeFrame: () => encodeFrame,
|
|
148
154
|
epochMs: () => epochMs,
|
|
155
|
+
forPeer: () => forPeer,
|
|
149
156
|
hasFlag: () => hasFlag,
|
|
150
157
|
isConnectionEnd: () => isConnectionEnd,
|
|
151
158
|
isDesktopProtocolError: () => isDesktopProtocolError,
|
|
159
|
+
knows: () => knows,
|
|
160
|
+
negotiate: () => negotiate,
|
|
152
161
|
nonNegInt: () => nonNegInt,
|
|
153
162
|
readCid: () => readCid,
|
|
154
163
|
stampCid: () => stampCid,
|
|
@@ -159,7 +168,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
159
168
|
// src/schema/primitives.ts
|
|
160
169
|
var import_zod = require("zod");
|
|
161
170
|
var PROTOCOL_MAJOR = 1;
|
|
162
|
-
var PROTOCOL_MINOR =
|
|
171
|
+
var PROTOCOL_MINOR = 1;
|
|
163
172
|
var PROTOCOL_VERSION = `${PROTOCOL_MAJOR}.${PROTOCOL_MINOR}`;
|
|
164
173
|
var ProtocolVersion = import_zod.z.string().regex(/^[1-9][0-9]{0,2}\.[0-9]{1,3}$/);
|
|
165
174
|
var RequestId = import_zod.z.string().min(1).max(64).regex(/^[A-Za-z0-9_-]+$/);
|
|
@@ -220,6 +229,7 @@ var ErrorReason = import_zod2.z.enum([
|
|
|
220
229
|
// another client of the same user took control
|
|
221
230
|
"window_exhausted"
|
|
222
231
|
]);
|
|
232
|
+
var FsPatchEditFailure = import_zod2.z.strictObject({ edit_index: nonNegInt, reason: import_zod2.z.string().max(300) });
|
|
223
233
|
var ProtocolErrorBody = import_zod2.z.strictObject({
|
|
224
234
|
code: ErrorCode,
|
|
225
235
|
message: import_zod2.z.string().max(300),
|
|
@@ -234,6 +244,8 @@ var ProtocolErrorBody = import_zod2.z.strictObject({
|
|
|
234
244
|
// PERMISSION_DENIED_OS deep link
|
|
235
245
|
retry_after_ms: nonNegInt.optional(),
|
|
236
246
|
limit_bytes: nonNegInt.optional(),
|
|
247
|
+
/** fs.patch when every edit failed (CONFLICT, patch_no_match / patch_ambiguous): the daemon's 422 `failures`. */
|
|
248
|
+
edits_failed: import_zod2.z.array(FsPatchEditFailure).max(256).optional(),
|
|
237
249
|
upgrade: import_zod2.z.strictObject({
|
|
238
250
|
min_version: ProtocolVersion,
|
|
239
251
|
max_version: ProtocolVersion,
|
|
@@ -639,7 +651,22 @@ var FsPatchParams = import_zod6.z.strictObject({
|
|
|
639
651
|
).min(1).max(256),
|
|
640
652
|
create_if_missing: import_zod6.z.boolean().default(false)
|
|
641
653
|
});
|
|
642
|
-
var
|
|
654
|
+
var FsPatchEditApplied = import_zod6.z.strictObject({
|
|
655
|
+
edit_index: nonNegInt,
|
|
656
|
+
mode: import_zod6.z.enum(["create", "replace", "replace_all"]),
|
|
657
|
+
/** Present for replace_all only, as the daemon sends it. */
|
|
658
|
+
matches_replaced: nonNegInt.optional()
|
|
659
|
+
});
|
|
660
|
+
var FsPatchResult = import_zod6.z.strictObject({
|
|
661
|
+
path: AbsPath,
|
|
662
|
+
applied: nonNegInt,
|
|
663
|
+
size: nonNegInt,
|
|
664
|
+
mtime_ms: epochMs,
|
|
665
|
+
/** Since 1.1 (FIELDS_SINCE): a 1.0 app sends only `applied`. Always sent to a ≥1.1 peer. */
|
|
666
|
+
edits_applied: import_zod6.z.array(FsPatchEditApplied).max(256).optional(),
|
|
667
|
+
/** Since 1.1 (FIELDS_SINCE). */
|
|
668
|
+
edits_failed: import_zod6.z.array(FsPatchEditFailure).max(256).optional()
|
|
669
|
+
});
|
|
643
670
|
var FsSearchPathsParams = import_zod6.z.strictObject({
|
|
644
671
|
pattern: import_zod6.z.string().min(1).max(512),
|
|
645
672
|
cwd: AbsPath,
|
|
@@ -789,9 +816,20 @@ var RelayCallRequest = import_zod9.z.strictObject({
|
|
|
789
816
|
params: import_zod9.z.unknown(),
|
|
790
817
|
timeout_ms: import_zod9.z.int().min(100).max(37e5).default(7e4)
|
|
791
818
|
});
|
|
819
|
+
var RELAY_CALL_VERSION_HEADER = "x-matrx-protocol-version";
|
|
792
820
|
var RelayCallResponse = import_zod9.z.discriminatedUnion("ok", [
|
|
793
|
-
import_zod9.z.strictObject({
|
|
794
|
-
|
|
821
|
+
import_zod9.z.strictObject({
|
|
822
|
+
ok: import_zod9.z.literal(true),
|
|
823
|
+
result: import_zod9.z.unknown(),
|
|
824
|
+
/** Since 1.1: the version the device negotiated for this call (its welcome). */
|
|
825
|
+
protocol_version: ProtocolVersion.optional()
|
|
826
|
+
}),
|
|
827
|
+
import_zod9.z.strictObject({
|
|
828
|
+
ok: import_zod9.z.literal(false),
|
|
829
|
+
error: ProtocolErrorBody,
|
|
830
|
+
/** Since 1.1, as above (absent when the device never answered hello). */
|
|
831
|
+
protocol_version: ProtocolVersion.optional()
|
|
832
|
+
})
|
|
795
833
|
]);
|
|
796
834
|
var RELAY_CALL_HELLO_ID = "hello";
|
|
797
835
|
var RELAY_CALL_REQUEST_ID = "call";
|
|
@@ -856,6 +894,7 @@ var NAMED_SCHEMAS = {
|
|
|
856
894
|
AbsPath,
|
|
857
895
|
ErrorCode,
|
|
858
896
|
ErrorReason,
|
|
897
|
+
FsPatchEditFailure,
|
|
859
898
|
ProtocolErrorBody,
|
|
860
899
|
FrameHeader,
|
|
861
900
|
ClientType,
|
|
@@ -899,6 +938,7 @@ var NAMED_SCHEMAS = {
|
|
|
899
938
|
FsDeleteResult,
|
|
900
939
|
FsWatchParams,
|
|
901
940
|
FsWatchResult,
|
|
941
|
+
FsPatchEditApplied,
|
|
902
942
|
FsPatchParams,
|
|
903
943
|
FsPatchResult,
|
|
904
944
|
FsSearchPathsParams,
|
|
@@ -944,4 +984,49 @@ var NAMED_SCHEMAS = {
|
|
|
944
984
|
RelayHopConnectionEnd,
|
|
945
985
|
CloseCodeValue
|
|
946
986
|
};
|
|
987
|
+
|
|
988
|
+
// src/versioning.ts
|
|
989
|
+
var FIELDS_SINCE = {
|
|
990
|
+
FsPatchResult: { edits_applied: "1.1", edits_failed: "1.1" },
|
|
991
|
+
"ProtocolErrorBody.data": { edits_failed: "1.1" },
|
|
992
|
+
"RelayCallResponse|0": { protocol_version: "1.1" },
|
|
993
|
+
"RelayCallResponse|1": { protocol_version: "1.1" }
|
|
994
|
+
};
|
|
995
|
+
function compareVersions(a, b) {
|
|
996
|
+
const [am = 0, an = 0] = a.split(".").map(Number);
|
|
997
|
+
const [bm = 0, bn = 0] = b.split(".").map(Number);
|
|
998
|
+
return am - bm || an - bn;
|
|
999
|
+
}
|
|
1000
|
+
function knows(version, since) {
|
|
1001
|
+
return compareVersions(version, since) >= 0;
|
|
1002
|
+
}
|
|
1003
|
+
function negotiate(peerVersion) {
|
|
1004
|
+
const [major = 0, minor = 0] = peerVersion.split(".").map(Number);
|
|
1005
|
+
if (major !== PROTOCOL_MAJOR) return `${PROTOCOL_MAJOR}.0`;
|
|
1006
|
+
return `${PROTOCOL_MAJOR}.${Math.min(minor, PROTOCOL_MINOR)}`;
|
|
1007
|
+
}
|
|
1008
|
+
function strip(value, fields, version) {
|
|
1009
|
+
if (!fields || value === null || typeof value !== "object" || Array.isArray(value)) return value;
|
|
1010
|
+
let out = null;
|
|
1011
|
+
for (const [field, since] of Object.entries(fields)) {
|
|
1012
|
+
if (field in value && !knows(version, since)) {
|
|
1013
|
+
out ??= { ...value };
|
|
1014
|
+
delete out[field];
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return out ?? value;
|
|
1018
|
+
}
|
|
1019
|
+
var RESULT_PATH = /* @__PURE__ */ new Map([["fs.patch", "FsPatchResult"]]);
|
|
1020
|
+
function forPeer(op, part, value, version) {
|
|
1021
|
+
if (part === "result") {
|
|
1022
|
+
const path = op ? RESULT_PATH.get(op) : void 0;
|
|
1023
|
+
return path ? strip(value, FIELDS_SINCE[path], version) : value;
|
|
1024
|
+
}
|
|
1025
|
+
if (value === null || typeof value !== "object") return value;
|
|
1026
|
+
const body = value;
|
|
1027
|
+
if (body.data === void 0) return value;
|
|
1028
|
+
const data = strip(body.data, FIELDS_SINCE["ProtocolErrorBody.data"], version);
|
|
1029
|
+
return data === body.data ? value : { ...body, data };
|
|
1030
|
+
}
|
|
1031
|
+
var VERSIONED_RESULT_OPS = [...RESULT_PATH.keys()];
|
|
947
1032
|
//# sourceMappingURL=index.cjs.map
|