@utilia-os/sdk-js 1.0.0 → 1.2.0

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.mts CHANGED
@@ -43,10 +43,22 @@ declare class UtiliaClient {
43
43
  * Ejecuta una funcion con reintentos y backoff exponencial
44
44
  */
45
45
  private executeWithRetry;
46
+ /**
47
+ * Genera un ID simple como fallback cuando crypto.randomUUID no esta disponible
48
+ */
49
+ private generateSimpleId;
46
50
  /**
47
51
  * Helper para esperar un tiempo
48
52
  */
49
53
  private sleep;
54
+ /**
55
+ * Construye una URL completa para conexiones SSE con la API key como query param.
56
+ * Util para EventSource que no soporta headers personalizados.
57
+ *
58
+ * @param path - Ruta relativa de la API (ej: /external/v1/tickets/ai-suggest/123/stream)
59
+ * @returns URL completa con apiKey como parametro de consulta
60
+ */
61
+ buildSseUrl(path: string): string;
50
62
  /**
51
63
  * Realiza una peticion GET
52
64
  */
@@ -310,6 +322,13 @@ interface TicketMessage {
310
322
  attachments: TicketAttachment[];
311
323
  createdAt: string;
312
324
  }
325
+ /**
326
+ * Datos del usuario que reporto el ticket
327
+ */
328
+ interface TicketReporter {
329
+ name: string;
330
+ email?: string;
331
+ }
313
332
  /**
314
333
  * Detalle completo de un ticket
315
334
  */
@@ -327,6 +346,10 @@ interface TicketDetail {
327
346
  messages: TicketMessage[];
328
347
  /** Archivos adjuntos del ticket original */
329
348
  attachments: TicketAttachment[];
349
+ /** Contexto capturado al crear el ticket */
350
+ context?: TicketContext | null;
351
+ /** Datos del usuario que reporto el ticket */
352
+ reporter?: TicketReporter | null;
330
353
  }
331
354
  /**
332
355
  * Respuesta al crear un mensaje
@@ -580,7 +603,19 @@ interface AiSuggestInput {
580
603
  description?: string;
581
604
  category?: string;
582
605
  priority?: string;
606
+ /** URL actual donde se reporta el problema */
607
+ currentUrl?: string;
608
+ /** User agent del navegador */
609
+ userAgent?: string;
610
+ /** Version de la aplicacion */
611
+ appVersion?: string;
583
612
  };
613
+ /** Imagenes adjuntas para analisis con vision (base64, max 5) */
614
+ images?: Array<{
615
+ base64: string;
616
+ filename: string;
617
+ mimeType: string;
618
+ }>;
584
619
  }
585
620
  /**
586
621
  * Sugerencias generadas por IA
@@ -609,6 +644,8 @@ interface AiJobStatus {
609
644
  transcription?: string;
610
645
  /** Sugerencias generadas */
611
646
  suggestions?: AiSuggestions;
647
+ /** ID del evento de analytics para tracking de aceptacion/rechazo */
648
+ analyticsEventId?: string;
612
649
  };
613
650
  /** Mensaje de error (si status es 'failed') */
614
651
  error?: string;
