@refraction-ui/react 0.9.2 → 0.10.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/form.cjs +1 -0
- package/dist/form.js +1 -0
- package/dist/index.cjs +1807 -473
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2084 -766
- package/dist/index.js.map +1 -1
- package/dist/internal/conversation/index.d.cts +235 -0
- package/dist/internal/conversation/index.d.ts +235 -0
- package/dist/internal/cookie-consent/index.d.cts +77 -0
- package/dist/internal/cookie-consent/index.d.ts +77 -0
- package/dist/internal/react-conversation/index.d.cts +97 -0
- package/dist/internal/react-conversation/index.d.ts +97 -0
- package/dist/internal/react-cookie-consent/index.d.cts +46 -0
- package/dist/internal/react-cookie-consent/index.d.ts +46 -0
- package/dist/theme.cjs +1 -0
- package/dist/theme.js +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @refraction-ui/conversation — headless chat store.
|
|
3
|
+
*
|
|
4
|
+
* Owns the *data format* and *behavior* of a multi-conversation chat with
|
|
5
|
+
* reply-threads, reactions, edit/delete, and streaming. It has NO UI opinion
|
|
6
|
+
* and NO backend opinion: the wire is supplied by a {@link ChatTransport}
|
|
7
|
+
* adapter, exactly as {@link AIProvider} is supplied to `@refraction-ui/ai`.
|
|
8
|
+
*
|
|
9
|
+
* Two threading modes (how replies relate to the main timeline):
|
|
10
|
+
* - `'inline'` (default): every message — replies included — appears in the
|
|
11
|
+
* main timeline; a reply shows its parent quoted, and opening it reveals the
|
|
12
|
+
* focused thread in a side panel.
|
|
13
|
+
* - `'panel'`: only root messages appear in the main timeline (each showing a
|
|
14
|
+
* reply count); replies live solely in the thread panel (Slack-style).
|
|
15
|
+
*/
|
|
16
|
+
/** Author display info — structurally compatible with thread-view's MessageData. */
|
|
17
|
+
interface ChatAuthor {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
avatarUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Conversational role. Generic; the transport decides what each means. */
|
|
23
|
+
type ChatRole = 'user' | 'assistant' | 'system';
|
|
24
|
+
/** Lifecycle of a single message. */
|
|
25
|
+
type MessageStatus = 'pending' | 'streaming' | 'sent' | 'error';
|
|
26
|
+
/** How replies relate to the main timeline. */
|
|
27
|
+
type ThreadingMode = 'inline' | 'panel';
|
|
28
|
+
/** An emoji reaction aggregate on a message. */
|
|
29
|
+
interface MessageReaction {
|
|
30
|
+
emoji: string;
|
|
31
|
+
count: number;
|
|
32
|
+
/** Whether the local user has reacted with this emoji */
|
|
33
|
+
userReacted: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** A file/media attachment (images, gifs, docs). */
|
|
36
|
+
interface MessageAttachment {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
url: string;
|
|
40
|
+
/** MIME type, e.g. 'image/gif', 'image/png', 'application/pdf' */
|
|
41
|
+
type: string;
|
|
42
|
+
size?: number;
|
|
43
|
+
}
|
|
44
|
+
/** A single message. */
|
|
45
|
+
interface ChatMessage {
|
|
46
|
+
/** Unique message ID */
|
|
47
|
+
id: string;
|
|
48
|
+
/** Conversation this message belongs to */
|
|
49
|
+
conversationId: string;
|
|
50
|
+
/** Who/what produced it */
|
|
51
|
+
role: ChatRole;
|
|
52
|
+
/** Author display info */
|
|
53
|
+
author: ChatAuthor;
|
|
54
|
+
/** Content (markdown — may contain code fences, images/gifs; grows while streaming) */
|
|
55
|
+
content: string;
|
|
56
|
+
/** Creation time */
|
|
57
|
+
timestamp: Date;
|
|
58
|
+
/** Lifecycle status */
|
|
59
|
+
status: MessageStatus;
|
|
60
|
+
/** Failure reason when `status === 'error'` */
|
|
61
|
+
error?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Root message id of the reply-thread this message belongs to. Absent on
|
|
64
|
+
* root/main-timeline messages. Threads are one level deep.
|
|
65
|
+
*/
|
|
66
|
+
parentId?: string;
|
|
67
|
+
/** Emoji reactions */
|
|
68
|
+
reactions?: MessageReaction[];
|
|
69
|
+
/** Attachments (images/gifs/files) */
|
|
70
|
+
attachments?: MessageAttachment[];
|
|
71
|
+
/** Whether this message was edited */
|
|
72
|
+
edited?: boolean;
|
|
73
|
+
/** Arbitrary consumer metadata — never inspected by the store */
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
/** A conversation/session (an entry in the conversation list). */
|
|
77
|
+
interface Conversation {
|
|
78
|
+
id: string;
|
|
79
|
+
/** Display title (auto-derived from the first message unless set) */
|
|
80
|
+
title: string;
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
/** Last-activity time (bumped on every message) */
|
|
83
|
+
updatedAt: Date;
|
|
84
|
+
metadata?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/** Context handed to the transport for one send. */
|
|
87
|
+
interface SendContext {
|
|
88
|
+
/** Active conversation ID */
|
|
89
|
+
conversationId: string;
|
|
90
|
+
/** The user message being sent */
|
|
91
|
+
message: ChatMessage;
|
|
92
|
+
/** Prior messages in scope (the thread when replying, else the main timeline) */
|
|
93
|
+
history: ChatMessage[];
|
|
94
|
+
/** Root message id when this send is a reply within a thread */
|
|
95
|
+
parentId?: string;
|
|
96
|
+
/** Aborted when the consumer calls `stop()` */
|
|
97
|
+
signal: AbortSignal;
|
|
98
|
+
}
|
|
99
|
+
/** A streamed piece of an assistant reply. */
|
|
100
|
+
interface TransportChunk {
|
|
101
|
+
/** Token/delta to append to the assistant reply */
|
|
102
|
+
delta?: string;
|
|
103
|
+
/** Replace the whole reply content (for non-streaming transports) */
|
|
104
|
+
content?: string;
|
|
105
|
+
/** Arbitrary metadata merged onto the assistant message */
|
|
106
|
+
metadata?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The backend wire. Implemented by adapter code the consumer owns — never by
|
|
110
|
+
* this package. A non-streaming backend yields one chunk with `content` then
|
|
111
|
+
* returns; a streaming backend yields many `delta` chunks.
|
|
112
|
+
*/
|
|
113
|
+
interface ChatTransport {
|
|
114
|
+
name: string;
|
|
115
|
+
send(ctx: SendContext): AsyncIterable<TransportChunk>;
|
|
116
|
+
}
|
|
117
|
+
/** Snapshot of the store. Returned by `getState()`; treat as immutable. */
|
|
118
|
+
interface ConversationState {
|
|
119
|
+
/** All conversations, most-recently-updated first */
|
|
120
|
+
conversations: Conversation[];
|
|
121
|
+
/** Active conversation ID, or null when none selected */
|
|
122
|
+
activeConversationId: string | null;
|
|
123
|
+
/** Flat messages of the active conversation (roots + replies) */
|
|
124
|
+
messages: ChatMessage[];
|
|
125
|
+
/** Root id of the thread shown in the side panel, or null when closed */
|
|
126
|
+
openThreadRootId: string | null;
|
|
127
|
+
/** Current threading mode */
|
|
128
|
+
threadingMode: ThreadingMode;
|
|
129
|
+
/** Coarse store status */
|
|
130
|
+
status: 'idle' | 'sending' | 'streaming' | 'error';
|
|
131
|
+
/** Last error, if any */
|
|
132
|
+
error: string | null;
|
|
133
|
+
}
|
|
134
|
+
/** Options for `createConversation`. */
|
|
135
|
+
interface ConversationConfig {
|
|
136
|
+
/** Backend wire. Without it the store is a local message log. */
|
|
137
|
+
transport?: ChatTransport;
|
|
138
|
+
/** Seed conversations */
|
|
139
|
+
conversations?: Conversation[];
|
|
140
|
+
/** Seed messages keyed by conversationId */
|
|
141
|
+
messages?: Record<string, ChatMessage[]>;
|
|
142
|
+
/** Initially active conversation */
|
|
143
|
+
activeConversationId?: string;
|
|
144
|
+
/** The local user — author of outgoing messages */
|
|
145
|
+
currentUser?: ChatAuthor;
|
|
146
|
+
/** Author of assistant replies (default: { id: 'assistant', name: 'Assistant' }) */
|
|
147
|
+
assistant?: ChatAuthor;
|
|
148
|
+
/** Derive a conversation title from its first message (default: first ~48 chars) */
|
|
149
|
+
generateTitle?: (firstMessage: string) => string;
|
|
150
|
+
/** Threading mode (default 'inline') */
|
|
151
|
+
threadingMode?: ThreadingMode;
|
|
152
|
+
}
|
|
153
|
+
/** Options for a single `sendMessage`. */
|
|
154
|
+
interface SendOptions {
|
|
155
|
+
/** Send into a specific conversation instead of the active one */
|
|
156
|
+
conversationId?: string;
|
|
157
|
+
/** Reply within the thread of this message id */
|
|
158
|
+
replyTo?: string;
|
|
159
|
+
/** Attachments on the outgoing message */
|
|
160
|
+
attachments?: MessageAttachment[];
|
|
161
|
+
/** Metadata attached to the outgoing user message */
|
|
162
|
+
metadata?: Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
/** The framework-agnostic store. React/Astro adapters wrap this. */
|
|
165
|
+
interface ConversationAPI {
|
|
166
|
+
/** Current immutable snapshot */
|
|
167
|
+
getState(): ConversationState;
|
|
168
|
+
/** Subscribe to changes; returns an unsubscribe fn (suits useSyncExternalStore) */
|
|
169
|
+
subscribe(listener: () => void): () => void;
|
|
170
|
+
/** Create a new conversation and make it active */
|
|
171
|
+
newConversation(opts?: {
|
|
172
|
+
title?: string;
|
|
173
|
+
metadata?: Record<string, unknown>;
|
|
174
|
+
}): Conversation;
|
|
175
|
+
/** Make a conversation active */
|
|
176
|
+
selectConversation(conversationId: string): void;
|
|
177
|
+
/** Delete a conversation and its messages */
|
|
178
|
+
deleteConversation(conversationId: string): void;
|
|
179
|
+
/** Rename a conversation */
|
|
180
|
+
renameConversation(conversationId: string, title: string): void;
|
|
181
|
+
/** Optimistically append the user message, then stream the reply via transport */
|
|
182
|
+
sendMessage(content: string, opts?: SendOptions): Promise<void>;
|
|
183
|
+
/** Append a message directly (no transport round-trip) */
|
|
184
|
+
appendMessage(message: ChatMessage): void;
|
|
185
|
+
/** Edit a message's content (marks it edited) */
|
|
186
|
+
editMessage(messageId: string, content: string): void;
|
|
187
|
+
/** Delete a message (and, for a thread root, its replies) */
|
|
188
|
+
deleteMessage(messageId: string): void;
|
|
189
|
+
/** Toggle the local user's emoji reaction on a message */
|
|
190
|
+
react(messageId: string, emoji: string): void;
|
|
191
|
+
/** Retry the last failed turn in the active conversation */
|
|
192
|
+
retryLast(): Promise<void>;
|
|
193
|
+
/** Abort the in-flight stream, keeping any partial reply */
|
|
194
|
+
stop(): void;
|
|
195
|
+
/** Open the side panel focused on a message's thread */
|
|
196
|
+
openThread(rootId: string): void;
|
|
197
|
+
/** Close the thread side panel */
|
|
198
|
+
closeThread(): void;
|
|
199
|
+
/** Switch threading mode */
|
|
200
|
+
setThreadingMode(mode: ThreadingMode): void;
|
|
201
|
+
/** Swap the transport at runtime */
|
|
202
|
+
setTransport(transport: ChatTransport): void;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* createConversation — headless multi-conversation chat store with reply-threads,
|
|
207
|
+
* reactions, edit/delete, and streaming. Backend-agnostic: provide a
|
|
208
|
+
* {@link ChatTransport} and `sendMessage` will optimistically append the user
|
|
209
|
+
* message, stream the reply, and expose retry/stop. Without a transport it is a
|
|
210
|
+
* pure local message log.
|
|
211
|
+
*/
|
|
212
|
+
declare function createConversation(config?: ConversationConfig): ConversationAPI;
|
|
213
|
+
|
|
214
|
+
/** Find a message by id. */
|
|
215
|
+
declare function findMessage(messages: ChatMessage[], id: string): ChatMessage | undefined;
|
|
216
|
+
/** Resolve a message id to its thread root (itself if it's already a root). */
|
|
217
|
+
declare function rootIdOf(messages: ChatMessage[], id: string): string;
|
|
218
|
+
/** Root (main-timeline) messages — those not belonging to a reply-thread. */
|
|
219
|
+
declare function selectRoots(messages: ChatMessage[]): ChatMessage[];
|
|
220
|
+
/** Replies belonging to a thread root, oldest first (excludes the root itself). */
|
|
221
|
+
declare function selectReplies(messages: ChatMessage[], rootId: string): ChatMessage[];
|
|
222
|
+
/** A full thread: root message followed by its replies. */
|
|
223
|
+
declare function selectThreadMessages(messages: ChatMessage[], rootId: string): ChatMessage[];
|
|
224
|
+
/** Number of replies in a thread. */
|
|
225
|
+
declare function getReplyCount(messages: ChatMessage[], rootId: string): number;
|
|
226
|
+
/**
|
|
227
|
+
* The main timeline for the active conversation, honoring the threading mode:
|
|
228
|
+
* - `'inline'`: every message in chronological order (replies included).
|
|
229
|
+
* - `'panel'`: only root messages (replies hidden behind their thread).
|
|
230
|
+
*/
|
|
231
|
+
declare function selectMainTimeline(messages: ChatMessage[], mode: ThreadingMode): ChatMessage[];
|
|
232
|
+
/** Convenience: main timeline from a store snapshot. */
|
|
233
|
+
declare function selectTimelineFromState(state: ConversationState): ChatMessage[];
|
|
234
|
+
|
|
235
|
+
export { type ChatAuthor, type ChatMessage, type ChatRole, type ChatTransport, type Conversation, type ConversationAPI, type ConversationConfig, type ConversationState, type MessageAttachment, type MessageReaction, type MessageStatus, type SendContext, type SendOptions, type ThreadingMode, type TransportChunk, createConversation, findMessage, getReplyCount, rootIdOf, selectMainTimeline, selectReplies, selectRoots, selectThreadMessages, selectTimelineFromState };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @refraction-ui/conversation — headless chat store.
|
|
3
|
+
*
|
|
4
|
+
* Owns the *data format* and *behavior* of a multi-conversation chat with
|
|
5
|
+
* reply-threads, reactions, edit/delete, and streaming. It has NO UI opinion
|
|
6
|
+
* and NO backend opinion: the wire is supplied by a {@link ChatTransport}
|
|
7
|
+
* adapter, exactly as {@link AIProvider} is supplied to `@refraction-ui/ai`.
|
|
8
|
+
*
|
|
9
|
+
* Two threading modes (how replies relate to the main timeline):
|
|
10
|
+
* - `'inline'` (default): every message — replies included — appears in the
|
|
11
|
+
* main timeline; a reply shows its parent quoted, and opening it reveals the
|
|
12
|
+
* focused thread in a side panel.
|
|
13
|
+
* - `'panel'`: only root messages appear in the main timeline (each showing a
|
|
14
|
+
* reply count); replies live solely in the thread panel (Slack-style).
|
|
15
|
+
*/
|
|
16
|
+
/** Author display info — structurally compatible with thread-view's MessageData. */
|
|
17
|
+
interface ChatAuthor {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
avatarUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Conversational role. Generic; the transport decides what each means. */
|
|
23
|
+
type ChatRole = 'user' | 'assistant' | 'system';
|
|
24
|
+
/** Lifecycle of a single message. */
|
|
25
|
+
type MessageStatus = 'pending' | 'streaming' | 'sent' | 'error';
|
|
26
|
+
/** How replies relate to the main timeline. */
|
|
27
|
+
type ThreadingMode = 'inline' | 'panel';
|
|
28
|
+
/** An emoji reaction aggregate on a message. */
|
|
29
|
+
interface MessageReaction {
|
|
30
|
+
emoji: string;
|
|
31
|
+
count: number;
|
|
32
|
+
/** Whether the local user has reacted with this emoji */
|
|
33
|
+
userReacted: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** A file/media attachment (images, gifs, docs). */
|
|
36
|
+
interface MessageAttachment {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
url: string;
|
|
40
|
+
/** MIME type, e.g. 'image/gif', 'image/png', 'application/pdf' */
|
|
41
|
+
type: string;
|
|
42
|
+
size?: number;
|
|
43
|
+
}
|
|
44
|
+
/** A single message. */
|
|
45
|
+
interface ChatMessage {
|
|
46
|
+
/** Unique message ID */
|
|
47
|
+
id: string;
|
|
48
|
+
/** Conversation this message belongs to */
|
|
49
|
+
conversationId: string;
|
|
50
|
+
/** Who/what produced it */
|
|
51
|
+
role: ChatRole;
|
|
52
|
+
/** Author display info */
|
|
53
|
+
author: ChatAuthor;
|
|
54
|
+
/** Content (markdown — may contain code fences, images/gifs; grows while streaming) */
|
|
55
|
+
content: string;
|
|
56
|
+
/** Creation time */
|
|
57
|
+
timestamp: Date;
|
|
58
|
+
/** Lifecycle status */
|
|
59
|
+
status: MessageStatus;
|
|
60
|
+
/** Failure reason when `status === 'error'` */
|
|
61
|
+
error?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Root message id of the reply-thread this message belongs to. Absent on
|
|
64
|
+
* root/main-timeline messages. Threads are one level deep.
|
|
65
|
+
*/
|
|
66
|
+
parentId?: string;
|
|
67
|
+
/** Emoji reactions */
|
|
68
|
+
reactions?: MessageReaction[];
|
|
69
|
+
/** Attachments (images/gifs/files) */
|
|
70
|
+
attachments?: MessageAttachment[];
|
|
71
|
+
/** Whether this message was edited */
|
|
72
|
+
edited?: boolean;
|
|
73
|
+
/** Arbitrary consumer metadata — never inspected by the store */
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
/** A conversation/session (an entry in the conversation list). */
|
|
77
|
+
interface Conversation {
|
|
78
|
+
id: string;
|
|
79
|
+
/** Display title (auto-derived from the first message unless set) */
|
|
80
|
+
title: string;
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
/** Last-activity time (bumped on every message) */
|
|
83
|
+
updatedAt: Date;
|
|
84
|
+
metadata?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/** Context handed to the transport for one send. */
|
|
87
|
+
interface SendContext {
|
|
88
|
+
/** Active conversation ID */
|
|
89
|
+
conversationId: string;
|
|
90
|
+
/** The user message being sent */
|
|
91
|
+
message: ChatMessage;
|
|
92
|
+
/** Prior messages in scope (the thread when replying, else the main timeline) */
|
|
93
|
+
history: ChatMessage[];
|
|
94
|
+
/** Root message id when this send is a reply within a thread */
|
|
95
|
+
parentId?: string;
|
|
96
|
+
/** Aborted when the consumer calls `stop()` */
|
|
97
|
+
signal: AbortSignal;
|
|
98
|
+
}
|
|
99
|
+
/** A streamed piece of an assistant reply. */
|
|
100
|
+
interface TransportChunk {
|
|
101
|
+
/** Token/delta to append to the assistant reply */
|
|
102
|
+
delta?: string;
|
|
103
|
+
/** Replace the whole reply content (for non-streaming transports) */
|
|
104
|
+
content?: string;
|
|
105
|
+
/** Arbitrary metadata merged onto the assistant message */
|
|
106
|
+
metadata?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The backend wire. Implemented by adapter code the consumer owns — never by
|
|
110
|
+
* this package. A non-streaming backend yields one chunk with `content` then
|
|
111
|
+
* returns; a streaming backend yields many `delta` chunks.
|
|
112
|
+
*/
|
|
113
|
+
interface ChatTransport {
|
|
114
|
+
name: string;
|
|
115
|
+
send(ctx: SendContext): AsyncIterable<TransportChunk>;
|
|
116
|
+
}
|
|
117
|
+
/** Snapshot of the store. Returned by `getState()`; treat as immutable. */
|
|
118
|
+
interface ConversationState {
|
|
119
|
+
/** All conversations, most-recently-updated first */
|
|
120
|
+
conversations: Conversation[];
|
|
121
|
+
/** Active conversation ID, or null when none selected */
|
|
122
|
+
activeConversationId: string | null;
|
|
123
|
+
/** Flat messages of the active conversation (roots + replies) */
|
|
124
|
+
messages: ChatMessage[];
|
|
125
|
+
/** Root id of the thread shown in the side panel, or null when closed */
|
|
126
|
+
openThreadRootId: string | null;
|
|
127
|
+
/** Current threading mode */
|
|
128
|
+
threadingMode: ThreadingMode;
|
|
129
|
+
/** Coarse store status */
|
|
130
|
+
status: 'idle' | 'sending' | 'streaming' | 'error';
|
|
131
|
+
/** Last error, if any */
|
|
132
|
+
error: string | null;
|
|
133
|
+
}
|
|
134
|
+
/** Options for `createConversation`. */
|
|
135
|
+
interface ConversationConfig {
|
|
136
|
+
/** Backend wire. Without it the store is a local message log. */
|
|
137
|
+
transport?: ChatTransport;
|
|
138
|
+
/** Seed conversations */
|
|
139
|
+
conversations?: Conversation[];
|
|
140
|
+
/** Seed messages keyed by conversationId */
|
|
141
|
+
messages?: Record<string, ChatMessage[]>;
|
|
142
|
+
/** Initially active conversation */
|
|
143
|
+
activeConversationId?: string;
|
|
144
|
+
/** The local user — author of outgoing messages */
|
|
145
|
+
currentUser?: ChatAuthor;
|
|
146
|
+
/** Author of assistant replies (default: { id: 'assistant', name: 'Assistant' }) */
|
|
147
|
+
assistant?: ChatAuthor;
|
|
148
|
+
/** Derive a conversation title from its first message (default: first ~48 chars) */
|
|
149
|
+
generateTitle?: (firstMessage: string) => string;
|
|
150
|
+
/** Threading mode (default 'inline') */
|
|
151
|
+
threadingMode?: ThreadingMode;
|
|
152
|
+
}
|
|
153
|
+
/** Options for a single `sendMessage`. */
|
|
154
|
+
interface SendOptions {
|
|
155
|
+
/** Send into a specific conversation instead of the active one */
|
|
156
|
+
conversationId?: string;
|
|
157
|
+
/** Reply within the thread of this message id */
|
|
158
|
+
replyTo?: string;
|
|
159
|
+
/** Attachments on the outgoing message */
|
|
160
|
+
attachments?: MessageAttachment[];
|
|
161
|
+
/** Metadata attached to the outgoing user message */
|
|
162
|
+
metadata?: Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
/** The framework-agnostic store. React/Astro adapters wrap this. */
|
|
165
|
+
interface ConversationAPI {
|
|
166
|
+
/** Current immutable snapshot */
|
|
167
|
+
getState(): ConversationState;
|
|
168
|
+
/** Subscribe to changes; returns an unsubscribe fn (suits useSyncExternalStore) */
|
|
169
|
+
subscribe(listener: () => void): () => void;
|
|
170
|
+
/** Create a new conversation and make it active */
|
|
171
|
+
newConversation(opts?: {
|
|
172
|
+
title?: string;
|
|
173
|
+
metadata?: Record<string, unknown>;
|
|
174
|
+
}): Conversation;
|
|
175
|
+
/** Make a conversation active */
|
|
176
|
+
selectConversation(conversationId: string): void;
|
|
177
|
+
/** Delete a conversation and its messages */
|
|
178
|
+
deleteConversation(conversationId: string): void;
|
|
179
|
+
/** Rename a conversation */
|
|
180
|
+
renameConversation(conversationId: string, title: string): void;
|
|
181
|
+
/** Optimistically append the user message, then stream the reply via transport */
|
|
182
|
+
sendMessage(content: string, opts?: SendOptions): Promise<void>;
|
|
183
|
+
/** Append a message directly (no transport round-trip) */
|
|
184
|
+
appendMessage(message: ChatMessage): void;
|
|
185
|
+
/** Edit a message's content (marks it edited) */
|
|
186
|
+
editMessage(messageId: string, content: string): void;
|
|
187
|
+
/** Delete a message (and, for a thread root, its replies) */
|
|
188
|
+
deleteMessage(messageId: string): void;
|
|
189
|
+
/** Toggle the local user's emoji reaction on a message */
|
|
190
|
+
react(messageId: string, emoji: string): void;
|
|
191
|
+
/** Retry the last failed turn in the active conversation */
|
|
192
|
+
retryLast(): Promise<void>;
|
|
193
|
+
/** Abort the in-flight stream, keeping any partial reply */
|
|
194
|
+
stop(): void;
|
|
195
|
+
/** Open the side panel focused on a message's thread */
|
|
196
|
+
openThread(rootId: string): void;
|
|
197
|
+
/** Close the thread side panel */
|
|
198
|
+
closeThread(): void;
|
|
199
|
+
/** Switch threading mode */
|
|
200
|
+
setThreadingMode(mode: ThreadingMode): void;
|
|
201
|
+
/** Swap the transport at runtime */
|
|
202
|
+
setTransport(transport: ChatTransport): void;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* createConversation — headless multi-conversation chat store with reply-threads,
|
|
207
|
+
* reactions, edit/delete, and streaming. Backend-agnostic: provide a
|
|
208
|
+
* {@link ChatTransport} and `sendMessage` will optimistically append the user
|
|
209
|
+
* message, stream the reply, and expose retry/stop. Without a transport it is a
|
|
210
|
+
* pure local message log.
|
|
211
|
+
*/
|
|
212
|
+
declare function createConversation(config?: ConversationConfig): ConversationAPI;
|
|
213
|
+
|
|
214
|
+
/** Find a message by id. */
|
|
215
|
+
declare function findMessage(messages: ChatMessage[], id: string): ChatMessage | undefined;
|
|
216
|
+
/** Resolve a message id to its thread root (itself if it's already a root). */
|
|
217
|
+
declare function rootIdOf(messages: ChatMessage[], id: string): string;
|
|
218
|
+
/** Root (main-timeline) messages — those not belonging to a reply-thread. */
|
|
219
|
+
declare function selectRoots(messages: ChatMessage[]): ChatMessage[];
|
|
220
|
+
/** Replies belonging to a thread root, oldest first (excludes the root itself). */
|
|
221
|
+
declare function selectReplies(messages: ChatMessage[], rootId: string): ChatMessage[];
|
|
222
|
+
/** A full thread: root message followed by its replies. */
|
|
223
|
+
declare function selectThreadMessages(messages: ChatMessage[], rootId: string): ChatMessage[];
|
|
224
|
+
/** Number of replies in a thread. */
|
|
225
|
+
declare function getReplyCount(messages: ChatMessage[], rootId: string): number;
|
|
226
|
+
/**
|
|
227
|
+
* The main timeline for the active conversation, honoring the threading mode:
|
|
228
|
+
* - `'inline'`: every message in chronological order (replies included).
|
|
229
|
+
* - `'panel'`: only root messages (replies hidden behind their thread).
|
|
230
|
+
*/
|
|
231
|
+
declare function selectMainTimeline(messages: ChatMessage[], mode: ThreadingMode): ChatMessage[];
|
|
232
|
+
/** Convenience: main timeline from a store snapshot. */
|
|
233
|
+
declare function selectTimelineFromState(state: ConversationState): ChatMessage[];
|
|
234
|
+
|
|
235
|
+
export { type ChatAuthor, type ChatMessage, type ChatRole, type ChatTransport, type Conversation, type ConversationAPI, type ConversationConfig, type ConversationState, type MessageAttachment, type MessageReaction, type MessageStatus, type SendContext, type SendOptions, type ThreadingMode, type TransportChunk, createConversation, findMessage, getReplyCount, rootIdOf, selectMainTimeline, selectReplies, selectRoots, selectThreadMessages, selectTimelineFromState };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @refraction-ui/cookie-consent — headless cookie-consent store.
|
|
3
|
+
*
|
|
4
|
+
* Owns consent categories + the user's per-category opt-in and banner state.
|
|
5
|
+
* Persistence is backend-agnostic via a {@link CookieStorage} adapter (the React
|
|
6
|
+
* adapter defaults to localStorage); no DOM/cookie access in the core.
|
|
7
|
+
*/
|
|
8
|
+
/** A consent category the user can opt into. */
|
|
9
|
+
interface CookieCategory {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
/** Required categories are always on and cannot be toggled off. */
|
|
14
|
+
required?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Per-category opt-in map (categoryId → granted). */
|
|
17
|
+
type ConsentPreferences = Record<string, boolean>;
|
|
18
|
+
/** Persistence adapter — implement over localStorage, cookies, a backend, etc. */
|
|
19
|
+
interface CookieStorage {
|
|
20
|
+
get(key: string): string | null;
|
|
21
|
+
set(key: string, value: string): void;
|
|
22
|
+
remove(key: string): void;
|
|
23
|
+
}
|
|
24
|
+
/** Options for `createCookieConsent`. */
|
|
25
|
+
interface CookieConsentConfig {
|
|
26
|
+
/** Consent categories (default: necessary*, analytics, marketing, preferences) */
|
|
27
|
+
categories?: CookieCategory[];
|
|
28
|
+
/** Persistence adapter; omit for in-memory (non-persistent) */
|
|
29
|
+
storage?: CookieStorage;
|
|
30
|
+
/** Storage key (default 'rfr-cookie-consent') */
|
|
31
|
+
storageKey?: string;
|
|
32
|
+
/** Consent version — bump to re-prompt users after a policy change */
|
|
33
|
+
version?: string;
|
|
34
|
+
/** Called whenever consent is saved, with the resolved preferences */
|
|
35
|
+
onChange?: (preferences: ConsentPreferences) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Immutable store snapshot. */
|
|
38
|
+
interface CookieConsentState {
|
|
39
|
+
/** Whether the user has made a choice (false → show the banner) */
|
|
40
|
+
consented: boolean;
|
|
41
|
+
/** Per-category opt-in */
|
|
42
|
+
preferences: ConsentPreferences;
|
|
43
|
+
/** Banner/dialog visibility */
|
|
44
|
+
open: boolean;
|
|
45
|
+
/** The configured categories */
|
|
46
|
+
categories: CookieCategory[];
|
|
47
|
+
}
|
|
48
|
+
/** The framework-agnostic store. */
|
|
49
|
+
interface CookieConsentAPI {
|
|
50
|
+
getState(): CookieConsentState;
|
|
51
|
+
subscribe(listener: () => void): () => void;
|
|
52
|
+
/** Grant every category and persist */
|
|
53
|
+
acceptAll(): void;
|
|
54
|
+
/** Grant only required categories and persist */
|
|
55
|
+
rejectAll(): void;
|
|
56
|
+
/** Persist the given preferences (required categories are forced on) */
|
|
57
|
+
savePreferences(preferences: ConsentPreferences): void;
|
|
58
|
+
/** Toggle a single (non-required) category in the working preferences */
|
|
59
|
+
setPreference(id: string, value: boolean): void;
|
|
60
|
+
/** Clear stored consent and re-open the banner */
|
|
61
|
+
reset(): void;
|
|
62
|
+
/** Open the banner/settings */
|
|
63
|
+
openSettings(): void;
|
|
64
|
+
/** Close the banner without changing stored consent */
|
|
65
|
+
close(): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Popular default GDPR-style categories. */
|
|
69
|
+
declare const DEFAULT_CATEGORIES: CookieCategory[];
|
|
70
|
+
/**
|
|
71
|
+
* createCookieConsent — headless consent store. Reads any persisted choice on
|
|
72
|
+
* init (re-prompting if the `version` changed), and exposes accept/reject/save
|
|
73
|
+
* plus banner visibility. Persistence is via the optional storage adapter.
|
|
74
|
+
*/
|
|
75
|
+
declare function createCookieConsent(config?: CookieConsentConfig): CookieConsentAPI;
|
|
76
|
+
|
|
77
|
+
export { type ConsentPreferences, type CookieCategory, type CookieConsentAPI, type CookieConsentConfig, type CookieConsentState, type CookieStorage, DEFAULT_CATEGORIES, createCookieConsent };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @refraction-ui/cookie-consent — headless cookie-consent store.
|
|
3
|
+
*
|
|
4
|
+
* Owns consent categories + the user's per-category opt-in and banner state.
|
|
5
|
+
* Persistence is backend-agnostic via a {@link CookieStorage} adapter (the React
|
|
6
|
+
* adapter defaults to localStorage); no DOM/cookie access in the core.
|
|
7
|
+
*/
|
|
8
|
+
/** A consent category the user can opt into. */
|
|
9
|
+
interface CookieCategory {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
/** Required categories are always on and cannot be toggled off. */
|
|
14
|
+
required?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Per-category opt-in map (categoryId → granted). */
|
|
17
|
+
type ConsentPreferences = Record<string, boolean>;
|
|
18
|
+
/** Persistence adapter — implement over localStorage, cookies, a backend, etc. */
|
|
19
|
+
interface CookieStorage {
|
|
20
|
+
get(key: string): string | null;
|
|
21
|
+
set(key: string, value: string): void;
|
|
22
|
+
remove(key: string): void;
|
|
23
|
+
}
|
|
24
|
+
/** Options for `createCookieConsent`. */
|
|
25
|
+
interface CookieConsentConfig {
|
|
26
|
+
/** Consent categories (default: necessary*, analytics, marketing, preferences) */
|
|
27
|
+
categories?: CookieCategory[];
|
|
28
|
+
/** Persistence adapter; omit for in-memory (non-persistent) */
|
|
29
|
+
storage?: CookieStorage;
|
|
30
|
+
/** Storage key (default 'rfr-cookie-consent') */
|
|
31
|
+
storageKey?: string;
|
|
32
|
+
/** Consent version — bump to re-prompt users after a policy change */
|
|
33
|
+
version?: string;
|
|
34
|
+
/** Called whenever consent is saved, with the resolved preferences */
|
|
35
|
+
onChange?: (preferences: ConsentPreferences) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Immutable store snapshot. */
|
|
38
|
+
interface CookieConsentState {
|
|
39
|
+
/** Whether the user has made a choice (false → show the banner) */
|
|
40
|
+
consented: boolean;
|
|
41
|
+
/** Per-category opt-in */
|
|
42
|
+
preferences: ConsentPreferences;
|
|
43
|
+
/** Banner/dialog visibility */
|
|
44
|
+
open: boolean;
|
|
45
|
+
/** The configured categories */
|
|
46
|
+
categories: CookieCategory[];
|
|
47
|
+
}
|
|
48
|
+
/** The framework-agnostic store. */
|
|
49
|
+
interface CookieConsentAPI {
|
|
50
|
+
getState(): CookieConsentState;
|
|
51
|
+
subscribe(listener: () => void): () => void;
|
|
52
|
+
/** Grant every category and persist */
|
|
53
|
+
acceptAll(): void;
|
|
54
|
+
/** Grant only required categories and persist */
|
|
55
|
+
rejectAll(): void;
|
|
56
|
+
/** Persist the given preferences (required categories are forced on) */
|
|
57
|
+
savePreferences(preferences: ConsentPreferences): void;
|
|
58
|
+
/** Toggle a single (non-required) category in the working preferences */
|
|
59
|
+
setPreference(id: string, value: boolean): void;
|
|
60
|
+
/** Clear stored consent and re-open the banner */
|
|
61
|
+
reset(): void;
|
|
62
|
+
/** Open the banner/settings */
|
|
63
|
+
openSettings(): void;
|
|
64
|
+
/** Close the banner without changing stored consent */
|
|
65
|
+
close(): void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Popular default GDPR-style categories. */
|
|
69
|
+
declare const DEFAULT_CATEGORIES: CookieCategory[];
|
|
70
|
+
/**
|
|
71
|
+
* createCookieConsent — headless consent store. Reads any persisted choice on
|
|
72
|
+
* init (re-prompting if the `version` changed), and exposes accept/reject/save
|
|
73
|
+
* plus banner visibility. Persistence is via the optional storage adapter.
|
|
74
|
+
*/
|
|
75
|
+
declare function createCookieConsent(config?: CookieConsentConfig): CookieConsentAPI;
|
|
76
|
+
|
|
77
|
+
export { type ConsentPreferences, type CookieCategory, type CookieConsentAPI, type CookieConsentConfig, type CookieConsentState, type CookieStorage, DEFAULT_CATEGORIES, createCookieConsent };
|