@teodorruskvi/chat-core 0.1.2

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.
Files changed (102) hide show
  1. package/dist/features/conversation/contexts/ChatUIContext.d.ts +41 -0
  2. package/dist/features/conversation/contexts/ThreadStateProvider.d.ts +24 -0
  3. package/dist/features/conversation/contexts/ThreadsProvider.d.ts +10 -0
  4. package/dist/features/conversation/contexts/index.d.ts +3 -0
  5. package/dist/features/conversation/contexts/reducers/MessageReducer.d.ts +22 -0
  6. package/dist/features/conversation/contexts/reducers/utils/reducerUtils.d.ts +21 -0
  7. package/dist/features/conversation/hooks/index.d.ts +7 -0
  8. package/dist/features/conversation/hooks/useChatController.d.ts +50 -0
  9. package/dist/features/conversation/hooks/useChatSession.d.ts +49 -0
  10. package/dist/features/conversation/hooks/useFilePreview.d.ts +15 -0
  11. package/dist/features/conversation/hooks/useParsedMessageContent.d.ts +12 -0
  12. package/dist/features/conversation/hooks/useThreadHistoryState.d.ts +44 -0
  13. package/dist/features/conversation/hooks/useThreadsState.d.ts +40 -0
  14. package/dist/features/conversation/messages/components/MessageBubble.d.ts +25 -0
  15. package/dist/features/conversation/messages/hooks/index.d.ts +2 -0
  16. package/dist/features/conversation/messages/hooks/useMessageContent.d.ts +13 -0
  17. package/dist/features/conversation/messages/hooks/useStreamingMarkdownBuffer.d.ts +3 -0
  18. package/dist/features/conversation/messages/hooks/useToolPayload.d.ts +15 -0
  19. package/dist/features/conversation/messages/renderers/tooling/ToolContent.d.ts +27 -0
  20. package/dist/features/conversation/messages/renderers/tooling/artifacts/ArtifactProgress.d.ts +13 -0
  21. package/dist/features/conversation/messages/utils/artifactUtils.d.ts +51 -0
  22. package/dist/features/conversation/messages/utils/index.d.ts +6 -0
  23. package/dist/features/conversation/messages/utils/messageUtils.d.ts +32 -0
  24. package/dist/features/persistence/checkpoints/hooks/index.d.ts +1 -0
  25. package/dist/features/persistence/checkpoints/hooks/useCheckpointIndex.d.ts +2 -0
  26. package/dist/features/persistence/checkpoints/types/index.d.ts +33 -0
  27. package/dist/features/persistence/checkpoints/utils/checkpointIndex.d.ts +18 -0
  28. package/dist/features/persistence/checkpoints/utils/editUtils.d.ts +11 -0
  29. package/dist/features/persistence/checkpoints/utils/historyUtils.d.ts +8 -0
  30. package/dist/features/persistence/checkpoints/utils/messagePreviews.d.ts +8 -0
  31. package/dist/features/persistence/checkpoints/utils/schemaUtils.d.ts +6 -0
  32. package/dist/features/streaming/contexts/StreamingProvider.d.ts +19 -0
  33. package/dist/features/streaming/contexts/index.d.ts +1 -0
  34. package/dist/features/streaming/contexts/types.d.ts +76 -0
  35. package/dist/features/streaming/hooks/types.d.ts +50 -0
  36. package/dist/features/streaming/hooks/use-stream.d.ts +2 -0
  37. package/dist/features/streaming/index.d.ts +5 -0
  38. package/dist/features/streaming/utils/index.d.ts +1 -0
  39. package/dist/features/streaming/utils/toolHandlers.d.ts +14 -0
  40. package/dist/features/thread/contexts/index.d.ts +1 -0
  41. package/dist/features/thread/contexts/reducers/MessageReducer.d.ts +1 -0
  42. package/dist/features/thread/hooks/useThreadHistoryState.d.ts +1 -0
  43. package/dist/features/thread/hooks/useThreadsState.d.ts +1 -0
  44. package/dist/index.esm.js +5344 -0
  45. package/dist/index.esm.js.map +1 -0
  46. package/dist/index.umd.js +9 -0
  47. package/dist/index.umd.js.map +1 -0
  48. package/dist/lib/core.d.ts +26 -0
  49. package/dist/lib/utils.d.ts +2 -0
  50. package/dist/shared/core/api/clients/authClient.d.ts +13 -0
  51. package/dist/shared/core/api/clients/chatClient.d.ts +50 -0
  52. package/dist/shared/core/api/clients/fileClient.d.ts +12 -0
  53. package/dist/shared/core/api/clients/index.d.ts +2 -0
  54. package/dist/shared/core/api/index.d.ts +2 -0
  55. package/dist/shared/core/api/utils/http.d.ts +20 -0
  56. package/dist/shared/core/api/utils/index.d.ts +1 -0
  57. package/dist/shared/core/constants/env.d.ts +39 -0
  58. package/dist/shared/core/constants/index.d.ts +2 -0
  59. package/dist/shared/core/constants/storage.d.ts +14 -0
  60. package/dist/shared/core/contexts/index.d.ts +4 -0
  61. package/dist/shared/core/contexts/providers/ApiProvider.d.ts +11 -0
  62. package/dist/shared/core/contexts/providers/ChatProviders.d.ts +25 -0
  63. package/dist/shared/core/contexts/providers/index.d.ts +2 -0
  64. package/dist/shared/core/hooks/index.d.ts +2 -0
  65. package/dist/shared/core/hooks/useApi.d.ts +1 -0
  66. package/dist/shared/core/hooks/useShallowStableValue.d.ts +1 -0
  67. package/dist/shared/core/index.d.ts +6 -0
  68. package/dist/shared/core/types/index.d.ts +1 -0
  69. package/dist/shared/core/utils/caseUtils.d.ts +1 -0
  70. package/dist/shared/core/utils/chatUtils.d.ts +10 -0
  71. package/dist/shared/core/utils/guards.d.ts +8 -0
  72. package/dist/shared/core/utils/index.d.ts +8 -0
  73. package/dist/shared/core/utils/messageFactory.d.ts +14 -0
  74. package/dist/shared/core/utils/metaUtils.d.ts +22 -0
  75. package/dist/shared/core/utils/normalizationUtils.d.ts +20 -0
  76. package/dist/shared/core/utils/parsers.d.ts +22 -0
  77. package/dist/shared/core/utils/toolCallUtils.d.ts +14 -0
  78. package/dist/shared/core/utils/toolFormatting.d.ts +8 -0
  79. package/dist/shared/ui/components/toast.d.ts +15 -0
  80. package/dist/shared/ui/hooks/use-toast.d.ts +44 -0
  81. package/dist/shared/ui/utils/cn.d.ts +2 -0
  82. package/dist/shared/ui/utils/index.d.ts +1 -0
  83. package/dist/shared/utils/jsonUtils.d.ts +18 -0
  84. package/dist/types/api/auth.d.ts +15 -0
  85. package/dist/types/api/common.d.ts +9 -0
  86. package/dist/types/api/files.d.ts +7 -0
  87. package/dist/types/api/runs.d.ts +104 -0
  88. package/dist/types/api.d.ts +7 -0
  89. package/dist/types/core/context.d.ts +5 -0
  90. package/dist/types/core/models.d.ts +6 -0
  91. package/dist/types/core.d.ts +97 -0
  92. package/dist/types/domain/artifacts.d.ts +94 -0
  93. package/dist/types/domain/chat.d.ts +80 -0
  94. package/dist/types/domain/index.d.ts +10 -0
  95. package/dist/types/domain/messages.d.ts +54 -0
  96. package/dist/types/domain/persistence.d.ts +67 -0
  97. package/dist/types/domain/primitives.d.ts +39 -0
  98. package/dist/types/domain/streaming.d.ts +231 -0
  99. package/dist/types/domain/tools.d.ts +66 -0
  100. package/dist/types/index.d.ts +13 -0
  101. package/dist/types/shared/common.d.ts +19 -0
  102. package/package.json +42 -0
