teodor-new-chat-ui 4.0.27 → 4.1.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/context/ChatProviders.d.ts +2 -6
- package/dist/context/index.d.ts +2 -6
- package/dist/context/providers/ChatSessionProvider.d.ts +19 -0
- package/dist/context/services/useChatStreamingService.d.ts +40 -0
- package/dist/index.esm.js +6143 -6249
- package/dist/index.umd.js +53 -53
- package/package.json +1 -1
- package/dist/context/hooks/useStreamEventCoordinator.d.ts +0 -20
- package/dist/context/providers/MessagesProvider.d.ts +0 -17
- package/dist/context/providers/StreamProvider.d.ts +0 -29
- package/dist/context/providers/ThreadProvider.d.ts +0 -23
- 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,12 @@
|
|
|
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 {
|
|
13
|
-
export { ThreadProvider, useThreads, ThreadProviderWithCallbacks } from './providers/ThreadProvider';
|
|
14
|
-
export { MessagesProvider, useMessages } from './providers/MessagesProvider';
|
|
12
|
+
export { ChatSessionProvider, useHasChatSession, useMessages, useStream, useThreads } from './providers/ChatSessionProvider';
|
|
15
13
|
export { useMessagesReducer } from './reducers/MessageReducer';
|
|
16
14
|
export type { ReducerStreamEvent } from './reducers/MessageReducer';
|
|
17
|
-
export { useStreamEventCoordinator } from './hooks/useStreamEventCoordinator';
|
|
18
|
-
export type { ThreadInfoEvent } from './hooks/useStreamEventCoordinator';
|
|
19
15
|
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 {};
|
|
@@ -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 {};
|