@fiction/sdk 1.0.39 → 1.0.41

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 (30) hide show
  1. package/dist/{FModal.vue_vue_type_script_setup_true_lang-B9Vpr1MV.js → FModal.vue_vue_type_script_setup_true_lang-BkRDQLfP.js} +2 -2
  2. package/dist/{FModal.vue_vue_type_script_setup_true_lang-B9Vpr1MV.js.map → FModal.vue_vue_type_script_setup_true_lang-BkRDQLfP.js.map} +1 -1
  3. package/dist/{SelfProvider.vue_vue_type_script_setup_true_lang-B-VYDrTJ.js → SelfProvider.vue_vue_type_script_setup_true_lang-BCjvISK2.js} +2 -2
  4. package/dist/{SelfProvider.vue_vue_type_script_setup_true_lang-B-VYDrTJ.js.map → SelfProvider.vue_vue_type_script_setup_true_lang-BCjvISK2.js.map} +1 -1
  5. package/dist/{SelfWidgetInline-DW6rw5EF.js → SelfWidgetInline-GzGL8CWn.js} +2 -2
  6. package/dist/{SelfWidgetInline-DW6rw5EF.js.map → SelfWidgetInline-GzGL8CWn.js.map} +1 -1
  7. package/dist/{SelfWidgetModal-CxkuNNO5.js → SelfWidgetModal-BUIFDzAz.js} +3 -3
  8. package/dist/{SelfWidgetModal-CxkuNNO5.js.map → SelfWidgetModal-BUIFDzAz.js.map} +1 -1
  9. package/dist/{SelfWidgetPopup-D3_kY3nR.js → SelfWidgetPopup-pENdjzof.js} +2 -2
  10. package/dist/{SelfWidgetPopup-D3_kY3nR.js.map → SelfWidgetPopup-pENdjzof.js.map} +1 -1
  11. package/dist/{SelfWrap.vue_vue_type_script_setup_true_lang-BM-kzpfo.js → SelfWrap.vue_vue_type_script_setup_true_lang-Bh_btZUV.js} +1562 -1408
  12. package/dist/SelfWrap.vue_vue_type_script_setup_true_lang-Bh_btZUV.js.map +1 -0
  13. package/dist/demo/index.d.ts +2 -0
  14. package/dist/sdk.css +1 -1
  15. package/dist/sdkClient.d.ts +3 -0
  16. package/dist/self/ClientAudio.d.ts +27 -4
  17. package/dist/self/SelfController.d.ts +12 -0
  18. package/dist/self/schema.d.ts +1 -0
  19. package/dist/self/test/SelfController.test.d.ts +1 -0
  20. package/dist/self/test/utils.test.d.ts +1 -0
  21. package/dist/self/ui/ElSelfAudioVisualizer.vue.d.ts +10 -0
  22. package/dist/self/ui/SelfWrap.vue.d.ts +1 -0
  23. package/dist/self.js +4 -4
  24. package/dist/widget/composables/useFictionWidget.d.ts +57 -0
  25. package/dist/widget/index.d.ts +2 -0
  26. package/dist/widget.js +77 -38
  27. package/dist/widget.js.map +1 -1
  28. package/package.json +2 -2
  29. package/dist/SelfWrap.vue_vue_type_script_setup_true_lang-BM-kzpfo.js.map +0 -1
  30. package/dist/self/ui/ElAudioVisualizer.vue.d.ts +0 -19
