@dxos/client-services 0.1.39-next.90cb9b6 → 0.1.40

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 (30) hide show
  1. package/dist/lib/browser/{chunk-6PNXHM7C.mjs → chunk-LGMYP2WL.mjs} +732 -576
  2. package/dist/lib/browser/chunk-LGMYP2WL.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 +14 -14
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +774 -618
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +754 -627
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +54 -0
  13. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -0
  14. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/invitations-service.d.ts +8 -3
  17. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  19. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  20. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  21. package/package.json +30 -30
  22. package/src/packlets/invitations/invitation-extension.ts +211 -0
  23. package/src/packlets/invitations/invitations-handler.ts +54 -123
  24. package/src/packlets/invitations/invitations-service.ts +106 -137
  25. package/src/packlets/services/utils.ts +3 -3
  26. package/src/packlets/testing/test-builder.ts +9 -7
  27. package/src/packlets/vault/iframe-host-runtime.ts +12 -4
  28. package/src/packlets/vault/iframe-proxy-runtime.ts +19 -4
  29. package/src/packlets/vault/worker-runtime.ts +3 -3
  30. package/dist/lib/browser/chunk-6PNXHM7C.mjs.map +0 -7
@@ -993,18 +993,236 @@ var DeviceInvitationProtocol = class {
993
993
  };
994
994
 
995
995
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
996
+ var import_node_assert6 = __toESM(require("node:assert"));
997
+ var import_async7 = require("@dxos/async");
998
+ var import_client = require("@dxos/client");
999
+ var import_context4 = require("@dxos/context");
1000
+ var import_credentials7 = require("@dxos/credentials");
1001
+ var import_errors2 = require("@dxos/errors");
1002
+ var import_keys6 = require("@dxos/keys");
1003
+ var import_log5 = require("@dxos/log");
1004
+ var import_network_manager = require("@dxos/network-manager");
1005
+ var import_protocols4 = require("@dxos/protocols");
1006
+ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
1007
+ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
1008
+
1009
+ // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
996
1010
  var import_node_assert5 = __toESM(require("node:assert"));
997
1011
  var import_async6 = require("@dxos/async");
998
- var import_client = require("@dxos/client");
999
1012
  var import_context3 = require("@dxos/context");
1000
- var import_credentials7 = require("@dxos/credentials");
1013
+ var import_errors = require("@dxos/errors");
1001
1014
  var import_keys5 = require("@dxos/keys");
1002
1015
  var import_log4 = require("@dxos/log");
1003
- var import_network_manager = require("@dxos/network-manager");
1004
1016
  var import_protocols3 = require("@dxos/protocols");
1005
- var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
1006
1017
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
1007
1018
  var import_teleport = require("@dxos/teleport");
1019
+ var OPTIONS_TIMEOUT = 1e4;
1020
+ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1021
+ constructor(_callbacks) {
1022
+ super({
1023
+ requested: {
1024
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1025
+ },
1026
+ exposed: {
1027
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1028
+ }
1029
+ });
1030
+ this._callbacks = _callbacks;
1031
+ this._ctx = new import_context3.Context();
1032
+ this._remoteOptionsTrigger = new import_async6.Trigger();
1033
+ }
1034
+ async getHandlers() {
1035
+ return {
1036
+ // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1037
+ // Perhaps in the future we will have more complex logic here.
1038
+ InvitationHostService: {
1039
+ options: async (options) => {
1040
+ (0, import_node_assert5.default)(!this._remoteOptions, "Remote options already set.");
1041
+ this._remoteOptions = options;
1042
+ this._remoteOptionsTrigger.wake();
1043
+ },
1044
+ introduce: async (request) => {
1045
+ const traceId = import_keys5.PublicKey.random().toHex();
1046
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
1047
+ id: traceId,
1048
+ parentId: this._traceParent
1049
+ }), {
1050
+ file: "invitation-extension.ts",
1051
+ line: 78,
1052
+ scope: this,
1053
+ callSite: (f, a) => f(...a)
1054
+ });
1055
+ const response = await this._callbacks.introduce(request);
1056
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
1057
+ id: traceId
1058
+ }), {
1059
+ file: "invitation-extension.ts",
1060
+ line: 83,
1061
+ scope: this,
1062
+ callSite: (f, a) => f(...a)
1063
+ });
1064
+ return response;
1065
+ },
1066
+ authenticate: async (request) => {
1067
+ const traceId = import_keys5.PublicKey.random().toHex();
1068
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
1069
+ id: traceId,
1070
+ parentId: this._traceParent
1071
+ }), {
1072
+ file: "invitation-extension.ts",
1073
+ line: 89,
1074
+ scope: this,
1075
+ callSite: (f, a) => f(...a)
1076
+ });
1077
+ const response = await this._callbacks.authenticate(request);
1078
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.end({
1079
+ id: traceId,
1080
+ data: {
1081
+ ...response
1082
+ }
1083
+ }), {
1084
+ file: "invitation-extension.ts",
1085
+ line: 94,
1086
+ scope: this,
1087
+ callSite: (f, a) => f(...a)
1088
+ });
1089
+ return response;
1090
+ },
1091
+ admit: async (request) => {
1092
+ const traceId = import_keys5.PublicKey.random().toHex();
1093
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
1094
+ id: traceId,
1095
+ parentId: this._traceParent
1096
+ }), {
1097
+ file: "invitation-extension.ts",
1098
+ line: 100,
1099
+ scope: this,
1100
+ callSite: (f, a) => f(...a)
1101
+ });
1102
+ const response = await this._callbacks.admit(request);
1103
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
1104
+ id: traceId
1105
+ }), {
1106
+ file: "invitation-extension.ts",
1107
+ line: 105,
1108
+ scope: this,
1109
+ callSite: (f, a) => f(...a)
1110
+ });
1111
+ return response;
1112
+ }
1113
+ }
1114
+ };
1115
+ }
1116
+ async onOpen(context) {
1117
+ var _a;
1118
+ await super.onOpen(context);
1119
+ try {
1120
+ await this.rpc.InvitationHostService.options({
1121
+ role: import_invitations.Options.Role.HOST
1122
+ });
1123
+ await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1124
+ timeout: OPTIONS_TIMEOUT
1125
+ }));
1126
+ if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
1127
+ throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1128
+ expected: import_invitations.Options.Role.GUEST,
1129
+ remoteOptions: this._remoteOptions
1130
+ });
1131
+ }
1132
+ this._callbacks.onOpen();
1133
+ } catch (err) {
1134
+ this._callbacks.onError(err);
1135
+ }
1136
+ }
1137
+ async onClose() {
1138
+ await this._ctx.dispose();
1139
+ }
1140
+ };
1141
+ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1142
+ constructor(_callbacks) {
1143
+ super({
1144
+ requested: {
1145
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1146
+ },
1147
+ exposed: {
1148
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1149
+ }
1150
+ });
1151
+ this._callbacks = _callbacks;
1152
+ this._ctx = new import_context3.Context();
1153
+ this._remoteOptionsTrigger = new import_async6.Trigger();
1154
+ }
1155
+ async getHandlers() {
1156
+ return {
1157
+ InvitationHostService: {
1158
+ options: async (options) => {
1159
+ (0, import_node_assert5.default)(!this._remoteOptions, "Remote options already set.");
1160
+ this._remoteOptions = options;
1161
+ this._remoteOptionsTrigger.wake();
1162
+ },
1163
+ introduce: () => {
1164
+ throw new Error("Method not allowed.");
1165
+ },
1166
+ authenticate: () => {
1167
+ throw new Error("Method not allowed.");
1168
+ },
1169
+ admit: () => {
1170
+ throw new Error("Method not allowed.");
1171
+ }
1172
+ }
1173
+ };
1174
+ }
1175
+ async onOpen(context) {
1176
+ var _a;
1177
+ await super.onOpen(context);
1178
+ try {
1179
+ (0, import_log4.log)("begin options", {}, {
1180
+ file: "invitation-extension.ts",
1181
+ line: 189,
1182
+ scope: this,
1183
+ callSite: (f, a) => f(...a)
1184
+ });
1185
+ await (0, import_context3.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1186
+ role: import_invitations.Options.Role.GUEST
1187
+ }));
1188
+ await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1189
+ timeout: OPTIONS_TIMEOUT
1190
+ }));
1191
+ (0, import_log4.log)("end options", {}, {
1192
+ file: "invitation-extension.ts",
1193
+ line: 192,
1194
+ scope: this,
1195
+ callSite: (f, a) => f(...a)
1196
+ });
1197
+ if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.HOST) {
1198
+ throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1199
+ expected: import_invitations.Options.Role.HOST,
1200
+ remoteOptions: this._remoteOptions
1201
+ });
1202
+ }
1203
+ this._callbacks.onOpen(this._ctx);
1204
+ } catch (err) {
1205
+ (0, import_log4.log)("openError", err, {
1206
+ file: "invitation-extension.ts",
1207
+ line: 202,
1208
+ scope: this,
1209
+ callSite: (f, a) => f(...a)
1210
+ });
1211
+ this._callbacks.onError(err);
1212
+ }
1213
+ }
1214
+ async onClose() {
1215
+ (0, import_log4.log)("onClose", {}, {
1216
+ file: "invitation-extension.ts",
1217
+ line: 208,
1218
+ scope: this,
1219
+ callSite: (f, a) => f(...a)
1220
+ });
1221
+ await this._ctx.dispose();
1222
+ }
1223
+ };
1224
+
1225
+ // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1008
1226
  var MAX_OTP_ATTEMPTS = 3;
