teodor-new-chat-ui 4.3.92 → 4.3.94

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.
@@ -1,8 +1,21 @@
1
- import type { ChatRequest, StreamEvent } from '@/types/api';
1
+ import type { ChatRequest, HistoryPayload, StreamEvent } from '@/types/api';
2
2
  import { type ReducerStreamEvent } from '../reducers/MessageReducer';
3
3
  export type ThreadInfoEvent = Extract<StreamEvent, {
4
4
  type: 'thread_info';
5
5
  }>;
6
+ type HeartbeatEvent = Extract<StreamEvent, {
7
+ type: 'heartbeat';
8
+ }>;
9
+ export interface StreamClosedInfo {
10
+ reason: 'complete' | 'aborted' | 'error';
11
+ lastSeq: number;
12
+ lastCheckpointId: string | null;
13
+ lastCheckpointNs: string | null;
14
+ lastStateHistory: HistoryPayload | null;
15
+ threadId: string | null;
16
+ manualStop: boolean;
17
+ error?: string | null;
18
+ }
6
19
  interface UseChatStreamingServiceOptions {
7
20
  baseUrl: string;
8
21
  onThreadInfo: (event: ThreadInfoEvent) => void;
@@ -12,6 +25,9 @@ interface UseChatStreamingServiceOptions {
12
25
  from: number;
13
26
  to: number;
14
27
  }) => void;
28
+ onStreamClosed?: (info: StreamClosedInfo) => void;
29
+ onConnectionError?: (error: string) => void;
30
+ onHeartbeat?: (event: HeartbeatEvent) => void;
15
31
  }
16
32
  interface StartStreamCallbacks {
17
33
  onOpen?: (info: {
@@ -23,6 +39,9 @@ interface StartStreamCallbacks {
23
39
  from: number;
24
40
  to: number;
25
41
  }) => void;
42
+ onClosed?: (info: StreamClosedInfo) => void;
43
+ onConnectionError?: (error: string) => void;
44
+ onHeartbeat?: (event: HeartbeatEvent) => void;
26
45
  }
27
46
  /**
28
47
  * Thin integration layer that adapts the public `useChatStream` hook to the
@@ -30,11 +49,12 @@ interface StartStreamCallbacks {
30
49
  * here means we continue to rely on the well-tested streaming hook for all SSE
31
50
  * behaviour while the provider focuses purely on state updates.
32
51
  */
33
- export declare function useChatStreamingService({ baseUrl, onThreadInfo, onMessageEvent, onUnhandledEvent, onSequenceGap, }: UseChatStreamingServiceOptions): {
52
+ export declare function useChatStreamingService({ baseUrl, onThreadInfo, onMessageEvent, onUnhandledEvent, onSequenceGap, onStreamClosed, onConnectionError, onHeartbeat, }: UseChatStreamingServiceOptions): {
34
53
  startStream: (request: ChatRequest, callbacks?: StartStreamCallbacks) => void;
35
54
  stop: () => void;
36
55
  isStreaming: boolean;
37
56
  error: string;
38
57
  setAuthToken: (t: string | null) => void;
58
+ replayBufferedEvents: (threadId?: string | null) => void;
39
59
  };
40
60
  export {};
@@ -1,4 +1,4 @@
1
- import { ChatRequest, StreamEvent } from "@/types/api";
1
+ import { ChatRequest, HistoryPayload, StreamEvent } from "@/types/api";
2
2
  export type UseChatStreamOptions = {
3
3
  baseUrl?: string;
4
4
  streamPath?: string;
@@ -24,6 +24,18 @@ export type UseChatStream = {
24
24
  from: number;
25
25
  to: number;
26
26
  }) => void;
27
+ onClosed?: (info: {
28
+ reason: "complete" | "aborted" | "error";
29
+ lastSeq: number;
30
+ lastCheckpointId: string | null;
31
+ lastCheckpointNs: string | null;
32
+ lastStateHistory: HistoryPayload | null;
33
+ error?: string | null;
34
+ }) => void;
35
+ onConnectionError?: (message: string) => void;
36
+ onHeartbeat?: (event: Extract<StreamEvent, {
37
+ type: "heartbeat";
38
+ }>) => void;
27
39
  }) => {
28
40
  close: () => void;
29
41
  };