med-scribe-alliance-ts-sdk 2.0.44 → 2.0.45

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 (2) hide show
  1. package/dist/index.mjs +164 -142
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -28,7 +28,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
28
28
  return e.AUTHENTICATION_FAILED = "authentication_failed", e.TOKEN_EXPIRED = "token_expired", e.INVALID_API_KEY = "invalid_api_key", e.FORBIDDEN = "forbidden", e.RATE_LIMIT_EXCEEDED = "rate_limit_exceeded", e.SESSION_NOT_FOUND = "session_not_found", e.TEMPLATE_NOT_FOUND = "template_not_found", e.SESSION_EXPIRED = "session_expired", e.INVALID_REQUEST = "invalid_request", e.INVALID_AUDIO_FORMAT = "invalid_audio_format", e.CHUNK_TOO_LARGE = "chunk_too_large", e.INVALID_TEMPLATE = "invalid_template", e.MISSING_REQUIRED_FIELD = "missing_required_field", e.PROCESSING_FAILED = "processing_failed", e.AUDIO_QUALITY_POOR = "audio_quality_poor", e.AUDIO_TOO_SHORT = "audio_too_short", e.LANGUAGE_UNSUPPORTED = "language_unsupported", e.INTERNAL_ERROR = "internal_error", e.SERVICE_UNAVAILABLE = "service_unavailable", e.DISCOVERY_FAILED = "discovery_failed", e.TRANSPORT_ERROR = "transport_error", e.WORKER_ERROR = "worker_error", e.UPLOAD_FAILED = "upload_failed", e.VAD_ERROR = "vad_error", e.CHUNK_LENGTH_EXCEEDED = "chunk_length_exceeded", e.CHUNK_LIMIT_REACHED = "chunk_limit_reached", e.CHUNK_CREATION_FAILED = "chunk_creation_failed", e.WORKER_POST_FAILED = "worker_post_failed", e.SESSION_CREATION_FAILED = "session_creation_failed", e.RECORDER_INIT_FAILED = "recorder_init_failed", e.RECORDER_START_FAILED = "recorder_start_failed", e.VAD_START_FAILED = "vad_start_failed", e.STOP_FAILED = "stop_failed", e.INTERNAL_RETRY_FAILED = "internal_retry_failed", e.SESSION_END_FAILED = "session_end_failed", e.UNSUPPORTED_STORAGE_PROVIDER = "unsupported_storage_provider", e;
29
29
  }({}), _ = /* @__PURE__ */ function(e) {
30
30
  return e[e.OK = 200] = "OK", e[e.CREATED = 201] = "CREATED", e[e.ACCEPTED = 202] = "ACCEPTED", e[e.BAD_REQUEST = 400] = "BAD_REQUEST", e[e.UNAUTHORIZED = 401] = "UNAUTHORIZED", e[e.FORBIDDEN = 403] = "FORBIDDEN", e[e.NOT_FOUND = 404] = "NOT_FOUND", e[e.GONE = 410] = "GONE", e[e.PAYLOAD_TOO_LARGE = 413] = "PAYLOAD_TOO_LARGE", e[e.UNPROCESSABLE_ENTITY = 422] = "UNPROCESSABLE_ENTITY", e[e.TOO_MANY_REQUESTS = 429] = "TOO_MANY_REQUESTS", e[e.INTERNAL_SERVER_ERROR = 500] = "INTERNAL_SERVER_ERROR", e[e.SERVICE_UNAVAILABLE = 503] = "SERVICE_UNAVAILABLE", e;
31
- }({}), v = 2e3, y = class e extends Error {
31
+ }({}), ee = 2e3, v = class e extends Error {
32
32
  constructor(t, n = g.INTERNAL_ERROR, r, i) {
33
33
  super(t), this.name = "ScribeError", this.code = n, this.httpStatus = r, this.details = i, Error.captureStackTrace && Error.captureStackTrace(this, e);
34
34
  }
@@ -44,46 +44,46 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
44
44
  details: this.details
45
45
  };
46
46
  }
47
- }, b = class extends y {
47
+ }, y = class extends v {
48
48
  constructor(e, t) {
49
49
  super(e, g.INVALID_REQUEST, _.BAD_REQUEST, t), this.name = "ValidationError";
50
50
  }
51
- }, x = class extends y {
51
+ }, b = class extends v {
52
52
  constructor(e, t) {
53
53
  super(e, g.DISCOVERY_FAILED, void 0, t), this.name = "DiscoveryError";
54
54
  }
55
- }, S = class extends y {
55
+ }, x = class extends v {
56
56
  constructor(e, t) {
57
57
  super(e, g.AUTHENTICATION_FAILED, _.UNAUTHORIZED, t), this.name = "AuthenticationError";
58
58
  }
59
- }, C = class extends y {
59
+ }, S = class extends v {
60
60
  constructor(e, t) {
61
61
  super(e, g.FORBIDDEN, _.FORBIDDEN, t), this.name = "ForbiddenError";
62
62
  }
63
- }, w = class extends y {
63
+ }, C = class extends v {
64
64
  constructor(e) {
65
65
  super(`Session '${e}' does not exist`, g.SESSION_NOT_FOUND, _.NOT_FOUND, { session_id: e }), this.name = "SessionNotFoundError";
66
66
  }
67
- }, ee = class extends y {
67
+ }, te = class extends v {
68
68
  constructor(e, t) {
69
69
  super(`Session '${e}' has expired`, g.SESSION_EXPIRED, _.GONE, {
70
70
  session_id: e,
71
71
  expired_at: t
72
72
  }), this.name = "SessionExpiredError";
73
73
  }
74
- }, T = class extends y {
74
+ }, w = class extends v {
75
75
  constructor(e) {
76
76
  super(`Rate limit exceeded${e ? `. Retry after ${e} seconds` : ""}`, g.RATE_LIMIT_EXCEEDED, _.TOO_MANY_REQUESTS, e ? { retry_after_seconds: e } : void 0), this.name = "RateLimitError";
77
77
  }
78
- }, E = class extends y {
78
+ }, T = class extends v {
79
79
  constructor(e, t) {
80
80
  super(e, g.TRANSPORT_ERROR, void 0, t), this.name = "TransportError";
81
81
  }
82
- }, D = class extends y {
82
+ }, ne = class extends v {
83
83
  constructor(e, t) {
84
84
  super(e, g.WORKER_ERROR, void 0, t), this.name = "WorkerError";
85
85
  }
86
- }, O = class extends y {
86
+ }, E = class extends v {
87
87
  constructor(e, t, n) {
88
88
  super(e, g.UPLOAD_FAILED, void 0, n), this.name = "UploadError", this.failedFiles = t;
89
89
  }
@@ -93,11 +93,11 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
93
93
  failedFiles: this.failedFiles
94
94
  };
95
95
  }
96
- }, k = class extends y {
96
+ }, D = class extends v {
97
97
  constructor(e) {
98
98
  super(`Storage provider '${e || "(none)"}' is not supported by this SDK build.`, g.UNSUPPORTED_STORAGE_PROVIDER, void 0, { provider: e }), this.name = "UnsupportedStorageProviderError", this.provider = e;
99
99
  }
100
- }, A = class {
100
+ }, O = class {
101
101
  constructor() {
102
102
  this.handlers = /* @__PURE__ */ new Map();
103
103
  }
@@ -123,7 +123,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
123
123
  let t = this.handlers.get(e);
124
124
  return t !== void 0 && t.size > 0;
125
125
  }
