@chatsdk-dev/elements 0.0.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.
Files changed (218) hide show
  1. package/README.md +43 -0
  2. package/dist/chunk-2LHKM7RD.js +14 -0
  3. package/dist/chunk-5UMYP6MD.js +10 -0
  4. package/dist/chunk-AP4MG32M.js +36 -0
  5. package/dist/chunk-CFM57HOS.js +358 -0
  6. package/dist/chunk-EGIUE7H2.js +37 -0
  7. package/dist/chunk-M5OONVIO.js +90 -0
  8. package/dist/chunk-MXTBCHYC.js +31 -0
  9. package/dist/chunk-NIC3MOMY.js +55 -0
  10. package/dist/chunk-QTRMNIG3.js +83 -0
  11. package/dist/chunk-R7G3RQLU.js +36 -0
  12. package/dist/chunk-RJG5D2TM.js +113 -0
  13. package/dist/chunk-SLJNKQ2G.js +125 -0
  14. package/dist/chunk-TDEFIW2L.js +9 -0
  15. package/dist/chunk-TDP6D7U7.js +551 -0
  16. package/dist/chunk-V2ITXC65.js +24 -0
  17. package/dist/chunk-VS55HRUS.js +16 -0
  18. package/dist/chunk-VYDYCGJL.js +25 -0
  19. package/dist/chunk-X5YUF2YM.js +113 -0
  20. package/dist/chunk-YX46JVQN.js +78 -0
  21. package/dist/chunk-YXAMLTTT.js +16 -0
  22. package/dist/chunk-YXFVHSY4.js +51 -0
  23. package/dist/chunk-ZCSZX3OI.js +4 -0
  24. package/dist/common/use-copy-to-clipboard.d.ts +3 -0
  25. package/dist/common/use-copy-to-clipboard.js +33 -0
  26. package/dist/common/utilts.d.ts +8 -0
  27. package/dist/common/utilts.js +28 -0
  28. package/dist/components/ai-elements/actions.d.ts +13 -0
  29. package/dist/components/ai-elements/actions.js +42 -0
  30. package/dist/components/ai-elements/agent.d.ts +31 -0
  31. package/dist/components/ai-elements/agent.js +77 -0
  32. package/dist/components/ai-elements/artifact.d.ts +27 -0
  33. package/dist/components/ai-elements/artifact.js +108 -0
  34. package/dist/components/ai-elements/attachments.d.ts +57 -0
  35. package/dist/components/ai-elements/attachments.js +258 -0
  36. package/dist/components/ai-elements/audio-player.d.ts +33 -0
  37. package/dist/components/ai-elements/audio-player.js +199 -0
  38. package/dist/components/ai-elements/canvas.d.ts +10 -0
  39. package/dist/components/ai-elements/canvas.js +24 -0
  40. package/dist/components/ai-elements/chain-of-thought.d.ts +34 -0
  41. package/dist/components/ai-elements/chain-of-thought.js +159 -0
  42. package/dist/components/ai-elements/checkpoint.d.ts +16 -0
  43. package/dist/components/ai-elements/checkpoint.js +47 -0
  44. package/dist/components/ai-elements/code-block.d.ts +48 -0
  45. package/dist/components/ai-elements/code-block.js +1 -0
  46. package/dist/components/ai-elements/commit.d.ts +68 -0
  47. package/dist/components/ai-elements/commit.js +314 -0
  48. package/dist/components/ai-elements/confirmation.d.ts +52 -0
  49. package/dist/components/ai-elements/confirmation.js +76 -0
  50. package/dist/components/ai-elements/connection.d.ts +5 -0
  51. package/dist/components/ai-elements/connection.js +34 -0
  52. package/dist/components/ai-elements/context.d.ts +36 -0
  53. package/dist/components/ai-elements/context.js +320 -0
  54. package/dist/components/ai-elements/controls.d.ts +8 -0
  55. package/dist/components/ai-elements/controls.js +17 -0
  56. package/dist/components/ai-elements/conversation.d.ts +27 -0
  57. package/dist/components/ai-elements/conversation.js +119 -0
  58. package/dist/components/ai-elements/edge.d.ts +9 -0
  59. package/dist/components/ai-elements/edge.js +111 -0
  60. package/dist/components/ai-elements/environment-variables.d.ts +42 -0
  61. package/dist/components/ai-elements/environment-variables.js +208 -0
  62. package/dist/components/ai-elements/file-tree.d.ts +30 -0
  63. package/dist/components/ai-elements/file-tree.js +212 -0
  64. package/dist/components/ai-elements/image.d.ts +10 -0
  65. package/dist/components/ai-elements/image.js +23 -0
  66. package/dist/components/ai-elements/inline-citation.d.ts +42 -0
  67. package/dist/components/ai-elements/inline-citation.js +203 -0
  68. package/dist/components/ai-elements/jsx-preview.d.ts +33 -0
  69. package/dist/components/ai-elements/jsx-preview.js +206 -0
  70. package/dist/components/ai-elements/loader.d.ts +9 -0
  71. package/dist/components/ai-elements/loader.js +115 -0
  72. package/dist/components/ai-elements/message.d.ts +42 -0
  73. package/dist/components/ai-elements/message.js +259 -0
  74. package/dist/components/ai-elements/mic-selector.d.ts +49 -0
  75. package/dist/components/ai-elements/mic-selector.js +252 -0
  76. package/dist/components/ai-elements/model-selector.d.ts +39 -0
  77. package/dist/components/ai-elements/model-selector.js +73 -0
  78. package/dist/components/ai-elements/node.d.ts +25 -0
  79. package/dist/components/ai-elements/node.js +41 -0
  80. package/dist/components/ai-elements/open-in-chat.d.ts +32 -0
  81. package/dist/components/ai-elements/open-in-chat.js +366 -0
  82. package/dist/components/ai-elements/package-info.d.ts +32 -0
  83. package/dist/components/ai-elements/package-info.js +162 -0
  84. package/dist/components/ai-elements/panel.d.ts +8 -0
  85. package/dist/components/ai-elements/panel.js +17 -0
  86. package/dist/components/ai-elements/persona.d.ts +50 -0
  87. package/dist/components/ai-elements/persona.js +209 -0
  88. package/dist/components/ai-elements/plan.d.ts +29 -0
  89. package/dist/components/ai-elements/plan.js +95 -0
  90. package/dist/components/ai-elements/prompt-input.d.ts +153 -0
  91. package/dist/components/ai-elements/prompt-input.js +939 -0
  92. package/dist/components/ai-elements/queue.d.ts +65 -0
  93. package/dist/components/ai-elements/queue.js +179 -0
  94. package/dist/components/ai-elements/reasoning.d.ts +30 -0
  95. package/dist/components/ai-elements/reasoning.js +161 -0
  96. package/dist/components/ai-elements/response.d.ts +9 -0
  97. package/dist/components/ai-elements/response.js +33 -0
  98. package/dist/components/ai-elements/sandbox.d.ts +28 -0
  99. package/dist/components/ai-elements/sandbox.js +98 -0
  100. package/dist/components/ai-elements/schema-display.d.ts +58 -0
  101. package/dist/components/ai-elements/schema-display.js +313 -0
  102. package/dist/components/ai-elements/shimmer.d.ts +14 -0
  103. package/dist/components/ai-elements/shimmer.js +1 -0
  104. package/dist/components/ai-elements/snippet.d.ts +22 -0
  105. package/dist/components/ai-elements/snippet.js +90 -0
  106. package/dist/components/ai-elements/sources.d.ts +16 -0
  107. package/dist/components/ai-elements/sources.js +62 -0
  108. package/dist/components/ai-elements/speech-input.d.ts +57 -0
  109. package/dist/components/ai-elements/speech-input.js +206 -0
  110. package/dist/components/ai-elements/stack-trace.d.ts +42 -0
  111. package/dist/components/ai-elements/stack-trace.js +377 -0
  112. package/dist/components/ai-elements/suggestion.d.ts +14 -0
  113. package/dist/components/ai-elements/suggestion.js +41 -0
  114. package/dist/components/ai-elements/task.d.ts +18 -0
  115. package/dist/components/ai-elements/task.js +60 -0
  116. package/dist/components/ai-elements/terminal.d.ts +31 -0
  117. package/dist/components/ai-elements/terminal.js +203 -0
  118. package/dist/components/ai-elements/test-results.d.ts +61 -0
  119. package/dist/components/ai-elements/test-results.js +349 -0
  120. package/dist/components/ai-elements/tool.d.ts +35 -0
  121. package/dist/components/ai-elements/tool.js +2 -0
  122. package/dist/components/ai-elements/toolbar.d.ts +8 -0
  123. package/dist/components/ai-elements/toolbar.js +18 -0
  124. package/dist/components/ai-elements/transcription.d.ts +19 -0
  125. package/dist/components/ai-elements/transcription.js +90 -0
  126. package/dist/components/ai-elements/voice-selector.d.ts +66 -0
  127. package/dist/components/ai-elements/voice-selector.js +332 -0
  128. package/dist/components/ai-elements/web-preview.d.ts +38 -0
  129. package/dist/components/ai-elements/web-preview.js +214 -0
  130. package/dist/components/info-card.d.ts +14 -0
  131. package/dist/components/info-card.js +1 -0
  132. package/dist/components/responsive-alert-dialog.d.ts +19 -0
  133. package/dist/components/responsive-alert-dialog.js +1 -0
  134. package/dist/components/responsive-dialog.d.ts +14 -0
  135. package/dist/components/responsive-dialog.js +1 -0
  136. package/dist/config-IcWUmjwj.d.ts +239 -0
  137. package/dist/features/chat/chat-card.d.ts +5 -0
  138. package/dist/features/chat/chat-card.js +14 -0
  139. package/dist/features/chat/chat-element/chat-element.d.ts +8 -0
  140. package/dist/features/chat/chat-element/chat-element.js +14 -0
  141. package/dist/features/chat/chat-element/use-chat.d.ts +21 -0
  142. package/dist/features/chat/chat-element/use-chat.js +14 -0
  143. package/dist/features/chat/chat-element/use-initial-messages.d.ts +20 -0
  144. package/dist/features/chat/chat-element/use-initial-messages.js +14 -0
  145. package/dist/features/chat/chat-header/chat-header.d.ts +8 -0
  146. package/dist/features/chat/chat-header/chat-header.js +14 -0
  147. package/dist/features/chat/chat-header/chat-menu.d.ts +5 -0
  148. package/dist/features/chat/chat-header/chat-menu.js +2 -0
  149. package/dist/features/chat/chat-history/chat-history-empty.d.ts +5 -0
  150. package/dist/features/chat/chat-history/chat-history-empty.js +1 -0
  151. package/dist/features/chat/chat-history/chat-history.d.ts +5 -0
  152. package/dist/features/chat/chat-history/chat-history.js +14 -0
  153. package/dist/features/chat/chat-message.d.ts +10 -0
  154. package/dist/features/chat/chat-message.js +1 -0
  155. package/dist/features/chat/chat-molecule.d.ts +35 -0
  156. package/dist/features/chat/chat-molecule.js +14 -0
  157. package/dist/features/chat/chat-prompt-input.d.ts +16 -0
  158. package/dist/features/chat/chat-prompt-input.js +14 -0
  159. package/dist/features/chat/chat.context.d.ts +26 -0
  160. package/dist/features/chat/chat.context.js +13 -0
  161. package/dist/features/chat/index.d.ts +14 -0
  162. package/dist/features/chat/index.js +14 -0
  163. package/dist/features/chat/queries/query-keys.d.ts +8 -0
  164. package/dist/features/chat/queries/query-keys.js +1 -0
  165. package/dist/features/chat/queries/use-create-conversation-mutation.d.ts +29 -0
  166. package/dist/features/chat/queries/use-create-conversation-mutation.js +38 -0
  167. package/dist/features/chat/queries/use-get-chat-query.d.ts +9 -0
  168. package/dist/features/chat/queries/use-get-chat-query.js +14 -0
  169. package/dist/features/chat/queries/use-get-conversation-query.d.ts +62 -0
  170. package/dist/features/chat/queries/use-get-conversation-query.js +14 -0
  171. package/dist/features/chat/queries/use-list-conversations-query.d.ts +29 -0
  172. package/dist/features/chat/queries/use-list-conversations-query.js +14 -0
  173. package/dist/features/chat/store.d.ts +13 -0
  174. package/dist/features/chat/store.js +1 -0
  175. package/dist/features/chat/utils.d.ts +5 -0
  176. package/dist/features/chat/utils.js +1 -0
  177. package/dist/features/data-fetching/use-api-client.d.ts +5 -0
  178. package/dist/features/data-fetching/use-api-client.js +14 -0
  179. package/dist/features/logger/logger.d.ts +9 -0
  180. package/dist/features/logger/logger.js +1 -0
  181. package/dist/features/molecule/chatsdk-provider.d.ts +19 -0
  182. package/dist/features/molecule/chatsdk-provider.js +26 -0
  183. package/dist/features/molecule/constants.d.ts +3 -0
  184. package/dist/features/molecule/constants.js +1 -0
  185. package/dist/features/molecule/molecule-provider.d.ts +39 -0
  186. package/dist/features/molecule/molecule-provider.js +1 -0
  187. package/dist/features/molecule/store.d.ts +53 -0
  188. package/dist/features/molecule/store.js +3 -0
  189. package/dist/features/molecule/types/api.d.ts +8 -0
  190. package/dist/features/molecule/types/api.js +1 -0
  191. package/dist/features/molecule/types/callbacks.d.ts +22 -0
  192. package/dist/features/molecule/types/callbacks.js +1 -0
  193. package/dist/features/molecule/types/config.d.ts +10 -0
  194. package/dist/features/molecule/types/config.js +1 -0
  195. package/dist/features/molecule/types/context.d.ts +11 -0
  196. package/dist/features/molecule/types/context.js +1 -0
  197. package/dist/features/molecule/types/locale.d.ts +9 -0
  198. package/dist/features/molecule/types/locale.js +1 -0
  199. package/dist/features/molecule/types/theme.d.ts +38 -0
  200. package/dist/features/molecule/types/theme.js +1 -0
  201. package/dist/features/molecule/types/translations.d.ts +10 -0
  202. package/dist/features/molecule/types/translations.js +1 -0
  203. package/dist/features/molecule/use-merge-global-config.d.ts +22 -0
  204. package/dist/features/molecule/use-merge-global-config.js +5 -0
  205. package/dist/features/molecule/use-molecule-config.d.ts +41 -0
  206. package/dist/features/molecule/use-molecule-config.js +6 -0
  207. package/dist/features/molecule/utils.d.ts +10 -0
  208. package/dist/features/molecule/utils.js +1 -0
  209. package/dist/i18n/config.d.ts +61 -0
  210. package/dist/i18n/config.js +1 -0
  211. package/dist/i18n/i18next.d.ts +11 -0
  212. package/dist/i18n/i18next.js +2 -0
  213. package/dist/i18n/utils.d.ts +11 -0
  214. package/dist/i18n/utils.js +6 -0
  215. package/dist/index.d.ts +20 -0
  216. package/dist/index.js +20 -0
  217. package/dist/styles.css +6811 -0
  218. package/package.json +123 -0
