@codemem/core 0.49.0 → 0.49.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/dist/{coordinator-runtime-BYCjEE7A.js → coordinator-runtime-CEc6KhBE.js} +80 -80
- package/dist/{coordinator-runtime-BYCjEE7A.js.map → coordinator-runtime-CEc6KhBE.js.map} +1 -1
- package/dist/distill-draft.d.ts +6 -0
- package/dist/distill-draft.d.ts.map +1 -1
- package/dist/distill-judge.d.ts +1 -1
- package/dist/distill-judge.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8720 -8709
- package/dist/index.js.map +1 -1
- package/dist/internal/relay-runtime.js +6 -6
- package/dist/{relay-peer-client-j0rOyeuZ.js → relay-peer-client-DmZfZebO.js} +2 -2
- package/dist/{relay-peer-client-j0rOyeuZ.js.map → relay-peer-client-DmZfZebO.js.map} +1 -1
- package/dist/sync-channel-pass.d.ts.map +1 -1
- package/dist/sync-pass.d.ts +3 -7
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-reachability-pass-C_-w0t6b.js +2 -0
- package/dist/{sync-reachability-pass-Co6WjaUD.js → sync-reachability-pass-Dhn4N2hr.js} +2094 -2072
- package/dist/{sync-reachability-pass-Co6WjaUD.js.map → sync-reachability-pass-Dhn4N2hr.js.map} +1 -1
- package/dist/sync-reachability-pass.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/sync-reachability-pass-5bOMxdoW.js +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as e } from "./scope-membership-cache-read-B6z47l2W.js";
|
|
2
2
|
import { p as t } from "./scope-membership-semantics-B8qXaMqx.js";
|
|
3
3
|
import { O as n } from "./sync-auth-constants-BVzVfSmn.js";
|
|
4
|
-
import { A as r, B as i,
|
|
4
|
+
import { A as r, B as i, D as a, L as o, M as s, R as c, V as l, W as u, ct as d, f, it as p, j as m, k as h, p as g } from "./relay-peer-client-DmZfZebO.js";
|
|
5
5
|
import { networkInterfaces as _ } from "node:os";
|
|
6
6
|
//#region src/memory-retirement-trust.ts
|
|
7
7
|
function v(e) {
|
|
@@ -80,11 +80,11 @@ function j(e, t) {
|
|
|
80
80
|
function M(e) {
|
|
81
81
|
return Number(e.db.prepare("SELECT COUNT(1) AS total FROM sync_peers").get()?.total ?? 0);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function ee(e) {
|
|
84
84
|
let t = Math.max(1, e.syncCoordinatorPresenceTtlS), n = Math.floor(t / 2);
|
|
85
85
|
return Math.max(5, Math.min(60, n > 0 ? n : 1)) * 1e3;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function N() {
|
|
88
88
|
return 3e4;
|
|
89
89
|
}
|
|
90
90
|
async function P(e, t, n, r) {
|
|
@@ -99,10 +99,10 @@ async function P(e, t, n, r) {
|
|
|
99
99
|
status: "posted",
|
|
100
100
|
error: null,
|
|
101
101
|
advertisedAddresses: o,
|
|
102
|
-
nextRefreshAtMs: r +
|
|
102
|
+
nextRefreshAtMs: r + ee(t)
|
|
103
103
|
});
|
|
104
104
|
} catch (e) {
|
|
105
|
-
let t = e instanceof Error ? e.message : String(e), a = t.includes("unknown_device") ? "not_enrolled" : "error", o = a === "not_enrolled" ? r : r +
|
|
105
|
+
let t = e instanceof Error ? e.message : String(e), a = t.includes("unknown_device") ? "not_enrolled" : "error", o = a === "not_enrolled" ? r : r + N();
|
|
106
106
|
n.presence_status = a, n.presence_error = t, n.advertised_addresses = [], C.set(i, {
|
|
107
107
|
status: a,
|
|
108
108
|
error: t,
|
|
@@ -113,47 +113,47 @@ async function P(e, t, n, r) {
|
|
|
113
113
|
}
|
|
114
114
|
function F(e) {
|
|
115
115
|
let t = e.syncAdvertise.toLowerCase();
|
|
116
|
-
if (t && t !== "auto" && t !== "default") return
|
|
117
|
-
if (e.syncHost && e.syncHost !== "0.0.0.0") return [
|
|
118
|
-
let n = Object.values(_()).flatMap((e) => e ?? []).filter((e) => !e.internal).map((e) => e.address).filter((e) => e && e !== "127.0.0.1" && e !== "::1").map((t) =>
|
|
116
|
+
if (t && t !== "auto" && t !== "default") return r([], t.split(",").map((e) => e.trim()).filter(Boolean), { defaultHttpPort: e.syncPort });
|
|
117
|
+
if (e.syncHost && e.syncHost !== "0.0.0.0") return [s(h(e.syncHost, e.syncPort))].filter(Boolean);
|
|
118
|
+
let n = Object.values(_()).flatMap((e) => e ?? []).filter((e) => !e.internal).map((e) => e.address).filter((e) => e && e !== "127.0.0.1" && e !== "::1").map((t) => s(h(t, e.syncPort))).filter(Boolean);
|
|
119
119
|
return [...new Set(n)];
|
|
120
120
|
}
|
|
121
121
|
async function I(e, t, n) {
|
|
122
122
|
if (!o(t)) return null;
|
|
123
|
-
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [a, s] =
|
|
123
|
+
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [a, s] = p(e.db, { keysDir: r }), c = d(r);
|
|
124
124
|
if (!c) throw Error("public key missing");
|
|
125
|
-
let
|
|
125
|
+
let m = i(t.syncCoordinatorUrl), h = {
|
|
126
126
|
fingerprint: s,
|
|
127
127
|
public_key: c,
|
|
128
128
|
addresses: F(t),
|
|
129
129
|
ttl_s: Math.max(1, t.syncCoordinatorPresenceTtlS),
|
|
130
130
|
capabilities: {
|
|
131
|
-
sync_capability:
|
|
132
|
-
sync_features:
|
|
131
|
+
sync_capability: f,
|
|
132
|
+
sync_features: g
|
|
133
133
|
}
|
|
134
134
|
}, _ = [];
|
|
135
135
|
for (let n of t.syncCoordinatorGroups) {
|
|
136
|
-
let
|
|
137
|
-
...
|
|
136
|
+
let i = {
|
|
137
|
+
...h,
|
|
138
138
|
group_id: n
|
|
139
|
-
},
|
|
139
|
+
}, o = Buffer.from(JSON.stringify(i), "utf8"), s = `${m}/v1/presence`, c = u({
|
|
140
140
|
deviceId: a,
|
|
141
141
|
dbPath: e.dbPath,
|
|
142
142
|
method: "POST",
|
|
143
|
-
url:
|
|
144
|
-
bodyBytes:
|
|
143
|
+
url: s,
|
|
144
|
+
bodyBytes: o,
|
|
145
145
|
keysDir: r
|
|
146
|
-
}), [d,
|
|
147
|
-
headers:
|
|
148
|
-
body:
|
|
149
|
-
bodyBytes:
|
|
146
|
+
}), [d, f] = await l("POST", s, {
|
|
147
|
+
headers: c,
|
|
148
|
+
body: i,
|
|
149
|
+
bodyBytes: o,
|
|
150
150
|
timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
|
|
151
151
|
});
|
|
152
|
-
if (d !== 200 || !
|
|
153
|
-
let e = typeof
|
|
152
|
+
if (d !== 200 || !f) {
|
|
153
|
+
let e = typeof f?.error == "string" ? f.error : "unknown";
|
|
154
154
|
throw Error(`coordinator presence failed (${d}: ${e})`);
|
|
155
155
|
}
|
|
156
|
-
_.push(
|
|
156
|
+
_.push(f);
|
|
157
157
|
}
|
|
158
158
|
return {
|
|
159
159
|
groups: t.syncCoordinatorGroups,
|
|
@@ -162,47 +162,47 @@ async function I(e, t, n) {
|
|
|
162
162
|
}
|
|
163
163
|
async function L(e, t, n) {
|
|
164
164
|
if (!o(t)) return [];
|
|
165
|
-
let
|
|
165
|
+
let a = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [s] = p(e.db, { keysDir: a }), c = i(t.syncCoordinatorUrl), d = /* @__PURE__ */ new Map();
|
|
166
166
|
for (let n of t.syncCoordinatorGroups) {
|
|
167
|
-
let
|
|
168
|
-
deviceId:
|
|
167
|
+
let i = `${c}/v1/peers?group_id=${encodeURIComponent(n)}`, o = u({
|
|
168
|
+
deviceId: s,
|
|
169
169
|
dbPath: e.dbPath,
|
|
170
170
|
method: "GET",
|
|
171
|
-
url:
|
|
171
|
+
url: i,
|
|
172
172
|
bodyBytes: Buffer.alloc(0),
|
|
173
|
-
keysDir:
|
|
174
|
-
}), [
|
|
175
|
-
headers:
|
|
173
|
+
keysDir: a
|
|
174
|
+
}), [f, p] = await l("GET", i, {
|
|
175
|
+
headers: o,
|
|
176
176
|
timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
|
|
177
177
|
});
|
|
178
|
-
if (
|
|
179
|
-
let e = typeof
|
|
180
|
-
throw Error(`coordinator lookup failed (${
|
|
178
|
+
if (f !== 200 || !p) {
|
|
179
|
+
let e = typeof p?.error == "string" ? p.error : "unknown";
|
|
180
|
+
throw Error(`coordinator lookup failed (${f}: ${e})`);
|
|
181
181
|
}
|
|
182
|
-
let m = Array.isArray(
|
|
182
|
+
let m = Array.isArray(p.items) ? p.items : [];
|
|
183
183
|
for (let e of m) {
|
|
184
184
|
if (!e || typeof e != "object") continue;
|
|
185
|
-
let t = e,
|
|
186
|
-
if (!
|
|
187
|
-
let
|
|
185
|
+
let t = e, i = b(t.device_id), a = b(t.fingerprint);
|
|
186
|
+
if (!i) continue;
|
|
187
|
+
let o = t.stale ? [] : Array.isArray(t.addresses) ? t.addresses.filter((e) => typeof e == "string") : [], s = `${i}:${a}`, l = d.get(s);
|
|
188
188
|
if (!l) {
|
|
189
|
-
|
|
189
|
+
d.set(s, {
|
|
190
190
|
...t,
|
|
191
|
-
addresses:
|
|
192
|
-
coordinator_id:
|
|
191
|
+
addresses: r([], o),
|
|
192
|
+
coordinator_id: c,
|
|
193
193
|
groups: [n],
|
|
194
194
|
fresh_groups: t.stale ? [] : [n]
|
|
195
195
|
});
|
|
196
196
|
continue;
|
|
197
197
|
}
|
|
198
|
-
l.addresses =
|
|
199
|
-
let u = !!l.stale,
|
|
200
|
-
l.stale = u &&
|
|
201
|
-
let
|
|
202
|
-
|
|
198
|
+
l.addresses = r(Array.isArray(l.addresses) ? l.addresses : [], o), l.groups = x(Array.isArray(l.groups) ? l.groups : [], [n]), l.fresh_groups = x(Array.isArray(l.fresh_groups) ? l.fresh_groups : [], t.stale ? [] : [n]);
|
|
199
|
+
let u = !!l.stale, f = !!t.stale;
|
|
200
|
+
l.stale = u && f;
|
|
201
|
+
let p = !f && (u || b(t.last_seen_at) > b(l.last_seen_at)) || f && u && b(t.last_seen_at) > b(l.last_seen_at);
|
|
202
|
+
p && (l.last_seen_at = t.last_seen_at), f ? u && p && (l.expires_at = t.expires_at) : l.expires_at = u ? t.expires_at : S(l.expires_at, t.expires_at);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
return [...
|
|
205
|
+
return [...d.values()];
|
|
206
206
|
}
|
|
207
207
|
function R(e) {
|
|
208
208
|
return Array.isArray(e) ? e.filter((e) => typeof e == "string" && e.trim().length > 0) : [];
|
|
@@ -229,27 +229,27 @@ function V(e, t, n) {
|
|
|
229
229
|
if (!i || !a) return !1;
|
|
230
230
|
let o = t.get(`${i}:${a}`);
|
|
231
231
|
if (!o?.length) return !1;
|
|
232
|
-
let s =
|
|
232
|
+
let s = r(B(e.addresses_json), []), c = e.manual_addresses_json == null ? s : B(e.manual_addresses_json), l = m(s, o, c, { successfulAddress: e.last_success_address ?? void 0 });
|
|
233
233
|
return JSON.stringify(l) === JSON.stringify(s) && e.manual_addresses_json != null ? !1 : (n(JSON.stringify(l), JSON.stringify(c), i, a), !0);
|
|
234
234
|
}
|
|
235
235
|
function H(e, t) {
|
|
236
236
|
let n = /* @__PURE__ */ new Map();
|
|
237
237
|
for (let e of t) {
|
|
238
238
|
if (e.stale) continue;
|
|
239
|
-
let t = b(e.device_id),
|
|
240
|
-
if (!t || !
|
|
241
|
-
let
|
|
242
|
-
if (
|
|
243
|
-
let
|
|
244
|
-
n.set(
|
|
239
|
+
let t = b(e.device_id), i = b(e.fingerprint);
|
|
240
|
+
if (!t || !i) continue;
|
|
241
|
+
let a = R(e.addresses);
|
|
242
|
+
if (a.length === 0) continue;
|
|
243
|
+
let o = `${t}:${i}`;
|
|
244
|
+
n.set(o, r(n.get(o) ?? [], a));
|
|
245
245
|
}
|
|
246
246
|
if (n.size === 0) return 0;
|
|
247
|
-
let
|
|
248
|
-
|
|
249
|
-
},
|
|
247
|
+
let i = e.prepare("SELECT peer_device_id, pinned_fingerprint, addresses_json, manual_addresses_json, last_success_address FROM sync_peers").all(), a = e.prepare("UPDATE sync_peers SET addresses_json = ?, manual_addresses_json = ? WHERE peer_device_id = ? AND pinned_fingerprint = ?"), o = (e, t, n, r) => {
|
|
248
|
+
a.run(e, t, n, r);
|
|
249
|
+
}, s = 0;
|
|
250
250
|
return e.transaction(() => {
|
|
251
|
-
for (let e of
|
|
252
|
-
}).immediate(),
|
|
251
|
+
for (let e of i) V(e, n, o) && (s += 1);
|
|
252
|
+
}).immediate(), s;
|
|
253
253
|
}
|
|
254
254
|
function U(t, n) {
|
|
255
255
|
let { localDeviceId: r, peerDeviceId: i, coordinatorId: a, peerGroupIds: o, peerPublicKey: s } = n, c = n.kinds?.length ? n.kinds : ["managed_project"], l = t.prepare("SELECT public_key FROM sync_device WHERE device_id = ?").pluck().get(r), u = t.prepare(`SELECT scope.scope_id, scope.coordinator_id, scope.group_id
|
|
@@ -401,7 +401,7 @@ async function X(e, t, n) {
|
|
|
401
401
|
peers: [],
|
|
402
402
|
trusted: 0
|
|
403
403
|
};
|
|
404
|
-
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i] =
|
|
404
|
+
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i] = p(e.db, { keysDir: r }), a = await L(e, t, { keysDir: r });
|
|
405
405
|
return H(e.db, a), {
|
|
406
406
|
peers: a,
|
|
407
407
|
trusted: Y(e.db, i, a)
|
|
@@ -409,7 +409,7 @@ async function X(e, t, n) {
|
|
|
409
409
|
}
|
|
410
410
|
async function ae(e, t, n, r) {
|
|
411
411
|
if (r?.peers) return Z(r.peers);
|
|
412
|
-
let i =
|
|
412
|
+
let i = c();
|
|
413
413
|
if (!o(i)) return /* @__PURE__ */ new Set();
|
|
414
414
|
try {
|
|
415
415
|
let r = await L({
|
|
@@ -435,20 +435,20 @@ function Z(e) {
|
|
|
435
435
|
}
|
|
436
436
|
async function Q(e, t, n) {
|
|
437
437
|
if (!o(t)) return [];
|
|
438
|
-
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [a] =
|
|
439
|
-
for (let
|
|
440
|
-
let
|
|
441
|
-
group_id:
|
|
438
|
+
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [a] = p(e.db, { keysDir: r }), s = i(t.syncCoordinatorUrl), c = /* @__PURE__ */ new Map();
|
|
439
|
+
for (let i of t.syncCoordinatorGroups) {
|
|
440
|
+
let o = `${s}/v1/reciprocal-approvals?${new URLSearchParams({
|
|
441
|
+
group_id: i,
|
|
442
442
|
direction: n.direction,
|
|
443
443
|
status: n.status?.trim() || "pending"
|
|
444
|
-
}).toString()}`, d =
|
|
444
|
+
}).toString()}`, d = u({
|
|
445
445
|
deviceId: a,
|
|
446
446
|
dbPath: e.dbPath,
|
|
447
447
|
method: "GET",
|
|
448
|
-
url:
|
|
448
|
+
url: o,
|
|
449
449
|
bodyBytes: Buffer.alloc(0),
|
|
450
450
|
keysDir: r
|
|
451
|
-
}), [f, p] = await
|
|
451
|
+
}), [f, p] = await l("GET", o, {
|
|
452
452
|
headers: d,
|
|
453
453
|
timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
|
|
454
454
|
});
|
|
@@ -470,21 +470,21 @@ async function oe(e, t, r) {
|
|
|
470
470
|
let a = r.groupId.trim(), s = r.requestedDeviceId.trim(), c = r.expectedIncomingRequestId?.trim();
|
|
471
471
|
if (!a || !s) throw Error("groupId and requestedDeviceId are required.");
|
|
472
472
|
if (r.expectedIncomingRequestId !== void 0 && !c) throw Error("expectedIncomingRequestId must not be empty when provided.");
|
|
473
|
-
let
|
|
473
|
+
let d = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [f] = p(e.db, { keysDir: d }), m = `${i(t.syncCoordinatorUrl)}/v1/reciprocal-approvals`, h = {
|
|
474
474
|
group_id: a,
|
|
475
475
|
requested_device_id: s,
|
|
476
476
|
...c === void 0 ? {} : { expected_incoming_request_id: c }
|
|
477
|
-
},
|
|
478
|
-
deviceId:
|
|
477
|
+
}, g = Buffer.from(JSON.stringify(h), "utf8"), _ = u({
|
|
478
|
+
deviceId: f,
|
|
479
479
|
dbPath: e.dbPath,
|
|
480
480
|
method: "POST",
|
|
481
|
-
url:
|
|
482
|
-
bodyBytes:
|
|
483
|
-
keysDir:
|
|
484
|
-
}), [v, y] = await
|
|
481
|
+
url: m,
|
|
482
|
+
bodyBytes: g,
|
|
483
|
+
keysDir: d
|
|
484
|
+
}), [v, y] = await l("POST", m, {
|
|
485
485
|
headers: _,
|
|
486
|
-
body:
|
|
487
|
-
bodyBytes:
|
|
486
|
+
body: h,
|
|
487
|
+
bodyBytes: g,
|
|
488
488
|
timeoutS: Math.max(1, t.syncCoordinatorTimeoutS)
|
|
489
489
|
});
|
|
490
490
|
if (v !== 200 || !y || !y.request || typeof y.request != "object") {
|
|
@@ -511,7 +511,7 @@ async function se(e, t) {
|
|
|
511
511
|
groups: t.syncCoordinatorGroups,
|
|
512
512
|
paired_peer_count: n
|
|
513
513
|
};
|
|
514
|
-
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [i] =
|
|
514
|
+
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [i] = p(e.db, { keysDir: r }), a = j(e, t), s = T.get(a) ?? 0, c = Date.now(), l = w.get(a);
|
|
515
515
|
if (l && c < l.nextRefreshAtMs) {
|
|
516
516
|
let n = structuredClone(l.snapshot);
|
|
517
517
|
if (await P(e, t, n, c), c = Date.now(), n.presence_status === "not_enrolled") return O(a), n.fresh_peer_count = 0, n.stale_peer_count = 0, n.discovered_peer_count = 0, n.discovered_devices = [], n.reciprocal_approvals = {
|
|
@@ -582,7 +582,7 @@ async function se(e, t) {
|
|
|
582
582
|
async function ce(e) {
|
|
583
583
|
let t = e.syncCoordinatorGroup || e.syncCoordinatorGroups[0] || "";
|
|
584
584
|
if (!t || !e.syncCoordinatorUrl || !e.syncCoordinatorAdminSecret) return [];
|
|
585
|
-
let n = `${
|
|
585
|
+
let n = `${i(e.syncCoordinatorUrl)}/v1/admin/join-requests?group_id=${encodeURIComponent(t)}`, [r, a] = await l("GET", n, {
|
|
586
586
|
headers: { "X-Codemem-Coordinator-Admin": e.syncCoordinatorAdminSecret },
|
|
587
587
|
timeoutS: Math.max(1, e.syncCoordinatorTimeoutS)
|
|
588
588
|
});
|
|
@@ -591,4 +591,4 @@ async function ce(e) {
|
|
|
591
591
|
//#endregion
|
|
592
592
|
export { Q as a, H as c, K as d, ce as i, I as l, oe as n, L as o, ae as r, X as s, se as t, U as u };
|
|
593
593
|
|
|
594
|
-
//# sourceMappingURL=coordinator-runtime-
|
|
594
|
+
//# sourceMappingURL=coordinator-runtime-CEc6KhBE.js.map
|