@@ -0,0 +1,41 @@
1
+ import React from "react";
2
+ import type { ChatMessage, RespondToInterruptOptions, ToolConfig, PendingInterrupt } from "@/types";
3
+ import type { MessageBubbleProps } from "../messages/components/MessageBubble";
4
+ import type { EditMeta } from "@/features/persistence/checkpoints/types";
5
+ import type { CheckpointIndex } from "@/features/persistence/checkpoints/utils/checkpointIndex";
6
+ import type { ToolCallWithResult } from "@/types";
7
+ export interface ChatUIContextValue {
8
+ layoutSize: "phone" | "tablet" | "desktop" | "half-screen";
9
+ customStyles: {
10
+ container?: string;
11
+ messagesArea?: string;
12
+ inputArea?: string;
13
+ sendButton?: string;
14
+ textarea?: string;
15
+ moreButton?: string;
16
+ };
17
+ messageCustomStyles?: (message: ChatMessage) => MessageBubbleProps["customStyles"] | undefined;
18
+ renderArtifactsInline: boolean;
19
+ showThinkingIndicator: boolean;
20
+ enableMessageEditing: boolean;
21
+ editingMessageId: string | null;
22
+ showToolMessages: boolean;
23
+ followNewMessages: boolean;
24
+ streamingDebounceMs: number;
25
+ toolConfig?: ToolConfig;
26
+ selectedToolCall?: ToolCallWithResult | null;
27
+ onSelectToolCall?: (toolCall: ToolCallWithResult | null) => void;
28
+ checkpointIndex?: CheckpointIndex;
29
+ activeCheckpointId?: string | null;
30
+ onSelectCheckpoint?: (checkpointId: string | null, parentCheckpointId?: string | null, isLatest?: boolean) => Promise<void> | void;
31
+ pendingInterrupt: PendingInterrupt | null;
32
+ onEdit: (messageId: string, content: string, meta?: EditMeta) => void;
33
+ onRegenerate: (messageIndex: number) => void;
34
+ onCancelEdit: () => void;
35
+ getInterruptOptions?: (message: ChatMessage) => RespondToInterruptOptions | undefined;
36
+ }
37
+ export interface ChatUIProviderProps extends ChatUIContextValue {
38
+ children: React.ReactNode;
39
+ }
40
+ export declare function ChatUIProvider({ children, ...value }: ChatUIProviderProps): import("react/jsx-runtime").JSX.Element;
41
+ export declare function useChatUI(): ChatUIContextValue;
@@ -0,0 +1,24 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { ThreadStateContextValue } from '@/features/streaming/contexts/types';
3
+ interface ThreadStateProviderProps {
4
+ children: ReactNode;
5
+ initialThreadId?: string | null;
6
+ initialCheckpointId?: string | null;
7
+ initialCheckpointNs?: string | null;
8
+ autoLoadInitial?: boolean;
9
+ isStreaming: boolean;
10
+ onError?: (error: string) => void;
11
+ }
12
+ interface ThreadStateUpdater {
13
+ registerClearThread: (fn: ThreadStateContextValue['clearThread']) => void;
14
+ registerRespondToInterrupt: (fn: ThreadStateContextValue['respondToInterrupt']) => void;
15
+ }
16
+ export declare function useThreadState(options: {
17
+ optional: true;
18
+ }): ThreadStateContextValue | null;
19
+ export declare function useThreadState(options?: {
20
+ optional?: false;
21
+ }): ThreadStateContextValue;
22
+ export declare function useThreadStateUpdater(): ThreadStateUpdater;
23
+ export declare function ThreadStateProvider({ children, initialThreadId, initialCheckpointId, initialCheckpointNs, autoLoadInitial, isStreaming, onError, }: ThreadStateProviderProps): import("react/jsx-runtime").JSX.Element;
24
+ export {};
@@ -0,0 +1,10 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { ThreadsContextValue } from '@/features/streaming/contexts/types';
3
+ export interface ThreadsProviderProps {
4
+ children: ReactNode;
5
+ initialThreadId?: string | null;
6
+ onError?: (error: string) => void;
7
+ onThreadChange?: (threadId: string | null) => void;
8
+ }
9
+ export declare function ThreadsProvider({ children, initialThreadId, onError, onThreadChange, }: ThreadsProviderProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function useThreads(): ThreadsContextValue;
@@ -0,0 +1,3 @@
1
+ export { ThreadsProvider, useThreads } from './ThreadsProvider';
2
+ export { ThreadStateProvider, useThreadState, useThreadStateUpdater } from './ThreadStateProvider';
3
+ export * from './ChatUIContext';
@@ -0,0 +1,22 @@
1
+ import type { ChatMessage } from "@/types";
2
+ import type { StreamEvent } from "@/types/domain/streaming";
3
+ import type { MessagesState, MessagesAction } from "@/types/domain/messages";
4
+ export declare const initialMessagesState: MessagesState;
5
+ export declare function messagesReducer(state: MessagesState, action: MessagesAction): MessagesState;
6
+ export declare function useMessagesReducer(initial?: ChatMessage[]): {
7
+ readonly reset: (messages?: ChatMessage[]) => void;
8
+ readonly seed: (messages: ChatMessage[], opts?: {
9
+ checkpointId?: string | null;
10
+ checkpointNs?: string | null;
11
+ pendingInterrupt?: {
12
+ id: string;
13
+ value: any;
14
+ } | null;
15
+ values?: Record<string, any>;
16
+ }) => void;
17
+ readonly prepend: (messages: ChatMessage[]) => void;
18
+ readonly pushUser: (message: ChatMessage, editingMessageId?: string | null) => void;
19
+ readonly onEvent: (ev: StreamEvent) => void;
20
+ readonly state: MessagesState;
21
+ readonly dispatch: import("react").Dispatch<MessagesAction>;
22
+ };
@@ -0,0 +1,21 @@
1
+ import type { ChatMessage, MessagePart } from "@/types";
2
+ export declare function sanitizeHistory(messages: ChatMessage[]): ChatMessage[];
3
+ export declare function findMessageById(messages: ChatMessage[], id: string): ChatMessage | null;
4
+ export declare function insertOrReplaceMessage(messages: ChatMessage[], message: ChatMessage): ChatMessage[];
5
+ export declare function replaceMessageAtIndex(messages: ChatMessage[], index: number, message: ChatMessage): ChatMessage[];
6
+ export declare function findLastAssistantId(messages: ChatMessage[]): string | null;
7
+ export declare function getFullTextFromParts(parts: MessagePart[]): string;
8
+ export declare function mergePartsWithMeta(baseParts: MessagePart[], deltaParts: MessagePart[], metaIn: {
9
+ lastSeq?: number | null;
10
+ lastText?: string;
11
+ }, seq: number | null): {
12
+ newParts: MessagePart[];
13
+ newMeta: {
14
+ lastSeq?: number | null;
15
+ lastText?: string;
16
+ };
17
+ changed: boolean;
18
+ };
19
+ export declare function computeSuffix(existing: string, incoming: string): string;
20
+ export declare function stampLastAssistantCheckpoint(messages: ChatMessage[], checkpointId: string, checkpointNs?: string | null): ChatMessage[];
21
+ export declare function nameFromModel(model?: string): string | null;
@@ -0,0 +1,7 @@
1
+ export { useFilePreview } from "./useFilePreview";
2
+ export { useParsedMessageContent } from "./useParsedMessageContent";
3
+ export { useToolPayload, type ToolPayloadResult, } from "../messages/hooks/useToolPayload";
4
+ export { useChatController } from "./useChatController";
5
+ export { useChatSession } from "./useChatSession";
6
+ export { useThreadsState } from "./useThreadsState";
7
+ export { useThreadHistoryState } from "./useThreadHistoryState";
@@ -0,0 +1,50 @@
1
+ import { type ChatRequest, type ProjectInfo, type ChatMessage, type StreamSubmitPayload, type StreamCallbacks, type MessagePart, type StreamEvent } from "@/types";
2
+ export type EditContextMeta = {
3
+ checkpointId?: string | null;
4
+ checkpointNs?: string | null;
5
+ };
6
+ /**
7
+ * Options for sending a message via handleSendMessage.
8
+ */
9
+ export interface SendMessageOptions {
10
+ /** Files to upload (will be converted to contentParts after upload) */
11
+ files?: File[];
12
+ /** Pre-built content parts (e.g., already-uploaded documents with URLs) */
13
+ contentParts?: MessagePart[];
14
+ }
15
+ export interface UseChatControllerProps {
16
+ submit: (payload: StreamSubmitPayload, callbacks?: StreamCallbacks) => Promise<void>;
17
+ chatRequest: ChatRequest;
18
+ lastCheckpointId: string | null;
19
+ lastCheckpointNs: string | null;
20
+ onMessageSent?: (message: string) => void;
21
+ onExcelUploadSuccess?: (payload: {
22
+ file: File;
23
+ }) => void;
24
+ onError?: (error: string) => void;
25
+ enableMessageEditing?: boolean;
26
+ messages: ChatMessage[];
27
+ setPendingAssistantResponse: (pending: boolean) => void;
28
+ project?: ProjectInfo | null;
29
+ /** Optional callback for stream events */
30
+ onEvent?: (event: StreamEvent) => void;
31
+ /** The active thread ID for draft isolation */
32
+ threadId?: string | null;
33
+ }
34
+ export declare function useChatController({ submit, chatRequest, lastCheckpointId, lastCheckpointNs, onMessageSent, onExcelUploadSuccess, onError, enableMessageEditing, messages, setPendingAssistantResponse, project, onEvent, threadId, }: UseChatControllerProps): {
35
+ editingMessageId: string | null;
36
+ editingInitialValue: string;
37
+ inputError: string | null;
38
+ setInputError: import("react").Dispatch<import("react").SetStateAction<string | null>>;
39
+ dismissError: boolean;
40
+ setDismissError: import("react").Dispatch<import("react").SetStateAction<boolean>>;
41
+ composerValue: string;
42
+ handleComposerChange: (text: string) => void;
43
+ handleSendMessage: (text: string, optionsOrFiles?: SendMessageOptions | File[]) => Promise<void>;
44
+ handleQuickPrompt: (prompt: string, isComposerDisabled: boolean) => void;
45
+ handleExcelUpload: (file: File) => Promise<void>;
46
+ startEditing: (messageId: string, content: string, meta?: EditContextMeta) => void;
47
+ cancelEditing: () => void;
48
+ handleRegenerateCb: (messageIndex: number) => void;
49
+ displayMessages: any[];
50
+ };
@@ -0,0 +1,49 @@
1
+ type UseChatSessionOptions = string | {
2
+ threadId?: string;
3
+ } | undefined;
4
+ export declare function useChatSession(options?: UseChatSessionOptions): {
5
+ threadId: string | null;
6
+ messages: any[];
7
+ isLoading: boolean;
8
+ isHistoryLoading: boolean;
9
+ error: string | null;
10
+ values: Record<string, unknown>;
11
+ metadata: {
12
+ assemblingMessageId: string | null;
13
+ } | undefined;
14
+ navigateToCheckpoint: (checkpointId: string, checkpointNs?: string | null) => Promise<void>;
15
+ returnToLatest: () => Promise<void>;
16
+ checkpoint: {
17
+ id: string | null;
18
+ namespace: string | null;
19
+ } | null;
20
+ checkpoints: import("../../../types").HydratedCheckpointSnapshot[];
21
+ checkpointIndex: import("../../persistence/checkpoints/utils/checkpointIndex").CheckpointIndex | {
22
+ timeline: never[];
23
+ messagePreviews: {};
24
+ };
25
+ interrupt: {
26
+ id: string;
27
+ value: unknown;
28
+ alternatives?: import("../../../types").InterruptAlternative[];
29
+ } | null;
30
+ respondToInterrupt: (approved: boolean, value?: unknown, options?: any) => Promise<void>;
31
+ isStreaming: boolean;
32
+ activeMessageId: string | null;
33
+ connectionState: string;
34
+ streamingAssistantId: string | null;
35
+ submit: (input: import("../../../types").StreamSubmitPayload, callbacks?: import("../../../types").StreamCallbacks) => Promise<void>;
36
+ stop: () => void;
37
+ clearThread: () => Promise<void> | void;
38
+ setCurrentThreadId: (id: string | null) => void;
39
+ createThread: (title?: string, project?: ({
40
+ id: string;
41
+ name?: string;
42
+ } | import("../../../types").ProjectInfo | null)) => Promise<string | null>;
43
+ deleteThread: (threadId: string) => Promise<void>;
44
+ renameThread: (threadId: string, title: string) => Promise<void>;
45
+ shareThread: (threadId: string, sharedWithUserId: string) => Promise<void>;
46
+ threads: import("../../../types").ThreadSummary[];
47
+ isThreadsLoading: boolean;
48
+ };
49
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { MouseEvent as ReactMouseEvent } from "react";
2
+ export declare function useFilePreview(options: {
3
+ allowFileOpen: boolean;
4
+ currentThreadId?: string | null;
5
+ }): {
6
+ uploadingFiles: Record<number, boolean>;
7
+ handleFileClick: (e: ReactMouseEvent<HTMLAnchorElement>, fp: any, idx: number) => Promise<void>;
8
+ fileViewerOpen: boolean;
9
+ currentFileInfo: {
10
+ id: string;
11
+ name: string;
12
+ mimeType: string;
13
+ } | null;
14
+ closeFileViewer: () => void;
15
+ };
@@ -0,0 +1,12 @@
1
+ import type { ChatMessage, MessagePart } from "@/types";
2
+ import type { ToolMeta } from "@/types";
3
+ export interface ParsedMessageContent {
4
+ contentParts: MessagePart[];
5
+ textContent: string;
6
+ toolMeta: ToolMeta;
7
+ imageParts: MessagePart[];
8
+ fileParts: MessagePart[];
9
+ toolRaw: string;
10
+ isToolStreaming: boolean;
11
+ }
12
+ export declare function useParsedMessageContent(message: ChatMessage): ParsedMessageContent;
@@ -0,0 +1,44 @@
1
+ import type { ChatApi } from "@/shared/core";
2
+ import type { StateHistoryEvent } from "@/features/streaming";
3
+ import type { ChatMessage, HydratedCheckpointSnapshot } from "@/types";
4
+ import type { TimelineCheckpoint } from "@/features/persistence/checkpoints/types";
5
+ import type { PendingInterrupt } from "@/types";
6
+ import type { CheckpointIndex } from "@/features/persistence/checkpoints/utils/checkpointIndex";
7
+ interface UseThreadHistoryStateOptions {
8
+ api: ChatApi;
9
+ seed: (messages: ChatMessage[], opts?: {
10
+ checkpointId?: string | null;
11
+ checkpointNs?: string | null;
12
+ pendingInterrupt?: PendingInterrupt;
13
+ values?: Record<string, unknown>;
14
+ }) => void;
15
+ onError?: (msg: string) => void;
16
+ currentThreadId: string | null;
17
+ initialThreadId?: string | null;
18
+ initialCheckpointId?: string | null;
19
+ initialCheckpointNs?: string | null;
20
+ autoLoadInitial?: boolean;
21
+ isStreaming: boolean;
22
+ getMessages: () => ChatMessage[];
23
+ }
24
+ interface ThreadHistoryResult {
25
+ threadCheckpoints: HydratedCheckpointSnapshot[];
26
+ threadTimeline: TimelineCheckpoint[];
27
+ checkpointIndex: CheckpointIndex;
28
+ isLoadingThread: boolean;
29
+ isLoadingCheckpoint: boolean;
30
+ threadStateError: string | null;
31
+ loadThread: (threadId: string, checkpointId?: string | null, options?: {
32
+ clearProgress?: boolean;
33
+ }) => Promise<void>;
34
+ navigateToCheckpoint: (checkpointId: string, checkpointNs?: string | null) => Promise<void>;
35
+ setCurrentCheckpointId: (checkpointId: string | null, checkpointNs?: string | null) => void;
36
+ returnToLatest: () => Promise<void>;
37
+ handleStateHistoryEvent: (event: StateHistoryEvent) => void;
38
+ markSkipNextLoad: (threadId: string | null) => void;
39
+ markStreamPendingThread: (threadId: string | null) => void;
40
+ resetHistoryState: () => void;
41
+ clearState: () => void;
42
+ }
43
+ export declare function useThreadHistoryState({ api, seed, onError, currentThreadId, initialThreadId, initialCheckpointId, initialCheckpointNs, autoLoadInitial, isStreaming, getMessages, }: UseThreadHistoryStateOptions): ThreadHistoryResult;
44
+ export {};
@@ -0,0 +1,40 @@
1
+ import { type MutableRefObject } from 'react';
2
+ import type { ChatApi } from "@/shared/core";
3
+ import type { ThreadInfoEvent } from '@/features/streaming';
4
+ import type { ProjectInfo, SharedThreadSummary, ThreadSummary } from '@/types';
5
+ interface ThreadActions {
6
+ createThread: (title?: string, project?: {
7
+ id: string;
8
+ name?: string;
9
+ } | ProjectInfo | null) => Promise<string | null>;
10
+ deleteThread: (threadId: string) => Promise<void>;
11
+ renameThread: (threadId: string, title: string) => Promise<void>;
12
+ refreshThreads: () => Promise<void>;
13
+ refreshSharedThreads: () => Promise<void>;
14
+ shareThread: (threadId: string, sharedWithUserId: string) => Promise<void>;
15
+ unshareThread: (threadId: string, shareId: string) => Promise<void>;
16
+ }
17
+ interface UseThreadsStateOptions {
18
+ api: ChatApi;
19
+ initialThreadId?: string | null;
20
+ onError?: (error: string) => void;
21
+ onThreadChange?: (threadId: string | null) => void;
22
+ onCurrentThreadDeleted?: () => void;
23
+ }
24
+ export interface UseThreadsStateResult {
25
+ threads: ThreadSummary[];
26
+ currentThreadId: string | null;
27
+ currentThreadIdRef: MutableRefObject<string | null>;
28
+ setCurrentThreadId: (id: string | null) => void;
29
+ isLoadingThreads: boolean;
30
+ threadsError: string | null;
31
+ sharedThreads: SharedThreadSummary[];
32
+ isLoadingSharedThreads: boolean;
33
+ actions: ThreadActions;
34
+ addThreadFromEvent: (threadInfo: ThreadInfoEvent) => void;
35
+ shareInFlight: boolean;
36
+ shareStatus: string | null;
37
+ clearShareStatus: () => void;
38
+ }
39
+ export declare function useThreadsState({ api, initialThreadId, onError, onThreadChange, onCurrentThreadDeleted, }: UseThreadsStateOptions): UseThreadsStateResult;
40
+ export {};
@@ -0,0 +1,25 @@
1
+ import React, { ReactNode } from "react";
2
+ import type { Role } from "@/types";
3
+ export interface MessageBubbleProps {
4
+ role: Role;
5
+ header?: ReactNode;
6
+ content: ReactNode;
7
+ actions?: ReactNode;
8
+ status?: ReactNode;
9
+ isCompactLayout?: boolean;
10
+ /** UI-only override for background/border styling */
11
+ variant?: "default" | "minimal" | "accent";
12
+ customStyles?: {
13
+ container?: string;
14
+ bubble?: string;
15
+ content?: string;
16
+ header?: string;
17
+ actions?: string;
18
+ };
19
+ }
20
+ /**
21
+ * MessageBubble - The geometric template for all messages.
22
+ * This component defines the shared layout: where the header goes,
23
+ * how the content is padded, and where actions are positioned.
24
+ */
25
+ export declare const MessageBubble: React.NamedExoticComponent<MessageBubbleProps>;
@@ -0,0 +1,2 @@
1
+ export * from "./useMessageContent";
2
+ export * from "./useStreamingMarkdownBuffer";
@@ -0,0 +1,13 @@
1
+ import type { ChatMessage, ImagePart, FilePart, ToolCall, MessagePart } from "@/types";
2
+ export interface MessageContentResult {
3
+ textContent: string;
4
+ imageParts: ImagePart[];
5
+ fileParts: FilePart[];
6
+ toolCalls: ToolCall[];
7
+ contentParts: MessagePart[];
8
+ }
9
+ /**
10
+ * useMessageContent - Hook to extract content blocks from a ChatMessage.
11
+ * This is the "brain" for any message component.
12
+ */
13
+ export declare function useMessageContent(message: ChatMessage | null | undefined): MessageContentResult;
@@ -0,0 +1,3 @@
1
+ import type { MessagePart } from "@/types";
2
+ export declare function useStreamingMarkdownBuffer(parts: MessagePart[], enabled: boolean, debounceMs: number): MessagePart[];
3
+ export default useStreamingMarkdownBuffer;
@@ -0,0 +1,15 @@
1
+ import type { ChatMessage } from "@/types";
2
+ export type ToolPayloadEvent = Record<string, unknown>;
3
+ export interface ToolPayloadBase {
4
+ value: unknown;
5
+ event: ToolPayloadEvent | null;
6
+ }
7
+ export interface ToolDictPayload extends ToolPayloadBase {
8
+ kind: "dict";
9
+ data: Record<string, unknown>;
10
+ }
11
+ export interface ToolGenericPayload extends ToolPayloadBase {
12
+ kind: "generic";
13
+ }
14
+ export type ToolPayloadResult = ToolDictPayload | ToolGenericPayload;
15
+ export declare function useToolPayload(message: ChatMessage): ToolPayloadResult | null;
@@ -0,0 +1,27 @@
1
+ import type { ChatMessage, MessageArtifact, MessagePart, ToolArtifactRenderer, ToolArtifactRendererMap, ToolRenderer, ToolRendererMap, ToolConfig, ToolPayloadResult, ToolMeta, ToolViewMode } from "@/types";
2
+ import { BuildToolConfigOptions } from "@/types";
3
+ /**
4
+ * Context passed to tool renderers
5
+ */
6
+ export interface ToolRendererContext {
7
+ message: ChatMessage;
8
+ toolMeta: ToolMeta;
9
+ toolPayload: ToolPayloadResult | null;
10
+ viewMode: ToolViewMode;
11
+ isStreaming: boolean;
12
+ }
13
+ /**
14
+ * Props for ToolContent component
15
+ */
16
+ export interface ToolContentProps {
17
+ message: ChatMessage;
18
+ viewMode: ToolViewMode;
19
+ isStreaming?: boolean;
20
+ toolConfig?: ToolConfig;
21
+ expandable?: boolean;
22
+ artifactOverride?: MessageArtifact | null;
23
+ contentOverride?: MessagePart[] | null;
24
+ }
25
+ export type { ToolRenderer, ToolRendererMap, ToolConfig, ToolArtifactRenderer, ToolArtifactRendererMap, BuildToolConfigOptions };
26
+ export declare function ToolContent({ message, viewMode, isStreaming, toolConfig, expandable, artifactOverride, contentOverride, }: ToolContentProps): import("react/jsx-runtime").JSX.Element;
27
+ export declare function createExpandableToolRenderer(renderer: ToolRenderer): ToolRenderer;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Artifact Progress Component
3
+ *
4
+ * Shows real-time progress for streaming artifacts.
5
+ * Displays status, progress bar, and partial data.
6
+ */
7
+ import type { MessageArtifact } from "@/types";
8
+ interface ArtifactProgressProps {
9
+ artifact: MessageArtifact | null | undefined;
10
+ showPartialData?: boolean;
11
+ }
12
+ export declare function ArtifactProgress({ artifact, showPartialData }: ArtifactProgressProps): import("react/jsx-runtime").JSX.Element | null;
13
+ export {};
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Artifact Utilities
3
+ *
4
+ * Helper functions for working with artifacts, including metadata handling
5
+ * and streaming updates.
6
+ */
7
+ import type { MessageArtifact, ChatMessage, ArtifactMetadata } from "@/types";
8
+ /**
9
+ * Extract artifact metadata from a message
10
+ */
11
+ export declare function getArtifactMetadata(message: ChatMessage): ArtifactMetadata | null;
12
+ /**
13
+ * Check if an artifact is streaming (has progress < 100)
14
+ */
15
+ export declare function isArtifactStreaming(artifact: MessageArtifact | undefined): boolean;
16
+ /**
17
+ * Update artifact metadata during streaming
18
+ */
19
+ export declare function updateArtifactMetadata(message: ChatMessage, updates: Partial<ArtifactMetadata>): ChatMessage;
20
+ /**
21
+ * Find a message by artifact ID or associated tool call ID
22
+ */
23
+ export declare function findMessageByArtifactId(messages: ChatMessage[], artifactId: string, toolCallId?: string): ChatMessage | null;
24
+ import type { PlotData, ArtifactPreview } from "@/types";
25
+ /**
26
+ * Normalize MIME type from format hints
27
+ */
28
+ export declare function normalizeMimeType(formatHint?: string): string;
29
+ /**
30
+ * Build label parts for artifact display
31
+ */
32
+ export declare function buildLabelParts(extras?: {
33
+ plotId?: string;
34
+ artifactId?: string;
35
+ }): string[];
36
+ /**
37
+ * Create artifact preview object from source data
38
+ */
39
+ export declare function createArtifactPreviewFromSource({ base64, url, formatHint, extras, }: {
40
+ base64?: string;
41
+ url?: string;
42
+ formatHint?: string;
43
+ extras?: {
44
+ plotId?: string;
45
+ artifactId?: string;
46
+ };
47
+ }): ArtifactPreview | null;
48
+ /**
49
+ * Create artifact preview object from Plot data
50
+ */
51
+ export declare function createArtifactPreviewFromPlot(plot: PlotData): ArtifactPreview | null;
@@ -0,0 +1,6 @@
1
+ export * from "@/shared/core/utils/guards";
2
+ export * from "@/shared/core/utils/parsers";
3
+ export * from "@/shared/core/utils/metaUtils";
4
+ export * from "./artifactUtils";
5
+ export * from "./messageUtils";
6
+ export * from "@/shared/core/utils/toolCallUtils";
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Message utility functions for parsing, sanitizing, and rendering message content
3
+ */
4
+ /**
5
+ * Check if an object is file-like (has file properties)
6
+ */
7
+ export declare function isFileLike(x: any): boolean;
8
+ /**
9
+ * Sanitize content for display by removing file-like objects and large content
10
+ */
11
+ export declare function sanitizeForDisplay(x: any): any;
12
+ /**
13
+ * Pretty print content for display
14
+ */
15
+ export declare function pretty(x: any): string;
16
+ /**
17
+ * Intelligently format tool output - markdown if it looks like it, otherwise raw
18
+ */
19
+ export declare function formatToolOutput(x: any): {
20
+ content: string;
21
+ isMarkdown: boolean;
22
+ };
23
+ export { parseJsonSafe, looksLikeMarkdown } from "@/shared/utils/jsonUtils";
24
+ import type { ChatMessage, MessagePart } from "@/types";
25
+ /**
26
+ * Stringify tool call parts for display/debugging
27
+ */
28
+ export declare function stringifyTool(parts: MessagePart[]): string;
29
+ /**
30
+ * Check if a message has actual text or image content (not just tool calls)
31
+ */
32
+ export declare function hasContent(message: ChatMessage): boolean;
@@ -0,0 +1 @@
1
+ export * from "./useCheckpointIndex";
@@ -0,0 +1,2 @@
1
+ import type { HydratedCheckpointSnapshot } from "@/types";
2
+ export declare function useCheckpointIndex(checkpoints: HydratedCheckpointSnapshot[]): import("../utils/checkpointIndex").CheckpointIndex;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Checkpoint metadata + timeline helpers used by checkpoint features.
3
+ * Re-export the shared checkpoint models as well.
4
+ */
5
+ export type { HydratedCheckpointSnapshot, PendingInterrupt, PregelTask } from "@/types/domain/persistence";
6
+ export type EditMeta = {
7
+ checkpointId?: string | null;
8
+ checkpointNs?: string | null;
9
+ };
10
+ export type CheckpointMeta = {
11
+ id: string;
12
+ userMessageId: string | null;
13
+ attemptCount?: number;
14
+ isLatestAttempt?: boolean;
15
+ attemptIndex?: number;
16
+ step: number | null;
17
+ source: string | null;
18
+ createdAt: string | null;
19
+ namespace: string | null;
20
+ parentId: string | null;
21
+ next?: string | null;
22
+ parentConfig?: Record<string, unknown> | null;
23
+ };
24
+ export type TimelineCheckpoint = {
25
+ id: string;
26
+ messageId: string | null;
27
+ step: number | null;
28
+ source: string | null;
29
+ createdAt: string | null;
30
+ next?: string | null;
31
+ parentConfig?: Record<string, unknown> | null;
32
+ label?: string | null;
33
+ };
@@ -0,0 +1,18 @@
1
+ import type { HydratedCheckpointSnapshot } from "@/types";
2
+ import type { CheckpointMeta, TimelineCheckpoint } from "../types";
3
+ export interface CheckpointIndex {
4
+ checkpoints: HydratedCheckpointSnapshot[];
5
+ checkpointMetaByCheckpointId: Map<string, CheckpointMeta>;
6
+ timeline: TimelineCheckpoint[];
7
+ messagePreviews: Map<string, string>;
8
+ getLatest: () => CheckpointMeta | undefined;
9
+ getCheckpoint: (id: string) => CheckpointMeta | undefined;
10
+ getMessageAttempts: (userMessageId: string) => CheckpointMeta[];
11
+ }
12
+ export declare function buildCheckpointIndex(checkpoints: HydratedCheckpointSnapshot[]): CheckpointIndex;
13
+ export declare function getMessageAttemptInfo(messageId: string | undefined, checkpointId: string | null | undefined, index: CheckpointIndex): {
14
+ attemptCount: number;
15
+ attemptIndex: number;
16
+ attempts: CheckpointMeta[];
17
+ };
18
+ export declare function getCheckpointForMessage(checkpointId: string | null | undefined, index: CheckpointIndex): CheckpointMeta | null;
@@ -0,0 +1,11 @@
1
+ import type { TimelineCheckpoint } from "../types";
2
+ type ParentCheckpointInfo = {
3
+ checkpointId: string;
4
+ checkpointNs: string | null;
5
+ };
6
+ /**
7
+ * Given the timeline checkpoints for a thread, find the parent checkpoint that the
8
+ * backend should branch from when editing the provided message id.
9
+ */
10
+ export declare function findParentCheckpointForEdit(timeline: TimelineCheckpoint[], messageId: string): ParentCheckpointInfo;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { HistoryPayload, HydratedCheckpointSnapshot, PendingInterrupt } from "@/types";
2
+ export type HistoryHydrationResult = {
3
+ threadId: string;
4
+ latest: HydratedCheckpointSnapshot | null;
5
+ checkpoints: HydratedCheckpointSnapshot[];
6
+ interrupt: PendingInterrupt;
7
+ };
8
+ export declare function hydrateHistorySnapshots(history: HistoryPayload | null | undefined): HistoryHydrationResult;
@@ -0,0 +1,8 @@
1
+ import type { HydratedCheckpointSnapshot, ChatMessage } from '@/types';
2
+ export declare function getPreviewForMessage(message: ChatMessage): string;
3
+ /**
4
+ * Builds a map of checkpoint ID -> preview text.
5
+ * Each checkpoint gets its own preview based on the latest user message in that checkpoint.
6
+ * This ensures all checkpoints display accurate previews even if they reference the same message ID.
7
+ */
8
+ export declare function buildCheckpointPreviewMap(checkpoints: HydratedCheckpointSnapshot[]): Map<string, string>;