@@ -0,0 +1,551 @@
1
+ import { ChatMenu } from './chunk-AP4MG32M.js';
2
+ import { ChatHistoryEmpty } from './chunk-YXAMLTTT.js';
3
+ import { chatQueryKeys } from './chunk-TDEFIW2L.js';
4
+ import { createMoleculeContext } from './chunk-M5OONVIO.js';
5
+ import { useMergeMoleculeConfig } from './chunk-VYDYCGJL.js';
6
+ import { useChatStore } from './chunk-2LHKM7RD.js';
7
+ import { getInitialMessagesFromStrings } from './chunk-5UMYP6MD.js';
8
+ import { ChatMessage } from './chunk-SLJNKQ2G.js';
9
+ import { getClient } from '@chatsdk-dev/api-client';
10
+ import { useTranslation } from 'react-i18next';
11
+ import { CardHeader, CardTitle, Card } from '@chatsdk-dev/ui/components/card';
12
+ import { DotsLoader } from '@chatsdk-dev/ui/components/dots-loader';
13
+ import { Text } from '@chatsdk-dev/ui/components/typography/text';
14
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
15
+ import { useState, useMemo, useEffect, useRef, Fragment } from 'react';
16
+ import { Conversation, ConversationContent, ConversationScrollButton } from '@chatsdk-dev/elements/components/ai-elements/conversation';
17
+ import { GlobeIcon, CheckIcon, ArrowLeft, Plus } from 'lucide-react';
18
+ import { PromptInput, PromptInputTextarea, PromptInputSubmit, PromptInputTools, PromptInputButton } from '@chatsdk-dev/elements/components/ai-elements/prompt-input';
19
+ import { ModelSelector, ModelSelectorTrigger, ModelSelectorLogo, ModelSelectorName, ModelSelectorContent, ModelSelectorInput, ModelSelectorList, ModelSelectorEmpty, ModelSelectorGroup, ModelSelectorItem, ModelSelectorLogoGroup } from '@chatsdk-dev/elements/components/ai-elements/model-selector';
20
+ import { jsxs, jsx } from 'react/jsx-runtime';
21
+ import { useChat as useChat$1 } from '@ai-sdk/react';
22
+ import { DefaultChatTransport } from 'ai';
23
+ import { Button } from '@chatsdk-dev/ui/components/button';
24
+ import { renderRelativeTime } from '@chatsdk-dev/elements/common/utilts';
25
+
26
+ function useGetChatQuery({ chatId }) {
27
+ const client = useApiClient();
28
+ return useQuery({
29
+ queryKey: chatQueryKeys.get(chatId),
30
+ queryFn: async () => {
31
+ const { data, error } = await client.chats.get({
32
+ path: { chatId }
33
+ });
34
+ if (error) {
35
+ throw new Error(
36
+ "error" in error ? error.error : "Failed to fetch chat"
37
+ );
38
+ }
39
+ return data;
40
+ },
41
+ enabled: !!chatId
42
+ });
43
+ }
44
+ function ChatPromptInput({
45
+ chatId,
46
+ onSubmit,
47
+ onModelChange,
48
+ status,
49
+ ref
50
+ }) {
51
+ const { data } = useGetChatQuery({ chatId });
52
+ const defaultModel = data?.chatModelSettings?.defaultModel;
53
+ const allowedModels = data?.chatModelSettings?.allowedModels;
54
+ const [input, setInput] = useState("");
55
+ const [model, setModel] = useState(defaultModel?.name);
56
+ const [modelSelectorOpen, setModelSelectorOpen] = useState(false);
57
+ const [webSearch, setWebSearch] = useState(false);
58
+ const selectedModel = allowedModels?.find((m) => m.name === model);
59
+ const modelGroups = allowedModels?.map((m) => m.chef);
60
+ const hasMultipleModels = allowedModels && allowedModels.length > 1;
61
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
62
+ /* @__PURE__ */ jsxs(
63
+ PromptInput,
64
+ {
65
+ onSubmit: (message, event) => {
66
+ onSubmit(message, event);
67
+ setInput("");
68
+ },
69
+ children: [
70
+ /* @__PURE__ */ jsx(
71
+ PromptInputTextarea,
72
+ {
73
+ ref,
74
+ placeholder: data?.chatBaseSettings?.inputPlaceholder,
75
+ onChange: (e) => setInput(e.target.value),
76
+ value: input
77
+ }
78
+ ),
79
+ /* @__PURE__ */ jsx(
80
+ PromptInputSubmit,
81
+ {
82
+ className: "m-1.5 self-end",
83
+ disabled: !input,
84
+ status
85
+ }
86
+ )
87
+ ]
88
+ }
89
+ ),
90
+ /* @__PURE__ */ jsxs(PromptInputTools, { children: [
91
+ /* @__PURE__ */ jsxs(
92
+ PromptInputButton,
93
+ {
94
+ variant: webSearch ? "primary" : "ghost",
95
+ onClick: () => setWebSearch(!webSearch),
96
+ children: [
97
+ /* @__PURE__ */ jsx(GlobeIcon, { size: 16 }),
98
+ /* @__PURE__ */ jsx("span", { children: "Search" })
99
+ ]
100
+ }
101
+ ),
102
+ hasMultipleModels && /* @__PURE__ */ jsxs(
103
+ ModelSelector,
104
+ {
105
+ onOpenChange: setModelSelectorOpen,
106
+ open: modelSelectorOpen,
107
+ children: [
108
+ /* @__PURE__ */ jsx(ModelSelectorTrigger, { children: /* @__PURE__ */ jsxs(PromptInputButton, { children: [
109
+ selectedModel?.chefSlug && /* @__PURE__ */ jsx(ModelSelectorLogo, { provider: selectedModel.chefSlug }),
110
+ /* @__PURE__ */ jsx(ModelSelectorName, { children: selectedModel?.name })
111
+ ] }) }),
112
+ /* @__PURE__ */ jsxs(ModelSelectorContent, { children: [
113
+ /* @__PURE__ */ jsx(ModelSelectorInput, { placeholder: "Search models..." }),
114
+ /* @__PURE__ */ jsxs(ModelSelectorList, { children: [
115
+ /* @__PURE__ */ jsx(ModelSelectorEmpty, { children: "No models found." }),
116
+ modelGroups?.map((chef) => /* @__PURE__ */ jsx(ModelSelectorGroup, { heading: chef, children: allowedModels.filter((m) => m.chef === chef).map((m) => /* @__PURE__ */ jsxs(
117
+ ModelSelectorItem,
118
+ {
119
+ onSelect: () => {
120
+ setModel(m.name);
121
+ onModelChange?.(m);
122
+ setModelSelectorOpen(false);
123
+ },
124
+ value: m.name,
125
+ children: [
126
+ /* @__PURE__ */ jsx(ModelSelectorLogo, { provider: m.chefSlug }),
127
+ /* @__PURE__ */ jsx(ModelSelectorName, { children: m.name }),
128
+ /* @__PURE__ */ jsx(ModelSelectorLogoGroup, { children: m.providers.map((provider) => /* @__PURE__ */ jsx(
129
+ ModelSelectorLogo,
130
+ {
131
+ provider
132
+ },
133
+ provider
134
+ )) }),
135
+ selectedModel?.name === m.name ? /* @__PURE__ */ jsx(CheckIcon, { className: "ml-auto size-4" }) : /* @__PURE__ */ jsx("div", { className: "ml-auto size-4" })
136
+ ]
137
+ },
138
+ m.name
139
+ )) }, chef))
140
+ ] })
141
+ ] })
142
+ ]
143
+ }
144
+ )
145
+ ] })
146
+ ] });
147
+ }
148
+ async function getConversation({
149
+ client,
150
+ chatId,
151
+ actorId,
152
+ conversationId
153
+ }) {
154
+ if (!conversationId) {
155
+ const { data: newConversation, error: error2 } = await client.chats.conversations.create({
156
+ path: { chatId },
157
+ body: { actorId }
158
+ });
159
+ if (error2) {
160
+ throw new Error(
161
+ "error" in error2 ? error2.error : "Failed to create conversation"
162
+ );
163
+ }
164
+ useChatStore.setState({
165
+ ...useChatStore.getState(),
166
+ selectedConversationId: newConversation._id
167
+ });
168
+ return newConversation;
169
+ }
170
+ const { data, error } = await client.chats.conversations.get({
171
+ path: { chatId, conversationId }
172
+ });
173
+ if (error) {
174
+ throw new Error(
175
+ "error" in error ? error.error : "Failed to fetch conversation"
176
+ );
177
+ }
178
+ return data;
179
+ }
180
+ function getConversationQueryConfig({
181
+ chatId,
182
+ conversationId,
183
+ client,
184
+ actorId
185
+ }) {
186
+ return {
187
+ queryKey: chatQueryKeys.conversation(chatId, conversationId),
188
+ queryFn: () => getConversation({ client, chatId, conversationId, actorId })
189
+ };
190
+ }
191
+ function useGetConversationQuery({
192
+ chatId,
193
+ conversationId
194
+ }) {
195
+ const client = useApiClient();
196
+ const { context } = useMoleculeConfig();
197
+ return useQuery({
198
+ ...getConversationQueryConfig({
199
+ chatId,
200
+ conversationId,
201
+ client,
202
+ actorId: context?.actor?.id ?? ""
203
+ }),
204
+ enabled: !!chatId,
205
+ staleTime: 200
206
+ });
207
+ }
208
+ function useInitialMessages() {
209
+ const { selectedConversationId } = useChatStore();
210
+ const { chatId } = useMoleculeComponent();
211
+ const { data } = useGetChatQuery({ chatId });
212
+ const { data: conversation } = useGetConversationQuery({
213
+ chatId,
214
+ conversationId: selectedConversationId
215
+ });
216
+ const conversationMessages = useMemo(() => {
217
+ if (!selectedConversationId) return void 0;
218
+ return conversation?.messages?.map((msg) => {
219
+ return {
220
+ id: msg.id,
221
+ role: msg.role,
222
+ parts: msg.parts.map((p) => ({
223
+ type: "text",
224
+ text: p.text ?? ""
225
+ })),
226
+ metadata: msg
227
+ };
228
+ });
229
+ }, [conversation, selectedConversationId]);
230
+ const initialMessages = useMemo(() => {
231
+ const initialChatMessages = getInitialMessagesFromStrings(
232
+ data?.chatBaseSettings?.initialChatMessages ?? []
233
+ );
234
+ return [...initialChatMessages, ...conversationMessages ?? []];
235
+ }, [data?.chatBaseSettings?.initialChatMessages, conversationMessages]);
236
+ return initialMessages;
237
+ }
238
+
239
+ // src/features/chat/chat-element/use-chat.tsx
240
+ function useChat() {
241
+ const client = useApiClient();
242
+ const { config, component } = useMolecule();
243
+ const { selectedConversationId, conversationType } = useChatStore();
244
+ const initialMessages = useInitialMessages();
245
+ const useChatResult = useChat$1({
246
+ messages: initialMessages,
247
+ transport: new DefaultChatTransport({
248
+ prepareSendMessagesRequest: ({
249
+ body,
250
+ headers,
251
+ credentials,
252
+ id,
253
+ messages,
254
+ trigger,
255
+ messageId
256
+ }) => {
257
+ return {
258
+ api: client.getUrl("chats.conversations.completion", {
259
+ chatId: component.chatId,
260
+ conversationId: body?.conversationId || "new"
261
+ }),
262
+ body: {
263
+ ...body,
264
+ id,
265
+ messages,
266
+ trigger,
267
+ messageId
268
+ },
269
+ headers,
270
+ credentials
271
+ };
272
+ },
273
+ headers: {
274
+ ...config.api?.headers
275
+ }
276
+ })
277
+ });
278
+ useEffect(() => {
279
+ if (conversationType === "history" || !selectedConversationId) {
280
+ useChatResult.stop();
281
+ useChatResult.setMessages(initialMessages);
282
+ }
283
+ }, [conversationType, selectedConversationId, initialMessages]);
284
+ return useChatResult;
285
+ }
286
+ function ChatElement() {
287
+ const queryClient = useQueryClient();
288
+ const client = useApiClient();
289
+ const { chatId } = useMoleculeComponent();
290
+ const { context } = useMoleculeConfig();
291
+ const { selectedConversationId } = useChatStore();
292
+ const { data: conversation } = useGetConversationQuery({
293
+ chatId,
294
+ conversationId: selectedConversationId
295
+ });
296
+ const { messages, sendMessage, status } = useChat();
297
+ const promptInputRef = useRef(null);
298
+ useEffect(() => {
299
+ promptInputRef.current?.focus();
300
+ }, [selectedConversationId]);
301
+ const handleSubmit = async (message) => {
302
+ let conversationId = conversation?._id;
303
+ if (!conversation) {
304
+ const newConversation = await queryClient.fetchQuery({
305
+ ...getConversationQueryConfig({
306
+ chatId,
307
+ conversationId: selectedConversationId,
308
+ client,
309
+ actorId: context?.actor?.id ?? ""
310
+ })
311
+ });
312
+ conversationId = newConversation._id;
313
+ }
314
+ sendMessage({ text: message.text }, { body: { conversationId } });
315
+ };
316
+ const lastMessage = messages[messages.length - 1];
317
+ const isWaitingForContent = status === "submitted" || status === "streaming" && lastMessage?.role === "assistant" && !lastMessage.parts.some(
318
+ (part) => part.type === "text" && part.text.length > 0
319
+ );
320
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
321
+ /* @__PURE__ */ jsxs(Conversation, { children: [
322
+ /* @__PURE__ */ jsxs(ConversationContent, { children: [
323
+ /* @__PURE__ */ jsx(ChatMessage, { messages }),
324
+ isWaitingForContent && /* @__PURE__ */ jsx(DotsLoader, {})
325
+ ] }),
326
+ /* @__PURE__ */ jsx(ConversationScrollButton, {})
327
+ ] }),
328
+ /* @__PURE__ */ jsx("div", { className: "m-4 my-2", children: /* @__PURE__ */ jsx(
329
+ ChatPromptInput,
330
+ {
331
+ ref: promptInputRef,
332
+ chatId,
333
+ onSubmit: handleSubmit,
334
+ status
335
+ }
336
+ ) })
337
+ ] });
338
+ }
339
+ ChatElement.displayName = "ChatElement";
340
+ function ChatHeader({ chatId }) {
341
+ const { t } = useTranslation();
342
+ const { tab, setTab } = useChatStore();
343
+ const { data } = useGetChatQuery({ chatId });
344
+ const [_, setImgLoaded] = useState(false);
345
+ const name = data?.chatAppearanceSettings?.displayName;
346
+ const iconUrl = data?.chatAppearanceSettings?.icon?.url;
347
+ return /* @__PURE__ */ jsxs(CardHeader, { className: "flex justify-between items-center h-14 bg-slate-900 dark:bg-zinc-400 rounded-t-lg px-4!", children: [
348
+ /* @__PURE__ */ jsxs(CardTitle, { children: [
349
+ tab === "chat" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
350
+ iconUrl && /* @__PURE__ */ jsx(
351
+ "img",
352
+ {
353
+ src: iconUrl,
354
+ alt: "Chat Icon",
355
+ className: "inline-block w-4 h-4",
356
+ onLoad: () => setImgLoaded(true)
357
+ }
358
+ ),
359
+ /* @__PURE__ */ jsx(
360
+ Text,
361
+ {
362
+ variant: "h1",
363
+ className: "text-sm text-background flex items-center gap-2",
364
+ children: name
365
+ }
366
+ )
367
+ ] }),
368
+ tab === "history" && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
369
+ /* @__PURE__ */ jsx(
370
+ Button,
371
+ {
372
+ onClick: () => setTab("chat"),
373
+ variant: "transparent",
374
+ className: "p-0!",
375
+ children: /* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" })
376
+ }
377
+ ),
378
+ /* @__PURE__ */ jsx(
379
+ Text,
380
+ {
381
+ variant: "h1",
382
+ className: "text-sm text-background flex items-center gap-2",
383
+ children: t("header.history-tab-label")
384
+ }
385
+ )
386
+ ] })
387
+ ] }),
388
+ tab === "chat" && /* @__PURE__ */ jsx(ChatMenu, {})
389
+ ] });
390
+ }
391
+ function useListConversationsQuery({
392
+ chatId
393
+ }) {
394
+ const client = useApiClient();
395
+ const { context } = useMoleculeConfig();
396
+ return useQuery({
397
+ queryKey: chatQueryKeys.listConversations(chatId),
398
+ queryFn: async () => {
399
+ const { data, error } = await client.chats.conversations.list({
400
+ path: { chatId },
401
+ query: { actorId: context?.actor?.id ?? "" }
402
+ });
403
+ if (error) {
404
+ throw new Error(
405
+ "error" in error ? error.error : "Failed to fetch conversations"
406
+ );
407
+ }
408
+ return data.conversations.reverse();
409
+ },
410
+ enabled: !!chatId
411
+ });
412
+ }
413
+ function ChatHistory() {
414
+ const { t, i18n } = useTranslation("chat", { keyPrefix: "history" });
415
+ const queryClient = useQueryClient();
416
+ const { chatId } = useMoleculeComponent();
417
+ const { data, isLoading } = useListConversationsQuery({ chatId });
418
+ const { setSelectedConversationId, setTab, setConversationType } = useChatStore();
419
+ if (isLoading) {
420
+ return /* @__PURE__ */ jsx("div", { className: "w-full h-full flex items-center justify-center", children: /* @__PURE__ */ jsx(DotsLoader, {}) });
421
+ }
422
+ return /* @__PURE__ */ jsxs("div", { className: "flex-1 min-h-0 flex flex-col gap-1 overflow-y-auto gap-2 p-2", children: [
423
+ data?.length === 0 ? /* @__PURE__ */ jsx(ChatHistoryEmpty, {}) : data?.map((conversation, index) => /* @__PURE__ */ jsxs(
424
+ Button,
425
+ {
426
+ variant: "ghost",
427
+ className: "flex flex-col items-start justify-center gap-2 px-3 py-2 h-auto text-left",
428
+ onClick: () => {
429
+ queryClient.invalidateQueries({
430
+ queryKey: chatQueryKeys.conversation(chatId, conversation._id)
431
+ });
432
+ setSelectedConversationId(conversation._id);
433
+ setTab("chat");
434
+ setConversationType("history");
435
+ },
436
+ children: [
437
+ /* @__PURE__ */ jsxs("div", { className: "self-stretch flex justify-between gap-1", children: [
438
+ /* @__PURE__ */ jsxs(Text, { className: "truncate text-sm", children: [
439
+ data.length - index,
440
+ ":",
441
+ " ",
442
+ conversation.title ?? t("unitled-conversation")
443
+ ] }),
444
+ /* @__PURE__ */ jsx(Text, { variant: "tiny", color: "muted", children: renderRelativeTime({
445
+ date: conversation._creationTime,
446
+ locale: i18n.language
447
+ }) })
448
+ ] }),
449
+ /* @__PURE__ */ jsx(
450
+ Text,
451
+ {
452
+ className: "flex-1 min-w-0 max-w-full truncate",
453
+ variant: "paragraph2",
454
+ color: "muted",
455
+ children: conversation.summary
456
+ }
457
+ )
458
+ ]
459
+ },
460
+ conversation._id
461
+ )),
462
+ /* @__PURE__ */ jsxs(
463
+ Button,
464
+ {
465
+ className: "absolute bottom-6 left-1/2 -translate-x-1/2",
466
+ onClick: () => {
467
+ setConversationType("new");
468
+ setSelectedConversationId();
469
+ setTab("chat");
470
+ },
471
+ children: [
472
+ /* @__PURE__ */ jsx(Plus, { className: "size-4" }),
473
+ t("new-conversation")
474
+ ]
475
+ }
476
+ )
477
+ ] });
478
+ }
479
+ function ChatCard() {
480
+ const { t } = useTranslation();
481
+ const { chatId } = useMoleculeComponent();
482
+ const { tab, selectedConversationId, conversationType } = useChatStore();
483
+ useListConversationsQuery({ chatId });
484
+ const { isLoading, data: chat } = useGetChatQuery({ chatId });
485
+ const { isLoading: isConversationLoading } = useGetConversationQuery({
486
+ chatId,
487
+ conversationId: selectedConversationId
488
+ });
489
+ const canCreateMessage = chat?.chatModelSettings?.allowedModels && chat?.chatModelSettings?.allowedModels.length > 0;
490
+ if (!canCreateMessage && chat?.chatBaseSettings?.hideChatWhenInsufficientCredits) {
491
+ return null;
492
+ }
493
+ return /* @__PURE__ */ jsxs(Card, { className: "min-w-[320px] h-[640px] w-[400px] flex flex-col relative p-0 rounded-lg gap-0", children: [
494
+ isLoading && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center z-10 bg-card rounded-lg", children: /* @__PURE__ */ jsx(DotsLoader, {}) }),
495
+ /* @__PURE__ */ jsx(ChatHeader, { chatId }),
496
+ conversationType === "history" && isConversationLoading && /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-center z-10 bg-card rounded-lg", children: /* @__PURE__ */ jsx(DotsLoader, {}) }),
497
+ !isLoading && (conversationType === "new" || !isConversationLoading) && /* @__PURE__ */ jsxs(
498
+ "div",
499
+ {
500
+ className: tab !== "chat" ? "hidden" : "flex flex-col flex-1 min-h-0",
501
+ children: [
502
+ conversationType === "history" && isConversationLoading && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center z-10 bg-card rounded-lg", children: /* @__PURE__ */ jsx(DotsLoader, {}) }),
503
+ canCreateMessage ? /* @__PURE__ */ jsx(ChatElement, {}) : /* @__PURE__ */ jsx("div", { className: "m-4 h-full flex items-center justify-center", children: /* @__PURE__ */ jsx(
504
+ Text,
505
+ {
506
+ variant: "paragraph1",
507
+ color: "muted",
508
+ className: "text-center font-light italic",
509
+ children: t("chat-card.insufficient-credits-error")
510
+ }
511
+ ) })
512
+ ]
513
+ }
514
+ ),
515
+ !isLoading && tab === "history" && /* @__PURE__ */ jsx(ChatHistory, {})
516
+ ] });
517
+ }
518
+ var {
519
+ MoleculeProvider,
520
+ useMolecule,
521
+ useMoleculeConfig,
522
+ useMoleculeComponent,
523
+ useMoleculeCallbacks
524
+ } = createMoleculeContext({ name: "ChatSDK.Chat" });
525
+ function ChatMolecule(props) {
526
+ const { config, callbacks, ...componentProps } = useMergeMoleculeConfig({
527
+ props,
528
+ name: "ChatSDK.Chat"
529
+ });
530
+ if (!componentProps.chatId) {
531
+ return null;
532
+ }
533
+ return /* @__PURE__ */ jsx(
534
+ MoleculeProvider,
535
+ {
536
+ config,
537
+ component: componentProps,
538
+ callbacks,
539
+ children: /* @__PURE__ */ jsx(ChatCard, {})
540
+ }
541
+ );
542
+ }
543
+ ChatMolecule.displayName = "ChatSDK.ChatMolecule";
544
+
545
+ // src/features/data-fetching/use-api-client.ts
546
+ function useApiClient() {
547
+ const { api } = useMoleculeConfig();
548
+ return getClient(api ?? {});
549
+ }
550
+
551
+ export { ChatCard, ChatElement, ChatHeader, ChatHistory, ChatMolecule, ChatPromptInput, MoleculeProvider, getConversationQueryConfig, useApiClient, useChat, useGetChatQuery, useGetConversationQuery, useInitialMessages, useListConversationsQuery, useMolecule, useMoleculeCallbacks, useMoleculeComponent, useMoleculeConfig };
@@ -0,0 +1,24 @@
1
+ import { resources, languages, defaultNamespace, fallbackLng } from './chunk-R7G3RQLU.js';
2
+ import i18next from 'i18next';
3
+ import { initReactI18next } from 'react-i18next/initReactI18next';
4
+
5
+ var runsOnServerSide = typeof window === "undefined";
6
+ var elementsI18n = i18next.createInstance();
7
+ elementsI18n.use(initReactI18next).init({
8
+ // debug: true,
9
+ showSupportNotice: false,
10
+ supportedLngs: languages,
11
+ fallbackLng,
12
+ fallbackNS: defaultNamespace,
13
+ defaultNS: defaultNamespace,
14
+ lng: void 0,
15
+ // detect the language on client side
16
+ detection: {
17
+ order: ["path", "htmlTag", "cookie", "navigator"]
18
+ },
19
+ preload: runsOnServerSide ? languages : [],
20
+ resources
21
+ });
22
+ var i18n = elementsI18n;
23
+
24
+ export { i18n };
@@ -0,0 +1,16 @@
1
+ // src/features/logger/logger.ts
2
+ function noOp() {
3
+ }
4
+ function getLogger(loggers) {
5
+ const _loggers = typeof loggers === "function" ? { info: loggers } : loggers;
6
+ const infoLogger = _loggers?.info || noOp;
7
+ const warnLogger = _loggers?.warn || infoLogger;
8
+ const errorLogger = _loggers?.error || infoLogger;
9
+ return {
10
+ info: infoLogger,
11
+ warn: warnLogger,
12
+ error: errorLogger
13
+ };
14
+ }
15
+
16
+ export { getLogger };
@@ -0,0 +1,25 @@
1
+ import { useMergeGlobalConfig } from './chunk-MXTBCHYC.js';
2
+
3
+ // src/features/molecule/use-molecule-config.ts
4
+ function useMergeMoleculeConfig(moleculeConfig) {
5
+ const {
6
+ defaultProps: flatDefaultProps,
7
+ component,
8
+ ...flatProps
9
+ } = moleculeConfig.props;
10
+ const { defaultProps: componentDefaultProps, ...componentProps } = component || {};
11
+ const _defaultProps = { ...flatDefaultProps, ...componentDefaultProps };
12
+ const _props = { ...componentProps, ...flatProps };
13
+ const { config, onloading, onsuccess, onerror, ...rest } = {
14
+ ..._defaultProps,
15
+ ..._props
16
+ };
17
+ const mergedConfig = useMergeGlobalConfig(config);
18
+ return {
19
+ ...rest,
20
+ config: mergedConfig,
21
+ callbacks: { onloading, onsuccess, onerror }
22
+ };
23
+ }
24
+
25
+ export { useMergeMoleculeConfig };