@dxos/client-services 0.3.11-main.c8e9429 → 0.3.11-main.cb5abf5

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.
Files changed (53) hide show
  1. package/dist/lib/browser/{chunk-OZ4IMR73.mjs → chunk-ESWBGQCJ.mjs} +198 -91
  2. package/dist/lib/browser/chunk-ESWBGQCJ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +4 -11
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-46ZYQFO5.cjs → chunk-Q7FPBLIU.cjs} +341 -234
  8. package/dist/lib/node/chunk-Q7FPBLIU.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +37 -37
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +11 -18
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -0
  14. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +28 -3
  16. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -0
  19. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/diagnostics.d.ts +32 -16
  22. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  23. package/dist/types/src/packlets/services/platform.d.ts +1 -14
  24. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  25. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  26. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space.d.ts +2 -0
  29. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  30. package/dist/types/src/packlets/system/system-service.d.ts +3 -2
  31. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  32. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  33. package/dist/types/src/version.d.ts +1 -1
  34. package/package.json +35 -35
  35. package/src/packlets/identity/identity-manager.ts +1 -1
  36. package/src/packlets/invitations/device-invitation-protocol.test.ts +14 -0
  37. package/src/packlets/invitations/device-invitation-protocol.ts +14 -0
  38. package/src/packlets/invitations/invitation-protocol.ts +44 -6
  39. package/src/packlets/invitations/invitations-handler.ts +19 -17
  40. package/src/packlets/invitations/space-invitation-protocol.test.ts +28 -0
  41. package/src/packlets/invitations/space-invitation-protocol.ts +11 -0
  42. package/src/packlets/network/network-service.ts +5 -1
  43. package/src/packlets/services/diagnostics.ts +52 -16
  44. package/src/packlets/services/platform.ts +7 -19
  45. package/src/packlets/spaces/automerge-space-state.ts +4 -0
  46. package/src/packlets/spaces/data-space-manager.ts +5 -1
  47. package/src/packlets/spaces/data-space.ts +37 -4
  48. package/src/packlets/spaces/spaces-service.ts +3 -3
  49. package/src/packlets/system/system-service.ts +7 -1
  50. package/src/packlets/testing/invitation-utils.ts +2 -10
  51. package/src/version.ts +1 -1
  52. package/dist/lib/browser/chunk-OZ4IMR73.mjs.map +0 -7
  53. package/dist/lib/node/chunk-46ZYQFO5.cjs.map +0 -7
@@ -996,7 +996,7 @@ var IdentityManager = class {
996
996
  genesisFeedKey: spaceRecord.genesisFeedKey
997
997
  },
998
998
  swarmIdentity,