@@ -221,6 +221,7 @@ export declare class FictionSDK extends SettingsObject<FictionSDKSettings> {
221
221
  gender?: string | null | undefined;
222
222
  birthdayAt?: string | null | undefined;
223
223
  businessTemplate?: string | null | undefined;
224
+ onboardedAt?: string | null | undefined;
224
225
  enrichment?: Record<string, any> | null | undefined;
225
226
  onboarding?: Record<string, any> | null | undefined;
226
227
  org?: {
@@ -451,6 +452,7 @@ export declare class FictionSDK extends SettingsObject<FictionSDKSettings> {
451
452
  gender?: string | null | undefined;
452
453
  birthdayAt?: string | null | undefined;
453
454
  businessTemplate?: string | null | undefined;
455
+ onboardedAt?: string | null | undefined;
454
456
  enrichment?: Record<string, any> | null | undefined;
455
457
  onboarding?: Record<string, any> | null | undefined;
456
458
  org?: {
@@ -572,6 +574,7 @@ export declare class FictionSDK extends SettingsObject<FictionSDKSettings> {
572
574
  gender?: string | null | undefined;
573
575
  birthdayAt?: string | null | undefined;
574
576
  businessTemplate?: string | null | undefined;
577
+ onboardedAt?: string | null | undefined;
575
578
  enrichment?: Record<string, any> | null | undefined;
576
579
  onboarding?: Record<string, any> | null | undefined;
577
580
  org?: {
@@ -4,6 +4,7 @@ export type AudioPermissionOptions = {
4
4
  noiseSuppression?: boolean;
5
5
  echoCancellation?: boolean;
6
6
  autoGainControl?: boolean;
7
+ voiceIsolation?: boolean;
7
8
  };
8
9
  type ClientAudioSettings = {
9
10
  [key: string]: unknown;
@@ -15,6 +16,10 @@ export declare class ClientAudio extends SettingsObject<ClientAudioSettings> {
15
16
  private audioLevelInterval?;
16
17
  private stream?;
17
18
  private visibilityChangeHandler?;
19
+ private vadTimeout?;
20
+ private lastSpeechTime;
21
+ private readonly VAD_SILENCE_THRESHOLD;
22
+ private readonly VAD_SILENCE_DURATION;
18
23
  audioLevels: import('vue').Ref<{
19
24
  inputLevel: number;
20
25
  outputLevel: number;
@@ -28,25 +33,43 @@ export declare class ClientAudio extends SettingsObject<ClientAudioSettings> {
28
33
  */
29
34
  private setupVisibilityHandler;
30
35
  /**
31
- * Handle app going to background (iOS microphone indicator fix)
36
+ * Handle app going to background (Privacy & Security Best Practice)
37
+ * CRITICAL: Must stop microphone tracks to remove indicator on mobile/browser
32
38
  */
33
39
  private handleAppBackground;
34
40
  /**
35
41
  * Handle app returning to foreground
42
+ * SECURITY: Do NOT auto-restart microphone - requires user gesture (browser security model)
36
43
  */
37
44
  private handleAppForeground;
38
45
  /**
39
- * Request microphone permission and setup audio analysis
46
+ * Request microphone permission with voice isolation and setup audio analysis
47
+ * Returns the MediaStream for ElevenLabs to reuse (prevents dual stream conflicts)
40
48
  */
41
49
  requestMicrophonePermission(options?: AudioPermissionOptions): Promise<boolean>;
50
+ /**
51
+ * Get the microphone stream for ElevenLabs to reuse
52
+ * CRITICAL: This prevents dual stream conflicts that break the analyser
53
+ */
54
+ getMicrophoneStream(): MediaStream | undefined;
42
55
  /**
43
56
  * Setup audio analysis for level monitoring
44
57
  */
45
58
  private setupAudioAnalysis;
46
59
  /**
47
- * Start monitoring audio levels
60
+ * Detect voice activity (returns true if user is speaking)
61
+ * Used for client-side VAD to prevent background noise issues
62
+ */
63
+ private detectVoiceActivity;
64
+ /**
65
+ * Check if user has stopped speaking (silence detected)
66
+ * Returns true if VAD_SILENCE_DURATION has passed since last speech
67
+ */
68
+ hasUserStoppedSpeaking(): boolean;
69
+ /**
70
+ * Start monitoring audio levels with VAD detection
48
71
  */
49
- startAudioLevelMonitoring(isConnected?: () => boolean): void;
72
+ startAudioLevelMonitoring(isConnected?: () => boolean, onSilenceDetected?: () => void): void;
50
73
  /**
51
74
  * Stop monitoring audio levels
52
75
  */
@@ -27,6 +27,8 @@ export declare class SelfController extends SettingsObject<SelfControllerSetting
27
27
  private clientAudio;
28
28
  private unwatchAudio?;
29
29
  private isConnecting;
30
+ private lastUserSpeechTime;
31
+ private lastUserMessageTime;
30
32
  private sessionId?;
31
33
  private conversationStartTime?;
32
34
  private chatCharacterCount;
@@ -45,7 +47,17 @@ export declare class SelfController extends SettingsObject<SelfControllerSetting
45
47
  outputLevel: number;
46
48
  }>;
47
49
  getClientAudio(): ClientAudio;
50
+ /**
51
+ * Get output (agent speaking) frequency data from ElevenLabs
52
+ * Used by visualizer during 'speaking' mode
53
+ */
48
54
  getOutputFrequencyData(): Uint8Array | null;
55
+ /**
56
+ * Get input (user speaking) frequency data from ElevenLabs
57
+ * Used by visualizer during 'listening' mode
58
+ * Fallback: Uses ClientAudio analyser if ElevenLabs data unavailable
59
+ */
60
+ getInputFrequencyData(): Uint8Array | null;
49
61
  private isDuplicateMessage;
50
62
  private addMessage;
51
63
  private getDynamicSettings;
@@ -10,6 +10,7 @@ export interface VoiceConnectionState {
10
10
  isConnected: boolean;
11
11
  isSpeaking: boolean;
12
12
  isListening: boolean;
13
+ isProcessing: boolean;
13
14
  transcript?: string;
14
15
  connectionStatus: 'connecting' | 'connected' | 'disconnected' | 'error';
15
16
  error?: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { SelfController } from '../SelfController';
2
+ type __VLS_Props = {
3
+ selfController?: SelfController;
4
+ size?: 'sm' | 'md' | 'lg';
5
+ color?: 'blue' | 'green' | 'gray' | 'auto';
6
+ enableWaveMotion?: boolean;
7
+ enableGlow?: boolean;
8
+ };
9
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
10
+ export default _default;
@@ -47,6 +47,7 @@ declare function __VLS_template(): {
47
47
  gender?: string | null | undefined;
48
48
  birthdayAt?: string | null | undefined;
49
49
  businessTemplate?: string | null | undefined;
50
+ onboardedAt?: string | null | undefined;
50
51
  enrichment?: Record<string, any> | null | undefined;
51
52
  onboarding?: Record<string, any> | null | undefined;
52
53
  org?: {
package/dist/self.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var E = Object.defineProperty;
2
2
  var d = (e, l) => E(e, "name", { value: l, configurable: !0 });
3
- import { a as A, g as C, c as I, b as M } from "./SelfWrap.vue_vue_type_script_setup_true_lang-BM-kzpfo.js";
4
- import { h as q, A as J, e as K, d as X, C as Y, V as ee, f as te, k as se, i as ae, j as oe, p as ie } from "./SelfWrap.vue_vue_type_script_setup_true_lang-BM-kzpfo.js";
3
+ import { a as A, g as C, c as I, b as M } from "./SelfWrap.vue_vue_type_script_setup_true_lang-Bh_btZUV.js";
4
+ import { h as q, A as J, e as K, d as X, C as Y, V as ee, f as te, k as se, i as ae, j as oe, p as ie } from "./SelfWrap.vue_vue_type_script_setup_true_lang-Bh_btZUV.js";
5
5
  import { defineComponent as b, createBlock as u, openBlock as c, withCtx as k, createElementVNode as o, createVNode as O, ref as v, watch as U, nextTick as V, createElementBlock as h, createCommentVNode as f, normalizeClass as p, normalizeStyle as _, unref as x } from "vue";
6
- import { _ as $ } from "./FModal.vue_vue_type_script_setup_true_lang-B9Vpr1MV.js";
7
- import { _ as N } from "./SelfProvider.vue_vue_type_script_setup_true_lang-B-VYDrTJ.js";
6
+ import { _ as $ } from "./FModal.vue_vue_type_script_setup_true_lang-BkRDQLfP.js";
7
+ import { _ as N } from "./SelfProvider.vue_vue_type_script_setup_true_lang-BCjvISK2.js";
8
8
  const z = { class: "relative w-full h-[80vh] md:h-[600px]" }, P = /* @__PURE__ */ b({
9
9
  name: "SelfModal",
10
10
  __name: "SelfModal",
@@ -0,0 +1,57 @@
1
+ import { MaybeRef } from 'vue';
2
+ import { Self } from '@fiction/types';
3
+ import { WidgetConfig, WidgetUpdate, FictionWidget } from '../FictionWidget';
4
+ export interface UseFictionWidgetConfig {
5
+ mode: WidgetConfig['mode'];
6
+ handle?: MaybeRef<string | undefined>;
7
+ self?: MaybeRef<Self | null | undefined>;
8
+ context?: MaybeRef<string | undefined>;
9
+ firstMessage?: MaybeRef<string | undefined>;
10
+ apiBase?: string;
11
+ onClose?: () => void;
12
+ }
13
+ /**
14
+ * Composable for managing FictionWidget lifecycle with automatic initialization,
15
+ * reactive updates, and cleanup.
16
+ *
17
+ * Benefits:
18
+ * - Eliminates manual DOM timing coordination (watch + nextTick)
19
+ * - Automatic cleanup on unmount
20
+ * - Reactive prop updates via widget.update()
21
+ * - Prevents double initialization
22
+ * - Clear loading/error states
23
+ *
24
+ * @example
25
+ * ```vue
26
+ * <script setup>
27
+ * const selfRef = ref<Self | null>(null)
28
+ * const { containerRef, loading, error } = useFictionWidget({
29
+ * mode: 'inline',
30
+ * self: selfRef,
31
+ * context: 'welcome'
32
+ * })
33
+ * </script>
34
+ *
35
+ * <template>
36
+ * <div ref="containerRef" class="w-full h-full" />
37
+ * </template>
38
+ * ```
39
+ */
40
+ export declare function useFictionWidget(config: UseFictionWidgetConfig): {
41
+ containerRef: import('vue').Ref<HTMLElement | null, HTMLElement | null>;
42
+ widget: import('vue').Ref<{
43
+ update: (updates: WidgetUpdate) => void;
44
+ toggle: () => void;
45
+ open: () => void;
46
+ close: () => void;
47
+ destroy: () => void;
48
+ } | null, FictionWidget | {
49
+ update: (updates: WidgetUpdate) => void;
50
+ toggle: () => void;
51
+ open: () => void;
52
+ close: () => void;
53
+ destroy: () => void;
54
+ } | null>;
55
+ loading: import('vue').Ref<boolean, boolean>;
56
+ error: import('vue').Ref<string | null, string | null>;
57
+ };
@@ -1,2 +1,4 @@
1
1
  export { FictionWidget } from './FictionWidget';
2
2
  export type { WidgetConfig, WidgetUpdate } from './FictionWidget';
3
+ export { useFictionWidget } from './composables/useFictionWidget';
4
+ export type { UseFictionWidgetConfig } from './composables/useFictionWidget';