@dxos/edge-client 0.8.4-main.40e3dcdf1b → 0.8.4-main.422d1c7879

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.
@@ -124,6 +124,7 @@ var createStubEdgeIdentity = () => {
124
124
 
125
125
  // src/edge-client.ts
126
126
  import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask, scheduleTaskInterval as scheduleTaskInterval2 } from "@dxos/async";
127
+ import { TRACE_SPAN_ATTRIBUTE } from "@dxos/context";
127
128
  import { Resource as Resource2 } from "@dxos/context";
128
129
  import { log as log2, logInfo as logInfo2 } from "@dxos/log";
129
130
  import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
@@ -300,14 +301,16 @@ var EdgeWsConnection = class extends Resource {
300
301
  this._connectionInfo.protocolHeader
301
302
  ] : [
302
303
  ...baseProtocols
303
- ]);
304
+ ], this._connectionInfo.headers ? {
305
+ headers: this._connectionInfo.headers
306
+ } : void 0);
304
307
  const muxer = new WebSocketMuxer(this._ws);
305
308
  this._wsMuxer = muxer;
306
309
  this._ws.onopen = () => {
307
310
  if (this.isOpen) {
308
311
  log("connected", void 0, {
309
312
  F: __dxlog_file3,
310
- L: 130,
313
+ L: 131,
311
314
  S: this,
312
315
  C: (f, a) => f(...a)
313
316
  });
@@ -320,7 +323,7 @@ var EdgeWsConnection = class extends Resource {
320
323
  currentIdentity: this._identity
321
324
  }, {
322
325
  F: __dxlog_file3,
323
- L: 136,
326
+ L: 137,
324
327
  S: this,
325
328
  C: (f, a) => f(...a)
326
329
  });
@@ -333,7 +336,7 @@ var EdgeWsConnection = class extends Resource {
333
336
  reason: event.reason
334
337
  }, {
335
338
  F: __dxlog_file3,
336
- L: 141,
339
+ L: 142,
337
340
  S: this,
338
341
  C: (f, a) => f(...a)
339
342
  });
@@ -348,7 +351,7 @@ var EdgeWsConnection = class extends Resource {
348
351
  info: event.message
349
352
  }, {
350
353
  F: __dxlog_file3,
351
- L: 148,
354
+ L: 149,
352
355
  S: this,
353
356
  C: (f, a) => f(...a)
354
357
  });
@@ -358,7 +361,7 @@ var EdgeWsConnection = class extends Resource {
358
361
  error: event.error
359
362
  }, {
360
363
  F: __dxlog_file3,
361
- L: 151,
364
+ L: 152,
362
365
  S: this,
363
366
  C: (f, a) => f(...a)
364
367
  });
@@ -370,7 +373,7 @@ var EdgeWsConnection = class extends Resource {
370
373
  event: event.type
371
374
  }, {
372
375
  F: __dxlog_file3,
373
- L: 159,
376
+ L: 160,
374
377
  S: this,
375
378
  C: (f, a) => f(...a)
376
379
  });
@@ -398,7 +401,7 @@ var EdgeWsConnection = class extends Resource {
398
401
  payload: protocol.getPayloadType(message)
399
402
  }, {
400
403
  F: __dxlog_file3,
401
- L: 185,
404
+ L: 186,
402
405
  S: this,
403
406
  C: (f, a) => f(...a)
404
407
  });
@@ -422,7 +425,7 @@ var EdgeWsConnection = class extends Resource {
422
425
  err
423
426
  }, {
424
427
  F: __dxlog_file3,
425
- L: 203,
428
+ L: 204,
426
429
  S: this,
427
430
  C: (f, a) => f(...a)
428
431
  });
