@dxos/client-services 0.6.14-staging.e15392e → 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.
Files changed (50) hide show
  1. package/dist/lib/browser/{chunk-UNN7JEOU.mjs → chunk-GP5GD22Z.mjs} +169 -142
  2. package/dist/lib/browser/chunk-GP5GD22Z.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/testing/index.mjs +9 -2
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-4BJB67XI.cjs → chunk-3ERQHVZE.cjs} +177 -150
  8. package/dist/lib/node/chunk-3ERQHVZE.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +47 -47
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +16 -9
  12. package/dist/lib/node/testing/index.cjs.map +3 -3
  13. package/dist/lib/node-esm/{chunk-Z3GXONTZ.mjs → chunk-UTJ4HL4J.mjs} +169 -142
  14. package/dist/lib/node-esm/chunk-UTJ4HL4J.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1 -1
  16. package/dist/lib/node-esm/meta.json +1 -1
  17. package/dist/lib/node-esm/testing/index.mjs +9 -2
  18. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  19. package/dist/types/src/packlets/devices/devices-service.d.ts +3 -1
  20. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -0
  22. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  23. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  26. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +1 -0
  28. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  29. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  30. package/dist/types/src/version.d.ts +1 -1
  31. package/dist/types/src/version.d.ts.map +1 -1
  32. package/package.json +38 -38
  33. package/src/packlets/devices/devices-service.ts +18 -7
  34. package/src/packlets/identity/identity.test.ts +16 -5
  35. package/src/packlets/invitations/edge-invitation-handler.ts +6 -3
  36. package/src/packlets/invitations/invitation-guest-extenstion.ts +5 -5
  37. package/src/packlets/invitations/invitation-host-extension.ts +7 -10
  38. package/src/packlets/invitations/invitations-handler.test.ts +3 -6
  39. package/src/packlets/invitations/invitations-handler.ts +34 -28
  40. package/src/packlets/invitations/invitations-manager.ts +5 -3
  41. package/src/packlets/invitations/invitations-service.ts +5 -1
  42. package/src/packlets/services/service-context.ts +2 -2
  43. package/src/packlets/services/service-host.ts +1 -1
  44. package/src/packlets/spaces/edge-feed-replicator.test.ts +12 -7
  45. package/src/packlets/spaces/edge-feed-replicator.ts +9 -5
  46. package/src/packlets/testing/invitation-utils.ts +7 -0
  47. package/src/version.ts +5 -1
  48. package/dist/lib/browser/chunk-UNN7JEOU.mjs.map +0 -7
  49. package/dist/lib/node/chunk-4BJB67XI.cjs.map +0 -7
  50. package/dist/lib/node-esm/chunk-Z3GXONTZ.mjs.map +0 -7
@@ -397,7 +397,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
397
397
  import { TRACE_PROCESSOR } from "@dxos/tracing";
398
398
 
399
399
  // packages/sdk/client-services/src/version.ts
400
- var DXOS_VERSION = "0.6.14-staging.e15392e";
400
+ var DXOS_VERSION = "0.7.0";
401
401
 
402
402
  // packages/sdk/client-services/src/packlets/services/platform.ts
403
403
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -909,7 +909,7 @@ var EdgeFeedReplicator = class extends Resource {
909
909
  S: this,
910
910
  C: (f, a) => f(...a)
911
911
  });
