teodor-new-chat-ui 4.0.27 → 4.0.28
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/context/ChatProviders.d.ts +2 -6
- package/dist/context/index.d.ts +3 -4
- package/dist/context/providers/ChatSessionProvider.d.ts +19 -0
- package/dist/context/providers/MessagesProvider.d.ts +8 -15
- package/dist/context/providers/StreamProvider.d.ts +8 -27
- package/dist/context/providers/ThreadProvider.d.ts +12 -21
- package/dist/context/services/useChatStreamingService.d.ts +40 -0
- package/dist/index.esm.js +6134 -6261
- package/dist/index.umd.js +53 -53
- package/package.json +1 -1
- package/dist/context/hooks/useStreamEventCoordinator.d.ts +0 -20
- package/dist/utils/env.d.ts +0 -2
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Context hierarchy:
|
|
5
5
|
* ApiProvider (auth token & API client)
|
|
6
|
-
* └─
|
|
7
|
-
* └─ ThreadProvider (thread list & current thread)
|
|
8
|
-
* └─ MessagesProvider (messages for current thread)
|
|
6
|
+
* └─ ChatSessionProvider (threads, messages, and streaming state)
|
|
9
7
|
*/
|
|
10
8
|
import { type ReactNode } from 'react';
|
|
11
9
|
import type { ApiConfig } from '@/types/api';
|
|
@@ -22,7 +20,5 @@ export interface ChatProvidersProps {
|
|
|
22
20
|
}
|
|
23
21
|
export declare function ChatProviders({ children, apiConfig, initialThreadId, autoLoadInitial, disableAutoRestore, enableFileAgentRouting, fileAgentId, onError, onThreadChange, }: ChatProvidersProps): import("react/jsx-runtime").JSX.Element;
|
|
24
22
|
export { useApi } from './providers/ApiProvider';
|
|
25
|
-
export { useStream } from './providers/
|
|
26
|
-
export { useThreads } from './providers/ThreadProvider';
|
|
27
|
-
export { useMessages } from './providers/MessagesProvider';
|
|
23
|
+
export { useStream, useThreads, useMessages } from './providers/ChatSessionProvider';
|
|
28
24
|
export type { ApiContextValue, StreamContextValue, ThreadContextValue, MessagesContextValue, SendOptions, } from './types';
|
package/dist/context/index.d.ts
CHANGED
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
* Organized structure:
|
|
5
5
|
* - providers/ - All React Context providers
|
|
6
6
|
* - reducers/ - State management logic
|
|
7
|
-
* -
|
|
7
|
+
* - services/ - Non-React utilities used by providers
|
|
8
8
|
* - legacy/ - Deprecated code (to be removed)
|
|
9
9
|
*/
|
|
10
10
|
export { ChatProviders } from './ChatProviders';
|
|
11
11
|
export { ApiProvider, useApi } from './providers/ApiProvider';
|
|
12
|
-
export { StreamProvider, useStream
|
|
12
|
+
export { StreamProvider, useStream } from './providers/StreamProvider';
|
|
13
13
|
export { ThreadProvider, useThreads, ThreadProviderWithCallbacks } from './providers/ThreadProvider';
|
|
14
14
|
export { MessagesProvider, useMessages } from './providers/MessagesProvider';
|
|
15
|
+
export { ChatSessionProvider, useHasChatSession } from './providers/ChatSessionProvider';
|
|
15
16
|
export { useMessagesReducer } from './reducers/MessageReducer';
|
|
16
17
|
export type { ReducerStreamEvent } from './reducers/MessageReducer';
|
|
17
|
-
export { useStreamEventCoordinator } from './hooks/useStreamEventCoordinator';
|
|
18
|
-
export type { ThreadInfoEvent } from './hooks/useStreamEventCoordinator';
|
|
19
18
|
export type { SendOptions, ApiContextValue, StreamContextValue, MessagesContextValue, ThreadContextValue, CoordinatorOptions, } from '@/types/api';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { MessagesContextValue, StreamContextValue, ThreadContextValue } from '@/types/api';
|
|
3
|
+
interface ChatSessionProviderPropsBase {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
initialThreadId?: string | null;
|
|
6
|
+
autoLoadInitial?: boolean;
|
|
7
|
+
disableAutoRestore?: boolean;
|
|
8
|
+
enableFileAgentRouting?: boolean;
|
|
9
|
+
fileAgentId?: string;
|
|
10
|
+
onError?: (error: string) => void;
|
|
11
|
+
onThreadChange?: (threadId: string | null) => void;
|
|
12
|
+
}
|
|
13
|
+
export type ChatSessionProviderProps = ChatSessionProviderPropsBase;
|
|
14
|
+
export declare function ChatSessionProvider({ children, initialThreadId, autoLoadInitial, disableAutoRestore, enableFileAgentRouting, fileAgentId, onError, onThreadChange, }: ChatSessionProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function useThreads(): ThreadContextValue;
|
|
16
|
+
export declare function useMessages(): MessagesContextValue;
|
|
17
|
+
export declare function useStream(): StreamContextValue;
|
|
18
|
+
export declare function useHasChatSession(): boolean;
|
|
19
|
+
export {};
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
+
import { useMessages, type ChatSessionProviderProps } from './ChatSessionProvider';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Coordinates with ThreadProvider and StreamProvider
|
|
3
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onRegisterThreadCallbacks?: (callbacks: {
|
|
12
|
-
onThreadLoaded: (threadId: string, payload: MessagesPayload) => void;
|
|
13
|
-
onThreadCleared: () => void;
|
|
14
|
-
}) => void;
|
|
15
|
-
}
|
|
16
|
-
export declare function MessagesProvider(props: MessagesProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
-
export declare function useMessages(): MessagesContextValue;
|
|
5
|
+
export type MessagesProviderProps = ChatSessionProviderProps;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export declare function MessagesProvider({ children, ...rest }: MessagesProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export { useMessages };
|
|
@@ -1,29 +1,10 @@
|
|
|
1
|
+
import { useStream, type ChatSessionProviderProps } from './ChatSessionProvider';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* This context is updated by events from the coordinator but doesn't own the stream itself
|
|
3
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type: 'STREAM_END';
|
|
12
|
-
} | {
|
|
13
|
-
type: 'STREAM_ERROR';
|
|
14
|
-
error: string;
|
|
15
|
-
} | {
|
|
16
|
-
type: 'UPDATE_CHECKPOINT';
|
|
17
|
-
checkpointId: string;
|
|
18
|
-
checkpointNs?: string | null;
|
|
19
|
-
} | {
|
|
20
|
-
type: 'UPDATE_ASSEMBLING_ID';
|
|
21
|
-
assistantId: string | null;
|
|
22
|
-
} | {
|
|
23
|
-
type: 'CLEAR_ERROR';
|
|
24
|
-
};
|
|
25
|
-
export declare function StreamProvider({ children }: {
|
|
26
|
-
children: ReactNode;
|
|
27
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
28
|
-
export declare function useStream(): StreamContextValue;
|
|
29
|
-
export declare function useStreamDispatch(): React.Dispatch<StreamAction>;
|
|
5
|
+
export type StreamProviderProps = ChatSessionProviderProps;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export declare function StreamProvider({ children, ...rest }: StreamProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export { useStream };
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
+
import { useThreads, type ChatSessionProviderProps } from './ChatSessionProvider';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
export declare function ThreadProvider({ children, initialThreadId, autoLoadInitial, disableAutoRestore, onThreadChange, onError, }: ThreadProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
export declare function useThreads(): ThreadContextValue;
|
|
16
|
-
export declare function useThreadDispatch(): {
|
|
17
|
-
onThreadLoaded: (threadId: string, payload: MessagesPayload) => void;
|
|
18
|
-
onThreadCleared: () => void;
|
|
19
|
-
};
|
|
20
|
-
export declare function ThreadProviderWithCallbacks({ children, onThreadLoaded, onThreadCleared, ...props }: ThreadProviderProps & {
|
|
21
|
-
onThreadLoaded: (threadId: string, payload: MessagesPayload) => void;
|
|
22
|
-
onThreadCleared: () => void;
|
|
23
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export type ThreadProviderProps = ChatSessionProviderProps;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ThreadProvider({ children, ...rest }: ThreadProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use ChatSessionProvider directly. This wrapper exists for backward compatibility.
|
|
12
|
+
*/
|
|
13
|
+
export declare const ThreadProviderWithCallbacks: typeof ThreadProvider;
|
|
14
|
+
export { useThreads };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ReducerStreamEvent } from '../reducers/MessageReducer';
|
|
2
|
+
import type { ChatRequest, StreamEvent } from '@/types/api';
|
|
3
|
+
export type ThreadInfoEvent = Extract<StreamEvent, {
|
|
4
|
+
type: 'thread_info';
|
|
5
|
+
}>;
|
|
6
|
+
interface UseChatStreamingServiceOptions {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
onThreadInfo: (event: ThreadInfoEvent) => void;
|
|
9
|
+
onMessageEvent: (event: ReducerStreamEvent) => void;
|
|
10
|
+
onUnhandledEvent?: (event: StreamEvent) => void;
|
|
11
|
+
onSequenceGap?: (gap: {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
interface StartStreamCallbacks {
|
|
17
|
+
onOpen?: (info: {
|
|
18
|
+
threadId: string | null;
|
|
19
|
+
created: boolean;
|
|
20
|
+
}) => void;
|
|
21
|
+
onError?: (error: unknown) => void;
|
|
22
|
+
onGap?: (gap: {
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Thin integration layer that adapts the public `useChatStream` hook to the
|
|
29
|
+
* coordination callbacks expected by `ChatSessionProvider`. Keeping this logic
|
|
30
|
+
* here means we continue to rely on the well-tested streaming hook for all SSE
|
|
31
|
+
* behaviour while the provider focuses purely on state updates.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useChatStreamingService({ baseUrl, onThreadInfo, onMessageEvent, onUnhandledEvent, onSequenceGap, }: UseChatStreamingServiceOptions): {
|
|
34
|
+
startStream: (request: ChatRequest, callbacks?: StartStreamCallbacks) => void;
|
|
35
|
+
stop: () => void;
|
|
36
|
+
isStreaming: boolean;
|
|
37
|
+
error: string;
|
|
38
|
+
setAuthToken: (t: string | null) => void;
|
|
39
|
+
};
|
|
40
|
+
export {};
|