@@ -431,7 +434,7 @@ var EdgeWsConnection = class extends Resource {
431
434
  _scheduleHeartbeats() {
432
435
  invariant3(this._ws, void 0, {
433
436
  F: __dxlog_file3,
434
- L: 208,
437
+ L: 209,
435
438
  S: this,
436
439
  A: [
437
440
  "this._ws",
@@ -453,7 +456,7 @@ var EdgeWsConnection = class extends Resource {
453
456
  void this._inactivityTimeoutCtx?.dispose();
454
457
  this._inactivityTimeoutCtx = new Context(void 0, {
455
458
  F: __dxlog_file3,
456
- L: 229
459
+ L: 230
457
460
  });
458
461
  scheduleTask(this._inactivityTimeoutCtx, () => {
459
462
  if (this.isOpen) {
@@ -462,7 +465,7 @@ var EdgeWsConnection = class extends Resource {
462
465
  lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
463
466
  }, {
464
467
  F: __dxlog_file3,
465
- L: 235,
468
+ L: 236,
466
469
  S: this,
467
470
  C: (f, a) => f(...a)
468
471
  });
@@ -600,7 +603,7 @@ var EdgeClient = class extends Resource2 {
600
603
  oldIdentity: this._identity
601
604
  }, {
602
605
  F: __dxlog_file4,
603
- L: 118,
606
+ L: 121,
604
607
  S: this,
605
608
  C: (f, a) => f(...a)
606
609
  });
@@ -613,11 +616,11 @@ var EdgeClient = class extends Resource2 {
613
616
  * Send message.
614
617
  * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
615
618
  */
616
- async send(message) {
619
+ async send(ctx, message) {
617
620
  if (this._ready.state !== TriggerState.RESOLVED) {
618
621
  log2("waiting for websocket", void 0, {
619
622
  F: __dxlog_file4,
620
- L: 131,
623
+ L: 134,
621
624
  S: this,
622
625
  C: (f, a) => f(...a)
623
626
  });
@@ -631,6 +634,14 @@ var EdgeClient = class extends Resource2 {
631
634
  if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
632
635
  throw new EdgeIdentityChangedError();
633
636
  }
637
+ const traceCtx = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE);
638
+ if (traceCtx) {
639
+ message.traceContext = {
640
+ $typeName: "dxos.edge.messenger.TraceContext",
641
+ traceparent: traceCtx.traceparent,
642
+ tracestate: traceCtx.tracestate
643
+ };
644
+ }
634
645
  this._currentConnection.send(message);
635
646
  }
636
647
  onMessage(listener) {
@@ -647,7 +658,7 @@ var EdgeClient = class extends Resource2 {
647
658
  } catch (error) {
648
659
  log2.catch(error, void 0, {
649
660
  F: __dxlog_file4,
650
- L: 164,
661
+ L: 176,
651
662
  S: this,
652
663
  C: (f, a) => f(...a)
653
664
  });
@@ -665,7 +676,7 @@ var EdgeClient = class extends Resource2 {
665
676
  info: this.info
666
677
  }, {
667
678
  F: __dxlog_file4,
668
- L: 177,
679
+ L: 189,
669
680
  S: this,
670
681
  C: (f, a) => f(...a)
671
682
  });
@@ -674,7 +685,7 @@ var EdgeClient = class extends Resource2 {
674
685
  err
675
686
  }, {
676
687
  F: __dxlog_file4,
677
- L: 179,
688
+ L: 191,
678
689
  S: this,
679
690
  C: (f, a) => f(...a)
680
691
  });
@@ -694,7 +705,7 @@ var EdgeClient = class extends Resource2 {
694
705
  peerKey: this._identity.peerKey
695
706
  }, {
696
707
  F: __dxlog_file4,
697
- L: 199,
708
+ L: 211,
698
709
  S: this,
699
710
  C: (f, a) => f(...a)
700
711
  });
@@ -711,7 +722,7 @@ var EdgeClient = class extends Resource2 {
711
722
  if (this._identity !== identity) {
712
723
  log2("identity changed during auth header request", void 0, {
713
724
  F: __dxlog_file4,
714
- L: 213,
725
+ L: 225,
715
726
  S: this,
716
727
  C: (f, a) => f(...a)
717
728
  });
@@ -724,13 +735,16 @@ var EdgeClient = class extends Resource2 {
724
735
  protocolHeader
725
736
  }, {
726
737
  F: __dxlog_file4,
727
- L: 219,
738
+ L: 231,
728
739
  S: this,
729
740
  C: (f, a) => f(...a)
730
741
  });
731
742
  const connection = new EdgeWsConnection(identity, {
732
743
  url,
733
- protocolHeader
744
+ protocolHeader,
745
+ headers: this._config.clientTag ? {
746
+ "X-DXOS-Client-Tag": this._config.clientTag
747
+ } : void 0
734
748
  }, {
735
749
  onConnected: () => {
736
750
  if (this._isActive(connection)) {
@@ -739,7 +753,7 @@ var EdgeClient = class extends Resource2 {
739
753
  } else {
740
754
  log2.verbose("connected callback ignored, because connection is not active", void 0, {
741
755
  F: __dxlog_file4,
742
- L: 229,
756
+ L: 245,
743
757
  S: this,
744
758
  C: (f, a) => f(...a)
745
759
  });
@@ -752,7 +766,7 @@ var EdgeClient = class extends Resource2 {
752
766
  } else {
753
767
  log2.verbose("restart requested by inactive connection", void 0, {
754
768
  F: __dxlog_file4,
755
- L: 237,
769
+ L: 253,
756
770
  S: this,
757
771
  C: (f, a) => f(...a)
758
772
  });
@@ -768,7 +782,7 @@ var EdgeClient = class extends Resource2 {
768
782
  type: message.payload?.typeUrl
769
783
  }, {
770
784
  F: __dxlog_file4,
771
- L: 245,
785
+ L: 261,
772
786
  S: this,
773
787
  C: (f, a) => f(...a)
774
788
  });
@@ -805,7 +819,7 @@ var EdgeClient = class extends Resource2 {
805
819
  err
806
820
  }, {
807
821
  F: __dxlog_file4,
808
- L: 280,
822
+ L: 296,
809
823
  S: this,
810
824
  C: (f, a) => f(...a)
811
825
  });
@@ -822,7 +836,7 @@ var EdgeClient = class extends Resource2 {
822
836
  payload: protocol.getPayloadType(message)
823
837
  }, {
824
838
  F: __dxlog_file4,
825
- L: 290,
839
+ L: 306,
826
840
  S: this,
827
841
  C: (f, a) => f(...a)
828
842
  });
@@ -843,7 +857,7 @@ var EdgeClient = class extends Resource2 {
843
857
  statusText: response.statusText
844
858
  }, {
845
859
  F: __dxlog_file4,
846
- L: 302,
860
+ L: 318,
847
861
  S: this,
848
862
  C: (f, a) => f(...a)
849
863
  });
@@ -866,11 +880,11 @@ import * as HttpClient from "@effect/platform/HttpClient";
866
880
  import * as Effect2 from "effect/Effect";
867
881
  import * as Function from "effect/Function";
868
882
  import { sleep } from "@dxos/async";
869
- import { Context as Context3 } from "@dxos/context";
883
+ import { TRACE_SPAN_ATTRIBUTE as TRACE_SPAN_ATTRIBUTE2 } from "@dxos/context";
870
884
  import { runAndForwardErrors } from "@dxos/effect";
871
885
  import { invariant as invariant4 } from "@dxos/invariant";
872
886
  import { log as log4 } from "@dxos/log";
873
- import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
887
+ import { EDGE_CLIENT_TAG_HEADER, EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
874
888
  import { createUrl } from "@dxos/util";
875
889
 
876
890
  // src/http-client.ts
@@ -924,18 +938,20 @@ var DEFAULT_MAX_RETRIES_COUNT = 3;
924
938
  var WARNING_BODY_SIZE = 10 * 1024 * 1024;
925
939
  var EdgeHttpClient = class {
926
940
  _baseUrl;
941
+ _clientTag;
927
942
  _edgeIdentity;
928
943
  /**
929
944
  * Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
930
945
  */
931
946
  _authHeader;
932
- constructor(baseUrl) {
947
+ constructor(baseUrl, options) {
933
948
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
949
+ this._clientTag = options?.clientTag;
934
950
  log4("created", {
935
951
  url: this._baseUrl
936
952
  }, {
937
953
  F: __dxlog_file6,
938
- L: 110,
954
+ L: 131,
939
955
  S: this,
940
956
  C: (f, a) => f(...a)
941
957
  });
@@ -952,8 +968,8 @@ var EdgeHttpClient = class {
952
968
  //
953
969
  // Status
954
970
  //
955
- async getStatus(args) {
956
- return this._call(new URL("/status", this.baseUrl), {
971
+ async getStatus(ctx, args) {
972
+ return this._call(ctx, new URL("/status", this.baseUrl), {
957
973
  ...args,
958
974
  method: "GET",
959
975
  auth: true
@@ -962,15 +978,15 @@ var EdgeHttpClient = class {
962
978
  //
963
979
  // Agents
964
980
  //
965
- createAgent(body, args) {
966
- return this._call(new URL("/agents/create", this.baseUrl), {
981
+ createAgent(ctx, body, args) {
982
+ return this._call(ctx, new URL("/agents/create", this.baseUrl), {
967
983
  ...args,
968
984
  method: "POST",
969
985
  body
970
986
  });
971
987
  }
972
- getAgentStatus(request, args) {
973
- return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
988
+ getAgentStatus(ctx, request, args) {
989
+ return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
974
990
  ...args,
975
991
  method: "GET"
976
992
  });
@@ -978,14 +994,14 @@ var EdgeHttpClient = class {
978
994
  //
979
995
  // Credentials
980
996
  //
981
- getCredentialsForNotarization(spaceId, args) {
982
- return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
997
+ getCredentialsForNotarization(ctx, spaceId, args) {
998
+ return this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
983
999
  ...args,
984
1000
  method: "GET"
985
1001
  });
986
1002
  }
987
- async notarizeCredentials(spaceId, body, args) {
988
- await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
1003
+ async notarizeCredentials(ctx, spaceId, body, args) {
1004
+ await this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
989
1005
  ...args,
990
1006
  body,
991
1007
  method: "POST"
@@ -994,8 +1010,8 @@ var EdgeHttpClient = class {
994
1010
  //
995
1011
  // Identity
996
1012
  //
997
- async recoverIdentity(body, args) {
998
- return this._call(new URL("/identity/recover", this.baseUrl), {
1013
+ async recoverIdentity(ctx, body, args) {
1014
+ return this._call(ctx, new URL("/identity/recover", this.baseUrl), {
999
1015
  ...args,
1000
1016
  body,
1001
1017
  method: "POST"
@@ -1004,8 +1020,8 @@ var EdgeHttpClient = class {
1004
1020
  //
1005
1021
  // Invitations
1006
1022
  //
1007
- async joinSpaceByInvitation(spaceId, body, args) {
1008
- return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
1023
+ async joinSpaceByInvitation(ctx, spaceId, body, args) {
1024
+ return this._call(ctx, new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
1009
1025
  ...args,
1010
1026
  body,
1011
1027
  method: "POST"
@@ -1014,8 +1030,8 @@ var EdgeHttpClient = class {
1014
1030
  //
1015
1031
  // OAuth and credentials
1016
1032
  //
1017
- async initiateOAuthFlow(body, args) {
1018
- return this._call(new URL("/oauth/initiate", this.baseUrl), {
1033
+ async initiateOAuthFlow(ctx, body, args) {
1034
+ return this._call(ctx, new URL("/oauth/initiate", this.baseUrl), {
1019
1035
  ...args,
1020
1036
  body,
1021
1037
  method: "POST"
@@ -1024,8 +1040,8 @@ var EdgeHttpClient = class {
1024
1040
  //
1025
1041
  // Spaces
1026
1042
  //
1027
- async createSpace(body, args) {
1028
- return this._call(new URL("/spaces/create", this.baseUrl), {
1043
+ async createSpace(ctx, body, args) {
1044
+ return this._call(ctx, new URL("/spaces/create", this.baseUrl), {
1029
1045
  ...args,
1030
1046
  body,
1031
1047
  method: "POST"
@@ -1034,18 +1050,18 @@ var EdgeHttpClient = class {
1034
1050
  //
1035
1051
  // Queues
1036
1052
  //
1037
- async queryQueue(subspaceTag, spaceId, query, args) {
1053
+ async queryQueue(ctx, subspaceTag, spaceId, query, args) {
1038
1054
  const queueId = query.queueIds?.[0];
1039
1055
  invariant4(queueId, "queueId required", {
1040
1056
  F: __dxlog_file6,
1041
- L: 219,
1057
+ L: 254,
1042
1058
  S: this,
1043
1059
  A: [
1044
1060
  "queueId",
1045
1061
  "'queueId required'"
1046
1062
  ]
1047
1063
  });
1048
- return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
1064
+ return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
1049
1065
  after: query.after,
1050
1066
  before: query.before,
1051
1067
  limit: query.limit,
@@ -1056,8 +1072,8 @@ var EdgeHttpClient = class {
1056
1072
  method: "GET"
1057
1073
  });
1058
1074
  }
1059
- async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
1060
- return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
1075
+ async insertIntoQueue(ctx, subspaceTag, spaceId, queueId, objects, args) {
1076
+ return this._call(ctx, new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
1061
1077
  ...args,
1062
1078
  body: {
1063
1079
  objects
@@ -1065,8 +1081,8 @@ var EdgeHttpClient = class {
1065
1081
  method: "POST"
1066
1082
  });
1067
1083
  }
1068
- async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
1069
- return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
1084
+ async deleteFromQueue(ctx, subspaceTag, spaceId, queueId, objectIds, args) {
1085
+ return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
1070
1086
  ids: objectIds.join(",")
1071
1087
  }), {
1072
1088
  ...args,
@@ -1076,7 +1092,7 @@ var EdgeHttpClient = class {
1076
1092
  //
1077
1093
  // Functions
1078
1094
  //
1079
- async uploadFunction(pathParts, body, args) {
1095
+ async uploadFunction(ctx, pathParts, body, args) {
1080
1096
  const formData = new FormData();
1081
1097
  formData.append("name", body.name ?? "");
1082
1098
  formData.append("version", body.version);
@@ -1096,20 +1112,20 @@ var EdgeHttpClient = class {
1096
1112
  pathParts.functionId
1097
1113
  ] : []
1098
1114
  ].join("/");
1099
- return this._call(new URL(path, this.baseUrl), {
1115
+ return this._call(ctx, new URL(path, this.baseUrl), {
1100
1116
  ...args,
1101
1117
  body: formData,
1102
1118
  method: "PUT",
1103
1119
  json: false
1104
1120
  });
1105
1121
  }
1106
- async listFunctions(args) {
1107
- return this._call(new URL("/functions", this.baseUrl), {
1122
+ async listFunctions(ctx, args) {
1123
+ return this._call(ctx, new URL("/functions", this.baseUrl), {
1108
1124
  ...args,
1109
1125
  method: "GET"
1110
1126
  });
1111
1127
  }
1112
- async invokeFunction(params, input, args) {
1128
+ async invokeFunction(ctx, params, input, args) {
1113
1129
  const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
1114
1130
  if (params.version) {
1115
1131
  url.searchParams.set("version", params.version);
@@ -1123,7 +1139,7 @@ var EdgeHttpClient = class {
1123
1139
  if (params.subrequestsLimit) {
1124
1140
  url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
1125
1141
  }
1126
- return this._call(url, {
1142
+ return this._call(ctx, url, {
1127
1143
  ...args,
1128
1144
  body: input,
1129
1145
  method: "POST"
@@ -1132,8 +1148,8 @@ var EdgeHttpClient = class {
1132
1148
  //
1133
1149
  // Workflows
1134
1150
  //
1135
- async executeWorkflow(spaceId, graphId, input, args) {
1136
- return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
1151
+ async executeWorkflow(ctx, spaceId, graphId, input, args) {
1152
+ return this._call(ctx, new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
1137
1153
  ...args,
1138
1154
  body: input,
1139
1155
  method: "POST"
@@ -1142,13 +1158,13 @@ var EdgeHttpClient = class {
1142
1158
  //
1143
1159
  // Triggers
1144
1160
  //
1145
- async getCronTriggers(spaceId) {
1146
- return this._call(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), {
1161
+ async getCronTriggers(ctx, spaceId) {
1162
+ return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
1147
1163
  method: "GET"
1148
1164
  });
1149
1165
  }
1150
- async forceRunCronTrigger(spaceId, triggerId) {
1151
- return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
1166
+ async forceRunCronTrigger(ctx, spaceId, triggerId) {
1167
+ return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
1152
1168
  method: "POST"
1153
1169
  });
1154
1170
  }
@@ -1158,25 +1174,38 @@ var EdgeHttpClient = class {
1158
1174
  /**
1159
1175
  * Execute a QueryAST query against a space.
1160
1176
  */
1161
- async execQuery(spaceId, body, args) {
1162
- return this._call(new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
1177
+ async execQuery(ctx, spaceId, body, args) {
1178
+ return this._call(ctx, new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
1163
1179
  ...args,
1164
1180
  body,
1165
1181
  method: "POST"
1166
1182
  });
1167
1183
  }
1168
1184
  //
1185
+ // Registry
1186
+ //
1187
+ /**
1188
+ * Fetches the hydrated plugin directory from the Edge registry service.
1189
+ * Unauthenticated; safe to call without an identity.
1190
+ */
1191
+ async getRegistryPlugins(ctx, args) {
1192
+ return this._call(ctx, new URL("/registry/plugins", this.baseUrl), {
1193
+ ...args,
1194
+ method: "GET"
1195
+ });
1196
+ }
1197
+ //
1169
1198
  // Import/Export space.
1170
1199
  //
1171
- async importBundle(spaceId, body, args) {
1172
- return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
1200
+ async importBundle(ctx, spaceId, body, args) {
1201
+ return this._call(ctx, new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
1173
1202
  ...args,
1174
1203
  body,
1175
1204
  method: "PUT"
1176
1205
  });
1177
1206
  }
1178
- async exportBundle(spaceId, body, args) {
1179
- return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
1207
+ async exportBundle(ctx, spaceId, body, args) {
1208
+ return this._call(ctx, new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
1180
1209
  ...args,
1181
1210
  body,
1182
1211
  method: "POST"
@@ -1189,21 +1218,18 @@ var EdgeHttpClient = class {
1189
1218
  return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
1190
1219
  }
1191
1220
  // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
1192
- async _call(url, args) {
1221
+ async _call(ctx, url, args) {
1193
1222
  const shouldRetry = createRetryHandler(args);
1194
- const requestContext = args.context ?? Context3.default(void 0, {
1195
- F: __dxlog_file6,
1196
- L: 426
1197
- });
1198
1223
  log4("fetch", {
1199
1224
  url,
1200
1225
  request: args.body
1201
1226
  }, {
1202
1227
  F: __dxlog_file6,
1203
- L: 427,
1228
+ L: 483,
1204
1229
  S: this,
1205
1230
  C: (f, a) => f(...a)
1206
1231
  });
1232
+ const traceHeaders = getTraceHeaders(ctx);
1207
1233
  let handledAuth = false;
1208
1234
  const tryCount = 1;
1209
1235
  while (true) {
@@ -1215,14 +1241,14 @@ var EdgeHttpClient = class {
1215
1241
  this._authHeader = await this._handleUnauthorized(response2);
1216
1242
  }
1217
1243
  }
1218
- const request = createRequest(args, this._authHeader);
1244
+ const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
1219
1245
  log4("call edge", {
1220
1246
  url,
1221
1247
  tryCount,
1222
1248
  authHeader: !!this._authHeader
1223
1249
  }, {
1224
1250
  F: __dxlog_file6,
1225
- L: 442,
1251
+ L: 500,
1226
1252
  S: this,
1227
1253
  C: (f, a) => f(...a)
1228
1254
  });
@@ -1231,7 +1257,7 @@ var EdgeHttpClient = class {
1231
1257
  const body2 = await response.clone().json();
1232
1258
  invariant4(body2, "Expected body to be present", {
1233
1259
  F: __dxlog_file6,
1234
- L: 447,
1260
+ L: 505,
1235
1261
  S: this,
1236
1262
  A: [
1237
1263
  "body",
@@ -1252,7 +1278,7 @@ var EdgeHttpClient = class {
1252
1278
  const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
1253
1279
  invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
1254
1280
  F: __dxlog_file6,
1255
- L: 463,
1281
+ L: 521,
1256
1282
  S: this,
1257
1283
  A: [
1258
1284
  "!body?.success",
@@ -1266,7 +1292,7 @@ var EdgeHttpClient = class {
1266
1292
  } else {
1267
1293
  invariant4(!response.ok, "Expected response to not be ok.", {
1268
1294
  F: __dxlog_file6,
1269
- L: 470,
1295
+ L: 528,
1270
1296
  S: this,
1271
1297
  A: [
1272
1298
  "!response.ok",
@@ -1278,13 +1304,13 @@ var EdgeHttpClient = class {
1278
1304
  } catch (error) {
1279
1305
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
1280
1306
  }
1281
- if (processingError?.isRetryable && await shouldRetry(requestContext, processingError.retryAfterMs)) {
1307
+ if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
1282
1308
  log4.verbose("retrying edge request", {
1283
1309
  url,
1284
1310
  processingError
1285
1311
  }, {
1286
1312
  F: __dxlog_file6,
1287
- L: 478,
1313
+ L: 536,
1288
1314
  S: this,
1289
1315
  C: (f, a) => f(...a)
1290
1316
  });
@@ -1297,7 +1323,7 @@ var EdgeHttpClient = class {
1297
1323
  if (!this._edgeIdentity) {
1298
1324
  log4.warn("unauthorized response received before identity was set", void 0, {
1299
1325
  F: __dxlog_file6,
1300
- L: 487,
1326
+ L: 545,
1301
1327
  S: this,
1302
1328
  C: (f, a) => f(...a)
1303
1329
  });
@@ -1307,7 +1333,7 @@ var EdgeHttpClient = class {
1307
1333
  return encodeAuthHeader(challenge);
1308
1334
  }
1309
1335
  };
1310
- var createRequest = ({ method, body, json = true }, authHeader) => {
1336
+ var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
1311
1337
  let requestBody;
1312
1338
  const headers = {};
1313
1339
  if (json) {
@@ -1321,7 +1347,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
1321
1347
  bodySize: requestBody.length
1322
1348
  }, {
1323
1349
  F: __dxlog_file6,
1324
- L: 511,
1350
+ L: 571,
1325
1351
  S: void 0,
1326
1352
  C: (f, a) => f(...a)
1327
1353
  });
@@ -1329,12 +1355,31 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
1329
1355
  if (authHeader) {
1330
1356
  headers["Authorization"] = authHeader;
1331
1357
  }
1358
+ if (traceHeaders) {
1359
+ Object.assign(headers, traceHeaders);
1360
+ }
1361
+ if (clientTag) {
1362
+ headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
1363
+ }
1332
1364
  return {
1333
1365
  method,
1334
1366
  body: requestBody,
1335
1367
  headers
1336
1368
  };
1337
1369
  };
1370
+ var getTraceHeaders = (ctx) => {
1371
+ const traceCtx = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE2);
1372
+ if (!traceCtx) {
1373
+ return void 0;
1374
+ }
1375
+ const headers = {
1376
+ traceparent: traceCtx.traceparent
1377
+ };
1378
+ if (traceCtx.tracestate) {
1379
+ headers.tracestate = traceCtx.tracestate;
1380
+ }
1381
+ return headers;
1382
+ };
1338
1383
  var createRetryHandler = ({ retry: retry2 }) => {
1339
1384
  if (!retry2 || retry2.count < 1) {
1340
1385
  return async () => false;