999
- onNetworkConnection: () => {
999
+ onAuthorizedConnection: () => {
1000
1000
  },
1001
1001
  onAuthFailure: () => {
1002
1002
  log3.warn("auth failure", void 0, {
@@ -1095,6 +1095,7 @@ var IdentityServiceImpl = class {
1095
1095
 
1096
1096
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
1097
1097
  import { invariant as invariant4 } from "@dxos/invariant";
1098
+ import { AlreadyJoinedError } from "@dxos/protocols";
1098
1099
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
1099
1100
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
1100
1101
  var DeviceInvitationProtocol = class {
@@ -1114,7 +1115,7 @@ var DeviceInvitationProtocol = class {
1114
1115
  async admit(request) {
1115
1116
  invariant4(request.device, void 0, {
1116
1117
  F: __dxlog_file5,
1117
- L: 35,
1118
+ L: 36,
1118
1119
  S: this,
1119
1120
  A: [
1120
1121
  "request.device",
@@ -1132,6 +1133,15 @@ var DeviceInvitationProtocol = class {
1132
1133
  }
1133
1134
  };
1134
1135
  }
1136
+ checkInvitation(invitation) {
1137
+ try {
1138
+ const identity = this._getIdentity();
1139
+ if (identity) {
1140
+ return new AlreadyJoinedError("Currently only one identity per client is supported.");
1141
+ }
1142
+ } catch {
1143
+ }
1144
+ }
1135
1145
  createIntroduction() {
1136
1146
  return {};
1137
1147
  }
@@ -1150,7 +1160,7 @@ var DeviceInvitationProtocol = class {
1150
1160
  async accept(response, request) {
1151
1161
  invariant4(response.device, void 0, {
1152
1162
  F: __dxlog_file5,
1153
- L: 68,
1163
+ L: 80,
1154
1164
  S: this,
1155
1165
  A: [
1156
1166
  "response.device",
@@ -1160,7 +1170,7 @@ var DeviceInvitationProtocol = class {
1160
1170
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1161
1171
  invariant4(request.device, void 0, {
1162
1172
  F: __dxlog_file5,
1163
- L: 71,
1173
+ L: 83,
1164
1174
  S: this,
1165
1175
  A: [
1166
1176
  "request.device",
@@ -1942,16 +1952,12 @@ var InvitationsHandler = class {
1942
1952
  }
1943
1953
  }
1944
1954
  }
1945
- } else {
1946
- setState({
1947
- state: Invitation3.State.READY_FOR_AUTHENTICATION
1948
- });
1949
1955
  }
1950
1956
  log5("request admission", {
1951
1957
  ...protocol.toJSON()
1952
1958
  }, {
1953
1959
  F: __dxlog_file7,
1954
- L: 312,
1960
+ L: 309,
1955
1961
  S: this,
1956
1962
  C: (f, a) => f(...a)
1957
1963
  });
@@ -1963,7 +1969,7 @@ var InvitationsHandler = class {
1963
1969
  ...protocol.toJSON()
1964
1970
  }, {
1965
1971
  F: __dxlog_file7,
1966
- L: 323,
1972
+ L: 320,
1967
1973
  S: this,
1968
1974
  C: (f, a) => f(...a)
1969
1975
  });
@@ -1976,7 +1982,7 @@ var InvitationsHandler = class {
1976
1982
  id: traceId
1977
1983
  }), {
1978
1984
  F: __dxlog_file7,
1979
- L: 325,
1985
+ L: 322,
1980
1986
  S: this,
1981
1987
  C: (f, a) => f(...a)
1982
1988
  });
@@ -1986,7 +1992,7 @@ var InvitationsHandler = class {
1986
1992
  ...protocol.toJSON()
1987
1993
  }, {
1988
1994
  F: __dxlog_file7,
1989
- L: 328,
1995
+ L: 325,
1990
1996
  S: this,
1991
1997
  C: (f, a) => f(...a)
1992
1998
  });
@@ -1996,7 +2002,7 @@ var InvitationsHandler = class {
1996
2002
  } else {
1997
2003
  log5("auth failed", err, {
1998
2004
  F: __dxlog_file7,
1999
- L: 331,
2005
+ L: 328,
2000
2006
  S: this,
2001
2007
  C: (f, a) => f(...a)
2002
2008
  });
@@ -2007,7 +2013,7 @@ var InvitationsHandler = class {
2007
2013
  error: err
2008
2014
  }), {
2009
2015
  F: __dxlog_file7,
2010
- L: 334,
2016
+ L: 331,
2011
2017
  S: this,
2012
2018
  C: (f, a) => f(...a)
2013
2019
  });
@@ -2025,7 +2031,7 @@ var InvitationsHandler = class {
2025
2031
  ...protocol.toJSON()
2026
2032
  }, {
2027
2033
  F: __dxlog_file7,
2028
- L: 345,
2034
+ L: 342,
2029
2035
  S: this,
2030
2036
  C: (f, a) => f(...a)
2031
2037
  });
@@ -2035,7 +2041,7 @@ var InvitationsHandler = class {
2035
2041
  } else {
2036
2042
  log5("auth failed", err, {
2037
2043
  F: __dxlog_file7,
2038
- L: 348,
2044
+ L: 345,
2039
2045
  S: this,
2040
2046
  C: (f, a) => f(...a)
2041
2047
  });
@@ -2046,29 +2052,34 @@ var InvitationsHandler = class {
2046
2052
  return extension;
2047
2053
  };
2048
2054
  scheduleTask2(ctx, async () => {
2049
- invariant6(invitation.swarmKey, void 0, {
2050
- F: __dxlog_file7,
2051
- L: 358,
2052
- S: this,
2053
- A: [
2054
- "invitation.swarmKey",
2055
- ""
2056
- ]
2057
- });
2058
- const topic = invitation.swarmKey;
2059
- const swarmConnection = await this._networkManager.joinSwarm({
2060
- topic,
2061
- peerId: PublicKey6.random(),
2062
- protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2063
- teleport.addExtension("dxos.halo.invitations", createExtension());
2064
- }),
2065
- topology: new StarTopology(topic),
2066
- label: "invitation guest"
2067
- });
2068
- ctx.onDispose(() => swarmConnection.close());
2069
- setState({
2070
- state: Invitation3.State.CONNECTING
2071
- });
2055
+ const error = protocol.checkInvitation(invitation);
2056
+ if (error) {
2057
+ stream.error(error);
2058
+ } else {
2059
+ invariant6(invitation.swarmKey, void 0, {
2060
+ F: __dxlog_file7,
2061
+ L: 359,
2062
+ S: this,
2063
+ A: [
2064
+ "invitation.swarmKey",
2065
+ ""
2066
+ ]
2067
+ });
2068
+ const topic = invitation.swarmKey;
2069
+ const swarmConnection = await this._networkManager.joinSwarm({
2070
+ topic,
2071
+ peerId: PublicKey6.random(),
2072
+ protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2073
+ teleport.addExtension("dxos.halo.invitations", createExtension());
2074
+ }),
2075
+ topology: new StarTopology(topic),
2076
+ label: "invitation guest"
2077
+ });
2078
+ ctx.onDispose(() => swarmConnection.close());
2079
+ setState({
2080
+ state: Invitation3.State.CONNECTING
2081
+ });
2082
+ }
2072
2083
  });
2073
2084
  const observable = new AuthenticatingInvitation({
2074
2085
  initialInvitation: invitation,
@@ -2274,6 +2285,7 @@ import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/creden
2274
2285
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2275
2286
  import { invariant as invariant8 } from "@dxos/invariant";
2276
2287
  import { log as log7 } from "@dxos/log";
2288
+ import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2277
2289
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2278
2290
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2279
2291
  var SpaceInvitationProtocol = class {
@@ -2298,7 +2310,7 @@ var SpaceInvitationProtocol = class {
2298
2310
  async admit(request, guestProfile) {
2299
2311
  invariant8(this._spaceKey, void 0, {
2300
2312
  F: __dxlog_file9,
2301
- L: 46,
2313
+ L: 47,
2302
2314
  S: this,
2303
2315
  A: [
2304
2316
  "this._spaceKey",
@@ -2308,7 +2320,7 @@ var SpaceInvitationProtocol = class {
2308
2320
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2309
2321
  invariant8(space, void 0, {
2310
2322
  F: __dxlog_file9,
2311
- L: 48,
2323
+ L: 49,
2312
2324
  S: this,
2313
2325
  A: [
2314
2326
  "space",
@@ -2317,7 +2329,7 @@ var SpaceInvitationProtocol = class {
2317
2329
  });
2318
2330
  invariant8(request.space, void 0, {
2319
2331
  F: __dxlog_file9,
2320
- L: 50,
2332
+ L: 51,
2321
2333
  S: this,
2322
2334
  A: [
2323
2335
  "request.space",
@@ -2330,14 +2342,14 @@ var SpaceInvitationProtocol = class {
2330
2342
  guest: deviceKey
2331
2343
  }, {
2332
2344
  F: __dxlog_file9,
2333
- L: 53,
2345
+ L: 54,
2334
2346
  S: this,
2335
2347
  C: (f, a) => f(...a)
2336
2348
  });
2337
2349
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2338
2350
  invariant8(credentials[0].credential, void 0, {
2339
2351
  F: __dxlog_file9,
2340
- L: 64,
2352
+ L: 65,
2341
2353
  S: this,
2342
2354
  A: [
2343
2355
  "credentials[0].credential",
@@ -2347,7 +2359,7 @@ var SpaceInvitationProtocol = class {
2347
2359
  const spaceMemberCredential = credentials[0].credential.credential;
2348
2360
  invariant8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2349
2361
  F: __dxlog_file9,
2350
- L: 66,
2362
+ L: 67,
2351
2363
  S: this,
2352
2364
  A: [
2353
2365
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2363,6 +2375,11 @@ var SpaceInvitationProtocol = class {
2363
2375
  }
2364
2376
  };
2365
2377
  }
2378
+ checkInvitation(invitation) {
2379
+ if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2380
+ return new AlreadyJoinedError2("Already joined space.");
2381
+ }
2382
+ }
2366
2383
  createIntroduction() {
2367
2384
  return {
2368
2385
  profile: this._signingContext.getProfile()
@@ -2383,7 +2400,7 @@ var SpaceInvitationProtocol = class {
2383
2400
  async accept(response) {
2384
2401
  invariant8(response.space, void 0, {
2385
2402
  F: __dxlog_file9,
2386
- L: 101,
2403
+ L: 108,
2387
2404
  S: this,
2388
2405
  A: [
2389
2406
  "response.space",
@@ -2394,7 +2411,7 @@ var SpaceInvitationProtocol = class {
2394
2411
  const assertion = getCredentialAssertion(credential);
2395
2412
  invariant8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2396
2413
  F: __dxlog_file9,
2397
- L: 104,
2414
+ L: 111,
2398
2415
  S: this,
2399
2416
  A: [
2400
2417
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2403,13 +2420,16 @@ var SpaceInvitationProtocol = class {
2403
2420
  });
2404
2421
  invariant8(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2405
2422
  F: __dxlog_file9,
2406
- L: 105,
2423
+ L: 112,
2407
2424
  S: this,
2408
2425
  A: [
2409
2426
  "credential.subject.id.equals(this._signingContext.identityKey)",
2410
2427
  ""
2411
2428
  ]
2412
2429
  });
2430
+ if (this._spaceManager.spaces.has(assertion.spaceKey)) {
2431
+ throw new AlreadyJoinedError2("Already joined space.");
2432
+ }
2413
2433
  await this._spaceManager.acceptSpace({
2414
2434
  spaceKey: assertion.spaceKey,
2415
2435
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2513,29 +2533,32 @@ import { invariant as invariant9 } from "@dxos/invariant";
2513
2533
  import { log as log8 } from "@dxos/log";
2514
2534
  import { STORAGE_VERSION } from "@dxos/protocols";
2515
2535
  import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2536
+ import { TRACE_PROCESSOR } from "@dxos/tracing";
2516
2537
 
2517
2538
  // packages/sdk/client-services/src/packlets/services/platform.ts
2539
+ import { Platform } from "@dxos/protocols/proto/dxos/client/services";
2518
2540
  var getPlatform = () => {
2519
2541
  if (process.browser) {
2520
2542
  if (typeof window !== "undefined") {
2521
2543
  const { userAgent } = window.navigator;
2522
2544
  return {
2523
- type: "browser",
2545
+ type: Platform.PLATFORM_TYPE.BROWSER,
2524
2546
  userAgent,
2525
2547
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
2526
2548
  };
2527
2549
  } else {
2528
2550
  return {
2529
- type: "shared-worker",
2551
+ type: Platform.PLATFORM_TYPE.SHARED_WORKER,
2530
2552
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
2531
2553
  };
2532
2554
  }
2533
2555
  } else {
2534
2556
  const { platform: platform2, version, arch } = process;
2535
2557
  return {
2536
- type: "node",
2537
- platform: `${platform2} ${version} ${arch}`,
2538
- runtime: process.version,
2558
+ type: Platform.PLATFORM_TYPE.NODE,
2559
+ platform: platform2,
2560
+ arch,
2561
+ runtime: version,
2539
2562
  uptime: Math.floor(process.uptime()),
2540
2563
  memory: process.memoryUsage()
2541
2564
  };
@@ -2543,7 +2566,7 @@ var getPlatform = () => {
2543
2566
  };
2544
2567
 
2545
2568
  // packages/sdk/client-services/src/version.ts
2546
- var DXOS_VERSION = "0.3.11-main.c8e9429";
2569
+ var DXOS_VERSION = "0.3.11-main.cb5abf5";
2547
2570
 
2548
2571
  // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2549
2572
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
@@ -2557,12 +2580,13 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2557
2580
  storage: {
2558
2581
  version: STORAGE_VERSION
2559
2582
  }
2560
- }
2583
+ },
2584
+ trace: TRACE_PROCESSOR.getDiagnostics()
2561
2585
  };
2562
2586
  {
2563
2587
  invariant9(clientServices.LoggingService, "SystemService is not available.", {
2564
2588
  F: __dxlog_file10,
2565
- L: 92,
2589
+ L: 111,
2566
2590
  S: void 0,
2567
2591
  A: [
2568
2592
  "clientServices.LoggingService",
@@ -2573,6 +2597,21 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2573
2597
  timeout: DEFAULT_TIMEOUT
2574
2598
  }).catch(() => void 0);
2575
2599
  }
2600
+ if (typeof navigator !== "undefined" && navigator.storage) {
2601
+ const map = /* @__PURE__ */ new Map();
2602
+ const dir = await navigator.storage.getDirectory();
2603
+ for await (const filename of dir?.keys()) {
2604
+ const idx = filename.indexOf("-", filename.indexOf("-") + 1);
2605
+ if (idx === -1) {
2606
+ continue;
2607
+ }
2608
+ map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
2609
+ }
2610
+ diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
2611
+ file,
2612
+ count
2613
+ }));
2614
+ }
2576
2615
  const identity = serviceContext.identityManager.identity;
2577
2616
  if (identity) {
2578
2617
  diagnostics.identity = {
@@ -2613,7 +2652,7 @@ var getProperties = (space) => {
2613
2652
  } catch (err) {
2614
2653
  log8.warn(err.message, void 0, {
2615
2654
  F: __dxlog_file10,
2616
- L: 160,
2655
+ L: 196,
2617
2656
  S: void 0,
2618
2657
  C: (f, a) => f(...a)
2619
2658
  });
@@ -2669,11 +2708,12 @@ var getSpaceStats = async (space) => {
2669
2708
  };
2670
2709
 
2671
2710
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2672
- import { Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2711
+ import { Event as Event5, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2673
2712
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2674
- import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
2713
+ import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
2675
2714
  import { timed } from "@dxos/debug";
2676
2715
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2716
+ import { failedInvariant } from "@dxos/invariant";
2677
2717
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2678
2718
  import { log as log10 } from "@dxos/log";
2679
2719
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2686,7 +2726,8 @@ import { ComplexSet as ComplexSet3 } from "@dxos/util";
2686
2726
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
2687
2727
  import { checkCredentialType } from "@dxos/credentials";
2688
2728
  var AutomergeSpaceState = class {
2689
- constructor() {
2729
+ constructor(_onNewRoot) {
2730
+ this._onNewRoot = _onNewRoot;
2690
2731
  this.rootUrl = void 0;
2691
2732
  this.lastEpoch = void 0;
2692
2733
  }
@@ -2697,6 +2738,7 @@ var AutomergeSpaceState = class {
2697
2738
  this.lastEpoch = credential;
2698
2739
  if (credential.subject.assertion.automergeRoot) {
2699
2740
  this.rootUrl = credential.subject.assertion.automergeRoot;
2741
+ this._onNewRoot(this.rootUrl);
2700
2742
  }
2701
2743
  }
2702
2744
  };
@@ -2988,7 +3030,7 @@ var DataSpace = class {
2988
3030
  this._notarizationPlugin = new NotarizationPlugin();
2989
3031
  this._cache = void 0;
2990
3032
  // TODO(dmaretskyi): Move into Space?
2991
- this._automergeSpaceState = new AutomergeSpaceState();
3033
+ this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
2992
3034
  this._state = SpaceState.CLOSED;
2993
3035
  /**
2994
3036
  * Error for _state === SpaceState.ERROR.
@@ -3017,7 +3059,7 @@ var DataSpace = class {
3017
3059
  state: SpaceState[this._state]
3018
3060
  }, {
3019
3061
  F: __dxlog_file12,
3020
- L: 137,
3062
+ L: 141,
3021
3063
  S: this,
3022
3064
  C: (f, a) => f(...a)
3023
3065
  });
@@ -3050,6 +3092,12 @@ var DataSpace = class {
3050
3092
  get automergeSpaceState() {
3051
3093
  return this._automergeSpaceState;
3052
3094
  }
3095
+ get _automergeInfo() {
3096
+ return {
3097
+ rootUrl: this._automergeSpaceState.rootUrl,
3098
+ lastEpoch: this._automergeSpaceState.lastEpoch
3099
+ };
3100
+ }
3053
3101
  async open() {
3054
3102
  await this._open();
3055
3103
  }
@@ -3064,7 +3112,7 @@ var DataSpace = class {
3064
3112
  state: SpaceState[this._state]
3065
3113
  }, {
3066
3114
  F: __dxlog_file12,
3067
- L: 189,
3115
+ L: 203,
3068
3116
  S: this,
3069
3117
  C: (f, a) => f(...a)
3070
3118
  });
@@ -3082,7 +3130,7 @@ var DataSpace = class {
3082
3130
  state: SpaceState[this._state]
3083
3131
  }, {
3084
3132
  F: __dxlog_file12,
3085
- L: 203,
3133
+ L: 217,
3086
3134
  S: this,
3087
3135
  C: (f, a) => f(...a)
3088
3136
  });
@@ -3111,10 +3159,10 @@ var DataSpace = class {
3111
3159
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3112
3160
  await this.initializeDataPipeline();
3113
3161
  } catch (err) {
3114
- if (err instanceof CancelledError) {
3162
+ if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3115
3163
  log10("data pipeline initialization cancelled", err, {
3116
3164
  F: __dxlog_file12,
3117
- L: 236,
3165
+ L: 250,
3118
3166
  S: this,
3119
3167
  C: (f, a) => f(...a)
3120
3168
  });
@@ -3122,7 +3170,7 @@ var DataSpace = class {
3122
3170
  }
3123
3171
  log10.error("Error initializing data pipeline", err, {
3124
3172
  F: __dxlog_file12,
3125
- L: 240,
3173
+ L: 254,
3126
3174
  S: this,
3127
3175
  C: (f, a) => f(...a)
3128
3176
  });
@@ -3131,7 +3179,7 @@ var DataSpace = class {
3131
3179
  state: SpaceState[this._state]
3132
3180
  }, {
3133
3181
  F: __dxlog_file12,
3134
- L: 242,
3182
+ L: 256,
3135
3183
  S: this,
3136
3184
  C: (f, a) => f(...a)
3137
3185
  });
@@ -3151,7 +3199,7 @@ var DataSpace = class {
3151
3199
  state: SpaceState[this._state]
3152
3200
  }, {
3153
3201
  F: __dxlog_file12,
3154
- L: 258,
3202
+ L: 272,
3155
3203
  S: this,
3156
3204
  C: (f, a) => f(...a)
3157
3205
  });
@@ -3162,7 +3210,7 @@ var DataSpace = class {
3162
3210
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3163
3211
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3164
3212
  F: __dxlog_file12,
3165
- L: 272,
3213
+ L: 286,
3166
3214
  S: this,
3167
3215
  C: (f, a) => f(...a)
3168
3216
  });
@@ -3173,7 +3221,7 @@ var DataSpace = class {
3173
3221
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3174
3222
  log10("data pipeline ready", void 0, {
3175
3223
  F: __dxlog_file12,
3176
- L: 281,
3224
+ L: 295,
3177
3225
  S: this,
3178
3226
  C: (f, a) => f(...a)
3179
3227
  });
@@ -3183,7 +3231,7 @@ var DataSpace = class {
3183
3231
  state: SpaceState[this._state]
3184
3232
  }, {
3185
3233
  F: __dxlog_file12,
3186
- L: 285,
3234
+ L: 299,
3187
3235
  S: this,
3188
3236
  C: (f, a) => f(...a)
3189
3237
  });
@@ -3199,7 +3247,7 @@ var DataSpace = class {
3199
3247
  await this._createWritableFeeds();
3200
3248
  log10("writable feeds created", void 0, {
3201
3249
  F: __dxlog_file12,
3202
- L: 301,
3250
+ L: 315,
3203
3251
  S: this,
3204
3252
  C: (f, a) => f(...a)
3205
3253
  });
@@ -3256,6 +3304,40 @@ var DataSpace = class {
3256
3304
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3257
3305
  }
3258
3306
  }
3307
+ _onNewAutomergeRoot(rootUrl) {
3308
+ log10("loading automerge root doc for space", {
3309
+ space: this.key,
3310
+ rootUrl
3311
+ }, {
3312
+ F: __dxlog_file12,
3313
+ L: 381,
3314
+ S: this,
3315
+ C: (f, a) => f(...a)
3316
+ });
3317
+ const handle = this._automergeHost.repo.find(rootUrl);
3318
+ queueMicrotask(async () => {
3319
+ try {
3320
+ await asyncTimeout(handle.whenReady(), 5e3);
3321
+ const doc = handle.docSync() ?? failedInvariant();
3322
+ if (!doc.experimental_spaceKey) {
3323
+ handle.change((doc2) => {
3324
+ doc2.experimental_spaceKey = this.key.toHex();
3325
+ });
3326
+ }
3327
+ } catch (err) {
3328
+ log10.warn("error loading automerge root doc", {
3329
+ space: this.key,
3330
+ rootUrl,
3331
+ err
3332
+ }, {
3333
+ F: __dxlog_file12,
3334
+ L: 394,
3335
+ S: this,
3336
+ C: (f, a) => f(...a)
3337
+ });
3338
+ }
3339
+ });
3340
+ }
3259
3341
  // TODO(dmaretskyi): Use profile from signing context.
3260
3342
  async updateOwnProfile(profile) {
3261
3343
  const credential = await this._signingContext.credentialSigner.createCredential({
@@ -3339,13 +3421,29 @@ var DataSpace = class {
3339
3421
  state: SpaceState[this._state]
3340
3422
  }, {
3341
3423
  F: __dxlog_file12,
3342
- L: 450,
3424
+ L: 483,
3343
3425
  S: this,
3344
3426
  C: (f, a) => f(...a)
3345
3427
  });
3346
3428
  this.stateUpdate.emit();
3347
3429
  }
3348
3430
  };
3431
+ _ts_decorate4([
3432
+ trace6.info()
3433
+ ], DataSpace.prototype, "_inner", void 0);
3434
+ _ts_decorate4([
3435
+ trace6.info()
3436
+ ], DataSpace.prototype, "key", null);
3437
+ _ts_decorate4([
3438
+ trace6.info({
3439
+ enum: SpaceState
3440
+ })
3441
+ ], DataSpace.prototype, "state", null);
3442
+ _ts_decorate4([
3443
+ trace6.info({
3444
+ depth: null
3445
+ })
3446
+ ], DataSpace.prototype, "_automergeInfo", null);
3349
3447
  _ts_decorate4([
3350
3448
  synchronized
3351
3449
  ], DataSpace.prototype, "open", null);
@@ -3372,7 +3470,8 @@ _ts_decorate4([
3372
3470
  synchronized
3373
3471
  ], DataSpace.prototype, "deactivate", null);
3374
3472
  DataSpace = _ts_decorate4([
3375
- trackLeaks("open", "close")
3473
+ trackLeaks("open", "close"),
3474
+ trace6.resource()
3376
3475
  ], DataSpace);
3377
3476
 
3378
3477
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
@@ -3598,12 +3697,15 @@ var DataSpaceManager = class {
3598
3697
  });
3599
3698
  const space = await this._constructSpace(metadata);
3600
3699
  const automergeRoot = this._automergeHost.repo.create();
3700
+ automergeRoot.change((doc) => {
3701
+ doc.experimental_spaceKey = spaceKey.toHex();
3702
+ });
3601
3703
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3602
3704
  await this._metadataStore.addSpace(metadata);
3603
3705
  const memberCredential = credentials[1];
3604
3706
  invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3605
3707
  F: __dxlog_file13,
3606
- L: 151,
3708
+ L: 154,
3607
3709
  S: this,
3608
3710
  A: [
3609
3711
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3621,13 +3723,13 @@ var DataSpaceManager = class {
3621
3723
  opts
3622
3724
  }, {
3623
3725
  F: __dxlog_file13,
3624
- L: 163,
3726
+ L: 166,
3625
3727
  S: this,
3626
3728
  C: (f, a) => f(...a)
3627
3729
  });
3628
3730
  invariant11(this._isOpen, "Not open.", {
3629
3731
  F: __dxlog_file13,
3630
- L: 164,
3732
+ L: 167,
3631
3733
  S: this,
3632
3734
  A: [
3633
3735
  "this._isOpen",
@@ -3636,7 +3738,7 @@ var DataSpaceManager = class {
3636
3738
  });
3637
3739
  invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3638
3740
  F: __dxlog_file13,
3639
- L: 165,
3741
+ L: 168,
3640
3742
  S: this,
3641
3743
  A: [
3642
3744
  "!this._spaces.has(opts.spaceKey)",
@@ -3671,7 +3773,7 @@ var DataSpaceManager = class {
3671
3773
  metadata
3672
3774
  }, {
3673
3775
  F: __dxlog_file13,
3674
- L: 198,
3776
+ L: 201,
3675
3777
  S: this,
3676
3778
  C: (f, a) => f(...a)
3677
3779
  });
@@ -3698,17 +3800,18 @@ var DataSpaceManager = class {
3698
3800
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
3699
3801
  credentialAuthenticator: deferFunction2(() => dataSpace.authVerifier.verifier)
3700
3802
  },
3701
- onNetworkConnection: (session) => {
3803
+ onAuthorizedConnection: (session) => {
3702
3804
  session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
3703
3805
  remotePeerId: session.remotePeerId
3704
3806
  }));
3705
3807
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
3808
+ this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
3706
3809
  session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
3707
3810
  },
3708
3811
  onAuthFailure: () => {
3709
3812
  log11.warn("auth failure", void 0, {
3710
3813
  F: __dxlog_file13,
3711
- L: 234,
3814
+ L: 238,
3712
3815
  S: this,
3713
3816
  C: (f, a) => f(...a)
3714
3817
  });
@@ -3732,7 +3835,7 @@ var DataSpaceManager = class {
3732
3835
  space: space.key
3733
3836
  }, {
3734
3837
  F: __dxlog_file13,
3735
- L: 252,
3838
+ L: 256,
3736
3839
  S: this,
3737
3840
  C: (f, a) => f(...a)
3738
3841
  });
@@ -3744,7 +3847,7 @@ var DataSpaceManager = class {
3744
3847
  open: this._isOpen
3745
3848
  }, {
3746
3849
  F: __dxlog_file13,
3747
- L: 259,
3850
+ L: 263,
3748
3851
  S: this,
3749
3852
  C: (f, a) => f(...a)
3750
3853
  });
@@ -3757,7 +3860,7 @@ var DataSpaceManager = class {
3757
3860
  space: space.key
3758
3861
  }, {
3759
3862
  F: __dxlog_file13,
3760
- L: 265,
3863
+ L: 269,
3761
3864
  S: this,
3762
3865
  C: (f, a) => f(...a)
3763
3866
  });
@@ -3814,7 +3917,7 @@ var SpacesServiceImpl = class {
3814
3917
  }
3815
3918
  async createSpace() {
3816
3919
  if (!this._identityManager.identity) {
3817
- throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
3920
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo");
3818
3921
  }
3819
3922
  const dataSpaceManager = await this._getDataSpaceManager();
3820
3923
  const space = await dataSpaceManager.createSpace();
@@ -4313,7 +4416,7 @@ var ServiceRegistry = class {
4313
4416
  };
4314
4417
 
4315
4418
  // packages/sdk/client-services/src/packlets/locks/browser.ts
4316
- import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
4419
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4317
4420
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4318
4421
  import { log as log14, logInfo } from "@dxos/log";
4319
4422
  function _ts_decorate7(decorators, target, key, desc) {
@@ -4354,7 +4457,7 @@ var Lock = class {
4354
4457
  S: this,
4355
4458
  C: (f, a) => f(...a)
4356
4459
  });
4357
- await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4460
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4358
4461
  log14("acquired lock", void 0, {
4359
4462
  F: __dxlog_file16,
4360
4463
  L: 44,
@@ -4501,7 +4604,7 @@ import { createSimplePeerTransportFactory, NetworkManager } from "@dxos/network-
4501
4604
  import { trace as trace9 } from "@dxos/protocols";
4502
4605
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4503
4606
  import { TextModel } from "@dxos/text-model";
4504
- import { TRACE_PROCESSOR, trace as Trace3 } from "@dxos/tracing";
4607
+ import { TRACE_PROCESSOR as TRACE_PROCESSOR2, trace as Trace3 } from "@dxos/tracing";
4505
4608
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
4506
4609
 
4507
4610
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
@@ -4677,6 +4780,7 @@ var NetworkServiceImpl = class {
4677
4780
  const update = () => {
4678
4781
  next({
4679
4782
  swarm: this.networkManager.connectionState,
4783
+ connectionInfo: this.networkManager.connectionLog?.swarms,
4680
4784
  signaling: this.signalManager.getStatus().map(({ host, state }) => ({
4681
4785
  server: host,
4682
4786
  state
@@ -4726,6 +4830,9 @@ var SystemServiceImpl = class {
4726
4830
  })))
4727
4831
  };
4728
4832
  }
4833
+ async getPlatform() {
4834
+ return getPlatform();
4835
+ }
4729
4836
  async updateStatus({ status }) {
4730
4837
  await this._onUpdateStatus(status);
4731
4838
  }
@@ -4789,7 +4896,7 @@ var ClientServicesHost = class {
4789
4896
  lockKey,
4790
4897
  callbacks
4791
4898
  } = {}) {
4792
- this._tracingService = TRACE_PROCESSOR.createTraceSender();
4899
+ this._tracingService = TRACE_PROCESSOR2.createTraceSender();
4793
4900
  this._statusUpdate = new Event8();
4794
4901
  this._opening = false;
4795
4902
  this._open = false;
@@ -5187,4 +5294,4 @@ export {
5187
5294
  createDefaultModelFactory,
5188
5295
  ClientServicesHost
5189
5296
  };
5190
- //# sourceMappingURL=chunk-OZ4IMR73.mjs.map
5297
+ //# sourceMappingURL=chunk-ESWBGQCJ.mjs.map