med-scribe-alliance-ts-sdk 2.0.53 → 2.0.55

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 CHANGED
@@ -401,7 +401,7 @@ interface RecordingOptions {
401
401
  | `getCurrentSession()` | `CreateSessionResponse \| null` | Get the active session if any. |
402
402
  | `updateSession(request, sessionId?)` | `SDKResult<PatchSessionResponse>` | Patch session (patient details, status, etc.). |
403
403
  | `processTemplate(templateId, sessionId?)` | `SDKResult<ProcessTemplateResponse>` | Trigger processing for a specific template. |
404
- | `cancelSession(sessionId?)` | `SDKResult<PatchSessionResponse>` | Cancel session (stops recorder, no server processing). |
404
+ | `cancelSession(sessionId?, { keepAlive? })` | `SDKResult<PatchSessionResponse>` | Cancel session (stops recorder, no server processing). `keepAlive: true` lets the request survive page unload. |
405
405
 
406
406
  ### Discovery
407
407
 
package/dist/index.d.ts CHANGED
@@ -217,6 +217,8 @@ export interface TransportRequest {
217
217
  /** Additional HTTP status codes to treat as success (not throw). */
218
218
  acceptStatuses?: number[];
219
219
  maxRetries?: number;
220
+ /** Sets fetch keepalive so the request survives page unload. */
221
+ keepAlive?: boolean;
220
222
  }
221
223
  export interface TransportResponse<T = any> {
222
224
  status: number;
@@ -353,7 +355,6 @@ export interface ResolvedConfig {
353
355
  supportedAudioFormats: string[];
354
356
  supportedUploadMethods: string[];
355
357
  storageProviders: string[];
356
- storageProvider: string;
357
358
  maxChunkDurationSeconds: number;
358
359
  /** modelId -> max session duration in seconds */
359
360
  maxSessionDurationSeconds: Map<string, number>;
@@ -469,6 +470,7 @@ export interface PatchSessionRequest {
469
470
  language_hint?: string[];
470
471
  transcript_language?: string;
471
472
  templates?: string[];
473
+ conversation_id?: string;
472
474
  }
473
475
  export interface PatchSessionResponse {
474
476
  session_id: string;
@@ -853,7 +855,9 @@ export declare class ScribeClient {
853
855
  * Patch/update a session (e.g., update user_status or processing_status).
854
856
  * Uses the current active session if no sessionId is provided.
855
857
  */
856
- updateSession(request: PatchSessionRequest, sessionId?: string): Promise<SDKResult<PatchSessionResponse>>;
858
+ updateSession(request: PatchSessionRequest, sessionId?: string, options?: {
859
+ keepAlive?: boolean;
860
+ }): Promise<SDKResult<PatchSessionResponse>>;
857
861
  /**
858
862
  * Trigger processing for a specific template in a session.
859
863
  * Uses the current active session if no sessionId is provided.
@@ -863,7 +867,9 @@ export declare class ScribeClient {
863
867
  * Cancel a session by setting both user_status and processing_status to 'cancelled'.
864
868
  * Uses the current active session if no sessionId is provided.
865
869
  */
866
- cancelSession(sessionId?: string): Promise<SDKResult<PatchSessionResponse>>;
870
+ cancelSession(sessionId?: string, options?: {
871
+ keepAlive?: boolean;
872
+ }): Promise<SDKResult<PatchSessionResponse>>;
867
873
  /**
868
874
  * Get the resolved discovery config.
869
875
  * Returns error if discovery hasn't been fetched yet.
@@ -1099,7 +1105,9 @@ export declare class SessionManager {
1099
1105
  /**
1100
1106
  * Patch an existing session (e.g., update user_status or processing_status).
1101
1107
  */
1102
- patchSession(baseUrl: string, request: PatchSessionRequest, sessionId?: string): Promise<ApiCallResult<PatchSessionResponse>>;
1108
+ patchSession(baseUrl: string, request: PatchSessionRequest, sessionId?: string, options?: {
1109
+ keepAlive?: boolean;
1110
+ }): Promise<ApiCallResult<PatchSessionResponse>>;
1103
1111
  /**
1104
1112
  * Trigger processing for a specific template in a session.
1105
1113
  */
@@ -1254,7 +1262,6 @@ export declare class RecordingManager {
1254
1262
  * Create the appropriate recorder based on upload type.
1255
1263
  */
1256
1264
  private createRecorder;
1257
- /** Storage provider name from discovery; defaults to 'aws'. */
1258
1265
  private getStorageProviderName;
1259
1266
  /** Validate the provider has a wrapper (throws UnsupportedStorageProviderError) and return its name. */
1260
1267
  private resolveStorageProviderName;
package/dist/index.mjs CHANGED
@@ -202,7 +202,8 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
202
202
  additional_data: e.record(e.string(), e.any()).optional(),
203
203
  language_hint: e.array(e.string()).optional(),
204
204
  transcript_language: e.string().optional(),
205
- templates: e.array(e.string()).optional()
205
+ templates: e.array(e.string()).optional(),
206
+ conversation_id: e.string().optional()
206
207
  }), le = e.object({
207
208
  session_id: e.string().min(1, "session_id is required"),
208
209
  status: e.string(),
@@ -456,7 +457,7 @@ var N = class {
456
457
  headers: t,
457
458
  credentials: n ? "omit" : "include"
458
459
  };
459
- if (e.isUpload && e.uploadFormFields) {
460
+ if (e.keepAlive && (r.keepalive = !0), e.isUpload && e.uploadFormFields) {
460
461
  let t = new FormData();
461
462
  for (let [n, r] of Object.entries(e.uploadFormFields)) t.append(n, r);
462
463
  e.uploadBlob && t.append(e.uploadFileFieldName ?? "file", e.uploadBlob, e.uploadFileName), r.body = t;
@@ -668,12 +669,12 @@ var N = class {
668
669
  destroy() {
669
670
  for (let [e, t] of this.pendingRequests) t.reject(new T("IPC transport destroyed")), this.pendingRequests.delete(e);
670
671
  }
671
- }, F = "aws";
672
- function ve(e) {
672
+ }, ve = "aws";
673
+ function ye(e) {
673
674
  let t = (e.storage_providers ?? []).filter((e) => typeof e == "string").map((e) => e.trim().toLowerCase()).filter((e) => e.length > 0);
674
- return t.length > 0 ? Array.from(new Set(t)) : [F];
675
+ return t.length > 0 ? Array.from(new Set(t)) : [ve];
675
676
  }
676
- function ye(e) {
677
+ function be(e) {
677
678
  try {
678
679
  let t = /* @__PURE__ */ new Map(), n = e.models ?? [];
679
680
  for (let e of n) e.id && typeof e.max_session_duration_seconds == "number" && t.set(e.id, e.max_session_duration_seconds);
@@ -684,8 +685,7 @@ function ye(e) {
684
685
  autoDetectLanguage: e.languages?.auto_detection ?? !1,
685
686
  supportedAudioFormats: e.capabilities.audio_formats,
686
687
  supportedUploadMethods: e.capabilities.upload_methods ?? [],
687
- storageProviders: ve(e.capabilities),
688
- storageProvider: F,
688
+ storageProviders: ye(e.capabilities),
689
689
  maxChunkDurationSeconds: e.capabilities.max_chunk_duration_seconds,
690
690
  maxSessionDurationSeconds: t,
691
691
  supportedAuthMethods: e.authentication.supported_methods,
@@ -699,7 +699,7 @@ function ye(e) {
699
699
  }
700
700
  //#endregion
701
701
  //#region src/discovery/discovery-manager.ts
702
- var I = class {
702
+ var F = class {
703
703
  constructor(e, t, n = !1) {
704
704
  this.cachedDocument = null, this.resolvedConfig = null, this.cacheTimestamp = 0, this.cacheTtlMs = i, this.transport = e, this.validator = t, this.debug = n;
705
705
  }
@@ -716,7 +716,7 @@ var I = class {
716
716
  url: n
717
717
  });
718
718
  this.validator.validateDiscoveryResponse(i.data);
719
- let a = i.data, o = ye(a);
719
+ let a = i.data, o = be(a);
720
720
  return this.cachedDocument = a, this.resolvedConfig = o, this.cacheTimestamp = Date.now(), this.debug && console.log("[ScribeSDK] Discovery complete:", a.service?.name ?? a.protocol), {
721
721
  data: o,
722
722
  httpStatus: i.status
@@ -769,7 +769,7 @@ var I = class {
769
769
  isCacheValid() {
770
770
  return Date.now() - this.cacheTimestamp < this.cacheTtlMs;
771
771
  }
772
- }, L = class {
772
+ }, I = class {
773
773
  constructor(e, t, n = !1) {
774
774
  this.currentSession = null, this.transport = e, this.validator = t, this.debug = n;
775
775
  }
@@ -833,21 +833,22 @@ var I = class {
833
833
  throw e instanceof v ? e : new v(`Failed to get session status: ${e instanceof Error ? e.message : "Unknown error"}`);
834
834
  }
835
835
  }
836
- async patchSession(e, t, n) {
836
+ async patchSession(e, t, n, r) {
837
837
  try {
838
- let r = n ?? this.currentSession?.session_id;
839
- if (!r) throw new v("No active session. Provide a sessionId or start a session first.");
840
- this.validator.validateSessionId(r), this.validator.validatePatchSessionRequest(t);
841
- let i = `${e}/sessions/${r}`;
842
- this.debug && console.log("[ScribeSDK] Patching session:", r, t);
843
- let a = await this.transport.request({
838
+ let i = n ?? this.currentSession?.session_id;
839
+ if (!i) throw new v("No active session. Provide a sessionId or start a session first.");
840
+ this.validator.validateSessionId(i), this.validator.validatePatchSessionRequest(t);
841
+ let a = `${e}/sessions/${i}`;
842
+ this.debug && console.log("[ScribeSDK] Patching session:", i, t);
843
+ let o = await this.transport.request({
844
844
  method: "PATCH",
845
- url: i,
846
- body: t
845
+ url: a,
846
+ body: t,
847
+ keepAlive: r?.keepAlive
847
848
  });
848
- return this.validator.validatePatchSessionResponse(a.data), this.debug && console.log("[ScribeSDK] Session patched:", r, a.data.status), {
849
- data: a.data,
850
- httpStatus: a.status
849
+ return this.validator.validatePatchSessionResponse(o.data), this.debug && console.log("[ScribeSDK] Session patched:", i, o.data.status), {
850
+ data: o.data,
851
+ httpStatus: o.status
851
852
  };
852
853
  } catch (e) {
853
854
  throw e instanceof v ? e : new v(`Failed to patch session: ${e instanceof Error ? e.message : "Unknown error"}`);
@@ -937,13 +938,13 @@ var I = class {
937
938
  }, { once: !0 });
938
939
  }) : this.sleep(e);
939
940
  }
940
- }, R = 1024, z = 16e3;
941
- R / z, z / R;
942
- var be = {
941
+ }, L = 1024, R = 16e3;
942
+ L / R, R / L;
943
+ var xe = {
943
944
  m4a: "audio/m4a",
944
945
  wav: "audio/wav",
945
946
  mp3: "audio/mpeg"
946
- }, xe = class {
947
+ }, Se = class {
947
948
  constructor(e, t) {
948
949
  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;
949
950
  let n = e.samplingRate;
@@ -1075,7 +1076,7 @@ var be = {
1075
1076
  } catch {}
1076
1077
  this.micStream = null;
1077
1078
  }
1078
- }, Se = class {
1079
+ }, z = class {
1079
1080
  constructor(e, t) {
1080
1081
  this.currentSampleLength = 0, this.currentFrameLength = 0, this.samplingRate = e, this.incrementalAllocationSize = Math.floor(e * t), this.buffer = new Float32Array(this.incrementalAllocationSize);
1081
1082
  }
@@ -1224,7 +1225,7 @@ var be = {
1224
1225
  };
1225
1226
  //#endregion
1226
1227
  //#region src/audio/mp3-encoder.ts
1227
- function we(e, t = z, r = 128) {
1228
+ function we(e, t = R, r = 128) {
1228
1229
  try {
1229
1230
  let i = new n.Mp3Encoder(1, t, r), a = new Int16Array(e.length);
1230
1231
  for (let t = 0; t < e.length; t++) {
@@ -1235,7 +1236,7 @@ function we(e, t = z, r = 128) {
1235
1236
  s && s.length > 0 && o.push(s);
1236
1237
  let c = i.flush();
1237
1238
  return c && c.length > 0 && o.push(c), o.length === 0 ? null : {
1238
- blob: new Blob(o, { type: be.mp3 }),
1239
+ blob: new Blob(o, { type: xe.mp3 }),
1239
1240
  chunks: o
1240
1241
  };
1241
1242
  } catch (e) {
@@ -1363,7 +1364,7 @@ var Ie = class {
1363
1364
  this.uploadPayload = e, this.storageProviderName = t, this.uploadHeaders = n, this.refreshUploadUrl = r ?? null, G(t);
1364
1365
  }
1365
1366
  compressAndUpload(e, t, n) {
1366
- let r = e.length / z;
1367
+ let r = e.length / R;
1367
1368
  if (r > 27) {
1368
1369
  this.fileManager.markFailure(n, new Blob(), `Chunk exceeds maximum length: ${r.toFixed(1)}s > 25s`), this.callbackRegistry.dispatch("onError", {
1369
1370
  type: m.VALIDATION_ERROR,
@@ -1567,7 +1568,7 @@ var Ie = class {
1567
1568
  }
1568
1569
  }, q = class {
1569
1570
  constructor(e, t, n, r) {
1570
- this._isPaused = !1, this.initialized = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.callbackRegistry = e, this.bufferManager = new Se(z, 25), this.fileManager = new Ce();
1571
+ this._isPaused = !1, this.initialized = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.callbackRegistry = e, this.bufferManager = new z(R, 25), this.fileManager = new Ce();
1571
1572
  let i = {
1572
1573
  prefChunkLength: n?.prefChunkLength ?? 10,
1573
1574
  despChunkLength: n?.despChunkLength ?? 20,
@@ -1578,7 +1579,7 @@ var Ie = class {
1578
1579
  shortSilenceThreshold: n?.shortSilenceThreshold,
1579
1580
  longSilenceThreshold: n?.longSilenceThreshold
1580
1581
  };
1581
- this.vadClient = new xe(i, e), this.workerManager = new Ie(e, this.fileManager, t, r), this.wireVadCallbacks();
1582
+ this.vadClient = new Se(i, e), this.workerManager = new Ie(e, this.fileManager, t, r), this.wireVadCallbacks();
1582
1583
  }
1583
1584
  initialize(e, t) {
1584
1585
  if (!t.upload || typeof t.upload != "object") throw Error("Upload payload is required for chunked recording");
@@ -1816,7 +1817,16 @@ var Ie = class {
1816
1817
  let e = this.mediaRecorder?.mimeType || "";
1817
1818
  return e.includes("mp4") ? "mp4" : e.includes("ogg") ? "ogg" : "webm";
1818
1819
  }
1819
- }, Y = class {
1820
+ }, Le = "aws", Y = "backend";
1821
+ function X(e) {
1822
+ return typeof e == "string" ? e.trim().length > 0 : typeof e == "object" && !!e;
1823
+ }
1824
+ function Z(e, t) {
1825
+ return (typeof e == "string" ? e.trim().toLowerCase() : "") || (typeof t == "string" ? Y : "aws");
1826
+ }
1827
+ //#endregion
1828
+ //#region src/recording/recording-manager.ts
1829
+ var Q = class {
1820
1830
  constructor(e, t, n, r, i) {
1821
1831
  this.recorder = null, this.activeSession = null, this.activeBaseUrl = "", this.activeUploadUrlRefresher = null, this._isRecording = !1, this._isStarting = !1, this._startGeneration = 0, this.retryContext = null, this.callbackRegistry = e, this.sessionManager = t, this.discoveryManager = n, this.transport = r, this.config = i ?? {};
1822
1832
  }
@@ -2145,11 +2155,7 @@ var Ie = class {
2145
2155
  return e === "single" ? new J(this.callbackRegistry, this.transport) : new q(this.callbackRegistry, this.transport, void 0, this.config.workerConfig);
2146
2156
  }
2147
2157
  getStorageProviderName() {
2148
- try {
2149
- return this.discoveryManager.getResolvedConfig().storageProvider || "aws";
2150
- } catch {
2151
- return "aws";
2152
- }
2158
+ return "aws";
2153
2159
  }
2154
2160
  resolveStorageProviderName() {
2155
2161
  let e = this.getStorageProviderName();
@@ -2208,23 +2214,14 @@ var Ie = class {
2208
2214
  partialCleanupAfterFailedFinalize() {
2209
2215
  this.recorder = null, this._isRecording = !1, this._isStarting = !1;
2210
2216
  }
2211
- }, Le = "aws", X = "backend";
2212
- function Z(e) {
2213
- return typeof e == "string" ? e.trim().length > 0 : typeof e == "object" && !!e;
2214
- }
2215
- function Q(e, t) {
2216
- return (typeof e == "string" ? e.trim().toLowerCase() : "") || (typeof t == "string" ? X : "aws");
2217
- }
2218
- //#endregion
2219
- //#region src/client.ts
2220
- var Re = class {
2217
+ }, Re = class {
2221
2218
  constructor(e) {
2222
2219
  this.isInitialized = !1, this.validateConfig(e), this.config = {
2223
2220
  debug: !1,
2224
2221
  autoDiscovery: !0,
2225
2222
  mode: l.DIRECT,
2226
2223
  ...e
2227
- }, this.callbackRegistry = new O(), this.validator = new k(), this.transport = this.createTransport(), this.discoveryManager = new I(this.transport, this.validator, this.config.debug), this.sessionManager = new L(this.transport, this.validator, this.config.debug), this.recordingManager = new Y(this.callbackRegistry, this.sessionManager, this.discoveryManager, this.transport, {
2224
+ }, this.callbackRegistry = new O(), this.validator = new k(), this.transport = this.createTransport(), this.discoveryManager = new F(this.transport, this.validator, this.config.debug), this.sessionManager = new I(this.transport, this.validator, this.config.debug), this.recordingManager = new Q(this.callbackRegistry, this.sessionManager, this.discoveryManager, this.transport, {
2228
2225
  debug: this.config.debug,
2229
2226
  flavour: this.config.flavour,
2230
2227
  workerConfig: this.resolveWorkerConfig()
@@ -2293,12 +2290,12 @@ var Re = class {
2293
2290
  return this.wrapResult(async () => {
2294
2291
  if (!e || e.size === 0) throw new y("A non-empty audio file is required");
2295
2292
  if (!t || !t.trim()) throw new y("fileName is required");
2296
- if (!Z(n)) throw new y("upload (upload_url payload) is required");
2293
+ if (!X(n)) throw new y("upload (upload_url payload) is required");
2297
2294
  let i = await K(this.transport, {
2298
2295
  fileName: t,
2299
2296
  blob: e,
2300
2297
  upload: n,
2301
- storageProvider: Q(r?.storageProvider ?? this.providerForUpload(n), n)
2298
+ storageProvider: Z(r?.storageProvider ?? this.providerForUpload(n), n)
2302
2299
  });
2303
2300
  return {
2304
2301
  data: {
@@ -2333,27 +2330,27 @@ var Re = class {
2333
2330
  getCurrentSession() {
2334
2331
  return this.recordingManager.getActiveSession() ?? this.sessionManager.getCurrentSession();
2335
2332
  }
2336
- async updateSession(e, t) {
2337
- let n = this.getEffectiveBaseUrl();
2338
- return this.wrapResult(() => this.sessionManager.patchSession(n, e, t));
2333
+ async updateSession(e, t, n) {
2334
+ let r = this.getEffectiveBaseUrl();
2335
+ return this.wrapResult(() => this.sessionManager.patchSession(r, e, t, n));
2339
2336
  }
2340
2337
  async processTemplate(e, t) {
2341
2338
  let n = this.getEffectiveBaseUrl();
2342
2339
  return this.wrapResult(() => this.sessionManager.processTemplate(n, e, t));
2343
2340
  }
2344
- async cancelSession(e) {
2345
- let t = e ?? this.recordingManager.getActiveSession()?.session_id ?? this.sessionManager.getCurrentSession()?.session_id;
2341
+ async cancelSession(e, t) {
2342
+ let n = e ?? this.recordingManager.getActiveSession()?.session_id ?? this.sessionManager.getCurrentSession()?.session_id;
2346
2343
  return this.recordingManager.isRecording() && this.recordingManager.forceStop(), this.recordingManager.reset(), this.sessionManager.clearCurrentSession(), this.callbackRegistry.dispatch("onSessionEvent", {
2347
2344
  type: p.DISCARDED,
2348
2345
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2349
2346
  data: {
2350
- sessionId: t ?? null,
2347
+ sessionId: n ?? null,
2351
2348
  reason: h.CANCELLED
2352
2349
  }
2353
2350
  }), this.updateSession({
2354
2351
  user_status: "cancelled",
2355
2352
  processing_status: "cancelled"
2356
- }, t);
2353
+ }, n, t);
2357
2354
  }
2358
2355
  getDiscoveryConfig() {
2359
2356
  try {
@@ -2473,4 +2470,4 @@ async function Be(e) {
2473
2470
  return URL.createObjectURL(i);
2474
2471
  }
2475
2472
  //#endregion
2476
- export { Le as AWS_STORAGE_PROVIDER, d as AudioEventType, x as AuthenticationError, V as AwsS3StorageProvider, X as BACKEND_STORAGE_PROVIDER, H as BackendStorageProvider, O as CallbackRegistry, c as CommunicationProtocol, h as DiscardReason, b as DiscoveryError, I as DiscoveryManager, g as ErrorCode, m as ErrorEventType, S as ForbiddenError, _ as HttpStatus, N as HttpTransport, P as IpcTransport, w as RateLimitError, Y as RecordingManager, u as RecordingState, Re as ScribeClient, v as ScribeError, p as SessionEventType, te as SessionExpiredError, L 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, Be as createWorkerBlobUrl, G as getStorageProvider, ze as getWorkerUrl, Z as hasUploadPayload, Fe as isStorageProviderSupported, Q as resolveStorageProvider };
2473
+ export { Le as AWS_STORAGE_PROVIDER, d as AudioEventType, x as AuthenticationError, V as AwsS3StorageProvider, Y as BACKEND_STORAGE_PROVIDER, H as BackendStorageProvider, O as CallbackRegistry, c as CommunicationProtocol, h as DiscardReason, b as DiscoveryError, F 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, Re as ScribeClient, v as ScribeError, p as SessionEventType, te as SessionExpiredError, I 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, Be as createWorkerBlobUrl, G as getStorageProvider, ze as getWorkerUrl, X as hasUploadPayload, Fe as isStorageProviderSupported, Z as resolveStorageProvider };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "med-scribe-alliance-ts-sdk",
3
- "version": "2.0.53",
3
+ "version": "2.0.55",
4
4
  "description": "TypeScript SDK for the MedScribe Alliance Protocol",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",