@absolutejs/voice 0.0.22-beta.617 → 0.0.22-beta.618

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +28 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39579,6 +39579,7 @@ var voice = (config) => {
39579
39579
  const monitorBindings = new Map;
39580
39580
  const runtime = {
39581
39581
  activeSessions: new Map,
39582
+ pendingSessions: new Map,
39582
39583
  logger: resolveLogger(config.logger),
39583
39584
  profileSwitchGuardAutoSwitchCounts: new Map,
39584
39585
  profileSwitchGuardedSessions: new Set,
@@ -39738,6 +39739,31 @@ var voice = (config) => {
39738
39739
  turnDetection: sessionOptions.turnDetection
39739
39740
  });
39740
39741
  };
39742
+ const createAndConnectSession = async (ws, sessionId, scenarioId) => {
39743
+ const session = await createManagedSession(ws, sessionId, scenarioId);
39744
+ const typedSession = session;
39745
+ runtime.activeSessions.set(sessionId, typedSession);
39746
+ registerMonitorSession(sessionId, typedSession);
39747
+ await session.connect(buildSocketAdapter(ws, sessionId));
39748
+ return typedSession;
39749
+ };
39750
+ const ensureManagedSession = async (ws, sessionId, scenarioId) => {
39751
+ const active = runtime.activeSessions.get(sessionId);
39752
+ if (active) {
39753
+ return active;
39754
+ }
39755
+ const inFlight = runtime.pendingSessions.get(sessionId);
39756
+ if (inFlight) {
39757
+ return inFlight;
39758
+ }
39759
+ const creation = createAndConnectSession(ws, sessionId, scenarioId);
39760
+ runtime.pendingSessions.set(sessionId, creation);
39761
+ try {
39762
+ return await creation;
39763
+ } finally {
39764
+ runtime.pendingSessions.delete(sessionId);
39765
+ }
39766
+ };
39741
39767
  const mountSurface = (app, value, factory) => {
39742
39768
  if (value === undefined || value === false) {
39743
39769
  return app;
@@ -39950,13 +39976,7 @@ var voice = (config) => {
39950
39976
  if (!audio) {
39951
39977
  return;
39952
39978
  }
39953
- const session = current ?? await createManagedSession(ws, sessionState.sessionId, sessionState.scenarioId ?? undefined);
39954
- if (!current) {
39955
- const typedSession = session;
39956
- runtime.activeSessions.set(sessionState.sessionId, typedSession);
39957
- registerMonitorSession(sessionState.sessionId, typedSession);
39958
- await session.connect(buildSocketAdapter(ws, sessionState.sessionId));
39959
- }
39979
+ const session = current ?? await ensureManagedSession(ws, sessionState.sessionId, sessionState.scenarioId ?? undefined);
39960
39980
  await session.receiveAudio(audio);
39961
39981
  },
39962
39982
  open: async (ws) => {
@@ -39967,11 +39987,7 @@ var voice = (config) => {
39967
39987
  runtime.activeSessions.delete(sessionState.sessionId);
39968
39988
  deregisterMonitorSession(sessionState.sessionId, "superseded");
39969
39989
  }
39970
- const session = await createManagedSession(ws, sessionState.sessionId, sessionState.scenarioId ?? undefined);
39971
- const typedSession = session;
39972
- runtime.activeSessions.set(sessionState.sessionId, typedSession);
39973
- registerMonitorSession(sessionState.sessionId, typedSession);
39974
- await session.connect(buildSocketAdapter(ws, sessionState.sessionId));
39990
+ await ensureManagedSession(ws, sessionState.sessionId, sessionState.scenarioId ?? undefined);
39975
39991
  }
39976
39992
  }).use(htmxRoutes()).use(surfaceRoutes());
39977
39993
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.617",
3
+ "version": "0.0.22-beta.618",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",