@anvia/react-ui 1.0.0-rc.1 → 1.0.0-rc.10

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 (72) hide show
  1. package/README.md +52 -39
  2. package/dist/attachment/index.d.ts +5 -5
  3. package/dist/attachment/index.js +4 -4
  4. package/dist/{attachment-BP597fV3.d.ts → attachment-mbjsroli.d.ts} +1 -1
  5. package/dist/chat/index.d.ts +13 -12
  6. package/dist/chat/index.js +11 -9
  7. package/dist/chat-tfA570mg.d.ts +86 -0
  8. package/dist/{chunk-7RMRM7W3.js → chunk-647LAYRV.js} +90 -65
  9. package/dist/chunk-647LAYRV.js.map +1 -0
  10. package/dist/chunk-6XOJFLX4.js +22 -0
  11. package/dist/chunk-6XOJFLX4.js.map +1 -0
  12. package/dist/chunk-CKA4CE26.js +25 -0
  13. package/dist/chunk-CKA4CE26.js.map +1 -0
  14. package/dist/{chunk-JWZDNM5D.js → chunk-CRXNFZRW.js} +145 -125
  15. package/dist/chunk-CRXNFZRW.js.map +1 -0
  16. package/dist/{chunk-7HR34SOF.js → chunk-CVXLQCDI.js} +13 -21
  17. package/dist/chunk-CVXLQCDI.js.map +1 -0
  18. package/dist/{chunk-ULGJLLZE.js → chunk-F6AKBUO3.js} +12 -12
  19. package/dist/chunk-F6AKBUO3.js.map +1 -0
  20. package/dist/{chunk-FABSIZZ7.js → chunk-HWJIMLHC.js} +97 -90
  21. package/dist/chunk-HWJIMLHC.js.map +1 -0
  22. package/dist/{chunk-SBYUKODG.js → chunk-MISX4WUT.js} +10 -15
  23. package/dist/chunk-MISX4WUT.js.map +1 -0
  24. package/dist/{chunk-R3NA6BWW.js → chunk-OQE6SHZE.js} +54 -56
  25. package/dist/chunk-OQE6SHZE.js.map +1 -0
  26. package/dist/{chunk-VEYJNQVW.js → chunk-S4XLE2RN.js} +11 -16
  27. package/dist/chunk-S4XLE2RN.js.map +1 -0
  28. package/dist/{chunk-43U2XQP2.js → chunk-SOG2GVE4.js} +69 -25
  29. package/dist/chunk-SOG2GVE4.js.map +1 -0
  30. package/dist/{chunk-56CV6S76.js → chunk-UCBAG42A.js} +9 -21
  31. package/dist/chunk-UCBAG42A.js.map +1 -0
  32. package/dist/completion/index.d.ts +4 -3
  33. package/dist/completion/index.js +4 -4
  34. package/dist/completion-input-DHlwrhxB.d.ts +24 -0
  35. package/dist/{composer-CzsbDFPt.d.ts → composer-CigccTLT.d.ts} +19 -7
  36. package/dist/human-input/index.d.ts +10 -8
  37. package/dist/human-input/index.js +5 -4
  38. package/dist/human-input-D7jgYsfM.d.ts +27 -0
  39. package/dist/image/index.d.ts +6 -6
  40. package/dist/image/index.js +4 -4
  41. package/dist/{image-DanUxcl2.d.ts → image-VZv6Ddsn.d.ts} +1 -1
  42. package/dist/index.d.ts +19 -18
  43. package/dist/index.js +60 -64
  44. package/dist/index.js.map +1 -1
  45. package/dist/message/index.d.ts +12 -11
  46. package/dist/message/index.js +8 -6
  47. package/dist/{message-CkEnKhAn.d.ts → message-CNRnZQwU.d.ts} +1 -1
  48. package/dist/selection-toolbar/index.d.ts +2 -2
  49. package/dist/selection-toolbar/index.js +5 -4
  50. package/dist/shared.d.ts +9 -8
  51. package/dist/shared.js +1 -1
  52. package/dist/stream/index.d.ts +2 -0
  53. package/dist/stream/index.js +1 -1
  54. package/dist/{thread-uEm8hH0s.d.ts → thread-Bz6-1zaJ.d.ts} +1 -0
  55. package/dist/thread-list/index.d.ts +3 -3
  56. package/dist/thread-list/index.js +6 -6
  57. package/package.json +17 -17
  58. package/dist/chat-B3kucz1w.d.ts +0 -13
  59. package/dist/chunk-43U2XQP2.js.map +0 -1
  60. package/dist/chunk-56CV6S76.js.map +0 -1
  61. package/dist/chunk-7HR34SOF.js.map +0 -1
  62. package/dist/chunk-7RMRM7W3.js.map +0 -1
  63. package/dist/chunk-FABSIZZ7.js.map +0 -1
  64. package/dist/chunk-JWZDNM5D.js.map +0 -1
  65. package/dist/chunk-R3NA6BWW.js.map +0 -1
  66. package/dist/chunk-SBYUKODG.js.map +0 -1
  67. package/dist/chunk-ULGJLLZE.js.map +0 -1
  68. package/dist/chunk-VEYJNQVW.js.map +0 -1
  69. package/dist/completion-input-WjK6kUyG.d.ts +0 -23
  70. package/dist/human-input-CydeYm_7.d.ts +0 -20
  71. package/dist/stream/styles.css +0 -17
  72. package/dist/styles.css +0 -130
