@dxos/client-services 0.1.49-next.fdd6c88 → 0.1.50-next.1bfebf8

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 (49) hide show
  1. package/dist/lib/browser/{chunk-KMQOZOUZ.mjs → chunk-UL74TKNZ.mjs} +543 -1131
  2. package/dist/lib/browser/chunk-UL74TKNZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +601 -9
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/index.cjs +1164 -1214
  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 +302 -780
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/index.d.ts +1 -0
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/packlets/devtools/devtools.d.ts +2 -1
  15. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  16. package/dist/types/src/packlets/devtools/metadata.d.ts +7 -0
  17. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -0
  18. package/dist/types/src/packlets/locks/browser.d.ts +16 -0
  19. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -0
  20. package/dist/types/src/packlets/locks/index.d.ts +3 -0
  21. package/dist/types/src/packlets/locks/index.d.ts.map +1 -0
  22. package/dist/types/src/packlets/locks/node.d.ts +13 -0
  23. package/dist/types/src/packlets/locks/node.d.ts.map +1 -0
  24. package/dist/types/src/packlets/locks/resource-lock.d.ts +16 -0
  25. package/dist/types/src/packlets/locks/resource-lock.d.ts.map +1 -0
  26. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  27. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space.d.ts +1 -1
  29. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/spaces-service.d.ts +0 -3
  31. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  32. package/dist/types/src/packlets/vault/index.d.ts +0 -1
  33. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  34. package/package.json +33 -30
  35. package/src/index.ts +1 -0
  36. package/src/packlets/devtools/devtools.ts +6 -0
  37. package/src/packlets/devtools/metadata.ts +14 -0
  38. package/src/packlets/{vault/vault-resource-lock.ts → locks/browser.ts} +13 -11
  39. package/src/packlets/locks/index.ts +6 -0
  40. package/src/packlets/locks/node.ts +52 -0
  41. package/src/packlets/locks/resource-lock.ts +24 -0
  42. package/src/packlets/services/service-context.ts +1 -2
  43. package/src/packlets/services/service-host.ts +13 -13
  44. package/src/packlets/spaces/notarization-plugin.ts +7 -3
  45. package/src/packlets/spaces/spaces-service.ts +0 -3
  46. package/src/packlets/vault/index.ts +0 -1
  47. package/dist/lib/browser/chunk-KMQOZOUZ.mjs.map +0 -7
  48. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +0 -20
  49. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +0 -1
@@ -199,7 +199,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
199
199
 
200
200
  // packages/sdk/client-services/src/packlets/devtools/devtools.ts
201
201
  import { Event as AsyncEvent } from "@dxos/async";
202
- import { Stream as Stream5 } from "@dxos/codec-protobuf";
202
+ import { Stream as Stream6 } from "@dxos/codec-protobuf";
203
203
 
204
204
  // packages/sdk/client-services/src/packlets/devtools/keys.ts
205
205
  import { scheduleTask } from "@dxos/async";
@@ -214,6 +214,17 @@ var subscribeToKeyringKeys = ({ keyring }) => new Stream4(({ next, ctx }) => {
214
214
  scheduleTask(ctx, update);
215
215
  });
216
216
 
217
+ // packages/sdk/client-services/src/packlets/devtools/metadata.ts
218
+ import { Stream as Stream5 } from "@dxos/codec-protobuf";
219
+ var subscribeToMetadata = ({ context }) => new Stream5(({ next, ctx }) => {
220
+ context.metadataStore.update.on(ctx, (data) => next({
221
+ metadata: data
222
+ }));
223
+ next({
224
+ metadata: context.metadataStore.metadata
225
+ });
226
+ });
227
+
217
228
  // packages/sdk/client-services/src/packlets/devtools/devtools.ts
