telygent-ui 0.1.7 → 0.1.8
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
CHANGED
|
@@ -18,9 +18,9 @@ import {ChatProvider, type SendMessageInput, type SendMessageResult, type ChatMe
|
|
|
18
18
|
import {ChatInterface} from "@/components/ai/ChatInterface";
|
|
19
19
|
|
|
20
20
|
const adapter = {
|
|
21
|
-
async sendMessage({message, conversationId}: SendMessageInput): Promise<SendMessageResult> {
|
|
21
|
+
async sendMessage({message, conversationId, messageContext}: SendMessageInput): Promise<SendMessageResult> {
|
|
22
22
|
// Use React Query, Axios, RTK Query, etc.
|
|
23
|
-
const response = await api.send({message, conversationId});
|
|
23
|
+
const response = await api.send({message, conversationId, messageContext});
|
|
24
24
|
return {
|
|
25
25
|
conversationId: response.conversationId,
|
|
26
26
|
message: {
|
|
@@ -45,9 +45,10 @@ const adapter = {
|
|
|
45
45
|
|
|
46
46
|
export default function Page() {
|
|
47
47
|
const conversationId = "your-conversation-id";
|
|
48
|
+
const messageContext = "Viewing document id: 3283823883";
|
|
48
49
|
return (
|
|
49
50
|
<ChatProvider adapter={adapter}>
|
|
50
|
-
<ChatInterface conversationId={conversationId} aiName="Telygent" />
|
|
51
|
+
<ChatInterface conversationId={conversationId} aiName="Telygent" messageContext={messageContext} />
|
|
51
52
|
</ChatProvider>
|
|
52
53
|
);
|
|
53
54
|
}
|
|
@@ -68,6 +69,7 @@ async function* streamChat(input: SendMessageInput): AsyncIterable<ChatStreamEve
|
|
|
68
69
|
body: JSON.stringify({
|
|
69
70
|
question: input.message,
|
|
70
71
|
conversationId: input.conversationId,
|
|
72
|
+
messageContext: input.messageContext,
|
|
71
73
|
}),
|
|
72
74
|
});
|
|
73
75
|
|
|
@@ -111,7 +113,7 @@ const adapter = {
|
|
|
111
113
|
export default function Page() {
|
|
112
114
|
return (
|
|
113
115
|
<ChatProvider adapter={adapter}>
|
|
114
|
-
<ChatInterface conversationId="conv_123" />
|
|
116
|
+
<ChatInterface conversationId="conv_123" messageContext="Viewing transaction id: txn_123" />
|
|
115
117
|
</ChatProvider>
|
|
116
118
|
);
|
|
117
119
|
}
|
package/package.json
CHANGED
|
@@ -385,7 +385,7 @@ UserMessageBody.displayName = "UserMessageBody";
|
|
|
385
385
|
|
|
386
386
|
export type ChatInterfaceProps = {
|
|
387
387
|
className?: string;
|
|
388
|
-
|
|
388
|
+
messageContext?: string;
|
|
389
389
|
placeholder?: string;
|
|
390
390
|
defaultPrompts?: {label: string; accent?: string}[];
|
|
391
391
|
conversationId: string;
|
|
@@ -396,7 +396,7 @@ export type ChatInterfaceProps = {
|
|
|
396
396
|
|
|
397
397
|
export function ChatInterface({
|
|
398
398
|
className,
|
|
399
|
-
|
|
399
|
+
messageContext,
|
|
400
400
|
placeholder,
|
|
401
401
|
defaultPrompts,
|
|
402
402
|
conversationId,
|
|
@@ -413,7 +413,7 @@ export function ChatInterface({
|
|
|
413
413
|
loading,
|
|
414
414
|
loadingHistory,
|
|
415
415
|
prompts,
|
|
416
|
-
} = useDatabaseChat({
|
|
416
|
+
} = useDatabaseChat({messageContext, defaultPrompts, conversationId});
|
|
417
417
|
|
|
418
418
|
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
419
419
|
const scrollRef = React.useRef<HTMLDivElement>(null);
|
|
@@ -620,10 +620,10 @@ export function ChatInterface({
|
|
|
620
620
|
</div>
|
|
621
621
|
|
|
622
622
|
<div className="border-t border-slate-200 bg-white px-6 py-4">
|
|
623
|
-
{
|
|
623
|
+
{messageContext ? (
|
|
624
624
|
<div className="mb-2 flex w-6/12">
|
|
625
625
|
<div className="truncate rounded-full border border-[dodgerblue] bg-[dodgerblue]/10 px-2 text-xs">
|
|
626
|
-
{
|
|
626
|
+
{messageContext}
|
|
627
627
|
</div>
|
|
628
628
|
</div>
|
|
629
629
|
) : null}
|
|
@@ -5,12 +5,12 @@ import {useChatAdapter, type ChatMessage, type ChatStreamEvent} from "../compone
|
|
|
5
5
|
|
|
6
6
|
export type UseDatabaseChatOptions = {
|
|
7
7
|
conversationId: string;
|
|
8
|
-
|
|
8
|
+
messageContext?: string;
|
|
9
9
|
defaultPrompts?: {label: string; accent?: string}[];
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export function useDatabaseChat(options: UseDatabaseChatOptions) {
|
|
13
|
-
const {conversationId: initialConversationId,
|
|
13
|
+
const {conversationId: initialConversationId, messageContext, defaultPrompts} = options;
|
|
14
14
|
const adapter = useChatAdapter();
|
|
15
15
|
|
|
16
16
|
const [conversationId] = React.useState<string>(initialConversationId);
|
|
@@ -74,7 +74,6 @@ export function useDatabaseChat(options: UseDatabaseChatOptions) {
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const withContext = `${viewContext ?? ""} ${outgoing}`.trim();
|
|
78
77
|
addMessage({role: "user", content: outgoing, createdAt: new Date()});
|
|
79
78
|
setMessage("");
|
|
80
79
|
|
|
@@ -93,9 +92,9 @@ export function useDatabaseChat(options: UseDatabaseChatOptions) {
|
|
|
93
92
|
|
|
94
93
|
const stream =
|
|
95
94
|
(await adapter.sendMessageStream({
|
|
96
|
-
message:
|
|
95
|
+
message: outgoing,
|
|
97
96
|
conversationId,
|
|
98
|
-
|
|
97
|
+
messageContext,
|
|
99
98
|
})) as AsyncIterable<ChatStreamEvent>;
|
|
100
99
|
|
|
101
100
|
for await (const event of stream) {
|
|
@@ -135,9 +134,9 @@ export function useDatabaseChat(options: UseDatabaseChatOptions) {
|
|
|
135
134
|
}
|
|
136
135
|
} else {
|
|
137
136
|
const result = await adapter.sendMessage({
|
|
138
|
-
message:
|
|
137
|
+
message: outgoing,
|
|
139
138
|
conversationId,
|
|
140
|
-
|
|
139
|
+
messageContext,
|
|
141
140
|
});
|
|
142
141
|
addMessage(result.message);
|
|
143
142
|
}
|
|
@@ -145,7 +144,7 @@ export function useDatabaseChat(options: UseDatabaseChatOptions) {
|
|
|
145
144
|
setLoading(false);
|
|
146
145
|
}
|
|
147
146
|
},
|
|
148
|
-
[adapter, addMessage, conversationId, message,
|
|
147
|
+
[adapter, addMessage, conversationId, message, messageContext]
|
|
149
148
|
);
|
|
150
149
|
|
|
151
150
|
return {
|