@@ -10,7 +10,7 @@ function InternalAttachmentProvider({
10
10
  function useAttachment() {
11
11
  const value = useContext(AttachmentContext);
12
12
  if (value === void 0) {
13
- throw new Error("Attachment primitives must be used inside Attachment.Root.");
13
+ throw new Error("Attachment primitives must be used inside AttachmentPrimitive.Root.");
14
14
  }
15
15
  return value;
16
16
  }
@@ -21,11 +21,12 @@ function useOptionalAttachment() {
21
21
  // src/contexts/chat.tsx
22
22
  import { createContext as createContext2, createElement as createElement2, useContext as useContext2 } from "react";
23
23
  var ChatContext = createContext2(void 0);
24
- function ChatProvider({
25
- controller,
26
- children
27
- }) {
28
- return createElement2(ChatContext.Provider, { value: controller }, children);
24
+ function ChatProvider({ controller, children }) {
25
+ return createElement2(
26
+ ChatContext.Provider,
27
+ { value: controller },
28
+ children
29
+ );
29
30
  }
30
31
  function useChatContext() {
31
32
  const value = useContext2(ChatContext);
@@ -35,16 +36,29 @@ function useChatContext() {
35
36
  return value;
36
37
  }
37
38
  function useHumanInput() {
38
- return useChatContext().humanInput;
39
+ const interactions = useChatContext().interactions;
40
+ const approvals = interactions.all.filter(
41
+ (item) => item.request.type === "tool-approval"
42
+ );
43
+ const questions = interactions.all.filter(
44
+ (item) => item.request.type === "tool-question"
45
+ );
46
+ return {
47
+ approvals: {
48
+ all: approvals,
49
+ pending: approvals.filter((item) => item.status === "pending")
50
+ },
51
+ questions: {
52
+ all: questions,
53
+ pending: questions.filter((item) => item.status === "pending")
54
+ }
55
+ };
39
56
  }
40
57
 
41
58
  // src/contexts/completion.tsx
42
59
  import { createContext as createContext3, createElement as createElement3, useContext as useContext3 } from "react";
43
60
  var CompletionContext = createContext3(void 0);
44
- function CompletionProvider({
45
- controller,
46
- children
47
- }) {
61
+ function CompletionProvider({ controller, children }) {
48
62
  return createElement3(
49
63
  CompletionContext.Provider,
50
64
  { value: controller },
@@ -71,7 +85,7 @@ function InternalCompletionInputProvider({
71
85
  function useCompletionInput() {
72
86
  const value = useContext4(CompletionInputContext);
73
87
  if (value === void 0) {
74
- throw new Error("Completion input primitives must be used inside Completion.Form.");
88
+ throw new Error("Completion input primitives must be used inside CompletionPrimitive.Form.");
75
89
  }
76
90
  return value;
77
91
  }
@@ -88,7 +102,7 @@ function InternalComposerProvider({
88
102
  function useComposer() {
89
103
  const value = useContext5(ComposerContext);
90
104
  if (value === void 0) {
91
- throw new Error("Composer primitives must be used inside Composer.Root.");
105
+ throw new Error("Composer primitives must be used inside ComposerPrimitive.Root.");
92
106
  }
93
107
  return value;
94
108
  }
@@ -130,21 +144,23 @@ function InternalQuestionPromptProvider({
130
144
  function useApproval() {
131
145
  const value = useContext6(ApprovalContext);
132
146
  if (value === void 0) {
133
- throw new Error("Approval primitives must be used inside HumanInput.Approval.");
147
+ throw new Error("Approval primitives must be used inside HumanInputPrimitive.Approval.");
134
148
  }
135
149
  return value;
136
150
  }
137
151
  function useQuestion() {
138
152
  const value = useContext6(QuestionContext);
139
153
  if (value === void 0) {
140
- throw new Error("Question primitives must be used inside HumanInput.Question.");
154
+ throw new Error("Question primitives must be used inside HumanInputPrimitive.Question.");
141
155
  }
142
156
  return value;
143
157
  }
144
158
  function useQuestionPrompt() {
145
159
  const value = useContext6(QuestionPromptContext);
146
160
  if (value === void 0) {
147
- throw new Error("Question choice primitives must be used inside HumanInput.QuestionPrompt.");
161
+ throw new Error(
162
+ "Question choice primitives must be used inside HumanInputPrimitive.QuestionPrompt."
163
+ );
148
164
  }
149
165
  return value;
150
166
  }
@@ -161,7 +177,7 @@ function InternalImageProvider({
161
177
  function useImage() {
162
178
  const value = useContext7(ImageContext);
163
179
  if (value === void 0) {
164
- throw new Error("Image primitives must be used inside Image.Root.");
180
+ throw new Error("Image primitives must be used inside ImagePrimitive.Root.");
165
181
  }
166
182
  return value;
167
183
  }
@@ -191,14 +207,18 @@ function InternalMessagePartProvider({
191
207
  function useMessage() {
192
208
  const value = useContext8(MessageContext);
193
209
  if (value === void 0) {
194
- throw new Error("Message primitives must be used inside Message.Root or Thread.Messages.");
210
+ throw new Error(
211
+ "Message primitives must be used inside MessagePrimitive.Root or ThreadPrimitive.Messages."
212
+ );
195
213
  }
196
214
  return value;
197
215
  }
198
216
  function useMessagePart() {
199
217
  const value = useContext8(MessagePartContext);
200
218
  if (value === void 0) {
201
- throw new Error("Message part primitives must be used inside Message.Parts or Message.Part.");
219
+ throw new Error(
220
+ "Message part primitives must be used inside MessagePrimitive.Parts or MessagePrimitive.Part."
221
+ );
202
222
  }
203
223
  return value;
204
224
  }
@@ -218,7 +238,9 @@ function InternalSelectionToolbarProvider({
218
238
  function useSelectionToolbar() {
219
239
  const value = useContext9(SelectionToolbarContext);
220
240
  if (value === void 0) {
221
- throw new Error("SelectionToolbar primitives must be used inside SelectionToolbar.Root.");
241
+ throw new Error(
242
+ "SelectionToolbar primitives must be used inside SelectionToolbarPrimitive.Root."
243
+ );
222
244
  }
223
245
  return value;
224
246
  }
@@ -239,15 +261,22 @@ function InternalThreadProvider({
239
261
  function useThread() {
240
262
  const value = useContext10(ThreadContext);
241
263
  if (value === void 0) {
242
- throw new Error("Thread primitives must be used inside Thread.Root.");
264
+ throw new Error("Thread primitives must be used inside ThreadPrimitive.Root.");
243
265
  }
244
266
  return value;
245
267
  }
246
268
 
247
269
  // src/contexts/thread-list.tsx
248
- import { createContext as createContext11, createElement as createElement11, useContext as useContext11 } from "react";
270
+ import {
271
+ createContext as createContext11,
272
+ createElement as createElement11,
273
+ useContext as useContext11
274
+ } from "react";
249
275
  var ThreadListContext = createContext11(void 0);
250
276
  var ThreadListItemContext = createContext11(void 0);
277
+ var ThreadListRootContext = createContext11(
278
+ void 0
279
+ );
251
280
  function ThreadListProvider({
252
281
  controller,
253
282
  children
@@ -260,6 +289,12 @@ function InternalThreadListItemProvider({
260
289
  }) {
261
290
  return createElement11(ThreadListItemContext.Provider, { value }, children);
262
291
  }
292
+ function InternalThreadListRootProvider({
293
+ value,
294
+ children
295
+ }) {
296
+ return createElement11(ThreadListRootContext.Provider, { value }, children);
297
+ }
263
298
  function useThreadList() {
264
299
  const value = useContext11(ThreadListContext);
265
300
  if (value === void 0) {
@@ -270,7 +305,14 @@ function useThreadList() {
270
305
  function useThreadListItem() {
271
306
  const value = useContext11(ThreadListItemContext);
272
307
  if (value === void 0) {
273
- throw new Error("ThreadListItem primitives must be used inside ThreadList.Items.");
308
+ throw new Error("ThreadListItem primitives must be used inside ThreadListPrimitive.Items.");
309
+ }
310
+ return value;
311
+ }
312
+ function useInternalThreadListRoot() {
313
+ const value = useContext11(ThreadListRootContext);
314
+ if (value === void 0) {
315
+ throw new Error("Thread-list primitives must be used inside ThreadListPrimitive.Root.");
274
316
  }
275
317
  return value;
276
318
  }
@@ -307,7 +349,9 @@ export {
307
349
  useThread,
308
350
  ThreadListProvider,
309
351
  InternalThreadListItemProvider,
352
+ InternalThreadListRootProvider,
310
353
  useThreadList,
311
- useThreadListItem
354
+ useThreadListItem,
355
+ useInternalThreadListRoot
312
356
  };
313
- //# sourceMappingURL=chunk-43U2XQP2.js.map
357
+ //# sourceMappingURL=chunk-SOG2GVE4.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/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/client\";\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 AttachmentPrimitive.Root.\");\n }\n return value;\n}\n\nexport function useOptionalAttachment(): AttachmentContextValue | undefined {\n return useContext(AttachmentContext);\n}\n","import type {\n ClientDataMap,\n ClientMetadata,\n ClientStreamRequest,\n ClientTransport,\n} from \"@anvia/client\";\nimport type {\n AgentToolApprovalRequest,\n AgentToolQuestionRequest,\n} from \"@anvia/core/agent/interactions\";\nimport type { UseChatResult } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type ChatController<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = UseChatResult<ClientTransport<ClientStreamRequest, Data, Metadata>>;\n\nexport type ChatProviderProps<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = {\n controller: ChatController<Metadata, Data>;\n children?: ReactNode;\n};\n\nconst ChatContext = createContext<ChatController | undefined>(undefined);\n\nexport function ChatProvider<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>({ controller, children }: ChatProviderProps<Metadata, Data>): ReactElement {\n return createElement(\n ChatContext.Provider,\n { value: controller as unknown as ChatController },\n children,\n );\n}\n\nexport function useChatContext<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>(): ChatController<Metadata, Data> {\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 unknown as ChatController<Metadata, Data>;\n}\n\nexport function useHumanInput() {\n const interactions = useChatContext().interactions;\n const approvals = interactions.all.filter(\n (item): item is typeof item & { request: AgentToolApprovalRequest } =>\n item.request.type === \"tool-approval\",\n );\n const questions = interactions.all.filter(\n (item): item is typeof item & { request: AgentToolQuestionRequest } =>\n item.request.type === \"tool-question\",\n );\n return {\n approvals: {\n all: approvals,\n pending: approvals.filter((item) => item.status === \"pending\"),\n },\n questions: {\n all: questions,\n pending: questions.filter((item) => item.status === \"pending\"),\n },\n };\n}\n","import type { ClientDataMap, ClientMetadata } from \"@anvia/client\";\nimport type { UseCompletionResult } from \"@anvia/react\";\nimport { createContext, createElement, type ReactElement, type ReactNode, useContext } from \"react\";\n\nexport type CompletionController<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = UseCompletionResult<Metadata, Data>;\n\nexport type CompletionProviderProps<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n> = {\n controller: CompletionController<Metadata, Data>;\n children?: ReactNode;\n};\n\nconst CompletionContext = createContext<CompletionController | undefined>(undefined);\n\nexport function CompletionProvider<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>({ controller, children }: CompletionProviderProps<Metadata, Data>): ReactElement {\n return createElement(\n CompletionContext.Provider,\n { value: controller as unknown as CompletionController },\n children,\n );\n}\n\nexport function useCompletionContext<\n Metadata extends ClientMetadata = ClientMetadata,\n Data extends ClientDataMap = ClientDataMap,\n>(): CompletionController<Metadata, Data> {\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 unknown as CompletionController<Metadata, Data>;\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 CompletionPrimitive.Form.\");\n }\n return value;\n}\n","import type { ClientMetadata, CreateUIAttachment, UIAttachment } from \"@anvia/client\";\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 | readonly ComposerEntityData[]\n | { [key: string]: ComposerEntityData };\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};\ntype ComposerMessageEntity = ClientMetadata & {\n id: string;\n triggerId: string;\n trigger: string;\n label: string;\n text: string;\n range: ClientMetadata & {\n from: number;\n to: number;\n };\n data?: ComposerEntityData | undefined;\n};\nexport type ComposerMessageMetadata = ClientMetadata & {\n composer: ClientMetadata & {\n entities: readonly ComposerMessageEntity[];\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 ComposerPrimitive.Root.\");\n }\n return value;\n}\n","import type { ClientInteraction } from \"@anvia/client\";\nimport type {\n AgentQuestionAnswer,\n AgentQuestionPrompt,\n AgentToolApprovalRequest,\n AgentToolQuestionRequest,\n} from \"@anvia/core/agent/interactions\";\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: ApprovalInteraction;\n reason: string;\n setReason(reason: string): void;\n};\n\nexport type QuestionContextValue = {\n question: QuestionInteraction;\n answers: Record<string, AgentQuestionAnswer>;\n setAnswer(prompt: AgentQuestionPrompt, answer: AgentQuestionAnswer): void;\n};\n\nexport type QuestionPromptContextValue = {\n prompt: AgentQuestionPrompt;\n};\n\nexport type ApprovalInteraction = ClientInteraction & { request: AgentToolApprovalRequest };\nexport type QuestionInteraction = ClientInteraction & { request: AgentToolQuestionRequest };\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: ApprovalInteraction;\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: AgentQuestionPrompt;\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 HumanInputPrimitive.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 HumanInputPrimitive.Question.\");\n }\n return value;\n}\n\nexport function useQuestionPrompt(): QuestionPromptContextValue {\n const value = useContext(QuestionPromptContext);\n if (value === undefined) {\n throw new Error(\n \"Question choice primitives must be used inside HumanInputPrimitive.QuestionPrompt.\",\n );\n }\n return value;\n}\n","import type { UIAttachment } from \"@anvia/client\";\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 ImagePrimitive.Root.\");\n }\n return value;\n}\n","import type { UIMessage, UIMessagePart } from \"@anvia/client\";\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(\n \"Message primitives must be used inside MessagePrimitive.Root or ThreadPrimitive.Messages.\",\n );\n }\n return value;\n}\n\nexport function useMessagePart(): MessagePartContextValue {\n const value = useContext(MessagePartContext);\n if (value === undefined) {\n throw new Error(\n \"Message part primitives must be used inside MessagePrimitive.Parts or MessagePrimitive.Part.\",\n );\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(\n \"SelectionToolbar primitives must be used inside SelectionToolbarPrimitive.Root.\",\n );\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 messagesRef: 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 ThreadPrimitive.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 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\nexport type InternalThreadListRootContextValue = {\n rootRef: MutableRefObject<HTMLDivElement | null>;\n newButtonRef: MutableRefObject<HTMLButtonElement | null>;\n itemElements: MutableRefObject<Map<string, HTMLDivElement>>;\n triggerElements: MutableRefObject<Map<string, HTMLButtonElement>>;\n registerItem(threadId: string, element: HTMLDivElement | null): void;\n registerTrigger(threadId: string, element: HTMLButtonElement | null): void;\n};\n\nconst ThreadListContext = createContext<ThreadListController | undefined>(undefined);\nconst ThreadListItemContext = createContext<ThreadListItemContextValue | undefined>(undefined);\nconst ThreadListRootContext = createContext<InternalThreadListRootContextValue | undefined>(\n undefined,\n);\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 InternalThreadListRootProvider({\n value,\n children,\n}: {\n value: InternalThreadListRootContextValue;\n children?: ReactNode;\n}): ReactElement {\n return createElement(ThreadListRootContext.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 ThreadListPrimitive.Items.\");\n }\n return value;\n}\n\nexport function useInternalThreadListRoot(): InternalThreadListRootContextValue {\n const value = useContext(ThreadListRootContext);\n if (value === undefined) {\n throw new Error(\"Thread-list primitives must be used inside ThreadListPrimitive.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,qEAAqE;AAAA,EACvF;AACA,SAAO;AACT;AAEO,SAAS,wBAA4D;AAC1E,SAAO,WAAW,iBAAiB;AACrC;;;ACnBA,SAAS,iBAAAA,gBAAe,iBAAAC,gBAAkD,cAAAC,mBAAkB;AAe5F,IAAM,cAAcF,eAA0C,MAAS;AAEhE,SAAS,aAGd,EAAE,YAAY,SAAS,GAAoD;AAC3E,SAAOC;AAAA,IACL,YAAY;AAAA,IACZ,EAAE,OAAO,WAAwC;AAAA,IACjD;AAAA,EACF;AACF;AAEO,SAAS,iBAGoB;AAClC,QAAM,QAAQC,YAAW,WAAW;AACpC,MAAI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,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,+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,0EAA0E;AAAA,EAC5F;AACA,SAAO;AACT;AAEO,SAAS,4BAAgE;AAC9E,QAAM,QAAQA,aAAW,qBAAqB;AAC9C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,sEAAsE;AAAA,EACxF;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,10 +1,13 @@
1
+ import {
2
+ messageElementFromNode
3
+ } from "./chunk-6XOJFLX4.js";
1
4
  import {
2
5
  renderPrimitive
3
6
  } from "./chunk-T3ZFZ3NP.js";
4
7
  import {
5
8
  InternalSelectionToolbarProvider,
6
9
  useSelectionToolbar
7
- } from "./chunk-43U2XQP2.js";
10
+ } from "./chunk-SOG2GVE4.js";
8
11
 
9
12
  // src/selection-toolbar/parts.tsx
10
13
  import {
@@ -93,8 +96,6 @@ var SelectionToolbarRoot = forwardRef(
93
96
  /* @__PURE__ */ jsx(SelectionToolbarCopy, {})
94
97
  ] }),
95
98
  style: toolbarStyle,
96
- "data-anvia-selection-toolbar": "",
97
- "data-message-id": selection.messageId,
98
99
  role: props.role ?? "toolbar"
99
100
  },
100
101
  ref
@@ -113,7 +114,6 @@ var SelectionToolbarQuote = forwardRef(
113
114
  disabled,
114
115
  onClick: handleClick,
115
116
  type: props.type ?? "button",
116
- "data-anvia-selection-quote": "",
117
117
  "data-state": disabled ? "disabled" : "enabled"
118
118
  },
119
119
  ref
@@ -131,7 +131,6 @@ var SelectionToolbarCopy = forwardRef(
131
131
  disabled,
132
132
  onClick: handleClick,
133
133
  type: props.type ?? "button",
134
- "data-anvia-selection-copy": "",
135
134
  "data-state": disabled ? "disabled" : "enabled"
136
135
  },
137
136
  ref
@@ -165,27 +164,16 @@ function selectionFromDocument(document) {
165
164
  }
166
165
  const anchorMessage = messageElementFromNode(selection.anchorNode);
167
166
  const focusMessage = messageElementFromNode(selection.focusNode);
168
- if (anchorMessage === void 0 || focusMessage === void 0 || anchorMessage !== focusMessage) {
169
- return void 0;
170
- }
171
- const messageId = anchorMessage.getAttribute("data-anvia-message-id");
172
- if (messageId === null || messageId.length === 0) {
167
+ if (anchorMessage === void 0 || focusMessage === void 0 || anchorMessage.element !== focusMessage.element) {
173
168
  return void 0;
174
169
  }
175
170
  const range = selection.getRangeAt(0);
176
171
  return {
177
172
  text,
178
- messageId,
173
+ messageId: anchorMessage.messageId,
179
174
  rect: selectionRect(range)
180
175
  };
181
176
  }
182
- function messageElementFromNode(node) {
183
- if (node === null) {
184
- return void 0;
185
- }
186
- const element = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
187
- return element?.closest("[data-anvia-message-id]") ?? void 0;
188
- }
189
177
  function selectionRect(range) {
190
178
  const rangeWithRect = range;
191
179
  const rect = rangeWithRect.getBoundingClientRect?.();
@@ -220,13 +208,13 @@ function sameSelection(currentSelection, nextSelection) {
220
208
  }
221
209
 
222
210
  // src/selection-toolbar/index.ts
223
- var SelectionToolbar = {
211
+ var SelectionToolbarPrimitive = {
224
212
  Root: SelectionToolbarRoot,
225
213
  Quote: SelectionToolbarQuote,
226
214
  Copy: SelectionToolbarCopy
227
215
  };
228
216
 
229
217
  export {
230
- SelectionToolbar
218
+ SelectionToolbarPrimitive
231
219
  };
232
- //# sourceMappingURL=chunk-56CV6S76.js.map
220
+ //# sourceMappingURL=chunk-UCBAG42A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/selection-toolbar/parts.tsx","../src/selection-toolbar/index.ts"],"sourcesContent":["import {\n type CSSProperties,\n forwardRef,\n type MouseEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport {\n InternalSelectionToolbarProvider,\n type SelectionToolbarContextValue,\n type SelectionToolbarSelection,\n useSelectionToolbar,\n} from \"../contexts\";\nimport { messageElementFromNode } from \"../message/elements\";\nimport { type PrimitiveProps, renderPrimitive } from \"../primitives\";\n\ntype SelectionToolbarRootProps = Omit<PrimitiveProps<\"div\">, \"children\"> & {\n children?: ReactNode;\n container?: Element | DocumentFragment;\n onQuote?: (selection: SelectionToolbarSelection) => void;\n onSelectionChange?: (selection: SelectionToolbarSelection | undefined) => void;\n};\n\nconst SelectionToolbarRoot = forwardRef<HTMLDivElement, SelectionToolbarRootProps>(\n function SelectionToolbarRoot(\n { children, container, onQuote, onSelectionChange, style, ...props },\n ref,\n ) {\n const [selection, setSelectionState] = useState<SelectionToolbarSelection | undefined>();\n const portalContainer = container ?? globalThis.document?.body;\n\n const setSelection = useCallback(\n (nextSelection: SelectionToolbarSelection | undefined) => {\n setSelectionState((currentSelection) => {\n if (sameSelection(currentSelection, nextSelection)) {\n return currentSelection;\n }\n onSelectionChange?.(nextSelection);\n return nextSelection;\n });\n },\n [onSelectionChange],\n );\n\n const clear = useCallback(() => {\n globalThis.document?.getSelection()?.removeAllRanges();\n setSelection(undefined);\n }, [setSelection]);\n\n const copy = useCallback(async () => {\n if (selection === undefined) {\n return;\n }\n await globalThis.navigator?.clipboard?.writeText(selection.text);\n clear();\n }, [clear, selection]);\n\n const quote = useCallback(() => {\n if (selection === undefined) {\n return;\n }\n onQuote?.(selection);\n clear();\n }, [clear, onQuote, selection]);\n\n const value = useMemo<SelectionToolbarContextValue>(() => {\n const context: SelectionToolbarContextValue = { quote, copy, clear };\n if (selection !== undefined) context.selection = selection;\n return context;\n }, [clear, copy, quote, selection]);\n\n useEffect(() => {\n const document = globalThis.document;\n if (document === undefined) {\n return;\n }\n\n const handleSelectionChange = () => {\n setSelection(selectionFromDocument(document));\n };\n\n document.addEventListener(\"selectionchange\", handleSelectionChange);\n document.addEventListener(\"mouseup\", handleSelectionChange);\n document.addEventListener(\"keyup\", handleSelectionChange);\n document.addEventListener(\"scroll\", handleSelectionChange, true);\n return () => {\n document.removeEventListener(\"selectionchange\", handleSelectionChange);\n document.removeEventListener(\"mouseup\", handleSelectionChange);\n document.removeEventListener(\"keyup\", handleSelectionChange);\n document.removeEventListener(\"scroll\", handleSelectionChange, true);\n };\n }, [setSelection]);\n\n if (selection === undefined || portalContainer === undefined) {\n return null;\n }\n\n const toolbarStyle: CSSProperties = {\n position: \"fixed\",\n top: selection.rect.top,\n left: selection.rect.left + selection.rect.width / 2,\n transform: \"translate(-50%, calc(-100% - 8px))\",\n ...style,\n };\n\n const toolbar = (\n <InternalSelectionToolbarProvider value={value}>\n {renderPrimitive(\n \"div\",\n {\n ...props,\n children: children ?? (\n <>\n <SelectionToolbarQuote />\n <SelectionToolbarCopy />\n </>\n ),\n style: toolbarStyle,\n role: props.role ?? \"toolbar\",\n } as PrimitiveProps<\"div\">,\n ref,\n )}\n </InternalSelectionToolbarProvider>\n );\n\n return createPortal(toolbar, portalContainer);\n },\n);\n\nconst SelectionToolbarQuote = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function SelectionToolbarQuote({ onClick, ...props }, ref) {\n const { disabled, handleClick } = useSelectionToolbarAction(\"quote\", props.disabled, onClick);\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Quote\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\nconst SelectionToolbarCopy = forwardRef<HTMLButtonElement, PrimitiveProps<\"button\">>(\n function SelectionToolbarCopy({ onClick, ...props }, ref) {\n const { disabled, handleClick } = useSelectionToolbarAction(\"copy\", props.disabled, onClick);\n\n return renderPrimitive(\n \"button\",\n {\n ...props,\n children: props.children ?? \"Copy\",\n disabled,\n onClick: handleClick,\n type: props.type ?? \"button\",\n \"data-state\": disabled ? \"disabled\" : \"enabled\",\n } as PrimitiveProps<\"button\">,\n ref,\n );\n },\n);\n\ntype SelectionToolbarAction = \"copy\" | \"quote\";\n\nfunction useSelectionToolbarAction(\n actionName: SelectionToolbarAction,\n disabledProp: boolean | undefined,\n onClick: ((event: MouseEvent<HTMLButtonElement>) => void) | undefined,\n): {\n disabled: boolean;\n handleClick(event: MouseEvent<HTMLButtonElement>): void;\n} {\n const toolbar = useSelectionToolbar();\n const disabled = disabledProp ?? toolbar.selection === undefined;\n const action = toolbar[actionName];\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n onClick?.(event);\n if (event.defaultPrevented || disabled) {\n return;\n }\n void action();\n },\n [action, disabled, onClick],\n );\n return { disabled, handleClick };\n}\n\nfunction selectionFromDocument(document: Document): SelectionToolbarSelection | undefined {\n const selection = document.getSelection();\n if (selection === null || selection.rangeCount === 0) {\n return undefined;\n }\n const text = selection.toString();\n if (text.trim().length === 0) {\n return undefined;\n }\n\n const anchorMessage = messageElementFromNode(selection.anchorNode);\n const focusMessage = messageElementFromNode(selection.focusNode);\n if (\n anchorMessage === undefined ||\n focusMessage === undefined ||\n anchorMessage.element !== focusMessage.element\n ) {\n return undefined;\n }\n\n const range = selection.getRangeAt(0);\n return {\n text,\n messageId: anchorMessage.messageId,\n rect: selectionRect(range),\n };\n}\n\nfunction selectionRect(range: Range): DOMRect {\n const rangeWithRect = range as Range & {\n getBoundingClientRect?: () => DOMRect;\n };\n const rect = rangeWithRect.getBoundingClientRect?.();\n if (rect !== undefined && (rect.width > 0 || rect.height > 0)) {\n return rect;\n }\n const firstRect = range.getClientRects().item(0);\n if (firstRect !== null) {\n return firstRect;\n }\n const DOMRectConstructor = globalThis.DOMRect;\n if (DOMRectConstructor !== undefined) {\n return new DOMRectConstructor(0, 0, 0, 0);\n }\n return {\n bottom: 0,\n height: 0,\n left: 0,\n right: 0,\n top: 0,\n width: 0,\n x: 0,\n y: 0,\n toJSON: () => ({}),\n } as DOMRect;\n}\n\nfunction sameSelection(\n currentSelection: SelectionToolbarSelection | undefined,\n nextSelection: SelectionToolbarSelection | undefined,\n): boolean {\n if (currentSelection === undefined || nextSelection === undefined) {\n return currentSelection === nextSelection;\n }\n return (\n currentSelection.text === nextSelection.text &&\n currentSelection.messageId === nextSelection.messageId &&\n currentSelection.rect.left === nextSelection.rect.left &&\n currentSelection.rect.top === nextSelection.rect.top &&\n currentSelection.rect.width === nextSelection.rect.width &&\n currentSelection.rect.height === nextSelection.rect.height\n );\n}\n\nexport { SelectionToolbarCopy, SelectionToolbarQuote, SelectionToolbarRoot };\n","import { SelectionToolbarCopy, SelectionToolbarQuote, SelectionToolbarRoot } from \"./parts\";\n\nexport const SelectionToolbarPrimitive = {\n Root: SelectionToolbarRoot,\n Quote: SelectionToolbarQuote,\n Copy: SelectionToolbarCopy,\n} as const;\n\nexport type { SelectionToolbarContextValue, SelectionToolbarSelection } from \"../contexts\";\nexport { useSelectionToolbar } from \"../contexts\";\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA,EAEE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AA2Gf,mBACE,KADF;AAzFd,IAAM,uBAAuB;AAAA,EA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AC3B;AACF;AAEA,SAAS,cAAc,OAAuB;AAC5C,QAAM,gBAAgB;AAGtB,QAAM,OAAO,cAAc,wBAAwB;AACnD,MAAI,SAAS,WAAc,KAAK,QAAQ,KAAK,KAAK,SAAS,IAAI;AAC7D,WAAO;AAAA,EACT;AACA,QAAM,YAAY,MAAM,eAAe,EAAE,KAAK,CAAC;AAC/C,MAAI,cAAc,MAAM;AACtB,WAAO;AAAA,EACT;AACA,QAAM,qBAAqB,WAAW;AACtC,MAAI,uBAAuB,QAAW;AACpC,WAAO,IAAI,mBAAmB,GAAG,GAAG,GAAG,CAAC;AAAA,EAC1C;AACA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL,OAAO;AAAA,IACP,GAAG;AAAA,IACH,GAAG;AAAA,IACH,QAAQ,OAAO,CAAC;AAAA,EAClB;AACF;AAEA,SAAS,cACP,kBACA,eACS;AACT,MAAI,qBAAqB,UAAa,kBAAkB,QAAW;AACjE,WAAO,qBAAqB;AAAA,EAC9B;AACA,SACE,iBAAiB,SAAS,cAAc,QACxC,iBAAiB,cAAc,cAAc,aAC7C,iBAAiB,KAAK,SAAS,cAAc,KAAK,QAClD,iBAAiB,KAAK,QAAQ,cAAc,KAAK,OACjD,iBAAiB,KAAK,UAAU,cAAc,KAAK,SACnD,iBAAiB,KAAK,WAAW,cAAc,KAAK;AAExD;;;AC5QO,IAAM,4BAA4B;AAAA,EACvC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACR;","names":["SelectionToolbarRoot","SelectionToolbarQuote","SelectionToolbarCopy"]}
@@ -1,8 +1,9 @@
1
1
  import * as react from 'react';
2
- export { C as CompletionController, a as CompletionInputContextValue, b as CompletionProvider, c as CompletionProviderProps, u as useCompletionContext, d as useCompletionInput } from '../completion-input-WjK6kUyG.js';
2
+ export { C as CompletionController, a as CompletionInputContextValue, b as CompletionProvider, c as CompletionProviderProps, u as useCompletionContext, d as useCompletionInput } from '../completion-input-DHlwrhxB.js';
3
+ import '@anvia/client';
3
4
  import '@anvia/react';
4
5
 
5
- declare const Completion: {
6
+ declare const CompletionPrimitive: {
6
7
  readonly Root: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
7
8
  asChild?: boolean;
8
9
  } & react.RefAttributes<HTMLDivElement>>;
@@ -25,4 +26,4 @@ declare const Completion: {
25
26
  } & react.RefAttributes<HTMLButtonElement>>;
26
27
  };
27
28
 
28
- export { Completion };
29
+ export { CompletionPrimitive };
@@ -1,14 +1,14 @@
1
1
  import {
2
- Completion
3
- } from "../chunk-VEYJNQVW.js";
2
+ CompletionPrimitive
3
+ } from "../chunk-S4XLE2RN.js";
4
4
  import "../chunk-T3ZFZ3NP.js";
5
5
  import {
6
6
  CompletionProvider,
7
7
  useCompletionContext,
8
8
  useCompletionInput
9
- } from "../chunk-43U2XQP2.js";
9
+ } from "../chunk-SOG2GVE4.js";
10
10
  export {
11
- Completion,
11
+ CompletionPrimitive,
12
12
  CompletionProvider,
13
13
  useCompletionContext,
14
14
  useCompletionInput
@@ -0,0 +1,24 @@
1
+ import { ClientMetadata, ClientDataMap } from '@anvia/client';
2
+ import { UseCompletionResult } from '@anvia/react';
3
+ import { ReactNode, ReactElement } from 'react';
4
+
5
+ type CompletionController<Metadata extends ClientMetadata = ClientMetadata, Data extends ClientDataMap = ClientDataMap> = UseCompletionResult<Metadata, Data>;
6
+ type CompletionProviderProps<Metadata extends ClientMetadata = ClientMetadata, Data extends ClientDataMap = ClientDataMap> = {
7
+ controller: CompletionController<Metadata, Data>;
8
+ children?: ReactNode;
9
+ };
10
+ declare function CompletionProvider<Metadata extends ClientMetadata = ClientMetadata, Data extends ClientDataMap = ClientDataMap>({ controller, children }: CompletionProviderProps<Metadata, Data>): ReactElement;
11
+ declare function useCompletionContext<Metadata extends ClientMetadata = ClientMetadata, Data extends ClientDataMap = ClientDataMap>(): CompletionController<Metadata, Data>;
12
+
13
+ type CompletionInputContextValue = {
14
+ input: string;
15
+ setInput(input: string): void;
16
+ submit(): Promise<void>;
17
+ stop(): void;
18
+ status: CompletionController["status"];
19
+ canSubmit: boolean;
20
+ canStop: boolean;
21
+ };
22
+ declare function useCompletionInput(): CompletionInputContextValue;
23
+
24
+ export { type CompletionController as C, type CompletionInputContextValue as a, CompletionProvider as b, type CompletionProviderProps as c, useCompletionInput as d, useCompletionContext as u };
@@ -1,9 +1,9 @@
1
- import { CreateUIAttachment, UIAttachment } from '@anvia/react';
1
+ import { CreateUIAttachment, UIAttachment, ClientMetadata } from '@anvia/client';
2
2
  import { ReactNode } from 'react';
3
- import { C as ChatController } from './chat-B3kucz1w.js';
3
+ import { C as ChatController } from './chat-tfA570mg.js';
4
4
 
5
- type ComposerEntityData = string | number | boolean | null | ComposerEntityData[] | {
6
- [key: string]: ComposerEntityData | undefined;
5
+ type ComposerEntityData = string | number | boolean | null | readonly ComposerEntityData[] | {
6
+ [key: string]: ComposerEntityData;
7
7
  };
8
8
  type ComposerAttachmentInput = File | CreateUIAttachment;
9
9
  type ComposerAttachmentsUpdate = UIAttachment[] | ((attachments: UIAttachment[]) => UIAttachment[]);
@@ -49,9 +49,21 @@ type ComposerEntity = {
49
49
  };
50
50
  data?: ComposerEntityData | undefined;
51
51
  };
52
- type ComposerMessageMetadata = {
53
- composer: {
54
- entities: ComposerEntity[];
52
+ type ComposerMessageEntity = ClientMetadata & {
53
+ id: string;
54
+ triggerId: string;
55
+ trigger: string;
56
+ label: string;
57
+ text: string;
58
+ range: ClientMetadata & {
59
+ from: number;
60
+ to: number;
61
+ };
62
+ data?: ComposerEntityData | undefined;
63
+ };
64
+ type ComposerMessageMetadata = ClientMetadata & {
65
+ composer: ClientMetadata & {
66
+ entities: readonly ComposerMessageEntity[];
55
67
  };
56
68
  };
57
69
  type ComposerTriggerState = {
@@ -1,17 +1,19 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ToolApproval, ToolQuestion } from '@anvia/react';
4
- import { c as useHumanInput } from '../chat-B3kucz1w.js';
5
- export { u as useChatContext } from '../chat-B3kucz1w.js';
6
- export { A as ApprovalContextValue, Q as QuestionContextValue, a as QuestionPromptContextValue, u as useApproval, b as useQuestion, c as useQuestionPrompt } from '../human-input-CydeYm_7.js';
3
+ import { d as ApprovalInteraction, e as QuestionInteraction } from '../human-input-D7jgYsfM.js';
4
+ export { A as ApprovalContextValue, Q as QuestionContextValue, a as QuestionPromptContextValue, u as useApproval, b as useQuestion, c as useQuestionPrompt } from '../human-input-D7jgYsfM.js';
5
+ import { c as useHumanInput } from '../chat-tfA570mg.js';
6
+ export { u as useChatContext } from '../chat-tfA570mg.js';
7
7
  import { P as PrimitiveProps } from '../render-CRKWam2v.js';
8
+ import '@anvia/client';
9
+ import '@anvia/react';
8
10
 
9
- type ApprovalChildren = ReactNode | ((approval: ToolApproval) => ReactNode);
11
+ type ApprovalChildren = ReactNode | ((approval: ApprovalInteraction) => ReactNode);
10
12
  type HumanInputFilter = "pending" | "all";
11
13
 
12
- type QuestionChildren = ReactNode | ((question: ToolQuestion) => ReactNode);
14
+ type QuestionChildren = ReactNode | ((question: QuestionInteraction) => ReactNode);
13
15
 
14
- declare const HumanInput: {
16
+ declare const HumanInputPrimitive: {
15
17
  readonly Panel: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "asChild"> & {
16
18
  asChild?: boolean;
17
19
  } & {
@@ -73,4 +75,4 @@ declare const HumanInput: {
73
75
  } & react.RefAttributes<HTMLButtonElement>>;
74
76
  };
75
77
 
76
- export { HumanInput, useHumanInput };
78
+ export { HumanInputPrimitive, useHumanInput };
@@ -1,6 +1,7 @@
1
1
  import {
2
- HumanInput
3
- } from "../chunk-R3NA6BWW.js";
2
+ HumanInputPrimitive
3
+ } from "../chunk-OQE6SHZE.js";
4
+ import "../chunk-CKA4CE26.js";
4
5
  import "../chunk-T3ZFZ3NP.js";
5
6
  import {
6
7
  useApproval,
@@ -8,9 +9,9 @@ import {
8
9
  useHumanInput,
9
10
  useQuestion,
10
11
  useQuestionPrompt
11
- } from "../chunk-43U2XQP2.js";
12
+ } from "../chunk-SOG2GVE4.js";
12
13
  export {
13
- HumanInput,
14
+ HumanInputPrimitive,
14
15
  useApproval,
15
16
  useChatContext,
16
17
  useHumanInput,
@@ -0,0 +1,27 @@
1
+ import { ClientInteraction } from '@anvia/client';
2
+ import { A as AgentToolApprovalRequest, d as AgentToolQuestionRequest, e as AgentQuestionAnswer, f as AgentQuestionPrompt } from './chat-tfA570mg.js';
3
+
4
+ type ApprovalContextValue = {
5
+ approval: ApprovalInteraction;
6
+ reason: string;
7
+ setReason(reason: string): void;
8
+ };
9
+ type QuestionContextValue = {
10
+ question: QuestionInteraction;
11
+ answers: Record<string, AgentQuestionAnswer>;
12
+ setAnswer(prompt: AgentQuestionPrompt, answer: AgentQuestionAnswer): void;
13
+ };
14
+ type QuestionPromptContextValue = {
15
+ prompt: AgentQuestionPrompt;
16
+ };
17
+ type ApprovalInteraction = ClientInteraction & {
18
+ request: AgentToolApprovalRequest;
19
+ };
20
+ type QuestionInteraction = ClientInteraction & {
21
+ request: AgentToolQuestionRequest;
22
+ };
23
+ declare function useApproval(): ApprovalContextValue;
24
+ declare function useQuestion(): QuestionContextValue;
25
+ declare function useQuestionPrompt(): QuestionPromptContextValue;
26
+
27
+ export { type ApprovalContextValue as A, type QuestionContextValue as Q, type QuestionPromptContextValue as a, useQuestion as b, useQuestionPrompt as c, type ApprovalInteraction as d, type QuestionInteraction as e, useApproval as u };
@@ -1,12 +1,12 @@
1
1
  import * as react from 'react';
2
- import * as _anvia_react from '@anvia/react';
3
- import { I as ImageContextValue } from '../image-DanUxcl2.js';
4
- export { u as useImage } from '../image-DanUxcl2.js';
2
+ import * as _anvia_client from '@anvia/client';
3
+ import { I as ImageContextValue } from '../image-VZv6Ddsn.js';
4
+ export { u as useImage } from '../image-VZv6Ddsn.js';
5
5
  import { P as PrimitiveProps } from '../render-CRKWam2v.js';
6
6
 
7
- declare const Image: {
7
+ declare const ImagePrimitive: {
8
8
  readonly Root: react.ForwardRefExoticComponent<Omit<PrimitiveProps<"figure">, "children"> & {
9
- attachment?: _anvia_react.UIAttachment;
9
+ attachment?: _anvia_client.UIAttachment;
10
10
  children?: react.ReactNode | ((image: ImageContextValue) => react.ReactNode);
11
11
  renderWhen?: "image" | "always";
12
12
  } & react.RefAttributes<HTMLElement>>;
@@ -37,4 +37,4 @@ declare const Image: {
37
37
  } & react.RefAttributes<HTMLDivElement>>;
38
38
  };
39
39
 
40
- export { Image, ImageContextValue };
40
+ export { ImageContextValue, ImagePrimitive };
@@ -1,12 +1,12 @@
1
1
  import {
2
- Image
3
- } from "../chunk-7HR34SOF.js";
2
+ ImagePrimitive
3
+ } from "../chunk-CVXLQCDI.js";
4
4
  import "../chunk-T3ZFZ3NP.js";
5
5
  import {
6
6
  useImage
7
- } from "../chunk-43U2XQP2.js";
7
+ } from "../chunk-SOG2GVE4.js";
8
8
  export {
9
- Image,
9
+ ImagePrimitive,
10
10
  useImage
11
11
  };
12
12
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { UIAttachment } from '@anvia/react';
1
+ import { UIAttachment } from '@anvia/client';
2
2
 
3
3
  type ImageContextValue = {
4
4
  attachment: UIAttachment;