218
229
  var DevtoolsHostEvents = class {
219
230
  constructor() {
@@ -225,7 +236,7 @@ var DevtoolsServiceImpl = class {
225
236
  this.params = params;
226
237
  }
227
238
  events(request) {
228
- return new Stream5(({ next }) => {
239
+ return new Stream6(({ next }) => {
229
240
  this.params.events.ready.on(() => {
230
241
  next({
231
242
  ready: {}
@@ -317,6 +328,11 @@ var DevtoolsServiceImpl = class {
317
328
  networkManager: this.params.context.networkManager
318
329
  });
319
330
  }
331
+ subscribeToMetadata() {
332
+ return subscribeToMetadata({
333
+ context: this.params.context
334
+ });
335
+ }
320
336
  };
321
337
 
322
338
  // packages/sdk/client-services/src/packlets/identity/authenticator.ts
@@ -840,7 +856,7 @@ var IdentityManager = class {
840
856
 
841
857
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
842
858
  import assert3 from "@dxos/node-std/assert";
843
- import { Stream as Stream6 } from "@dxos/codec-protobuf";
859
+ import { Stream as Stream7 } from "@dxos/codec-protobuf";
844
860
  import { signPresentation } from "@dxos/credentials";
845
861
  import { todo } from "@dxos/debug";
846
862
  var IdentityServiceImpl = class {
@@ -856,7 +872,7 @@ var IdentityServiceImpl = class {
856
872
  return todo();
857
873
  }
858
874
  queryIdentity() {
859
- return new Stream6(({ next }) => {
875
+ return new Stream7(({ next }) => {
860
876
  const emitNext = () => next({
861
877
  identity: this._getIdentity()
862
878
  });
@@ -1788,7 +1804,7 @@ var InvitationsHandler = class {
1788
1804
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1789
1805
  import assert7 from "@dxos/node-std/assert";
1790
1806
  import { Event as Event3 } from "@dxos/async";
1791
- import { Stream as Stream7 } from "@dxos/codec-protobuf";
1807
+ import { Stream as Stream8 } from "@dxos/codec-protobuf";
1792
1808
  import { log as log6 } from "@dxos/log";
1793
1809
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
1794
1810
  var InvitationsServiceImpl = class {
@@ -1817,7 +1833,7 @@ var InvitationsServiceImpl = class {
1817
1833
  this._createInvitations.set(invitation.get().invitationId, invitation);
1818
1834
  this._invitationCreated.emit(invitation.get());
1819
1835
  }
1820
- return new Stream7(({ next, close }) => {
1836
+ return new Stream8(({ next, close }) => {
1821
1837
  invitation.subscribe((invitation2) => {
1822
1838
  next(invitation2);
1823
1839
  }, (err) => {
@@ -1839,7 +1855,7 @@ var InvitationsServiceImpl = class {
1839
1855
  this._acceptInvitations.set(invitation.get().invitationId, invitation);
1840
1856
  this._invitationAccepted.emit(invitation.get());
1841
1857
  }
1842
- return new Stream7(({ next, close }) => {
1858
+ return new Stream8(({ next, close }) => {
1843
1859
  invitation.subscribe((invitation2) => {
1844
1860
  next(invitation2);
1845
1861
  }, (err) => {
@@ -1902,7 +1918,7 @@ var InvitationsServiceImpl = class {
1902
1918
  }
1903
1919
  }
1904
1920
  queryInvitations() {
1905
- return new Stream7(({ next, ctx }) => {
1921
+ return new Stream8(({ next, ctx }) => {
1906
1922
  this._invitationCreated.on(ctx, (invitation) => {
1907
1923
  next({
1908
1924
  action: QueryInvitationsResponse.Action.ADDED,
@@ -2043,6 +2059,131 @@ var SpaceInvitationProtocol = class {
2043
2059
  }
2044
2060
  };
2045
2061
 
2062
+ // packages/sdk/client-services/src/packlets/locks/browser.ts
2063
+ import { asyncTimeout, Trigger as Trigger4 } from "@dxos/async";
2064
+ import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
2065
+ import { log as log8, logInfo } from "@dxos/log";
2066
+ var __decorate = function(decorators, target, key, desc) {
2067
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2068
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2069
+ r = Reflect.decorate(decorators, target, key, desc);
2070
+ else
2071
+ for (var i = decorators.length - 1; i >= 0; i--)
2072
+ if (d = decorators[i])
2073
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2074
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2075
+ };
2076
+ var Message;
2077
+ (function(Message2) {
2078
+ Message2["ACQUIRING"] = "acquiring";
2079
+ })(Message || (Message = {}));
2080
+ var Lock = class {
2081
+ constructor({ lockKey, onAcquire, onRelease }) {
2082
+ this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
2083
+ this._releaseTrigger = new Trigger4();
2084
+ this._lockKey = lockKey;
2085
+ this._onAcquire = onAcquire;
2086
+ this._onRelease = onRelease;
2087
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
2088
+ }
2089
+ get lockKey() {
2090
+ return this._lockKey;
2091
+ }
2092
+ async acquire() {
2093
+ this._broadcastChannel.postMessage({
2094
+ message: Message.ACQUIRING
2095
+ });
2096
+ try {
2097
+ log8("aquiring lock...", {}, {
2098
+ file: "browser.ts",
2099
+ line: 42,
2100
+ scope: this,
2101
+ callSite: (f, a) => f(...a)
2102
+ });
2103
+ await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
2104
+ log8("acquired lock", {}, {
2105
+ file: "browser.ts",
2106
+ line: 44,
2107
+ scope: this,
2108
+ callSite: (f, a) => f(...a)
2109
+ });
2110
+ } catch (e) {
2111
+ log8("stealing lock...", {}, {
2112
+ file: "browser.ts",
2113
+ line: 46,
2114
+ scope: this,
2115
+ callSite: (f, a) => f(...a)
2116
+ });
2117
+ await this._requestLock(true);
2118
+ log8("stolen lock", {}, {
2119
+ file: "browser.ts",
2120
+ line: 48,
2121
+ scope: this,
2122
+ callSite: (f, a) => f(...a)
2123
+ });
2124
+ }
2125
+ }
2126
+ async release() {
2127
+ this._releaseTrigger.wake();
2128
+ }
2129
+ _onMessage(event) {
2130
+ if (event.data.message === Message.ACQUIRING) {
2131
+ this._releaseTrigger.wake();
2132
+ }
2133
+ }
2134
+ async _requestLock(steal = false) {
2135
+ log8("requesting lock...", {
2136
+ steal
2137
+ }, {
2138
+ file: "browser.ts",
2139
+ line: 63,
2140
+ scope: this,
2141
+ callSite: (f, a) => f(...a)
2142
+ });
2143
+ const acquired = new Trigger4();
2144
+ void navigator.locks.request(this._lockKey, {
2145
+ steal
2146
+ }, async () => {
2147
+ var _a, _b;
2148
+ await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
2149
+ acquired.wake();
2150
+ this._releaseTrigger = new Trigger4();
2151
+ await this._releaseTrigger.wait();
2152
+ log8("releasing lock...", {}, {
2153
+ file: "browser.ts",
2154
+ line: 72,
2155
+ scope: this,
2156
+ callSite: (f, a) => f(...a)
2157
+ });
2158
+ await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
2159
+ log8("released lock", {}, {
2160
+ file: "browser.ts",
2161
+ line: 74,
2162
+ scope: this,
2163
+ callSite: (f, a) => f(...a)
2164
+ });
2165
+ }).catch(async () => {
2166
+ var _a;
2167
+ await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
2168
+ });
2169
+ await acquired.wait();
2170
+ log8("recieved lock", {
2171
+ steal
2172
+ }, {
2173
+ file: "browser.ts",
2174
+ line: 81,
2175
+ scope: this,
2176
+ callSite: (f, a) => f(...a)
2177
+ });
2178
+ }
2179
+ };
2180
+ __decorate([
2181
+ logInfo
2182
+ ], Lock.prototype, "lockKey", null);
2183
+ var isLocked = (lockPath) => {
2184
+ throw new Error("Not implemented");
2185
+ };
2186
+
2046
2187
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2047
2188
  import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2048
2189
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
@@ -2051,23 +2192,24 @@ import { timed } from "@dxos/debug";
2051
2192
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2052
2193
  import { CancelledError, SystemError } from "@dxos/errors";
2053
2194
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2054
- import { log as log9 } from "@dxos/log";
2195
+ import { log as log10 } from "@dxos/log";
2055
2196
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2056
2197
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2057
2198
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2058
2199
 
2059
2200
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2060
2201
  import assert9 from "@dxos/node-std/assert";
2061
- import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2202
+ import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
2062
2203
  import { Context as Context5, rejectOnDispose } from "@dxos/context";
2063
2204
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2064
- import { log as log8 } from "@dxos/log";
2205
+ import { log as log9 } from "@dxos/log";
2065
2206
  import { schema as schema3 } from "@dxos/protocols";
2066
2207
  import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
2067
2208
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2068
2209
  var DEFAULT_RETRY_TIMEOUT = 1e3;
2069
2210
  var DEFAULT_SUCCESS_DELAY = 1e3;
2070
2211
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2212
+ var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2071
2213
  var NotarizationPlugin = class {
2072
2214
  constructor() {
2073
2215
  this._ctx = new Context5();
@@ -2085,23 +2227,23 @@ var NotarizationPlugin = class {
2085
2227
  * Request credentials to be notarized.
2086
2228
  */
2087
2229
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2088
- log8("notarize", {
2230
+ log9("notarize", {
2089
2231
  credentials
2090
2232
  }, {
2091
2233
  file: "notarization-plugin.ts",
2092
- line: 85,
2234
+ line: 87,
2093
2235
  scope: this,
2094
2236
  callSite: (f, a) => f(...a)
2095
2237
  });
2096
2238
  assert9(credentials.every((credential) => credential.id), "Credentials must have an id");
2097
- const errors = new Trigger4();
2239
+ const errors = new Trigger5();
2098
2240
  const ctx = this._ctx.derive({
2099
2241
  onError: (err) => {
2100
- log8.warn("Notarization error", {
2242
+ log9.warn("Notarization error", {
2101
2243
  err
2102
2244
  }, {
2103
2245
  file: "notarization-plugin.ts",
2104
- line: 94,
2246
+ line: 96,
2105
2247
  scope: this,
2106
2248
  callSite: (f, a) => f(...a)
2107
2249
  });
@@ -2112,12 +2254,12 @@ var NotarizationPlugin = class {
2112
2254
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2113
2255
  if (timeout !== 0) {
2114
2256
  scheduleTask3(ctx, () => {
2115
- log8.warn("Notarization timeout", {
2257
+ log9.warn("Notarization timeout", {
2116
2258
  timeout,
2117
2259
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2118
2260
  }, {
2119
2261
  file: "notarization-plugin.ts",
2120
- line: 106,
2262
+ line: 108,
2121
2263
  scope: this,
2122
2264
  callSite: (f, a) => f(...a)
2123
2265
  });
@@ -2136,11 +2278,11 @@ var NotarizationPlugin = class {
2136
2278
  ...this._extensions
2137
2279
  ].find((peer2) => !peersTried.has(peer2));
2138
2280
  if (!peer) {
2139
- log8.warn("Exhausted all peers to notarize with", {
2281
+ log9.warn("Exhausted all peers to notarize with", {
2140
2282
  retryIn: retryTimeout
2141
2283
  }, {
2142
2284
  file: "notarization-plugin.ts",
2143
- line: 131,
2285
+ line: 133,
2144
2286
  scope: this,
2145
2287
  callSite: (f, a) => f(...a)
2146
2288
  });
@@ -2149,32 +2291,34 @@ var NotarizationPlugin = class {
2149
2291
  return;
2150
2292
  }
2151
2293
  peersTried.add(peer);
2152
- log8("try notarizing", {
2294
+ log9("try notarizing", {
2153
2295
  peer: peer.localPeerId,
2154
2296
  credentialId: credentials.map((credential) => credential.id)
2155
2297
  }, {
2156
2298
  file: "notarization-plugin.ts",
2157
- line: 138,
2299
+ line: 140,
2158
2300
  scope: this,
2159
2301
  callSite: (f, a) => f(...a)
2160
2302
  });
2161
2303
  await peer.rpc.NotarizationService.notarize({
2162
2304
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2163
2305
  });
2164
- log8("success", {}, {
2306
+ log9("success", {}, {
2165
2307
  file: "notarization-plugin.ts",
2166
- line: 142,
2308
+ line: 144,
2167
2309
  scope: this,
2168
2310
  callSite: (f, a) => f(...a)
2169
2311
  });
2170
2312
  await sleep2(successDelay);
2171
2313
  } catch (err) {
2172
- log8.warn("error notarizing (recoverable)", err, {
2173
- file: "notarization-plugin.ts",
2174
- line: 145,
2175
- scope: this,
2176
- callSite: (f, a) => f(...a)
2177
- });
2314
+ if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2315
+ log9.warn("error notarizing (recoverable)", err, {
2316
+ file: "notarization-plugin.ts",
2317
+ line: 148,
2318
+ scope: this,
2319
+ callSite: (f, a) => f(...a)
2320
+ });
2321
+ }
2178
2322
  notarizeTask.schedule();
2179
2323
  }
2180
2324
  });
@@ -2186,9 +2330,9 @@ var NotarizationPlugin = class {
2186
2330
  allNotarized,
2187
2331
  errors.wait()
2188
2332
  ]);
2189
- log8("done", {}, {
2333
+ log9("done", {}, {
2190
2334
  file: "notarization-plugin.ts",
2191
- line: 155,
2335
+ line: 159,
2192
2336
  scope: this,
2193
2337
  callSite: (f, a) => f(...a)
2194
2338
  });
@@ -2216,7 +2360,7 @@ var NotarizationPlugin = class {
2216
2360
  if (this._processedCredentials.has(id)) {
2217
2361
  return;
2218
2362
  }
2219
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger4()).value.wait();
2363
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger5()).value.wait();
2220
2364
  }
2221
2365
  /**
2222
2366
  * Requests from other peers to notarize credentials.
@@ -2224,7 +2368,7 @@ var NotarizationPlugin = class {
2224
2368
  async _onNotarize(request) {
2225
2369
  var _a;
2226
2370
  if (!this._writer) {
2227
- throw new Error("Writer not set");
2371
+ throw new Error(WRITER_NOT_SET_ERROR_CODE);
2228
2372
  }
2229
2373
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2230
2374
  assert9(credential.id, "Credential must have an id");
@@ -2237,11 +2381,11 @@ var NotarizationPlugin = class {
2237
2381
  createExtension() {
2238
2382
  const extension = new NotarizationTeleportExtension({
2239
2383
  onOpen: async () => {
2240
- log8("extension opened", {
2384
+ log9("extension opened", {
2241
2385
  peer: extension.localPeerId
2242
2386
  }, {
2243
2387
  file: "notarization-plugin.ts",
2244
- line: 204,
2388
+ line: 208,
2245
2389
  scope: this,
2246
2390
  callSite: (f, a) => f(...a)
2247
2391
  });
@@ -2249,11 +2393,11 @@ var NotarizationPlugin = class {
2249
2393
  this._extensionOpened.emit();
2250
2394
  },
2251
2395
  onClose: async () => {
2252
- log8("extension closed", {
2396
+ log9("extension closed", {
2253
2397
  peer: extension.localPeerId
2254
2398
  }, {
2255
2399
  file: "notarization-plugin.ts",
2256
- line: 209,
2400
+ line: 213,
2257
2401
  scope: this,
2258
2402
  callSite: (f, a) => f(...a)
2259
2403
  });
@@ -2296,7 +2440,7 @@ var NotarizationTeleportExtension = class extends RpcExtension2 {
2296
2440
  };
2297
2441
 
2298
2442
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2299
- var __decorate = function(decorators, target, key, desc) {
2443
+ var __decorate2 = function(decorators, target, key, desc) {
2300
2444
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2301
2445
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2302
2446
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2391,7 +2535,7 @@ var DataSpace = class DataSpace2 {
2391
2535
  await this.initializeDataPipeline();
2392
2536
  } catch (err) {
2393
2537
  if (err instanceof CancelledError) {
2394
- log9("Data pipeline initialization cancelled", err, {
2538
+ log10("Data pipeline initialization cancelled", err, {
2395
2539
  file: "data-space.ts",
2396
2540
  line: 172,
2397
2541
  scope: this,
@@ -2399,7 +2543,7 @@ var DataSpace = class DataSpace2 {
2399
2543
  });
2400
2544
  return;
2401
2545
  }
2402
- log9.error("Error initializing data pipeline", err, {
2546
+ log10.error("Error initializing data pipeline", err, {
2403
2547
  file: "data-space.ts",
2404
2548
  line: 176,
2405
2549
  scope: this,
@@ -2425,7 +2569,7 @@ var DataSpace = class DataSpace2 {
2425
2569
  });
2426
2570
  this.metrics.controlPipelineReady = new Date();
2427
2571
  await this._createWritableFeeds();
2428
- log9("Writable feeds created", {}, {
2572
+ log10("Writable feeds created", {}, {
2429
2573
  file: "data-space.ts",
2430
2574
  line: 201,
2431
2575
  scope: this,
@@ -2440,7 +2584,7 @@ var DataSpace = class DataSpace2 {
2440
2584
  await this._inner.initializeDataPipeline();
2441
2585
  this.metrics.dataPipelineOpen = new Date();
2442
2586
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2443
- log9("waiting for data pipeline to reach target timeframe", {}, {
2587
+ log10("waiting for data pipeline to reach target timeframe", {}, {
2444
2588
  file: "data-space.ts",
2445
2589
  line: 220,
2446
2590
  scope: this,
@@ -2451,7 +2595,7 @@ var DataSpace = class DataSpace2 {
2451
2595
  breakOnStall: false
2452
2596
  });
2453
2597
  this.metrics.dataPipelineReady = new Date();
2454
- log9("data pipeline ready", {}, {
2598
+ log10("data pipeline ready", {}, {
2455
2599
  file: "data-space.ts",
2456
2600
  line: 229,
2457
2601
  scope: this,
@@ -2527,10 +2671,10 @@ var DataSpace = class DataSpace2 {
2527
2671
  }
2528
2672
  }
2529
2673
  };
2530
- __decorate([
2674
+ __decorate2([
2531
2675
  timed(1e4)
2532
2676
  ], DataSpace.prototype, "_createWritableFeeds", null);
2533
- DataSpace = __decorate([
2677
+ DataSpace = __decorate2([
2534
2678
  trackLeaks("open", "close")
2535
2679
  ], DataSpace);
2536
2680
 
@@ -2540,7 +2684,7 @@ import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/
2540
2684
  import { cancelWithContext as cancelWithContext3, Context as Context7 } from "@dxos/context";
2541
2685
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2542
2686
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2543
- import { log as log10 } from "@dxos/log";
2687
+ import { log as log11 } from "@dxos/log";
2544
2688
  import { trace as trace4 } from "@dxos/protocols";
2545
2689
  import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2546
2690
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
@@ -2617,7 +2761,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2617
2761
  };
2618
2762
 
2619
2763
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2620
- var __decorate2 = function(decorators, target, key, desc) {
2764
+ var __decorate3 = function(decorators, target, key, desc) {
2621
2765
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2622
2766
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2623
2767
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2646,13 +2790,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2646
2790
  return this._spaces;
2647
2791
  }
2648
2792
  async open() {
2649
- log10("open", {}, {
2793
+ log11("open", {}, {
2650
2794
  file: "data-space-manager.ts",
2651
2795
  line: 80,
2652
2796
  scope: this,
2653
2797
  callSite: (f, a) => f(...a)
2654
2798
  });
2655
- log10.trace("dxos.echo.data-space-manager.open", trace4.begin({
2799
+ log11.trace("dxos.echo.data-space-manager.open", trace4.begin({
2656
2800
  id: this._instanceId
2657
2801
  }), {
2658
2802
  file: "data-space-manager.ts",
@@ -2661,7 +2805,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2661
2805
  callSite: (f, a) => f(...a)
2662
2806
  });
2663
2807
  await this._metadataStore.load();
2664
- log10("metadata loaded", {
2808
+ log11("metadata loaded", {
2665
2809
  spaces: this._metadataStore.spaces.length
2666
2810
  }, {
2667
2811
  file: "data-space-manager.ts",
@@ -2671,7 +2815,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2671
2815
  });
2672
2816
  for (const spaceMetadata of this._metadataStore.spaces) {
2673
2817
  try {
2674
- log10("load space", {
2818
+ log11("load space", {
2675
2819
  spaceMetadata
2676
2820
  }, {
2677
2821
  file: "data-space-manager.ts",
@@ -2682,7 +2826,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2682
2826
  const space = await this._constructSpace(spaceMetadata);
2683
2827
  space.initializeDataPipelineAsync();
2684
2828
  } catch (err) {
2685
- log10.error("Error loading space", {
2829
+ log11.error("Error loading space", {
2686
2830
  spaceMetadata,
2687
2831
  err
2688
2832
  }, {
@@ -2695,7 +2839,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2695
2839
  }
2696
2840
  this._isOpen = true;
2697
2841
  this.updated.emit();
2698
- log10.trace("dxos.echo.data-space-manager.open", trace4.end({
2842
+ log11.trace("dxos.echo.data-space-manager.open", trace4.end({
2699
2843
  id: this._instanceId
2700
2844
  }), {
2701
2845
  file: "data-space-manager.ts",
@@ -2705,7 +2849,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2705
2849
  });
2706
2850
  }
2707
2851
  async close() {
2708
- log10("close", {}, {
2852
+ log11("close", {}, {
2709
2853
  file: "data-space-manager.ts",
2710
2854
  line: 102,
2711
2855
  scope: this,
@@ -2731,7 +2875,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2731
2875
  controlFeedKey,
2732
2876
  dataFeedKey
2733
2877
  };
2734
- log10("creating space...", {
2878
+ log11("creating space...", {
2735
2879
  spaceKey
2736
2880
  }, {
2737
2881
  file: "data-space-manager.ts",
@@ -2751,7 +2895,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2751
2895
  }
2752
2896
  // TODO(burdon): Rename join space.
2753
2897
  async acceptSpace(opts) {
2754
- log10("accept space", {
2898
+ log11("accept space", {
2755
2899
  opts
2756
2900
  }, {
2757
2901
  file: "data-space-manager.ts",
@@ -2785,7 +2929,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2785
2929
  }));
2786
2930
  }
2787
2931
  async _constructSpace(metadata) {
2788
- log10("construct space", {
2932
+ log11("construct space", {
2789
2933
  metadata
2790
2934
  }, {
2791
2935
  file: "data-space-manager.ts",
@@ -2823,7 +2967,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2823
2967
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2824
2968
  },
2825
2969
  onAuthFailure: () => {
2826
- log10.warn("auth failure", {}, {
2970
+ log11.warn("auth failure", {}, {
2827
2971
  file: "data-space-manager.ts",
2828
2972
  line: 212,
2829
2973
  scope: this,
@@ -2844,7 +2988,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2844
2988
  signingContext: this._signingContext,
2845
2989
  callbacks: {
2846
2990
  beforeReady: async () => {
2847
- log10("before space ready", {
2991
+ log11("before space ready", {
2848
2992
  space: space.key
2849
2993
  }, {
2850
2994
  file: "data-space-manager.ts",
@@ -2855,7 +2999,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2855
2999
  this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2856
3000
  },
2857
3001
  afterReady: async () => {
2858
- log10("after space ready", {
3002
+ log11("after space ready", {
2859
3003
  space: space.key,
2860
3004
  open: this._isOpen
2861
3005
  }, {
@@ -2882,28 +3026,28 @@ var DataSpaceManager = class DataSpaceManager2 {
2882
3026
  return dataSpace;
2883
3027
  }
2884
3028
  };
2885
- __decorate2([
3029
+ __decorate3([
2886
3030
  synchronized
2887
3031
  ], DataSpaceManager.prototype, "open", null);
2888
- __decorate2([
3032
+ __decorate3([
2889
3033
  synchronized
2890
3034
  ], DataSpaceManager.prototype, "close", null);
2891
- __decorate2([
3035
+ __decorate3([
2892
3036
  synchronized
2893
3037
  ], DataSpaceManager.prototype, "createSpace", null);
2894
- __decorate2([
3038
+ __decorate3([
2895
3039
  synchronized
2896
3040
  ], DataSpaceManager.prototype, "acceptSpace", null);
2897
- DataSpaceManager = __decorate2([
3041
+ DataSpaceManager = __decorate3([
2898
3042
  trackLeaks2("open", "close")
2899
3043
  ], DataSpaceManager);
2900
3044
 
2901
3045
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2902
3046
  import { EventSubscriptions as EventSubscriptions2, scheduleTask as scheduleTask5 } from "@dxos/async";
2903
- import { Stream as Stream8 } from "@dxos/codec-protobuf";
3047
+ import { Stream as Stream9 } from "@dxos/codec-protobuf";
2904
3048
  import { raise, todo as todo2 } from "@dxos/debug";
2905
3049
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
2906
- import { log as log11 } from "@dxos/log";
3050
+ import { log as log12 } from "@dxos/log";
2907
3051
  import { encodeError } from "@dxos/protocols";
2908
3052
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/client/services";
2909
3053
  import { humanize } from "@dxos/util";
@@ -2927,15 +3071,15 @@ var SpacesServiceImpl = class {
2927
3071
  todo2();
2928
3072
  }
2929
3073
  querySpaces() {
2930
- return new Stream8(({ next, ctx }) => {
3074
+ return new Stream9(({ next, ctx }) => {
2931
3075
  const onUpdate = async () => {
2932
3076
  const dataSpaceManager = await this._getDataSpaceManager();
2933
3077
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
2934
- log11("update", {
3078
+ log12("update", {
2935
3079
  spaces
2936
3080
  }, {
2937
3081
  file: "spaces-service.ts",
2938
- line: 62,
3082
+ line: 59,
2939
3083
  scope: this,
2940
3084
  callSite: (f, a) => f(...a)
2941
3085
  });
@@ -2979,7 +3123,7 @@ var SpacesServiceImpl = class {
2979
3123
  await space.postMessage(getChannelId(channel), message);
2980
3124
  }
2981
3125
  subscribeMessages({ spaceKey, channel }) {
2982
- return new Stream8(({ ctx, next }) => {
3126
+ return new Stream9(({ ctx, next }) => {
2983
3127
  scheduleTask5(ctx, async () => {
2984
3128
  var _a;
2985
3129
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -2992,7 +3136,7 @@ var SpacesServiceImpl = class {
2992
3136
  });
2993
3137
  }
2994
3138
  queryCredentials({ spaceKey }) {
2995
- return new Stream8(({ ctx, next }) => {
3139
+ return new Stream9(({ ctx, next }) => {
2996
3140
  var _a;
2997
3141
  const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
2998
3142
  const processor = space.spaceState.registerProcessor({
@@ -3103,900 +3247,124 @@ var toStorageType = (type) => {
3103
3247
  }
3104
3248
  };
3105
3249
 
3106
- // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3250
+ // packages/sdk/client-services/src/packlets/services/service-context.ts
3107
3251
  import assert11 from "@dxos/node-std/assert";
3108
- import { Event as Event7 } from "@dxos/async";
3109
- import { appServiceBundle, shellServiceBundle } from "@dxos/client-protocol";
3110
- import { ShellLayout } from "@dxos/protocols/proto/dxos/iframe";
3111
- import { createProtoRpcPeer } from "@dxos/rpc";
3112
- var ShellRuntimeImpl = class {
3113
- constructor(_port) {
3114
- this._port = _port;
3115
- this.layoutUpdate = new Event7();
3116
- this._layout = ShellLayout.DEFAULT;
3117
- }
3118
- get layout() {
3119
- return this._layout;
3120
- }
3121
- get invitationCode() {
3122
- return this._invitationCode;
3123
- }
3124
- get spaceKey() {
3125
- return this._spaceKey;
3126
- }
3127
- setLayout(layout, options = {}) {
3128
- this._layout = layout;
3129
- this._invitationCode = options.invitationCode;
3130
- this._spaceKey = options.spaceKey;
3131
- this.layoutUpdate.emit({
3132
- layout,
3133
- ...options
3252
+ import { Trigger as Trigger6 } from "@dxos/async";
3253
+ import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3254
+ import { failUndefined as failUndefined3 } from "@dxos/debug";
3255
+ import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3256
+ import { FeedFactory, FeedStore } from "@dxos/feed-store";
3257
+ import { Keyring } from "@dxos/keyring";
3258
+ import { PublicKey as PublicKey9 } from "@dxos/keys";
3259
+ import { log as log13 } from "@dxos/log";
3260
+ import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3261
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3262
+ var ServiceContext = class {
3263
+ // prettier-ignore
3264
+ constructor(storage, networkManager, signalManager, modelFactory) {
3265
+ this.storage = storage;
3266
+ this.networkManager = networkManager;
3267
+ this.signalManager = signalManager;
3268
+ this.modelFactory = modelFactory;
3269
+ this.initialized = new Trigger6();
3270
+ this.dataServiceSubscriptions = new DataServiceSubscriptions();
3271
+ this._handlerFactories = /* @__PURE__ */ new Map();
3272
+ this._instanceId = PublicKey9.random().toHex();
3273
+ this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
3274
+ this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
3275
+ this.keyring = new Keyring(storage.createDirectory("keyring"));
3276
+ this.feedStore = new FeedStore({
3277
+ factory: new FeedFactory({
3278
+ root: storage.createDirectory("feeds"),
3279
+ signer: this.keyring,
3280
+ hypercore: {
3281
+ valueEncoding
3282
+ }
3283
+ })
3134
3284
  });
3135
- }
3136
- async setAppContext(context) {
3137
- assert11(this._appRpc, "runtime not open");
3138
- await this._appRpc.rpc.AppService.setContext(context);
3285
+ this.spaceManager = new SpaceManager({
3286
+ feedStore: this.feedStore,
3287
+ networkManager: this.networkManager,
3288
+ metadataStore: this.metadataStore,
3289
+ modelFactory: this.modelFactory,
3290
+ snapshotStore: this.snapshotStore
3291
+ });
3292
+ this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3293
+ this.invitations = new InvitationsHandler(this.networkManager);
3294
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3295
+ var _a;
3296
+ return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3297
+ }, this._acceptIdentity.bind(this)));
3139
3298
  }
3140
3299
  async open() {
3141
- this._appRpc = createProtoRpcPeer({
3142
- requested: appServiceBundle,
3143
- exposed: shellServiceBundle,
3144
- handlers: {
3145
- ShellService: {
3146
- setLayout: async (request) => {
3147
- this._layout = request.layout;
3148
- this._invitationCode = request.invitationCode;
3149
- this._spaceKey = request.spaceKey;
3150
- this.layoutUpdate.emit(request);
3151
- }
3152
- }
3153
- },
3154
- port: this._port
3300
+ log13.trace("dxos.sdk.service-context.open", trace5.begin({
3301
+ id: this._instanceId
3302
+ }), {
3303
+ file: "service-context.ts",
3304
+ line: 119,
3305
+ scope: this,
3306
+ callSite: (f, a) => f(...a)
3307
+ });
3308
+ await this._checkStorageVersion();
3309
+ log13("opening...", {}, {
3310
+ file: "service-context.ts",
3311
+ line: 123,
3312
+ scope: this,
3313
+ callSite: (f, a) => f(...a)
3314
+ });
3315
+ await this.signalManager.open();
3316
+ await this.networkManager.open();
3317
+ await this.spaceManager.open();
3318
+ await this.identityManager.open();
3319
+ if (this.identityManager.identity) {
3320
+ await this._initialize();
3321
+ }
3322
+ log13("opened", {}, {
3323
+ file: "service-context.ts",
3324
+ line: 131,
3325
+ scope: this,
3326
+ callSite: (f, a) => f(...a)
3327
+ });
3328
+ log13.trace("dxos.sdk.service-context.open", trace5.end({
3329
+ id: this._instanceId
3330
+ }), {
3331
+ file: "service-context.ts",
3332
+ line: 132,
3333
+ scope: this,
3334
+ callSite: (f, a) => f(...a)
3155
3335
  });
3156
- await this._appRpc.open();
3157
3336
  }
3158
3337
  async close() {
3159
- var _a;
3160
- await ((_a = this._appRpc) == null ? void 0 : _a.close());
3161
- this._appRpc = void 0;
3162
- }
3163
- };
3164
- var MemoryShellRuntime = class {
3165
- constructor({ layout, invitationCode, spaceKey } = {}) {
3166
- this.layoutUpdate = new Event7();
3167
- this.contextUpdate = new Event7();
3168
- this._layout = layout != null ? layout : ShellLayout.DEFAULT;
3169
- this._invitationCode = invitationCode;
3170
- this._spaceKey = spaceKey;
3171
- }
3172
- get layout() {
3173
- return this._layout;
3174
- }
3175
- get invitationCode() {
3176
- return this._invitationCode;
3177
- }
3178
- get spaceKey() {
3179
- return this._spaceKey;
3180
- }
3181
- setLayout(layout, options = {}) {
3182
- this._layout = layout;
3183
- this._invitationCode = options.invitationCode;
3184
- this._spaceKey = options.spaceKey;
3185
- this.layoutUpdate.emit({
3186
- layout,
3187
- ...options
3338
+ var _a, _b;
3339
+ log13("closing...", {}, {
3340
+ file: "service-context.ts",
3341
+ line: 136,
3342
+ scope: this,
3343
+ callSite: (f, a) => f(...a)
3344
+ });
3345
+ await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3346
+ await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3347
+ await this.identityManager.close();
3348
+ await this.spaceManager.close();
3349
+ await this.feedStore.close();
3350
+ await this.networkManager.close();
3351
+ await this.signalManager.close();
3352
+ this.dataServiceSubscriptions.clear();
3353
+ log13("closed", {}, {
3354
+ file: "service-context.ts",
3355
+ line: 145,
3356
+ scope: this,
3357
+ callSite: (f, a) => f(...a)
3188
3358
  });
3189
3359
  }
3190
- async setAppContext(context) {
3191
- this.contextUpdate.emit(context);
3192
- }
3193
- };
3194
-
3195
- // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3196
- import { Trigger as Trigger10 } from "@dxos/async";
3197
- import { PROXY_CONNECTION_TIMEOUT as PROXY_CONNECTION_TIMEOUT2 } from "@dxos/client-protocol";
3198
- import { log as log19, logInfo as logInfo3 } from "@dxos/log";
3199
- import { MemorySignalManager as MemorySignalManager2, MemorySignalManagerContext as MemorySignalManagerContext2, WebsocketSignalManager as WebsocketSignalManager3 } from "@dxos/messaging";
3200
- import { createWebRTCTransportFactory as createWebRTCTransportFactory2 } from "@dxos/network-manager";
3201
- import { getAsyncValue as getAsyncValue2 } from "@dxos/util";
3202
-
3203
- // packages/sdk/client-services/src/packlets/services/service-host.ts
3204
- import assert14 from "@dxos/node-std/assert";
3205
- import { Event as Event9 } from "@dxos/async";
3206
- import { clientServiceBundle, createDefaultModelFactory } from "@dxos/client-protocol";
3207
- import { DataServiceImpl } from "@dxos/echo-pipeline";
3208
- import { PublicKey as PublicKey10 } from "@dxos/keys";
3209
- import { log as log18 } from "@dxos/log";
3210
- import { WebsocketSignalManager as WebsocketSignalManager2 } from "@dxos/messaging";
3211
- import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
3212
- import { trace as trace6 } from "@dxos/protocols";
3213
- import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
3214
-
3215
- // packages/sdk/client-services/src/packlets/devices/devices-service.ts
3216
- import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
3217
- import { Stream as Stream9 } from "@dxos/codec-protobuf";
3218
- import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
3219
- var DevicesServiceImpl = class {
3220
- constructor(_identityManager) {
3221
- this._identityManager = _identityManager;
3222
- }
3223
- updateDevice(request) {
3224
- throw new Error("Method not implemented.");
3225
- }
3226
- queryDevices() {
3227
- return new Stream9(({ next }) => {
3228
- const update = () => {
3229
- var _a;
3230
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
3231
- if (!deviceKeys) {
3232
- next({
3233
- devices: []
3234
- });
3235
- } else {
3236
- next({
3237
- devices: Array.from(deviceKeys.values()).map((key) => {
3238
- var _a2;
3239
- return {
3240
- deviceKey: key,
3241
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
3242
- };
3243
- })
3244
- });
3245
- }
3246
- };
3247
- const subscriptions = new EventSubscriptions3();
3248
- subscriptions.add(this._identityManager.stateUpdate.on(() => {
3249
- update();
3250
- if (this._identityManager.identity) {
3251
- subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
3252
- update();
3253
- }));
3254
- }
3255
- }));
3256
- update();
3257
- return () => subscriptions.clear();
3258
- });
3259
- }
3260
- };
3261
-
3262
- // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3263
- import { Event as Event8 } from "@dxos/async";
3264
- import { Stream as Stream10 } from "@dxos/codec-protobuf";
3265
- import { log as log12, shouldLog, getContextFromEntry } from "@dxos/log";
3266
- import { jsonify } from "@dxos/util";
3267
- var LoggingServiceImpl = class {
3268
- constructor() {
3269
- this._logs = new Event8();
3270
- this._logProcessor = (_config, entry2) => {
3271
- this._logs.emit(entry2);
3272
- };
3273
- }
3274
- async open() {
3275
- log12.runtimeConfig.processors.push(this._logProcessor);
3276
- }
3277
- async close() {
3278
- const index = log12.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
3279
- log12.runtimeConfig.processors.splice(index, 1);
3280
- }
3281
- queryLogs(request) {
3282
- var _a;
3283
- const filters = ((_a = request.filters) == null ? void 0 : _a.length) ? request.filters : void 0;
3284
- return new Stream10(({ ctx, next }) => {
3285
- const handler = (entry2) => {
3286
- var _a2, _b, _c;
3287
- if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3288
- return;
3289
- }
3290
- if (shouldLog(entry2, filters)) {
3291
- const record = {
3292
- ...entry2,
3293
- context: jsonify(getContextFromEntry(entry2))
3294
- };
3295
- (_b = record.meta) == null ? true : delete _b.bugcheck;
3296
- (_c = record.meta) == null ? true : delete _c.scope;
3297
- next(record);
3298
- }
3299
- };
3300
- ctx.onDispose(() => {
3301
- this._logs.off(handler);
3302
- });
3303
- this._logs.on(handler);
3304
- });
3305
- }
3306
- };
3307
-
3308
- // packages/sdk/client-services/src/packlets/network/network-service.ts
3309
- import { Stream as Stream11 } from "@dxos/codec-protobuf";
3310
- var NetworkServiceImpl = class {
3311
- constructor(networkManager, signalManager) {
3312
- this.networkManager = networkManager;
3313
- this.signalManager = signalManager;
3314
- }
3315
- queryStatus() {
3316
- return new Stream11(({ next }) => {
3317
- const update = () => {
3318
- next({
3319
- swarm: this.networkManager.connectionState,
3320
- signaling: this.signalManager.getStatus().map(({ host, state }) => ({
3321
- server: host,
3322
- state
3323
- }))
3324
- });
3325
- };
3326
- const unsubscribeSwarm = this.networkManager.connectionStateChanged.on(() => update());
3327
- const unsubscribeSignal = this.signalManager.statusChanged.on(() => update());
3328
- update();
3329
- return () => {
3330
- unsubscribeSwarm();
3331
- unsubscribeSignal();
3332
- };
3333
- });
3334
- }
3335
- async updateConfig(request) {
3336
- await this.networkManager.setConnectionState(request.swarm);
3337
- }
3338
- };
3339
-
3340
- // packages/sdk/client-services/src/packlets/system/system-service.ts
3341
- import { Stream as Stream12 } from "@dxos/codec-protobuf";
3342
- var SystemServiceImpl = class {
3343
- constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
3344
- this._config = config;
3345
- this._statusUpdate = statusUpdate;
3346
- this._getCurrentStatus = getCurrentStatus;
3347
- this._onUpdateStatus = onUpdateStatus;
3348
- this._onReset = onReset;
3349
- }
3350
- async getConfig() {
3351
- var _a, _b;
3352
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
3353
- }
3354
- async updateStatus({ status }) {
3355
- await this._onUpdateStatus(status);
3356
- }
3357
- queryStatus() {
3358
- return new Stream12(({ next }) => {
3359
- const update = () => {
3360
- next({
3361
- status: this._getCurrentStatus()
3362
- });
3363
- };
3364
- update();
3365
- const unsubscribe = this._statusUpdate.on(() => update());
3366
- const interval = setInterval(update, 3e3);
3367
- return () => {
3368
- clearInterval(interval);
3369
- unsubscribe();
3370
- };
3371
- });
3372
- }
3373
- async reset() {
3374
- await this._onReset();
3375
- }
3376
- };
3377
-
3378
- // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3379
- import { Trigger as Trigger5 } from "@dxos/async";
3380
- import { iframeServiceBundle, workerServiceBundle } from "@dxos/client-protocol";
3381
- import { RemoteServiceConnectionError } from "@dxos/errors";
3382
- import { log as log13 } from "@dxos/log";
3383
- import { WebRTCTransportService } from "@dxos/network-manager";
3384
- import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
3385
- import { getAsyncValue } from "@dxos/util";
3386
- var IFrameProxyRuntime = class {
3387
- constructor({ config, systemPort, shellPort }) {
3388
- this._id = String(Math.floor(Math.random() * 1e6));
3389
- this._release = new Trigger5();
3390
- this._configProvider = config;
3391
- this._systemPort = systemPort;
3392
- this._shellPort = shellPort;
3393
- if (this._shellPort) {
3394
- this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
3395
- }
3396
- }
3397
- get shell() {
3398
- return this._shellRuntime;
3399
- }
3400
- async open(origin) {
3401
- var _a;
3402
- this._config = await getAsyncValue(this._configProvider);
3403
- this._transportService = new WebRTCTransportService({
3404
- iceServers: this._config.get("runtime.services.ice")
3405
- });
3406
- this._systemRpc = createProtoRpcPeer2({
3407
- requested: workerServiceBundle,
3408
- exposed: iframeServiceBundle,
3409
- handlers: {
3410
- BridgeService: this._transportService
3411
- },
3412
- port: this._systemPort,
3413
- timeout: 200
3414
- });
3415
- let lockKey;
3416
- if (typeof navigator !== "undefined") {
3417
- lockKey = this._lockKey(origin);
3418
- this._release = new Trigger5();
3419
- const ready = new Trigger5();
3420
- void navigator.locks.request(lockKey, async () => {
3421
- ready.wake();
3422
- await this._release.wait();
3423
- });
3424
- await ready.wait();
3425
- }
3426
- try {
3427
- await this._systemRpc.open();
3428
- await this._systemRpc.rpc.WorkerService.start({
3429
- origin,
3430
- lockKey
3431
- });
3432
- } catch (err) {
3433
- log13.catch(err, {}, {
3434
- file: "iframe-proxy-runtime.ts",
3435
- line: 85,
3436
- scope: this,
3437
- callSite: (f, a) => f(...a)
3438
- });
3439
- throw new RemoteServiceConnectionError("Failed to connect to worker");
3440
- }
3441
- await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
3442
- }
3443
- async close() {
3444
- var _a;
3445
- this._release.wake();
3446
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3447
- await this._systemRpc.rpc.WorkerService.stop();
3448
- await this._systemRpc.close();
3449
- }
3450
- _lockKey(origin) {
3451
- return `${origin}-${this._id}`;
3452
- }
3453
- };
3454
-
3455
- // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3456
- import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
3457
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
3458
- import { log as log14, logInfo } from "@dxos/log";
3459
- var __decorate3 = function(decorators, target, key, desc) {
3460
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3461
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3462
- r = Reflect.decorate(decorators, target, key, desc);
3463
- else
3464
- for (var i = decorators.length - 1; i >= 0; i--)
3465
- if (d = decorators[i])
3466
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3467
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3468
- };
3469
- var Message;
3470
- (function(Message2) {
3471
- Message2["ACQUIRING"] = "acquiring";
3472
- })(Message || (Message = {}));
3473
- var VaultResourceLock = class {
3474
- constructor({ lockKey, onAcquire, onRelease }) {
3475
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3476
- this._releaseTrigger = new Trigger6();
3477
- this._lockKey = lockKey;
3478
- this._onAcquire = onAcquire;
3479
- this._onRelease = onRelease;
3480
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
3481
- }
3482
- get lockKey() {
3483
- return this._lockKey;
3484
- }
3485
- async acquire() {
3486
- this._broadcastChannel.postMessage({
3487
- message: Message.ACQUIRING
3488
- });
3489
- try {
3490
- log14("aquiring lock...", {}, {
3491
- file: "vault-resource-lock.ts",
3492
- line: 45,
3493
- scope: this,
3494
- callSite: (f, a) => f(...a)
3495
- });
3496
- await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
3497
- log14("acquired lock", {}, {
3498
- file: "vault-resource-lock.ts",
3499
- line: 47,
3500
- scope: this,
3501
- callSite: (f, a) => f(...a)
3502
- });
3503
- } catch (e) {
3504
- log14("stealing lock...", {}, {
3505
- file: "vault-resource-lock.ts",
3506
- line: 49,
3507
- scope: this,
3508
- callSite: (f, a) => f(...a)
3509
- });
3510
- await this._requestLock(true);
3511
- log14("stolen lock", {}, {
3512
- file: "vault-resource-lock.ts",
3513
- line: 51,
3514
- scope: this,
3515
- callSite: (f, a) => f(...a)
3516
- });
3517
- }
3518
- }
3519
- async release() {
3520
- this._releaseTrigger.wake();
3521
- }
3522
- _onMessage(event) {
3523
- if (event.data.message === Message.ACQUIRING) {
3524
- this._releaseTrigger.wake();
3525
- }
3526
- }
3527
- async _requestLock(steal = false) {
3528
- log14("requesting lock...", {
3529
- steal
3530
- }, {
3531
- file: "vault-resource-lock.ts",
3532
- line: 66,
3533
- scope: this,
3534
- callSite: (f, a) => f(...a)
3535
- });
3536
- const acquired = new Trigger6();
3537
- void navigator.locks.request(this._lockKey, {
3538
- steal
3539
- }, async () => {
3540
- var _a, _b;
3541
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3542
- acquired.wake();
3543
- this._releaseTrigger = new Trigger6();
3544
- await this._releaseTrigger.wait();
3545
- log14("releasing lock...", {}, {
3546
- file: "vault-resource-lock.ts",
3547
- line: 75,
3548
- scope: this,
3549
- callSite: (f, a) => f(...a)
3550
- });
3551
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3552
- log14("released lock", {}, {
3553
- file: "vault-resource-lock.ts",
3554
- line: 77,
3555
- scope: this,
3556
- callSite: (f, a) => f(...a)
3557
- });
3558
- }).catch(async () => {
3559
- var _a;
3560
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3561
- });
3562
- await acquired.wait();
3563
- log14("recieved lock", {
3564
- steal
3565
- }, {
3566
- file: "vault-resource-lock.ts",
3567
- line: 84,
3568
- scope: this,
3569
- callSite: (f, a) => f(...a)
3570
- });
3571
- }
3572
- };
3573
- __decorate3([
3574
- logInfo
3575
- ], VaultResourceLock.prototype, "lockKey", null);
3576
-
3577
- // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3578
- import { Trigger as Trigger8 } from "@dxos/async";
3579
- import { log as log16 } from "@dxos/log";
3580
- import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
3581
- import { WebRTCTransportProxyFactory } from "@dxos/network-manager";
3582
-
3583
- // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3584
- import assert12 from "@dxos/node-std/assert";
3585
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger7 } from "@dxos/async";
3586
- import { iframeServiceBundle as iframeServiceBundle2, PROXY_CONNECTION_TIMEOUT, workerServiceBundle as workerServiceBundle2 } from "@dxos/client-protocol";
3587
- import { log as log15, logInfo as logInfo2 } from "@dxos/log";
3588
- import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
3589
- import { Callback } from "@dxos/util";
3590
-
3591
- // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
3592
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
3593
- import { raise as raise2 } from "@dxos/debug";
3594
- import { parseMethodName, RpcPeer } from "@dxos/rpc";
3595
- var ClientRpcServer = class {
3596
- constructor(params) {
3597
- this._handlerCache = /* @__PURE__ */ new Map();
3598
- const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
3599
- this._handleCall = handleCall;
3600
- this._handleStream = handleStream;
3601
- this._serviceRegistry = serviceRegistry;
3602
- this._rpcPeer = new RpcPeer({
3603
- ...rpcOptions,
3604
- callHandler: (method, params2) => {
3605
- const [serviceName, methodName] = parseMethodName(method);
3606
- const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
3607
- if (this._handleCall) {
3608
- return this._handleCall(methodName, params2, handler);
3609
- } else {
3610
- return handler(methodName, params2);
3611
- }
3612
- },
3613
- streamHandler: (method, params2) => {
3614
- const [serviceName, methodName] = parseMethodName(method);
3615
- const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
3616
- if (this._handleStream) {
3617
- return Stream13.unwrapPromise(this._handleStream(methodName, params2, handler));
3618
- } else {
3619
- return handler(methodName, params2);
3620
- }
3621
- }
3622
- });
3623
- }
3624
- async open() {
3625
- await this._rpcPeer.open();
3626
- }
3627
- async close() {
3628
- await this._rpcPeer.close();
3629
- }
3630
- _getServiceHandler(serviceName) {
3631
- var _a;
3632
- if (!this._handlerCache.has(serviceName)) {
3633
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : raise2(new Error(`Service not available: ${serviceName}`));
3634
- const service = this._serviceRegistry.services[key];
3635
- if (!service) {
3636
- throw new Error(`Service not available: ${serviceName}`);
3637
- }
3638
- this._handlerCache.set(serviceName, descriptor.createServer(service));
3639
- }
3640
- return this._handlerCache.get(serviceName);
3641
- }
3642
- };
3643
-
3644
- // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3645
- var __decorate4 = function(decorators, target, key, desc) {
3646
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3647
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3648
- r = Reflect.decorate(decorators, target, key, desc);
3649
- else
3650
- for (var i = decorators.length - 1; i >= 0; i--)
3651
- if (d = decorators[i])
3652
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3653
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3654
- };
3655
- var WorkerSession = class {
3656
- constructor({ serviceHost, systemPort, appPort, shellPort, readySignal }) {
3657
- this._startTrigger = new Trigger7();
3658
- this.onClose = new Callback();
3659
- assert12(serviceHost);
3660
- this._serviceHost = serviceHost;
3661
- const middleware = {
3662
- handleCall: async (method, params, handler) => {
3663
- const error = await readySignal.wait({
3664
- timeout: PROXY_CONNECTION_TIMEOUT
3665
- });
3666
- if (error) {
3667
- throw error;
3668
- }
3669
- return handler(method, params);
3670
- },
3671
- handleStream: async (method, params, handler) => {
3672
- const error = await readySignal.wait({
3673
- timeout: PROXY_CONNECTION_TIMEOUT
3674
- });
3675
- if (error) {
3676
- throw error;
3677
- }
3678
- return handler(method, params);
3679
- }
3680
- };
3681
- this._clientRpc = new ClientRpcServer({
3682
- serviceRegistry: this._serviceHost.serviceRegistry,
3683
- port: appPort,
3684
- ...middleware
3685
- });
3686
- this._shellClientRpc = new ClientRpcServer({
3687
- serviceRegistry: this._serviceHost.serviceRegistry,
3688
- port: shellPort,
3689
- ...middleware
3690
- });
3691
- this._iframeRpc = createProtoRpcPeer3({
3692
- requested: iframeServiceBundle2,
3693
- exposed: workerServiceBundle2,
3694
- handlers: {
3695
- WorkerService: {
3696
- start: async (request) => {
3697
- this.origin = request.origin;
3698
- this.lockKey = request.lockKey;
3699
- this._startTrigger.wake();
3700
- },
3701
- stop: async () => {
3702
- setTimeout(async () => {
3703
- try {
3704
- await this.close();
3705
- } catch (err) {
3706
- log15.catch(err, {}, {
3707
- file: "worker-session.ts",
3708
- line: 100,
3709
- scope: this,
3710
- callSite: (f, a) => f(...a)
3711
- });
3712
- }
3713
- });
3714
- }
3715
- }
3716
- },
3717
- port: systemPort,
3718
- timeout: 1e3
3719
- });
3720
- this.bridgeService = this._iframeRpc.rpc.BridgeService;
3721
- }
3722
- async open() {
3723
- log15.info("opening..", {}, {
3724
- file: "worker-session.ts",
3725
- line: 114,
3726
- scope: this,
3727
- callSite: (f, a) => f(...a)
3728
- });
3729
- await Promise.all([
3730
- this._clientRpc.open(),
3731
- this._iframeRpc.open(),
3732
- this._maybeOpenShell()
3733
- ]);
3734
- await this._startTrigger.wait({
3735
- timeout: PROXY_CONNECTION_TIMEOUT
3736
- });
3737
- if (this.lockKey) {
3738
- void this._afterLockReleases(this.lockKey, () => this.close());
3739
- }
3740
- }
3741
- async close() {
3742
- log15.info("closing..", {}, {
3743
- file: "worker-session.ts",
3744
- line: 124,
3745
- scope: this,
3746
- callSite: (f, a) => f(...a)
3747
- });
3748
- try {
3749
- await this.onClose.callIfSet();
3750
- } catch (err) {
3751
- log15.catch(err, {}, {
3752
- file: "worker-session.ts",
3753
- line: 128,
3754
- scope: this,
3755
- callSite: (f, a) => f(...a)
3756
- });
3757
- }
3758
- await Promise.all([
3759
- this._clientRpc.close(),
3760
- this._iframeRpc.close()
3761
- ]);
3762
- }
3763
- async _maybeOpenShell() {
3764
- try {
3765
- await asyncTimeout2(this._shellClientRpc.open(), 1e3);
3766
- } catch (e) {
3767
- log15.info("No shell connected.", {}, {
3768
- file: "worker-session.ts",
3769
- line: 138,
3770
- scope: this,
3771
- callSite: (f, a) => f(...a)
3772
- });
3773
- }
3774
- }
3775
- _afterLockReleases(lockKey, callback) {
3776
- return navigator.locks.request(lockKey, () => {
3777
- }).then(callback);
3778
- }
3779
- };
3780
- __decorate4([
3781
- logInfo2
3782
- ], WorkerSession.prototype, "origin", void 0);
3783
- __decorate4([
3784
- logInfo2
3785
- ], WorkerSession.prototype, "lockKey", void 0);
3786
-
3787
- // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3788
- var WorkerRuntime = class {
3789
- // prettier-ignore
3790
- constructor(_configProvider) {
3791
- this._configProvider = _configProvider;
3792
- this._transportFactory = new WebRTCTransportProxyFactory();
3793
- this._ready = new Trigger8();
3794
- this.sessions = /* @__PURE__ */ new Set();
3795
- this._clientServices = new ClientServicesHost();
3796
- }
3797
- get host() {
3798
- return this._clientServices;
3799
- }
3800
- async start() {
3801
- log16("starting...", {}, {
3802
- file: "worker-runtime.ts",
3803
- line: 48,
3804
- scope: this,
3805
- callSite: (f, a) => f(...a)
3806
- });
3807
- try {
3808
- this._config = await this._configProvider();
3809
- const signals = this._config.get("runtime.services.signaling");
3810
- this._clientServices.initialize({
3811
- config: this._config,
3812
- signalManager: signals ? new WebsocketSignalManager(signals) : new MemorySignalManager(new MemorySignalManagerContext()),
3813
- transportFactory: this._transportFactory
3814
- });
3815
- await this._clientServices.open();
3816
- this._ready.wake(void 0);
3817
- log16("started", {}, {
3818
- file: "worker-runtime.ts",
3819
- line: 62,
3820
- scope: this,
3821
- callSite: (f, a) => f(...a)
3822
- });
3823
- } catch (err) {
3824
- this._ready.wake(err);
3825
- log16.catch(err, {}, {
3826
- file: "worker-runtime.ts",
3827
- line: 65,
3828
- scope: this,
3829
- callSite: (f, a) => f(...a)
3830
- });
3831
- }
3832
- }
3833
- async stop() {
3834
- await this._clientServices.close();
3835
- }
3836
- /**
3837
- * Create a new session.
3838
- */
3839
- async createSession({ appPort, systemPort, shellPort }) {
3840
- const session = new WorkerSession({
3841
- serviceHost: this._clientServices,
3842
- appPort,
3843
- systemPort,
3844
- shellPort,
3845
- readySignal: this._ready
3846
- });
3847
- session.onClose.set(async () => {
3848
- this.sessions.delete(session);
3849
- this._reconnectWebrtc();
3850
- });
3851
- await session.open();
3852
- this.sessions.add(session);
3853
- this._reconnectWebrtc();
3854
- }
3855
- /**
3856
- * Selects one of the existing session fro WebRTC networking.
3857
- */
3858
- _reconnectWebrtc() {
3859
- log16("reconnecting webrtc...", {}, {
3860
- file: "worker-runtime.ts",
3861
- line: 102,
3862
- scope: this,
3863
- callSite: (f, a) => f(...a)
3864
- });
3865
- if (this._sessionForNetworking) {
3866
- if (!this.sessions.has(this._sessionForNetworking)) {
3867
- this._sessionForNetworking = void 0;
3868
- }
3869
- }
3870
- if (!this._sessionForNetworking) {
3871
- const selected = Array.from(this.sessions).find((session) => session.bridgeService);
3872
- if (selected) {
3873
- this._sessionForNetworking = selected;
3874
- this._transportFactory.setBridgeService(selected.bridgeService);
3875
- } else {
3876
- this._transportFactory.setBridgeService(void 0);
3877
- }
3878
- }
3879
- }
3880
- };
3881
-
3882
- // packages/sdk/client-services/src/packlets/services/service-context.ts
3883
- import assert13 from "@dxos/node-std/assert";
3884
- import { Trigger as Trigger9 } from "@dxos/async";
3885
- import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
3886
- import { failUndefined as failUndefined3 } from "@dxos/debug";
3887
- import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3888
- import { FeedFactory, FeedStore } from "@dxos/feed-store";
3889
- import { Keyring } from "@dxos/keyring";
3890
- import { PublicKey as PublicKey9 } from "@dxos/keys";
3891
- import { log as log17 } from "@dxos/log";
3892
- import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3893
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3894
- var ServiceContext = class {
3895
- // prettier-ignore
3896
- constructor(storage, networkManager, signalManager, modelFactory) {
3897
- this.storage = storage;
3898
- this.networkManager = networkManager;
3899
- this.signalManager = signalManager;
3900
- this.modelFactory = modelFactory;
3901
- this.initialized = new Trigger9();
3902
- this.dataServiceSubscriptions = new DataServiceSubscriptions();
3903
- this._handlerFactories = /* @__PURE__ */ new Map();
3904
- this._instanceId = PublicKey9.random().toHex();
3905
- this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
3906
- this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
3907
- this.keyring = new Keyring(storage.createDirectory("keyring"));
3908
- this.feedStore = new FeedStore({
3909
- factory: new FeedFactory({
3910
- root: storage.createDirectory("feeds"),
3911
- signer: this.keyring,
3912
- hypercore: {
3913
- valueEncoding
3914
- }
3915
- })
3916
- });
3917
- this.spaceManager = new SpaceManager({
3918
- feedStore: this.feedStore,
3919
- networkManager: this.networkManager,
3920
- metadataStore: this.metadataStore,
3921
- modelFactory: this.modelFactory,
3922
- snapshotStore: this.snapshotStore
3923
- });
3924
- this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3925
- this.invitations = new InvitationsHandler(this.networkManager);
3926
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3927
- var _a;
3928
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3929
- }, this._acceptIdentity.bind(this)));
3930
- }
3931
- async open() {
3932
- log17.trace("dxos.sdk.service-context.open", trace5.begin({
3933
- id: this._instanceId
3934
- }), {
3935
- file: "service-context.ts",
3936
- line: 119,
3937
- scope: this,
3938
- callSite: (f, a) => f(...a)
3939
- });
3940
- await this._checkStorageVersion();
3941
- log17("opening...", {}, {
3942
- file: "service-context.ts",
3943
- line: 123,
3944
- scope: this,
3945
- callSite: (f, a) => f(...a)
3946
- });
3947
- await this.signalManager.open();
3948
- await this.networkManager.open();
3949
- await this.spaceManager.open();
3950
- await this.identityManager.open();
3951
- if (this.identityManager.identity) {
3952
- await this._initialize();
3953
- }
3954
- log17("opened", {}, {
3955
- file: "service-context.ts",
3956
- line: 131,
3957
- scope: this,
3958
- callSite: (f, a) => f(...a)
3959
- });
3960
- log17.trace("dxos.sdk.service-context.open", trace5.end({
3961
- id: this._instanceId
3962
- }), {
3963
- file: "service-context.ts",
3964
- line: 132,
3965
- scope: this,
3966
- callSite: (f, a) => f(...a)
3967
- });
3968
- }
3969
- async close() {
3970
- var _a, _b;
3971
- log17("closing...", {}, {
3972
- file: "service-context.ts",
3973
- line: 136,
3974
- scope: this,
3975
- callSite: (f, a) => f(...a)
3976
- });
3977
- await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3978
- await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3979
- await this.identityManager.close();
3980
- await this.spaceManager.close();
3981
- await this.feedStore.close();
3982
- await this.networkManager.close();
3983
- await this.signalManager.close();
3984
- this.dataServiceSubscriptions.clear();
3985
- log17("closed", {}, {
3986
- file: "service-context.ts",
3987
- line: 145,
3988
- scope: this,
3989
- callSite: (f, a) => f(...a)
3990
- });
3991
- }
3992
- async createIdentity(params = {}) {
3993
- const identity = await this.identityManager.createIdentity(params);
3994
- await this._initialize();
3995
- return identity;
3360
+ async createIdentity(params = {}) {
3361
+ const identity = await this.identityManager.createIdentity(params);
3362
+ await this._initialize();
3363
+ return identity;
3996
3364
  }
3997
3365
  getInvitationHandler(invitation) {
3998
3366
  const factory = this._handlerFactories.get(invitation.kind);
3999
- assert13(factory, `Unknown invitation kind: ${invitation.kind}`);
3367
+ assert11(factory, `Unknown invitation kind: ${invitation.kind}`);
4000
3368
  return factory(invitation);
4001
3369
  }
4002
3370
  async _acceptIdentity(params) {
@@ -4007,24 +3375,15 @@ var ServiceContext = class {
4007
3375
  async _checkStorageVersion() {
4008
3376
  await this.metadataStore.load();
4009
3377
  if (this.metadataStore.version !== STORAGE_VERSION) {
4010
- log17.error("Invalid storage version", {
4011
- current: this.metadataStore.version,
4012
- expected: STORAGE_VERSION
4013
- }, {
4014
- file: "service-context.ts",
4015
- line: 171,
4016
- scope: this,
4017
- callSite: (f, a) => f(...a)
4018
- });
4019
- await this.metadataStore.clear();
3378
+ throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${STORAGE_VERSION}`);
4020
3379
  }
4021
3380
  }
4022
3381
  // Called when identity is created.
4023
3382
  async _initialize() {
4024
3383
  var _a;
4025
- log17("initializing spaces...", {}, {
3384
+ log13("initializing spaces...", {}, {
4026
3385
  file: "service-context.ts",
4027
- line: 179,
3386
+ line: 178,
4028
3387
  scope: this,
4029
3388
  callSite: (f, a) => f(...a)
4030
3389
  });
@@ -4045,7 +3404,7 @@ var ServiceContext = class {
4045
3404
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
4046
3405
  await this.dataSpaceManager.open();
4047
3406
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
4048
- assert13(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3407
+ assert11(this.dataSpaceManager, "dataSpaceManager not initialized yet");
4049
3408
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
4050
3409
  });
4051
3410
  this.initialized.wake();
@@ -4059,33 +3418,33 @@ var ServiceContext = class {
4059
3418
  return;
4060
3419
  }
4061
3420
  if (!this.dataSpaceManager) {
4062
- log17("dataSpaceManager not initialized yet, ignoring space admission", {
3421
+ log13("dataSpaceManager not initialized yet, ignoring space admission", {
4063
3422
  details: assertion
4064
3423
  }, {
4065
3424
  file: "service-context.ts",
4066
- line: 218,
3425
+ line: 217,
4067
3426
  scope: this,
4068
3427
  callSite: (f, a) => f(...a)
4069
3428
  });
4070
3429
  return;
4071
3430
  }
4072
3431
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
4073
- log17("space already exists, ignoring space admission", {
3432
+ log13("space already exists, ignoring space admission", {
4074
3433
  details: assertion
4075
3434
  }, {
4076
3435
  file: "service-context.ts",
4077
- line: 222,
3436
+ line: 221,
4078
3437
  scope: this,
4079
3438
  callSite: (f, a) => f(...a)
4080
3439
  });
4081
3440
  return;
4082
3441
  }
4083
3442
  try {
4084
- log17("accepting space recorded in halo", {
3443
+ log13("accepting space recorded in halo", {
4085
3444
  details: assertion
4086
3445
  }, {
4087
3446
  file: "service-context.ts",
4088
- line: 227,
3447
+ line: 226,
4089
3448
  scope: this,
4090
3449
  callSite: (f, a) => f(...a)
4091
3450
  });
@@ -4094,9 +3453,9 @@ var ServiceContext = class {
4094
3453
  genesisFeedKey: assertion.genesisFeedKey
4095
3454
  });
4096
3455
  } catch (err) {
4097
- log17.catch(err, {}, {
3456
+ log13.catch(err, {}, {
4098
3457
  file: "service-context.ts",
4099
- line: 233,
3458
+ line: 232,
4100
3459
  scope: this,
4101
3460
  callSite: (f, a) => f(...a)
4102
3461
  });
@@ -4131,6 +3490,181 @@ var ServiceRegistry = class {
4131
3490
  }
4132
3491
  };
4133
3492
 
3493
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
3494
+ import assert12 from "@dxos/node-std/assert";
3495
+ import { Event as Event8 } from "@dxos/async";
3496
+ import { clientServiceBundle, createDefaultModelFactory } from "@dxos/client-protocol";
3497
+ import { DataServiceImpl } from "@dxos/echo-pipeline";
3498
+ import { PublicKey as PublicKey10 } from "@dxos/keys";
3499
+ import { log as log15 } from "@dxos/log";
3500
+ import { WebsocketSignalManager } from "@dxos/messaging";
3501
+ import { createWebRTCTransportFactory, NetworkManager } from "@dxos/network-manager";
3502
+ import { trace as trace6 } from "@dxos/protocols";
3503
+ import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
3504
+
3505
+ // packages/sdk/client-services/src/packlets/devices/devices-service.ts
3506
+ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
3507
+ import { Stream as Stream10 } from "@dxos/codec-protobuf";
3508
+ import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
3509
+ var DevicesServiceImpl = class {
3510
+ constructor(_identityManager) {
3511
+ this._identityManager = _identityManager;
3512
+ }
3513
+ updateDevice(request) {
3514
+ throw new Error("Method not implemented.");
3515
+ }
3516
+ queryDevices() {
3517
+ return new Stream10(({ next }) => {
3518
+ const update = () => {
3519
+ var _a;
3520
+ const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
3521
+ if (!deviceKeys) {
3522
+ next({
3523
+ devices: []
3524
+ });
3525
+ } else {
3526
+ next({
3527
+ devices: Array.from(deviceKeys.values()).map((key) => {
3528
+ var _a2;
3529
+ return {
3530
+ deviceKey: key,
3531
+ kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
3532
+ };
3533
+ })
3534
+ });
3535
+ }
3536
+ };
3537
+ const subscriptions = new EventSubscriptions3();
3538
+ subscriptions.add(this._identityManager.stateUpdate.on(() => {
3539
+ update();
3540
+ if (this._identityManager.identity) {
3541
+ subscriptions.add(this._identityManager.identity.stateUpdate.on(() => {
3542
+ update();
3543
+ }));
3544
+ }
3545
+ }));
3546
+ update();
3547
+ return () => subscriptions.clear();
3548
+ });
3549
+ }
3550
+ };
3551
+
3552
+ // packages/sdk/client-services/src/packlets/logging/logging-service.ts
3553
+ import { Event as Event7 } from "@dxos/async";
3554
+ import { Stream as Stream11 } from "@dxos/codec-protobuf";
3555
+ import { log as log14, shouldLog, getContextFromEntry } from "@dxos/log";
3556
+ import { jsonify } from "@dxos/util";
3557
+ var LoggingServiceImpl = class {
3558
+ constructor() {
3559
+ this._logs = new Event7();
3560
+ this._logProcessor = (_config, entry2) => {
3561
+ this._logs.emit(entry2);
3562
+ };
3563
+ }
3564
+ async open() {
3565
+ log14.runtimeConfig.processors.push(this._logProcessor);
3566
+ }
3567
+ async close() {
3568
+ const index = log14.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
3569
+ log14.runtimeConfig.processors.splice(index, 1);
3570
+ }
3571
+ queryLogs(request) {
3572
+ var _a;
3573
+ const filters = ((_a = request.filters) == null ? void 0 : _a.length) ? request.filters : void 0;
3574
+ return new Stream11(({ ctx, next }) => {
3575
+ const handler = (entry2) => {
3576
+ var _a2, _b, _c;
3577
+ if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
3578
+ return;
3579
+ }
3580
+ if (shouldLog(entry2, filters)) {
3581
+ const record = {
3582
+ ...entry2,
3583
+ context: jsonify(getContextFromEntry(entry2))
3584
+ };
3585
+ (_b = record.meta) == null ? true : delete _b.bugcheck;
3586
+ (_c = record.meta) == null ? true : delete _c.scope;
3587
+ next(record);
3588
+ }
3589
+ };
3590
+ ctx.onDispose(() => {
3591
+ this._logs.off(handler);
3592
+ });
3593
+ this._logs.on(handler);
3594
+ });
3595
+ }
3596
+ };
3597
+
3598
+ // packages/sdk/client-services/src/packlets/network/network-service.ts
3599
+ import { Stream as Stream12 } from "@dxos/codec-protobuf";
3600
+ var NetworkServiceImpl = class {
3601
+ constructor(networkManager, signalManager) {
3602
+ this.networkManager = networkManager;
3603
+ this.signalManager = signalManager;
3604
+ }
3605
+ queryStatus() {
3606
+ return new Stream12(({ next }) => {
3607
+ const update = () => {
3608
+ next({
3609
+ swarm: this.networkManager.connectionState,
3610
+ signaling: this.signalManager.getStatus().map(({ host, state }) => ({
3611
+ server: host,
3612
+ state
3613
+ }))
3614
+ });
3615
+ };
3616
+ const unsubscribeSwarm = this.networkManager.connectionStateChanged.on(() => update());
3617
+ const unsubscribeSignal = this.signalManager.statusChanged.on(() => update());
3618
+ update();
3619
+ return () => {
3620
+ unsubscribeSwarm();
3621
+ unsubscribeSignal();
3622
+ };
3623
+ });
3624
+ }
3625
+ async updateConfig(request) {
3626
+ await this.networkManager.setConnectionState(request.swarm);
3627
+ }
3628
+ };
3629
+
3630
+ // packages/sdk/client-services/src/packlets/system/system-service.ts
3631
+ import { Stream as Stream13 } from "@dxos/codec-protobuf";
3632
+ var SystemServiceImpl = class {
3633
+ constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
3634
+ this._config = config;
3635
+ this._statusUpdate = statusUpdate;
3636
+ this._getCurrentStatus = getCurrentStatus;
3637
+ this._onUpdateStatus = onUpdateStatus;
3638
+ this._onReset = onReset;
3639
+ }
3640
+ async getConfig() {
3641
+ var _a, _b;
3642
+ return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
3643
+ }
3644
+ async updateStatus({ status }) {
3645
+ await this._onUpdateStatus(status);
3646
+ }
3647
+ queryStatus() {
3648
+ return new Stream13(({ next }) => {
3649
+ const update = () => {
3650
+ next({
3651
+ status: this._getCurrentStatus()
3652
+ });
3653
+ };
3654
+ update();
3655
+ const unsubscribe = this._statusUpdate.on(() => update());
3656
+ const interval = setInterval(update, 3e3);
3657
+ return () => {
3658
+ clearInterval(interval);
3659
+ unsubscribe();
3660
+ };
3661
+ });
3662
+ }
3663
+ async reset() {
3664
+ await this._onReset();
3665
+ }
3666
+ };
3667
+
4134
3668
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4135
3669
  var ClientServicesHost = class {
4136
3670
  constructor({
@@ -4144,7 +3678,7 @@ var ClientServicesHost = class {
4144
3678
  // TODO(wittjosiah): Turn this on by default.
4145
3679
  lockKey
4146
3680
  } = {}) {
4147
- this._statusUpdate = new Event9();
3681
+ this._statusUpdate = new Event8();
4148
3682
  this._opening = false;
4149
3683
  this._open = false;
4150
3684
  this._storage = storage;
@@ -4156,15 +3690,17 @@ var ClientServicesHost = class {
4156
3690
  signalManager
4157
3691
  });
4158
3692
  }
4159
- this._resourceLock = lockKey ? new VaultResourceLock({
4160
- lockKey,
4161
- onAcquire: () => {
4162
- if (!this._opening) {
4163
- void this.open();
4164
- }
4165
- },
4166
- onRelease: () => this.close()
4167
- }) : void 0;
3693
+ if (lockKey) {
3694
+ this._resourceLock = new Lock({
3695
+ lockKey,
3696
+ onAcquire: () => {
3697
+ if (!this._opening) {
3698
+ void this.open();
3699
+ }
3700
+ },
3701
+ onRelease: () => this.close()
3702
+ });
3703
+ }
4168
3704
  this._systemService = new SystemServiceImpl({
4169
3705
  config: this._config,
4170
3706
  statusUpdate: this._statusUpdate,
@@ -4205,9 +3741,9 @@ var ClientServicesHost = class {
4205
3741
  */
4206
3742
  initialize({ config, ...options }) {
4207
3743
  var _a, _b, _c;
4208
- assert14(!this._open, "service host is open");
3744
+ assert12(!this._open, "service host is open");
4209
3745
  if (config) {
4210
- assert14(!this._config, "config already set");
3746
+ assert12(!this._config, "config already set");
4211
3747
  this._config = config;
4212
3748
  if (!this._storage) {
4213
3749
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
@@ -4215,9 +3751,9 @@ var ClientServicesHost = class {
4215
3751
  }
4216
3752
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4217
3753
  iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4218
- }), signalManager = new WebsocketSignalManager2((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
3754
+ }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4219
3755
  this._signalManager = signalManager;
4220
- assert14(!this._networkManager, "network manager already set");
3756
+ assert12(!this._networkManager, "network manager already set");
4221
3757
  this._networkManager = new NetworkManager({
4222
3758
  log: connectionLog,
4223
3759
  transportFactory,
@@ -4230,7 +3766,7 @@ var ClientServicesHost = class {
4230
3766
  return;
4231
3767
  }
4232
3768
  const traceId = PublicKey10.random().toHex();
4233
- log18.trace("dxos.sdk.client-services-host.open", trace6.begin({
3769
+ log15.trace("dxos.sdk.client-services-host.open", trace6.begin({
4234
3770
  id: traceId
4235
3771
  }), {
4236
3772
  file: "service-host.ts",
@@ -4238,12 +3774,12 @@ var ClientServicesHost = class {
4238
3774
  scope: this,
4239
3775
  callSite: (f, a) => f(...a)
4240
3776
  });
4241
- assert14(this._config, "config not set");
4242
- assert14(this._storage, "storage not set");
4243
- assert14(this._signalManager, "signal manager not set");
4244
- assert14(this._networkManager, "network manager not set");
3777
+ assert12(this._config, "config not set");
3778
+ assert12(this._storage, "storage not set");
3779
+ assert12(this._signalManager, "signal manager not set");
3780
+ assert12(this._networkManager, "network manager not set");
4245
3781
  this._opening = true;
4246
- log18("opening...", {
3782
+ log15("opening...", {
4247
3783
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4248
3784
  }, {
4249
3785
  file: "service-host.ts",
@@ -4278,7 +3814,7 @@ var ClientServicesHost = class {
4278
3814
  this._open = true;
4279
3815
  this._statusUpdate.emit();
4280
3816
  const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4281
- log18("opened", {
3817
+ log15("opened", {
4282
3818
  deviceKey
4283
3819
  }, {
4284
3820
  file: "service-host.ts",
@@ -4286,7 +3822,7 @@ var ClientServicesHost = class {
4286
3822
  scope: this,
4287
3823
  callSite: (f, a) => f(...a)
4288
3824
  });
4289
- log18.trace("dxos.sdk.client-services-host.open", trace6.end({
3825
+ log15.trace("dxos.sdk.client-services-host.open", trace6.end({
4290
3826
  id: traceId
4291
3827
  }), {
4292
3828
  file: "service-host.ts",
@@ -4301,7 +3837,7 @@ var ClientServicesHost = class {
4301
3837
  return;
4302
3838
  }
4303
3839
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4304
- log18("closing...", {
3840
+ log15("closing...", {
4305
3841
  deviceKey
4306
3842
  }, {
4307
3843
  file: "service-host.ts",
@@ -4316,7 +3852,7 @@ var ClientServicesHost = class {
4316
3852
  await this._serviceContext.close();
4317
3853
  this._open = false;
4318
3854
  this._statusUpdate.emit();
4319
- log18("closed", {
3855
+ log15("closed", {
4320
3856
  deviceKey
4321
3857
  }, {
4322
3858
  file: "service-host.ts",
@@ -4328,7 +3864,7 @@ var ClientServicesHost = class {
4328
3864
  async reset() {
4329
3865
  var _a;
4330
3866
  const traceId = PublicKey10.random().toHex();
4331
- log18.trace("dxos.sdk.client-services-host.reset", trace6.begin({
3867
+ log15.trace("dxos.sdk.client-services-host.reset", trace6.begin({
4332
3868
  id: traceId
4333
3869
  }), {
4334
3870
  file: "service-host.ts",
@@ -4336,7 +3872,7 @@ var ClientServicesHost = class {
4336
3872
  scope: this,
4337
3873
  callSite: (f, a) => f(...a)
4338
3874
  });
4339
- log18("resetting...", {}, {
3875
+ log15("resetting...", {}, {
4340
3876
  file: "service-host.ts",
4341
3877
  line: 273,
4342
3878
  scope: this,
@@ -4344,13 +3880,13 @@ var ClientServicesHost = class {
4344
3880
  });
4345
3881
  await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4346
3882
  await this._storage.reset();
4347
- log18("reset", {}, {
3883
+ log15("reset", {}, {
4348
3884
  file: "service-host.ts",
4349
3885
  line: 276,
4350
3886
  scope: this,
4351
3887
  callSite: (f, a) => f(...a)
4352
3888
  });
4353
- log18.trace("dxos.sdk.client-services-host.reset", trace6.end({
3889
+ log15.trace("dxos.sdk.client-services-host.reset", trace6.end({
4354
3890
  id: traceId
4355
3891
  }), {
4356
3892
  file: "service-host.ts",
@@ -4383,125 +3919,6 @@ var LocalClientServices = class {
4383
3919
  }
4384
3920
  };
4385
3921
 
4386
- // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
4387
- var __decorate5 = function(decorators, target, key, desc) {
4388
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4389
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
4390
- r = Reflect.decorate(decorators, target, key, desc);
4391
- else
4392
- for (var i = decorators.length - 1; i >= 0; i--)
4393
- if (d = decorators[i])
4394
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4395
- return c > 3 && r && Object.defineProperty(target, key, r), r;
4396
- };
4397
- var LOCK_KEY = "DXOS_RESOURCE_LOCK";
4398
- var IFrameHostRuntime = class {
4399
- constructor({ config, origin, appPort, shellPort }) {
4400
- this._ready = new Trigger10();
4401
- this._configProvider = config;
4402
- this.origin = origin;
4403
- this._appPort = appPort;
4404
- this._shellPort = shellPort;
4405
- if (this._shellPort) {
4406
- this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
4407
- }
4408
- }
4409
- get services() {
4410
- return this._clientServices;
4411
- }
4412
- get shell() {
4413
- return this._shellRuntime;
4414
- }
4415
- async start() {
4416
- var _a;
4417
- log19("starting...", {}, {
4418
- file: "iframe-host-runtime.ts",
4419
- line: 70,
4420
- scope: this,
4421
- callSite: (f, a) => f(...a)
4422
- });
4423
- try {
4424
- this._config = await getAsyncValue2(this._configProvider);
4425
- this._transportFactory = createWebRTCTransportFactory2({
4426
- iceServers: this._config.get("runtime.services.ice")
4427
- });
4428
- const signals = this._config.get("runtime.services.signaling");
4429
- this._clientServices = new LocalClientServices({
4430
- lockKey: LOCK_KEY,
4431
- config: this._config,
4432
- signalManager: signals ? new WebsocketSignalManager3(signals) : new MemorySignalManager2(new MemorySignalManagerContext2()),
4433
- transportFactory: this._transportFactory
4434
- });
4435
- const middleware = {
4436
- handleCall: async (method, params, handler) => {
4437
- const error = await this._ready.wait({
4438
- timeout: PROXY_CONNECTION_TIMEOUT2
4439
- });
4440
- if (error) {
4441
- throw error;
4442
- }
4443
- return handler(method, params);
4444
- },
4445
- handleStream: async (method, params, handler) => {
4446
- const error = await this._ready.wait({
4447
- timeout: PROXY_CONNECTION_TIMEOUT2
4448
- });
4449
- if (error) {
4450
- throw error;
4451
- }
4452
- return handler(method, params);
4453
- }
4454
- };
4455
- this._clientRpc = new ClientRpcServer({
4456
- serviceRegistry: this._clientServices.host.serviceRegistry,
4457
- port: this._appPort,
4458
- ...middleware
4459
- });
4460
- await Promise.all([
4461
- this._clientServices.open(),
4462
- this._clientRpc.open(),
4463
- (_a = this._shellRuntime) == null ? void 0 : _a.open()
4464
- ]);
4465
- this._ready.wake(void 0);
4466
- log19("started", {}, {
4467
- file: "iframe-host-runtime.ts",
4468
- line: 113,
4469
- scope: this,
4470
- callSite: (f, a) => f(...a)
4471
- });
4472
- } catch (err) {
4473
- this._ready.wake(err);
4474
- log19.catch(err, {}, {
4475
- file: "iframe-host-runtime.ts",
4476
- line: 116,
4477
- scope: this,
4478
- callSite: (f, a) => f(...a)
4479
- });
4480
- }
4481
- }
4482
- async stop() {
4483
- var _a;
4484
- log19("stopping...", {}, {
4485
- file: "iframe-host-runtime.ts",
4486
- line: 121,
4487
- scope: this,
4488
- callSite: (f, a) => f(...a)
4489
- });
4490
- await this._clientRpc.close();
4491
- await this._clientServices.close();
4492
- await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
4493
- log19("stopped", {}, {
4494
- file: "iframe-host-runtime.ts",
4495
- line: 125,
4496
- scope: this,
4497
- callSite: (f, a) => f(...a)
4498
- });
4499
- }
4500
- };
4501
- __decorate5([
4502
- logInfo3
4503
- ], IFrameHostRuntime.prototype, "origin", void 0);
4504
-
4505
3922
  export {
4506
3923
  subscribeToFeeds,
4507
3924
  subscribeToFeedBlocks,
@@ -4522,20 +3939,15 @@ export {
4522
3939
  InvitationsHandler,
4523
3940
  InvitationsServiceImpl,
4524
3941
  SpaceInvitationProtocol,
3942
+ Lock,
3943
+ isLocked,
4525
3944
  DataSpace,
4526
3945
  DataSpaceManager,
4527
3946
  SpacesServiceImpl,
4528
3947
  createStorageObjects,
4529
- ShellRuntimeImpl,
4530
- MemoryShellRuntime,
4531
- IFrameHostRuntime,
4532
- IFrameProxyRuntime,
4533
- VaultResourceLock,
4534
- WorkerSession,
4535
- WorkerRuntime,
4536
3948
  ServiceContext,
4537
3949
  ServiceRegistry,
4538
3950
  ClientServicesHost,
4539
3951
  LocalClientServices
4540
3952
  };
4541
- //# sourceMappingURL=chunk-KMQOZOUZ.mjs.map
3953
+ //# sourceMappingURL=chunk-UL74TKNZ.mjs.map