@nexo-labs/chat-agent 1.8.0 → 1.9.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/react.d.mts +179 -147
- package/dist/react.d.mts.map +1 -1
- package/dist/react.mjs +1318 -1192
- package/dist/react.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -4
- package/src/adapters/ChatAdapter.ts +56 -58
- package/src/adapters/MockAdapter.ts +117 -107
- package/src/adapters/NexoPayloadChatAdapter.ts +260 -223
- package/src/components/ChatHistoryList.tsx +226 -193
- package/src/components/ChatInterface.tsx +13 -32
- package/src/components/ChatMenuDropdown.tsx +27 -15
- package/src/components/DocumentSelector.tsx +49 -40
- package/src/components/FloatingChatManager.tsx +9 -14
- package/src/components/FloatingChatPanel.tsx +73 -74
- package/src/components/SourcesList.tsx +390 -294
- package/src/components/assistant-ui/index.ts +10 -3
- package/src/components/assistant-ui/markdown-text.tsx +9 -9
- package/src/components/assistant-ui/thinking-indicator.tsx +4 -4
- package/src/components/assistant-ui/thread.tsx +369 -385
- package/src/components/buttons/FloatingChatButton.tsx +15 -14
- package/src/components/buttons/ViewMoreLink.tsx +5 -7
- package/src/components/chat-context.tsx +54 -12
- package/src/components/index.ts +2 -2
- package/src/components/useDocumentSelector.ts +92 -83
- package/src/hooks/useAssistantRuntime.ts +157 -152
- package/src/hooks/useChatSession.ts +60 -55
- package/src/hooks/useChunkLoader.ts +19 -25
- package/src/index.ts +2 -2
- package/src/lib/utils.ts +2 -2
- package/src/react.ts +21 -13
- package/src/styles/input.css +11 -6
- package/src/types/components.tsx +10 -2
- package/src/components/UsageDisplay.tsx +0 -112
- package/src/hooks/useChatMessages.ts +0 -317
package/dist/react.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React$1, { ComponentType, FC, ReactNode } from "react";
|
|
2
1
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
import React$1, { ComponentType, FC, ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/ChatAdapter.d.ts
|
|
5
5
|
interface Source {
|
|
6
6
|
id: string;
|
|
7
7
|
title: string;
|
|
8
8
|
slug: string;
|
|
9
|
-
type:
|
|
9
|
+
type: string;
|
|
10
10
|
chunkIndex: number;
|
|
11
11
|
relevanceScore: number;
|
|
12
12
|
content: string;
|
|
@@ -54,7 +54,12 @@ interface StreamCallbacks {
|
|
|
54
54
|
onToken?: (token: string) => void;
|
|
55
55
|
onSources?: (sources: Source[]) => void;
|
|
56
56
|
onDone?: () => void;
|
|
57
|
-
onUsage?: (usage:
|
|
57
|
+
onUsage?: (usage: {
|
|
58
|
+
daily_limit: number;
|
|
59
|
+
daily_used: number;
|
|
60
|
+
daily_remaining: number;
|
|
61
|
+
reset_at: string;
|
|
62
|
+
}) => void;
|
|
58
63
|
onError?: (error: Error) => void;
|
|
59
64
|
}
|
|
60
65
|
interface ChatAdapter {
|
|
@@ -73,111 +78,49 @@ interface ChatAdapter {
|
|
|
73
78
|
getAgents(): Promise<PublicAgentInfo[]>;
|
|
74
79
|
}
|
|
75
80
|
//#endregion
|
|
76
|
-
//#region src/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
conversationId: string | null;
|
|
94
|
-
setConversationId: (id: string | null) => void;
|
|
95
|
-
messages: Message$1[];
|
|
96
|
-
setMessages: React.Dispatch<React.SetStateAction<Message$1[]>>;
|
|
97
|
-
isLoadingSession: boolean;
|
|
98
|
-
handleNewConversation: () => Promise<void>;
|
|
99
|
-
sessionsHistory: SessionSummary[];
|
|
100
|
-
isLoadingHistory: boolean;
|
|
101
|
-
loadHistory: () => Promise<void>;
|
|
102
|
-
loadSession: (conversationId: string) => Promise<void>;
|
|
103
|
-
renameSession: (conversationId: string, newTitle: string) => Promise<boolean>;
|
|
104
|
-
deleteSession: (conversationId: string) => Promise<boolean>;
|
|
81
|
+
//#region src/adapters/MockAdapter.d.ts
|
|
82
|
+
declare class MockAdapter implements ChatAdapter {
|
|
83
|
+
private sessions;
|
|
84
|
+
constructor();
|
|
85
|
+
sendMessage(message: string, context: SendMessageContext, callbacks: StreamCallbacks, signal?: AbortSignal): Promise<void>;
|
|
86
|
+
getActiveSession(): Promise<{
|
|
87
|
+
conversationId: string;
|
|
88
|
+
messages: Message$1[];
|
|
89
|
+
} | null>;
|
|
90
|
+
getHistory(): Promise<SessionSummary[]>;
|
|
91
|
+
loadSession(id: string): Promise<{
|
|
92
|
+
conversationId: string;
|
|
93
|
+
messages: Message$1[];
|
|
94
|
+
} | null>;
|
|
95
|
+
renameSession(id: string, newTitle: string): Promise<boolean>;
|
|
96
|
+
deleteSession(id: string): Promise<boolean>;
|
|
97
|
+
getAgents(): Promise<PublicAgentInfo[]>;
|
|
105
98
|
}
|
|
106
|
-
declare const ChatProvider: ({
|
|
107
|
-
children,
|
|
108
|
-
adapter: customAdapter
|
|
109
|
-
}: {
|
|
110
|
-
children: ReactNode;
|
|
111
|
-
adapter?: ChatAdapter;
|
|
112
|
-
}) => react_jsx_runtime0.JSX.Element;
|
|
113
|
-
declare const useChat: () => ChatContextType;
|
|
114
99
|
//#endregion
|
|
115
|
-
//#region src/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*/
|
|
133
|
-
type LinkComponent = React$1.ComponentType<LinkComponentProps>;
|
|
134
|
-
/**
|
|
135
|
-
* Props for an Image component that can be injected
|
|
136
|
-
* Compatible with next/image and regular <img> tags
|
|
137
|
-
*/
|
|
138
|
-
interface ImageComponentProps {
|
|
139
|
-
src: string;
|
|
140
|
-
alt: string;
|
|
141
|
-
width?: number;
|
|
142
|
-
height?: number;
|
|
143
|
-
className?: string;
|
|
100
|
+
//#region src/adapters/NexoPayloadChatAdapter.d.ts
|
|
101
|
+
declare class NexoPayloadChatAdapter implements ChatAdapter {
|
|
102
|
+
sendMessage(message: string, context: SendMessageContext, callbacks: StreamCallbacks, signal?: AbortSignal): Promise<void>;
|
|
103
|
+
private processStream;
|
|
104
|
+
getActiveSession(): Promise<{
|
|
105
|
+
conversationId: string;
|
|
106
|
+
messages: Message$1[];
|
|
107
|
+
} | null>;
|
|
108
|
+
getHistory(): Promise<SessionSummary[]>;
|
|
109
|
+
loadSession(id: string): Promise<{
|
|
110
|
+
conversationId: string;
|
|
111
|
+
messages: Message$1[];
|
|
112
|
+
} | null>;
|
|
113
|
+
renameSession(id: string, newTitle: string): Promise<boolean>;
|
|
114
|
+
deleteSession(id: string): Promise<boolean>;
|
|
115
|
+
getAgents(): Promise<PublicAgentInfo[]>;
|
|
116
|
+
private parseBackendMessages;
|
|
144
117
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Type for an Image component that can be injected from outside
|
|
147
|
-
* Default fallback is a regular <img> tag
|
|
148
|
-
*/
|
|
149
|
-
type ImageComponent = React$1.ComponentType<ImageComponentProps>;
|
|
150
118
|
//#endregion
|
|
151
|
-
//#region src/components/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
*/
|
|
155
|
-
interface User {
|
|
156
|
-
id: string | number;
|
|
157
|
-
[key: string]: unknown;
|
|
158
|
-
}
|
|
159
|
-
interface FloatingChatManagerProps {
|
|
160
|
-
aiIcon?: string;
|
|
161
|
-
useUser: () => {
|
|
162
|
-
user: User | null;
|
|
163
|
-
};
|
|
164
|
-
generateHref: (props: {
|
|
165
|
-
type: string;
|
|
166
|
-
value: {
|
|
167
|
-
id: number;
|
|
168
|
-
slug?: string | null;
|
|
169
|
-
};
|
|
170
|
-
}) => string;
|
|
171
|
-
LinkComponent?: LinkComponent;
|
|
172
|
-
ImageComponent?: ImageComponent;
|
|
119
|
+
//#region src/components/assistant-ui/markdown-text.d.ts
|
|
120
|
+
interface MarkdownTextProps {
|
|
121
|
+
text: string;
|
|
173
122
|
}
|
|
174
|
-
declare const
|
|
175
|
-
aiIcon,
|
|
176
|
-
useUser,
|
|
177
|
-
generateHref,
|
|
178
|
-
LinkComponent,
|
|
179
|
-
ImageComponent
|
|
180
|
-
}: FloatingChatManagerProps) => react_jsx_runtime0.JSX.Element | null;
|
|
123
|
+
declare const MarkdownText: FC<MarkdownTextProps>;
|
|
181
124
|
//#endregion
|
|
182
125
|
//#region ../../node_modules/.pnpm/@assistant-ui+react@0.11.58_@types+react-dom@19.1.6_@types+react@19.1.8__@types+react@1_1ace430487f19a6261550fadd639952a/node_modules/@assistant-ui/react/dist/types/Unsubscribe.d.ts
|
|
183
126
|
type Unsubscribe = () => void;
|
|
@@ -2246,6 +2189,42 @@ declare global {
|
|
|
2246
2189
|
}
|
|
2247
2190
|
}
|
|
2248
2191
|
//#endregion
|
|
2192
|
+
//#region src/types/components.d.ts
|
|
2193
|
+
/**
|
|
2194
|
+
* Props for a Link component that can be injected
|
|
2195
|
+
* Compatible with next/link and regular <a> tags
|
|
2196
|
+
*/
|
|
2197
|
+
interface LinkComponentProps {
|
|
2198
|
+
href: string;
|
|
2199
|
+
children: React$1.ReactNode;
|
|
2200
|
+
onClick?: () => void;
|
|
2201
|
+
className?: string;
|
|
2202
|
+
target?: string;
|
|
2203
|
+
'aria-label'?: string;
|
|
2204
|
+
title?: string;
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Type for a Link component that can be injected from outside
|
|
2208
|
+
* Default fallback is a regular <a> tag
|
|
2209
|
+
*/
|
|
2210
|
+
type LinkComponent = React$1.ComponentType<LinkComponentProps>;
|
|
2211
|
+
/**
|
|
2212
|
+
* Props for an Image component that can be injected
|
|
2213
|
+
* Compatible with next/image and regular <img> tags
|
|
2214
|
+
*/
|
|
2215
|
+
interface ImageComponentProps {
|
|
2216
|
+
src: string;
|
|
2217
|
+
alt: string;
|
|
2218
|
+
width?: number;
|
|
2219
|
+
height?: number;
|
|
2220
|
+
className?: string;
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Type for an Image component that can be injected from outside
|
|
2224
|
+
* Default fallback is a regular <img> tag
|
|
2225
|
+
*/
|
|
2226
|
+
type ImageComponent = React$1.ComponentType<ImageComponentProps>;
|
|
2227
|
+
//#endregion
|
|
2249
2228
|
//#region src/components/assistant-ui/thread.d.ts
|
|
2250
2229
|
interface ThreadProps {
|
|
2251
2230
|
runtime: ReturnType<typeof useExternalStoreRuntime>;
|
|
@@ -2274,20 +2253,111 @@ declare const Composer: FC;
|
|
|
2274
2253
|
declare const UserMessage: FC;
|
|
2275
2254
|
declare const AssistantMessage: FC;
|
|
2276
2255
|
//#endregion
|
|
2277
|
-
//#region src/components/
|
|
2278
|
-
|
|
2279
|
-
|
|
2256
|
+
//#region src/components/chat-context.d.ts
|
|
2257
|
+
/**
|
|
2258
|
+
* Resolves collection type metadata for UI rendering.
|
|
2259
|
+
* All fields are optional — sensible defaults are applied.
|
|
2260
|
+
*/
|
|
2261
|
+
interface CollectionTypeResolver {
|
|
2262
|
+
/** Human-readable label (e.g. 'posts' → 'Artículo') */
|
|
2263
|
+
label?: (type: string) => string;
|
|
2264
|
+
/** Icon component (e.g. 'books' → <BookOpen />) */
|
|
2265
|
+
icon?: (type: string) => React.ReactNode;
|
|
2266
|
+
/** URL route segment for link generation (e.g. 'posts' → 'articulos') */
|
|
2267
|
+
contentType?: (type: string) => string;
|
|
2268
|
+
/** Typesense chunk collection name (e.g. 'posts' → 'posts_chunk') */
|
|
2269
|
+
chunkCollection?: (type: string) => string;
|
|
2280
2270
|
}
|
|
2281
|
-
|
|
2271
|
+
interface ChatContextType {
|
|
2272
|
+
adapter: ChatAdapter;
|
|
2273
|
+
/** Typesense collection names available for document search */
|
|
2274
|
+
searchCollections: string[];
|
|
2275
|
+
/** Resolved collection type config (with defaults applied) */
|
|
2276
|
+
collectionResolver: Required<CollectionTypeResolver>;
|
|
2277
|
+
isPanelOpen: boolean;
|
|
2278
|
+
isMaximized: boolean;
|
|
2279
|
+
openPanel: () => void;
|
|
2280
|
+
closePanel: () => void;
|
|
2281
|
+
setMaximized: (value: boolean) => void;
|
|
2282
|
+
tokenUsage: TokenUsage | null;
|
|
2283
|
+
isLoadingTokens: boolean;
|
|
2284
|
+
updateTokenUsage: (newUsage: Partial<TokenUsage>) => void;
|
|
2285
|
+
limitError: string | null;
|
|
2286
|
+
setLimitError: (error: string | null) => void;
|
|
2287
|
+
agents: PublicAgentInfo[];
|
|
2288
|
+
selectedAgent: string | null;
|
|
2289
|
+
setSelectedAgent: (slug: string) => void;
|
|
2290
|
+
isLoadingAgents: boolean;
|
|
2291
|
+
conversationId: string | null;
|
|
2292
|
+
setConversationId: (id: string | null) => void;
|
|
2293
|
+
messages: Message$1[];
|
|
2294
|
+
setMessages: React.Dispatch<React.SetStateAction<Message$1[]>>;
|
|
2295
|
+
isLoadingSession: boolean;
|
|
2296
|
+
handleNewConversation: () => Promise<void>;
|
|
2297
|
+
sessionsHistory: SessionSummary[];
|
|
2298
|
+
isLoadingHistory: boolean;
|
|
2299
|
+
loadHistory: () => Promise<void>;
|
|
2300
|
+
loadSession: (conversationId: string) => Promise<void>;
|
|
2301
|
+
renameSession: (conversationId: string, newTitle: string) => Promise<boolean>;
|
|
2302
|
+
deleteSession: (conversationId: string) => Promise<boolean>;
|
|
2303
|
+
}
|
|
2304
|
+
interface ChatProviderProps {
|
|
2305
|
+
children: ReactNode;
|
|
2306
|
+
adapter?: ChatAdapter;
|
|
2307
|
+
/** Typesense collection names available for document search */
|
|
2308
|
+
searchCollections?: string[];
|
|
2309
|
+
/** Collection type resolver for UI labels, icons, and URL mapping */
|
|
2310
|
+
collectionResolver?: CollectionTypeResolver;
|
|
2311
|
+
}
|
|
2312
|
+
declare const ChatProvider: ({
|
|
2313
|
+
children,
|
|
2314
|
+
adapter: customAdapter,
|
|
2315
|
+
searchCollections,
|
|
2316
|
+
collectionResolver: customResolver
|
|
2317
|
+
}: ChatProviderProps) => react_jsx_runtime0.JSX.Element;
|
|
2318
|
+
declare const useChat: () => ChatContextType;
|
|
2282
2319
|
//#endregion
|
|
2283
|
-
//#region src/
|
|
2320
|
+
//#region src/components/FloatingChatManager.d.ts
|
|
2321
|
+
/**
|
|
2322
|
+
* Minimal user type - consumer provides their own user type
|
|
2323
|
+
*/
|
|
2324
|
+
interface User {
|
|
2325
|
+
id: string | number;
|
|
2326
|
+
[key: string]: unknown;
|
|
2327
|
+
}
|
|
2328
|
+
interface FloatingChatManagerProps {
|
|
2329
|
+
aiIcon?: string;
|
|
2330
|
+
useUser: () => {
|
|
2331
|
+
user: User | null;
|
|
2332
|
+
};
|
|
2333
|
+
generateHref: (props: {
|
|
2334
|
+
type: string;
|
|
2335
|
+
value: {
|
|
2336
|
+
id: number;
|
|
2337
|
+
slug?: string | null;
|
|
2338
|
+
};
|
|
2339
|
+
}) => string;
|
|
2340
|
+
LinkComponent?: LinkComponent;
|
|
2341
|
+
ImageComponent?: ImageComponent;
|
|
2342
|
+
}
|
|
2343
|
+
declare const FloatingChatManager: ({
|
|
2344
|
+
aiIcon,
|
|
2345
|
+
useUser,
|
|
2346
|
+
generateHref,
|
|
2347
|
+
LinkComponent,
|
|
2348
|
+
ImageComponent
|
|
2349
|
+
}: FloatingChatManagerProps) => react_jsx_runtime0.JSX.Element | null;
|
|
2350
|
+
//#endregion
|
|
2351
|
+
//#region src/components/useDocumentSelector.d.ts
|
|
2284
2352
|
interface Document {
|
|
2285
2353
|
id: string;
|
|
2286
2354
|
title: string;
|
|
2287
2355
|
slug: string;
|
|
2288
|
-
type:
|
|
2356
|
+
type: string;
|
|
2289
2357
|
collection: string;
|
|
2290
2358
|
}
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region src/hooks/useAssistantRuntime.d.ts
|
|
2291
2361
|
interface UseAssistantRuntimeProps {
|
|
2292
2362
|
messages: Message$1[];
|
|
2293
2363
|
setMessages: React.Dispatch<React.SetStateAction<Message$1[]>>;
|
|
@@ -2308,43 +2378,5 @@ declare function useAssistantRuntime({
|
|
|
2308
2378
|
selectedAgent
|
|
2309
2379
|
}: UseAssistantRuntimeProps): AssistantRuntime;
|
|
2310
2380
|
//#endregion
|
|
2311
|
-
//#region src/adapters/NexoPayloadChatAdapter.d.ts
|
|
2312
|
-
declare class NexoPayloadChatAdapter implements ChatAdapter {
|
|
2313
|
-
sendMessage(message: string, context: SendMessageContext, callbacks: StreamCallbacks, signal?: AbortSignal): Promise<void>;
|
|
2314
|
-
private processStream;
|
|
2315
|
-
getActiveSession(): Promise<{
|
|
2316
|
-
conversationId: string;
|
|
2317
|
-
messages: Message$1[];
|
|
2318
|
-
} | null>;
|
|
2319
|
-
getHistory(): Promise<SessionSummary[]>;
|
|
2320
|
-
loadSession(id: string): Promise<{
|
|
2321
|
-
conversationId: string;
|
|
2322
|
-
messages: Message$1[];
|
|
2323
|
-
} | null>;
|
|
2324
|
-
renameSession(id: string, newTitle: string): Promise<boolean>;
|
|
2325
|
-
deleteSession(id: string): Promise<boolean>;
|
|
2326
|
-
getAgents(): Promise<PublicAgentInfo[]>;
|
|
2327
|
-
private parseBackendMessages;
|
|
2328
|
-
}
|
|
2329
|
-
//#endregion
|
|
2330
|
-
//#region src/adapters/MockAdapter.d.ts
|
|
2331
|
-
declare class MockAdapter implements ChatAdapter {
|
|
2332
|
-
private sessions;
|
|
2333
|
-
constructor();
|
|
2334
|
-
sendMessage(message: string, context: SendMessageContext, callbacks: StreamCallbacks, signal?: AbortSignal): Promise<void>;
|
|
2335
|
-
getActiveSession(): Promise<{
|
|
2336
|
-
conversationId: string;
|
|
2337
|
-
messages: Message$1[];
|
|
2338
|
-
} | null>;
|
|
2339
|
-
getHistory(): Promise<SessionSummary[]>;
|
|
2340
|
-
loadSession(id: string): Promise<{
|
|
2341
|
-
conversationId: string;
|
|
2342
|
-
messages: Message$1[];
|
|
2343
|
-
} | null>;
|
|
2344
|
-
renameSession(id: string, newTitle: string): Promise<boolean>;
|
|
2345
|
-
deleteSession(id: string): Promise<boolean>;
|
|
2346
|
-
getAgents(): Promise<PublicAgentInfo[]>;
|
|
2347
|
-
}
|
|
2348
|
-
//#endregion
|
|
2349
2381
|
export { AssistantMessage, type ChatAdapter, ChatProvider, Composer, FloatingChatManager, MarkdownText, type Message$1 as Message, MockAdapter, NexoPayloadChatAdapter, type SessionSummary, type Source, type StreamCallbacks, Thread, UserMessage, useAssistantRuntime, useChat };
|
|
2350
2382
|
//# sourceMappingURL=react.d.mts.map
|