med-scribe-alliance-ts-sdk 2.0.45 → 2.0.47
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.
- package/README.md +3 -3
- package/dist/index.d.ts +16 -10
- package/dist/index.mjs +138 -101
- package/dist/worker.bundle.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -198,7 +198,7 @@ await client.reset(); // stops recording if active, clears all state and caches
|
|
|
198
198
|
- **`cancelSession()` does NOT trigger processing.** It stops the recorder locally, cleans up state, and tells the server the session is cancelled. No `endSession` call is made to the backend.
|
|
199
199
|
- **All async methods return `SDKResult<T>`, never throw.** Always check `result.success` before accessing `result.data`. Errors are in `result.error`.
|
|
200
200
|
- **The SDK validates inputs against the discovery document.** If the server doesn't support an upload type, language, or model you requested, you'll get a `ValidationError` before the API call is made.
|
|
201
|
-
- **Audio uploads go to a server-selected storage backend.**
|
|
201
|
+
- **Audio uploads go to a server-selected storage backend.** The create-session response decides it: `storage_provider: "aws"` with an `upload_url` object means a direct S3 presigned POST; an `upload_url` string means the audio is posted to the backend endpoint instead. Discovery's `capabilities.storage_providers` only advertises which backends the deployment can mint URLs for.
|
|
202
202
|
|
|
203
203
|
- **SharedWorker is optional.** If you provide `workerScriptUrl`, the SDK offloads MP3 compression and upload to a SharedWorker. If the worker fails to load, it silently falls back to main-thread processing.
|
|
204
204
|
- **Microphone permission is requested on `startRecording()`.** The browser will prompt the user for mic access. If denied, you'll get an error via `onError` callback.
|
|
@@ -390,7 +390,7 @@ interface RecordingOptions {
|
|
|
390
390
|
| `isRecordingPaused()` | `boolean` | Whether the active recording is paused. |
|
|
391
391
|
| `retryFailedUploads()` | `SDKResult<RetryUploadResult>` | Retry uploads that failed during the last recording. |
|
|
392
392
|
| `hasFailedUploads()` | `boolean` | Whether there are retryable failed uploads. |
|
|
393
|
-
| `uploadAudioFile(file, fileName, upload)` | `SDKResult<UploadAudioFileResult>` | Upload one pre-recorded audio file
|
|
393
|
+
| `uploadAudioFile(file, fileName, upload, options?)` | `SDKResult<UploadAudioFileResult>` | Upload one pre-recorded audio file using a session's `upload_url` (string or presigned object). No mic/recorder. The provider is taken from the session's `storage_provider`, or inferred from the payload shape; `options.storageProvider` overrides both. |
|
|
394
394
|
|
|
395
395
|
### Session
|
|
396
396
|
|
|
@@ -628,7 +628,7 @@ console.log(result.data.session_id);
|
|
|
628
628
|
| `TransportError` | — | Network / IPC failure |
|
|
629
629
|
| `WorkerError` | — | SharedWorker failure |
|
|
630
630
|
| `UploadError` | — | Audio upload failure (failed transfer, or malformed `upload_url` payload). Has `failedFiles: string[]`. |
|
|
631
|
-
| `UnsupportedStorageProviderError` | — |
|
|
631
|
+
| `UnsupportedStorageProviderError` | — | The session's `storage_provider` names a backend this SDK build has no wrapper for. Thrown at `startRecording`. Has `provider: string`. |
|
|
632
632
|
|
|
633
633
|
## SharedWorker Support
|
|
634
634
|
|
package/dist/index.d.ts
CHANGED
|
@@ -323,7 +323,7 @@ export interface CapabilitiesInfo {
|
|
|
323
323
|
upload_methods?: string[];
|
|
324
324
|
webhook_delivery?: boolean;
|
|
325
325
|
client_sdk_delivery?: boolean;
|
|
326
|
-
|
|
326
|
+
storage_providers?: string[];
|
|
327
327
|
}
|
|
328
328
|
export interface ModelConfig {
|
|
329
329
|
id: string;
|
|
@@ -352,7 +352,7 @@ export interface ResolvedConfig {
|
|
|
352
352
|
autoDetectLanguage: boolean;
|
|
353
353
|
supportedAudioFormats: string[];
|
|
354
354
|
supportedUploadMethods: string[];
|
|
355
|
-
|
|
355
|
+
storageProviders: string[];
|
|
356
356
|
maxChunkDurationSeconds: number;
|
|
357
357
|
/** modelId -> max session duration in seconds */
|
|
358
358
|
maxSessionDurationSeconds: Map<string, number>;
|
|
@@ -381,14 +381,14 @@ export interface CreateSessionRequest {
|
|
|
381
381
|
patient_details?: PatientDetails;
|
|
382
382
|
session_id?: string;
|
|
383
383
|
}
|
|
384
|
-
|
|
385
|
-
export type SessionUploadInfo = Record<string, unknown>;
|
|
384
|
+
export type SessionUploadInfo = string | Record<string, unknown>;
|
|
386
385
|
export interface CreateSessionResponse {
|
|
387
386
|
session_id: string;
|
|
388
387
|
status: SessionStatus;
|
|
389
388
|
created_at: string;
|
|
390
389
|
expires_at: string;
|
|
391
390
|
upload_url: SessionUploadInfo;
|
|
391
|
+
storage_provider?: string | null;
|
|
392
392
|
patient_details?: PatientDetails;
|
|
393
393
|
}
|
|
394
394
|
export interface EndSessionRequest {
|
|
@@ -818,7 +818,9 @@ export declare class ScribeClient {
|
|
|
818
818
|
* @param fileName - Storage object name, e.g. "1.mp3".
|
|
819
819
|
* @param upload - The `upload_url` payload from the create-session response.
|
|
820
820
|
*/
|
|
821
|
-
uploadAudioFile(file: Blob, fileName: string, upload: SessionUploadInfo
|
|
821
|
+
uploadAudioFile(file: Blob, fileName: string, upload: SessionUploadInfo, options?: {
|
|
822
|
+
storageProvider?: string | null;
|
|
823
|
+
}): Promise<SDKResult<UploadAudioFileResult>>;
|
|
822
824
|
/**
|
|
823
825
|
* Create a session directly (without starting a recording).
|
|
824
826
|
*/
|
|
@@ -934,8 +936,7 @@ export declare class ScribeClient {
|
|
|
934
936
|
*/
|
|
935
937
|
private createTransport;
|
|
936
938
|
private resolveWorkerConfig;
|
|
937
|
-
|
|
938
|
-
private getStorageProviderName;
|
|
939
|
+
private providerForUpload;
|
|
939
940
|
/**
|
|
940
941
|
* Get the effective base URL — prefer discovery's base_url, fall back to config.
|
|
941
942
|
*/
|
|
@@ -965,7 +966,6 @@ export interface PreparedUpload {
|
|
|
965
966
|
attachAuth: boolean;
|
|
966
967
|
}
|
|
967
968
|
export interface StorageProvider {
|
|
968
|
-
/** Matches discovery's `capabilities.storage_provider`. */
|
|
969
969
|
readonly name: string;
|
|
970
970
|
/** @throws UploadError if the upload payload is malformed. */
|
|
971
971
|
prepareUpload(ctx: UploadContext): PreparedUpload;
|
|
@@ -974,6 +974,14 @@ export declare class AwsS3StorageProvider implements StorageProvider {
|
|
|
974
974
|
readonly name = "aws";
|
|
975
975
|
prepareUpload({ fileName, blob, upload }: UploadContext): PreparedUpload;
|
|
976
976
|
}
|
|
977
|
+
export declare class BackendStorageProvider implements StorageProvider {
|
|
978
|
+
readonly name = "backend";
|
|
979
|
+
prepareUpload({ fileName, blob, upload }: UploadContext): PreparedUpload;
|
|
980
|
+
}
|
|
981
|
+
export declare const AWS_STORAGE_PROVIDER = "aws";
|
|
982
|
+
export declare const BACKEND_STORAGE_PROVIDER = "backend";
|
|
983
|
+
export declare function hasUploadPayload(upload: unknown): upload is SessionUploadInfo;
|
|
984
|
+
export declare function resolveStorageProvider(sessionProvider: string | null | undefined, upload: SessionUploadInfo | undefined): string;
|
|
977
985
|
export declare function isStorageProviderSupported(name: string): boolean;
|
|
978
986
|
/** @throws UnsupportedStorageProviderError if no wrapper is registered. */
|
|
979
987
|
export declare function getStorageProvider(name: string): StorageProvider;
|
|
@@ -1245,9 +1253,7 @@ export declare class RecordingManager {
|
|
|
1245
1253
|
* Create the appropriate recorder based on upload type.
|
|
1246
1254
|
*/
|
|
1247
1255
|
private createRecorder;
|
|
1248
|
-
/** Storage provider name from discovery; defaults to 'aws'. */
|
|
1249
1256
|
private getStorageProviderName;
|
|
1250
|
-
/** Validate the provider has a wrapper (throws UnsupportedStorageProviderError) and return its name. */
|
|
1251
1257
|
private resolveStorageProviderName;
|
|
1252
1258
|
/**
|
|
1253
1259
|
* Build upload headers from the current auth state.
|
package/dist/index.mjs
CHANGED
|
@@ -164,14 +164,14 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
164
164
|
upload_methods: e.array(e.string()).optional(),
|
|
165
165
|
webhook_delivery: e.boolean().optional(),
|
|
166
166
|
client_sdk_delivery: e.boolean().optional(),
|
|
167
|
-
|
|
167
|
+
storage_providers: e.array(e.string()).optional()
|
|
168
168
|
}),
|
|
169
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
|
-
}),
|
|
174
|
+
}), oe = 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
|
-
}),
|
|
190
|
+
}), se = 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
|
-
}),
|
|
193
|
+
}), ce = e.object({
|
|
194
194
|
user_status: e.string().optional(),
|
|
195
195
|
processing_status: e.string().optional(),
|
|
196
196
|
patient_details: e.object({
|
|
@@ -203,25 +203,26 @@ 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
|
-
}),
|
|
206
|
+
}), le = 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(),
|
|
210
210
|
expires_at: e.string(),
|
|
211
|
-
upload_url: e.record(e.string(), e.unknown()),
|
|
211
|
+
upload_url: e.union([e.string().min(1, "upload_url is required"), e.record(e.string(), e.unknown())]),
|
|
212
|
+
storage_provider: e.string().nullish(),
|
|
212
213
|
patient_details: e.object({
|
|
213
214
|
name: e.string().optional(),
|
|
214
215
|
age: e.union([e.string(), e.number()]).optional(),
|
|
215
216
|
gender: e.string().optional(),
|
|
216
217
|
mobile: e.number().optional()
|
|
217
218
|
}).nullable().optional()
|
|
218
|
-
}),
|
|
219
|
+
}), ue = e.object({
|
|
219
220
|
session_id: e.string().min(1, "session_id is required"),
|
|
220
221
|
status: e.string(),
|
|
221
222
|
message: e.string(),
|
|
222
223
|
audio_files_received: e.number().int(),
|
|
223
224
|
audio_files: e.array(e.string())
|
|
224
|
-
}),
|
|
225
|
+
}), de = e.object({
|
|
225
226
|
session_id: e.string().min(1, "session_id is required"),
|
|
226
227
|
status: e.string(),
|
|
227
228
|
created_at: e.string(),
|
|
@@ -252,16 +253,16 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
252
253
|
mobile: e.number().optional()
|
|
253
254
|
}).nullable().optional(),
|
|
254
255
|
message: e.string().optional()
|
|
255
|
-
}),
|
|
256
|
+
}), fe = e.object({
|
|
256
257
|
session_id: e.string().min(1, "session_id is required"),
|
|
257
258
|
status: e.string(),
|
|
258
259
|
message: e.string()
|
|
259
|
-
}),
|
|
260
|
+
}), pe = e.object({
|
|
260
261
|
session_id: e.string().min(1, "session_id is required"),
|
|
261
262
|
template_id: e.string(),
|
|
262
263
|
status: e.string(),
|
|
263
264
|
message: e.string()
|
|
264
|
-
}),
|
|
265
|
+
}), me = e.string().min(1, "Session ID is required"), he = e.object({
|
|
265
266
|
templates: e.array(e.string()).min(1, "templates must contain at least one item").max(2, "templates cannot have more than 2 items"),
|
|
266
267
|
uploadType: e.string().optional(),
|
|
267
268
|
communicationProtocol: e.string().optional(),
|
|
@@ -279,39 +280,39 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
279
280
|
}).optional(),
|
|
280
281
|
sessionId: e.string().optional(),
|
|
281
282
|
version: e.string().optional()
|
|
282
|
-
}),
|
|
283
|
+
}), k = class {
|
|
283
284
|
validateDiscoveryResponse(e) {
|
|
284
285
|
this.parseWithValidationError(ae, e, "Invalid discovery response");
|
|
285
286
|
}
|
|
286
287
|
validateCreateSessionRequest(e) {
|
|
287
|
-
this.parseWithValidationError(
|
|
288
|
+
this.parseWithValidationError(oe, e, "Invalid CreateSessionRequest");
|
|
288
289
|
}
|
|
289
290
|
validateEndSessionRequest(e) {
|
|
290
|
-
this.parseWithValidationError(
|
|
291
|
+
this.parseWithValidationError(se, e, "Invalid EndSessionRequest");
|
|
291
292
|
}
|
|
292
293
|
validateCreateSessionResponse(e) {
|
|
293
|
-
this.parseWithValidationError(
|
|
294
|
+
this.parseWithValidationError(le, e, "Invalid CreateSessionResponse");
|
|
294
295
|
}
|
|
295
296
|
validateEndSessionResponse(e) {
|
|
296
|
-
this.parseWithValidationError(
|
|
297
|
+
this.parseWithValidationError(ue, e, "Invalid EndSessionResponse");
|
|
297
298
|
}
|
|
298
299
|
validateGetSessionStatusResponse(e) {
|
|
299
|
-
this.parseWithValidationError(
|
|
300
|
+
this.parseWithValidationError(de, e, "Invalid GetSessionStatusResponse");
|
|
300
301
|
}
|
|
301
302
|
validateSessionId(e) {
|
|
302
|
-
this.parseWithValidationError(
|
|
303
|
+
this.parseWithValidationError(me, e, "Invalid session ID");
|
|
303
304
|
}
|
|
304
305
|
validateRecordingOptions(e) {
|
|
305
|
-
this.parseWithValidationError(
|
|
306
|
+
this.parseWithValidationError(he, e, "Invalid RecordingOptions");
|
|
306
307
|
}
|
|
307
308
|
validatePatchSessionRequest(e) {
|
|
308
|
-
this.parseWithValidationError(
|
|
309
|
+
this.parseWithValidationError(ce, e, "Invalid PatchSessionRequest");
|
|
309
310
|
}
|
|
310
311
|
validatePatchSessionResponse(e) {
|
|
311
|
-
this.parseWithValidationError(
|
|
312
|
+
this.parseWithValidationError(fe, e, "Invalid PatchSessionResponse");
|
|
312
313
|
}
|
|
313
314
|
validateProcessTemplateResponse(e) {
|
|
314
|
-
this.parseWithValidationError(
|
|
315
|
+
this.parseWithValidationError(pe, e, "Invalid ProcessTemplateResponse");
|
|
315
316
|
}
|
|
316
317
|
validateAgainstDiscovery(e, t) {
|
|
317
318
|
try {
|
|
@@ -354,27 +355,27 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
354
355
|
};
|
|
355
356
|
//#endregion
|
|
356
357
|
//#region src/utils/retry.ts
|
|
357
|
-
async function
|
|
358
|
+
async function A(e, t = {}) {
|
|
358
359
|
let { maxRetries: n = 2, delayMs: r = ee, onRetry: i } = t, a = null;
|
|
359
360
|
for (let t = 0; t <= n; t++) try {
|
|
360
361
|
return await e();
|
|
361
362
|
} catch (e) {
|
|
362
|
-
if (a = e instanceof Error ? e : Error(String(e)),
|
|
363
|
+
if (a = e instanceof Error ? e : Error(String(e)), ge(e?.httpStatus ?? e?.statusCode ?? e?.status)) throw a;
|
|
363
364
|
if (t >= n || i && i(t + 1, a) === !1) break;
|
|
364
|
-
await
|
|
365
|
+
await _e(r);
|
|
365
366
|
}
|
|
366
367
|
throw a ?? /* @__PURE__ */ Error("Retry failed: unknown error");
|
|
367
368
|
}
|
|
368
|
-
function
|
|
369
|
+
function ge(e) {
|
|
369
370
|
return typeof e == "number" ? e >= 400 && e < 500 && e !== 408 && e !== 429 : !1;
|
|
370
371
|
}
|
|
371
|
-
function
|
|
372
|
+
function _e(e) {
|
|
372
373
|
return new Promise((t) => setTimeout(t, e));
|
|
373
374
|
}
|
|
374
375
|
//#endregion
|
|
375
376
|
//#region src/utils/timezone.ts
|
|
376
|
-
var
|
|
377
|
-
function
|
|
377
|
+
var j = "X-timezone";
|
|
378
|
+
function M() {
|
|
378
379
|
try {
|
|
379
380
|
return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
|
|
380
381
|
} catch {
|
|
@@ -383,7 +384,7 @@ function F() {
|
|
|
383
384
|
}
|
|
384
385
|
//#endregion
|
|
385
386
|
//#region src/transport/http-transport.ts
|
|
386
|
-
var
|
|
387
|
+
var N = class {
|
|
387
388
|
constructor(e) {
|
|
388
389
|
this.tokenRefreshPromise = null, this.accessToken = e.accessToken, this.flavour = e.flavour, this.debug = e.debug ?? !1, this.onUnauthorized = e.onUnauthorized;
|
|
389
390
|
}
|
|
@@ -392,7 +393,7 @@ var I = class {
|
|
|
392
393
|
}
|
|
393
394
|
async request(e) {
|
|
394
395
|
try {
|
|
395
|
-
return e.isUpload ? await
|
|
396
|
+
return e.isUpload ? await A(() => this.executeRequest(e), this.getRetryOptions(e)) : await this.executeRequest(e);
|
|
396
397
|
} catch (t) {
|
|
397
398
|
throw t instanceof v ? t : new T(`Network error: ${t instanceof Error ? t.message : "Unknown error"}`, {
|
|
398
399
|
url: e.url,
|
|
@@ -444,8 +445,8 @@ var I = class {
|
|
|
444
445
|
let t = {}, n = e.isUpload === !0 && e.attachAuth === !1;
|
|
445
446
|
if (e.isUpload ? e.uploadFormFields || (t["Content-Type"] = "audio/mp3") : (t["Content-Type"] = "application/json", t.Accept = "application/json"), !n) {
|
|
446
447
|
this.accessToken && (t.Authorization = `Bearer ${this.accessToken}`), this.flavour && (t.flavour = this.flavour);
|
|
447
|
-
let e =
|
|
448
|
-
e && (t[
|
|
448
|
+
let e = M();
|
|
449
|
+
e && (t[j] = e);
|
|
449
450
|
}
|
|
450
451
|
return e.headers && Object.assign(t, e.headers), t;
|
|
451
452
|
}
|
|
@@ -510,7 +511,7 @@ var I = class {
|
|
|
510
511
|
}
|
|
511
512
|
};
|
|
512
513
|
}
|
|
513
|
-
},
|
|
514
|
+
}, P = class {
|
|
514
515
|
constructor(e) {
|
|
515
516
|
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) => {
|
|
516
517
|
this.handleResponse(e);
|
|
@@ -521,7 +522,7 @@ var I = class {
|
|
|
521
522
|
}
|
|
522
523
|
async request(e) {
|
|
523
524
|
try {
|
|
524
|
-
return e.isUpload ? await
|
|
525
|
+
return e.isUpload ? await A(() => this.executeRequest(e), this.getRetryOptions(e)) : await this.executeRequest(e);
|
|
525
526
|
} catch (t) {
|
|
526
527
|
throw t instanceof v ? t : new T(`IPC error: ${t instanceof Error ? t.message : "Unknown error"}`, {
|
|
527
528
|
url: e.url,
|
|
@@ -579,8 +580,8 @@ var I = class {
|
|
|
579
580
|
let t = {}, n = e.isUpload === !0 && e.attachAuth === !1;
|
|
580
581
|
if (e.isUpload ? e.uploadFormFields || (t["Content-Type"] = "audio/mp3") : (t["Content-Type"] = "application/json", t.Accept = "application/json"), !n) {
|
|
581
582
|
this.accessToken && (t.Authorization = `Bearer ${this.accessToken}`), this.flavour && (t.flavour = this.flavour);
|
|
582
|
-
let e =
|
|
583
|
-
e && (t[
|
|
583
|
+
let e = M();
|
|
584
|
+
e && (t[j] = e);
|
|
584
585
|
}
|
|
585
586
|
return e.headers && Object.assign(t, e.headers), t;
|
|
586
587
|
}
|
|
@@ -667,13 +668,25 @@ var I = class {
|
|
|
667
668
|
destroy() {
|
|
668
669
|
for (let [e, t] of this.pendingRequests) t.reject(new T("IPC transport destroyed")), this.pendingRequests.delete(e);
|
|
669
670
|
}
|
|
670
|
-
};
|
|
671
|
+
}, ve = "aws", F = "backend";
|
|
672
|
+
function I(e) {
|
|
673
|
+
return typeof e == "string" ? e.trim().length > 0 : typeof e == "object" && !!e;
|
|
674
|
+
}
|
|
675
|
+
function L(e, t) {
|
|
676
|
+
return (typeof e == "string" ? e.trim().toLowerCase() : "") || (typeof t == "string" ? F : "aws");
|
|
677
|
+
}
|
|
671
678
|
//#endregion
|
|
672
679
|
//#region src/discovery/resolved-config.ts
|
|
673
|
-
|
|
680
|
+
var ye = ["aws"];
|
|
681
|
+
function be(e) {
|
|
682
|
+
let t = (e.storage_providers ?? []).filter((e) => typeof e == "string").map((e) => e.trim().toLowerCase()).filter((e) => e.length > 0);
|
|
683
|
+
return t.length > 0 ? Array.from(new Set(t)) : [...ye];
|
|
684
|
+
}
|
|
685
|
+
function xe(e) {
|
|
674
686
|
try {
|
|
675
687
|
let t = /* @__PURE__ */ new Map(), n = e.models ?? [];
|
|
676
688
|
for (let e of n) e.id && typeof e.max_session_duration_seconds == "number" && t.set(e.id, e.max_session_duration_seconds);
|
|
689
|
+
let r = be(e.capabilities);
|
|
677
690
|
return {
|
|
678
691
|
baseUrl: e.endpoints.base_url,
|
|
679
692
|
webhooksUrl: e.endpoints.webhooks_url,
|
|
@@ -681,7 +694,7 @@ function R(e) {
|
|
|
681
694
|
autoDetectLanguage: e.languages?.auto_detection ?? !1,
|
|
682
695
|
supportedAudioFormats: e.capabilities.audio_formats,
|
|
683
696
|
supportedUploadMethods: e.capabilities.upload_methods ?? [],
|
|
684
|
-
|
|
697
|
+
storageProviders: r,
|
|
685
698
|
maxChunkDurationSeconds: e.capabilities.max_chunk_duration_seconds,
|
|
686
699
|
maxSessionDurationSeconds: t,
|
|
687
700
|
supportedAuthMethods: e.authentication.supported_methods,
|
|
@@ -695,7 +708,7 @@ function R(e) {
|
|
|
695
708
|
}
|
|
696
709
|
//#endregion
|
|
697
710
|
//#region src/discovery/discovery-manager.ts
|
|
698
|
-
var
|
|
711
|
+
var R = class {
|
|
699
712
|
constructor(e, t, n = !1) {
|
|
700
713
|
this.cachedDocument = null, this.resolvedConfig = null, this.cacheTimestamp = 0, this.cacheTtlMs = i, this.transport = e, this.validator = t, this.debug = n;
|
|
701
714
|
}
|
|
@@ -712,7 +725,7 @@ var z = class {
|
|
|
712
725
|
url: n
|
|
713
726
|
});
|
|
714
727
|
this.validator.validateDiscoveryResponse(i.data);
|
|
715
|
-
let a = i.data, o =
|
|
728
|
+
let a = i.data, o = xe(a);
|
|
716
729
|
return this.cachedDocument = a, this.resolvedConfig = o, this.cacheTimestamp = Date.now(), this.debug && console.log("[ScribeSDK] Discovery complete:", a.service?.name ?? a.protocol), {
|
|
717
730
|
data: o,
|
|
718
731
|
httpStatus: i.status
|
|
@@ -765,7 +778,7 @@ var z = class {
|
|
|
765
778
|
isCacheValid() {
|
|
766
779
|
return Date.now() - this.cacheTimestamp < this.cacheTtlMs;
|
|
767
780
|
}
|
|
768
|
-
},
|
|
781
|
+
}, z = class {
|
|
769
782
|
constructor(e, t, n = !1) {
|
|
770
783
|
this.currentSession = null, this.transport = e, this.validator = t, this.debug = n;
|
|
771
784
|
}
|
|
@@ -933,13 +946,13 @@ var z = class {
|
|
|
933
946
|
}, { once: !0 });
|
|
934
947
|
}) : this.sleep(e);
|
|
935
948
|
}
|
|
936
|
-
},
|
|
937
|
-
|
|
938
|
-
var
|
|
949
|
+
}, B = 1024, V = 16e3;
|
|
950
|
+
B / V, V / B;
|
|
951
|
+
var H = {
|
|
939
952
|
m4a: "audio/m4a",
|
|
940
953
|
wav: "audio/wav",
|
|
941
954
|
mp3: "audio/mpeg"
|
|
942
|
-
},
|
|
955
|
+
}, Se = class {
|
|
943
956
|
constructor(e, t) {
|
|
944
957
|
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;
|
|
945
958
|
let n = e.samplingRate;
|
|
@@ -1071,7 +1084,7 @@ var U = {
|
|
|
1071
1084
|
} catch {}
|
|
1072
1085
|
this.micStream = null;
|
|
1073
1086
|
}
|
|
1074
|
-
},
|
|
1087
|
+
}, Ce = class {
|
|
1075
1088
|
constructor(e, t) {
|
|
1076
1089
|
this.currentSampleLength = 0, this.currentFrameLength = 0, this.samplingRate = e, this.incrementalAllocationSize = Math.floor(e * t), this.buffer = new Float32Array(this.incrementalAllocationSize);
|
|
1077
1090
|
}
|
|
@@ -1121,7 +1134,7 @@ var U = {
|
|
|
1121
1134
|
formatTimestamp(e) {
|
|
1122
1135
|
return `${Math.floor(e / 60).toString().padStart(2, "0")}:${(e % 60).toFixed(6).padStart(9, "0")}`;
|
|
1123
1136
|
}
|
|
1124
|
-
},
|
|
1137
|
+
}, we = class {
|
|
1125
1138
|
constructor() {
|
|
1126
1139
|
this.chunks = [], this.successfulUploads = [], this.totalRawSamples = 0, this.totalRawFrames = 0, this.totalInsertedSamples = 0, this.totalInsertedFrames = 0;
|
|
1127
1140
|
}
|
|
@@ -1220,7 +1233,7 @@ var U = {
|
|
|
1220
1233
|
};
|
|
1221
1234
|
//#endregion
|
|
1222
1235
|
//#region src/audio/mp3-encoder.ts
|
|
1223
|
-
function
|
|
1236
|
+
function Te(e, t = V, r = 128) {
|
|
1224
1237
|
try {
|
|
1225
1238
|
let i = new n.Mp3Encoder(1, t, r), a = new Int16Array(e.length);
|
|
1226
1239
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -1231,7 +1244,7 @@ function ve(e, t = H, r = 128) {
|
|
|
1231
1244
|
s && s.length > 0 && o.push(s);
|
|
1232
1245
|
let c = i.flush();
|
|
1233
1246
|
return c && c.length > 0 && o.push(c), o.length === 0 ? null : {
|
|
1234
|
-
blob: new Blob(o, { type:
|
|
1247
|
+
blob: new Blob(o, { type: H.mp3 }),
|
|
1235
1248
|
chunks: o
|
|
1236
1249
|
};
|
|
1237
1250
|
} catch (e) {
|
|
@@ -1240,25 +1253,25 @@ function ve(e, t = H, r = 128) {
|
|
|
1240
1253
|
}
|
|
1241
1254
|
//#endregion
|
|
1242
1255
|
//#region src/storage/aws-s3-provider.ts
|
|
1243
|
-
var
|
|
1256
|
+
var Ee = e.object({
|
|
1244
1257
|
uploadData: e.object({
|
|
1245
1258
|
url: e.string().min(1, "uploadData.url is required"),
|
|
1246
1259
|
fields: e.record(e.string(), e.string())
|
|
1247
1260
|
}),
|
|
1248
1261
|
folderPath: e.string().optional(),
|
|
1249
1262
|
txn_id: e.string().optional()
|
|
1250
|
-
}),
|
|
1263
|
+
}), De = "key", Oe = "${filename}", U = "Content-Type", ke = "audio/mp3", W = class {
|
|
1251
1264
|
constructor() {
|
|
1252
1265
|
this.name = "aws";
|
|
1253
1266
|
}
|
|
1254
1267
|
prepareUpload({ fileName: e, blob: t, upload: n }) {
|
|
1255
|
-
let r =
|
|
1268
|
+
let r = Ee.safeParse(n);
|
|
1256
1269
|
if (!r.success) throw new E(`Invalid AWS upload payload in session response: ${r.error.message}`, [e]);
|
|
1257
1270
|
let { uploadData: i } = r.data, a = {};
|
|
1258
|
-
for (let [t, n] of Object.entries(i.fields)) a[t] = t ===
|
|
1259
|
-
if (!(
|
|
1271
|
+
for (let [t, n] of Object.entries(i.fields)) a[t] = t === De ? n.split(Oe).join(e) : n;
|
|
1272
|
+
if (!(U in a)) {
|
|
1260
1273
|
let e = t?.type;
|
|
1261
|
-
a[
|
|
1274
|
+
a[U] = e && e.startsWith("audio/") ? e : ke;
|
|
1262
1275
|
}
|
|
1263
1276
|
return {
|
|
1264
1277
|
url: i.url,
|
|
@@ -1270,11 +1283,41 @@ var ye = e.object({
|
|
|
1270
1283
|
attachAuth: !1
|
|
1271
1284
|
};
|
|
1272
1285
|
}
|
|
1273
|
-
},
|
|
1286
|
+
}, Ae = e.string().trim().min(1, "upload_url is required"), je = "Content-Type", Me = "audio/mp3", Ne = {
|
|
1287
|
+
mp3: "audio/mp3",
|
|
1288
|
+
webm: "audio/webm",
|
|
1289
|
+
wav: "audio/wav",
|
|
1290
|
+
ogg: "audio/ogg",
|
|
1291
|
+
m4a: "audio/m4a",
|
|
1292
|
+
mp4: "audio/mp4"
|
|
1293
|
+
};
|
|
1294
|
+
function Pe(e, t) {
|
|
1295
|
+
let n = t?.type;
|
|
1296
|
+
return n && n.startsWith("audio/") ? n : Ne[e.split(".").pop()?.toLowerCase() ?? ""] ?? Me;
|
|
1297
|
+
}
|
|
1298
|
+
var G = class {
|
|
1299
|
+
constructor() {
|
|
1300
|
+
this.name = "backend";
|
|
1301
|
+
}
|
|
1302
|
+
prepareUpload({ fileName: e, blob: t, upload: n }) {
|
|
1303
|
+
let r = Ae.safeParse(n);
|
|
1304
|
+
if (!r.success) throw new E(`Invalid backend upload payload: expected an upload_url string, got ${typeof n}`, [e]);
|
|
1305
|
+
return {
|
|
1306
|
+
url: `${r.data.replace(/\/+$/, "")}/${encodeURIComponent(e)}`,
|
|
1307
|
+
method: "POST",
|
|
1308
|
+
bodyMode: "binary",
|
|
1309
|
+
headers: { [je]: Pe(e, t) },
|
|
1310
|
+
attachAuth: !0
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
}, K = {
|
|
1314
|
+
aws: () => new W(),
|
|
1315
|
+
backend: () => new G()
|
|
1316
|
+
};
|
|
1274
1317
|
function q(e) {
|
|
1275
1318
|
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
1276
1319
|
}
|
|
1277
|
-
function
|
|
1320
|
+
function Fe(e) {
|
|
1278
1321
|
return q(e) in K;
|
|
1279
1322
|
}
|
|
1280
1323
|
function J(e) {
|
|
@@ -1305,7 +1348,7 @@ async function Y(e, t) {
|
|
|
1305
1348
|
}
|
|
1306
1349
|
//#endregion
|
|
1307
1350
|
//#region src/worker/worker-manager.ts
|
|
1308
|
-
var
|
|
1351
|
+
var Ie = class {
|
|
1309
1352
|
constructor(e, t, n, r) {
|
|
1310
1353
|
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 {
|
|
1311
1354
|
this.worker = new SharedWorker(r.workerScriptUrl, { name: "scribe-sdk-worker" }), this.port = this.worker.port, this.port.onmessage = (e) => {
|
|
@@ -1319,7 +1362,7 @@ var we = class {
|
|
|
1319
1362
|
this.uploadPayload = e, this.storageProviderName = t, this.uploadHeaders = n, this.refreshUploadUrl = r ?? null, J(t);
|
|
1320
1363
|
}
|
|
1321
1364
|
compressAndUpload(e, t, n) {
|
|
1322
|
-
let r = e.length /
|
|
1365
|
+
let r = e.length / V;
|
|
1323
1366
|
if (r > 27) {
|
|
1324
1367
|
this.fileManager.markFailure(n, new Blob(), `Chunk exceeds maximum length: ${r.toFixed(1)}s > 25s`), this.callbackRegistry.dispatch("onError", {
|
|
1325
1368
|
type: m.VALIDATION_ERROR,
|
|
@@ -1457,7 +1500,7 @@ var we = class {
|
|
|
1457
1500
|
async doMainThreadUpload(e, t, n) {
|
|
1458
1501
|
let r = null;
|
|
1459
1502
|
try {
|
|
1460
|
-
let i =
|
|
1503
|
+
let i = Te(e);
|
|
1461
1504
|
if (!i) {
|
|
1462
1505
|
this.fileManager.markFailure(n, new Blob(), "MP3 encoding failed"), this.callbackRegistry.dispatch("onUploadEvent", {
|
|
1463
1506
|
type: f.FAILED,
|
|
@@ -1523,7 +1566,7 @@ var we = class {
|
|
|
1523
1566
|
}
|
|
1524
1567
|
}, X = class {
|
|
1525
1568
|
constructor(e, t, n, r) {
|
|
1526
|
-
this._isPaused = !1, this.initialized = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.callbackRegistry = e, this.bufferManager = new
|
|
1569
|
+
this._isPaused = !1, this.initialized = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.callbackRegistry = e, this.bufferManager = new Ce(V, 25), this.fileManager = new we();
|
|
1527
1570
|
let i = {
|
|
1528
1571
|
prefChunkLength: n?.prefChunkLength ?? 10,
|
|
1529
1572
|
despChunkLength: n?.despChunkLength ?? 20,
|
|
@@ -1534,10 +1577,10 @@ var we = class {
|
|
|
1534
1577
|
shortSilenceThreshold: n?.shortSilenceThreshold,
|
|
1535
1578
|
longSilenceThreshold: n?.longSilenceThreshold
|
|
1536
1579
|
};
|
|
1537
|
-
this.vadClient = new
|
|
1580
|
+
this.vadClient = new Se(i, e), this.workerManager = new Ie(e, this.fileManager, t, r), this.wireVadCallbacks();
|
|
1538
1581
|
}
|
|
1539
1582
|
initialize(e, t) {
|
|
1540
|
-
if (!t.upload || typeof t.upload != "object") throw Error("
|
|
1583
|
+
if (!t.upload || typeof t.upload != "object") throw Error("Chunked recording requires a presigned upload payload object, not a URL string.");
|
|
1541
1584
|
if (!t.storageProvider) throw Error("Storage provider is required for chunked recording");
|
|
1542
1585
|
this.workerManager.setUploadConfig(t.upload, t.storageProvider, t.uploadHeaders, t.refreshUploadUrl), this.initialized = !0;
|
|
1543
1586
|
}
|
|
@@ -1642,7 +1685,7 @@ var we = class {
|
|
|
1642
1685
|
this.mediaRecorder = null, this.audioChunks = [], this.micStream = null, this._isPaused = !1, this.uploadPayload = {}, this.storageProviderName = "", this.failedUploadData = null, this.callbackRegistry = e, this.transport = t;
|
|
1643
1686
|
}
|
|
1644
1687
|
initialize(e, t) {
|
|
1645
|
-
if (!t.upload
|
|
1688
|
+
if (!I(t.upload)) throw Error("Upload payload is required for single recording");
|
|
1646
1689
|
if (!t.storageProvider) throw Error("Storage provider is required for single recording");
|
|
1647
1690
|
this.uploadPayload = t.upload, this.storageProviderName = t.storageProvider, J(t.storageProvider), this.failedUploadData = null;
|
|
1648
1691
|
}
|
|
@@ -1805,7 +1848,7 @@ var we = class {
|
|
|
1805
1848
|
this.activeSession = a;
|
|
1806
1849
|
let c;
|
|
1807
1850
|
try {
|
|
1808
|
-
c = this.resolveStorageProviderName();
|
|
1851
|
+
c = this.resolveStorageProviderName(a);
|
|
1809
1852
|
} catch (e) {
|
|
1810
1853
|
throw r === this._startGeneration && (this.cleanupRecordingState(), this.dispatchStartError(m.VALIDATION_ERROR, g.UNSUPPORTED_STORAGE_PROVIDER, e)), e;
|
|
1811
1854
|
}
|
|
@@ -1868,7 +1911,7 @@ var we = class {
|
|
|
1868
1911
|
try {
|
|
1869
1912
|
let o;
|
|
1870
1913
|
try {
|
|
1871
|
-
o = this.resolveStorageProviderName();
|
|
1914
|
+
o = this.resolveStorageProviderName(t);
|
|
1872
1915
|
} catch (e) {
|
|
1873
1916
|
throw i === this._startGeneration && (this.cleanupRecordingState(), this.dispatchStartError(m.VALIDATION_ERROR, g.UNSUPPORTED_STORAGE_PROVIDER, e)), e;
|
|
1874
1917
|
}
|
|
@@ -2100,22 +2143,19 @@ var we = class {
|
|
|
2100
2143
|
createRecorder(e) {
|
|
2101
2144
|
return e === "single" ? new Z(this.callbackRegistry, this.transport) : new X(this.callbackRegistry, this.transport, void 0, this.config.workerConfig);
|
|
2102
2145
|
}
|
|
2103
|
-
getStorageProviderName() {
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
} catch {
|
|
2107
|
-
return "aws";
|
|
2108
|
-
}
|
|
2146
|
+
getStorageProviderName(e) {
|
|
2147
|
+
let t = e ?? this.activeSession;
|
|
2148
|
+
return L(t?.storage_provider, t?.upload_url);
|
|
2109
2149
|
}
|
|
2110
|
-
resolveStorageProviderName() {
|
|
2111
|
-
let
|
|
2112
|
-
return J(
|
|
2150
|
+
resolveStorageProviderName(e) {
|
|
2151
|
+
let t = this.getStorageProviderName(e);
|
|
2152
|
+
return J(t), t;
|
|
2113
2153
|
}
|
|
2114
2154
|
buildUploadHeaders(e) {
|
|
2115
2155
|
let t = {};
|
|
2116
2156
|
e && (t.Authorization = `Bearer ${e}`), this.config.flavour && (t.flavour = this.config.flavour);
|
|
2117
|
-
let n =
|
|
2118
|
-
return n && (t[
|
|
2157
|
+
let n = M();
|
|
2158
|
+
return n && (t[j] = n), t;
|
|
2119
2159
|
}
|
|
2120
2160
|
buildUploadUrlRefresher(e, t, n) {
|
|
2121
2161
|
return () => this.fetchFreshUploadUrl(e, t, n);
|
|
@@ -2154,7 +2194,7 @@ var we = class {
|
|
|
2154
2194
|
}
|
|
2155
2195
|
this.retryContext = {
|
|
2156
2196
|
upload: this.activeSession.upload_url,
|
|
2157
|
-
storageProvider: this.getStorageProviderName(),
|
|
2197
|
+
storageProvider: this.getStorageProviderName(this.activeSession),
|
|
2158
2198
|
failedChunks: e
|
|
2159
2199
|
}, this.config.debug && console.log(`[ScribeSDK] Preserved ${e.length} failed uploads for retry`);
|
|
2160
2200
|
}
|
|
@@ -2164,14 +2204,14 @@ var we = class {
|
|
|
2164
2204
|
partialCleanupAfterFailedFinalize() {
|
|
2165
2205
|
this.recorder = null, this._isRecording = !1, this._isStarting = !1;
|
|
2166
2206
|
}
|
|
2167
|
-
},
|
|
2207
|
+
}, Le = class {
|
|
2168
2208
|
constructor(e) {
|
|
2169
2209
|
this.isInitialized = !1, this.validateConfig(e), this.config = {
|
|
2170
2210
|
debug: !1,
|
|
2171
2211
|
autoDiscovery: !0,
|
|
2172
2212
|
mode: l.DIRECT,
|
|
2173
2213
|
...e
|
|
2174
|
-
}, this.callbackRegistry = new O(), this.validator = new
|
|
2214
|
+
}, this.callbackRegistry = new O(), this.validator = new k(), this.transport = this.createTransport(), this.discoveryManager = new R(this.transport, this.validator, this.config.debug), this.sessionManager = new z(this.transport, this.validator, this.config.debug), this.recordingManager = new Q(this.callbackRegistry, this.sessionManager, this.discoveryManager, this.transport, {
|
|
2175
2215
|
debug: this.config.debug,
|
|
2176
2216
|
flavour: this.config.flavour,
|
|
2177
2217
|
workerConfig: this.resolveWorkerConfig()
|
|
@@ -2236,25 +2276,25 @@ var we = class {
|
|
|
2236
2276
|
forceAllowMoreChunks() {
|
|
2237
2277
|
this.recordingManager.forceAllowMoreChunks();
|
|
2238
2278
|
}
|
|
2239
|
-
async uploadAudioFile(e, t, n) {
|
|
2279
|
+
async uploadAudioFile(e, t, n, r) {
|
|
2240
2280
|
return this.wrapResult(async () => {
|
|
2241
2281
|
if (!e || e.size === 0) throw new y("A non-empty audio file is required");
|
|
2242
2282
|
if (!t || !t.trim()) throw new y("fileName is required");
|
|
2243
|
-
if (!n
|
|
2244
|
-
let
|
|
2283
|
+
if (!I(n)) throw new y("upload (upload_url payload) is required");
|
|
2284
|
+
let i = await Y(this.transport, {
|
|
2245
2285
|
fileName: t,
|
|
2246
2286
|
blob: e,
|
|
2247
2287
|
upload: n,
|
|
2248
|
-
storageProvider: this.
|
|
2288
|
+
storageProvider: L(r?.storageProvider ?? this.providerForUpload(n), n)
|
|
2249
2289
|
});
|
|
2250
2290
|
return {
|
|
2251
2291
|
data: {
|
|
2252
2292
|
fileName: t,
|
|
2253
|
-
status:
|
|
2254
|
-
headers:
|
|
2255
|
-
response:
|
|
2293
|
+
status: i.status,
|
|
2294
|
+
headers: i.headers,
|
|
2295
|
+
response: i.data
|
|
2256
2296
|
},
|
|
2257
|
-
httpStatus:
|
|
2297
|
+
httpStatus: i.status
|
|
2258
2298
|
};
|
|
2259
2299
|
});
|
|
2260
2300
|
}
|
|
@@ -2368,7 +2408,7 @@ var we = class {
|
|
|
2368
2408
|
}) : Promise.resolve(void 0);
|
|
2369
2409
|
if (this.config.mode === l.IPC) {
|
|
2370
2410
|
if (!this.config.ipcTransport) throw new y("ipcTransport (IpcBridge) is required when mode is \"ipc\"");
|
|
2371
|
-
return new
|
|
2411
|
+
return new P({
|
|
2372
2412
|
bridge: this.config.ipcTransport,
|
|
2373
2413
|
accessToken: this.config.accessToken,
|
|
2374
2414
|
flavour: this.config.flavour,
|
|
@@ -2376,7 +2416,7 @@ var we = class {
|
|
|
2376
2416
|
onUnauthorized: e
|
|
2377
2417
|
});
|
|
2378
2418
|
}
|
|
2379
|
-
return new
|
|
2419
|
+
return new N({
|
|
2380
2420
|
accessToken: this.config.accessToken,
|
|
2381
2421
|
flavour: this.config.flavour,
|
|
2382
2422
|
debug: this.config.debug,
|
|
@@ -2390,12 +2430,9 @@ var we = class {
|
|
|
2390
2430
|
workerScriptUrl: this.config.workerScriptUrl
|
|
2391
2431
|
};
|
|
2392
2432
|
}
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
} catch {
|
|
2397
|
-
return "aws";
|
|
2398
|
-
}
|
|
2433
|
+
providerForUpload(e) {
|
|
2434
|
+
let t = this.sessionManager.getCurrentSession();
|
|
2435
|
+
return t && t.upload_url === e ? t.storage_provider : void 0;
|
|
2399
2436
|
}
|
|
2400
2437
|
getEffectiveBaseUrl() {
|
|
2401
2438
|
try {
|
|
@@ -2408,7 +2445,7 @@ var we = class {
|
|
|
2408
2445
|
if (!e.baseUrl) throw new y("baseUrl is required");
|
|
2409
2446
|
}
|
|
2410
2447
|
}, $ = "worker.bundle.js";
|
|
2411
|
-
function
|
|
2448
|
+
function Re() {
|
|
2412
2449
|
if (typeof window < "u" && window.__MEDSCRIBE_WORKER_URL__) return window.__MEDSCRIBE_WORKER_URL__;
|
|
2413
2450
|
if (typeof document < "u" && document.currentScript) {
|
|
2414
2451
|
let e = document.currentScript.src;
|
|
@@ -2416,11 +2453,11 @@ function Ee() {
|
|
|
2416
2453
|
}
|
|
2417
2454
|
return `/${$}`;
|
|
2418
2455
|
}
|
|
2419
|
-
async function
|
|
2456
|
+
async function ze(e) {
|
|
2420
2457
|
let t = e ?? `https://cdn.jsdelivr.net/npm/med-scribe-alliance-ts-sdk/dist/${$}`, n = await fetch(t);
|
|
2421
2458
|
if (!n.ok) throw Error(`Failed to fetch worker script: ${n.status} ${n.statusText}`);
|
|
2422
2459
|
let r = await n.text(), i = new Blob([r], { type: "application/javascript" });
|
|
2423
2460
|
return URL.createObjectURL(i);
|
|
2424
2461
|
}
|
|
2425
2462
|
//#endregion
|
|
2426
|
-
export { d as AudioEventType, x as AuthenticationError,
|
|
2463
|
+
export { ve as AWS_STORAGE_PROVIDER, d as AudioEventType, x as AuthenticationError, W as AwsS3StorageProvider, F as BACKEND_STORAGE_PROVIDER, G as BackendStorageProvider, O as CallbackRegistry, c as CommunicationProtocol, h as DiscardReason, b as DiscoveryError, R as DiscoveryManager, g as ErrorCode, m as ErrorEventType, S as ForbiddenError, _ as HttpStatus, N as HttpTransport, P as IpcTransport, w as RateLimitError, Q as RecordingManager, u as RecordingState, Le as ScribeClient, v as ScribeError, p as SessionEventType, te as SessionExpiredError, z 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, k as Validator, ne as WorkerError, ze as createWorkerBlobUrl, J as getStorageProvider, Re as getWorkerUrl, I as hasUploadPayload, Fe as isStorageProviderSupported, L as resolveStorageProvider };
|
package/dist/worker.bundle.js
CHANGED
|
@@ -74,4 +74,4 @@ bitsperframe: %d
|
|
|
74
74
|
|
|
75
75
|
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=pr,s=!er.jitless,c=s&&mr.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Ca([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function Ea(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Or(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Mr(e,r,tr())))}),t)}var Da=Y(`$ZodUnion`,(e,t)=>{Ui.init(e,t),X(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),X(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),X(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),X(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>or(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Ea(t,r,e,i)):Ea(o,r,e,i)}}),Oa=Y(`$ZodIntersection`,(e,t)=>{Ui.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Aa(e,t,n)):Aa(e,i,a)}});function ka(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(hr(e)&&hr(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=ka(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ka(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Aa(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),Or(e))return e;let o=ka(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var ja=Y(`$ZodRecord`,(e,t)=>{Ui.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!hr(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>Mr(e,r,tr())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...Ar(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...Ar(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Ei.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Mr(e,r,tr())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Ar(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Ar(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Ma=Y(`$ZodEnum`,(e,t)=>{Ui.init(e,t);let n=nr(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>_r.has(typeof e)).map(e=>typeof e==`string`?vr(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Na=Y(`$ZodTransform`,(e,t)=>{Ui.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new $n(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new Qn;return n.value=i,n.fallback=!0,n}});function Pa(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var Fa=Y(`$ZodOptional`,(e,t)=>{Ui.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,X(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),X(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${or(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>Pa(e,r)):Pa(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Ia=Y(`$ZodExactOptional`,(e,t)=>{Fa.init(e,t),X(e._zod,`values`,()=>t.innerType._zod.values),X(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),La=Y(`$ZodNullable`,(e,t)=>{Ui.init(e,t),X(e._zod,`optin`,()=>t.innerType._zod.optin),X(e._zod,`optout`,()=>t.innerType._zod.optout),X(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${or(e.source)}|null)$`):void 0}),X(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Ra=Y(`$ZodDefault`,(e,t)=>{Ui.init(e,t),e._zod.optin=`optional`,X(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>za(e,t)):za(r,t)}});function za(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Ba=Y(`$ZodPrefault`,(e,t)=>{Ui.init(e,t),e._zod.optin=`optional`,X(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Va=Y(`$ZodNonOptional`,(e,t)=>{Ui.init(e,t),X(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Ha(t,e)):Ha(i,e)}});function Ha(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var Ua=Y(`$ZodCatch`,(e,t)=>{Ui.init(e,t),e._zod.optin=`optional`,X(e._zod,`optout`,()=>t.innerType._zod.optout),X(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Mr(e,n,tr()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Mr(e,n,tr()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),Wa=Y(`$ZodPipe`,(e,t)=>{Ui.init(e,t),X(e._zod,`values`,()=>t.in._zod.values),X(e._zod,`optin`,()=>t.in._zod.optin),X(e._zod,`optout`,()=>t.out._zod.optout),X(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Ga(e,t.in,n)):Ga(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Ga(e,t.out,n)):Ga(r,t.out,n)}});function Ga(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var Ka=Y(`$ZodReadonly`,(e,t)=>{Ui.init(e,t),X(e._zod,`propValues`,()=>t.innerType._zod.propValues),X(e._zod,`values`,()=>t.innerType._zod.values),X(e._zod,`optin`,()=>t.innerType?._zod?.optin),X(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(qa):qa(r)}});function qa(e){return e.value=Object.freeze(e.value),e}var Ja=Y(`$ZodCustom`,(e,t)=>{ki.init(e,t),Ui.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Ya(t,n,r,e));Ya(i,n,r,e)}});function Ya(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Pr(e))}}var Xa,Za=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Qa(){return new Za}(Xa=globalThis).__zod_globalRegistry??(Xa.__zod_globalRegistry=Qa());var $a=globalThis.__zod_globalRegistry;function eo(e,t){return new e({type:`string`,...Z(t)})}function to(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...Z(t)})}function no(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...Z(t)})}function ro(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...Z(t)})}function io(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...Z(t)})}function ao(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...Z(t)})}function oo(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...Z(t)})}function so(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...Z(t)})}function co(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...Z(t)})}function lo(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...Z(t)})}function uo(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...Z(t)})}function fo(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...Z(t)})}function po(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...Z(t)})}function mo(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...Z(t)})}function ho(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...Z(t)})}function go(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...Z(t)})}function _o(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...Z(t)})}function vo(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...Z(t)})}function yo(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...Z(t)})}function bo(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...Z(t)})}function xo(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...Z(t)})}function So(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...Z(t)})}function Co(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...Z(t)})}function wo(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...Z(t)})}function To(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...Z(t)})}function Eo(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...Z(t)})}function Do(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...Z(t)})}function Oo(e){return new e({type:`unknown`})}function ko(e,t){return new e({type:`never`,...Z(t)})}function Ao(e,t){return new Ai({check:`max_length`,...Z(t),maximum:e})}function jo(e,t){return new ji({check:`min_length`,...Z(t),minimum:e})}function Mo(e,t){return new Mi({check:`length_equals`,...Z(t),length:e})}function No(e,t){return new Pi({check:`string_format`,format:`regex`,...Z(t),pattern:e})}function Po(e){return new Fi({check:`string_format`,format:`lowercase`,...Z(e)})}function Fo(e){return new Ii({check:`string_format`,format:`uppercase`,...Z(e)})}function Io(e,t){return new Li({check:`string_format`,format:`includes`,...Z(t),includes:e})}function Lo(e,t){return new Ri({check:`string_format`,format:`starts_with`,...Z(t),prefix:e})}function Ro(e,t){return new zi({check:`string_format`,format:`ends_with`,...Z(t),suffix:e})}function zo(e){return new Bi({check:`overwrite`,tx:e})}function Bo(e){return zo(t=>t.normalize(e))}function Vo(){return zo(e=>e.trim())}function Ho(){return zo(e=>e.toLowerCase())}function Uo(){return zo(e=>e.toUpperCase())}function Wo(){return zo(e=>dr(e))}function Go(e,t,n){return new e({type:`array`,element:t,...Z(n)})}function Ko(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...Z(n)})}function qo(e,t){let n=Jo(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Pr(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(Pr(r))}},e(t.value,t)),t);return n}function Jo(e,t){let n=new ki({check:`custom`,...Z(t)});return n._zod.check=e,n}function Yo(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??$a,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function Xo(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,Xo(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&$o(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Zo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
76
76
|
|
|
77
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Qo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:ts(t,`input`,e.processors),output:ts(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function $o(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return $o(r.element,n);if(r.type===`set`)return $o(r.valueType,n);if(r.type===`lazy`)return $o(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return $o(r.innerType,n);if(r.type===`intersection`)return $o(r.left,n)||$o(r.right,n);if(r.type===`record`||r.type===`map`)return $o(r.keyType,n)||$o(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:$o(r.in,n)||$o(r.out,n);if(r.type===`object`){for(let e in r.shape)if($o(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if($o(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if($o(e,n))return!0;return!!(r.rest&&$o(r.rest,n))}return!1}var es=(e,t={})=>n=>{let r=Yo({...n,processors:t});return Xo(e,r),Zo(r,e),Qo(r,e)},ts=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Yo({...i??{},target:a,io:t,processors:n});return Xo(e,o),Zo(o,e),Qo(o,e)},ns={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},rs=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ns[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},is=(e,t,n,r)=>{n.not={}},as=(e,t,n,r)=>{let i=e._zod.def,a=nr(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},os=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},ss=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},cs=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Xo(a.element,t,{...r,path:[...r.path,`items`]})},ls=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=Xo(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Xo(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},us=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Xo(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},ds=(e,t,n,r)=>{let i=e._zod.def,a=Xo(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Xo(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},fs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Xo(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=Xo(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=Xo(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},ps=(e,t,n,r)=>{let i=e._zod.def,a=Xo(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},ms=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},hs=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},gs=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},_s=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},vs=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;Xo(o,t,r);let s=t.seen.get(e);s.ref=o},ys=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},bs=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},xs=Y(`ZodISODateTime`,(e,t)=>{na.init(e,t),$.init(e,t)});function Ss(e){return wo(xs,e)}var Cs=Y(`ZodISODate`,(e,t)=>{ra.init(e,t),$.init(e,t)});function ws(e){return To(Cs,e)}var Ts=Y(`ZodISOTime`,(e,t)=>{ia.init(e,t),$.init(e,t)});function Es(e){return Eo(Ts,e)}var Ds=Y(`ZodISODuration`,(e,t)=>{aa.init(e,t),$.init(e,t)});function Os(e){return Do(Ds,e)}var ks=Y(`ZodError`,(e,t)=>{Ir.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>zr(e,t)},flatten:{value:t=>Rr(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,rr,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,rr,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),As=Br(ks),js=Vr(ks),Ms=Hr(ks),Ns=Wr(ks),Ps=Kr(ks),Fs=qr(ks),Is=Jr(ks),Ls=Yr(ks),Rs=Xr(ks),zs=Zr(ks),Bs=Qr(ks),Vs=$r(ks),Hs=new WeakMap;function Us(e,t,n){let r=Object.getPrototypeOf(e),i=Hs.get(r);if(i||(i=new Set,Hs.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var Ws=Y(`ZodType`,(e,t)=>(Ui.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:ts(e,`input`),output:ts(e,`output`)}}),e.toJSONSchema=es(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.parse=(t,n)=>As(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ms(e,t,n),e.parseAsync=async(t,n)=>js(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ns(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Ps(e,t,n),e.decode=(t,n)=>Fs(e,t,n),e.encodeAsync=async(t,n)=>Is(e,t,n),e.decodeAsync=async(t,n)=>Ls(e,t,n),e.safeEncode=(t,n)=>Rs(e,t,n),e.safeDecode=(t,n)=>zs(e,t,n),e.safeEncodeAsync=async(t,n)=>Bs(e,t,n),e.safeDecodeAsync=async(t,n)=>Vs(e,t,n),Us(e,`ZodType`,{check(...e){let t=this.def;return this.clone(lr(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return yr(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Xc(e,t))},superRefine(e,t){return this.check(Zc(e,t))},overwrite(e){return this.check(zo(e))},optional(){return Mc(this)},exactOptional(){return Pc(this)},nullable(){return Ic(this)},nullish(){return Mc(Ic(this))},nonoptional(e){return Hc(this,e)},array(){return vc(this)},or(e){return Sc([this,e])},and(e){return wc(this,e)},transform(e){return Kc(this,Ac(e))},default(e){return Rc(this,e)},prefault(e){return Bc(this,e)},catch(e){return Wc(this,e)},pipe(e){return Kc(this,e)},readonly(){return Jc(this)},describe(e){let t=this.clone();return $a.add(t,{description:e}),t},meta(...e){if(e.length===0)return $a.get(this);let t=this.clone();return $a.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,`description`,{get(){return $a.get(e)?.description},configurable:!0}),e)),Gs=Y(`_ZodString`,(e,t)=>{Wi.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rs(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Us(e,`_ZodString`,{regex(...e){return this.check(No(...e))},includes(...e){return this.check(Io(...e))},startsWith(...e){return this.check(Lo(...e))},endsWith(...e){return this.check(Ro(...e))},min(...e){return this.check(jo(...e))},max(...e){return this.check(Ao(...e))},length(...e){return this.check(Mo(...e))},nonempty(...e){return this.check(jo(1,...e))},lowercase(e){return this.check(Po(e))},uppercase(e){return this.check(Fo(e))},trim(){return this.check(Vo())},normalize(...e){return this.check(Bo(...e))},toLowerCase(){return this.check(Ho())},toUpperCase(){return this.check(Uo())},slugify(){return this.check(Wo())}})}),Ks=Y(`ZodString`,(e,t)=>{Wi.init(e,t),Gs.init(e,t),e.email=t=>e.check(to(Js,t)),e.url=t=>e.check(so(Zs,t)),e.jwt=t=>e.check(Co(fc,t)),e.emoji=t=>e.check(co(Qs,t)),e.guid=t=>e.check(no(Ys,t)),e.uuid=t=>e.check(ro(Xs,t)),e.uuidv4=t=>e.check(io(Xs,t)),e.uuidv6=t=>e.check(ao(Xs,t)),e.uuidv7=t=>e.check(oo(Xs,t)),e.nanoid=t=>e.check(lo($s,t)),e.guid=t=>e.check(no(Ys,t)),e.cuid=t=>e.check(uo(ec,t)),e.cuid2=t=>e.check(fo(tc,t)),e.ulid=t=>e.check(po(nc,t)),e.base64=t=>e.check(bo(lc,t)),e.base64url=t=>e.check(xo(uc,t)),e.xid=t=>e.check(mo(rc,t)),e.ksuid=t=>e.check(ho(ic,t)),e.ipv4=t=>e.check(go(ac,t)),e.ipv6=t=>e.check(_o(oc,t)),e.cidrv4=t=>e.check(vo(sc,t)),e.cidrv6=t=>e.check(yo(cc,t)),e.e164=t=>e.check(So(dc,t)),e.datetime=t=>e.check(Ss(t)),e.date=t=>e.check(ws(t)),e.time=t=>e.check(Es(t)),e.duration=t=>e.check(Os(t))});function qs(e){return eo(Ks,e)}var $=Y(`ZodStringFormat`,(e,t)=>{Q.init(e,t),Gs.init(e,t)}),Js=Y(`ZodEmail`,(e,t)=>{qi.init(e,t),$.init(e,t)}),Ys=Y(`ZodGUID`,(e,t)=>{Gi.init(e,t),$.init(e,t)}),Xs=Y(`ZodUUID`,(e,t)=>{Ki.init(e,t),$.init(e,t)}),Zs=Y(`ZodURL`,(e,t)=>{Ji.init(e,t),$.init(e,t)}),Qs=Y(`ZodEmoji`,(e,t)=>{Yi.init(e,t),$.init(e,t)}),$s=Y(`ZodNanoID`,(e,t)=>{Xi.init(e,t),$.init(e,t)}),ec=Y(`ZodCUID`,(e,t)=>{Zi.init(e,t),$.init(e,t)}),tc=Y(`ZodCUID2`,(e,t)=>{Qi.init(e,t),$.init(e,t)}),nc=Y(`ZodULID`,(e,t)=>{$i.init(e,t),$.init(e,t)}),rc=Y(`ZodXID`,(e,t)=>{ea.init(e,t),$.init(e,t)}),ic=Y(`ZodKSUID`,(e,t)=>{ta.init(e,t),$.init(e,t)}),ac=Y(`ZodIPv4`,(e,t)=>{oa.init(e,t),$.init(e,t)}),oc=Y(`ZodIPv6`,(e,t)=>{sa.init(e,t),$.init(e,t)}),sc=Y(`ZodCIDRv4`,(e,t)=>{ca.init(e,t),$.init(e,t)}),cc=Y(`ZodCIDRv6`,(e,t)=>{la.init(e,t),$.init(e,t)}),lc=Y(`ZodBase64`,(e,t)=>{da.init(e,t),$.init(e,t)}),uc=Y(`ZodBase64URL`,(e,t)=>{pa.init(e,t),$.init(e,t)}),dc=Y(`ZodE164`,(e,t)=>{ma.init(e,t),$.init(e,t)}),fc=Y(`ZodJWT`,(e,t)=>{ga.init(e,t),$.init(e,t)}),pc=Y(`ZodUnknown`,(e,t)=>{_a.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function mc(){return Oo(pc)}var hc=Y(`ZodNever`,(e,t)=>{va.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>is(e,t,n,r)});function gc(e){return ko(hc,e)}var _c=Y(`ZodArray`,(e,t)=>{ba.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cs(e,t,n,r),e.element=t.element,Us(e,`ZodArray`,{min(e,t){return this.check(jo(e,t))},nonempty(e){return this.check(jo(1,e))},max(e,t){return this.check(Ao(e,t))},length(e,t){return this.check(Mo(e,t))},unwrap(){return this.element}})});function vc(e,t){return Go(_c,e,t)}var yc=Y(`ZodObject`,(e,t)=>{Ta.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ls(e,t,n,r),X(e,`shape`,()=>t.shape),Us(e,`ZodObject`,{keyof(){return Oc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:mc()})},loose(){return this.clone({...this._zod.def,catchall:mc()})},strict(){return this.clone({...this._zod.def,catchall:gc()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return Cr(this,e)},safeExtend(e){return wr(this,e)},merge(e){return Tr(this,e)},pick(e){return xr(this,e)},omit(e){return Sr(this,e)},partial(...e){return Er(jc,this,e[0])},required(...e){return Dr(Vc,this,e[0])}})});function bc(e,t){return new yc({type:`object`,shape:e??{},...Z(t)})}var xc=Y(`ZodUnion`,(e,t)=>{Da.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r),e.options=t.options});function Sc(e,t){return new xc({type:`union`,options:e,...Z(t)})}var Cc=Y(`ZodIntersection`,(e,t)=>{Oa.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r)});function wc(e,t){return new Cc({type:`intersection`,left:e,right:t})}var Tc=Y(`ZodRecord`,(e,t)=>{ja.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Ec(e,t,n){return!t||!t._zod?new Tc({type:`record`,keyType:qs(),valueType:e,...Z(t)}):new Tc({type:`record`,keyType:e,valueType:t,...Z(n)})}var Dc=Y(`ZodEnum`,(e,t)=>{Ma.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>as(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Dc({...t,checks:[],...Z(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Dc({...t,checks:[],...Z(r),entries:i})}});function Oc(e,t){return new Dc({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...Z(t)})}var kc=Y(`ZodTransform`,(e,t)=>{Na.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new $n(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Pr(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Pr(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function Ac(e){return new kc({type:`transform`,transform:e})}var jc=Y(`ZodOptional`,(e,t)=>{Fa.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mc(e){return new jc({type:`optional`,innerType:e})}var Nc=Y(`ZodExactOptional`,(e,t)=>{Ia.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Pc(e){return new Nc({type:`optional`,innerType:e})}var Fc=Y(`ZodNullable`,(e,t)=>{La.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ps(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ic(e){return new Fc({type:`nullable`,innerType:e})}var Lc=Y(`ZodDefault`,(e,t)=>{Ra.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Rc(e,t){return new Lc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():gr(t)}})}var zc=Y(`ZodPrefault`,(e,t)=>{Ba.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bc(e,t){return new zc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():gr(t)}})}var Vc=Y(`ZodNonOptional`,(e,t)=>{Va.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ms(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hc(e,t){return new Vc({type:`nonoptional`,innerType:e,...Z(t)})}var Uc=Y(`ZodCatch`,(e,t)=>{Ua.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_s(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Wc(e,t){return new Uc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Gc=Y(`ZodPipe`,(e,t)=>{Wa.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vs(e,t,n,r),e.in=t.in,e.out=t.out});function Kc(e,t){return new Gc({type:`pipe`,in:e,out:t})}var qc=Y(`ZodReadonly`,(e,t)=>{Ka.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ys(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Jc(e){return new qc({type:`readonly`,innerType:e})}var Yc=Y(`ZodCustom`,(e,t)=>{Ja.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>os(e,t,n,r)});function Xc(e,t={}){return Ko(Yc,e,t)}function Zc(e,t){return qo(e,t)}var Qc=function(e){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}({}),$c=class e extends Error{constructor(t,n=Qc.INTERNAL_ERROR,r,i){super(t),this.name=`ScribeError`,this.code=n,this.httpStatus=r,this.details=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}static fromApiError(t,n){return new e(t.message,t.code,n,t.details)}toJSON(){return{name:this.name,message:this.message,code:this.code,httpStatus:this.httpStatus,details:this.details}}},el=class extends $c{constructor(e,t,n){super(e,Qc.UPLOAD_FAILED,void 0,n),this.name=`UploadError`,this.failedFiles=t}toJSON(){return{...super.toJSON(),failedFiles:this.failedFiles}}},tl=class extends $c{constructor(e){super(`Storage provider '${e||`(none)`}' is not supported by this SDK build.`,Qc.UNSUPPORTED_STORAGE_PROVIDER,void 0,{provider:e}),this.name=`UnsupportedStorageProviderError`,this.provider=e}},nl=bc({uploadData:bc({url:qs().min(1,`uploadData.url is required`),fields:Ec(qs(),qs())}),folderPath:qs().optional(),txn_id:qs().optional()}),rl=`key`,il="${filename}",al=`Content-Type`,ol=`audio/mp3`,sl=class{constructor(){this.name=`aws`}prepareUpload({fileName:e,blob:t,upload:n}){let r=nl.safeParse(n);if(!r.success)throw new el(`Invalid AWS upload payload in session response: ${r.error.message}`,[e]);let{uploadData:i}=r.data,a={};for(let[t,n]of Object.entries(i.fields))a[t]=t===rl?n.split(il).join(e):n;if(!(al in a)){let e=t?.type;a[al]=e&&e.startsWith(`audio/`)?e:ol}return{url:i.url,method:`POST`,bodyMode:`multipart`,formFields:a,fileFieldName:`file`,headers:{},attachAuth:!1}}},cl={aws:()=>new sl};function ll(e){return typeof e==`string`?e.trim().toLowerCase():``}function ul(e){let t=cl[ll(e)];if(!t)throw new tl(e);return t()}var dl=2,fl=2e3,pl=1e4,ml,hl=[],gl=new Map,_l=null,vl=new Map;function yl(e,t){let n=vl.get(e);if(n){vl.delete(e);for(let e of n)e(t)}}function bl(e,t){try{e.postMessage(t)}catch{}}function xl(e){for(let t of hl)bl(t,e)}function Sl(){return new Promise(e=>{let t=_l;_l=()=>{t?.(),e()},setTimeout(()=>{e()},pl)})}function Cl(e){return new Promise(t=>{let n=vl.get(e);n||(n=new Set,vl.set(e,n)),n.add(t),setTimeout(()=>{let n=vl.get(e);n?.has(t)&&(n.delete(t),n.size===0&&vl.delete(e),t(null))},pl)})}function wl(e,t,n,r){let i={...e.headers};e.attachAuth&&(Object.assign(i,r),ml&&(i.Authorization=`Bearer ${ml}`));let a;if(e.bodyMode===`multipart`&&e.formFields){let r=new FormData;for(let[t,n]of Object.entries(e.formFields))r.append(t,n);r.append(e.fileFieldName??`file`,n,t),a=r}else a=n,i[`Content-Type`]||=`audio/mp3`;return{method:e.method,body:a,headers:i,credentials:e.attachAuth?`include`:`omit`}}async function Tl(e,t,n,r,i){bl(e,{type:`upload_url_required`,fileName:n});let a=await Cl(e);if(!a)return i;try{return ul(t).prepareUpload({fileName:n,blob:r,upload:a})}catch{return i}}async function El(e,t,n,r,i,a){let o=`Upload failed after retries`,s;for(let c=0;c<=dl;c++)try{let l=await fetch(e.url,wl(e,t,n,r));if(l.ok)return{success:!0};if(s=l.status,o=await Dl(l),l.status===401&&e.attachAuth){xl({type:`token_required`}),await Sl();continue}if(c<dl){e=await Tl(a,i,t,n,e),await Ol(fl);continue}return{success:!1,error:o,statusCode:s}}catch(r){o=r?.message??`Network error`,c<dl&&(e=await Tl(a,i,t,n,e),await Ol(fl))}return{success:!1,error:o,statusCode:s}}async function Dl(e){try{let t=await e.json();return t?.error?.message??t?.message??e.statusText??`Request failed`}catch{return e.statusText??`HTTP ${e.status}`}}function Ol(e){return new Promise(t=>setTimeout(t,e))}async function kl(e,t,n,r,i,a){try{let o=Xn(e);if(!o){bl(a,{type:`upload_failed`,fileName:t,error:`MP3 encoding failed`});return}bl(a,{type:`chunk_encoded`,fileName:t,chunkData:o.chunks});let s;try{s=ul(n).prepareUpload({fileName:t,blob:o.blob,upload:r})}catch(e){bl(a,{type:`upload_failed`,fileName:t,error:e?.message??`Failed to prepare upload`,chunkData:o.chunks});return}let c=await El(s,t,o.blob,i,n,a);c.success?bl(a,{type:`upload_success`,fileName:t}):bl(a,{type:`upload_failed`,fileName:t,error:c.error??`Upload failed after retries`,chunkData:o.chunks})}catch(e){bl(a,{type:`upload_failed`,fileName:t,error:e?.message??`Unknown error`})}}function Al(e,t){switch(e.type){case`compress_and_upload`:{gl.has(t)||gl.set(t,new Set);let n=gl.get(t),r=kl(e.audioFrames,e.fileName,e.storageProvider,e.upload,e.headers,t);n.add(r),r.finally(()=>n.delete(r));break}case`wait_for_all_uploads`:{let e=gl.get(t)??new Set;Promise.all(e).then(()=>{bl(t,{type:`all_uploads_complete`})});break}case`update_auth_token`:ml=e.token,_l&&=(_l(),null);break;case`update_upload_url`:yl(t,e.upload);break;case`terminate`:{let e=hl.indexOf(t);e>=0&&hl.splice(e,1),gl.delete(t),yl(t,null);try{t.close()}catch{}hl.length===0&&self.close();break}}}var jl=self;jl.onconnect=e=>{let t=e.ports[0];hl.push(t),t.onmessage=e=>{Al(e.data,t)},t.start()}})();
|
|
77
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Qo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:ts(t,`input`,e.processors),output:ts(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function $o(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return $o(r.element,n);if(r.type===`set`)return $o(r.valueType,n);if(r.type===`lazy`)return $o(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`)return $o(r.innerType,n);if(r.type===`intersection`)return $o(r.left,n)||$o(r.right,n);if(r.type===`record`||r.type===`map`)return $o(r.keyType,n)||$o(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:$o(r.in,n)||$o(r.out,n);if(r.type===`object`){for(let e in r.shape)if($o(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if($o(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if($o(e,n))return!0;return!!(r.rest&&$o(r.rest,n))}return!1}var es=(e,t={})=>n=>{let r=Yo({...n,processors:t});return Xo(e,r),Zo(r,e),Qo(r,e)},ts=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Yo({...i??{},target:a,io:t,processors:n});return Xo(e,o),Zo(o,e),Qo(o,e)},ns={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},rs=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ns[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},is=(e,t,n,r)=>{n.not={}},as=(e,t,n,r)=>{let i=e._zod.def,a=nr(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},os=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},ss=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},cs=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Xo(a.element,t,{...r,path:[...r.path,`items`]})},ls=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=Xo(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Xo(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},us=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Xo(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},ds=(e,t,n,r)=>{let i=e._zod.def,a=Xo(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Xo(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},fs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Xo(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=Xo(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=Xo(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},ps=(e,t,n,r)=>{let i=e._zod.def,a=Xo(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},ms=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},hs=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},gs=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},_s=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},vs=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;Xo(o,t,r);let s=t.seen.get(e);s.ref=o},ys=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},bs=(e,t,n,r)=>{let i=e._zod.def;Xo(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},xs=Y(`ZodISODateTime`,(e,t)=>{na.init(e,t),$.init(e,t)});function Ss(e){return wo(xs,e)}var Cs=Y(`ZodISODate`,(e,t)=>{ra.init(e,t),$.init(e,t)});function ws(e){return To(Cs,e)}var Ts=Y(`ZodISOTime`,(e,t)=>{ia.init(e,t),$.init(e,t)});function Es(e){return Eo(Ts,e)}var Ds=Y(`ZodISODuration`,(e,t)=>{aa.init(e,t),$.init(e,t)});function Os(e){return Do(Ds,e)}var ks=Y(`ZodError`,(e,t)=>{Ir.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>zr(e,t)},flatten:{value:t=>Rr(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,rr,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,rr,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),As=Br(ks),js=Vr(ks),Ms=Hr(ks),Ns=Wr(ks),Ps=Kr(ks),Fs=qr(ks),Is=Jr(ks),Ls=Yr(ks),Rs=Xr(ks),zs=Zr(ks),Bs=Qr(ks),Vs=$r(ks),Hs=new WeakMap;function Us(e,t,n){let r=Object.getPrototypeOf(e),i=Hs.get(r);if(i||(i=new Set,Hs.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var Ws=Y(`ZodType`,(e,t)=>(Ui.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:ts(e,`input`),output:ts(e,`output`)}}),e.toJSONSchema=es(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.parse=(t,n)=>As(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ms(e,t,n),e.parseAsync=async(t,n)=>js(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ns(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Ps(e,t,n),e.decode=(t,n)=>Fs(e,t,n),e.encodeAsync=async(t,n)=>Is(e,t,n),e.decodeAsync=async(t,n)=>Ls(e,t,n),e.safeEncode=(t,n)=>Rs(e,t,n),e.safeDecode=(t,n)=>zs(e,t,n),e.safeEncodeAsync=async(t,n)=>Bs(e,t,n),e.safeDecodeAsync=async(t,n)=>Vs(e,t,n),Us(e,`ZodType`,{check(...e){let t=this.def;return this.clone(lr(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return yr(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Xc(e,t))},superRefine(e,t){return this.check(Zc(e,t))},overwrite(e){return this.check(zo(e))},optional(){return Mc(this)},exactOptional(){return Pc(this)},nullable(){return Ic(this)},nullish(){return Mc(Ic(this))},nonoptional(e){return Hc(this,e)},array(){return vc(this)},or(e){return Sc([this,e])},and(e){return wc(this,e)},transform(e){return Kc(this,Ac(e))},default(e){return Rc(this,e)},prefault(e){return Bc(this,e)},catch(e){return Wc(this,e)},pipe(e){return Kc(this,e)},readonly(){return Jc(this)},describe(e){let t=this.clone();return $a.add(t,{description:e}),t},meta(...e){if(e.length===0)return $a.get(this);let t=this.clone();return $a.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,`description`,{get(){return $a.get(e)?.description},configurable:!0}),e)),Gs=Y(`_ZodString`,(e,t)=>{Wi.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rs(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Us(e,`_ZodString`,{regex(...e){return this.check(No(...e))},includes(...e){return this.check(Io(...e))},startsWith(...e){return this.check(Lo(...e))},endsWith(...e){return this.check(Ro(...e))},min(...e){return this.check(jo(...e))},max(...e){return this.check(Ao(...e))},length(...e){return this.check(Mo(...e))},nonempty(...e){return this.check(jo(1,...e))},lowercase(e){return this.check(Po(e))},uppercase(e){return this.check(Fo(e))},trim(){return this.check(Vo())},normalize(...e){return this.check(Bo(...e))},toLowerCase(){return this.check(Ho())},toUpperCase(){return this.check(Uo())},slugify(){return this.check(Wo())}})}),Ks=Y(`ZodString`,(e,t)=>{Wi.init(e,t),Gs.init(e,t),e.email=t=>e.check(to(Js,t)),e.url=t=>e.check(so(Zs,t)),e.jwt=t=>e.check(Co(fc,t)),e.emoji=t=>e.check(co(Qs,t)),e.guid=t=>e.check(no(Ys,t)),e.uuid=t=>e.check(ro(Xs,t)),e.uuidv4=t=>e.check(io(Xs,t)),e.uuidv6=t=>e.check(ao(Xs,t)),e.uuidv7=t=>e.check(oo(Xs,t)),e.nanoid=t=>e.check(lo($s,t)),e.guid=t=>e.check(no(Ys,t)),e.cuid=t=>e.check(uo(ec,t)),e.cuid2=t=>e.check(fo(tc,t)),e.ulid=t=>e.check(po(nc,t)),e.base64=t=>e.check(bo(lc,t)),e.base64url=t=>e.check(xo(uc,t)),e.xid=t=>e.check(mo(rc,t)),e.ksuid=t=>e.check(ho(ic,t)),e.ipv4=t=>e.check(go(ac,t)),e.ipv6=t=>e.check(_o(oc,t)),e.cidrv4=t=>e.check(vo(sc,t)),e.cidrv6=t=>e.check(yo(cc,t)),e.e164=t=>e.check(So(dc,t)),e.datetime=t=>e.check(Ss(t)),e.date=t=>e.check(ws(t)),e.time=t=>e.check(Es(t)),e.duration=t=>e.check(Os(t))});function qs(e){return eo(Ks,e)}var $=Y(`ZodStringFormat`,(e,t)=>{Q.init(e,t),Gs.init(e,t)}),Js=Y(`ZodEmail`,(e,t)=>{qi.init(e,t),$.init(e,t)}),Ys=Y(`ZodGUID`,(e,t)=>{Gi.init(e,t),$.init(e,t)}),Xs=Y(`ZodUUID`,(e,t)=>{Ki.init(e,t),$.init(e,t)}),Zs=Y(`ZodURL`,(e,t)=>{Ji.init(e,t),$.init(e,t)}),Qs=Y(`ZodEmoji`,(e,t)=>{Yi.init(e,t),$.init(e,t)}),$s=Y(`ZodNanoID`,(e,t)=>{Xi.init(e,t),$.init(e,t)}),ec=Y(`ZodCUID`,(e,t)=>{Zi.init(e,t),$.init(e,t)}),tc=Y(`ZodCUID2`,(e,t)=>{Qi.init(e,t),$.init(e,t)}),nc=Y(`ZodULID`,(e,t)=>{$i.init(e,t),$.init(e,t)}),rc=Y(`ZodXID`,(e,t)=>{ea.init(e,t),$.init(e,t)}),ic=Y(`ZodKSUID`,(e,t)=>{ta.init(e,t),$.init(e,t)}),ac=Y(`ZodIPv4`,(e,t)=>{oa.init(e,t),$.init(e,t)}),oc=Y(`ZodIPv6`,(e,t)=>{sa.init(e,t),$.init(e,t)}),sc=Y(`ZodCIDRv4`,(e,t)=>{ca.init(e,t),$.init(e,t)}),cc=Y(`ZodCIDRv6`,(e,t)=>{la.init(e,t),$.init(e,t)}),lc=Y(`ZodBase64`,(e,t)=>{da.init(e,t),$.init(e,t)}),uc=Y(`ZodBase64URL`,(e,t)=>{pa.init(e,t),$.init(e,t)}),dc=Y(`ZodE164`,(e,t)=>{ma.init(e,t),$.init(e,t)}),fc=Y(`ZodJWT`,(e,t)=>{ga.init(e,t),$.init(e,t)}),pc=Y(`ZodUnknown`,(e,t)=>{_a.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function mc(){return Oo(pc)}var hc=Y(`ZodNever`,(e,t)=>{va.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>is(e,t,n,r)});function gc(e){return ko(hc,e)}var _c=Y(`ZodArray`,(e,t)=>{ba.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cs(e,t,n,r),e.element=t.element,Us(e,`ZodArray`,{min(e,t){return this.check(jo(e,t))},nonempty(e){return this.check(jo(1,e))},max(e,t){return this.check(Ao(e,t))},length(e,t){return this.check(Mo(e,t))},unwrap(){return this.element}})});function vc(e,t){return Go(_c,e,t)}var yc=Y(`ZodObject`,(e,t)=>{Ta.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ls(e,t,n,r),X(e,`shape`,()=>t.shape),Us(e,`ZodObject`,{keyof(){return Oc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:mc()})},loose(){return this.clone({...this._zod.def,catchall:mc()})},strict(){return this.clone({...this._zod.def,catchall:gc()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return Cr(this,e)},safeExtend(e){return wr(this,e)},merge(e){return Tr(this,e)},pick(e){return xr(this,e)},omit(e){return Sr(this,e)},partial(...e){return Er(jc,this,e[0])},required(...e){return Dr(Vc,this,e[0])}})});function bc(e,t){return new yc({type:`object`,shape:e??{},...Z(t)})}var xc=Y(`ZodUnion`,(e,t)=>{Da.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r),e.options=t.options});function Sc(e,t){return new xc({type:`union`,options:e,...Z(t)})}var Cc=Y(`ZodIntersection`,(e,t)=>{Oa.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r)});function wc(e,t){return new Cc({type:`intersection`,left:e,right:t})}var Tc=Y(`ZodRecord`,(e,t)=>{ja.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Ec(e,t,n){return!t||!t._zod?new Tc({type:`record`,keyType:qs(),valueType:e,...Z(t)}):new Tc({type:`record`,keyType:e,valueType:t,...Z(n)})}var Dc=Y(`ZodEnum`,(e,t)=>{Ma.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>as(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Dc({...t,checks:[],...Z(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Dc({...t,checks:[],...Z(r),entries:i})}});function Oc(e,t){return new Dc({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...Z(t)})}var kc=Y(`ZodTransform`,(e,t)=>{Na.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new $n(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Pr(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Pr(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function Ac(e){return new kc({type:`transform`,transform:e})}var jc=Y(`ZodOptional`,(e,t)=>{Fa.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mc(e){return new jc({type:`optional`,innerType:e})}var Nc=Y(`ZodExactOptional`,(e,t)=>{Ia.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Pc(e){return new Nc({type:`optional`,innerType:e})}var Fc=Y(`ZodNullable`,(e,t)=>{La.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ps(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ic(e){return new Fc({type:`nullable`,innerType:e})}var Lc=Y(`ZodDefault`,(e,t)=>{Ra.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Rc(e,t){return new Lc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():gr(t)}})}var zc=Y(`ZodPrefault`,(e,t)=>{Ba.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>gs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bc(e,t){return new zc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():gr(t)}})}var Vc=Y(`ZodNonOptional`,(e,t)=>{Va.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ms(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hc(e,t){return new Vc({type:`nonoptional`,innerType:e,...Z(t)})}var Uc=Y(`ZodCatch`,(e,t)=>{Ua.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>_s(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Wc(e,t){return new Uc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Gc=Y(`ZodPipe`,(e,t)=>{Wa.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vs(e,t,n,r),e.in=t.in,e.out=t.out});function Kc(e,t){return new Gc({type:`pipe`,in:e,out:t})}var qc=Y(`ZodReadonly`,(e,t)=>{Ka.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ys(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Jc(e){return new qc({type:`readonly`,innerType:e})}var Yc=Y(`ZodCustom`,(e,t)=>{Ja.init(e,t),Ws.init(e,t),e._zod.processJSONSchema=(t,n,r)=>os(e,t,n,r)});function Xc(e,t={}){return Ko(Yc,e,t)}function Zc(e,t){return qo(e,t)}var Qc=function(e){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}({}),$c=class e extends Error{constructor(t,n=Qc.INTERNAL_ERROR,r,i){super(t),this.name=`ScribeError`,this.code=n,this.httpStatus=r,this.details=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}static fromApiError(t,n){return new e(t.message,t.code,n,t.details)}toJSON(){return{name:this.name,message:this.message,code:this.code,httpStatus:this.httpStatus,details:this.details}}},el=class extends $c{constructor(e,t,n){super(e,Qc.UPLOAD_FAILED,void 0,n),this.name=`UploadError`,this.failedFiles=t}toJSON(){return{...super.toJSON(),failedFiles:this.failedFiles}}},tl=class extends $c{constructor(e){super(`Storage provider '${e||`(none)`}' is not supported by this SDK build.`,Qc.UNSUPPORTED_STORAGE_PROVIDER,void 0,{provider:e}),this.name=`UnsupportedStorageProviderError`,this.provider=e}},nl=bc({uploadData:bc({url:qs().min(1,`uploadData.url is required`),fields:Ec(qs(),qs())}),folderPath:qs().optional(),txn_id:qs().optional()}),rl=`key`,il="${filename}",al=`Content-Type`,ol=`audio/mp3`,sl=class{constructor(){this.name=`aws`}prepareUpload({fileName:e,blob:t,upload:n}){let r=nl.safeParse(n);if(!r.success)throw new el(`Invalid AWS upload payload in session response: ${r.error.message}`,[e]);let{uploadData:i}=r.data,a={};for(let[t,n]of Object.entries(i.fields))a[t]=t===rl?n.split(il).join(e):n;if(!(al in a)){let e=t?.type;a[al]=e&&e.startsWith(`audio/`)?e:ol}return{url:i.url,method:`POST`,bodyMode:`multipart`,formFields:a,fileFieldName:`file`,headers:{},attachAuth:!1}}},cl=qs().trim().min(1,`upload_url is required`),ll=`Content-Type`,ul=`audio/mp3`,dl={mp3:`audio/mp3`,webm:`audio/webm`,wav:`audio/wav`,ogg:`audio/ogg`,m4a:`audio/m4a`,mp4:`audio/mp4`};function fl(e,t){let n=t?.type;return n&&n.startsWith(`audio/`)?n:dl[e.split(`.`).pop()?.toLowerCase()??``]??ul}var pl=class{constructor(){this.name=`backend`}prepareUpload({fileName:e,blob:t,upload:n}){let r=cl.safeParse(n);if(!r.success)throw new el(`Invalid backend upload payload: expected an upload_url string, got ${typeof n}`,[e]);return{url:`${r.data.replace(/\/+$/,``)}/${encodeURIComponent(e)}`,method:`POST`,bodyMode:`binary`,headers:{[ll]:fl(e,t)},attachAuth:!0}}},ml={aws:()=>new sl,backend:()=>new pl};function hl(e){return typeof e==`string`?e.trim().toLowerCase():``}function gl(e){let t=ml[hl(e)];if(!t)throw new tl(e);return t()}var _l=2,vl=2e3,yl=1e4,bl,xl=[],Sl=new Map,Cl=null,wl=new Map;function Tl(e,t){let n=wl.get(e);if(n){wl.delete(e);for(let e of n)e(t)}}function El(e,t){try{e.postMessage(t)}catch{}}function Dl(e){for(let t of xl)El(t,e)}function Ol(){return new Promise(e=>{let t=Cl;Cl=()=>{t?.(),e()},setTimeout(()=>{e()},yl)})}function kl(e){return new Promise(t=>{let n=wl.get(e);n||(n=new Set,wl.set(e,n)),n.add(t),setTimeout(()=>{let n=wl.get(e);n?.has(t)&&(n.delete(t),n.size===0&&wl.delete(e),t(null))},yl)})}function Al(e,t,n,r){let i={...e.headers};e.attachAuth&&(Object.assign(i,r),bl&&(i.Authorization=`Bearer ${bl}`));let a;if(e.bodyMode===`multipart`&&e.formFields){let r=new FormData;for(let[t,n]of Object.entries(e.formFields))r.append(t,n);r.append(e.fileFieldName??`file`,n,t),a=r}else a=n,i[`Content-Type`]||=`audio/mp3`;return{method:e.method,body:a,headers:i,credentials:e.attachAuth?`include`:`omit`}}async function jl(e,t,n,r,i){El(e,{type:`upload_url_required`,fileName:n});let a=await kl(e);if(!a)return i;try{return gl(t).prepareUpload({fileName:n,blob:r,upload:a})}catch{return i}}async function Ml(e,t,n,r,i,a){let o=`Upload failed after retries`,s;for(let c=0;c<=_l;c++)try{let l=await fetch(e.url,Al(e,t,n,r));if(l.ok)return{success:!0};if(s=l.status,o=await Nl(l),l.status===401&&e.attachAuth){Dl({type:`token_required`}),await Ol();continue}if(c<_l){e=await jl(a,i,t,n,e),await Pl(vl);continue}return{success:!1,error:o,statusCode:s}}catch(r){o=r?.message??`Network error`,c<_l&&(e=await jl(a,i,t,n,e),await Pl(vl))}return{success:!1,error:o,statusCode:s}}async function Nl(e){try{let t=await e.json();return t?.error?.message??t?.message??e.statusText??`Request failed`}catch{return e.statusText??`HTTP ${e.status}`}}function Pl(e){return new Promise(t=>setTimeout(t,e))}async function Fl(e,t,n,r,i,a){try{let o=Xn(e);if(!o){El(a,{type:`upload_failed`,fileName:t,error:`MP3 encoding failed`});return}El(a,{type:`chunk_encoded`,fileName:t,chunkData:o.chunks});let s;try{s=gl(n).prepareUpload({fileName:t,blob:o.blob,upload:r})}catch(e){El(a,{type:`upload_failed`,fileName:t,error:e?.message??`Failed to prepare upload`,chunkData:o.chunks});return}let c=await Ml(s,t,o.blob,i,n,a);c.success?El(a,{type:`upload_success`,fileName:t}):El(a,{type:`upload_failed`,fileName:t,error:c.error??`Upload failed after retries`,chunkData:o.chunks})}catch(e){El(a,{type:`upload_failed`,fileName:t,error:e?.message??`Unknown error`})}}function Il(e,t){switch(e.type){case`compress_and_upload`:{Sl.has(t)||Sl.set(t,new Set);let n=Sl.get(t),r=Fl(e.audioFrames,e.fileName,e.storageProvider,e.upload,e.headers,t);n.add(r),r.finally(()=>n.delete(r));break}case`wait_for_all_uploads`:{let e=Sl.get(t)??new Set;Promise.all(e).then(()=>{El(t,{type:`all_uploads_complete`})});break}case`update_auth_token`:bl=e.token,Cl&&=(Cl(),null);break;case`update_upload_url`:Tl(t,e.upload);break;case`terminate`:{let e=xl.indexOf(t);e>=0&&xl.splice(e,1),Sl.delete(t),Tl(t,null);try{t.close()}catch{}xl.length===0&&self.close();break}}}var Ll=self;Ll.onconnect=e=>{let t=e.ports[0];xl.push(t),t.onmessage=e=>{Il(e.data,t)},t.start()}})();
|