@chatterfly/widget 0.4.0 → 0.6.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
@@ -124,7 +124,7 @@ interface WidgetConfig {
124
124
  */
125
125
  connectionPolicy?: ConnectionPolicy | "always-on";
126
126
  }
127
- type RunStatus = "idle" | "connecting" | "replaying" | "running" | "awaiting_input" | "awaiting_voice" | "awaiting_form" | "awaiting_chat" | "awaiting_editor" | "completed" | "error" | "offline" | "expired";
127
+ type RunStatus = "idle" | "connecting" | "replaying" | "running" | "awaiting_authorization" | "awaiting_input" | "awaiting_voice" | "awaiting_form" | "awaiting_chat" | "awaiting_editor" | "completed" | "error" | "offline" | "expired";
128
128
  /**
129
129
  * Connection lifecycle tuning (Phase 119.4/119.5). Controls when an
130
130
  * idle-at-input widget deliberately drops its socket ("dormant"), lazily
@@ -272,12 +272,21 @@ type RunEvent = {
272
272
  type: "message.sent";
273
273
  content: string;
274
274
  participant_role: string;
275
+ } | {
276
+ type: "run_complete";
277
+ state?: Record<string, unknown>;
275
278
  } | {
276
279
  type: "run.completed";
277
280
  state?: Record<string, unknown>;
278
281
  } | {
279
282
  type: "run.cancelled";
280
283
  state?: Record<string, unknown>;
284
+ } | {
285
+ type: "run.authorization_required";
286
+ payload: string;
287
+ } | {
288
+ type: "run_error";
289
+ error?: string;
281
290
  } | {
282
291
  type: "run.failed";
283
292
  error: string;
@@ -290,13 +299,25 @@ type RunEvent = {
290
299
  } | {
291
300
  type: "timeline.entry";
292
301
  payload: TimelineEntry;
302
+ } | {
303
+ type: "provider_operation";
304
+ node_id?: string;
305
+ payload: ProviderOperationSummary;
293
306
  };
307
+ interface ProviderOperationSummary {
308
+ operation: string;
309
+ outcome: "success" | "error";
310
+ replayed?: boolean;
311
+ record_id?: string;
312
+ record_url?: string;
313
+ error_code?: string;
314
+ }
294
315
  interface TimelineEntry {
295
316
  id: string;
296
317
  run_id: string;
297
318
  session_id: string | null;
298
319
  seq: number;
299
- event_type: "prompt" | "response" | "message" | "form_opened" | "form_submitted" | "status_change" | "delay_started" | "delay_resumed";
320
+ event_type: "prompt" | "response" | "message" | "form_opened" | "form_submitted" | "status_change" | "delay_started" | "delay_resumed" | "llm_call" | "tool_call" | "tool_result" | "provider_operation";
300
321
  sender: "bot" | "user" | "system";
301
322
  payload: Record<string, unknown>;
302
323
  created_at: string;
@@ -322,6 +343,8 @@ interface WidgetStrings {
322
343
  statusCompletedTitle: string;
323
344
  statusCompletedBody: string;
324
345
  statusErrorTitle: string;
346
+ statusAuthorizationTitle: string;
347
+ statusAuthorizationBody: string;
325
348
  statusOfflineTitle: string;
326
349
  statusOfflineBody: string;
327
350
  statusExpiredTitle: string;
@@ -330,7 +353,9 @@ interface WidgetStrings {
330
353
  resumingConversation: string;
331
354
  reconnecting: string;
332
355
  conversationCompleted: string;
356
+ conversationTimedOut: string;
333
357
  somethingWentWrong: string;
358
+ tryAgain: string;
334
359
  chatInputPlaceholder: string;
335
360
  sendButton: string;
336
361
  handBackButton: string;
@@ -523,6 +548,8 @@ declare const ChatAdapter: react.ForwardRefExoticComponent<ChatAdapterProps & re
523
548
  type VoiceOrbState = "idle" | "listening" | "speaking" | "processing" | "confirming" | "error";
524
549
  interface VoiceOrbProps {
525
550
  state: VoiceOrbState;
551
+ /** Smoothed microphone energy in the range 0..1. */
552
+ inputLevel?: number;
526
553
  onPress?: () => void;
