@q9labsai/chalk-client 5.2.6 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/access/grant.d.ts +2 -0
  3. package/dist/{chunk-I7Y4HR2P.js → chunk-2CEMOTZF.js} +333 -64
  4. package/dist/{chunk-5YPQNMJE.js → chunk-FD7ZSDTM.js} +103 -26
  5. package/dist/{chunk-CJVLTSIO.js → chunk-MHJ4UPM3.js} +165 -6
  6. package/dist/chunk-N4IPKRS6.js +76 -0
  7. package/dist/{chunk-YIDKETOX.js → chunk-O5JB5XVX.js} +840 -38
  8. package/dist/{chunk-WFRTUBN6.js → chunk-VAJ6XNAA.js} +1 -1
  9. package/dist/client.d.ts +182 -1
  10. package/dist/connection/dependencies.d.ts +2 -1
  11. package/dist/effect.js +29 -4
  12. package/dist/generated/http-api.d.ts +180 -1
  13. package/dist/generated/schemas.d.ts +290 -1
  14. package/dist/generated/sync.d.ts +60 -1
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +33 -15
  17. package/dist/media/call-stats.d.ts +27 -0
  18. package/dist/media/client.d.ts +2 -2
  19. package/dist/media/ice-servers.d.ts +3 -0
  20. package/dist/media/index.d.ts +2 -0
  21. package/dist/media/index.js +4 -1
  22. package/dist/media/plane.d.ts +4 -2
  23. package/dist/media/receive-stall.d.ts +52 -0
  24. package/dist/media/types.d.ts +21 -0
  25. package/dist/media/video-render-size.d.ts +7 -0
  26. package/dist/media/viewer-layer.d.ts +48 -0
  27. package/dist/public-invites/index.js +3 -2
  28. package/dist/server/index.cjs +19 -4
  29. package/dist/server/index.js +19 -4
  30. package/dist/server/types.d.cts +2 -0
  31. package/dist/server/types.d.ts +2 -0
  32. package/dist/session/index.d.ts +18 -0
  33. package/dist/space-client/same-identity.d.ts +6 -0
  34. package/dist/space-client/types.d.ts +6 -0
  35. package/dist/sync/index.js +2 -1
  36. package/dist/sync/v1-command-scheduler.d.ts +4 -0
  37. package/dist/sync/v1-types.d.ts +6 -0
  38. package/package.json +3 -1
@@ -1,3 +1,7 @@
1
+ import {
2
+ withRequestContext
3
+ } from "./chunk-N4IPKRS6.js";
4
+
1
5
  // src/generated/schemas.ts
2
6
  import { Schema, SchemaGetter } from "effect";
