@anvia/react-ui 0.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -0
  3. package/dist/attachment/index.d.ts +21 -0
  4. package/dist/attachment/index.js +12 -0
  5. package/dist/attachment/index.js.map +1 -0
  6. package/dist/attachment-BP597fV3.d.ts +9 -0
  7. package/dist/chat/index.d.ts +106 -0
  8. package/dist/chat/index.js +22 -0
  9. package/dist/chat/index.js.map +1 -0
  10. package/dist/chat-B3kucz1w.d.ts +13 -0
  11. package/dist/chunk-7AS6R7BB.js +230 -0
  12. package/dist/chunk-7AS6R7BB.js.map +1 -0
  13. package/dist/chunk-AOZN3SWB.js +529 -0
  14. package/dist/chunk-AOZN3SWB.js.map +1 -0
  15. package/dist/chunk-AXZB6JSE.js +813 -0
  16. package/dist/chunk-AXZB6JSE.js.map +1 -0
  17. package/dist/chunk-LSHD67YK.js +200 -0
  18. package/dist/chunk-LSHD67YK.js.map +1 -0
  19. package/dist/chunk-RRINF6FN.js +125 -0
  20. package/dist/chunk-RRINF6FN.js.map +1 -0
  21. package/dist/chunk-T3ZFZ3NP.js +30 -0
  22. package/dist/chunk-T3ZFZ3NP.js.map +1 -0
  23. package/dist/chunk-WK33ER4Q.js +411 -0
  24. package/dist/chunk-WK33ER4Q.js.map +1 -0
  25. package/dist/completion/index.d.ts +28 -0
  26. package/dist/completion/index.js +16 -0
  27. package/dist/completion/index.js.map +1 -0
  28. package/dist/completion-input-WjK6kUyG.d.ts +23 -0
  29. package/dist/human-input/index.d.ts +76 -0
  30. package/dist/human-input/index.js +20 -0
  31. package/dist/human-input/index.js.map +1 -0
  32. package/dist/human-input-CydeYm_7.d.ts +20 -0
  33. package/dist/index.d.ts +15 -0
  34. package/dist/index.js +56 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/message/index.d.ts +87 -0
  37. package/dist/message/index.js +17 -0
  38. package/dist/message/index.js.map +1 -0
  39. package/dist/message-Beb4ZLNU.d.ts +12 -0
  40. package/dist/render-CRKWam2v.d.ts +8 -0
  41. package/dist/shared.d.ts +9 -0
  42. package/dist/shared.js +33 -0
  43. package/dist/shared.js.map +1 -0
  44. package/dist/styles.css +47 -0
  45. package/dist/thread-CluT3m5k.d.ts +31 -0
  46. package/package.json +82 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Indra Zulfi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @anvia/react-ui
