@polpo-ai/chat 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +255 -0
- package/dist/chunk-CCSIMOXD.js +230 -0
- package/dist/chunk-CCSIMOXD.js.map +1 -0
- package/dist/chunk-LTLIBITC.js +64 -0
- package/dist/chunk-LTLIBITC.js.map +1 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +198 -0
- package/dist/index.js +737 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/index.d.ts +21 -0
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -0
- package/package.json +55 -0
- package/registry.json +188 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ComponentType, HTMLAttributes } from 'react';
|
|
3
|
+
import { ChatMessage as ChatMessage$1, ContentPart, ToolCallEvent } from '@polpo-ai/sdk';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import { UseChatReturn } from '@polpo-ai/react';
|
|
6
|
+
export { useDocumentDrag, useSubmitHandler } from './hooks/index.js';
|
|
7
|
+
export { ToolCallChip, ToolCallShell } from './tools/index.js';
|
|
8
|
+
import 'lucide-react';
|
|
9
|
+
|
|
10
|
+
interface ChatMessagesHandle {
|
|
11
|
+
/** Scroll the list to the bottom. */
|
|
12
|
+
scrollToBottom: (behavior?: "smooth" | "auto") => void;
|
|
13
|
+
}
|
|
14
|
+
interface ChatMessagesProps {
|
|
15
|
+
/**
|
|
16
|
+
* Custom renderer for each message.
|
|
17
|
+
* Receives the message, its index, whether it is the last item, and
|
|
18
|
+
* whether the assistant is currently streaming.
|
|
19
|
+
*/
|
|
20
|
+
renderItem?: (msg: ChatMessage$1, index: number, isLast: boolean, isStreaming: boolean) => ReactNode;
|
|
21
|
+
/** Extra classes applied to the Virtuoso container. */
|
|
22
|
+
className?: string;
|
|
23
|
+
/** Number of skeleton pairs to show during the initial load. */
|
|
24
|
+
skeletonCount?: number;
|
|
25
|
+
}
|
|
26
|
+
declare const ChatMessages: react.ForwardRefExoticComponent<ChatMessagesProps & react.RefAttributes<ChatMessagesHandle>>;
|
|
27
|
+
|
|
28
|
+
/** Components override accepted by Streamdown — use Record for flexibility. */
|
|
29
|
+
type StreamdownComponentsProp = Record<string, unknown>;
|
|
30
|
+
interface ChatMessageItemData {
|
|
31
|
+
id?: string;
|
|
32
|
+
role: "user" | "assistant";
|
|
33
|
+
content: string | ContentPart[];
|
|
34
|
+
ts?: string;
|
|
35
|
+
toolCalls?: ToolCallEvent[];
|
|
36
|
+
}
|
|
37
|
+
interface ChatMessageProps {
|
|
38
|
+
msg: ChatMessageItemData;
|
|
39
|
+
isLast?: boolean;
|
|
40
|
+
isStreaming?: boolean;
|
|
41
|
+
avatar?: ReactNode;
|
|
42
|
+
agentName?: string;
|
|
43
|
+
streamdownComponents?: StreamdownComponentsProp;
|
|
44
|
+
}
|
|
45
|
+
declare const ChatUserMessage: react.MemoExoticComponent<({ msg, isLast, isStreaming, }: {
|
|
46
|
+
msg: ChatMessageItemData;
|
|
47
|
+
isLast?: boolean;
|
|
48
|
+
isStreaming?: boolean;
|
|
49
|
+
}) => react_jsx_runtime.JSX.Element>;
|
|
50
|
+
declare const ChatAssistantMessage: react.MemoExoticComponent<({ msg, isLast, isStreaming, avatar, agentName, streamdownComponents: components, }: {
|
|
51
|
+
msg: ChatMessageItemData;
|
|
52
|
+
isLast?: boolean;
|
|
53
|
+
isStreaming?: boolean;
|
|
54
|
+
avatar?: ReactNode;
|
|
55
|
+
agentName?: string;
|
|
56
|
+
streamdownComponents?: StreamdownComponentsProp;
|
|
57
|
+
}) => react_jsx_runtime.JSX.Element>;
|
|
58
|
+
declare const ChatMessage: react.MemoExoticComponent<({ msg, isLast, isStreaming, avatar, agentName, streamdownComponents, }: ChatMessageProps) => react_jsx_runtime.JSX.Element>;
|
|
59
|
+
|
|
60
|
+
interface ChatProps {
|
|
61
|
+
/** Session ID — omit for new chats */
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
/** Agent name for completions */
|
|
64
|
+
agent?: string;
|
|
65
|
+
/** Called when a new session is created */
|
|
66
|
+
onSessionCreated?: (sessionId: string) => void;
|
|
67
|
+
/** Called on each stream update (useful for external scroll control) */
|
|
68
|
+
onUpdate?: () => void;
|
|
69
|
+
/** Custom message renderer — if omitted, uses ChatMessage with defaults */
|
|
70
|
+
renderMessage?: (msg: ChatMessageProps["msg"], index: number, isLast: boolean, isStreaming: boolean) => ReactNode;
|
|
71
|
+
/** Avatar ReactNode shown on assistant messages */
|
|
72
|
+
avatar?: ReactNode;
|
|
73
|
+
/** Agent display name shown on assistant messages */
|
|
74
|
+
agentName?: string;
|
|
75
|
+
/** Streamdown components override for code blocks etc. */
|
|
76
|
+
streamdownComponents?: Record<string, unknown>;
|
|
77
|
+
/** Number of skeleton items while loading */
|
|
78
|
+
skeletonCount?: number;
|
|
79
|
+
/** Placeholder text for the default input */
|
|
80
|
+
inputPlaceholder?: string;
|
|
81
|
+
/** Hint text below the default input */
|
|
82
|
+
inputHint?: string;
|
|
83
|
+
/** Whether file attachments are enabled on the default input (default: true) */
|
|
84
|
+
allowAttachments?: boolean;
|
|
85
|
+
/** Children rendered after the message list — replaces the default ChatInput */
|
|
86
|
+
children?: ReactNode;
|
|
87
|
+
/** Additional className on the outer container */
|
|
88
|
+
className?: string;
|
|
89
|
+
}
|
|
90
|
+
declare const Chat: react.ForwardRefExoticComponent<ChatProps & react.RefAttributes<ChatMessagesHandle>>;
|
|
91
|
+
|
|
92
|
+
interface ChatInputProps {
|
|
93
|
+
/** Placeholder text for the textarea */
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
/** Hint text below the input */
|
|
96
|
+
hint?: string;
|
|
97
|
+
/** Whether file attachments are enabled (default: true) */
|
|
98
|
+
allowAttachments?: boolean;
|
|
99
|
+
/** Additional className on the outer wrapper */
|
|
100
|
+
className?: string;
|
|
101
|
+
/** Custom submit button renderer */
|
|
102
|
+
renderSubmit?: (props: {
|
|
103
|
+
isStreaming: boolean;
|
|
104
|
+
onStop: () => void;
|
|
105
|
+
}) => ReactNode;
|
|
106
|
+
}
|
|
107
|
+
declare function ChatInput({ placeholder, hint, allowAttachments, className, renderSubmit, }: ChatInputProps): react_jsx_runtime.JSX.Element;
|
|
108
|
+
|
|
109
|
+
interface ChatProviderProps {
|
|
110
|
+
/** Resume an existing session by ID. */
|
|
111
|
+
sessionId?: string;
|
|
112
|
+
/** Target a specific agent for direct conversation. */
|
|
113
|
+
agent?: string;
|
|
114
|
+
/** Called when a new session is created (first message). */
|
|
115
|
+
onSessionCreated?: (id: string) => void;
|
|
116
|
+
/** Called after each stream update (e.g. scroll-to-bottom). */
|
|
117
|
+
onUpdate?: () => void;
|
|
118
|
+
children: ReactNode;
|
|
119
|
+
}
|
|
120
|
+
interface ChatContextValue extends UseChatReturn {
|
|
121
|
+
/** Upload a file attachment (delegates to useFiles). */
|
|
122
|
+
uploadFile: (destPath: string, file: File | Blob, filename: string) => Promise<{
|
|
123
|
+
uploaded: {
|
|
124
|
+
name: string;
|
|
125
|
+
size: number;
|
|
126
|
+
}[];
|
|
127
|
+
count: number;
|
|
128
|
+
}>;
|
|
129
|
+
/** Whether a file upload is in progress. */
|
|
130
|
+
isUploading: boolean;
|
|
131
|
+
}
|
|
132
|
+
declare function ChatProvider({ sessionId, agent, onSessionCreated, onUpdate, children, }: ChatProviderProps): react_jsx_runtime.JSX.Element;
|
|
133
|
+
declare function useChatContext(): ChatContextValue;
|
|
134
|
+
|
|
135
|
+
declare function ChatTyping({ className }: {
|
|
136
|
+
className?: string;
|
|
137
|
+
}): react_jsx_runtime.JSX.Element;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Skeleton loaders for chat UI — mirrors the exact layout of ChatMessageItem
|
|
141
|
+
* so the loading state feels native, not jarring.
|
|
142
|
+
*/
|
|
143
|
+
/** Skeleton for an AI message: avatar + name + text lines */
|
|
144
|
+
declare function MessageSkeleton({ lines }: {
|
|
145
|
+
lines?: number;
|
|
146
|
+
}): react_jsx_runtime.JSX.Element;
|
|
147
|
+
/** Skeleton for a user message: right-aligned bubble */
|
|
148
|
+
declare function UserMessageSkeleton(): react_jsx_runtime.JSX.Element;
|
|
149
|
+
/** Full conversation skeleton — alternating user/AI messages */
|
|
150
|
+
declare function ChatSkeleton({ count }: {
|
|
151
|
+
count?: number;
|
|
152
|
+
}): react_jsx_runtime.JSX.Element;
|
|
153
|
+
|
|
154
|
+
interface ChatScrollButtonProps {
|
|
155
|
+
isAtBottom: boolean;
|
|
156
|
+
showNewMessage?: boolean;
|
|
157
|
+
onClick: () => void;
|
|
158
|
+
className?: string;
|
|
159
|
+
}
|
|
160
|
+
declare function ChatScrollButton({ isAtBottom, showNewMessage, onClick, className, }: ChatScrollButtonProps): react_jsx_runtime.JSX.Element | null;
|
|
161
|
+
|
|
162
|
+
/** Props that any code-block component must accept. */
|
|
163
|
+
interface CodeBlockComponentProps {
|
|
164
|
+
code: string;
|
|
165
|
+
language: string;
|
|
166
|
+
children?: React.ReactNode;
|
|
167
|
+
}
|
|
168
|
+
/** The shape returned by createStreamdownComponents / the default export. */
|
|
169
|
+
interface StreamdownComponents {
|
|
170
|
+
code: (props: HTMLAttributes<HTMLElement> & {
|
|
171
|
+
node?: unknown;
|
|
172
|
+
"data-block"?: string;
|
|
173
|
+
}) => React.ReactNode;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a `streamdownComponents` override object for Streamdown.
|
|
177
|
+
*
|
|
178
|
+
* Pass your own `CodeBlock` component to get syntax-highlighted fenced
|
|
179
|
+
* code blocks. If omitted, a plain `<pre><code>` fallback is used.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```tsx
|
|
183
|
+
* import { CodeBlock } from "@/components/ai-elements/code-block";
|
|
184
|
+
* import { createStreamdownComponents } from "@polpo-ai/chat";
|
|
185
|
+
*
|
|
186
|
+
* const streamdownComponents = createStreamdownComponents(CodeBlock);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function createStreamdownComponents(CodeBlockComponent?: ComponentType<CodeBlockComponentProps>): StreamdownComponents;
|
|
190
|
+
declare const streamdownComponents: StreamdownComponents;
|
|
191
|
+
|
|
192
|
+
/** Format an ISO timestamp as a human-readable relative time string. */
|
|
193
|
+
declare function relativeTime(iso: string): string;
|
|
194
|
+
|
|
195
|
+
/** Extract the concatenated text from a message content value (string or ContentPart[]). */
|
|
196
|
+
declare function getTextContent(content: string | ContentPart[]): string;
|
|
197
|
+
|
|
198
|
+
export { Chat, ChatAssistantMessage, ChatInput, type ChatInputProps, ChatMessage, type ChatMessageItemData, type ChatMessageProps, ChatMessages, type ChatMessagesHandle, type ChatMessagesProps, type ChatProps, ChatProvider, ChatScrollButton, ChatSkeleton, ChatTyping, ChatUserMessage, MessageSkeleton, UserMessageSkeleton, createStreamdownComponents, getTextContent, relativeTime, streamdownComponents, useChatContext };
|