@coasys/ad4m-connect 0.13.1-staging.11 → 0.13.1-staging.12

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/core.d.ts CHANGED
@@ -25,6 +25,30 @@ export default class Ad4mConnect extends EventTarget {
25
25
  private embeddedReject?;
26
26
  constructor(options: Ad4mConnectOptions);
27
27
  connect(): Promise<Ad4mClient>;
28
+ /**
29
+ * Connect directly to `this.url`. For a background try (`retry`), `retry.wanted` is asked after
30
+ * each wait (the health check, the auth read): once it answers false the attempt gives up without
31
+ * touching the connection, closes the client it opened and resolves `undefined`. A stale retry
32
+ * must not replace the client, or apply the auth, of a connection the user started meanwhile.
33
+ */
34
+ private connectStandalone;
35
+ /**
36
+ * `connect()` again until the node answers, for a stored session whose node was unreachable
37
+ * when the app loaded: restarting, or redeploying. Without it the first failure left the user
38
+ * on the connection screen, looking logged out, until they reloaded the page. Waits
39
+ * `initialDelayMs` before the first try, doubling up to `maxDelayMs`. Resolves with the client
40
+ * once connected, or `undefined` when `signal` aborts, the token is gone or changed (a new login:
41
+ * the old token's refusal must not discard the new one), or `url` changed: the user picked
42
+ * another node, and the stored token is not for it. A try already under way when
43
+ * that happens gives up too, before it touches the connection. Embedded mode resolves
44
+ * `undefined` at once: its `connect` waits for the parent's postMessage, so a retry adds only
45
+ * ack timeouts.
46
+ */
47
+ connectWhenReachable({ signal, initialDelayMs, maxDelayMs }?: {
48
+ signal?: AbortSignal;
49
+ initialDelayMs?: number;
50
+ maxDelayMs?: number;
51
+ }): Promise<Ad4mClient | undefined>;
28
52
  /** Make this client the connection, closing the one it replaces. */
29
53
  private adoptClient;
30
54
  private buildClient;
package/dist/core.js CHANGED
@@ -39,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
 
41
41
  // ../package.json
42
- var version = "0.13.1-staging.11";
42
+ var version = "0.13.1-staging.12";
43
43
 
44
44
  // src/utils.ts
45
45
  function isEmbedded() {
@@ -67,6 +67,67 @@ function removeLocal(key) {
67
67
  if (localStorageSupported())
68
68
  localStorage.removeItem(`${version}/${key}`);
69
69
  }
70
+ var SESSION_KEYS = ["ad4m-token", "ad4m-url", "ad4m-port", "ad4m-last-host"];
71
+ function adoptStoredSession(url) {
72
+ if (!localStorageSupported() || localStorage.getItem(`${version}/ad4m-token`))
73
+ return false;
74
+ const suffix = "/ad4m-token";
75
+ const prefixes = [];
76
+ let newest = null;
77
+ for (let i = 0; i < localStorage.length; i++) {
78
+ const key = localStorage.key(i);
79
+ if (!(key == null ? void 0 : key.endsWith(suffix)) || !localStorage.getItem(key))
80
+ continue;
81
+ const prefix = key.slice(0, key.length - suffix.length);
82
+ if (!adoptableFrom(prefix) || url !== void 0 && !storedFor(prefix, url))
83
+ continue;
84
+ prefixes.push(prefix);
85
+ if (newest === null || compareVersions(newest, prefix) < 0)
86
+ newest = prefix;
87
+ }
88
+ if (newest === null)
89
+ return false;
90
+ for (const name of SESSION_KEYS) {
91
+ const value = localStorage.getItem(`${newest}/${name}`);
92
+ if (value !== null)
93
+ localStorage.setItem(`${version}/${name}`, value);
94
+ else
95
+ localStorage.removeItem(`${version}/${name}`);
96
+ }
97
+ for (const prefix of prefixes) {
98
+ for (const name of SESSION_KEYS)
99
+ localStorage.removeItem(`${prefix}/${name}`);
100
+ }
101
+ return true;
102
+ }
103
+ function adoptableFrom(prefix) {
104
+ const line = minorLine(version);
105
+ return line !== null && minorLine(prefix) === line && compareVersions(prefix, version) < 0;
106
+ }
107
+ function minorLine(v) {
108
+ var _a, _b;
109
+ return (_b = (_a = /^(\d+\.\d+)\.\d+(?:-|$)/.exec(v)) == null ? void 0 : _a[1]) != null ? _b : null;
110
+ }
111
+ function storedFor(prefix, url) {
112
+ const stored = localStorage.getItem(`${prefix}/ad4m-url`);
113
+ return stored !== null && wsUrlToHttpBase(stored) === wsUrlToHttpBase(url);
114
+ }
115
+ function compareVersions(a, b) {
116
+ const split = (v) => {
117
+ const i = v.indexOf("-");
118
+ return i < 0 ? [v, ""] : [v.slice(0, i), v.slice(i + 1)];
119
+ };
120
+ const [aCore, aPre] = split(a);
121
+ const [bCore, bPre] = split(b);
122
+ const byCore = aCore.localeCompare(bCore, void 0, { numeric: true });
123
+ if (byCore !== 0 || aPre === bPre)
124
+ return byCore;
125
+ if (!aPre)
126
+ return 1;
127
+ if (!bPre)
128
+ return -1;
129
+ return aPre.localeCompare(bPre, void 0, { numeric: true });
130
+ }
70
131
  function wsUrlToHttpBase(wsUrl) {
71
132
  return wsUrl.replace(/^ws(s?):\/\//, (_, s) => `http${s}://`);
72
133
  }
@@ -289,6 +350,7 @@ var READ_METHODS = /* @__PURE__ */ new Set([
289
350
  "hosting.info",
290
351
  "hosting.wallet",
291
352
  "hosting.walletHistory",
353
+ "identity.custodyStatus",
292
354
  "identity.devices",
293
355
  "identity.joinStatus",
294
356
  "identity.log",
@@ -323,6 +385,7 @@ var READ_METHODS = /* @__PURE__ */ new Set([
323
385
  "perspective.subjectClassesOf",
324
386
  "perspective.verifyFlowReceipt",
325
387
  "runtime.computeLog",
388
+ "runtime.config",
326
389
  "runtime.freeHostingEnabled",
327
390
  "runtime.friendStatus",
328
391
  "runtime.friends",
@@ -331,6 +394,7 @@ var READ_METHODS = /* @__PURE__ */ new Set([
331
394
  "runtime.inbox",
332
395
  "runtime.info",
333
396
  "runtime.linkLanguageTemplates",
397
+ "runtime.logTail",
334
398
  "runtime.networkMetrics",
335
399
  "runtime.notifications",
336
400
  "runtime.outbox",
@@ -378,11 +442,12 @@ var OPENS_METHODS = /* @__PURE__ */ new Set([
378
442
  "perspective.subscribeQuery"
379
443
  ]);
380
444
  var RpcError = class extends Error {
381
- constructor(status, body) {
445
+ constructor(status, body, data) {
382
446
  super(`RPC error ${status}: ${body}`);
383
447
  this.name = "RpcError";
384
448
  this.status = status;
385
449
  this.body = body;
450
+ this.data = data;
386
451
  }
387
452
  };
388
453
  var DEFAULT_TIMEOUT_MS = 3e4;
@@ -511,7 +576,7 @@ var ApiClient = class {
511
576
  pending.resolve(parsed.result);
512
577
  return;
513
578
  }
514
- const rpcError = new RpcError(error.code ?? 500, error.message ?? "Unknown error");
579
+ const rpcError = new RpcError(error.code ?? 500, error.message ?? "Unknown error", error.data);
515
580
  pending.reject(rpcError);
516
581
  if (rpcError.status === 401)
517
582
  this._failAuth(rpcError.body);
@@ -2473,6 +2538,8 @@ function parseCallMessage(payload) {
2473
2538
  }
2474
2539
  if (msg.kind === "reset")
2475
2540
  return { ...envelope, kind: "reset" };
2541
+ if (msg.kind === "beat")
2542
+ return { ...envelope, kind: "beat" };
2476
2543
  if (msg.kind === "data") {
2477
2544
  const { label, data, binary } = msg;
2478
2545
  if (typeof label !== "string" || typeof data !== "string")
@@ -2689,6 +2756,10 @@ var MeshManager = class {
2689
2756
  const to = payload.to;
2690
2757
  if (typeof to === "string" && to !== TARGET_ALL && to !== this.selfId)
2691
2758
  return;
2759
+ if (message.kind === "beat") {
2760
+ this.emit("beat", from);
2761
+ return;
2762
+ }
2692
2763
  const slot = this.slots.get(from);
2693
2764
  if (message.kind === "data") {
2694
2765
  if (slot)
@@ -2814,6 +2885,11 @@ var MeshManager = class {
2814
2885
  sendData(label, data, binary = false) {
2815
2886
  this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, to: TARGET_ALL, kind: "data", label, data, binary });
2816
2887
  }
2888
+ beat() {
2889
+ if (this.closed)
2890
+ return;
2891
+ this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, to: TARGET_ALL, kind: "beat" });
2892
+ }
2817
2893
  subscribeDataChannel(callback) {
2818
2894
  this.dataListeners.add(callback);
2819
2895
  return () => this.dataListeners.delete(callback);
@@ -3240,15 +3316,34 @@ var MeshManager = class {
3240
3316
  }
3241
3317
  };
3242
3318
  var CALL_PRESENCE_PREDICATE = "ad4m://session/in-call";
3319
+ var CALL_BEATS_PREDICATE = "ad4m://session/in-call-beat";
3320
+ var BEAT_INTERVAL_MS = 2e4;
3321
+ var PRESENCE_STALE_MS = 9e4;
3243
3322
  var ROSTER_POLL_INTERVAL_MS = 3e3;
3244
- function presencePeer(did, link, roomId) {
3245
- if (link?.predicate !== CALL_PRESENCE_PREDICATE || link.target !== roomId)
3246
- return null;
3247
- const source = link.source;
3323
+ function peerOf(did, source) {
3248
3324
  if (typeof source !== "string" || source === did || agentOfMeshPeer(source) !== did)
3249
3325
  return null;
3250
3326
  return source;
3251
3327
  }
3328
+ function callPeer(did, link, roomId, predicate) {
3329
+ if (link?.predicate !== predicate || link.target !== roomId)
3330
+ return null;
3331
+ return peerOf(did, link.source);
3332
+ }
3333
+ function roomPeers(did, links, roomId) {
3334
+ const peers = /* @__PURE__ */ new Map();
3335
+ for (const link of links) {
3336
+ const peer = callPeer(did, link, roomId, CALL_PRESENCE_PREDICATE);
3337
+ if (peer)
3338
+ peers.set(peer, false);
3339
+ }
3340
+ for (const link of links) {
3341
+ const peer = callPeer(did, link, roomId, CALL_BEATS_PREDICATE);
3342
+ if (peer && peers.has(peer))
3343
+ peers.set(peer, true);
3344
+ }
3345
+ return peers;
3346
+ }
3252
3347
  function sameDeviceChannel(agentDid, device, roomId) {
3253
3348
  const Channel = globalThis.BroadcastChannel;
3254
3349
  if (typeof Channel !== "function")
@@ -3306,19 +3401,38 @@ function createSession(config) {
3306
3401
  }
3307
3402
  let statusBeforeCall = [];
3308
3403
  let announced = false;
3309
- async function ownLinksWithoutCall() {
3310
- const status = ownOnlineStatus ? await ownOnlineStatus() : null;
3404
+ let beatInterval = null;
3405
+ const heardAt = /* @__PURE__ */ new Map();
3406
+ let repairing = null;
3407
+ let repairedAt = -Infinity;
3408
+ function isStale(peer, now, states) {
3409
+ if (!heardAt.has(peer) || states.get(peer) === "connected")
3410
+ heardAt.set(peer, now);
3411
+ return now - heardAt.get(peer) >= PRESENCE_STALE_MS;
3412
+ }
3413
+ function linksWithout(status, drop) {
3414
+ const all = (status?.data?.links ?? []).map((link) => link.data);
3415
+ const peers = roomPeers(agentDid, all, roomId);
3311
3416
  const links = [];
3312
- for (const link of status?.data?.links ?? []) {
3313
- const l = link.data;
3417
+ for (const l of all) {
3314
3418
  if (!l?.source || l.target === void 0)
3315
3419
  continue;
3316
- if (presencePeer(agentDid, l, roomId) === selfPeer)
3420
+ const peer = callPeer(agentDid, l, roomId, CALL_PRESENCE_PREDICATE) ?? callPeer(agentDid, l, roomId, CALL_BEATS_PREDICATE);
3421
+ if (peer && (drop.has(peer) || !peers.has(peer)))
3317
3422
  continue;
3318
3423
  links.push({ source: l.source, target: l.target, ...l.predicate ? { predicate: l.predicate } : {} });
3319
3424
  }
3320
3425
  return links;
3321
3426
  }
3427
+ async function ownLinksWithoutCall() {
3428
+ return linksWithout(ownOnlineStatus ? await ownOnlineStatus() : null, /* @__PURE__ */ new Set([selfPeer]));
3429
+ }
3430
+ function callLinks() {
3431
+ return [
3432
+ { source: selfPeer, predicate: CALL_PRESENCE_PREDICATE, target: roomId },
3433
+ { source: selfPeer, predicate: CALL_BEATS_PREDICATE, target: roomId }
3434
+ ];
3435
+ }
3322
3436
  async function announceCallPresence() {
3323
3437
  if (!setOnlineStatus)
3324
3438
  return;
@@ -3327,17 +3441,35 @@ function createSession(config) {
3327
3441
  console.warn("session: reading own status failed:", err2);
3328
3442
  return [];
3329
3443
  });
3330
- const presence = { source: selfPeer, predicate: CALL_PRESENCE_PREDICATE, target: roomId };
3331
- await setOnlineStatus({ links: [...statusBeforeCall, presence] });
3444
+ await setOnlineStatus({ links: [...statusBeforeCall, ...callLinks()] });
3332
3445
  announced = true;
3333
3446
  } catch (err2) {
3334
3447
  console.warn("session: call-presence announcement failed:", err2);
3335
3448
  }
3336
3449
  }
3450
+ function repairOwnStatus(own, stale) {
3451
+ const links = own?.data?.links;
3452
+ if (!setOnlineStatus || !announced || repairing || !links)
3453
+ return;
3454
+ const listed = roomPeers(agentDid, links.map((l) => l.data), roomId).get(selfPeer) === true;
3455
+ if (stale.size === 0 && listed)
3456
+ return;
3457
+ const now = Date.now();
3458
+ if (now - repairedAt < PRESENCE_STALE_MS)
3459
+ return;
3460
+ repairedAt = now;
3461
+ const write = setOnlineStatus({ links: [...linksWithout(own, /* @__PURE__ */ new Set([...stale, selfPeer])), ...callLinks()] }).catch((err2) => console.warn("session: repairing call presence failed:", err2)).finally(() => {
3462
+ if (repairing === write)
3463
+ repairing = null;
3464
+ });
3465
+ repairing = write;
3466
+ }
3337
3467
  async function withdrawCallPresence() {
3338
3468
  if (!setOnlineStatus || !announced)
3339
3469
  return;
3340
3470
  announced = false;
3471
+ if (repairing)
3472
+ await repairing;
3341
3473
  try {
3342
3474
  const links = await ownLinksWithoutCall().catch((err2) => {
3343
3475
  console.warn("session: reading own status failed:", err2);
@@ -3358,12 +3490,24 @@ function createSession(config) {
3358
3490
  const own = ownOnlineStatus ? await ownOnlineStatus() : null;
3359
3491
  if (meshManager !== mesh)
3360
3492
  return;
3493
+ const now = Date.now();
3494
+ const states = mesh.peerStates();
3361
3495
  const inCall = /* @__PURE__ */ new Set();
3496
+ const seen = /* @__PURE__ */ new Set();
3497
+ const staleOwn = /* @__PURE__ */ new Set();
3362
3498
  const collect = (did, links) => {
3363
- for (const link of links ?? []) {
3364
- const peer = presencePeer(did, link.data, roomId);
3365
- if (peer && peer !== selfPeer)
3499
+ for (const [peer, beats] of roomPeers(did, (links ?? []).map((l) => l.data), roomId)) {
3500
+ if (peer === selfPeer)
3501
+ continue;
3502
+ if (!beats) {
3503
+ inCall.add(peer);
3504
+ continue;
3505
+ }
3506
+ seen.add(peer);
3507
+ if (!isStale(peer, now, states))
3366
3508
  inCall.add(peer);
3509
+ else if (did === agentDid)
3510
+ staleOwn.add(peer);
3367
3511
  }
3368
3512
  };
3369
3513
  for (const agent of agents) {
@@ -3371,14 +3515,26 @@ function createSession(config) {
3371
3515
  collect(agent.did, agent.status?.data?.links);
3372
3516
  }
3373
3517
  collect(agentDid, own?.data?.links);
3518
+ for (const peer of [...heardAt.keys()])
3519
+ if (!seen.has(peer))
3520
+ heardAt.delete(peer);
3374
3521
  mesh.setRoster([...inCall]);
3522
+ repairOwnStatus(own, staleOwn);
3375
3523
  } catch (err2) {
3376
3524
  console.warn("session: roster poll failed:", err2);
3377
3525
  } finally {
3378
3526
  polling = false;
3379
3527
  }
3380
3528
  }
3381
- function startRosterPolling() {
3529
+ function startRosterPolling(mesh) {
3530
+ heardAt.clear();
3531
+ repairedAt = -Infinity;
3532
+ mesh.on("beat", (peer) => {
3533
+ if (meshManager === mesh && heardAt.has(peer))
3534
+ heardAt.set(peer, Date.now());
3535
+ });
3536
+ mesh.beat();
3537
+ beatInterval = setInterval(() => mesh.beat(), BEAT_INTERVAL_MS);
3382
3538
  void pollRoster();
3383
3539
  rosterInterval = setInterval(() => void pollRoster(), ROSTER_POLL_INTERVAL_MS);
3384
3540
  }
@@ -3387,6 +3543,10 @@ function createSession(config) {
3387
3543
  clearInterval(rosterInterval);
3388
3544
  rosterInterval = null;
3389
3545
  }
3546
+ if (beatInterval !== null) {
3547
+ clearInterval(beatInterval);
3548
+ beatInterval = null;
3549
+ }
3390
3550
  }
3391
3551
  function wireMeshEvents(mesh) {
3392
3552
  for (const event of ["peer-state", "peer-recovery", "error"]) {
@@ -3528,7 +3688,7 @@ function createSession(config) {
3528
3688
  await withdrawCallPresence();
3529
3689
  throw new Error("Session destroyed");
3530
3690
  }
3531
- startRosterPolling();
3691
+ startRosterPolling(mesh);
3532
3692
  emit("topology-changed", "mesh");
3533
3693
  setState("active");
3534
3694
  return;
@@ -4296,7 +4456,10 @@ var SHACLShape = class {
4296
4456
  return pred(t);
4297
4457
  return `<${t}>`;
4298
4458
  };
4299
- const statements = (source) => links.filter((l) => l.source === source && l.predicate !== "sh://property").flatMap((l) => l.predicate === "sh://in" ? [`sh:in ( ${JSON.parse(l.target.slice(15)).map((v) => str(v.value)).join(" ")} )`, `ad4m:in ${obj(l)}`] : [`${pred(l.predicate)} ${obj(l)}`]);
4459
+ const statements = (source) => links.filter((l) => l.source === source && l.predicate !== "sh://property").flatMap((l) => l.predicate === "sh://in" ? [`sh:in ( ${JSON.parse(l.target.slice(15)).map((v) => {
4460
+ const value = v !== null && typeof v === "object" && "value" in v ? v.value : v;
4461
+ return typeof value === "string" ? str(value) : JSON.stringify(value);
4462
+ }).join(" ")} )`, `ad4m:in ${obj(l)}`] : [`${pred(l.predicate)} ${obj(l)}`]);
4300
4463
  const properties = links.filter((l) => l.source === this.nodeShapeUri && l.predicate === "sh://property").map((l, i) => {
4301
4464
  const lines = statements(l.target);
4302
4465
  const name = this.properties[i].name;
@@ -4512,7 +4675,7 @@ var SHACLShape = class {
4512
4675
  target: prop.class
4513
4676
  });
4514
4677
  }
4515
- if (prop.in && prop.in.length > 0) {
4678
+ if (prop.in !== void 0) {
4516
4679
  links.push({
4517
4680
  source: propShapeId,
4518
4681
  predicate: "sh://in",
@@ -4858,7 +5021,7 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
4858
5021
  if (propMeta.flag && propMeta.initial) {
4859
5022
  propShape.hasValue = propMeta.initial;
4860
5023
  }
4861
- if (propMeta.options && propMeta.options.length > 0) {
5024
+ if (propMeta.options !== void 0) {
4862
5025
  propShape.in = propMeta.options;
4863
5026
  }
4864
5027
  if (propMeta.local !== void 0) {
@@ -6405,6 +6568,9 @@ var PerspectiveProxy = class {
6405
6568
  invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6406
6569
  return result;
6407
6570
  }
6571
+ async discardBatch(batchId) {
6572
+ return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").discardBatch(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, batchId);
6573
+ }
6408
6574
  async getExpression(expressionURI) {
6409
6575
  return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").getExpression(expressionURI);
6410
6576
  }
@@ -6692,6 +6858,35 @@ var PerspectiveProxy = class {
6692
6858
  await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").updateSubject(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, className, exprAddr, JSON.stringify(values), batchId);
6693
6859
  invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6694
6860
  }
6861
+ async instanceCreate(body) {
6862
+ const created = await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceCreate(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
6863
+ invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6864
+ return created;
6865
+ }
6866
+ async instanceUpdate(body) {
6867
+ const updated = await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceUpdate(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
6868
+ invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6869
+ return updated;
6870
+ }
6871
+ async instanceRemove(body) {
6872
+ try {
6873
+ return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceRemove(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
6874
+ } finally {
6875
+ invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6876
+ }
6877
+ }
6878
+ async instanceAddToCollection(body) {
6879
+ const added = await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceAddToCollection(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
6880
+ invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6881
+ return added;
6882
+ }
6883
+ async instanceRemoveFromCollection(body) {
6884
+ try {
6885
+ return await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").instanceRemoveFromCollection(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, body);
6886
+ } finally {
6887
+ invalidatePerspectiveCache(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid);
6888
+ }
6889
+ }
6695
6890
  async getSubjectData(subjectClass, exprAddr) {
6696
6891
  if (typeof subjectClass === "string") {
6697
6892
  return JSON.parse(await __classPrivateFieldGet$7(this, _PerspectiveProxy_client, "f").getSubjectData(__classPrivateFieldGet$7(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify({ className: subjectClass }), exprAddr));
@@ -7039,7 +7234,7 @@ var PerspectiveProxy = class {
7039
7234
  required: minCount > 0,
7040
7235
  collection: isCollection2,
7041
7236
  writable,
7042
- ...options && options.length > 0 ? { options } : {}
7237
+ ...options !== void 0 ? { options } : {}
7043
7238
  };
7044
7239
  });
7045
7240
  return { className: safeName, shapeUri, properties };
@@ -7074,7 +7269,7 @@ var PerspectiveProxy = class {
7074
7269
  return {};
7075
7270
  const result = {};
7076
7271
  for (const prop of shape.properties) {
7077
- if (prop.options && prop.options.length > 0) {
7272
+ if (prop.options !== void 0) {
7078
7273
  result[prop.name] = prop.options;
7079
7274
  }
7080
7275
  }
@@ -7389,6 +7584,21 @@ var PerspectiveClient = class {
7389
7584
  async removeSubject(uuid, subjectClass, expressionAddress, batchId) {
7390
7585
  return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.removeSubject", { uuid, subjectClass, expressionAddress, batchId });
7391
7586
  }
7587
+ async instanceCreate(uuid, body) {
7588
+ return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.instanceCreate", { uuid, ...body });
7589
+ }
7590
+ async instanceUpdate(uuid, body) {
7591
+ return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.instanceUpdate", { uuid, ...body });
7592
+ }
7593
+ async instanceRemove(uuid, body) {
7594
+ return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.instanceRemove", { uuid, ...body });
7595
+ }
7596
+ async instanceAddToCollection(uuid, body) {
7597
+ return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.instanceAddToCollection", { uuid, ...body });
7598
+ }
7599
+ async instanceRemoveFromCollection(uuid, body) {
7600
+ return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.instanceRemoveFromCollection", { uuid, ...body });
7601
+ }
7392
7602
  async getSubjectData(uuid, subjectClass, expressionAddress) {
7393
7603
  return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.getSubjectData", { uuid, subjectClass, expressionAddress });
7394
7604
  }
@@ -7424,6 +7634,9 @@ var PerspectiveClient = class {
7424
7634
  const diff = await __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.commitBatch", { uuid, batchId });
7425
7635
  return LinkExpressionMutations.fromWire(diff);
7426
7636
  }
7637
+ async discardBatch(uuid, batchId) {
7638
+ return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").call("perspective.discardBatch", { uuid, batchId });
7639
+ }
7427
7640
  onReconnect(callback) {
7428
7641
  return __classPrivateFieldGet$6(this, _PerspectiveClient_apiClient, "f").onReconnect(callback);
7429
7642
  }
@@ -7468,6 +7681,18 @@ var RuntimeClient = class {
7468
7681
  async quit() {
7469
7682
  return __classPrivateFieldGet$5(this, _RuntimeClient_apiClient, "f").call("runtime.quit", {});
7470
7683
  }
7684
+ async restart() {
7685
+ return __classPrivateFieldGet$5(this, _RuntimeClient_apiClient, "f").call("runtime.restart", {});
7686
+ }
7687
+ async logTail(lines) {
7688
+ return __classPrivateFieldGet$5(this, _RuntimeClient_apiClient, "f").call("runtime.logTail", { lines });
7689
+ }
7690
+ async config() {
7691
+ return __classPrivateFieldGet$5(this, _RuntimeClient_apiClient, "f").call("runtime.config", {});
7692
+ }
7693
+ async setConfig(set, unset) {
7694
+ return __classPrivateFieldGet$5(this, _RuntimeClient_apiClient, "f").call("runtime.setConfig", { set, unset });
7695
+ }
7471
7696
  async openLink(url) {
7472
7697
  return __classPrivateFieldGet$5(this, _RuntimeClient_apiClient, "f").call("runtime.openLink", { url });
7473
7698
  }
@@ -12245,6 +12470,12 @@ var IdentityClient = class {
12245
12470
  async devices() {
12246
12471
  return __classPrivateFieldGet$2(this, _IdentityClient_apiClient, "f").call("identity.devices", {});
12247
12472
  }
12473
+ async rekey() {
12474
+ return __classPrivateFieldGet$2(this, _IdentityClient_apiClient, "f").call("identity.rekey", {});
12475
+ }
12476
+ async custodyStatus() {
12477
+ return __classPrivateFieldGet$2(this, _IdentityClient_apiClient, "f").call("identity.custodyStatus", {});
12478
+ }
12248
12479
  };
12249
12480
  _IdentityClient_apiClient = /* @__PURE__ */ new WeakMap();
12250
12481
  function isContainmentTraversal(scope) {
@@ -14851,6 +15082,7 @@ var Ad4mConnect = class extends EventTarget {
14851
15082
  this.creditPollInterval = null;
14852
15083
  autoBind(this);
14853
15084
  this.options = options;
15085
+ adoptStoredSession(options.url || void 0);
14854
15086
  this.port = options.port || parseInt(getLocal("ad4m-port")) || DEFAULT_PORT;
14855
15087
  this.url = options.url || getLocal("ad4m-url") || `http://localhost:${this.port}`;
14856
15088
  this.token = getLocal("ad4m-token") || "";
@@ -14924,6 +15156,16 @@ var Ad4mConnect = class extends EventTarget {
14924
15156
  }
14925
15157
  });
14926
15158
  }
15159
+ return this.connectStandalone();
15160
+ });
15161
+ }
15162
+ connectStandalone(retry) {
15163
+ return __async(this, null, function* () {
15164
+ var _a, _b;
15165
+ const wanted = () => {
15166
+ var _a2;
15167
+ return (_a2 = retry == null ? void 0 : retry.wanted()) != null ? _a2 : true;
15168
+ };
14927
15169
  const open = () => {
14928
15170
  const client = new Ad4mClient(this.baseUrl, this.token);
14929
15171
  const auth2 = this.readAuth(client).catch((error) => ({ state: "unauthenticated", error }));
@@ -14934,19 +15176,61 @@ var Ad4mConnect = class extends EventTarget {
14934
15176
  yield checkConnection(this.baseUrl);
14935
15177
  } catch (error) {
14936
15178
  session == null ? void 0 : session.client.close();
15179
+ if (!wanted())
15180
+ return void 0;
14937
15181
  console.error("[Ad4m Connect] Connection failed:", error);
14938
15182
  this.notifyConnectionChange("error");
14939
15183
  throw error;
14940
15184
  }
15185
+ if (!wanted()) {
15186
+ session == null ? void 0 : session.client.close();
15187
+ return void 0;
15188
+ }
14941
15189
  if (!session)
14942
15190
  session = open();
14943
15191
  const auth = yield session.auth;
15192
+ if (!wanted()) {
15193
+ session.client.close();
15194
+ return void 0;
15195
+ }
15196
+ const status = ((_a = auth.error) == null ? void 0 : _a.name) === "RpcError" ? auth.error.status : void 0;
15197
+ const refused = status >= 400 && status < 500 && status !== 408;
15198
+ if (retry && auth.state === "unauthenticated" && !refused) {
15199
+ session.client.close();
15200
+ throw (_b = auth.error) != null ? _b : new Error("the executor has not answered about the session yet");
15201
+ }
14944
15202
  setLocal("ad4m-url", this.url);
14945
15203
  this.adoptClient(session.client);
14946
15204
  this.applyAuth(auth);
14947
15205
  return this.ad4mClient;
14948
15206
  });
14949
15207
  }
15208
+ connectWhenReachable() {
15209
+ return __async(this, arguments, function* ({ signal, initialDelayMs = 2e3, maxDelayMs = 3e4 } = {}) {
15210
+ if (this.embedded)
15211
+ return void 0;
15212
+ const url = this.url;
15213
+ const token = this.token;
15214
+ const wanted = () => !(signal == null ? void 0 : signal.aborted) && !!token && this.token === token && this.url === url;
15215
+ for (let delay = initialDelayMs; ; delay = Math.min(delay * 2, maxDelayMs)) {
15216
+ yield new Promise((resolve) => {
15217
+ const done = () => {
15218
+ clearTimeout(timer);
15219
+ signal == null ? void 0 : signal.removeEventListener("abort", done);
15220
+ resolve();
15221
+ };
15222
+ const timer = setTimeout(done, delay);
15223
+ signal == null ? void 0 : signal.addEventListener("abort", done, { once: true });
15224
+ });
15225
+ if (!wanted())
15226
+ return void 0;
15227
+ try {
15228
+ return yield this.connectStandalone({ wanted });
15229
+ } catch (e) {
15230
+ }
15231
+ }
15232
+ });
15233
+ }
14950
15234
  adoptClient(client) {
14951
15235
  this.notifyConnectionChange("connecting");
14952
15236
  if (this.ad4mClient && this.ad4mClient !== client && typeof this.ad4mClient.close === "function") {