2
+
3
+ Composable React UI primitives for Anvia chat and completion experiences.
4
+
5
+ ```tsx
6
+ import { useChat } from "@anvia/react";
7
+ import { ChatProvider, Composer, Message, Thread } from "@anvia/react-ui";
8
+
9
+ export function SupportChat() {
10
+ const chat = useChat({ endpoint: "/api/chat" });
11
+
12
+ return (
13
+ <ChatProvider controller={chat}>
14
+ <Thread.Root>
15
+ <Thread.Viewport>
16
+ <Thread.Empty>Start a conversation.</Thread.Empty>
17
+ <Thread.Suggestions />
18
+ <Thread.Messages>
19
+ <Message.Root>
20
+ <Message.Content>
21
+ <Message.Parts />
22
+ </Message.Content>
23
+ <Message.Actions />
24
+ </Message.Root>
25
+ </Thread.Messages>
26
+ <Thread.Error />
27
+ <Thread.ScrollToBottom>Jump to latest</Thread.ScrollToBottom>
28
+ </Thread.Viewport>
29
+ <Composer.Root>
30
+ <Composer.Attachments />
31
+ <Composer.AddAttachment>Attach</Composer.AddAttachment>
32
+ <Composer.Input maxRows={6} placeholder="Send a message..." />
33
+ <Composer.Stop>Stop</Composer.Stop>
34
+ <Composer.Submit>Send</Composer.Submit>
35
+ </Composer.Root>
36
+ </Thread.Root>
37
+ </ChatProvider>
38
+ );
39
+ }
40
+ ```
41
+
42
+ Import `@anvia/react-ui/styles.css` for a small default stylesheet, or style the stable
43
+ `data-anvia-*` attributes directly.
44
+
45
+ The primitives are headless by default: pass `className` or `asChild` for design-system
46
+ integration, control `Composer.Root` with `input`/`attachments` props when needed, and use
47
+ `submitMessage` for custom composer payloads. Use `keepMounted` on optional collections when empty
48
+ wrappers are useful for layout.
@@ -0,0 +1,21 @@
1
+ import * as _anvia_react from '@anvia/react';
2
+ import * as react from 'react';
3
+ export { A as AttachmentContextValue, u as useAttachment } from '../attachment-BP597fV3.js';
4
+ import { P as PrimitiveProps } from '../render-CRKWam2v.js';
5
+
6
+ declare const Attachment: {
7
+ readonly Root: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
8
+ children?: react.ReactNode | ((attachment: _anvia_react.UIAttachment) => react.ReactNode);
9
+ } & react.RefAttributes<HTMLDivElement>>;
10
+ readonly Name: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref">, "asChild"> & {
11
+ asChild?: boolean;
12
+ } & react.RefAttributes<HTMLSpanElement>>;
13
+ readonly Preview: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
14
+ asChild?: boolean;
15
+ } & react.RefAttributes<HTMLDivElement>>;
16
+ readonly Remove: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
17
+ asChild?: boolean;
18
+ } & react.RefAttributes<HTMLButtonElement>>;
19
+ };
20
+
21
+ export { Attachment };
@@ -0,0 +1,12 @@
1
+ import {
2
+ Attachment
3
+ } from "../chunk-RRINF6FN.js";
4
+ import "../chunk-T3ZFZ3NP.js";
5
+ import {
6
+ useAttachment
7
+ } from "../chunk-7AS6R7BB.js";
8
+ export {
9
+ Attachment,
10
+ useAttachment
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,9 @@
1
+ import { UIAttachment } from '@anvia/react';
2
+
3
+ type AttachmentContextValue = {
4
+ attachment: UIAttachment;
5
+ remove?(): void;
6
+ };
7
+ declare function useAttachment(): AttachmentContextValue;
8
+
9
+ export { type AttachmentContextValue as A, useAttachment as u };
@@ -0,0 +1,106 @@
1
+ import { C as ChatController } from '../chat-B3kucz1w.js';
2
+ export { a as ChatProvider, b as ChatProviderProps, u as useChatContext } from '../chat-B3kucz1w.js';
3
+ export { C as ComposerAttachmentInput, a as ComposerAttachmentsUpdate, b as ComposerContextValue, T as ThreadContextValue, u as useComposer, c as useThread } from '../thread-CluT3m5k.js';
4
+ import * as react from 'react';
5
+ import { ReactNode } from 'react';
6
+ import { UIAttachment, UIMessage, UseChatStatus, ChatSuggestion } from '@anvia/react';
7
+ import { P as PrimitiveProps } from '../render-CRKWam2v.js';
8
+
9
+ type ComposerSubmitMessageArgs<TEvent = unknown> = {
10
+ input: string;
11
+ attachments: UIAttachment[];
12
+ chat: ChatController<TEvent>;
13
+ clear(): void;
14
+ };
15
+ type ComposerSubmitMessage<TEvent = unknown> = (args: ComposerSubmitMessageArgs<TEvent>) => Promise<void> | void;
16
+ type ComposerAttachmentsChildren = ReactNode | ((attachment: UIAttachment) => ReactNode);
17
+ declare const Composer: {
18
+ readonly Root: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref">, "asChild"> & {
19
+ asChild?: boolean;
20
+ } & {
21
+ attachments?: UIAttachment[];
22
+ defaultAttachments?: UIAttachment[];
23
+ defaultInput?: string;
24
+ input?: string;
25
+ onAttachmentsChange?: (attachments: UIAttachment[]) => void;
26
+ onInputChange?: (input: string) => void;
27
+ submitMessage?: ComposerSubmitMessage;
28
+ } & react.RefAttributes<HTMLFormElement>>;
29
+ readonly Input: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref">, "asChild"> & {
30
+ asChild?: boolean;
31
+ } & {
32
+ autoResize?: boolean;
33
+ maxRows?: number;
34
+ minRows?: number;
35
+ } & react.RefAttributes<HTMLTextAreaElement>>;
36
+ readonly Attachments: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
37
+ children?: ComposerAttachmentsChildren;
38
+ keepMounted?: boolean;
39
+ } & react.RefAttributes<HTMLDivElement>>;
40
+ readonly AddAttachment: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
41
+ asChild?: boolean;
42
+ } & {
43
+ accept?: string;
44
+ multiple?: boolean;
45
+ } & react.RefAttributes<HTMLButtonElement>>;
46
+ readonly AttachmentInput: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref">, "asChild"> & {
47
+ asChild?: boolean;
48
+ } & react.RefAttributes<HTMLInputElement>>;
49
+ readonly AttachmentDropzone: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
50
+ asChild?: boolean;
51
+ } & {
52
+ disabled?: boolean;
53
+ } & react.RefAttributes<HTMLDivElement>>;
54
+ readonly Submit: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
55
+ asChild?: boolean;
56
+ } & react.RefAttributes<HTMLButtonElement>>;
57
+ readonly Stop: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
58
+ asChild?: boolean;
59
+ } & react.RefAttributes<HTMLButtonElement>>;
60
+ };
61
+
62
+ type ThreadMessagesChildren = ReactNode | ((message: UIMessage) => ReactNode);
63
+ type ThreadSuggestionChildren = ReactNode | ((suggestion: ChatSuggestion) => ReactNode);
64
+ declare const Thread: {
65
+ readonly Root: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
66
+ asChild?: boolean;
67
+ } & react.RefAttributes<HTMLDivElement>>;
68
+ readonly Viewport: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
69
+ asChild?: boolean;
70
+ } & {
71
+ autoScroll?: boolean;
72
+ } & react.RefAttributes<HTMLDivElement>>;
73
+ readonly ViewportFooter: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
74
+ asChild?: boolean;
75
+ } & react.RefAttributes<HTMLDivElement>>;
76
+ readonly Messages: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
77
+ children?: ThreadMessagesChildren;
78
+ keepMounted?: boolean;
79
+ } & react.RefAttributes<HTMLDivElement>>;
80
+ readonly Empty: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
81
+ asChild?: boolean;
82
+ } & react.RefAttributes<HTMLDivElement>>;
83
+ readonly Status: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
84
+ children?: ReactNode | ((status: UseChatStatus) => ReactNode);
85
+ } & react.RefAttributes<HTMLDivElement>>;
86
+ readonly Loading: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
87
+ asChild?: boolean;
88
+ } & react.RefAttributes<HTMLDivElement>>;
89
+ readonly Error: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
90
+ children?: ReactNode | ((error: unknown) => ReactNode);
91
+ } & react.RefAttributes<HTMLDivElement>>;
92
+ readonly Suggestions: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"div">, "children"> & {
93
+ children?: ThreadSuggestionChildren;
94
+ keepMounted?: boolean;
95
+ } & react.RefAttributes<HTMLDivElement>>;
96
+ readonly Suggestion: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"button">, "children"> & {
97
+ children?: ReactNode;
98
+ prompt?: string;
99
+ suggestion?: ChatSuggestion;
100
+ } & react.RefAttributes<HTMLButtonElement>>;
101
+ readonly ScrollToBottom: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref">, "asChild"> & {
102
+ asChild?: boolean;
103
+ } & react.RefAttributes<HTMLButtonElement>>;
104
+ };
105
+
106
+ export { ChatController, Composer, type ComposerSubmitMessage, type ComposerSubmitMessageArgs, Thread };
@@ -0,0 +1,22 @@
1
+ import {
2
+ Composer,
3
+ Thread
4
+ } from "../chunk-AXZB6JSE.js";
5
+ import "../chunk-AOZN3SWB.js";
6
+ import "../chunk-RRINF6FN.js";
7
+ import "../chunk-T3ZFZ3NP.js";
8
+ import {
9
+ ChatProvider,
10
+ useChatContext,
11
+ useComposer,
12
+ useThread
13
+ } from "../chunk-7AS6R7BB.js";
14
+ export {
15
+ ChatProvider,
16
+ Composer,
17
+ Thread,
18
+ useChatContext,
19
+ useComposer,
20
+ useThread
21
+ };
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,13 @@
1
+ import { UseChatResult } from '@anvia/react';
2
+ import { ReactNode, ReactElement } from 'react';
3
+
4
+ type ChatController<TEvent = unknown> = UseChatResult<TEvent>;
5
+ type ChatProviderProps<TEvent = unknown> = {
6
+ controller: ChatController<TEvent>;
7
+ children?: ReactNode;
8
+ };
9
+ declare function ChatProvider<TEvent = unknown>({ controller, children, }: ChatProviderProps<TEvent>): ReactElement;
10
+ declare function useChatContext<TEvent = unknown>(): ChatController<TEvent>;
11
+ declare function useHumanInput(): ChatController["humanInput"];
12
+
13
+ export { type ChatController as C, ChatProvider as a, type ChatProviderProps as b, useHumanInput as c, useChatContext as u };
@@ -0,0 +1,230 @@
1
+ // src/contexts/attachment.tsx
2
+ import { createContext, createElement, useContext } from "react";
3
+ var AttachmentContext = createContext(void 0);
4
+ function InternalAttachmentProvider({
5
+ value,
6
+ children
7
+ }) {
8
+ return createElement(AttachmentContext.Provider, { value }, children);
9
+ }
10
+ function useAttachment() {
11
+ const value = useContext(AttachmentContext);
12
+ if (value === void 0) {
13
+ throw new Error("Attachment primitives must be used inside Attachment.Root.");
14
+ }
15
+ return value;
16
+ }
17
+
18
+ // src/contexts/chat.tsx
19
+ import { createContext as createContext2, createElement as createElement2, useContext as useContext2 } from "react";
20
+ var ChatContext = createContext2(void 0);
21
+ function ChatProvider({
22
+ controller,
23
+ children
24
+ }) {
25
+ return createElement2(ChatContext.Provider, { value: controller }, children);
26
+ }
27
+ function useChatContext() {
28
+ const value = useContext2(ChatContext);
29
+ if (value === void 0) {
30
+ throw new Error("Anvia chat primitives must be used inside ChatProvider.");
31
+ }
32
+ return value;
33
+ }
34
+ function useHumanInput() {
35
+ return useChatContext().humanInput;
36
+ }
37
+
38
+ // src/contexts/completion.tsx
39
+ import { createContext as createContext3, createElement as createElement3, useContext as useContext3 } from "react";
40
+ var CompletionContext = createContext3(void 0);
41
+ function CompletionProvider({
42
+ controller,
43
+ children
44
+ }) {
45
+ return createElement3(
46
+ CompletionContext.Provider,
47
+ { value: controller },
48
+ children
49
+ );
50
+ }
51
+ function useCompletionContext() {
52
+ const value = useContext3(CompletionContext);
53
+ if (value === void 0) {
54
+ throw new Error("Anvia completion primitives must be used inside CompletionProvider.");
55
+ }
56
+ return value;
57
+ }
58
+
59
+ // src/contexts/completion-input.tsx
60
+ import { createContext as createContext4, createElement as createElement4, useContext as useContext4 } from "react";
61
+ var CompletionInputContext = createContext4(void 0);
62
+ function InternalCompletionInputProvider({
63
+ value,
64
+ children
65
+ }) {
66
+ return createElement4(CompletionInputContext.Provider, { value }, children);
67
+ }
68
+ function useCompletionInput() {
69
+ const value = useContext4(CompletionInputContext);
70
+ if (value === void 0) {
71
+ throw new Error("Completion input primitives must be used inside Completion.Form.");
72
+ }
73
+ return value;
74
+ }
75
+
76
+ // src/contexts/composer.tsx
77
+ import { createContext as createContext5, createElement as createElement5, useContext as useContext5 } from "react";
78
+ var ComposerContext = createContext5(void 0);
79
+ function InternalComposerProvider({
80
+ value,
81
+ children
82
+ }) {
83
+ return createElement5(ComposerContext.Provider, { value }, children);
84
+ }
85
+ function useComposer() {
86
+ const value = useContext5(ComposerContext);
87
+ if (value === void 0) {
88
+ throw new Error("Composer primitives must be used inside Composer.Root.");
89
+ }
90
+ return value;
91
+ }
92
+
93
+ // src/contexts/human-input.tsx
94
+ import {
95
+ createContext as createContext6,
96
+ createElement as createElement6,
97
+ useContext as useContext6,
98
+ useMemo,
99
+ useState
100
+ } from "react";
101
+ var ApprovalContext = createContext6(void 0);
102
+ var QuestionContext = createContext6(void 0);
103
+ var QuestionPromptContext = createContext6(void 0);
104
+ function InternalApprovalProvider({
105
+ approval,
106
+ children
107
+ }) {
108
+ const [reason, setReason] = useState("");
109
+ const value = useMemo(
110
+ () => ({ approval, reason, setReason }),
111
+ [approval, reason]
112
+ );
113
+ return createElement6(ApprovalContext.Provider, { value }, children);
114
+ }
115
+ function InternalQuestionProvider({
116
+ value,
117
+ children
118
+ }) {
119
+ return createElement6(QuestionContext.Provider, { value }, children);
120
+ }
121
+ function InternalQuestionPromptProvider({
122
+ prompt,
123
+ children
124
+ }) {
125
+ return createElement6(QuestionPromptContext.Provider, { value: { prompt } }, children);
126
+ }
127
+ function useApproval() {
128
+ const value = useContext6(ApprovalContext);
129
+ if (value === void 0) {
130
+ throw new Error("Approval primitives must be used inside HumanInput.Approval.");
131
+ }
132
+ return value;
133
+ }
134
+ function useQuestion() {
135
+ const value = useContext6(QuestionContext);
136
+ if (value === void 0) {
137
+ throw new Error("Question primitives must be used inside HumanInput.Question.");
138
+ }
139
+ return value;
140
+ }
141
+ function useQuestionPrompt() {
142
+ const value = useContext6(QuestionPromptContext);
143
+ if (value === void 0) {
144
+ throw new Error("Question choice primitives must be used inside HumanInput.QuestionPrompt.");
145
+ }
146
+ return value;
147
+ }
148
+
149
+ // src/contexts/message.tsx
150
+ import { createContext as createContext7, createElement as createElement7, useContext as useContext7 } from "react";
151
+ var MessageContext = createContext7(void 0);
152
+ var MessagePartContext = createContext7(void 0);
153
+ function InternalMessageProvider({
154
+ message,
155
+ children
156
+ }) {
157
+ return createElement7(MessageContext.Provider, { value: { message } }, children);
158
+ }
159
+ function InternalMessagePartProvider({
160
+ part,
161
+ children
162
+ }) {
163
+ return createElement7(MessagePartContext.Provider, { value: { part } }, children);
164
+ }
165
+ function useMessage() {
166
+ const value = useContext7(MessageContext);
167
+ if (value === void 0) {
168
+ throw new Error("Message primitives must be used inside Message.Root or Thread.Messages.");
169
+ }
170
+ return value;
171
+ }
172
+ function useMessagePart() {
173
+ const value = useContext7(MessagePartContext);
174
+ if (value === void 0) {
175
+ throw new Error("Message part primitives must be used inside Message.Parts or Message.Part.");
176
+ }
177
+ return value;
178
+ }
179
+ function useOptionalMessagePart() {
180
+ return useContext7(MessagePartContext);
181
+ }
182
+
183
+ // src/contexts/thread.tsx
184
+ import {
185
+ createContext as createContext8,
186
+ createElement as createElement8,
187
+ useContext as useContext8
188
+ } from "react";
189
+ var ThreadContext = createContext8(void 0);
190
+ function InternalThreadProvider({
191
+ value,
192
+ children
193
+ }) {
194
+ return createElement8(ThreadContext.Provider, { value }, children);
195
+ }
196
+ function useThread() {
197
+ const value = useContext8(ThreadContext);
198
+ if (value === void 0) {
199
+ throw new Error("Thread primitives must be used inside Thread.Root.");
200
+ }
201
+ return value;
202
+ }
203
+
204
+ export {
205
+ InternalAttachmentProvider,
206
+ useAttachment,
207
+ ChatProvider,
208
+ useChatContext,
209
+ useHumanInput,
210
+ CompletionProvider,
211
+ useCompletionContext,
212
+ InternalCompletionInputProvider,
213
+ useCompletionInput,
214
+ InternalComposerProvider,
215
+ useComposer,
216
+ InternalApprovalProvider,
217
+ InternalQuestionProvider,
218
+ InternalQuestionPromptProvider,
219
+ useApproval,
220
+ useQuestion,
221
+ useQuestionPrompt,
222
+ InternalMessageProvider,
223
+ InternalMessagePartProvider,
224
+ useMessage,
225
+ useMessagePart,
226
+ useOptionalMessagePart,
227
+ InternalThreadProvider,
228
+ useThread
229
+ };
230
+ //# sourceMappingURL=chunk-7AS6R7BB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/contexts/attachment.tsx","../src/contexts/chat.tsx","../src/contexts/completion.tsx","../src/contexts/completion-input.tsx","../src/contexts/composer.tsx","../src/contexts/human-input.tsx","../src/contexts/message.tsx","../src/contexts/thread.tsx"],"sourcesContent":["import type { UIAttachment } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type AttachmentContextValue = {\n attachment: UIAttachment;\n remove?(): void;\n};\n\nconst AttachmentContext = createContext<AttachmentContextValue | undefined>(undefined);\n\nexport function InternalAttachmentProvider({\n value,\n children,\n}: {\n value: AttachmentContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(AttachmentContext.Provider, { value }, children);\n}\n\nexport function useAttachment(): AttachmentContextValue {\n const value = useContext(AttachmentContext);\n if (value === undefined) {\n throw new Error(\"Attachment primitives must be used inside Attachment.Root.\");\n }\n return value;\n}\n","import type { UseChatResult } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ChatController<TEvent = unknown> = UseChatResult<TEvent>;\n\nexport type ChatProviderProps<TEvent = unknown> = {\n controller: ChatController<TEvent>;\n children?: ReactNode;\n};\n\nconst ChatContext = createContext<ChatController | undefined>(undefined);\n\nexport function ChatProvider<TEvent = unknown>({\n controller,\n children,\n}: ChatProviderProps<TEvent>): ReactElement {\n return createElement(ChatContext.Provider, { value: controller as ChatController }, children);\n}\n\nexport function useChatContext<TEvent = unknown>(): ChatController<TEvent> {\n const value = useContext(ChatContext);\n if (value === undefined) {\n throw new Error(\"Anvia chat primitives must be used inside ChatProvider.\");\n }\n return value as ChatController<TEvent>;\n}\n\nexport function useHumanInput(): ChatController[\"humanInput\"] {\n return useChatContext().humanInput;\n}\n","import type { UseCompletionResult } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type CompletionController<TEvent = unknown> = UseCompletionResult<TEvent>;\n\nexport type CompletionProviderProps<TEvent = unknown> = {\n controller: CompletionController<TEvent>;\n children?: ReactNode;\n};\n\nconst CompletionContext = createContext<CompletionController | undefined>(undefined);\n\nexport function CompletionProvider<TEvent = unknown>({\n controller,\n children,\n}: CompletionProviderProps<TEvent>): ReactElement {\n return createElement(\n CompletionContext.Provider,\n { value: controller as CompletionController },\n children,\n );\n}\n\nexport function useCompletionContext<TEvent = unknown>(): CompletionController<TEvent> {\n const value = useContext(CompletionContext);\n if (value === undefined) {\n throw new Error(\"Anvia completion primitives must be used inside CompletionProvider.\");\n }\n return value as CompletionController<TEvent>;\n}\n","import { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nimport type { CompletionController } from \"./completion\";\n\nexport type CompletionInputContextValue = {\n input: string;\n setInput(input: string): void;\n submit(): Promise<void>;\n stop(): void;\n status: CompletionController[\"status\"];\n canSubmit: boolean;\n canStop: boolean;\n};\n\nconst CompletionInputContext = createContext<CompletionInputContextValue | undefined>(undefined);\n\nexport function InternalCompletionInputProvider({\n value,\n children,\n}: {\n value: CompletionInputContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(CompletionInputContext.Provider, { value }, children);\n}\n\nexport function useCompletionInput(): CompletionInputContextValue {\n const value = useContext(CompletionInputContext);\n if (value === undefined) {\n throw new Error(\"Completion input primitives must be used inside Completion.Form.\");\n }\n return value;\n}\n","import type { CreateUIAttachment, UIAttachment } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\nimport type { ChatController } from \"./chat\";\n\nexport type ComposerAttachmentInput = File | CreateUIAttachment;\nexport type ComposerAttachmentsUpdate =\n | UIAttachment[]\n | ((attachments: UIAttachment[]) => UIAttachment[]);\n\nexport type ComposerContextValue = {\n input: string;\n setInput(input: string): void;\n attachments: UIAttachment[];\n setAttachments(update: ComposerAttachmentsUpdate): void;\n addAttachment(attachment: ComposerAttachmentInput): Promise<void>;\n removeAttachment(id: string): void;\n clearAttachments(): void;\n submit(): Promise<void>;\n stop(): void;\n status: ChatController[\"status\"];\n canSubmit: boolean;\n canStop: boolean;\n};\n\nconst ComposerContext = createContext<ComposerContextValue | undefined>(undefined);\n\nexport function InternalComposerProvider({\n value,\n children,\n}: {\n value: ComposerContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ComposerContext.Provider, { value }, children);\n}\n\nexport function useComposer(): ComposerContextValue {\n const value = useContext(ComposerContext);\n if (value === undefined) {\n throw new Error(\"Composer primitives must be used inside Composer.Root.\");\n }\n return value;\n}\n","import type {\n ToolApproval,\n ToolQuestion,\n ToolQuestionAnswer,\n ToolQuestionPrompt,\n} from \"@anvia/react\";\nimport {\n createContext,\n createElement,\n type ReactElement,\n type ReactNode,\n useContext,\n useMemo,\n useState,\n} from \"react\";\n\nexport type ApprovalContextValue = {\n approval: ToolApproval;\n reason: string;\n setReason(reason: string): void;\n};\n\nexport type QuestionContextValue = {\n question: ToolQuestion;\n answers: Record<string, ToolQuestionAnswer>;\n setAnswer(prompt: ToolQuestionPrompt, answer: ToolQuestionAnswer): void;\n};\n\nexport type QuestionPromptContextValue = {\n prompt: ToolQuestionPrompt;\n};\n\nconst ApprovalContext = createContext<ApprovalContextValue | undefined>(undefined);\nconst QuestionContext = createContext<QuestionContextValue | undefined>(undefined);\nconst QuestionPromptContext = createContext<QuestionPromptContextValue | undefined>(undefined);\n\nexport function InternalApprovalProvider({\n approval,\n children,\n}: {\n approval: ToolApproval;\n children?: ReactNode;\n}): ReactElement {\n const [reason, setReason] = useState(\"\");\n const value = useMemo<ApprovalContextValue>(\n () => ({ approval, reason, setReason }),\n [approval, reason],\n );\n\n return createElement(ApprovalContext.Provider, { value }, children);\n}\n\nexport function InternalQuestionProvider({\n value,\n children,\n}: {\n value: QuestionContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(QuestionContext.Provider, { value }, children);\n}\n\nexport function InternalQuestionPromptProvider({\n prompt,\n children,\n}: {\n prompt: ToolQuestionPrompt;\n children?: ReactNode;\n}): ReactElement {\n return createElement(QuestionPromptContext.Provider, { value: { prompt } }, children);\n}\n\nexport function useApproval(): ApprovalContextValue {\n const value = useContext(ApprovalContext);\n if (value === undefined) {\n throw new Error(\"Approval primitives must be used inside HumanInput.Approval.\");\n }\n return value;\n}\n\nexport function useQuestion(): QuestionContextValue {\n const value = useContext(QuestionContext);\n if (value === undefined) {\n throw new Error(\"Question primitives must be used inside HumanInput.Question.\");\n }\n return value;\n}\n\nexport function useQuestionPrompt(): QuestionPromptContextValue {\n const value = useContext(QuestionPromptContext);\n if (value === undefined) {\n throw new Error(\"Question choice primitives must be used inside HumanInput.QuestionPrompt.\");\n }\n return value;\n}\n","import type { UIMessage, UIMessagePart } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type MessageContextValue = {\n message: UIMessage;\n};\n\nexport type MessagePartContextValue = {\n part: UIMessagePart;\n};\n\nconst MessageContext = createContext<MessageContextValue | undefined>(undefined);\nconst MessagePartContext = createContext<MessagePartContextValue | undefined>(undefined);\n\nexport function InternalMessageProvider({\n message,\n children,\n}: {\n message: UIMessage;\n children?: ReactNode;\n}): ReactElement {\n return createElement(MessageContext.Provider, { value: { message } }, children);\n}\n\nexport function InternalMessagePartProvider({\n part,\n children,\n}: {\n part: UIMessagePart;\n children?: ReactNode;\n}): ReactElement {\n return createElement(MessagePartContext.Provider, { value: { part } }, children);\n}\n\nexport function useMessage(): MessageContextValue {\n const value = useContext(MessageContext);\n if (value === undefined) {\n throw new Error(\"Message primitives must be used inside Message.Root or Thread.Messages.\");\n }\n return value;\n}\n\nexport function useMessagePart(): MessagePartContextValue {\n const value = useContext(MessagePartContext);\n if (value === undefined) {\n throw new Error(\"Message part primitives must be used inside Message.Parts or Message.Part.\");\n }\n return value;\n}\n\nexport function useOptionalMessagePart(): MessagePartContextValue | undefined {\n return useContext(MessagePartContext);\n}\n","import {\n createContext,\n createElement,\n type MutableRefObject,\n type ReactElement,\n type ReactNode,\n useContext,\n} from \"react\";\n\nexport type ThreadContextValue = {\n viewportRef: MutableRefObject<HTMLElement | null>;\n atBottom: boolean;\n setAtBottom(atBottom: boolean): void;\n scrollToBottom(behavior?: ScrollBehavior): void;\n};\n\nconst ThreadContext = createContext<ThreadContextValue | undefined>(undefined);\n\nexport function InternalThreadProvider({\n value,\n children,\n}: {\n value: ThreadContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ThreadContext.Provider, { value }, children);\n}\n\nexport function useThread(): ThreadContextValue {\n const value = useContext(ThreadContext);\n if (value === undefined) {\n throw new Error(\"Thread primitives must be used inside Thread.Root.\");\n }\n return value;\n}\n"],"mappings":";AACA,SAAS,eAAe,eAAkD,kBAAkB;AAO5F,IAAM,oBAAoB,cAAkD,MAAS;AAE9E,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AACF,GAGiB;AACf,SAAO,cAAc,kBAAkB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACtE;AAEO,SAAS,gBAAwC;AACtD,QAAM,QAAQ,WAAW,iBAAiB;AAC1C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,4DAA4D;AAAA,EAC9E;AACA,SAAO;AACT;;;ACzBA,SAAS,iBAAAA,gBAAe,iBAAAC,gBAAkD,cAAAC,mBAAkB;AAS5F,IAAM,cAAcF,eAA0C,MAAS;AAEhE,SAAS,aAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAA4C;AAC1C,SAAOC,eAAc,YAAY,UAAU,EAAE,OAAO,WAA6B,GAAG,QAAQ;AAC9F;AAEO,SAAS,iBAA2D;AACzE,QAAM,QAAQC,YAAW,WAAW;AACpC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC3E;AACA,SAAO;AACT;AAEO,SAAS,gBAA8C;AAC5D,SAAO,eAAe,EAAE;AAC1B;;;AC5BA,SAAS,iBAAAC,gBAAe,iBAAAC,gBAAkD,cAAAC,mBAAkB;AAS5F,IAAM,oBAAoBF,eAAgD,MAAS;AAE5E,SAAS,mBAAqC;AAAA,EACnD;AAAA,EACA;AACF,GAAkD;AAChD,SAAOC;AAAA,IACL,kBAAkB;AAAA,IAClB,EAAE,OAA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AAS,aAAkC;AAChD,QAAM,QAAQC,YAAW,cAAc;AACvC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,yEAAyE;AAAA,EAC3F;AACA,SAAO;AACT;AAEO,SAAS,iBAA0C;AACxD,QAAM,QAAQA,YAAW,kBAAkB;AAC3C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,4EAA4E;AAAA,EAC9F;AACA,SAAO;AACT;AAEO,SAAS,yBAA8D;AAC5E,SAAOA,YAAW,kBAAkB;AACtC;;;ACpDA;AAAA,EACE,iBAAAC;AAAA,EACA,iBAAAC;AAAA,EAIA,cAAAC;AAAA,OACK;AASP,IAAM,gBAAgBF,eAA8C,MAAS;AAEtE,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AACF,GAGiB;AACf,SAAOC,eAAc,cAAc,UAAU,EAAE,MAAM,GAAG,QAAQ;AAClE;AAEO,SAAS,YAAgC;AAC9C,QAAM,QAAQC,YAAW,aAAa;AACtC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;","names":["createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext"]}