@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.
- package/dist/features/conversation/contexts/ChatUIContext.d.ts +41 -0
- package/dist/features/conversation/contexts/ThreadStateProvider.d.ts +24 -0
- package/dist/features/conversation/contexts/ThreadsProvider.d.ts +10 -0
- package/dist/features/conversation/contexts/index.d.ts +3 -0
- package/dist/features/conversation/contexts/reducers/MessageReducer.d.ts +22 -0
- package/dist/features/conversation/contexts/reducers/utils/reducerUtils.d.ts +21 -0
- package/dist/features/conversation/hooks/index.d.ts +7 -0
- package/dist/features/conversation/hooks/useChatController.d.ts +50 -0
- package/dist/features/conversation/hooks/useChatSession.d.ts +49 -0
- package/dist/features/conversation/hooks/useFilePreview.d.ts +15 -0
- package/dist/features/conversation/hooks/useParsedMessageContent.d.ts +12 -0
- package/dist/features/conversation/hooks/useThreadHistoryState.d.ts +44 -0
- package/dist/features/conversation/hooks/useThreadsState.d.ts +40 -0
- package/dist/features/conversation/messages/components/MessageBubble.d.ts +25 -0
- package/dist/features/conversation/messages/hooks/index.d.ts +2 -0
- package/dist/features/conversation/messages/hooks/useMessageContent.d.ts +13 -0
- package/dist/features/conversation/messages/hooks/useStreamingMarkdownBuffer.d.ts +3 -0
- package/dist/features/conversation/messages/hooks/useToolPayload.d.ts +15 -0
- package/dist/features/conversation/messages/renderers/tooling/ToolContent.d.ts +27 -0
- package/dist/features/conversation/messages/renderers/tooling/artifacts/ArtifactProgress.d.ts +13 -0
- package/dist/features/conversation/messages/utils/artifactUtils.d.ts +51 -0
- package/dist/features/conversation/messages/utils/index.d.ts +6 -0
- package/dist/features/conversation/messages/utils/messageUtils.d.ts +32 -0
- package/dist/features/persistence/checkpoints/hooks/index.d.ts +1 -0
- package/dist/features/persistence/checkpoints/hooks/useCheckpointIndex.d.ts +2 -0
- package/dist/features/persistence/checkpoints/types/index.d.ts +33 -0
- package/dist/features/persistence/checkpoints/utils/checkpointIndex.d.ts +18 -0
- package/dist/features/persistence/checkpoints/utils/editUtils.d.ts +11 -0
- package/dist/features/persistence/checkpoints/utils/historyUtils.d.ts +8 -0
- package/dist/features/persistence/checkpoints/utils/messagePreviews.d.ts +8 -0
- package/dist/features/persistence/checkpoints/utils/schemaUtils.d.ts +6 -0
- package/dist/features/streaming/contexts/StreamingProvider.d.ts +19 -0
- package/dist/features/streaming/contexts/index.d.ts +1 -0
- package/dist/features/streaming/contexts/types.d.ts +76 -0
- package/dist/features/streaming/hooks/types.d.ts +50 -0
- package/dist/features/streaming/hooks/use-stream.d.ts +2 -0
- package/dist/features/streaming/index.d.ts +5 -0
- package/dist/features/streaming/utils/index.d.ts +1 -0
- package/dist/features/streaming/utils/toolHandlers.d.ts +14 -0
- package/dist/features/thread/contexts/index.d.ts +1 -0
- package/dist/features/thread/contexts/reducers/MessageReducer.d.ts +1 -0
- package/dist/features/thread/hooks/useThreadHistoryState.d.ts +1 -0
- package/dist/features/thread/hooks/useThreadsState.d.ts +1 -0
- package/dist/index.esm.js +5344 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +9 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/lib/core.d.ts +26 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/shared/core/api/clients/authClient.d.ts +13 -0
- package/dist/shared/core/api/clients/chatClient.d.ts +50 -0
- package/dist/shared/core/api/clients/fileClient.d.ts +12 -0
- package/dist/shared/core/api/clients/index.d.ts +2 -0
- package/dist/shared/core/api/index.d.ts +2 -0
- package/dist/shared/core/api/utils/http.d.ts +20 -0
- package/dist/shared/core/api/utils/index.d.ts +1 -0
- package/dist/shared/core/constants/env.d.ts +39 -0
- package/dist/shared/core/constants/index.d.ts +2 -0
- package/dist/shared/core/constants/storage.d.ts +14 -0
- package/dist/shared/core/contexts/index.d.ts +4 -0
- package/dist/shared/core/contexts/providers/ApiProvider.d.ts +11 -0
- package/dist/shared/core/contexts/providers/ChatProviders.d.ts +25 -0
- package/dist/shared/core/contexts/providers/index.d.ts +2 -0
- package/dist/shared/core/hooks/index.d.ts +2 -0
- package/dist/shared/core/hooks/useApi.d.ts +1 -0
- package/dist/shared/core/hooks/useShallowStableValue.d.ts +1 -0
- package/dist/shared/core/index.d.ts +6 -0
- package/dist/shared/core/types/index.d.ts +1 -0
- package/dist/shared/core/utils/caseUtils.d.ts +1 -0
- package/dist/shared/core/utils/chatUtils.d.ts +10 -0
- package/dist/shared/core/utils/guards.d.ts +8 -0
- package/dist/shared/core/utils/index.d.ts +8 -0
- package/dist/shared/core/utils/messageFactory.d.ts +14 -0
- package/dist/shared/core/utils/metaUtils.d.ts +22 -0
- package/dist/shared/core/utils/normalizationUtils.d.ts +20 -0
- package/dist/shared/core/utils/parsers.d.ts +22 -0
- package/dist/shared/core/utils/toolCallUtils.d.ts +14 -0
- package/dist/shared/core/utils/toolFormatting.d.ts +8 -0
- package/dist/shared/ui/components/toast.d.ts +15 -0
- package/dist/shared/ui/hooks/use-toast.d.ts +44 -0
- package/dist/shared/ui/utils/cn.d.ts +2 -0
- package/dist/shared/ui/utils/index.d.ts +1 -0
- package/dist/shared/utils/jsonUtils.d.ts +18 -0
- package/dist/types/api/auth.d.ts +15 -0
- package/dist/types/api/common.d.ts +9 -0
- package/dist/types/api/files.d.ts +7 -0
- package/dist/types/api/runs.d.ts +104 -0
- package/dist/types/api.d.ts +7 -0
- package/dist/types/core/context.d.ts +5 -0
- package/dist/types/core/models.d.ts +6 -0
- package/dist/types/core.d.ts +97 -0
- package/dist/types/domain/artifacts.d.ts +94 -0
- package/dist/types/domain/chat.d.ts +80 -0
- package/dist/types/domain/index.d.ts +10 -0
- package/dist/types/domain/messages.d.ts +54 -0
- package/dist/types/domain/persistence.d.ts +67 -0
- package/dist/types/domain/primitives.d.ts +39 -0
- package/dist/types/domain/streaming.d.ts +231 -0
- package/dist/types/domain/tools.d.ts +66 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/shared/common.d.ts +19 -0
- package/package.json +42 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type PlainObject = Record<string, unknown>;
|
|
2
|
+
export declare function toPlainObject(value: unknown): PlainObject | undefined;
|
|
3
|
+
export declare function readString(source: PlainObject | undefined, keys: string[]): string | undefined;
|
|
4
|
+
export declare function readNumber(source: PlainObject | undefined, keys: string[]): number | null;
|
|
5
|
+
export declare function extractConfigFields(source: unknown): PlainObject | undefined;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StreamContextValue } from '@/types/core';
|
|
2
|
+
import type { ToolEndEvent, StreamEvent, StreamFinishInfo } from "@/types/domain/streaming";
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
interface StreamingProviderProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
onError?: (error: string) => void;
|
|
7
|
+
onAuthError?: (error: string) => void;
|
|
8
|
+
onConnectionError?: (error: string) => void;
|
|
9
|
+
onToolEnd?: (event: ToolEndEvent) => void;
|
|
10
|
+
onUpdateEvent?: (event: StreamEvent) => void;
|
|
11
|
+
onCustomEvent?: (event: StreamEvent) => void;
|
|
12
|
+
onMetadataEvent?: (event: StreamEvent) => void;
|
|
13
|
+
onFinish?: (info: StreamFinishInfo) => void;
|
|
14
|
+
onStreamingChange?: (isStreaming: boolean) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function StreamingProvider({ children, onError, onAuthError, onConnectionError, onToolEnd, onUpdateEvent, onCustomEvent, onMetadataEvent, onFinish, onStreamingChange, }: StreamingProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare function useStream(): StreamContextValue;
|
|
18
|
+
export declare function useHasChatSession(): boolean;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StreamingProvider, useStream, useHasChatSession } from "./StreamingProvider";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ChatMessage, ProjectInfo, ThreadSummary, PendingInterrupt, HydratedCheckpointSnapshot } from "@/types";
|
|
2
|
+
import type { TimelineCheckpoint } from "@/features/persistence/checkpoints/types";
|
|
3
|
+
import type { CheckpointIndex } from "@/features/persistence/checkpoints/utils/checkpointIndex";
|
|
4
|
+
import type { StateHistoryEvent } from "@/types/domain/streaming";
|
|
5
|
+
import type { MutableRefObject } from "react";
|
|
6
|
+
import type { ThreadInfoEvent } from "@/types/domain/streaming";
|
|
7
|
+
export interface ThreadsContextValue {
|
|
8
|
+
threads: ThreadSummary[];
|
|
9
|
+
currentThreadId: string | null;
|
|
10
|
+
setCurrentThreadId: (id: string | null) => void;
|
|
11
|
+
currentThreadIdRef: MutableRefObject<string | null>;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
error: string | null;
|
|
14
|
+
sharedThreads: ThreadSummary[];
|
|
15
|
+
isLoadingSharedThreads: boolean;
|
|
16
|
+
actions: {
|
|
17
|
+
createThread: (title?: string, project?: ({
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
} | ProjectInfo | null)) => Promise<string | null>;
|
|
21
|
+
deleteThread: (threadId: string) => Promise<void>;
|
|
22
|
+
renameThread: (threadId: string, title: string) => Promise<void>;
|
|
23
|
+
refreshThreads: () => Promise<void>;
|
|
24
|
+
refreshSharedThreads: () => Promise<void>;
|
|
25
|
+
shareThread: (threadId: string, sharedWithUserId: string) => Promise<void>;
|
|
26
|
+
unshareThread: (threadId: string, shareId: string) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
shareInFlight: boolean;
|
|
29
|
+
shareStatus: string | null;
|
|
30
|
+
clearShareStatus: () => void;
|
|
31
|
+
addThreadFromEvent: (threadInfo: ThreadInfoEvent) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface ThreadStateContextValue {
|
|
34
|
+
threadId: string | null;
|
|
35
|
+
messages: ChatMessage[];
|
|
36
|
+
interrupt: PendingInterrupt;
|
|
37
|
+
checkpoint: {
|
|
38
|
+
id: string | null;
|
|
39
|
+
namespace: string | null;
|
|
40
|
+
};
|
|
41
|
+
checkpoints: HydratedCheckpointSnapshot[];
|
|
42
|
+
checkpointIndex: CheckpointIndex;
|
|
43
|
+
timelineCheckpoints: TimelineCheckpoint[];
|
|
44
|
+
metadata: {
|
|
45
|
+
assemblingMessageId: string | null;
|
|
46
|
+
};
|
|
47
|
+
values: Record<string, unknown>;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
isLoadingCheckpoint: boolean;
|
|
50
|
+
error: string | null;
|
|
51
|
+
loadOlder: () => Promise<void>;
|
|
52
|
+
seedFromSnapshot: (snapshot: {
|
|
53
|
+
messages: ChatMessage[];
|
|
54
|
+
checkpointId?: string | null;
|
|
55
|
+
checkpointNs?: string | null;
|
|
56
|
+
interrupt?: PendingInterrupt;
|
|
57
|
+
}) => void;
|
|
58
|
+
clearState: () => Promise<void> | void;
|
|
59
|
+
navigateToCheckpoint: (checkpointId: string, checkpointNs?: string | null) => Promise<void>;
|
|
60
|
+
setCurrentCheckpointId: (checkpointId: string | null, checkpointNs?: string | null) => void;
|
|
61
|
+
returnToLatest: () => Promise<void>;
|
|
62
|
+
loadThread: (threadId: string, checkpointId?: string | null, checkpointNs?: string | null) => Promise<void>;
|
|
63
|
+
clearThread: () => Promise<void> | void;
|
|
64
|
+
respondToInterrupt: (approved: boolean, value?: unknown, options?: any) => Promise<void>;
|
|
65
|
+
messagePreviews: Map<string, string>;
|
|
66
|
+
handleStateHistoryEvent: (payload: StateHistoryEvent) => void;
|
|
67
|
+
markSkipNextLoad: (threadId: string) => void;
|
|
68
|
+
markStreamPendingThread: (threadId: string) => void;
|
|
69
|
+
resetHistoryState: () => void;
|
|
70
|
+
pushUser: (content: string | ChatMessage, options?: {
|
|
71
|
+
editingMessageId?: string | null;
|
|
72
|
+
}) => ChatMessage;
|
|
73
|
+
onEvent: (ev: any) => void;
|
|
74
|
+
/** Global collection of artifacts discovered in the message history */
|
|
75
|
+
artifacts: import("@/types").MessageArtifact[];
|
|
76
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ChatRequest, HistoryPayload, StreamEvent } from "@/types";
|
|
2
|
+
export type UseChatStreamOptions = {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
streamPath?: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
credentials?: RequestCredentials;
|
|
8
|
+
autoAppendAssistant?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type UseStreamApi = {
|
|
11
|
+
isStreaming: boolean;
|
|
12
|
+
error: string | null;
|
|
13
|
+
lastCheckpointId: string | null;
|
|
14
|
+
assistantText: string;
|
|
15
|
+
lastSeq: number;
|
|
16
|
+
connected: boolean;
|
|
17
|
+
stream: (req: ChatRequest, onEvent?: (ev: StreamEvent) => void, options?: {
|
|
18
|
+
onError?: (message: string) => void;
|
|
19
|
+
onOpen?: (info: {
|
|
20
|
+
threadId: string | null;
|
|
21
|
+
created: boolean;
|
|
22
|
+
}) => void;
|
|
23
|
+
onGap?: (gap: {
|
|
24
|
+
from: number;
|
|
25
|
+
to: number;
|
|
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
|
+
onAuthError?: (message: string) => void;
|
|
37
|
+
onHeartbeat?: (event: Extract<StreamEvent, {
|
|
38
|
+
type: "heartbeat";
|
|
39
|
+
}>) => void;
|
|
40
|
+
}) => {
|
|
41
|
+
close: () => void;
|
|
42
|
+
};
|
|
43
|
+
stop: () => void;
|
|
44
|
+
clear: () => void;
|
|
45
|
+
setToken: (t: string | null) => void;
|
|
46
|
+
};
|
|
47
|
+
export type ActiveRunContext = {
|
|
48
|
+
threadId: string | null;
|
|
49
|
+
headers: Record<string, string>;
|
|
50
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from "./contexts";
|
|
2
|
+
export { useStream, useStream as useStreamingHook } from "./hooks/use-stream";
|
|
3
|
+
export type { UseStreamApi, UseChatStreamOptions, ActiveRunContext, } from "./hooks/types";
|
|
4
|
+
export * from "./utils";
|
|
5
|
+
export type { ToolEndEvent, ThreadInfoEvent, StateHistoryEvent } from "@/types/domain/streaming";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./toolHandlers";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ToolEndEvent } from "@/types";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a task ID from a tool end event payload.
|
|
4
|
+
* Supports both snake_case (task_id) and camelCase (taskId) keys on artifact or content payloads.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractTaskIdFromToolEnd(event: ToolEndEvent): string | null;
|
|
7
|
+
/**
|
|
8
|
+
* Builds an onToolEnd handler that syncs task context and delegates to an optional user handler.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTaskSyncToolEndHandler(params: {
|
|
11
|
+
setCurrentTaskId: (taskId: string) => void;
|
|
12
|
+
getCurrentTaskId?: () => string | null;
|
|
13
|
+
onToolEnd?: (event: ToolEndEvent) => void;
|
|
14
|
+
}): (event: ToolEndEvent) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ThreadsProvider, useThreads, ThreadStateProvider, useThreadState, useThreadStateUpdater, } from "@/features/conversation/contexts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMessagesReducer, messagesReducer, initialMessagesState } from "@/features/conversation/contexts/reducers/MessageReducer";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useThreadHistoryState } from "@/features/conversation/hooks/useThreadHistoryState";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useThreadsState } from "@/features/conversation/hooks/useThreadsState";
|