3
7
  var ChalkCodePointLimits = {
@@ -84,6 +88,7 @@ var AccessGrantSchema = Schema.Struct({
84
88
  });
85
89
  var AdmitEpisodeParticipantRequestSchema = Schema.Struct({
86
90
  admission: Schema.optional(Schema.Literals(["policy", "direct"])),
91
+ identity_external_id: Schema.optional(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256))),
87
92
  identity_id: Schema.optional(UUIDSchema),
88
93
  metadata: Schema.optional(Schema.Unknown),
89
94
  name: Schema.String.check(Schema.isMinLength(1)),
@@ -91,6 +96,30 @@ var AdmitEpisodeParticipantRequestSchema = Schema.Struct({
91
96
  role: Schema.String.check(Schema.isMinLength(1))
92
97
  });
93
98
  var AuditLogIdSchema = Schema.String.check(Schema.isMinLength(36), Schema.isMaxLength(36), Schema.isPattern(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)).pipe(Schema.brand("AuditLogId"));
99
+ var CallStatsRequestSchema = Schema.Struct({
100
+ samples: Schema.Array(
101
+ Schema.Struct({
102
+ connection_type: Schema.Literals(["udp", "tcp", "turn", "unknown"]),
103
+ elapsed_ms: Schema.Number,
104
+ freeze_count: Schema.optional(Schema.NullOr(Schema.Number)),
105
+ freeze_ms: Schema.optional(Schema.NullOr(Schema.Number)),
106
+ local_candidate_type: Schema.optional(Schema.Literals(["host", "srflx", "prflx", "relay"])),
107
+ recv_bitrate_kbps: Schema.optional(Schema.NullOr(Schema.Number)),
108
+ recv_height: Schema.optional(Schema.NullOr(Schema.Number)),
109
+ recv_jitter_ms: Schema.optional(Schema.NullOr(Schema.Number)),
110
+ recv_loss_pct: Schema.optional(Schema.NullOr(Schema.Number)),
111
+ relay_protocol: Schema.optional(Schema.Literals(["udp", "tcp", "tls"])),
112
+ remote_candidate_type: Schema.optional(Schema.Literals(["host", "srflx", "prflx", "relay"])),
113
+ rtt_ms: Schema.optional(Schema.NullOr(Schema.Number)),
114
+ send_bitrate_kbps: Schema.optional(Schema.NullOr(Schema.Number)),
115
+ send_jitter_ms: Schema.optional(Schema.NullOr(Schema.Number)),
116
+ send_layer: Schema.optional(Schema.Literals(["h", "m", "l"])),
117
+ send_loss_pct: Schema.optional(Schema.NullOr(Schema.Number)),
118
+ window_ms: Schema.Number
119
+ })
120
+ ).check(Schema.isMinLength(1), Schema.isMaxLength(30)),
121
+ version: Schema.Literal(1)
122
+ });
94
123
  var CancelRecordingPreparationRequestSchema = Schema.Struct({
95
124
  expected_revision: Schema.Number
96
125
  });
@@ -135,6 +164,7 @@ var CloudflareSFUCloseTracksAPIResponseSchema = Schema.Struct({
135
164
  var CloudflareSFUCloseTracksRequestSchema = Schema.Struct({
136
165
  connection_id: Schema.String.check(Schema.isMinLength(1)),
137
166
  force: Schema.Boolean,
167
+ receive_only: Schema.optional(Schema.Boolean),
138
168
  session_description: Schema.optional(
139
169
  Schema.NullOr(
140
170
  Schema.Struct({
@@ -172,7 +202,7 @@ var CloudflareSFURenegotiateRequestSchema = Schema.Struct({
172
202
  var CloudflareSFURenegotiateResponseSchema = Schema.Struct({
173
203
  accepted: Schema.Boolean
174
204
  });
175
- var CloudflareSFUTracksAPIResponseSchema = Schema.Struct({
205
+ var CloudflareSFUUpdateTracksAPIResponseSchema = Schema.Struct({
176
206
  requiresImmediateRenegotiation: Schema.optional(Schema.Boolean),
177
207
  sessionDescription: Schema.optional(
178
208
  Schema.NullOr(
@@ -213,6 +243,7 @@ var CloudflareSFUTracksAPIResponseSchema = Schema.Struct({
213
243
  )
214
244
  )
215
245
  });
246
+ var CloudflareSFUTracksAPIResponseSchema = CloudflareSFUUpdateTracksAPIResponseSchema;
216
247
  var CloudflareSFUTracksRequestSchema = Schema.Struct({
217
248
  connection_id: Schema.String.check(Schema.isMinLength(1)),
218
249
  session_description: Schema.optional(
@@ -243,6 +274,28 @@ var CloudflareSFUTracksRequestSchema = Schema.Struct({
243
274
  })
244
275
  )
245
276
  });
277
+ var CloudflareSFUUpdateTracksRequestSchema = Schema.Struct({
278
+ connection_id: Schema.String.check(Schema.isMinLength(1)),
279
+ tracks: Schema.Array(
280
+ Schema.Struct({
281
+ location: Schema.String.check(Schema.isMinLength(1)),
282
+ mid: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
283
+ publication_id: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
284
+ sessionId: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
285
+ simulcast: Schema.optional(
286
+ Schema.NullOr(
287
+ Schema.Struct({
288
+ preferredRid: Schema.String.check(Schema.isMinLength(1)),
289
+ priorityOrdering: Schema.String.check(Schema.isMinLength(1)),
290
+ ridNotAvailable: Schema.String.check(Schema.isMinLength(1))
291
+ })
292
+ )
293
+ ),
294
+ source: Schema.optional(Schema.String.check(Schema.isMinLength(1))),
295
+ trackName: Schema.String.check(Schema.isMinLength(1))
296
+ })
297
+ )
298
+ });
246
299
  var ConnectionReportRequestSchema = Schema.Struct({
247
300
  events: Schema.Array(
248
301
  Schema.Struct({
@@ -1125,7 +1178,8 @@ var AddCloudflareSFUTracksQueryParamsSchema = Schema.Struct({
1125
1178
  "local_signaling_failure",
1126
1179
  "remote_signaling_failure",
1127
1180
  "dormant_connection",
1128
- "access_refresh"
1181
+ "access_refresh",
1182
+ "receive_stalled"
1129
1183
  ])
1130
1184
  )
1131
1185
  });
@@ -1923,6 +1977,19 @@ var TestWebhookEndpoint429ResponseHeadersSchema = Schema.Struct({
1923
1977
  "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
1924
1978
  "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
1925
1979
  });
1980
+ var UpdateCloudflareSFUTracksPathParamsSchema = Schema.Struct({
1981
+ episode_id: EpisodeIdSchema,
1982
+ participant_id: ParticipantIdSchema,
1983
+ space_id: SpaceIdSchema,
1984
+ tenant_id: TenantIdSchema
1985
+ });
1986
+ var UpdateCloudflareSFUTracksRequestBodySchema = CloudflareSFUUpdateTracksRequestSchema;
1987
+ var UpdateCloudflareSFUTracksResponseSchema = CloudflareSFUUpdateTracksAPIResponseSchema;
1988
+ var UpdateCloudflareSFUTracks429ResponseHeadersSchema = Schema.Struct({
1989
+ "Retry-After": RetryAfterHeaderSchema,
1990
+ "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
1991
+ "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
1992
+ });
1926
1993
  var UpdateMembershipPathParamsSchema = Schema.Struct({
1927
1994
  membership_id: MembershipIdSchema,
1928
1995
  tenant_id: TenantIdSchema
@@ -1981,6 +2048,15 @@ var UpdateWebhookEndpoint429ResponseHeadersSchema = Schema.Struct({
1981
2048
  "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
1982
2049
  "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
1983
2050
  });
2051
+ var UploadCallStatsPathParamsSchema = Schema.Struct({
2052
+ tenant_id: TenantIdSchema
2053
+ });
2054
+ var UploadCallStatsRequestBodySchema = CallStatsRequestSchema;
2055
+ var UploadCallStats429ResponseHeadersSchema = Schema.Struct({
2056
+ "Retry-After": RetryAfterHeaderSchema,
2057
+ "X-RateLimit-Limit": RateLimitLimitHeaderSchema,
2058
+ "X-RateLimit-Remaining": RateLimitRemainingHeaderSchema
2059
+ });
1984
2060
  var AccessForbiddenError = class extends Schema.TaggedErrorClass()("AccessForbiddenError", {
1985
2061
  error: Schema.Struct({
1986
2062
  code: Schema.Literal("access.forbidden"),
@@ -5108,6 +5184,22 @@ var TestWebhookEndpointErrorSchema = Schema.Union([
5108
5184
  WebhookInvalidUrlErrorSchema,
5109
5185
  WebhookUnsafeUrlErrorSchema
5110
5186
  ]);
5187
+ var UpdateCloudflareSFUTracksErrorSchema = Schema.Union([
5188
+ AccessForbiddenErrorSchema,
5189
+ AccessUnauthenticatedErrorSchema,
5190
+ EpisodeInvalidIdErrorSchema,
5191
+ EpisodeNotFoundErrorSchema,
5192
+ MediaConnectionNotFoundErrorSchema,
5193
+ MediaUnavailableErrorSchema,
5194
+ ParticipantInvalidIdErrorSchema,
5195
+ RequestInvalidErrorSchema,
5196
+ RequestPayloadTooLargeErrorSchema,
5197
+ RequestRateLimitedErrorSchema,
5198
+ ServiceInternalErrorSchema,
5199
+ ServiceUnavailableErrorSchema,
5200
+ SpaceInvalidIdErrorSchema,
5201
+ TenantInvalidIdErrorSchema
5202
+ ]);
5111
5203
  var UpdateMembershipErrorSchema = Schema.Union([
5112
5204
  AccessForbiddenErrorSchema,
5113
5205
  AccessUnauthenticatedErrorSchema,
@@ -5196,6 +5288,7 @@ var UpdateWebhookEndpointErrorSchema = Schema.Union([
5196
5288
  WebhookInvalidUrlErrorSchema,
5197
5289
  WebhookUnsafeUrlErrorSchema
5198
5290
  ]);
5291
+ var UploadCallStatsErrorSchema = Schema.Union([AccessForbiddenErrorSchema, AccessUnauthenticatedErrorSchema, RequestInvalidErrorSchema, RequestPayloadTooLargeErrorSchema, RequestRateLimitedErrorSchema, ServiceInternalErrorSchema, ServiceUnavailableErrorSchema, TenantInvalidIdErrorSchema]);
5199
5292
  var ChalkOperationPolicies = {
5200
5293
  addCloudflareSFUTracks: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5201
5294
  admitEpisodeParticipant: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
@@ -5257,11 +5350,13 @@ var ChalkOperationPolicies = {
5257
5350
  sendProblemReport: { maxBodyBytes: 37024, rateLimit: { limit: 3, policy: "problem_reports.participant", windowSeconds: 3600 } },
5258
5351
  setEpisodeDeadline: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5259
5352
  testWebhookEndpoint: { rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5353
+ updateCloudflareSFUTracks: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5260
5354
  updateMembership: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5261
5355
  updateSpace: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5262
5356
  updateSpacePublicInvite: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5263
5357
  updateTenant: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5264
- updateWebhookEndpoint: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } }
5358
+ updateWebhookEndpoint: { maxBodyBytes: 1048576, rateLimit: { limit: 60, policy: "v1.authenticated.write", windowSeconds: 60 } },
5359
+ uploadCallStats: { maxBodyBytes: 32768, rateLimit: { limit: 30, policy: "call_stats.participant", windowSeconds: 600 } }
5265
5360
  };
5266
5361
 
5267
5362
  // src/generated/http-api.ts
@@ -5830,6 +5925,28 @@ var defaultGroup = HttpApiGroup.make("default").add(
5830
5925
  ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5831
5926
  ]
5832
5927
  })
5928
+ ).add(
5929
+ HttpApiEndpoint.put("updateCloudflareSFUTracks", "/v1/tenants/:tenant_id/spaces/:space_id/episodes/:episode_id/participants/:participant_id/media/sfu/tracks/update", {
5930
+ params: UpdateCloudflareSFUTracksPathParamsSchema,
5931
+ payload: UpdateCloudflareSFUTracksRequestBodySchema,
5932
+ success: UpdateCloudflareSFUTracksResponseSchema.pipe(HttpApiSchema.status(200)),
5933
+ error: [
5934
+ EpisodeInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5935
+ ParticipantInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5936
+ RequestInvalidErrorSchema.pipe(HttpApiSchema.status(400)),
5937
+ SpaceInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5938
+ TenantInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5939
+ AccessUnauthenticatedErrorSchema.pipe(HttpApiSchema.status(401)),
5940
+ AccessForbiddenErrorSchema.pipe(HttpApiSchema.status(403)),
5941
+ EpisodeNotFoundErrorSchema.pipe(HttpApiSchema.status(404)),
5942
+ MediaConnectionNotFoundErrorSchema.pipe(HttpApiSchema.status(404)),
5943
+ RequestPayloadTooLargeErrorSchema.pipe(HttpApiSchema.status(413)),
5944
+ RequestRateLimitedErrorSchema.pipe(HttpApiSchema.status(429)),
5945
+ ServiceInternalErrorSchema.pipe(HttpApiSchema.status(500)),
5946
+ MediaUnavailableErrorSchema.pipe(HttpApiSchema.status(503)),
5947
+ ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5948
+ ]
5949
+ })
5833
5950
  ).add(
5834
5951
  HttpApiEndpoint.patch("updateWebhookEndpoint", "/v1/tenants/:tenant_id/webhook-endpoints/:endpoint_id", {
5835
5952
  params: UpdateWebhookEndpointPathParamsSchema,
@@ -5865,6 +5982,22 @@ var defaultGroup = HttpApiGroup.make("default").add(
5865
5982
  ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5866
5983
  ]
5867
5984
  })
5985
+ ).add(
5986
+ HttpApiEndpoint.post("uploadCallStats", "/v1/tenants/:tenant_id/call-stats", {
5987
+ params: UploadCallStatsPathParamsSchema,
5988
+ payload: UploadCallStatsRequestBodySchema,
5989
+ success: HttpApiSchema.Empty(204).pipe(HttpApiSchema.status(204)),
5990
+ error: [
5991
+ RequestInvalidErrorSchema.pipe(HttpApiSchema.status(400)),
5992
+ TenantInvalidIdErrorSchema.pipe(HttpApiSchema.status(400)),
5993
+ AccessUnauthenticatedErrorSchema.pipe(HttpApiSchema.status(401)),
5994
+ AccessForbiddenErrorSchema.pipe(HttpApiSchema.status(403)),
5995
+ RequestPayloadTooLargeErrorSchema.pipe(HttpApiSchema.status(413)),
5996
+ RequestRateLimitedErrorSchema.pipe(HttpApiSchema.status(429)),
5997
+ ServiceInternalErrorSchema.pipe(HttpApiSchema.status(500)),
5998
+ ServiceUnavailableErrorSchema.pipe(HttpApiSchema.status(503))
5999
+ ]
6000
+ })
5868
6001
  );
5869
6002
  var episodesGroup = HttpApiGroup.make("episodes").add(
5870
6003
  HttpApiEndpoint.post("admitEpisodeParticipant", "/v1/tenants/:tenant_id/spaces/:space_id/episodes/:episode_id/participants", {
@@ -6862,7 +6995,7 @@ var createChalkEffectClient = (options) => {
6862
6995
  })
6863
6996
  }).pipe(Effect.provide(FetchHttpClient.layer));
6864
6997
  const configuredClient = options.credentials === void 0 ? client : client.pipe(Effect.provideService(FetchHttpClient.RequestInit, { credentials: options.credentials }));
6865
- return options.fetch ? configuredClient.pipe(Effect.provideService(FetchHttpClient.Fetch, options.fetch)) : configuredClient;
6998
+ return configuredClient.pipe(Effect.provideService(FetchHttpClient.Fetch, withRequestContext(options.fetch)));
6866
6999
  };
6867
7000
  function requestHeaders(options) {
6868
7001
  return {
@@ -7013,17 +7146,31 @@ function parseMediaAccess(value) {
7013
7146
  provider: value.provider,
7014
7147
  clientPayload: {
7015
7148
  connectionId: requireNonEmptyString(payload.connectionId),
7016
- stunServer: requireNonEmptyString(payload.stunServer)
7149
+ stunServer: requireNonEmptyString(payload.stunServer),
7150
+ ...payload.iceServers === void 0 || payload.iceServers === null ? {} : { iceServers: parseIceServers(payload.iceServers) }
7017
7151
  }
7018
7152
  };
7019
7153
  default:
7020
7154
  throw new AccessGrantError();
7021
7155
  }
7022
7156
  }
7157
+ function parseIceServers(value) {
7158
+ if (!Array.isArray(value)) throw new AccessGrantError();
7159
+ return value.map((entry) => {
7160
+ if (!isRecord(entry) || !Array.isArray(entry.urls) || entry.urls.length === 0) throw new AccessGrantError();
7161
+ const urls = entry.urls.map(requireNonEmptyString);
7162
+ if (entry.username === void 0 && entry.credential === void 0) return { urls };
7163
+ return { urls, username: requireNonEmptyString(entry.username), credential: requireNonEmptyString(entry.credential) };
7164
+ });
7165
+ }
7023
7166
  function mediaClientPayload(value) {
7024
7167
  switch (value.provider) {
7025
7168
  case "cloudflare_sfu":
7026
- return { connectionId: value.clientPayload.connectionId, stunServer: value.clientPayload.stunServer };
7169
+ return {
7170
+ connectionId: value.clientPayload.connectionId,
7171
+ stunServer: value.clientPayload.stunServer,
7172
+ ...value.clientPayload.iceServers ? { iceServers: value.clientPayload.iceServers } : {}
7173
+ };
7027
7174
  }
7028
7175
  }
7029
7176
  function requireCredential(value, audience) {
@@ -7071,6 +7218,7 @@ export {
7071
7218
  AccessGrantSchema,
7072
7219
  AdmitEpisodeParticipantRequestSchema,
7073
7220
  AuditLogIdSchema,
7221
+ CallStatsRequestSchema,
7074
7222
  CancelRecordingPreparationRequestSchema,
7075
7223
  ChatAttachmentSchema,
7076
7224
  ChatAttachmentDownloadSchema,
@@ -7080,8 +7228,10 @@ export {
7080
7228
  CloudflareSFUPublicationsResponseSchema,
7081
7229
  CloudflareSFURenegotiateRequestSchema,
7082
7230
  CloudflareSFURenegotiateResponseSchema,
7231
+ CloudflareSFUUpdateTracksAPIResponseSchema,
7083
7232
  CloudflareSFUTracksAPIResponseSchema,
7084
7233
  CloudflareSFUTracksRequestSchema,
7234
+ CloudflareSFUUpdateTracksRequestSchema,
7085
7235
  ConnectionReportRequestSchema,
7086
7236
  CreateAPIKeyRequestSchema,
7087
7237
  CreateEpisodeRequestSchema,
@@ -7427,6 +7577,10 @@ export {
7427
7577
  TestWebhookEndpointRequestHeadersSchema,
7428
7578
  TestWebhookEndpointResponseSchema,
7429
7579
  TestWebhookEndpoint429ResponseHeadersSchema,
7580
+ UpdateCloudflareSFUTracksPathParamsSchema,
7581
+ UpdateCloudflareSFUTracksRequestBodySchema,
7582
+ UpdateCloudflareSFUTracksResponseSchema,
7583
+ UpdateCloudflareSFUTracks429ResponseHeadersSchema,
7430
7584
  UpdateMembershipPathParamsSchema,
7431
7585
  UpdateMembershipRequestBodySchema,
7432
7586
  UpdateMembershipResponseSchema,
@@ -7448,6 +7602,9 @@ export {
7448
7602
  UpdateWebhookEndpointRequestBodySchema,
7449
7603
  UpdateWebhookEndpointResponseSchema,
7450
7604
  UpdateWebhookEndpoint429ResponseHeadersSchema,
7605
+ UploadCallStatsPathParamsSchema,
7606
+ UploadCallStatsRequestBodySchema,
7607
+ UploadCallStats429ResponseHeadersSchema,
7451
7608
  AccessForbiddenError,
7452
7609
  AccessForbiddenErrorWireSchema,
7453
7610
  AccessForbiddenErrorSchema,
@@ -7870,11 +8027,13 @@ export {
7870
8027
  SendProblemReportErrorSchema,
7871
8028
  SetEpisodeDeadlineErrorSchema,
7872
8029
  TestWebhookEndpointErrorSchema,
8030
+ UpdateCloudflareSFUTracksErrorSchema,
7873
8031
  UpdateMembershipErrorSchema,
7874
8032
  UpdateSpaceErrorSchema,
7875
8033
  UpdateSpacePublicInviteErrorSchema,
7876
8034
  UpdateTenantErrorSchema,
7877
8035
  UpdateWebhookEndpointErrorSchema,
8036
+ UploadCallStatsErrorSchema,
7878
8037
  ChalkOperationPolicies,
7879
8038
  ChalkApi,
7880
8039
  createChalkEffectClient,
@@ -0,0 +1,76 @@
1
+ // src/session/index.ts
2
+ var SESSION_ID_KEY = "session.id";
3
+ var STORAGE_KEY = "chalk.session.id";
4
+ var TAB_KEY = "chalk.session.tab";
5
+ var TAB_NAME_PREFIX = "chalk.tab:";
6
+ var SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
7
+ var source = browserSession;
8
+ var browserId;
9
+ function setSessionSource(next) {
10
+ source = next;
11
+ }
12
+ function currentSessionId() {
13
+ return source();
14
+ }
15
+ function newSessionId() {
16
+ const random = globalThis.crypto;
17
+ if (typeof random?.randomUUID === "function") return random.randomUUID();
18
+ return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (digit) => (Number(digit) ^ random.getRandomValues(new Uint8Array(1))[0] & 15 >> Number(digit) / 4).toString(16));
19
+ }
20
+ function browserSession() {
21
+ if (browserId) return browserId;
22
+ if (typeof globalThis.document === "undefined") return void 0;
23
+ const tab = tabToken();
24
+ browserId = newSessionId();
25
+ try {
26
+ const storage = globalThis.sessionStorage;
27
+ browserId = storedSession(storage, tab) ?? browserId;
28
+ storage.setItem(STORAGE_KEY, browserId);
29
+ if (tab !== void 0) storage.setItem(TAB_KEY, tab);
30
+ } catch {
31
+ }
32
+ return browserId;
33
+ }
34
+ function storedSession(storage, tab) {
35
+ const stored = storage.getItem(STORAGE_KEY) ?? void 0;
36
+ if (!stored || !SESSION_ID.test(stored)) return void 0;
37
+ return tab === void 0 || storage.getItem(TAB_KEY) === tab ? stored : void 0;
38
+ }
39
+ function tabToken() {
40
+ const win = globalThis.window;
41
+ if (!win) return void 0;
42
+ if (win.name.startsWith(TAB_NAME_PREFIX)) return win.name;
43
+ if (win.name !== "") return void 0;
44
+ win.name = `${TAB_NAME_PREFIX}${newSessionId()}`;
45
+ return win.name;
46
+ }
47
+ function sessionBaggage() {
48
+ const sessionId = currentSessionId();
49
+ return sessionId ? `${SESSION_ID_KEY}=${sessionId}` : void 0;
50
+ }
51
+ function requestContextHeaders() {
52
+ const baggage = sessionBaggage();
53
+ if (!baggage) return {};
54
+ const trace = newSessionId().replaceAll("-", "");
55
+ return { baggage, traceparent: `00-${trace}-${trace.slice(16)}-01` };
56
+ }
57
+ function withRequestContext(fetchImplementation) {
58
+ return (input, init) => {
59
+ const send = fetchImplementation ?? globalThis.fetch;
60
+ const context = requestContextHeaders();
61
+ if (Object.keys(context).length === 0) return send(input, init);
62
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
63
+ for (const [name, value] of Object.entries(context)) if (!headers.has(name)) headers.set(name, value);
64
+ return send(input, { ...init, headers });
65
+ };
66
+ }
67
+
68
+ export {
69
+ SESSION_ID_KEY,
70
+ setSessionSource,
71
+ currentSessionId,
72
+ newSessionId,
73
+ sessionBaggage,
74
+ requestContextHeaders,
75
+ withRequestContext
76
+ };