912
- this._ctx.onDispose(this._messenger.addListener((message) => {
912
+ this._ctx.onDispose(this._messenger.onMessage((message) => {
913
913
  if (!message.serviceId) {
914
914
  return;
915
915
  }
@@ -943,10 +943,12 @@ var EdgeFeedReplicator = class extends Resource {
943
943
  });
944
944
  this._onMessage(payload);
945
945
  }));
946
- this._messenger.connected.on(this._ctx, async () => {
947
- await this._resetConnection();
948
- this._startReplication();
949
- });
946
+ this._ctx.onDispose(this._messenger.onReconnected(() => {
947
+ scheduleMicroTask(this._ctx, () => this._handleReconnect());
948
+ }));
949
+ }
950
+ async _handleReconnect() {
951
+ await this._resetConnection();
950
952
  if (this._messenger.isConnected) {
951
953
  this._startReplication();
952
954
  }
@@ -954,7 +956,7 @@ var EdgeFeedReplicator = class extends Resource {
954
956
  async _close() {
955
957
  log4("close", void 0, {
956
958
  F: __dxlog_file6,
957
- L: 91,
959
+ L: 95,
958
960
  S: this,
959
961
  C: (f, a) => f(...a)
960
962
  });
@@ -966,7 +968,7 @@ var EdgeFeedReplicator = class extends Resource {
966
968
  this._connectionCtx = connectionCtx;
967
969
  log4("connection context created", void 0, {
968
970
  F: __dxlog_file6,
969
- L: 99,
971
+ L: 103,
970
972
  S: this,
971
973
  C: (f, a) => f(...a)
972
974
  });
@@ -979,7 +981,7 @@ var EdgeFeedReplicator = class extends Resource {
979
981
  async _resetConnection() {
980
982
  log4("resetConnection", void 0, {
981
983
  F: __dxlog_file6,
982
- L: 108,
984
+ L: 112,
983
985
  S: this,
984
986
  C: (f, a) => f(...a)
985
987
  });
@@ -995,7 +997,7 @@ var EdgeFeedReplicator = class extends Resource {
995
997
  hasConnectionCtx: !!this._connectionCtx
996
998
  }, {
997
999
  F: __dxlog_file6,
998
- L: 116,
1000
+ L: 120,
999
1001
  S: this,
1000
1002
  C: (f, a) => f(...a)
1001
1003
  });
@@ -1012,7 +1014,7 @@ var EdgeFeedReplicator = class extends Resource {
1012
1014
  key: feed.key
1013
1015
  }, {
1014
1016
  F: __dxlog_file6,
1015
- L: 129,
1017
+ L: 133,
1016
1018
  S: this,
1017
1019
  C: (f, a) => f(...a)
1018
1020
  });
@@ -1028,7 +1030,7 @@ var EdgeFeedReplicator = class extends Resource {
1028
1030
  if (!this._connectionCtx) {
1029
1031
  log4.info("message dropped because connection was disposed", void 0, {
1030
1032
  F: __dxlog_file6,
1031
- L: 142,
1033
+ L: 146,
1032
1034
  S: this,
1033
1035
  C: (f, a) => f(...a)
1034
1036
  });
@@ -1042,13 +1044,13 @@ var EdgeFeedReplicator = class extends Resource {
1042
1044
  };
1043
1045
  log4.info("sending message", logPayload, {
1044
1046
  F: __dxlog_file6,
1045
- L: 148,
1047
+ L: 152,
1046
1048
  S: this,
1047
1049
  C: (f, a) => f(...a)
1048
1050
  });
1049
1051
  invariant2(message.feedKey, void 0, {
1050
1052
  F: __dxlog_file6,
1051
- L: 150,
1053
+ L: 154,
1052
1054
  S: this,
1053
1055
  A: [
1054
1056
  "message.feedKey",
@@ -1060,7 +1062,7 @@ var EdgeFeedReplicator = class extends Resource {
1060
1062
  type: message.type
1061
1063
  }, {
1062
1064
  F: __dxlog_file6,
1063
- L: 153,
1065
+ L: 157,
1064
1066
  S: this,
1065
1067
  C: (f, a) => f(...a)
1066
1068
  });
@@ -1079,7 +1081,7 @@ var EdgeFeedReplicator = class extends Resource {
1079
1081
  if (!this._connectionCtx) {
1080
1082
  log4.warn("received message after connection context was disposed", void 0, {
1081
1083
  F: __dxlog_file6,
1082
- L: 168,
1084
+ L: 172,
1083
1085
  S: this,
1084
1086
  C: (f, a) => f(...a)
1085
1087
  });
@@ -1094,7 +1096,7 @@ var EdgeFeedReplicator = class extends Resource {
1094
1096
  message
1095
1097
  }, {
1096
1098
  F: __dxlog_file6,
1097
- L: 174,
1099
+ L: 178,
1098
1100
  S: this,
1099
1101
  C: (f, a) => f(...a)
1100
1102
  });
@@ -1105,7 +1107,7 @@ var EdgeFeedReplicator = class extends Resource {
1105
1107
  feedKey
1106
1108
  }, {
1107
1109
  F: __dxlog_file6,
1108
- L: 179,
1110
+ L: 183,
1109
1111
  S: this,
1110
1112
  C: (f, a) => f(...a)
1111
1113
  });
@@ -1138,7 +1140,7 @@ var EdgeFeedReplicator = class extends Resource {
1138
1140
  blocks: message.blocks.map((b) => b.index)
1139
1141
  }, {
1140
1142
  F: __dxlog_file6,
1141
- L: 201,
1143
+ L: 205,
1142
1144
  S: this,
1143
1145
  C: (f, a) => f(...a)
1144
1146
  });
@@ -1149,7 +1151,7 @@ var EdgeFeedReplicator = class extends Resource {
1149
1151
  feedKey
1150
1152
  }, {
1151
1153
  F: __dxlog_file6,
1152
- L: 206,
1154
+ L: 210,
1153
1155
  S: this,
1154
1156
  C: (f, a) => f(...a)
1155
1157
  });
@@ -1163,7 +1165,7 @@ var EdgeFeedReplicator = class extends Resource {
1163
1165
  ...message
1164
1166
  }, {
1165
1167
  F: __dxlog_file6,
1166
- L: 215,
1168
+ L: 219,
1167
1169
  S: this,
1168
1170
  C: (f, a) => f(...a)
1169
1171
  });
@@ -1178,7 +1180,7 @@ var EdgeFeedReplicator = class extends Resource {
1178
1180
  to
1179
1181
  }, {
1180
1182
  F: __dxlog_file6,
1181
- L: 222,
1183
+ L: 226,
1182
1184
  S: this,
1183
1185
  C: (f, a) => f(...a)
1184
1186
  });
@@ -1188,7 +1190,7 @@ var EdgeFeedReplicator = class extends Resource {
1188
1190
  });
1189
1191
  invariant2(data instanceof Uint8Array, void 0, {
1190
1192
  F: __dxlog_file6,
1191
- L: 227,
1193
+ L: 231,
1192
1194
  S: this,
1193
1195
  A: [
1194
1196
  "data instanceof Uint8Array",
@@ -1216,7 +1218,7 @@ var EdgeFeedReplicator = class extends Resource {
1216
1218
  blocks: blocks.length
1217
1219
  }, {
1218
1220
  F: __dxlog_file6,
1219
- L: 248,
1221
+ L: 252,
1220
1222
  S: this,
1221
1223
  C: (f, a) => f(...a)
1222
1224
  });
@@ -1238,7 +1240,7 @@ var EdgeFeedReplicator = class extends Resource {
1238
1240
  if (!this._remoteLength.has(feed.key)) {
1239
1241
  log4("blocks not pushed because remote length is unknown", void 0, {
1240
1242
  F: __dxlog_file6,
1241
- L: 269,
1243
+ L: 273,
1242
1244
  S: this,
1243
1245
  C: (f, a) => f(...a)
1244
1246
  });
@@ -1263,7 +1265,7 @@ var EdgeFeedReplicator = class extends Resource {
1263
1265
  if (err instanceof EdgeIdentityChangedError || err instanceof EdgeConnectionClosedError) {
1264
1266
  log4("resetting on reconnect", void 0, {
1265
1267
  F: __dxlog_file6,
1266
- L: 286,
1268
+ L: 290,
1267
1269
  S: this,
1268
1270
  C: (f, a) => f(...a)
1269
1271
  });
@@ -1274,7 +1276,7 @@ var EdgeFeedReplicator = class extends Resource {
1274
1276
  }
1275
1277
  }, {
1276
1278
  F: __dxlog_file6,
1277
- L: 280
1279
+ L: 284
1278
1280
  });
1279
1281
  return connectionCtx;
1280
1282
  }
@@ -4837,6 +4839,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
4837
4839
 
4838
4840
  // packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts
4839
4841
  var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts";
4842
+ var MAX_RETRIES_PER_INVITATION = 5;
4840
4843
  var DEFAULT_REQUEST_RETRY_INTERVAL_MS = 3e3;
4841
4844
  var DEFAULT_REQUEST_RETRY_JITTER_MS = 500;
4842
4845
  var EdgeInvitationHandler = class {
@@ -4850,7 +4853,7 @@ var EdgeInvitationHandler = class {
4850
4853
  if (!this._client) {
4851
4854
  log14("edge disabled", void 0, {
4852
4855
  F: __dxlog_file17,
4853
- L: 65,
4856
+ L: 66,
4854
4857
  S: this,
4855
4858
  C: (f, a) => f(...a)
4856
4859
  });
@@ -4864,7 +4867,7 @@ var EdgeInvitationHandler = class {
4864
4867
  invitation
4865
4868
  }, {
4866
4869
  F: __dxlog_file17,
4867
- L: 79,
4870
+ L: 80,
4868
4871
  S: this,
4869
4872
  C: (f, a) => f(...a)
4870
4873
  });
@@ -4874,7 +4877,9 @@ var EdgeInvitationHandler = class {
4874
4877
  this._flowLock?.release();
4875
4878
  this._flowLock = void 0;
4876
4879
  });
4880
+ let requestCount = 0;
4877
4881
  const tryHandleInvitation = async () => {
4882
+ requestCount++;
4878
4883
  const admissionRequest = await protocol.createAdmissionRequest(deviceProfile);
4879
4884
  if (admissionRequest.space) {
4880
4885
  try {
@@ -4887,19 +4892,19 @@ var EdgeInvitationHandler = class {
4887
4892
  after: error.retryAfterMs ?? this._calculateNextRetryMs()
4888
4893
  }, {
4889
4894
  F: __dxlog_file17,
4890
- L: 95,
4895
+ L: 98,
4891
4896
  S: this,
4892
4897
  C: (f, a) => f(...a)
4893
4898
  });
4894
- if (error.isRetryable) {
4899
+ if (error.isRetryable && requestCount < MAX_RETRIES_PER_INVITATION) {
4895
4900
  scheduleTask5(ctx, tryHandleInvitation, error.retryAfterMs ?? this._calculateNextRetryMs());
4896
4901
  }
4897
- } else {
4902
+ } else if (requestCount < MAX_RETRIES_PER_INVITATION) {
4898
4903
  log14.info("failed to handle invitation with edge", {
4899
4904
  error
4900
4905
  }, {
4901
4906
  F: __dxlog_file17,
4902
- L: 104,
4907
+ L: 107,
4903
4908
  S: this,
4904
4909
  C: (f, a) => f(...a)
4905
4910
  });
@@ -4914,14 +4919,14 @@ var EdgeInvitationHandler = class {
4914
4919
  try {
4915
4920
  log14("edge invitation flow", void 0, {
4916
4921
  F: __dxlog_file17,
4917
- L: 120,
4922
+ L: 123,
4918
4923
  S: this,
4919
4924
  C: (f, a) => f(...a)
4920
4925
  });
4921
4926
  this._flowLock = await tryAcquireBeforeContextDisposed(ctx, guardedState.mutex);
4922
- log14("edge invitation flow acquired the lock", void 0, {
4927
+ log14.verbose("edge invitation flow acquired the lock", void 0, {
4923
4928
  F: __dxlog_file17,
4924
- L: 122,
4929
+ L: 125,
4925
4930
  S: this,
4926
4931
  C: (f, a) => f(...a)
4927
4932
  });
@@ -4954,7 +4959,7 @@ var EdgeInvitationHandler = class {
4954
4959
  async _joinSpaceByInvitation(guardedState, spaceId, request) {
4955
4960
  invariant11(this._client, void 0, {
4956
4961
  F: __dxlog_file17,
4957
- L: 157,
4962
+ L: 160,
4958
4963
  S: this,
4959
4964
  A: [
4960
4965
  "this._client",
@@ -5052,14 +5057,14 @@ var InvitationGuestExtension = class extends RpcExtension2 {
5052
5057
  async onOpen(context) {
5053
5058
  await super.onOpen(context);
5054
5059
  try {
5055
- log15("guest acquire lock", void 0, {
5060
+ log15.verbose("guest acquire lock", void 0, {
5056
5061
  F: __dxlog_file18,
5057
5062
  L: 89,
5058
5063
  S: this,
5059
5064
  C: (f, a) => f(...a)
5060
5065
  });
5061
5066
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
5062
- log15("guest lock acquired", void 0, {
5067
+ log15.verbose("guest lock acquired", void 0, {
5063
5068
  F: __dxlog_file18,
5064
5069
  L: 91,
5065
5070
  S: this,
@@ -5068,7 +5073,7 @@ var InvitationGuestExtension = class extends RpcExtension2 {
5068
5073
  await cancelWithContext4(this._ctx, this.rpc.InvitationHostService.options({
5069
5074
  role: InvitationOptions.Role.GUEST
5070
5075
  }));
5071
- log15("options sent", void 0, {
5076
+ log15.verbose("options sent", void 0, {
5072
5077
  F: __dxlog_file18,
5073
5078
  L: 96,
5074
5079
  S: this,
@@ -5077,7 +5082,7 @@ var InvitationGuestExtension = class extends RpcExtension2 {
5077
5082
  await cancelWithContext4(this._ctx, this._remoteOptionsTrigger.wait({
5078
5083
  timeout: OPTIONS_TIMEOUT
5079
5084
  }));
5080
- log15("options received", void 0, {
5085
+ log15.verbose("options received", void 0, {
5081
5086
  F: __dxlog_file18,
5082
5087
  L: 98,
5083
5088
  S: this,
@@ -5111,7 +5116,7 @@ var InvitationGuestExtension = class extends RpcExtension2 {
5111
5116
  if (this._invitationFlowLock != null) {
5112
5117
  this._invitationFlowLock.release();
5113
5118
  this._invitationFlowLock = null;
5114
- log15("invitation flow lock released", void 0, {
5119
+ log15.verbose("invitation flow lock released", void 0, {
5115
5120
  F: __dxlog_file18,
5116
5121
  L: 131,
5117
5122
  S: this,
@@ -5210,7 +5215,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
5210
5215
  authMethod: Invitation5.AuthMethod.NONE
5211
5216
  };
5212
5217
  }
5213
- log16("guest introduced themselves", {
5218
+ log16.verbose("guest introduced themselves", {
5214
5219
  guestProfile: profile
5215
5220
  }, {
5216
5221
  F: __dxlog_file19,
@@ -5245,7 +5250,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
5245
5250
  C: (f, a) => f(...a)
5246
5251
  });
5247
5252
  const invitation = this._requireActiveInvitation();
5248
- log16("received authentication request", {
5253
+ log16.verbose("received authentication request", {
5249
5254
  authCode: code
5250
5255
  }, {
5251
5256
  F: __dxlog_file19,
@@ -5373,41 +5378,39 @@ var InvitationHostExtension = class extends RpcExtension3 {
5373
5378
  async onOpen(context) {
5374
5379
  await super.onOpen(context);
5375
5380
  try {
5376
- log16("host acquire lock", void 0, {
5381
+ log16.verbose("host acquire lock", void 0, {
5377
5382
  F: __dxlog_file19,
5378
5383
  L: 239,
5379
5384
  S: this,
5380
5385
  C: (f, a) => f(...a)
5381
5386
  });
5382
5387
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
5383
- log16("host lock acquired", void 0, {
5388
+ log16.verbose("host lock acquired", void 0, {
5384
5389
  F: __dxlog_file19,
5385
5390
  L: 241,
5386
5391
  S: this,
5387
5392
  C: (f, a) => f(...a)
5388
5393
  });
5389
- const lastState = this._requireActiveInvitation().state;
5390
5394
  this._callbacks.onStateUpdate(Invitation5.State.CONNECTING);
5391
5395
  await this.rpc.InvitationHostService.options({
5392
5396
  role: InvitationOptions2.Role.HOST
5393
5397
  });
5394
- log16("options sent", void 0, {
5398
+ log16.verbose("options sent", void 0, {
5395
5399
  F: __dxlog_file19,
5396
- L: 245,
5400
+ L: 244,
5397
5401
  S: this,
5398
5402
  C: (f, a) => f(...a)
5399
5403
  });
5400
5404
  await cancelWithContext5(this._ctx, this._remoteOptionsTrigger.wait({
5401
5405
  timeout: OPTIONS_TIMEOUT2
5402
5406
  }));
5403
- log16("options received", void 0, {
5407
+ log16.verbose("options received", void 0, {
5404
5408
  F: __dxlog_file19,
5405
- L: 247,
5409
+ L: 246,
5406
5410
  S: this,
5407
5411
  C: (f, a) => f(...a)
5408
5412
  });
5409
5413
  if (this._remoteOptions?.role !== InvitationOptions2.Role.GUEST) {
5410
- this._callbacks.onStateUpdate(lastState);
5411
5414
  throw new InvalidInvitationExtensionRoleError2(void 0, {
5412
5415
  expected: InvitationOptions2.Role.GUEST,
5413
5416
  remoteOptions: this._remoteOptions,
@@ -5454,9 +5457,9 @@ var InvitationHostExtension = class extends RpcExtension3 {
5454
5457
  if (this._invitationFlowLock != null) {
5455
5458
  this._invitationFlowLock?.release();
5456
5459
  this._invitationFlowLock = null;
5457
- log16("invitation flow lock released", void 0, {
5460
+ log16.verbose("invitation flow lock released", void 0, {
5458
5461
  F: __dxlog_file19,
5459
- L: 302,
5462
+ L: 299,
5460
5463
  S: this,
5461
5464
  C: (f, a) => f(...a)
5462
5465
  });
@@ -5664,7 +5667,7 @@ var InvitationsHandler = class {
5664
5667
  S: this,
5665
5668
  C: (f, a) => f(...a)
5666
5669
  });
5667
- metrics.increment("dxos.invitation.created");
5670
+ metrics.increment("dxos.invitation.host");
5668
5671
  const guardedState = createGuardedInvitationState(ctx, invitation, stream);
5669
5672
  const createExtension = () => {
5670
5673
  const extension = new InvitationHostExtension(guardedState.mutex, {
@@ -5672,7 +5675,9 @@ var InvitationsHandler = class {
5672
5675
  return ctx.disposed ? null : guardedState.current;
5673
5676
  },
5674
5677
  onStateUpdate: (newState) => {
5675
- guardedState.set(extension, newState);
5678
+ if (newState !== Invitation7.State.ERROR && newState !== Invitation7.State.TIMEOUT) {
5679
+ guardedState.set(extension, newState);
5680
+ }
5676
5681
  return guardedState.current;
5677
5682
  },
5678
5683
  admit: async (admissionRequest) => {
@@ -5682,14 +5687,14 @@ var InvitationsHandler = class {
5682
5687
  ...protocol.toJSON()
5683
5688
  }, {
5684
5689
  F: __dxlog_file22,
5685
- L: 105,
5690
+ L: 107,
5686
5691
  S: this,
5687
5692
  C: (f, a) => f(...a)
5688
5693
  });
5689
5694
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
5690
5695
  invariant15(deviceKey, void 0, {
5691
5696
  F: __dxlog_file22,
5692
- L: 110,
5697
+ L: 112,
5693
5698
  S: this,
5694
5699
  A: [
5695
5700
  "deviceKey",
@@ -5708,7 +5713,7 @@ var InvitationsHandler = class {
5708
5713
  let admitted = false;
5709
5714
  connectionCtx.onDispose(() => {
5710
5715
  if (!admitted) {
5711
- guardedState.error(extension, new ContextDisposedError3());
5716
+ guardedState.set(extension, Invitation7.State.CONNECTING);
5712
5717
  }
5713
5718
  });
5714
5719
  scheduleTask7(connectionCtx, async () => {
@@ -5718,27 +5723,27 @@ var InvitationsHandler = class {
5718
5723
  id: traceId
5719
5724
  }), {
5720
5725
  F: __dxlog_file22,
5721
- L: 135,
5726
+ L: 137,
5722
5727
  S: this,
5723
5728
  C: (f, a) => f(...a)
5724
5729
  });
5725
- log19("connected", {
5730
+ log19.verbose("connected", {
5726
5731
  ...protocol.toJSON()
5727
5732
  }, {
5728
5733
  F: __dxlog_file22,
5729
- L: 136,
5734
+ L: 138,
5730
5735
  S: this,
5731
5736
  C: (f, a) => f(...a)
5732
5737
  });
5733
5738
  const deviceKey = await extension.completedTrigger.wait({
5734
5739
  timeout: invitation.timeout
5735
5740
  });
5736
- log19("admitted guest", {
5741
+ log19.verbose("admitted guest", {
5737
5742
  guest: deviceKey,
5738
5743
  ...protocol.toJSON()
5739
5744
  }, {
5740
5745
  F: __dxlog_file22,
5741
- L: 138,
5746
+ L: 140,
5742
5747
  S: this,
5743
5748
  C: (f, a) => f(...a)
5744
5749
  });
@@ -5748,7 +5753,7 @@ var InvitationsHandler = class {
5748
5753
  id: traceId
5749
5754
  }), {
5750
5755
  F: __dxlog_file22,
5751
- L: 141,
5756
+ L: 143,
5752
5757
  S: this,
5753
5758
  C: (f, a) => f(...a)
5754
5759
  });
@@ -5757,24 +5762,25 @@ var InvitationsHandler = class {
5757
5762
  await ctx.dispose();
5758
5763
  }
5759
5764
  } catch (err) {
5765
+ const stateChanged = guardedState.set(extension, Invitation7.State.CONNECTING);
5760
5766
  if (err instanceof TimeoutError2) {
5761
- if (guardedState.set(extension, Invitation7.State.TIMEOUT)) {
5767
+ if (stateChanged) {
5762
5768
  metrics.increment("dxos.invitation.timeout");
5763
- log19("timeout", {
5769
+ log19.verbose("timeout", {
5764
5770
  ...protocol.toJSON()
5765
5771
  }, {
5766
5772
  F: __dxlog_file22,
5767
- L: 151,
5773
+ L: 154,
5768
5774
  S: this,
5769
5775
  C: (f, a) => f(...a)
5770
5776
  });
5771
5777
  }
5772
5778
  } else {
5773
- if (guardedState.error(extension, err)) {
5779
+ if (stateChanged) {
5774
5780
  metrics.increment("dxos.invitation.failed");
5775
5781
  log19.error("failed", err, {
5776
5782
  F: __dxlog_file22,
5777
- L: 156,
5783
+ L: 159,
5778
5784
  S: this,
5779
5785
  C: (f, a) => f(...a)
5780
5786
  });
@@ -5785,7 +5791,7 @@ var InvitationsHandler = class {
5785
5791
  error: err
5786
5792
  }), {
5787
5793
  F: __dxlog_file22,
5788
- L: 159,
5794
+ L: 162,
5789
5795
  S: this,
5790
5796
  C: (f, a) => f(...a)
5791
5797
  });
@@ -5794,35 +5800,36 @@ var InvitationsHandler = class {
5794
5800
  });
5795
5801
  },
5796
5802
  onError: (err) => {
5803
+ const stateChanged = guardedState.set(extension, Invitation7.State.CONNECTING);
5797
5804
  if (err instanceof InvalidInvitationExtensionRoleError3) {
5798
5805
  log19("invalid role", {
5799
5806
  ...err.context
5800
5807
  }, {
5801
5808
  F: __dxlog_file22,
5802
- L: 167,
5809
+ L: 171,
5803
5810
  S: this,
5804
5811
  C: (f, a) => f(...a)
5805
5812
  });
5806
5813
  return;
5807
5814
  }
5808
5815
  if (err instanceof TimeoutError2) {
5809
- if (guardedState.set(extension, Invitation7.State.TIMEOUT)) {
5816
+ if (stateChanged) {
5810
5817
  metrics.increment("dxos.invitation.timeout");
5811
- log19("timeout", {
5818
+ log19.verbose("timeout", {
5812
5819
  err
5813
5820
  }, {
5814
5821
  F: __dxlog_file22,
5815
- L: 173,
5822
+ L: 177,
5816
5823
  S: this,
5817
5824
  C: (f, a) => f(...a)
5818
5825
  });
5819
5826
  }
5820
5827
  } else {
5821
- if (guardedState.error(extension, err)) {
5828
+ if (stateChanged) {
5822
5829
  metrics.increment("dxos.invitation.failed");
5823
5830
  log19.error("failed", err, {
5824
5831
  F: __dxlog_file22,
5825
- L: 178,
5832
+ L: 182,
5826
5833
  S: this,
5827
5834
  C: (f, a) => f(...a)
5828
5835
  });
@@ -5836,18 +5843,25 @@ var InvitationsHandler = class {
5836
5843
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
5837
5844
  log19.warn("invitation has already expired", void 0, {
5838
5845
  F: __dxlog_file22,
5839
- L: 189,
5846
+ L: 193,
5840
5847
  S: this,
5841
5848
  C: (f, a) => f(...a)
5842
5849
  });
5843
- } else {
5844
- scheduleTask7(ctx, async () => {
5845
- await swarmConnection.close();
5846
- guardedState.set(null, Invitation7.State.EXPIRED);
5847
- metrics.increment("dxos.invitation.expired");
5848
- await ctx.dispose();
5849
- }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5850
+ guardedState.set(null, Invitation7.State.EXPIRED);
5851
+ void ctx.dispose().catch((err) => log19.catch(err, void 0, {
5852
+ F: __dxlog_file22,
5853
+ L: 195,
5854
+ S: this,
5855
+ C: (f, a) => f(...a)
5856
+ }));
5857
+ return;
5850
5858
  }
5859
+ scheduleTask7(ctx, async () => {
5860
+ await swarmConnection.close();
5861
+ guardedState.set(null, Invitation7.State.EXPIRED);
5862
+ metrics.increment("dxos.invitation.expired");
5863
+ await ctx.dispose();
5864
+ }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5851
5865
  }
5852
5866
  let swarmConnection;
5853
5867
  scheduleTask7(ctx, async () => {
@@ -5863,7 +5877,7 @@ var InvitationsHandler = class {
5863
5877
  type: invitation.type
5864
5878
  }, {
5865
5879
  F: __dxlog_file22,
5866
- L: 220,
5880
+ L: 226,
5867
5881
  S: this,
5868
5882
  C: (f, a) => f(...a)
5869
5883
  });
@@ -5871,7 +5885,7 @@ var InvitationsHandler = class {
5871
5885
  if (deviceProfile) {
5872
5886
  invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5873
5887
  F: __dxlog_file22,
5874
- L: 229,
5888
+ L: 235,
5875
5889
  S: this,
5876
5890
  A: [
5877
5891
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -5889,7 +5903,7 @@ var InvitationsHandler = class {
5889
5903
  triedPeers: triedPeersIds.size
5890
5904
  }, {
5891
5905
  F: __dxlog_file22,
5892
- L: 237,
5906
+ L: 243,
5893
5907
  S: this,
5894
5908
  C: (f, a) => f(...a)
5895
5909
  });
@@ -5911,12 +5925,12 @@ var InvitationsHandler = class {
5911
5925
  return;
5912
5926
  }
5913
5927
  connectionCtx.onDispose(async () => {
5914
- log19("extension disposed", {
5928
+ log19.verbose("extension disposed", {
5915
5929
  admitted,
5916
5930
  currentState: guardedState.current.state
5917
5931
  }, {
5918
5932
  F: __dxlog_file22,
5919
- L: 265,
5933
+ L: 271,
5920
5934
  S: this,
5921
5935
  C: (f, a) => f(...a)
5922
5936
  });
@@ -5934,7 +5948,7 @@ var InvitationsHandler = class {
5934
5948
  id: traceId
5935
5949
  }), {
5936
5950
  F: __dxlog_file22,
5937
- L: 277,
5951
+ L: 283,
5938
5952
  S: this,
5939
5953
  C: (f, a) => f(...a)
5940
5954
  });
@@ -5946,7 +5960,7 @@ var InvitationsHandler = class {
5946
5960
  ...protocol.toJSON()
5947
5961
  }, {
5948
5962
  F: __dxlog_file22,
5949
- L: 288,
5963
+ L: 294,
5950
5964
  S: this,
5951
5965
  C: (f, a) => f(...a)
5952
5966
  });
@@ -5956,7 +5970,7 @@ var InvitationsHandler = class {
5956
5970
  ...protocol.toJSON()
5957
5971
  }, {
5958
5972
  F: __dxlog_file22,
5959
- L: 292,
5973
+ L: 298,
5960
5974
  S: this,
5961
5975
  C: (f, a) => f(...a)
5962
5976
  });
@@ -5970,7 +5984,7 @@ var InvitationsHandler = class {
5970
5984
  authMethod: introductionResponse.authMethod
5971
5985
  }, {
5972
5986
  F: __dxlog_file22,
5973
- L: 300,
5987
+ L: 306,
5974
5988
  S: this,
5975
5989
  C: (f, a) => f(...a)
5976
5990
  });
@@ -5992,7 +6006,7 @@ var InvitationsHandler = class {
5992
6006
  ...protocol.toJSON()
5993
6007
  }, {
5994
6008
  F: __dxlog_file22,
5995
- L: 330,
6009
+ L: 336,
5996
6010
  S: this,
5997
6011
  C: (f, a) => f(...a)
5998
6012
  });
@@ -6005,7 +6019,7 @@ var InvitationsHandler = class {
6005
6019
  ...protocol.toJSON()
6006
6020
  }, {
6007
6021
  F: __dxlog_file22,
6008
- L: 344,
6022
+ L: 350,
6009
6023
  S: this,
6010
6024
  C: (f, a) => f(...a)
6011
6025
  });
@@ -6018,25 +6032,25 @@ var InvitationsHandler = class {
6018
6032
  id: traceId
6019
6033
  }), {
6020
6034
  F: __dxlog_file22,
6021
- L: 353,
6035
+ L: 359,
6022
6036
  S: this,
6023
6037
  C: (f, a) => f(...a)
6024
6038
  });
6025
6039
  } catch (err) {
6026
6040
  if (err instanceof TimeoutError2) {
6027
- log19("timeout", {
6041
+ log19.verbose("timeout", {
6028
6042
  ...protocol.toJSON()
6029
6043
  }, {
6030
6044
  F: __dxlog_file22,
6031
- L: 356,
6045
+ L: 362,
6032
6046
  S: this,
6033
6047
  C: (f, a) => f(...a)
6034
6048
  });
6035
6049
  guardedState.set(extension, Invitation7.State.TIMEOUT);
6036
6050
  } else {
6037
- log19("auth failed", err, {
6051
+ log19.verbose("auth failed", err, {
6038
6052
  F: __dxlog_file22,
6039
- L: 359,
6053
+ L: 365,
6040
6054
  S: this,
6041
6055
  C: (f, a) => f(...a)
6042
6056
  });
@@ -6048,7 +6062,7 @@ var InvitationsHandler = class {
6048
6062
  error: err
6049
6063
  }), {
6050
6064
  F: __dxlog_file22,
6051
- L: 363,
6065
+ L: 369,
6052
6066
  S: this,
6053
6067
  C: (f, a) => f(...a)
6054
6068
  });
@@ -6060,19 +6074,19 @@ var InvitationsHandler = class {
6060
6074
  return;
6061
6075
  }
6062
6076
  if (err instanceof TimeoutError2) {
6063
- log19("timeout", {
6077
+ log19.verbose("timeout", {
6064
6078
  ...protocol.toJSON()
6065
6079
  }, {
6066
6080
  F: __dxlog_file22,
6067
- L: 372,
6081
+ L: 378,
6068
6082
  S: this,
6069
6083
  C: (f, a) => f(...a)
6070
6084
  });
6071
6085
  guardedState.set(extension, Invitation7.State.TIMEOUT);
6072
6086
  } else {
6073
- log19("auth failed", err, {
6087
+ log19.verbose("auth failed", err, {
6074
6088
  F: __dxlog_file22,
6075
- L: 375,
6089
+ L: 381,
6076
6090
  S: this,
6077
6091
  C: (f, a) => f(...a)
6078
6092
  });
@@ -6089,7 +6103,7 @@ var InvitationsHandler = class {
6089
6103
  ...protocol.toJSON()
6090
6104
  }, {
6091
6105
  F: __dxlog_file22,
6092
- L: 387,
6106
+ L: 393,
6093
6107
  S: this,
6094
6108
  C: (f, a) => f(...a)
6095
6109
  });
@@ -6109,7 +6123,7 @@ var InvitationsHandler = class {
6109
6123
  } else {
6110
6124
  invariant15(invitation.swarmKey, void 0, {
6111
6125
  F: __dxlog_file22,
6112
- L: 399,
6126
+ L: 405,
6113
6127
  S: this,
6114
6128
  A: [
6115
6129
  "invitation.swarmKey",
@@ -6153,7 +6167,7 @@ var InvitationsHandler = class {
6153
6167
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
6154
6168
  log19("guest waiting for authentication code...", void 0, {
6155
6169
  F: __dxlog_file22,
6156
- L: 451,
6170
+ L: 457,
6157
6171
  S: this,
6158
6172
  C: (f, a) => f(...a)
6159
6173
  });
@@ -6161,7 +6175,7 @@ var InvitationsHandler = class {
6161
6175
  const authCode = await authenticated.wait(options);
6162
6176
  log19("sending authentication request", void 0, {
6163
6177
  F: __dxlog_file22,
6164
- L: 455,
6178
+ L: 461,
6165
6179
  S: this,
6166
6180
  C: (f, a) => f(...a)
6167
6181
  });
@@ -6180,7 +6194,7 @@ var InvitationsHandler = class {
6180
6194
  attempt
6181
6195
  }, {
6182
6196
  F: __dxlog_file22,
6183
- L: 466,
6197
+ L: 472,
6184
6198
  S: this,
6185
6199
  C: (f, a) => f(...a)
6186
6200
  });
@@ -6198,7 +6212,7 @@ var InvitationsHandler = class {
6198
6212
  }
6199
6213
  log19("sending authentication request", void 0, {
6200
6214
  F: __dxlog_file22,
6201
- L: 485,
6215
+ L: 491,
6202
6216
  S: this,
6203
6217
  C: (f, a) => f(...a)
6204
6218
  });
@@ -6222,6 +6236,7 @@ var createAdmissionKeypair = () => {
6222
6236
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
6223
6237
  import { Stream as Stream9 } from "@dxos/codec-protobuf";
6224
6238
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
6239
+ import { trace as trace8 } from "@dxos/tracing";
6225
6240
  var InvitationsServiceImpl = class {
6226
6241
  constructor(_invitationsManager) {
6227
6242
  this._invitationsManager = _invitationsManager;
@@ -6232,7 +6247,10 @@ var InvitationsServiceImpl = class {
6232
6247
  }
6233
6248
  createInvitation(options) {
6234
6249
  return new Stream9(({ next, close }) => {
6235
- void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
6250
+ void this._invitationsManager.createInvitation(options).then((invitation) => {
6251
+ trace8.metrics.increment("dxos.invitation.created");
6252
+ invitation.subscribe(next, close, close);
6253
+ }).catch(close);
6236
6254
  });
6237
6255
  }
6238
6256
  acceptInvitation(request) {
@@ -6810,8 +6828,8 @@ var InvitationsManager = class {
6810
6828
  this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
6811
6829
  }
6812
6830
  }
6813
- _createInvitation(protocol, options) {
6814
- const { invitationId = PublicKey12.random().toHex(), type = Invitation9.Type.INTERACTIVE, authMethod = Invitation9.AuthMethod.SHARED_SECRET, state = Invitation9.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = options?.authMethod !== Invitation9.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6831
+ _createInvitation(protocol, _options) {
6832
+ const { invitationId = PublicKey12.random().toHex(), type = Invitation9.Type.INTERACTIVE, authMethod = Invitation9.AuthMethod.SHARED_SECRET, state = Invitation9.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = _options?.authMethod !== Invitation9.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false, ...options } = _options ?? {};
6815
6833
  const authCode = options?.authCode ?? (authMethod === Invitation9.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6816
6834
  return {
6817
6835
  invitationId,
@@ -6828,6 +6846,7 @@ var InvitationsManager = class {
6828
6846
  role,
6829
6847
  multiUse,
6830
6848
  delegationCredentialId: options?.delegationCredentialId,
6849
+ ...options,
6831
6850
  ...protocol.getInvitationContext()
6832
6851
  };
6833
6852
  }
@@ -6840,14 +6859,14 @@ var InvitationsManager = class {
6840
6859
  }
6841
6860
  }, {
6842
6861
  F: __dxlog_file24,
6843
- L: 234
6862
+ L: 236
6844
6863
  });
6845
6864
  ctx.onDispose(() => {
6846
6865
  log21("complete", {
6847
6866
  ...handler.toJSON()
6848
6867
  }, {
6849
6868
  F: __dxlog_file24,
6850
- L: 241,
6869
+ L: 243,
6851
6870
  S: this,
6852
6871
  C: (f, a) => f(...a)
6853
6872
  });
@@ -6880,7 +6899,7 @@ var InvitationsManager = class {
6880
6899
  ...handler.toJSON()
6881
6900
  }, {
6882
6901
  F: __dxlog_file24,
6883
- L: 261,
6902
+ L: 263,
6884
6903
  S: this,
6885
6904
  C: (f, a) => f(...a)
6886
6905
  });
@@ -6891,7 +6910,7 @@ var InvitationsManager = class {
6891
6910
  } else {
6892
6911
  log21.warn("auth failed", err, {
6893
6912
  F: __dxlog_file24,
6894
- L: 264,
6913
+ L: 266,
6895
6914
  S: this,
6896
6915
  C: (f, a) => f(...a)
6897
6916
  });
@@ -6904,14 +6923,14 @@ var InvitationsManager = class {
6904
6923
  }
6905
6924
  }, {
6906
6925
  F: __dxlog_file24,
6907
- L: 258
6926
+ L: 260
6908
6927
  });
6909
6928
  ctx.onDispose(() => {
6910
6929
  log21("complete", {
6911
6930
  ...handler.toJSON()
6912
6931
  }, {
6913
6932
  F: __dxlog_file24,
6914
- L: 271,
6933
+ L: 273,
6915
6934
  S: this,
6916
6935
  C: (f, a) => f(...a)
6917
6936
  });
@@ -6956,7 +6975,7 @@ var InvitationsManager = class {
6956
6975
  } catch (err) {
6957
6976
  log21.catch(err, void 0, {
6958
6977
  F: __dxlog_file24,
6959
- L: 307,
6978
+ L: 309,
6960
6979
  S: this,
6961
6980
  C: (f, a) => f(...a)
6962
6981
  });
@@ -7093,7 +7112,7 @@ var isLocked = (lockPath) => {
7093
7112
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
7094
7113
  import { raise as raise2 } from "@dxos/debug";
7095
7114
  import { parseMethodName, RpcPeer } from "@dxos/rpc";
7096
- import { MapCounter, trace as trace8 } from "@dxos/tracing";
7115
+ import { MapCounter, trace as trace9 } from "@dxos/tracing";
7097
7116
  function _ts_decorate8(decorators, target, key, desc) {
7098
7117
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7099
7118
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -7157,13 +7176,13 @@ var ClientRpcServer = class {
7157
7176
  }
7158
7177
  };
7159
7178
  _ts_decorate8([
7160
- trace8.metricsCounter()
7179
+ trace9.metricsCounter()
7161
7180
  ], ClientRpcServer.prototype, "_callMetrics", void 0);
7162
7181
  _ts_decorate8([
7163
- trace8.info()
7182
+ trace9.info()
7164
7183
  ], ClientRpcServer.prototype, "_services", null);
7165
7184
  ClientRpcServer = _ts_decorate8([
7166
- trace8.resource()
7185
+ trace9.resource()
7167
7186
  ], ClientRpcServer);
7168
7187
 
7169
7188
  // packages/sdk/client-services/src/packlets/agents/edge-agent-manager.ts
@@ -7438,7 +7457,7 @@ import { invariant as invariant20 } from "@dxos/invariant";
7438
7457
  import { Keyring } from "@dxos/keyring";
7439
7458
  import { PublicKey as PublicKey15 } from "@dxos/keys";
7440
7459
  import { log as log25 } from "@dxos/log";
7441
- import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
7460
+ import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace10 } from "@dxos/protocols";
7442
7461
  import { Invitation as Invitation10 } from "@dxos/protocols/proto/dxos/client/services";
7443
7462
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
7444
7463
  import { trace as Trace3 } from "@dxos/tracing";
@@ -7696,7 +7715,7 @@ var ServiceContext = class extends Resource7 {
7696
7715
  S: this,
7697
7716
  C: (f, a) => f(...a)
7698
7717
  });
7699
- log25.trace("dxos.sdk.service-context.open", trace9.begin({
7718
+ log25.trace("dxos.sdk.service-context.open", trace10.begin({
7700
7719
  id: this._instanceId
7701
7720
  }), {
7702
7721
  F: __dxlog_file28,
@@ -7731,7 +7750,7 @@ var ServiceContext = class extends Resource7 {
7731
7750
  S: this,
7732
7751
  C: (f, a) => f(...a)
7733
7752
  });
7734
- log25.trace("dxos.sdk.service-context.open", trace9.end({
7753
+ log25.trace("dxos.sdk.service-context.open", trace10.end({
7735
7754
  id: this._instanceId
7736
7755
  }), {
7737
7756
  F: __dxlog_file28,
@@ -7951,8 +7970,8 @@ var ServiceContext = class extends Resource7 {
7951
7970
  S: this,
7952
7971
  C: (f, a) => f(...a)
7953
7972
  });
7954
- if (params?.deviceCredential) {
7955
- edgeIdentity = await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, {
7973
+ if (params?.deviceCredential || Boolean(globalThis?.DEVICE_INVITE_INTEROP)) {
7974
+ edgeIdentity = await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, params?.deviceCredential && {
7956
7975
  credential: params.deviceCredential
7957
7976
  }, []);
7958
7977
  } else {
@@ -8264,7 +8283,7 @@ import { PublicKey as PublicKey19 } from "@dxos/keys";
8264
8283
  import { log as log28 } from "@dxos/log";
8265
8284
  import { EdgeSignalManager, WebsocketSignalManager } from "@dxos/messaging";
8266
8285
  import { SwarmNetworkManager, createIceProvider, createRtcTransportFactory } from "@dxos/network-manager";
8267
- import { trace as trace10 } from "@dxos/protocols";
8286
+ import { trace as trace11 } from "@dxos/protocols";
8268
8287
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
8269
8288
  import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
8270
8289
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
@@ -8276,8 +8295,9 @@ import { invariant as invariant22 } from "@dxos/invariant";
8276
8295
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
8277
8296
  var __dxlog_file30 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
8278
8297
  var DevicesServiceImpl = class {
8279
- constructor(_identityManager) {
8298
+ constructor(_identityManager, _edgeConnection) {
8280
8299
  this._identityManager = _identityManager;
8300
+ this._edgeConnection = _edgeConnection;
8281
8301
  }
8282
8302
  async updateDevice(profile) {
8283
8303
  return this._identityManager.updateDeviceProfile(profile);
@@ -8293,7 +8313,7 @@ var DevicesServiceImpl = class {
8293
8313
  } else {
8294
8314
  invariant22(this._identityManager.identity?.presence, "presence not present", {
8295
8315
  F: __dxlog_file30,
8296
- L: 32,
8316
+ L: 36,
8297
8317
  S: this,
8298
8318
  A: [
8299
8319
  "this._identityManager.identity?.presence",
@@ -8304,12 +8324,19 @@ var DevicesServiceImpl = class {
8304
8324
  next({
8305
8325
  devices: Array.from(deviceKeys.entries()).map(([key, profile]) => {
8306
8326
  const isMe = this._identityManager.identity?.deviceKey.equals(key);
8307
- const peerState = peers.find((peer) => peer.identityKey.equals(key));
8327
+ let presence;
8328
+ if (isMe) {
8329
+ presence = Device2.PresenceState.ONLINE;
8330
+ } else if (profile.os?.toUpperCase() === "EDGE") {
8331
+ presence = this._edgeConnection?.isConnected ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE;
8332
+ } else {
8333
+ presence = peers.some((peer) => peer.identityKey.equals(key)) ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE;
8334
+ }
8308
8335
  return {
8309
8336
  deviceKey: key,
8310
8337
  kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind2.CURRENT : DeviceKind2.TRUSTED,
8311
8338
  profile,
8312
- presence: isMe ? Device2.PresenceState.ONLINE : peerState ? Device2.PresenceState.ONLINE : Device2.PresenceState.OFFLINE
8339
+ presence
8313
8340
  };
8314
8341
  })
8315
8342
  });
@@ -8833,7 +8860,7 @@ var ClientServicesHost = class {
8833
8860
  return;
8834
8861
  }
8835
8862
  const traceId = PublicKey19.random().toHex();
8836
- log28.trace("dxos.client-services.host.open", trace10.begin({
8863
+ log28.trace("dxos.client-services.host.open", trace11.begin({
8837
8864
  id: traceId
8838
8865
  }), {
8839
8866
  F: __dxlog_file31,
@@ -8907,7 +8934,7 @@ var ClientServicesHost = class {
8907
8934
  IdentityService: identityService,
8908
8935
  ContactsService: new ContactsServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
8909
8936
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
8910
- DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
8937
+ DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager, this._edgeConnection),
8911
8938
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, dataSpaceManagerProvider),
8912
8939
  DataService: this._serviceContext.echoHost.dataService,
8913
8940
  QueryService: this._serviceContext.echoHost.queryService,
@@ -8947,7 +8974,7 @@ var ClientServicesHost = class {
8947
8974
  S: this,
8948
8975
  C: (f, a) => f(...a)
8949
8976
  });
8950
- log28.trace("dxos.client-services.host.open", trace10.end({
8977
+ log28.trace("dxos.client-services.host.open", trace11.end({
8951
8978
  id: traceId
8952
8979
  }), {
8953
8980
  F: __dxlog_file31,
@@ -8990,7 +9017,7 @@ var ClientServicesHost = class {
8990
9017
  }
8991
9018
  async reset() {
8992
9019
  const traceId = PublicKey19.random().toHex();
8993
- log28.trace("dxos.sdk.client-services-host.reset", trace10.begin({
9020
+ log28.trace("dxos.sdk.client-services-host.reset", trace11.begin({
8994
9021
  id: traceId
8995
9022
  }), {
8996
9023
  F: __dxlog_file31,
@@ -9014,7 +9041,7 @@ var ClientServicesHost = class {
9014
9041
  S: this,
9015
9042
  C: (f, a) => f(...a)
9016
9043
  });
9017
- log28.trace("dxos.sdk.client-services-host.reset", trace10.end({
9044
+ log28.trace("dxos.sdk.client-services-host.reset", trace11.end({
9018
9045
  id: traceId
9019
9046
  }), {
9020
9047
  F: __dxlog_file31,
@@ -9096,4 +9123,4 @@ export {
9096
9123
  importProfileData,
9097
9124
  ClientServicesHost
9098
9125
  };
9099
- //# sourceMappingURL=chunk-UNN7JEOU.mjs.map
9126
+ //# sourceMappingURL=chunk-GP5GD22Z.mjs.map