126
- }, te = e.object({
126
+ }, re = e.object({
127
127
  id: e.string().min(1, "models[].id is required"),
128
128
  display_name: e.string().optional(),
129
129
  languages: e.array(e.string()).optional(),
@@ -134,12 +134,12 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
134
134
  speaker_diarization: e.boolean().optional(),
135
135
  custom_templates: e.boolean().optional()
136
136
  }).optional()
137
- }), ne = e.object({
137
+ }), ie = e.object({
138
138
  issuer: e.string(),
139
139
  authorization_endpoint: e.string(),
140
140
  token_endpoint: e.string(),
141
141
  scopes_supported: e.array(e.string())
142
- }), j = e.object({
142
+ }), ae = e.object({
143
143
  protocol: e.string().min(1, "protocol is required"),
144
144
  protocol_version: e.string().min(1, "protocol_version is required"),
145
145
  supported_versions: e.array(e.string()).optional(),
@@ -156,7 +156,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
156
156
  }),
157
157
  authentication: e.object({
158
158
  supported_methods: e.array(e.string()),
159
- oidc: ne.optional()
159
+ oidc: ie.optional()
160
160
  }),
161
161
  capabilities: e.object({
162
162
  audio_formats: e.array(e.string()).min(1, "capabilities.audio_formats must have at least one format"),
@@ -166,12 +166,12 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
166
166
  client_sdk_delivery: e.boolean().optional(),
167
167
  storage_provider: e.string().optional()
168
168
  }),
169
- models: e.array(te).optional().default([]),
169
+ models: e.array(re).optional().default([]),
170
170
  languages: e.object({
171
171
  supported: e.array(e.string()),
172
172
  auto_detection: e.boolean().optional()
173
173
  })
174
- }), M = e.object({
174
+ }), k = e.object({
175
175
  templates: e.array(e.string()).max(2, "templates cannot have more than 2 items"),
176
176
  upload_type: e.string().min(1, "upload_type is required"),
177
177
  communication_protocol: e.string().min(1, "communication_protocol is required"),
@@ -187,10 +187,10 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
187
187
  mobile: e.number().optional()
188
188
  }).optional(),
189
189
  session_id: e.string().optional()
190
- }), N = e.object({
190
+ }), oe = e.object({
191
191
  audio_files_sent: e.number().int().min(0, "audio_files_sent must be a non-negative integer"),
192
192
  audio_files_uploaded: e.number().int().min(0, "audio_files_uploaded must be a non-negative integer")
193
- }), P = e.object({
193
+ }), se = e.object({
194
194
  user_status: e.string().optional(),
195
195
  processing_status: e.string().optional(),
196
196
  patient_details: e.object({
@@ -203,7 +203,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
203
203
  language_hint: e.array(e.string()).optional(),
204
204
  transcript_language: e.string().optional(),
205
205
  templates: e.array(e.string()).optional()
206
- }), re = e.object({
206
+ }), ce = e.object({
207
207
  session_id: e.string().min(1, "session_id is required"),
208
208
  status: e.string(),
209
209
  created_at: e.string(),
@@ -215,13 +215,13 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
215
215
  gender: e.string().optional(),
216
216
  mobile: e.number().optional()
217
217
  }).nullable().optional()
218
- }), ie = e.object({
218
+ }), A = e.object({
219
219
  session_id: e.string().min(1, "session_id is required"),
220
220
  status: e.string(),
221
221
  message: e.string(),
222
222
  audio_files_received: e.number().int(),
223
223
  audio_files: e.array(e.string())
224
- }), ae = e.object({
224
+ }), j = e.object({
225
225
  session_id: e.string().min(1, "session_id is required"),
226
226
  status: e.string(),
227
227
  created_at: e.string(),
@@ -252,16 +252,16 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
252
252
  mobile: e.number().optional()
253
253
  }).nullable().optional(),
254
254
  message: e.string().optional()
255
- }), oe = e.object({
255
+ }), le = e.object({
256
256
  session_id: e.string().min(1, "session_id is required"),
257
257
  status: e.string(),
258
258
  message: e.string()
259
- }), se = e.object({
259
+ }), ue = e.object({
260
260
  session_id: e.string().min(1, "session_id is required"),
261
261
  template_id: e.string(),
262
262
  status: e.string(),
263
263
  message: e.string()
264
- }), ce = e.string().min(1, "Session ID is required"), le = e.object({
264
+ }), de = e.string().min(1, "Session ID is required"), fe = e.object({
265
265
  templates: e.array(e.string()).min(1, "templates must contain at least one item").max(2, "templates cannot have more than 2 items"),
266
266
  uploadType: e.string().optional(),
267
267
  communicationProtocol: e.string().optional(),
@@ -279,39 +279,39 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
279
279
  }).optional(),
280
280
  sessionId: e.string().optional(),
281
281
  version: e.string().optional()
