teodor-new-chat-ui 4.0.6 → 4.0.7

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.
@@ -0,0 +1,2 @@
1
+ export { ApiProvider, useApi } from './providers/ApiProvider';
2
+ export type { ApiProviderProps } from './providers/ApiProvider';
@@ -1,68 +1,2 @@
1
- import React from "react";
2
- import { ChatMessage, ThreadSummary, CheckpointList, ApiConfig } from "@/types/api";
3
- import { ChatApi } from "@/lib/chat-api";
4
- export interface SendOptions {
5
- checkpointId?: string;
6
- checkpointNs?: string;
7
- nodeFilter?: string;
8
- config?: Record<string, unknown>;
9
- payloadExtras?: Record<string, unknown>;
10
- attachments?: File[];
11
- }
12
- export interface ChatContextValue {
13
- baseUrl: string;
14
- token: string | null;
15
- setToken: (t: string | null) => void;
16
- api: ChatApi;
17
- threads: ThreadSummary[];
18
- currentThreadId: string | null;
19
- setCurrentThreadId: (id: string | null) => void;
20
- isLoadingThreads: boolean;
21
- isLoadingThread: boolean;
22
- messages: ChatMessage[];
23
- isStreaming: boolean;
24
- error: string | null;
25
- lastCheckpointId: string | null;
26
- lastCheckpointNs: string | null;
27
- streamingAssistantId: string | null;
28
- hasMoreHistory: boolean;
29
- isLoadingHistory: boolean;
30
- loadOlderMessages: (opts?: {
31
- limit?: number;
32
- }) => Promise<void>;
33
- historyPageSize: number;
34
- listCheckpoints: (threadId: string) => Promise<CheckpointList>;
35
- navigateToCheckpoint: (checkpointId: string, checkpointNs?: string | null) => Promise<void>;
36
- returnToLatest: () => Promise<void>;
37
- refreshThreads: () => Promise<void>;
38
- createThread: (title?: string) => Promise<string>;
39
- deleteThread: (threadId: string) => Promise<void>;
40
- renameThread: (threadId: string, title: string) => Promise<void>;
41
- loadThread: (threadId: string, checkpointId?: string, checkpointNs?: string, force?: boolean) => Promise<void>;
42
- clearCurrentThread: () => Promise<void>;
43
- send: (text: string, opts?: SendOptions) => Promise<void>;
44
- stop: () => void;
45
- handleInterrupt: (interruptId: string, approved: boolean, value?: unknown) => Promise<void>;
46
- }
47
- export declare const ChatContext: React.Context<ChatContextValue>;
48
- export interface ChatProviderProps {
49
- children: React.ReactNode;
50
- apiConfig?: ApiConfig;
51
- onError?: (error: string) => void;
52
- onThreadChange?: (threadId: string | null) => void;
53
- initialThreadId?: string | null;
54
- /**
55
- * If true the provider will attempt to auto-load `initialThreadId` when mounted.
56
- * Set to false to defer initial loading to the host application.
57
- */
58
- autoLoadInitial?: boolean;
59
- /**
60
- * If true, prevents auto-loading from localStorage on mount.
61
- * Useful when you want full control over initial thread without localStorage interference.
62
- */
63
- disableAutoRestore?: boolean;
64
- enableFileAgentRouting?: boolean;
65
- fileAgentId?: string;
66
- }
67
- export declare function ChatProvider({ children, apiConfig, onError, onThreadChange, initialThreadId, autoLoadInitial, disableAutoRestore, enableFileAgentRouting, fileAgentId }: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
68
- export declare function useChat(): ChatContextValue;
1
+ export { ChatProvider, ChatContext, useChat, } from './providers/ChatProvider';
2
+ export type { ChatProviderProps, ChatContextValue, SendOptions, } from './providers/ChatProvider';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * ChatProviders - Root provider that composes all chat contexts
3
+ *
4
+ * Context hierarchy:
5
+ * ApiProvider (auth token & API client)
6
+ * └─ StreamProvider (streaming status)
7
+ * └─ ThreadProvider (thread list & current thread)
8
+ * └─ MessagesProvider (messages for current thread)
9
+ */
10
+ import { type ReactNode } from 'react';
11
+ import type { ApiConfig } from '@/types/api';
12
+ export interface ChatProvidersProps {
13
+ children: ReactNode;
14
+ apiConfig?: ApiConfig;
15
+ initialThreadId?: string | null;
16
+ autoLoadInitial?: boolean;
17
+ disableAutoRestore?: boolean;
18
+ enableFileAgentRouting?: boolean;
19
+ fileAgentId?: string;
20
+ onError?: (error: string) => void;
21
+ onThreadChange?: (threadId: string | null) => void;
22
+ }
23
+ export declare function ChatProviders({ children, apiConfig, initialThreadId, autoLoadInitial, disableAutoRestore, enableFileAgentRouting, fileAgentId, onError, onThreadChange, }: ChatProvidersProps): import("react/jsx-runtime").JSX.Element;
24
+ export { useApi } from './ApiProvider';
25
+ export { useStream } from './StreamProvider';
26
+ export { useThreads } from './ThreadProvider';
27
+ export { useMessages } from './MessagesProvider';
28
+ export type { ApiContextValue, StreamContextValue, ThreadContextValue, MessagesContextValue, SendOptions, } from './types';
@@ -0,0 +1,2 @@
1
+ export { MessagesProvider, useMessages } from './providers/MessagesProvider';
2
+ export type { MessagesProviderProps } from './providers/MessagesProvider';
@@ -0,0 +1,2 @@
1
+ export { StreamProvider, useStream, useStreamDispatch, } from './providers/StreamProvider';
2
+ export type { StreamAction } from './providers/StreamProvider';
@@ -0,0 +1,2 @@
1
+ export { ThreadProvider, useThreads, useThreadDispatch, ThreadProviderWithCallbacks, } from './providers/ThreadProvider';
2
+ export type { ThreadProviderProps } from './providers/ThreadProvider';
@@ -1,17 +1,8 @@
1
1
  import type { StreamEvent } from "@/types/api";
2
- import { type ReducerStreamEvent } from "./MessageReducer";
3
- import type { MutableRefObject } from "react";
2
+ import { type ReducerStreamEvent } from "../reducers/MessageReducer";
4
3
  export type ThreadInfoEvent = Extract<StreamEvent, {
5
4
  type: "thread_info";
6
5
  }>;
7
- interface ThreadInfoHandlerOptions {
8
- currentThreadId: string | null;
9
- messageCount: number;
10
- setCurrentThreadId: (id: string | null) => void;
11
- markThreadRefreshPending: () => void;
12
- skipNextLoadRef: MutableRefObject<string | null>;
13
- }
14
- export declare function useThreadInfoHandler({ currentThreadId, messageCount, setCurrentThreadId, markThreadRefreshPending, skipNextLoadRef, }: ThreadInfoHandlerOptions): (ev: ThreadInfoEvent) => void;
15
6
  interface CoordinatorOptions {
16
7
  onThreadInfo?: (ev: ThreadInfoEvent) => void;
17
8
  onMessageEvent: (ev: ReducerStreamEvent) => void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Context Module - Public API
3
+ *
4
+ * Organized structure:
5
+ * - providers/ - All React Context providers
6
+ * - reducers/ - State management logic
7
+ * - hooks/ - Shared hooks for event coordination
8
+ * - legacy/ - Deprecated code (to be removed)
9
+ */
10
+ export { ChatProviders } from './ChatProviders';
11
+ export { ApiProvider, useApi } from './providers/ApiProvider';
12
+ export { StreamProvider, useStream, useStreamDispatch } from './providers/StreamProvider';
13
+ export { ThreadProvider, useThreads, ThreadProviderWithCallbacks } from './providers/ThreadProvider';
14
+ export { MessagesProvider, useMessages } from './providers/MessagesProvider';
15
+ export { ChatProvider, useChat } from './providers/ChatProvider';
16
+ export type { ChatContextValue } from './providers/ChatProvider';
17
+ export { useMessagesReducer } from './reducers/MessageReducer';
18
+ export type { ReducerStreamEvent } from './reducers/MessageReducer';
19
+ export { useStreamEventCoordinator } from './hooks/useStreamEventCoordinator';
20
+ export type { ThreadInfoEvent } from './hooks/useStreamEventCoordinator';
21
+ export type { SendOptions, ApiContextValue, StreamContextValue, MessagesContextValue, ThreadContextValue, CoordinatorOptions, } from '@/types/api';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * ApiProvider - Lowest level context providing API client and auth token
3
+ */
4
+ import { type ReactNode } from 'react';
5
+ import type { ApiContextValue, ApiConfig } from '@/types/api';
6
+ export interface ApiProviderProps {
7
+ children: ReactNode;
8
+ apiConfig?: ApiConfig;
9
+ }
10
+ export declare function ApiProvider({ children, apiConfig }: ApiProviderProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function useApi(): ApiContextValue;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * ChatProvider - Compatibility layer that provides the original ChatProvider API
3
+ * using the new split context architecture underneath
4
+ *
5
+ * This allows existing code to continue working without changes while
6
+ * benefiting from the performance improvements of split contexts.
7
+ */
8
+ import React, { type ReactNode } from 'react';
9
+ import { useApi } from './ApiProvider';
10
+ import type { ApiConfig, ChatMessage, CheckpointList, ThreadSummary, SendOptions } from '@/types/api';
11
+ export interface ChatContextValue {
12
+ baseUrl: string;
13
+ token: string | null;
14
+ setToken: (t: string | null) => void;
15
+ api: ReturnType<typeof useApi>['api'];
16
+ threads: ThreadSummary[];
17
+ currentThreadId: string | null;
18
+ setCurrentThreadId: (id: string | null) => void;
19
+ isLoadingThreads: boolean;
20
+ isLoadingThread: boolean;
21
+ messages: ChatMessage[];
22
+ isStreaming: boolean;
23
+ error: string | null;
24
+ lastCheckpointId: string | null;
25
+ lastCheckpointNs: string | null;
26
+ streamingAssistantId: string | null;
27
+ hasMoreHistory: boolean;
28
+ isLoadingHistory: boolean;
29
+ loadOlderMessages: (opts?: {
30
+ limit?: number;
31
+ }) => Promise<void>;
32
+ historyPageSize: number;
33
+ listCheckpoints: (threadId: string) => Promise<CheckpointList>;
34
+ navigateToCheckpoint: (checkpointId: string, checkpointNs?: string | null) => Promise<void>;
35
+ returnToLatest: () => Promise<void>;
36
+ refreshThreads: () => Promise<void>;
37
+ createThread: (title?: string) => Promise<string>;
38
+ deleteThread: (threadId: string) => Promise<void>;
39
+ renameThread: (threadId: string, title: string) => Promise<void>;
40
+ loadThread: (threadId: string, checkpointId?: string, checkpointNs?: string, force?: boolean) => Promise<void>;
41
+ clearCurrentThread: () => Promise<void>;
42
+ send: (text: string, opts?: SendOptions) => Promise<void>;
43
+ stop: () => void;
44
+ handleInterrupt: (interruptId: string, approved: boolean, value?: unknown) => Promise<void>;
45
+ }
46
+ export declare const ChatContext: React.Context<ChatContextValue>;
47
+ export interface ChatProviderProps {
48
+ children: ReactNode;
49
+ apiConfig?: ApiConfig;
50
+ onError?: (error: string) => void;
51
+ onThreadChange?: (threadId: string | null) => void;
52
+ initialThreadId?: string | null;
53
+ autoLoadInitial?: boolean;
54
+ disableAutoRestore?: boolean;
55
+ enableFileAgentRouting?: boolean;
56
+ fileAgentId?: string;
57
+ }
58
+ export declare function ChatProvider(props: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
59
+ export declare function useChat(): ChatContextValue;
60
+ export type { SendOptions } from '@/types/api';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * MessagesProvider - Manages messages, streaming, and message operations
3
+ * Coordinates with ThreadProvider and StreamProvider
4
+ */
5
+ import { type ReactNode } from 'react';
6
+ import type { MessagesContextValue } from '@/types/api';
7
+ export interface MessagesProviderProps {
8
+ children: ReactNode;
9
+ enableFileAgentRouting?: boolean;
10
+ fileAgentId?: string;
11
+ }
12
+ export declare function MessagesProvider(props: MessagesProviderProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function useMessages(): MessagesContextValue;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * StreamProvider - Manages streaming state (isStreaming, error, checkpoints)
3
+ * This context is updated by events from the coordinator but doesn't own the stream itself
4
+ */
5
+ import React, { type ReactNode } from 'react';
6
+ import type { StreamContextValue } from '@/types/api';
7
+ export type StreamAction = {
8
+ type: 'STREAM_START';
9
+ assistantId?: string;
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>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * ThreadProvider - Manages thread list, current thread, and thread operations
3
+ */
4
+ import { type ReactNode } from 'react';
5
+ import type { ThreadContextValue, MessagesPayload } from '@/types/api';
6
+ export interface ThreadProviderProps {
7
+ children: ReactNode;
8
+ initialThreadId?: string | null;
9
+ autoLoadInitial?: boolean;
10
+ disableAutoRestore?: boolean;
11
+ onThreadChange?: (threadId: string | null) => void;
12
+ onError?: (error: string) => void;
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;
@@ -0,0 +1 @@
1
+ export type { ApiContextValue, StreamContextValue, MessagesContextValue, ThreadContextValue, SendOptions, StreamEvent, MessageAction, StreamAction, ThreadAction, CoordinatorOptions, } from '@/types/api';