@absolutejs/voice 0.0.10 → 0.0.11

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.js CHANGED
@@ -675,12 +675,20 @@ var createSocketAdapter = (ws) => ({
675
675
  ws.send(data);
676
676
  }
677
677
  });
678
+ var normalizeOnTurn = (handler) => {
679
+ if (handler.length > 1) {
680
+ const directHandler = handler;
681
+ return async ({ context, session, turn, api }) => directHandler(session, turn, api, context);
682
+ }
683
+ return handler;
684
+ };
678
685
  var voice = (config) => {
679
686
  const runtime = {
680
687
  activeSessions: new Map,
681
688
  logger: resolveLogger(config.logger),
682
689
  socketSessions: new WeakMap
683
690
  };
691
+ const onTurn = normalizeOnTurn(config.onTurn);
684
692
  const htmxOptions = config.htmx && typeof config.htmx === "object" ? config.htmx : undefined;
685
693
  const htmxRoute = htmxOptions?.route ?? `${config.path}/htmx/session`;
686
694
  const htmxRenderers = resolveVoiceHTMXRenderers(config.htmx && config.htmx !== true ? config.htmx : undefined);
@@ -762,7 +770,7 @@ var voice = (config) => {
762
770
  onComplete: config.onComplete,
763
771
  onError: config.onError,
764
772
  onSession: config.onSession,
765
- onTurn: config.onTurn
773
+ onTurn
766
774
  },
767
775
  socket: createSocketAdapter(ws),
768
776
  store: config.session,
@@ -797,7 +805,7 @@ var voice = (config) => {
797
805
  onComplete: config.onComplete,
798
806
  onError: config.onError,
799
807
  onSession: config.onSession,
800
- onTurn: config.onTurn
808
+ onTurn
801
809
  },
802
810
  socket: createSocketAdapter(ws),
803
811
  store: config.session,
package/dist/types.d.ts CHANGED
@@ -173,18 +173,20 @@ export type VoiceRouteResult<TResult = unknown> = {
173
173
  result?: TResult;
174
174
  assistantText?: string;
175
175
  };
176
+ export type VoiceOnTurnObjectHandler<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = (input: {
177
+ context: TContext;
178
+ session: TSession;
179
+ turn: VoiceTurnRecord;
180
+ api: VoiceSessionHandle<TContext, TSession, TResult>;
181
+ }) => Promise<VoiceRouteResult<TResult> | void> | VoiceRouteResult<TResult> | void;
182
+ export type VoiceOnTurnHandler<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = VoiceOnTurnObjectHandler<TContext, TSession, TResult> | ((session: TSession, turn: VoiceTurnRecord, api: VoiceSessionHandle<TContext, TSession, TResult>, context: TContext) => Promise<VoiceRouteResult<TResult> | void> | VoiceRouteResult<TResult> | void);
176
183
  export type VoiceRouteConfig<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = {
177
184
  onSession?: (input: {
178
185
  context: TContext;
179
186
  session: TSession;
180
187
  api: VoiceSessionHandle<TContext, TSession, TResult>;
181
188
  }) => Promise<void> | void;
182
- onTurn: (input: {
183
- context: TContext;
184
- session: TSession;
185
- turn: VoiceTurnRecord;
186
- api: VoiceSessionHandle<TContext, TSession, TResult>;
187
- }) => Promise<VoiceRouteResult<TResult> | void> | VoiceRouteResult<TResult> | void;
189
+ onTurn: VoiceOnTurnHandler<TContext, TSession, TResult>;
188
190
  onComplete: (input: {
189
191
  context: TContext;
190
192
  session: TSession;
@@ -198,6 +200,9 @@ export type VoiceRouteConfig<TContext = unknown, TSession extends VoiceSessionRe
198
200
  api?: VoiceSessionHandle<TContext, TSession, TResult>;
199
201
  }) => Promise<void> | void;
200
202
  };
203
+ export type VoiceNormalizedRouteConfig<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = Omit<VoiceRouteConfig<TContext, TSession, TResult>, 'onTurn'> & {
204
+ onTurn: VoiceOnTurnObjectHandler<TContext, TSession, TResult>;
205
+ };
201
206
  export type VoicePluginConfig<TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = {
202
207
  path: string;
203
208
  stt: STTAdapter;
@@ -220,7 +225,7 @@ export type CreateVoiceSessionOptions<TContext = unknown, TSession extends Voice
220
225
  turnDetection: {
221
226
  silenceMs: number;
222
227
  };
223
- route: VoiceRouteConfig<TContext, TSession, TResult>;
228
+ route: VoiceNormalizedRouteConfig<TContext, TSession, TResult>;
224
229
  logger?: VoiceLogger;
225
230
  };
226
231
  export type CreateVoiceSession = <TContext = unknown, TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown>(options: CreateVoiceSessionOptions<TContext, TSession, TResult>) => VoiceSessionHandle<TContext, TSession, TResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",