527
554
  onRelease?: () => void;
528
555
  disabled?: boolean;
@@ -538,7 +565,7 @@ interface VoiceOrbProps {
538
565
  * - confirming: pop + success color
539
566
  * - error: shake + red flash
540
567
  */
541
- declare function VoiceOrb({ state, onPress, onRelease, disabled, }: VoiceOrbProps): react_jsx_runtime.JSX.Element;
568
+ declare function VoiceOrb({ state, inputLevel, onPress, onRelease, disabled, }: VoiceOrbProps): react_jsx_runtime.JSX.Element;
542
569
 
543
570
  interface VoicePromptCardProps {
544
571
  field: FieldSpec;
@@ -643,12 +670,21 @@ interface VoiceLiveRendererProps {
643
670
  participantToken: string;
644
671
  /** HITL session id; the proxy resolves field, channel, and tokens from it. */
645
672
  sessionId: string;
673
+ /** Current field's HITL session, distinct from the first session pinned for the socket. */
674
+ fieldSessionId: string;
646
675
  /** Resolved widget/voice live tunables (config.style "live"). May be empty — defaults are server-side. */
647
676
  liveConfig?: SurfaceConfig;
648
677
  onValue: (value: unknown) => void;
678
+ onPlaybackComplete?: () => void;
679
+ onFieldRevealed?: (sessionId: string) => void;
680
+ timedOut?: boolean;
681
+ timeoutMessage?: string;
682
+ retryLabel?: string;
683
+ userCanEnd?: boolean;
684
+ endLabel?: string;
649
685
  disabled?: boolean;
650
686
  }
651
- declare function VoiceLiveRenderer({ field, apiBase, participantToken, sessionId, liveConfig, onValue, disabled, }: VoiceLiveRendererProps): react_jsx_runtime.JSX.Element;
687
+ declare function VoiceLiveRenderer({ field, apiBase, participantToken, sessionId, fieldSessionId, liveConfig, onValue, onPlaybackComplete, onFieldRevealed, timedOut, timeoutMessage, retryLabel, userCanEnd, endLabel, disabled, }: VoiceLiveRendererProps): react_jsx_runtime.JSX.Element;
652
688
 
653
689
  interface RequiredConnection {
654
690
  slug: string;
@@ -711,13 +747,17 @@ declare function ConnectionOnboarding({ connections, appBase, participantToken,
711
747
  * Live model, so the widget only manages the audio pipes and surfaces
712
748
  * transparency events to the UI.
713
749
  */
714
- type LiveVoiceState = "idle" | "connecting" | "listening" | "speaking" | "muted" | "completed" | "error";
750
+ type LiveVoiceState = "idle" | "connecting" | "listening"
751
+ /** Transcript arrived; answer/tool/workflow/model turn is advancing. */
752
+ | "processing" | "finalizing" | "speaking" | "muted" | "completed" | "error";
715
753
  interface LiveTranscript {
716
754
  /** "user" for input transcription, "assistant" for output transcription. */
717
755
  who: "user" | "assistant";
718
756
  text: string;
719
757
  /** Final transcripts arrive once per utterance; partials may stream. */
720
758
  final: boolean;
759
+ /** Durable timeline sequence for restored transcript entries. */
760
+ sequence?: number;
721
761
  }
722
762
  interface LiveSessionConfig {
723
763
  apiBase: string;
@@ -735,11 +775,35 @@ interface LiveSessionResult {
735
775
  assistantText: string;
736
776
  /** Latest field id reported by the proxy via field_change. */
737
777
  activeFieldId: string | null;
778
+ /**
779
+ * The most recent field whose audio has finished PLAYING. The engine opens a
780
+ * field (and sends field_change) seconds before the spoken question ends, so
781
+ * renderers should gate field UI on this, not on activeFieldId.
782
+ */
783
+ askedFieldId: string | null;
784
+ /** True once the terminal socket has closed and all received PCM has played. */
785
+ playbackComplete: boolean;
738
786
  /** The committed value, set when the proxy emits a value envelope. */
739
787
  lastValue: unknown;
788
+ /** Latest durable checkpoint metadata; checkpoint contents remain server-only. */
789
+ checkpoint: {
790
+ sequence: number;
791
+ turn: number;
792
+ reconstructed: boolean;
793
+ } | null;
794
+ /** Server-owned completion progress; final output arrives through the run stream. */
795
+ completion: {
796
+ status: "finalizing" | "completed";
797
+ reason: string | null;
798
+ } | null;
799
+ /** Smoothed microphone energy in the range 0..1; visual feedback only. */
800
+ inputLevel: number;
740
801
  isMuted: boolean;
741
802
  toggleMute: () => void;
742
803
  error: string | null;
804
+ errorRecoverable: boolean;
805
+ retryError: () => void;
806
+ requestEnd: () => void;
743
807
  }
744
808
  declare function useGeminiLiveSession(cfg: LiveSessionConfig, onValue: (value: unknown) => void): LiveSessionResult;
745
809
 
@@ -835,6 +899,10 @@ interface ValidationError {
835
899
  }
836
900
  interface UseRunStreamResult {
837
901
  status: RunStatus;
902
+ /** Sanitized terminal classification used for participant-facing presentation. */
903
+ failureKind: "timeout" | null;
904
+ /** Current token, including a successful public-run re-mint. */
905
+ currentParticipantToken: string;
838
906
  activeSession: HITLSession | null;
839
907
  messages: ChatMessage[];
840
908
  timeline: TimelineEntry[];
package/dist/index.d.ts CHANGED
@@ -124,7 +124,7 @@ interface WidgetConfig {
124
124
  */
125
125
  connectionPolicy?: ConnectionPolicy | "always-on";
126
126
  }
127
- type RunStatus = "idle" | "connecting" | "replaying" | "running" | "awaiting_input" | "awaiting_voice" | "awaiting_form" | "awaiting_chat" | "awaiting_editor" | "completed" | "error" | "offline" | "expired";
127
+ type RunStatus = "idle" | "connecting" | "replaying" | "running" | "awaiting_authorization" | "awaiting_input" | "awaiting_voice" | "awaiting_form" | "awaiting_chat" | "awaiting_editor" | "completed" | "error" | "offline" | "expired";
128
128
  /**
129
129
  * Connection lifecycle tuning (Phase 119.4/119.5). Controls when an
130
130
  * idle-at-input widget deliberately drops its socket ("dormant"), lazily
@@ -272,12 +272,21 @@ type RunEvent = {
272
272
  type: "message.sent";
273
273
  content: string;
274
274
  participant_role: string;
275
+ } | {
276
+ type: "run_complete";
277
+ state?: Record<string, unknown>;
275
278
  } | {
276
279
  type: "run.completed";
277
280
  state?: Record<string, unknown>;
278
281
  } | {
279
282
  type: "run.cancelled";
280
283
  state?: Record<string, unknown>;
284
+ } | {
285
+ type: "run.authorization_required";
286
+ payload: string;
287
+ } | {
288
+ type: "run_error";
289
+ error?: string;
281
290
  } | {
282
291
  type: "run.failed";
283
292
  error: string;
@@ -290,13 +299,25 @@ type RunEvent = {
290
299
  } | {
291
300
  type: "timeline.entry";
292
301
  payload: TimelineEntry;
302
+ } | {
303
+ type: "provider_operation";
304
+ node_id?: string;
305
+ payload: ProviderOperationSummary;
293
306
  };
307
+ interface ProviderOperationSummary {
308
+ operation: string;
309
+ outcome: "success" | "error";
310
+ replayed?: boolean;
311
+ record_id?: string;
312
+ record_url?: string;
313
+ error_code?: string;
314
+ }
294
315
  interface TimelineEntry {
295
316
  id: string;
296
317
  run_id: string;
297
318
  session_id: string | null;
298
319
  seq: number;
299
- event_type: "prompt" | "response" | "message" | "form_opened" | "form_submitted" | "status_change" | "delay_started" | "delay_resumed";
320
+ event_type: "prompt" | "response" | "message" | "form_opened" | "form_submitted" | "status_change" | "delay_started" | "delay_resumed" | "llm_call" | "tool_call" | "tool_result" | "provider_operation";
300
321
  sender: "bot" | "user" | "system";
301
322
  payload: Record<string, unknown>;
302
323
  created_at: string;
@@ -322,6 +343,8 @@ interface WidgetStrings {
322
343
  statusCompletedTitle: string;
323
344
  statusCompletedBody: string;
324
345
  statusErrorTitle: string;
346
+ statusAuthorizationTitle: string;
347
+ statusAuthorizationBody: string;
325
348
  statusOfflineTitle: string;
326
349
  statusOfflineBody: string;
327
350
  statusExpiredTitle: string;
@@ -330,7 +353,9 @@ interface WidgetStrings {
330
353
  resumingConversation: string;
331
354
  reconnecting: string;
332
355
  conversationCompleted: string;
356
+ conversationTimedOut: string;
333
357
  somethingWentWrong: string;
358
+ tryAgain: string;
334
359
  chatInputPlaceholder: string;
335
360
  sendButton: string;
336
361
  handBackButton: string;
@@ -523,6 +548,8 @@ declare const ChatAdapter: react.ForwardRefExoticComponent<ChatAdapterProps & re
523
548
  type VoiceOrbState = "idle" | "listening" | "speaking" | "processing" | "confirming" | "error";
524
549
  interface VoiceOrbProps {
525
550
  state: VoiceOrbState;
551
+ /** Smoothed microphone energy in the range 0..1. */
552
+ inputLevel?: number;
526
553
  onPress?: () => void;
527
554
  onRelease?: () => void;
528
555
  disabled?: boolean;
@@ -538,7 +565,7 @@ interface VoiceOrbProps {
538
565
  * - confirming: pop + success color
539
566
  * - error: shake + red flash
540
567
  */
541
- declare function VoiceOrb({ state, onPress, onRelease, disabled, }: VoiceOrbProps): react_jsx_runtime.JSX.Element;
568
+ declare function VoiceOrb({ state, inputLevel, onPress, onRelease, disabled, }: VoiceOrbProps): react_jsx_runtime.JSX.Element;
542
569
 
543
570
  interface VoicePromptCardProps {
544
571
  field: FieldSpec;
@@ -643,12 +670,21 @@ interface VoiceLiveRendererProps {
643
670
  participantToken: string;
644
671
  /** HITL session id; the proxy resolves field, channel, and tokens from it. */
645
672
  sessionId: string;
673
+ /** Current field's HITL session, distinct from the first session pinned for the socket. */
674
+ fieldSessionId: string;
646
675
  /** Resolved widget/voice live tunables (config.style "live"). May be empty — defaults are server-side. */
647
676
  liveConfig?: SurfaceConfig;
648
677
  onValue: (value: unknown) => void;
678
+ onPlaybackComplete?: () => void;
679
+ onFieldRevealed?: (sessionId: string) => void;
680
+ timedOut?: boolean;
681
+ timeoutMessage?: string;
682
+ retryLabel?: string;
683
+ userCanEnd?: boolean;
684
+ endLabel?: string;
649
685
  disabled?: boolean;
650
686
  }
651
- declare function VoiceLiveRenderer({ field, apiBase, participantToken, sessionId, liveConfig, onValue, disabled, }: VoiceLiveRendererProps): react_jsx_runtime.JSX.Element;
687
+ declare function VoiceLiveRenderer({ field, apiBase, participantToken, sessionId, fieldSessionId, liveConfig, onValue, onPlaybackComplete, onFieldRevealed, timedOut, timeoutMessage, retryLabel, userCanEnd, endLabel, disabled, }: VoiceLiveRendererProps): react_jsx_runtime.JSX.Element;
652
688
 
653
689
  interface RequiredConnection {
654
690
  slug: string;
@@ -711,13 +747,17 @@ declare function ConnectionOnboarding({ connections, appBase, participantToken,
711
747
  * Live model, so the widget only manages the audio pipes and surfaces
712
748
  * transparency events to the UI.
713
749
  */
714
- type LiveVoiceState = "idle" | "connecting" | "listening" | "speaking" | "muted" | "completed" | "error";
750
+ type LiveVoiceState = "idle" | "connecting" | "listening"
751
+ /** Transcript arrived; answer/tool/workflow/model turn is advancing. */
752
+ | "processing" | "finalizing" | "speaking" | "muted" | "completed" | "error";
715
753
  interface LiveTranscript {
716
754
  /** "user" for input transcription, "assistant" for output transcription. */
717
755
  who: "user" | "assistant";
718
756
  text: string;
719
757
  /** Final transcripts arrive once per utterance; partials may stream. */
720
758
  final: boolean;
759
+ /** Durable timeline sequence for restored transcript entries. */
760
+ sequence?: number;
721
761
  }
722
762
  interface LiveSessionConfig {
723
763
  apiBase: string;
@@ -735,11 +775,35 @@ interface LiveSessionResult {
735
775
  assistantText: string;
736
776
  /** Latest field id reported by the proxy via field_change. */
737
777
  activeFieldId: string | null;
778
+ /**
779
+ * The most recent field whose audio has finished PLAYING. The engine opens a
780
+ * field (and sends field_change) seconds before the spoken question ends, so
781
+ * renderers should gate field UI on this, not on activeFieldId.
782
+ */
783
+ askedFieldId: string | null;
784
+ /** True once the terminal socket has closed and all received PCM has played. */
785
+ playbackComplete: boolean;
738
786
  /** The committed value, set when the proxy emits a value envelope. */
739
787
  lastValue: unknown;
788
+ /** Latest durable checkpoint metadata; checkpoint contents remain server-only. */
789
+ checkpoint: {
790
+ sequence: number;
791
+ turn: number;
792
+ reconstructed: boolean;
793
+ } | null;
794
+ /** Server-owned completion progress; final output arrives through the run stream. */
795
+ completion: {
796
+ status: "finalizing" | "completed";
797
+ reason: string | null;
798
+ } | null;
799
+ /** Smoothed microphone energy in the range 0..1; visual feedback only. */
800
+ inputLevel: number;
740
801
  isMuted: boolean;
741
802
  toggleMute: () => void;
742
803
  error: string | null;
804
+ errorRecoverable: boolean;
805
+ retryError: () => void;
806
+ requestEnd: () => void;
743
807
  }
744
808
  declare function useGeminiLiveSession(cfg: LiveSessionConfig, onValue: (value: unknown) => void): LiveSessionResult;
745
809
 
@@ -835,6 +899,10 @@ interface ValidationError {
835
899
  }
836
900
  interface UseRunStreamResult {
837
901
  status: RunStatus;
902
+ /** Sanitized terminal classification used for participant-facing presentation. */
903
+ failureKind: "timeout" | null;
904
+ /** Current token, including a successful public-run re-mint. */
905
+ currentParticipantToken: string;
838
906
  activeSession: HITLSession | null;
839
907
  messages: ChatMessage[];
840
908
  timeline: TimelineEntry[];