@dxos/edge-client 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549

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.
@@ -934,7 +934,7 @@ var EdgeHttpClient = class {
934
934
  url: this._baseUrl
935
935
  }, {
936
936
  F: __dxlog_file6,
937
- L: 107,
937
+ L: 102,
938
938
  S: this,
939
939
  C: (f, a) => f(...a)
940
940
  });
@@ -1115,8 +1115,7 @@ var EdgeHttpClient = class {
1115
1115
  return this._call(url, {
1116
1116
  ...args,
1117
1117
  body: input,
1118
- method: "POST",
1119
- rawResponse: true
1118
+ method: "POST"
1120
1119
  });
1121
1120
  }
1122
1121
  //
@@ -1137,6 +1136,11 @@ var EdgeHttpClient = class {
1137
1136
  method: "GET"
1138
1137
  });
1139
1138
  }
1139
+ async forceRunCronTrigger(spaceId, triggerId) {
1140
+ return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
1141
+ method: "POST"
1142
+ });
1143
+ }
1140
1144
  //
1141
1145
  // Import/Export space.
1142
1146
  //
@@ -1201,12 +1205,9 @@ var EdgeHttpClient = class {
1201
1205
  const response = await fetch(url, request);
1202
1206
  if (response.ok) {
1203
1207
  const body2 = await response.clone().json();
1204
- if (args.rawResponse) {
1205
- return body2;
1206
- }
1207
1208
  invariant4(body2, "Expected body to be present", {
1208
1209
  F: __dxlog_file6,
1209
- L: 424,
1210
+ L: 421,
1210
1211
  S: this,
1211
1212
  A: [
1212
1213
  "body",
@@ -1227,21 +1228,21 @@ var EdgeHttpClient = class {
1227
1228
  const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
1228
1229
  invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
1229
1230
  F: __dxlog_file6,
1230
- L: 440,
1231
+ L: 437,
1231
1232
  S: this,
1232
1233
  A: [
1233
1234
  "!body?.success",
1234
1235
  "'Expected body to not be a failure response or undefined.'"
1235
1236
  ]
1236
1237
  });
1237
- if (body?.errorData?.type === "auth_challenge" && typeof body?.errorData?.challenge === "string") {
1238
- processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
1238
+ if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
1239
+ processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
1239
1240
  } else if (body?.success === false) {
1240
1241
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
1241
1242
  } else {
1242
1243
  invariant4(!response.ok, "Expected response to not be ok.", {
1243
1244
  F: __dxlog_file6,
1244
- L: 447,
1245
+ L: 444,
1245
1246
  S: this,
1246
1247
  A: [
1247
1248
  "!response.ok",
@@ -1259,7 +1260,7 @@ var EdgeHttpClient = class {
1259
1260
  processingError
1260
1261
  }, {
1261
1262
  F: __dxlog_file6,
1262
- L: 455,
1263
+ L: 452,
1263
1264
  S: this,
1264
1265
  C: (f, a) => f(...a)
1265
1266
  });
@@ -1272,7 +1273,7 @@ var EdgeHttpClient = class {
1272
1273
  if (!this._edgeIdentity) {
1273
1274
  log4.warn("unauthorized response received before identity was set", void 0, {
1274
1275
  F: __dxlog_file6,
1275
- L: 464,
1276
+ L: 461,
1276
1277
  S: this,
1277
1278
  C: (f, a) => f(...a)
1278
1279
  });
@@ -1296,7 +1297,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
1296
1297
  bodySize: requestBody.length
1297
1298
  }, {
1298
1299
  F: __dxlog_file6,
1299
- L: 488,
1300
+ L: 485,
1300
1301
  S: void 0,
1301
1302
  C: (f, a) => f(...a)
1302
1303
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/auth.ts", "../../../src/edge-client.ts", "../../../src/edge-identity.ts", "../../../src/edge-ws-connection.ts", "../../../src/errors.ts", "../../../src/utils.ts", "../../../src/edge-http-client.ts", "../../../src/http-client.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport * from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nexport * from './auth';\nexport * from './defs';\nexport * from './edge-client';\nexport * from './errors';\nexport * from './protocol';\nexport * from './edge-http-client';\nexport * from './edge-identity';\nexport * from './edge-ws-muxer';\nexport * from './http-client';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createCredential, signPresentation } from '@dxos/credentials';\nimport { type Signer } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { type Chain, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport type { EdgeIdentity } from './edge-identity';\n\n/**\n * Edge identity backed by a device key without a credential chain.\n */\nexport const createDeviceEdgeIdentity = async (signer: Signer, key: PublicKey): Promise<EdgeIdentity> => {\n return {\n identityKey: key.toHex(),\n peerKey: key.toHex(),\n presentCredentials: async ({ challenge }) => {\n return signPresentation({\n presentation: {\n credentials: [\n // Verifier requires at least one credential in the presentation to establish the subject.\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: key,\n subject: key,\n signer,\n }),\n ],\n },\n signer,\n signerKey: key,\n nonce: challenge,\n });\n },\n };\n};\n\n/**\n * Edge identity backed by a chain of credentials.\n */\nexport const createChainEdgeIdentity = async (\n signer: Signer,\n identityKey: PublicKey,\n peerKey: PublicKey,\n chain: Chain | undefined,\n credentials: Credential[],\n): Promise<EdgeIdentity> => {\n const credentialsToSign =\n credentials.length > 0\n ? credentials\n : [\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: identityKey,\n subject: identityKey,\n signer,\n chain,\n signingKey: peerKey,\n }),\n ];\n\n return {\n identityKey: identityKey.toHex(),\n peerKey: peerKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n // TODO: make chain required after device invitation flow update release\n invariant(chain);\n return signPresentation({\n presentation: {\n credentials: credentialsToSign,\n },\n signer,\n nonce: challenge,\n signerKey: peerKey,\n chain,\n });\n },\n };\n};\n\n/**\n * Edge identity backed by a random ephemeral key without HALO.\n */\nexport const createEphemeralEdgeIdentity = async (): Promise<EdgeIdentity> => {\n const keyring = new Keyring();\n const key = await keyring.createKey();\n return createDeviceEdgeIdentity(keyring, key);\n};\n\n/**\n * Creates a HALO chain of credentials to act as an edge identity.\n */\nexport const createTestHaloEdgeIdentity = async (\n signer: Signer,\n identityKey: PublicKey,\n deviceKey: PublicKey,\n): Promise<EdgeIdentity> => {\n const deviceAdmission = await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.AuthorizedDevice',\n deviceKey,\n identityKey,\n },\n issuer: identityKey,\n subject: deviceKey,\n signer,\n });\n return createChainEdgeIdentity(signer, identityKey, deviceKey, { credential: deviceAdmission }, [\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: identityKey,\n subject: identityKey,\n signer,\n }),\n ]);\n};\n\nexport const createStubEdgeIdentity = (): EdgeIdentity => {\n const identityKey = PublicKey.random();\n const deviceKey = PublicKey.random();\n return {\n identityKey: identityKey.toHex(),\n peerKey: deviceKey.toHex(),\n presentCredentials: async () => {\n throw new Error('Stub identity does not support authentication.');\n },\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport {\n Event,\n PersistentLifecycle,\n Trigger,\n TriggerState,\n scheduleMicroTask,\n scheduleTaskInterval,\n} from '@dxos/async';\nimport { type Lifecycle, Resource } from '@dxos/context';\nimport { log, logInfo } from '@dxos/log';\nimport { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';\n\nimport { protocol } from './defs';\nimport { type EdgeIdentity, handleAuthChallenge } from './edge-identity';\nimport { EdgeWsConnection } from './edge-ws-connection';\nimport { EdgeConnectionClosedError, EdgeIdentityChangedError } from './errors';\nimport { type Protocol } from './protocol';\nimport { getEdgeUrlWithProtocol } from './utils';\n\nconst DEFAULT_TIMEOUT = 10_000;\n\n// Refresh status every second: rtt, rate counters.\nconst STATUS_REFRESH_INTERVAL = 1000;\n\nexport type MessageListener = (message: Message) => void;\nexport type ReconnectListener = () => void;\n\nexport type MessengerConfig = {\n socketEndpoint: string;\n timeout?: number;\n protocol?: Protocol;\n disableAuth?: boolean;\n};\n\nexport interface EdgeConnection extends Required<Lifecycle> {\n statusChanged: Event<EdgeStatus>;\n get info(): any;\n get identityKey(): string;\n get peerKey(): string;\n get isOpen(): boolean;\n get status(): EdgeStatus;\n setIdentity(identity: EdgeIdentity): void;\n send(message: Message): Promise<void>;\n onMessage(listener: MessageListener): () => void;\n onReconnected(listener: ReconnectListener): () => void;\n}\n\n/**\n * Messenger client for EDGE:\n * - While open, uses PersistentLifecycle to keep an open EdgeWsConnection, reconnecting on failures.\n * - Manages identity and re-create EdgeWsConnection when identity changes.\n * - Dispatches connection state and message notifications.\n */\nexport class EdgeClient extends Resource implements EdgeConnection {\n public readonly statusChanged = new Event<EdgeStatus>();\n\n private readonly _persistentLifecycle = new PersistentLifecycle<EdgeWsConnection>({\n start: async () => this._connect(),\n stop: async (state: EdgeWsConnection) => this._disconnect(state),\n });\n\n private readonly _messageListeners = new Set<MessageListener>();\n private readonly _reconnectListeners = new Set<ReconnectListener>();\n private readonly _baseWsUrl: string;\n private readonly _baseHttpUrl: string;\n private _currentConnection?: EdgeWsConnection = undefined;\n private _ready = new Trigger();\n\n constructor(\n private _identity: EdgeIdentity,\n private readonly _config: MessengerConfig,\n ) {\n super();\n this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, 'ws');\n this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, 'http');\n }\n\n @logInfo\n public get info() {\n return {\n open: this.isOpen,\n status: this.status,\n identity: this._identity.identityKey,\n device: this._identity.peerKey,\n };\n }\n\n get status(): EdgeStatus {\n return {\n state:\n Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED\n ? EdgeStatus.ConnectionState.CONNECTED\n : EdgeStatus.ConnectionState.NOT_CONNECTED,\n uptime: this._currentConnection?.uptime ?? 0,\n rtt: this._currentConnection?.rtt ?? 0,\n rateBytesUp: this._currentConnection?.uploadRate ?? 0,\n rateBytesDown: this._currentConnection?.downloadRate ?? 0,\n messagesSent: this._currentConnection?.messagesSent ?? 0,\n messagesReceived: this._currentConnection?.messagesReceived ?? 0,\n };\n }\n\n get identityKey() {\n return this._identity.identityKey;\n }\n\n get peerKey() {\n return this._identity.peerKey;\n }\n\n setIdentity(identity: EdgeIdentity) {\n if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {\n log('Edge identity changed', { identity, oldIdentity: this._identity });\n this._identity = identity;\n this._closeCurrentConnection(new EdgeIdentityChangedError());\n void this._persistentLifecycle.scheduleRestart();\n }\n }\n\n /**\n * Send message.\n * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.\n */\n public async send(message: Message) {\n if (this._ready.state !== TriggerState.RESOLVED) {\n log('waiting for websocket');\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n }\n\n if (!this._currentConnection) {\n throw new EdgeConnectionClosedError();\n }\n\n if (\n message.source &&\n (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)\n ) {\n throw new EdgeIdentityChangedError();\n }\n\n this._currentConnection.send(message);\n }\n\n public onMessage(listener: MessageListener) {\n this._messageListeners.add(listener);\n return () => this._messageListeners.delete(listener);\n }\n\n public onReconnected(listener: () => void) {\n this._reconnectListeners.add(listener);\n if (this._ready.state === TriggerState.RESOLVED) {\n // Microtask so that listener is always called asynchronously, no matter the state of the ready trigger\n // at the moment of registration.\n scheduleMicroTask(this._ctx, () => {\n if (this._reconnectListeners.has(listener)) {\n try {\n listener();\n } catch (error) {\n log.catch(error);\n }\n }\n });\n }\n\n return () => this._reconnectListeners.delete(listener);\n }\n\n /**\n * Open connection to messaging service.\n */\n protected override async _open(): Promise<void> {\n log('opening...', { info: this.info });\n this._persistentLifecycle.open().catch((err) => {\n log.warn('Error while opening connection', { err });\n });\n\n // Notify about status changes (rtt, rate counters).\n scheduleTaskInterval(\n this._ctx,\n async () => {\n if (!this._currentConnection) {\n return;\n }\n this.statusChanged.emit(this.status);\n },\n STATUS_REFRESH_INTERVAL,\n );\n }\n\n /**\n * Close connection and free resources.\n */\n protected override async _close(): Promise<void> {\n log('closing...', { peerKey: this._identity.peerKey });\n this._closeCurrentConnection();\n await this._persistentLifecycle.close();\n }\n\n private async _connect(): Promise<EdgeWsConnection | undefined> {\n if (this._ctx.disposed) {\n return undefined;\n }\n\n const identity = this._identity;\n const path = `/ws/${identity.identityKey}/${identity.peerKey}`;\n const protocolHeader = this._config.disableAuth ? undefined : await this._createAuthHeader(path);\n if (this._identity !== identity) {\n log('identity changed during auth header request');\n return undefined;\n }\n\n const restartRequired = new Trigger();\n const url = new URL(path, this._baseWsUrl);\n log('Opening websocket', { url: url.toString(), protocolHeader });\n const connection = new EdgeWsConnection(\n identity,\n { url, protocolHeader },\n {\n onConnected: () => {\n if (this._isActive(connection)) {\n this._ready.wake();\n this._notifyReconnected();\n } else {\n log.verbose('connected callback ignored, because connection is not active');\n }\n },\n onRestartRequired: () => {\n if (this._isActive(connection)) {\n this._closeCurrentConnection();\n void this._persistentLifecycle.scheduleRestart();\n } else {\n log.verbose('restart requested by inactive connection');\n }\n restartRequired.wake();\n },\n onMessage: (message) => {\n if (this._isActive(connection)) {\n this._notifyMessageReceived(message);\n } else {\n log.verbose('ignored a message on inactive connection', {\n from: message.source,\n type: message.payload?.typeUrl,\n });\n }\n },\n },\n );\n this._currentConnection = connection;\n\n await connection.open();\n // Race with restartRequired so that restart is not blocked by _connect execution.\n // Wait on ready to attempt a reconnect if it times out.\n await Promise.race([this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT }), restartRequired]);\n return connection;\n }\n\n private async _disconnect(state: EdgeWsConnection): Promise<void> {\n await state.close();\n this.statusChanged.emit(this.status);\n }\n\n private _closeCurrentConnection(error: Error = new EdgeConnectionClosedError()): void {\n this._currentConnection = undefined;\n this._ready.throw(error);\n this._ready.reset();\n this.statusChanged.emit(this.status);\n }\n\n private _notifyReconnected(): void {\n this.statusChanged.emit(this.status);\n for (const listener of this._reconnectListeners) {\n try {\n listener();\n } catch (err) {\n log.error('ws reconnect listener failed', { err });\n }\n }\n }\n\n private _notifyMessageReceived(message: Message): void {\n for (const listener of this._messageListeners) {\n try {\n listener(message);\n } catch (err) {\n log.error('ws incoming message processing failed', { err, payload: protocol.getPayloadType(message) });\n }\n }\n }\n\n private async _createAuthHeader(path: string): Promise<string | undefined> {\n const httpUrl = new URL(path, this._baseHttpUrl);\n httpUrl.protocol = getEdgeUrlWithProtocol(this._baseWsUrl.toString(), 'http');\n const response = await fetch(httpUrl, { method: 'GET' });\n if (response.status === 401) {\n return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));\n } else {\n log.warn('no auth challenge from edge', { status: response.status, statusText: response.statusText });\n return undefined;\n }\n }\n\n private _isActive = (connection: EdgeWsConnection) => connection === this._currentConnection;\n}\n\nconst encodePresentationWsAuthHeader = (encodedPresentation: Uint8Array): string => {\n // '=' and '/' characters are not allowed in the WebSocket subprotocol header.\n const encodedToken = Buffer.from(encodedPresentation).toString('base64').replace(/=*$/, '').replaceAll('/', '|');\n return `base64url.bearer.authorization.dxos.org.${encodedToken}`;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Presentation } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nexport interface EdgeIdentity {\n peerKey: string;\n identityKey: string;\n /**\n * Returns credential presentation issued by the identity key.\n * Presentation must have the provided challenge.\n * Presentation may include ServiceAccess credentials.\n */\n presentCredentials({ challenge }: { challenge: Uint8Array }): Promise<Presentation>;\n}\n\nexport const handleAuthChallenge = async (failedResponse: Response, identity: EdgeIdentity): Promise<Uint8Array> => {\n invariant(failedResponse.status === 401);\n\n const headerValue = failedResponse.headers.get('Www-Authenticate');\n invariant(headerValue?.startsWith('VerifiablePresentation challenge='));\n\n const challenge = headerValue?.slice('VerifiablePresentation challenge='.length);\n invariant(challenge);\n\n const presentation = await identity.presentCredentials({ challenge: Buffer.from(challenge, 'base64') });\n return schema.getCodecForType('dxos.halo.credentials.Presentation').encode(presentation);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { scheduleTask, scheduleTaskInterval } from '@dxos/async';\nimport { Context, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log, logInfo } from '@dxos/log';\nimport { EdgeWebsocketProtocol } from '@dxos/protocols';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\nimport { type EdgeIdentity } from './edge-identity';\nimport { CLOUDFLARE_MESSAGE_MAX_BYTES, WebSocketMuxer } from './edge-ws-muxer';\nimport { toUint8Array } from './protocol';\n\nconst SIGNAL_KEEPALIVE_INTERVAL = 4_000;\nconst SIGNAL_KEEPALIVE_TIMEOUT = 12_000;\n\nexport type EdgeWsConnectionCallbacks = {\n onConnected: () => void;\n onMessage: (message: Message) => void;\n onRestartRequired: () => void;\n};\n\nexport class EdgeWsConnection extends Resource {\n private _inactivityTimeoutCtx: Context | undefined;\n private _ws: WebSocket | undefined;\n private _wsMuxer: WebSocketMuxer | undefined;\n private _lastReceivedMessageTimestamp = Date.now();\n\n private _openTimestamp: number | undefined;\n\n // Latency tracking.\n private _pingTimestamp: number | undefined;\n private _rtt = 0;\n\n // Rate tracking with sliding window.\n private _uploadRate = 0;\n private _downloadRate = 0;\n private readonly _rateWindow = 10000; // 10 second sliding window.\n private readonly _rateUpdateInterval = 1000; // Update rates every second.\n private _bytesSamples: Array<{ timestamp: number; sent: number; received: number }> = [];\n\n private _messagesSent = 0;\n private _messagesReceived = 0;\n\n constructor(\n private readonly _identity: EdgeIdentity,\n private readonly _connectionInfo: { url: URL; protocolHeader?: string },\n private readonly _callbacks: EdgeWsConnectionCallbacks,\n ) {\n super();\n }\n\n @logInfo\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identity.identityKey,\n device: this._identity.peerKey,\n };\n }\n\n public get rtt(): number {\n return this._rtt;\n }\n\n public get uptime(): number {\n return this._openTimestamp ? (Date.now() - this._openTimestamp) / 1000 : 0;\n }\n\n public get uploadRate(): number {\n return this._uploadRate;\n }\n\n public get downloadRate(): number {\n return this._downloadRate;\n }\n\n public get messagesSent(): number {\n return this._messagesSent;\n }\n\n public get messagesReceived(): number {\n return this._messagesReceived;\n }\n\n public send(message: Message): void {\n invariant(this._ws);\n invariant(this._wsMuxer);\n log('sending...', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });\n this._messagesSent++;\n if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {\n const binary = buf.toBinary(MessageSchema, message);\n if (binary.length > CLOUDFLARE_MESSAGE_MAX_BYTES) {\n log.error('Message dropped because it was too large (>1MB).', {\n byteLength: binary.byteLength,\n serviceId: message.serviceId,\n payload: protocol.getPayloadType(message),\n });\n return;\n }\n this._recordBytes(binary.byteLength, 0);\n this._ws.send(binary);\n } else {\n // For muxer, we need to track the size of the message being sent.\n const binary = buf.toBinary(MessageSchema, message);\n this._recordBytes(binary.byteLength, 0);\n this._wsMuxer.send(message).catch((e) => log.catch(e));\n }\n }\n\n protected override async _open(): Promise<void> {\n const baseProtocols = [...Object.values(EdgeWebsocketProtocol)];\n this._ws = new WebSocket(\n this._connectionInfo.url.toString(),\n this._connectionInfo.protocolHeader\n ? [...baseProtocols, this._connectionInfo.protocolHeader]\n : [...baseProtocols],\n );\n const muxer = new WebSocketMuxer(this._ws);\n this._wsMuxer = muxer;\n\n this._ws.onopen = () => {\n if (this.isOpen) {\n log('connected');\n this._openTimestamp = Date.now();\n this._callbacks.onConnected();\n this._scheduleHeartbeats();\n this._scheduleRateCalculation();\n } else {\n log.verbose('connected after becoming inactive', { currentIdentity: this._identity });\n }\n };\n this._ws.onclose = (event: WebSocket.CloseEvent) => {\n if (this.isOpen) {\n log.warn('server disconnected', { code: event.code, reason: event.reason });\n this._callbacks.onRestartRequired();\n muxer.destroy();\n }\n };\n this._ws.onerror = (event: WebSocket.ErrorEvent) => {\n if (this.isOpen) {\n log.warn('edge connection socket error', { error: event.error, info: event.message });\n this._callbacks.onRestartRequired();\n } else {\n log.verbose('error ignored on closed connection', { error: event.error });\n }\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event: WebSocket.MessageEvent) => {\n if (!this.isOpen) {\n log.verbose('message ignored on closed connection', { event: event.type });\n return;\n }\n this._lastReceivedMessageTimestamp = Date.now();\n if (event.data === '__pong__') {\n // Calculate latency.\n if (this._pingTimestamp) {\n this._rtt = Date.now() - this._pingTimestamp;\n this._pingTimestamp = undefined;\n }\n this._rescheduleHeartbeatTimeout();\n return;\n }\n const bytes = await toUint8Array(event.data);\n this._recordBytes(0, bytes.byteLength);\n if (!this.isOpen) {\n return;\n }\n\n this._messagesReceived++;\n\n const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0)\n ? buf.fromBinary(MessageSchema, bytes)\n : muxer.receiveData(bytes);\n\n if (message) {\n log('received', { from: message.source, payload: protocol.getPayloadType(message) });\n this._callbacks.onMessage(message);\n }\n };\n }\n\n protected override async _close(): Promise<void> {\n void this._inactivityTimeoutCtx?.dispose().catch(() => {});\n\n try {\n this._ws?.close();\n this._ws = undefined;\n this._wsMuxer?.destroy();\n this._wsMuxer = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('error closing websocket', { err });\n }\n }\n\n private _scheduleHeartbeats(): void {\n invariant(this._ws);\n scheduleTaskInterval(\n this._ctx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._pingTimestamp = Date.now();\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._pingTimestamp = Date.now();\n this._ws.send('__ping__');\n this._rescheduleHeartbeatTimeout();\n }\n\n private _rescheduleHeartbeatTimeout(): void {\n if (!this.isOpen) {\n return;\n }\n void this._inactivityTimeoutCtx?.dispose();\n this._inactivityTimeoutCtx = new Context();\n scheduleTask(\n this._inactivityTimeoutCtx,\n () => {\n if (this.isOpen) {\n if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {\n log.warn('restart due to inactivity timeout', {\n lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp,\n });\n this._callbacks.onRestartRequired();\n } else {\n this._rescheduleHeartbeatTimeout();\n }\n }\n },\n SIGNAL_KEEPALIVE_TIMEOUT,\n );\n }\n\n private _recordBytes(sent: number, received: number): void {\n const now = Date.now();\n\n // Find if we have a sample for the current second.\n const currentSecond = Math.floor(now / 1000) * 1000;\n const existingSample = this._bytesSamples.find((s) => Math.floor(s.timestamp / 1000) * 1000 === currentSecond);\n\n if (existingSample) {\n existingSample.sent += sent;\n existingSample.received += received;\n } else {\n this._bytesSamples.push({ timestamp: now, sent, received });\n }\n }\n\n private _scheduleRateCalculation(): void {\n scheduleTaskInterval(\n this._ctx,\n async () => {\n this._calculateRates();\n },\n this._rateUpdateInterval,\n );\n // Calculate initial rates.\n this._calculateRates();\n }\n\n private _calculateRates(): void {\n const now = Date.now();\n const cutoff = now - this._rateWindow;\n\n // Remove old samples.\n this._bytesSamples = this._bytesSamples.filter((s) => s.timestamp > cutoff);\n\n if (this._bytesSamples.length === 0) {\n this._uploadRate = 0;\n this._downloadRate = 0;\n return;\n }\n\n // Calculate total bytes and time span.\n let totalSent = 0;\n let totalReceived = 0;\n const oldestTimestamp = Math.min(...this._bytesSamples.map((s) => s.timestamp));\n const timeSpan = (now - oldestTimestamp) / 1000; // Convert to seconds.\n\n for (const sample of this._bytesSamples) {\n totalSent += sample.sent;\n totalReceived += sample.received;\n }\n\n // Calculate rates (bytes per second).\n this._uploadRate = timeSpan > 0 ? Math.round(totalSent / timeSpan) : 0;\n this._downloadRate = timeSpan > 0 ? Math.round(totalReceived / timeSpan) : 0;\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport class EdgeConnectionClosedError extends Error {\n constructor() {\n super('Edge connection closed.');\n }\n}\n\nexport class EdgeIdentityChangedError extends Error {\n constructor() {\n super('Edge identity changed.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport const getEdgeUrlWithProtocol = (baseUrl: string, protocol: 'http' | 'ws') => {\n const isSecure = baseUrl.startsWith('https') || baseUrl.startsWith('wss');\n const url = new URL(baseUrl);\n url.protocol = protocol + (isSecure ? 's' : '');\n return url.toString();\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as FetchHttpClient from '@effect/platform/FetchHttpClient';\nimport * as HttpClient from '@effect/platform/HttpClient';\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\n\nimport { sleep } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey, type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport {\n type CreateAgentRequestBody,\n type CreateAgentResponseBody,\n type CreateSpaceRequest,\n type CreateSpaceResponseBody,\n EdgeAuthChallengeError,\n EdgeCallFailedError,\n type EdgeStatus,\n type ExecuteWorkflowResponseBody,\n type ExportBundleRequest,\n type ExportBundleResponse,\n type GetAgentStatusResponseBody,\n type GetNotarizationResponseBody,\n type ImportBundleRequest,\n type InitiateOAuthFlowRequest,\n type InitiateOAuthFlowResponse,\n type JoinSpaceRequest,\n type JoinSpaceResponseBody,\n type ObjectId,\n type PostNotarizationRequestBody,\n type QueryResult,\n type QueueQuery,\n type RecoverIdentityRequest,\n type RecoverIdentityResponseBody,\n type UploadFunctionRequest,\n type UploadFunctionResponseBody,\n} from '@dxos/protocols';\nimport { createUrl } from '@dxos/util';\n\nimport { type EdgeIdentity, handleAuthChallenge } from './edge-identity';\nimport { HttpConfig, encodeAuthHeader, withLogging, withRetryConfig } from './http-client';\nimport { getEdgeUrlWithProtocol } from './utils';\n\nconst DEFAULT_RETRY_TIMEOUT = 1500;\nconst DEFAULT_RETRY_JITTER = 500;\nconst DEFAULT_MAX_RETRIES_COUNT = 3;\nconst WARNING_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport type RetryConfig = {\n /**\n * A number of call retries, not counting the initial request.\n */\n count: number;\n /**\n * Delay before retries in ms.\n */\n timeout?: number;\n /**\n * A random amount of time before retrying to help prevent large bursts of requests.\n */\n jitter?: number;\n};\n\ntype EdgeHttpRequestArgs = {\n method: string;\n context?: Context;\n retry?: RetryConfig;\n body?: any;\n /**\n * @default true\n */\n json?: boolean;\n\n /**\n * Do not expect a standard EDGE JSON response with a `success` field.\n * @deprecated Use only for debugging.\n */\n rawResponse?: boolean;\n\n /**\n * Force authentication.\n * This should be used for requests with large bodies to avoid sending the body twice.\n * The client will call /auth endpoint to generate the auth header.\n */\n auth?: boolean;\n};\n\nexport type EdgeHttpGetArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'auth'>;\nexport type EdgeHttpPostArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'body' | 'auth'>;\n\nexport class EdgeHttpClient {\n private readonly _baseUrl: string;\n\n private _edgeIdentity: EdgeIdentity | undefined;\n\n /**\n * Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.\n */\n private _authHeader: string | undefined;\n\n constructor(baseUrl: string) {\n this._baseUrl = getEdgeUrlWithProtocol(baseUrl, 'http');\n log('created', { url: this._baseUrl });\n }\n\n get baseUrl() {\n return this._baseUrl;\n }\n\n setIdentity(identity: EdgeIdentity): void {\n if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {\n this._edgeIdentity = identity;\n this._authHeader = undefined;\n }\n }\n\n //\n // Status\n //\n\n public async getStatus(args?: EdgeHttpGetArgs): Promise<EdgeStatus> {\n return this._call(new URL('/status', this.baseUrl), { ...args, method: 'GET' });\n }\n\n //\n // Agents\n //\n\n public createAgent(body: CreateAgentRequestBody, args?: EdgeHttpGetArgs): Promise<CreateAgentResponseBody> {\n return this._call(new URL('/agents/create', this.baseUrl), { ...args, method: 'POST', body });\n }\n\n public getAgentStatus(\n request: { ownerIdentityKey: PublicKey },\n args?: EdgeHttpGetArgs,\n ): Promise<GetAgentStatusResponseBody> {\n return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {\n ...args,\n method: 'GET',\n });\n }\n\n //\n // Credentials\n //\n\n public getCredentialsForNotarization(spaceId: SpaceId, args?: EdgeHttpGetArgs): Promise<GetNotarizationResponseBody> {\n return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, method: 'GET' });\n }\n\n public async notarizeCredentials(\n spaceId: SpaceId,\n body: PostNotarizationRequestBody,\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Identity\n //\n\n public async recoverIdentity(\n body: RecoverIdentityRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<RecoverIdentityResponseBody> {\n return this._call(new URL('/identity/recover', this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Invitations\n //\n\n public async joinSpaceByInvitation(\n spaceId: SpaceId,\n body: JoinSpaceRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<JoinSpaceResponseBody> {\n return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // OAuth and credentials\n //\n\n public async initiateOAuthFlow(\n body: InitiateOAuthFlowRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<InitiateOAuthFlowResponse> {\n return this._call(new URL('/oauth/initiate', this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Spaces\n //\n\n async createSpace(body: CreateSpaceRequest, args?: EdgeHttpGetArgs): Promise<CreateSpaceResponseBody> {\n return this._call(new URL('/spaces/create', this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Queues\n //\n\n public async queryQueue(\n subspaceTag: string,\n spaceId: SpaceId,\n query: QueueQuery,\n args?: EdgeHttpGetArgs,\n ): Promise<QueryResult> {\n const { queueId } = query;\n return this._call(\n createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {\n after: query.after,\n before: query.before,\n limit: query.limit,\n reverse: query.reverse,\n objectIds: query.objectIds?.join(','),\n }),\n {\n ...args,\n method: 'GET',\n },\n );\n }\n\n public async insertIntoQueue(\n subspaceTag: string,\n spaceId: SpaceId,\n queueId: ObjectId,\n objects: unknown[],\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {\n ...args,\n body: { objects },\n method: 'POST',\n });\n }\n\n public async deleteFromQueue(\n subspaceTag: string,\n spaceId: SpaceId,\n queueId: ObjectId,\n objectIds: ObjectId[],\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n return this._call(\n createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {\n ids: objectIds.join(','),\n }),\n {\n ...args,\n method: 'DELETE',\n },\n );\n }\n\n //\n // Functions\n //\n\n public async uploadFunction(\n pathParts: { functionId?: string },\n body: UploadFunctionRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<UploadFunctionResponseBody> {\n const formData = new FormData();\n formData.append('name', body.name ?? '');\n formData.append('version', body.version);\n formData.append('ownerPublicKey', body.ownerPublicKey);\n formData.append('entryPoint', body.entryPoint);\n body.runtime && formData.append('runtime', body.runtime);\n for (const [filename, content] of Object.entries(body.assets)) {\n formData.append(\n 'assets',\n new Blob([content as Uint8Array<ArrayBuffer>], { type: getFileMimeType(filename) }),\n filename,\n );\n }\n\n const path = ['functions', ...(pathParts.functionId ? [pathParts.functionId] : [])].join('/');\n return this._call(new URL(path, this.baseUrl), {\n ...args,\n body: formData,\n method: 'PUT',\n json: false,\n });\n }\n\n public async listFunctions(args?: EdgeHttpGetArgs): Promise<any> {\n return this._call(new URL('/functions', this.baseUrl), { ...args, method: 'GET' });\n }\n\n public async invokeFunction(\n params: {\n functionId: string;\n version?: string;\n spaceId?: SpaceId;\n cpuTimeLimit?: number;\n subrequestsLimit?: number;\n },\n input: unknown,\n args?: EdgeHttpGetArgs,\n ): Promise<any> {\n const url = new URL(`/functions/${params.functionId}`, this.baseUrl);\n if (params.version) {\n url.searchParams.set('version', params.version);\n }\n if (params.spaceId) {\n url.searchParams.set('spaceId', params.spaceId.toString());\n }\n if (params.cpuTimeLimit) {\n url.searchParams.set('cpuTimeLimit', params.cpuTimeLimit.toString());\n }\n if (params.subrequestsLimit) {\n url.searchParams.set('subrequestsLimit', params.subrequestsLimit.toString());\n }\n\n return this._call(url, {\n ...args,\n body: input,\n method: 'POST',\n rawResponse: true,\n });\n }\n\n //\n // Workflows\n //\n\n public async executeWorkflow(\n spaceId: SpaceId,\n graphId: ObjectId,\n input: any,\n args?: EdgeHttpGetArgs,\n ): Promise<ExecuteWorkflowResponseBody> {\n return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {\n ...args,\n body: input,\n method: 'POST',\n });\n }\n\n //\n // Triggers\n //\n\n public async getCronTriggers(spaceId: SpaceId) {\n return this._call(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), { method: 'GET' });\n }\n\n //\n // Import/Export space.\n //\n\n public async importBundle(\n spaceId: SpaceId, //\n body: ImportBundleRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), { ...args, body, method: 'PUT' });\n }\n\n public async exportBundle(\n spaceId: SpaceId,\n body: ExportBundleRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<ExportBundleResponse> {\n return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {\n ...args,\n body,\n method: 'POST',\n });\n }\n\n //\n // Internal\n //\n\n private async _fetch<T>(url: URL, _args: EdgeHttpRequestArgs): Promise<T> {\n return Function.pipe(\n HttpClient.get(url),\n withLogging,\n withRetryConfig,\n Effect.provide(FetchHttpClient.layer),\n Effect.provide(HttpConfig.default),\n Effect.withSpan('EdgeHttpClient'),\n Effect.runPromise,\n ) as T;\n }\n\n // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).\n private async _call<T>(url: URL, args: EdgeHttpRequestArgs): Promise<T> {\n const shouldRetry = createRetryHandler(args);\n const requestContext = args.context ?? Context.default();\n log('fetch', { url, request: args.body });\n\n let handledAuth = false;\n const tryCount = 1;\n while (true) {\n let processingError: EdgeCallFailedError | undefined = undefined;\n try {\n if (!this._authHeader && args.auth) {\n const response = await fetch(new URL(`/auth`, this.baseUrl));\n if (response.status === 401) {\n this._authHeader = await this._handleUnauthorized(response);\n }\n }\n\n const request = createRequest(args, this._authHeader);\n log('call edge', { url, tryCount, authHeader: !!this._authHeader });\n const response = await fetch(url, request);\n\n if (response.ok) {\n const body = await response.clone().json();\n if (args.rawResponse) {\n return body as any;\n }\n invariant(body, 'Expected body to be present');\n if (!('success' in body)) {\n return body;\n }\n if (body.success) {\n return body.data;\n }\n } else if (response.status === 401 && !handledAuth) {\n this._authHeader = await this._handleUnauthorized(response);\n handledAuth = true;\n continue;\n }\n\n const body =\n response.headers.get('Content-Type') === 'application/json' ? await response.clone().json() : undefined;\n\n invariant(!body?.success, 'Expected body to not be a failure response or undefined.');\n\n if (body?.errorData?.type === 'auth_challenge' && typeof body?.errorData?.challenge === 'string') {\n processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);\n } else if (body?.success === false) {\n processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);\n } else {\n invariant(!response.ok, 'Expected response to not be ok.');\n processingError = await EdgeCallFailedError.fromHttpFailure(response);\n }\n } catch (error: any) {\n processingError = EdgeCallFailedError.fromProcessingFailureCause(error);\n }\n\n if (processingError?.isRetryable && (await shouldRetry(requestContext, processingError.retryAfterMs))) {\n log.verbose('retrying edge request', { url, processingError });\n } else {\n throw processingError!;\n }\n }\n }\n\n private async _handleUnauthorized(response: Response): Promise<string> {\n if (!this._edgeIdentity) {\n log.warn('unauthorized response received before identity was set');\n throw await EdgeCallFailedError.fromHttpFailure(response);\n }\n\n const challenge = await handleAuthChallenge(response, this._edgeIdentity);\n return encodeAuthHeader(challenge);\n }\n}\n\nconst createRequest = (\n { method, body, json = true }: EdgeHttpRequestArgs,\n authHeader: string | undefined,\n): RequestInit => {\n let requestBody: BodyInit | undefined;\n const headers: HeadersInit = {};\n\n if (json) {\n requestBody = body && JSON.stringify(body);\n headers['Content-Type'] = 'application/json';\n } else {\n requestBody = body;\n }\n\n if (typeof requestBody === 'string' && requestBody.length > WARNING_BODY_SIZE) {\n log.warn('Request with large body', { bodySize: requestBody.length });\n }\n\n if (authHeader) {\n headers['Authorization'] = authHeader;\n }\n\n return {\n method,\n body: requestBody,\n headers,\n };\n};\n\n/**\n * @deprecated\n */\nconst createRetryHandler = ({ retry }: EdgeHttpRequestArgs) => {\n if (!retry || retry.count < 1) {\n return async () => false;\n }\n\n let retries = 0;\n const maxRetries = retry.count ?? DEFAULT_MAX_RETRIES_COUNT;\n const baseTimeout = retry.timeout ?? DEFAULT_RETRY_TIMEOUT;\n const jitter = retry.jitter ?? DEFAULT_RETRY_JITTER;\n return async (ctx: Context, retryAfter?: number) => {\n if (++retries > maxRetries || ctx.disposed) {\n return false;\n }\n\n if (retryAfter) {\n await sleep(retryAfter);\n } else {\n const timeout = baseTimeout + Math.random() * jitter;\n await sleep(timeout);\n }\n\n return true;\n };\n};\n\nconst getFileMimeType = (filename: string) =>\n ['.js', '.mjs'].some((codeExtension) => filename.endsWith(codeExtension))\n ? 'application/javascript+module'\n : filename.endsWith('.wasm')\n ? 'application/wasm'\n : 'application/octet-stream';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as HttpClient from '@effect/platform/HttpClient';\nimport type * as HttpClientError from '@effect/platform/HttpClientError';\nimport type * as HttpClientResponse from '@effect/platform/HttpClientResponse';\nimport * as Context from 'effect/Context';\nimport * as Duration from 'effect/Duration';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Schedule from 'effect/Schedule';\n\nimport { log } from '@dxos/log';\n\n// TODO(burdon): Factor out.\n\nexport type RetryOptions = {\n timeout: Duration.Duration;\n retryTimes: number;\n retryBaseDelay: Duration.Duration;\n};\n\n// Layer pattern.\nexport class HttpConfig extends Context.Tag('HttpConfig')<HttpConfig, RetryOptions>() {\n static default = Layer.succeed(HttpConfig, {\n timeout: Duration.millis(1_000),\n retryTimes: 3,\n retryBaseDelay: Duration.millis(1_000),\n });\n}\n\n// HOC pattern.\nexport const withRetry = (\n effect: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError, HttpClient.HttpClient>,\n {\n timeout = Duration.millis(1_000),\n retryBaseDelay = Duration.millis(1_000),\n retryTimes = 3,\n }: Partial<RetryOptions> = {},\n) => {\n return effect.pipe(\n Effect.flatMap((res) =>\n // Treat 500 errors as retryable?\n res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json,\n ),\n Effect.timeout(timeout),\n Effect.retry({\n schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),\n times: retryTimes,\n }),\n );\n};\n\nexport const withRetryConfig = (\n effect: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError, HttpClient.HttpClient>,\n) =>\n Effect.gen(function* () {\n const config = yield* HttpConfig;\n return yield* withRetry(effect, config);\n });\n\nexport const withLogging = <A extends HttpClientResponse.HttpClientResponse, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.tap((res) => {\n log.info('response', { status: res.status });\n }),\n );\n\n/**\n *\n */\n// TODO(burdon): Document.\nexport const encodeAuthHeader = (challenge: Uint8Array) => {\n const encodedChallenge = Buffer.from(challenge).toString('base64');\n return `VerifiablePresentation pb;base64,${encodedChallenge}`;\n};\n"],
5
- "mappings": ";;;;;;;;;;;AAIA,cAAc;;;ACAd,SAASA,kBAAkBC,wBAAwB;AAEnD,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,iBAAiB;;AAQnB,IAAMC,2BAA2B,OAAOC,QAAgBC,QAAAA;AAC7D,SAAO;IACLC,aAAaD,IAAIE,MAAK;IACtBC,SAASH,IAAIE,MAAK;IAClBE,oBAAoB,OAAO,EAAEC,UAAS,MAAE;AACtC,aAAOX,iBAAiB;QACtBY,cAAc;UACZC,aAAa;;YAEX,MAAMd,iBAAiB;cACrBe,WAAW;gBACT,SAAS;cACX;cACAC,QAAQT;cACRU,SAASV;cACTD;YACF,CAAA;;QAEJ;QACAA;QACAY,WAAWX;QACXY,OAAOP;MACT,CAAA;IACF;EACF;AACF;AAKO,IAAMQ,0BAA0B,OACrCd,QACAE,aACAE,SACAW,OACAP,gBAAAA;AAEA,QAAMQ,oBACJR,YAAYS,SAAS,IACjBT,cACA;IACE,MAAMd,iBAAiB;MACrBe,WAAW;QACT,SAAS;MACX;MACAC,QAAQR;MACRS,SAAST;MACTF;MACAe;MACAG,YAAYd;IACd,CAAA;;AAGR,SAAO;IACLF,aAAaA,YAAYC,MAAK;IAC9BC,SAASA,QAAQD,MAAK;IACtBE,oBAAoB,OAAO,EAAEC,UAAS,MAAE;AAEtCV,gBAAUmB,OAAAA,QAAAA;;;;;;;;;AACV,aAAOpB,iBAAiB;QACtBY,cAAc;UACZC,aAAaQ;QACf;QACAhB;QACAa,OAAOP;QACPM,WAAWR;QACXW;MACF,CAAA;IACF;EACF;AACF;AAKO,IAAMI,8BAA8B,YAAA;AACzC,QAAMC,UAAU,IAAIvB,QAAAA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M,UAAU/I;AAC/B,SAAO,OAAOgJ,KAAcC,eAAAA;AAC1B,QAAI,EAAEN,UAAUC,cAAcI,IAAIE,UAAU;AAC1C,aAAO;IACT;AAEA,QAAID,YAAY;AACd,YAAME,MAAMF,UAAAA;IACd,OAAO;AACL,YAAMH,WAAUD,cAAcO,KAAKC,OAAM,IAAKN;AAC9C,YAAMI,MAAML,QAAAA;IACd;AAEA,WAAO;EACT;AACF;AAEA,IAAM5E,kBAAkB,CAACP,aACvB;EAAC;EAAO;EAAQ2F,KAAK,CAACC,kBAAkB5F,SAAS6F,SAASD,aAAAA,CAAAA,IACtD,kCACA5F,SAAS6F,SAAS,OAAA,IAChB,qBACA;",
6
- "names": ["createCredential", "signPresentation", "invariant", "Keyring", "PublicKey", "createDeviceEdgeIdentity", "signer", "key", "identityKey", "toHex", "peerKey", "presentCredentials", "challenge", "presentation", "credentials", "assertion", "issuer", "subject", "signerKey", "nonce", "createChainEdgeIdentity", "chain", "credentialsToSign", "length", "signingKey", "createEphemeralEdgeIdentity", "keyring", "createKey", "createTestHaloEdgeIdentity", "deviceKey", "deviceAdmission", "credential", "createStubEdgeIdentity", "random", "Error", "Event", "PersistentLifecycle", "Trigger", "TriggerState", "scheduleMicroTask", "scheduleTaskInterval", "Resource", "log", "logInfo", "EdgeStatus", "invariant", "schema", "handleAuthChallenge", "failedResponse", "identity", "status", "headerValue", "headers", "get", "startsWith", "challenge", "slice", "length", "presentation", "presentCredentials", "Buffer", "from", "getCodecForType", "encode", "WebSocket", "scheduleTask", "scheduleTaskInterval", "Context", "Resource", "invariant", "log", "logInfo", "EdgeWebsocketProtocol", "buf", "MessageSchema", "SIGNAL_KEEPALIVE_INTERVAL", "SIGNAL_KEEPALIVE_TIMEOUT", "EdgeWsConnection", "Resource", "_inactivityTimeoutCtx", "_ws", "_wsMuxer", "_lastReceivedMessageTimestamp", "Date", "now", "_openTimestamp", "_pingTimestamp", "_rtt", "_uploadRate", "_downloadRate", "_rateWindow", "_rateUpdateInterval", "_bytesSamples", "_messagesSent", "_messagesReceived", "_identity", "_connectionInfo", "_callbacks", "info", "open", "isOpen", "identity", "identityKey", "device", "peerKey", "rtt", "uptime", "uploadRate", "downloadRate", "messagesSent", "messagesReceived", "send", "message", "invariant", "log", "payload", "protocol", "getPayloadType", "includes", "EdgeWebsocketProtocol", "V0", "binary", "buf", "toBinary", "MessageSchema", "length", "CLOUDFLARE_MESSAGE_MAX_BYTES", "error", "byteLength", "serviceId", "_recordBytes", "catch", "e", "_open", "baseProtocols", "Object", "values", "WebSocket", "url", "toString", "protocolHeader", "muxer", "WebSocketMuxer", "onopen", "onConnected", "_scheduleHeartbeats", "_scheduleRateCalculation", "verbose", "currentIdentity", "onclose", "event", "warn", "code", "reason", "onRestartRequired", "destroy", "onerror", "onmessage", "type", "data", "undefined", "_rescheduleHeartbeatTimeout", "bytes", "toUint8Array", "fromBinary", "receiveData", "from", "source", "onMessage", "_close", "dispose", "close", "err", "Error", "scheduleTaskInterval", "_ctx", "Context", "scheduleTask", "lastReceivedMessageTimestamp", "sent", "received", "currentSecond", "Math", "floor", "existingSample", "find", "s", "timestamp", "push", "_calculateRates", "cutoff", "filter", "totalSent", "totalReceived", "oldestTimestamp", "min", "map", "timeSpan", "sample", "round", "EdgeConnectionClosedError", "Error", "EdgeIdentityChangedError", "getEdgeUrlWithProtocol", "baseUrl", "protocol", "isSecure", "startsWith", "url", "URL", "toString", "DEFAULT_TIMEOUT", "STATUS_REFRESH_INTERVAL", "EdgeClient", "Resource", "statusChanged", "Event", "_persistentLifecycle", "PersistentLifecycle", "start", "_connect", "stop", "state", "_disconnect", "_messageListeners", "Set", "_reconnectListeners", "_baseWsUrl", "_baseHttpUrl", "_currentConnection", "undefined", "_ready", "Trigger", "_identity", "_config", "getEdgeUrlWithProtocol", "socketEndpoint", "info", "open", "isOpen", "status", "identity", "identityKey", "device", "peerKey", "Boolean", "TriggerState", "RESOLVED", "EdgeStatus", "ConnectionState", "CONNECTED", "NOT_CONNECTED", "uptime", "rtt", "rateBytesUp", "uploadRate", "rateBytesDown", "downloadRate", "messagesSent", "messagesReceived", "setIdentity", "log", "oldIdentity", "_closeCurrentConnection", "EdgeIdentityChangedError", "scheduleRestart", "send", "message", "wait", "timeout", "EdgeConnectionClosedError", "source", "onMessage", "listener", "add", "delete", "onReconnected", "scheduleMicroTask", "_ctx", "has", "error", "catch", "_open", "err", "warn", "scheduleTaskInterval", "emit", "_close", "close", "disposed", "path", "protocolHeader", "disableAuth", "_createAuthHeader", "restartRequired", "url", "URL", "toString", "connection", "EdgeWsConnection", "onConnected", "_isActive", "wake", "_notifyReconnected", "verbose", "onRestartRequired", "_notifyMessageReceived", "from", "type", "payload", "typeUrl", "Promise", "race", "throw", "reset", "protocol", "getPayloadType", "httpUrl", "response", "fetch", "method", "encodePresentationWsAuthHeader", "handleAuthChallenge", "statusText", "encodedPresentation", "encodedToken", "Buffer", "replace", "replaceAll", "FetchHttpClient", "HttpClient", "Effect", "Function", "sleep", "Context", "invariant", "log", "EdgeAuthChallengeError", "EdgeCallFailedError", "createUrl", "Context", "Duration", "Effect", "Layer", "Schedule", "log", "HttpConfig", "Tag", "default", "succeed", "timeout", "millis", "retryTimes", "retryBaseDelay", "withRetry", "effect", "pipe", "flatMap", "res", "status", "fail", "Error", "toString", "json", "retry", "schedule", "exponential", "jittered", "times", "withRetryConfig", "gen", "config", "withLogging", "tap", "info", "encodeAuthHeader", "challenge", "encodedChallenge", "Buffer", "from", "DEFAULT_RETRY_TIMEOUT", "DEFAULT_RETRY_JITTER", "DEFAULT_MAX_RETRIES_COUNT", "WARNING_BODY_SIZE", "EdgeHttpClient", "_baseUrl", "_edgeIdentity", "_authHeader", "baseUrl", "getEdgeUrlWithProtocol", "log", "url", "setIdentity", "identity", "identityKey", "peerKey", "undefined", "getStatus", "args", "_call", "URL", "method", "createAgent", "body", "getAgentStatus", "request", "ownerIdentityKey", "toHex", "getCredentialsForNotarization", "spaceId", "notarizeCredentials", "recoverIdentity", "joinSpaceByInvitation", "initiateOAuthFlow", "createSpace", "queryQueue", "subspaceTag", "query", "queueId", "createUrl", "after", "before", "limit", "reverse", "objectIds", "join", "insertIntoQueue", "objects", "deleteFromQueue", "ids", "uploadFunction", "pathParts", "formData", "FormData", "append", "name", "version", "ownerPublicKey", "entryPoint", "runtime", "filename", "content", "Object", "entries", "assets", "Blob", "type", "getFileMimeType", "path", "functionId", "json", "listFunctions", "invokeFunction", "params", "input", "searchParams", "set", "toString", "cpuTimeLimit", "subrequestsLimit", "rawResponse", "executeWorkflow", "graphId", "getCronTriggers", "importBundle", "exportBundle", "_fetch", "_args", "pipe", "get", "withLogging", "withRetryConfig", "provide", "layer", "HttpConfig", "default", "withSpan", "runPromise", "shouldRetry", "createRetryHandler", "requestContext", "context", "Context", "handledAuth", "tryCount", "processingError", "auth", "response", "fetch", "status", "_handleUnauthorized", "createRequest", "authHeader", "ok", "clone", "invariant", "success", "data", "headers", "errorData", "challenge", "EdgeAuthChallengeError", "EdgeCallFailedError", "fromUnsuccessfulResponse", "fromHttpFailure", "error", "fromProcessingFailureCause", "isRetryable", "retryAfterMs", "verbose", "warn", "handleAuthChallenge", "encodeAuthHeader", "requestBody", "JSON", "stringify", "length", "bodySize", "retry", "count", "retries", "maxRetries", "baseTimeout", "timeout", "jitter", "ctx", "retryAfter", "disposed", "sleep", "Math", "random", "some", "codeExtension", "endsWith"]
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport * from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nexport * from './auth';\nexport * from './defs';\nexport * from './edge-client';\nexport * from './errors';\nexport * from './protocol';\nexport * from './edge-http-client';\nexport * from './edge-identity';\nexport * from './edge-ws-muxer';\nexport * from './http-client';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createCredential, signPresentation } from '@dxos/credentials';\nimport { type Signer } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { type Chain, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport type { EdgeIdentity } from './edge-identity';\n\n/**\n * Edge identity backed by a device key without a credential chain.\n */\nexport const createDeviceEdgeIdentity = async (signer: Signer, key: PublicKey): Promise<EdgeIdentity> => {\n return {\n identityKey: key.toHex(),\n peerKey: key.toHex(),\n presentCredentials: async ({ challenge }) => {\n return signPresentation({\n presentation: {\n credentials: [\n // Verifier requires at least one credential in the presentation to establish the subject.\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: key,\n subject: key,\n signer,\n }),\n ],\n },\n signer,\n signerKey: key,\n nonce: challenge,\n });\n },\n };\n};\n\n/**\n * Edge identity backed by a chain of credentials.\n */\nexport const createChainEdgeIdentity = async (\n signer: Signer,\n identityKey: PublicKey,\n peerKey: PublicKey,\n chain: Chain | undefined,\n credentials: Credential[],\n): Promise<EdgeIdentity> => {\n const credentialsToSign =\n credentials.length > 0\n ? credentials\n : [\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: identityKey,\n subject: identityKey,\n signer,\n chain,\n signingKey: peerKey,\n }),\n ];\n\n return {\n identityKey: identityKey.toHex(),\n peerKey: peerKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n // TODO: make chain required after device invitation flow update release\n invariant(chain);\n return signPresentation({\n presentation: {\n credentials: credentialsToSign,\n },\n signer,\n nonce: challenge,\n signerKey: peerKey,\n chain,\n });\n },\n };\n};\n\n/**\n * Edge identity backed by a random ephemeral key without HALO.\n */\nexport const createEphemeralEdgeIdentity = async (): Promise<EdgeIdentity> => {\n const keyring = new Keyring();\n const key = await keyring.createKey();\n return createDeviceEdgeIdentity(keyring, key);\n};\n\n/**\n * Creates a HALO chain of credentials to act as an edge identity.\n */\nexport const createTestHaloEdgeIdentity = async (\n signer: Signer,\n identityKey: PublicKey,\n deviceKey: PublicKey,\n): Promise<EdgeIdentity> => {\n const deviceAdmission = await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.AuthorizedDevice',\n deviceKey,\n identityKey,\n },\n issuer: identityKey,\n subject: deviceKey,\n signer,\n });\n return createChainEdgeIdentity(signer, identityKey, deviceKey, { credential: deviceAdmission }, [\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: identityKey,\n subject: identityKey,\n signer,\n }),\n ]);\n};\n\nexport const createStubEdgeIdentity = (): EdgeIdentity => {\n const identityKey = PublicKey.random();\n const deviceKey = PublicKey.random();\n return {\n identityKey: identityKey.toHex(),\n peerKey: deviceKey.toHex(),\n presentCredentials: async () => {\n throw new Error('Stub identity does not support authentication.');\n },\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport {\n Event,\n PersistentLifecycle,\n Trigger,\n TriggerState,\n scheduleMicroTask,\n scheduleTaskInterval,\n} from '@dxos/async';\nimport { type Lifecycle, Resource } from '@dxos/context';\nimport { log, logInfo } from '@dxos/log';\nimport { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';\n\nimport { protocol } from './defs';\nimport { type EdgeIdentity, handleAuthChallenge } from './edge-identity';\nimport { EdgeWsConnection } from './edge-ws-connection';\nimport { EdgeConnectionClosedError, EdgeIdentityChangedError } from './errors';\nimport { type Protocol } from './protocol';\nimport { getEdgeUrlWithProtocol } from './utils';\n\nconst DEFAULT_TIMEOUT = 10_000;\n\n// Refresh status every second: rtt, rate counters.\nconst STATUS_REFRESH_INTERVAL = 1000;\n\nexport type MessageListener = (message: Message) => void;\nexport type ReconnectListener = () => void;\n\nexport type MessengerConfig = {\n socketEndpoint: string;\n timeout?: number;\n protocol?: Protocol;\n disableAuth?: boolean;\n};\n\nexport interface EdgeConnection extends Required<Lifecycle> {\n statusChanged: Event<EdgeStatus>;\n get info(): any;\n get identityKey(): string;\n get peerKey(): string;\n get isOpen(): boolean;\n get status(): EdgeStatus;\n setIdentity(identity: EdgeIdentity): void;\n send(message: Message): Promise<void>;\n onMessage(listener: MessageListener): () => void;\n onReconnected(listener: ReconnectListener): () => void;\n}\n\n/**\n * Messenger client for EDGE:\n * - While open, uses PersistentLifecycle to keep an open EdgeWsConnection, reconnecting on failures.\n * - Manages identity and re-create EdgeWsConnection when identity changes.\n * - Dispatches connection state and message notifications.\n */\nexport class EdgeClient extends Resource implements EdgeConnection {\n public readonly statusChanged = new Event<EdgeStatus>();\n\n private readonly _persistentLifecycle = new PersistentLifecycle<EdgeWsConnection>({\n start: async () => this._connect(),\n stop: async (state: EdgeWsConnection) => this._disconnect(state),\n });\n\n private readonly _messageListeners = new Set<MessageListener>();\n private readonly _reconnectListeners = new Set<ReconnectListener>();\n private readonly _baseWsUrl: string;\n private readonly _baseHttpUrl: string;\n private _currentConnection?: EdgeWsConnection = undefined;\n private _ready = new Trigger();\n\n constructor(\n private _identity: EdgeIdentity,\n private readonly _config: MessengerConfig,\n ) {\n super();\n this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, 'ws');\n this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, 'http');\n }\n\n @logInfo\n public get info() {\n return {\n open: this.isOpen,\n status: this.status,\n identity: this._identity.identityKey,\n device: this._identity.peerKey,\n };\n }\n\n get status(): EdgeStatus {\n return {\n state:\n Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED\n ? EdgeStatus.ConnectionState.CONNECTED\n : EdgeStatus.ConnectionState.NOT_CONNECTED,\n uptime: this._currentConnection?.uptime ?? 0,\n rtt: this._currentConnection?.rtt ?? 0,\n rateBytesUp: this._currentConnection?.uploadRate ?? 0,\n rateBytesDown: this._currentConnection?.downloadRate ?? 0,\n messagesSent: this._currentConnection?.messagesSent ?? 0,\n messagesReceived: this._currentConnection?.messagesReceived ?? 0,\n };\n }\n\n get identityKey() {\n return this._identity.identityKey;\n }\n\n get peerKey() {\n return this._identity.peerKey;\n }\n\n setIdentity(identity: EdgeIdentity) {\n if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {\n log('Edge identity changed', { identity, oldIdentity: this._identity });\n this._identity = identity;\n this._closeCurrentConnection(new EdgeIdentityChangedError());\n void this._persistentLifecycle.scheduleRestart();\n }\n }\n\n /**\n * Send message.\n * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.\n */\n public async send(message: Message) {\n if (this._ready.state !== TriggerState.RESOLVED) {\n log('waiting for websocket');\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n }\n\n if (!this._currentConnection) {\n throw new EdgeConnectionClosedError();\n }\n\n if (\n message.source &&\n (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)\n ) {\n throw new EdgeIdentityChangedError();\n }\n\n this._currentConnection.send(message);\n }\n\n public onMessage(listener: MessageListener) {\n this._messageListeners.add(listener);\n return () => this._messageListeners.delete(listener);\n }\n\n public onReconnected(listener: () => void) {\n this._reconnectListeners.add(listener);\n if (this._ready.state === TriggerState.RESOLVED) {\n // Microtask so that listener is always called asynchronously, no matter the state of the ready trigger\n // at the moment of registration.\n scheduleMicroTask(this._ctx, () => {\n if (this._reconnectListeners.has(listener)) {\n try {\n listener();\n } catch (error) {\n log.catch(error);\n }\n }\n });\n }\n\n return () => this._reconnectListeners.delete(listener);\n }\n\n /**\n * Open connection to messaging service.\n */\n protected override async _open(): Promise<void> {\n log('opening...', { info: this.info });\n this._persistentLifecycle.open().catch((err) => {\n log.warn('Error while opening connection', { err });\n });\n\n // Notify about status changes (rtt, rate counters).\n scheduleTaskInterval(\n this._ctx,\n async () => {\n if (!this._currentConnection) {\n return;\n }\n this.statusChanged.emit(this.status);\n },\n STATUS_REFRESH_INTERVAL,\n );\n }\n\n /**\n * Close connection and free resources.\n */\n protected override async _close(): Promise<void> {\n log('closing...', { peerKey: this._identity.peerKey });\n this._closeCurrentConnection();\n await this._persistentLifecycle.close();\n }\n\n private async _connect(): Promise<EdgeWsConnection | undefined> {\n if (this._ctx.disposed) {\n return undefined;\n }\n\n const identity = this._identity;\n const path = `/ws/${identity.identityKey}/${identity.peerKey}`;\n const protocolHeader = this._config.disableAuth ? undefined : await this._createAuthHeader(path);\n if (this._identity !== identity) {\n log('identity changed during auth header request');\n return undefined;\n }\n\n const restartRequired = new Trigger();\n const url = new URL(path, this._baseWsUrl);\n log('Opening websocket', { url: url.toString(), protocolHeader });\n const connection = new EdgeWsConnection(\n identity,\n { url, protocolHeader },\n {\n onConnected: () => {\n if (this._isActive(connection)) {\n this._ready.wake();\n this._notifyReconnected();\n } else {\n log.verbose('connected callback ignored, because connection is not active');\n }\n },\n onRestartRequired: () => {\n if (this._isActive(connection)) {\n this._closeCurrentConnection();\n void this._persistentLifecycle.scheduleRestart();\n } else {\n log.verbose('restart requested by inactive connection');\n }\n restartRequired.wake();\n },\n onMessage: (message) => {\n if (this._isActive(connection)) {\n this._notifyMessageReceived(message);\n } else {\n log.verbose('ignored a message on inactive connection', {\n from: message.source,\n type: message.payload?.typeUrl,\n });\n }\n },\n },\n );\n this._currentConnection = connection;\n\n await connection.open();\n // Race with restartRequired so that restart is not blocked by _connect execution.\n // Wait on ready to attempt a reconnect if it times out.\n await Promise.race([this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT }), restartRequired]);\n return connection;\n }\n\n private async _disconnect(state: EdgeWsConnection): Promise<void> {\n await state.close();\n this.statusChanged.emit(this.status);\n }\n\n private _closeCurrentConnection(error: Error = new EdgeConnectionClosedError()): void {\n this._currentConnection = undefined;\n this._ready.throw(error);\n this._ready.reset();\n this.statusChanged.emit(this.status);\n }\n\n private _notifyReconnected(): void {\n this.statusChanged.emit(this.status);\n for (const listener of this._reconnectListeners) {\n try {\n listener();\n } catch (err) {\n log.error('ws reconnect listener failed', { err });\n }\n }\n }\n\n private _notifyMessageReceived(message: Message): void {\n for (const listener of this._messageListeners) {\n try {\n listener(message);\n } catch (err) {\n log.error('ws incoming message processing failed', { err, payload: protocol.getPayloadType(message) });\n }\n }\n }\n\n private async _createAuthHeader(path: string): Promise<string | undefined> {\n const httpUrl = new URL(path, this._baseHttpUrl);\n httpUrl.protocol = getEdgeUrlWithProtocol(this._baseWsUrl.toString(), 'http');\n const response = await fetch(httpUrl, { method: 'GET' });\n if (response.status === 401) {\n return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));\n } else {\n log.warn('no auth challenge from edge', { status: response.status, statusText: response.statusText });\n return undefined;\n }\n }\n\n private _isActive = (connection: EdgeWsConnection) => connection === this._currentConnection;\n}\n\nconst encodePresentationWsAuthHeader = (encodedPresentation: Uint8Array): string => {\n // '=' and '/' characters are not allowed in the WebSocket subprotocol header.\n const encodedToken = Buffer.from(encodedPresentation).toString('base64').replace(/=*$/, '').replaceAll('/', '|');\n return `base64url.bearer.authorization.dxos.org.${encodedToken}`;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Presentation } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nexport interface EdgeIdentity {\n peerKey: string;\n identityKey: string;\n /**\n * Returns credential presentation issued by the identity key.\n * Presentation must have the provided challenge.\n * Presentation may include ServiceAccess credentials.\n */\n presentCredentials({ challenge }: { challenge: Uint8Array }): Promise<Presentation>;\n}\n\nexport const handleAuthChallenge = async (failedResponse: Response, identity: EdgeIdentity): Promise<Uint8Array> => {\n invariant(failedResponse.status === 401);\n\n const headerValue = failedResponse.headers.get('Www-Authenticate');\n invariant(headerValue?.startsWith('VerifiablePresentation challenge='));\n\n const challenge = headerValue?.slice('VerifiablePresentation challenge='.length);\n invariant(challenge);\n\n const presentation = await identity.presentCredentials({ challenge: Buffer.from(challenge, 'base64') });\n return schema.getCodecForType('dxos.halo.credentials.Presentation').encode(presentation);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { scheduleTask, scheduleTaskInterval } from '@dxos/async';\nimport { Context, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log, logInfo } from '@dxos/log';\nimport { EdgeWebsocketProtocol } from '@dxos/protocols';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\nimport { type EdgeIdentity } from './edge-identity';\nimport { CLOUDFLARE_MESSAGE_MAX_BYTES, WebSocketMuxer } from './edge-ws-muxer';\nimport { toUint8Array } from './protocol';\n\nconst SIGNAL_KEEPALIVE_INTERVAL = 4_000;\nconst SIGNAL_KEEPALIVE_TIMEOUT = 12_000;\n\nexport type EdgeWsConnectionCallbacks = {\n onConnected: () => void;\n onMessage: (message: Message) => void;\n onRestartRequired: () => void;\n};\n\nexport class EdgeWsConnection extends Resource {\n private _inactivityTimeoutCtx: Context | undefined;\n private _ws: WebSocket | undefined;\n private _wsMuxer: WebSocketMuxer | undefined;\n private _lastReceivedMessageTimestamp = Date.now();\n\n private _openTimestamp: number | undefined;\n\n // Latency tracking.\n private _pingTimestamp: number | undefined;\n private _rtt = 0;\n\n // Rate tracking with sliding window.\n private _uploadRate = 0;\n private _downloadRate = 0;\n private readonly _rateWindow = 10000; // 10 second sliding window.\n private readonly _rateUpdateInterval = 1000; // Update rates every second.\n private _bytesSamples: Array<{ timestamp: number; sent: number; received: number }> = [];\n\n private _messagesSent = 0;\n private _messagesReceived = 0;\n\n constructor(\n private readonly _identity: EdgeIdentity,\n private readonly _connectionInfo: { url: URL; protocolHeader?: string },\n private readonly _callbacks: EdgeWsConnectionCallbacks,\n ) {\n super();\n }\n\n @logInfo\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identity.identityKey,\n device: this._identity.peerKey,\n };\n }\n\n public get rtt(): number {\n return this._rtt;\n }\n\n public get uptime(): number {\n return this._openTimestamp ? (Date.now() - this._openTimestamp) / 1000 : 0;\n }\n\n public get uploadRate(): number {\n return this._uploadRate;\n }\n\n public get downloadRate(): number {\n return this._downloadRate;\n }\n\n public get messagesSent(): number {\n return this._messagesSent;\n }\n\n public get messagesReceived(): number {\n return this._messagesReceived;\n }\n\n public send(message: Message): void {\n invariant(this._ws);\n invariant(this._wsMuxer);\n log('sending...', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });\n this._messagesSent++;\n if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {\n const binary = buf.toBinary(MessageSchema, message);\n if (binary.length > CLOUDFLARE_MESSAGE_MAX_BYTES) {\n log.error('Message dropped because it was too large (>1MB).', {\n byteLength: binary.byteLength,\n serviceId: message.serviceId,\n payload: protocol.getPayloadType(message),\n });\n return;\n }\n this._recordBytes(binary.byteLength, 0);\n this._ws.send(binary);\n } else {\n // For muxer, we need to track the size of the message being sent.\n const binary = buf.toBinary(MessageSchema, message);\n this._recordBytes(binary.byteLength, 0);\n this._wsMuxer.send(message).catch((e) => log.catch(e));\n }\n }\n\n protected override async _open(): Promise<void> {\n const baseProtocols = [...Object.values(EdgeWebsocketProtocol)];\n this._ws = new WebSocket(\n this._connectionInfo.url.toString(),\n this._connectionInfo.protocolHeader\n ? [...baseProtocols, this._connectionInfo.protocolHeader]\n : [...baseProtocols],\n );\n const muxer = new WebSocketMuxer(this._ws);\n this._wsMuxer = muxer;\n\n this._ws.onopen = () => {\n if (this.isOpen) {\n log('connected');\n this._openTimestamp = Date.now();\n this._callbacks.onConnected();\n this._scheduleHeartbeats();\n this._scheduleRateCalculation();\n } else {\n log.verbose('connected after becoming inactive', { currentIdentity: this._identity });\n }\n };\n this._ws.onclose = (event: WebSocket.CloseEvent) => {\n if (this.isOpen) {\n log.warn('server disconnected', { code: event.code, reason: event.reason });\n this._callbacks.onRestartRequired();\n muxer.destroy();\n }\n };\n this._ws.onerror = (event: WebSocket.ErrorEvent) => {\n if (this.isOpen) {\n log.warn('edge connection socket error', { error: event.error, info: event.message });\n this._callbacks.onRestartRequired();\n } else {\n log.verbose('error ignored on closed connection', { error: event.error });\n }\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event: WebSocket.MessageEvent) => {\n if (!this.isOpen) {\n log.verbose('message ignored on closed connection', { event: event.type });\n return;\n }\n this._lastReceivedMessageTimestamp = Date.now();\n if (event.data === '__pong__') {\n // Calculate latency.\n if (this._pingTimestamp) {\n this._rtt = Date.now() - this._pingTimestamp;\n this._pingTimestamp = undefined;\n }\n this._rescheduleHeartbeatTimeout();\n return;\n }\n const bytes = await toUint8Array(event.data);\n this._recordBytes(0, bytes.byteLength);\n if (!this.isOpen) {\n return;\n }\n\n this._messagesReceived++;\n\n const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0)\n ? buf.fromBinary(MessageSchema, bytes)\n : muxer.receiveData(bytes);\n\n if (message) {\n log('received', { from: message.source, payload: protocol.getPayloadType(message) });\n this._callbacks.onMessage(message);\n }\n };\n }\n\n protected override async _close(): Promise<void> {\n void this._inactivityTimeoutCtx?.dispose().catch(() => {});\n\n try {\n this._ws?.close();\n this._ws = undefined;\n this._wsMuxer?.destroy();\n this._wsMuxer = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('error closing websocket', { err });\n }\n }\n\n private _scheduleHeartbeats(): void {\n invariant(this._ws);\n scheduleTaskInterval(\n this._ctx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._pingTimestamp = Date.now();\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._pingTimestamp = Date.now();\n this._ws.send('__ping__');\n this._rescheduleHeartbeatTimeout();\n }\n\n private _rescheduleHeartbeatTimeout(): void {\n if (!this.isOpen) {\n return;\n }\n void this._inactivityTimeoutCtx?.dispose();\n this._inactivityTimeoutCtx = new Context();\n scheduleTask(\n this._inactivityTimeoutCtx,\n () => {\n if (this.isOpen) {\n if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {\n log.warn('restart due to inactivity timeout', {\n lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp,\n });\n this._callbacks.onRestartRequired();\n } else {\n this._rescheduleHeartbeatTimeout();\n }\n }\n },\n SIGNAL_KEEPALIVE_TIMEOUT,\n );\n }\n\n private _recordBytes(sent: number, received: number): void {\n const now = Date.now();\n\n // Find if we have a sample for the current second.\n const currentSecond = Math.floor(now / 1000) * 1000;\n const existingSample = this._bytesSamples.find((s) => Math.floor(s.timestamp / 1000) * 1000 === currentSecond);\n\n if (existingSample) {\n existingSample.sent += sent;\n existingSample.received += received;\n } else {\n this._bytesSamples.push({ timestamp: now, sent, received });\n }\n }\n\n private _scheduleRateCalculation(): void {\n scheduleTaskInterval(\n this._ctx,\n async () => {\n this._calculateRates();\n },\n this._rateUpdateInterval,\n );\n // Calculate initial rates.\n this._calculateRates();\n }\n\n private _calculateRates(): void {\n const now = Date.now();\n const cutoff = now - this._rateWindow;\n\n // Remove old samples.\n this._bytesSamples = this._bytesSamples.filter((s) => s.timestamp > cutoff);\n\n if (this._bytesSamples.length === 0) {\n this._uploadRate = 0;\n this._downloadRate = 0;\n return;\n }\n\n // Calculate total bytes and time span.\n let totalSent = 0;\n let totalReceived = 0;\n const oldestTimestamp = Math.min(...this._bytesSamples.map((s) => s.timestamp));\n const timeSpan = (now - oldestTimestamp) / 1000; // Convert to seconds.\n\n for (const sample of this._bytesSamples) {\n totalSent += sample.sent;\n totalReceived += sample.received;\n }\n\n // Calculate rates (bytes per second).\n this._uploadRate = timeSpan > 0 ? Math.round(totalSent / timeSpan) : 0;\n this._downloadRate = timeSpan > 0 ? Math.round(totalReceived / timeSpan) : 0;\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport class EdgeConnectionClosedError extends Error {\n constructor() {\n super('Edge connection closed.');\n }\n}\n\nexport class EdgeIdentityChangedError extends Error {\n constructor() {\n super('Edge identity changed.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport const getEdgeUrlWithProtocol = (baseUrl: string, protocol: 'http' | 'ws') => {\n const isSecure = baseUrl.startsWith('https') || baseUrl.startsWith('wss');\n const url = new URL(baseUrl);\n url.protocol = protocol + (isSecure ? 's' : '');\n return url.toString();\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as FetchHttpClient from '@effect/platform/FetchHttpClient';\nimport * as HttpClient from '@effect/platform/HttpClient';\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\n\nimport { sleep } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey, type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport {\n type CreateAgentRequestBody,\n type CreateAgentResponseBody,\n type CreateSpaceRequest,\n type CreateSpaceResponseBody,\n EdgeAuthChallengeError,\n EdgeCallFailedError,\n type EdgeFailure,\n type EdgeStatus,\n type ExecuteWorkflowResponseBody,\n type ExportBundleRequest,\n type ExportBundleResponse,\n type GetAgentStatusResponseBody,\n type GetNotarizationResponseBody,\n type ImportBundleRequest,\n type InitiateOAuthFlowRequest,\n type InitiateOAuthFlowResponse,\n type JoinSpaceRequest,\n type JoinSpaceResponseBody,\n type ObjectId,\n type PostNotarizationRequestBody,\n type QueryResult,\n type QueueQuery,\n type RecoverIdentityRequest,\n type RecoverIdentityResponseBody,\n type UploadFunctionRequest,\n type UploadFunctionResponseBody,\n} from '@dxos/protocols';\nimport { createUrl } from '@dxos/util';\n\nimport { type EdgeIdentity, handleAuthChallenge } from './edge-identity';\nimport { HttpConfig, encodeAuthHeader, withLogging, withRetryConfig } from './http-client';\nimport { getEdgeUrlWithProtocol } from './utils';\n\nconst DEFAULT_RETRY_TIMEOUT = 1500;\nconst DEFAULT_RETRY_JITTER = 500;\nconst DEFAULT_MAX_RETRIES_COUNT = 3;\nconst WARNING_BODY_SIZE = 10 * 1024 * 1024; // 10MB\n\nexport type RetryConfig = {\n /**\n * A number of call retries, not counting the initial request.\n */\n count: number;\n /**\n * Delay before retries in ms.\n */\n timeout?: number;\n /**\n * A random amount of time before retrying to help prevent large bursts of requests.\n */\n jitter?: number;\n};\n\ntype EdgeHttpRequestArgs = {\n method: string;\n context?: Context;\n retry?: RetryConfig;\n body?: any;\n /**\n * @default true\n */\n json?: boolean;\n\n /**\n * Force authentication.\n * This should be used for requests with large bodies to avoid sending the body twice.\n * The client will call /auth endpoint to generate the auth header.\n */\n auth?: boolean;\n};\n\nexport type EdgeHttpGetArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'auth'>;\nexport type EdgeHttpPostArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'body' | 'auth'>;\n\nexport class EdgeHttpClient {\n private readonly _baseUrl: string;\n\n private _edgeIdentity: EdgeIdentity | undefined;\n\n /**\n * Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.\n */\n private _authHeader: string | undefined;\n\n constructor(baseUrl: string) {\n this._baseUrl = getEdgeUrlWithProtocol(baseUrl, 'http');\n log('created', { url: this._baseUrl });\n }\n\n get baseUrl() {\n return this._baseUrl;\n }\n\n setIdentity(identity: EdgeIdentity): void {\n if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {\n this._edgeIdentity = identity;\n this._authHeader = undefined;\n }\n }\n\n //\n // Status\n //\n\n public async getStatus(args?: EdgeHttpGetArgs): Promise<EdgeStatus> {\n return this._call(new URL('/status', this.baseUrl), { ...args, method: 'GET' });\n }\n\n //\n // Agents\n //\n\n public createAgent(body: CreateAgentRequestBody, args?: EdgeHttpGetArgs): Promise<CreateAgentResponseBody> {\n return this._call(new URL('/agents/create', this.baseUrl), { ...args, method: 'POST', body });\n }\n\n public getAgentStatus(\n request: { ownerIdentityKey: PublicKey },\n args?: EdgeHttpGetArgs,\n ): Promise<GetAgentStatusResponseBody> {\n return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {\n ...args,\n method: 'GET',\n });\n }\n\n //\n // Credentials\n //\n\n public getCredentialsForNotarization(spaceId: SpaceId, args?: EdgeHttpGetArgs): Promise<GetNotarizationResponseBody> {\n return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, method: 'GET' });\n }\n\n public async notarizeCredentials(\n spaceId: SpaceId,\n body: PostNotarizationRequestBody,\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Identity\n //\n\n public async recoverIdentity(\n body: RecoverIdentityRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<RecoverIdentityResponseBody> {\n return this._call(new URL('/identity/recover', this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Invitations\n //\n\n public async joinSpaceByInvitation(\n spaceId: SpaceId,\n body: JoinSpaceRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<JoinSpaceResponseBody> {\n return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // OAuth and credentials\n //\n\n public async initiateOAuthFlow(\n body: InitiateOAuthFlowRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<InitiateOAuthFlowResponse> {\n return this._call(new URL('/oauth/initiate', this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Spaces\n //\n\n async createSpace(body: CreateSpaceRequest, args?: EdgeHttpGetArgs): Promise<CreateSpaceResponseBody> {\n return this._call(new URL('/spaces/create', this.baseUrl), { ...args, body, method: 'POST' });\n }\n\n //\n // Queues\n //\n\n public async queryQueue(\n subspaceTag: string,\n spaceId: SpaceId,\n query: QueueQuery,\n args?: EdgeHttpGetArgs,\n ): Promise<QueryResult> {\n const { queueId } = query;\n return this._call(\n createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {\n after: query.after,\n before: query.before,\n limit: query.limit,\n reverse: query.reverse,\n objectIds: query.objectIds?.join(','),\n }),\n {\n ...args,\n method: 'GET',\n },\n );\n }\n\n public async insertIntoQueue(\n subspaceTag: string,\n spaceId: SpaceId,\n queueId: ObjectId,\n objects: unknown[],\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {\n ...args,\n body: { objects },\n method: 'POST',\n });\n }\n\n public async deleteFromQueue(\n subspaceTag: string,\n spaceId: SpaceId,\n queueId: ObjectId,\n objectIds: ObjectId[],\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n return this._call(\n createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {\n ids: objectIds.join(','),\n }),\n {\n ...args,\n method: 'DELETE',\n },\n );\n }\n\n //\n // Functions\n //\n\n public async uploadFunction(\n pathParts: { functionId?: string },\n body: UploadFunctionRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<UploadFunctionResponseBody> {\n const formData = new FormData();\n formData.append('name', body.name ?? '');\n formData.append('version', body.version);\n formData.append('ownerPublicKey', body.ownerPublicKey);\n formData.append('entryPoint', body.entryPoint);\n body.runtime && formData.append('runtime', body.runtime);\n for (const [filename, content] of Object.entries(body.assets)) {\n formData.append(\n 'assets',\n new Blob([content as Uint8Array<ArrayBuffer>], { type: getFileMimeType(filename) }),\n filename,\n );\n }\n\n const path = ['functions', ...(pathParts.functionId ? [pathParts.functionId] : [])].join('/');\n return this._call(new URL(path, this.baseUrl), {\n ...args,\n body: formData,\n method: 'PUT',\n json: false,\n });\n }\n\n public async listFunctions(args?: EdgeHttpGetArgs): Promise<any> {\n return this._call(new URL('/functions', this.baseUrl), { ...args, method: 'GET' });\n }\n\n public async invokeFunction(\n params: {\n functionId: string;\n version?: string;\n spaceId?: SpaceId;\n cpuTimeLimit?: number;\n subrequestsLimit?: number;\n },\n input: unknown,\n args?: EdgeHttpGetArgs,\n ): Promise<any> {\n const url = new URL(`/functions/${params.functionId}`, this.baseUrl);\n if (params.version) {\n url.searchParams.set('version', params.version);\n }\n if (params.spaceId) {\n url.searchParams.set('spaceId', params.spaceId.toString());\n }\n if (params.cpuTimeLimit) {\n url.searchParams.set('cpuTimeLimit', params.cpuTimeLimit.toString());\n }\n if (params.subrequestsLimit) {\n url.searchParams.set('subrequestsLimit', params.subrequestsLimit.toString());\n }\n\n return this._call(url, {\n ...args,\n body: input,\n method: 'POST',\n });\n }\n\n //\n // Workflows\n //\n\n public async executeWorkflow(\n spaceId: SpaceId,\n graphId: ObjectId,\n input: any,\n args?: EdgeHttpGetArgs,\n ): Promise<ExecuteWorkflowResponseBody> {\n return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {\n ...args,\n body: input,\n method: 'POST',\n });\n }\n\n //\n // Triggers\n //\n\n public async getCronTriggers(spaceId: SpaceId) {\n return this._call(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), { method: 'GET' });\n }\n\n public async forceRunCronTrigger(spaceId: SpaceId, triggerId: ObjectId) {\n return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {\n method: 'POST',\n });\n }\n\n //\n // Import/Export space.\n //\n\n public async importBundle(\n spaceId: SpaceId, //\n body: ImportBundleRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), { ...args, body, method: 'PUT' });\n }\n\n public async exportBundle(\n spaceId: SpaceId,\n body: ExportBundleRequest,\n args?: EdgeHttpGetArgs,\n ): Promise<ExportBundleResponse> {\n return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {\n ...args,\n body,\n method: 'POST',\n });\n }\n\n //\n // Internal\n //\n\n private async _fetch<T>(url: URL, _args: EdgeHttpRequestArgs): Promise<T> {\n return Function.pipe(\n HttpClient.get(url),\n withLogging,\n withRetryConfig,\n Effect.provide(FetchHttpClient.layer),\n Effect.provide(HttpConfig.default),\n Effect.withSpan('EdgeHttpClient'),\n Effect.runPromise,\n ) as T;\n }\n\n // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).\n private async _call<T>(url: URL, args: EdgeHttpRequestArgs): Promise<T> {\n const shouldRetry = createRetryHandler(args);\n const requestContext = args.context ?? Context.default();\n log('fetch', { url, request: args.body });\n\n let handledAuth = false;\n const tryCount = 1;\n while (true) {\n let processingError: EdgeCallFailedError | undefined = undefined;\n try {\n if (!this._authHeader && args.auth) {\n const response = await fetch(new URL(`/auth`, this.baseUrl));\n if (response.status === 401) {\n this._authHeader = await this._handleUnauthorized(response);\n }\n }\n\n const request = createRequest(args, this._authHeader);\n log('call edge', { url, tryCount, authHeader: !!this._authHeader });\n const response = await fetch(url, request);\n\n if (response.ok) {\n const body = await response.clone().json();\n invariant(body, 'Expected body to be present');\n if (!('success' in body)) {\n return body;\n }\n if (body.success) {\n return body.data;\n }\n } else if (response.status === 401 && !handledAuth) {\n this._authHeader = await this._handleUnauthorized(response);\n handledAuth = true;\n continue;\n }\n\n const body: EdgeFailure =\n response.headers.get('Content-Type') === 'application/json' ? await response.clone().json() : undefined;\n\n invariant(!body?.success, 'Expected body to not be a failure response or undefined.');\n\n if (body?.data?.type === 'auth_challenge' && typeof body?.data?.challenge === 'string') {\n processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);\n } else if (body?.success === false) {\n processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);\n } else {\n invariant(!response.ok, 'Expected response to not be ok.');\n processingError = await EdgeCallFailedError.fromHttpFailure(response);\n }\n } catch (error: any) {\n processingError = EdgeCallFailedError.fromProcessingFailureCause(error);\n }\n\n if (processingError?.isRetryable && (await shouldRetry(requestContext, processingError.retryAfterMs))) {\n log.verbose('retrying edge request', { url, processingError });\n } else {\n throw processingError!;\n }\n }\n }\n\n private async _handleUnauthorized(response: Response): Promise<string> {\n if (!this._edgeIdentity) {\n log.warn('unauthorized response received before identity was set');\n throw await EdgeCallFailedError.fromHttpFailure(response);\n }\n\n const challenge = await handleAuthChallenge(response, this._edgeIdentity);\n return encodeAuthHeader(challenge);\n }\n}\n\nconst createRequest = (\n { method, body, json = true }: EdgeHttpRequestArgs,\n authHeader: string | undefined,\n): RequestInit => {\n let requestBody: BodyInit | undefined;\n const headers: HeadersInit = {};\n\n if (json) {\n requestBody = body && JSON.stringify(body);\n headers['Content-Type'] = 'application/json';\n } else {\n requestBody = body;\n }\n\n if (typeof requestBody === 'string' && requestBody.length > WARNING_BODY_SIZE) {\n log.warn('Request with large body', { bodySize: requestBody.length });\n }\n\n if (authHeader) {\n headers['Authorization'] = authHeader;\n }\n\n return {\n method,\n body: requestBody,\n headers,\n };\n};\n\n/**\n * @deprecated\n */\nconst createRetryHandler = ({ retry }: EdgeHttpRequestArgs) => {\n if (!retry || retry.count < 1) {\n return async () => false;\n }\n\n let retries = 0;\n const maxRetries = retry.count ?? DEFAULT_MAX_RETRIES_COUNT;\n const baseTimeout = retry.timeout ?? DEFAULT_RETRY_TIMEOUT;\n const jitter = retry.jitter ?? DEFAULT_RETRY_JITTER;\n return async (ctx: Context, retryAfter?: number) => {\n if (++retries > maxRetries || ctx.disposed) {\n return false;\n }\n\n if (retryAfter) {\n await sleep(retryAfter);\n } else {\n const timeout = baseTimeout + Math.random() * jitter;\n await sleep(timeout);\n }\n\n return true;\n };\n};\n\nconst getFileMimeType = (filename: string) =>\n ['.js', '.mjs'].some((codeExtension) => filename.endsWith(codeExtension))\n ? 'application/javascript+module'\n : filename.endsWith('.wasm')\n ? 'application/wasm'\n : 'application/octet-stream';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as HttpClient from '@effect/platform/HttpClient';\nimport type * as HttpClientError from '@effect/platform/HttpClientError';\nimport type * as HttpClientResponse from '@effect/platform/HttpClientResponse';\nimport * as Context from 'effect/Context';\nimport * as Duration from 'effect/Duration';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Schedule from 'effect/Schedule';\n\nimport { log } from '@dxos/log';\n\n// TODO(burdon): Factor out.\n\nexport type RetryOptions = {\n timeout: Duration.Duration;\n retryTimes: number;\n retryBaseDelay: Duration.Duration;\n};\n\n// Layer pattern.\nexport class HttpConfig extends Context.Tag('HttpConfig')<HttpConfig, RetryOptions>() {\n static default = Layer.succeed(HttpConfig, {\n timeout: Duration.millis(1_000),\n retryTimes: 3,\n retryBaseDelay: Duration.millis(1_000),\n });\n}\n\n// HOC pattern.\nexport const withRetry = (\n effect: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError, HttpClient.HttpClient>,\n {\n timeout = Duration.millis(1_000),\n retryBaseDelay = Duration.millis(1_000),\n retryTimes = 3,\n }: Partial<RetryOptions> = {},\n) => {\n return effect.pipe(\n Effect.flatMap((res) =>\n // Treat 500 errors as retryable?\n res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json,\n ),\n Effect.timeout(timeout),\n Effect.retry({\n schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),\n times: retryTimes,\n }),\n );\n};\n\nexport const withRetryConfig = (\n effect: Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError, HttpClient.HttpClient>,\n) =>\n Effect.gen(function* () {\n const config = yield* HttpConfig;\n return yield* withRetry(effect, config);\n });\n\nexport const withLogging = <A extends HttpClientResponse.HttpClientResponse, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.tap((res) => {\n log.info('response', { status: res.status });\n }),\n );\n\n/**\n *\n */\n// TODO(burdon): Document.\nexport const encodeAuthHeader = (challenge: Uint8Array) => {\n const encodedChallenge = Buffer.from(challenge).toString('base64');\n return `VerifiablePresentation pb;base64,${encodedChallenge}`;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;AAIA,cAAc;;;ACAd,SAASA,kBAAkBC,wBAAwB;AAEnD,SAASC,iBAAiB;AAC1B,SAASC,eAAe;AACxB,SAASC,iBAA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AAM,IAAKN;AAC9C,YAAMI,MAAML,QAAAA;IACd;AAEA,WAAO;EACT;AACF;AAEA,IAAM5E,kBAAkB,CAACP,aACvB;EAAC;EAAO;EAAQ2F,KAAK,CAACC,kBAAkB5F,SAAS6F,SAASD,aAAAA,CAAAA,IACtD,kCACA5F,SAAS6F,SAAS,OAAA,IAChB,qBACA;",
6
+ "names": ["createCredential", "signPresentation", "invariant", "Keyring", "PublicKey", "createDeviceEdgeIdentity", "signer", "key", "identityKey", "toHex", "peerKey", "presentCredentials", "challenge", "presentation", "credentials", "assertion", "issuer", "subject", "signerKey", "nonce", "createChainEdgeIdentity", "chain", "credentialsToSign", "length", "signingKey", "createEphemeralEdgeIdentity", "keyring", "createKey", "createTestHaloEdgeIdentity", "deviceKey", "deviceAdmission", "credential", "createStubEdgeIdentity", "random", "Error", "Event", "PersistentLifecycle", "Trigger", "TriggerState", "scheduleMicroTask", "scheduleTaskInterval", "Resource", "log", "logInfo", "EdgeStatus", "invariant", "schema", "handleAuthChallenge", "failedResponse", "identity", "status", "headerValue", "headers", "get", "startsWith", "challenge", "slice", "length", "presentation", "presentCredentials", "Buffer", "from", "getCodecForType", "encode", "WebSocket", "scheduleTask", "scheduleTaskInterval", "Context", "Resource", "invariant", "log", "logInfo", "EdgeWebsocketProtocol", "buf", "MessageSchema", "SIGNAL_KEEPALIVE_INTERVAL", "SIGNAL_KEEPALIVE_TIMEOUT", "EdgeWsConnection", "Resource", "_inactivityTimeoutCtx", "_ws", "_wsMuxer", "_lastReceivedMessageTimestamp", "Date", "now", "_openTimestamp", "_pingTimestamp", "_rtt", "_uploadRate", "_downloadRate", "_rateWindow", "_rateUpdateInterval", "_bytesSamples", "_messagesSent", "_messagesReceived", "_identity", "_connectionInfo", "_callbacks", "info", "open", "isOpen", "identity", "identityKey", "device", "peerKey", "rtt", "uptime", "uploadRate", "downloadRate", "messagesSent", "messagesReceived", "send", "message", "invariant", "log", "payload", "protocol", "getPayloadType", "includes", "EdgeWebsocketProtocol", "V0", "binary", "buf", "toBinary", "MessageSchema", "length", "CLOUDFLARE_MESSAGE_MAX_BYTES", "error", "byteLength", "serviceId", "_recordBytes", "catch", "e", "_open", "baseProtocols", "Object", "values", "WebSocket", "url", "toString", "protocolHeader", "muxer", "WebSocketMuxer", "onopen", "onConnected", "_scheduleHeartbeats", "_scheduleRateCalculation", "verbose", "currentIdentity", "onclose", "event", "warn", "code", "reason", "onRestartRequired", "destroy", "onerror", "onmessage", "type", "data", "undefined", "_rescheduleHeartbeatTimeout", "bytes", "toUint8Array", "fromBinary", "receiveData", "from", "source", "onMessage", "_close", "dispose", "close", "err", "Error", "scheduleTaskInterval", "_ctx", "Context", "scheduleTask", "lastReceivedMessageTimestamp", "sent", "received", "currentSecond", "Math", "floor", "existingSample", "find", "s", "timestamp", "push", "_calculateRates", "cutoff", "filter", "totalSent", "totalReceived", "oldestTimestamp", "min", "map", "timeSpan", "sample", "round", "EdgeConnectionClosedError", "Error", "EdgeIdentityChangedError", "getEdgeUrlWithProtocol", "baseUrl", "protocol", "isSecure", "startsWith", "url", "URL", "toString", "DEFAULT_TIMEOUT", "STATUS_REFRESH_INTERVAL", "EdgeClient", "Resource", "statusChanged", "Event", "_persistentLifecycle", "PersistentLifecycle", "start", "_connect", "stop", "state", "_disconnect", "_messageListeners", "Set", "_reconnectListeners", "_baseWsUrl", "_baseHttpUrl", "_currentConnection", "undefined", "_ready", "Trigger", "_identity", "_config", "getEdgeUrlWithProtocol", "socketEndpoint", "info", "open", "isOpen", "status", "identity", "identityKey", "device", "peerKey", "Boolean", "TriggerState", "RESOLVED", "EdgeStatus", "ConnectionState", "CONNECTED", "NOT_CONNECTED", "uptime", "rtt", "rateBytesUp", "uploadRate", "rateBytesDown", "downloadRate", "messagesSent", "messagesReceived", "setIdentity", "log", "oldIdentity", "_closeCurrentConnection", "EdgeIdentityChangedError", "scheduleRestart", "send", "message", "wait", "timeout", "EdgeConnectionClosedError", "source", "onMessage", "listener", "add", "delete", "onReconnected", "scheduleMicroTask", "_ctx", "has", "error", "catch", "_open", "err", "warn", "scheduleTaskInterval", "emit", "_close", "close", "disposed", "path", "protocolHeader", "disableAuth", "_createAuthHeader", "restartRequired", "url", "URL", "toString", "connection", "EdgeWsConnection", "onConnected", "_isActive", "wake", "_notifyReconnected", "verbose", "onRestartRequired", "_notifyMessageReceived", "from", "type", "payload", "typeUrl", "Promise", "race", "throw", "reset", "protocol", "getPayloadType", "httpUrl", "response", "fetch", "method", "encodePresentationWsAuthHeader", "handleAuthChallenge", "statusText", "encodedPresentation", "encodedToken", "Buffer", "replace", "replaceAll", "FetchHttpClient", "HttpClient", "Effect", "Function", "sleep", "Context", "invariant", "log", "EdgeAuthChallengeError", "EdgeCallFailedError", "createUrl", "Context", "Duration", "Effect", "Layer", "Schedule", "log", "HttpConfig", "Tag", "default", "succeed", "timeout", "millis", "retryTimes", "retryBaseDelay", "withRetry", "effect", "pipe", "flatMap", "res", "status", "fail", "Error", "toString", "json", "retry", "schedule", "exponential", "jittered", "times", "withRetryConfig", "gen", "config", "withLogging", "tap", "info", "encodeAuthHeader", "challenge", "encodedChallenge", "Buffer", "from", "DEFAULT_RETRY_TIMEOUT", "DEFAULT_RETRY_JITTER", "DEFAULT_MAX_RETRIES_COUNT", "WARNING_BODY_SIZE", "EdgeHttpClient", "_baseUrl", "_edgeIdentity", "_authHeader", "baseUrl", "getEdgeUrlWithProtocol", "log", "url", "setIdentity", "identity", "identityKey", "peerKey", "undefined", "getStatus", "args", "_call", "URL", "method", "createAgent", "body", "getAgentStatus", "request", "ownerIdentityKey", "toHex", "getCredentialsForNotarization", "spaceId", "notarizeCredentials", "recoverIdentity", "joinSpaceByInvitation", "initiateOAuthFlow", "createSpace", "queryQueue", "subspaceTag", "query", "queueId", "createUrl", "after", "before", "limit", "reverse", "objectIds", "join", "insertIntoQueue", "objects", "deleteFromQueue", "ids", "uploadFunction", "pathParts", "formData", "FormData", "append", "name", "version", "ownerPublicKey", "entryPoint", "runtime", "filename", "content", "Object", "entries", "assets", "Blob", "type", "getFileMimeType", "path", "functionId", "json", "listFunctions", "invokeFunction", "params", "input", "searchParams", "set", "toString", "cpuTimeLimit", "subrequestsLimit", "executeWorkflow", "graphId", "getCronTriggers", "forceRunCronTrigger", "triggerId", "importBundle", "exportBundle", "_fetch", "_args", "pipe", "get", "withLogging", "withRetryConfig", "provide", "layer", "HttpConfig", "default", "withSpan", "runPromise", "shouldRetry", "createRetryHandler", "requestContext", "context", "Context", "handledAuth", "tryCount", "processingError", "auth", "response", "fetch", "status", "_handleUnauthorized", "createRequest", "authHeader", "ok", "clone", "invariant", "success", "data", "headers", "challenge", "EdgeAuthChallengeError", "EdgeCallFailedError", "fromUnsuccessfulResponse", "fromHttpFailure", "error", "fromProcessingFailureCause", "isRetryable", "retryAfterMs", "verbose", "warn", "handleAuthChallenge", "encodeAuthHeader", "requestBody", "JSON", "stringify", "length", "bodySize", "retry", "count", "retries", "maxRetries", "baseTimeout", "timeout", "jitter", "ctx", "retryAfter", "disposed", "sleep", "Math", "random", "some", "codeExtension", "endsWith"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/protocol.ts":{"bytes":10133,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defs.ts":{"bytes":1550,"imports":[{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"src/edge-ws-muxer.ts":{"bytes":23993,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"}],"format":"esm"},"src/auth.ts":{"bytes":12117,"imports":[{"path":"@dxos/credentials","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"src/edge-identity.ts":{"bytes":3976,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true}],"format":"esm"},"src/edge-ws-connection.ts":{"bytes":37349,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"./edge-ws-muxer"},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"src/errors.ts":{"bytes":1188,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":1398,"imports":[],"format":"esm"},"src/edge-client.ts":{"bytes":37723,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/edge-ws-connection.ts","kind":"import-statement","original":"./edge-ws-connection"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/http-client.ts":{"bytes":7286,"imports":[{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/edge-http-client.ts":{"bytes":50966,"imports":[{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/http-client.ts","kind":"import-statement","original":"./http-client"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/index.ts":{"bytes":1375,"imports":[{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/auth.ts","kind":"import-statement","original":"./auth"},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-client.ts","kind":"import-statement","original":"./edge-client"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"},{"path":"src/edge-http-client.ts","kind":"import-statement","original":"./edge-http-client"},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"./edge-ws-muxer"},{"path":"src/http-client.ts","kind":"import-statement","original":"./http-client"}],"format":"esm"},"src/testing/test-server.ts":{"bytes":4545,"imports":[{"path":"@dxos/node-std/http","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/testing/test-utils.ts":{"bytes":14017,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"../defs"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"../edge-ws-muxer"},{"path":"src/protocol.ts","kind":"import-statement","original":"../protocol"}],"format":"esm"},"src/testing/index.ts":{"bytes":570,"imports":[{"path":"src/testing/test-server.ts","kind":"import-statement","original":"./test-server"},{"path":"src/testing/test-utils.ts","kind":"import-statement","original":"./test-utils"}],"format":"esm"}},"outputs":{"dist/lib/browser/edge-ws-muxer.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/browser/edge-ws-muxer.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","WebSocketMuxer"],"entryPoint":"src/edge-ws-muxer.ts","inputs":{},"bytes":249},"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":73632},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/credentials","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","EdgeClient","EdgeConnectionClosedError","EdgeHttpClient","EdgeIdentityChangedError","HttpConfig","Protocol","WebSocketMuxer","createChainEdgeIdentity","createDeviceEdgeIdentity","createEphemeralEdgeIdentity","createStubEdgeIdentity","createTestHaloEdgeIdentity","encodeAuthHeader","getTypename","handleAuthChallenge","protocol","toUint8Array","withLogging","withRetry","withRetryConfig"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":60},"src/auth.ts":{"bytesInOutput":2963},"src/edge-client.ts":{"bytesInOutput":10071},"src/edge-identity.ts":{"bytesInOutput":1158},"src/edge-ws-connection.ts":{"bytesInOutput":10215},"src/errors.ts":{"bytesInOutput":232},"src/utils.ts":{"bytesInOutput":244},"src/edge-http-client.ts":{"bytesInOutput":12338},"src/http-client.ts":{"bytesInOutput":1552}},"bytes":39767},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9559},"dist/lib/browser/testing/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"},{"path":"@dxos/node-std/http","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true}],"exports":["DEFAULT_PORT","createTestEdgeWsServer","createTestServer","responseHandler"],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/test-server.ts":{"bytesInOutput":1151},"src/testing/index.ts":{"bytesInOutput":0},"src/testing/test-utils.ts":{"bytesInOutput":3678}},"bytes":5103},"dist/lib/browser/chunk-VESGVCLQ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17259},"dist/lib/browser/chunk-VESGVCLQ.mjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","Protocol","WebSocketMuxer","getTypename","protocol","toUint8Array"],"inputs":{"src/edge-ws-muxer.ts":{"bytesInOutput":5688},"src/defs.ts":{"bytesInOutput":298},"src/protocol.ts":{"bytesInOutput":2604}},"bytes":8880}}}
1
+ {"inputs":{"src/protocol.ts":{"bytes":10133,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defs.ts":{"bytes":1550,"imports":[{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"src/edge-ws-muxer.ts":{"bytes":23993,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"}],"format":"esm"},"src/auth.ts":{"bytes":12117,"imports":[{"path":"@dxos/credentials","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"src/edge-identity.ts":{"bytes":3976,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true}],"format":"esm"},"src/edge-ws-connection.ts":{"bytes":37349,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"./edge-ws-muxer"},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"src/errors.ts":{"bytes":1188,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":1398,"imports":[],"format":"esm"},"src/edge-client.ts":{"bytes":37723,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/edge-ws-connection.ts","kind":"import-statement","original":"./edge-ws-connection"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/http-client.ts":{"bytes":7286,"imports":[{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/edge-http-client.ts":{"bytes":51170,"imports":[{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/http-client.ts","kind":"import-statement","original":"./http-client"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/index.ts":{"bytes":1375,"imports":[{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/auth.ts","kind":"import-statement","original":"./auth"},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-client.ts","kind":"import-statement","original":"./edge-client"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"},{"path":"src/edge-http-client.ts","kind":"import-statement","original":"./edge-http-client"},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"./edge-ws-muxer"},{"path":"src/http-client.ts","kind":"import-statement","original":"./http-client"}],"format":"esm"},"src/testing/test-server.ts":{"bytes":4545,"imports":[{"path":"@dxos/node-std/http","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/testing/test-utils.ts":{"bytes":14017,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"../defs"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"../edge-ws-muxer"},{"path":"src/protocol.ts","kind":"import-statement","original":"../protocol"}],"format":"esm"},"src/testing/index.ts":{"bytes":570,"imports":[{"path":"src/testing/test-server.ts","kind":"import-statement","original":"./test-server"},{"path":"src/testing/test-utils.ts","kind":"import-statement","original":"./test-utils"}],"format":"esm"}},"outputs":{"dist/lib/browser/edge-ws-muxer.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/browser/edge-ws-muxer.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","WebSocketMuxer"],"entryPoint":"src/edge-ws-muxer.ts","inputs":{},"bytes":249},"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":73707},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/credentials","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","EdgeClient","EdgeConnectionClosedError","EdgeHttpClient","EdgeIdentityChangedError","HttpConfig","Protocol","WebSocketMuxer","createChainEdgeIdentity","createDeviceEdgeIdentity","createEphemeralEdgeIdentity","createStubEdgeIdentity","createTestHaloEdgeIdentity","encodeAuthHeader","getTypename","handleAuthChallenge","protocol","toUint8Array","withLogging","withRetry","withRetryConfig"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":60},"src/auth.ts":{"bytesInOutput":2963},"src/edge-client.ts":{"bytesInOutput":10071},"src/edge-identity.ts":{"bytesInOutput":1158},"src/edge-ws-connection.ts":{"bytesInOutput":10215},"src/errors.ts":{"bytesInOutput":232},"src/utils.ts":{"bytesInOutput":244},"src/edge-http-client.ts":{"bytesInOutput":12413},"src/http-client.ts":{"bytesInOutput":1552}},"bytes":39842},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9559},"dist/lib/browser/testing/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"},{"path":"@dxos/node-std/http","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true}],"exports":["DEFAULT_PORT","createTestEdgeWsServer","createTestServer","responseHandler"],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/test-server.ts":{"bytesInOutput":1151},"src/testing/index.ts":{"bytesInOutput":0},"src/testing/test-utils.ts":{"bytesInOutput":3678}},"bytes":5103},"dist/lib/browser/chunk-VESGVCLQ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17259},"dist/lib/browser/chunk-VESGVCLQ.mjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","Protocol","WebSocketMuxer","getTypename","protocol","toUint8Array"],"inputs":{"src/edge-ws-muxer.ts":{"bytesInOutput":5688},"src/defs.ts":{"bytesInOutput":298},"src/protocol.ts":{"bytesInOutput":2604}},"bytes":8880}}}