@@ -616,6 +653,29 @@ interface AiJobStatus {
616
653
  /**
617
654
  * Opciones para el metodo getSuggestions con polling
618
655
  */
656
+ /**
657
+ * Acciones del usuario sobre sugerencias de IA
658
+ */
659
+ type AiUserAction = 'ACCEPTED_ALL' | 'ACCEPTED_PARTIAL' | 'REJECTED' | 'MODIFIED' | 'IGNORED';
660
+ /**
661
+ * Entrada para reportar la accion del usuario sobre sugerencias de IA
662
+ */
663
+ interface TrackAiActionInput {
664
+ /** ID del evento de analytics retornado en el resultado de sugerencias */
665
+ eventId: string;
666
+ /** Accion tomada por el usuario */
667
+ userAction: AiUserAction;
668
+ /** Campos que el usuario acepto */
669
+ fieldsAccepted?: string[];
670
+ /** Campos que el usuario modifico */
671
+ fieldsModified?: string[];
672
+ /** Campos que el usuario rechazo */
673
+ fieldsRejected?: string[];
674
+ /** Tiempo en milisegundos desde que se mostraron las sugerencias hasta la decision */
675
+ timeToDecisionMs?: number;
676
+ /** Origen de la accion */
677
+ source?: 'SDK_EXTERNAL' | 'WIDGET';
678
+ }
619
679
  interface GetSuggestionsOptions {
620
680
  /** Intervalo de polling en ms (default: 1000) */
621
681
  pollInterval?: number;
@@ -624,6 +684,65 @@ interface GetSuggestionsOptions {
624
684
  /** Callback para reportar progreso */
625
685
  onProgress?: (progress: number) => void;
626
686
  }
687
+ /**
688
+ * Evento SSE recibido durante el streaming de un job
689
+ */
690
+ interface SseEvent {
691
+ /** Tipo de evento */
692
+ event: 'progress' | 'completed' | 'failed' | 'heartbeat';
693
+ /** Progreso actual (0-100) */
694
+ progress?: number;
695
+ /** Estado descriptivo */
696
+ status?: string;
697
+ /** Resultado del job (disponible en evento 'completed') */
698
+ result?: AiJobStatus['result'];
699
+ /** Mensaje de error (disponible en evento 'failed') */
700
+ error?: string;
701
+ }
702
+ /**
703
+ * Opciones para el metodo streamSuggestions
704
+ */
705
+ interface StreamSuggestionsOptions {
706
+ /** Callback para reportar progreso (0-100) */
707
+ onProgress?: (progress: number) => void;
708
+ /** Callback para errores no fatales */
709
+ onError?: (error: Error) => void;
710
+ /** Timeout en ms (default: 120000) */
711
+ timeout?: number;
712
+ }
713
+ /**
714
+ * Handle retornado por streamSuggestions para controlar la conexion SSE
715
+ */
716
+ interface StreamSuggestionsHandle {
717
+ /** Promesa que resuelve con el resultado cuando el job completa */
718
+ result: Promise<AiJobStatus['result']>;
719
+ /** Funcion para abortar la conexion SSE */
720
+ abort: () => void;
721
+ }
722
+ /**
723
+ * Estado del job de transcripcion asincrona
724
+ */
725
+ interface TranscriptionJobStatus {
726
+ /** Estado actual del job */
727
+ status: 'pending' | 'processing' | 'completed' | 'failed';
728
+ /** Progreso del job (0-100) */
729
+ progress?: number;
730
+ /** Texto transcrito (disponible cuando status es 'completed') */
731
+ transcription?: string;
732
+ /** Mensaje de error (si status es 'failed') */
733
+ error?: string;
734
+ }
735
+ /**
736
+ * Opciones para el metodo streamTranscription
737
+ */
738
+ interface StreamTranscriptionOptions {
739
+ /** Callback para reportar progreso (0-100) */
740
+ onProgress?: (progress: number) => void;
741
+ /** Callback para errores no fatales */
742
+ onError?: (error: Error) => void;
743
+ /** Timeout en ms (default: 120000) */
744
+ timeout?: number;
745
+ }
627
746
  declare class AiService {
628
747
  private readonly client;
629
748
  private readonly basePath;
@@ -720,6 +839,148 @@ declare class AiService {
720
839
  * ```
721
840
  */
722
841
  getSuggestions(data: AiSuggestInput, options?: GetSuggestionsOptions): Promise<AiJobStatus['result']>;
842
+ /**
843
+ * Reporta la accion del usuario sobre sugerencias de IA.
844
+ * Permite trackear si el usuario acepto, rechazo o modifico las sugerencias.
845
+ *
846
+ * @param data - Datos de la accion del usuario
847
+ * @returns Confirmacion de que la accion fue registrada
848
+ *
849
+ * @example
850
+ * ```typescript
851
+ * const result = await sdk.ai.getSuggestions({
852
+ * userId: 'user-123',
853
+ * text: 'No puedo iniciar sesion',
854
+ * });
855
+ *
856
+ * // El usuario revisa las sugerencias y acepta todas
857
+ * await sdk.ai.trackAiAction({
858
+ * eventId: result?.analyticsEventId!,
859
+ * userAction: 'ACCEPTED_ALL',
860
+ * fieldsAccepted: ['title', 'description', 'category', 'priority'],
861
+ * timeToDecisionMs: 3500,
862
+ * });
863
+ * ```
864
+ */
865
+ trackAiAction(data: TrackAiActionInput): Promise<{
866
+ success: boolean;
867
+ }>;
868
+ /**
869
+ * Solicita sugerencias de IA y recibe el resultado via SSE (Server-Sent Events).
870
+ * Alternativa al polling que ofrece actualizaciones en tiempo real.
871
+ *
872
+ * Requiere un entorno con EventSource nativo (navegador).
873
+ * Para Node.js se necesita un polyfill como 'eventsource'.
874
+ *
875
+ * @param data - Datos para generar sugerencias
876
+ * @param options - Opciones de streaming
877
+ * @returns Handle con promesa de resultado y funcion de aborto
878
+ *
879
+ * @example
880
+ * ```typescript
881
+ * const handle = await sdk.ai.streamSuggestions(
882
+ * { userId: 'user-123', text: 'No puedo iniciar sesion' },
883
+ * { onProgress: (p) => console.log(`Progreso: ${p}%`) },
884
+ * );
885
+ *
886
+ * // Esperar resultado
887
+ * const result = await handle.result;
888
+ * console.log(result?.suggestions);
889
+ *
890
+ * // O abortar si el usuario cancela
891
+ * handle.abort();
892
+ * ```
893
+ */
894
+ streamSuggestions(data: AiSuggestInput, options?: StreamSuggestionsOptions): Promise<StreamSuggestionsHandle>;
895
+ /**
896
+ * Solicita una transcripcion de audio de forma asincrona.
897
+ * Retorna un jobId para consultar el estado o usar con streamTranscription.
898
+ *
899
+ * @param audioBase64 - Audio codificado en base64
900
+ * @param audioFilename - Nombre del archivo con extension
901
+ * @returns ID del job para consultar estado
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * const { jobId } = await sdk.ai.requestTranscription(
906
+ * audioBase64,
907
+ * 'recording.webm',
908
+ * );
909
+ * ```
910
+ */
911
+ requestTranscription(audioBase64: string, audioFilename: string): Promise<{
912
+ jobId: string;
913
+ }>;
914
+ /**
915
+ * Obtiene el estado de un job de transcripcion asincrona.
916
+ *
917
+ * @param jobId - ID del job obtenido de requestTranscription
918
+ * @returns Estado actual del job de transcripcion
919
+ *
920
+ * @example
921
+ * ```typescript
922
+ * const status = await sdk.ai.getTranscriptionStatus(jobId);
923
+ *
924
+ * if (status.status === 'completed') {
925
+ * console.log(status.transcription);
926
+ * }
927
+ * ```
928
+ */
929
+ getTranscriptionStatus(jobId: string): Promise<TranscriptionJobStatus>;
930
+ /**
931
+ * Solicita una transcripcion de audio y recibe el resultado via SSE.
932
+ * Alternativa al polling para transcripciones asincronas.
933
+ *
934
+ * Requiere un entorno con EventSource nativo (navegador).
935
+ * Para Node.js se necesita un polyfill como 'eventsource'.
936
+ *
937
+ * @param audioBase64 - Audio codificado en base64
938
+ * @param audioFilename - Nombre del archivo con extension
939
+ * @param options - Opciones de streaming
940
+ * @returns Promesa que resuelve con el texto transcrito
941
+ *
942
+ * @example
943
+ * ```typescript
944
+ * const { transcription } = await sdk.ai.streamTranscription(
945
+ * audioBase64,
946
+ * 'recording.webm',
947
+ * { onProgress: (p) => console.log(`Progreso: ${p}%`) },
948
+ * );
949
+ * console.log(transcription);
950
+ * ```
951
+ */
952
+ streamTranscription(audioBase64: string, audioFilename: string, options?: StreamTranscriptionOptions): Promise<{
953
+ transcription: string;
954
+ }>;
955
+ /**
956
+ * Reporta un error del cliente al servidor para monitoreo.
957
+ * Este metodo nunca lanza excepciones; los errores de reporte se ignoran silenciosamente.
958
+ *
959
+ * @param params - Datos del error a reportar
960
+ *
961
+ * @example
962
+ * ```typescript
963
+ * await sdk.ai.reportError({
964
+ * message: 'No se pudo cargar el widget',
965
+ * code: 'WIDGET_LOAD_ERROR',
966
+ * component: 'widget',
967
+ * url: window.location.href,
968
+ * userAgent: navigator.userAgent,
969
+ * });
970
+ * ```
971
+ */
972
+ reportError(params: {
973
+ message: string;
974
+ stack?: string;
975
+ code?: string;
976
+ component?: string;
977
+ context?: string;
978
+ endpoint?: string;
979
+ method?: string;
980
+ requestId?: string;
981
+ url?: string;
982
+ userAgent?: string;
983
+ }): Promise<void>;
723
984
  /**
724
985
  * Helper para esperar un tiempo
725
986
  */
@@ -754,7 +1015,14 @@ declare class UtiliaSDKError extends Error {
754
1015
  readonly code: ErrorCode;
755
1016
  /** Timestamp de cuando ocurrio el error */
756
1017
  readonly timestamp: Date;
757
- constructor(code: ErrorCode, message: string);
1018
+ /** ID de la peticion que genero el error */
1019
+ readonly requestId?: string;
1020
+ /** Codigo de estado HTTP de la respuesta */
1021
+ readonly statusCode?: number;
1022
+ constructor(code: ErrorCode, message: string, options?: {
1023
+ requestId?: string;
1024
+ statusCode?: number;
1025
+ });
758
1026
  /**
759
1027
  * Serializa el error a un objeto JSON
760
1028
  */
@@ -763,6 +1031,8 @@ declare class UtiliaSDKError extends Error {
763
1031
  code: ErrorCode;
764
1032
  message: string;
765
1033
  timestamp: string;
1034
+ requestId: string | undefined;
1035
+ statusCode: number | undefined;
766
1036
  };
767
1037
  /**
768
1038
  * Verifica si el error es de tipo rate limit
@@ -869,4 +1139,4 @@ declare class UtiliaSDK {
869
1139
  constructor(config: UtiliaSDKConfig);
870
1140
  }
871
1141
 
872
- export { type AddMessageInput, type AiJobStatus, type AiSuggestInput, type AiSuggestions, type CreateTicketInput, type CreateTicketUser, type CreatedMessage, type CreatedTicket, ErrorCode, type ExternalUser, type FileQuota, type GetSuggestionsOptions, type IdentifyUserInput, type MessageAuthor, type PaginatedResponse, type PaginationMeta, type RequestConfig, SDK_LIMITS, type TicketAttachment, type TicketCategory, type TicketContext, type TicketDetail, type TicketFilters, type TicketListItem, type TicketMessage, type TicketPriority, type TicketStatus, type UnreadCount, type UploadFileOptions, type UploadedFile, UtiliaSDK, type UtiliaSDKConfig, UtiliaSDKError };
1142
+ export { type AddMessageInput, type AiJobStatus, type AiSuggestInput, type AiSuggestions, type AiUserAction, type CreateTicketInput, type CreateTicketUser, type CreatedMessage, type CreatedTicket, ErrorCode, type ExternalUser, type FileQuota, type GetSuggestionsOptions, type IdentifyUserInput, type MessageAuthor, type PaginatedResponse, type PaginationMeta, type RequestConfig, SDK_LIMITS, type SseEvent, type StreamSuggestionsHandle, type StreamSuggestionsOptions, type StreamTranscriptionOptions, type TicketAttachment, type TicketCategory, type TicketContext, type TicketDetail, type TicketFilters, type TicketListItem, type TicketMessage, type TicketPriority, type TicketReporter, type TicketStatus, type TrackAiActionInput, type TranscriptionJobStatus, type UnreadCount, type UploadFileOptions, type UploadedFile, UtiliaSDK, type UtiliaSDKConfig, UtiliaSDKError };
package/dist/index.d.ts CHANGED
@@ -43,10 +43,22 @@ declare class UtiliaClient {
43
43
  * Ejecuta una funcion con reintentos y backoff exponencial
44
44
  */
45
45
  private executeWithRetry;
46
+ /**
47
+ * Genera un ID simple como fallback cuando crypto.randomUUID no esta disponible
48
+ */
49
+ private generateSimpleId;
46
50
  /**
47
51
  * Helper para esperar un tiempo
48
52
  */
49
53
  private sleep;
54
+ /**
55
+ * Construye una URL completa para conexiones SSE con la API key como query param.
56
+ * Util para EventSource que no soporta headers personalizados.
57
+ *
58
+ * @param path - Ruta relativa de la API (ej: /external/v1/tickets/ai-suggest/123/stream)
59
+ * @returns URL completa con apiKey como parametro de consulta
60
+ */
61
+ buildSseUrl(path: string): string;
50
62
  /**
51
63
  * Realiza una peticion GET
52
64
  */
@@ -310,6 +322,13 @@ interface TicketMessage {
310
322
  attachments: TicketAttachment[];
311
323
  createdAt: string;
312
324
  }
325
+ /**
326
+ * Datos del usuario que reporto el ticket
327
+ */
328
+ interface TicketReporter {
329
+ name: string;
330
+ email?: string;
331
+ }
313
332
  /**
314
333
  * Detalle completo de un ticket
315
334
  */
@@ -327,6 +346,10 @@ interface TicketDetail {
327
346
  messages: TicketMessage[];
328
347
  /** Archivos adjuntos del ticket original */
329
348
  attachments: TicketAttachment[];
349
+ /** Contexto capturado al crear el ticket */
350
+ context?: TicketContext | null;
351
+ /** Datos del usuario que reporto el ticket */
352
+ reporter?: TicketReporter | null;
330
353
  }
331
354
  /**
332
355
  * Respuesta al crear un mensaje
@@ -580,7 +603,19 @@ interface AiSuggestInput {
580
603
  description?: string;
581
604
  category?: string;
582
605
  priority?: string;
606
+ /** URL actual donde se reporta el problema */
607
+ currentUrl?: string;
608
+ /** User agent del navegador */
609
+ userAgent?: string;
610
+ /** Version de la aplicacion */
611
+ appVersion?: string;
583
612
  };
613
+ /** Imagenes adjuntas para analisis con vision (base64, max 5) */
614
+ images?: Array<{
615
+ base64: string;
616
+ filename: string;
617
+ mimeType: string;
618
+ }>;
584
619
  }
585
620
  /**
586
621
  * Sugerencias generadas por IA
@@ -609,6 +644,8 @@ interface AiJobStatus {
609
644
  transcription?: string;
610
645
  /** Sugerencias generadas */
611
646
  suggestions?: AiSuggestions;
647
+ /** ID del evento de analytics para tracking de aceptacion/rechazo */
648
+ analyticsEventId?: string;
612
649
  };
613
650
  /** Mensaje de error (si status es 'failed') */
614
651
  error?: string;
@@ -616,6 +653,29 @@ interface AiJobStatus {
616
653
  /**
617
654
  * Opciones para el metodo getSuggestions con polling
618
655
  */
656
+ /**
657
+ * Acciones del usuario sobre sugerencias de IA
658
+ */
659
+ type AiUserAction = 'ACCEPTED_ALL' | 'ACCEPTED_PARTIAL' | 'REJECTED' | 'MODIFIED' | 'IGNORED';
660
+ /**
661
+ * Entrada para reportar la accion del usuario sobre sugerencias de IA
662
+ */
663
+ interface TrackAiActionInput {
664
+ /** ID del evento de analytics retornado en el resultado de sugerencias */
665
+ eventId: string;
666
+ /** Accion tomada por el usuario */
667
+ userAction: AiUserAction;
668
+ /** Campos que el usuario acepto */
669
+ fieldsAccepted?: string[];
670
+ /** Campos que el usuario modifico */
671
+ fieldsModified?: string[];
672
+ /** Campos que el usuario rechazo */
673
+ fieldsRejected?: string[];
674
+ /** Tiempo en milisegundos desde que se mostraron las sugerencias hasta la decision */
675
+ timeToDecisionMs?: number;
676
+ /** Origen de la accion */
677
+ source?: 'SDK_EXTERNAL' | 'WIDGET';
678
+ }
619
679
  interface GetSuggestionsOptions {
620
680
  /** Intervalo de polling en ms (default: 1000) */
621
681
  pollInterval?: number;
@@ -624,6 +684,65 @@ interface GetSuggestionsOptions {
624
684
  /** Callback para reportar progreso */
625
685
  onProgress?: (progress: number) => void;
626
686
  }
687
+ /**
688
+ * Evento SSE recibido durante el streaming de un job
689
+ */
690
+ interface SseEvent {
691
+ /** Tipo de evento */
692
+ event: 'progress' | 'completed' | 'failed' | 'heartbeat';
693
+ /** Progreso actual (0-100) */
694
+ progress?: number;
695
+ /** Estado descriptivo */
696
+ status?: string;
697
+ /** Resultado del job (disponible en evento 'completed') */
698
+ result?: AiJobStatus['result'];
699
+ /** Mensaje de error (disponible en evento 'failed') */
700
+ error?: string;
701
+ }
702
+ /**
703
+ * Opciones para el metodo streamSuggestions
704
+ */
705
+ interface StreamSuggestionsOptions {
706
+ /** Callback para reportar progreso (0-100) */
707
+ onProgress?: (progress: number) => void;
708
+ /** Callback para errores no fatales */
709
+ onError?: (error: Error) => void;
710
+ /** Timeout en ms (default: 120000) */
711
+ timeout?: number;
712
+ }
713
+ /**
714
+ * Handle retornado por streamSuggestions para controlar la conexion SSE
715
+ */
716
+ interface StreamSuggestionsHandle {
717
+ /** Promesa que resuelve con el resultado cuando el job completa */
718
+ result: Promise<AiJobStatus['result']>;
719
+ /** Funcion para abortar la conexion SSE */
720
+ abort: () => void;
721
+ }
722
+ /**
723
+ * Estado del job de transcripcion asincrona
724
+ */
725
+ interface TranscriptionJobStatus {
726
+ /** Estado actual del job */
727
+ status: 'pending' | 'processing' | 'completed' | 'failed';
728
+ /** Progreso del job (0-100) */
729
+ progress?: number;
730
+ /** Texto transcrito (disponible cuando status es 'completed') */
731
+ transcription?: string;
732
+ /** Mensaje de error (si status es 'failed') */
733
+ error?: string;
734
+ }
735
+ /**
736
+ * Opciones para el metodo streamTranscription
737
+ */
738
+ interface StreamTranscriptionOptions {
739
+ /** Callback para reportar progreso (0-100) */
740
+ onProgress?: (progress: number) => void;
741
+ /** Callback para errores no fatales */
742
+ onError?: (error: Error) => void;
743
+ /** Timeout en ms (default: 120000) */
744
+ timeout?: number;
745
+ }
627
746
  declare class AiService {
628
747
  private readonly client;
629
748
  private readonly basePath;
@@ -720,6 +839,148 @@ declare class AiService {
720
839
  * ```
721
840
  */
722
841
  getSuggestions(data: AiSuggestInput, options?: GetSuggestionsOptions): Promise<AiJobStatus['result']>;
842
+ /**
843
+ * Reporta la accion del usuario sobre sugerencias de IA.
844
+ * Permite trackear si el usuario acepto, rechazo o modifico las sugerencias.
845
+ *
846
+ * @param data - Datos de la accion del usuario
847
+ * @returns Confirmacion de que la accion fue registrada
848
+ *
849
+ * @example
850
+ * ```typescript
851
+ * const result = await sdk.ai.getSuggestions({
852
+ * userId: 'user-123',
853
+ * text: 'No puedo iniciar sesion',
854
+ * });
855
+ *
856
+ * // El usuario revisa las sugerencias y acepta todas
857
+ * await sdk.ai.trackAiAction({
858
+ * eventId: result?.analyticsEventId!,
859
+ * userAction: 'ACCEPTED_ALL',
860
+ * fieldsAccepted: ['title', 'description', 'category', 'priority'],
861
+ * timeToDecisionMs: 3500,
862
+ * });
863
+ * ```
864
+ */
865
+ trackAiAction(data: TrackAiActionInput): Promise<{
866
+ success: boolean;
867
+ }>;
868
+ /**
869
+ * Solicita sugerencias de IA y recibe el resultado via SSE (Server-Sent Events).
870
+ * Alternativa al polling que ofrece actualizaciones en tiempo real.
871
+ *
872
+ * Requiere un entorno con EventSource nativo (navegador).
873
+ * Para Node.js se necesita un polyfill como 'eventsource'.
874
+ *
875
+ * @param data - Datos para generar sugerencias
876
+ * @param options - Opciones de streaming
877
+ * @returns Handle con promesa de resultado y funcion de aborto
878
+ *
879
+ * @example
880
+ * ```typescript
881
+ * const handle = await sdk.ai.streamSuggestions(
882
+ * { userId: 'user-123', text: 'No puedo iniciar sesion' },
883
+ * { onProgress: (p) => console.log(`Progreso: ${p}%`) },
884
+ * );
885
+ *
886
+ * // Esperar resultado
887
+ * const result = await handle.result;
888
+ * console.log(result?.suggestions);
889
+ *
890
+ * // O abortar si el usuario cancela
891
+ * handle.abort();
892
+ * ```
893
+ */
894
+ streamSuggestions(data: AiSuggestInput, options?: StreamSuggestionsOptions): Promise<StreamSuggestionsHandle>;
895
+ /**
896
+ * Solicita una transcripcion de audio de forma asincrona.
897
+ * Retorna un jobId para consultar el estado o usar con streamTranscription.
898
+ *
899
+ * @param audioBase64 - Audio codificado en base64
900
+ * @param audioFilename - Nombre del archivo con extension
901
+ * @returns ID del job para consultar estado
902
+ *
903
+ * @example
904
+ * ```typescript
905
+ * const { jobId } = await sdk.ai.requestTranscription(
906
+ * audioBase64,
907
+ * 'recording.webm',
908
+ * );
909
+ * ```
910
+ */
911
+ requestTranscription(audioBase64: string, audioFilename: string): Promise<{
912
+ jobId: string;
913
+ }>;
914
+ /**
915
+ * Obtiene el estado de un job de transcripcion asincrona.
916
+ *
917
+ * @param jobId - ID del job obtenido de requestTranscription
918
+ * @returns Estado actual del job de transcripcion
919
+ *
920
+ * @example
921
+ * ```typescript
922
+ * const status = await sdk.ai.getTranscriptionStatus(jobId);
923
+ *
924
+ * if (status.status === 'completed') {
925
+ * console.log(status.transcription);
926
+ * }
927
+ * ```
928
+ */
929
+ getTranscriptionStatus(jobId: string): Promise<TranscriptionJobStatus>;
930
+ /**
931
+ * Solicita una transcripcion de audio y recibe el resultado via SSE.
932
+ * Alternativa al polling para transcripciones asincronas.
933
+ *
934
+ * Requiere un entorno con EventSource nativo (navegador).
935
+ * Para Node.js se necesita un polyfill como 'eventsource'.
936
+ *
937
+ * @param audioBase64 - Audio codificado en base64
938
+ * @param audioFilename - Nombre del archivo con extension
939
+ * @param options - Opciones de streaming
940
+ * @returns Promesa que resuelve con el texto transcrito
941
+ *
942
+ * @example
943
+ * ```typescript
944
+ * const { transcription } = await sdk.ai.streamTranscription(
945
+ * audioBase64,
946
+ * 'recording.webm',
947
+ * { onProgress: (p) => console.log(`Progreso: ${p}%`) },
948
+ * );
949
+ * console.log(transcription);
950
+ * ```
951
+ */
952
+ streamTranscription(audioBase64: string, audioFilename: string, options?: StreamTranscriptionOptions): Promise<{
953
+ transcription: string;
954
+ }>;
955
+ /**
956
+ * Reporta un error del cliente al servidor para monitoreo.
957
+ * Este metodo nunca lanza excepciones; los errores de reporte se ignoran silenciosamente.
958
+ *
959
+ * @param params - Datos del error a reportar
960
+ *
961
+ * @example
962
+ * ```typescript
963
+ * await sdk.ai.reportError({
964
+ * message: 'No se pudo cargar el widget',
965
+ * code: 'WIDGET_LOAD_ERROR',
966
+ * component: 'widget',
967
+ * url: window.location.href,
968
+ * userAgent: navigator.userAgent,
969
+ * });
970
+ * ```
971
+ */
972
+ reportError(params: {
973
+ message: string;
974
+ stack?: string;
975
+ code?: string;
976
+ component?: string;
977
+ context?: string;
978
+ endpoint?: string;
979
+ method?: string;
980
+ requestId?: string;
981
+ url?: string;
982
+ userAgent?: string;
983
+ }): Promise<void>;
723
984
  /**
724
985
  * Helper para esperar un tiempo
725
986
  */
@@ -754,7 +1015,14 @@ declare class UtiliaSDKError extends Error {
754
1015
  readonly code: ErrorCode;
755
1016
  /** Timestamp de cuando ocurrio el error */
756
1017
  readonly timestamp: Date;
757
- constructor(code: ErrorCode, message: string);
1018
+ /** ID de la peticion que genero el error */
1019
+ readonly requestId?: string;
1020
+ /** Codigo de estado HTTP de la respuesta */
1021
+ readonly statusCode?: number;
1022
+ constructor(code: ErrorCode, message: string, options?: {
1023
+ requestId?: string;
1024
+ statusCode?: number;
1025
+ });
758
1026
  /**
759
1027
  * Serializa el error a un objeto JSON
760
1028
  */
@@ -763,6 +1031,8 @@ declare class UtiliaSDKError extends Error {
763
1031
  code: ErrorCode;
764
1032
  message: string;
765
1033
  timestamp: string;
1034
+ requestId: string | undefined;
1035
+ statusCode: number | undefined;
766
1036
  };
767
1037
  /**
768
1038
  * Verifica si el error es de tipo rate limit
@@ -869,4 +1139,4 @@ declare class UtiliaSDK {
869
1139
  constructor(config: UtiliaSDKConfig);
870
1140
  }
871
1141
 
872
- export { type AddMessageInput, type AiJobStatus, type AiSuggestInput, type AiSuggestions, type CreateTicketInput, type CreateTicketUser, type CreatedMessage, type CreatedTicket, ErrorCode, type ExternalUser, type FileQuota, type GetSuggestionsOptions, type IdentifyUserInput, type MessageAuthor, type PaginatedResponse, type PaginationMeta, type RequestConfig, SDK_LIMITS, type TicketAttachment, type TicketCategory, type TicketContext, type TicketDetail, type TicketFilters, type TicketListItem, type TicketMessage, type TicketPriority, type TicketStatus, type UnreadCount, type UploadFileOptions, type UploadedFile, UtiliaSDK, type UtiliaSDKConfig, UtiliaSDKError };
1142
+ export { type AddMessageInput, type AiJobStatus, type AiSuggestInput, type AiSuggestions, type AiUserAction, type CreateTicketInput, type CreateTicketUser, type CreatedMessage, type CreatedTicket, ErrorCode, type ExternalUser, type FileQuota, type GetSuggestionsOptions, type IdentifyUserInput, type MessageAuthor, type PaginatedResponse, type PaginationMeta, type RequestConfig, SDK_LIMITS, type SseEvent, type StreamSuggestionsHandle, type StreamSuggestionsOptions, type StreamTranscriptionOptions, type TicketAttachment, type TicketCategory, type TicketContext, type TicketDetail, type TicketFilters, type TicketListItem, type TicketMessage, type TicketPriority, type TicketReporter, type TicketStatus, type TrackAiActionInput, type TranscriptionJobStatus, type UnreadCount, type UploadFileOptions, type UploadedFile, UtiliaSDK, type UtiliaSDKConfig, UtiliaSDKError };