@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,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Context Types
|
|
3
|
+
* Infrastructure and context provider types
|
|
4
|
+
*/
|
|
5
|
+
import type { ChatMessage, GraphCommand, MessagePart } from "./domain/chat";
|
|
6
|
+
import type { ProjectInfo, ThreadSummary } from "./api/runs";
|
|
7
|
+
import type { PendingInterrupt } from "./domain/persistence";
|
|
8
|
+
import type { ActiveRunContext, StreamEvent } from "./domain/streaming";
|
|
9
|
+
export interface Envelope<T = unknown> {
|
|
10
|
+
data: T;
|
|
11
|
+
}
|
|
12
|
+
export type TokenListener = (token: string | null) => void;
|
|
13
|
+
export declare function isEnvelope(x: unknown): x is Envelope<unknown>;
|
|
14
|
+
export interface ApiContextValue {
|
|
15
|
+
token: string | null;
|
|
16
|
+
setToken: (token: string | null) => void;
|
|
17
|
+
chatApi: any;
|
|
18
|
+
authApi: any;
|
|
19
|
+
fileApi: any;
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ApiConfig {
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
authBaseUrl?: string;
|
|
25
|
+
chatBaseUrl?: string;
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
getToken?: () => string | null;
|
|
29
|
+
uploadPath?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface StreamSubmitPayload {
|
|
32
|
+
threadId?: string;
|
|
33
|
+
content?: string | ChatMessage;
|
|
34
|
+
attachments?: File[];
|
|
35
|
+
text?: string;
|
|
36
|
+
payload?: Record<string, unknown>;
|
|
37
|
+
contentParts?: MessagePart[];
|
|
38
|
+
edit?: boolean;
|
|
39
|
+
editingMessageId?: string | null;
|
|
40
|
+
originalMessageId?: string;
|
|
41
|
+
checkpointId?: string;
|
|
42
|
+
checkpointNs?: string | null;
|
|
43
|
+
config?: Record<string, unknown>;
|
|
44
|
+
project?: ProjectInfo | null;
|
|
45
|
+
command?: GraphCommand;
|
|
46
|
+
}
|
|
47
|
+
export interface StreamCallbacks {
|
|
48
|
+
onEvent?: (event: StreamEvent) => void;
|
|
49
|
+
}
|
|
50
|
+
export type PushUserOptions = {
|
|
51
|
+
attachments?: File[];
|
|
52
|
+
editingMessageId?: string | null;
|
|
53
|
+
};
|
|
54
|
+
export interface StreamContextValue {
|
|
55
|
+
submit: (input: StreamSubmitPayload, callbacks?: StreamCallbacks) => Promise<void>;
|
|
56
|
+
interrupt: ((value: unknown) => Promise<void>) | PendingInterrupt;
|
|
57
|
+
resume: (value?: unknown) => Promise<void>;
|
|
58
|
+
goto: (node: string, value?: unknown) => Promise<void>;
|
|
59
|
+
stop: () => void;
|
|
60
|
+
isStreaming: boolean;
|
|
61
|
+
error: string | null;
|
|
62
|
+
messages: ChatMessage[];
|
|
63
|
+
activeMessageId: string | null;
|
|
64
|
+
connectionState?: "idle" | "connecting" | "connected" | "reconnecting" | "error";
|
|
65
|
+
clearError: () => void;
|
|
66
|
+
}
|
|
67
|
+
export interface ThreadsContextValue {
|
|
68
|
+
threads: ThreadSummary[];
|
|
69
|
+
loading: boolean;
|
|
70
|
+
error: string | null;
|
|
71
|
+
createThread: (title?: string) => Promise<ThreadSummary>;
|
|
72
|
+
deleteThread: (threadId: string) => Promise<void>;
|
|
73
|
+
updateThread: (threadId: string, updates: Partial<ThreadSummary>) => Promise<void>;
|
|
74
|
+
refreshThreads: () => Promise<void>;
|
|
75
|
+
refreshSharedThreads: () => Promise<void>;
|
|
76
|
+
shareThread: (threadId: string, sharedWithUserId: string) => Promise<void>;
|
|
77
|
+
unshareThread: (threadId: string, shareId: string) => Promise<void>;
|
|
78
|
+
shareInFlight: boolean;
|
|
79
|
+
shareStatus: string | null;
|
|
80
|
+
clearShareStatus: () => void;
|
|
81
|
+
}
|
|
82
|
+
export interface ThreadStateContextValue {
|
|
83
|
+
threadId: string | null;
|
|
84
|
+
messages: ChatMessage[];
|
|
85
|
+
loading: boolean;
|
|
86
|
+
error: string | null;
|
|
87
|
+
metadata: ThreadStateMetadata;
|
|
88
|
+
pushUser: (content: string | ChatMessage) => ChatMessage;
|
|
89
|
+
reset: () => void;
|
|
90
|
+
clearError: () => void;
|
|
91
|
+
}
|
|
92
|
+
export interface ThreadStateMetadata {
|
|
93
|
+
assemblingMessageId: string | null;
|
|
94
|
+
checkpointId: string | null;
|
|
95
|
+
pendingInterrupts: PendingInterrupt[];
|
|
96
|
+
activeRun: ActiveRunContext | null;
|
|
97
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact Domain Types
|
|
3
|
+
*
|
|
4
|
+
* Centralized type definitions for all artifact-related functionality.
|
|
5
|
+
* This is the single source of truth for artifact types across the application.
|
|
6
|
+
*/
|
|
7
|
+
import type { ReactNode } from "react";
|
|
8
|
+
import type { ChatMessage } from "./chat";
|
|
9
|
+
import type { TemporalMetadata, ProgressMetadata } from "./primitives";
|
|
10
|
+
/**
|
|
11
|
+
* Base artifact interface attached to messages
|
|
12
|
+
*/
|
|
13
|
+
export interface MessageArtifact {
|
|
14
|
+
type: string;
|
|
15
|
+
index: number;
|
|
16
|
+
name?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
plots?: PlotData[];
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Metadata for artifact lifecycle tracking
|
|
23
|
+
*/
|
|
24
|
+
export interface ArtifactMetadata extends TemporalMetadata, ProgressMetadata {
|
|
25
|
+
id: string;
|
|
26
|
+
type: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Artifact with metadata attached (used during streaming)
|
|
30
|
+
*/
|
|
31
|
+
export interface ArtifactWithMetadata extends MessageArtifact {
|
|
32
|
+
metadata: ArtifactMetadata;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Plot-specific artifact data (charts, graphs, visualizations)
|
|
36
|
+
*/
|
|
37
|
+
export interface PlotData {
|
|
38
|
+
plotId?: string;
|
|
39
|
+
artifactId?: string;
|
|
40
|
+
contentBase64?: string;
|
|
41
|
+
url?: string;
|
|
42
|
+
format?: string;
|
|
43
|
+
mimeType?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Preview data for rendering artifacts (images, plots, etc.)
|
|
47
|
+
*/
|
|
48
|
+
export interface ArtifactPreview {
|
|
49
|
+
src: string;
|
|
50
|
+
alt: string;
|
|
51
|
+
label?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Props for artifact renderer components
|
|
55
|
+
*/
|
|
56
|
+
export interface ArtifactRendererProps {
|
|
57
|
+
artifact: MessageArtifact | null | undefined;
|
|
58
|
+
idx?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Context for tool payload rendering
|
|
62
|
+
*/
|
|
63
|
+
export interface ToolPayloadBase {
|
|
64
|
+
value: unknown;
|
|
65
|
+
event: Record<string, unknown> | null;
|
|
66
|
+
}
|
|
67
|
+
export interface ToolDictPayload extends ToolPayloadBase {
|
|
68
|
+
kind: "dict";
|
|
69
|
+
data: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
export interface ToolGenericPayload extends ToolPayloadBase {
|
|
72
|
+
kind: "generic";
|
|
73
|
+
}
|
|
74
|
+
export type ToolPayloadResult = ToolDictPayload | ToolGenericPayload;
|
|
75
|
+
/**
|
|
76
|
+
* Context passed to tool artifact renderers
|
|
77
|
+
*/
|
|
78
|
+
export interface ToolArtifactRendererContext {
|
|
79
|
+
artifact: MessageArtifact | null;
|
|
80
|
+
message: ChatMessage;
|
|
81
|
+
toolPayload: ToolPayloadResult | null;
|
|
82
|
+
isStreaming: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Function signature for custom tool artifact renderers
|
|
86
|
+
*/
|
|
87
|
+
export type ToolArtifactRenderer = (ctx: ToolArtifactRendererContext) => ReactNode | null;
|
|
88
|
+
/**
|
|
89
|
+
* Map of artifact type to custom renderer
|
|
90
|
+
*/
|
|
91
|
+
export type ToolArtifactRendererMap = {
|
|
92
|
+
default?: ToolArtifactRenderer;
|
|
93
|
+
[key: string]: ToolArtifactRenderer | undefined;
|
|
94
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { TemporalMetadata, Role } from "./primitives";
|
|
2
|
+
/**
|
|
3
|
+
* Content Block Types (Aligned with backend/LangChain)
|
|
4
|
+
*/
|
|
5
|
+
export type MessagePartType = "text" | "image_url" | "file" | "tool_call";
|
|
6
|
+
export interface TextPart {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ImagePart {
|
|
11
|
+
type: "image_url";
|
|
12
|
+
image_url: {
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface FilePart {
|
|
17
|
+
type: "file";
|
|
18
|
+
url?: string;
|
|
19
|
+
base64?: string;
|
|
20
|
+
mimeType?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
size?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ToolCall {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
args: Record<string, any>;
|
|
28
|
+
artifact?: any;
|
|
29
|
+
status?: "running" | "completed" | "failed";
|
|
30
|
+
content?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface InterruptAlternative {
|
|
33
|
+
id: string;
|
|
34
|
+
label: string;
|
|
35
|
+
value?: any;
|
|
36
|
+
}
|
|
37
|
+
export type MessagePart = TextPart | ImagePart | FilePart;
|
|
38
|
+
/**
|
|
39
|
+
* Message object (Unified structure)
|
|
40
|
+
*/
|
|
41
|
+
export interface ChatMessage extends TemporalMetadata {
|
|
42
|
+
id: string;
|
|
43
|
+
role: Role;
|
|
44
|
+
content: MessagePart[];
|
|
45
|
+
name?: string;
|
|
46
|
+
model?: string;
|
|
47
|
+
toolCallId?: string;
|
|
48
|
+
toolCalls?: ToolCall[];
|
|
49
|
+
checkpointId?: string | null;
|
|
50
|
+
checkpointNs?: string | null;
|
|
51
|
+
toolStreaming?: boolean;
|
|
52
|
+
artifact?: any;
|
|
53
|
+
additionalKwargs?: Record<string, any>;
|
|
54
|
+
responseMetadata?: Record<string, any>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Feature-specific request/command types
|
|
58
|
+
*/
|
|
59
|
+
export interface ChatRequest {
|
|
60
|
+
text?: string;
|
|
61
|
+
threadId?: string;
|
|
62
|
+
checkpointId?: string;
|
|
63
|
+
checkpointNs?: string;
|
|
64
|
+
attachments?: File[];
|
|
65
|
+
payload?: Record<string, any>;
|
|
66
|
+
config?: Record<string, any>;
|
|
67
|
+
command?: GraphCommand;
|
|
68
|
+
edit?: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface GraphCommand {
|
|
71
|
+
kind: "resume" | "goto";
|
|
72
|
+
value?: any;
|
|
73
|
+
node?: string;
|
|
74
|
+
}
|
|
75
|
+
export type StreamCommand = {
|
|
76
|
+
type: "stop";
|
|
77
|
+
} | {
|
|
78
|
+
type: "submit";
|
|
79
|
+
request: ChatRequest;
|
|
80
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain barrel
|
|
3
|
+
* Re-export domain models and primitives from a single entry point.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./primitives";
|
|
6
|
+
export * from "./chat";
|
|
7
|
+
export * from "./artifacts";
|
|
8
|
+
export * from "./streaming";
|
|
9
|
+
export * from "./persistence";
|
|
10
|
+
export * from "./tools";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ChatMessage, PendingInterrupt, StreamEvent } from "@/types";
|
|
2
|
+
export interface MessagesState {
|
|
3
|
+
messages: ChatMessage[];
|
|
4
|
+
assemblingId: string | null;
|
|
5
|
+
lastCheckpointId: string | null;
|
|
6
|
+
lastCheckpointNs: string | null;
|
|
7
|
+
pendingInterrupt: PendingInterrupt;
|
|
8
|
+
messagesStreamMeta?: Record<string, {
|
|
9
|
+
lastSeq?: number | null;
|
|
10
|
+
lastText?: string;
|
|
11
|
+
}>;
|
|
12
|
+
values: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export type MessagesAction = {
|
|
15
|
+
type: "reset";
|
|
16
|
+
payload?: {
|
|
17
|
+
messages?: ChatMessage[];
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
type: "seed";
|
|
21
|
+
payload: {
|
|
22
|
+
messages: ChatMessage[];
|
|
23
|
+
checkpointId?: string | null;
|
|
24
|
+
checkpointNs?: string | null;
|
|
25
|
+
pendingInterrupt?: PendingInterrupt;
|
|
26
|
+
values?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
type: "prepend";
|
|
30
|
+
payload: {
|
|
31
|
+
messages: ChatMessage[];
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
type: "user_message";
|
|
35
|
+
payload: {
|
|
36
|
+
message: ChatMessage;
|
|
37
|
+
editingMessageId?: string | null;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
type: "event";
|
|
41
|
+
payload: {
|
|
42
|
+
ev: StreamEvent;
|
|
43
|
+
};
|
|
44
|
+
} | {
|
|
45
|
+
type: "batch";
|
|
46
|
+
payload: {
|
|
47
|
+
events: StreamEvent[];
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
type: "interrupt_response";
|
|
51
|
+
payload: {
|
|
52
|
+
interruptId: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence Domain Types
|
|
3
|
+
* Checkpoints, history, and data persistence
|
|
4
|
+
*/
|
|
5
|
+
import type { ChatMessage, InterruptAlternative } from "./chat";
|
|
6
|
+
export interface HydratedCheckpointSnapshot {
|
|
7
|
+
checkpointId: string | null;
|
|
8
|
+
checkpointNs?: string | null;
|
|
9
|
+
threadId?: string | null;
|
|
10
|
+
messages?: ChatMessage[];
|
|
11
|
+
parentId?: string | null;
|
|
12
|
+
pendingWrites?: unknown[];
|
|
13
|
+
metadata?: {
|
|
14
|
+
step?: number;
|
|
15
|
+
source?: string | null;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
} | null;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
interrupt?: PendingInterrupt;
|
|
20
|
+
tasks?: PregelTask[] | null;
|
|
21
|
+
next?: string | string[] | null;
|
|
22
|
+
parentConfig?: Record<string, unknown> | null;
|
|
23
|
+
values?: {
|
|
24
|
+
interrupts?: PendingInterrupt[];
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
config?: {
|
|
28
|
+
stream_mode?: string[];
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
} | null;
|
|
31
|
+
}
|
|
32
|
+
export interface PregelTask {
|
|
33
|
+
id?: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
path?: string[];
|
|
36
|
+
parents?: string[];
|
|
37
|
+
interrupts?: PendingInterrupt[];
|
|
38
|
+
state?: unknown;
|
|
39
|
+
result?: unknown;
|
|
40
|
+
error?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
export type PendingInterrupt = {
|
|
44
|
+
id: string;
|
|
45
|
+
value: unknown;
|
|
46
|
+
alternatives?: InterruptAlternative[];
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* Interrupt Response Types
|
|
50
|
+
*/
|
|
51
|
+
export interface RespondToInterruptPayload {
|
|
52
|
+
approved: boolean;
|
|
53
|
+
value?: unknown;
|
|
54
|
+
id?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface RespondToInterruptOptions {
|
|
57
|
+
threadId?: string;
|
|
58
|
+
checkpointId?: string;
|
|
59
|
+
checkpointNs?: string;
|
|
60
|
+
payload?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
export interface CheckpointIndex {
|
|
63
|
+
threadId: string;
|
|
64
|
+
checkpoints: Map<string, HydratedCheckpointSnapshot>;
|
|
65
|
+
currentIndex: number | null;
|
|
66
|
+
hydratedSnapshots: Map<string, HydratedCheckpointSnapshot>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain Primitives
|
|
3
|
+
*
|
|
4
|
+
* Shared atoms used across chat, artifacts, and tools.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ISO-8601 timestamp string
|
|
8
|
+
*/
|
|
9
|
+
export type Timestamp = string;
|
|
10
|
+
/**
|
|
11
|
+
* Common message roles used across chat and tool events
|
|
12
|
+
*/
|
|
13
|
+
export type Role = "user" | "assistant" | "system" | "tool";
|
|
14
|
+
/**
|
|
15
|
+
* Standard lifecycle states for streaming or long-running entities
|
|
16
|
+
*/
|
|
17
|
+
export type LifecycleStatus = "pending" | "in_progress" | "completed" | "failed";
|
|
18
|
+
/**
|
|
19
|
+
* Timestamps attached to persisted entities
|
|
20
|
+
*/
|
|
21
|
+
export interface TemporalMetadata {
|
|
22
|
+
createdAt: Timestamp;
|
|
23
|
+
updatedAt?: Timestamp;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Progress/status metadata shared by artifacts and tool executions
|
|
27
|
+
*/
|
|
28
|
+
export interface ProgressMetadata {
|
|
29
|
+
status?: LifecycleStatus;
|
|
30
|
+
progress?: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Shared view modes for tool rendering
|
|
35
|
+
*/
|
|
36
|
+
export type ToolViewMode = "preview" | "expanded";
|
|
37
|
+
/**
|
|
38
|
+
* Common identifiers attached to tool events
|
|
39
|
+
*/
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming Domain Types
|
|
3
|
+
* Real-time streaming events and state (LangGraph-compatible).
|
|
4
|
+
*/
|
|
5
|
+
import type { ChatMessage, StreamSubmitPayload, StreamCallbacks } from "@/types";
|
|
6
|
+
import type { HistoryPayload, ProjectInfo } from "../api/runs";
|
|
7
|
+
export type UseChatStreamOptions = {
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
streamPath?: string;
|
|
10
|
+
token?: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
credentials?: RequestCredentials;
|
|
13
|
+
autoAppendAssistant?: boolean;
|
|
14
|
+
onEvent?: (event: StreamEvent) => void;
|
|
15
|
+
onError?: (error: Error) => void;
|
|
16
|
+
onAuthError?: (error: string) => void;
|
|
17
|
+
onConnectionError?: (error: string) => void;
|
|
18
|
+
onFinish?: (info: StreamFinishInfo) => void;
|
|
19
|
+
onThreadInfo?: (event: ThreadInfoEvent) => void;
|
|
20
|
+
onMetadataEvent?: (event: Extract<StreamEvent, {
|
|
21
|
+
type: "metadata";
|
|
22
|
+
}>) => void;
|
|
23
|
+
onCustomEvent?: (event: StreamEvent) => void;
|
|
24
|
+
onUpdateEvent?: (event: Extract<StreamEvent, {
|
|
25
|
+
type: "updates";
|
|
26
|
+
}>) => void;
|
|
27
|
+
onToolEnd?: (event: ToolEndEvent) => void;
|
|
28
|
+
onToolStart?: (event: ToolStartEvent) => void;
|
|
29
|
+
handleStateHistoryEvent?: (event: StateHistoryEvent) => void;
|
|
30
|
+
onHeartbeat?: (event: HeartbeatEvent) => void;
|
|
31
|
+
onToken?: (token: string) => void;
|
|
32
|
+
};
|
|
33
|
+
export interface UseStreamApi {
|
|
34
|
+
isStreaming: boolean;
|
|
35
|
+
error: string | null;
|
|
36
|
+
assistantText: string;
|
|
37
|
+
activeMessageId: string | null;
|
|
38
|
+
streamedMessages: Record<string, ChatMessage>;
|
|
39
|
+
lastCheckpointId: string | null;
|
|
40
|
+
lastSeq: number;
|
|
41
|
+
connected: boolean;
|
|
42
|
+
stream: (input: StreamSubmitPayload, callbacks?: StreamCallbacks) => Promise<void>;
|
|
43
|
+
stop: () => void;
|
|
44
|
+
clear: () => void;
|
|
45
|
+
setToken: (token: string | null) => void;
|
|
46
|
+
values: Record<string, unknown>;
|
|
47
|
+
interrupt: () => Promise<void>;
|
|
48
|
+
resume: () => Promise<void>;
|
|
49
|
+
goto: () => Promise<void>;
|
|
50
|
+
connectionState: "idle" | "connecting" | "connected" | "reconnecting" | "error";
|
|
51
|
+
messages: ChatMessage[];
|
|
52
|
+
submit: (input: StreamSubmitPayload, callbacks?: StreamCallbacks) => Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export type ActiveRunContext = {
|
|
55
|
+
runId?: string;
|
|
56
|
+
nodeId?: string;
|
|
57
|
+
threadId?: string | null;
|
|
58
|
+
isStreaming: boolean;
|
|
59
|
+
headers?: Record<string, string>;
|
|
60
|
+
};
|
|
61
|
+
export type StreamFinishInfo = {
|
|
62
|
+
lastSeq: number;
|
|
63
|
+
lastCheckpointId: string | null;
|
|
64
|
+
lastCheckpointNs: string | null;
|
|
65
|
+
lastStateHistory: HistoryPayload | null;
|
|
66
|
+
};
|
|
67
|
+
export type ToolEventIdentity = {
|
|
68
|
+
id?: string;
|
|
69
|
+
callId?: string;
|
|
70
|
+
};
|
|
71
|
+
export type ToolStartEvent = {
|
|
72
|
+
type: "tool.start";
|
|
73
|
+
args: Record<string, unknown>;
|
|
74
|
+
name?: string;
|
|
75
|
+
tool?: string;
|
|
76
|
+
seq?: number;
|
|
77
|
+
additionalKwargs?: Record<string, unknown>;
|
|
78
|
+
} & ToolEventIdentity;
|
|
79
|
+
export type ToolEndEvent = {
|
|
80
|
+
type: "tool.end";
|
|
81
|
+
content: string;
|
|
82
|
+
artifact?: unknown;
|
|
83
|
+
error?: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
tool?: string;
|
|
86
|
+
seq?: number;
|
|
87
|
+
additionalKwargs?: Record<string, unknown>;
|
|
88
|
+
} & ToolEventIdentity;
|
|
89
|
+
export type ToolProgressEvent = {
|
|
90
|
+
type: "tool.progress";
|
|
91
|
+
content?: string;
|
|
92
|
+
id?: string;
|
|
93
|
+
callId?: string;
|
|
94
|
+
status?: string;
|
|
95
|
+
step?: string;
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
idx?: number;
|
|
98
|
+
seq?: number;
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
};
|
|
101
|
+
export type ArtifactUpdateEvent = {
|
|
102
|
+
type: "artifact.update";
|
|
103
|
+
artifact_id: string;
|
|
104
|
+
partial_data?: Record<string, unknown>;
|
|
105
|
+
progress?: number;
|
|
106
|
+
status?: "pending" | "in_progress" | "completed" | "failed";
|
|
107
|
+
error?: string;
|
|
108
|
+
};
|
|
109
|
+
export type ToolStreamEvent = ToolStartEvent | ToolEndEvent | ArtifactUpdateEvent;
|
|
110
|
+
export type MessageStreamEvent = ToolProgressEvent | {
|
|
111
|
+
type: "messages/partial";
|
|
112
|
+
messages: Array<{
|
|
113
|
+
content: string;
|
|
114
|
+
id: string;
|
|
115
|
+
type: string;
|
|
116
|
+
response_metadata?: Record<string, unknown>;
|
|
117
|
+
}>;
|
|
118
|
+
};
|
|
119
|
+
export type ThreadStreamEvent = {
|
|
120
|
+
type: "thread_info";
|
|
121
|
+
threadId: string;
|
|
122
|
+
title: string;
|
|
123
|
+
project?: ProjectInfo | null;
|
|
124
|
+
createdAt: string;
|
|
125
|
+
updatedAt: string;
|
|
126
|
+
messageCount: number;
|
|
127
|
+
lastMessage?: string | null;
|
|
128
|
+
created?: boolean | null;
|
|
129
|
+
ready?: boolean | null;
|
|
130
|
+
seq?: number | null;
|
|
131
|
+
} | {
|
|
132
|
+
type: "checkpoint";
|
|
133
|
+
checkpointId: string;
|
|
134
|
+
checkpointNs?: string | null;
|
|
135
|
+
};
|
|
136
|
+
export type ThreadInfoEvent = Extract<ThreadStreamEvent, {
|
|
137
|
+
type: "thread_info";
|
|
138
|
+
}>;
|
|
139
|
+
export type SystemStreamEvent = {
|
|
140
|
+
type: "error";
|
|
141
|
+
message: string;
|
|
142
|
+
error_type?: string;
|
|
143
|
+
code?: string;
|
|
144
|
+
} | {
|
|
145
|
+
type: "interrupt";
|
|
146
|
+
id: string;
|
|
147
|
+
value: any;
|
|
148
|
+
seq: number;
|
|
149
|
+
} | {
|
|
150
|
+
type: "heartbeat";
|
|
151
|
+
timestamp: number;
|
|
152
|
+
seq: number;
|
|
153
|
+
} | {
|
|
154
|
+
type: "cancelled";
|
|
155
|
+
reason?: string;
|
|
156
|
+
seq?: number;
|
|
157
|
+
} | {
|
|
158
|
+
type: "custom";
|
|
159
|
+
data: unknown;
|
|
160
|
+
name?: string;
|
|
161
|
+
seq?: number;
|
|
162
|
+
} | ({
|
|
163
|
+
type: "state_history";
|
|
164
|
+
seq?: number;
|
|
165
|
+
} & HistoryPayload) | {
|
|
166
|
+
type: "metadata";
|
|
167
|
+
threadId?: string;
|
|
168
|
+
status?: string;
|
|
169
|
+
runId?: string;
|
|
170
|
+
} | {
|
|
171
|
+
type: "updates";
|
|
172
|
+
tools?: Record<string, unknown>;
|
|
173
|
+
[key: string]: unknown;
|
|
174
|
+
} | {
|
|
175
|
+
type: "values";
|
|
176
|
+
[key: string]: unknown;
|
|
177
|
+
} | {
|
|
178
|
+
type: "token";
|
|
179
|
+
token: string;
|
|
180
|
+
};
|
|
181
|
+
export type HeartbeatEvent = Extract<SystemStreamEvent, {
|
|
182
|
+
type: "heartbeat";
|
|
183
|
+
}>;
|
|
184
|
+
export type StateHistoryEvent = Extract<SystemStreamEvent, {
|
|
185
|
+
type: "state_history";
|
|
186
|
+
}>;
|
|
187
|
+
export type StreamEvent = MessageStreamEvent | ToolStreamEvent | ThreadStreamEvent | SystemStreamEvent;
|
|
188
|
+
export interface StreamEventHandlers {
|
|
189
|
+
onConnectionError?: (error: string) => void;
|
|
190
|
+
onError?: (error: string) => void;
|
|
191
|
+
onOpen?: (data: {
|
|
192
|
+
threadId: string | null;
|
|
193
|
+
created: boolean;
|
|
194
|
+
}) => void;
|
|
195
|
+
onGap?: (gap: {
|
|
196
|
+
from: number;
|
|
197
|
+
to: number;
|
|
198
|
+
}) => void;
|
|
199
|
+
onUpdateEvent?: (event: Extract<StreamEvent, {
|
|
200
|
+
type: "updates";
|
|
201
|
+
}>) => void;
|
|
202
|
+
onCustomEvent?: (event: Extract<StreamEvent, {
|
|
203
|
+
type: "custom";
|
|
204
|
+
}>) => void;
|
|
205
|
+
onMetadataEvent?: (event: Extract<StreamEvent, {
|
|
206
|
+
type: "metadata";
|
|
207
|
+
}>) => void;
|
|
208
|
+
onClosed?: (info: {
|
|
209
|
+
reason: "complete" | "aborted" | "error";
|
|
210
|
+
lastSeq: number;
|
|
211
|
+
lastCheckpointId: string | null;
|
|
212
|
+
lastCheckpointNs: string | null;
|
|
213
|
+
lastStateHistory: HistoryPayload | null;
|
|
214
|
+
error?: string | null;
|
|
215
|
+
}) => void;
|
|
216
|
+
onFinish?: (info: StreamFinishInfo) => void;
|
|
217
|
+
onAuthError?: (error: string) => void;
|
|
218
|
+
onHeartbeat?: (event: HeartbeatEvent) => void;
|
|
219
|
+
onToolStart?: (event: ToolStartEvent) => void;
|
|
220
|
+
onToolEnd?: (event: ToolEndEvent) => void;
|
|
221
|
+
onToken?: (token: string) => void;
|
|
222
|
+
onThreadInfo?: (event: ThreadInfoEvent) => void;
|
|
223
|
+
}
|
|
224
|
+
export declare function isStreamEvent(obj: any): obj is StreamEvent;
|
|
225
|
+
export declare function isToolEvent(obj: any): obj is ToolStreamEvent;
|
|
226
|
+
export declare function isToolStartEvent(obj: any): obj is ToolStartEvent;
|
|
227
|
+
export declare function isToolEndEvent(obj: any): obj is ToolEndEvent;
|
|
228
|
+
export declare function isArtifactUpdateEvent(obj: any): obj is ArtifactUpdateEvent;
|
|
229
|
+
export declare function isMessageStreamEvent(obj: any): obj is MessageStreamEvent;
|
|
230
|
+
export declare function isThreadStreamEvent(obj: any): obj is ThreadStreamEvent;
|
|
231
|
+
export declare function isSystemStreamEvent(obj: any): obj is SystemStreamEvent;
|