reachat 2.1.2 → 2.2.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/dist/{CSVFileRenderer-DXI8PDqR.js → CSVFileRenderer-BOdL4Jte.js} +2 -2
- package/dist/{CSVFileRenderer-DXI8PDqR.js.map → CSVFileRenderer-BOdL4Jte.js.map} +1 -1
- package/dist/{DefaultFileRenderer-Bi8LNDio.js → DefaultFileRenderer-C2MsQ9wz.js} +3 -3
- package/dist/{DefaultFileRenderer-Bi8LNDio.js.map → DefaultFileRenderer-C2MsQ9wz.js.map} +1 -1
- package/dist/Markdown/plugins/index.d.ts +2 -0
- package/dist/Markdown/plugins/redactMatchers.d.ts +21 -0
- package/dist/Markdown/plugins/remarkRedact.d.ts +37 -0
- package/dist/SessionMessages/SessionMessage/MessageActions.d.ts +2 -2
- package/dist/SessionMessages/SessionMessage/MessageFiles.d.ts +2 -2
- package/dist/SessionMessages/SessionMessage/MessageQuestion.d.ts +2 -2
- package/dist/SessionMessages/SessionMessage/MessageResponse.d.ts +2 -2
- package/dist/SessionMessages/SessionMessage/MessageSources.d.ts +2 -2
- package/dist/SessionMessages/SessionMessage/SessionMessage.d.ts +2 -2
- package/dist/SessionsList/SessionListItem.d.ts +2 -2
- package/dist/docs.json +5 -13
- package/dist/{index-CBHNcMyR.js → index-DdRyk11n.js} +783 -1458
- package/dist/index-DdRyk11n.js.map +1 -0
- package/dist/index.css +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -46
- package/dist/index.umd.cjs +735 -1412
- package/dist/index.umd.cjs.map +1 -1
- package/dist/stories/AgUi.stories.tsx +118 -0
- package/dist/stories/Chat.stories.tsx +6 -1
- package/dist/stories/ChatSuggestions.stories.tsx +9 -81
- package/dist/stories/Companion.stories.tsx +7 -1
- package/dist/stories/Console.stories.tsx +66 -21
- package/dist/stories/EnhancedInput.stories.tsx +7 -1
- package/dist/stories/Redact.stories.tsx +175 -0
- package/dist/stories/examples.ts +31 -0
- package/dist/useAgUi/index.d.ts +4 -0
- package/dist/useAgUi/types.d.ts +157 -0
- package/dist/useAgUi/useAgUi.d.ts +119 -0
- package/dist/useAgUi/useAgUi.spec.d.ts +1 -0
- package/package.json +3 -1
- package/dist/index-CBHNcMyR.js.map +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import {
|
|
3
|
+
Chat,
|
|
4
|
+
SessionMessages,
|
|
5
|
+
ChatInput,
|
|
6
|
+
SessionMessagePanel,
|
|
7
|
+
SessionsList,
|
|
8
|
+
NewSessionButton,
|
|
9
|
+
SessionGroups,
|
|
10
|
+
SessionMessagesHeader,
|
|
11
|
+
Session,
|
|
12
|
+
remarkRedact,
|
|
13
|
+
commonRedactMatchers
|
|
14
|
+
} from 'reachat';
|
|
15
|
+
import { subHours } from 'date-fns';
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
title: 'Demos/Redact',
|
|
19
|
+
component: Chat
|
|
20
|
+
} as Meta;
|
|
21
|
+
|
|
22
|
+
export const RedactExample = () => {
|
|
23
|
+
const markdownQuestion = `# User Information
|
|
24
|
+
|
|
25
|
+
Please help me with the following sensitive data:
|
|
26
|
+
|
|
27
|
+
- My SSN is 123-45-6789
|
|
28
|
+
- Credit card: 4532-1234-5678-9010
|
|
29
|
+
- Bitcoin address: 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
|
|
30
|
+
|
|
31
|
+
Can you help me process this information?`;
|
|
32
|
+
|
|
33
|
+
const markdownResponse = `## Analysis
|
|
34
|
+
|
|
35
|
+
I can see you've provided:
|
|
36
|
+
- SSN: 123-45-6789
|
|
37
|
+
- Credit Card: 4532-1234-5678-9010
|
|
38
|
+
- Bitcoin: 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
|
|
39
|
+
|
|
40
|
+
**Note:** All sensitive information has been automatically redacted in the UI for your security.`;
|
|
41
|
+
|
|
42
|
+
const sessionWithRedaction: Session[] = [
|
|
43
|
+
{
|
|
44
|
+
id: 'session-redact',
|
|
45
|
+
title: 'Redaction Showcase',
|
|
46
|
+
createdAt: subHours(new Date(), 1),
|
|
47
|
+
updatedAt: new Date(),
|
|
48
|
+
conversations: [
|
|
49
|
+
{
|
|
50
|
+
id: 'conversation-1',
|
|
51
|
+
question: markdownQuestion,
|
|
52
|
+
response: markdownResponse,
|
|
53
|
+
createdAt: new Date()
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
className="dark:bg-gray-950 bg-white"
|
|
62
|
+
style={{
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
top: 0,
|
|
65
|
+
left: 0,
|
|
66
|
+
right: 0,
|
|
67
|
+
bottom: 0,
|
|
68
|
+
padding: 20,
|
|
69
|
+
margin: 20,
|
|
70
|
+
borderRadius: 5
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<Chat
|
|
74
|
+
viewType="console"
|
|
75
|
+
sessions={sessionWithRedaction}
|
|
76
|
+
activeSessionId="session-redact"
|
|
77
|
+
remarkPlugins={[remarkRedact(commonRedactMatchers)]}
|
|
78
|
+
>
|
|
79
|
+
<SessionsList>
|
|
80
|
+
<NewSessionButton />
|
|
81
|
+
<SessionGroups />
|
|
82
|
+
</SessionsList>
|
|
83
|
+
|
|
84
|
+
<SessionMessagePanel>
|
|
85
|
+
<SessionMessagesHeader />
|
|
86
|
+
<SessionMessages />
|
|
87
|
+
<ChatInput />
|
|
88
|
+
</SessionMessagePanel>
|
|
89
|
+
</Chat>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const CustomMatchers = () => {
|
|
95
|
+
const markdownQuestion = `# Custom Redaction
|
|
96
|
+
|
|
97
|
+
This example shows custom matchers:
|
|
98
|
+
|
|
99
|
+
- Email: test@example.com
|
|
100
|
+
- Phone: (555) 123-4567
|
|
101
|
+
- Custom pattern: SECRET-12345`;
|
|
102
|
+
|
|
103
|
+
const markdownResponse = `I can see you've provided:
|
|
104
|
+
- Email: test@example.com
|
|
105
|
+
- Phone: (555) 123-4567
|
|
106
|
+
- Custom: SECRET-12345`;
|
|
107
|
+
|
|
108
|
+
// Custom matchers using the new pattern-based API
|
|
109
|
+
const customMatchers = [
|
|
110
|
+
{
|
|
111
|
+
name: 'Email',
|
|
112
|
+
pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'Phone',
|
|
116
|
+
pattern: /\b\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'Secret Code',
|
|
120
|
+
pattern: /\bSECRET-\d+\b/g
|
|
121
|
+
},
|
|
122
|
+
...commonRedactMatchers
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const sessionWithCustom: Session[] = [
|
|
126
|
+
{
|
|
127
|
+
id: 'session-custom',
|
|
128
|
+
title: 'Custom Matchers',
|
|
129
|
+
createdAt: subHours(new Date(), 1),
|
|
130
|
+
updatedAt: new Date(),
|
|
131
|
+
conversations: [
|
|
132
|
+
{
|
|
133
|
+
id: 'conversation-1',
|
|
134
|
+
question: markdownQuestion,
|
|
135
|
+
response: markdownResponse,
|
|
136
|
+
createdAt: new Date()
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
className="dark:bg-gray-950 bg-white"
|
|
145
|
+
style={{
|
|
146
|
+
position: 'absolute',
|
|
147
|
+
top: 0,
|
|
148
|
+
left: 0,
|
|
149
|
+
right: 0,
|
|
150
|
+
bottom: 0,
|
|
151
|
+
padding: 20,
|
|
152
|
+
margin: 20,
|
|
153
|
+
borderRadius: 5
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<Chat
|
|
157
|
+
viewType="console"
|
|
158
|
+
sessions={sessionWithCustom}
|
|
159
|
+
activeSessionId="session-custom"
|
|
160
|
+
remarkPlugins={[remarkRedact(customMatchers)]}
|
|
161
|
+
>
|
|
162
|
+
<SessionsList>
|
|
163
|
+
<NewSessionButton />
|
|
164
|
+
<SessionGroups />
|
|
165
|
+
</SessionsList>
|
|
166
|
+
|
|
167
|
+
<SessionMessagePanel>
|
|
168
|
+
<SessionMessagesHeader />
|
|
169
|
+
<SessionMessages />
|
|
170
|
+
<ChatInput />
|
|
171
|
+
</SessionMessagePanel>
|
|
172
|
+
</Chat>
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
};
|
package/dist/stories/examples.ts
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
1
2
|
import { Session } from '@/types';
|
|
2
3
|
import { subHours } from 'date-fns';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Creates an onSendMessage handler for story demos.
|
|
7
|
+
* Appends a new conversation with a canned response to the active session.
|
|
8
|
+
*/
|
|
9
|
+
export const createSendMessageHandler = (
|
|
10
|
+
setSessions: Dispatch<SetStateAction<Session[]>>,
|
|
11
|
+
activeId: string | undefined
|
|
12
|
+
) => (message: string) => {
|
|
13
|
+
if (!activeId) return;
|
|
14
|
+
|
|
15
|
+
setSessions(prev =>
|
|
16
|
+
prev.map(session =>
|
|
17
|
+
session.id === activeId
|
|
18
|
+
? {
|
|
19
|
+
...session,
|
|
20
|
+
conversations: [
|
|
21
|
+
...session.conversations,
|
|
22
|
+
{
|
|
23
|
+
id: Date.now().toString(),
|
|
24
|
+
question: message,
|
|
25
|
+
response: 'This is a response to your question.',
|
|
26
|
+
createdAt: new Date()
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
: session
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
4
35
|
export const fakeSessions: Session[] = [
|
|
5
36
|
{
|
|
6
37
|
id: '1',
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { useAgUi } from './useAgUi';
|
|
2
|
+
export type { UseAgUiOptions, UseAgUiReturn } from './useAgUi';
|
|
3
|
+
export { AgUiEventType } from './types';
|
|
4
|
+
export type { AgUiEvent, AgUiBaseEvent, AgUiRunStartedEvent, AgUiRunFinishedEvent, AgUiRunErrorEvent, AgUiStepStartedEvent, AgUiStepFinishedEvent, AgUiTextMessageStartEvent, AgUiTextMessageContentEvent, AgUiTextMessageEndEvent, AgUiTextMessageChunkEvent, AgUiToolCallStartEvent, AgUiToolCallArgsEvent, AgUiToolCallEndEvent, AgUiToolCallResultEvent, AgUiToolCallChunkEvent, AgUiStateSnapshotEvent, AgUiStateDeltaEvent, AgUiMessagesSnapshotEvent, AgUiRawEvent, AgUiCustomEvent, AgUiToolCallInfo, AgUiMessage, AgUiTool, AgUiContext, AgUiRunAgentInput, AgUiRole } from './types';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AG-UI Protocol event types and interfaces.
|
|
3
|
+
*
|
|
4
|
+
* These are self-contained type definitions for the AG-UI protocol,
|
|
5
|
+
* so consumers don't need to install @ag-ui/core separately.
|
|
6
|
+
* See: https://docs.ag-ui.com
|
|
7
|
+
*/
|
|
8
|
+
export declare enum AgUiEventType {
|
|
9
|
+
RUN_STARTED = "RUN_STARTED",
|
|
10
|
+
RUN_FINISHED = "RUN_FINISHED",
|
|
11
|
+
RUN_ERROR = "RUN_ERROR",
|
|
12
|
+
STEP_STARTED = "STEP_STARTED",
|
|
13
|
+
STEP_FINISHED = "STEP_FINISHED",
|
|
14
|
+
TEXT_MESSAGE_START = "TEXT_MESSAGE_START",
|
|
15
|
+
TEXT_MESSAGE_CONTENT = "TEXT_MESSAGE_CONTENT",
|
|
16
|
+
TEXT_MESSAGE_END = "TEXT_MESSAGE_END",
|
|
17
|
+
TEXT_MESSAGE_CHUNK = "TEXT_MESSAGE_CHUNK",
|
|
18
|
+
TOOL_CALL_START = "TOOL_CALL_START",
|
|
19
|
+
TOOL_CALL_ARGS = "TOOL_CALL_ARGS",
|
|
20
|
+
TOOL_CALL_END = "TOOL_CALL_END",
|
|
21
|
+
TOOL_CALL_RESULT = "TOOL_CALL_RESULT",
|
|
22
|
+
TOOL_CALL_CHUNK = "TOOL_CALL_CHUNK",
|
|
23
|
+
STATE_SNAPSHOT = "STATE_SNAPSHOT",
|
|
24
|
+
STATE_DELTA = "STATE_DELTA",
|
|
25
|
+
MESSAGES_SNAPSHOT = "MESSAGES_SNAPSHOT",
|
|
26
|
+
RAW = "RAW",
|
|
27
|
+
CUSTOM = "CUSTOM"
|
|
28
|
+
}
|
|
29
|
+
export interface AgUiBaseEvent {
|
|
30
|
+
type: AgUiEventType;
|
|
31
|
+
timestamp?: number;
|
|
32
|
+
rawEvent?: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface AgUiRunStartedEvent extends AgUiBaseEvent {
|
|
35
|
+
type: AgUiEventType.RUN_STARTED;
|
|
36
|
+
threadId: string;
|
|
37
|
+
runId: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AgUiRunFinishedEvent extends AgUiBaseEvent {
|
|
40
|
+
type: AgUiEventType.RUN_FINISHED;
|
|
41
|
+
threadId: string;
|
|
42
|
+
runId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AgUiRunErrorEvent extends AgUiBaseEvent {
|
|
45
|
+
type: AgUiEventType.RUN_ERROR;
|
|
46
|
+
message: string;
|
|
47
|
+
code?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface AgUiStepStartedEvent extends AgUiBaseEvent {
|
|
50
|
+
type: AgUiEventType.STEP_STARTED;
|
|
51
|
+
stepName: string;
|
|
52
|
+
}
|
|
53
|
+
export interface AgUiStepFinishedEvent extends AgUiBaseEvent {
|
|
54
|
+
type: AgUiEventType.STEP_FINISHED;
|
|
55
|
+
stepName: string;
|
|
56
|
+
}
|
|
57
|
+
export interface AgUiTextMessageStartEvent extends AgUiBaseEvent {
|
|
58
|
+
type: AgUiEventType.TEXT_MESSAGE_START;
|
|
59
|
+
messageId: string;
|
|
60
|
+
role?: AgUiRole;
|
|
61
|
+
}
|
|
62
|
+
export interface AgUiTextMessageContentEvent extends AgUiBaseEvent {
|
|
63
|
+
type: AgUiEventType.TEXT_MESSAGE_CONTENT;
|
|
64
|
+
messageId: string;
|
|
65
|
+
delta: string;
|
|
66
|
+
}
|
|
67
|
+
export interface AgUiTextMessageEndEvent extends AgUiBaseEvent {
|
|
68
|
+
type: AgUiEventType.TEXT_MESSAGE_END;
|
|
69
|
+
messageId: string;
|
|
70
|
+
}
|
|
71
|
+
export interface AgUiTextMessageChunkEvent extends AgUiBaseEvent {
|
|
72
|
+
type: AgUiEventType.TEXT_MESSAGE_CHUNK;
|
|
73
|
+
messageId?: string;
|
|
74
|
+
role?: AgUiRole;
|
|
75
|
+
delta?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface AgUiToolCallStartEvent extends AgUiBaseEvent {
|
|
78
|
+
type: AgUiEventType.TOOL_CALL_START;
|
|
79
|
+
toolCallId: string;
|
|
80
|
+
toolCallName: string;
|
|
81
|
+
parentMessageId?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface AgUiToolCallArgsEvent extends AgUiBaseEvent {
|
|
84
|
+
type: AgUiEventType.TOOL_CALL_ARGS;
|
|
85
|
+
toolCallId: string;
|
|
86
|
+
delta: string;
|
|
87
|
+
}
|
|
88
|
+
export interface AgUiToolCallEndEvent extends AgUiBaseEvent {
|
|
89
|
+
type: AgUiEventType.TOOL_CALL_END;
|
|
90
|
+
toolCallId: string;
|
|
91
|
+
}
|
|
92
|
+
export interface AgUiToolCallResultEvent extends AgUiBaseEvent {
|
|
93
|
+
type: AgUiEventType.TOOL_CALL_RESULT;
|
|
94
|
+
toolCallId: string;
|
|
95
|
+
content: string;
|
|
96
|
+
}
|
|
97
|
+
export interface AgUiToolCallChunkEvent extends AgUiBaseEvent {
|
|
98
|
+
type: AgUiEventType.TOOL_CALL_CHUNK;
|
|
99
|
+
toolCallId?: string;
|
|
100
|
+
toolCallName?: string;
|
|
101
|
+
parentMessageId?: string;
|
|
102
|
+
delta?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface AgUiStateSnapshotEvent extends AgUiBaseEvent {
|
|
105
|
+
type: AgUiEventType.STATE_SNAPSHOT;
|
|
106
|
+
snapshot: unknown;
|
|
107
|
+
}
|
|
108
|
+
export interface AgUiStateDeltaEvent extends AgUiBaseEvent {
|
|
109
|
+
type: AgUiEventType.STATE_DELTA;
|
|
110
|
+
delta: unknown[];
|
|
111
|
+
}
|
|
112
|
+
export interface AgUiMessagesSnapshotEvent extends AgUiBaseEvent {
|
|
113
|
+
type: AgUiEventType.MESSAGES_SNAPSHOT;
|
|
114
|
+
messages: AgUiMessage[];
|
|
115
|
+
}
|
|
116
|
+
export interface AgUiRawEvent extends AgUiBaseEvent {
|
|
117
|
+
type: AgUiEventType.RAW;
|
|
118
|
+
event: unknown;
|
|
119
|
+
source?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface AgUiCustomEvent extends AgUiBaseEvent {
|
|
122
|
+
type: AgUiEventType.CUSTOM;
|
|
123
|
+
name: string;
|
|
124
|
+
value: unknown;
|
|
125
|
+
}
|
|
126
|
+
export type AgUiEvent = AgUiRunStartedEvent | AgUiRunFinishedEvent | AgUiRunErrorEvent | AgUiStepStartedEvent | AgUiStepFinishedEvent | AgUiTextMessageStartEvent | AgUiTextMessageContentEvent | AgUiTextMessageEndEvent | AgUiTextMessageChunkEvent | AgUiToolCallStartEvent | AgUiToolCallArgsEvent | AgUiToolCallEndEvent | AgUiToolCallResultEvent | AgUiToolCallChunkEvent | AgUiStateSnapshotEvent | AgUiStateDeltaEvent | AgUiMessagesSnapshotEvent | AgUiRawEvent | AgUiCustomEvent;
|
|
127
|
+
export type AgUiRole = 'developer' | 'system' | 'assistant' | 'user' | 'tool';
|
|
128
|
+
export interface AgUiMessage {
|
|
129
|
+
id: string;
|
|
130
|
+
role: AgUiRole;
|
|
131
|
+
content?: string;
|
|
132
|
+
name?: string;
|
|
133
|
+
toolCallId?: string;
|
|
134
|
+
}
|
|
135
|
+
export interface AgUiTool {
|
|
136
|
+
name: string;
|
|
137
|
+
description: string;
|
|
138
|
+
parameters: Record<string, unknown>;
|
|
139
|
+
}
|
|
140
|
+
export interface AgUiContext {
|
|
141
|
+
description: string;
|
|
142
|
+
value: string;
|
|
143
|
+
}
|
|
144
|
+
export interface AgUiRunAgentInput {
|
|
145
|
+
threadId: string;
|
|
146
|
+
runId: string;
|
|
147
|
+
messages: AgUiMessage[];
|
|
148
|
+
tools: AgUiTool[];
|
|
149
|
+
context: AgUiContext[];
|
|
150
|
+
state: unknown;
|
|
151
|
+
forwardedProps: Record<string, unknown>;
|
|
152
|
+
}
|
|
153
|
+
export interface AgUiToolCallInfo {
|
|
154
|
+
toolCallId: string;
|
|
155
|
+
toolCallName: string;
|
|
156
|
+
args: string;
|
|
157
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Session, Conversation } from '../types';
|
|
2
|
+
import { AgUiEvent, AgUiContext, AgUiMessage, AgUiTool, AgUiToolCallInfo } from './types';
|
|
3
|
+
export interface UseAgUiOptions {
|
|
4
|
+
/**
|
|
5
|
+
* URL of the AG-UI compatible agent endpoint.
|
|
6
|
+
*/
|
|
7
|
+
agent: string;
|
|
8
|
+
/**
|
|
9
|
+
* Initial sessions to populate the chat.
|
|
10
|
+
*/
|
|
11
|
+
initialSessions?: Session[];
|
|
12
|
+
/**
|
|
13
|
+
* Initial active session ID.
|
|
14
|
+
*/
|
|
15
|
+
initialActiveSessionId?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Tools to expose to the agent.
|
|
18
|
+
*/
|
|
19
|
+
tools?: AgUiTool[];
|
|
20
|
+
/**
|
|
21
|
+
* Context to send with each run.
|
|
22
|
+
*/
|
|
23
|
+
context?: AgUiContext[];
|
|
24
|
+
/**
|
|
25
|
+
* Additional properties forwarded to the agent.
|
|
26
|
+
*/
|
|
27
|
+
forwardedProps?: Record<string, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Custom headers for the HTTP request.
|
|
30
|
+
*/
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Called when a tool call is received from the agent.
|
|
34
|
+
*/
|
|
35
|
+
onToolCall?: (toolCall: AgUiToolCallInfo) => Promise<void> | void;
|
|
36
|
+
/**
|
|
37
|
+
* Called when the agent run encounters an error.
|
|
38
|
+
*/
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Called when an AG-UI event is received (for debugging/logging).
|
|
42
|
+
*/
|
|
43
|
+
onEvent?: (event: AgUiEvent) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface UseAgUiReturn {
|
|
46
|
+
/**
|
|
47
|
+
* All chat sessions.
|
|
48
|
+
*/
|
|
49
|
+
sessions: Session[];
|
|
50
|
+
/**
|
|
51
|
+
* The currently active session ID.
|
|
52
|
+
*/
|
|
53
|
+
activeSessionId: string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the agent is currently processing.
|
|
56
|
+
*/
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Select a session by ID.
|
|
60
|
+
*/
|
|
61
|
+
selectSession: (sessionId: string) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Delete a session by ID.
|
|
64
|
+
*/
|
|
65
|
+
deleteSession: (sessionId: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new empty session.
|
|
68
|
+
*/
|
|
69
|
+
createSession: () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Send a message to the agent.
|
|
72
|
+
*/
|
|
73
|
+
sendMessage: (message: string) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Stop the current agent run.
|
|
76
|
+
*/
|
|
77
|
+
stopMessage: () => void;
|
|
78
|
+
}
|
|
79
|
+
export declare function addConversationToSession(sessions: Session[], sessionId: string, conversation: Conversation): Session[];
|
|
80
|
+
export declare function updateConversationInSession(sessions: Session[], sessionId: string, conversationId: string, response: string): Session[];
|
|
81
|
+
/**
|
|
82
|
+
* Converts reachat Session/Conversation history into AG-UI messages.
|
|
83
|
+
*/
|
|
84
|
+
export declare function sessionsToAgUiMessages(session: Session): AgUiMessage[];
|
|
85
|
+
/**
|
|
86
|
+
* Parses a single SSE data line, returning the event or an Error
|
|
87
|
+
* if the JSON is malformed.
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseSSELine(line: string): AgUiEvent | Error | null;
|
|
90
|
+
/**
|
|
91
|
+
* Parses an SSE stream from a Response into AG-UI events.
|
|
92
|
+
*/
|
|
93
|
+
export declare function parseSSE(response: Response, signal: AbortSignal): AsyncGenerator<AgUiEvent | Error>;
|
|
94
|
+
/**
|
|
95
|
+
* React hook that connects to an AG-UI protocol endpoint and provides
|
|
96
|
+
* all the props needed for the reachat `<Chat>` component.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```tsx
|
|
100
|
+
* const agui = useAgUi({ agent: 'https://my-agent.example.com/run' });
|
|
101
|
+
*
|
|
102
|
+
* <Chat
|
|
103
|
+
* sessions={agui.sessions}
|
|
104
|
+
* activeSessionId={agui.activeSessionId}
|
|
105
|
+
* isLoading={agui.isLoading}
|
|
106
|
+
* onSelectSession={agui.selectSession}
|
|
107
|
+
* onDeleteSession={agui.deleteSession}
|
|
108
|
+
* onNewSession={agui.createSession}
|
|
109
|
+
* onSendMessage={agui.sendMessage}
|
|
110
|
+
* onStopMessage={agui.stopMessage}
|
|
111
|
+
* >
|
|
112
|
+
* <SessionMessagePanel>
|
|
113
|
+
* <SessionMessages />
|
|
114
|
+
* <ChatInput />
|
|
115
|
+
* </SessionMessagePanel>
|
|
116
|
+
* </Chat>
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function useAgUi({ agent, initialSessions, initialActiveSessionId, tools, context, forwardedProps, headers, onToolCall, onError, onEvent }: UseAgUiOptions): UseAgUiReturn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reachat",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Chat UI for Building LLMs",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build-storybook": "storybook build",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"browser": "dist/index.js",
|
|
41
41
|
"typings": "dist/index.d.ts",
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@floating-ui/dom": "^1.6.0",
|
|
43
44
|
"@floating-ui/react": "^0.27.6",
|
|
44
45
|
"@radix-ui/react-slot": "^1.1.0",
|
|
45
46
|
"@tiptap/core": "^3.15.3",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"react-syntax-highlighter": "^16.1.0",
|
|
62
63
|
"reakeys": "^2.0.3",
|
|
63
64
|
"rehype-katex": "^7.0.0",
|
|
65
|
+
"rehype-raw": "^7.0.0",
|
|
64
66
|
"remark-gfm": "^4.0.0",
|
|
65
67
|
"remark-math": "^6.0.0",
|
|
66
68
|
"remark-youtube": "^1.3.2",
|