@anvia/react-ui 0.5.1 → 0.6.1
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 +19 -12
- package/dist/attachment/index.js +2 -2
- package/dist/chat/index.js +5 -4
- package/dist/{chunk-YQJLVBQD.js → chunk-43U2XQP2.js} +8 -2
- package/dist/{chunk-YQJLVBQD.js.map → chunk-43U2XQP2.js.map} +1 -1
- package/dist/{chunk-GZHTC36V.js → chunk-56CV6S76.js} +2 -2
- package/dist/{chunk-NGEDM4XU.js → chunk-7HR34SOF.js} +2 -2
- package/dist/{chunk-ZODMCETL.js → chunk-7I6XUWM7.js} +136 -72
- package/dist/chunk-7I6XUWM7.js.map +1 -0
- package/dist/{chunk-2N5PXLAS.js → chunk-7RMRM7W3.js} +2 -2
- package/dist/{chunk-SWGMBZR2.js → chunk-LM5SU5AP.js} +23 -5
- package/dist/{chunk-SWGMBZR2.js.map → chunk-LM5SU5AP.js.map} +1 -1
- package/dist/{chunk-KNOZLODL.js → chunk-R3NA6BWW.js} +2 -2
- package/dist/{chunk-WUMACFYS.js → chunk-SBYUKODG.js} +2 -2
- package/dist/chunk-UESNSQGQ.js +302 -0
- package/dist/chunk-UESNSQGQ.js.map +1 -0
- package/dist/{chunk-T6GPGCK4.js → chunk-VEYJNQVW.js} +2 -2
- package/dist/completion/index.js +2 -2
- package/dist/human-input/index.js +2 -2
- package/dist/image/index.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +13 -9
- package/dist/message/index.d.ts +8 -13
- package/dist/message/index.js +4 -3
- package/dist/{message-Beb4ZLNU.d.ts → message-CkEnKhAn.d.ts} +2 -0
- package/dist/selection-toolbar/index.js +2 -2
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +1 -1
- package/dist/stream/index.d.ts +20 -0
- package/dist/stream/index.js +8 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/styles.css +9 -0
- package/dist/styles.css +5 -8
- package/dist/thread-list/index.js +2 -2
- package/package.json +20 -14
- package/dist/chunk-ZODMCETL.js.map +0 -1
- /package/dist/{chunk-GZHTC36V.js.map → chunk-56CV6S76.js.map} +0 -0
- /package/dist/{chunk-NGEDM4XU.js.map → chunk-7HR34SOF.js.map} +0 -0
- /package/dist/{chunk-2N5PXLAS.js.map → chunk-7RMRM7W3.js.map} +0 -0
- /package/dist/{chunk-KNOZLODL.js.map → chunk-R3NA6BWW.js.map} +0 -0
- /package/dist/{chunk-WUMACFYS.js.map → chunk-SBYUKODG.js.map} +0 -0
- /package/dist/{chunk-T6GPGCK4.js.map → chunk-VEYJNQVW.js.map} +0 -0
package/README.md
CHANGED
|
@@ -60,18 +60,25 @@ support inline `@`, `/`, `$`, or other entity chips; selected entities are submi
|
|
|
60
60
|
`metadata.composer.entities`. Use `Composer.TextareaInput` when you need the previous native
|
|
61
61
|
textarea behavior.
|
|
62
62
|
|
|
63
|
-
Streaming
|
|
64
|
-
`UIMessage[]` state
|
|
63
|
+
Streaming smoothing is opt-in and display-only. Keep `useChat` as the owner of transport and
|
|
64
|
+
`UIMessage[]` state. Keep the lifecycle mounted after streaming stops so its buffered tail drains;
|
|
65
|
+
`Message.Parts` also keeps later tool parts behind text that has not been revealed yet:
|
|
65
66
|
|
|
66
67
|
```tsx
|
|
67
|
-
<Message.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
<Message.Parts
|
|
69
|
+
stream={{
|
|
70
|
+
isStreaming:
|
|
71
|
+
chat.status === "streaming" &&
|
|
72
|
+
message.role === "assistant" &&
|
|
73
|
+
chat.messages.at(-1)?.id === message.id,
|
|
74
|
+
resetKey: message.id,
|
|
75
|
+
flushImmediately: chat.status === "error",
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{(part) => (part.type === "text" ? <Message.Markdown /> : <Message.Part />)}
|
|
79
|
+
</Message.Parts>
|
|
77
80
|
```
|
|
81
|
+
|
|
82
|
+
For app-owned text state, `StreamMarkdown` is available from `@anvia/react-ui/stream`. It is a
|
|
83
|
+
context-free renderer: pass the already displayed text as `content`, set `live` only for its growing
|
|
84
|
+
tail, and import `@anvia/react-ui/stream/styles.css` for the settle animation.
|
package/dist/attachment/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Attachment
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SBYUKODG.js";
|
|
4
4
|
import "../chunk-T3ZFZ3NP.js";
|
|
5
5
|
import {
|
|
6
6
|
useAttachment
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-43U2XQP2.js";
|
|
8
8
|
export {
|
|
9
9
|
Attachment,
|
|
10
10
|
useAttachment
|
package/dist/chat/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Composer,
|
|
3
3
|
Thread
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-LM5SU5AP.js";
|
|
5
|
+
import "../chunk-7I6XUWM7.js";
|
|
6
|
+
import "../chunk-UESNSQGQ.js";
|
|
7
|
+
import "../chunk-SBYUKODG.js";
|
|
7
8
|
import "../chunk-T3ZFZ3NP.js";
|
|
8
9
|
import {
|
|
9
10
|
ChatProvider,
|
|
10
11
|
useChatContext,
|
|
11
12
|
useComposer,
|
|
12
13
|
useThread
|
|
13
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-43U2XQP2.js";
|
|
14
15
|
export {
|
|
15
16
|
ChatProvider,
|
|
16
17
|
Composer,
|
|
@@ -178,9 +178,15 @@ function InternalMessageProvider({
|
|
|
178
178
|
}
|
|
179
179
|
function InternalMessagePartProvider({
|
|
180
180
|
part,
|
|
181
|
+
isLive = false,
|
|
182
|
+
streamControlled = false,
|
|
181
183
|
children
|
|
182
184
|
}) {
|
|
183
|
-
return createElement8(
|
|
185
|
+
return createElement8(
|
|
186
|
+
MessagePartContext.Provider,
|
|
187
|
+
{ value: { isLive, part, streamControlled } },
|
|
188
|
+
children
|
|
189
|
+
);
|
|
184
190
|
}
|
|
185
191
|
function useMessage() {
|
|
186
192
|
const value = useContext8(MessageContext);
|
|
@@ -304,4 +310,4 @@ export {
|
|
|
304
310
|
useThreadList,
|
|
305
311
|
useThreadListItem
|
|
306
312
|
};
|
|
307
|
-
//# sourceMappingURL=chunk-
|
|
313
|
+
//# sourceMappingURL=chunk-43U2XQP2.js.map
|
|
@@ -1 +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/image.tsx","../src/contexts/message.tsx","../src/contexts/selection-toolbar.tsx","../src/contexts/thread.tsx","../src/contexts/thread-list.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\nexport function useOptionalAttachment(): AttachmentContextValue | undefined {\n return useContext(AttachmentContext);\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 ComposerEntityData =\n | string\n | number\n | boolean\n | null\n | ComposerEntityData[]\n | { [key: string]: ComposerEntityData | undefined };\n\nexport type ComposerAttachmentInput = File | CreateUIAttachment;\nexport type ComposerAttachmentsUpdate =\n | UIAttachment[]\n | ((attachments: UIAttachment[]) => UIAttachment[]);\nexport type ComposerEntitiesUpdate =\n | ComposerEntity[]\n | ((entities: ComposerEntity[]) => ComposerEntity[]);\nexport type ComposerQuote = {\n text: string;\n messageId: string;\n};\nexport type ComposerTriggerItem = {\n id: string;\n label: string;\n text?: string | undefined;\n detail?: ReactNode | undefined;\n data?: ComposerEntityData | undefined;\n disabled?: boolean | undefined;\n};\nexport type ComposerTriggerItemsArgs = {\n trigger: ComposerTriggerDefinition;\n query: string;\n input: string;\n entities: ComposerEntity[];\n signal: AbortSignal;\n};\nexport type ComposerTriggerItems =\n | ComposerTriggerItem[]\n | ((args: ComposerTriggerItemsArgs) => ComposerTriggerItem[] | Promise<ComposerTriggerItem[]>);\nexport type ComposerTriggerDefinition = {\n id: string;\n char: string;\n items: ComposerTriggerItems;\n minQueryLength?: number | undefined;\n allowedPrefixes?: string[] | null | undefined;\n startOfLine?: boolean | undefined;\n allowSpaces?: boolean | undefined;\n};\nexport type ComposerEntity = {\n id: string;\n triggerId: string;\n trigger: string;\n label: string;\n text: string;\n range: {\n from: number;\n to: number;\n };\n data?: ComposerEntityData | undefined;\n};\nexport type ComposerMessageMetadata = {\n composer: {\n entities: ComposerEntity[];\n };\n};\nexport type ComposerTriggerState = {\n trigger: ComposerTriggerDefinition;\n query: string;\n items: ComposerTriggerItem[];\n loading: boolean;\n selectedIndex: number;\n rect?: {\n top: number;\n right: number;\n bottom: number;\n left: number;\n width: number;\n height: number;\n };\n selectItem(item: ComposerTriggerItem): void;\n setSelectedIndex(index: number): void;\n};\nexport type ComposerTriggerStateUpdate =\n | ComposerTriggerState\n | undefined\n | ((state: ComposerTriggerState | undefined) => ComposerTriggerState | undefined);\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 entities: ComposerEntity[];\n setEntities(update: ComposerEntitiesUpdate): void;\n quote?: ComposerQuote | undefined;\n setQuote(quote: ComposerQuote | undefined): void;\n clearQuote(): void;\n triggers: ComposerTriggerDefinition[];\n activeTrigger?: ComposerTriggerState | undefined;\n setActiveTrigger(update: ComposerTriggerStateUpdate): 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 { UIAttachment } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ImageContextValue = {\n attachment: UIAttachment;\n src?: string;\n name?: string;\n mediaType?: string;\n isImage: boolean;\n zoomOpen: boolean;\n setZoomOpen(open: boolean): void;\n};\n\nconst ImageContext = createContext<ImageContextValue | undefined>(undefined);\n\nexport function InternalImageProvider({\n value,\n children,\n}: {\n value: ImageContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ImageContext.Provider, { value }, children);\n}\n\nexport function useImage(): ImageContextValue {\n const value = useContext(ImageContext);\n if (value === undefined) {\n throw new Error(\"Image primitives must be used inside Image.Root.\");\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 { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type SelectionToolbarSelection = {\n text: string;\n messageId: string;\n rect: DOMRect;\n};\n\nexport type SelectionToolbarContextValue = {\n selection?: SelectionToolbarSelection;\n quote(): void;\n copy(): Promise<void>;\n clear(): void;\n};\n\nconst SelectionToolbarContext = createContext<SelectionToolbarContextValue | undefined>(undefined);\n\nexport function InternalSelectionToolbarProvider({\n value,\n children,\n}: {\n value: SelectionToolbarContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(SelectionToolbarContext.Provider, { value }, children);\n}\n\nexport function useSelectionToolbar(): SelectionToolbarContextValue {\n const value = useContext(SelectionToolbarContext);\n if (value === undefined) {\n throw new Error(\"SelectionToolbar primitives must be used inside SelectionToolbar.Root.\");\n }\n return value;\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","import { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ThreadListRecord = {\n id: string;\n title?: string;\n createdAt?: string | Date;\n updatedAt?: string | Date;\n archived?: boolean;\n metadata?: unknown;\n};\n\nexport type ThreadListController = {\n threads: ThreadListRecord[];\n activeThreadId?: string;\n status?: \"idle\" | \"loading\" | \"error\";\n error?: unknown;\n createThread(): Promise<void> | void;\n switchThread(threadId: string): Promise<void> | void;\n archiveThread?(threadId: string): Promise<void> | void;\n unarchiveThread?(threadId: string): Promise<void> | void;\n deleteThread?(threadId: string): Promise<void> | void;\n};\n\nexport type ThreadListItemContextValue = {\n thread: ThreadListRecord;\n active: boolean;\n};\n\nexport type ThreadListProviderProps = {\n controller: ThreadListController;\n children?: ReactNode;\n};\n\nconst ThreadListContext = createContext<ThreadListController | undefined>(undefined);\nconst ThreadListItemContext = createContext<ThreadListItemContextValue | undefined>(undefined);\n\nexport function ThreadListProvider({\n controller,\n children,\n}: ThreadListProviderProps): ReactElement {\n return createElement(ThreadListContext.Provider, { value: controller }, children);\n}\n\nexport function InternalThreadListItemProvider({\n value,\n children,\n}: {\n value: ThreadListItemContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ThreadListItemContext.Provider, { value }, children);\n}\n\nexport function useThreadList(): ThreadListController {\n const value = useContext(ThreadListContext);\n if (value === undefined) {\n throw new Error(\"ThreadList primitives must be used inside ThreadListProvider.\");\n }\n return value;\n}\n\nexport function useThreadListItem(): ThreadListItemContextValue {\n const value = useContext(ThreadListItemContext);\n if (value === undefined) {\n throw new Error(\"ThreadListItem primitives must be used inside ThreadList.Items.\");\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;AAEO,SAAS,wBAA4D;AAC1E,SAAO,WAAW,iBAAiB;AACrC;;;AC7BA,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,gBAA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AM,IAAI,MAAM,wEAAwE;AAAA,EAC1F;AACA,SAAO;AACT;;;ACjCA;AAAA,EACE,iBAAAC;AAAA,EACA,iBAAAC;AAAA,EAIA,cAAAC;AAAA,OACK;AASP,IAAM,gBAAgBF,gBAA8C,MAAS;AAEtE,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AACF,GAGiB;AACf,SAAOC,gBAAc,cAAc,UAAU,EAAE,MAAM,GAAG,QAAQ;AAClE;AAEO,SAAS,YAAgC;AAC9C,QAAM,QAAQC,aAAW,aAAa;AACtC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;;;AClCA,SAAS,iBAAAC,iBAAe,iBAAAC,iBAAkD,cAAAC,oBAAkB;AAiC5F,IAAM,oBAAoBF,gBAAgD,MAAS;AACnF,IAAM,wBAAwBA,gBAAsD,MAAS;AAEtF,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF,GAA0C;AACxC,SAAOC,gBAAc,kBAAkB,UAAU,EAAE,OAAO,WAAW,GAAG,QAAQ;AAClF;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGiB;AACf,SAAOA,gBAAc,sBAAsB,UAAU,EAAE,MAAM,GAAG,QAAQ;AAC1E;AAEO,SAAS,gBAAsC;AACpD,QAAM,QAAQC,aAAW,iBAAiB;AAC1C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,SAAO;AACT;AAEO,SAAS,oBAAgD;AAC9D,QAAM,QAAQA,aAAW,qBAAqB;AAC9C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,iEAAiE;AAAA,EACnF;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","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext"]}
|
|
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/image.tsx","../src/contexts/message.tsx","../src/contexts/selection-toolbar.tsx","../src/contexts/thread.tsx","../src/contexts/thread-list.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\nexport function useOptionalAttachment(): AttachmentContextValue | undefined {\n return useContext(AttachmentContext);\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 ComposerEntityData =\n | string\n | number\n | boolean\n | null\n | ComposerEntityData[]\n | { [key: string]: ComposerEntityData | undefined };\n\nexport type ComposerAttachmentInput = File | CreateUIAttachment;\nexport type ComposerAttachmentsUpdate =\n | UIAttachment[]\n | ((attachments: UIAttachment[]) => UIAttachment[]);\nexport type ComposerEntitiesUpdate =\n | ComposerEntity[]\n | ((entities: ComposerEntity[]) => ComposerEntity[]);\nexport type ComposerQuote = {\n text: string;\n messageId: string;\n};\nexport type ComposerTriggerItem = {\n id: string;\n label: string;\n text?: string | undefined;\n detail?: ReactNode | undefined;\n data?: ComposerEntityData | undefined;\n disabled?: boolean | undefined;\n};\nexport type ComposerTriggerItemsArgs = {\n trigger: ComposerTriggerDefinition;\n query: string;\n input: string;\n entities: ComposerEntity[];\n signal: AbortSignal;\n};\nexport type ComposerTriggerItems =\n | ComposerTriggerItem[]\n | ((args: ComposerTriggerItemsArgs) => ComposerTriggerItem[] | Promise<ComposerTriggerItem[]>);\nexport type ComposerTriggerDefinition = {\n id: string;\n char: string;\n items: ComposerTriggerItems;\n minQueryLength?: number | undefined;\n allowedPrefixes?: string[] | null | undefined;\n startOfLine?: boolean | undefined;\n allowSpaces?: boolean | undefined;\n};\nexport type ComposerEntity = {\n id: string;\n triggerId: string;\n trigger: string;\n label: string;\n text: string;\n range: {\n from: number;\n to: number;\n };\n data?: ComposerEntityData | undefined;\n};\nexport type ComposerMessageMetadata = {\n composer: {\n entities: ComposerEntity[];\n };\n};\nexport type ComposerTriggerState = {\n trigger: ComposerTriggerDefinition;\n query: string;\n items: ComposerTriggerItem[];\n loading: boolean;\n selectedIndex: number;\n rect?: {\n top: number;\n right: number;\n bottom: number;\n left: number;\n width: number;\n height: number;\n };\n selectItem(item: ComposerTriggerItem): void;\n setSelectedIndex(index: number): void;\n};\nexport type ComposerTriggerStateUpdate =\n | ComposerTriggerState\n | undefined\n | ((state: ComposerTriggerState | undefined) => ComposerTriggerState | undefined);\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 entities: ComposerEntity[];\n setEntities(update: ComposerEntitiesUpdate): void;\n quote?: ComposerQuote | undefined;\n setQuote(quote: ComposerQuote | undefined): void;\n clearQuote(): void;\n triggers: ComposerTriggerDefinition[];\n activeTrigger?: ComposerTriggerState | undefined;\n setActiveTrigger(update: ComposerTriggerStateUpdate): 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 { UIAttachment } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ImageContextValue = {\n attachment: UIAttachment;\n src?: string;\n name?: string;\n mediaType?: string;\n isImage: boolean;\n zoomOpen: boolean;\n setZoomOpen(open: boolean): void;\n};\n\nconst ImageContext = createContext<ImageContextValue | undefined>(undefined);\n\nexport function InternalImageProvider({\n value,\n children,\n}: {\n value: ImageContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ImageContext.Provider, { value }, children);\n}\n\nexport function useImage(): ImageContextValue {\n const value = useContext(ImageContext);\n if (value === undefined) {\n throw new Error(\"Image primitives must be used inside Image.Root.\");\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 isLive: boolean;\n part: UIMessagePart;\n streamControlled: boolean;\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 isLive = false,\n streamControlled = false,\n children,\n}: {\n part: UIMessagePart;\n isLive?: boolean;\n streamControlled?: boolean;\n children?: ReactNode;\n}): ReactElement {\n return createElement(\n MessagePartContext.Provider,\n { value: { isLive, part, streamControlled } },\n children,\n );\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 { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type SelectionToolbarSelection = {\n text: string;\n messageId: string;\n rect: DOMRect;\n};\n\nexport type SelectionToolbarContextValue = {\n selection?: SelectionToolbarSelection;\n quote(): void;\n copy(): Promise<void>;\n clear(): void;\n};\n\nconst SelectionToolbarContext = createContext<SelectionToolbarContextValue | undefined>(undefined);\n\nexport function InternalSelectionToolbarProvider({\n value,\n children,\n}: {\n value: SelectionToolbarContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(SelectionToolbarContext.Provider, { value }, children);\n}\n\nexport function useSelectionToolbar(): SelectionToolbarContextValue {\n const value = useContext(SelectionToolbarContext);\n if (value === undefined) {\n throw new Error(\"SelectionToolbar primitives must be used inside SelectionToolbar.Root.\");\n }\n return value;\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","import { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ThreadListRecord = {\n id: string;\n title?: string;\n createdAt?: string | Date;\n updatedAt?: string | Date;\n archived?: boolean;\n metadata?: unknown;\n};\n\nexport type ThreadListController = {\n threads: ThreadListRecord[];\n activeThreadId?: string;\n status?: \"idle\" | \"loading\" | \"error\";\n error?: unknown;\n createThread(): Promise<void> | void;\n switchThread(threadId: string): Promise<void> | void;\n archiveThread?(threadId: string): Promise<void> | void;\n unarchiveThread?(threadId: string): Promise<void> | void;\n deleteThread?(threadId: string): Promise<void> | void;\n};\n\nexport type ThreadListItemContextValue = {\n thread: ThreadListRecord;\n active: boolean;\n};\n\nexport type ThreadListProviderProps = {\n controller: ThreadListController;\n children?: ReactNode;\n};\n\nconst ThreadListContext = createContext<ThreadListController | undefined>(undefined);\nconst ThreadListItemContext = createContext<ThreadListItemContextValue | undefined>(undefined);\n\nexport function ThreadListProvider({\n controller,\n children,\n}: ThreadListProviderProps): ReactElement {\n return createElement(ThreadListContext.Provider, { value: controller }, children);\n}\n\nexport function InternalThreadListItemProvider({\n value,\n children,\n}: {\n value: ThreadListItemContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ThreadListItemContext.Provider, { value }, children);\n}\n\nexport function useThreadList(): ThreadListController {\n const value = useContext(ThreadListContext);\n if (value === undefined) {\n throw new Error(\"ThreadList primitives must be used inside ThreadListProvider.\");\n }\n return value;\n}\n\nexport function useThreadListItem(): ThreadListItemContextValue {\n const value = useContext(ThreadListItemContext);\n if (value === undefined) {\n throw new Error(\"ThreadListItem primitives must be used inside ThreadList.Items.\");\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;AAEO,SAAS,wBAA4D;AAC1E,SAAO,WAAW,iBAAiB;AACrC;;;AC7BA,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,OAAO,WAAmC;AAAA,IAC5C;AAAA,EACF;A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A;AACF,GAGiB;AACf,SAAOC,gBAAc,cAAc,UAAU,EAAE,MAAM,GAAG,QAAQ;AAClE;AAEO,SAAS,YAAgC;AAC9C,QAAM,QAAQC,aAAW,aAAa;AACtC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,SAAO;AACT;;;AClCA,SAAS,iBAAAC,iBAAe,iBAAAC,iBAAkD,cAAAC,oBAAkB;AAiC5F,IAAM,oBAAoBF,gBAAgD,MAAS;AACnF,IAAM,wBAAwBA,gBAAsD,MAAS;AAEtF,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AACF,GAA0C;AACxC,SAAOC,gBAAc,kBAAkB,UAAU,EAAE,OAAO,WAAW,GAAG,QAAQ;AAClF;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGiB;AACf,SAAOA,gBAAc,sBAAsB,UAAU,EAAE,MAAM,GAAG,QAAQ;AAC1E;AAEO,SAAS,gBAAsC;AACpD,QAAM,QAAQC,aAAW,iBAAiB;AAC1C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,+DAA+D;AAAA,EACjF;AACA,SAAO;AACT;AAEO,SAAS,oBAAgD;AAC9D,QAAM,QAAQA,aAAW,qBAAqB;AAC9C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,iEAAiE;AAAA,EACnF;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","createContext","createElement","useContext","createContext","createElement","useContext","createContext","createElement","useContext"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
InternalSelectionToolbarProvider,
|
|
6
6
|
useSelectionToolbar
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-43U2XQP2.js";
|
|
8
8
|
|
|
9
9
|
// src/selection-toolbar/parts.tsx
|
|
10
10
|
import {
|
|
@@ -229,4 +229,4 @@ var SelectionToolbar = {
|
|
|
229
229
|
export {
|
|
230
230
|
SelectionToolbar
|
|
231
231
|
};
|
|
232
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-56CV6S76.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
InternalImageProvider,
|
|
7
7
|
useImage,
|
|
8
8
|
useOptionalAttachment
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-43U2XQP2.js";
|
|
10
10
|
|
|
11
11
|
// src/image/parts.tsx
|
|
12
12
|
import {
|
|
@@ -429,4 +429,4 @@ var Image = {
|
|
|
429
429
|
export {
|
|
430
430
|
Image
|
|
431
431
|
};
|
|
432
|
-
//# sourceMappingURL=chunk-
|
|
432
|
+
//# sourceMappingURL=chunk-7HR34SOF.js.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StreamMarkdown
|
|
3
|
+
} from "./chunk-UESNSQGQ.js";
|
|
1
4
|
import {
|
|
2
5
|
Attachment
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SBYUKODG.js";
|
|
4
7
|
import {
|
|
5
8
|
renderPrimitive
|
|
6
9
|
} from "./chunk-T3ZFZ3NP.js";
|
|
@@ -11,7 +14,7 @@ import {
|
|
|
11
14
|
useMessage,
|
|
12
15
|
useMessagePart,
|
|
13
16
|
useOptionalMessagePart
|
|
14
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-43U2XQP2.js";
|
|
15
18
|
|
|
16
19
|
// src/message/actions.tsx
|
|
17
20
|
import { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
@@ -151,10 +154,14 @@ var MessageEntity = forwardRef2(function MessageEntity2({ children, entity, ...p
|
|
|
151
154
|
|
|
152
155
|
// src/message/parts.tsx
|
|
153
156
|
import {
|
|
157
|
+
useSmoothStreamItems,
|
|
154
158
|
useSmoothStreamText
|
|
155
159
|
} from "@anvia/react";
|
|
156
|
-
import {
|
|
157
|
-
|
|
160
|
+
import {
|
|
161
|
+
createElement,
|
|
162
|
+
forwardRef as forwardRef3,
|
|
163
|
+
useMemo
|
|
164
|
+
} from "react";
|
|
158
165
|
import remarkGfm from "remark-gfm";
|
|
159
166
|
|
|
160
167
|
// src/entities.ts
|
|
@@ -495,19 +502,65 @@ function findLastIndex(items, predicate) {
|
|
|
495
502
|
|
|
496
503
|
// src/message/parts.tsx
|
|
497
504
|
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
498
|
-
var
|
|
505
|
+
var messagePartStreamAdapter = {
|
|
506
|
+
getKey: (part) => part.id,
|
|
507
|
+
getText: (part) => part.type === "text" || part.type === "reasoning" ? part.text : void 0,
|
|
508
|
+
withText: (part, text) => {
|
|
509
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
510
|
+
return part.text === text ? part : { ...part, text };
|
|
511
|
+
}
|
|
512
|
+
return part;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var MessageParts = forwardRef3(function MessageParts2({ children, filter, stream, ...props }, ref) {
|
|
499
516
|
const { message } = useMessage();
|
|
500
517
|
const parts = filter === void 0 ? message.parts : message.parts.filter(filter);
|
|
518
|
+
if (stream !== void 0) {
|
|
519
|
+
return /* @__PURE__ */ jsx3(SmoothedMessageParts, { ...props, parts, ref, stream, children });
|
|
520
|
+
}
|
|
501
521
|
return renderPrimitive(
|
|
502
522
|
"div",
|
|
503
523
|
{
|
|
504
524
|
...props,
|
|
505
|
-
children: parts
|
|
525
|
+
children: renderMessagePartNodes(parts, children),
|
|
506
526
|
"data-anvia-message-parts": ""
|
|
507
527
|
},
|
|
508
528
|
ref
|
|
509
529
|
);
|
|
510
530
|
});
|
|
531
|
+
var SmoothedMessageParts = forwardRef3(
|
|
532
|
+
function SmoothedMessageParts2({ children, parts, stream, ...props }, ref) {
|
|
533
|
+
const smooth = useSmoothStreamItems(parts, {
|
|
534
|
+
adapter: messagePartStreamAdapter,
|
|
535
|
+
isStreaming: stream.isStreaming,
|
|
536
|
+
resetKey: stream.resetKey,
|
|
537
|
+
...stream.flushImmediately === void 0 ? {} : { flushImmediately: stream.flushImmediately }
|
|
538
|
+
});
|
|
539
|
+
return renderPrimitive(
|
|
540
|
+
"div",
|
|
541
|
+
{
|
|
542
|
+
...props,
|
|
543
|
+
children: renderMessagePartNodes(smooth.items, children, smooth.liveItemKey),
|
|
544
|
+
"data-anvia-message-parts": "",
|
|
545
|
+
"data-draining": smooth.isDraining ? "" : void 0,
|
|
546
|
+
"data-streaming": stream.isStreaming ? "" : void 0
|
|
547
|
+
},
|
|
548
|
+
ref
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
);
|
|
552
|
+
function renderMessagePartNodes(parts, children, liveItemKey) {
|
|
553
|
+
return parts.map((part) => /* @__PURE__ */ jsx3(
|
|
554
|
+
InternalMessagePartProvider,
|
|
555
|
+
{
|
|
556
|
+
isLive: liveItemKey === part.id,
|
|
557
|
+
part,
|
|
558
|
+
streamControlled: liveItemKey !== void 0,
|
|
559
|
+
children: typeof children === "function" ? children(part) : children ?? /* @__PURE__ */ jsx3(MessagePart, {})
|
|
560
|
+
},
|
|
561
|
+
part.id
|
|
562
|
+
));
|
|
563
|
+
}
|
|
511
564
|
var MessagePart = forwardRef3(function MessagePart2({ children, ...props }, ref) {
|
|
512
565
|
const { part } = useMessagePart();
|
|
513
566
|
const renderedChildren = typeof children === "function" ? children(part) : children ?? defaultPart(part);
|
|
@@ -523,42 +576,37 @@ var MessagePart = forwardRef3(function MessagePart2({ children, ...props }, ref)
|
|
|
523
576
|
);
|
|
524
577
|
});
|
|
525
578
|
var MessageText = forwardRef3(function MessageText2(props, ref) {
|
|
526
|
-
const { part } = useMessagePart();
|
|
579
|
+
const { part, streamControlled } = useMessagePart();
|
|
527
580
|
if (part.type !== "text") {
|
|
528
581
|
return null;
|
|
529
582
|
}
|
|
530
|
-
return /* @__PURE__ */ jsx3(
|
|
583
|
+
return /* @__PURE__ */ jsx3(
|
|
584
|
+
MessageTextContent,
|
|
585
|
+
{
|
|
586
|
+
...props,
|
|
587
|
+
content: part.text,
|
|
588
|
+
partId: part.id,
|
|
589
|
+
ref,
|
|
590
|
+
streamControlled
|
|
591
|
+
}
|
|
592
|
+
);
|
|
531
593
|
});
|
|
532
594
|
var MessageTextContent = forwardRef3(
|
|
533
|
-
function MessageTextContent2({
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
...props
|
|
541
|
-
}, ref) {
|
|
542
|
-
const animationEnabled = animate && props.children === void 0;
|
|
543
|
-
const smooth = useSmoothStreamText(
|
|
544
|
-
content,
|
|
545
|
-
smoothStreamOptions(
|
|
546
|
-
animationEnabled,
|
|
547
|
-
animationMode,
|
|
548
|
-
isStreaming,
|
|
549
|
-
smoothingPreset,
|
|
550
|
-
reducedMotion
|
|
551
|
-
)
|
|
552
|
-
);
|
|
553
|
-
const animationActive = animationEnabled && animationMode !== "none" && isStreaming !== false && reducedMotion !== true;
|
|
595
|
+
function MessageTextContent2({ content, partId, stream, streamControlled, ...props }, ref) {
|
|
596
|
+
const ownsStream = stream !== void 0 && !streamControlled && props.children === void 0;
|
|
597
|
+
const smooth = useSmoothStreamText(content, {
|
|
598
|
+
isStreaming: ownsStream ? stream.isStreaming : false,
|
|
599
|
+
resetKey: ownsStream ? stream.resetKey : partId,
|
|
600
|
+
...ownsStream && stream.flushImmediately !== void 0 ? { flushImmediately: stream.flushImmediately } : {}
|
|
601
|
+
});
|
|
554
602
|
return renderPrimitive(
|
|
555
603
|
"span",
|
|
556
604
|
{
|
|
557
605
|
...props,
|
|
558
|
-
children: props.children ?? (
|
|
606
|
+
children: props.children ?? (ownsStream ? smooth.text : content),
|
|
559
607
|
"data-anvia-text": "",
|
|
560
|
-
"data-
|
|
561
|
-
"data-streaming":
|
|
608
|
+
"data-draining": ownsStream && smooth.isDraining ? "" : void 0,
|
|
609
|
+
"data-streaming": ownsStream && stream.isStreaming ? "" : void 0
|
|
562
610
|
},
|
|
563
611
|
ref
|
|
564
612
|
);
|
|
@@ -577,52 +625,75 @@ var MessageMarkdown = forwardRef3(function MessageMarkdown2({ children, ...props
|
|
|
577
625
|
const validEntities = children === void 0 || children === expectedMarkdown ? validComposerEntities(layout.text, message.metadata) : [];
|
|
578
626
|
const segment = part?.type === "text" ? layout.segments.find((candidate) => candidate.part.id === part.id) : void 0;
|
|
579
627
|
const entities = segment === void 0 ? validEntities : entitiesForTextSegment(validEntities, segment);
|
|
580
|
-
|
|
628
|
+
const lastPart = message.parts.at(-1);
|
|
629
|
+
const liveEligible = part?.type === "text" ? lastPart?.id === part.id : lastPart?.type === "text";
|
|
630
|
+
return /* @__PURE__ */ jsx3(
|
|
631
|
+
MessageMarkdownContent,
|
|
632
|
+
{
|
|
633
|
+
...props,
|
|
634
|
+
entities,
|
|
635
|
+
liveEligible,
|
|
636
|
+
markdown,
|
|
637
|
+
ref,
|
|
638
|
+
resetKey: message.id,
|
|
639
|
+
streamControlled: partContext?.streamControlled ?? false,
|
|
640
|
+
streamLive: partContext?.isLive ?? false
|
|
641
|
+
}
|
|
642
|
+
);
|
|
581
643
|
});
|
|
582
644
|
var MessageMarkdownContent = forwardRef3(
|
|
583
645
|
function MessageMarkdownContent2({
|
|
584
|
-
animate = false,
|
|
585
|
-
animationMode = "smooth",
|
|
586
|
-
isStreaming,
|
|
587
|
-
smoothingPreset,
|
|
588
|
-
reducedMotion,
|
|
589
646
|
components,
|
|
590
647
|
renderEntity,
|
|
591
648
|
remarkPlugins,
|
|
592
649
|
entities,
|
|
650
|
+
liveEligible,
|
|
593
651
|
markdown,
|
|
652
|
+
resetKey,
|
|
653
|
+
stream,
|
|
654
|
+
streamControlled,
|
|
655
|
+
streamLive,
|
|
594
656
|
...props
|
|
595
657
|
}, ref) {
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const renderedMarkdown = animate ? smooth.text : markdown;
|
|
602
|
-
const renderedEntities = validComposerEntities(renderedMarkdown, {
|
|
603
|
-
composer: { entities }
|
|
658
|
+
const ownsStream = stream !== void 0 && !streamControlled;
|
|
659
|
+
const smooth = useSmoothStreamText(markdown, {
|
|
660
|
+
isStreaming: ownsStream ? stream.isStreaming : false,
|
|
661
|
+
resetKey: ownsStream ? stream.resetKey : resetKey,
|
|
662
|
+
...ownsStream && stream.flushImmediately !== void 0 ? { flushImmediately: stream.flushImmediately } : {}
|
|
604
663
|
});
|
|
605
|
-
|
|
606
|
-
|
|
664
|
+
const renderedMarkdown = ownsStream ? smooth.text : markdown;
|
|
665
|
+
const renderedEntities = useMemo(
|
|
666
|
+
() => entities.length === 0 ? entities : validComposerEntities(renderedMarkdown, {
|
|
667
|
+
composer: { entities }
|
|
668
|
+
}),
|
|
669
|
+
[entities, renderedMarkdown]
|
|
670
|
+
);
|
|
671
|
+
const renderedComponents = useMemo(
|
|
672
|
+
() => markdownComponents(components, renderedEntities, renderEntity),
|
|
673
|
+
[components, renderEntity, renderedEntities]
|
|
674
|
+
);
|
|
675
|
+
const renderedRemarkPlugins = useMemo(
|
|
676
|
+
() => renderedEntities.length === 0 ? remarkPlugins : [
|
|
677
|
+
createMessageEntityRemarkPlugin(renderedMarkdown, renderedEntities),
|
|
678
|
+
...remarkPlugins ?? [remarkGfm]
|
|
679
|
+
],
|
|
680
|
+
[remarkPlugins, renderedEntities, renderedMarkdown]
|
|
681
|
+
);
|
|
682
|
+
const live = streamControlled ? streamLive : ownsStream && liveEligible && (stream.isStreaming || smooth.isDraining);
|
|
683
|
+
return /* @__PURE__ */ jsx3(
|
|
684
|
+
StreamMarkdown,
|
|
607
685
|
{
|
|
608
686
|
...props,
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
{
|
|
612
|
-
components: markdownComponents(components, renderedEntities, renderEntity),
|
|
613
|
-
remarkPlugins: [
|
|
614
|
-
createMessageEntityRemarkPlugin(renderedMarkdown, renderedEntities),
|
|
615
|
-
...remarkPlugins ?? [remarkGfm]
|
|
616
|
-
],
|
|
617
|
-
remarkRehypeOptions: messageEntityRehypeOptions(),
|
|
618
|
-
children: renderedMarkdown
|
|
619
|
-
}
|
|
620
|
-
),
|
|
687
|
+
components: renderedComponents,
|
|
688
|
+
content: renderedMarkdown,
|
|
621
689
|
"data-anvia-markdown": "",
|
|
622
|
-
"data-
|
|
623
|
-
"data-streaming":
|
|
624
|
-
|
|
625
|
-
|
|
690
|
+
"data-draining": ownsStream && smooth.isDraining ? "" : void 0,
|
|
691
|
+
"data-streaming": ownsStream && stream.isStreaming ? "" : void 0,
|
|
692
|
+
live,
|
|
693
|
+
ref,
|
|
694
|
+
remarkPlugins: renderedRemarkPlugins,
|
|
695
|
+
remarkRehypeOptions: renderedEntities.length === 0 ? void 0 : messageEntityRehypeOptions()
|
|
696
|
+
}
|
|
626
697
|
);
|
|
627
698
|
}
|
|
628
699
|
);
|
|
@@ -663,13 +734,6 @@ function markdownComponents(components, entities, renderEntity) {
|
|
|
663
734
|
}
|
|
664
735
|
};
|
|
665
736
|
}
|
|
666
|
-
function smoothStreamOptions(enabled, mode, isStreaming, preset, reducedMotion) {
|
|
667
|
-
const options = { enabled, mode };
|
|
668
|
-
if (isStreaming !== void 0) options.isStreaming = isStreaming;
|
|
669
|
-
if (preset !== void 0) options.preset = preset;
|
|
670
|
-
if (reducedMotion !== void 0) options.reducedMotion = reducedMotion;
|
|
671
|
-
return options;
|
|
672
|
-
}
|
|
673
737
|
var MessageCodeBlock = forwardRef3(
|
|
674
738
|
function MessageCodeBlock2({ children, code, language, ...props }, ref) {
|
|
675
739
|
return renderPrimitive(
|
|
@@ -993,4 +1057,4 @@ export {
|
|
|
993
1057
|
shiftComposerEntityRanges,
|
|
994
1058
|
Message
|
|
995
1059
|
};
|
|
996
|
-
//# sourceMappingURL=chunk-
|
|
1060
|
+
//# sourceMappingURL=chunk-7I6XUWM7.js.map
|