282
- }), F = class {
282
+ }), M = class {
283
283
  validateDiscoveryResponse(e) {
284
- this.parseWithValidationError(j, e, "Invalid discovery response");
284
+ this.parseWithValidationError(ae, e, "Invalid discovery response");
285
285
  }
286
286
  validateCreateSessionRequest(e) {
287
- this.parseWithValidationError(M, e, "Invalid CreateSessionRequest");
287
+ this.parseWithValidationError(k, e, "Invalid CreateSessionRequest");
288
288
  }
289
289
  validateEndSessionRequest(e) {
290
- this.parseWithValidationError(N, e, "Invalid EndSessionRequest");
290
+ this.parseWithValidationError(oe, e, "Invalid EndSessionRequest");
291
291
  }
292
292
  validateCreateSessionResponse(e) {
293
- this.parseWithValidationError(re, e, "Invalid CreateSessionResponse");
293
+ this.parseWithValidationError(ce, e, "Invalid CreateSessionResponse");
294
294
  }
295
295
  validateEndSessionResponse(e) {
296
- this.parseWithValidationError(ie, e, "Invalid EndSessionResponse");
296
+ this.parseWithValidationError(A, e, "Invalid EndSessionResponse");
297
297
  }
298
298
  validateGetSessionStatusResponse(e) {
299
- this.parseWithValidationError(ae, e, "Invalid GetSessionStatusResponse");
299
+ this.parseWithValidationError(j, e, "Invalid GetSessionStatusResponse");
300
300
  }
301
301
  validateSessionId(e) {
302
- this.parseWithValidationError(ce, e, "Invalid session ID");
302
+ this.parseWithValidationError(de, e, "Invalid session ID");
303
303
  }
304
304
  validateRecordingOptions(e) {
305
- this.parseWithValidationError(le, e, "Invalid RecordingOptions");
305
+ this.parseWithValidationError(fe, e, "Invalid RecordingOptions");
306
306
  }
307
307
  validatePatchSessionRequest(e) {
308
- this.parseWithValidationError(P, e, "Invalid PatchSessionRequest");
308
+ this.parseWithValidationError(se, e, "Invalid PatchSessionRequest");
309
309
  }
310
310
  validatePatchSessionResponse(e) {
311
- this.parseWithValidationError(oe, e, "Invalid PatchSessionResponse");
311
+ this.parseWithValidationError(le, e, "Invalid PatchSessionResponse");
312
312
  }
313
313
  validateProcessTemplateResponse(e) {
314
- this.parseWithValidationError(se, e, "Invalid ProcessTemplateResponse");
314
+ this.parseWithValidationError(ue, e, "Invalid ProcessTemplateResponse");
315
315
  }
316
316
  validateAgainstDiscovery(e, t) {
317
317
  try {
@@ -322,7 +322,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
322
322
  }
323
323
  parseWithValidationError(e, t, n) {
324
324
  let r = e.safeParse(t);
325
- if (!r.success) throw new b(`${n}:\n${this.formatZodIssues(r.error)}`, { zodErrors: r.error.issues });
325
+ if (!r.success) throw new y(`${n}:\n${this.formatZodIssues(r.error)}`, { zodErrors: r.error.issues });
326
326
  }
327
327
  formatZodIssues(e) {
328
328
  return e.issues.map((e) => ` - ${e.path.length > 0 ? e.path.join(".") + ": " : ""}${e.message}`).join("\n");
@@ -330,7 +330,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
330
330
  checkUploadType(e, t) {
331
331
  if (!e.uploadType || t.supportedUploadMethods.length === 0) return;
332
332
  let n = t.supportedUploadMethods;
333
- if (!n.includes(e.uploadType)) throw new b(`Upload type '${e.uploadType}' is not supported by the server. Supported: [${n.join(", ")}]`, {
333
+ if (!n.includes(e.uploadType)) throw new y(`Upload type '${e.uploadType}' is not supported by the server. Supported: [${n.join(", ")}]`, {
334
334
  requested: e.uploadType,
335
335
  supported: n
336
336
  });
@@ -338,7 +338,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
338
338
  checkLanguageHint(e, t) {
339
339
  if (!e.languageHint || e.languageHint.length === 0 || t.supportedLanguages.length === 0) return;
340
340
  let n = t.supportedLanguages;
341
- for (let t of e.languageHint) if (!n.includes(t)) throw new b(`Language '${t}' is not supported by the server. Supported: [${n.join(", ")}]`, {
341
+ for (let t of e.languageHint) if (!n.includes(t)) throw new y(`Language '${t}' is not supported by the server. Supported: [${n.join(", ")}]`, {
342
342
  requested: t,
343
343
  supported: n
344
344
  });
@@ -346,7 +346,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
346
346
  checkModel(e, t) {
347
347
  if (!e.model || t.availableModels.length === 0) return;
348
348
  let n = t.availableModels.map((e) => e.id);
349
- if (!n.includes(e.model)) throw new b(`Model '${e.model}' is not available. Available: [${n.join(", ")}]`, {
349
+ if (!n.includes(e.model)) throw new y(`Model '${e.model}' is not available. Available: [${n.join(", ")}]`, {
350
350
  requested: e.model,
351
351
  available: n
352
352
  });
@@ -354,26 +354,36 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
354
354
  };
355
355
  //#endregion
356
356
  //#region src/utils/retry.ts
357
- async function I(e, t = {}) {
358
- let { maxRetries: n = 2, delayMs: r = v, onRetry: i } = t, a = null;
357
+ async function N(e, t = {}) {
358
+ let { maxRetries: n = 2, delayMs: r = ee, onRetry: i } = t, a = null;
359
359
  for (let t = 0; t <= n; t++) try {
360
360
  return await e();
361
361
  } catch (e) {
362
- if (a = e instanceof Error ? e : Error(String(e)), ue(e?.httpStatus ?? e?.statusCode ?? e?.status)) throw a;
362
+ if (a = e instanceof Error ? e : Error(String(e)), pe(e?.httpStatus ?? e?.statusCode ?? e?.status)) throw a;
363
363
  if (t >= n || i && i(t + 1, a) === !1) break;
364
- await de(r);
364
+ await me(r);
365
365
  }
366
366
  throw a ?? /* @__PURE__ */ Error("Retry failed: unknown error");
367
367
  }
368
- function ue(e) {
368
+ function pe(e) {
369
369
  return typeof e == "number" ? e >= 400 && e < 500 && e !== 408 && e !== 429 : !1;
370
370
  }
371
- function de(e) {
371
+ function me(e) {
372
372
  return new Promise((t) => setTimeout(t, e));
373
373
  }
374
374
  //#endregion
375
+ //#region src/utils/timezone.ts
376
+ var P = "X-timezone";
377
+ function F() {
378
+ try {
379
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
380
+ } catch {
381
+ return;
382
+ }
383
+ }
384
+ //#endregion
375
385
  //#region src/transport/http-transport.ts
376
- var L = class {
386
+ var I = class {
377
387
  constructor(e) {
378
388
  this.tokenRefreshPromise = null, this.accessToken = e.accessToken, this.flavour = e.flavour, this.debug = e.debug ?? !1, this.onUnauthorized = e.onUnauthorized;
379
389
  }
@@ -382,9 +392,9 @@ var L = class {
382
392
  }
383
393
  async request(e) {
384
394
  try {
385
- return e.isUpload ? await I(() => this.executeRequest(e), this.getRetryOptions(e)) : await this.executeRequest(e);
395
+ return e.isUpload ? await N(() => this.executeRequest(e), this.getRetryOptions(e)) : await this.executeRequest(e);
386
396
  } catch (t) {
387
- throw t instanceof y ? t : new E(`Network error: ${t instanceof Error ? t.message : "Unknown error"}`, {
397
+ throw t instanceof v ? t : new T(`Network error: ${t instanceof Error ? t.message : "Unknown error"}`, {
388
398
  url: e.url,
389
399
  method: e.method
390
400
  });
@@ -413,7 +423,7 @@ var L = class {
413
423
  statusText: t.statusText
414
424
  }), t;
415
425
  } catch (t) {
416
- throw new E(`Fetch failed: ${t instanceof Error ? t.message : "Unknown error"}`, {
426
+ throw new T(`Fetch failed: ${t instanceof Error ? t.message : "Unknown error"}`, {
417
427
  url: e.url,
418
428
  method: e.method
419
429
  });
@@ -432,7 +442,12 @@ var L = class {
432
442
  }
433
443
  buildHeaders(e) {
434
444
  let t = {}, n = e.isUpload === !0 && e.attachAuth === !1;
435
- return e.isUpload ? e.uploadFormFields || (t["Content-Type"] = "audio/mp3") : (t["Content-Type"] = "application/json", t.Accept = "application/json"), n || (this.accessToken && (t.Authorization = `Bearer ${this.accessToken}`), this.flavour && (t.flavour = this.flavour)), e.headers && Object.assign(t, e.headers), t;
445
+ if (e.isUpload ? e.uploadFormFields || (t["Content-Type"] = "audio/mp3") : (t["Content-Type"] = "application/json", t.Accept = "application/json"), !n) {
446
+ this.accessToken && (t.Authorization = `Bearer ${this.accessToken}`), this.flavour && (t.flavour = this.flavour);
447
+ let e = F();
448
+ e && (t[P] = e);
449
+ }
450
+ return e.headers && Object.assign(t, e.headers), t;
436
451
  }
437
452
  buildRequestInit(e, t) {
438
453
  let n = e.isUpload === !0 && e.attachAuth === !1, r = {
@@ -461,24 +476,24 @@ var L = class {
461
476
  r = await e.json();
462
477
  } catch {}
463
478
  let i = r?.error?.message ?? r?.message ?? e.statusText ?? "Request failed", a = r?.error?.code ?? "http_error";
464
- if (n === _.UNAUTHORIZED) throw new S(i, {
479
+ if (n === _.UNAUTHORIZED) throw new x(i, {
465
480
  url: t.url,
466
481
  ...r?.error?.details
467
482
  });
468
- if (n === _.FORBIDDEN) throw new C(i, {
483
+ if (n === _.FORBIDDEN) throw new S(i, {
469
484
  url: t.url,
470
485
  ...r?.error?.details
471
486
  });
472
- if (n === _.NOT_FOUND) throw new w(r?.error?.details?.session_id ?? t.url);
473
- if (n === _.PAYLOAD_TOO_LARGE) throw new y(i, g.CHUNK_TOO_LARGE, n, {
487
+ if (n === _.NOT_FOUND) throw new C(r?.error?.details?.session_id ?? t.url);
488
+ if (n === _.PAYLOAD_TOO_LARGE) throw new v(i, g.CHUNK_TOO_LARGE, n, {
474
489
  url: t.url,
475
490
  ...r?.error?.details
476
491
  });
477
492
  if (n === _.TOO_MANY_REQUESTS) {
478
493
  let t = parseInt(e.headers.get("Retry-After") ?? "", 10);
479
- throw new T(isNaN(t) ? void 0 : t);
494
+ throw new w(isNaN(t) ? void 0 : t);
480
495
  }
481
- throw new y(i, a, n, r?.error?.details);
496
+ throw new v(i, a, n, r?.error?.details);
482
497
  }
483
498
  extractHeaders(e) {
484
499
  let t = {};
@@ -495,7 +510,7 @@ var L = class {
495
510
  }
496
511
  };
497
512
  }
498
- }, R = class {
513
+ }, L = class {
499
514
  constructor(e) {
500
515
  this.pendingRequests = /* @__PURE__ */ new Map(), this.correlationCounter = 0, this.tokenRefreshPromise = null, this.bridge = e.bridge, this.accessToken = e.accessToken, this.flavour = e.flavour, this.debug = e.debug ?? !1, this.onUnauthorized = e.onUnauthorized, this.bridge.onResponse((e) => {
501
516
  this.handleResponse(e);
@@ -506,9 +521,9 @@ var L = class {
506
521
  }
507
522
  async request(e) {
508
523
  try {
509
- return e.isUpload ? await I(() => this.executeRequest(e), this.getRetryOptions(e)) : await this.executeRequest(e);
524
+ return e.isUpload ? await N(() => this.executeRequest(e), this.getRetryOptions(e)) : await this.executeRequest(e);
510
525
  } catch (t) {
511
- throw t instanceof y ? t : new E(`IPC error: ${t instanceof Error ? t.message : "Unknown error"}`, {
526
+ throw t instanceof v ? t : new T(`IPC error: ${t instanceof Error ? t.message : "Unknown error"}`, {
512
527
  url: e.url,
513
528
  method: e.method
514
529
  });
@@ -516,7 +531,7 @@ var L = class {
516
531
  }
517
532
  async executeRequest(e) {
518
533
  let t = await this.doIpcRequest(e);
519
- if (t.error) throw new E(t.error, {
534
+ if (t.error) throw new T(t.error, {
520
535
  url: e.url,
521
536
  method: e.method
522
537
  });
@@ -562,7 +577,12 @@ var L = class {
562
577
  }
563
578
  buildHeaders(e) {
564
579
  let t = {}, n = e.isUpload === !0 && e.attachAuth === !1;
565
- return e.isUpload ? e.uploadFormFields || (t["Content-Type"] = "audio/mp3") : (t["Content-Type"] = "application/json", t.Accept = "application/json"), n || (this.accessToken && (t.Authorization = `Bearer ${this.accessToken}`), this.flavour && (t.flavour = this.flavour)), e.headers && Object.assign(t, e.headers), t;
580
+ if (e.isUpload ? e.uploadFormFields || (t["Content-Type"] = "audio/mp3") : (t["Content-Type"] = "application/json", t.Accept = "application/json"), !n) {
581
+ this.accessToken && (t.Authorization = `Bearer ${this.accessToken}`), this.flavour && (t.flavour = this.flavour);
582
+ let e = F();
583
+ e && (t[P] = e);
584
+ }
585
+ return e.headers && Object.assign(t, e.headers), t;
566
586
  }
567
587
  async buildIpcRequest(e, t, n) {
568
588
  let r = {
@@ -580,7 +600,7 @@ var L = class {
580
600
  sendAndWait(e, t) {
581
601
  return new Promise((n, r) => {
582
602
  let i = setTimeout(() => {
583
- this.pendingRequests.delete(e), r(new E("IPC request timed out after 15s", {
603
+ this.pendingRequests.delete(e), r(new T("IPC request timed out after 15s", {
584
604
  correlationId: e,
585
605
  url: t.url
586
606
  }));
@@ -596,7 +616,7 @@ var L = class {
596
616
  try {
597
617
  this.bridge.send(t);
598
618
  } catch (n) {
599
- clearTimeout(i), this.pendingRequests.delete(e), r(new E(`Failed to send IPC request: ${n instanceof Error ? n.message : "Unknown error"}`, {
619
+ clearTimeout(i), this.pendingRequests.delete(e), r(new T(`Failed to send IPC request: ${n instanceof Error ? n.message : "Unknown error"}`, {
600
620
  correlationId: e,
601
621
  url: t.url
602
622
  }));
@@ -609,24 +629,24 @@ var L = class {
609
629
  }
610
630
  handleErrorResponse(e, t) {
611
631
  let n = e.status, r = e.body, i = r?.error?.message ?? r?.message ?? "Request failed", a = r?.error?.code ?? "http_error";
612
- if (n === _.UNAUTHORIZED) throw new S(i, {
632
+ if (n === _.UNAUTHORIZED) throw new x(i, {
613
633
  url: t.url,
614
634
  ...r?.error?.details
615
635
  });
616
- if (n === _.FORBIDDEN) throw new C(i, {
636
+ if (n === _.FORBIDDEN) throw new S(i, {
617
637
  url: t.url,
618
638
  ...r?.error?.details
619
639
  });
620
- if (n === _.NOT_FOUND) throw new w(r?.error?.details?.session_id ?? t.url);
621
- if (n === _.PAYLOAD_TOO_LARGE) throw new y(i, g.CHUNK_TOO_LARGE, n, {
640
+ if (n === _.NOT_FOUND) throw new C(r?.error?.details?.session_id ?? t.url);
641
+ if (n === _.PAYLOAD_TOO_LARGE) throw new v(i, g.CHUNK_TOO_LARGE, n, {
622
642
  url: t.url,
623
643
  ...r?.error?.details
624
644
  });
625
645
  if (n === _.TOO_MANY_REQUESTS) {
626
646
  let t = parseInt(e.headers?.["retry-after"] ?? "", 10);
627
- throw new T(isNaN(t) ? void 0 : t);
647
+ throw new w(isNaN(t) ? void 0 : t);
628
648
  }
629
- throw new y(i, a, n, r?.error?.details);
649
+ throw new v(i, a, n, r?.error?.details);
630
650
  }
631
651
  generateCorrelationId() {
632
652
  return this.correlationCounter += 1, `ipc_${Date.now()}_${this.correlationCounter}`;
@@ -645,12 +665,12 @@ var L = class {
645
665
  };
646
666
  }
647
667
  destroy() {
648
- for (let [e, t] of this.pendingRequests) t.reject(new E("IPC transport destroyed")), this.pendingRequests.delete(e);
668
+ for (let [e, t] of this.pendingRequests) t.reject(new T("IPC transport destroyed")), this.pendingRequests.delete(e);
649
669
  }
650
670
  };
651
671
  //#endregion
652
672
  //#region src/discovery/resolved-config.ts
653
- function z(e) {
673
+ function R(e) {
654
674
  try {
655
675
  let t = /* @__PURE__ */ new Map(), n = e.models ?? [];
656
676
  for (let e of n) e.id && typeof e.max_session_duration_seconds == "number" && t.set(e.id, e.max_session_duration_seconds);
@@ -670,12 +690,12 @@ function z(e) {
670
690
  clientSdkDelivery: e.capabilities.client_sdk_delivery ?? !1
671
691
  };
672
692
  } catch (e) {
673
- throw e instanceof x ? e : new x(`Failed to resolve discovery config: ${e instanceof Error ? e.message : "Unknown error"}`);
693
+ throw e instanceof b ? e : new b(`Failed to resolve discovery config: ${e instanceof Error ? e.message : "Unknown error"}`);
674
694
  }
675
695
  }
676
696
  //#endregion
677
697
  //#region src/discovery/discovery-manager.ts
678
- var B = class {
698
+ var z = class {
679
699
  constructor(e, t, n = !1) {
680
700
  this.cachedDocument = null, this.resolvedConfig = null, this.cacheTimestamp = 0, this.cacheTtlMs = i, this.transport = e, this.validator = t, this.debug = n;
681
701
  }
@@ -692,17 +712,17 @@ var B = class {
692
712
  url: n
693
713
  });
694
714
  this.validator.validateDiscoveryResponse(i.data);
695
- let a = i.data, o = z(a);
715
+ let a = i.data, o = R(a);
696
716
  return this.cachedDocument = a, this.resolvedConfig = o, this.cacheTimestamp = Date.now(), this.debug && console.log("[ScribeSDK] Discovery complete:", a.service?.name ?? a.protocol), {
697
717
  data: o,
698
718
  httpStatus: i.status
699
719
  };
700
720
  } catch (t) {
701
- throw t instanceof x ? t : new x(`Failed to fetch discovery document: ${t instanceof Error ? t.message : "Unknown error"}`, { baseUrl: e });
721
+ throw t instanceof b ? t : new b(`Failed to fetch discovery document: ${t instanceof Error ? t.message : "Unknown error"}`, { baseUrl: e });
702
722
  }
703
723
  }
704
724
  getResolvedConfig() {
705
- if (!this.resolvedConfig) throw new x("Discovery has not been fetched yet. Call init() first.");
725
+ if (!this.resolvedConfig) throw new b("Discovery has not been fetched yet. Call init() first.");
706
726
  return this.resolvedConfig;
707
727
  }
708
728
  getDiscoveryDocument() {
@@ -745,7 +765,7 @@ var B = class {
745
765
  isCacheValid() {
746
766
  return Date.now() - this.cacheTimestamp < this.cacheTtlMs;
747
767
  }
748
- }, V = class {
768
+ }, B = class {
749
769
  constructor(e, t, n = !1) {
750
770
  this.currentSession = null, this.transport = e, this.validator = t, this.debug = n;
751
771
  }
@@ -764,13 +784,13 @@ var B = class {
764
784
  httpStatus: i.status
765
785
  };
766
786
  } catch (e) {
767
- throw e instanceof y ? e : new y(`Failed to create session: ${e instanceof Error ? e.message : "Unknown error"}`);
787
+ throw e instanceof v ? e : new v(`Failed to create session: ${e instanceof Error ? e.message : "Unknown error"}`);
768
788
  }
769
789
  }
770
790
  async endSession(e, t, n) {
771
791
  try {
772
792
  let r = n ?? this.currentSession?.session_id;
773
- if (!r) throw new y("No active session to end. Provide a sessionId or start a session first.");
793
+ if (!r) throw new v("No active session to end. Provide a sessionId or start a session first.");
774
794
  this.validator.validateSessionId(r), this.validator.validateEndSessionRequest(t);
775
795
  let i = `${e}/sessions/${r}/end`;
776
796
  this.debug && console.log("[ScribeSDK] Ending session:", r);
@@ -784,13 +804,13 @@ var B = class {
784
804
  httpStatus: a.status
785
805
  };
786
806
  } catch (e) {
787
- throw e instanceof y ? e : new y(`Failed to end session: ${e instanceof Error ? e.message : "Unknown error"}`);
807
+ throw e instanceof v ? e : new v(`Failed to end session: ${e instanceof Error ? e.message : "Unknown error"}`);
788
808
  }
789
809
  }
790
810
  async getSessionStatus(e, t, n, r) {
791
811
  try {
792
812
  let i = t ?? this.currentSession?.session_id;
793
- if (!i) throw new y("No active session. Provide a sessionId or start a session first.");
813
+ if (!i) throw new v("No active session. Provide a sessionId or start a session first.");
794
814
  this.validator.validateSessionId(i);
795
815
  let a = new URLSearchParams();
796
816
  n && a.set("template_id", n), r && a.set("version", r);
@@ -806,13 +826,13 @@ var B = class {
806
826
  httpStatus: c.status
807
827
  };
808
828
  } catch (e) {
809
- throw e instanceof y ? e : new y(`Failed to get session status: ${e instanceof Error ? e.message : "Unknown error"}`);
829
+ throw e instanceof v ? e : new v(`Failed to get session status: ${e instanceof Error ? e.message : "Unknown error"}`);
810
830
  }
811
831
  }
812
832
  async patchSession(e, t, n) {
813
833
  try {
814
834
  let r = n ?? this.currentSession?.session_id;
815
- if (!r) throw new y("No active session. Provide a sessionId or start a session first.");
835
+ if (!r) throw new v("No active session. Provide a sessionId or start a session first.");
816
836
  this.validator.validateSessionId(r), this.validator.validatePatchSessionRequest(t);
817
837
  let i = `${e}/sessions/${r}`;
818
838
  this.debug && console.log("[ScribeSDK] Patching session:", r, t);
@@ -826,13 +846,13 @@ var B = class {
826
846
  httpStatus: a.status
827
847
  };
828
848
  } catch (e) {
829
- throw e instanceof y ? e : new y(`Failed to patch session: ${e instanceof Error ? e.message : "Unknown error"}`);
849
+ throw e instanceof v ? e : new v(`Failed to patch session: ${e instanceof Error ? e.message : "Unknown error"}`);
830
850
  }
831
851
  }
832
852
  async processTemplate(e, t, n) {
833
853
  try {
834
854
  let r = n ?? this.currentSession?.session_id;
835
- if (!r) throw new y("No active session. Provide a sessionId or start a session first.");
855
+ if (!r) throw new v("No active session. Provide a sessionId or start a session first.");
836
856
  this.validator.validateSessionId(r);
837
857
  let i = `${e}/sessions/${r}/process/template/${encodeURIComponent(t)}`;
838
858
  this.debug && console.log("[ScribeSDK] Processing template:", t, "for session:", r);
@@ -845,13 +865,13 @@ var B = class {
845
865
  httpStatus: a.status
846
866
  };
847
867
  } catch (e) {
848
- throw e instanceof y ? e : new y(`Failed to process template: ${e instanceof Error ? e.message : "Unknown error"}`);
868
+ throw e instanceof v ? e : new v(`Failed to process template: ${e instanceof Error ? e.message : "Unknown error"}`);
849
869
  }
850
870
  }
851
871
  async pollForCompletion(e, t, n, r, i) {
852
872
  try {
853
873
  let a = t ?? this.currentSession?.session_id;
854
- if (!a) throw new y("No active session. Provide a sessionId or start a session first.");
874
+ if (!a) throw new v("No active session. Provide a sessionId or start a session first.");
855
875
  let o = n?.maxAttempts ?? 60, s = n?.intervalMs ?? 2e3, c = n?.timeoutMs, l = c !== void 0 && c > 0 ? Date.now() + c : void 0;
856
876
  this.debug && console.log("[ScribeSDK] Polling for completion:", a, {
857
877
  maxAttempts: o,
@@ -859,8 +879,8 @@ var B = class {
859
879
  timeoutMs: c
860
880
  });
861
881
  for (let t = 1; t <= o; t++) {
862
- if (n?.signal?.aborted) throw new y("Polling was aborted", "polling_aborted", void 0, { session_id: a });
863
- if (l !== void 0 && Date.now() >= l) throw new y(`Polling timed out after ${c}ms for session '${a}'`, "polling_timeout", void 0, {
882
+ if (n?.signal?.aborted) throw new v("Polling was aborted", "polling_aborted", void 0, { session_id: a });
883
+ if (l !== void 0 && Date.now() >= l) throw new v(`Polling timed out after ${c}ms for session '${a}'`, "polling_timeout", void 0, {
864
884
  session_id: a,
865
885
  timeout_ms: c
866
886
  });
@@ -881,12 +901,12 @@ var B = class {
881
901
  await this.sleepWithAbort(e, n?.signal);
882
902
  }
883
903
  }
884
- throw new y(`Polling timed out after ${o} attempts for session '${a}'`, "polling_timeout", void 0, {
904
+ throw new v(`Polling timed out after ${o} attempts for session '${a}'`, "polling_timeout", void 0, {
885
905
  session_id: a,
886
906
  max_attempts: o
887
907
  });
888
908
  } catch (e) {
889
- throw e instanceof y ? e : new y(`Failed to poll session: ${e instanceof Error ? e.message : "Unknown error"}`);
909
+ throw e instanceof v ? e : new v(`Failed to poll session: ${e instanceof Error ? e.message : "Unknown error"}`);
890
910
  }
891
911
  }
892
912
  getCurrentSession() {
@@ -904,22 +924,22 @@ var B = class {
904
924
  sleepWithAbort(e, t) {
905
925
  return t ? new Promise((n, r) => {
906
926
  if (t.aborted) {
907
- r(new y("Polling was aborted", "polling_aborted"));
927
+ r(new v("Polling was aborted", "polling_aborted"));
908
928
  return;
909
929
  }
910
930
  let i = setTimeout(n, e);
911
931
  t.addEventListener("abort", () => {
912
- clearTimeout(i), r(new y("Polling was aborted", "polling_aborted"));
932
+ clearTimeout(i), r(new v("Polling was aborted", "polling_aborted"));
913
933
  }, { once: !0 });
914
934
  }) : this.sleep(e);
915
935
  }
916
- }, H = 1024, U = 16e3;
917
- H / U, U / H;
918
- var fe = {
936
+ }, V = 1024, H = 16e3;
937
+ V / H, H / V;
938
+ var U = {
919
939
  m4a: "audio/m4a",
920
940
  wav: "audio/wav",
921
941
  mp3: "audio/mpeg"
922
- }, pe = class {
942
+ }, he = class {
923
943
  constructor(e, t) {
924
944
  this.vadPast = [], this.lastClipIndex = 0, this.silDurationAcc = 0, this.micVad = null, this.micStream = null, this.isLoading = !0, this.isRecording = !1, this.noSpeechStartTime = null, this.lastWarningTime = null;
925
945
  let n = e.samplingRate;
@@ -1051,7 +1071,7 @@ var fe = {
1051
1071
  } catch {}
1052
1072
  this.micStream = null;
1053
1073
  }
1054
- }, me = class {
1074
+ }, ge = class {
1055
1075
  constructor(e, t) {
1056
1076
  this.currentSampleLength = 0, this.currentFrameLength = 0, this.samplingRate = e, this.incrementalAllocationSize = Math.floor(e * t), this.buffer = new Float32Array(this.incrementalAllocationSize);
1057
1077
  }
@@ -1101,7 +1121,7 @@ var fe = {
1101
1121
  formatTimestamp(e) {
1102
1122
  return `${Math.floor(e / 60).toString().padStart(2, "0")}:${(e % 60).toFixed(6).padStart(9, "0")}`;
1103
1123
  }
1104
- }, he = class {
1124
+ }, _e = class {
1105
1125
  constructor() {
1106
1126
  this.chunks = [], this.successfulUploads = [], this.totalRawSamples = 0, this.totalRawFrames = 0, this.totalInsertedSamples = 0, this.totalInsertedFrames = 0;
1107
1127
  }
@@ -1200,7 +1220,7 @@ var fe = {
1200
1220
  };
1201
1221
  //#endregion
1202
1222
  //#region src/audio/mp3-encoder.ts
1203
- function ge(e, t = U, r = 128) {
1223
+ function ve(e, t = H, r = 128) {
1204
1224
  try {
1205
1225
  let i = new n.Mp3Encoder(1, t, r), a = new Int16Array(e.length);
1206
1226
  for (let t = 0; t < e.length; t++) {
@@ -1211,7 +1231,7 @@ function ge(e, t = U, r = 128) {
1211
1231
  s && s.length > 0 && o.push(s);
1212
1232
  let c = i.flush();
1213
1233
  return c && c.length > 0 && o.push(c), o.length === 0 ? null : {
1214
- blob: new Blob(o, { type: fe.mp3 }),
1234
+ blob: new Blob(o, { type: U.mp3 }),
1215
1235
  chunks: o
1216
1236
  };
1217
1237
  } catch (e) {
@@ -1220,25 +1240,25 @@ function ge(e, t = U, r = 128) {
1220
1240
  }
1221
1241
  //#endregion
1222
1242
  //#region src/storage/aws-s3-provider.ts
1223
- var _e = e.object({
1243
+ var ye = e.object({
1224
1244
  uploadData: e.object({
1225
1245
  url: e.string().min(1, "uploadData.url is required"),
1226
1246
  fields: e.record(e.string(), e.string())
1227
1247
  }),
1228
1248
  folderPath: e.string().optional(),
1229
1249
  txn_id: e.string().optional()
1230
- }), ve = "key", ye = "${filename}", W = "Content-Type", be = "audio/mp3", G = class {
1250
+ }), be = "key", xe = "${filename}", W = "Content-Type", Se = "audio/mp3", G = class {
1231
1251
  constructor() {
1232
1252
  this.name = "aws";
1233
1253
  }
1234
1254
  prepareUpload({ fileName: e, blob: t, upload: n }) {
1235
- let r = _e.safeParse(n);
1236
- if (!r.success) throw new O(`Invalid AWS upload payload in session response: ${r.error.message}`, [e]);
1255
+ let r = ye.safeParse(n);
1256
+ if (!r.success) throw new E(`Invalid AWS upload payload in session response: ${r.error.message}`, [e]);
1237
1257
  let { uploadData: i } = r.data, a = {};
1238
- for (let [t, n] of Object.entries(i.fields)) a[t] = t === ve ? n.split(ye).join(e) : n;
1258
+ for (let [t, n] of Object.entries(i.fields)) a[t] = t === be ? n.split(xe).join(e) : n;
1239
1259
  if (!(W in a)) {
1240
1260
  let e = t?.type;
1241
- a[W] = e && e.startsWith("audio/") ? e : be;
1261
+ a[W] = e && e.startsWith("audio/") ? e : Se;
1242
1262
  }
1243
1263
  return {
1244
1264
  url: i.url,
@@ -1254,12 +1274,12 @@ var _e = e.object({
1254
1274
  function q(e) {
1255
1275
  return typeof e == "string" ? e.trim().toLowerCase() : "";
1256
1276
  }
1257
- function xe(e) {
1277
+ function Ce(e) {
1258
1278
  return q(e) in K;
1259
1279
  }
1260
1280
  function J(e) {
1261
1281
  let t = K[q(e)];
1262
- if (!t) throw new k(e);
1282
+ if (!t) throw new D(e);
1263
1283
  return t();
1264
1284
  }
1265
1285
  //#endregion
@@ -1285,7 +1305,7 @@ async function Y(e, t) {
1285
1305
  }
1286
1306
  //#endregion
1287
1307
  //#region src/worker/worker-manager.ts
1288
- var Se = class {
1308
+ var we = class {
1289
1309
  constructor(e, t, n, r) {
1290
1310
  if (this.worker = null, this.port = null, this.useWorker = !1, this.uploadPayload = {}, this.storageProviderName = "", this.uploadHeaders = {}, this.refreshUploadUrl = null, this.inFlightRefresh = null, this.pendingUploads = /* @__PURE__ */ new Set(), this.allUploadsResolver = null, this.callbackRegistry = e, this.fileManager = t, this.transport = n, !r?.forceMainThread && typeof SharedWorker < "u" && r?.workerScriptUrl) try {
1291
1311
  this.worker = new SharedWorker(r.workerScriptUrl, { name: "scribe-sdk-worker" }), this.port = this.worker.port, this.port.onmessage = (e) => {
@@ -1299,7 +1319,7 @@ var Se = class {
1299
1319
  this.uploadPayload = e, this.storageProviderName = t, this.uploadHeaders = n, this.refreshUploadUrl = r ?? null, J(t);
1300
1320
  }
1301
1321
  compressAndUpload(e, t, n) {
1302
- let r = e.length / U;
1322
+ let r = e.length / H;
1303
1323
  if (r > 27) {
1304
1324
  this.fileManager.markFailure(n, new Blob(), `Chunk exceeds maximum length: ${r.toFixed(1)}s > 25s`), this.callbackRegistry.dispatch("onError", {
1305
1325
  type: m.VALIDATION_ERROR,
@@ -1437,7 +1457,7 @@ var Se = class {
1437
1457
  async doMainThreadUpload(e, t, n) {
1438
1458
  let r = null;
1439
1459
  try {
1440
- let i = ge(e);
1460
+ let i = ve(e);
1441
1461
  if (!i) {
1442
1462
  this.fileManager.markFailure(n, new Blob(), "MP3 encoding failed"), this.callbackRegistry.dispatch("onUploadEvent", {
1443
1463
  type: f.FAILED,
@@ -1503,7 +1523,7 @@ var Se = class {
1503
1523
  }
1504
1524
  }, X = class {
1505
1525
  constructor(e, t, n, r) {
1506
- this._isPaused = !1, this.initialized = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.callbackRegistry = e, this.bufferManager = new me(U, 25), this.fileManager = new he();
1526
+ this._isPaused = !1, this.initialized = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.callbackRegistry = e, this.bufferManager = new ge(H, 25), this.fileManager = new _e();
1507
1527
  let i = {
1508
1528
  prefChunkLength: n?.prefChunkLength ?? 10,
1509
1529
  despChunkLength: n?.despChunkLength ?? 20,
@@ -1514,7 +1534,7 @@ var Se = class {
1514
1534
  shortSilenceThreshold: n?.shortSilenceThreshold,
1515
1535
  longSilenceThreshold: n?.longSilenceThreshold
1516
1536
  };
1517
- this.vadClient = new pe(i, e), this.workerManager = new Se(e, this.fileManager, t, r), this.wireVadCallbacks();
1537
+ this.vadClient = new he(i, e), this.workerManager = new we(e, this.fileManager, t, r), this.wireVadCallbacks();
1518
1538
  }
1519
1539
  initialize(e, t) {
1520
1540
  if (!t.upload || typeof t.upload != "object") throw Error("Upload payload is required for chunked recording");
@@ -1757,7 +1777,7 @@ var Se = class {
1757
1777
  this.recorder = null, this.activeSession = null, this.activeBaseUrl = "", this.activeUploadUrlRefresher = null, this._isRecording = !1, this._isStarting = !1, this._startGeneration = 0, this.retryContext = null, this.callbackRegistry = e, this.sessionManager = t, this.discoveryManager = n, this.transport = r, this.config = i ?? {};
1758
1778
  }
1759
1779
  async start(e, t, n) {
1760
- if (this._isRecording || this._isStarting) throw new y("Recording is already in progress. Stop the current recording first.");
1780
+ if (this._isRecording || this._isStarting) throw new v("Recording is already in progress. Stop the current recording first.");
1761
1781
  this._isStarting = !0;
1762
1782
  let r = ++this._startGeneration;
1763
1783
  this.retryContext = null, this.activeBaseUrl = e;
@@ -1781,7 +1801,7 @@ var Se = class {
1781
1801
  } catch (e) {
1782
1802
  throw r === this._startGeneration && this.dispatchStartError(m.TRANSPORT_ERROR, g.SESSION_CREATION_FAILED, e), e;
1783
1803
  }
1784
- if (r !== this._startGeneration) throw new y("Recording start was superseded by a concurrent operation.");
1804
+ if (r !== this._startGeneration) throw new v("Recording start was superseded by a concurrent operation.");
1785
1805
  this.activeSession = a;
1786
1806
  let c;
1787
1807
  try {
@@ -1825,7 +1845,7 @@ var Se = class {
1825
1845
  try {
1826
1846
  l.reset();
1827
1847
  } catch {}
1828
- throw new y("Recording start was superseded by a concurrent operation.");
1848
+ throw new v("Recording start was superseded by a concurrent operation.");
1829
1849
  }
1830
1850
  return this._isRecording = !0, this.callbackRegistry.dispatch("onRecordingStateChange", {
1831
1851
  type: u.STARTED,
@@ -1839,7 +1859,7 @@ var Se = class {
1839
1859
  }
1840
1860
  }
1841
1861
  async startWithExistingSession(e, t, n, r) {
1842
- if (this._isRecording || this._isStarting) throw new y("Recording is already in progress. Stop the current recording first.");
1862
+ if (this._isRecording || this._isStarting) throw new v("Recording is already in progress. Stop the current recording first.");
1843
1863
  this._isStarting = !0;
1844
1864
  let i = ++this._startGeneration;
1845
1865
  this.retryContext = null, this.activeBaseUrl = e;
@@ -1883,7 +1903,7 @@ var Se = class {
1883
1903
  try {
1884
1904
  s.reset();
1885
1905
  } catch {}
1886
- throw new y("Recording start was superseded by a concurrent operation.");
1906
+ throw new v("Recording start was superseded by a concurrent operation.");
1887
1907
  }
1888
1908
  return this._isRecording = !0, this.callbackRegistry.dispatch("onRecordingStateChange", {
1889
1909
  type: u.STARTED,
@@ -1929,7 +1949,7 @@ var Se = class {
1929
1949
  if (i.length > 0) try {
1930
1950
  i = (await this.retryFailedUploads()).data.stillFailed;
1931
1951
  } catch (e) {
1932
- console.error("[ScribeSDK] Internal retry pass failed:", e), e instanceof O && (i = e.failedFiles), this.callbackRegistry.dispatch("onError", {
1952
+ console.error("[ScribeSDK] Internal retry pass failed:", e), e instanceof E && (i = e.failedFiles), this.callbackRegistry.dispatch("onError", {
1933
1953
  type: m.TRANSPORT_ERROR,
1934
1954
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1935
1955
  error: {
@@ -1962,7 +1982,7 @@ var Se = class {
1962
1982
  }
1963
1983
  }
1964
1984
  async finalizeSession(e, t) {
1965
- if (!this.activeSession) throw new y("No active session to finalize", g.SESSION_END_FAILED);
1985
+ if (!this.activeSession) throw new v("No active session to finalize", g.SESSION_END_FAILED);
1966
1986
  try {
1967
1987
  let n = await this.sessionManager.endSession(this.activeBaseUrl, {
1968
1988
  audio_files_sent: e,
@@ -2025,7 +2045,7 @@ var Se = class {
2025
2045
  this.activeSession && this.activeSession.session_id === e && (this.activeSession = null, this.activeBaseUrl = "", this.activeUploadUrlRefresher = null, this.retryContext = null);
2026
2046
  }
2027
2047
  async retryFailedUploads() {
2028
- if (this._isRecording) throw new y("Cannot retry uploads while recording is active.");
2048
+ if (this._isRecording) throw new v("Cannot retry uploads while recording is active.");
2029
2049
  if (!this.retryContext || this.retryContext.failedChunks.length === 0) return {
2030
2050
  data: {
2031
2051
  retried: 0,
@@ -2067,7 +2087,7 @@ var Se = class {
2067
2087
  }
2068
2088
  }), this.config.debug && console.log(`[ScribeSDK] Retry failed: ${o.fileName}`, e);
2069
2089
  }
2070
- if (r.length === 0 ? this.retryContext = null : this.retryContext.failedChunks = t.filter((e) => r.includes(e.fileName)), this.config.debug && console.log(`[ScribeSDK] Retry complete: ${i}/${n} succeeded`), r.length > 0) throw new O(`${r.length} upload(s) still failed after retry`, r);
2090
+ if (r.length === 0 ? this.retryContext = null : this.retryContext.failedChunks = t.filter((e) => r.includes(e.fileName)), this.config.debug && console.log(`[ScribeSDK] Retry complete: ${i}/${n} succeeded`), r.length > 0) throw new E(`${r.length} upload(s) still failed after retry`, r);
2071
2091
  return {
2072
2092
  data: {
2073
2093
  retried: n,
@@ -2093,7 +2113,9 @@ var Se = class {
2093
2113
  }
2094
2114
  buildUploadHeaders(e) {
2095
2115
  let t = {};
2096
- return e && (t.Authorization = `Bearer ${e}`), this.config.flavour && (t.flavour = this.config.flavour), t;
2116
+ e && (t.Authorization = `Bearer ${e}`), this.config.flavour && (t.flavour = this.config.flavour);
2117
+ let n = F();
2118
+ return n && (t[P] = n), t;
2097
2119
  }
2098
2120
  buildUploadUrlRefresher(e, t, n) {
2099
2121
  return () => this.fetchFreshUploadUrl(e, t, n);
@@ -2142,14 +2164,14 @@ var Se = class {
2142
2164
  partialCleanupAfterFailedFinalize() {
2143
2165
  this.recorder = null, this._isRecording = !1, this._isStarting = !1;
2144
2166
  }
2145
- }, Ce = class {
2167
+ }, Te = class {
2146
2168
  constructor(e) {
2147
2169
  this.isInitialized = !1, this.validateConfig(e), this.config = {
2148
2170
  debug: !1,
2149
2171
  autoDiscovery: !0,
2150
2172
  mode: l.DIRECT,
2151
2173
  ...e
2152
- }, this.callbackRegistry = new A(), this.validator = new F(), this.transport = this.createTransport(), this.discoveryManager = new B(this.transport, this.validator, this.config.debug), this.sessionManager = new V(this.transport, this.validator, this.config.debug), this.recordingManager = new Q(this.callbackRegistry, this.sessionManager, this.discoveryManager, this.transport, {
2174
+ }, this.callbackRegistry = new O(), this.validator = new M(), this.transport = this.createTransport(), this.discoveryManager = new z(this.transport, this.validator, this.config.debug), this.sessionManager = new B(this.transport, this.validator, this.config.debug), this.recordingManager = new Q(this.callbackRegistry, this.sessionManager, this.discoveryManager, this.transport, {
2153
2175
  debug: this.config.debug,
2154
2176
  flavour: this.config.flavour,
2155
2177
  workerConfig: this.resolveWorkerConfig()
@@ -2177,7 +2199,7 @@ var Se = class {
2177
2199
  try {
2178
2200
  this.discoveryManager.getResolvedConfig();
2179
2201
  } catch (e) {
2180
- if (e instanceof b) throw e;
2202
+ if (e instanceof y) throw e;
2181
2203
  }
2182
2204
  return this.recordingManager.start(t, e, this.config.accessToken);
2183
2205
  });
@@ -2216,9 +2238,9 @@ var Se = class {
2216
2238
  }
2217
2239
  async uploadAudioFile(e, t, n) {
2218
2240
  return this.wrapResult(async () => {
2219
- if (!e || e.size === 0) throw new b("A non-empty audio file is required");
2220
- if (!t || !t.trim()) throw new b("fileName is required");
2221
- if (!n || typeof n != "object") throw new b("upload (upload_url payload) is required");
2241
+ if (!e || e.size === 0) throw new y("A non-empty audio file is required");
2242
+ if (!t || !t.trim()) throw new y("fileName is required");
2243
+ if (!n || typeof n != "object") throw new y("upload (upload_url payload) is required");
2222
2244
  let r = await Y(this.transport, {
2223
2245
  fileName: t,
2224
2246
  blob: e,
@@ -2333,7 +2355,7 @@ var Se = class {
2333
2355
  }
2334
2356
  }
2335
2357
  toScribeError(e) {
2336
- return e instanceof y ? e : new y(e instanceof Error ? e.message : "Unknown error");
2358
+ return e instanceof v ? e : new v(e instanceof Error ? e.message : "Unknown error");
2337
2359
  }
2338
2360
  createTransport() {
2339
2361
  let e = () => this.callbackRegistry.hasHandlers("onTokenRequired") ? new Promise((e) => {
@@ -2345,8 +2367,8 @@ var Se = class {
2345
2367
  } });
2346
2368
  }) : Promise.resolve(void 0);
2347
2369
  if (this.config.mode === l.IPC) {
2348
- if (!this.config.ipcTransport) throw new b("ipcTransport (IpcBridge) is required when mode is \"ipc\"");
2349
- return new R({
2370
+ if (!this.config.ipcTransport) throw new y("ipcTransport (IpcBridge) is required when mode is \"ipc\"");
2371
+ return new L({
2350
2372
  bridge: this.config.ipcTransport,
2351
2373
  accessToken: this.config.accessToken,
2352
2374
  flavour: this.config.flavour,
@@ -2354,7 +2376,7 @@ var Se = class {
2354
2376
  onUnauthorized: e
2355
2377
  });
2356
2378
  }
2357
- return new L({
2379
+ return new I({
2358
2380
  accessToken: this.config.accessToken,
2359
2381
  flavour: this.config.flavour,
2360
2382
  debug: this.config.debug,
@@ -2383,10 +2405,10 @@ var Se = class {
2383
2405
  }
2384
2406
  }
2385
2407
  validateConfig(e) {
2386
- if (!e.baseUrl) throw new b("baseUrl is required");
2408
+ if (!e.baseUrl) throw new y("baseUrl is required");
2387
2409
  }
2388
2410
  }, $ = "worker.bundle.js";
2389
- function we() {
2411
+ function Ee() {
2390
2412
  if (typeof window < "u" && window.__MEDSCRIBE_WORKER_URL__) return window.__MEDSCRIBE_WORKER_URL__;
2391
2413
  if (typeof document < "u" && document.currentScript) {
2392
2414
  let e = document.currentScript.src;
@@ -2394,11 +2416,11 @@ function we() {
2394
2416
  }
2395
2417
  return `/${$}`;
2396
2418
  }
2397
- async function Te(e) {
2419
+ async function De(e) {
2398
2420
  let t = e ?? `https://cdn.jsdelivr.net/npm/med-scribe-alliance-ts-sdk/dist/${$}`, n = await fetch(t);
2399
2421
  if (!n.ok) throw Error(`Failed to fetch worker script: ${n.status} ${n.statusText}`);
2400
2422
  let r = await n.text(), i = new Blob([r], { type: "application/javascript" });
2401
2423
  return URL.createObjectURL(i);
2402
2424
  }
2403
2425
  //#endregion
2404
- export { d as AudioEventType, S as AuthenticationError, G as AwsS3StorageProvider, A as CallbackRegistry, c as CommunicationProtocol, h as DiscardReason, x as DiscoveryError, B as DiscoveryManager, g as ErrorCode, m as ErrorEventType, C as ForbiddenError, _ as HttpStatus, L as HttpTransport, R as IpcTransport, T as RateLimitError, Q as RecordingManager, u as RecordingState, Ce as ScribeClient, y as ScribeError, p as SessionEventType, ee as SessionExpiredError, V as SessionManager, w as SessionNotFoundError, a as SessionStatus, o as TemplateStatus, E as TransportError, l as TransportMode, k as UnsupportedStorageProviderError, O as UploadError, f as UploadEventType, s as UploadType, b as ValidationError, F as Validator, D as WorkerError, Te as createWorkerBlobUrl, J as getStorageProvider, we as getWorkerUrl, xe as isStorageProviderSupported };
2426
+ export { d as AudioEventType, x as AuthenticationError, G as AwsS3StorageProvider, O as CallbackRegistry, c as CommunicationProtocol, h as DiscardReason, b as DiscoveryError, z as DiscoveryManager, g as ErrorCode, m as ErrorEventType, S as ForbiddenError, _ as HttpStatus, I as HttpTransport, L as IpcTransport, w as RateLimitError, Q as RecordingManager, u as RecordingState, Te as ScribeClient, v as ScribeError, p as SessionEventType, te as SessionExpiredError, B as SessionManager, C as SessionNotFoundError, a as SessionStatus, o as TemplateStatus, T as TransportError, l as TransportMode, D as UnsupportedStorageProviderError, E as UploadError, f as UploadEventType, s as UploadType, y as ValidationError, M as Validator, ne as WorkerError, De as createWorkerBlobUrl, J as getStorageProvider, Ee as getWorkerUrl, Ce as isStorageProviderSupported };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "med-scribe-alliance-ts-sdk",
3
- "version": "2.0.44",
3
+ "version": "2.0.45",
4
4
  "description": "TypeScript SDK for the MedScribe Alliance Protocol",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",