@absolutejs/voice 0.0.8 → 0.0.9

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/htmx.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { VoiceHTMXRenderConfig, VoiceHTMXRenderInput, VoiceHTMXTargets, VoiceSessionRecord } from './types';
1
+ import type { VoiceHTMXConfig, VoiceHTMXRenderConfig, VoiceHTMXRenderInput, VoiceHTMXTargets, VoiceSessionRecord } from './types';
2
2
  type ResolvedVoiceHTMXRenderConfig<TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = Required<VoiceHTMXRenderConfig<TSession, TResult>>;
3
3
  export declare const resolveVoiceHTMXTargets: (custom?: Partial<VoiceHTMXTargets>) => VoiceHTMXTargets;
4
- export declare const resolveVoiceHTMXRenderers: <TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown>(custom?: VoiceHTMXRenderConfig<TSession, TResult>) => ResolvedVoiceHTMXRenderConfig<TSession, TResult>;
4
+ export declare const resolveVoiceHTMXRenderers: <TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown>(custom?: VoiceHTMXConfig<TSession, TResult>) => ResolvedVoiceHTMXRenderConfig<TSession, TResult>;
5
5
  export declare const buildVoiceHTMXResponse: <TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown>(input: VoiceHTMXRenderInput<TResult, TSession>, renderers: ResolvedVoiceHTMXRenderConfig<TSession, TResult>, targets: VoiceHTMXTargets) => string;
6
6
  export {};
package/dist/index.js CHANGED
@@ -173,14 +173,17 @@ var resolveVoiceHTMXTargets = (custom) => ({
173
173
  ...DEFAULT_HTMX_TARGETS,
174
174
  ...custom
175
175
  });
176
- var resolveVoiceHTMXRenderers = (custom) => ({
177
- assistant: custom?.assistant ?? defaultAssistant,
178
- emptyState: custom?.emptyState ?? defaultEmptyState,
179
- metrics: custom?.metrics ?? defaultMetrics,
180
- result: custom?.result ?? defaultResult,
181
- status: custom?.status ?? defaultStatus,
182
- turns: custom?.turns ?? defaultTurns
183
- });
176
+ var resolveVoiceHTMXRenderers = (custom) => {
177
+ const renderConfig = typeof custom === "function" ? { result: custom } : custom;
178
+ return {
179
+ assistant: renderConfig?.assistant ?? defaultAssistant,
180
+ emptyState: renderConfig?.emptyState ?? defaultEmptyState,
181
+ metrics: renderConfig?.metrics ?? defaultMetrics,
182
+ result: renderConfig?.result ?? defaultResult,
183
+ status: renderConfig?.status ?? defaultStatus,
184
+ turns: renderConfig?.turns ?? defaultTurns
185
+ };
186
+ };
184
187
  var renderOob = (id, html) => `<div id="${escapeHtml(id)}" hx-swap-oob="innerHTML">${html}</div>`;
185
188
  var buildVoiceHTMXResponse = (input, renderers, targets) => [
186
189
  renderOob(targets.metrics, renderers.metrics(input)),
@@ -678,10 +681,10 @@ var voice = (config) => {
678
681
  logger: resolveLogger(config.logger),
679
682
  socketSessions: new WeakMap
680
683
  };
681
- const htmxConfig = typeof config.htmx === "object" ? config.htmx : undefined;
682
- const htmxRoute = htmxConfig?.route ?? `${config.path}/htmx/session`;
683
- const htmxRenderers = resolveVoiceHTMXRenderers(htmxConfig);
684
- const htmxTargets = resolveVoiceHTMXTargets(htmxConfig?.targets);
684
+ const htmxOptions = config.htmx && typeof config.htmx === "object" ? config.htmx : undefined;
685
+ const htmxRoute = htmxOptions?.route ?? `${config.path}/htmx/session`;
686
+ const htmxRenderers = resolveVoiceHTMXRenderers(config.htmx && config.htmx !== true ? config.htmx : undefined);
687
+ const htmxTargets = resolveVoiceHTMXTargets(htmxOptions?.targets);
685
688
  const htmxRoutes = () => {
686
689
  if (!config.htmx) {
687
690
  return new Elysia;
package/dist/types.d.ts CHANGED
@@ -299,6 +299,7 @@ export type VoiceHTMXRenderConfig<TSession extends VoiceSessionRecord = VoiceSes
299
299
  result?: (input: VoiceHTMXRenderInput<TResult, TSession>) => string;
300
300
  emptyState?: (kind: keyof VoiceHTMXTargets, input: VoiceHTMXRenderInput<TResult, TSession>) => string;
301
301
  };
302
+ export type VoiceHTMXRenderer<TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = (input: VoiceHTMXRenderInput<TResult, TSession>) => string;
302
303
  export type VoiceHTMXTargets = {
303
304
  assistant: string;
304
305
  metrics: string;
@@ -306,10 +307,11 @@ export type VoiceHTMXTargets = {
306
307
  status: string;
307
308
  turns: string;
308
309
  };
309
- export type VoiceHTMXConfig<TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = VoiceHTMXRenderConfig<TSession, TResult> & {
310
+ export type VoiceHTMXOptions<TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = VoiceHTMXRenderConfig<TSession, TResult> & {
310
311
  route?: string;
311
312
  targets?: Partial<VoiceHTMXTargets>;
312
313
  };
314
+ export type VoiceHTMXConfig<TSession extends VoiceSessionRecord = VoiceSessionRecord, TResult = unknown> = VoiceHTMXRenderer<TSession, TResult> | VoiceHTMXOptions<TSession, TResult>;
313
315
  export type VoiceStreamState<TResult = unknown> = {
314
316
  sessionId: string | null;
315
317
  status: VoiceSessionStatus | 'idle';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",