med-scribe-alliance-ts-sdk 2.0.41 → 2.0.43

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/dist/index.d.ts CHANGED
@@ -1193,9 +1193,9 @@ export declare class RecordingManager {
1193
1193
  stop(): Promise<ApiCallResult<EndRecordingResult>>;
1194
1194
  /**
1195
1195
  * End the session, dispatch onSessionEvent, and return the response.
1196
- * Called from stop() (auto-finalize) and finalizeAfterExternalEndSession()
1197
- * (consumer-driven). Returns undefined and dispatches onError on failure.
1198
- * Caller is responsible for cleanup.
1196
+ * Called from stop() after all uploads succeed.
1197
+ * Throws on failure (after dispatching onError) — caller is responsible
1198
+ * for cleanup.
1199
1199
  */
1200
1200
  private finalizeSession;
1201
1201
  /**
package/dist/index.mjs CHANGED
@@ -1535,17 +1535,26 @@ var Se = class {
1535
1535
  return this._isPaused;
1536
1536
  }
1537
1537
  async stop() {
1538
+ this._isPaused = !1;
1538
1539
  try {
1539
- return this._isPaused = !1, this.vadClient.destroy(), this.flushRemainingAudio(), await this.workerManager.waitForAllUploads(), this.fileManager.markPendingAsFailed(), {
1540
- failedUploads: this.fileManager.getFailedUploads(),
1541
- totalFiles: this.fileManager.getChunkCount()
1542
- };
1540
+ this.vadClient.destroy();
1543
1541
  } catch (e) {
1544
- return console.error("[ScribeSDK] Error stopping chunked recorder:", e), this.fileManager.markPendingAsFailed(), {
1545
- failedUploads: this.fileManager.getFailedUploads(),
1546
- totalFiles: this.fileManager.getChunkCount()
1547
- };
1542
+ console.error("[ScribeSDK] Error destroying VAD during stop:", e);
1543
+ }
1544
+ try {
1545
+ this.flushRemainingAudio();
1546
+ } catch (e) {
1547
+ console.error("[ScribeSDK] Error flushing remaining audio:", e);
1548
1548
  }
1549
+ try {
1550
+ await this.workerManager.waitForAllUploads();
1551
+ } catch (e) {
1552
+ console.error("[ScribeSDK] Error waiting for uploads:", e);
1553
+ }
1554
+ return this.fileManager.markPendingAsFailed(), {
1555
+ failedUploads: this.fileManager.getFailedUploads(),
1556
+ totalFiles: this.fileManager.getChunkCount()
1557
+ };
1549
1558
  }
1550
1559
  reset() {
1551
1560
  this._isPaused = !1, this.chunkLimitReached = !1, this.chunkLimitOverridden = !1, this.vadClient.reset(), this.fileManager.resetInstance(), this.bufferManager.resetInstance(), this.workerManager.destroy(), this.initialized = !1;
@@ -1650,7 +1659,16 @@ var Se = class {
1650
1659
  totalFiles: 0
1651
1660
  };
1652
1661
  try {
1653
- let e = await this.stopMediaRecorder(), t = `1.${this.getFileExtension()}`;
1662
+ let e;
1663
+ try {
1664
+ e = await this.stopMediaRecorder();
1665
+ } catch (t) {
1666
+ if (this.audioChunks.length > 0) {
1667
+ let t = this.mediaRecorder?.mimeType || "audio/webm";
1668
+ e = new Blob(this.audioChunks, { type: t });
1669
+ } else throw t;
1670
+ }
1671
+ let t = `1.${this.getFileExtension()}`;
1654
1672
  try {
1655
1673
  return await Y(this.transport, {
1656
1674
  fileName: t,
@@ -1684,11 +1702,6 @@ var Se = class {
1684
1702
  totalFiles: 1
1685
1703
  };
1686
1704
  }
1687
- } catch (e) {
1688
- return console.error("[ScribeSDK] Error stopping single recorder:", e), {
1689
- failedUploads: [],
1690
- totalFiles: 0
1691
- };
1692
1705
  } finally {
1693
1706
  this.releaseMicStream();
1694
1707
  }
@@ -1904,13 +1917,17 @@ var Se = class {
1904
1917
  },
1905
1918
  httpStatus: void 0
1906
1919
  };
1907
- let e = !1, t;
1920
+ let e = !1, t, n = {
1921
+ failedUploads: [],
1922
+ totalFiles: 0,
1923
+ sessionEnded: !1
1924
+ };
1908
1925
  try {
1909
- let n = await this.recorder.stop();
1926
+ let r = await this.recorder.stop();
1910
1927
  this.preserveRetryContext(), this._isRecording = !1;
1911
- let r = n.failedUploads;
1912
- if (r.length > 0) try {
1913
- r = (await this.retryFailedUploads()).data.stillFailed;
1928
+ let i = r.failedUploads;
1929
+ if (i.length > 0) try {
1930
+ i = (await this.retryFailedUploads()).data.stillFailed;
1914
1931
  } catch (e) {
1915
1932
  console.error("[ScribeSDK] Internal retry pass failed:", e), this.callbackRegistry.dispatch("onError", {
1916
1933
  type: m.TRANSPORT_ERROR,
@@ -1921,49 +1938,29 @@ var Se = class {
1921
1938
  }
1922
1939
  });
1923
1940
  }
1924
- let i = {
1925
- failedUploads: r,
1926
- totalFiles: n.totalFiles,
1927
- sessionEnded: !1
1928
- };
1929
- if (r.length === 0 && this.activeSession) {
1930
- let r = await this.finalizeSession(n.totalFiles, n.totalFiles);
1931
- r && (i.sessionEnded = !0, i.endSessionResponse = r.data, t = r.httpStatus, e = !0);
1941
+ if (n.failedUploads = i, n.totalFiles = r.totalFiles, i.length === 0 && this.activeSession) {
1942
+ let i = await this.finalizeSession(r.totalFiles, r.totalFiles);
1943
+ n.sessionEnded = !0, n.endSessionResponse = i.data, t = i.httpStatus, e = !0;
1932
1944
  }
1933
- return this.callbackRegistry.dispatch("onRecordingStateChange", {
1934
- type: u.ENDED,
1935
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1936
- data: i
1937
- }), this.config.debug && console.log("[ScribeSDK] Recording stopped:", {
1938
- totalFiles: i.totalFiles,
1939
- failedUploads: i.failedUploads.length,
1940
- sessionEnded: i.sessionEnded
1945
+ return this.config.debug && console.log("[ScribeSDK] Recording stopped:", {
1946
+ totalFiles: n.totalFiles,
1947
+ failedUploads: n.failedUploads.length,
1948
+ sessionEnded: n.sessionEnded
1941
1949
  }), {
1942
- data: i,
1950
+ data: n,
1943
1951
  httpStatus: t
1944
1952
  };
1945
- } catch (e) {
1946
- return console.error("[ScribeSDK] Error stopping recording:", e), this.callbackRegistry.dispatch("onError", {
1947
- type: m.TRANSPORT_ERROR,
1948
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1949
- error: {
1950
- code: g.STOP_FAILED,
1951
- message: e instanceof Error ? e.message : "Failed to stop recording"
1952
- }
1953
- }), {
1954
- data: {
1955
- failedUploads: [],
1956
- totalFiles: 0,
1957
- sessionEnded: !1
1958
- },
1959
- httpStatus: void 0
1960
- };
1961
1953
  } finally {
1962
- e ? this.cleanupRecordingState() : this.partialCleanupAfterFailedFinalize();
1954
+ this.callbackRegistry.dispatch("onRecordingStateChange", {
1955
+ type: u.ENDED,
1956
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1957
+ data: n
1958
+ }), e ? this.cleanupRecordingState() : this.partialCleanupAfterFailedFinalize();
1963
1959
  }
1964
1960
  }
1965
1961
  async finalizeSession(e, t) {
1966
- if (this.activeSession) try {
1962
+ if (!this.activeSession) throw new v("No active session to finalize", g.SESSION_END_FAILED);
1963
+ try {
1967
1964
  let n = await this.sessionManager.endSession(this.activeBaseUrl, {
1968
1965
  audio_files_sent: e,
1969
1966
  audio_files_uploaded: t
@@ -1974,15 +1971,14 @@ var Se = class {
1974
1971
  data: n.data
1975
1972
  }), n;
1976
1973
  } catch (e) {
1977
- console.error("[ScribeSDK] Failed to end session:", e), this.callbackRegistry.dispatch("onError", {
1974
+ throw console.error("[ScribeSDK] Failed to end session:", e), this.callbackRegistry.dispatch("onError", {
1978
1975
  type: m.TRANSPORT_ERROR,
1979
1976
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1980
1977
  error: {
1981
1978
  code: g.SESSION_END_FAILED,
1982
1979
  message: e instanceof Error ? e.message : "Failed to end session"
1983
1980
  }
1984
- });
1985
- return;
1981
+ }), e;
1986
1982
  }
1987
1983
  }
1988
1984
  forceStop() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "med-scribe-alliance-ts-sdk",
3
- "version": "2.0.41",
3
+ "version": "2.0.43",
4
4
  "description": "TypeScript SDK for the MedScribe Alliance Protocol",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",