1009
1227
  var InvitationsHandler = class {
1010
1228
  constructor(_networkManager) {
@@ -1012,9 +1230,9 @@ var InvitationsHandler = class {
1012
1230
  }
1013
1231
  createInvitation(protocol, options) {
1014
1232
  var _a;
1015
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services2.Invitation.Type.INTERACTIVE, authMethod = import_services2.Invitation.AuthMethod.SHARED_SECRET, state = import_services2.Invitation.State.INIT, timeout = import_client.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random() } = options != null ? options : {};
1233
+ const { invitationId = import_keys6.PublicKey.random().toHex(), type = import_services2.Invitation.Type.INTERACTIVE, authMethod = import_services2.Invitation.AuthMethod.SHARED_SECRET, state = import_services2.Invitation.State.INIT, timeout = import_client.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options != null ? options : {};
1016
1234
  const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services2.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client.AUTHENTICATION_CODE_LENGTH) : void 0;
1017
- (0, import_node_assert5.default)(protocol);
1235
+ (0, import_node_assert6.default)(protocol);
1018
1236
  const invitation = {
1019
1237
  invitationId,
1020
1238
  type,
@@ -1025,37 +1243,37 @@ var InvitationsHandler = class {
1025
1243
  timeout,
1026
1244
  ...protocol.getInvitationContext()
1027
1245
  };
1028
- const stream = new import_async6.PushStream();
1029
- const ctx = new import_context3.Context({
1246
+ const stream = new import_async7.PushStream();
1247
+ const ctx = new import_context4.Context({
1030
1248
  onError: (err) => {
1031
1249
  void ctx.dispose();
1032
1250
  stream.error(err);
1033
1251
  }
1034
1252
  });
1035
1253
  ctx.onDispose(() => {
1036
- (0, import_log4.log)("complete", {
1254
+ (0, import_log5.log)("complete", {
1037
1255
  ...protocol.toJSON()
1038
1256
  }, {
1039
1257
  file: "invitations-handler.ts",
1040
- line: 106,
1258
+ line: 99,
1041
1259
  scope: this,
1042
1260
  callSite: (f, a) => f(...a)
1043
1261
  });
1044
1262
  stream.complete();
1045
1263
  });
1046
1264
  const createExtension = () => {
1047
- const success = new import_async6.Trigger();
1265
+ const success = new import_async7.Trigger();
1048
1266
  let guestProfile;
1049
1267
  let authenticationPassed = false;
1050
1268
  let authenticationRetry = 0;
1051
1269
  const extension = new InvitationHostExtension({
1052
1270
  introduce: async ({ profile }) => {
1053
- (0, import_log4.log)("guest introduced itself", {
1271
+ (0, import_log5.log)("guest introduced itself", {
1054
1272
  guestProfile: profile,
1055
1273
  ...protocol.toJSON()
1056
1274
  }, {
1057
1275
  file: "invitations-handler.ts",
1058
- line: 119,
1276
+ line: 112,
1059
1277
  scope: this,
1060
1278
  callSite: (f, a) => f(...a)
1061
1279
  });
@@ -1070,33 +1288,33 @@ var InvitationsHandler = class {
1070
1288
  };
1071
1289
  },
1072
1290
  authenticate: async ({ authCode: code }) => {
1073
- (0, import_log4.log)("received authentication request", {
1291
+ (0, import_log5.log)("received authentication request", {
1074
1292
  authCode: code
1075
1293
  }, {
1076
1294
  file: "invitations-handler.ts",
1077
- line: 138,
1295
+ line: 131,
1078
1296
  scope: this,
1079
1297
  callSite: (f, a) => f(...a)
1080
1298
  });
1081
- let status = import_invitations.AuthenticationResponse.Status.OK;
1299
+ let status = import_invitations2.AuthenticationResponse.Status.OK;
1082
1300
  switch (invitation.authMethod) {
1083
1301
  case import_services2.Invitation.AuthMethod.NONE: {
1084
- (0, import_log4.log)("authentication not required", {}, {
1302
+ (0, import_log5.log)("authentication not required", {}, {
1085
1303
  file: "invitations-handler.ts",
1086
- line: 143,
1304
+ line: 136,
1087
1305
  scope: this,
1088
1306
  callSite: (f, a) => f(...a)
1089
1307
  });
1090
1308
  return {
1091
- status: import_invitations.AuthenticationResponse.Status.OK
1309
+ status: import_invitations2.AuthenticationResponse.Status.OK
1092
1310
  };
1093
1311
  }
1094
1312
  case import_services2.Invitation.AuthMethod.SHARED_SECRET: {
1095
1313
  if (invitation.authCode) {
1096
1314
  if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1097
- status = import_invitations.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1315
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1098
1316
  } else if (code !== invitation.authCode) {
1099
- status = import_invitations.AuthenticationResponse.Status.INVALID_OTP;
1317
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
1100
1318
  } else {
1101
1319
  authenticationPassed = true;
1102
1320
  }
@@ -1104,15 +1322,15 @@ var InvitationsHandler = class {
1104
1322
  break;
1105
1323
  }
1106
1324
  default: {
1107
- import_log4.log.error("invalid authentication method", {
1325
+ import_log5.log.error("invalid authentication method", {
1108
1326
  authMethod: invitation.authMethod
1109
1327
  }, {
1110
1328
  file: "invitations-handler.ts",
1111
- line: 161,
1329
+ line: 154,
1112
1330
  scope: this,
1113
1331
  callSite: (f, a) => f(...a)
1114
1332
  });
1115
- status = import_invitations.AuthenticationResponse.Status.INTERNAL_ERROR;
1333
+ status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1116
1334
  break;
1117
1335
  }
1118
1336
  }
@@ -1127,7 +1345,7 @@ var InvitationsHandler = class {
1127
1345
  throw new Error("Not authenticated");
1128
1346
  }
1129
1347
  const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1130
- (0, import_node_assert5.default)(deviceKey);
1348
+ (0, import_node_assert6.default)(deviceKey);
1131
1349
  const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
1132
1350
  success.wake(deviceKey);
1133
1351
  return admissionResponse;
@@ -1137,23 +1355,23 @@ var InvitationsHandler = class {
1137
1355
  }
1138
1356
  },
1139
1357
  onOpen: () => {
1140
- (0, import_async6.scheduleTask)(ctx, async () => {
1141
- const traceId = import_keys5.PublicKey.random().toHex();
1358
+ (0, import_async7.scheduleTask)(ctx, async () => {
1359
+ const traceId = import_keys6.PublicKey.random().toHex();
1142
1360
  try {
1143
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.begin({
1361
+ import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1144
1362
  id: traceId,
1145
1363
  parentId: this._traceParent
1146
1364
  }), {
1147
1365
  file: "invitations-handler.ts",
1148
- line: 196,
1366
+ line: 189,
1149
1367
  scope: this,
1150
1368
  callSite: (f, a) => f(...a)
1151
1369
  });
1152
- (0, import_log4.log)("connected", {
1370
+ (0, import_log5.log)("connected", {
1153
1371
  ...protocol.toJSON()
1154
1372
  }, {
1155
1373
  file: "invitations-handler.ts",
1156
- line: 200,
1374
+ line: 193,
1157
1375
  scope: this,
1158
1376
  callSite: (f, a) => f(...a)
1159
1377
  });
@@ -1164,12 +1382,12 @@ var InvitationsHandler = class {
1164
1382
  const deviceKey = await success.wait({
1165
1383
  timeout
1166
1384
  });
1167
- (0, import_log4.log)("admitted guest", {
1385
+ (0, import_log5.log)("admitted guest", {
1168
1386
  guest: deviceKey,
1169
1387
  ...protocol.toJSON()
1170
1388
  }, {
1171
1389
  file: "invitations-handler.ts",
1172
- line: 203,
1390
+ line: 196,
1173
1391
  scope: this,
1174
1392
  callSite: (f, a) => f(...a)
1175
1393
  });
@@ -1177,21 +1395,21 @@ var InvitationsHandler = class {
1177
1395
  ...invitation,
1178
1396
  state: import_services2.Invitation.State.SUCCESS
1179
1397
  });
1180
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.end({
1398
+ import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1181
1399
  id: traceId
1182
1400
  }), {
1183
1401
  file: "invitations-handler.ts",
1184
- line: 205,
1402
+ line: 198,
1185
1403
  scope: this,
1186
1404
  callSite: (f, a) => f(...a)
1187
1405
  });
1188
1406
  } catch (err) {
1189
- if (err instanceof import_async6.TimeoutError) {
1190
- (0, import_log4.log)("timeout", {
1407
+ if (err instanceof import_async7.TimeoutError) {
1408
+ (0, import_log5.log)("timeout", {
1191
1409
  ...protocol.toJSON()
1192
1410
  }, {
1193
1411
  file: "invitations-handler.ts",
1194
- line: 208,
1412
+ line: 201,
1195
1413
  scope: this,
1196
1414
  callSite: (f, a) => f(...a)
1197
1415
  });
@@ -1200,36 +1418,63 @@ var InvitationsHandler = class {
1200
1418
  state: import_services2.Invitation.State.TIMEOUT
1201
1419
  });
1202
1420
  } else {
1203
- import_log4.log.error("failed", err, {
1421
+ import_log5.log.error("failed", err, {
1204
1422
  file: "invitations-handler.ts",
1205
- line: 211,
1423
+ line: 204,
1206
1424
  scope: this,
1207
1425
  callSite: (f, a) => f(...a)
1208
1426
  });
1209
1427
  stream.error(err);
1210
1428
  }
1211
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.error({
1429
+ import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1212
1430
  id: traceId,
1213
1431
  error: err
1214
1432
  }), {
1215
1433
  file: "invitations-handler.ts",
1216
- line: 214,
1434
+ line: 207,
1217
1435
  scope: this,
1218
1436
  callSite: (f, a) => f(...a)
1219
1437
  });
1220
1438
  } finally {
1221
1439
  if (type !== import_services2.Invitation.Type.MULTIUSE) {
1222
- await (0, import_async6.sleep)(import_client.ON_CLOSE_DELAY);
1440
+ await (0, import_async7.sleep)(import_client.ON_CLOSE_DELAY);
1223
1441
  await ctx.dispose();
1224
1442
  }
1225
1443
  }
1226
1444
  });
1445
+ },
1446
+ onError: (err) => {
1447
+ if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
1448
+ return;
1449
+ }
1450
+ if (err instanceof import_async7.TimeoutError) {
1451
+ (0, import_log5.log)("timeout", {
1452
+ ...protocol.toJSON()
1453
+ }, {
1454
+ file: "invitations-handler.ts",
1455
+ line: 221,
1456
+ scope: this,
1457
+ callSite: (f, a) => f(...a)
1458
+ });
1459
+ stream.next({
1460
+ ...invitation,
1461
+ state: import_services2.Invitation.State.TIMEOUT
1462
+ });
1463
+ } else {
1464
+ import_log5.log.error("failed", err, {
1465
+ file: "invitations-handler.ts",
1466
+ line: 224,
1467
+ scope: this,
1468
+ callSite: (f, a) => f(...a)
1469
+ });
1470
+ stream.error(err);
1471
+ }
1227
1472
  }
1228
1473
  });
1229
1474
  extension._traceParent = this._traceParent;
1230
1475
  return extension;
1231
1476
  };
1232
- (0, import_async6.scheduleTask)(ctx, async () => {
1477
+ (0, import_async7.scheduleTask)(ctx, async () => {
1233
1478
  const topic = invitation.swarmKey;
1234
1479
  const swarmConnection = await this._networkManager.joinSwarm({
1235
1480
  topic,
@@ -1260,28 +1505,36 @@ var InvitationsHandler = class {
1260
1505
  }
1261
1506
  acceptInvitation(protocol, invitation) {
1262
1507
  const { timeout = import_client.INVITATION_TIMEOUT } = invitation;
1263
- (0, import_node_assert5.default)(protocol);
1264
- const authenticated = new import_async6.Trigger();
1265
- const stream = new import_async6.PushStream();
1266
- const ctx = new import_context3.Context({
1508
+ (0, import_node_assert6.default)(protocol);
1509
+ const authenticated = new import_async7.Trigger();
1510
+ let currentState;
1511
+ const stream = new import_async7.PushStream();
1512
+ const setState = (newData) => {
1513
+ (0, import_node_assert6.default)(newData.state !== void 0);
1514
+ currentState = newData.state;
1515
+ stream.next({
1516
+ ...invitation,
1517
+ ...newData
1518
+ });
1519
+ };
1520
+ const ctx = new import_context4.Context({
1267
1521
  onError: (err) => {
1268
- if (err instanceof import_async6.TimeoutError) {
1269
- (0, import_log4.log)("timeout", {
1522
+ if (err instanceof import_async7.TimeoutError) {
1523
+ (0, import_log5.log)("timeout", {
1270
1524
  ...protocol.toJSON()
1271
1525
  }, {
1272
1526
  file: "invitations-handler.ts",
1273
- line: 267,
1527
+ line: 279,
1274
1528
  scope: this,
1275
1529
  callSite: (f, a) => f(...a)
1276
1530
  });
1277
- stream.next({
1278
- ...invitation,
1531
+ setState({
1279
1532
  state: import_services2.Invitation.State.TIMEOUT
1280
1533
  });
1281
1534
  } else {
1282
- import_log4.log.warn("auth failed", err, {
1535
+ import_log5.log.warn("auth failed", err, {
1283
1536
  file: "invitations-handler.ts",
1284
- line: 270,
1537
+ line: 282,
1285
1538
  scope: this,
1286
1539
  callSite: (f, a) => f(...a)
1287
1540
  });
@@ -1291,11 +1544,11 @@ var InvitationsHandler = class {
1291
1544
  }
1292
1545
  });
1293
1546
  ctx.onDispose(() => {
1294
- (0, import_log4.log)("complete", {
1547
+ (0, import_log5.log)("complete", {
1295
1548
  ...protocol.toJSON()
1296
1549
  }, {
1297
1550
  file: "invitations-handler.ts",
1298
- line: 278,
1551
+ line: 290,
1299
1552
  scope: this,
1300
1553
  callSite: (f, a) => f(...a)
1301
1554
  });
@@ -1304,50 +1557,62 @@ var InvitationsHandler = class {
1304
1557
  const createExtension = () => {
1305
1558
  let connectionCount = 0;
1306
1559
  const extension = new InvitationGuestExtension({
1307
- onOpen: () => {
1308
- (0, import_async6.scheduleTask)(ctx, async () => {
1309
- const traceId = import_keys5.PublicKey.random().toHex();
1560
+ onOpen: (extensionCtx) => {
1561
+ extensionCtx.onDispose(async () => {
1562
+ (0, import_log5.log)("extension disposed", {
1563
+ currentState
1564
+ }, {
1565
+ file: "invitations-handler.ts",
1566
+ line: 300,
1567
+ scope: this,
1568
+ callSite: (f, a) => f(...a)
1569
+ });
1570
+ if (currentState !== import_services2.Invitation.State.SUCCESS) {
1571
+ stream.error(new Error("Remote peer disconnected."));
1572
+ }
1573
+ });
1574
+ (0, import_async7.scheduleTask)(ctx, async () => {
1575
+ const traceId = import_keys6.PublicKey.random().toHex();
1310
1576
  try {
1311
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.begin({
1577
+ import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
1312
1578
  id: traceId,
1313
1579
  parentId: this._traceParent
1314
1580
  }), {
1315
1581
  file: "invitations-handler.ts",
1316
- line: 290,
1582
+ line: 309,
1317
1583
  scope: this,
1318
1584
  callSite: (f, a) => f(...a)
1319
1585
  });
1320
1586
  if (++connectionCount > 1) {
1321
1587
  throw new Error(`multiple connections detected: ${connectionCount}`);
1322
1588
  }
1323
- (0, import_async6.scheduleTask)(ctx, () => ctx.raise(new import_async6.TimeoutError(timeout)), timeout);
1324
- (0, import_log4.log)("connected", {
1589
+ (0, import_async7.scheduleTask)(ctx, () => ctx.raise(new import_async7.TimeoutError(timeout)), timeout);
1590
+ (0, import_log5.log)("connected", {
1325
1591
  ...protocol.toJSON()
1326
1592
  }, {
1327
1593
  file: "invitations-handler.ts",
1328
- line: 301,
1594
+ line: 320,
1329
1595
  scope: this,
1330
1596
  callSite: (f, a) => f(...a)
1331
1597
  });
1332
- stream.next({
1333
- ...invitation,
1598
+ setState({
1334
1599
  state: import_services2.Invitation.State.CONNECTED
1335
1600
  });
1336
- (0, import_log4.log)("introduce", {
1601
+ (0, import_log5.log)("introduce", {
1337
1602
  ...protocol.toJSON()
1338
1603
  }, {
1339
1604
  file: "invitations-handler.ts",
1340
- line: 305,
1605
+ line: 324,
1341
1606
  scope: this,
1342
1607
  callSite: (f, a) => f(...a)
1343
1608
  });
1344
1609
  const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
1345
- (0, import_log4.log)("introduce response", {
1610
+ (0, import_log5.log)("introduce response", {
1346
1611
  ...protocol.toJSON(),
1347
1612
  response: introductionResponse
1348
1613
  }, {
1349
1614
  file: "invitations-handler.ts",
1350
- line: 309,
1615
+ line: 328,
1351
1616
  scope: this,
1352
1617
  callSite: (f, a) => f(...a)
1353
1618
  });
@@ -1357,44 +1622,42 @@ var InvitationsHandler = class {
1357
1622
  }
1358
1623
  if (isAuthenticationRequired(invitation)) {
1359
1624
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1360
- (0, import_log4.log)("guest waiting for authentication code...", {}, {
1625
+ (0, import_log5.log)("guest waiting for authentication code...", {}, {
1361
1626
  file: "invitations-handler.ts",
1362
- line: 318,
1627
+ line: 337,
1363
1628
  scope: this,
1364
1629
  callSite: (f, a) => f(...a)
1365
1630
  });
1366
- stream.next({
1367
- ...invitation,
1631
+ setState({
1368
1632
  state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
1369
1633
  });
1370
1634
  const authCode = await authenticated.wait({
1371
1635
  timeout
1372
1636
  });
1373
- (0, import_log4.log)("sending authentication request", {}, {
1637
+ (0, import_log5.log)("sending authentication request", {}, {
1374
1638
  file: "invitations-handler.ts",
1375
- line: 322,
1639
+ line: 341,
1376
1640
  scope: this,
1377
1641
  callSite: (f, a) => f(...a)
1378
1642
  });
1379
- stream.next({
1380
- ...invitation,
1643
+ setState({
1381
1644
  state: import_services2.Invitation.State.AUTHENTICATING
1382
1645
  });
1383
1646
  const response = await extension.rpc.InvitationHostService.authenticate({
1384
1647
  authCode
1385
1648
  });
1386
- if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
1649
+ if (response.status === void 0 || response.status === import_invitations2.AuthenticationResponse.Status.OK) {
1387
1650
  break;
1388
1651
  }
1389
- if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
1652
+ if (response.status === import_invitations2.AuthenticationResponse.Status.INVALID_OTP) {
1390
1653
  if (attempt === MAX_OTP_ATTEMPTS) {
1391
1654
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1392
1655
  } else {
1393
- (0, import_log4.log)("retrying invalid code", {
1656
+ (0, import_log5.log)("retrying invalid code", {
1394
1657
  attempt
1395
1658
  }, {
1396
1659
  file: "invitations-handler.ts",
1397
- line: 333,
1660
+ line: 352,
1398
1661
  scope: this,
1399
1662
  callSite: (f, a) => f(...a)
1400
1663
  });
@@ -1403,72 +1666,69 @@ var InvitationsHandler = class {
1403
1666
  }
1404
1667
  }
1405
1668
  } else {
1406
- stream.next({
1407
- ...invitation,
1669
+ setState({
1408
1670
  state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
1409
1671
  });
1410
1672
  }
1411
- (0, import_log4.log)("request admission", {
1673
+ (0, import_log5.log)("request admission", {
1412
1674
  ...protocol.toJSON()
1413
1675
  }, {
1414
1676
  file: "invitations-handler.ts",
1415
- line: 344,
1677
+ line: 363,
1416
1678
  scope: this,
1417
1679
  callSite: (f, a) => f(...a)
1418
1680
  });
1419
1681
  const admissionRequest = await protocol.createAdmissionRequest();
1420
1682
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
1421
1683
  const result = await protocol.accept(admissionResponse, admissionRequest);
1422
- (0, import_log4.log)("admitted by host", {
1684
+ (0, import_log5.log)("admitted by host", {
1423
1685
  ...protocol.toJSON()
1424
1686
  }, {
1425
1687
  file: "invitations-handler.ts",
1426
- line: 352,
1688
+ line: 371,
1427
1689
  scope: this,
1428
1690
  callSite: (f, a) => f(...a)
1429
1691
  });
1430
- stream.next({
1431
- ...invitation,
1692
+ setState({
1432
1693
  ...result,
1433
1694
  state: import_services2.Invitation.State.SUCCESS
1434
1695
  });
1435
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.end({
1696
+ import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
1436
1697
  id: traceId
1437
1698
  }), {
1438
1699
  file: "invitations-handler.ts",
1439
- line: 354,
1700
+ line: 373,
1440
1701
  scope: this,
1441
1702
  callSite: (f, a) => f(...a)
1442
1703
  });
1443
1704
  } catch (err) {
1444
- if (err instanceof import_async6.TimeoutError) {
1445
- (0, import_log4.log)("timeout", {
1705
+ if (err instanceof import_async7.TimeoutError) {
1706
+ (0, import_log5.log)("timeout", {
1446
1707
  ...protocol.toJSON()
1447
1708
  }, {
1448
1709
  file: "invitations-handler.ts",
1449
- line: 357,
1710
+ line: 376,
1450
1711
  scope: this,
1451
1712
  callSite: (f, a) => f(...a)
1452
1713
  });
1453
- stream.next({
1454
- ...invitation,
1714
+ setState({
1455
1715
  state: import_services2.Invitation.State.TIMEOUT
1456
1716
  });
1457
1717
  } else {
1458
- (0, import_log4.log)("auth failed", err, {
1718
+ (0, import_log5.log)("auth failed", err, {
1459
1719
  file: "invitations-handler.ts",
1460
- line: 360,
1720
+ line: 379,
1461
1721
  scope: this,
1462
1722
  callSite: (f, a) => f(...a)
1463
1723
  });
1464
1724
  stream.error(err);
1465
1725
  }
1466
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.error({
1726
+ import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
1467
1727
  id: traceId,
1468
1728
  error: err
1469
1729
  }), {
1470
1730
  file: "invitations-handler.ts",
1471
- line: 363,
1731
+ line: 382,
1472
1732
  scope: this,
1473
1733
  callSite: (f, a) => f(...a)
1474
1734
  });
@@ -1476,24 +1736,49 @@ var InvitationsHandler = class {
1476
1736
  await ctx.dispose();
1477
1737
  }
1478
1738
  });
1739
+ },
1740
+ onError: (err) => {
1741
+ if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
1742
+ return;
1743
+ }
1744
+ if (err instanceof import_async7.TimeoutError) {
1745
+ (0, import_log5.log)("timeout", {
1746
+ ...protocol.toJSON()
1747
+ }, {
1748
+ file: "invitations-handler.ts",
1749
+ line: 393,
1750
+ scope: this,
1751
+ callSite: (f, a) => f(...a)
1752
+ });
1753
+ setState({
1754
+ state: import_services2.Invitation.State.TIMEOUT
1755
+ });
1756
+ } else {
1757
+ (0, import_log5.log)("auth failed", err, {
1758
+ file: "invitations-handler.ts",
1759
+ line: 396,
1760
+ scope: this,
1761
+ callSite: (f, a) => f(...a)
1762
+ });
1763
+ stream.error(err);
1764
+ }
1479
1765
  }
1480
1766
  });
1481
1767
  return extension;
1482
1768
  };
1483
- (0, import_async6.scheduleTask)(ctx, async () => {
1484
- (0, import_node_assert5.default)(invitation.swarmKey);
1769
+ (0, import_async7.scheduleTask)(ctx, async () => {
1770
+ (0, import_node_assert6.default)(invitation.swarmKey);
1485
1771
  const topic = invitation.swarmKey;
1486
1772
  const swarmConnection = await this._networkManager.joinSwarm({
1487
1773
  topic,
1488
- peerId: import_keys5.PublicKey.random(),
1774
+ peerId: import_keys6.PublicKey.random(),
1489
1775
  protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
1490
1776
  teleport.addExtension("dxos.halo.invitations", createExtension());
1491
1777
  }),
1492
1778
  topology: new import_network_manager.StarTopology(topic)
1493
1779
  });
1494
1780
  ctx.onDispose(() => swarmConnection.close());
1495
- stream.next({
1496
- ...invitation,
1781
+ setState({
1497
1782
  state: import_services2.Invitation.State.CONNECTING
1498
1783
  });
1499
1784
  });
@@ -1501,8 +1786,7 @@ var InvitationsHandler = class {
1501
1786
  initialInvitation: invitation,
1502
1787
  subscriber: stream.observable,
1503
1788
  onCancel: async () => {
1504
- stream.next({
1505
- ...invitation,
1789
+ setState({
1506
1790
  state: import_services2.Invitation.State.CANCELLED
1507
1791
  });
1508
1792
  await ctx.dispose();
@@ -1515,119 +1799,12 @@ var InvitationsHandler = class {
1515
1799
  }
1516
1800
  };
1517
1801
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services2.Invitation.AuthMethod.NONE;
1518
- var InvitationHostExtension = class extends import_teleport.RpcExtension {
1519
- constructor(_callbacks) {
1520
- super({
1521
- exposed: {
1522
- InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1523
- }
1524
- });
1525
- this._callbacks = _callbacks;
1526
- }
1527
- async getHandlers() {
1528
- return {
1529
- // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1530
- // Perhaps in the future we will have more complex logic here.
1531
- InvitationHostService: {
1532
- introduce: async (request) => {
1533
- const traceId = import_keys5.PublicKey.random().toHex();
1534
- import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
1535
- id: traceId,
1536
- parentId: this._traceParent
1537
- }), {
1538
- file: "invitations-handler.ts",
1539
- line: 442,
1540
- scope: this,
1541
- callSite: (f, a) => f(...a)
1542
- });
1543
- const response = await this._callbacks.introduce(request);
1544
- import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
1545
- id: traceId
1546
- }), {
1547
- file: "invitations-handler.ts",
1548
- line: 447,
1549
- scope: this,
1550
- callSite: (f, a) => f(...a)
1551
- });
1552
- return response;
1553
- },
1554
- authenticate: async (request) => {
1555
- const traceId = import_keys5.PublicKey.random().toHex();
1556
- import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
1557
- id: traceId,
1558
- parentId: this._traceParent
1559
- }), {
1560
- file: "invitations-handler.ts",
1561
- line: 453,
1562
- scope: this,
1563
- callSite: (f, a) => f(...a)
1564
- });
1565
- const response = await this._callbacks.authenticate(request);
1566
- import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.end({
1567
- id: traceId,
1568
- data: {
1569
- ...response
1570
- }
1571
- }), {
1572
- file: "invitations-handler.ts",
1573
- line: 458,
1574
- scope: this,
1575
- callSite: (f, a) => f(...a)
1576
- });
1577
- return response;
1578
- },
1579
- admit: async (request) => {
1580
- const traceId = import_keys5.PublicKey.random().toHex();
1581
- import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
1582
- id: traceId,
1583
- parentId: this._traceParent
1584
- }), {
1585
- file: "invitations-handler.ts",
1586
- line: 464,
1587
- scope: this,
1588
- callSite: (f, a) => f(...a)
1589
- });
1590
- const response = await this._callbacks.admit(request);
1591
- import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
1592
- id: traceId
1593
- }), {
1594
- file: "invitations-handler.ts",
1595
- line: 469,
1596
- scope: this,
1597
- callSite: (f, a) => f(...a)
1598
- });
1599
- return response;
1600
- }
1601
- }
1602
- };
1603
- }
1604
- async onOpen(context) {
1605
- await super.onOpen(context);
1606
- this._callbacks.onOpen();
1607
- }
1608
- };
1609
- var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1610
- constructor(_callbacks) {
1611
- super({
1612
- requested: {
1613
- InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1614
- }
1615
- });
1616
- this._callbacks = _callbacks;
1617
- }
1618
- async getHandlers() {
1619
- return {};
1620
- }
1621
- async onOpen(context) {
1622
- await super.onOpen(context);
1623
- this._callbacks.onOpen();
1624
- }
1625
- };
1626
1802
 
1627
1803
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1628
- var import_node_assert6 = __toESM(require("node:assert"));
1804
+ var import_node_assert7 = __toESM(require("node:assert"));
1805
+ var import_async8 = require("@dxos/async");
1629
1806
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
1630
- var import_log5 = require("@dxos/log");
1807
+ var import_log6 = require("@dxos/log");
1631
1808
  var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1632
1809
  var InvitationsServiceImpl = class {
1633
1810
  constructor(_invitationsHandler, _getHandler) {
@@ -1635,203 +1812,74 @@ var InvitationsServiceImpl = class {
1635
1812
  this._getHandler = _getHandler;
1636
1813
  this._createInvitations = /* @__PURE__ */ new Map();
1637
1814
  this._acceptInvitations = /* @__PURE__ */ new Map();
1815
+ this._invitationCreated = new import_async8.Event();
1816
+ this._invitationAccepted = new import_async8.Event();
1817
+ this._removedCreated = new import_async8.Event();
1818
+ this._removedAccepted = new import_async8.Event();
1638
1819
  }
1639
1820
  // TODO(burdon): Guest/host label.
1640
1821
  getLoggingContext() {
1641
1822
  return {};
1642
1823
  }
1643
- createInvitation(invitation) {
1824
+ createInvitation(options) {
1825
+ let invitation;
1826
+ const existingInvitation = this._createInvitations.get(options.invitationId);
1827
+ if (existingInvitation) {
1828
+ invitation = existingInvitation;
1829
+ } else {
1830
+ const handler = this._getHandler(options);
1831
+ invitation = this._invitationsHandler.createInvitation(handler, options);
1832
+ this._createInvitations.set(invitation.get().invitationId, invitation);
1833
+ this._invitationCreated.emit(invitation.get());
1834
+ }
1644
1835
  return new import_codec_protobuf7.Stream(({ next, close }) => {
1645
- const handler = this._getHandler(invitation);
1646
- (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1647
- file: "invitations-service.ts",
1648
- line: 37,
1649
- scope: this,
1650
- callSite: (f, a) => f(...a)
1651
- });
1652
- let invitationId;
1653
- const observable = this._invitationsHandler.createInvitation(handler, invitation);
1654
- observable.subscribe((invitation2) => {
1655
- switch (invitation2.state) {
1656
- case import_services3.Invitation.State.CONNECTING: {
1657
- (0, import_node_assert6.default)(invitation2.invitationId);
1658
- invitationId = invitation2.invitationId;
1659
- this._createInvitations.set(invitation2.invitationId, observable);
1660
- invitation2.state = import_services3.Invitation.State.CONNECTING;
1661
- next(invitation2);
1662
- break;
1663
- }
1664
- case import_services3.Invitation.State.CONNECTED: {
1665
- (0, import_node_assert6.default)(invitation2.invitationId);
1666
- invitation2.state = import_services3.Invitation.State.CONNECTED;
1667
- next(invitation2);
1668
- break;
1669
- }
1670
- case import_services3.Invitation.State.READY_FOR_AUTHENTICATION: {
1671
- (0, import_node_assert6.default)(invitation2.invitationId);
1672
- invitation2.state = import_services3.Invitation.State.READY_FOR_AUTHENTICATION;
1673
- next(invitation2);
1674
- break;
1675
- }
1676
- case import_services3.Invitation.State.AUTHENTICATING: {
1677
- (0, import_node_assert6.default)(invitation2.invitationId);
1678
- invitation2.state = import_services3.Invitation.State.AUTHENTICATING;
1679
- next(invitation2);
1680
- break;
1681
- }
1682
- case import_services3.Invitation.State.SUCCESS: {
1683
- (0, import_node_assert6.default)(invitation2.invitationId);
1684
- invitation2.state = import_services3.Invitation.State.SUCCESS;
1685
- next(invitation2);
1686
- break;
1687
- }
1688
- case import_services3.Invitation.State.CANCELLED: {
1689
- (0, import_node_assert6.default)(invitationId);
1690
- invitation2.invitationId = invitationId;
1691
- invitation2.state = import_services3.Invitation.State.CANCELLED;
1692
- next(invitation2);
1693
- break;
1694
- }
1695
- case import_services3.Invitation.State.TIMEOUT: {
1696
- (0, import_node_assert6.default)(invitationId);
1697
- invitation2.invitationId = invitationId;
1698
- invitation2.state = import_services3.Invitation.State.TIMEOUT;
1699
- next(invitation2);
1700
- break;
1701
- }
1702
- }
1836
+ invitation.subscribe((invitation2) => {
1837
+ next(invitation2);
1703
1838
  }, (err) => {
1704
1839
  close(err);
1705
1840
  }, () => {
1706
1841
  close();
1842
+ this._createInvitations.delete(invitation.get().invitationId);
1707
1843
  });
1708
- return (err) => {
1709
- const context = this.getLoggingContext();
1710
- if (err) {
1711
- import_log5.log.warn("stream closed", {
1712
- ...context,
1713
- err
1714
- }, {
1715
- file: "invitations-service.ts",
1716
- line: 103,
1717
- scope: this,
1718
- callSite: (f, a) => f(...a)
1719
- });
1720
- } else {
1721
- (0, import_log5.log)("stream closed", context, {
1722
- file: "invitations-service.ts",
1723
- line: 105,
1724
- scope: this,
1725
- callSite: (f, a) => f(...a)
1726
- });
1727
- }
1728
- this._createInvitations.delete(invitation.invitationId);
1729
- };
1730
1844
  });
1731
1845
  }
1732
- acceptInvitation(invitation) {
1846
+ acceptInvitation(options) {
1847
+ let invitation;
1848
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
1849
+ if (existingInvitation) {
1850
+ invitation = existingInvitation;
1851
+ } else {
1852
+ const handler = this._getHandler(options);
1853
+ invitation = this._invitationsHandler.acceptInvitation(handler, options);
1854
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
1855
+ this._invitationAccepted.emit(invitation.get());
1856
+ }
1733
1857
  return new import_codec_protobuf7.Stream(({ next, close }) => {
1734
- (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1735
- file: "invitations-service.ts",
1736
- line: 115,
1737
- scope: this,
1738
- callSite: (f, a) => f(...a)
1739
- });
1740
- const handler = this._getHandler(invitation);
1741
- let invitationId;
1742
- const observable = this._invitationsHandler.acceptInvitation(handler, invitation);
1743
- observable.subscribe((invitation2) => {
1744
- switch (invitation2.state) {
1745
- case import_services3.Invitation.State.CONNECTING: {
1746
- (0, import_node_assert6.default)(invitation2.invitationId);
1747
- invitationId = invitation2.invitationId;
1748
- this._acceptInvitations.set(invitation2.invitationId, observable);
1749
- invitation2.state = import_services3.Invitation.State.CONNECTING;
1750
- next(invitation2);
1751
- break;
1752
- }
1753
- case import_services3.Invitation.State.CONNECTED: {
1754
- (0, import_node_assert6.default)(invitation2.invitationId);
1755
- invitation2.state = import_services3.Invitation.State.CONNECTED;
1756
- next(invitation2);
1757
- break;
1758
- }
1759
- case import_services3.Invitation.State.READY_FOR_AUTHENTICATION: {
1760
- (0, import_node_assert6.default)(invitation2.invitationId);
1761
- invitation2.state = import_services3.Invitation.State.READY_FOR_AUTHENTICATION;
1762
- next(invitation2);
1763
- break;
1764
- }
1765
- case import_services3.Invitation.State.AUTHENTICATING: {
1766
- (0, import_node_assert6.default)(invitation2.invitationId);
1767
- invitation2.state = import_services3.Invitation.State.AUTHENTICATING;
1768
- next(invitation2);
1769
- break;
1770
- }
1771
- case import_services3.Invitation.State.SUCCESS: {
1772
- invitation2.state = import_services3.Invitation.State.SUCCESS;
1773
- next(invitation2);
1774
- break;
1775
- }
1776
- case import_services3.Invitation.State.CANCELLED: {
1777
- (0, import_node_assert6.default)(invitationId);
1778
- invitation2.invitationId = invitationId;
1779
- invitation2.state = import_services3.Invitation.State.CANCELLED;
1780
- next(invitation2);
1781
- break;
1782
- }
1783
- case import_services3.Invitation.State.TIMEOUT: {
1784
- (0, import_node_assert6.default)(invitationId);
1785
- invitation2.invitationId = invitationId;
1786
- invitation2.state = import_services3.Invitation.State.TIMEOUT;
1787
- next(invitation2);
1788
- break;
1789
- }
1790
- }
1858
+ invitation.subscribe((invitation2) => {
1859
+ next(invitation2);
1791
1860
  }, (err) => {
1792
1861
  close(err);
1793
1862
  }, () => {
1794
1863
  close();
1864
+ this._acceptInvitations.delete(invitation.get().invitationId);
1795
1865
  });
1796
- return (err) => {
1797
- const context = this.getLoggingContext();
1798
- if (err) {
1799
- import_log5.log.warn("stream closed", {
1800
- ...context,
1801
- err
1802
- }, {
1803
- file: "invitations-service.ts",
1804
- line: 181,
1805
- scope: this,
1806
- callSite: (f, a) => f(...a)
1807
- });
1808
- } else {
1809
- (0, import_log5.log)("stream closed", context, {
1810
- file: "invitations-service.ts",
1811
- line: 183,
1812
- scope: this,
1813
- callSite: (f, a) => f(...a)
1814
- });
1815
- }
1816
- this._acceptInvitations.delete(invitation.invitationId);
1817
- };
1818
1866
  });
1819
1867
  }
1820
1868
  async authenticate({ invitationId, authCode }) {
1821
- (0, import_log5.log)("authenticating...", {}, {
1869
+ (0, import_log6.log)("authenticating...", {}, {
1822
1870
  file: "invitations-service.ts",
1823
- line: 192,
1871
+ line: 103,
1824
1872
  scope: this,
1825
1873
  callSite: (f, a) => f(...a)
1826
1874
  });
1827
- (0, import_node_assert6.default)(invitationId);
1875
+ (0, import_node_assert7.default)(invitationId);
1828
1876
  const observable = this._acceptInvitations.get(invitationId);
1829
1877
  if (!observable) {
1830
- import_log5.log.warn("invalid invitation", {
1878
+ import_log6.log.warn("invalid invitation", {
1831
1879
  invitationId
1832
1880
  }, {
1833
1881
  file: "invitations-service.ts",
1834
- line: 196,
1882
+ line: 107,
1835
1883
  scope: this,
1836
1884
  callSite: (f, a) => f(...a)
1837
1885
  });
@@ -1840,35 +1888,91 @@ var InvitationsServiceImpl = class {
1840
1888
  }
1841
1889
  }
1842
1890
  async cancelInvitation({ invitationId }) {
1843
- var _a;
1844
- (0, import_log5.log)("cancelling...", {}, {
1891
+ (0, import_log6.log)("deleting...", {}, {
1845
1892
  file: "invitations-service.ts",
1846
- line: 203,
1893
+ line: 114,
1847
1894
  scope: this,
1848
1895
  callSite: (f, a) => f(...a)
1849
1896
  });
1850
- (0, import_node_assert6.default)(invitationId);
1851
- const observable = (_a = this._createInvitations.get(invitationId)) != null ? _a : this._acceptInvitations.get(invitationId);
1852
- if (!observable) {
1853
- import_log5.log.warn("invalid invitation", {
1897
+ (0, import_node_assert7.default)(invitationId);
1898
+ const created = this._createInvitations.get(invitationId);
1899
+ const accepted = this._acceptInvitations.get(invitationId);
1900
+ if (created) {
1901
+ await created.cancel();
1902
+ this._createInvitations.delete(invitationId);
1903
+ this._removedCreated.emit(created.get());
1904
+ } else if (accepted) {
1905
+ await accepted.cancel();
1906
+ this._acceptInvitations.delete(invitationId);
1907
+ this._removedAccepted.emit(accepted.get());
1908
+ } else {
1909
+ import_log6.log.warn("invalid invitation", {
1854
1910
  invitationId
1855
1911
  }, {
1856
1912
  file: "invitations-service.ts",
1857
- line: 207,
1913
+ line: 127,
1858
1914
  scope: this,
1859
1915
  callSite: (f, a) => f(...a)
1860
1916
  });
1861
- } else {
1862
- await (observable == null ? void 0 : observable.cancel());
1863
1917
  }
1864
1918
  }
1919
+ queryInvitations() {
1920
+ return new import_codec_protobuf7.Stream(({ next, ctx }) => {
1921
+ this._invitationCreated.on(ctx, (invitation) => {
1922
+ next({
1923
+ action: import_services3.QueryInvitationsResponse.Action.ADDED,
1924
+ type: import_services3.QueryInvitationsResponse.Type.CREATED,
1925
+ invitations: [
1926
+ invitation
1927
+ ]
1928
+ });
1929
+ });
1930
+ this._invitationAccepted.on(ctx, (invitation) => {
1931
+ next({
1932
+ action: import_services3.QueryInvitationsResponse.Action.ADDED,
1933
+ type: import_services3.QueryInvitationsResponse.Type.ACCEPTED,
1934
+ invitations: [
1935
+ invitation
1936
+ ]
1937
+ });
1938
+ });
1939
+ this._removedCreated.on(ctx, (invitation) => {
1940
+ next({
1941
+ action: import_services3.QueryInvitationsResponse.Action.REMOVED,
1942
+ type: import_services3.QueryInvitationsResponse.Type.CREATED,
1943
+ invitations: [
1944
+ invitation
1945
+ ]
1946
+ });
1947
+ });
1948
+ this._removedAccepted.on(ctx, (invitation) => {
1949
+ next({
1950
+ action: import_services3.QueryInvitationsResponse.Action.REMOVED,
1951
+ type: import_services3.QueryInvitationsResponse.Type.ACCEPTED,
1952
+ invitations: [
1953
+ invitation
1954
+ ]
1955
+ });
1956
+ });
1957
+ next({
1958
+ action: import_services3.QueryInvitationsResponse.Action.ADDED,
1959
+ type: import_services3.QueryInvitationsResponse.Type.CREATED,
1960
+ invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
1961
+ });
1962
+ next({
1963
+ action: import_services3.QueryInvitationsResponse.Action.ADDED,
1964
+ type: import_services3.QueryInvitationsResponse.Type.ACCEPTED,
1965
+ invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
1966
+ });
1967
+ });
1968
+ }
1865
1969
  };
1866
1970
 
1867
1971
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
1868
- var import_node_assert7 = __toESM(require("node:assert"));
1972
+ var import_node_assert8 = __toESM(require("node:assert"));
1869
1973
  var import_credentials8 = require("@dxos/credentials");
1870
1974
  var import_feed_store3 = require("@dxos/feed-store");
1871
- var import_log6 = require("@dxos/log");
1975
+ var import_log7 = require("@dxos/log");
1872
1976
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1873
1977
  var SpaceInvitationProtocol = class {
1874
1978
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
@@ -1891,12 +1995,12 @@ var SpaceInvitationProtocol = class {
1891
1995
  }
1892
1996
  async admit(request, guestProfile) {
1893
1997
  var _a;
1894
- (0, import_node_assert7.default)(this._spaceKey);
1998
+ (0, import_node_assert8.default)(this._spaceKey);
1895
1999
  const space = await this._spaceManager.spaces.get(this._spaceKey);
1896
- (0, import_node_assert7.default)(space);
1897
- (0, import_node_assert7.default)(request.space);
2000
+ (0, import_node_assert8.default)(space);
2001
+ (0, import_node_assert8.default)(request.space);
1898
2002
  const { identityKey, deviceKey } = request.space;
1899
- (0, import_log6.log)("writing guest credentials", {
2003
+ (0, import_log7.log)("writing guest credentials", {
1900
2004
  host: this._signingContext.deviceKey,
1901
2005
  guest: deviceKey
1902
2006
  }, {
@@ -1906,9 +2010,9 @@ var SpaceInvitationProtocol = class {
1906
2010
  callSite: (f, a) => f(...a)
1907
2011
  });
1908
2012
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1909
- (0, import_node_assert7.default)(credentials[0].credential);
2013
+ (0, import_node_assert8.default)(credentials[0].credential);
1910
2014
  const spaceMemberCredential = credentials[0].credential.credential;
1911
- (0, import_node_assert7.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2015
+ (0, import_node_assert8.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1912
2016
  await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
1913
2017
  return {
1914
2018
  space: {
@@ -1936,11 +2040,11 @@ var SpaceInvitationProtocol = class {
1936
2040
  };
1937
2041
  }
1938
2042
  async accept(response) {
1939
- (0, import_node_assert7.default)(response.space);
2043
+ (0, import_node_assert8.default)(response.space);
1940
2044
  const { credential, controlTimeframe, dataTimeframe } = response.space;
1941
2045
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
1942
- (0, import_node_assert7.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1943
- (0, import_node_assert7.default)(credential.subject.id.equals(this._signingContext.identityKey));
2046
+ (0, import_node_assert8.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2047
+ (0, import_node_assert8.default)(credential.subject.id.equals(this._signingContext.identityKey));
1944
2048
  await this._spaceManager.acceptSpace({
1945
2049
  spaceKey: assertion.spaceKey,
1946
2050
  genesisFeedKey: assertion.genesisFeedKey,
@@ -1955,12 +2059,12 @@ var SpaceInvitationProtocol = class {
1955
2059
  };
1956
2060
 
1957
2061
  // packages/sdk/client-services/src/packlets/services/service-host.ts
1958
- var import_node_assert13 = __toESM(require("node:assert"));
1959
- var import_async18 = require("@dxos/async");
2062
+ var import_node_assert14 = __toESM(require("node:assert"));
2063
+ var import_async20 = require("@dxos/async");
1960
2064
  var import_client8 = require("@dxos/client");
1961
2065
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
1962
- var import_log16 = require("@dxos/log");
1963
- var import_protocols7 = require("@dxos/protocols");
2066
+ var import_log18 = require("@dxos/log");
2067
+ var import_protocols8 = require("@dxos/protocols");
1964
2068
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
1965
2069
 
1966
2070
  // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
@@ -1977,7 +2081,7 @@ var TracingServiceImpl = class {
1977
2081
  };
1978
2082
 
1979
2083
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
1980
- var import_async7 = require("@dxos/async");
2084
+ var import_async9 = require("@dxos/async");
1981
2085
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
1982
2086
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
1983
2087
  var DevicesServiceImpl = class {
@@ -2008,7 +2112,7 @@ var DevicesServiceImpl = class {
2008
2112
  });
2009
2113
  }
2010
2114
  };
2011
- const subscriptions = new import_async7.EventSubscriptions();
2115
+ const subscriptions = new import_async9.EventSubscriptions();
2012
2116
  subscriptions.add(this._identityManager.stateUpdate.on(() => {
2013
2117
  update();
2014
2118
  if (this._identityManager.identity) {
@@ -2046,37 +2150,37 @@ var NetworkServiceImpl = class {
2046
2150
  };
2047
2151
 
2048
2152
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2049
- var import_node_assert9 = __toESM(require("node:assert"));
2050
- var import_async10 = require("@dxos/async");
2153
+ var import_node_assert10 = __toESM(require("node:assert"));
2154
+ var import_async12 = require("@dxos/async");
2051
2155
  var import_client3 = require("@dxos/client");
2052
- var import_context6 = require("@dxos/context");
2156
+ var import_context7 = require("@dxos/context");
2053
2157
  var import_credentials10 = require("@dxos/credentials");
2054
2158
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
2055
- var import_keys8 = require("@dxos/keys");
2056
- var import_log9 = require("@dxos/log");
2057
- var import_protocols5 = require("@dxos/protocols");
2159
+ var import_keys9 = require("@dxos/keys");
2160
+ var import_log10 = require("@dxos/log");
2161
+ var import_protocols6 = require("@dxos/protocols");
2058
2162
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
2059
2163
  var import_util5 = require("@dxos/util");
2060
2164
 
2061
2165
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2062
- var import_async9 = require("@dxos/async");
2166
+ var import_async11 = require("@dxos/async");
2063
2167
  var import_client2 = require("@dxos/client");
2064
- var import_context5 = require("@dxos/context");
2168
+ var import_context6 = require("@dxos/context");
2065
2169
  var import_debug3 = require("@dxos/debug");
2066
2170
  var import_echo_pipeline = require("@dxos/echo-pipeline");
2067
- var import_errors = require("@dxos/errors");
2068
- var import_keys7 = require("@dxos/keys");
2069
- var import_log8 = require("@dxos/log");
2171
+ var import_errors3 = require("@dxos/errors");
2172
+ var import_keys8 = require("@dxos/keys");
2173
+ var import_log9 = require("@dxos/log");
2070
2174
  var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
2071
2175
  var import_util4 = require("@dxos/util");
2072
2176
 
2073
2177
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2074
- var import_node_assert8 = __toESM(require("node:assert"));
2075
- var import_async8 = require("@dxos/async");
2076
- var import_context4 = require("@dxos/context");
2077
- var import_keys6 = require("@dxos/keys");
2078
- var import_log7 = require("@dxos/log");
2079
- var import_protocols4 = require("@dxos/protocols");
2178
+ var import_node_assert9 = __toESM(require("node:assert"));
2179
+ var import_async10 = require("@dxos/async");
2180
+ var import_context5 = require("@dxos/context");
2181
+ var import_keys7 = require("@dxos/keys");
2182
+ var import_log8 = require("@dxos/log");
2183
+ var import_protocols5 = require("@dxos/protocols");
2080
2184
  var import_teleport2 = require("@dxos/teleport");
2081
2185
  var import_util3 = require("@dxos/util");
2082
2186
  var DEFAULT_RETRY_TIMEOUT = 1e3;
@@ -2084,11 +2188,11 @@ var DEFAULT_SUCCESS_DELAY = 1e3;
2084
2188
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2085
2189
  var NotarizationPlugin = class {
2086
2190
  constructor() {
2087
- this._ctx = new import_context4.Context();
2088
- this._extensionOpened = new import_async8.Event();
2191
+ this._ctx = new import_context5.Context();
2192
+ this._extensionOpened = new import_async10.Event();
2089
2193
  this._extensions = /* @__PURE__ */ new Set();
2090
- this._processedCredentials = new import_util3.ComplexSet(import_keys6.PublicKey.hash);
2091
- this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys6.PublicKey.hash);
2194
+ this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
2195
+ this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys7.PublicKey.hash);
2092
2196
  }
2093
2197
  async open() {
2094
2198
  }
@@ -2099,7 +2203,7 @@ var NotarizationPlugin = class {
2099
2203
  * Request credentials to be notarized.
2100
2204
  */
2101
2205
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2102
- (0, import_log7.log)("notarize", {
2206
+ (0, import_log8.log)("notarize", {
2103
2207
  credentials
2104
2208
  }, {
2105
2209
  file: "notarization-plugin.ts",
@@ -2107,11 +2211,11 @@ var NotarizationPlugin = class {
2107
2211
  scope: this,
2108
2212
  callSite: (f, a) => f(...a)
2109
2213
  });
2110
- (0, import_node_assert8.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2111
- const errors = new import_async8.Trigger();
2214
+ (0, import_node_assert9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2215
+ const errors = new import_async10.Trigger();
2112
2216
  const ctx = this._ctx.derive({
2113
2217
  onError: (err) => {
2114
- import_log7.log.warn("Notarization error", {
2218
+ import_log8.log.warn("Notarization error", {
2115
2219
  err
2116
2220
  }, {
2117
2221
  file: "notarization-plugin.ts",
@@ -2125,8 +2229,8 @@ var NotarizationPlugin = class {
2125
2229
  });
2126
2230
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2127
2231
  if (timeout !== 0) {
2128
- (0, import_async8.scheduleTask)(ctx, () => {
2129
- import_log7.log.warn("Notarization timeout", {
2232
+ (0, import_async10.scheduleTask)(ctx, () => {
2233
+ import_log8.log.warn("Notarization timeout", {
2130
2234
  timeout,
2131
2235
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2132
2236
  }, {
@@ -2136,12 +2240,12 @@ var NotarizationPlugin = class {
2136
2240
  callSite: (f, a) => f(...a)
2137
2241
  });
2138
2242
  void ctx.dispose();
2139
- errors.throw(new import_async8.TimeoutError(timeout, "Notarization timed out"));
2243
+ errors.throw(new import_async10.TimeoutError(timeout, "Notarization timed out"));
2140
2244
  }, timeout);
2141
2245
  }
2142
2246
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2143
2247
  const peersTried = /* @__PURE__ */ new Set();
2144
- const notarizeTask = new import_async8.DeferredTask(ctx, async () => {
2248
+ const notarizeTask = new import_async10.DeferredTask(ctx, async () => {
2145
2249
  try {
2146
2250
  if (this._extensions.size === 0) {
2147
2251
  return;
@@ -2150,7 +2254,7 @@ var NotarizationPlugin = class {
2150
2254
  ...this._extensions
2151
2255
  ].find((peer2) => !peersTried.has(peer2));
2152
2256
  if (!peer) {
2153
- import_log7.log.warn("Exhausted all peers to notarize with", {
2257
+ import_log8.log.warn("Exhausted all peers to notarize with", {
2154
2258
  retryIn: retryTimeout
2155
2259
  }, {
2156
2260
  file: "notarization-plugin.ts",
@@ -2159,11 +2263,11 @@ var NotarizationPlugin = class {
2159
2263
  callSite: (f, a) => f(...a)
2160
2264
  });
2161
2265
  peersTried.clear();
2162
- (0, import_async8.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2266
+ (0, import_async10.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2163
2267
  return;
2164
2268
  }
2165
2269
  peersTried.add(peer);
2166
- (0, import_log7.log)("try notarizing", {
2270
+ (0, import_log8.log)("try notarizing", {
2167
2271
  peer: peer.localPeerId,
2168
2272
  credentialId: credentials.map((credential) => credential.id)
2169
2273
  }, {
@@ -2175,15 +2279,15 @@ var NotarizationPlugin = class {
2175
2279
  await peer.rpc.NotarizationService.notarize({
2176
2280
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2177
2281
  });
2178
- (0, import_log7.log)("success", {}, {
2282
+ (0, import_log8.log)("success", {}, {
2179
2283
  file: "notarization-plugin.ts",
2180
2284
  line: 142,
2181
2285
  scope: this,
2182
2286
  callSite: (f, a) => f(...a)
2183
2287
  });
2184
- await (0, import_async8.sleep)(successDelay);
2288
+ await (0, import_async10.sleep)(successDelay);
2185
2289
  } catch (err) {
2186
- import_log7.log.warn("error notarizing (recoverable)", err, {
2290
+ import_log8.log.warn("error notarizing (recoverable)", err, {
2187
2291
  file: "notarization-plugin.ts",
2188
2292
  line: 145,
2189
2293
  scope: this,
@@ -2196,11 +2300,11 @@ var NotarizationPlugin = class {
2196
2300
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2197
2301
  try {
2198
2302
  await Promise.race([
2199
- (0, import_context4.rejectOnDispose)(ctx),
2303
+ (0, import_context5.rejectOnDispose)(ctx),
2200
2304
  allNotarized,
2201
2305
  errors.wait()
2202
2306
  ]);
2203
- (0, import_log7.log)("done", {}, {
2307
+ (0, import_log8.log)("done", {}, {
2204
2308
  file: "notarization-plugin.ts",
2205
2309
  line: 155,
2206
2310
  scope: this,
@@ -2223,14 +2327,14 @@ var NotarizationPlugin = class {
2223
2327
  this._processCredentialsTriggers.delete(credential.id);
2224
2328
  }
2225
2329
  setWriter(writer) {
2226
- (0, import_node_assert8.default)(!this._writer, "Writer already set.");
2330
+ (0, import_node_assert9.default)(!this._writer, "Writer already set.");
2227
2331
  this._writer = writer;
2228
2332
  }
2229
2333
  async _waitUntilProcessed(id) {
2230
2334
  if (this._processedCredentials.has(id)) {
2231
2335
  return;
2232
2336
  }
2233
- await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async8.Trigger()).value.wait();
2337
+ await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async10.Trigger()).value.wait();
2234
2338
  }
2235
2339
  /**
2236
2340
  * Requests from other peers to notarize credentials.
@@ -2241,7 +2345,7 @@ var NotarizationPlugin = class {
2241
2345
  throw new Error("Writer not set");
2242
2346
  }
2243
2347
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2244
- (0, import_node_assert8.default)(credential.id, "Credential must have an id");
2348
+ (0, import_node_assert9.default)(credential.id, "Credential must have an id");
2245
2349
  if (this._processedCredentials.has(credential.id)) {
2246
2350
  continue;
2247
2351
  }
@@ -2251,7 +2355,7 @@ var NotarizationPlugin = class {
2251
2355
  createExtension() {
2252
2356
  const extension = new NotarizationTeleportExtension({
2253
2357
  onOpen: async () => {
2254
- (0, import_log7.log)("extension opened", {
2358
+ (0, import_log8.log)("extension opened", {
2255
2359
  peer: extension.localPeerId
2256
2360
  }, {
2257
2361
  file: "notarization-plugin.ts",
@@ -2263,7 +2367,7 @@ var NotarizationPlugin = class {
2263
2367
  this._extensionOpened.emit();
2264
2368
  },
2265
2369
  onClose: async () => {
2266
- (0, import_log7.log)("extension closed", {
2370
+ (0, import_log8.log)("extension closed", {
2267
2371
  peer: extension.localPeerId
2268
2372
  }, {
2269
2373
  file: "notarization-plugin.ts",
@@ -2282,10 +2386,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
2282
2386
  constructor(_params) {
2283
2387
  super({
2284
2388
  requested: {
2285
- NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2389
+ NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2286
2390
  },
2287
2391
  exposed: {
2288
- NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2392
+ NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2289
2393
  }
2290
2394
  });
2291
2395
  this._params = _params;
@@ -2323,9 +2427,9 @@ var __decorate = function(decorators, target, key, desc) {
2323
2427
  var AUTH_TIMEOUT2 = 3e4;
2324
2428
  var DataSpace = class DataSpace2 {
2325
2429
  constructor(params) {
2326
- this._ctx = new import_context5.Context();
2430
+ this._ctx = new import_context6.Context();
2327
2431
  this._state = import_client2.SpaceState.CLOSED;
2328
- this.stateUpdate = new import_async9.Event();
2432
+ this.stateUpdate = new import_async11.Event();
2329
2433
  var _a;
2330
2434
  this._inner = params.inner;
2331
2435
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -2346,7 +2450,7 @@ var DataSpace = class DataSpace2 {
2346
2450
  snapshotId: params.snapshotId
2347
2451
  });
2348
2452
  this.authVerifier = new TrustedKeySetAuthVerifier({
2349
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2453
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2350
2454
  update: this._inner.stateUpdate,
2351
2455
  authTimeout: AUTH_TIMEOUT2
2352
2456
  });
@@ -2400,12 +2504,12 @@ var DataSpace = class DataSpace2 {
2400
2504
  * Initialize the data pipeline in a separate task.
2401
2505
  */
2402
2506
  initializeDataPipelineAsync() {
2403
- (0, import_async9.scheduleTask)(this._ctx, async () => {
2507
+ (0, import_async11.scheduleTask)(this._ctx, async () => {
2404
2508
  try {
2405
2509
  await this.initializeDataPipeline();
2406
2510
  } catch (err) {
2407
- if (err instanceof import_errors.CancelledError) {
2408
- (0, import_log8.log)("Data pipeline initialization cancelled", err, {
2511
+ if (err instanceof import_errors3.CancelledError) {
2512
+ (0, import_log9.log)("Data pipeline initialization cancelled", err, {
2409
2513
  file: "data-space.ts",
2410
2514
  line: 178,
2411
2515
  scope: this,
@@ -2413,7 +2517,7 @@ var DataSpace = class DataSpace2 {
2413
2517
  });
2414
2518
  return;
2415
2519
  }
2416
- import_log8.log.error("Error initializing data pipeline", err, {
2520
+ import_log9.log.error("Error initializing data pipeline", err, {
2417
2521
  file: "data-space.ts",
2418
2522
  line: 182,
2419
2523
  scope: this,
@@ -2425,7 +2529,7 @@ var DataSpace = class DataSpace2 {
2425
2529
  async initializeDataPipeline() {
2426
2530
  var _a, _b, _c, _d;
2427
2531
  if (this._state !== import_client2.SpaceState.INACTIVE) {
2428
- throw new import_errors.SystemError("Invalid operation");
2532
+ throw new import_errors3.SystemError("Invalid operation");
2429
2533
  }
2430
2534
  this._state = import_client2.SpaceState.INITIALIZING;
2431
2535
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
@@ -2433,7 +2537,7 @@ var DataSpace = class DataSpace2 {
2433
2537
  breakOnStall: false
2434
2538
  });
2435
2539
  await this._createWritableFeeds();
2436
- (0, import_log8.log)("Writable feeds created", {}, {
2540
+ (0, import_log9.log)("Writable feeds created", {}, {
2437
2541
  file: "data-space.ts",
2438
2542
  line: 200,
2439
2543
  scope: this,
@@ -2454,7 +2558,7 @@ var DataSpace = class DataSpace2 {
2454
2558
  return pipeline;
2455
2559
  }
2456
2560
  });
2457
- (0, import_log8.log)("waiting for data pipeline to reach target timeframe", {}, {
2561
+ (0, import_log9.log)("waiting for data pipeline to reach target timeframe", {}, {
2458
2562
  file: "data-space.ts",
2459
2563
  line: 220,
2460
2564
  scope: this,
@@ -2464,7 +2568,7 @@ var DataSpace = class DataSpace2 {
2464
2568
  ctx: this._ctx,
2465
2569
  breakOnStall: false
2466
2570
  });
2467
- (0, import_log8.log)("data pipeline ready", {}, {
2571
+ (0, import_log9.log)("data pipeline ready", {}, {
2468
2572
  file: "data-space.ts",
2469
2573
  line: 227,
2470
2574
  scope: this,
@@ -2523,7 +2627,7 @@ __decorate([
2523
2627
  (0, import_debug3.timed)(1e4)
2524
2628
  ], DataSpace.prototype, "_createWritableFeeds", null);
2525
2629
  DataSpace = __decorate([
2526
- (0, import_async9.trackLeaks)("open", "close")
2630
+ (0, import_async11.trackLeaks)("open", "close")
2527
2631
  ], DataSpace);
2528
2632
 
2529
2633
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
@@ -2547,24 +2651,24 @@ var DataSpaceManager = class DataSpaceManager2 {
2547
2651
  this._modelFactory = _modelFactory;
2548
2652
  this._feedStore = _feedStore;
2549
2653
  this._snapshotStore = _snapshotStore;
2550
- this._ctx = new import_context6.Context();
2551
- this.updated = new import_async10.Event();
2552
- this._spaces = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
2654
+ this._ctx = new import_context7.Context();
2655
+ this.updated = new import_async12.Event();
2656
+ this._spaces = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
2553
2657
  this._isOpen = false;
2554
- this._instanceId = import_keys8.PublicKey.random().toHex();
2658
+ this._instanceId = import_keys9.PublicKey.random().toHex();
2555
2659
  }
2556
2660
  // TODO(burdon): Remove.
2557
2661
  get spaces() {
2558
2662
  return this._spaces;
2559
2663
  }
2560
2664
  async open() {
2561
- (0, import_log9.log)("open", {}, {
2665
+ (0, import_log10.log)("open", {}, {
2562
2666
  file: "data-space-manager.ts",
2563
2667
  line: 83,
2564
2668
  scope: this,
2565
2669
  callSite: (f, a) => f(...a)
2566
2670
  });
2567
- import_log9.log.trace("dxos.echo.data-space-manager", import_protocols5.trace.begin({
2671
+ import_log10.log.trace("dxos.echo.data-space-manager", import_protocols6.trace.begin({
2568
2672
  id: this._instanceId,
2569
2673
  parentId: this._traceParent
2570
2674
  }), {
@@ -2574,7 +2678,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2574
2678
  callSite: (f, a) => f(...a)
2575
2679
  });
2576
2680
  await this._metadataStore.load();
2577
- (0, import_log9.log)("metadata loaded", {
2681
+ (0, import_log10.log)("metadata loaded", {
2578
2682
  spaces: this._metadataStore.spaces.length
2579
2683
  }, {
2580
2684
  file: "data-space-manager.ts",
@@ -2583,7 +2687,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2583
2687
  callSite: (f, a) => f(...a)
2584
2688
  });
2585
2689
  for (const spaceMetadata of this._metadataStore.spaces) {
2586
- (0, import_log9.log)("load space", {
2690
+ (0, import_log10.log)("load space", {
2587
2691
  spaceMetadata
2588
2692
  }, {
2589
2693
  file: "data-space-manager.ts",
@@ -2598,7 +2702,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2598
2702
  this.updated.emit();
2599
2703
  }
2600
2704
  async close() {
2601
- (0, import_log9.log)("close", {}, {
2705
+ (0, import_log10.log)("close", {}, {
2602
2706
  file: "data-space-manager.ts",
2603
2707
  line: 100,
2604
2708
  scope: this,
@@ -2609,7 +2713,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2609
2713
  for (const space of this._spaces.values()) {
2610
2714
  await space.close();
2611
2715
  }
2612
- import_log9.log.trace("dxos.echo.data-space-manager", import_protocols5.trace.end({
2716
+ import_log10.log.trace("dxos.echo.data-space-manager", import_protocols6.trace.end({
2613
2717
  id: this._instanceId
2614
2718
  }), {
2615
2719
  file: "data-space-manager.ts",
@@ -2622,7 +2726,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2622
2726
  * Creates a new space writing the genesis credentials to the control feed.
2623
2727
  */
2624
2728
  async createSpace() {
2625
- (0, import_node_assert9.default)(this._isOpen, "Not open.");
2729
+ (0, import_node_assert10.default)(this._isOpen, "Not open.");
2626
2730
  const spaceKey = await this._keyring.createKey();
2627
2731
  const controlFeedKey = await this._keyring.createKey();
2628
2732
  const dataFeedKey = await this._keyring.createKey();
@@ -2632,7 +2736,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2632
2736
  controlFeedKey,
2633
2737
  dataFeedKey
2634
2738
  };
2635
- (0, import_log9.log)("creating space...", {
2739
+ (0, import_log10.log)("creating space...", {
2636
2740
  spaceKey
2637
2741
  }, {
2638
2742
  file: "data-space-manager.ts",
@@ -2644,7 +2748,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2644
2748
  const credentials = await (0, import_echo_pipeline2.spaceGenesis)(this._keyring, this._signingContext, space.inner);
2645
2749
  await this._metadataStore.addSpace(metadata);
2646
2750
  const memberCredential = credentials[1];
2647
- (0, import_node_assert9.default)((0, import_credentials10.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2751
+ (0, import_node_assert10.default)((0, import_credentials10.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2648
2752
  await this._signingContext.recordCredential(memberCredential);
2649
2753
  await space.initializeDataPipeline();
2650
2754
  this.updated.emit();
@@ -2652,7 +2756,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2652
2756
  }
2653
2757
  // TODO(burdon): Rename join space.
2654
2758
  async acceptSpace(opts) {
2655
- (0, import_log9.log)("accept space", {
2759
+ (0, import_log10.log)("accept space", {
2656
2760
  opts
2657
2761
  }, {
2658
2762
  file: "data-space-manager.ts",
@@ -2660,8 +2764,8 @@ var DataSpaceManager = class DataSpaceManager2 {
2660
2764
  scope: this,
2661
2765
  callSite: (f, a) => f(...a)
2662
2766
  });
2663
- (0, import_node_assert9.default)(this._isOpen, "Not open.");
2664
- (0, import_node_assert9.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2767
+ (0, import_node_assert10.default)(this._isOpen, "Not open.");
2768
+ (0, import_node_assert10.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2665
2769
  const metadata = {
2666
2770
  key: opts.spaceKey,
2667
2771
  genesisFeedKey: opts.genesisFeedKey,
@@ -2680,13 +2784,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2680
2784
  * TODO(dmaretskyi): Consider removing.
2681
2785
  */
2682
2786
  async waitUntilSpaceReady(spaceKey) {
2683
- await (0, import_context6.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
2787
+ await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
2684
2788
  const space = this._spaces.get(spaceKey);
2685
2789
  return !!space && space.state === import_client3.SpaceState.READY;
2686
2790
  }));
2687
2791
  }
2688
2792
  async _constructSpace(metadata) {
2689
- (0, import_log9.log)("construct space", {
2793
+ (0, import_log10.log)("construct space", {
2690
2794
  metadata
2691
2795
  }, {
2692
2796
  file: "data-space-manager.ts",
@@ -2741,7 +2845,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2741
2845
  snapshotId: metadata.snapshot,
2742
2846
  callbacks: {
2743
2847
  beforeReady: async () => {
2744
- (0, import_log9.log)("before space ready", {
2848
+ (0, import_log10.log)("before space ready", {
2745
2849
  space: space.key
2746
2850
  }, {
2747
2851
  file: "data-space-manager.ts",
@@ -2752,7 +2856,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2752
2856
  this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseBackend.createDataServiceHost());
2753
2857
  },
2754
2858
  afterReady: async () => {
2755
- (0, import_log9.log)("after space ready", {
2859
+ (0, import_log10.log)("after space ready", {
2756
2860
  space: space.key,
2757
2861
  open: this._isOpen
2758
2862
  }, {
@@ -2779,27 +2883,27 @@ var DataSpaceManager = class DataSpaceManager2 {
2779
2883
  }
2780
2884
  };
2781
2885
  __decorate2([
2782
- import_async10.synchronized
2886
+ import_async12.synchronized
2783
2887
  ], DataSpaceManager.prototype, "open", null);
2784
2888
  __decorate2([
2785
- import_async10.synchronized
2889
+ import_async12.synchronized
2786
2890
  ], DataSpaceManager.prototype, "close", null);
2787
2891
  __decorate2([
2788
- import_async10.synchronized
2892
+ import_async12.synchronized
2789
2893
  ], DataSpaceManager.prototype, "createSpace", null);
2790
2894
  __decorate2([
2791
- import_async10.synchronized
2895
+ import_async12.synchronized
2792
2896
  ], DataSpaceManager.prototype, "acceptSpace", null);
2793
2897
  DataSpaceManager = __decorate2([
2794
- (0, import_async10.trackLeaks)("open", "close")
2898
+ (0, import_async12.trackLeaks)("open", "close")
2795
2899
  ], DataSpaceManager);
2796
2900
 
2797
2901
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2798
- var import_async11 = require("@dxos/async");
2902
+ var import_async13 = require("@dxos/async");
2799
2903
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2800
2904
  var import_debug4 = require("@dxos/debug");
2801
2905
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2802
- var import_log10 = require("@dxos/log");
2906
+ var import_log11 = require("@dxos/log");
2803
2907
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2804
2908
  var import_util6 = require("@dxos/util");
2805
2909
  var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
@@ -2826,7 +2930,7 @@ var SpacesServiceImpl = class {
2826
2930
  const onUpdate = async () => {
2827
2931
  const dataSpaceManager = await this._getDataSpaceManager();
2828
2932
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
2829
- (0, import_log10.log)("update", {
2933
+ (0, import_log11.log)("update", {
2830
2934
  spaces
2831
2935
  }, {
2832
2936
  file: "spaces-service.ts",
@@ -2838,9 +2942,9 @@ var SpacesServiceImpl = class {
2838
2942
  spaces
2839
2943
  });
2840
2944
  };
2841
- (0, import_async11.scheduleTask)(ctx, async () => {
2945
+ (0, import_async13.scheduleTask)(ctx, async () => {
2842
2946
  const dataSpaceManager = await this._getDataSpaceManager();
2843
- const subscriptions = new import_async11.EventSubscriptions();
2947
+ const subscriptions = new import_async13.EventSubscriptions();
2844
2948
  ctx.onDispose(() => subscriptions.clear());
2845
2949
  const subscribeSpaces = () => {
2846
2950
  subscriptions.clear();
@@ -2875,7 +2979,7 @@ var SpacesServiceImpl = class {
2875
2979
  }
2876
2980
  subscribeMessages({ spaceKey, channel }) {
2877
2981
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
2878
- (0, import_async11.scheduleTask)(ctx, async () => {
2982
+ (0, import_async13.scheduleTask)(ctx, async () => {
2879
2983
  var _a;
2880
2984
  const dataSpaceManager = await this._getDataSpaceManager();
2881
2985
  const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
@@ -2896,7 +3000,7 @@ var SpacesServiceImpl = class {
2896
3000
  }
2897
3001
  });
2898
3002
  ctx.onDispose(() => processor.close());
2899
- (0, import_async11.scheduleTask)(ctx, () => processor.open());
3003
+ (0, import_async13.scheduleTask)(ctx, () => processor.open());
2900
3004
  });
2901
3005
  }
2902
3006
  async writeCredentials({ spaceKey, credentials }) {
@@ -2943,23 +3047,23 @@ var SpacesServiceImpl = class {
2943
3047
  var getChannelId = (channel) => `user-channel/${channel}`;
2944
3048
 
2945
3049
  // packages/sdk/client-services/src/packlets/storage/storage.ts
2946
- var import_errors2 = require("@dxos/errors");
3050
+ var import_errors4 = require("@dxos/errors");
2947
3051
  var import_config = require("@dxos/protocols/proto/dxos/config");
2948
3052
  var import_random_access_storage = require("@dxos/random-access-storage");
2949
3053
  var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
2950
3054
  var createStorageObjects = (config) => {
2951
3055
  const { path = "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
2952
3056
  if (persistent && storageType === StorageDriver.RAM) {
2953
- throw new import_errors2.InvalidConfigError("RAM storage cannot be used in persistent mode.");
3057
+ throw new import_errors4.InvalidConfigError("RAM storage cannot be used in persistent mode.");
2954
3058
  }
2955
3059
  if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
2956
- throw new import_errors2.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3060
+ throw new import_errors4.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
2957
3061
  }
2958
3062
  if (persistent && keyStorage === StorageDriver.RAM) {
2959
- throw new import_errors2.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3063
+ throw new import_errors4.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
2960
3064
  }
2961
3065
  if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
2962
- throw new import_errors2.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3066
+ throw new import_errors4.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
2963
3067
  }
2964
3068
  return {
2965
3069
  storage: (0, import_random_access_storage.createStorage)({
@@ -3028,8 +3132,8 @@ var SystemServiceImpl = class {
3028
3132
  };
3029
3133
 
3030
3134
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3031
- var import_async13 = require("@dxos/async");
3032
- var import_log11 = require("@dxos/log");
3135
+ var import_async15 = require("@dxos/async");
3136
+ var import_log12 = require("@dxos/log");
3033
3137
  var import_messaging = require("@dxos/messaging");
3034
3138
  var import_network_manager2 = require("@dxos/network-manager");
3035
3139
  var import_util7 = require("@dxos/util");
@@ -3088,15 +3192,15 @@ var ClientRpcServer = class {
3088
3192
  };
3089
3193
 
3090
3194
  // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3091
- var import_node_assert10 = __toESM(require("node:assert"));
3092
- var import_async12 = require("@dxos/async");
3195
+ var import_node_assert11 = __toESM(require("node:assert"));
3196
+ var import_async14 = require("@dxos/async");
3093
3197
  var import_client4 = require("@dxos/client");
3094
3198
  var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
3095
3199
  var import_rpc2 = require("@dxos/rpc");
3096
3200
  var ShellRuntimeImpl = class {
3097
3201
  constructor(_port) {
3098
3202
  this._port = _port;
3099
- this.layoutUpdate = new import_async12.Event();
3203
+ this.layoutUpdate = new import_async14.Event();
3100
3204
  this._layout = import_iframe.ShellLayout.DEFAULT;
3101
3205
  }
3102
3206
  get layout() {
@@ -3118,7 +3222,7 @@ var ShellRuntimeImpl = class {
3118
3222
  });
3119
3223
  }
3120
3224
  async setAppContext(context) {
3121
- (0, import_node_assert10.default)(this._appRpc, "runtime not open");
3225
+ (0, import_node_assert11.default)(this._appRpc, "runtime not open");
3122
3226
  await this._appRpc.rpc.AppService.setContext(context);
3123
3227
  }
3124
3228
  async open() {
@@ -3147,8 +3251,8 @@ var ShellRuntimeImpl = class {
3147
3251
  };
3148
3252
  var MemoryShellRuntime = class {
3149
3253
  constructor({ layout, invitationCode, spaceKey } = {}) {
3150
- this.layoutUpdate = new import_async12.Event();
3151
- this.contextUpdate = new import_async12.Event();
3254
+ this.layoutUpdate = new import_async14.Event();
3255
+ this.contextUpdate = new import_async14.Event();
3152
3256
  this._layout = layout != null ? layout : import_iframe.ShellLayout.DEFAULT;
3153
3257
  this._invitationCode = invitationCode;
3154
3258
  this._spaceKey = spaceKey;
@@ -3190,8 +3294,31 @@ var __decorate3 = function(decorators, target, key, desc) {
3190
3294
  var LOCK_KEY = "DXOS_RESOURCE_LOCK";
3191
3295
  var IFrameHostRuntime = class {
3192
3296
  constructor({ configProvider, appPort, shellPort }) {
3193
- this._transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)();
3194
- this._ready = new import_async13.Trigger();
3297
+ this._transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
3298
+ iceServers: [
3299
+ {
3300
+ urls: "stun:dev.kube.dxos.org:3478",
3301
+ username: "dxos",
3302
+ credential: "dxos"
3303
+ },
3304
+ {
3305
+ urls: "turn:dev.kube.dxos.org:3478",
3306
+ username: "dxos",
3307
+ credential: "dxos"
3308
+ },
3309
+ {
3310
+ urls: "stun:kube.dxos.org:3478",
3311
+ username: "dxos",
3312
+ credential: "dxos"
3313
+ },
3314
+ {
3315
+ urls: "turn:kube.dxos.org:3478",
3316
+ username: "dxos",
3317
+ credential: "dxos"
3318
+ }
3319
+ ]
3320
+ });
3321
+ this._ready = new import_async15.Trigger();
3195
3322
  this._configProvider = configProvider;
3196
3323
  this._appPort = appPort;
3197
3324
  this._shellPort = shellPort;
@@ -3207,23 +3334,21 @@ var IFrameHostRuntime = class {
3207
3334
  }
3208
3335
  async start() {
3209
3336
  var _a;
3210
- (0, import_log11.log)("starting...", {}, {
3337
+ (0, import_log12.log)("starting...", {}, {
3211
3338
  file: "iframe-host-runtime.ts",
3212
- line: 67,
3339
+ line: 75,
3213
3340
  scope: this,
3214
3341
  callSite: (f, a) => f(...a)
3215
3342
  });
3216
3343
  try {
3217
3344
  this._config = await (0, import_util7.getAsyncValue)(this._configProvider);
3218
- const signalServer = this._config.get("runtime.services.signal.server");
3345
+ const signals = this._config.get("runtime.services.signaling");
3219
3346
  this._clientServices = new LocalClientServices({
3220
3347
  lockKey: LOCK_KEY,
3221
3348
  config: this._config,
3222
3349
  networkManager: new import_network_manager2.NetworkManager({
3223
3350
  log: true,
3224
- signalManager: signalServer ? new import_messaging.WebsocketSignalManager([
3225
- signalServer
3226
- ]) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3351
+ signalManager: signals ? new import_messaging.WebsocketSignalManager(signals) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3227
3352
  transportFactory: this._transportFactory
3228
3353
  })
3229
3354
  });
@@ -3258,17 +3383,17 @@ var IFrameHostRuntime = class {
3258
3383
  (_a = this._shellRuntime) == null ? void 0 : _a.open()
3259
3384
  ]);
3260
3385
  this._ready.wake(void 0);
3261
- (0, import_log11.log)("started", {}, {
3386
+ (0, import_log12.log)("started", {}, {
3262
3387
  file: "iframe-host-runtime.ts",
3263
- line: 110,
3388
+ line: 118,
3264
3389
  scope: this,
3265
3390
  callSite: (f, a) => f(...a)
3266
3391
  });
3267
3392
  } catch (err) {
3268
3393
  this._ready.wake(err);
3269
- import_log11.log.catch(err, {}, {
3394
+ import_log12.log.catch(err, {}, {
3270
3395
  file: "iframe-host-runtime.ts",
3271
- line: 113,
3396
+ line: 121,
3272
3397
  scope: this,
3273
3398
  callSite: (f, a) => f(...a)
3274
3399
  });
@@ -3276,34 +3401,59 @@ var IFrameHostRuntime = class {
3276
3401
  }
3277
3402
  async stop() {
3278
3403
  var _a;
3279
- (0, import_log11.log)("stopping...", {}, {
3404
+ (0, import_log12.log)("stopping...", {}, {
3280
3405
  file: "iframe-host-runtime.ts",
3281
- line: 118,
3406
+ line: 126,
3282
3407
  scope: this,
3283
3408
  callSite: (f, a) => f(...a)
3284
3409
  });
3285
3410
  await this._clientRpc.close();
3286
3411
  await this._clientServices.close();
3287
3412
  await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3288
- (0, import_log11.log)("stopped", {}, {
3413
+ (0, import_log12.log)("stopped", {}, {
3289
3414
  file: "iframe-host-runtime.ts",
3290
- line: 122,
3415
+ line: 130,
3291
3416
  scope: this,
3292
3417
  callSite: (f, a) => f(...a)
3293
3418
  });
3294
3419
  }
3295
3420
  };
3296
3421
  __decorate3([
3297
- import_log11.logInfo
3422
+ import_log12.logInfo
3298
3423
  ], IFrameHostRuntime.prototype, "origin", void 0);
3299
3424
 
3300
3425
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3301
3426
  var import_client5 = require("@dxos/client");
3427
+ var import_errors5 = require("@dxos/errors");
3428
+ var import_log13 = require("@dxos/log");
3302
3429
  var import_network_manager3 = require("@dxos/network-manager");
3303
3430
  var import_rpc3 = require("@dxos/rpc");
3304
3431
  var IFrameProxyRuntime = class {
3305
3432
  constructor({ systemPort, workerAppPort, windowAppPort, shellPort }) {
3306
- this._transportService = new import_network_manager3.WebRTCTransportService();
3433
+ this._transportService = new import_network_manager3.WebRTCTransportService({
3434
+ iceServers: [
3435
+ {
3436
+ urls: "stun:dev.kube.dxos.org:3478",
3437
+ username: "dxos",
3438
+ credential: "dxos"
3439
+ },
3440
+ {
3441
+ urls: "turn:dev.kube.dxos.org:3478",
3442
+ username: "dxos",
3443
+ credential: "dxos"
3444
+ },
3445
+ {
3446
+ urls: "stun:kube.dxos.org:3478",
3447
+ username: "dxos",
3448
+ credential: "dxos"
3449
+ },
3450
+ {
3451
+ urls: "turn:kube.dxos.org:3478",
3452
+ username: "dxos",
3453
+ credential: "dxos"
3454
+ }
3455
+ ]
3456
+ });
3307
3457
  this._systemPort = systemPort;
3308
3458
  this._windowAppPort = windowAppPort;
3309
3459
  this._workerAppPort = workerAppPort;
@@ -3319,7 +3469,7 @@ var IFrameProxyRuntime = class {
3319
3469
  }
3320
3470
  },
3321
3471
  port: this._systemPort,
3322
- timeout: 200
3472
+ timeout: 1e3
3323
3473
  });
3324
3474
  this._workerAppPort.subscribe((msg) => this._windowAppPort.send(msg));
3325
3475
  this._windowAppPort.subscribe((msg) => this._workerAppPort.send(msg));
@@ -3332,10 +3482,20 @@ var IFrameProxyRuntime = class {
3332
3482
  }
3333
3483
  async open(origin) {
3334
3484
  var _a;
3335
- await this._systemRpc.open();
3336
- await this._systemRpc.rpc.WorkerService.start({
3337
- origin
3338
- });
3485
+ try {
3486
+ await this._systemRpc.open();
3487
+ await this._systemRpc.rpc.WorkerService.start({
3488
+ origin
3489
+ });
3490
+ } catch (err) {
3491
+ import_log13.log.catch(err, {}, {
3492
+ file: "iframe-proxy-runtime.ts",
3493
+ line: 79,
3494
+ scope: this,
3495
+ callSite: (f, a) => f(...a)
3496
+ });
3497
+ throw new import_errors5.RemoteServiceConnectionError("Failed to connect to worker");
3498
+ }
3339
3499
  await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
3340
3500
  }
3341
3501
  async close() {
@@ -3347,8 +3507,8 @@ var IFrameProxyRuntime = class {
3347
3507
  };
3348
3508
 
3349
3509
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3350
- var import_async14 = require("@dxos/async");
3351
- var import_log12 = require("@dxos/log");
3510
+ var import_async16 = require("@dxos/async");
3511
+ var import_log14 = require("@dxos/log");
3352
3512
  var __decorate4 = function(decorators, target, key, desc) {
3353
3513
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3354
3514
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3366,7 +3526,7 @@ var Message;
3366
3526
  var VaultResourceLock = class {
3367
3527
  constructor({ lockKey, onAcquire, onRelease }) {
3368
3528
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3369
- this._releaseTrigger = new import_async14.Trigger();
3529
+ this._releaseTrigger = new import_async16.Trigger();
3370
3530
  this._lockKey = lockKey;
3371
3531
  this._onAcquire = onAcquire;
3372
3532
  this._onRelease = onRelease;
@@ -3380,28 +3540,28 @@ var VaultResourceLock = class {
3380
3540
  message: Message.ACQUIRING
3381
3541
  });
3382
3542
  try {
3383
- (0, import_log12.log)("aquiring lock...", {}, {
3543
+ (0, import_log14.log)("aquiring lock...", {}, {
3384
3544
  file: "vault-resource-lock.ts",
3385
3545
  line: 44,
3386
3546
  scope: this,
3387
3547
  callSite: (f, a) => f(...a)
3388
3548
  });
3389
- await (0, import_async14.asyncTimeout)(this._requestLock(), 3e3);
3390
- (0, import_log12.log)("acquired lock", {}, {
3549
+ await (0, import_async16.asyncTimeout)(this._requestLock(), 3e3);
3550
+ (0, import_log14.log)("acquired lock", {}, {
3391
3551
  file: "vault-resource-lock.ts",
3392
3552
  line: 46,
3393
3553
  scope: this,
3394
3554
  callSite: (f, a) => f(...a)
3395
3555
  });
3396
3556
  } catch (e) {
3397
- (0, import_log12.log)("stealing lock...", {}, {
3557
+ (0, import_log14.log)("stealing lock...", {}, {
3398
3558
  file: "vault-resource-lock.ts",
3399
3559
  line: 48,
3400
3560
  scope: this,
3401
3561
  callSite: (f, a) => f(...a)
3402
3562
  });
3403
3563
  await this._requestLock(true);
3404
- (0, import_log12.log)("stolen lock", {}, {
3564
+ (0, import_log14.log)("stolen lock", {}, {
3405
3565
  file: "vault-resource-lock.ts",
3406
3566
  line: 50,
3407
3567
  scope: this,
@@ -3418,7 +3578,7 @@ var VaultResourceLock = class {
3418
3578
  }
3419
3579
  }
3420
3580
  async _requestLock(steal = false) {
3421
- (0, import_log12.log)("requesting lock...", {
3581
+ (0, import_log14.log)("requesting lock...", {
3422
3582
  steal
3423
3583
  }, {
3424
3584
  file: "vault-resource-lock.ts",
@@ -3426,23 +3586,23 @@ var VaultResourceLock = class {
3426
3586
  scope: this,
3427
3587
  callSite: (f, a) => f(...a)
3428
3588
  });
3429
- const acquired = new import_async14.Trigger();
3589
+ const acquired = new import_async16.Trigger();
3430
3590
  void navigator.locks.request(this._lockKey, {
3431
3591
  steal
3432
3592
  }, async () => {
3433
3593
  var _a, _b;
3434
3594
  await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3435
3595
  acquired.wake();
3436
- this._releaseTrigger = new import_async14.Trigger();
3596
+ this._releaseTrigger = new import_async16.Trigger();
3437
3597
  await this._releaseTrigger.wait();
3438
- (0, import_log12.log)("releasing lock...", {}, {
3598
+ (0, import_log14.log)("releasing lock...", {}, {
3439
3599
  file: "vault-resource-lock.ts",
3440
3600
  line: 74,
3441
3601
  scope: this,
3442
3602
  callSite: (f, a) => f(...a)
3443
3603
  });
3444
3604
  await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3445
- (0, import_log12.log)("released lock", {}, {
3605
+ (0, import_log14.log)("released lock", {}, {
3446
3606
  file: "vault-resource-lock.ts",
3447
3607
  line: 76,
3448
3608
  scope: this,
@@ -3453,7 +3613,7 @@ var VaultResourceLock = class {
3453
3613
  await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3454
3614
  });
3455
3615
  await acquired.wait();
3456
- (0, import_log12.log)("recieved lock", {
3616
+ (0, import_log14.log)("recieved lock", {
3457
3617
  steal
3458
3618
  }, {
3459
3619
  file: "vault-resource-lock.ts",
@@ -3464,20 +3624,20 @@ var VaultResourceLock = class {
3464
3624
  }
3465
3625
  };
3466
3626
  __decorate4([
3467
- import_log12.logInfo
3627
+ import_log14.logInfo
3468
3628
  ], VaultResourceLock.prototype, "lockKey", null);
3469
3629
 
3470
3630
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3471
- var import_async16 = require("@dxos/async");
3472
- var import_log14 = require("@dxos/log");
3631
+ var import_async18 = require("@dxos/async");
3632
+ var import_log16 = require("@dxos/log");
3473
3633
  var import_messaging2 = require("@dxos/messaging");
3474
3634
  var import_network_manager4 = require("@dxos/network-manager");
3475
3635
 
3476
3636
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3477
- var import_node_assert11 = __toESM(require("node:assert"));
3478
- var import_async15 = require("@dxos/async");
3637
+ var import_node_assert12 = __toESM(require("node:assert"));
3638
+ var import_async17 = require("@dxos/async");
3479
3639
  var import_client6 = require("@dxos/client");
3480
- var import_log13 = require("@dxos/log");
3640
+ var import_log15 = require("@dxos/log");
3481
3641
  var import_rpc4 = require("@dxos/rpc");
3482
3642
  var import_util8 = require("@dxos/util");
3483
3643
  var __decorate5 = function(decorators, target, key, desc) {
@@ -3494,10 +3654,10 @@ var WorkerSession = class {
3494
3654
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
3495
3655
  heartbeatInterval: 1e3
3496
3656
  } }) {
3497
- this._startTrigger = new import_async15.Trigger();
3657
+ this._startTrigger = new import_async17.Trigger();
3498
3658
  this.onClose = new import_util8.Callback();
3499
- (0, import_node_assert11.default)(options);
3500
- (0, import_node_assert11.default)(serviceHost);
3659
+ (0, import_node_assert12.default)(options);
3660
+ (0, import_node_assert12.default)(serviceHost);
3501
3661
  this._options = options;
3502
3662
  this._serviceHost = serviceHost;
3503
3663
  const middleware = {
@@ -3544,7 +3704,7 @@ var WorkerSession = class {
3544
3704
  try {
3545
3705
  await this.close();
3546
3706
  } catch (err) {
3547
- import_log13.log.catch(err, {}, {
3707
+ import_log15.log.catch(err, {}, {
3548
3708
  file: "worker-session.ts",
3549
3709
  line: 107,
3550
3710
  scope: this,
@@ -3562,7 +3722,7 @@ var WorkerSession = class {
3562
3722
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
3563
3723
  }
3564
3724
  async open() {
3565
- import_log13.log.info("opening..", {}, {
3725
+ import_log15.log.info("opening..", {}, {
3566
3726
  file: "worker-session.ts",
3567
3727
  line: 121,
3568
3728
  scope: this,
@@ -3580,7 +3740,7 @@ var WorkerSession = class {
3580
3740
  try {
3581
3741
  await this._iframeRpc.rpc.IframeService.heartbeat();
3582
3742
  } catch (err1) {
3583
- import_log13.log.warn("Heartbeat failed", {
3743
+ import_log15.log.warn("Heartbeat failed", {
3584
3744
  err: err1
3585
3745
  }, {
3586
3746
  file: "worker-session.ts",
@@ -3591,7 +3751,7 @@ var WorkerSession = class {
3591
3751
  try {
3592
3752
  await this.close();
3593
3753
  } catch (err) {
3594
- import_log13.log.catch(err, {}, {
3754
+ import_log15.log.catch(err, {}, {
3595
3755
  file: "worker-session.ts",
3596
3756
  line: 137,
3597
3757
  scope: this,
@@ -3602,7 +3762,7 @@ var WorkerSession = class {
3602
3762
  }, this._options.heartbeatInterval);
3603
3763
  }
3604
3764
  async close() {
3605
- import_log13.log.info("closing..", {}, {
3765
+ import_log15.log.info("closing..", {}, {
3606
3766
  file: "worker-session.ts",
3607
3767
  line: 144,
3608
3768
  scope: this,
@@ -3611,7 +3771,7 @@ var WorkerSession = class {
3611
3771
  try {
3612
3772
  await this.onClose.callIfSet();
3613
3773
  } catch (err) {
3614
- import_log13.log.catch(err, {}, {
3774
+ import_log15.log.catch(err, {}, {
3615
3775
  file: "worker-session.ts",
3616
3776
  line: 148,
3617
3777
  scope: this,
@@ -3628,9 +3788,9 @@ var WorkerSession = class {
3628
3788
  }
3629
3789
  async _maybeOpenShell() {
3630
3790
  try {
3631
- await (0, import_async15.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3791
+ await (0, import_async17.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3632
3792
  } catch (e) {
3633
- import_log13.log.info("No shell connected.", {}, {
3793
+ import_log15.log.info("No shell connected.", {}, {
3634
3794
  file: "worker-session.ts",
3635
3795
  line: 162,
3636
3796
  scope: this,
@@ -3640,7 +3800,7 @@ var WorkerSession = class {
3640
3800
  }
3641
3801
  };
3642
3802
  __decorate5([
3643
- import_log13.logInfo
3803
+ import_log15.logInfo
3644
3804
  ], WorkerSession.prototype, "origin", void 0);
3645
3805
 
3646
3806
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
@@ -3649,7 +3809,7 @@ var WorkerRuntime = class {
3649
3809
  constructor(_configProvider) {
3650
3810
  this._configProvider = _configProvider;
3651
3811
  this._transportFactory = new import_network_manager4.WebRTCTransportProxyFactory();
3652
- this._ready = new import_async16.Trigger();
3812
+ this._ready = new import_async18.Trigger();
3653
3813
  this.sessions = /* @__PURE__ */ new Set();
3654
3814
  this._clientServices = new ClientServicesHost();
3655
3815
  }
@@ -3657,7 +3817,7 @@ var WorkerRuntime = class {
3657
3817
  return this._clientServices;
3658
3818
  }
3659
3819
  async start() {
3660
- (0, import_log14.log)("starting...", {}, {
3820
+ (0, import_log16.log)("starting...", {}, {
3661
3821
  file: "worker-runtime.ts",
3662
3822
  line: 48,
3663
3823
  scope: this,
@@ -3665,20 +3825,18 @@ var WorkerRuntime = class {
3665
3825
  });
3666
3826
  try {
3667
3827
  this._config = await this._configProvider();
3668
- const signalServer = this._config.get("runtime.services.signal.server");
3828
+ const signals = this._config.get("runtime.services.signaling");
3669
3829
  this._clientServices.initialize({
3670
3830
  config: this._config,
3671
3831
  networkManager: new import_network_manager4.NetworkManager({
3672
3832
  log: true,
3673
- signalManager: signalServer ? new import_messaging2.WebsocketSignalManager([
3674
- signalServer
3675
- ]) : new import_messaging2.MemorySignalManager(new import_messaging2.MemorySignalManagerContext()),
3833
+ signalManager: signals ? new import_messaging2.WebsocketSignalManager(signals) : new import_messaging2.MemorySignalManager(new import_messaging2.MemorySignalManagerContext()),
3676
3834
  transportFactory: this._transportFactory
3677
3835
  })
3678
3836
  });
3679
3837
  await this._clientServices.open();
3680
3838
  this._ready.wake(void 0);
3681
- (0, import_log14.log)("started", {}, {
3839
+ (0, import_log16.log)("started", {}, {
3682
3840
  file: "worker-runtime.ts",
3683
3841
  line: 65,
3684
3842
  scope: this,
@@ -3686,7 +3844,7 @@ var WorkerRuntime = class {
3686
3844
  });
3687
3845
  } catch (err) {
3688
3846
  this._ready.wake(err);
3689
- import_log14.log.catch(err, {}, {
3847
+ import_log16.log.catch(err, {}, {
3690
3848
  file: "worker-runtime.ts",
3691
3849
  line: 68,
3692
3850
  scope: this,
@@ -3738,27 +3896,27 @@ var WorkerRuntime = class {
3738
3896
  };
3739
3897
 
3740
3898
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3741
- var import_node_assert12 = __toESM(require("node:assert"));
3742
- var import_async17 = require("@dxos/async");
3899
+ var import_node_assert13 = __toESM(require("node:assert"));
3900
+ var import_async19 = require("@dxos/async");
3743
3901
  var import_client7 = require("@dxos/client");
3744
3902
  var import_credentials11 = require("@dxos/credentials");
3745
3903
  var import_debug6 = require("@dxos/debug");
3746
3904
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
3747
3905
  var import_feed_store4 = require("@dxos/feed-store");
3748
3906
  var import_keyring = require("@dxos/keyring");
3749
- var import_keys9 = require("@dxos/keys");
3750
- var import_log15 = require("@dxos/log");
3751
- var import_protocols6 = require("@dxos/protocols");
3907
+ var import_keys10 = require("@dxos/keys");
3908
+ var import_log17 = require("@dxos/log");
3909
+ var import_protocols7 = require("@dxos/protocols");
3752
3910
  var ServiceContext = class {
3753
3911
  // prettier-ignore
3754
3912
  constructor(storage, networkManager, modelFactory) {
3755
3913
  this.storage = storage;
3756
3914
  this.networkManager = networkManager;
3757
3915
  this.modelFactory = modelFactory;
3758
- this.initialized = new import_async17.Trigger();
3916
+ this.initialized = new import_async19.Trigger();
3759
3917
  this.dataServiceSubscriptions = new import_echo_pipeline4.DataServiceSubscriptions();
3760
3918
  this._handlerFactories = /* @__PURE__ */ new Map();
3761
- this._instanceId = import_keys9.PublicKey.random().toHex();
3919
+ this._instanceId = import_keys10.PublicKey.random().toHex();
3762
3920
  networkManager._traceParent = this._instanceId;
3763
3921
  this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
3764
3922
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
@@ -3787,7 +3945,7 @@ var ServiceContext = class {
3787
3945
  }, this._acceptIdentity.bind(this)));
3788
3946
  }
3789
3947
  async open() {
3790
- import_log15.log.trace("dxos.sdk.service-context", import_protocols6.trace.begin({
3948
+ import_log17.log.trace("dxos.sdk.service-context", import_protocols7.trace.begin({
3791
3949
  id: this._instanceId
3792
3950
  }), {
3793
3951
  file: "service-context.ts",
@@ -3795,7 +3953,7 @@ var ServiceContext = class {
3795
3953
  scope: this,
3796
3954
  callSite: (f, a) => f(...a)
3797
3955
  });
3798
- (0, import_log15.log)("opening...", {}, {
3956
+ (0, import_log17.log)("opening...", {}, {
3799
3957
  file: "service-context.ts",
3800
3958
  line: 117,
3801
3959
  scope: this,
@@ -3807,7 +3965,7 @@ var ServiceContext = class {
3807
3965
  if (this.identityManager.identity) {
3808
3966
  await this._initialize();
3809
3967
  }
3810
- (0, import_log15.log)("opened", {}, {
3968
+ (0, import_log17.log)("opened", {}, {
3811
3969
  file: "service-context.ts",
3812
3970
  line: 124,
3813
3971
  scope: this,
@@ -3816,7 +3974,7 @@ var ServiceContext = class {
3816
3974
  }
3817
3975
  async close() {
3818
3976
  var _a, _b;
3819
- (0, import_log15.log)("closing...", {}, {
3977
+ (0, import_log17.log)("closing...", {}, {
3820
3978
  file: "service-context.ts",
3821
3979
  line: 128,
3822
3980
  scope: this,
@@ -3829,13 +3987,13 @@ var ServiceContext = class {
3829
3987
  await this.feedStore.close();
3830
3988
  await this.networkManager.close();
3831
3989
  this.dataServiceSubscriptions.clear();
3832
- (0, import_log15.log)("closed", {}, {
3990
+ (0, import_log17.log)("closed", {}, {
3833
3991
  file: "service-context.ts",
3834
3992
  line: 136,
3835
3993
  scope: this,
3836
3994
  callSite: (f, a) => f(...a)
3837
3995
  });
3838
- import_log15.log.trace("dxos.sdk.service-context", import_protocols6.trace.end({
3996
+ import_log17.log.trace("dxos.sdk.service-context", import_protocols7.trace.end({
3839
3997
  id: this._instanceId
3840
3998
  }), {
3841
3999
  file: "service-context.ts",
@@ -3851,7 +4009,7 @@ var ServiceContext = class {
3851
4009
  }
3852
4010
  getInvitationHandler(invitation) {
3853
4011
  const factory = this._handlerFactories.get(invitation.kind);
3854
- (0, import_node_assert12.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
4012
+ (0, import_node_assert13.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3855
4013
  return factory(invitation);
3856
4014
  }
3857
4015
  async _acceptIdentity(params) {
@@ -3862,7 +4020,7 @@ var ServiceContext = class {
3862
4020
  // Called when identity is created.
3863
4021
  async _initialize() {
3864
4022
  var _a;
3865
- (0, import_log15.log)("initializing spaces...", {}, {
4023
+ (0, import_log17.log)("initializing spaces...", {}, {
3866
4024
  file: "service-context.ts",
3867
4025
  line: 163,
3868
4026
  scope: this,
@@ -3886,7 +4044,7 @@ var ServiceContext = class {
3886
4044
  this.dataSpaceManager._traceParent = this._instanceId;
3887
4045
  await this.dataSpaceManager.open();
3888
4046
  this._handlerFactories.set(import_client7.Invitation.Kind.SPACE, (invitation) => {
3889
- (0, import_node_assert12.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
4047
+ (0, import_node_assert13.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3890
4048
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3891
4049
  });
3892
4050
  this.initialized.wake();
@@ -3900,7 +4058,7 @@ var ServiceContext = class {
3900
4058
  return;
3901
4059
  }
3902
4060
  if (!this.dataSpaceManager) {
3903
- (0, import_log15.log)("dataSpaceManager not initialized yet, ignoring space admission", {
4061
+ (0, import_log17.log)("dataSpaceManager not initialized yet, ignoring space admission", {
3904
4062
  details: assertion
3905
4063
  }, {
3906
4064
  file: "service-context.ts",
@@ -3911,7 +4069,7 @@ var ServiceContext = class {
3911
4069
  return;
3912
4070
  }
3913
4071
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3914
- (0, import_log15.log)("space already exists, ignoring space admission", {
4072
+ (0, import_log17.log)("space already exists, ignoring space admission", {
3915
4073
  details: assertion
3916
4074
  }, {
3917
4075
  file: "service-context.ts",
@@ -3922,7 +4080,7 @@ var ServiceContext = class {
3922
4080
  return;
3923
4081
  }
3924
4082
  try {
3925
- (0, import_log15.log)("accepting space recorded in halo", {
4083
+ (0, import_log17.log)("accepting space recorded in halo", {
3926
4084
  details: assertion
3927
4085
  }, {
3928
4086
  file: "service-context.ts",
@@ -3935,7 +4093,7 @@ var ServiceContext = class {
3935
4093
  genesisFeedKey: assertion.genesisFeedKey
3936
4094
  });
3937
4095
  } catch (err) {
3938
- import_log15.log.catch(err, {}, {
4096
+ import_log17.log.catch(err, {}, {
3939
4097
  file: "service-context.ts",
3940
4098
  line: 220,
3941
4099
  scope: this,
@@ -3983,7 +4141,7 @@ var ClientServicesHost = class {
3983
4141
  // TODO(wittjosiah): Turn this on by default.
3984
4142
  lockKey
3985
4143
  } = {}) {
3986
- this._statusUpdate = new import_async18.Event();
4144
+ this._statusUpdate = new import_async20.Event();
3987
4145
  this._opening = false;
3988
4146
  this._open = false;
3989
4147
  this._instanceId = import_client8.PublicKey.random().toHex();
@@ -4040,16 +4198,16 @@ var ClientServicesHost = class {
4040
4198
  * Can only be called once.
4041
4199
  */
4042
4200
  initialize({ config, networkManager }) {
4043
- (0, import_node_assert13.default)(!this._open, "service host is open");
4201
+ (0, import_node_assert14.default)(!this._open, "service host is open");
4044
4202
  if (config) {
4045
- (0, import_node_assert13.default)(!this._config, "config already set");
4203
+ (0, import_node_assert14.default)(!this._config, "config already set");
4046
4204
  this._config = config;
4047
4205
  if (!this._storage) {
4048
4206
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
4049
4207
  }
4050
4208
  }
4051
4209
  if (networkManager) {
4052
- (0, import_node_assert13.default)(!this._networkManager, "network manager already set");
4210
+ (0, import_node_assert14.default)(!this._networkManager, "network manager already set");
4053
4211
  this._networkManager = networkManager;
4054
4212
  }
4055
4213
  }
@@ -4058,7 +4216,7 @@ var ClientServicesHost = class {
4058
4216
  if (this._open) {
4059
4217
  return;
4060
4218
  }
4061
- import_log16.log.trace("dxos.sdk.client-services-host", import_protocols7.trace.begin({
4219
+ import_log18.log.trace("dxos.sdk.client-services-host", import_protocols8.trace.begin({
4062
4220
  id: this._instanceId
4063
4221
  }), {
4064
4222
  file: "service-host.ts",
@@ -4066,11 +4224,11 @@ var ClientServicesHost = class {
4066
4224
  scope: this,
4067
4225
  callSite: (f, a) => f(...a)
4068
4226
  });
4069
- (0, import_node_assert13.default)(this._config, "config not set");
4070
- (0, import_node_assert13.default)(this._storage, "storage not set");
4071
- (0, import_node_assert13.default)(this._networkManager, "network manager not set");
4227
+ (0, import_node_assert14.default)(this._config, "config not set");
4228
+ (0, import_node_assert14.default)(this._storage, "storage not set");
4229
+ (0, import_node_assert14.default)(this._networkManager, "network manager not set");
4072
4230
  this._opening = true;
4073
- (0, import_log16.log)("opening...", {
4231
+ (0, import_log18.log)("opening...", {
4074
4232
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4075
4233
  }, {
4076
4234
  file: "service-host.ts",
@@ -4104,7 +4262,7 @@ var ClientServicesHost = class {
4104
4262
  this._open = true;
4105
4263
  this._statusUpdate.emit();
4106
4264
  const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4107
- (0, import_log16.log)("opened", {
4265
+ (0, import_log18.log)("opened", {
4108
4266
  deviceKey
4109
4267
  }, {
4110
4268
  file: "service-host.ts",
@@ -4119,7 +4277,7 @@ var ClientServicesHost = class {
4119
4277
  return;
4120
4278
  }
4121
4279
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4122
- (0, import_log16.log)("closing...", {
4280
+ (0, import_log18.log)("closing...", {
4123
4281
  deviceKey
4124
4282
  }, {
4125
4283
  file: "service-host.ts",
@@ -4133,7 +4291,7 @@ var ClientServicesHost = class {
4133
4291
  await this._serviceContext.close();
4134
4292
  this._open = false;
4135
4293
  this._statusUpdate.emit();
4136
- (0, import_log16.log)("closed", {
4294
+ (0, import_log18.log)("closed", {
4137
4295
  deviceKey
4138
4296
  }, {
4139
4297
  file: "service-host.ts",
@@ -4141,7 +4299,7 @@ var ClientServicesHost = class {
4141
4299
  scope: this,
4142
4300
  callSite: (f, a) => f(...a)
4143
4301
  });
4144
- import_log16.log.trace("dxos.sdk.client-services-host", import_protocols7.trace.end({
4302
+ import_log18.log.trace("dxos.sdk.client-services-host", import_protocols8.trace.end({
4145
4303
  id: this._instanceId
4146
4304
  }), {
4147
4305
  file: "service-host.ts",
@@ -4152,7 +4310,7 @@ var ClientServicesHost = class {
4152
4310
  }
4153
4311
  async reset() {
4154
4312
  var _a;
4155
- (0, import_log16.log)("resetting...", {}, {
4313
+ (0, import_log18.log)("resetting...", {}, {
4156
4314
  file: "service-host.ts",
4157
4315
  line: 240,
4158
4316
  scope: this,
@@ -4160,7 +4318,7 @@ var ClientServicesHost = class {
4160
4318
  });
4161
4319
  await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4162
4320
  await this._storage.reset();
4163
- (0, import_log16.log)("reset", {}, {
4321
+ (0, import_log18.log)("reset", {}, {
4164
4322
  file: "service-host.ts",
4165
4323
  line: 243,
4166
4324
  scope: this,
@@ -4193,7 +4351,7 @@ var LocalClientServices = class {
4193
4351
 
4194
4352
  // packages/sdk/client-services/src/packlets/services/utils.ts
4195
4353
  var import_config2 = require("@dxos/config");
4196
- var import_log17 = require("@dxos/log");
4354
+ var import_log19 = require("@dxos/log");
4197
4355
  var import_messaging3 = require("@dxos/messaging");
4198
4356
  var import_network_manager5 = require("@dxos/network-manager");
4199
4357
  var fromHost = (config = new import_config2.Config()) => {
@@ -4203,11 +4361,9 @@ var fromHost = (config = new import_config2.Config()) => {
4203
4361
  });
4204
4362
  };
4205
4363
  var createNetworkManager = (config, options = {}) => {
4206
- const signalServer = config.get("runtime.services.signal.server");
4207
- if (signalServer) {
4208
- const { log: log1 = true, signalManager = new import_messaging3.WebsocketSignalManager([
4209
- signalServer
4210
- ]), transportFactory = (0, import_network_manager5.createWebRTCTransportFactory)({
4364
+ const signals = config.get("runtime.services.signaling");
4365
+ if (signals) {
4366
+ const { log: log1 = true, signalManager = new import_messaging3.WebsocketSignalManager(signals), transportFactory = (0, import_network_manager5.createWebRTCTransportFactory)({
4211
4367
  iceServers: config.get("runtime.services.ice")
4212
4368
  }) } = options;
4213
4369
  return new import_network_manager5.NetworkManager({
@@ -4216,7 +4372,7 @@ var createNetworkManager = (config, options = {}) => {
4216
4372
  transportFactory
4217
4373
  });
4218
4374
  }
4219
- import_log17.log.warn("P2P network is not configured.", {}, {
4375
+ import_log19.log.warn("P2P network is not configured.", {}, {
4220
4376
  file: "utils.ts",
4221
4377
  line: 48,
4222
4378
  scope: void 0,